diff options
| author | Michael Brown | 2025-04-14 12:34:20 +0200 |
|---|---|---|
| committer | Michael Brown | 2025-04-14 15:52:51 +0200 |
| commit | 37e9f785ba6573a5298cf6aea2b04bf4ad674b2f (patch) | |
| tree | e2f1064e8dbf8eab9a8fadf5e84f8e44fa455dc9 /src/include/ipxe/devtree.h | |
| parent | [fdt] Remove concept of a device tree cursor (diff) | |
| download | ipxe-37e9f785ba6573a5298cf6aea2b04bf4ad674b2f.tar.gz ipxe-37e9f785ba6573a5298cf6aea2b04bf4ad674b2f.tar.xz ipxe-37e9f785ba6573a5298cf6aea2b04bf4ad674b2f.zip | |
[dt] Add basic concept of a devicetree bus
Add a basic model for devices instantiated by parsing the system
flattened device tree, with drivers matched via the "compatible"
property for any non-root node.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/devtree.h')
| -rw-r--r-- | src/include/ipxe/devtree.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/include/ipxe/devtree.h b/src/include/ipxe/devtree.h new file mode 100644 index 000000000..f31ddbd5b --- /dev/null +++ b/src/include/ipxe/devtree.h @@ -0,0 +1,76 @@ +#ifndef _IPXE_DEVTREE_H +#define _IPXE_DEVTREE_H + +/** @file + * + * Devicetree bus + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include <ipxe/device.h> + +/** A devicetree device */ +struct dt_device { + /** Generic device */ + struct device dev; + /** Device path */ + const char *path; + /** Driver for this device */ + struct dt_driver *driver; + /** Driver-private data */ + void *priv; +}; + +/** A devicetree driver */ +struct dt_driver { + /** Driver name */ + const char *name; + /** Compatible programming model identifiers */ + const char **ids; + /** Number of compatible programming model identifiers */ + unsigned int id_count; + /** + * Probe device + * + * @v dt Devicetree device + * @v offset Starting node offset + * @ret rc Return status code + */ + int ( * probe ) ( struct dt_device *dt, unsigned int offset ); + /** + * Remove device + * + * @v dt Devicetree device + */ + void ( * remove ) ( struct dt_device *dt ); +}; + +/** Devicetree driver table */ +#define DT_DRIVERS __table ( struct dt_driver, "dt_drivers" ) + +/** Declare a devicetree driver */ +#define __dt_driver __table_entry ( DT_DRIVERS, 01 ) + +/** + * Set devicetree driver-private data + * + * @v dt Devicetree device + * @v priv Private data + */ +static inline void dt_set_drvdata ( struct dt_device *dt, void *priv ) { + dt->priv = priv; +} + +/** + * Get devicetree driver-private data + * + * @v dt Devicetree device + * @ret priv Private data + */ +static inline void * dt_get_drvdata ( struct dt_device *dt ) { + return dt->priv; +} + +#endif /* _IPXE_DEVTREE_H */ |
