diff options
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/device-remove.c | 1 | ||||
-rw-r--r-- | drivers/core/device.c | 56 | ||||
-rw-r--r-- | drivers/core/devres.c | 57 | ||||
-rw-r--r-- | drivers/core/lists.c | 4 |
4 files changed, 91 insertions, 27 deletions
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 5c8dc4ad70..444e34b492 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -140,6 +140,7 @@ void device_free(struct udevice *dev) dev->parent_priv = NULL; } } + dev->flags &= ~DM_FLAG_PLATDATA_VALID; devres_release_probe(dev); } diff --git a/drivers/core/device.c b/drivers/core/device.c index 4e037083a6..9f39218423 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -311,17 +311,16 @@ static void *alloc_priv(int size, uint flags) return priv; } -int device_probe(struct udevice *dev) +int device_ofdata_to_platdata(struct udevice *dev) { const struct driver *drv; int size = 0; int ret; - int seq; if (!dev) return -EINVAL; - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev->flags & DM_FLAG_PLATDATA_VALID) return 0; drv = dev->driver; @@ -346,7 +345,7 @@ int device_probe(struct udevice *dev) } } - /* Ensure all parents are probed */ + /* Allocate parent data for this child */ if (dev->parent) { size = dev->parent->driver->per_child_auto_alloc_size; if (!size) { @@ -360,7 +359,45 @@ int device_probe(struct udevice *dev) goto fail; } } + } + + if (drv->ofdata_to_platdata && + (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) { + ret = drv->ofdata_to_platdata(dev); + if (ret) + goto fail; + } + + dev->flags |= DM_FLAG_PLATDATA_VALID; + return 0; +fail: + device_free(dev); + + return ret; +} + +int device_probe(struct udevice *dev) +{ + const struct driver *drv; + int ret; + int seq; + + if (!dev) + return -EINVAL; + + if (dev->flags & DM_FLAG_ACTIVATED) + return 0; + + drv = dev->driver; + assert(drv); + + ret = device_ofdata_to_platdata(dev); + if (ret) + goto fail; + + /* Ensure all parents are probed */ + if (dev->parent) { ret = device_probe(dev->parent); if (ret) goto fail; @@ -411,13 +448,6 @@ int device_probe(struct udevice *dev) goto fail; } - if (drv->ofdata_to_platdata && - (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) { - ret = drv->ofdata_to_platdata(dev); - if (ret) - goto fail; - } - /* Only handle devices that have a valid ofnode */ if (dev_of_valid(dev)) { /* @@ -431,10 +461,8 @@ int device_probe(struct udevice *dev) if (drv->probe) { ret = drv->probe(dev); - if (ret) { - dev->flags &= ~DM_FLAG_ACTIVATED; + if (ret) goto fail; - } } ret = uclass_post_probe_device(dev); diff --git a/drivers/core/devres.c b/drivers/core/devres.c index f2a19ec61b..237b42653c 100644 --- a/drivers/core/devres.c +++ b/drivers/core/devres.c @@ -7,6 +7,8 @@ * Copyright (c) 2006 Tejun Heo <teheo@suse.de> */ +#define LOG_CATEGORY LOGC_DEVRES + #include <common.h> #include <linux/compat.h> #include <linux/kernel.h> @@ -15,12 +17,23 @@ #include <dm/root.h> #include <dm/util.h> +/** enum devres_phase - Shows where resource was allocated + * + * DEVRES_PHASE_BIND: In the bind() method + * DEVRES_PHASE_OFDATA: In the ofdata_to_platdata() method + * DEVRES_PHASE_PROBE: In the probe() method + */ +enum devres_phase { + DEVRES_PHASE_BIND, + DEVRES_PHASE_OFDATA, + DEVRES_PHASE_PROBE, +}; + /** * struct devres - Bookkeeping info for managed device resource * @entry: List to associate this structure with a device * @release: Callback invoked when this resource is released - * @probe: Flag to show when this resource was allocated - (true = probe, false = bind) + * @probe: Show where this resource was allocated * @name: Name of release function * @size: Size of resource data * @data: Resource data @@ -28,7 +41,7 @@ struct devres { struct list_head entry; dr_release_t release; - bool probe; + enum devres_phase phase; #ifdef CONFIG_DEBUG_DEVRES const char *name; size_t size; @@ -46,8 +59,8 @@ static void set_node_dbginfo(struct devres *dr, const char *name, size_t size) static void devres_log(struct udevice *dev, struct devres *dr, const char *op) { - printf("%s: DEVRES %3s %p %s (%lu bytes)\n", - dev->name, op, dr, dr->name, (unsigned long)dr->size); + log_debug("%s: DEVRES %3s %p %s (%lu bytes)\n", dev->name, op, dr, + dr->name, (unsigned long)dr->size); } #else /* CONFIG_DEBUG_DEVRES */ #define set_node_dbginfo(dr, n, s) do {} while (0) @@ -80,7 +93,7 @@ void devres_free(void *res) if (res) { struct devres *dr = container_of(res, struct devres, data); - BUG_ON(!list_empty(&dr->entry)); + assert_noisy(list_empty(&dr->entry)); kfree(dr); } } @@ -90,8 +103,13 @@ void devres_add(struct udevice *dev, void *res) struct devres *dr = container_of(res, struct devres, data); devres_log(dev, dr, "ADD"); - BUG_ON(!list_empty(&dr->entry)); - dr->probe = dev->flags & DM_FLAG_BOUND ? true : false; + assert_noisy(list_empty(&dr->entry)); + if (dev->flags & DM_FLAG_PLATDATA_VALID) + dr->phase = DEVRES_PHASE_PROBE; + else if (dev->flags & DM_FLAG_BOUND) + dr->phase = DEVRES_PHASE_OFDATA; + else + dr->phase = DEVRES_PHASE_BIND; list_add_tail(&dr->entry, &dev->devres_head); } @@ -172,12 +190,12 @@ int devres_release(struct udevice *dev, dr_release_t release, } static void release_nodes(struct udevice *dev, struct list_head *head, - bool probe_only) + bool probe_and_ofdata_only) { struct devres *dr, *tmp; list_for_each_entry_safe_reverse(dr, tmp, head, entry) { - if (probe_only && !dr->probe) + if (probe_and_ofdata_only && dr->phase == DEVRES_PHASE_BIND) break; devres_log(dev, dr, "REL"); dr->release(dev, dr->data); @@ -197,6 +215,8 @@ void devres_release_all(struct udevice *dev) } #ifdef CONFIG_DEBUG_DEVRES +static char *const devres_phase_name[] = {"BIND", "OFDATA", "PROBE"}; + static void dump_resources(struct udevice *dev, int depth) { struct devres *dr; @@ -207,7 +227,7 @@ static void dump_resources(struct udevice *dev, int depth) list_for_each_entry(dr, &dev->devres_head, entry) printf(" %p (%lu byte) %s %s\n", dr, (unsigned long)dr->size, dr->name, - dr->probe ? "PROBE" : "BIND"); + devres_phase_name[dr->phase]); list_for_each_entry(child, &dev->child_head, sibling_node) dump_resources(child, depth + 1); @@ -221,6 +241,19 @@ void dm_dump_devres(void) if (root) dump_resources(root, 0); } + +void devres_get_stats(const struct udevice *dev, struct devres_stats *stats) +{ + struct devres *dr; + + stats->allocs = 0; + stats->total_size = 0; + list_for_each_entry(dr, &dev->devres_head, entry) { + stats->allocs++; + stats->total_size += dr->size; + } +} + #endif /* @@ -254,5 +287,5 @@ void devm_kfree(struct udevice *dev, void *p) int rc; rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p); - WARN_ON(rc); + assert_noisy(!rc); } diff --git a/drivers/core/lists.c b/drivers/core/lists.c index 4681b3e5dd..68204c303f 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -176,8 +176,10 @@ int lists_bind_fdt(struct udevice *parent, ofnode node, struct udevice **devp, if (pre_reloc_only) { if (!dm_ofnode_pre_reloc(node) && - !(entry->flags & DM_FLAG_PRE_RELOC)) + !(entry->flags & DM_FLAG_PRE_RELOC)) { + log_debug("Skipping device pre-relocation\n"); return 0; + } } log_debug(" - found match at '%s': '%s' matches '%s'\n", |