summaryrefslogtreecommitdiffstats
path: root/include/driver.h
diff options
context:
space:
mode:
authorsascha <sascha@nomad.localdomain>2007-10-19 08:45:57 +0200
committersascha <sascha@nomad.localdomain>2007-10-19 08:45:57 +0200
commit3b6d6a45e705efb64fe522158ed33f640073da12 (patch)
treea7f25b80f133f7046ad88b6a19ee320281922ffa /include/driver.h
parent98839f801049609613a964e0526083b66d236e5a (diff)
downloadbarebox-3b6d6a45e705efb64fe522158ed33f640073da12.tar.gz
barebox-3b6d6a45e705efb64fe522158ed33f640073da12.tar.xz
- Implement tree structure for devices
- Use device tree structure to implement partitions - Let devinfo print a nice tree - Introduce 'fixed' partitions which are not removable - Fix mount: It was not possible to mount on a relative path.
Diffstat (limited to 'include/driver.h')
-rw-r--r--include/driver.h45
1 files changed, 38 insertions, 7 deletions
diff --git a/include/driver.h b/include/driver.h
index 018bbacee5..1b927596b0 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -37,7 +37,11 @@ struct device_d {
struct driver_d *driver; /* The driver for this device */
- struct list_head list;
+ struct list_head list; /* The list of all devices */
+ struct list_head children; /* our children */
+ struct list_head sibling;
+
+ struct device_d *parent; /* our parent, NULL if not present */
unsigned long type;
@@ -70,12 +74,30 @@ struct driver_d {
#define RW_SIZE(x) (x)
#define RW_SIZE_MASK 0x7
-/* Register/unregister devices and drivers. Since we don't have modules
- * we do not need a driver_unregister function.
+/* Register devices and drivers.
*/
int register_driver(struct driver_d *);
int register_device(struct device_d *);
-void unregister_device(struct device_d *);
+
+/* Unregister a device. This function can fail, e.g. when the device
+ * has children.
+ */
+int unregister_device(struct device_d *);
+
+/* Organize devices in a tree. These functions do _not_ register or
+ * unregister a device. Only registered devices are allowed here.
+ */
+int dev_add_child(struct device_d *dev, struct device_d *child);
+
+/* Iterate over a devices children
+ */
+#define device_for_each_child(dev, child) \
+ list_for_each_entry(child, &dev->children, sibling)
+
+/* Iterate over a devices children - Safe against removal version
+ */
+#define device_for_each_child_safe(dev, tmpdev, child) \
+ list_for_each_entry_safe(child, tmpdev, &dev->children, sibling)
/* Iterate through the devices of a given type. if last is NULL, the
* first device of this type is returned. Put this pointer in as
@@ -84,7 +106,7 @@ void unregister_device(struct device_d *);
*/
struct device_d *get_device_by_type(ulong type, struct device_d *last);
struct device_d *get_device_by_id(const char *id);
-struct device_d *get_first_device(void);
+struct device_d *get_device_by_path(const char *path);
/* Find a free device id from the given template. This is archieved by
* appending a number to the template. Dynamically created devices should
@@ -92,13 +114,22 @@ struct device_d *get_first_device(void);
*/
int get_free_deviceid(char *id, char *id_template);
-struct device_d *device_from_spec_str(const char *str, char **endp);
char *deviceid_from_spec_str(const char *str, char **endp);
+/* linear list over all available devices
+ */
extern struct list_head device_list;
-#define for_each_device(dev) list_for_each_entry(dev, &device_list, list)
+/* linear list over all available drivers
+ */
extern struct list_head driver_list;
+
+/* Iterate over all devices
+ */
+#define for_each_device(dev) list_for_each_entry(dev, &device_list, list)
+
+/* Iterate over all drivers
+ */
#define for_each_driver(drv) list_for_each_entry(drv, &driver_list, list)
/* Find a driver with the given name. Currently the filesystem implementation