summaryrefslogtreecommitdiff
path: root/include/dm/device-internal.h
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-04-05 11:29:57 -0400
committerTom Rini <trini@konsulko.com>2021-04-05 11:29:57 -0400
commit90eba245a66aa20589404ba537215faf2012c1a3 (patch)
treec581cd1f00dd162aeac4262bb4e74c2a9fea98c9 /include/dm/device-internal.h
parentb46dd116ce03e235f2a7d4843c6278e1da44b5e1 (diff)
parentdb8b46120aed6554d1ff405260ea6d2cc2439fcc (diff)
downloadu-boot-90eba245a66aa20589404ba537215faf2012c1a3.tar.gz
Merge branch 'next'
Diffstat (limited to 'include/dm/device-internal.h')
-rw-r--r--include/dm/device-internal.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index 39406c3f35..e6b71cbfd2 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -10,11 +10,86 @@
#ifndef _DM_DEVICE_INTERNAL_H
#define _DM_DEVICE_INTERNAL_H
+#include <linker_lists.h>
#include <dm/ofnode.h>
struct device_node;
struct udevice;
+/*
+ * These two macros DM_DEVICE_INST and DM_DEVICE_REF are only allowed 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.
+ *
+ * It is OK to use them with 'extern' though, since that does not actually
+ * add a new record to the linker_list.
+ */
+
+/**
+ * DM_DEVICE_INST() - Declare a bound device ready for run-time use
+ *
+ * This adds an actual struct udevice to a list which is found by driver model
+ * on start-up.
+ *
+ * For example:
+ *
+ * extern U_BOOT_DRIVER(sandbox_fixed_clock);
+ * extern DM_UCLASS_INST(clk);
+ *
+ * DM_DEVICE_INST(clk_fixed) = {
+ * .driver = DM_DRIVER_REF(sandbox_fixed_clock),
+ * .name = "sandbox_fixed_clock",
+ * .plat_ = &_sandbox_fixed_clock_plat_clk_fixed,
+ * .uclass = DM_UCLASS_REF(clk),
+ * ...
+ * .seq_ = 0,
+ * };
+ *
+ * @_name: Name of the udevice. This must be a valid C identifier, used by the
+ * linker_list.
+ */
+#define DM_DEVICE_INST(_name) \
+ ll_entry_declare(struct udevice, _name, udevice)
+
+/**
+ * DM_DEVICE_REF() - Get a reference to a device
+ *
+ * This is useful in data structures and code for referencing a udevice at
+ * build time. Before this is used, an extern DM_DEVICE_INST() must have been
+ * declared.
+ *
+ * For example:
+ *
+ * extern DM_DEVICE_INST(clk_fixed);
+ *
+ * struct udevice *devs[] = {
+ * DM_DEVICE_REF(clk_fixed),
+ * };
+ *
+ * @_name: Name of the udevice. This must be a valid C identifier, used by the
+ * linker_list
+ * @returns struct udevice * for the device
+ */
+#define DM_DEVICE_REF(_name) \
+ ll_entry_ref(struct udevice, _name, udevice)
+
+/**
+ * DM_DEVICE_GET() - Get a pointer to a given device
+ *
+ * This is similar to DM_DEVICE_REF() except that it does not need the extern
+ * declaration before it. However it cannot be used in a data structures, only
+ * in code within a function.
+ *
+ * For example:
+ *
+ * void some_function() {
+ * struct udevice *dev = DM_DEVICE_GET(clk_fixed);
+ * ...
+ * }
+ */
+#define DM_DEVICE_GET(__name) \
+ ll_entry_get(struct udevice, __name, udevice)
+
/**
* device_bind() - Create a device and bind it to a driver
*
@@ -209,6 +284,9 @@ static inline int device_chld_remove(struct udevice *dev, struct driver *drv,
* Use this function to override normal operation for special situations, such
* as needing to allocate a variable amount of data.
*
+ * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver
+ * model code, since the pointer must be within the gd->dm_priv_base region.
+ *
* @dev Device to check
* @priv New private-data pointer
*/
@@ -223,6 +301,9 @@ void dev_set_priv(struct udevice *dev, void *priv);
* Use this function to override normal operation for special situations, such
* as needing to allocate a variable amount of data.
*
+ * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver
+ * model code, since the pointer must be within the gd->dm_priv_base region.
+ *
* @dev: Device to update
* @parent_priv: New parent-private data
*/
@@ -237,6 +318,9 @@ void dev_set_parent_priv(struct udevice *dev, void *parent_priv);
* Use this function to override normal operation for special situations, such
* as needing to allocate a variable amount of data.
*
+ * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver
+ * model code, since the pointer must be within the gd->dm_priv_base region.
+ *
* @dev: Device to update
* @uclass_priv: New uclass private data
*/
@@ -251,6 +335,9 @@ void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv);
* Use this function to override normal operation for special situations, such
* as needing to allocate a variable amount of data.
*
+ * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver
+ * model code, since the pointer must be within the gd->dm_priv_base region.
+ *
* @dev Device to check
* @plat New platform-data pointer
*/
@@ -265,6 +352,9 @@ void dev_set_plat(struct udevice *dev, void *priv);
* Use this function to override normal operation for special situations, such
* as needing to allocate a variable amount of data.
*
+ * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver
+ * model code, since the pointer must be within the gd->dm_priv_base region.
+ *
* @dev: Device to update
* @parent_plat: New parent platform data
*/
@@ -279,6 +369,9 @@ void dev_set_parent_plat(struct udevice *dev, void *parent_plat);
* Use this function to override normal operation for special situations, such
* as needing to allocate a variable amount of data.
*
+ * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver
+ * model code, since the pointer must be within the gd->dm_priv_base region.
+ *
* @dev: Device to update
* @uclass_plat: New uclass platform data
*/