aboutsummaryrefslogtreecommitdiff
path: root/include/dm
diff options
context:
space:
mode:
Diffstat (limited to 'include/dm')
-rw-r--r--include/dm/device-internal.h85
-rw-r--r--include/dm/device.h111
-rw-r--r--include/dm/lists.h2
-rw-r--r--include/dm/platdata.h28
-rw-r--r--include/dm/platform_data/spi_pl022.h2
-rw-r--r--include/dm/read.h18
-rw-r--r--include/dm/simple_bus.h15
-rw-r--r--include/dm/test.h20
-rw-r--r--include/dm/uclass-internal.h14
-rw-r--r--include/dm/uclass.h16
10 files changed, 238 insertions, 73 deletions
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index af3b6b2..639bbd2 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -190,6 +190,90 @@ static inline int device_chld_remove(struct udevice *dev, struct driver *drv,
#endif
/**
+ * dev_set_priv() - Set the private data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * private data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev Device to check
+ * @priv New private-data pointer
+ */
+void dev_set_priv(struct udevice *dev, void *priv);
+
+/**
+ * dev_set_parent_priv() - Set the parent-private data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * parent-private data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @parent_priv: New parent-private data
+ */
+void dev_set_parent_priv(struct udevice *dev, void *parent_priv);
+
+/**
+ * dev_set_uclass_priv() - Set the uclass private data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * uclass-private data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @uclass_priv: New uclass private data
+ */
+void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv);
+
+/**
+ * dev_set_plat() - Set the platform data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * platform data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev Device to check
+ * @plat New platform-data pointer
+ */
+void dev_set_plat(struct udevice *dev, void *priv);
+
+/**
+ * dev_set_parent_plat() - Set the parent platform data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * parent platform data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @parent_plat: New parent platform data
+ */
+void dev_set_parent_plat(struct udevice *dev, void *parent_plat);
+
+/**
+ * dev_set_uclass_plat() - Set the uclass platform data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * uclass platform data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @uclass_plat: New uclass platform data
+ */
+void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat);
+
+/**
* simple_bus_translate() - translate a bus address to a system address
*
* This handles the 'ranges' property in a simple bus. It translates the
@@ -204,6 +288,7 @@ fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr);
/* Cast away any volatile pointer */
#define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
#define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
+#define DM_UCLASS_ROOT_S_NON_CONST (((gd_t *)gd)->uclass_root_s)
/* device resource management */
#ifdef CONFIG_DEVRES
diff --git a/include/dm/device.h b/include/dm/device.h
index 30fc98d..f5b4cd6 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -104,7 +104,7 @@ enum {
* particular port or peripheral (essentially a driver instance).
*
* A device will come into existence through a 'bind' call, either due to
- * a U_BOOT_DEVICE() macro (in which case plat is non-NULL) or a node
+ * a U_BOOT_DRVINFO() macro (in which case plat is non-NULL) or a node
* in the device tree (in which case of_offset is >= 0). In the latter case
* we translate the device tree information into plat in a function
* implemented by the driver of_to_plat method (called just before the
@@ -116,26 +116,34 @@ enum {
*
* @driver: The driver used by this device
* @name: Name of device, typically the FDT node name
- * @plat: Configuration data for this device
- * @parent_plat: The parent bus's configuration data for this device
- * @uclass_plat: The uclass's configuration data for this device
- * @node: Reference to device tree node for this device
+ * @plat_: Configuration data for this device (do not access outside driver
+ * model)
+ * @parent_plat_: The parent bus's configuration data for this device (do not
+ * access outside driver model)
+ * @uclass_plat_: The uclass's configuration data for this device (do not access
+ * outside driver model)
* @driver_data: Driver data word for the entry that matched this device with
* its driver
* @parent: Parent of this device, or NULL for the top level device
- * @priv: Private data for this device
+ * @priv_: Private data for this device (do not access outside driver model)
* @uclass: Pointer to uclass for this device
- * @uclass_priv: The uclass's private data for this device
- * @parent_priv: The parent's private data for this device
+ * @uclass_priv_: The uclass's private data for this device (do not access
+ * outside driver model)
+ * @parent_priv_: The parent's private data for this device (do not access
+ * outside driver model)
* @uclass_node: Used by uclass to link its devices
* @child_head: List of children of this device
* @sibling_node: Next device in list of all devices
- * @flags: Flags for this device DM_FLAG_...
- * @seq: Allocated sequence number for this device (-1 = none). This is set up
+ * @flags_: Flags for this device DM_FLAG_... (do not access outside driver
+ * model)
+ * @seq_: Allocated sequence number for this device (-1 = none). This is set up
* when the device is bound and is unique within the device's uclass. If the
* device has an alias in the devicetree then that is used to set the sequence
* number. Otherwise, the next available number is used. Sequence numbers are
- * used by certain commands that need device to be numbered (e.g. 'mmc dev')
+ * used by certain commands that need device to be numbered (e.g. 'mmc dev').
+ * (do not access outside driver model)
+ * @node_: Reference to device tree node for this device (do not access outside
+ * driver model)
* @devres_head: List of memory allocations associated with this device.
* When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
* add to this list. Memory so-allocated will be freed
@@ -144,21 +152,23 @@ enum {
struct udevice {
const struct driver *driver;
const char *name;
- void *plat;
- void *parent_plat;
- void *uclass_plat;
- ofnode node;
+ void *plat_;
+ void *parent_plat_;
+ void *uclass_plat_;
ulong driver_data;
struct udevice *parent;
- void *priv;
+ void *priv_;
struct uclass *uclass;
- void *uclass_priv;
- void *parent_priv;
+ void *uclass_priv_;
+ void *parent_priv_;
struct list_head uclass_node;
struct list_head child_head;
struct list_head sibling_node;
- uint32_t flags;
- int sqq;
+ u32 flags_;
+ int seq_;
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ ofnode node_;
+#endif
#ifdef CONFIG_DEVRES
struct list_head devres_head;
#endif
@@ -170,22 +180,67 @@ struct udevice {
/* Returns the operations for a device */
#define device_get_ops(dev) (dev->driver->ops)
+static inline u32 dev_get_flags(const struct udevice *dev)
+{
+ return dev->flags_;
+}
+
+static inline void dev_or_flags(struct udevice *dev, u32 or)
+{
+ dev->flags_ |= or;
+}
+
+static inline void dev_bic_flags(struct udevice *dev, u32 bic)
+{
+ dev->flags_ &= ~bic;
+}
+
+/**
+ * dev_ofnode() - get the DT node reference associated with a udevice
+ *
+ * @dev: device to check
+ * @return reference of the the device's DT node
+ */
+static inline ofnode dev_ofnode(const struct udevice *dev)
+{
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ return dev->node_;
+#else
+ return ofnode_null();
+#endif
+}
+
/* Returns non-zero if the device is active (probed and not removed) */
-#define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED)
+#define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
static inline int dev_of_offset(const struct udevice *dev)
{
- return ofnode_to_offset(dev->node);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ return ofnode_to_offset(dev_ofnode(dev));
+#else
+ return -1;
+#endif
}
-static inline bool dev_has_of_node(struct udevice *dev)
+static inline bool dev_has_ofnode(const struct udevice *dev)
{
- return ofnode_valid(dev->node);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ return ofnode_valid(dev_ofnode(dev));
+#else
+ return false;
+#endif
+}
+
+static inline void dev_set_ofnode(struct udevice *dev, ofnode node)
+{
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ dev->node_ = node;
+#endif
}
static inline int dev_seq(const struct udevice *dev)
{
- return dev->sqq;
+ return dev->seq_;
}
/**
@@ -238,7 +293,7 @@ struct udevice_id {
* platform data to be allocated in the device's ->plat pointer.
* This is typically only useful for device-tree-aware drivers (those with
* an of_match), since drivers which use plat will have the data
- * provided in the U_BOOT_DEVICE() instantiation.
+ * provided in the U_BOOT_DRVINFO() instantiation.
* @per_child_auto: Each device can hold private data owned by
* its parent. If required this will be automatically allocated if this
* value is non-zero.
@@ -280,7 +335,7 @@ struct driver {
ll_entry_declare(struct driver, __name, driver)
/* Get a pointer to a given driver */
-#define DM_GET_DRIVER(__name) \
+#define DM_DRIVER_GET(__name) \
ll_entry_get(struct driver, __name, driver)
/**
@@ -288,7 +343,7 @@ struct driver {
* produce no code but its information will be parsed by tools like
* dtoc
*/
-#define U_BOOT_DRIVER_ALIAS(__name, __alias)
+#define DM_DRIVER_ALIAS(__name, __alias)
/**
* dev_get_plat() - Get the platform data for a device
diff --git a/include/dm/lists.h b/include/dm/lists.h
index 070bc9c..1a86552 100644
--- a/include/dm/lists.h
+++ b/include/dm/lists.h
@@ -35,7 +35,7 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id);
/**
* lists_bind_drivers() - search for and bind all drivers to parent
*
- * This searches the U_BOOT_DEVICE() structures and creates new devices for
+ * This searches the U_BOOT_DRVINFO() structures and creates new devices for
* each one. The devices will have @parent as their parent.
*
* @parent: parent device (root)
diff --git a/include/dm/platdata.h b/include/dm/platdata.h
index d650fb3..3821a56 100644
--- a/include/dm/platdata.h
+++ b/include/dm/platdata.h
@@ -56,46 +56,34 @@ struct driver_rt {
* is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
* available). U-Boot's driver model uses device tree for configuration.
*
- * When of-platdata is in use, U_BOOT_DEVICE() cannot be used outside of the
+ * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the
* dt-plat.c file created by dtoc
*/
-#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C)
-#define U_BOOT_DEVICE(__name) _Static_assert(false, \
- "Cannot use U_BOOT_DEVICE with of-platdata. Please use devicetree instead")
+#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLAT_C)
+#define U_BOOT_DRVINFO(__name) _Static_assert(false, \
+ "Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead")
#else
-#define U_BOOT_DEVICE(__name) \
+#define U_BOOT_DRVINFO(__name) \
ll_entry_declare(struct driver_info, __name, driver_info)
#endif
/* Declare a list of devices. The argument is a driver_info[] array */
-#define U_BOOT_DEVICES(__name) \
+#define U_BOOT_DRVINFOS(__name) \
ll_entry_declare_list(struct driver_info, __name, driver_info)
/**
* Get a pointer to a given device info given its name
*
- * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a
+ * With the declaration U_BOOT_DRVINFO(name), DM_DRVINFO_GET(name) will return a
* pointer to the struct driver_info created by that declaration.
*
* if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
* struct driver_info to find the device pointer itself.
*
- * TODO(sjg@chromium.org): U_BOOT_DEVICE() tells U-Boot to create a device, so
- * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
- * finds the driver_info record, not the device.
- *
* @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
* @return struct driver_info * to the driver that created the device
*/
-#define DM_GET_DEVICE(__name) \
+#define DM_DRVINFO_GET(__name) \
ll_entry_get(struct driver_info, __name, driver_info)
-/**
- * dm_populate_phandle_data() - Populates phandle data in platda
- *
- * This populates phandle data with an U_BOOT_DEVICE entry get by
- * DM_GET_DEVICE. The implementation of this function will be done
- * by dtoc when parsing dtb.
- */
-void dm_populate_phandle_data(void);
#endif
diff --git a/include/dm/platform_data/spi_pl022.h b/include/dm/platform_data/spi_pl022.h
index c5aa321..7f74b3c 100644
--- a/include/dm/platform_data/spi_pl022.h
+++ b/include/dm/platform_data/spi_pl022.h
@@ -3,7 +3,7 @@
* (C) Copyright 2018
* Quentin Schulz, Bootlin, quentin.schulz@bootlin.com
*
- * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use
+ * Structure for use with U_BOOT_DRVINFO for pl022 SPI devices or to use
* in of_to_plat.
*/
diff --git a/include/dm/read.h b/include/dm/read.h
index 0585eb1..fc987f7 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -21,7 +21,7 @@ struct resource;
#if CONFIG_IS_ENABLED(OF_LIVE)
static inline const struct device_node *dev_np(const struct udevice *dev)
{
- return ofnode_to_np(dev->node);
+ return ofnode_to_np(dev_ofnode(dev));
}
#else
static inline const struct device_node *dev_np(const struct udevice *dev)
@@ -30,22 +30,6 @@ static inline const struct device_node *dev_np(const struct udevice *dev)
}
#endif
-/**
- * dev_ofnode() - get the DT node reference associated with a udevice
- *
- * @dev: device to check
- * @return reference of the the device's DT node
- */
-static inline ofnode dev_ofnode(const struct udevice *dev)
-{
- return dev->node;
-}
-
-static inline bool dev_of_valid(const struct udevice *dev)
-{
- return ofnode_valid(dev_ofnode(dev));
-}
-
#ifndef CONFIG_DM_DEV_READ_INLINE
/**
diff --git a/include/dm/simple_bus.h b/include/dm/simple_bus.h
new file mode 100644
index 0000000..4ad4cc4
--- /dev/null
+++ b/include/dm/simple_bus.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef __DM_SIMPLE_BUS_H
+#define __DM_SIMPLE_BUS_H
+
+struct simple_bus_plat {
+ u32 base;
+ u32 size;
+ u32 target;
+};
+
+#endif
diff --git a/include/dm/test.h b/include/dm/test.h
index b2adce7..6ac6672 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -134,14 +134,12 @@ extern struct unit_test_state global_dm_test_state;
* @testdev: Test device
* @force_fail_alloc: Force all memory allocs to fail
* @skip_post_probe: Skip uclass post-probe processing
- * @removed: Used to keep track of a device that was removed
*/
struct dm_test_state {
struct udevice *root;
struct udevice *testdev;
int force_fail_alloc;
int skip_post_probe;
- struct udevice *removed;
};
/* Declare a new driver model test */
@@ -169,6 +167,24 @@ struct sandbox_sdl_plat {
int font_size;
};
+/**
+ * struct dm_test_parent_plat - Used to track state in bus tests
+ *
+ * @count:
+ * @bind_flag: Indicates that the child post-bind method was called
+ * @uclass_bind_flag: Also indicates that the child post-bind method was called
+ */
+struct dm_test_parent_plat {
+ int count;
+ int bind_flag;
+ int uclass_bind_flag;
+};
+
+enum {
+ TEST_FLAG_CHILD_PROBED = 10,
+ TEST_FLAG_CHILD_REMOVED = -7,
+};
+
/* Declare ping methods for the drivers */
int test_ping(struct udevice *dev, int pingval, int *pingret);
int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index 3e052f9..c5a464b 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -12,6 +12,20 @@
#include <dm/ofnode.h>
/**
+ * uclass_set_priv() - Set the private data for a uclass
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * private data when an 'auto' size if provided by the uclass driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @uc Uclass to update
+ * @priv New private-data pointer
+ */
+void uclass_set_priv(struct uclass *uc, void *priv);
+
+/**
* uclass_find_next_free_seq() - Get the next free sequence number
*
* This returns the next free sequence number. This is useful only if
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 91edbfb..b5f066d 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -24,7 +24,7 @@
* There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and
* PMIC IO lines, all made available in a unified way through the uclass.
*
- * @priv: Private data for this uclass
+ * @priv_: Private data for this uclass (do not access outside driver model)
* @uc_drv: The driver for the uclass itself, not to be confused with a
* 'struct driver'
* @dev_head: List of devices in this uclass (devices are attached to their
@@ -32,7 +32,7 @@
* @sibling_node: Next uclass in the linked list of uclasses
*/
struct uclass {
- void *priv;
+ void *priv_;
struct uclass_driver *uc_drv;
struct list_head dev_head;
struct list_head sibling_node;
@@ -112,7 +112,15 @@ struct uclass_driver {
/* Declare a new uclass_driver */
#define UCLASS_DRIVER(__name) \
- ll_entry_declare(struct uclass_driver, __name, uclass)
+ ll_entry_declare(struct uclass_driver, __name, uclass_driver)
+
+/**
+ * uclass_get_priv() - Get the private data for a uclass
+ *
+ * @uc Uclass to check
+ * @return private data, or NULL if none
+ */
+void *uclass_get_priv(const struct uclass *uc);
/**
* uclass_get() - Get a uclass based on an ID, creating it if needed
@@ -256,7 +264,7 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
* uclass_get_device_by_driver() - Get a uclass device for a driver
*
* This searches the devices in the uclass for one that uses the given
- * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is
+ * driver. Use DM_DRIVER_GET(name) for the @drv argument, where 'name' is
* the driver name - as used in U_BOOT_DRIVER(name).
*
* The device is probed to activate it ready for use.