diff options
| author | Tom Rini <[email protected]> | 2021-01-11 13:55:03 -0500 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2021-01-11 13:55:03 -0500 |
| commit | d71be1990218957b9f05dbf13a72859a2abe06d7 (patch) | |
| tree | 99858dc9988f7f7b4c0ab1d8d45738e3abdf38c8 /include/dm | |
| parent | c4fddedc48f336eabc4ce3f74940e6aa372de18c (diff) | |
| parent | bc0b99bd8b19599f670f42401de655fa9b44cd94 (diff) | |
Merge branch 'next'
Signed-off-by: Tom Rini <[email protected]>
Diffstat (limited to 'include/dm')
25 files changed, 408 insertions, 215 deletions
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index c5d7ec0650f..639bbd293d9 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -19,8 +19,8 @@ struct udevice; * device_bind() - Create a device and bind it to a driver * * Called to set up a new device attached to a driver. The device will either - * have platdata, or a device tree node which can be used to create the - * platdata. + * have plat, or a device tree node which can be used to create the + * plat. * * Once bound a device exists but is not yet active until device_probe() is * called. @@ -28,22 +28,18 @@ struct udevice; * @parent: Pointer to device's parent, under which this driver will exist * @drv: Device's driver * @name: Name of device (e.g. device tree node name) - * @platdata: Pointer to data for this device - the structure is device- + * @plat: Pointer to data for this device - the structure is device- * specific but may include the device's I/O address, etc.. This is NULL for * devices which use device tree. - * @of_offset: Offset of device tree node for this device. This is -1 for - * devices which don't use device tree. + * @ofnode: Devicetree node for this device. This is ofnode_null() for + * devices which don't use devicetree or don't have a node. * @devp: if non-NULL, returns a pointer to the bound device * @return 0 if OK, -ve on error */ int device_bind(struct udevice *parent, const struct driver *drv, - const char *name, void *platdata, int of_offset, + const char *name, void *plat, ofnode node, struct udevice **devp); -int device_bind_ofnode(struct udevice *parent, const struct driver *drv, - const char *name, void *platdata, ofnode node, - struct udevice **devp); - /** * device_bind_with_driver_data() - Create a device and bind it to a driver * @@ -76,7 +72,7 @@ int device_bind_with_driver_data(struct udevice *parent, * @parent: Pointer to device's parent * @pre_reloc_only: If true, bind the driver only if its DM_FLAG_PRE_RELOC flag * is set. If false bind the driver always. - * @info: Name and platdata for this device + * @info: Name and plat for this device * @devp: if non-NULL, returns a pointer to the bound device * @return 0 if OK, -ve on error */ @@ -93,7 +89,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, int device_reparent(struct udevice *dev, struct udevice *new_parent); /** - * device_ofdata_to_platdata() - Read platform data for a device + * device_of_to_plat() - Read platform data for a device * * Read platform data for a device (typically from the device tree) so that * the information needed to probe the device is present. @@ -106,7 +102,7 @@ int device_reparent(struct udevice *dev, struct udevice *new_parent); * @dev: Pointer to device to process * @return 0 if OK, -ve on error */ -int device_ofdata_to_platdata(struct udevice *dev); +int device_of_to_plat(struct udevice *dev); /** * device_probe() - Probe a device, activating it @@ -194,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 @@ -208,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 5bef4842470..f5b4cd6876e 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -23,16 +23,16 @@ struct driver_info; /* Driver is active (probed). Cleared when it is removed */ #define DM_FLAG_ACTIVATED (1 << 0) -/* DM is responsible for allocating and freeing platdata */ +/* DM is responsible for allocating and freeing plat */ #define DM_FLAG_ALLOC_PDATA (1 << 1) /* DM should init this device prior to relocation */ #define DM_FLAG_PRE_RELOC (1 << 2) -/* DM is responsible for allocating and freeing parent_platdata */ +/* DM is responsible for allocating and freeing parent_plat */ #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) -/* DM is responsible for allocating and freeing uclass_platdata */ +/* DM is responsible for allocating and freeing uclass_plat */ #define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) /* Allocate driver private data on a DMA boundary */ @@ -64,7 +64,7 @@ struct driver_info; /* DM does not enable/disable the power domains corresponding to this device */ #define DM_FLAG_DEFAULT_PD_CTRL_OFF (1 << 11) -/* Driver platdata has been read. Cleared when the device is removed */ +/* Driver plat has been read. Cleared when the device is removed */ #define DM_FLAG_PLATDATA_VALID (1 << 12) /* @@ -104,36 +104,46 @@ 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 platdata 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 platdata in a function - * implemented by the driver ofdata_to_platdata method (called just before the + * we translate the device tree information into plat in a function + * implemented by the driver of_to_plat method (called just before the * probe method if the device has a device tree node. * - * All three of platdata, priv and uclass_priv can be allocated by the + * All three of plat, priv and uclass_priv can be allocated by the * driver, or you can use the auto_alloc_size members of struct driver and * struct uclass_driver to have driver model do this automatically. * * @driver: The driver used by this device * @name: Name of device, typically the FDT node name - * @platdata: Configuration data for this device - * @parent_platdata: The parent bus's configuration data for this device - * @uclass_platdata: 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_... - * @req_seq: Requested sequence number for this device (-1 = any) - * @seq: Allocated sequence number for this device (-1 = none). This is set up - * when the device is probed and will be unique within the device's uclass. + * @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'). + * (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 @@ -142,22 +152,23 @@ enum { struct udevice { const struct driver *driver; const char *name; - void *platdata; - void *parent_platdata; - void *uclass_platdata; - 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 req_seq; - int seq; + u32 flags_; + int seq_; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + ofnode node_; +#endif #ifdef CONFIG_DEVRES struct list_head devres_head; #endif @@ -169,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 void dev_set_of_offset(struct udevice *dev, int of_offset) +static inline bool dev_has_ofnode(const struct udevice *dev) { - dev->node = offset_to_ofnode(of_offset); +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + return ofnode_valid(dev_ofnode(dev)); +#else + return false; +#endif } -static inline bool dev_has_of_node(struct udevice *dev) +static inline void dev_set_ofnode(struct udevice *dev, ofnode node) { - return ofnode_valid(dev->node); +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + dev->node_ = node; +#endif +} + +static inline int dev_seq(const struct udevice *dev) +{ + return dev->seq_; } /** @@ -208,7 +264,7 @@ struct udevice_id { * * This holds methods for setting up a new device, and also removing it. * The device needs information to set itself up - this is provided either - * by platdata or a device tree node (which we find by looking up + * by plat or a device tree node (which we find by looking up * matching compatible strings with of_match). * * Drivers all belong to a uclass, representing a class of devices of the @@ -224,26 +280,26 @@ struct udevice_id { * @probe: Called to probe a device, i.e. activate it * @remove: Called to remove a device, i.e. de-activate it * @unbind: Called to unbind a device from its driver - * @ofdata_to_platdata: Called before probe to decode device tree data + * @of_to_plat: Called before probe to decode device tree data * @child_post_bind: Called after a new child has been bound * @child_pre_probe: Called before a child device is probed. The device has * memory allocated but it has not yet been probed. * @child_post_remove: Called after a child device is removed. The device * has memory allocated but its device_remove() method has been called. - * @priv_auto_alloc_size: If non-zero this is the size of the private data + * @priv_auto: If non-zero this is the size of the private data * to be allocated in the device's ->priv pointer. If zero, then the driver * is responsible for allocating any data required. - * @platdata_auto_alloc_size: If non-zero this is the size of the - * platform data to be allocated in the device's ->platdata pointer. + * @plat_auto: If non-zero this is the size of the + * 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 platdata will have the data - * provided in the U_BOOT_DEVICE() instantiation. - * @per_child_auto_alloc_size: Each device can hold private data owned by + * an of_match), since drivers which use plat will have the data + * 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. - * @per_child_platdata_auto_alloc_size: A bus likes to store information about + * @per_child_plat_auto: A bus likes to store information about * its children. If non-zero this is the size of this data, to be allocated - * in the child's parent_platdata pointer. + * in the child's parent_plat pointer. * @ops: Driver-specific operations. This is typically a list of function * pointers defined by the driver, to implement driver functions required by * the uclass. @@ -259,14 +315,14 @@ struct driver { int (*probe)(struct udevice *dev); int (*remove)(struct udevice *dev); int (*unbind)(struct udevice *dev); - int (*ofdata_to_platdata)(struct udevice *dev); + int (*of_to_plat)(struct udevice *dev); int (*child_post_bind)(struct udevice *dev); int (*child_pre_probe)(struct udevice *dev); int (*child_post_remove)(struct udevice *dev); - int priv_auto_alloc_size; - int platdata_auto_alloc_size; - int per_child_auto_alloc_size; - int per_child_platdata_auto_alloc_size; + int priv_auto; + int plat_auto; + int per_child_auto; + int per_child_plat_auto; const void *ops; /* driver-specific operations */ uint32_t flags; #if CONFIG_IS_ENABLED(ACPIGEN) @@ -279,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) /** @@ -287,37 +343,37 @@ 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_platdata() - Get the platform data for a device + * dev_get_plat() - Get the platform data for a device * * This checks that dev is not NULL, but no other checks for now * * @dev Device to check * @return platform data, or NULL if none */ -void *dev_get_platdata(const struct udevice *dev); +void *dev_get_plat(const struct udevice *dev); /** - * dev_get_parent_platdata() - Get the parent platform data for a device + * dev_get_parent_plat() - Get the parent platform data for a device * * This checks that dev is not NULL, but no other checks for now * * @dev Device to check * @return parent's platform data, or NULL if none */ -void *dev_get_parent_platdata(const struct udevice *dev); +void *dev_get_parent_plat(const struct udevice *dev); /** - * dev_get_uclass_platdata() - Get the uclass platform data for a device + * dev_get_uclass_plat() - Get the uclass platform data for a device * * This checks that dev is not NULL, but no other checks for now * * @dev Device to check * @return uclass's platform data, or NULL if none */ -void *dev_get_uclass_platdata(const struct udevice *dev); +void *dev_get_uclass_plat(const struct udevice *dev); /** * dev_get_priv() - Get the private data for a device @@ -444,24 +500,16 @@ int device_get_child_count(const struct udevice *parent); /** * device_find_child_by_seq() - Find a child device based on a sequence * - * This searches for a device with the given seq or req_seq. - * - * For seq, if an active device has this sequence it will be returned. - * If there is no such device then this will return -ENODEV. - * - * For req_seq, if a device (whether activated or not) has this req_seq - * value, that device will be returned. This is a strong indication that - * the device will receive that sequence when activated. + * This searches for a device with the given seq. * * @parent: Parent device - * @seq_or_req_seq: Sequence number to find (0=first) - * @find_req_seq: true to find req_seq, false to find seq + * @seq: Sequence number to find (0=first) * @devp: Returns pointer to device (there is only one per for each seq). * Set to NULL if none is found - * @return 0 if OK, -ve on error + * @return 0 if OK, -ENODEV if not found */ -int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp); +int device_find_child_by_seq(const struct udevice *parent, int seq, + struct udevice **devp); /** * device_get_child_by_seq() - Get a child device based on a sequence @@ -627,9 +675,9 @@ int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp); /** - * device_first_child_ofdata_err() - Find the first child and reads its platdata + * device_first_child_ofdata_err() - Find the first child and reads its plat * - * The ofdata_to_platdata() method is called on the child before it is returned, + * The of_to_plat() method is called on the child before it is returned, * but the child is not probed. * * @parent: Parent to check @@ -640,9 +688,9 @@ int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp); /* - * device_next_child_ofdata_err() - Find the next child and read its platdata + * device_next_child_ofdata_err() - Find the next child and read its plat * - * The ofdata_to_platdata() method is called on the child before it is returned, + * The of_to_plat() method is called on the child before it is returned, * but the child is not probed. * * @devp: On entry, points to the previous child; on exit returns the child that @@ -803,19 +851,19 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev) list_for_each_entry(pos, &parent->child_head, sibling_node) /** - * device_foreach_child_ofdata_to_platdata() - iterate through children + * device_foreach_child_of_to_plat() - iterate through children * * This stops when it gets an error, with @pos set to the device that failed to * read ofdata. * This creates a for() loop which works through the available children of * a device in order from start to end. Device ofdata is read by calling - * device_ofdata_to_platdata() on each one. The devices are not probed. + * device_of_to_plat() on each one. The devices are not probed. * * @pos: struct udevice * for the current device * @parent: parent device to scan */ -#define device_foreach_child_ofdata_to_platdata(pos, parent) \ +#define device_foreach_child_of_to_plat(pos, parent) \ for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \ _ret = device_next_child_ofdata_err(&dev)) diff --git a/include/dm/lists.h b/include/dm/lists.h index 810e244d9ef..1a865525461 100644 --- a/include/dm/lists.h +++ b/include/dm/lists.h @@ -16,7 +16,7 @@ * lists_driver_lookup_name() - Return u_boot_driver corresponding to name * * This function returns a pointer to a driver given its name. This is used - * for binding a driver given its name and platdata. + * for binding a driver given its name and plat. * * @name: Name of driver to look up * @return pointer to driver, or NULL if not found @@ -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/ofnode.h b/include/dm/ofnode.h index ced7f6ffb25..5b088650d3b 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -10,6 +10,7 @@ /* TODO([email protected]): Drop fdtdec.h include */ #include <fdtdec.h> #include <dm/of.h> +#include <dm/of_access.h> #include <log.h> /* Enable checks to protect against invalid calls */ @@ -218,6 +219,18 @@ static inline ofnode ofnode_null(void) return node; } +static inline ofnode ofnode_root(void) +{ + ofnode node; + + if (of_live_active()) + node.np = gd_of_root(); + else + node.of_offset = 0; + + return node; +} + /** * ofnode_read_u32() - Read a 32-bit integer from a property * @@ -365,6 +378,49 @@ bool ofnode_read_bool(ofnode node, const char *propname); */ ofnode ofnode_find_subnode(ofnode node, const char *subnode_name); +#if CONFIG_IS_ENABLED(DM_INLINE_OFNODE) +static inline bool ofnode_is_enabled(ofnode node) +{ + if (ofnode_is_np(node)) { + return of_device_is_available(ofnode_to_np(node)); + } else { + return fdtdec_get_is_enabled(gd->fdt_blob, + ofnode_to_offset(node)); + } +} + +static inline ofnode ofnode_first_subnode(ofnode node) +{ + assert(ofnode_valid(node)); + if (ofnode_is_np(node)) + return np_to_ofnode(node.np->child); + + return offset_to_ofnode( + fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node))); +} + +static inline ofnode ofnode_next_subnode(ofnode node) +{ + assert(ofnode_valid(node)); + if (ofnode_is_np(node)) + return np_to_ofnode(node.np->sibling); + + return offset_to_ofnode( + fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node))); +} +#else +/** + * ofnode_is_enabled() - Checks whether a node is enabled. + * This looks for a 'status' property. If this exists, then returns true if + * the status is 'okay' and false otherwise. If there is no status property, + * it returns true on the assumption that anything mentioned should be enabled + * by default. + * + * @node: node to examine + * @return false (not enabled) or true (enabled) + */ +bool ofnode_is_enabled(ofnode node); + /** * ofnode_first_subnode() - find the first subnode of a parent node * @@ -382,6 +438,7 @@ ofnode ofnode_first_subnode(ofnode node); * has no more siblings) */ ofnode ofnode_next_subnode(ofnode node); +#endif /* DM_INLINE_OFNODE */ /** * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode) diff --git a/include/dm/pci.h b/include/dm/pci.h index 10f9fd9e378..bddacbf5997 100644 --- a/include/dm/pci.h +++ b/include/dm/pci.h @@ -30,7 +30,7 @@ int pci_get_devfn(struct udevice *dev); * * This returns an int to avoid a dependency on pci.h * - * @reg: reg value from dt-platdata.c array (first member). This is not a + * @reg: reg value from dt-plat.c array (first member). This is not a * pointer type, since the caller may use fdt32_t or fdt64_t depending on * the address sizes. * @return device/function for that device (pci_dev_t format) diff --git a/include/dm/platdata.h b/include/dm/platdata.h index 216efa8ef77..3821a56f2ca 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -20,15 +20,15 @@ * available). U-Boot's driver model uses device tree for configuration. * * @name: Driver name - * @platdata: Driver-specific platform data - * @platdata_size: Size of platform data structure + * @plat: Driver-specific platform data + * @plat_size: Size of platform data structure * @parent_idx: Index of the parent driver_info structure */ struct driver_info { const char *name; - const void *platdata; + const void *plat; #if CONFIG_IS_ENABLED(OF_PLATDATA) - unsigned short platdata_size; + unsigned short plat_size; short parent_idx; #endif }; @@ -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 - * dt-platdata.c file created by dtoc + * 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([email protected]): 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/fsl_espi.h b/include/dm/platform_data/fsl_espi.h index 812933f51cd..de2307f7fb5 100644 --- a/include/dm/platform_data/fsl_espi.h +++ b/include/dm/platform_data/fsl_espi.h @@ -6,7 +6,7 @@ #ifndef __fsl_espi_h #define __fsl_espi_h -struct fsl_espi_platdata { +struct fsl_espi_plat { uint flags; uint speed_hz; uint num_chipselect; diff --git a/include/dm/platform_data/lpc32xx_hsuart.h b/include/dm/platform_data/lpc32xx_hsuart.h index 9bfd62833cd..6f41e0e734a 100644 --- a/include/dm/platform_data/lpc32xx_hsuart.h +++ b/include/dm/platform_data/lpc32xx_hsuart.h @@ -7,11 +7,11 @@ #define _LPC32XX_HSUART_PLAT_H /** - * struct lpc32xx_hsuart_platdata - NXP LPC32xx HSUART platform data + * struct lpc32xx_hsuart_plat - NXP LPC32xx HSUART platform data * * @base: Base register address */ -struct lpc32xx_hsuart_platdata { +struct lpc32xx_hsuart_plat { unsigned long base; }; diff --git a/include/dm/platform_data/pxa_mmc_gen.h b/include/dm/platform_data/pxa_mmc_gen.h index 9875bab2cf4..d15c1551f46 100644 --- a/include/dm/platform_data/pxa_mmc_gen.h +++ b/include/dm/platform_data/pxa_mmc_gen.h @@ -9,7 +9,7 @@ #include <mmc.h> /* - * struct pxa_mmc_platdata - information about a PXA MMC controller + * struct pxa_mmc_plat - information about a PXA MMC controller * * @base: MMC controller base register address */ diff --git a/include/dm/platform_data/serial_bcm283x_mu.h b/include/dm/platform_data/serial_bcm283x_mu.h index 37f5174dbf2..6c77272e804 100644 --- a/include/dm/platform_data/serial_bcm283x_mu.h +++ b/include/dm/platform_data/serial_bcm283x_mu.h @@ -14,7 +14,7 @@ * * @base: Register base address */ -struct bcm283x_mu_serial_platdata { +struct bcm283x_mu_serial_plat { unsigned long base; unsigned int clock; bool skip_init; diff --git a/include/dm/platform_data/serial_coldfire.h b/include/dm/platform_data/serial_coldfire.h index ba916fece3d..5e265e9087d 100644 --- a/include/dm/platform_data/serial_coldfire.h +++ b/include/dm/platform_data/serial_coldfire.h @@ -7,13 +7,13 @@ #define __serial_coldfire_h /* - * struct coldfire_serial_platdata - information about a coldfire port + * struct coldfire_serial_plat - information about a coldfire port * * @base: Uart port base register address * @port: Uart port index, for cpu with pinmux for uart / gpio * baudrtatre: Uart port baudrate */ -struct coldfire_serial_platdata { +struct coldfire_serial_plat { unsigned long base; int port; int baudrate; diff --git a/include/dm/platform_data/serial_mxc.h b/include/dm/platform_data/serial_mxc.h index 86cd3bcf628..cc59eeb1dd1 100644 --- a/include/dm/platform_data/serial_mxc.h +++ b/include/dm/platform_data/serial_mxc.h @@ -7,7 +7,7 @@ #define __serial_mxc_h /* Information about a serial port */ -struct mxc_serial_platdata { +struct mxc_serial_plat { struct mxc_uart *reg; /* address of registers in physical memory */ bool use_dte; }; diff --git a/include/dm/platform_data/serial_pl01x.h b/include/dm/platform_data/serial_pl01x.h index 77d96c49f03..e3d4e308a14 100644 --- a/include/dm/platform_data/serial_pl01x.h +++ b/include/dm/platform_data/serial_pl01x.h @@ -20,7 +20,7 @@ enum pl01x_type { * @skip_init: Don't attempt to change port configuration (also means @clock * is ignored) */ -struct pl01x_serial_platdata { +struct pl01x_serial_plat { unsigned long base; enum pl01x_type type; unsigned int clock; diff --git a/include/dm/platform_data/serial_pxa.h b/include/dm/platform_data/serial_pxa.h index b78bdb64094..0d7dc4c462d 100644 --- a/include/dm/platform_data/serial_pxa.h +++ b/include/dm/platform_data/serial_pxa.h @@ -40,13 +40,13 @@ #endif /* - * struct pxa_serial_platdata - information about a PXA port + * struct pxa_serial_plat - information about a PXA port * * @base: Uart port base register address * @port: Uart port index, for cpu with pinmux for uart / gpio * baudrtatre: Uart port baudrate */ -struct pxa_serial_platdata { +struct pxa_serial_plat { struct pxa_uart_regs *base; int port; int baudrate; diff --git a/include/dm/platform_data/serial_sh.h b/include/dm/platform_data/serial_sh.h index 711435d8f6e..69cd012fc5a 100644 --- a/include/dm/platform_data/serial_sh.h +++ b/include/dm/platform_data/serial_sh.h @@ -27,7 +27,7 @@ enum sh_serial_type { * @clk_mode: Clock mode, set internal (INT) or external (EXT) * @type: Type of SCIF */ -struct sh_serial_platdata { +struct sh_serial_plat { unsigned long base; unsigned int clk; enum sh_clk_mode clk_mode; diff --git a/include/dm/platform_data/spi_coldfire.h b/include/dm/platform_data/spi_coldfire.h index 8ad8eaedfde..da514bad0d3 100644 --- a/include/dm/platform_data/spi_coldfire.h +++ b/include/dm/platform_data/spi_coldfire.h @@ -10,14 +10,14 @@ #define MAX_CTAR_FIELDS 8 /* - * struct coldfire_spi_platdata - information about a coldfire spi module + * struct coldfire_spi_plat - information about a coldfire spi module * * @regs_addr: base address for module registers * @speed_hz: default SCK frequency * @mode: default SPI mode * @num_cs: number of DSPI chipselect signals */ -struct coldfire_spi_platdata { +struct coldfire_spi_plat { fdt_addr_t regs_addr; uint speed_hz; uint mode; diff --git a/include/dm/platform_data/spi_davinci.h b/include/dm/platform_data/spi_davinci.h index fbc62c262ab..42a467e40b2 100644 --- a/include/dm/platform_data/spi_davinci.h +++ b/include/dm/platform_data/spi_davinci.h @@ -7,7 +7,7 @@ #ifndef __spi_davinci_h #define __spi_davinci_h -struct davinci_spi_platdata { +struct davinci_spi_plat { struct davinci_spi_regs *regs; u8 num_cs; /* total no. of CS available */ }; diff --git a/include/dm/platform_data/spi_pl022.h b/include/dm/platform_data/spi_pl022.h index 63a58ee4535..7f74b3cbc5c 100644 --- a/include/dm/platform_data/spi_pl022.h +++ b/include/dm/platform_data/spi_pl022.h @@ -3,8 +3,8 @@ * (C) Copyright 2018 * Quentin Schulz, Bootlin, [email protected] * - * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use - * in ofdata_to_platdata. + * Structure for use with U_BOOT_DRVINFO for pl022 SPI devices or to use + * in of_to_plat. */ #ifndef __spi_pl022_h diff --git a/include/dm/read.h b/include/dm/read.h index 0585eb12281..fc987f77598 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/root.h b/include/dm/root.h index c8d629ba9bf..89afbee6196 100644 --- a/include/dm/root.h +++ b/include/dm/root.h @@ -31,15 +31,15 @@ struct global_data; void dm_fixup_for_gd_move(struct global_data *new_gd); /** - * dm_scan_platdata() - Scan all platform data and bind drivers + * dm_scan_plat() - Scan all platform data and bind drivers * - * This scans all available platdata and creates drivers for each + * This scans all available plat and creates drivers for each * * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC * flag. If false bind all drivers. * @return 0 if OK, -ve on error */ -int dm_scan_platdata(bool pre_reloc_only); +int dm_scan_plat(bool pre_reloc_only); /** * dm_scan_fdt() - Scan the device tree and bind drivers @@ -47,26 +47,24 @@ int dm_scan_platdata(bool pre_reloc_only); * This scans the device tree and creates a driver for each node. Only * the top-level subnodes are examined. * - * @blob: Pointer to device tree blob * @pre_reloc_only: If true, bind only nodes with special devicetree properties, * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. * @return 0 if OK, -ve on error */ -int dm_scan_fdt(const void *blob, bool pre_reloc_only); +int dm_scan_fdt(bool pre_reloc_only); /** - * dm_extended_scan_fdt() - Scan the device tree and bind drivers + * dm_extended_scan() - Scan the device tree and bind drivers * * This calls dm_scna_dft() which scans the device tree and creates a driver * for each node. the top-level subnodes are examined and also all sub-nodes * of "clocks" node. * - * @blob: Pointer to device tree blob * @pre_reloc_only: If true, bind only nodes with special devicetree properties, * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. * @return 0 if OK, -ve on error */ -int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only); +int dm_extended_scan(bool pre_reloc_only); /** * dm_scan_other() - Scan for other devices diff --git a/include/dm/simple_bus.h b/include/dm/simple_bus.h new file mode 100644 index 00000000000..4ad4cc4051d --- /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 b2adce730ad..6ac6672cd6f 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-id.h b/include/dm/uclass-id.h index e952a9967c2..ae4425d7a57 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -16,6 +16,7 @@ enum uclass_id { UCLASS_DEMO, UCLASS_TEST, UCLASS_TEST_FDT, + UCLASS_TEST_FDT_MANUAL, UCLASS_TEST_BUS, UCLASS_TEST_PROBE, UCLASS_TEST_DUMMY, diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index 6e3f15c2b08..c5a464be7c4 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -12,17 +12,34 @@ #include <dm/ofnode.h> /** - * uclass_find_next_free_req_seq() - Get the next free req_seq number + * uclass_set_priv() - Set the private data for a uclass * - * This returns the next free req_seq number. This is useful only if - * OF_CONTROL is not used. The next free req_seq number is simply the - * maximum req_seq of the uclass + 1. - * This allows assiging req_seq number in the binding order. + * This is normally handled by driver model, which automatically allocates + * private data when an 'auto' size if provided by the uclass driver. * - * @id: Id number of the uclass - * @return The next free req_seq number + * 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 */ -int uclass_find_next_free_req_seq(enum uclass_id id); +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 + * OF_CONTROL is not used. The next free sequence number is simply the + * maximum sequence number used by all devices in the uclass + 1. The value + * returned is always greater than the largest alias, if DM_SEQ_ALIAS is enabled + * and the uclass has the DM_UC_FLAG_SEQ_ALIAS flag. + * + * This allows assigning the sequence number in the binding order. + * + * @uc: uclass to check + * @return The next free sequence number + */ +int uclass_find_next_free_seq(struct uclass *uc); /** * uclass_get_device_tail() - handle the end of a get_device call @@ -103,25 +120,17 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name, /** * uclass_find_device_by_seq() - Find uclass device based on ID and sequence * - * This searches for a device with the given seq or req_seq. - * - * For seq, if an active device has this sequence it will be returned. - * If there is no such device then this will return -ENODEV. - * - * For req_seq, if a device (whether activated or not) has this req_seq - * value, that device will be returned. This is a strong indication that - * the device will receive that sequence when activated. + * This searches for a device with the given seq. * * The device is NOT probed, it is merely returned. * * @id: ID to look up - * @seq_or_req_seq: Sequence number to find (0=first) - * @find_req_seq: true to find req_seq, false to find seq + * @seq: Sequence number to find (0=first) * @devp: Returns pointer to device (there is only one per for each seq) - * @return 0 if OK, -ve on error + * @return 0 if OK, -ENODEV if not found */ -int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp); +int uclass_find_device_by_seq(enum uclass_id id, int seq, + struct udevice **devp); /** * uclass_find_device_by_of_offset() - Find a uclass device by device tree node diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 71883043046..b5f066dbf48 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; @@ -44,6 +44,9 @@ struct udevice; /* Members of this uclass sequence themselves with aliases */ #define DM_UC_FLAG_SEQ_ALIAS (1 << 0) +/* Members of this uclass without aliases don't get a sequence number */ +#define DM_UC_FLAG_NO_AUTO_SEQ (1 << 1) + /* Same as DM_FLAG_ALLOC_PRIV_DMA */ #define DM_UC_FLAG_ALLOC_PRIV_DMA (1 << 5) @@ -65,21 +68,21 @@ struct udevice; * @child_post_probe: Called after a child in this uclass is probed * @init: Called to set up the uclass * @destroy: Called to destroy the uclass - * @priv_auto_alloc_size: If non-zero this is the size of the private data + * @priv_auto: If non-zero this is the size of the private data * to be allocated in the uclass's ->priv pointer. If zero, then the uclass * driver is responsible for allocating any data required. - * @per_device_auto_alloc_size: Each device can hold private data owned + * @per_device_auto: Each device can hold private data owned * by the uclass. If required this will be automatically allocated if this * value is non-zero. - * @per_device_platdata_auto_alloc_size: Each device can hold platform data - * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, + * @per_device_plat_auto: Each device can hold platform data + * owned by the uclass as 'dev->uclass_plat'. If the value is non-zero, * then this will be automatically allocated. - * @per_child_auto_alloc_size: Each child device (of a parent in this + * @per_child_auto: Each child device (of a parent in this * uclass) can hold parent data for the device/uclass. This value is only * used as a fallback if this member is 0 in the driver. - * @per_child_platdata_auto_alloc_size: A bus likes to store information about + * @per_child_plat_auto: A bus likes to store information about * its children. If non-zero this is the size of this data, to be allocated - * in the child device's parent_platdata pointer. This value is only used as + * in the child device's parent_plat pointer. This value is only used as * a fallback if this member is 0 in the driver. * @ops: Uclass operations, providing the consistent interface to devices * within the uclass. @@ -98,18 +101,26 @@ struct uclass_driver { int (*child_post_probe)(struct udevice *dev); int (*init)(struct uclass *class); int (*destroy)(struct uclass *class); - int priv_auto_alloc_size; - int per_device_auto_alloc_size; - int per_device_platdata_auto_alloc_size; - int per_child_auto_alloc_size; - int per_child_platdata_auto_alloc_size; + int priv_auto; + int per_device_auto; + int per_device_plat_auto; + int per_child_auto; + int per_child_plat_auto; const void *ops; uint32_t flags; }; /* 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 @@ -253,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. @@ -366,21 +377,6 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data, struct udevice **devp); /** - * uclass_resolve_seq() - Resolve a device's sequence number - * - * On entry dev->seq is -1, and dev->req_seq may be -1 (to allocate a - * sequence number automatically, or >= 0 to select a particular number. - * If the requested sequence number is in use, then this device will - * be allocated another one. - * - * Note that the device's seq value is not changed by this function. - * - * @dev: Device for which to allocate sequence number - * @return sequence number allocated, or -ve on error - */ -int uclass_resolve_seq(struct udevice *dev); - -/** * uclass_id_foreach_dev() - Helper function to iteration through devices * * This creates a for() loop which works through the available devices in |
