Hi Matt, Greg,
On 10/8/21 1:51 PM, Frank Rowand wrote:
On 10/6/21 7:09 PM, Zev Weiss wrote:
Nodes marked with this (boolean) property will have a writable status
sysfs file, which can be used to toggle them between "okay" and
"reserved", effectively hot-plugging them. Note that this will only
be effective for devices on busses that register for OF reconfig
notifications (currently spi, i2c, and platform), and only if
CONFIG_OF_DYNAMIC is enabled.
Signed-off-by: Zev Weiss <zev@xxxxxxxxxxxxxxxxx>
---
drivers/of/kobj.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
index 378cb421aae1..141ae23f3130 100644
--- a/drivers/of/kobj.c
+++ b/drivers/of/kobj.c
@@ -36,6 +36,69 @@ static ssize_t of_node_property_read(struct file *filp, struct kobject *kobj,
return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length);
}
+static ssize_t of_node_status_write(struct file *filp, struct kobject *kobj,
+ struct bin_attribute *bin_attr, char *buf,
+ loff_t offset, size_t count)
+{
+ int rc;
+ char *newstatus;
+ struct property **deadprev;
+ struct property *newprop = NULL;
+ struct property *oldprop = container_of(bin_attr, struct property, attr);
+ struct device_node *np = container_of(kobj, struct device_node, kobj);
+
+ if (WARN_ON_ONCE(strcmp(oldprop->name, "status")))
+ return -EIO;
+
+ if (offset)
+ return -EINVAL;
+
+ if (sysfs_buf_streq(buf, count, "okay") || sysfs_buf_streq(buf, count, "ok"))
+ newstatus = "okay";
+ else if (sysfs_buf_streq(buf, count, "reserved"))
+ newstatus = "reserved";
+ else if (sysfs_buf_streq(buf, count, "disabled"))
+ newstatus = "disabled";
+ else
+ return -EINVAL;
+
+ if (!strcmp(newstatus, oldprop->value))
+ return count;
+
If the general approach of this patch set is the correct way to provide the desired
functionality (I'm still pondering that), then a version of the following code
After pondering, this approach does not appear workable to me.
<snip>
So another approach is needed. I have no yet thought this through, but I
have an alternative. First, change the new property name from "dynamic"
to something more descriptive like "ownership_shifts_between_os_and_others"
(yes, my suggestions is way too verbose and needs to be word smithed, but
the point is to clearly state the underlying action that occurs), then
define the result of this variable to be driver specific, where the
driver is required upon probe to instantiate the device in a manner
that does not impact the other user(s) of the underlying hardware
and to use a driver specific method to transfer control of the
hardware between the os and the other user(s). I propose the method
would be via a device specific file (or set of files) in sysfs (Greg's
input invited on the use of sysfs in this manner - if I recall correctly
this is the current preferred mechanism).