summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/devtree.h
diff options
context:
space:
mode:
authorSimon Rettberg2026-01-28 12:53:53 +0100
committerSimon Rettberg2026-01-28 12:53:53 +0100
commit8e82785c584dc13e20f9229decb95bd17bbe9cd1 (patch)
treea8b359e59196be5b2e3862bed189107f4bc9975f /src/include/ipxe/devtree.h
parentMerge branch 'master' into openslx (diff)
parent[prefix] Make unlzma.S compatible with 386 class CPUs (diff)
downloadipxe-openslx.tar.gz
ipxe-openslx.tar.xz
ipxe-openslx.zip
Merge branch 'master' into openslxopenslx
Diffstat (limited to 'src/include/ipxe/devtree.h')
-rw-r--r--src/include/ipxe/devtree.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/include/ipxe/devtree.h b/src/include/ipxe/devtree.h
new file mode 100644
index 000000000..2bf473a3b
--- /dev/null
+++ b/src/include/ipxe/devtree.h
@@ -0,0 +1,97 @@
+#ifndef _IPXE_DEVTREE_H
+#define _IPXE_DEVTREE_H
+
+/** @file
+ *
+ * Devicetree bus
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/device.h>
+#include <ipxe/dma.h>
+#include <ipxe/fdt.h>
+
+/** A devicetree device */
+struct dt_device {
+ /** Device name */
+ const char *name;
+ /** Generic device */
+ struct device dev;
+ /** DMA device */
+ struct dma_device dma;
+ /** 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;
+}
+
+/**
+ * Get devicetree parent device
+ *
+ * @v dt Devicetree device
+ * @ret parent Parent devicetree device
+ */
+static inline struct dt_device * dt_parent ( struct dt_device *dt ) {
+ return container_of ( dt->dev.parent, struct dt_device, dev );
+}
+
+extern void * dt_ioremap ( struct dt_device *dt, unsigned int offset,
+ unsigned int index, size_t len );
+extern int dt_probe_node ( struct device *parent, unsigned int offset );
+extern void dt_remove_node ( struct device *parent );
+extern int dt_probe_children ( struct dt_device *parent, unsigned int offset );
+extern void dt_remove_children ( struct dt_device *parent );
+
+#endif /* _IPXE_DEVTREE_H */