From 12559f5bab3e43b603dccfa6c354ffd7da03249c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:27 -0700 Subject: dm: core: Add functions to set priv/plat This should not normally be needed in drivers, but add accessors for the few cases that exist. Signed-off-by: Simon Glass --- drivers/core/device.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index d1a08ce783..f2d750c8de 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -959,6 +959,36 @@ int device_set_name(struct udevice *dev, const char *name) return 0; } +void dev_set_priv(struct udevice *dev, void *priv) +{ + dev->priv = priv; +} + +void dev_set_parent_priv(struct udevice *dev, void *parent_priv) +{ + dev->parent_priv = parent_priv; +} + +void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv) +{ + dev->uclass_priv = uclass_priv; +} + +void dev_set_plat(struct udevice *dev, void *plat) +{ + dev->plat = plat; +} + +void dev_set_parent_plat(struct udevice *dev, void *parent_plat) +{ + dev->parent_plat = parent_plat; +} + +void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat) +{ + dev->uclass_plat = uclass_plat; +} + #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) bool device_is_compatible(const struct udevice *dev, const char *compat) { -- cgit v1.2.3 From 89ba6d553572fe9177ae472170b8373e49f97953 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:29 -0700 Subject: dm: core: Use access methods for dev/uclass private data Use these functions in the core code as much as possible. With this, there are only two places where each priv/plat pointer is accessed, one for read and one for write. Signed-off-by: Simon Glass --- drivers/core/device-remove.c | 8 +++--- drivers/core/device.c | 61 ++++++++++++++++++++++++-------------------- drivers/core/uclass.c | 13 ++++++---- 3 files changed, 45 insertions(+), 37 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 8c12169771..e15ab051be 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -94,11 +94,11 @@ int device_unbind(struct udevice *dev) } if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { free(dev_get_uclass_plat(dev)); - dev->uclass_plat = NULL; + dev_set_uclass_plat(dev, NULL); } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev_get_parent_plat(dev)); - dev->parent_plat = NULL; + dev_set_parent_plat(dev, NULL); } ret = uclass_unbind_device(dev); if (ret) @@ -131,7 +131,7 @@ void device_free(struct udevice *dev) size = dev->uclass->uc_drv->per_device_auto; if (size) { free(dev_get_uclass_priv(dev)); - dev->uclass_priv = NULL; + dev_set_uclass_priv(dev, NULL); } if (dev->parent) { size = dev->parent->driver->per_child_auto; @@ -141,7 +141,7 @@ void device_free(struct udevice *dev) } if (size) { free(dev_get_parent_priv(dev)); - dev->parent_priv = NULL; + dev_set_parent_priv(dev, NULL); } } dev->flags &= ~DM_FLAG_PLATDATA_VALID; diff --git a/drivers/core/device.c b/drivers/core/device.c index f2d750c8de..261c3b2793 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -42,6 +42,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, struct uclass *uc; int size, ret = 0; bool auto_seq = true; + void *ptr; if (devp) *devp = NULL; @@ -64,7 +65,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, #ifdef CONFIG_DEVRES INIT_LIST_HEAD(&dev->devres_head); #endif - dev->plat = plat; + dev_set_plat(dev, plat); dev->driver_data = driver_data; dev->name = name; dev->node = node; @@ -102,25 +103,26 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, } if (alloc) { dev->flags |= DM_FLAG_ALLOC_PDATA; - dev->plat = calloc(1, drv->plat_auto); - if (!dev->plat) { + ptr = calloc(1, drv->plat_auto); + if (!ptr) { ret = -ENOMEM; goto fail_alloc1; } - if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) { - memcpy(dev->plat, plat, of_plat_size); - } + if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) + memcpy(ptr, plat, of_plat_size); + dev_set_plat(dev, ptr); } } size = uc->uc_drv->per_device_plat_auto; if (size) { dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; - dev->uclass_plat = calloc(1, size); - if (!dev->uclass_plat) { + ptr = calloc(1, size); + if (!ptr) { ret = -ENOMEM; goto fail_alloc2; } + dev_set_uclass_plat(dev, ptr); } if (parent) { @@ -130,11 +132,12 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, } if (size) { dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA; - dev->parent_plat = calloc(1, size); - if (!dev->parent_plat) { + ptr = calloc(1, size); + if (!ptr) { ret = -ENOMEM; goto fail_alloc3; } + dev_set_parent_plat(dev, ptr); } /* put dev into parent's successor list */ list_add_tail(&dev->sibling_node, &parent->child_head); @@ -191,19 +194,19 @@ fail_uclass_bind: if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) { list_del(&dev->sibling_node); if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { - free(dev->parent_plat); - dev->parent_plat = NULL; + free(dev_get_parent_plat(dev)); + dev_set_parent_plat(dev, NULL); } } fail_alloc3: if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { - free(dev->uclass_plat); - dev->uclass_plat = NULL; + free(dev_get_uclass_plat(dev)); + dev_set_uclass_plat(dev, NULL); } fail_alloc2: if (dev->flags & DM_FLAG_ALLOC_PDATA) { - free(dev->plat); - dev->plat = NULL; + free(dev_get_plat(dev)); + dev_set_plat(dev, NULL); } fail_alloc1: devres_release_all(dev); @@ -324,6 +327,7 @@ int device_of_to_plat(struct udevice *dev) { const struct driver *drv; int size = 0; + void *ptr; int ret; if (!dev) @@ -352,36 +356,37 @@ int device_of_to_plat(struct udevice *dev) assert(drv); /* Allocate private data if requested and not reentered */ - if (drv->priv_auto && !dev->priv) { - dev->priv = alloc_priv(drv->priv_auto, drv->flags); - if (!dev->priv) { + if (drv->priv_auto && !dev_get_priv(dev)) { + ptr = alloc_priv(drv->priv_auto, drv->flags); + if (!ptr) { ret = -ENOMEM; goto fail; } + dev_set_priv(dev, ptr); } /* Allocate private data if requested and not reentered */ size = dev->uclass->uc_drv->per_device_auto; - if (size && !dev->uclass_priv) { - dev->uclass_priv = alloc_priv(size, - dev->uclass->uc_drv->flags); - if (!dev->uclass_priv) { + if (size && !dev_get_uclass_priv(dev)) { + ptr = alloc_priv(size, dev->uclass->uc_drv->flags); + if (!ptr) { ret = -ENOMEM; goto fail; } + dev_set_uclass_priv(dev, ptr); } /* Allocate parent data for this child */ if (dev->parent) { size = dev->parent->driver->per_child_auto; - if (!size) { + if (!size) size = dev->parent->uclass->uc_drv->per_child_auto; - } - if (size && !dev->parent_priv) { - dev->parent_priv = alloc_priv(size, drv->flags); - if (!dev->parent_priv) { + if (size && !dev_get_parent_priv(dev)) { + ptr = alloc_priv(size, drv->flags); + if (!ptr) { ret = -ENOMEM; goto fail; } + dev_set_parent_priv(dev, ptr); } } diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 5e24927b34..e845f60472 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -72,11 +72,14 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) if (!uc) return -ENOMEM; if (uc_drv->priv_auto) { - uc->priv = calloc(1, uc_drv->priv_auto); - if (!uc->priv) { + void *ptr; + + ptr = calloc(1, uc_drv->priv_auto); + if (!ptr) { ret = -ENOMEM; goto fail_mem; } + uclass_set_priv(uc, ptr); } uc->uc_drv = uc_drv; INIT_LIST_HEAD(&uc->sibling_node); @@ -94,8 +97,8 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) return 0; fail: if (uc_drv->priv_auto) { - free(uc->priv); - uc->priv = NULL; + free(uclass_get_priv(uc)); + uclass_set_priv(uc, NULL); } list_del(&uc->sibling_node); fail_mem: @@ -132,7 +135,7 @@ int uclass_destroy(struct uclass *uc) uc_drv->destroy(uc); list_del(&uc->sibling_node); if (uc_drv->priv_auto) - free(uc->priv); + free(uclass_get_priv(uc)); free(uc); return 0; -- cgit v1.2.3 From fb8c9fb3fa422314d53516ba30f280be1e7216f9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:30 -0700 Subject: dm: core: Rename the priv/plat members These are supposed to be private to driver model, not accessed by any code outside. Add a trailing underscore to indicate this. Signed-off-by: Simon Glass --- drivers/core/device.c | 24 ++++++++++++------------ drivers/core/uclass.c | 4 ++-- include/dm/device.h | 29 +++++++++++++++++------------ include/dm/uclass.h | 4 ++-- 4 files changed, 33 insertions(+), 28 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index 261c3b2793..a4c8310f81 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -514,7 +514,7 @@ void *dev_get_plat(const struct udevice *dev) return NULL; } - return dev->plat; + return dev->plat_; } void *dev_get_parent_plat(const struct udevice *dev) @@ -524,7 +524,7 @@ void *dev_get_parent_plat(const struct udevice *dev) return NULL; } - return dev->parent_plat; + return dev->parent_plat_; } void *dev_get_uclass_plat(const struct udevice *dev) @@ -534,7 +534,7 @@ void *dev_get_uclass_plat(const struct udevice *dev) return NULL; } - return dev->uclass_plat; + return dev->uclass_plat_; } void *dev_get_priv(const struct udevice *dev) @@ -544,7 +544,7 @@ void *dev_get_priv(const struct udevice *dev) return NULL; } - return dev->priv; + return dev->priv_; } void *dev_get_uclass_priv(const struct udevice *dev) @@ -554,7 +554,7 @@ void *dev_get_uclass_priv(const struct udevice *dev) return NULL; } - return dev->uclass_priv; + return dev->uclass_priv_; } void *dev_get_parent_priv(const struct udevice *dev) @@ -564,7 +564,7 @@ void *dev_get_parent_priv(const struct udevice *dev) return NULL; } - return dev->parent_priv; + return dev->parent_priv_; } static int device_get_device_tail(struct udevice *dev, int ret, @@ -966,32 +966,32 @@ int device_set_name(struct udevice *dev, const char *name) void dev_set_priv(struct udevice *dev, void *priv) { - dev->priv = priv; + dev->priv_ = priv; } void dev_set_parent_priv(struct udevice *dev, void *parent_priv) { - dev->parent_priv = parent_priv; + dev->parent_priv_ = parent_priv; } void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv) { - dev->uclass_priv = uclass_priv; + dev->uclass_priv_ = uclass_priv; } void dev_set_plat(struct udevice *dev, void *plat) { - dev->plat = plat; + dev->plat_ = plat; } void dev_set_parent_plat(struct udevice *dev, void *parent_plat) { - dev->parent_plat = parent_plat; + dev->parent_plat_ = parent_plat; } void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat) { - dev->uclass_plat = uclass_plat; + dev->uclass_plat_ = uclass_plat; } #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index e845f60472..f60bc9a850 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -165,12 +165,12 @@ const char *uclass_get_name(enum uclass_id id) void *uclass_get_priv(const struct uclass *uc) { - return uc->priv; + return uc->priv_; } void uclass_set_priv(struct uclass *uc, void *priv) { - uc->priv = priv; + uc->priv_ = priv; } enum uclass_id uclass_get_by_name(const char *name) diff --git a/include/dm/device.h b/include/dm/device.h index 30fc98dc34..daebd6eb68 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -116,17 +116,22 @@ 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 + * @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) * @node: Reference to device tree node for this device * @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 @@ -144,16 +149,16 @@ enum { struct udevice { const struct driver *driver; const char *name; - void *plat; - void *parent_plat; - void *uclass_plat; + void *plat_; + void *parent_plat_; + void *uclass_plat_; ofnode node; 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; diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 20d4b9e683..f06339e4d6 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; -- cgit v1.2.3 From 82021e31a71ae51bea1226e58727dd3163a26895 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:08 -0700 Subject: dm: core: Split out alloc code into a new function Add a new function to handle the allocation of private/platform data for a device. This will make it easier to skip this feature when using the new of-platdata. Signed-off-by: Simon Glass --- drivers/core/device.c | 89 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 37 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index a4c8310f81..72169632c8 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -323,34 +323,17 @@ static void *alloc_priv(int size, uint flags) return priv; } -int device_of_to_plat(struct udevice *dev) +/** + * device_alloc_priv() - Allocate priv/plat data required by the device + * + * @dev: Device to process + * @return 0 if OK, -ENOMEM if out of memory + */ +static int device_alloc_priv(struct udevice *dev) { const struct driver *drv; - int size = 0; void *ptr; - int ret; - - if (!dev) - return -EINVAL; - - if (dev->flags & DM_FLAG_PLATDATA_VALID) - return 0; - - /* Ensure all parents have ofdata */ - if (dev->parent) { - ret = device_of_to_plat(dev->parent); - if (ret) - goto fail; - - /* - * The device might have already been probed during - * the call to device_probe() on its parent device - * (e.g. PCI bridge devices). Test the flags again - * so that we don't mess up the device. - */ - if (dev->flags & DM_FLAG_PLATDATA_VALID) - return 0; - } + int size; drv = dev->driver; assert(drv); @@ -358,20 +341,17 @@ int device_of_to_plat(struct udevice *dev) /* Allocate private data if requested and not reentered */ if (drv->priv_auto && !dev_get_priv(dev)) { ptr = alloc_priv(drv->priv_auto, drv->flags); - if (!ptr) { - ret = -ENOMEM; - goto fail; - } + if (!ptr) + return -ENOMEM; dev_set_priv(dev, ptr); } + /* Allocate private data if requested and not reentered */ size = dev->uclass->uc_drv->per_device_auto; if (size && !dev_get_uclass_priv(dev)) { ptr = alloc_priv(size, dev->uclass->uc_drv->flags); - if (!ptr) { - ret = -ENOMEM; - goto fail; - } + if (!ptr) + return -ENOMEM; dev_set_uclass_priv(dev, ptr); } @@ -382,14 +362,49 @@ int device_of_to_plat(struct udevice *dev) size = dev->parent->uclass->uc_drv->per_child_auto; if (size && !dev_get_parent_priv(dev)) { ptr = alloc_priv(size, drv->flags); - if (!ptr) { - ret = -ENOMEM; - goto fail; - } + if (!ptr) + return -ENOMEM; dev_set_parent_priv(dev, ptr); } } + return 0; +} + +int device_of_to_plat(struct udevice *dev) +{ + const struct driver *drv; + int ret; + + if (!dev) + return -EINVAL; + + if (dev->flags & DM_FLAG_PLATDATA_VALID) + return 0; + + /* Ensure all parents have ofdata */ + if (dev->parent) { + ret = device_of_to_plat(dev->parent); + if (ret) + goto fail; + + /* + * The device might have already been probed during + * the call to device_probe() on its parent device + * (e.g. PCI bridge devices). Test the flags again + * so that we don't mess up the device. + */ + if (dev->flags & DM_FLAG_PLATDATA_VALID) + return 0; + } + + ret = device_alloc_priv(dev); + if (ret) + goto fail; + + drv = dev->driver; + assert(drv); + if (drv->of_to_plat && (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) { ret = drv->of_to_plat(dev); -- cgit v1.2.3 From 2462139fdd4f1f5eb50427e287a802b9c9eef097 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:09 -0700 Subject: dm: core: Rename sqq to seq_ Now that the sequence-numbering migration is complete, rename this member back to seq_, adding an underscore to indicate it is internal to driver model. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- drivers/core/device.c | 8 ++++---- drivers/core/dump.c | 2 +- drivers/core/uclass.c | 8 ++++---- drivers/pci/pci-uclass.c | 2 +- include/dm/device.h | 9 +++++---- test/dm/core.c | 6 +++--- 6 files changed, 18 insertions(+), 17 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index 72169632c8..f4ae7786ee 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -73,7 +73,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, dev->driver = drv; dev->uclass = uc; - dev->sqq = -1; + dev->seq_ = -1; if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) && (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) { /* @@ -83,13 +83,13 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { if (uc->uc_drv->name && ofnode_valid(node)) { - if (!dev_read_alias_seq(dev, &dev->sqq)) + if (!dev_read_alias_seq(dev, &dev->seq_)) auto_seq = false; } } } if (auto_seq && !(uc->uc_drv->flags & DM_UC_FLAG_NO_AUTO_SEQ)) - dev->sqq = uclass_find_next_free_seq(uc); + dev->seq_ = uclass_find_next_free_seq(uc); if (drv->plat_auto) { bool alloc = !plat; @@ -658,7 +658,7 @@ int device_find_child_by_seq(const struct udevice *parent, int seq, *devp = NULL; list_for_each_entry(dev, &parent->child_head, sibling_node) { - if (dev->sqq == seq) { + if (dev->seq_ == seq) { *devp = dev; return 0; } diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 7784ec02de..1d4628abc7 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -69,7 +69,7 @@ static void dm_display_line(struct udevice *dev, int index) printf("%-3i %c %s @ %08lx", index, dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', dev->name, (ulong)map_to_sysmem(dev)); - if (dev->sqq != -1) + if (dev->seq_ != -1) printf(", seq %d", dev_seq(dev)); puts("\n"); } diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index f60bc9a850..e773e34833 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -297,8 +297,8 @@ int uclass_find_next_free_seq(struct uclass *uc) /* Avoid conflict with existing devices */ list_for_each_entry(dev, &uc->dev_head, uclass_node) { - if (dev->sqq > max) - max = dev->sqq; + if (dev->seq_ > max) + max = dev->seq_; } /* * At this point, max will be -1 if there are no existing aliases or @@ -323,8 +323,8 @@ int uclass_find_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) return ret; uclass_foreach_dev(dev, uc) { - log_debug(" - %d '%s'\n", dev->sqq, dev->name); - if (dev->sqq == seq) { + log_debug(" - %d '%s'\n", dev->seq_, dev->name); + if (dev->seq_ == seq) { *devp = dev; log_debug(" - found\n"); return 0; diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 37a233878d..1f6c51f1e8 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1019,7 +1019,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) ret = uclass_get(UCLASS_PCI, &uc); if (ret) return ret; - bus->sqq = uclass_find_next_free_seq(uc); + bus->seq_ = uclass_find_next_free_seq(uc); } /* For bridges, use the top-level PCI controller */ diff --git a/include/dm/device.h b/include/dm/device.h index daebd6eb68..a063bbaa17 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -136,11 +136,12 @@ enum { * @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 + * @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) * @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 @@ -163,7 +164,7 @@ struct udevice { struct list_head child_head; struct list_head sibling_node; uint32_t flags; - int sqq; + int seq_; #ifdef CONFIG_DEVRES struct list_head devres_head; #endif @@ -190,7 +191,7 @@ static inline bool dev_has_of_node(struct udevice *dev) static inline int dev_seq(const struct udevice *dev) { - return dev->sqq; + return dev->seq_; } /** diff --git a/test/dm/core.c b/test/dm/core.c index cf66e27db4..b274b04388 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -1075,10 +1075,10 @@ static int dm_test_all_have_seq(struct unit_test_state *uts) list_for_each_entry(uc, &gd->uclass_root, sibling_node) { list_for_each_entry(dev, &uc->dev_head, uclass_node) { - if (dev->sqq == -1) + if (dev->seq_ == -1) printf("Device '%s' has no seq (%d)\n", - dev->name, dev->sqq); - ut_assert(dev->sqq != -1); + dev->name, dev->seq_); + ut_assert(dev->seq_ != -1); } } -- cgit v1.2.3 From 73466df3e214f6ff1966e69df351f273eec1a029 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:10 -0700 Subject: dm: core: Access device flags through functions At present flags are stored as part of the device. In preparation for storing them separately, change the access to go through inline functions. Signed-off-by: Simon Glass --- cmd/remoteproc.c | 2 +- drivers/clk/clk.c | 2 +- drivers/core/device-remove.c | 18 +++++++++--------- drivers/core/device.c | 32 ++++++++++++++++---------------- drivers/core/devres.c | 4 ++-- drivers/core/dump.c | 4 ++-- drivers/mtd/nand/raw/octeontx_nand.c | 2 +- drivers/remoteproc/rproc-uclass.c | 2 +- drivers/serial/serial-uclass.c | 2 +- include/dm/device.h | 15 +++++++++++++++ include/virtio.h | 2 +- test/dm/bus.c | 10 +++++----- test/dm/core.c | 14 +++++++------- test/dm/cpu.c | 2 +- test/dm/test-fdt.c | 20 ++++++++++---------- test/dm/virtio.c | 2 +- 16 files changed, 74 insertions(+), 59 deletions(-) (limited to 'drivers/core/device.c') diff --git a/cmd/remoteproc.c b/cmd/remoteproc.c index 5f9ba92560..b3ddcebe31 100644 --- a/cmd/remoteproc.c +++ b/cmd/remoteproc.c @@ -35,7 +35,7 @@ static int print_remoteproc_list(void) uc_pdata = dev_get_uclass_plat(dev); /* Do not print if rproc is not probed */ - if (!(dev->flags & DM_FLAG_ACTIVATED)) + if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)) continue; switch (uc_pdata->mem_type) { diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index eb75132f27..1efb7fe9f3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -67,7 +67,7 @@ const char *clk_hw_get_name(const struct clk *hw) bool clk_dev_binded(struct clk *clk) { - if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND)) + if (clk->dev && (dev_get_flags(clk->dev) & DM_FLAG_BOUND)) return true; return false; diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index e15ab051be..44eaa67d56 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -69,10 +69,10 @@ int device_unbind(struct udevice *dev) if (!dev) return log_msg_ret("dev", -EINVAL); - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return log_msg_ret("active", -EINVAL); - if (!(dev->flags & DM_FLAG_BOUND)) + if (!(dev_get_flags(dev) & DM_FLAG_BOUND)) return log_msg_ret("not-bound", -EINVAL); drv = dev->driver; @@ -88,15 +88,15 @@ int device_unbind(struct udevice *dev) if (ret) return log_msg_ret("child unbind", ret); - if (dev->flags & DM_FLAG_ALLOC_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { free(dev_get_plat(dev)); dev_set_plat(dev, NULL); } - if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) { free(dev_get_uclass_plat(dev)); dev_set_uclass_plat(dev, NULL); } - if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev_get_parent_plat(dev)); dev_set_parent_plat(dev, NULL); } @@ -109,7 +109,7 @@ int device_unbind(struct udevice *dev) devres_release_all(dev); - if (dev->flags & DM_FLAG_NAME_ALLOCED) + if (dev_get_flags(dev) & DM_FLAG_NAME_ALLOCED) free((char *)dev->name); free(dev); @@ -144,7 +144,7 @@ void device_free(struct udevice *dev) dev_set_parent_priv(dev, NULL); } } - dev->flags &= ~DM_FLAG_PLATDATA_VALID; + dev_bic_flags(dev, DM_FLAG_PLATDATA_VALID); devres_release_probe(dev); } @@ -166,7 +166,7 @@ int device_remove(struct udevice *dev, uint flags) if (!dev) return -EINVAL; - if (!(dev->flags & DM_FLAG_ACTIVATED)) + if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)) return 0; drv = dev->driver; @@ -207,7 +207,7 @@ int device_remove(struct udevice *dev, uint flags) if (flags_remove(flags, drv->flags)) { device_free(dev); - dev->flags &= ~DM_FLAG_ACTIVATED; + dev_bic_flags(dev, DM_FLAG_ACTIVATED); } return ret; diff --git a/drivers/core/device.c b/drivers/core/device.c index f4ae7786ee..ba50d46eff 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -96,13 +96,13 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (CONFIG_IS_ENABLED(OF_PLATDATA)) { if (of_plat_size) { - dev->flags |= DM_FLAG_OF_PLATDATA; + dev_or_flags(dev, DM_FLAG_OF_PLATDATA); if (of_plat_size < drv->plat_auto) alloc = true; } } if (alloc) { - dev->flags |= DM_FLAG_ALLOC_PDATA; + dev_or_flags(dev, DM_FLAG_ALLOC_PDATA); ptr = calloc(1, drv->plat_auto); if (!ptr) { ret = -ENOMEM; @@ -116,7 +116,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, size = uc->uc_drv->per_device_plat_auto; if (size) { - dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; + dev_or_flags(dev, DM_FLAG_ALLOC_UCLASS_PDATA); ptr = calloc(1, size); if (!ptr) { ret = -ENOMEM; @@ -131,7 +131,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, size = parent->uclass->uc_drv->per_child_plat_auto; } if (size) { - dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA; + dev_or_flags(dev, DM_FLAG_ALLOC_PARENT_PDATA); ptr = calloc(1, size); if (!ptr) { ret = -ENOMEM; @@ -169,7 +169,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (devp) *devp = dev; - dev->flags |= DM_FLAG_BOUND; + dev_or_flags(dev, DM_FLAG_BOUND); return 0; @@ -193,18 +193,18 @@ fail_bind: fail_uclass_bind: if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) { list_del(&dev->sibling_node); - if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev_get_parent_plat(dev)); dev_set_parent_plat(dev, NULL); } } fail_alloc3: - if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) { free(dev_get_uclass_plat(dev)); dev_set_uclass_plat(dev, NULL); } fail_alloc2: - if (dev->flags & DM_FLAG_ALLOC_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { free(dev_get_plat(dev)); dev_set_plat(dev, NULL); } @@ -379,7 +379,7 @@ int device_of_to_plat(struct udevice *dev) if (!dev) return -EINVAL; - if (dev->flags & DM_FLAG_PLATDATA_VALID) + if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID) return 0; /* Ensure all parents have ofdata */ @@ -394,7 +394,7 @@ int device_of_to_plat(struct udevice *dev) * (e.g. PCI bridge devices). Test the flags again * so that we don't mess up the device. */ - if (dev->flags & DM_FLAG_PLATDATA_VALID) + if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID) return 0; } @@ -412,7 +412,7 @@ int device_of_to_plat(struct udevice *dev) goto fail; } - dev->flags |= DM_FLAG_PLATDATA_VALID; + dev_or_flags(dev, DM_FLAG_PLATDATA_VALID); return 0; fail: @@ -429,7 +429,7 @@ int device_probe(struct udevice *dev) if (!dev) return -EINVAL; - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return 0; drv = dev->driver; @@ -451,11 +451,11 @@ int device_probe(struct udevice *dev) * (e.g. PCI bridge devices). Test the flags again * so that we don't mess up the device. */ - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return 0; } - dev->flags |= DM_FLAG_ACTIVATED; + dev_or_flags(dev, DM_FLAG_ACTIVATED); /* * Process pinctrl for everything except the root device, and @@ -515,7 +515,7 @@ fail_uclass: __func__, dev->name); } fail: - dev->flags &= ~DM_FLAG_ACTIVATED; + dev_bic_flags(dev, DM_FLAG_ACTIVATED); device_free(dev); @@ -965,7 +965,7 @@ bool device_is_last_sibling(const struct udevice *dev) void device_set_name_alloced(struct udevice *dev) { - dev->flags |= DM_FLAG_NAME_ALLOCED; + dev_or_flags(dev, DM_FLAG_NAME_ALLOCED); } int device_set_name(struct udevice *dev, const char *name) diff --git a/drivers/core/devres.c b/drivers/core/devres.c index 522b07d613..313ddc7089 100644 --- a/drivers/core/devres.c +++ b/drivers/core/devres.c @@ -107,9 +107,9 @@ void devres_add(struct udevice *dev, void *res) devres_log(dev, dr, "ADD"); assert_noisy(list_empty(&dr->entry)); - if (dev->flags & DM_FLAG_PLATDATA_VALID) + if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID) dr->phase = DEVRES_PHASE_PROBE; - else if (dev->flags & DM_FLAG_BOUND) + else if (dev_get_flags(dev) & DM_FLAG_BOUND) dr->phase = DEVRES_PHASE_OFDATA; else dr->phase = DEVRES_PHASE_BIND; diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 1d4628abc7..f8afea30a9 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -14,7 +14,7 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) { int i, is_last; struct udevice *child; - u32 flags = dev->flags; + u32 flags = dev_get_flags(dev); /* print the first 20 characters to not break the tree-format. */ printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " : @@ -67,7 +67,7 @@ void dm_dump_all(void) static void dm_display_line(struct udevice *dev, int index) { printf("%-3i %c %s @ %08lx", index, - dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', + dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ', dev->name, (ulong)map_to_sysmem(dev)); if (dev->seq_ != -1) printf(", seq %d", dev_seq(dev)); diff --git a/drivers/mtd/nand/raw/octeontx_nand.c b/drivers/mtd/nand/raw/octeontx_nand.c index b1ed4d910a..96a5fe6592 100644 --- a/drivers/mtd/nand/raw/octeontx_nand.c +++ b/drivers/mtd/nand/raw/octeontx_nand.c @@ -2187,7 +2187,7 @@ int octeontx_pci_nand_deferred_probe(void) debug("%s: Performing deferred probing\n", __func__); list_for_each_entry(pdev, &octeontx_pci_nand_deferred_devices, list) { debug("%s: Probing %s\n", __func__, pdev->dev->name); - pdev->dev->flags &= ~DM_FLAG_ACTIVATED; + dev_get_flags(pdev->dev) &= ~DM_FLAG_ACTIVATED; rc = device_probe(pdev->dev); if (rc && rc != -ENODEV) { printf("%s: Error %d with deferred probe of %s\n", diff --git a/drivers/remoteproc/rproc-uclass.c b/drivers/remoteproc/rproc-uclass.c index 773b8119f4..c2d6a4e0c1 100644 --- a/drivers/remoteproc/rproc-uclass.c +++ b/drivers/remoteproc/rproc-uclass.c @@ -247,7 +247,7 @@ static int _rproc_dev_is_probed(struct udevice *dev, struct dm_rproc_uclass_pdata *uc_pdata, const void *data) { - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return 0; return -EAGAIN; diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index b6457242de..58a6541d8c 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -123,7 +123,7 @@ static void serial_find_console_or_panic(void) #ifdef CONFIG_SERIAL_SEARCH_ALL if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) || !uclass_get_device(UCLASS_SERIAL, INDEX, &dev)) { - if (dev->flags & DM_FLAG_ACTIVATED) { + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) { gd->cur_serial_dev = dev; return; } diff --git a/include/dm/device.h b/include/dm/device.h index a063bbaa17..4ec423e961 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -179,6 +179,21 @@ struct udevice { /* Returns non-zero if the device is active (probed and not removed) */ #define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED) +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; +} + static inline int dev_of_offset(const struct udevice *dev) { return ofnode_to_offset(dev->node); diff --git a/include/virtio.h b/include/virtio.h index 10a9c073ba..a42bdad6b8 100644 --- a/include/virtio.h +++ b/include/virtio.h @@ -492,7 +492,7 @@ static inline void __virtio_clear_bit(struct udevice *udev, unsigned int fbit) */ static inline bool virtio_has_feature(struct udevice *vdev, unsigned int fbit) { - if (!(vdev->flags & DM_FLAG_BOUND)) + if (!(dev_get_flags(vdev) & DM_FLAG_BOUND)) WARN_ON(true); return __virtio_test_bit(vdev->parent, fbit); diff --git a/test/dm/bus.c b/test/dm/bus.c index 785ccfc25d..e768eab695 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -55,16 +55,16 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts) ut_assertok(device_get_child(bus, 0, &dev)); ut_asserteq(-ENODEV, device_get_child(bus, 4, &dev)); ut_assertok(device_get_child_by_seq(bus, 5, &dev)); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); ut_asserteq_str("c-test@5", dev->name); /* Device with sequence number 0 should be accessible */ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, &dev)); ut_assertok(device_find_child_by_seq(bus, 0, &dev)); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev)); ut_assertok(device_get_child_by_seq(bus, 0, &dev)); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev)); /* There is no device with sequence number 2 */ @@ -96,10 +96,10 @@ static int dm_test_bus_children_of_offset(struct unit_test_state *uts) ut_assert(node > 0); ut_assertok(device_find_child_by_of_offset(bus, node, &dev)); ut_assertnonnull(dev); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); ut_assertok(device_get_child_by_of_offset(bus, node, &dev)); ut_assertnonnull(dev); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); return 0; } diff --git a/test/dm/core.c b/test/dm/core.c index b274b04388..565896ed50 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -131,7 +131,7 @@ static int dm_test_autobind(struct unit_test_state *uts) /* No devices should be probed */ list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node) - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); /* Our test driver should have been bound 3 times */ ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3); @@ -212,7 +212,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts) ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]); /* The root device should not be activated until needed */ - ut_assert(dms->root->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED); /* * We should be able to find the three test devices, and they should @@ -222,17 +222,17 @@ static int dm_test_autoprobe(struct unit_test_state *uts) for (i = 0; i < 3; i++) { ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED), + ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED), "Driver %d/%s already activated", i, dev->name); /* This should activate it */ ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); /* Activating a device should activate the root device */ if (!i) - ut_assert(dms->root->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED); } /* @@ -460,10 +460,10 @@ static int dm_test_remove(struct unit_test_state *uts) for (i = 0; i < 3; i++) { ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - ut_assertf(dev->flags & DM_FLAG_ACTIVATED, + ut_assertf(dev_get_flags(dev) & DM_FLAG_ACTIVATED, "Driver %d/%s not activated", i, dev->name); ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); - ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED), + ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED), "Driver %d/%s should have deactivated", i, dev->name); ut_assert(!dev_get_priv(dev)); diff --git a/test/dm/cpu.c b/test/dm/cpu.c index 28869c1d6f..ed12cafee2 100644 --- a/test/dm/cpu.c +++ b/test/dm/cpu.c @@ -25,7 +25,7 @@ static int dm_test_cpu(struct unit_test_state *uts) for (uclass_find_first_device(UCLASS_CPU, &dev); dev; uclass_find_next_device(&dev)) - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev)); ut_asserteq_ptr(cpu_get_current_dev(), dev); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 633256821c..711bf20a9c 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -1031,8 +1031,8 @@ static int dm_test_child_ofdata(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); count = 0; device_foreach_child_of_to_plat(dev, bus) { - ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); count++; } ut_asserteq(3, count); @@ -1050,8 +1050,8 @@ static int dm_test_first_child_probe(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); count = 0; device_foreach_child_probe(dev, bus) { - ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); count++; } ut_asserteq(3, count); @@ -1067,19 +1067,19 @@ static int dm_test_ofdata_order(struct unit_test_state *uts) ut_assertok(uclass_find_first_device(UCLASS_I2C, &bus)); ut_assertnonnull(bus); - ut_assert(!(bus->flags & DM_FLAG_PLATDATA_VALID)); + ut_assert(!(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID)); ut_assertok(device_find_first_child(bus, &dev)); ut_assertnonnull(dev); - ut_assert(!(dev->flags & DM_FLAG_PLATDATA_VALID)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)); /* read the child's ofdata which should cause the parent's to be read */ ut_assertok(device_of_to_plat(dev)); - ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); - ut_assert(bus->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); + ut_assert(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); - ut_assert(!(bus->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(bus) & DM_FLAG_ACTIVATED)); return 0; } diff --git a/test/dm/virtio.c b/test/dm/virtio.c index 2e876c36e4..ad355981cf 100644 --- a/test/dm/virtio.c +++ b/test/dm/virtio.c @@ -122,7 +122,7 @@ static int dm_test_virtio_remove(struct unit_test_state *uts) ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK)); /* check the device can be successfully removed */ - dev->flags |= DM_FLAG_ACTIVATED; + dev_or_flags(dev, DM_FLAG_ACTIVATED); ut_assertok(device_remove(bus, DM_REMOVE_ACTIVE_ALL)); return 0; -- cgit v1.2.3 From c23405f8176c8d32d36ad992eb203ec87c4f5507 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:12 -0700 Subject: dm: core: Rename dev_has_of_node() to dev_has_ofnode() We use 'ofnode' rather than 'of_node' in U-Boot. Rename this function to fit. Signed-off-by: Simon Glass --- drivers/core/device.c | 2 +- drivers/mmc/octeontx_hsmmc.c | 2 +- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- include/dm/device.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index ba50d46eff..8c7ce220f8 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -406,7 +406,7 @@ int device_of_to_plat(struct udevice *dev) assert(drv); if (drv->of_to_plat && - (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) { + (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_ofnode(dev))) { ret = drv->of_to_plat(dev); if (ret) goto fail; diff --git a/drivers/mmc/octeontx_hsmmc.c b/drivers/mmc/octeontx_hsmmc.c index 57d107aac3..f3da6af909 100644 --- a/drivers/mmc/octeontx_hsmmc.c +++ b/drivers/mmc/octeontx_hsmmc.c @@ -3752,7 +3752,7 @@ static int octeontx_mmc_host_probe(struct udevice *dev) host->dev = dev; debug("%s(%s): Base address: %p\n", __func__, dev->name, host->base_addr); - if (!dev_has_of_node(dev)) { + if (!dev_has_ofnode(dev)) { pr_err("%s: No device tree information found\n", __func__); return -1; } diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 4e474cbff7..4653e86ba4 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -305,7 +305,7 @@ int pinctrl_select_state(struct udevice *dev, const char *statename) * Some device which is logical like mmc.blk, do not have * a valid ofnode. */ - if (!dev_has_of_node(dev)) + if (!dev_has_ofnode(dev)) return 0; /* * Try full-implemented pinctrl first. diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 17db5eb060..ae6b1450d3 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -517,7 +517,7 @@ static ofnode usb_get_ofnode(struct udevice *hub, int port) ofnode node; u32 reg; - if (!dev_has_of_node(hub)) + if (!dev_has_ofnode(hub)) return ofnode_null(); /* diff --git a/include/dm/device.h b/include/dm/device.h index a0c1752cdd..b15a14ec33 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -200,7 +200,7 @@ static inline int dev_of_offset(const struct udevice *dev) return ofnode_to_offset(dev->node); } -static inline bool dev_has_of_node(struct udevice *dev) +static inline bool dev_has_ofnode(struct udevice *dev) { return ofnode_valid(dev->node); } -- cgit v1.2.3 From 7d14ee443ca674314e0fe5c3e25f48e52a8fd5ee Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:13 -0700 Subject: dm: core: Use dev_has_ofnode() instead of dev_of_valid() We have two functions which do the same thing. Standardise on dev_has_ofnode() since there is no such thing as an 'invalid' ofnode in normal operation: it is either null or missing. Also move the functions into one place. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- drivers/clk/clk-uclass.c | 2 +- drivers/core/device.c | 2 +- drivers/gpio/sandbox.c | 2 +- drivers/i2c/designware_i2c_pci.c | 4 ++-- drivers/i2c/i2c-uclass.c | 2 +- drivers/mmc/pci_mmc.c | 2 +- drivers/pci/pci-uclass.c | 6 +++--- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/spi/spi-uclass.c | 2 +- drivers/sysreset/sysreset_sandbox.c | 2 +- drivers/timer/timer-uclass.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- include/dm/device.h | 13 ++++++++++++- include/dm/read.h | 16 ---------------- test/dm/pci.c | 6 +++--- 15 files changed, 30 insertions(+), 35 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index ac954a34d2..5cfd00ce77 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -345,7 +345,7 @@ int clk_set_defaults(struct udevice *dev, int stage) { int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; /* If this not in SPL and pre-reloc state, don't take any action. */ diff --git a/drivers/core/device.c b/drivers/core/device.c index 8c7ce220f8..bd4ecc9e24 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -485,7 +485,7 @@ int device_probe(struct udevice *dev) } /* Only handle devices that have a valid ofnode */ - if (dev_of_valid(dev)) { + if (dev_has_ofnode(dev)) { /* * Process 'assigned-{clocks/clock-parents/clock-rates}' * properties diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 489271b560..f8fa4baa2c 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -294,7 +294,7 @@ static int gpio_sandbox_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) /* Tell the uclass how many GPIOs we have */ uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT; diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c index 18eef625f0..ec0cdf6220 100644 --- a/drivers/i2c/designware_i2c_pci.c +++ b/drivers/i2c/designware_i2c_pci.c @@ -92,7 +92,7 @@ static int designware_i2c_pci_bind(struct udevice *dev) { char name[20]; - if (dev_of_valid(dev)) + if (dev_has_ofnode(dev)) return 0; sprintf(name, "i2c_designware#%u", dev_seq(dev)); @@ -152,7 +152,7 @@ static int dw_i2c_acpi_fill_ssdt(const struct udevice *dev, int ret; /* If no device-tree node, ignore this since we assume it isn't used */ - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; ret = acpi_device_path(dev, path, sizeof(path)); diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index 456cf3b85f..be56785217 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -678,7 +678,7 @@ static int i2c_child_post_bind(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) struct dm_i2c_chip *plat = dev_get_parent_plat(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; return i2c_chip_of_to_plat(dev, plat); #else diff --git a/drivers/mmc/pci_mmc.c b/drivers/mmc/pci_mmc.c index fc09ad99e5..c71c495d58 100644 --- a/drivers/mmc/pci_mmc.c +++ b/drivers/mmc/pci_mmc.c @@ -75,7 +75,7 @@ static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev, struct acpi_dp *dp; int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; ret = gpio_get_acpi(&priv->cd_gpio, &gpio); diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 1f6c51f1e8..4cdd06b125 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -540,7 +540,7 @@ int pci_auto_config_devices(struct udevice *bus) int ret; debug("%s: device %s\n", __func__, dev->name); - if (dev_of_valid(dev) && + if (dev_has_ofnode(dev) && dev_read_bool(dev, "pci,no-autoconfig")) continue; ret = dm_pciauto_config_device(dev); @@ -1036,7 +1036,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) hose->bus = bus; hose->first_busno = dev_seq(bus); hose->last_busno = dev_seq(bus); - if (dev_of_valid(bus)) { + if (dev_has_ofnode(bus)) { hose->skip_auto_config_until_reloc = dev_read_bool(bus, "u-boot,skip-auto-config-until-reloc"); @@ -1091,7 +1091,7 @@ static int pci_uclass_child_post_bind(struct udevice *dev) { struct pci_child_plat *pplat; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; pplat = dev_get_parent_plat(dev); diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 4653e86ba4..7919e54e8d 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -112,7 +112,7 @@ static int pinconfig_post_bind(struct udevice *dev) ofnode node; int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; dev_for_each_subnode(node, dev) { diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index a392a93aa1..ba325cf4e0 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -160,7 +160,7 @@ static int spi_child_post_bind(struct udevice *dev) { struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; return spi_slave_of_to_plat(dev, plat); diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c index 7026a48c4b..8eca7d8bfd 100644 --- a/drivers/sysreset/sysreset_sandbox.c +++ b/drivers/sysreset/sysreset_sandbox.c @@ -50,7 +50,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) * (see the U_BOOT_DEVICE() declaration below) should not do anything. * If we are that device, return an error. */ - if (state->fdt_fname && !dev_of_valid(dev)) + if (state->fdt_fname && !dev_has_ofnode(dev)) return -ENODEV; switch (type) { diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index 8e63c17e9f..da1a72f025 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -54,7 +54,7 @@ static int timer_pre_probe(struct udevice *dev) ulong ret; /* It is possible that a timer device has a null ofnode */ - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; err = clk_get_by_index(dev, 0, &timer_clk); diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index ae6b1450d3..e3b616c326 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -773,7 +773,7 @@ static int usb_child_post_bind(struct udevice *dev) struct usb_dev_plat *plat = dev_get_parent_plat(dev); int val; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; /* We only support matching a few things */ diff --git a/include/dm/device.h b/include/dm/device.h index b15a14ec33..4a1224bcc2 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -192,6 +192,17 @@ 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) +{ + return dev->node; +} + /* Returns non-zero if the device is active (probed and not removed) */ #define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED) @@ -200,7 +211,7 @@ static inline int dev_of_offset(const struct udevice *dev) return ofnode_to_offset(dev->node); } -static inline bool dev_has_ofnode(struct udevice *dev) +static inline bool dev_has_ofnode(const struct udevice *dev) { return ofnode_valid(dev->node); } diff --git a/include/dm/read.h b/include/dm/read.h index 0585eb1228..d5cdd87911 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -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/test/dm/pci.c b/test/dm/pci.c index 76490befdf..fa2e4a8559 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -120,13 +120,13 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts) ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(dev_of_valid(swap)); + ut_assertok(dev_has_ofnode(swap)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(dev_of_valid(swap)); + ut_assertok(dev_has_ofnode(swap)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x10, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(!dev_of_valid(swap)); + ut_assertok(!dev_has_ofnode(swap)); return 0; } -- cgit v1.2.3 From f10643cf8a4ca006d1ad194e930cd292fd869d17 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:14 -0700 Subject: dm: core: Access device ofnode through functions At present ofnode is present in the device even if it is never used. With of-platdata this field is not used, so can be removed. In preparation for this, change the access to go through inline functions. Signed-off-by: Simon Glass --- arch/arm/mach-stm32mp/pwr_regulator.c | 2 +- board/synopsys/hsdk/clk-lib.c | 2 +- drivers/ata/mtk_ahci.c | 3 ++- drivers/clk/meson/axg.c | 2 +- drivers/clk/meson/g12a.c | 2 +- drivers/clk/meson/gxbb.c | 2 +- drivers/core/device.c | 2 +- drivers/core/root.c | 2 +- drivers/gpio/mpc8xxx_gpio.c | 4 ++-- drivers/gpio/octeon_gpio.c | 2 +- drivers/misc/swap_case.c | 2 +- drivers/mmc/octeontx_hsmmc.c | 23 +++++++++++++---------- drivers/mtd/nand/raw/octeontx_nand.c | 2 +- drivers/mtd/nand/spi/core.c | 2 +- drivers/net/fm/eth.c | 4 ++-- drivers/net/fsl_enetc.c | 8 ++++---- drivers/net/fsl_enetc_mdio.c | 2 +- drivers/net/mdio-ipq4019.c | 4 ++-- drivers/net/mdio_mux_i2creg.c | 2 +- drivers/net/mvmdio.c | 4 ++-- drivers/net/octeontx/smi.c | 2 +- drivers/net/tsec.c | 3 ++- drivers/phy/phy-ti-am654.c | 2 +- drivers/power/domain/meson-ee-pwrc.c | 4 ++-- drivers/power/domain/meson-gx-pwrc-vpu.c | 4 ++-- drivers/power/regulator/pbias_regulator.c | 3 ++- drivers/pwm/pwm-meson.c | 9 ++++++--- drivers/reset/reset-socfpga.c | 2 +- drivers/spi/fsl_dspi.c | 6 ++++-- drivers/tee/optee/core.c | 2 +- drivers/usb/cdns3/core.c | 4 ++-- drivers/usb/dwc3/core.c | 2 +- drivers/usb/dwc3/dwc3-generic.c | 6 +++--- drivers/usb/dwc3/dwc3-meson-g12a.c | 2 +- drivers/usb/dwc3/dwc3-meson-gxl.c | 2 +- drivers/usb/gadget/dwc2_udc_otg.c | 4 ++-- drivers/usb/host/dwc3-octeon-glue.c | 2 +- drivers/usb/host/dwc3-sti-glue.c | 5 +++-- drivers/usb/host/ehci-mx6.c | 2 +- drivers/usb/host/xhci-dwc3.c | 2 +- drivers/usb/mtu3/mtu3_core.c | 2 +- drivers/usb/mtu3/mtu3_plat.c | 4 ++-- drivers/usb/musb-new/ti-musb.c | 2 +- drivers/video/nexell_display.c | 2 +- drivers/video/rockchip/rk_mipi.c | 2 +- include/dm/device.h | 23 +++++++++++++++++++++-- include/dm/read.h | 2 +- include/linux/mtd/mtd.h | 4 ++-- net/mdio-mux-uclass.c | 2 +- net/mdio-uclass.c | 8 ++++---- 50 files changed, 113 insertions(+), 82 deletions(-) (limited to 'drivers/core/device.c') diff --git a/arch/arm/mach-stm32mp/pwr_regulator.c b/arch/arm/mach-stm32mp/pwr_regulator.c index af6ea43964..766ed95f1a 100644 --- a/arch/arm/mach-stm32mp/pwr_regulator.c +++ b/arch/arm/mach-stm32mp/pwr_regulator.c @@ -81,7 +81,7 @@ static int stm32mp_pwr_bind(struct udevice *dev) { int children; - children = pmic_bind_children(dev, dev->node, pwr_children_info); + children = pmic_bind_children(dev, dev_ofnode(dev), pwr_children_info); if (!children) dev_dbg(dev, "no child found\n"); diff --git a/board/synopsys/hsdk/clk-lib.c b/board/synopsys/hsdk/clk-lib.c index 1c74bfb93a..bd43179fc7 100644 --- a/board/synopsys/hsdk/clk-lib.c +++ b/board/synopsys/hsdk/clk-lib.c @@ -23,8 +23,8 @@ int soc_clk_ctl(const char *name, ulong *rate, enum clk_ctl_ops ctl) /* Dummy fmeas device, just to be able to use standard clk_* api */ struct udevice fmeas = { .name = "clk-fmeas", - .node = ofnode_path("/clk-fmeas"), }; + dev_set_ofnode(&fmeas, ofnode_path("/clk-fmeas")); ret = clk_get_by_name(&fmeas, name, &clk); if (ret) { diff --git a/drivers/ata/mtk_ahci.c b/drivers/ata/mtk_ahci.c index cd28e0cae3..46b7677783 100644 --- a/drivers/ata/mtk_ahci.c +++ b/drivers/ata/mtk_ahci.c @@ -68,7 +68,8 @@ static int mtk_ahci_parse_property(struct ahci_uc_priv *hpriv, SYS_CFG_SATA_MSK, SYS_CFG_SATA_EN); } - ofnode_read_u32(dev->node, "ports-implemented", &hpriv->port_map); + ofnode_read_u32(dev_ofnode(dev), "ports-implemented", + &hpriv->port_map); return 0; } diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c index 82068578ff..d6da59d269 100644 --- a/drivers/clk/meson/axg.c +++ b/drivers/clk/meson/axg.c @@ -289,7 +289,7 @@ static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); - priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c index 01b22abc34..5058db1a47 100644 --- a/drivers/clk/meson/g12a.c +++ b/drivers/clk/meson/g12a.c @@ -979,7 +979,7 @@ static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); - priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c index 2a20541dcb..e379540dee 100644 --- a/drivers/clk/meson/gxbb.c +++ b/drivers/clk/meson/gxbb.c @@ -885,7 +885,7 @@ static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); - priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); diff --git a/drivers/core/device.c b/drivers/core/device.c index bd4ecc9e24..6a9bee093d 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -68,7 +68,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, dev_set_plat(dev, plat); dev->driver_data = driver_data; dev->name = name; - dev->node = node; + dev_set_ofnode(dev, node); dev->parent = parent; dev->driver = drv; dev->uclass = uc; diff --git a/drivers/core/root.c b/drivers/core/root.c index 9ef242979b..fe7359433f 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -148,7 +148,7 @@ int dm_init(bool of_live) if (ret) return ret; if (CONFIG_IS_ENABLED(OF_CONTROL)) - DM_ROOT_NON_CONST->node = ofnode_root(); + dev_set_ofnode(DM_ROOT_NON_CONST, ofnode_root()); ret = device_probe(DM_ROOT_NON_CONST); if (ret) return ret; diff --git a/drivers/gpio/mpc8xxx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c index 2bc1a0d571..a964347fa3 100644 --- a/drivers/gpio/mpc8xxx_gpio.c +++ b/drivers/gpio/mpc8xxx_gpio.c @@ -191,7 +191,7 @@ static int mpc8xxx_gpio_of_to_plat(struct udevice *dev) u32 i; u32 reg[4]; - if (ofnode_read_bool(dev->node, "little-endian")) + if (ofnode_read_bool(dev_ofnode(dev), "little-endian")) data->little_endian = true; if (data->little_endian) @@ -257,7 +257,7 @@ static int mpc8xxx_gpio_probe(struct udevice *dev) if (!str) return -ENOMEM; - if (ofnode_device_is_compatible(dev->node, "fsl,qoriq-gpio")) { + if (ofnode_device_is_compatible(dev_ofnode(dev), "fsl,qoriq-gpio")) { unsigned long gpibe = data->addr + sizeof(struct ccsr_gpio) - sizeof(u32); diff --git a/drivers/gpio/octeon_gpio.c b/drivers/gpio/octeon_gpio.c index 958516d8f8..42eae79d8c 100644 --- a/drivers/gpio/octeon_gpio.c +++ b/drivers/gpio/octeon_gpio.c @@ -190,7 +190,7 @@ static int octeon_gpio_probe(struct udevice *dev) GPIO_CONST_GPIOS_MASK; } else { priv->base = dev_remap_addr(dev); - uc_priv->gpio_count = ofnode_read_u32_default(dev->node, + uc_priv->gpio_count = ofnode_read_u32_default(dev_ofnode(dev), "nr-gpios", 32); } diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c index abea0e7613..3cbc8f37ec 100644 --- a/drivers/misc/swap_case.c +++ b/drivers/misc/swap_case.c @@ -54,7 +54,7 @@ struct swap_case_priv { static int sandbox_swap_case_use_ea(const struct udevice *dev) { - return !!ofnode_get_property(dev->node, "use-ea", NULL); + return !!ofnode_get_property(dev_ofnode(dev), "use-ea", NULL); } /* Please keep these macros in sync with ea_regs below */ diff --git a/drivers/mmc/octeontx_hsmmc.c b/drivers/mmc/octeontx_hsmmc.c index f3da6af909..442ca493d7 100644 --- a/drivers/mmc/octeontx_hsmmc.c +++ b/drivers/mmc/octeontx_hsmmc.c @@ -3439,7 +3439,7 @@ static u32 xlate_voltage(u32 voltage) */ static bool octeontx_mmc_get_valid(struct udevice *dev) { - const char *stat = ofnode_read_string(dev->node, "status"); + const char *stat = ofnode_read_string(dev_ofnode(dev), "status"); if (!stat || !strncmp(stat, "ok", 2)) return true; @@ -3461,14 +3461,15 @@ static int octeontx_mmc_get_config(struct udevice *dev) uint low, high; char env_name[32]; int err; - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); int bus_width = 1; ulong new_max_freq; debug("%s(%s)", __func__, dev->name); slot->cfg.name = dev->name; - slot->cfg.f_max = ofnode_read_s32_default(dev->node, "max-frequency", + slot->cfg.f_max = ofnode_read_s32_default(dev_ofnode(dev), + "max-frequency", 26000000); snprintf(env_name, sizeof(env_name), "mmc_max_frequency%d", slot->bus_id); @@ -3486,25 +3487,26 @@ static int octeontx_mmc_get_config(struct udevice *dev) if (IS_ENABLED(CONFIG_ARCH_OCTEONTX2)) { slot->hs400_tuning_block = - ofnode_read_s32_default(dev->node, + ofnode_read_s32_default(dev_ofnode(dev), "marvell,hs400-tuning-block", -1); debug("%s(%s): mmc HS400 tuning block: %d\n", __func__, dev->name, slot->hs400_tuning_block); slot->hs200_tap_adj = - ofnode_read_s32_default(dev->node, + ofnode_read_s32_default(dev_ofnode(dev), "marvell,hs200-tap-adjust", 0); debug("%s(%s): hs200-tap-adjust: %d\n", __func__, dev->name, slot->hs200_tap_adj); slot->hs400_tap_adj = - ofnode_read_s32_default(dev->node, + ofnode_read_s32_default(dev_ofnode(dev), "marvell,hs400-tap-adjust", 0); debug("%s(%s): hs400-tap-adjust: %d\n", __func__, dev->name, slot->hs400_tap_adj); } - err = ofnode_read_u32_array(dev->node, "voltage-ranges", voltages, 2); + err = ofnode_read_u32_array(dev_ofnode(dev), "voltage-ranges", + voltages, 2); if (err) { slot->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34; } else { @@ -3756,14 +3758,15 @@ static int octeontx_mmc_host_probe(struct udevice *dev) pr_err("%s: No device tree information found\n", __func__); return -1; } - host->node = dev->node; + host->node = dev_ofnode(dev); host->last_slotid = -1; if (otx_is_platform(PLATFORM_ASIM)) host->is_asim = true; if (otx_is_platform(PLATFORM_EMULATOR)) host->is_emul = true; host->dma_wait_delay = - ofnode_read_u32_default(dev->node, "marvell,dma-wait-delay", 1); + ofnode_read_u32_default(dev_ofnode(dev), + "marvell,dma-wait-delay", 1); /* Force reset of eMMC */ writeq(0, host->base_addr + MIO_EMM_CFG()); debug("%s: Clearing MIO_EMM_CFG\n", __func__); @@ -3824,7 +3827,7 @@ static int octeontx_mmc_host_child_pre_probe(struct udevice *dev) struct octeontx_mmc_host *host = dev_get_priv(dev_get_parent(dev)); struct octeontx_mmc_slot *slot; struct mmc_uclass_priv *upriv; - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); u32 bus_id; char name[16]; int err; diff --git a/drivers/mtd/nand/raw/octeontx_nand.c b/drivers/mtd/nand/raw/octeontx_nand.c index 96a5fe6592..64433cf6cc 100644 --- a/drivers/mtd/nand/raw/octeontx_nand.c +++ b/drivers/mtd/nand/raw/octeontx_nand.c @@ -1999,7 +1999,7 @@ static int octeontx_nfc_chip_init(struct octeontx_nfc *tn, struct udevice *dev, static int octeontx_nfc_chips_init(struct octeontx_nfc *tn) { struct udevice *dev = tn->dev; - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); ofnode nand_node; int nr_chips = of_get_child_count(node); int ret; diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index ab9a24ed5b..cd12376ab8 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1173,7 +1173,7 @@ static int spinand_probe(struct udevice *dev) return -ENOMEM; sprintf(mtd->name, "spi-nand%d", spi_nand_idx++); spinand->slave = slave; - spinand_set_ofnode(spinand, dev->node); + spinand_set_ofnode(spinand, dev_ofnode(dev)); #endif ret = spinand_init(spinand); diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c index a10f87eefc..0e89e663f7 100644 --- a/drivers/net/fm/eth.c +++ b/drivers/net/fm/eth.c @@ -957,7 +957,7 @@ phy_interface_t fman_read_sys_if(struct udevice *dev) { const char *if_str; - if_str = ofnode_read_string(dev->node, "phy-connection-type"); + if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type"); debug("MAC system interface mode %s\n", if_str); return phy_get_interface_by_name(if_str); @@ -969,7 +969,7 @@ static int fm_eth_bind(struct udevice *dev) char mac_name[11]; u32 fm, num; - if (ofnode_read_u32(ofnode_get_parent(dev->node), "cell-index", &fm)) { + if (ofnode_read_u32(ofnode_get_parent(dev_ofnode(dev)), "cell-index", &fm)) { printf("FMan node property cell-index missing\n"); return -EINVAL; } diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c index 2e684e5839..f6fc7801b9 100644 --- a/drivers/net/fsl_enetc.c +++ b/drivers/net/fsl_enetc.c @@ -99,7 +99,7 @@ static int enetc_bind(struct udevice *dev) * and some are not, use different naming scheme - enetc-N based on * PCI function # and enetc#N based on interface count */ - if (ofnode_valid(dev->node)) + if (ofnode_valid(dev_ofnode(dev))) sprintf(name, "enetc-%u", PCI_FUNC(pci_get_devfn(dev))); else sprintf(name, "enetc#%u", eth_num_devices++); @@ -253,12 +253,12 @@ static void enetc_start_pcs(struct udevice *dev) mdio_register(&priv->imdio); } - if (!ofnode_valid(dev->node)) { + if (!ofnode_valid(dev_ofnode(dev))) { enetc_dbg(dev, "no enetc ofnode found, skipping PCS set-up\n"); return; } - if_str = ofnode_read_string(dev->node, "phy-mode"); + if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode"); if (if_str) priv->if_type = phy_get_interface_by_name(if_str); else @@ -306,7 +306,7 @@ static int enetc_probe(struct udevice *dev) { struct enetc_priv *priv = dev_get_priv(dev); - if (ofnode_valid(dev->node) && !ofnode_is_available(dev->node)) { + if (ofnode_valid(dev_ofnode(dev)) && !ofnode_is_available(dev_ofnode(dev))) { enetc_dbg(dev, "interface disabled\n"); return -ENODEV; } diff --git a/drivers/net/fsl_enetc_mdio.c b/drivers/net/fsl_enetc_mdio.c index 4da97b61d1..3eb6ac9fc8 100644 --- a/drivers/net/fsl_enetc_mdio.c +++ b/drivers/net/fsl_enetc_mdio.c @@ -112,7 +112,7 @@ static int enetc_mdio_bind(struct udevice *dev) * and some are not, use different naming scheme - enetc-N based on * PCI function # and enetc#N based on interface count */ - if (ofnode_valid(dev->node)) + if (ofnode_valid(dev_ofnode(dev))) sprintf(name, "emdio-%u", PCI_FUNC(pci_get_devfn(dev))); else sprintf(name, "emdio#%u", eth_num_devices++); diff --git a/drivers/net/mdio-ipq4019.c b/drivers/net/mdio-ipq4019.c index 13a8856286..50134b4d9b 100644 --- a/drivers/net/mdio-ipq4019.c +++ b/drivers/net/mdio-ipq4019.c @@ -107,8 +107,8 @@ static const struct mdio_ops ipq4019_mdio_ops = { static int ipq4019_mdio_bind(struct udevice *dev) { - if (ofnode_valid(dev->node)) - device_set_name(dev, ofnode_get_name(dev->node)); + if (ofnode_valid(dev_ofnode(dev))) + device_set_name(dev, ofnode_get_name(dev_ofnode(dev))); return 0; } diff --git a/drivers/net/mdio_mux_i2creg.c b/drivers/net/mdio_mux_i2creg.c index f8557dd2c4..3654230118 100644 --- a/drivers/net/mdio_mux_i2creg.c +++ b/drivers/net/mdio_mux_i2creg.c @@ -61,7 +61,7 @@ static int mdio_mux_i2creg_probe(struct udevice *dev) } /* parent should be an I2C chip, grandparent should be an I2C bus */ - chip_node = ofnode_get_parent(dev->node); + chip_node = ofnode_get_parent(dev_ofnode(dev)); bus_node = ofnode_get_parent(chip_node); err = uclass_get_device_by_ofnode(UCLASS_I2C, bus_node, &i2c_bus); diff --git a/drivers/net/mvmdio.c b/drivers/net/mvmdio.c index 005f28f1b2..96f8dc62b5 100644 --- a/drivers/net/mvmdio.c +++ b/drivers/net/mvmdio.c @@ -197,8 +197,8 @@ static int mvmdio_write(struct udevice *dev, int addr, int devad, int reg, */ static int mvmdio_bind(struct udevice *dev) { - if (ofnode_valid(dev->node)) - device_set_name(dev, ofnode_get_name(dev->node)); + if (ofnode_valid(dev_ofnode(dev))) + device_set_name(dev, ofnode_get_name(dev_ofnode(dev))); return 0; } diff --git a/drivers/net/octeontx/smi.c b/drivers/net/octeontx/smi.c index d1582b968b..58436419f1 100644 --- a/drivers/net/octeontx/smi.c +++ b/drivers/net/octeontx/smi.c @@ -313,7 +313,7 @@ read_error: int octeontx_smi_probe(struct udevice *dev) { - int ret, subnode, cnt = 0, node = dev->node.of_offset; + int ret, subnode, cnt = 0, node = dev_ofnode(dev).of_offset; struct mii_dev *bus; struct octeontx_smi_priv *priv; pci_dev_t bdf = dm_pci_get_bdf(dev); diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index 2d124732cf..ec48689372 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -707,7 +707,8 @@ static int init_phy(struct tsec_private *priv) tsec_configure_serdes(priv); #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO) - if (ofnode_valid(ofnode_find_subnode(priv->dev->node, "fixed-link"))) + if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev), + "fixed-link"))) phydev = phy_connect(NULL, 0, priv->dev, priv->interface); else phydev = dm_eth_phy_connect(priv->dev); diff --git a/drivers/phy/phy-ti-am654.c b/drivers/phy/phy-ti-am654.c index 8e35ea1475..82010e7c96 100644 --- a/drivers/phy/phy-ti-am654.c +++ b/drivers/phy/phy-ti-am654.c @@ -344,7 +344,7 @@ static int serdes_am654_bind(struct udevice *dev) ret = device_bind_driver_to_node(dev->parent, "ti-serdes-am654-mux-clk", - dev_read_name(dev), dev->node, + dev_read_name(dev), dev_ofnode(dev), NULL); if (ret) { dev_err(dev, "%s: not able to bind clock driver\n", __func__); diff --git a/drivers/power/domain/meson-ee-pwrc.c b/drivers/power/domain/meson-ee-pwrc.c index 2e7ab67128..ef8274ce96 100644 --- a/drivers/power/domain/meson-ee-pwrc.c +++ b/drivers/power/domain/meson-ee-pwrc.c @@ -397,11 +397,11 @@ static int meson_ee_pwrc_probe(struct udevice *dev) if (!priv->data) return -EINVAL; - priv->regmap_hhi = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->regmap_hhi = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->regmap_hhi)) return PTR_ERR(priv->regmap_hhi); - ret = ofnode_read_u32(dev->node, "amlogic,ao-sysctrl", + ret = ofnode_read_u32(dev_ofnode(dev), "amlogic,ao-sysctrl", &ao_phandle); if (ret) return ret; diff --git a/drivers/power/domain/meson-gx-pwrc-vpu.c b/drivers/power/domain/meson-gx-pwrc-vpu.c index 40947c66f3..eb94af2cf8 100644 --- a/drivers/power/domain/meson-gx-pwrc-vpu.c +++ b/drivers/power/domain/meson-gx-pwrc-vpu.c @@ -300,11 +300,11 @@ static int meson_gx_pwrc_vpu_probe(struct udevice *dev) ofnode hhi_node; int ret; - priv->regmap_ao = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->regmap_ao = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->regmap_ao)) return PTR_ERR(priv->regmap_ao); - ret = ofnode_read_u32(dev->node, "amlogic,hhi-sysctrl", + ret = ofnode_read_u32(dev_ofnode(dev), "amlogic,hhi-sysctrl", &hhi_phandle); if (ret) return ret; diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c index 6f0d0a59ff..5bf186e4d4 100644 --- a/drivers/power/regulator/pbias_regulator.c +++ b/drivers/power/regulator/pbias_regulator.c @@ -103,7 +103,8 @@ static int pbias_bind(struct udevice *dev) { int children; - children = pmic_bind_children(dev, dev->node, pmic_children_info); + children = pmic_bind_children(dev, dev_ofnode(dev), + pmic_children_info); if (!children) debug("%s: %s - no child found\n", __func__, dev->name); diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 58b7469f97..03eeacc286 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -304,13 +304,14 @@ static int meson_pwm_probe(struct udevice *dev) if (strcmp(cdev->driver->name, "fixed_rate_clock")) continue; - str = ofnode_read_string(cdev->node, "clock-output-names"); + str = ofnode_read_string(dev_ofnode(cdev), + "clock-output-names"); if (!str) continue; if (!strcmp(str, "xtal")) { err = uclass_get_device_by_ofnode(UCLASS_CLK, - cdev->node, + dev_ofnode(cdev), &cdev); if (err) { printf("%s%d: Failed to get xtal clk\n", __func__, i); @@ -345,7 +346,9 @@ static int meson_pwm_probe(struct udevice *dev) return -EINVAL; } - err = uclass_get_device_by_ofnode(UCLASS_CLK, cdev->node, &cdev); + err = uclass_get_device_by_ofnode(UCLASS_CLK, + dev_ofnode(cdev), + &cdev); if (err) { printf("%s%d: Failed to get clk controller\n", __func__, i); return err; diff --git a/drivers/reset/reset-socfpga.c b/drivers/reset/reset-socfpga.c index c64c9b5917..98450db94b 100644 --- a/drivers/reset/reset-socfpga.c +++ b/drivers/reset/reset-socfpga.c @@ -148,7 +148,7 @@ static int socfpga_reset_bind(struct udevice *dev) * Bind it to the node, too, so that it can get its base address. */ ret = device_bind_driver_to_node(dev, "socfpga_sysreset", "sysreset", - dev->node, &sys_child); + dev_ofnode(dev), &sys_child); if (ret) debug("Warning: No sysreset driver: ret=%d\n", ret); diff --git a/drivers/spi/fsl_dspi.c b/drivers/spi/fsl_dspi.c index b8c0216b39..c17a5522bc 100644 --- a/drivers/spi/fsl_dspi.c +++ b/drivers/spi/fsl_dspi.c @@ -460,8 +460,10 @@ static int fsl_dspi_child_pre_probe(struct udevice *dev) return -EINVAL; } - ofnode_read_u32(dev->node, "fsl,spi-cs-sck-delay", &cs_sck_delay); - ofnode_read_u32(dev->node, "fsl,spi-sck-cs-delay", &sck_cs_delay); + ofnode_read_u32(dev_ofnode(dev), "fsl,spi-cs-sck-delay", + &cs_sck_delay); + ofnode_read_u32(dev_ofnode(dev), "fsl,spi-sck-cs-delay", + &sck_cs_delay); /* Set PCS to SCK delay scale values */ ns_delay_scale(&pcssck, &cssck, cs_sck_delay, priv->bus_clk); diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 7c38d6e052..b898c32edc 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -592,7 +592,7 @@ static optee_invoke_fn *get_invoke_func(struct udevice *dev) const char *method; debug("optee: looking for conduit method in DT.\n"); - method = ofnode_get_property(dev->node, "method", NULL); + method = ofnode_get_property(dev_ofnode(dev), "method", NULL); if (!method) { debug("optee: missing \"method\" property\n"); return ERR_PTR(-ENXIO); diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index e861c82f7e..798a21793f 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -110,7 +110,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) enum usb_dr_mode dr_mode; int ret = 0; - dr_mode = usb_get_dr_mode(dev->node); + dr_mode = usb_get_dr_mode(dev_ofnode(dev)); cdns->role = USB_ROLE_NONE; /* @@ -393,7 +393,7 @@ int cdns3_bind(struct udevice *parent) ofnode node; int ret; - node = ofnode_by_compatible(parent->node, "cdns,usb3"); + node = ofnode_by_compatible(dev_ofnode(parent), "cdns,usb3"); if (!ofnode_valid(node)) { ret = -ENODEV; goto fail; diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 2e003530a1..dfd7cf683f 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -905,7 +905,7 @@ void dwc3_of_parse(struct dwc3 *dwc) */ hird_threshold = 12; - dwc->hsphy_mode = usb_get_phy_mode(dev->node); + dwc->hsphy_mode = usb_get_phy_mode(dev_ofnode(dev)); dwc->has_lpm_erratum = dev_read_bool(dev, "snps,has-lpm-erratum"); diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 459add80c5..39e931f634 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -108,7 +108,7 @@ static int dwc3_generic_remove(struct udevice *dev, static int dwc3_generic_of_to_plat(struct udevice *dev) { struct dwc3_generic_plat *plat = dev_get_plat(dev); - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); plat->base = dev_read_addr(dev); @@ -301,7 +301,7 @@ static int dwc3_glue_bind(struct udevice *parent) ofnode node; int ret; - ofnode_for_each_subnode(node, parent->node) { + ofnode_for_each_subnode(node, dev_ofnode(parent)) { const char *name = ofnode_get_name(node); enum usb_dr_mode dr_mode; struct udevice *dev; @@ -418,7 +418,7 @@ static int dwc3_glue_probe(struct udevice *dev) while (child) { enum usb_dr_mode dr_mode; - dr_mode = usb_get_dr_mode(child->node); + dr_mode = usb_get_dr_mode(dev_ofnode(child)); device_find_next_child(&child); if (ops && ops->select_dr_mode) ops->select_dr_mode(dev, index, dr_mode); diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index acc7866b64..6f99fb27f3 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -395,7 +395,7 @@ static int dwc3_meson_g12a_probe(struct udevice *dev) } #endif - priv->otg_mode = usb_get_dr_mode(dev->node); + priv->otg_mode = usb_get_dr_mode(dev_ofnode(dev)); ret = dwc3_meson_g12a_usb_init(priv); if (ret) diff --git a/drivers/usb/dwc3/dwc3-meson-gxl.c b/drivers/usb/dwc3/dwc3-meson-gxl.c index b63cc235f7..08467d6210 100644 --- a/drivers/usb/dwc3/dwc3-meson-gxl.c +++ b/drivers/usb/dwc3/dwc3-meson-gxl.c @@ -338,7 +338,7 @@ static int dwc3_meson_gxl_probe(struct udevice *dev) if (ret) return ret; - priv->otg_mode = usb_get_dr_mode(dev->node); + priv->otg_mode = usb_get_dr_mode(dev_ofnode(dev)); if (priv->otg_mode == USB_DR_MODE_PERIPHERAL) priv->otg_phy_mode = USB_DR_MODE_PERIPHERAL; diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c index 4771b1e931..e3871e381e 100644 --- a/drivers/usb/gadget/dwc2_udc_otg.c +++ b/drivers/usb/gadget/dwc2_udc_otg.c @@ -987,8 +987,8 @@ static int dwc2_udc_otg_of_to_plat(struct udevice *dev) void (*set_params)(struct dwc2_plat_otg_data *data); int ret; - if (usb_get_dr_mode(dev->node) != USB_DR_MODE_PERIPHERAL && - usb_get_dr_mode(dev->node) != USB_DR_MODE_OTG) { + if (usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_PERIPHERAL && + usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_OTG) { dev_dbg(dev, "Invalid mode\n"); return -ENODEV; } diff --git a/drivers/usb/host/dwc3-octeon-glue.c b/drivers/usb/host/dwc3-octeon-glue.c index c3cac9c5ab..742e156cbb 100644 --- a/drivers/usb/host/dwc3-octeon-glue.c +++ b/drivers/usb/host/dwc3-octeon-glue.c @@ -366,7 +366,7 @@ static int octeon_dwc3_glue_bind(struct udevice *dev) /* Find snps,dwc3 node from subnode */ dwc3_node = ofnode_null(); - ofnode_for_each_subnode(node, dev->node) { + ofnode_for_each_subnode(node, dev_ofnode(dev)) { if (ofnode_device_is_compatible(node, "snps,dwc3")) dwc3_node = node; } diff --git a/drivers/usb/host/dwc3-sti-glue.c b/drivers/usb/host/dwc3-sti-glue.c index deb820a0f8..e5c6a1a67d 100644 --- a/drivers/usb/host/dwc3-sti-glue.c +++ b/drivers/usb/host/dwc3-sti-glue.c @@ -108,7 +108,8 @@ static int sti_dwc3_glue_of_to_plat(struct udevice *dev) int ret; u32 reg[4]; - ret = ofnode_read_u32_array(dev->node, "reg", reg, ARRAY_SIZE(reg)); + ret = ofnode_read_u32_array(dev_ofnode(dev), "reg", reg, + ARRAY_SIZE(reg)); if (ret) { pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret); return ret; @@ -154,7 +155,7 @@ static int sti_dwc3_glue_bind(struct udevice *dev) ofnode node, dwc3_node; /* Find snps,dwc3 node from subnode */ - ofnode_for_each_subnode(node, dev->node) { + ofnode_for_each_subnode(node, dev_ofnode(dev)) { if (ofnode_device_is_compatible(node, "snps,dwc3")) dwc3_node = node; } diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index d2f49cf469..ef3a63afa4 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -523,7 +523,7 @@ static int ehci_usb_of_to_plat(struct udevice *dev) struct usb_plat *plat = dev_get_plat(dev); enum usb_dr_mode dr_mode; - dr_mode = usb_get_dr_mode(dev->node); + dr_mode = usb_get_dr_mode(dev_ofnode(dev)); switch (dr_mode) { case USB_DR_MODE_HOST: diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c index 59408e4e50..3e0ae80cec 100644 --- a/drivers/usb/host/xhci-dwc3.c +++ b/drivers/usb/host/xhci-dwc3.c @@ -155,7 +155,7 @@ static int xhci_dwc3_probe(struct udevice *dev) writel(reg, &dwc3_reg->g_usb2phycfg[0]); - dr_mode = usb_get_dr_mode(dev->node); + dr_mode = usb_get_dr_mode(dev_ofnode(dev)); if (dr_mode == USB_DR_MODE_UNKNOWN) /* by default set dual role mode to HOST */ dr_mode = USB_DR_MODE_HOST; diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 28136f88f4..2f5cc9b148 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -802,7 +802,7 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb) mtu->ippc_base = ssusb->ippc_base; mtu->mac_base = ssusb->mac_base; mtu->ssusb = ssusb; - mtu->max_speed = usb_get_maximum_speed(dev->node); + mtu->max_speed = usb_get_maximum_speed(dev_ofnode(dev)); mtu->force_vbus = dev_read_bool(dev, "mediatek,force-vbus"); ret = mtu3_hw_init(mtu); diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index c951107b20..b097471f3d 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -173,7 +173,7 @@ static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb) return -ENODEV; } - ssusb->dr_mode = usb_get_dr_mode(child->node); + ssusb->dr_mode = usb_get_dr_mode(dev_ofnode(child)); if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN || ssusb->dr_mode == USB_DR_MODE_OTG) @@ -313,7 +313,7 @@ static int mtu3_glue_bind(struct udevice *parent) ofnode node; int ret; - node = ofnode_by_compatible(parent->node, "mediatek,ssusb"); + node = ofnode_by_compatible(dev_ofnode(parent), "mediatek,ssusb"); if (!ofnode_valid(node)) return -ENODEV; diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index 81b12fadfc..75cf1811f7 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -289,7 +289,7 @@ static int ti_musb_wrapper_bind(struct udevice *parent) ofnode node; int ret; - ofnode_for_each_subnode(node, parent->node) { + ofnode_for_each_subnode(node, dev_ofnode(parent)) { struct udevice *dev; const char *name = ofnode_get_name(node); enum usb_dr_mode dr_mode; diff --git a/drivers/video/nexell_display.c b/drivers/video/nexell_display.c index 00e2c36f37..b47bef3578 100644 --- a/drivers/video/nexell_display.c +++ b/drivers/video/nexell_display.c @@ -416,7 +416,7 @@ static struct nx_display_dev *nx_display_setup(void) __func__); return NULL; } - node = dev->node.of_offset; + node = dev_ofnode(dev).of_offset; if (CONFIG_IS_ENABLED(OF_CONTROL)) { ret = nx_display_parse_dt(dev, dp, plat); diff --git a/drivers/video/rockchip/rk_mipi.c b/drivers/video/rockchip/rk_mipi.c index d125a5ba73..159201a591 100644 --- a/drivers/video/rockchip/rk_mipi.c +++ b/drivers/video/rockchip/rk_mipi.c @@ -119,7 +119,7 @@ int rk_mipi_dsi_enable(struct udevice *dev, rk_mipi_dsi_write(regs, VID_PKT_SIZE, 0x4b0); /* Set dpi color coding depth 24 bit */ - timing_node = ofnode_find_subnode(dev->node, "display-timings"); + timing_node = ofnode_find_subnode(dev_ofnode(dev), "display-timings"); node = ofnode_first_subnode(timing_node); val = ofnode_read_u32_default(node, "bits-per-pixel", -1); diff --git a/include/dm/device.h b/include/dm/device.h index 4a1224bcc2..1b274206ea 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -200,7 +200,11 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic) */ 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) */ @@ -208,12 +212,27 @@ static inline ofnode dev_ofnode(const struct udevice *dev) 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_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) diff --git a/include/dm/read.h b/include/dm/read.h index d5cdd87911..fc987f7759 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) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 54d03d0240..927854950a 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -334,12 +334,12 @@ struct mtd_info { #if IS_ENABLED(CONFIG_DM) static inline void mtd_set_ofnode(struct mtd_info *mtd, ofnode node) { - mtd->dev->node = node; + dev_set_ofnode(mtd->dev, node); } static inline const ofnode mtd_get_ofnode(struct mtd_info *mtd) { - return mtd->dev->node; + return dev_ofnode(mtd->dev); } #else struct device_node; diff --git a/net/mdio-mux-uclass.c b/net/mdio-mux-uclass.c index 5f38f9fde4..780526c19e 100644 --- a/net/mdio-mux-uclass.c +++ b/net/mdio-mux-uclass.c @@ -163,7 +163,7 @@ static int dm_mdio_mux_post_bind(struct udevice *mux) ofnode ch_node; int err, first_err = 0; - if (!ofnode_valid(mux->node)) { + if (!dev_has_ofnode(mux)) { debug("%s: no mux node found, no child MDIO busses set up\n", __func__); return 0; diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index d062382c2a..697e5f838d 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -40,8 +40,8 @@ static int dm_mdio_post_bind(struct udevice *dev) const char *dt_name; /* set a custom name for the MDIO device, if present in DT */ - if (ofnode_valid(dev->node)) { - dt_name = ofnode_read_string(dev->node, "device-name"); + if (dev_has_ofnode(dev)) { + dt_name = dev_read_string(dev, "device-name"); if (dt_name) { debug("renaming dev %s to %s\n", dev->name, dt_name); device_set_name(dev, dt_name); @@ -182,14 +182,14 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) struct phy_device *phy; int i; - if (!ofnode_valid(ethdev->node)) { + if (!dev_has_ofnode(ethdev)) { debug("%s: supplied eth dev has no DT node!\n", ethdev->name); return NULL; } interface = PHY_INTERFACE_MODE_NONE; for (i = 0; i < PHY_MODE_STR_CNT; i++) { - if_str = ofnode_read_string(ethdev->node, phy_mode_str[i]); + if_str = dev_read_string(ethdev, phy_mode_str[i]); if (if_str) { interface = phy_get_interface_by_name(if_str); break; -- cgit v1.2.3 From 8a715530bb1f9522030757379415b174f3109951 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:17 -0700 Subject: dm: core: Allow the uclass list to move At present the uclass list head is in global_data. This is convenient but with the new of-platdata we need the list head to be declared by the generated code. Change this over to be a pointer. Provide a 'static' version in global_data to retain the current behaviour. Signed-off-by: Simon Glass --- drivers/core/device.c | 4 ++-- drivers/core/root.c | 7 ++++--- drivers/core/uclass.c | 4 ++-- include/asm-generic/global_data.h | 8 +++++++- include/dm/device-internal.h | 1 + test/dm/core.c | 6 +++--- 6 files changed, 19 insertions(+), 11 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index 6a9bee093d..aeab3836ed 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -613,7 +613,7 @@ static int device_find_by_ofnode(ofnode node, struct udevice **devp) struct udevice *dev; int ret; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev); if (!ret || dev) { @@ -1032,7 +1032,7 @@ int dev_disable_by_path(const char *path) if (!of_live_active()) return -ENOSYS; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev); if (!ret) break; diff --git a/drivers/core/root.c b/drivers/core/root.c index 2a5ebec27d..3adbc94eb9 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -45,8 +45,8 @@ void dm_fixup_for_gd_move(struct global_data *new_gd) { /* The sentinel node has moved, so update things that point to it */ if (gd->dm_root) { - new_gd->uclass_root.next->prev = &new_gd->uclass_root; - new_gd->uclass_root.prev->next = &new_gd->uclass_root; + new_gd->uclass_root->next->prev = new_gd->uclass_root; + new_gd->uclass_root->prev->next = new_gd->uclass_root; } } @@ -136,7 +136,8 @@ int dm_init(bool of_live) dm_warn("Virtual root driver already exists!\n"); return -EINVAL; } - INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST); + gd->uclass_root = &DM_UCLASS_ROOT_S_NON_CONST; + INIT_LIST_HEAD(DM_UCLASS_ROOT_NON_CONST); if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) { fix_drivers(); diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index e773e34833..cdb975d5b3 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -33,7 +33,7 @@ struct uclass *uclass_find(enum uclass_id key) * node to the start of the list, or creating a linear array mapping * id to node. */ - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { if (uc->uc_drv->id == key) return uc; } @@ -84,7 +84,7 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) uc->uc_drv = uc_drv; INIT_LIST_HEAD(&uc->sibling_node); INIT_LIST_HEAD(&uc->dev_head); - list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST); + list_add(&uc->sibling_node, DM_UCLASS_ROOT_NON_CONST); if (uc_drv->init) { ret = uc_drv->init(uc); diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 87d827d0f4..b63575919f 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -194,7 +194,13 @@ struct global_data { /** * @uclass_root: head of core tree */ - struct list_head uclass_root; + struct list_head uclass_root_s; + /** + * @uclass_root: pointer to head of core tree, if uclasses are in + * read-only memory and cannot be adjusted to use @uclass_root as a + * list head. + */ + struct list_head *uclass_root; # if CONFIG_IS_ENABLED(OF_PLATDATA) /** Dynamic info about the driver */ struct driver_rt *dm_driver_rt; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 03b092bdf7..639bbd293d 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -288,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/test/dm/core.c b/test/dm/core.c index 565896ed50..580d171e30 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -116,14 +116,14 @@ static int dm_test_autobind(struct unit_test_state *uts) * device with no children. */ ut_assert(dms->root); - ut_asserteq(1, list_count_items(&gd->uclass_root)); + ut_asserteq(1, list_count_items(gd->uclass_root)); ut_asserteq(0, list_count_items(&gd->dm_root->child_head)); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); ut_assertok(dm_scan_plat(false)); /* We should have our test class now at least, plus more children */ - ut_assert(1 < list_count_items(&gd->uclass_root)); + ut_assert(1 < list_count_items(gd->uclass_root)); ut_assert(0 < list_count_items(&gd->dm_root->child_head)); /* Our 3 dm_test_infox children should be bound to the test uclass */ @@ -1073,7 +1073,7 @@ static int dm_test_all_have_seq(struct unit_test_state *uts) struct udevice *dev; struct uclass *uc; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { list_for_each_entry(dev, &uc->dev_head, uclass_node) { if (dev->seq_ == -1) printf("Device '%s' has no seq (%d)\n", -- cgit v1.2.3