diff mbox series

[03/30] dm: core: Add macros to access the new linker lists

Message ID 20201230210941.3.I203d6c2e1211d979289198ee3410009acd7353e6@changeid
State Superseded
Delegated to: Simon Glass
Headers show
Series dm: Implement OF_PLATDATA_INST in driver model (part E) | expand

Commit Message

Simon Glass Dec. 31, 2020, 4:09 a.m. UTC
Add macros which work with instantiated devices and uclasses, as created
at build time by dtoc. Include variants that can be used in data
structures.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/device-internal.h | 26 ++++++++++++++++++++++++++
 include/dm/device.h          | 11 +++++++++++
 include/dm/uclass-internal.h | 23 +++++++++++++++++++++++
 include/dm/uclass.h          | 20 ++++++++++++++++++++
 4 files changed, 80 insertions(+)
diff mbox series

Patch

diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index 639bbd293d9..9d7256130cd 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -10,11 +10,37 @@ 
 #ifndef _DM_DEVICE_INTERNAL_H
 #define _DM_DEVICE_INTERNAL_H
 
+#include <linker_lists.h>
 #include <dm/ofnode.h>
 
 struct device_node;
 struct udevice;
 
+/*
+ * These are only allowed these in code generated by dtoc, because the ordering
+ * is important and if other instances creep in then they may mess up the
+ * ordering expected by dtoc.
+ */
+
+/* Declare a bound device ready for run-time use */
+#define DM_DEVICE_INST(__name)						\
+	ll_entry_declare(struct udevice, __name, udevice)
+
+/* Declare a bound device as an extern, so it can be referenced at build time */
+#define DM_DEVICE_DECL(__name)						\
+	ll_entry_decl(struct udevice, __name, udevice)
+
+/*
+ * Get a pointer to a given device, for use in data structures. This requires
+ * that the symbol be declared with DM_DRIVER_DECL() first
+ */
+#define DM_DEVICE_REF(__name)						\
+	ll_entry_ref(struct udevice, __name, udevice)
+
+/* Get a pointer to a given device */
+#define DM_DEVICE_GET(__name)						\
+	ll_entry_get(struct udevice, __name, udevice)
+
 /**
  * device_bind() - Create a device and bind it to a driver
  *
diff --git a/include/dm/device.h b/include/dm/device.h
index e08a11c4a18..00d25c16862 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -338,6 +338,17 @@  struct driver {
 #define DM_DRIVER_GET(__name)						\
 	ll_entry_get(struct driver, __name, driver)
 
+/* Declare a driver as an extern, so it can be referenced at build time */
+#define DM_DRIVER_DECL(__name)					\
+	ll_entry_decl(struct driver, __name, driver)
+
+/*
+ * Get a pointer to a given driver, for use in data structures. This requires
+ * that the symbol be declared with DM_DRIVER_DECL() first
+ */
+#define DM_DRIVER_REF(__name)					\
+	ll_entry_ref(struct driver, __name, driver)
+
 /**
  * Declare a macro to state a alias for a driver name. This macro will
  * produce no code but its information will be parsed by tools like
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index c5a464be7c4..fc4d8dc2b53 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -11,6 +11,29 @@ 
 
 #include <dm/ofnode.h>
 
+/*
+ * These are only allowed these in code generated by dtoc, because the ordering
+ * is important and if other instances creep in then they may mess up the
+ * ordering expected by dtoc.
+ */
+
+/*
+ * Declare a uclass ready for run-time use. This adds an actual struct uclass
+ * to a list which is found by driver model on start-up.
+ */
+#define DM_UCLASS_INST(__name)						\
+	ll_entry_declare(struct uclass, __name, uclass)
+
+#define DM_UCLASS_DECL(__name)						\
+	ll_entry_decl(struct uclass, __name, uclass)
+
+/*
+ * Declare a uclass as an extern, so it can be referenced at build time. This
+ * is an extern for DM_UCLASS_INST().
+ */
+#define DM_UCLASS_REF(__name)						\
+	ll_entry_ref(struct uclass, __name, uclass)
+
 /**
  * uclass_set_priv() - Set the private data for a uclass
  *
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index b5f066dbf48..472a7145c60 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -114,6 +114,26 @@  struct uclass_driver {
 #define UCLASS_DRIVER(__name)						\
 	ll_entry_declare(struct uclass_driver, __name, uclass_driver)
 
+/*
+ * These two macros are related to of-platdata, and normally only used in
+ * code generated by dtoc
+ */
+
+/*
+ * Declare a uclass driver as an extern, so it can be referenced at build time
+ * This is the extern equivalent of UCLASS_DRIVER(). You need to place this at
+ * the top level before you use DM_UCLASS_DRIVER_REF() in a file.
+ */
+#define DM_UCLASS_DRIVER_DECL(__name)					\
+	ll_entry_decl(struct uclass_driver, __name, uclass_driver)
+
+/*
+ * Get a pointer to a given uclass driver, for use in data structures. This
+ * requires that the symbol be declared with DM_UCLASS_DRIVER_DECL() first
+ */
+#define DM_UCLASS_DRIVER_REF(__name)					\
+	ll_entry_ref(struct uclass_driver, __name, uclass_driver)
+
 /**
  * uclass_get_priv() - Get the private data for a uclass
  *