From d0c20ce6bcb9af3d70ed6ada618607ca1099e811 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:07 -0700 Subject: dm: core: Add an ofnode function to get the devicetree root This is needed in at least one place. Avoid the conditional code in root.c by adding this inline function. Signed-off-by: Simon Glass --- drivers/core/root.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 5f10d7a39c7..9ee65504e6e 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -147,12 +147,8 @@ int dm_init(bool of_live) ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST); if (ret) return ret; -#if CONFIG_IS_ENABLED(OF_CONTROL) - if (CONFIG_IS_ENABLED(OF_LIVE) && of_live) - DM_ROOT_NON_CONST->node = np_to_ofnode(gd_of_root()); - else - DM_ROOT_NON_CONST->node = offset_to_ofnode(0); -#endif + if (CONFIG_IS_ENABLED(OF_CONTROL)) + DM_ROOT_NON_CONST->node = ofnode_root(); ret = device_probe(DM_ROOT_NON_CONST); if (ret) return ret; -- cgit v1.2.3 From 2ebea5eaebf2c11c3f18f553d1bceba22e220893 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:08 -0700 Subject: dm: core: Combine the flattree and livetree binding code At present there are two copies of this code. With ofnode we can combine them to reduce duplication. Update the dm_scan_fdt_node() function and adjust its callers. Signed-off-by: Simon Glass --- drivers/core/root.c | 74 ++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 58 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 9ee65504e6e..62efa0fedcf 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -199,33 +199,6 @@ int dm_scan_platdata(bool pre_reloc_only) } #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) -static int dm_scan_fdt_live(struct udevice *parent, - const struct device_node *node_parent, - bool pre_reloc_only) -{ - struct device_node *np; - int ret = 0, err; - - for (np = node_parent->child; np; np = np->sibling) { - - if (!of_device_is_available(np)) { - pr_debug(" - ignoring disabled device\n"); - continue; - } - err = lists_bind_fdt(parent, np_to_ofnode(np), NULL, - pre_reloc_only); - if (err && !ret) { - ret = err; - debug("%s: ret=%d\n", np->name, ret); - } - } - - if (ret) - dm_warn("Some drivers failed to bind\n"); - - return ret; -} - /** * dm_scan_fdt_node() - Scan the device tree and bind drivers for a node * @@ -233,28 +206,30 @@ static int dm_scan_fdt_live(struct udevice *parent, * for each one. * * @parent: Parent device for the devices that will be created - * @blob: Pointer to device tree blob - * @offset: Offset of node to scan + * @node: Node to scan * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC * flag. If false bind all drivers. * @return 0 if OK, -ve on error */ -static int dm_scan_fdt_node(struct udevice *parent, const void *blob, - int offset, bool pre_reloc_only) +static int dm_scan_fdt_node(struct udevice *parent, ofnode parent_node, + bool pre_reloc_only) { int ret = 0, err; + ofnode node; + + if (!ofnode_valid(parent_node)) + return 0; - for (offset = fdt_first_subnode(blob, offset); - offset > 0; - offset = fdt_next_subnode(blob, offset)) { - const char *node_name = fdt_get_name(blob, offset, NULL); + for (node = ofnode_first_subnode(parent_node); + ofnode_valid(node); + node = ofnode_next_subnode(node)) { + const char *node_name = ofnode_get_name(node); - if (!fdtdec_get_is_enabled(blob, offset)) { + if (!ofnode_is_enabled(node)) { pr_debug(" - ignoring disabled device\n"); continue; } - err = lists_bind_fdt(parent, offset_to_ofnode(offset), NULL, - pre_reloc_only); + err = lists_bind_fdt(parent, node, NULL, pre_reloc_only); if (err && !ret) { ret = err; debug("%s: ret=%d\n", node_name, ret); @@ -269,24 +244,13 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob, int dm_scan_fdt_dev(struct udevice *dev) { - if (!dev_of_valid(dev)) - return 0; - - if (of_live_active()) - return dm_scan_fdt_live(dev, dev_np(dev), - gd->flags & GD_FLG_RELOC ? false : true); - - return dm_scan_fdt_node(dev, gd->fdt_blob, dev_of_offset(dev), + return dm_scan_fdt_node(dev, dev_ofnode(dev), gd->flags & GD_FLG_RELOC ? false : true); } int dm_scan_fdt(const void *blob, bool pre_reloc_only) { - if (of_live_active()) - return dm_scan_fdt_live(gd->dm_root, gd_of_root(), - pre_reloc_only); - - return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only); + return dm_scan_fdt_node(gd->dm_root, ofnode_root(), pre_reloc_only); } static int dm_scan_fdt_ofnode_path(const void *blob, const char *path, @@ -295,14 +259,8 @@ static int dm_scan_fdt_ofnode_path(const void *blob, const char *path, ofnode node; node = ofnode_path(path); - if (!ofnode_valid(node)) - return 0; - - if (of_live_active()) - return dm_scan_fdt_live(gd->dm_root, node.np, pre_reloc_only); - return dm_scan_fdt_node(gd->dm_root, blob, node.of_offset, - pre_reloc_only); + return dm_scan_fdt_node(gd->dm_root, node, pre_reloc_only); } int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) -- cgit v1.2.3 From 725e4fce61e5b8339fdc975b01ce7bb3dd9fa5f4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:09 -0700 Subject: dm: core: Drop unused parameter from dm_scan_fdt() This doesn't need to be passed the devicetree anymore. Drop it. Signed-off-by: Simon Glass --- drivers/core/root.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 62efa0fedcf..54498b2df71 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -248,13 +248,12 @@ int dm_scan_fdt_dev(struct udevice *dev) gd->flags & GD_FLG_RELOC ? false : true); } -int dm_scan_fdt(const void *blob, bool pre_reloc_only) +int dm_scan_fdt(bool pre_reloc_only) { return dm_scan_fdt_node(gd->dm_root, ofnode_root(), pre_reloc_only); } -static int dm_scan_fdt_ofnode_path(const void *blob, const char *path, - bool pre_reloc_only) +static int dm_scan_fdt_ofnode_path(const char *path, bool pre_reloc_only) { ofnode node; @@ -272,7 +271,7 @@ int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) "/firmware" }; - ret = dm_scan_fdt(blob, pre_reloc_only); + ret = dm_scan_fdt(pre_reloc_only); if (ret) { debug("dm_scan_fdt() failed: %d\n", ret); return ret; @@ -280,7 +279,7 @@ int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) /* Some nodes aren't devices themselves but may contain some */ for (i = 0; i < ARRAY_SIZE(nodes); i++) { - ret = dm_scan_fdt_ofnode_path(blob, nodes[i], pre_reloc_only); + ret = dm_scan_fdt_ofnode_path(nodes[i], pre_reloc_only); if (ret) { debug("dm_scan_fdt() scan for %s failed: %d\n", nodes[i], ret); -- cgit v1.2.3 From 8ee05b5f903bdfb0c4c2d578fd0172ecb900e3e2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:10 -0700 Subject: dm: core: Drop unused parameter from dm_extended_scan_fdt() This doesn't need to be passed the devicetree anymore. Drop it. Also rename the function to drop the _fdt suffix. Signed-off-by: Simon Glass --- drivers/core/root.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 54498b2df71..6f8168bb92d 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -262,7 +262,7 @@ static int dm_scan_fdt_ofnode_path(const char *path, bool pre_reloc_only) return dm_scan_fdt_node(gd->dm_root, node, pre_reloc_only); } -int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) +int dm_extended_scan(bool pre_reloc_only) { int ret, i; const char * const nodes[] = { @@ -315,9 +315,9 @@ int dm_init_and_scan(bool pre_reloc_only) } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { - ret = dm_extended_scan_fdt(gd->fdt_blob, pre_reloc_only); + ret = dm_extended_scan(pre_reloc_only); if (ret) { - debug("dm_extended_scan_dt() failed: %d\n", ret); + debug("dm_extended_scan() failed: %d\n", ret); return ret; } } -- cgit v1.2.3 From caa4daa2ae3dc0a3e516addea5772c9af76abcb0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 3 Dec 2020 16:55:18 -0700 Subject: dm: treewide: Rename 'platdata' variables to just 'plat' We use 'priv' for private data but often use 'platdata' for platform data. We can't really use 'pdata' since that is ambiguous (it could mean private or platform data). Rename some of the latter variables to end with 'plat' for consistency. Signed-off-by: Simon Glass --- drivers/core/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 6f8168bb92d..348dc9e1c1f 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -123,8 +123,8 @@ void fix_devices(void) struct driver_info *entry; for (entry = dev; entry != dev + n_ents; entry++) { - if (entry->platdata) - entry->platdata += gd->reloc_off; + if (entry->plat) + entry->plat += gd->reloc_off; } } -- cgit v1.2.3 From d1998a9fde0a917d6496299f6a97b6bccfdc6724 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 3 Dec 2020 16:55:21 -0700 Subject: dm: treewide: Rename ofdata_to_platdata() to of_to_plat() This name is far too long. Rename it to remove the 'data' bits. This makes it consistent with the platdata->plat rename. Signed-off-by: Simon Glass --- drivers/core/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 348dc9e1c1f..42f8f0cedd4 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -69,8 +69,8 @@ void fix_drivers(void) entry->remove += gd->reloc_off; if (entry->unbind) entry->unbind += gd->reloc_off; - if (entry->ofdata_to_platdata) - entry->ofdata_to_platdata += gd->reloc_off; + if (entry->of_to_plat) + entry->of_to_plat += gd->reloc_off; if (entry->child_post_bind) entry->child_post_bind += gd->reloc_off; if (entry->child_pre_probe) -- cgit v1.2.3 From 8a8d24bdf174851ebb8607f359d54b72e3283b97 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 3 Dec 2020 16:55:23 -0700 Subject: dm: treewide: Rename ..._platdata variables to just ..._plat Try to maintain some consistency between these variables by using _plat as a suffix for them. Signed-off-by: Simon Glass --- drivers/core/root.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 42f8f0cedd4..672aa7cea72 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -174,7 +174,7 @@ int dm_remove_devices_flags(uint flags) } #endif -int dm_scan_platdata(bool pre_reloc_only) +int dm_scan_plat(bool pre_reloc_only) { int ret; @@ -308,9 +308,9 @@ int dm_init_and_scan(bool pre_reloc_only) debug("dm_init() failed: %d\n", ret); return ret; } - ret = dm_scan_platdata(pre_reloc_only); + ret = dm_scan_plat(pre_reloc_only); if (ret) { - debug("dm_scan_platdata() failed: %d\n", ret); + debug("dm_scan_plat() failed: %d\n", ret); return ret; } -- cgit v1.2.3 From cd53e5bf4bba421d98eb42ec71af31b521a90c2a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 16 Dec 2020 21:20:09 -0700 Subject: dm: core: Add a new sequence number for devices At present each device has two sequence numbers, with 'req_seq' being set up at bind time and 'seq' at probe time. The idea is that devices can 'request' a sequence number and then the conflicts are resolved when the device is probed. This makes things complicated in a few cases, since we don't really know what the sequence number will end up being. We want to honour the bind-time requests if at all possible, but in fact the only source of these at present is the devicetree aliases. Since we have the devicetree available at bind time, we may as well just use it, in the hope that the required processing will turn out to be useful later (i.e. the device actually gets used). Add a new 'sqq' member, the bind-time sequence number. It operates in parallel to the old values for now. All devices get a valid sqq value, i.e. it is never -1. Drop an #ifdef while we are here. Signed-off-by: Simon Glass --- drivers/core/root.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 672aa7cea72..f2fba5883aa 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -311,22 +311,24 @@ int dm_init_and_scan(bool pre_reloc_only) ret = dm_scan_plat(pre_reloc_only); if (ret) { debug("dm_scan_plat() failed: %d\n", ret); - return ret; + goto fail; } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { ret = dm_extended_scan(pre_reloc_only); if (ret) { debug("dm_extended_scan() failed: %d\n", ret); - return ret; + goto fail; } } ret = dm_scan_other(pre_reloc_only); if (ret) - return ret; + goto fail; return 0; +fail: + return ret; } #ifdef CONFIG_ACPIGEN -- cgit v1.2.3 From 9c503137b73534c3b5abb90691b4d9675b1cdead Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:23 -0700 Subject: dm: core: Use 'uclass_driver' for the uclass linker_list At present the name 'uclass_driver' is used for the uclass linker list. This does not follow the convention of using the struct name. Fix it. Signed-off-by: Simon Glass --- drivers/core/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index f2fba5883aa..9ef242979ba 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -86,8 +86,8 @@ void fix_drivers(void) void fix_uclass(void) { struct uclass_driver *uclass = - ll_entry_start(struct uclass_driver, uclass); - const int n_ents = ll_entry_count(struct uclass_driver, uclass); + ll_entry_start(struct uclass_driver, uclass_driver); + const int n_ents = ll_entry_count(struct uclass_driver, uclass_driver); struct uclass_driver *entry; for (entry = uclass; entry != uclass + n_ents; entry++) { -- 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 --- drivers/core/root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 9ef242979ba..fe7359433f6 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; -- cgit v1.2.3 From 49bbe6eab5babbc353f1dc76e6275671c69dffb2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:16 -0700 Subject: dm: core: Split out scanning code to dm_scan() Move the code related to scanning for devices to bind, into a new function. This will make it easier to skip this step with the new of-platdata improvements. Signed-off-by: Simon Glass --- drivers/core/root.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index fe7359433f6..2a5ebec27d8 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -296,39 +296,60 @@ __weak int dm_scan_other(bool pre_reloc_only) return 0; } -int dm_init_and_scan(bool pre_reloc_only) +/** + * dm_scan() - Scan tables to bind devices + * + * Runs through the driver_info tables and binds the devices it finds. Then runs + * through the devicetree nodes. Finally calls dm_scan_other() to add any + * special devices + * + * @pre_reloc_only: If true, bind only nodes with special devicetree properties, + * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. + */ +static int dm_scan(bool pre_reloc_only) { int ret; - if (CONFIG_IS_ENABLED(OF_PLATDATA)) - dm_populate_phandle_data(); - - ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); - if (ret) { - debug("dm_init() failed: %d\n", ret); - return ret; - } ret = dm_scan_plat(pre_reloc_only); if (ret) { debug("dm_scan_plat() failed: %d\n", ret); - goto fail; + return ret; } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { ret = dm_extended_scan(pre_reloc_only); if (ret) { debug("dm_extended_scan() failed: %d\n", ret); - goto fail; + return ret; } } ret = dm_scan_other(pre_reloc_only); if (ret) - goto fail; + return ret; + + return 0; +} + +int dm_init_and_scan(bool pre_reloc_only) +{ + int ret; + + if (CONFIG_IS_ENABLED(OF_PLATDATA)) + dm_populate_phandle_data(); + + ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); + if (ret) { + debug("dm_init() failed: %d\n", ret); + return ret; + } + ret = dm_scan(pre_reloc_only); + if (ret) { + log_debug("dm_scan() failed: %d\n", ret); + return ret; + } return 0; -fail: - return ret; } #ifdef CONFIG_ACPIGEN -- 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/root.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 2a5ebec27d8..3adbc94eb94 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(); -- cgit v1.2.3 From d960f0db289144a80553e4d226d5dd145d63926a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:05 -0700 Subject: dtoc: Drop dm_populate_phandle_data() This has not been needed since parent information was added and we started using indicies for references to other drivers instead of pointers. It was kept around in the expectation that it might be needed later. However with the latest updates, it doesn't seem likely that we'll need this in the foreseeable future. Drop dm_populate_phandle_data() from dtoc and driver model. Signed-off-by: Simon Glass --- drivers/core/root.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/core/root.c') diff --git a/drivers/core/root.c b/drivers/core/root.c index 3adbc94eb94..78de7cdf875 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -336,9 +336,6 @@ int dm_init_and_scan(bool pre_reloc_only) { int ret; - if (CONFIG_IS_ENABLED(OF_PLATDATA)) - dm_populate_phandle_data(); - ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); if (ret) { debug("dm_init() failed: %d\n", ret); -- cgit v1.2.3