summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-05-08 13:39:24 +0300
committerSimon Glass <sjg@chromium.org>2022-06-28 05:09:52 +0300
commit930a3ddadebf3660cc3163081671de189300afdd (patch)
tree9bc3064b0b9e15d409d78beba75b2e38d3a867ef /drivers/core
parent53c20bebb2215caaadc58b2eee2c80c61456b93d (diff)
downloadu-boot-930a3ddadebf3660cc3163081671de189300afdd.tar.xz
dm: core: Support accessing core tags
At present tag numbers are only allocated for non-core data, meaning that the 'core' data, like priv and plat, are accessed through dedicated functions. For debugging and consistency it is convenient to use tags for this 'core' data too. Add support for this, with new tag numbers and functions to access the pointer and size for each. Update one of the test drivers so that the uclass-private data can be tested here. There is some code duplication with functions like device_alloc_priv() but this is not addressed for now. At some point, some rationalisation may help to reduce code size, but more thought it needed on that. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/device.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 7f71570a94..d9ce546c0c 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -674,6 +674,71 @@ void *dev_get_parent_priv(const struct udevice *dev)
return dm_priv_to_rw(dev->parent_priv_);
}
+void *dev_get_attach_ptr(const struct udevice *dev, enum dm_tag_t tag)
+{
+ switch (tag) {
+ case DM_TAG_PLAT:
+ return dev_get_plat(dev);
+ case DM_TAG_PARENT_PLAT:
+ return dev_get_parent_plat(dev);
+ case DM_TAG_UC_PLAT:
+ return dev_get_uclass_plat(dev);
+ case DM_TAG_PRIV:
+ return dev_get_priv(dev);
+ case DM_TAG_PARENT_PRIV:
+ return dev_get_parent_priv(dev);
+ case DM_TAG_UC_PRIV:
+ return dev_get_uclass_priv(dev);
+ default:
+ return NULL;
+ }
+}
+
+int dev_get_attach_size(const struct udevice *dev, enum dm_tag_t tag)
+{
+ const struct udevice *parent = dev_get_parent(dev);
+ const struct uclass *uc = dev->uclass;
+ const struct uclass_driver *uc_drv = uc->uc_drv;
+ const struct driver *parent_drv = NULL;
+ int size = 0;
+
+ if (parent)
+ parent_drv = parent->driver;
+
+ switch (tag) {
+ case DM_TAG_PLAT:
+ size = dev->driver->plat_auto;
+ break;
+ case DM_TAG_PARENT_PLAT:
+ if (parent) {
+ size = parent_drv->per_child_plat_auto;
+ if (!size)
+ size = parent->uclass->uc_drv->per_child_plat_auto;
+ }
+ break;
+ case DM_TAG_UC_PLAT:
+ size = uc_drv->per_device_plat_auto;
+ break;
+ case DM_TAG_PRIV:
+ size = dev->driver->priv_auto;
+ break;
+ case DM_TAG_PARENT_PRIV:
+ if (parent) {
+ size = parent_drv->per_child_auto;
+ if (!size)
+ size = parent->uclass->uc_drv->per_child_auto;
+ }
+ break;
+ case DM_TAG_UC_PRIV:
+ size = uc_drv->per_device_auto;
+ break;
+ default:
+ break;
+ }
+
+ return size;
+}
+
static int device_get_device_tail(struct udevice *dev, int ret,
struct udevice **devp)
{