Skip to contentSkip to conversation

dynamic device tree char driver

PATCH New Alan Tull 2 participants 6 messages Aug 16, 2012 – Aug 21, 2012 3 messages not in the archive Device tree

lore
Share & tools
lore

Alan Tull

author
#0 lore raw

Hello,

I'm Alan Tull, interested in dynamic features of device trees.

The following patch adds a char driver to add or remove device tree nodes dynamically. Its ioctl passes a struct with:
- size of the blob
- pointer to the blob

The path to add the nodes under is coded in the blob with dummy nodes. For example the following can be compiled into a blob and sent to this driver adding a single node under /soc/apb_periphs:

/dts-v1/;

/ {
        soc {
                apb_periphs {
                        i2c1: i2c@ffc05000 {
                                compatible = "snps,designware-i2c";
                                reg = <0xffc05000 0x1000>;
                                interrupts = <0 159 4>;
                                emptyfifo_hold_master = <1>;
                        };
                };
        };
};

I wanted to get feeback early before I went too far down this particular path. As such, this code doesn't do any notification for drivers yet. Also it won't properly add nested nodes yet. It can add/remove a single node and see it show up properly under /proc/device-tree.

Alan Tull
Altera

author
#2 lore raw

PATCH 1/1 dynamic device tree char driver

In reply to a message not in the archive

* Add a ioctls for adding/removing nodes using binary blobs.

---
 drivers/of/Makefile  |    1 +
 drivers/of/dynamic.c |  287 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/of/dynamic.h |   26 +++++
 3 files changed, 314 insertions(+), 0 deletions(-)
 create mode 100644 drivers/of/dynamic.c
 create mode 100644 drivers/of/dynamic.h
drivers/of/Makefile +1 -0
index e027f44..5c08045 100644
@@ -4,6 +4,7 @@ obj-$(CONFIG_OF_PROMTREE) += pdt.o
 obj-$(CONFIG_OF_ADDRESS)  += address.o
 obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
+obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
 obj-$(CONFIG_OF_I2C)	+= of_i2c.o
 obj-$(CONFIG_OF_NET)	+= of_net.o
 obj-$(CONFIG_OF_SELFTEST) += selftest.o
drivers/of/dynamic.c new file +287 -0

287 lines not on this page · raw message

drivers/of/dynamic.h new file +26 -0
new file mode 100644
index 0000000..4ee4e96
@@ -0,0 +1,26 @@
+/*
+ * Dynamic Device Tree support
+ *
+ * Copyrignt (C) 2012 Altera Corporation
+ *
+ */
+
+#ifndef __OF_DYNAMIC_H
+#define __OF_DYNAMIC_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+struct of_dynamic_blob_info {
+	__u32 size;
+	__u8 *blob;
+};
+
+/*
+ * TODO pick some unused ioctls (see Documentation/ioctl/ioctl-number-txt)
+ * and ask mec to register them
+ */
+#define OF_DYNAMIC_ADD_NODE	_IOW('W', 0, struct of_dynamic_blob_info *)
+#define OF_DYNAMIC_REMOVE_NODE	_IOW('W', 1, struct of_dynamic_blob_info *)
+
+#endif /* __OF_DYNAMIC_H */
Signature · 1 line
1.7.1
#3 lore raw
In reply to a message not in the archive
Quoted 4 lines · Alan Tull

Hello,

I'm Alan Tull, interested in dynamic features of device trees.

Hey Alan. How are you doing?

Quoted 23 lines

The following patch adds a char driver to add or remove device tree nodes dynamically. Its ioctl passes a struct with:
- size of the blob
- pointer to the blob

The path to add the nodes under is coded in the blob with dummy nodes. For example the following can be compiled into a blob and sent to this driver adding a single node under /soc/apb_periphs:

/dts-v1/;

/ {
        soc {
                apb_periphs {
                        i2c1: i2c@ffc05000 {
                                compatible = "snps,designware-i2c";
                                reg = <0xffc05000 0x1000>;
                                interrupts = <0 159 4>;
                                emptyfifo_hold_master = <1>;
                        };
                };
        };
};
Quoted 4 lines

I wanted to get feeback early before I went too far down this particular path. As such, this code doesn't do any notification for drivers yet. Also it won't properly add nested nodes yet. It can add/remove a single node and see it show up properly under /proc/device-tree.

Have you looked at arch/powerpc/platforms/pseries/reconfig.c?

There was also a recent discussion titled "OF_DYNAMIC usage" that you should look at.

I don't think a char driver and ioctls will fly...

Another option could be kexecing with a new DTB if you can live with a reboot.

Rob

Quoted 9 lines

Alan Tull
Altera

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

author
#5 lore raw
In reply to a message not in the archive
Quoted 7 lines · Rob Herring
Quoted 4 lines · Alan Tull

Hello,

I'm Alan Tull, interested in dynamic features of device trees.

Hey Alan. How are you doing?

Doing good! Nice to hear from you.

Quoted 24 lines
Quoted 24 lines

The following patch adds a char driver to add or remove device tree nodes dynamically. Its ioctl passes a struct with:
- size of the blob
- pointer to the blob

The path to add the nodes under is coded in the blob with dummy nodes. For example the following can be compiled into a blob and sent to this driver adding a single node under /soc/apb_periphs:

/dts-v1/;

/ {
        soc {
                apb_periphs {
                        i2c1: i2c@ffc05000 {
                                compatible = "snps,designware-i2c";
                                reg = <0xffc05000 0x1000>;
                                interrupts = <0 159 4>;
                                emptyfifo_hold_master = <1>;
                        };
                };
        };
};
Quoted 6 lines
Quoted 4 lines

I wanted to get feeback early before I went too far down this particular path. As such, this code doesn't do any notification for drivers yet. Also it won't properly add nested nodes yet. It can add/remove a single node and see it show up properly under /proc/device-tree.

Have you looked at arch/powerpc/platforms/pseries/reconfig.c?

Yes. In fact I borrowed a three functions from it and gave credit in the patch. I'm trying to do something that is architecture independent and that uses the same type of device tree files (blobs) as are used during bootup. In my case it will run on an ARM which will have soft peripherals instantiated in a FPGA. So after bootup we want to be able to reconfigure the IP in the FPGA dynamically, then reconfigure the device tree and load some drivers. Pretty cool stuff.That's why I'm interested in doing this dynamically without a reboot.

Quoted 4 lines

There was also a recent discussion titled "OF_DYNAMIC usage" that you should look at.

I don't think a char driver and ioctls will fly...

Doh! Yes, I know the thread. For some reason, I thought it would be better to post a patch as a new thread rather than posting a patch to the "OF_DYNAMIC usage" thread but perhaps not. Sorry for forking the discussion.

That is where I got the idea of doing ioctls. I am assuming that there's only going to be one proper place in the tree for each blob to get inserted, so I leave that path information in the blob rather than storing it passing it as a separate parameter of the ioctl.

reconfig.c's interface is pretty bad. It uses /proc as the place for the user to write commands. The commands are broken up such that the userspace has to 'add _node', then do 'add_property' a few times. Also it had to introduce a flag "OF_DYNAMIC" (not to be confused with "CONFIG_OF_DYNAMIC") to keep of_node_release from releasing the nodes that are allocated in reconfig.c. Seems messy.

With an ioctl, the userspace can just send a single command to add a blob. The blob can contain one node or many nodes as long as they all end up under the same path. Removing nodes is just as straightforward and clean.

Quoted 3 lines

Another option could be kexecing with a new DTB if you can live with a reboot.

We are looking at reconfiguring soft peripheral in a FPGA on the fly. So a reboot won't work here.

Quoted 14 lines

Rob

Quoted 9 lines

Alan Tull
Altera

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#6 lore raw
Quoted 50 lines · Alan Tull
Quoted 7 lines · Rob Herring
Quoted 4 lines · Alan Tull

Hello,

I'm Alan Tull, interested in dynamic features of device trees.

Hey Alan. How are you doing?

Doing good! Nice to hear from you.

Quoted 24 lines
Quoted 24 lines

The following patch adds a char driver to add or remove device tree nodes dynamically. Its ioctl passes a struct with:
- size of the blob
- pointer to the blob

The path to add the nodes under is coded in the blob with dummy nodes. For example the following can be compiled into a blob and sent to this driver adding a single node under /soc/apb_periphs:

/dts-v1/;

/ {
        soc {
                apb_periphs {
                        i2c1: i2c@ffc05000 {
                                compatible = "snps,designware-i2c";
                                reg = <0xffc05000 0x1000>;
                                interrupts = <0 159 4>;
                                emptyfifo_hold_master = <1>;
                        };
                };
        };
};
Quoted 6 lines
Quoted 4 lines

I wanted to get feeback early before I went too far down this particular path. As such, this code doesn't do any notification for drivers yet. Also it won't properly add nested nodes yet. It can add/remove a single node and see it show up properly under /proc/device-tree.

Have you looked at arch/powerpc/platforms/pseries/reconfig.c?

Yes. In fact I borrowed a three functions from it and gave credit in the patch. I'm trying to do something that is architecture independent and that uses the same type of device tree files (blobs) as are used during bootup. In my case it will run on an ARM which will have soft peripherals instantiated in a FPGA. So after bootup we want to be able to reconfigure the IP in the FPGA dynamically, then reconfigure the device tree and load some drivers. Pretty cool stuff.That's why I'm interested in doing this dynamically without a reboot.

Quoted 8 lines
Quoted 4 lines

There was also a recent discussion titled "OF_DYNAMIC usage" that you should look at.

I don't think a char driver and ioctls will fly...

Doh! Yes, I know the thread. For some reason, I thought it would be better to post a patch as a new thread rather than posting a patch to the "OF_DYNAMIC usage" thread but perhaps not. Sorry for forking the discussion.

The fork is fine. Just making sure you were aware of it.

Quoted 4 lines

That is where I got the idea of doing ioctls. I am assuming that there's only going to be one proper place in the tree for each blob to get inserted, so I leave that path information in the blob rather than storing it passing it as a separate parameter of the ioctl.

ioctls simply won't fly. So I would start by extending the current interface to do blobs. From a user standpoint, something like this is certainly easier to use than an ioctl:

echo "add blob" > /proc/devicetree/ofdt
cat blob.dtb > /proc/devicetree/ofdt

Quoted 11 lines

reconfig.c's interface is pretty bad. It uses /proc as the place for the user to write commands. The commands are broken up such that the userspace has to 'add _node', then do 'add_property' a few times. Also it had to introduce a flag "OF_DYNAMIC" (not to be confused with "CONFIG_OF_DYNAMIC") to keep of_node_release from releasing the nodes that are allocated in reconfig.c. Seems messy.

With an ioctl, the userspace can just send a single command to add a blob. The blob can contain one node or many nodes as long as they all end up under the same path. Removing nodes is just as straightforward and clean.

Whether paths are part of the blob are debatable. I'm sure you and your competitors can put your heads together and come up with something. :)

Rob

Quoted 23 lines
Quoted 3 lines

Another option could be kexecing with a new DTB if you can live with a reboot.

We are looking at reconfiguring soft peripheral in a FPGA on the fly. So a reboot won't work here.

Quoted 14 lines

Rob

Quoted 9 lines

Alan Tull
Altera

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

author
#8 lore raw
In reply to a message not in the archive
Quoted 67 lines · Rob Herring
Quoted 50 lines · Alan Tull
Quoted 7 lines · Rob Herring
Quoted 4 lines · Alan Tull

Hello,

I'm Alan Tull, interested in dynamic features of device trees.

Hey Alan. How are you doing?

Doing good! Nice to hear from you.

Quoted 24 lines
Quoted 24 lines

The following patch adds a char driver to add or remove device tree nodes dynamically. Its ioctl passes a struct with:
- size of the blob
- pointer to the blob

The path to add the nodes under is coded in the blob with dummy nodes. For example the following can be compiled into a blob and sent to this driver adding a single node under /soc/apb_periphs:

/dts-v1/;

/ {
        soc {
                apb_periphs {
                        i2c1: i2c@ffc05000 {
                                compatible = "snps,designware-i2c";
                                reg = <0xffc05000 0x1000>;
                                interrupts = <0 159 4>;
                                emptyfifo_hold_master = <1>;
                        };
                };
        };
};
Quoted 6 lines
Quoted 4 lines

I wanted to get feeback early before I went too far down this particular path. As such, this code doesn't do any notification for drivers yet. Also it won't properly add nested nodes yet. It can add/remove a single node and see it show up properly under /proc/device-tree.

Have you looked at arch/powerpc/platforms/pseries/reconfig.c?

Yes. In fact I borrowed a three functions from it and gave credit in the patch. I'm trying to do something that is architecture independent and that uses the same type of device tree files (blobs) as are used during bootup. In my case it will run on an ARM which will have soft peripherals instantiated in a FPGA. So after bootup we want to be able to reconfigure the IP in the FPGA dynamically, then reconfigure the device tree and load some drivers. Pretty cool stuff.That's why I'm interested in doing this dynamically without a reboot.

Quoted 8 lines
Quoted 4 lines

There was also a recent discussion titled "OF_DYNAMIC usage" that you should look at.

I don't think a char driver and ioctls will fly...

Doh! Yes, I know the thread. For some reason, I thought it would be better to post a patch as a new thread rather than posting a patch to the "OF_DYNAMIC usage" thread but perhaps not. Sorry for forking the discussion.

The fork is fine. Just making sure you were aware of it.

Quoted 4 lines

That is where I got the idea of doing ioctls. I am assuming that there's only going to be one proper place in the tree for each blob to get inserted, so I leave that path information in the blob rather than storing it passing it as a separate parameter of the ioctl.

Quoted 6 lines

ioctls simply won't fly. So I would start by extending the current interface to do blobs. From a user standpoint, something like this is certainly easier to use than an ioctl:

echo "add blob" > /proc/devicetree/ofdt
cat blob.dtb > /proc/devicetree/ofdt

That does have the advantage of not needing a userspace app. But something could write to /proc/devicetree/ofdt between the echo and the cat. A way to prevent that would be

echo "add blob" > add.txt
cat add.txt blob.dtb > /proc/devicetree/ofdt

In real world use, there would be a set of dtb's and a userspace app that would prepend the "add blob" command when sending it to proc.

I am a bit surprised that it is considered fine to cat a binary file to /proc. I'm used to thinking that as all being readable text.

Quoted 13 lines
Quoted 8 lines

reconfig.c's interface is pretty bad. It uses /proc as the place for the user to write commands. The commands are broken up such that the userspace has to 'add _node', then do 'add_property' a few times. Also it had to introduce a flag "OF_DYNAMIC" (not to be confused with "CONFIG_OF_DYNAMIC") to keep of_node_release from releasing the nodes that are allocated in reconfig.c. Seems messy.

Quoted 4 lines

With an ioctl, the userspace can just send a single command to add a blob. The blob can contain one node or many nodes as long as they all end up under the same path. Removing nodes is just as straightforward and clean.

Quoted 30 lines

Whether paths are part of the blob are debatable. I'm sure you and your competitors can put your heads together and come up with something. :)

Rob

Quoted 23 lines
Quoted 3 lines

Another option could be kexecing with a new DTB if you can live with a reboot.

We are looking at reconfiguring soft peripheral in a FPGA on the fly. So a reboot won't work here.

Quoted 14 lines

Rob

Quoted 9 lines

Alan Tull
Altera

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

Confidentiality Notice.
This message may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution, or copying of this message, or any attachments, is strictly prohibited. If you have received this message in error, please advise the sender by reply e-mail, and delete the message and any attachments. Thank you.