RFC: dm: Add uclass adjunct support
Subsystems (14)
cover RFC: dm: Add uclass adjunct support
[Note: this is marked RFC as I am still not sure that this is the best approach. But this is my third redesign so I think it makes sense to get some feedback before trying to refine it further]
U-Boot's driver model requires each device to belong to exactly one uclass. Multi-function hardware must work around this by creating child devices in different uclasses via device_bind_driver_to_node(), with a NOP parent device.
This is quite common: at least 8 PMIC drivers bind sysreset children, every Qualcomm GCC driver (15+ platforms) does this and several PHY drivers bind clock children.
This series adds uclass adjuncts, which allow a device to register in additional uclasses without creating child devices. Each adjunct carries its own ops pointer, per-device uclass private/platform data, and sequence number.
With this series, uclass lookup and iteration functions include adjunct registrations alongside primary devices. The uclass_foreach_dev() iterator walks all entries in the uclass, including adjunct ones. Iterators that use a struct udevice * to iterate (uclass_find_first_device() etc.) only see primary devices, since they navigate via the embedded primary ucm.
A new ucm_ iterator API uses struct uclass_member * as the cursor, enabling adjunct-aware iteration and lookup. It provides find, probe, check, drvdata, seq and ofnode variants. uclass_foreach_dev_probe() uses this internally so that it includes adjuncts.
As a concrete example, a Qualcomm GCC driver could register as UCLASS_CLK (primary) with adjunct UCLASS_RESET and UCLASS_POWER_DOMAIN, thus removing the UCLASS_NOP container and the qcom_cc_bind() function. The raa215300 PMIC conversion in this series demonstrates the pattern: one device, no child sysreset driver, no dev_get_priv(dev->parent) indirection.
The mechanism is enabled by a new CONFIG_DM_UC_ADJUNCT option. Code size is largely neutral without this, except for the change to add dev_int_set_seq() which is used by PCI boards.
Note that a couple of linker-list fixes are included so that sandbox will start up correctly. It still does not pass all tests though, due to various bugs surfaced by this series. If we go ahead, we will need at least one precursor series to resolve these pre-existing problems.
This is an RFC. The next steps could be:
- Convert one Qualcomm GCC driver to use adjuncts
- Convert one RK8xx PMIC from child-sysreset to adjunct
- Update per-subsystem ops accessors (clk_dev_ops(), etc.)
Simon Glass (15):
dm: Fix linker list alignment for ll_entry_get()
linker_lists: Fix end-marker alignment to prevent padding
dm: Add a way to write the internal seq_ member
dm: Rename uclass to uclass_ and add an accessor
dm: Add struct uclass_member for uclass membership
dm: Embed struct uclass_member in struct udevice
dm: core: Add uclass-adjunct data structures
dm: core: Add a uclass-adjunct API
dm: core: Integrate adjuncts into existing code paths
dm: core: Add uclass-ID-keyed accessors for priv and plat
dm: core: Add static adjunct declarations for drivers
dm: test: Add tests for uclass adjuncts
doc: dm: Document uclass adjunct support
sysreset: Use device_get_uclass_ops() for adjunct support
power: pmic: raa215300: Convert sysreset to uclass adjunct
arch/arm/mach-rockchip/board.c | 2 +- arch/arm/mach-rockchip/rk3288/syscon_rk3288.c | 8 +- arch/sandbox/dts/test.dts | 4 + board/nuvoton/poleg_evb/poleg_evb.c | 4 +- board/theobroma-systems/common/common.c | 4 +- cmd/rng.c | 2 +- cmd/w1.c | 4 +- doc/develop/driver-model/design.rst | 134 ++++++ drivers/core/Kconfig | 10 + drivers/core/Makefile | 1 + drivers/core/adjunct.c | 249 ++++++++++ drivers/core/device-remove.c | 13 +- drivers/core/device.c | 72 ++- drivers/core/dump.c | 6 +- drivers/core/read.c | 2 +- drivers/core/uclass.c | 314 ++++++++++-- drivers/i2c/ast2600_i2c.c | 2 +- drivers/i2c/npcm_i2c.c | 2 +- drivers/misc/test_drv.c | 35 +- drivers/mmc/octeontx_hsmmc.c | 2 +- drivers/pci/pci-emul-uclass.c | 4 +- drivers/pci/pci-uclass.c | 2 +- drivers/pci/pcie_mediatek_gen3.c | 4 +- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/power/pmic/raa215300.c | 60 ++- drivers/serial/serial_s5p4418_pl011.c | 2 +- drivers/spi/spi-uclass.c | 4 +- drivers/sysreset/Kconfig | 3 + drivers/sysreset/Makefile | 1 - drivers/sysreset/sysreset_raa215300.c | 58 --- drivers/usb/host/ehci-mx6.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- drivers/video/video-uclass.c | 4 +- include/dm/device-internal.h | 186 ++++++- include/dm/device.h | 156 +++++- include/dm/read.h | 2 +- include/dm/uclass-internal.h | 8 + include/dm/uclass.h | 214 +++++++- include/linker_lists.h | 25 +- include/sysreset.h | 9 +- lib/efi_loader/efi_device_path.c | 4 +- net/eth-uclass.c | 2 +- test/dm/Makefile | 1 + test/dm/adjunct.c | 455 ++++++++++++++++++ test/dm/bus.c | 21 +- test/dm/core.c | 8 +- test/dm/test-fdt.c | 39 +- test/dm/test-uclass.c | 8 +- tools/dtoc/dtb_platdata.py | 34 +- tools/dtoc/test_dtoc.py | 121 +++-- 50 files changed, 1999 insertions(+), 312 deletions(-) create mode 100644 drivers/core/adjunct.c delete mode 100644 drivers/sysreset/sysreset_raa215300.c create mode 100644 test/dm/adjunct.c
Signature · 4 lines
2.43.0 base-commit: eb00c710508d09b2a3b9aca75dd18280f1304703 branch: dmc-us
RFC PATCH 1/15 dm: Fix linker list alignment for ll_entry_get()
From: Simon Glass <[email protected]>
The extern declaration in ll_entry_get() lacks the __aligned(4) attribute present in ll_entry_declare(). When the compiler sees an unaligned extern reference to a linker list entry in the same compilation unit as its definition, it may increase the section alignment beyond the expected struct size. This causes gaps in the linker list array, which the alignment checker reports as failures.
For example, sandbox_dir is both defined and referenced via DM_DRIVER_GET() in sandboxfs.c. The compiler applies 32-byte alignment to its section instead of the 4-byte alignment from the definition, creating an 8-byte gap before it in the driver list.
Add __aligned(4) to the extern declaration in ll_entry_get() to match ll_entry_declare()
---
include/linker_lists.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linker_lists.h +2 -1
@@ -266,7 +266,8 @@*/ #define ll_entry_get (_type, _name, _list) \ ({ \ - extern _type _u_boot_list_2_##_list##_2_##_name; \ + extern _type _u_boot_list_2_##_list##_2_##_name \ + __aligned(4); \ _type *_ll_result = \ &_u_boot_list_2_##_list##_2_##_name; \ _ll_result; \
Signature · 1 line
2.43.0
RFC PATCH 2/15 linker_lists: Fix end-marker alignment to prevent padding
In reply to Simon GlassFrom: Simon Glass <[email protected]>
Change the alignment of end markers in ll_entry_end() and ll_end_decl() from __aligned(4) and __aligned(CONFIG_LINKER_LIST_ALIGN) respectively to __aligned(1).
The linker places zero-size end markers at aligned boundaries based on what follows them. When the next list's start marker has a high alignment requirement (e.g., 32 bytes), padding gets inserted before the end marker. This causes the byte span (end - start) to not be an exact multiple of the struct size.
The compiler optimizes pointer subtraction (end - start) using magic-number multiplication for division. This optimization only produces correct results when the byte span is an exact multiple of the struct size. With padding, the result is garbage (e.g., -858993444 instead of 15).
By using __aligned(1), the end marker is placed immediately after the last entry with no padding, ensuring (end - start) equals exactly n * sizeof where n is the number of entries. This makes ll_entry_count() and direct pointer arithmetic work correctly.
---
include/linker_lists.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
include/linker_lists.h +20 -2
@@ -145,6 +145,20 @@* Since this macro defines an array end symbol, its leftmost index * must be 2 and its rightmost index must be 3. * +* The end symbol uses __aligned(1) to ensure it is placed immediately after +* the last entry without any padding. This is critical for ll_entry_count() +* to work correctly. +* +* If the end marker had a higher alignment (e.g., 4 or 32 bytes), the linker +* might insert padding between the last entry and the end marker to satisfy +* alignment requirements of the following section. This would cause pointer +* subtraction (end - start) to produce incorrect results because the compiler +* optimizes pointer division using magic-number multiplication, which only +* works correctly when the byte span is an exact multiple of the struct size. +* +* With __aligned(1), the end marker is placed at exactly (start + n * sizeof) +* where n is the number of entries, ensuring correct pointer arithmetic. +* * Example: * * ::
@@ -153,7 +167,7 @@*/ #define ll_entry_end (_type, _list) \ ({ \ - static char end[0] __aligned(4) __attribute__((unused)) \ + static char end[0] __aligned(1) __attribute__((unused)) \ __section("__u_boot_list_2_"#_list"_3"); \ _type * tmp = (_type *)&end; \ asm("":"+r"(tmp)); \
@@ -239,8 +253,12 @@ static _type _sym[0] __aligned(CONFIG_LINKER_LIST_ALIGN) \ __maybe_unused __section("__u_boot_list_2_" #_list "_1") +/* + * ll_end_decl uses __aligned(1) to avoid padding before the end marker. + * See the comment for ll_entry_end() for a full explanation. + */ #define ll_end_decl(_sym, _type, _list) \ - static _type _sym[0] __aligned(CONFIG_LINKER_LIST_ALIGN) \ + static _type _sym[0] __aligned(1) \ __maybe_unused __section("__u_boot_list_2_" #_list "_3") /**
Signature · 1 line
2.43.0
RFC PATCH 3/15 dm: Add a way to write the internal seq_ member
In reply to Simon GlassAdd a dev_int_set_seq() inline in device-internal.h to wrap writes to dev->seq_ from outside the driver-model core. This is the write side of dev_seq() and should be used only when absolutely necessary.
Use it in pci-uclass.c which is the only external caller that sets seq_ directly.
---
drivers/core/device.c | 5 +++++ drivers/pci/pci-uclass.c | 2 +- include/dm/device-internal.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/core/device.c +5 -0
@@ -1179,6 +1179,11 @@ void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat) dev->uclass_plat_ = uclass_plat; } +void dev_int_set_seq (struct udevice *dev,int seq) +{ + dev->seq_ = seq; +} +#if CONFIG_IS_ENABLED (OF_REAL )bool device_is_compatible (const struct udevice *dev,const char *compat) {
drivers/pci/pci-uclass.c +1 -1
@@ -1161,7 +1161,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) ret =uclass_get (UCLASS_PCI , &uc);if (ret)return ret; - bus->seq_ =uclass_find_next_free_seq (uc); +dev_int_set_seq (bus,uclass_find_next_free_seq (uc)); }/* For bridges, use the top-level PCI controller */
include/dm/device-internal.h +3 -0
@@ -437,4 +437,7 @@ static inline int device_notify(const struct udevice *dev, enum event_t type)return 0 ; #endif } + +void dev_int_set_seq (struct udevice *dev,int seq); +#endif
Signature · 1 line
2.43.0
RFC PATCH 4/15 dm: Rename uclass to uclass_ and add an accessor
In reply to Simon GlassRename the uclass field in struct udevice to uclass_ to match the trailing-underscore convention used by other internal fields such as seq_ and flags_
Add a dev_uclass() accessor for use outside driver model itself. The driver-model core files are left alone, since they are part of the implementation.
Update dtoc to generate the new field name, and update all callers throughout the tree.
---
arch/arm/mach-rockchip/rk3288/syscon_rk3288.c | 8 ++++---- cmd/w1.c | 4 ++-- drivers/core/device-remove.c | 4 ++-- drivers/core/device.c | 20 +++++++++---------- drivers/core/dump.c | 2 +- drivers/core/read.c | 2 +- drivers/core/uclass.c | 20 +++++++++---------- drivers/mmc/octeontx_hsmmc.c | 2 +- drivers/pci/pci-emul-uclass.c | 4 ++-- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/spi/spi-uclass.c | 4 ++-- drivers/usb/host/ehci-mx6.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- drivers/video/video-uclass.c | 4 ++-- include/dm/device-internal.h | 2 +- include/dm/device.h | 9 +++++++-- include/dm/read.h | 2 +- lib/efi_loader/efi_device_path.c | 4 ++-- net/eth-uclass.c | 2 +- test/dm/bus.c | 12 +++++------ test/dm/test-uclass.c | 2 +- tools/dtoc/dtb_platdata.py | 2 +- tools/dtoc/test_dtoc.py | 14 ++++++------- 23 files changed, 67 insertions(+), 62 deletions(-)
arch/arm/mach-rockchip/rk3288/syscon_rk3288.c +4 -4
@@ -48,7 +48,7 @@ static int rk3288_noc_bind_of_plat(struct udevice *dev) {struct rockchip_rk3288_noc_plat *plat =dev_get_plat (dev);struct syscon_uc_info *priv =dev_get_uclass_priv (dev); -int size = dev->uclass->uc_drv->per_device_auto; +int size =dev_uclass (dev)->uc_drv->per_device_auto;if (size && !priv) { priv =calloc (1 , size);
@@ -68,7 +68,7 @@ static int rk3288_grf_bind_of_plat(struct udevice *dev) {struct rockchip_rk3288_grf_plat *plat =dev_get_plat (dev);struct syscon_uc_info *priv =dev_get_uclass_priv (dev); -int size = dev->uclass->uc_drv->per_device_auto; +int size =dev_uclass (dev)->uc_drv->per_device_auto;if (size && !priv) { priv =calloc (1 , size);
@@ -88,7 +88,7 @@ static int rk3288_sgrf_bind_of_plat(struct udevice *dev) {struct rockchip_rk3288_sgrf_plat *plat =dev_get_plat (dev);struct syscon_uc_info *priv =dev_get_uclass_priv (dev); -int size = dev->uclass->uc_drv->per_device_auto; +int size =dev_uclass (dev)->uc_drv->per_device_auto;if (size && !priv) { priv =calloc (1 , size);
@@ -108,7 +108,7 @@ static int rk3288_pmu_bind_of_plat(struct udevice *dev) {struct rockchip_rk3288_pmu_plat *plat =dev_get_plat (dev);struct syscon_uc_info *priv =dev_get_uclass_priv (dev); -int size = dev->uclass->uc_drv->per_device_auto; +int size =dev_uclass (dev)->uc_drv->per_device_auto;if (size && !priv) { priv =calloc (1 , size);
cmd/w1.c +2 -2
@@ -31,7 +31,7 @@ static int w1_bus(void) ret =device_probe (dev);printf ("\t%s (%d) uclass %s : " , dev->name,dev_seq (dev), - dev->uclass->uc_drv->name); +dev_uclass (dev)->uc_drv->name);if (ret)printf ("device error\n" );
@@ -85,7 +85,7 @@ static int w1_read(int argc, char *const argv[])return CMD_RET_FAILURE ; } -if (strcmp (dev->uclass->uc_drv->name,"w1_eeprom" )) { +if (strcmp (dev_uclass (dev)->uc_drv->name,"w1_eeprom" )) {printf ("the device present on the interface is of unknown device class\n" );return CMD_RET_FAILURE ; }
drivers/core/device-remove.c +2 -2
@@ -137,7 +137,7 @@ void device_free(struct udevice *dev)free (dev_get_priv (dev));dev_set_priv (dev,NULL ); } - size = dev->uclass->uc_drv->per_device_auto; + size = dev->uclass_->uc_drv->per_device_auto;if (size) {free (dev_get_uclass_priv (dev));dev_set_uclass_priv (dev,NULL );
@@ -145,7 +145,7 @@ void device_free(struct udevice *dev)if (dev->parent) { size = dev->parent->driver->per_child_auto;if (!size) - size = dev->parent->uclass->uc_drv->per_child_auto; + size = dev->parent->uclass_->uc_drv->per_child_auto;if (size) {free (dev_get_parent_priv (dev));dev_set_parent_priv (dev,NULL );
drivers/core/device.c +10 -10
@@ -78,7 +78,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,dev_set_ofnode (dev, node); dev->parent = parent; dev->driver = drv; - dev->uclass = uc; + dev->uclass_ = uc; dev->seq_ =-1 ; if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
@@ -146,7 +146,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,if (parent) { size = parent->driver->per_child_plat_auto;if (!size) - size = parent->uclass->uc_drv->per_child_plat_auto; + size = parent->uclass_->uc_drv->per_child_plat_auto;if (size) {dev_or_flags (dev,DM_FLAG_ALLOC_PARENT_PDATA ); ptr =calloc (1 , size);
@@ -362,9 +362,9 @@ static int device_alloc_priv(struct udevice *dev) }/* Allocate private data if requested and not reentered */ - size = dev->uclass->uc_drv->per_device_auto; + size = dev->uclass_->uc_drv->per_device_auto;if (size && !dev_get_uclass_priv (dev)) { - ptr =alloc_priv (size, dev->uclass->uc_drv->flags); + ptr =alloc_priv (size, dev->uclass_->uc_drv->flags);if (!ptr)return -ENOMEM ;dev_set_uclass_priv (dev, ptr);
@@ -374,7 +374,7 @@ static int device_alloc_priv(struct udevice *dev)if (dev->parent) { size = dev->parent->driver->per_child_auto;if (!size) - size = dev->parent->uclass->uc_drv->per_child_auto; + size = dev->parent->uclass_->uc_drv->per_child_auto;if (size && !dev_get_parent_priv (dev)) { ptr =alloc_priv (size, drv->flags);if (!ptr)
@@ -700,7 +700,7 @@ void *dev_get_attach_ptr(const struct udevice *dev, enum dm_tag_t tag)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 *uc = dev->uclass_;const struct uclass_driver *uc_drv = uc->uc_drv;const struct driver *parent_drv =NULL ;int size =0 ;
@@ -716,7 +716,7 @@ int dev_get_attach_size(const struct udevice *dev, enum dm_tag_t tag)if (parent) { size = parent_drv->per_child_plat_auto;if (!size) - size = parent->uclass->uc_drv->per_child_plat_auto; + size = parent->uclass_->uc_drv->per_child_plat_auto; }break ;case DM_TAG_UC_PLAT :
@@ -729,7 +729,7 @@ int dev_get_attach_size(const struct udevice *dev, enum dm_tag_t tag)if (parent) { size = parent_drv->per_child_auto;if (!size) - size = parent->uclass->uc_drv->per_child_auto; + size = parent->uclass_->uc_drv->per_child_auto; }break ;case DM_TAG_UC_PRIV :
@@ -1094,7 +1094,7 @@ const void *dev_get_driver_ops(const struct udevice *dev)enum uclass_id device_get_uclass_id (const struct udevice *dev) { -return dev->uclass->uc_drv->id; +return dev->uclass_->uc_drv->id; }const char *dev_get_uclass_name (const struct udevice *dev)
@@ -1102,7 +1102,7 @@ const char *dev_get_uclass_name(const struct udevice *dev)if (!dev)return NULL ; -return dev->uclass->uc_drv->name; +return dev->uclass_->uc_drv->name; }bool device_has_children (const struct udevice *dev)
drivers/core/dump.c +1 -1
@@ -39,7 +39,7 @@ static void show_devices(struct udevice *dev, int depth, int last_flag,/* print the first 20 characters to not break the tree-format. */ printf (CONFIG_IS_ENABLED (USE_TINY_PRINTF ) ?" %s %d [ %c ] %s " : -" %-10.10s %3d [ %c ] %-20.20s " , dev->uclass->uc_drv->name, +" %-10.10s %3d [ %c ] %-20.20s " , dev->uclass_->uc_drv->name, dev->seq_, flags &DM_FLAG_ACTIVATED ?'+' :' ' , dev->driver->name);
drivers/core/read.c +1 -1
@@ -347,7 +347,7 @@ const void *dev_read_prop_by_prop(struct ofprop *prop,int dev_read_alias_seq (const struct udevice *dev,int *devnump) {ofnode node =dev_ofnode (dev); -const char *uc_name = dev->uclass->uc_drv->name; +const char *uc_name = dev->uclass_->uc_drv->name;int ret = -ENOTSUPP ;if (ofnode_is_np (node)) {
drivers/core/uclass.c +10 -10
@@ -203,7 +203,7 @@ enum uclass_id uclass_get_by_name(const char *name)int dev_get_uclass_index (struct udevice *dev,struct uclass **ucp) {struct udevice *iter; -struct uclass *uc = dev->uclass; +struct uclass *uc = dev->uclass_;int i =0 ;if (list_empty (&uc->dev_head))
@@ -266,7 +266,7 @@ void uclass_find_next_device(struct udevice **devp)struct udevice *dev = *devp; *devp =NULL ; -if (!list_is_last (&dev->uclass_node, &dev->uclass->dev_head)) +if (!list_is_last (&dev->uclass_node, &dev->uclass_->dev_head)) *devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node); }
@@ -715,11 +715,11 @@ int uclass_bind_device(struct udevice *dev)struct uclass *uc;int ret; - uc = dev->uclass; + uc = dev->uclass_;list_add_tail (&dev->uclass_node, &uc->dev_head);if (dev->parent) { -struct uclass_driver *uc_drv = dev->parent->uclass->uc_drv; +struct uclass_driver *uc_drv = dev->parent->uclass_->uc_drv;if (uc_drv->child_post_bind) { ret = uc_drv->child_post_bind (dev);
@@ -742,7 +742,7 @@ int uclass_pre_unbind_device(struct udevice *dev)struct uclass *uc;int ret; - uc = dev->uclass; + uc = dev->uclass_;if (uc->uc_drv->pre_unbind) { ret = uc->uc_drv->pre_unbind (dev);if (ret)
@@ -765,7 +765,7 @@ int uclass_pre_probe_device(struct udevice *dev)struct uclass_driver *uc_drv;int ret; - uc_drv = dev->uclass->uc_drv; + uc_drv = dev->uclass_->uc_drv;if (uc_drv->pre_probe) { ret = uc_drv->pre_probe (dev);if (ret)
@@ -774,7 +774,7 @@ int uclass_pre_probe_device(struct udevice *dev)if (!dev->parent)return 0 ; - uc_drv = dev->parent->uclass->uc_drv; + uc_drv = dev->parent->uclass_->uc_drv;if (uc_drv->child_pre_probe) { ret = uc_drv->child_pre_probe (dev);if (ret)
@@ -790,7 +790,7 @@ int uclass_post_probe_device(struct udevice *dev)int ret;if (dev->parent) { - uc_drv = dev->parent->uclass->uc_drv; + uc_drv = dev->parent->uclass_->uc_drv;if (uc_drv->child_post_probe) { ret = uc_drv->child_post_probe (dev);if (ret)
@@ -798,7 +798,7 @@ int uclass_post_probe_device(struct udevice *dev) } } - uc_drv = dev->uclass->uc_drv; + uc_drv = dev->uclass_->uc_drv;if (uc_drv->post_probe) { ret = uc_drv->post_probe (dev);if (ret)
@@ -814,7 +814,7 @@ int uclass_pre_remove_device(struct udevice *dev)struct uclass *uc;int ret; - uc = dev->uclass; + uc = dev->uclass_;if (uc->uc_drv->pre_remove) { ret = uc->uc_drv->pre_remove (dev);if (ret)
drivers/mmc/octeontx_hsmmc.c +1 -1
@@ -3962,7 +3962,7 @@ static int octeontx_mmc_host_child_pre_probe(struct udevice *dev)/* * FIXME: This is not allowed * dev_set_uclass_priv(dev, upriv); -* uclass_set_priv(dev->uclass, upriv); +* uclass_set_priv(dev_uclass(dev), upriv); */ }else { upriv =dev_get_uclass_priv (dev);
drivers/pci/pci-emul-uclass.c +2 -2
@@ -81,7 +81,7 @@ uint sandbox_pci_read_bar(u32 barval, int type, uint size)static int sandbox_pci_emul_post_probe (struct udevice *dev) { -struct sandbox_pci_emul_priv *priv =uclass_get_priv (dev->uclass); +struct sandbox_pci_emul_priv *priv =uclass_get_priv (dev_uclass (dev)); priv->dev_count++;sandbox_set_enable_pci_map (true);
@@ -91,7 +91,7 @@ static int sandbox_pci_emul_post_probe(struct udevice *dev)static int sandbox_pci_emul_pre_remove (struct udevice *dev) { -struct sandbox_pci_emul_priv *priv =uclass_get_priv (dev->uclass); +struct sandbox_pci_emul_priv *priv =uclass_get_priv (dev_uclass (dev)); priv->dev_count--;sandbox_set_enable_pci_map (priv->dev_count >0 );
drivers/pinctrl/pinctrl-uclass.c +1 -1
@@ -37,7 +37,7 @@ static int pinctrl_config_one(struct udevice *config)dev_err (config,"could not find pctldev\n" );return -EINVAL ; } -if (pctldev->uclass->uc_drv->id ==UCLASS_PINCTRL ) +if (dev_uclass (pctldev)->uc_drv->id ==UCLASS_PINCTRL )break ; }
drivers/spi/spi-uclass.c +2 -2
@@ -94,7 +94,7 @@ int dm_spi_xfer(struct udevice *dev, unsigned int bitlen,struct udevice *bus = dev->parent;struct dm_spi_ops *ops =spi_get_ops (bus); -if (bus->uclass->uc_drv->id !=UCLASS_SPI ) +if (dev_uclass (bus)->uc_drv->id !=UCLASS_SPI )return -EOPNOTSUPP ;if (!ops->xfer)return -ENOSYS ;
@@ -108,7 +108,7 @@ int dm_spi_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep,struct udevice *bus = dev->parent;struct dm_spi_ops *ops =spi_get_ops (bus); -if (bus->uclass->uc_drv->id !=UCLASS_SPI ) +if (dev_uclass (bus)->uc_drv->id !=UCLASS_SPI )return -EOPNOTSUPP ;if (!ops->get_mmap)return -ENOSYS ;
drivers/usb/host/ehci-mx6.c +1 -1
@@ -609,7 +609,7 @@ static int mx6_parse_dt_addrs(struct udevice *dev)#if defined(CONFIG_MX6 )int anatop_off, ret, devnump; - ret =fdtdec_get_alias_seq (blob, dev->uclass->uc_drv->name, + ret =fdtdec_get_alias_seq (blob,dev_uclass (dev)->uc_drv->name, phy_off, &devnump);if (ret <0 )return ret;
drivers/usb/host/usb-uclass.c +1 -1
@@ -63,7 +63,7 @@ int submit_control_msg(struct usb_device *udev, unsigned long pipe, {struct udevice *bus = udev->controller_dev;struct dm_usb_ops *ops =usb_get_ops (bus); -struct usb_uclass_priv *uc_priv =uclass_get_priv (bus->uclass); +struct usb_uclass_priv *uc_priv =uclass_get_priv (dev_uclass (bus));int err;if (!ops->control)
drivers/video/video-uclass.c +2 -2
@@ -634,7 +634,7 @@ void video_set_white_on_black(struct udevice *dev, bool white_on_black)static int video_post_probe (struct udevice *dev) {struct video_uc_plat *plat =dev_get_uclass_plat (dev); -struct video_uc_priv *uc_priv =uclass_get_priv (dev->uclass); +struct video_uc_priv *uc_priv =uclass_get_priv (dev_uclass (dev));struct video_priv *priv =dev_get_uclass_priv (dev);char name[30 ], drv[15 ], *str;const char *drv_name = drv;
@@ -753,7 +753,7 @@ static int video_post_bind(struct udevice *dev)return 0 ;/* Set up the video pointer, if this is the first device */ - uc_priv =uclass_get_priv (dev->uclass); + uc_priv =uclass_get_priv (dev_uclass (dev));if (!uc_priv->video_ptr) uc_priv->video_ptr = gd->video_top;
include/dm/device-internal.h +1 -1
@@ -42,7 +42,7 @@ struct udevice;* .driver = DM_DRIVER_REF(sandbox_fixed_clock), * .name = "sandbox_fixed_clock", * .plat_ = &_sandbox_fixed_clock_plat_clk_fixed, -* .uclass = DM_UCLASS_REF(clk), +* .uclass_ = DM_UCLASS_REF(clk), * ... * .seq_ = 0, * };
include/dm/device.h +7 -2
@@ -144,7 +144,7 @@ enum {* its driver * @parent: Parent of this device, or NULL for the top level device * @priv_: Private data for this device (do not access outside driver model) -* @uclass: Pointer to uclass for this device +* @uclass_: Pointer to uclass 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
@@ -179,7 +179,7 @@ struct udevice {ulong driver_data;struct udevice *parent;void *priv_; -struct uclass *uclass; +struct uclass *uclass_;void *uclass_priv_;void *parent_priv_;struct list_head uclass_node;
@@ -310,6 +310,11 @@ static inline int dev_seq(const struct udevice *dev)return dev->seq_; } +static inline struct uclass *dev_uclass (const struct udevice *dev) +{ +return dev->uclass_; +} +/** * struct udevice_id - Lists the compatible strings supported by a driver * @compatible: Compatible string
include/dm/read.h +1 -1
@@ -1169,7 +1169,7 @@ static inline const void *dev_read_prop_by_prop(struct ofprop *prop,static inline int dev_read_alias_seq (const struct udevice *dev,int *devnump) {#if CONFIG_IS_ENABLED (OF_CONTROL ) -return fdtdec_get_alias_seq (gd->fdt_blob, dev->uclass->uc_drv->name, +return fdtdec_get_alias_seq (gd->fdt_blob,dev_uclass (dev)->uc_drv->name,dev_of_offset (dev), devnump);#else return -ENOTSUPP ;
lib/efi_loader/efi_device_path.c +2 -2
@@ -405,7 +405,7 @@ __maybe_unused static unsigned int dp_size(struct udevice *dev)return dp_size (dev->parent) +sizeof (struct efi_device_path_mac_addr );case UCLASS_BLK : -switch (dev->parent->uclass->uc_drv->id) { +switch (dev_uclass (dev->parent)->uc_drv->id) {#ifdef CONFIG_IDE case UCLASS_IDE : return dp_size(dev->parent) +
@@ -638,7 +638,7 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev) vdp->dp.length =sizeof (*vdp);memcpy (&vdp->guid, &efi_u_boot_guid,sizeof (efi_guid_t)); vdp->uclass_id = uclass_id; - vdp->dev_number = dev->seq_; + vdp->dev_number =dev_seq (dev);return &vdp[1 ]; }
net/eth-uclass.c +1 -1
@@ -529,7 +529,7 @@ int eth_initialize(void)static int eth_post_bind (struct udevice *dev) { -struct eth_uclass_priv *priv =uclass_get_priv (dev->uclass); +struct eth_uclass_priv *priv =uclass_get_priv (dev_uclass (dev));int ret;if (strchr (dev->name,' ' )) {
test/dm/bus.c +6 -6
@@ -219,15 +219,15 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts) size = drv->per_child_auto;#ifdef CONFIG_SANDBOX -os_mprotect_allow (bus->uclass->uc_drv,sizeof (*bus->uclass->uc_drv)); +os_mprotect_allow (bus->uclass_->uc_drv,sizeof (*bus->uclass_->uc_drv));os_mprotect_allow (drv,sizeof (*drv));#endif - bus->uclass->uc_drv->per_child_auto = size; + bus->uclass_->uc_drv->per_child_auto = size; drv->per_child_auto =0 ; ret =test_bus_parent_data (uts);if (ret)return ret; - bus->uclass->uc_drv->per_child_auto =0 ; + bus->uclass_->uc_drv->per_child_auto =0 ; drv->per_child_auto = size;return 0 ;
@@ -360,15 +360,15 @@ static int dm_test_bus_parent_plat_uclass(struct unit_test_state *uts) drv = (struct driver *)bus->driver; size = drv->per_child_plat_auto;#ifdef CONFIG_SANDBOX -os_mprotect_allow (bus->uclass->uc_drv,sizeof (*bus->uclass->uc_drv)); +os_mprotect_allow (bus->uclass_->uc_drv,sizeof (*bus->uclass_->uc_drv));os_mprotect_allow (drv,sizeof (*drv));#endif - bus->uclass->uc_drv->per_child_plat_auto = size; + bus->uclass_->uc_drv->per_child_plat_auto = size; drv->per_child_plat_auto =0 ; ret =test_bus_parent_plat (uts);if (ret)return ret; - bus->uclass->uc_drv->per_child_plat_auto =0 ; + bus->uclass_->uc_drv->per_child_plat_auto =0 ; drv->per_child_plat_auto = size;return 0 ;
test/dm/test-uclass.c +1 -1
@@ -70,7 +70,7 @@ static int test_post_probe(struct udevice *dev) struct udevice, uclass_node);struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev); -struct uclass *uc = dev->uclass; +struct uclass *uc = dev->uclass_; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]++;ut_assert (priv);
tools/dtoc/dtb_platdata.py +1 -1
@@ -763,7 +763,7 @@ class DtbPlatdata(): node.parent.var_name) if priv_name: self.buf('\t.priv_\t\t= %s,\n' % priv_name) - self.buf('\t.uclass\t\t= DM_UCLASS_REF(%s),\n' % uclass.name) + self.buf('\t.uclass_\t= DM_UCLASS_REF(%s),\n' % uclass.name) if uclass_priv_name: self.buf('\t.uclass_priv_ = %s,\n' % uclass_priv_name)
tools/dtoc/test_dtoc.py +7 -7
@@ -558,7 +558,7 @@ DM_DEVICE_INST(i2c) = { \t.name\t\t= "sandbox_i2c", \t.plat_\t\t= &dtv_i2c, \t.priv_\t\t= _sandbox_i2c_priv_i2c, -\t.uclass\t\t= DM_UCLASS_REF(i2c), +\t.uclass_\t= DM_UCLASS_REF(i2c), \t.uclass_priv_ = _sandbox_i2c_uc_priv_i2c, \t.uclass_node\t= { \t\t.prev = &DM_UCLASS_REF(i2c)->dev_head,
@@ -586,7 +586,7 @@ DM_DEVICE_INST(root) = { \t.driver\t\t= DM_DRIVER_REF(root_driver), \t.name\t\t= "root_driver", \t.plat_\t\t= &dtv_root, -\t.uclass\t\t= DM_UCLASS_REF(root), +\t.uclass_\t= DM_UCLASS_REF(root), \t.uclass_node\t= { \t\t.prev = &DM_UCLASS_REF(root)->dev_head, \t\t.next = &DM_UCLASS_REF(root)->dev_head,
@@ -630,7 +630,7 @@ DM_DEVICE_INST(some_bus) = { \t.uclass_plat_\t= _denx_u_boot_test_bus_ucplat_some_bus, \t.driver_data\t= DM_TEST_TYPE_FIRST, \t.priv_\t\t= _denx_u_boot_test_bus_priv_some_bus, -\t.uclass\t\t= DM_UCLASS_REF(testbus), +\t.uclass_\t= DM_UCLASS_REF(testbus), \t.uclass_priv_ = _denx_u_boot_test_bus_uc_priv_some_bus, \t.uclass_node\t= { \t\t.prev = &DM_UCLASS_REF(testbus)->dev_head,
@@ -660,7 +660,7 @@ DM_DEVICE_INST(spl_test) = { \t.driver\t\t= DM_DRIVER_REF(sandbox_spl_test), \t.name\t\t= "sandbox_spl_test", \t.plat_\t\t= &dtv_spl_test, -\t.uclass\t\t= DM_UCLASS_REF(misc), +\t.uclass_\t= DM_UCLASS_REF(misc), \t.uclass_node\t= { \t\t.prev = &DM_UCLASS_REF(misc)->dev_head, \t\t.next = &DM_DEVICE_REF(spl_test3)->uclass_node,
@@ -689,7 +689,7 @@ DM_DEVICE_INST(spl_test3) = { \t.driver\t\t= DM_DRIVER_REF(sandbox_spl_test), \t.name\t\t= "sandbox_spl_test", \t.plat_\t\t= &dtv_spl_test3, -\t.uclass\t\t= DM_UCLASS_REF(misc), +\t.uclass_\t= DM_UCLASS_REF(misc), \t.uclass_node\t= { \t\t.prev = &DM_DEVICE_REF(spl_test)->uclass_node, \t\t.next = &DM_UCLASS_REF(misc)->dev_head,
@@ -737,7 +737,7 @@ DM_DEVICE_INST(test) = { \t.driver_data\t= DM_TEST_TYPE_FIRST, \t.parent\t\t= DM_DEVICE_REF(some_bus), \t.priv_\t\t= _denx_u_boot_fdt_test_priv_test, -\t.uclass\t\t= DM_UCLASS_REF(testfdt), +\t.uclass_\t= DM_UCLASS_REF(testfdt), \t.parent_priv_\t= _denx_u_boot_fdt_test_parent_priv_test, \t.uclass_node\t= { \t\t.prev = &DM_UCLASS_REF(testfdt)->dev_head,
@@ -783,7 +783,7 @@ DM_DEVICE_INST(test0) = { \t.driver_data\t= DM_TEST_TYPE_SECOND, \t.parent\t\t= DM_DEVICE_REF(some_bus), \t.priv_\t\t= _denx_u_boot_fdt_test_priv_test0, -\t.uclass\t\t= DM_UCLASS_REF(testfdt), +\t.uclass_\t= DM_UCLASS_REF(testfdt), \t.parent_priv_\t= _denx_u_boot_fdt_test_parent_priv_test0, \t.uclass_node\t= { \t\t.prev = &DM_DEVICE_REF(test)->uclass_node,
Signature · 1 line
2.43.0
RFC PATCH 5/15 dm: Add struct uclass_member for uclass membership
In reply to Simon GlassWe want to support linking a device into a secondary uclass. Add a new struct hold the require information.
For now this struct is not actually used.
---
include/dm/device.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
include/dm/device.h +34 -0
@@ -115,6 +115,40 @@ enum { DM_REMOVE_NO_PD = 1 << 1, }; +/** +* struct uclass_member - a device's membership in a uclass +* +* This holds the information needed to link a device into a uclass. Every +* device has one of these embedded in struct udevice for its primary uclass. +* When DM_UC_ADJUNCT is enabled, additional instances can be allocated to +* register a device in further uclasses (adjuncts). +* +* This struct should not be used outside core driver-model code and tests. +* Use accessor functions instead. +* +* @uc: Pointer to the uclass +* @uc_node: Node in the uclass's device list +* @uc_priv: Per-device private data owned by the uclass +* @uc_plat: Per-device platform data owned by the uclass +* @seq: Sequence number within this uclass (-1 = none) +* @ops: Ops provided by this device for the uclass +* @dev: Owning device (adjuncts only; for the primary uclass use +* container_of) +* @adj_node: Node in the device's list of adjuncts +*/ +struct uclass_member { +struct uclass *uc; +struct list_head uc_node; +void *uc_priv; +void *uc_plat; +int seq; +const void *ops; +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +struct udevice *dev; +struct list_head adj_node; +#endif +}; +/** * struct udevice - An instance of a driver *
Signature · 1 line
2.43.0
RFC PATCH 6/15 dm: Embed struct uclass_member in struct udevice
In reply to Simon GlassReplace the individual uclass-membership fields in struct udevice (uclass_, uclass_priv_, uclass_plat_, uclass_node, seq_) with an embedded struct uclass_member. This groups the uclass-membership state into a single struct that can also (later) be allocated independently for adjunct uclass-registrations.
Update the affected accessors and the dtoc tool.
---
arch/arm/mach-rockchip/board.c | 2 +- board/nuvoton/poleg_evb/poleg_evb.c | 4 +- board/theobroma-systems/common/common.c | 4 +- cmd/rng.c | 2 +- drivers/core/device-remove.c | 4 +- drivers/core/device.c | 44 ++++----- drivers/core/dump.c | 6 +- drivers/core/read.c | 2 +- drivers/core/uclass.c | 46 +++++----- drivers/i2c/ast2600_i2c.c | 2 +- drivers/i2c/npcm_i2c.c | 2 +- drivers/pci/pcie_mediatek_gen3.c | 4 +- drivers/serial/serial_s5p4418_pl011.c | 2 +- include/dm/device.h | 23 +---- include/dm/uclass.h | 6 +- test/dm/bus.c | 12 +-- test/dm/core.c | 8 +- test/dm/test-uclass.c | 8 +- tools/dtoc/dtb_platdata.py | 33 +++---- tools/dtoc/test_dtoc.py | 114 +++++++++++++----------- 20 files changed, 165 insertions(+), 163 deletions(-)
arch/arm/mach-rockchip/board.c +1 -1
@@ -531,7 +531,7 @@ int mmc_get_env_dev(void)return devnum; } - devnum = dev->seq_; + devnum =dev_seq (dev);debug ("%s: get MMC env from mmc%d\n" , __func__, devnum);return devnum; }
board/nuvoton/poleg_evb/poleg_evb.c +2 -2
@@ -55,14 +55,14 @@ static int last_stage_init(void)env_set ("mem" , value); } -if (dev && (dev->seq_ >=0 )) { +if (dev && (dev_seq (dev) >=0 )) {void *addr; addr =dev_read_addr_ptr (dev);if (addr) {sprintf (value,"uart8250,mmio32,0x%x" , (u32 )addr);env_set ("earlycon" , value); } -sprintf (value,"ttyS%d,115200n8" , dev->seq_); +sprintf (value,"ttyS%d,115200n8" ,dev_seq (dev));env_set ("console" , value);#ifdef CONFIG_SYS_SKIP_UART_INIT return board_set_console ();
board/theobroma-systems/common/common.c +2 -2
@@ -78,8 +78,8 @@ int setup_boottargets(void)* If mmc1 comes first in the boot order and U-Boot proper was * loaded from mmc0, swap mmc0 and mmc1 in the list. */ -if ((mmc0 < mmc1 && devp->seq_ ==1 ) || - (mmc0 > mmc1 && devp->seq_ ==0 )) { +if ((mmc0 < mmc1 &&dev_seq (devp) ==1 ) || + (mmc0 > mmc1 &&dev_seq (devp) ==0 )) { mmc0[3 ] ='1' ; mmc1[3 ] ='0' ;debug ("%s: set boot_targets to: %s\n" , __func__, env);
cmd/rng.c +1 -1
@@ -23,7 +23,7 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) uclass_foreach_dev_probe(UCLASS_RNG, dev) { idx++; -printf ("RNG #%d - %s\n" , dev->seq_, dev->name); +printf ("RNG #%d - %s\n" ,dev_seq (dev), dev->name); }if (!idx) {
drivers/core/device-remove.c +2 -2
@@ -137,7 +137,7 @@ void device_free(struct udevice *dev)free (dev_get_priv (dev));dev_set_priv (dev,NULL ); } - size = dev->uclass_->uc_drv->per_device_auto; + size = dev->ucm.uc->uc_drv->per_device_auto;if (size) {free (dev_get_uclass_priv (dev));dev_set_uclass_priv (dev,NULL );
@@ -145,7 +145,7 @@ void device_free(struct udevice *dev)if (dev->parent) { size = dev->parent->driver->per_child_auto;if (!size) - size = dev->parent->uclass_->uc_drv->per_child_auto; + size = dev->parent->ucm.uc->uc_drv->per_child_auto;if (size) {free (dev_get_parent_priv (dev));dev_set_parent_priv (dev,NULL );
drivers/core/device.c +23 -21
160 lines not on this page · raw message
drivers/core/dump.c +3 -3
@@ -39,8 +39,8 @@ static void show_devices(struct udevice *dev, int depth, int last_flag,/* print the first 20 characters to not break the tree-format. */ printf (CONFIG_IS_ENABLED (USE_TINY_PRINTF ) ?" %s %d [ %c ] %s " : -" %-10.10s %3d [ %c ] %-20.20s " , dev->uclass_->uc_drv->name, - dev->seq_, +" %-10.10s %3d [ %c ] %-20.20s " , dev->ucm.uc->uc_drv->name, + dev->ucm.seq, flags &DM_FLAG_ACTIVATED ?'+' :' ' , dev->driver->name);for (i = depth; i >=0 ; i--) {
@@ -156,7 +156,7 @@ static void dm_display_line(struct udevice *dev, int index)printf ("%-3i %c %s @ %08lx" , index,dev_get_flags (dev) &DM_FLAG_ACTIVATED ?'*' :' ' , dev->name, (ulong )map_to_sysmem (dev)); -if (dev->seq_ !=-1 ) +if (dev->ucm.seq !=-1 )printf (", seq %d" ,dev_seq (dev));puts ("\n" ); }
drivers/core/read.c +1 -1
@@ -347,7 +347,7 @@ const void *dev_read_prop_by_prop(struct ofprop *prop,int dev_read_alias_seq (const struct udevice *dev,int *devnump) {ofnode node =dev_ofnode (dev); -const char *uc_name = dev->uclass_->uc_drv->name; +const char *uc_name = dev->ucm.uc->uc_drv->name;int ret = -ENOTSUPP ;if (ofnode_is_np (node)) {
drivers/core/uclass.c +23 -23
144 lines not on this page · raw message
drivers/i2c/ast2600_i2c.c +1 -1
@@ -183,7 +183,7 @@ static int ast2600_i2c_set_speed(struct udevice *dev, unsigned int speed)int inc =0 ;u32 data; -debug ("Setting speed for I2C%d to <%u>\n" , dev->seq_, speed); +debug ("Setting speed for I2C%d to <%u>\n" ,dev_seq (dev), speed);if (!speed) {debug ("No valid speed specified\n" );return -EINVAL ;
drivers/i2c/npcm_i2c.c +1 -1
@@ -578,7 +578,7 @@ static int npcm_i2c_probe(struct udevice *dev)return -EINVAL ; } - bus->num = dev->seq_; + bus->num =dev_seq (dev); bus->reg =dev_read_addr_ptr (dev); bus->freq =dev_read_u32_default (dev,"clock-frequency" ,100000 ); bus->started = false;
drivers/pci/pcie_mediatek_gen3.c +2 -2
@@ -97,10 +97,10 @@ static pci_dev_t convert_bdf(const struct udevice *controller, pci_dev_t bdf)* external PCIe device. If multiple PCIe controllers are probed in U-Boot, * U-Boot will use bus numbers greater than 2 as input parameters. Therefore, * we should convert the BDF bus number to either 0 or 1 by subtracting the -* offset by controller->seq_ +* offset by dev_seq(controller) */ - bdfs[0 ] = bdfs[0 ] - controller->seq_; + bdfs[0 ] = bdfs[0 ] -dev_seq (controller);return PCI_BDF (bdfs[0 ], bdfs[1 ], bdfs[2 ]); }
drivers/serial/serial_s5p4418_pl011.c +1 -1
@@ -22,7 +22,7 @@ int s5p4418_pl011_serial_probe(struct udevice *dev)int rst_id, ret;if (!plat->skip_init) { - uart_num = dev->seq_; + uart_num =dev_seq (dev); rst_id =RESET_ID_UART0 + uart_num;if (uart_num <0 || rst_id >RESET_ID_UART5 ) {
include/dm/device.h +4 -19
@@ -172,28 +172,17 @@ struct uclass_member {* model) * @parent_plat_: The parent bus's configuration data for this device (do not * access outside driver model) -* @uclass_plat_: The uclass's configuration data for this device (do not access -* outside driver model) * @driver_data: Driver data word for the entry that matched this device with * its driver * @parent: Parent of this device, or NULL for the top level device * @priv_: Private data for this device (do not access outside driver model) -* @uclass_: Pointer to uclass for this device -* @uclass_priv_: The uclass's private data for this device (do not access -* outside driver model) +* @ucm: Primary uclass membership (do not access outside driver model) * @parent_priv_: The parent's private data for this device (do not access * outside driver model) -* @uclass_node: Used by uclass to link its devices * @child_head: List of children of this device * @sibling_node: Next device in list of all devices * @flags_: Flags for this device `DM_FLAG_...` (do not access outside driver * model) -* @seq_: Allocated sequence number for this device (-1 = none). This is set up -* when the device is bound and is unique within the device's uclass. If the -* device has an alias in the devicetree then that is used to set the sequence -* number. Otherwise, the next available number is used. Sequence numbers are -* used by certain commands that need device to be numbered (e.g. 'mmc dev'). -* (do not access outside driver model) * @node_: Reference to device tree node for this device (do not access outside * driver model) * @devres_head: List of memory allocations associated with this device.
@@ -209,20 +198,16 @@ struct udevice {const char *name;void *plat_;void *parent_plat_; -void *uclass_plat_;ulong driver_data;struct udevice *parent;void *priv_; -struct uclass *uclass_; -void *uclass_priv_; +struct uclass_member ucm;void *parent_priv_; -struct list_head uclass_node;struct list_head child_head;struct list_head sibling_node;#if !CONFIG_IS_ENABLED (OF_PLATDATA_RT )u32 flags_;#endif -int seq_;#if CONFIG_IS_ENABLED (OF_REAL )ofnode node_;#endif
@@ -341,12 +326,12 @@ static inline void dev_set_ofnode(struct udevice *dev, ofnode node)static inline int dev_seq (const struct udevice *dev) { -return dev->seq_; +return dev->ucm.seq; }static inline struct uclass *dev_uclass (const struct udevice *dev) { -return dev->uclass_; +return dev->ucm.uc; }/**
include/dm/uclass.h +3 -3
@@ -504,7 +504,7 @@ int uclass_id_count(enum uclass_id id);*/ #define uclass_id_foreach_dev (id, pos, uc) \ if (!uclass_get(id, &uc)) \ - list_for_each_entry(pos, &uc->dev_head, uclass_node) + list_for_each_entry(pos, &uc->dev_head, ucm.uc_node)/** * uclass_foreach_dev() - iterate through devices of a given uclass
@@ -517,7 +517,7 @@ int uclass_id_count(enum uclass_id id);* @uc: uclass to scan (`struct uclass *`) */ #define uclass_foreach_dev (pos, uc) \ - list_for_each_entry(pos, &uc->dev_head, uclass_node) + list_for_each_entry(pos, &uc->dev_head, ucm.uc_node)/** * uclass_foreach_dev_safe() - safely iterate through devices of a given uclass
@@ -532,7 +532,7 @@ int uclass_id_count(enum uclass_id id);* @uc: uclass to scan (`struct uclass *`) */ #define uclass_foreach_dev_safe (pos, next, uc) \ - list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node) + list_for_each_entry_safe(pos, next, &uc->dev_head, ucm.uc_node)/** * uclass_foreach_dev_probe() - iterate through devices of a given uclass ID
test/dm/bus.c +6 -6
@@ -219,15 +219,15 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts) size = drv->per_child_auto;#ifdef CONFIG_SANDBOX -os_mprotect_allow (bus->uclass_->uc_drv,sizeof (*bus->uclass_->uc_drv)); +os_mprotect_allow (bus->ucm.uc->uc_drv,sizeof (*bus->ucm.uc->uc_drv));os_mprotect_allow (drv,sizeof (*drv));#endif - bus->uclass_->uc_drv->per_child_auto = size; + bus->ucm.uc->uc_drv->per_child_auto = size; drv->per_child_auto =0 ; ret =test_bus_parent_data (uts);if (ret)return ret; - bus->uclass_->uc_drv->per_child_auto =0 ; + bus->ucm.uc->uc_drv->per_child_auto =0 ; drv->per_child_auto = size;return 0 ;
@@ -360,15 +360,15 @@ static int dm_test_bus_parent_plat_uclass(struct unit_test_state *uts) drv = (struct driver *)bus->driver; size = drv->per_child_plat_auto;#ifdef CONFIG_SANDBOX -os_mprotect_allow (bus->uclass_->uc_drv,sizeof (*bus->uclass_->uc_drv)); +os_mprotect_allow (bus->ucm.uc->uc_drv,sizeof (*bus->ucm.uc->uc_drv));os_mprotect_allow (drv,sizeof (*drv));#endif - bus->uclass_->uc_drv->per_child_plat_auto = size; + bus->ucm.uc->uc_drv->per_child_plat_auto = size; drv->per_child_plat_auto =0 ; ret =test_bus_parent_plat (uts);if (ret)return ret; - bus->uclass_->uc_drv->per_child_plat_auto =0 ; + bus->ucm.uc->uc_drv->per_child_plat_auto =0 ; drv->per_child_plat_auto = size;return 0 ;
test/dm/core.c +4 -4
@@ -1226,11 +1226,11 @@ static int dm_test_all_have_seq(struct unit_test_state *uts)struct uclass *uc;list_for_each_entry (uc, gd->uclass_root, sibling_node) { -list_for_each_entry (dev, &uc->dev_head, uclass_node) { -if (dev->seq_ ==-1 ) +list_for_each_entry (dev, &uc->dev_head, ucm.uc_node) { +if (dev->ucm.seq ==-1 )printf ("Device '%s' has no seq (%d)\n" , - dev->name, dev->seq_); -ut_assert (dev->seq_ !=-1 ); + dev->name, dev->ucm.seq); +ut_assert (dev->ucm.seq !=-1 ); } }
test/dm/test-uclass.c +4 -4
@@ -66,11 +66,11 @@ static int test_pre_probe(struct udevice *dev)static int test_post_probe (struct udevice *dev) {struct unit_test_state *uts =ut_get_state (); -struct udevice *prev =list_entry (dev->uclass_node.prev, - struct udevice, uclass_node); +struct udevice *prev =list_entry (dev->ucm.uc_node.prev, + struct udevice, ucm.uc_node);struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev); -struct uclass *uc = dev->uclass_; +struct uclass *uc = dev->ucm.uc; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]++;ut_assert (priv);
@@ -78,7 +78,7 @@ static int test_post_probe(struct udevice *dev) priv->base_add =0 ;if (uts->skip_post_probe)return 0 ; -if (&prev->uclass_node != &uc->dev_head) { +if (&prev->ucm.uc_node != &uc->dev_head) {struct dm_test_uclass_perdev_priv *prev_uc_priv =dev_get_uclass_priv (prev);struct dm_test_pdata *pdata =dev_get_plat (prev);
tools/dtoc/dtb_platdata.py +17 -16
@@ -735,8 +735,6 @@ class DtbPlatdata(): self.buf('\t.plat_\t\t= &%s%s,\n' % (VAL_PREFIX, node.var_name)) if parent_plat_name: self.buf('\t.parent_plat_\t= %s,\n' % parent_plat_name) - if uclass_plat_name: - self.buf('\t.uclass_plat_\t= %s,\n' % uclass_plat_name) driver_date = None if node != self._fdt.GetRoot():
@@ -763,20 +761,22 @@ class DtbPlatdata(): node.parent.var_name) if priv_name: self.buf('\t.priv_\t\t= %s,\n' % priv_name) - self.buf('\t.uclass_\t= DM_UCLASS_REF(%s),\n' % uclass.name) - + self.buf('\t.ucm\t\t= {\n') + self.buf('\t\t.uc\t= DM_UCLASS_REF(%s),\n' % uclass.name) if uclass_priv_name: - self.buf('\t.uclass_priv_ = %s,\n' % uclass_priv_name) + self.buf('\t\t.uc_priv = %s,\n' % uclass_priv_name) + if uclass_plat_name: + self.buf('\t\t.uc_plat = %s,\n' % uclass_plat_name) + self.list_node('uc_node', uclass.node_refs, node.uclass_seq, indent=2) + self.buf('\t\t.seq\t= %d,\n' % node.seq) + self.buf('\t},\n') + if parent_priv_name: self.buf('\t.parent_priv_\t= %s,\n' % parent_priv_name) - self.list_node('uclass_node', uclass.node_refs, node.uclass_seq) self.list_head('child_head', 'sibling_node', node.child_devs, node.var_name) if node.parent in self._valid_nodes: self.list_node('sibling_node', node.parent.child_refs, node.parent_seq) - # flags is left as 0 - - self.buf('\t.seq_ = %d,\n' % node.seq) self.buf('};\n') self.buf('\n')
@@ -827,11 +827,12 @@ class DtbPlatdata(): self.buf('\t\t.next = &%s->%s,\n' % (first, member)) self.buf('\t},\n') - def list_node(self, member, node_refs, seq): - self.buf('\t.%s\t= {\n' % member) - self.buf('\t\t.prev = %s,\n' % node_refs[seq - 1]) - self.buf('\t\t.next = %s,\n' % node_refs[seq + 1]) - self.buf('\t},\n') + def list_node(self, member, node_refs, seq, indent=1): + tab = '\t' * indent + self.buf('%s.%s\t= {\n' % (tab, member)) + self.buf('%s\t.prev = %s,\n' % (tab, node_refs[seq - 1])) + self.buf('%s\t.next = %s,\n' % (tab, node_refs[seq + 1])) + self.buf('%s},\n' % tab) def generate_uclasses(self): self.out('\n')
@@ -876,7 +877,7 @@ class DtbPlatdata(): self.buf('\t.priv_\t\t= %s,\n' % priv_name) self.buf('\t.uc_drv\t\t= DM_UCLASS_DRIVER_REF(%s),\n' % uclass.name) self.list_node('sibling_node', uclass_node, seq) - self.list_head('dev_head', 'uclass_node', uc_drv.devs, None) + self.list_head('dev_head', 'ucm.uc_node', uc_drv.devs, None) self.buf('};\n') self.buf('\n') self.out(''.join(self.get_buf()))
@@ -967,7 +968,7 @@ class DtbPlatdata(): node.uclass_seq = len(node.uclass.devs) node.uclass.devs.append(node) uclass.node_refs[node.uclass_seq] = \ - '&%s->uclass_node' % node.dev_ref + '&%s->ucm.uc_node' % node.dev_ref parent_driver = None if node.parent in self._valid_nodes:
tools/dtoc/test_dtoc.py +64 -50
231 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 7/15 dm: core: Add uclass-adjunct data structures
In reply to Simon GlassAdd the data structures needed to support uclass adjuncts, which allow a device to belong to more than one uclass.
Make the dev back-pointer in struct uclass_member unconditional so it works for both primary (embedded) and adjunct (standalone) memberships. This simplifies the list traversal at a cost of an extra pointer in every device (even without DM_UC_ADJUNCT).
Add adj_head to struct udevice and adj_node to struct uclass_member (both conditional on DM_UC_ADJUNCT) for chaining a device's uclass memberships.
Update dtoc to generate the .dev field in ucm initialisers.
No functional change is intended.
---
drivers/core/Kconfig | 10 ++++++++++ include/dm/device.h | 9 +++++---- include/dm/uclass.h | 4 +++- tools/dtoc/dtb_platdata.py | 1 + tools/dtoc/test_dtoc.py | 7 +++++++ 5 files changed, 26 insertions(+), 5 deletions(-)
drivers/core/Kconfig +10 -0
@@ -85,6 +85,16 @@ config DM_STATS To display the memory stats, use the 'dm mem' command. +config DM_UC_ADJUNCT + bool "Support uclass adjuncts for devices" + depends on DM + default y if SANDBOX + help + Allow a device to belong to more than one uclass. + A device bound to one uclass (e.g. UCLASS_PHY) can register + adjunct uclasses (e.g. UCLASS_CLK) at bind/probe-time via + device_add_uclass_adj(). If unsure, say N. + config SPL_DM_STATS bool "Collect and show driver model stats in SPL" depends on SPL_DM
include/dm/device.h +5 -4
@@ -131,10 +131,9 @@ enum {* @uc_priv: Per-device private data owned by the uclass * @uc_plat: Per-device platform data owned by the uclass * @seq: Sequence number within this uclass (-1 = none) +* @dev: Owning device (set for both primary and adjunct memberships) * @ops: Ops provided by this device for the uclass -* @dev: Owning device (adjuncts only; for the primary uclass use -* container_of) -* @adj_node: Node in the device's list of adjuncts +* @adj_node: Node in the owning device's adj_head list (struct udevice) */ struct uclass_member {struct uclass *uc;
@@ -142,9 +141,9 @@ struct uclass_member {void *uc_priv;void *uc_plat;int seq; +struct udevice *dev;const void *ops;#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) -struct udevice *dev;struct list_head adj_node;#endif };
@@ -177,6 +176,8 @@ struct uclass_member {* @parent: Parent of this device, or NULL for the top level device * @priv_: Private data for this device (do not access outside driver model) * @ucm: Primary uclass membership (do not access outside driver model) +* @adj_head: List of all uclass memberships including the primary (struct +* uclass_member via adj_node) * @parent_priv_: The parent's private data for this device (do not access * outside driver model) * @child_head: List of children of this device
include/dm/uclass.h +3 -1
@@ -28,7 +28,8 @@* @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 -* uclass when their bind method is called) +* uclass when their bind method is called). Adjunct registrations also appear +* on this list as standalone struct uclass_member entries. * @sibling_node: Next uclass in the linked list of uclasses */ struct uclass {
@@ -39,6 +40,7 @@ struct uclass { };struct driver ; +struct uclass_member ;struct udevice ;/* Members of this uclass sequence themselves with aliases */
tools/dtoc/dtb_platdata.py +1 -0
@@ -769,6 +769,7 @@ class DtbPlatdata(): self.buf('\t\t.uc_plat = %s,\n' % uclass_plat_name) self.list_node('uc_node', uclass.node_refs, node.uclass_seq, indent=2) self.buf('\t\t.seq\t= %d,\n' % node.seq) + self.buf('\t\t.dev\t= DM_DEVICE_REF(%s),\n' % node.var_name) self.buf('\t},\n') if parent_priv_name:
tools/dtoc/test_dtoc.py +7 -0
@@ -566,6 +566,7 @@ DM_DEVICE_INST(i2c) = { \t\t\t.next = &DM_UCLASS_REF(i2c)->dev_head, \t\t}, \t\t.seq\t= 4, +\t\t.dev\t= DM_DEVICE_REF(i2c), \t}, \t.child_head\t= { \t\t.prev = &DM_DEVICE_REF(i2c)->child_head,
@@ -595,6 +596,7 @@ DM_DEVICE_INST(root) = { \t\t\t.next = &DM_UCLASS_REF(root)->dev_head, \t\t}, \t\t.seq\t= 0, +\t\t.dev\t= DM_DEVICE_REF(root), \t}, \t.child_head\t= { \t\t.prev = &DM_DEVICE_REF(spl_test3)->sibling_node,
@@ -642,6 +644,7 @@ DM_DEVICE_INST(some_bus) = { \t\t\t.next = &DM_UCLASS_REF(testbus)->dev_head, \t\t}, \t\t.seq\t= 2, +\t\t.dev\t= DM_DEVICE_REF(some_bus), \t}, \t.child_head\t= { \t\t.prev = &DM_DEVICE_REF(test0)->sibling_node,
@@ -673,6 +676,7 @@ DM_DEVICE_INST(spl_test) = { \t\t\t.next = &DM_DEVICE_REF(spl_test3)->ucm.uc_node, \t\t}, \t\t.seq\t= 0, +\t\t.dev\t= DM_DEVICE_REF(spl_test), \t}, \t.child_head\t= { \t\t.prev = &DM_DEVICE_REF(spl_test)->child_head,
@@ -704,6 +708,7 @@ DM_DEVICE_INST(spl_test3) = { \t\t\t.next = &DM_UCLASS_REF(misc)->dev_head, \t\t}, \t\t.seq\t= 1, +\t\t.dev\t= DM_DEVICE_REF(spl_test3), \t}, \t.child_head\t= { \t\t.prev = &DM_DEVICE_REF(spl_test3)->child_head,
@@ -754,6 +759,7 @@ DM_DEVICE_INST(test) = { \t\t\t.next = &DM_DEVICE_REF(test0)->ucm.uc_node, \t\t}, \t\t.seq\t= 1, +\t\t.dev\t= DM_DEVICE_REF(test), \t}, \t.parent_priv_\t= _denx_u_boot_fdt_test_parent_priv_test, \t.child_head\t= {
@@ -802,6 +808,7 @@ DM_DEVICE_INST(test0) = { \t\t\t.next = &DM_UCLASS_REF(testfdt)->dev_head, \t\t}, \t\t.seq\t= 2, +\t\t.dev\t= DM_DEVICE_REF(test0), \t}, \t.parent_priv_\t= _denx_u_boot_fdt_test_parent_priv_test0, \t.child_head\t= {
Signature · 1 line
2.43.0
RFC PATCH 8/15 dm: core: Add a uclass-adjunct API
In reply to Simon GlassAdd the adjunct API and its implementation, allowing a device to register in additional uclasses beyond its primary one.
Most of the code lives in a new adjunct.c file, with its functions called from elsewhere in driver model.
Add shared ucm_alloc_plat() and ucm_alloc_priv() helpers used by both the primary bind/probe path and adjuncts, to avoid duplicating the allocation logic.
Add a new device_get_uclass_ops() function to look up ops by uclass ID; this maps to device_get_ops() when DM_UC_ADJUNCT is disabled to avoid adding to code size.
---
drivers/core/Makefile | 1 + drivers/core/adjunct.c | 209 +++++++++++++++++++++++++++++++++++ drivers/core/device.c | 20 +++- include/dm/device-internal.h | 165 +++++++++++++++++++++++++++ include/dm/device.h | 40 +++++++ 5 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 drivers/core/adjunct.c
drivers/core/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o tag.o obj-$(CONFIG_$(PHASE_)ACPIGEN) += acpi.o obj-$(CONFIG_$(PHASE_)DEVRES) += devres.o obj-$(CONFIG_$(PHASE_)DM_DEVICE_REMOVE) += device-remove.o +obj-$(CONFIG_$(PHASE_)DM_UC_ADJUNCT) += adjunct.o obj-$(CONFIG_$(PHASE_)SIMPLE_BUS) += simple-bus.o obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o obj-$(CONFIG_DM) += dump.o
drivers/core/adjunct.c new file +209 -0
209 lines not on this page · raw message
drivers/core/device.c +19 -1
@@ -301,7 +301,7 @@ int device_reparent(struct udevice *dev, struct udevice *new_parent)return 0 ; } -static void *alloc_priv (int size,uint flags) +void *alloc_priv (int size,uint flags) {void *priv;
@@ -1186,6 +1186,24 @@ void dev_int_set_seq(struct udevice *dev, int seq) dev->ucm.seq = seq; } +const void *device_get_uclass_ops (struct udevice *dev,enum uclass_id id) +{ +if (CONFIG_IS_ENABLED (DM_UC_ADJUNCT )) { +struct uclass_member *ucm; + +/* Walk primary + adjunct memberships for matching uclass */ +list_for_each_entry (ucm, &dev->adj_head, adj_node) { +if (ucm->uc->uc_drv->id == id) +return ucm->ops; + } + }else { +if (dev->ucm.uc->uc_drv->id == id) +return dev->driver->ops; + } + +return NULL ; +} +#if CONFIG_IS_ENABLED (OF_REAL )bool device_is_compatible (const struct udevice *dev,const char *compat) {
include/dm/device-internal.h +165 -0
175 lines not on this page · raw message
include/dm/device.h +40 -0
@@ -203,6 +203,9 @@ struct udevice {struct udevice *parent;void *priv_;struct uclass_member ucm; +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +struct list_head adj_head; +#endif void *parent_priv_;struct list_head child_head;struct list_head sibling_node;
@@ -422,6 +425,43 @@ struct driver {#endif }; +/** +* device_get_uclass_ops() - Get the ops for a device in a given uclass +* +* If the device's driver provides ops for the given uclass (either as its +* primary uclass or via an adjunct registration), return them. +* +* @dev: Device to query +* @id: Uclass ID to look up ops for +* Return: ops pointer, or NULL if not found +*/ +const void *device_get_uclass_ops (struct udevice *dev,enum uclass_id id); + +/** +* device_add_uclass_adj() - Add an adjunct uclass for a device +* +* Binds the adjunct and, if the device is already probed, also allocates +* uclass private data. This is the main entry point for drivers that need +* to register an adjunct dynamically: it does the right thing regardless of +* whether it is called from bind() or probe() +* +* @dev: Device to add the adjunct to +* @id: Uclass ID for the adjunct uclass +* @ops: Operations pointer for the adjunct uclass +* Return: 0 if OK, -ve on error +*/ +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +int device_add_uclass_adj (struct udevice *dev,enum uclass_id id, +const void *ops); +#else +static inline int device_add_uclass_adj (struct udevice *dev, +enum uclass_id id, +const void *ops) +{ +return -ENOSYS ; +} +#endif +/** * U_BOOT_DRIVER() - Declare a new U-Boot driver * @__name: name of the driver
Signature · 1 line
2.43.0
RFC PATCH 9/15 dm: core: Integrate adjuncts into existing code paths
In reply to Simon GlassWire adjunct support into the existing driver-model lifecycle and uclass iteration.
Use the shared ucm_alloc_plat() and ucm_alloc_priv() helpers in the primary bind and probe paths. Call device_init_adj() at bind, device_probe_adjs() at probe, device_free_adjs() at remove and device_unbind_adjs() at unbind.
Update uclass0iteration to handle the combined dev_head list, which now contains both primary and adjunct entries. Function-based iterators use ucm->dev
Some iterators use container_of() so cannot handle adjuncts.
---
drivers/core/device-remove.c | 9 +- drivers/core/device.c | 9 +- drivers/core/uclass.c | 286 ++++++++++++++++++++++++++++++++--- include/dm/uclass-internal.h | 8 + include/dm/uclass.h | 210 ++++++++++++++++++++++--- 5 files changed, 483 insertions(+), 39 deletions(-)
drivers/core/device-remove.c +8 -1
@@ -109,6 +109,10 @@ int device_unbind(struct udevice *dev)free (dev_get_parent_plat (dev));dev_set_parent_plat (dev,NULL ); } + ret =device_unbind_adjs (dev); +if (ret) +return log_msg_ret ("adj" , ret); + ret =uclass_unbind_device (dev);if (ret)return log_msg_ret ("uc" , ret);
@@ -131,12 +135,15 @@ int device_unbind(struct udevice *dev)*/ void device_free (struct udevice *dev) { -int size; +int size, ret;if (dev->driver->priv_auto) {free (dev_get_priv (dev));dev_set_priv (dev,NULL ); } + ret =device_remove_adjs (dev); +if (ret) +log_debug ("Failed to remove adjuncts: %d\n" , ret); size = dev->ucm.uc->uc_drv->per_device_auto;if (size) {free (dev_get_uclass_priv (dev));
drivers/core/device.c +8 -1
@@ -80,7 +80,9 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,dev_set_ofnode (dev, node); dev->parent = parent; dev->driver = drv; +device_init_adj (dev); ucm->uc = uc; + ucm->dev = dev; ucm->seq =-1 ; if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
@@ -351,6 +353,7 @@ static int device_alloc_priv(struct udevice *dev)const struct driver *drv;void *ptr;int size; +int ret; drv = dev->driver;assert (drv);
@@ -363,7 +366,7 @@ static int device_alloc_priv(struct udevice *dev)dev_set_priv (dev, ptr); } -/* Allocate private data if requested and not reentered */ +/* Allocate uclass-private data if requested and not reentered */ size = dev->ucm.uc->uc_drv->per_device_auto;if (size && !dev_get_uclass_priv (dev)) { ptr =alloc_priv (size, dev->ucm.uc->uc_drv->flags);
@@ -372,6 +375,10 @@ static int device_alloc_priv(struct udevice *dev)dev_set_uclass_priv (dev, ptr); } + ret =device_probe_adjs_ (dev); +if (ret) +return ret; +/* Allocate parent data for this child */ if (dev->parent) { size = dev->parent->driver->per_child_auto;
drivers/core/uclass.c +268 -18
343 lines not on this page · raw message
include/dm/uclass-internal.h +8 -0
@@ -138,6 +138,10 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);* The device is not prepared for use - this is an internal function. * The function uclass_get_device_tail() can be used to probe the device. * +* Note: this skips adjunct members because it uses struct udevice * as +* the cursor. Use uclass_foreach_dev() or ucm_find_first() to include +* adjuncts. +* * Return: 0 if OK (found or not found), -ve on error */ int uclass_find_first_device (enum uclass_id id,struct udevice **devp);
@@ -149,6 +153,10 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp);* * The device is not prepared for use - this is an internal function. * The function uclass_get_device_tail() can be used to probe the device. +* +* Note: this skips adjunct members because it uses struct udevice * as +* the cursor. Use uclass_foreach_dev() or ucm_find_next() to include +* adjuncts. */ void uclass_find_next_device (struct udevice **devp);
include/dm/uclass.h +191 -19
312 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 10/15 dm: core: Add uclass-ID-keyed accessors for priv and plat
In reply to Simon GlassAdd device_get_uclass_priv_by_id() and device_get_uclass_plat_by_id() which search both primary and adjunct memberships for the matching uclass ID. This allows subsystem code to retrieve the correct per-device uclass data regardless of whether the device was found via its primary uclass or an adjunct.
When DM_UC_ADJUNCT is disabled, these map to dev_get_uclass_priv() and dev_get_uclass_plat() respectively, with no overhead.
---
drivers/core/adjunct.c | 23 +++++++++++++++++++++++ drivers/core/device.c | 16 ++++------------ include/dm/device.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 12 deletions(-)
drivers/core/adjunct.c +23 -0
@@ -76,6 +76,19 @@ int device_add_uclass_adj(struct udevice *dev, enum uclass_id id,return ret; } +const void *device_get_uclass_ops (struct udevice *dev,enum uclass_id id) +{ +struct uclass_member *ucm; + +/* Walk primary + adjunct memberships for matching uclass */ +list_for_each_entry (ucm, &dev->adj_head, adj_node) { +if (ucm->uc->uc_drv->id == id) +return ucm->ops; + } + +return NULL ; +} +void *device_get_adj_uclass_priv (struct udevice *dev,enum uclass_id id) {struct uclass_member *ucm;
@@ -127,6 +140,16 @@ int ucm_alloc_priv(struct uclass_member *ucm)return 0 ; } +void *device_get_uclass_priv (struct udevice *dev,enum uclass_id id) +{ +return device_get_adj_uclass_priv (dev, id); +} + +void *device_get_uclass_plat (struct udevice *dev,enum uclass_id id) +{ +return device_get_adj_uclass_plat (dev, id); +} +int device_probe_adjs_ (struct udevice *dev) {struct uclass_driver *uc_drv;
drivers/core/device.c +4 -12
@@ -1193,23 +1193,15 @@ void dev_int_set_seq(struct udevice *dev, int seq) dev->ucm.seq = seq; } +#if !CONFIG_IS_ENABLED (DM_UC_ADJUNCT )const void *device_get_uclass_ops (struct udevice *dev,enum uclass_id id) { -if (CONFIG_IS_ENABLED (DM_UC_ADJUNCT )) { -struct uclass_member *ucm; - -/* Walk primary + adjunct memberships for matching uclass */ -list_for_each_entry (ucm, &dev->adj_head, adj_node) { -if (ucm->uc->uc_drv->id == id) -return ucm->ops; - } - }else { -if (dev->ucm.uc->uc_drv->id == id) -return dev->driver->ops; - } +if (dev->ucm.uc->uc_drv->id == id) +return dev->driver->ops;return NULL ; } +#endif #if CONFIG_IS_ENABLED (OF_REAL )bool device_is_compatible (const struct udevice *dev,const char *compat)
include/dm/device.h +34 -0
@@ -462,6 +462,40 @@ static inline int device_add_uclass_adj(struct udevice *dev, }#endif +/** +* device_get_uclass_priv() - Get uclass private data by uclass ID +* +* Return the per-device uclass private data for the given uclass ID, +* searching both primary and adjunct memberships. When DM_UC_ADJUNCT is +* not enabled, this simply returns the primary uclass private data. +* +* @dev: Device to query +* @id: Uclass ID to look up private data for +* Return: private data pointer, or NULL if not found +*/ +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +void *device_get_uclass_priv (struct udevice *dev,enum uclass_id id); +#else +#define device_get_uclass_priv (dev, id) dev_get_uclass_priv(dev) +#endif + +/** +* device_get_uclass_plat() - Get uclass platform data by uclass ID +* +* Return the per-device uclass platform data for the given uclass ID, +* searching both primary and adjunct memberships. When DM_UC_ADJUNCT is +* not enabled, this simply returns the primary uclass platform data. +* +* @dev: Device to query +* @id: Uclass ID to look up platform data for +* Return: platform data pointer, or NULL if not found +*/ +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +void *device_get_uclass_plat (struct udevice *dev,enum uclass_id id); +#else +#define device_get_uclass_plat (dev, id) dev_get_uclass_plat(dev) +#endif +/** * U_BOOT_DRIVER() - Declare a new U-Boot driver * @__name: name of the driver
Signature · 1 line
2.43.0
RFC PATCH 11/15 dm: core: Add static adjunct declarations for drivers
In reply to Simon GlassAdd struct driver_adjunct and a .adjuncts field to struct driver, allowing drivers to declare adjunct uclass memberships at compile time. The core registers these automatically during probe via device_bind_static_adjs(), before the driver's probe() runs.
This removes the need for custom probe functions that only call device_add_uclass_adj(). The dynamic API remains available for cases where adjuncts are conditional.
---
drivers/core/adjunct.c | 17 +++++++++++++++++ drivers/core/device.c | 4 ++++ include/dm/device-internal.h | 16 ++++++++++++++++ include/dm/device.h | 21 +++++++++++++++++++++ 4 files changed, 58 insertions(+)
drivers/core/adjunct.c +17 -0
@@ -150,6 +150,23 @@ void *device_get_uclass_plat(struct udevice *dev, enum uclass_id id)return device_get_adj_uclass_plat (dev, id); } +int device_bind_static_adjs (struct udevice *dev) +{ +const struct driver_adjunct *adj = dev->driver->adjuncts; +int ret; + +if (!adj) +return 0 ; + +for (; adj->id; adj++) { + ret =device_bind_adj_ (dev, adj->id, adj->ops); +if (ret) +return ret; + } + +return 0 ; +} +int device_probe_adjs_ (struct udevice *dev) {struct uclass_driver *uc_drv;
drivers/core/device.c +4 -0
@@ -168,6 +168,10 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,if (ret) goto fail_uclass_bind; + ret =device_bind_static_adjs (dev); +if (ret) + goto fail_uclass_bind; +/* if we fail to bind we remove device from successors and free it */ if (drv->bind) { ret = drv->bind (dev);
include/dm/device-internal.h +16 -0
@@ -519,6 +519,17 @@ void *device_get_adj_uclass_priv(struct udevice *dev, enum uclass_id id);*/ void *device_get_adj_uclass_plat (struct udevice *dev,enum uclass_id id); +/** +* device_bind_static_adjs() - Register statically declared adjuncts +* +* Called during bind to register any adjuncts declared in the driver's +* adjuncts array. +* +* @dev: Device to register static adjuncts for +* Return: 0 if OK, -ve on error +*/ +int device_bind_static_adjs (struct udevice *dev); +/** * device_probe_adjs_() - Allocate private data for adjunct uclasses *
@@ -581,6 +592,11 @@ static inline void *device_get_adj_uclass_plat(struct udevice *dev,return NULL ; } +static inline int device_bind_static_adjs (struct udevice *dev) +{ +return 0 ; +} +static inline int device_probe_adjs_ (struct udevice *dev) {return 0 ;
include/dm/device.h +21 -0
@@ -354,6 +354,20 @@ struct udevice_id {#define of_match_ptr (_ptr) NULL#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */ +/** +* struct driver_adjunct - Static adjunct declaration for a driver +* +* Allows a driver to declare membership in additional uclasses at compile +* time, rather than calling device_add_uclass_adj() dynamically. +* +* @id: Uclass ID for this adjunct membership +* @ops: Operations provided by this driver for the adjunct uclass +*/ +struct driver_adjunct { +enum uclass_id id; +const void *ops; +}; +/** * struct driver - A driver for a feature or peripheral *
@@ -399,6 +413,10 @@ struct udevice_id {* pointers defined by the driver, to implement driver functions required by * the uclass. * @flags: driver flags - see `DM_FLAG_...` +* @adjuncts: Sentinel-terminated array of static adjunct declarations, or +* NULL if the driver does not statically declare any adjuncts. Each entry +* specifies a uclass ID and ops pointer. The core registers these during +* probe, before calling the driver's probe function. * @acpi_ops: Advanced Configuration and Power Interface (ACPI) operations, * allowing the device to add things to the ACPI tables passed to Linux */
@@ -420,6 +438,9 @@ struct driver {int per_child_plat_auto;const void *ops;/* driver-specific operations */ uint32_t flags; +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +const struct driver_adjunct *adjuncts; +#endif #if CONFIG_IS_ENABLED (ACPIGEN )struct acpi_ops *acpi_ops;#endif
Signature · 1 line
2.43.0
RFC PATCH 12/15 dm: test: Add tests for uclass adjuncts
In reply to Simon GlassAdd a test driver and test cases for the DM_UC_ADJUNCT feature:
- testadj_drv: a UCLASS_TEST driver that registers an adjunct UCLASS_TEST_FDT uclass with custom ping ops during probe
- DTS node test-adj with compatible "denx,u-boot-test-adj"
Test cases:
- dm_test_adj_add: verify the device is discoverable in the adjunct uclass via uclass_find_device_by_ofnode()
- dm_test_adj_ops: verify device_get_adj_ops() returns the correct ops and the adjunct ping() produces the expected result
- dm_test_adj_uclass_ops: verify device_get_uclass_ops() resolves the correct ops for both primary and adjunct uclasses
- dm_test_adj_remove: verify removing a device cleans up adjuncts
- dm_test_adj_uclass_priv: verify per_device_auto allocation for adjuncts when the uclass driver requests it
---
arch/sandbox/dts/test.dts | 4 + drivers/misc/test_drv.c | 35 ++- test/dm/Makefile | 1 + test/dm/adjunct.c | 455 ++++++++++++++++++++++++++++++++++++++ test/dm/bus.c | 9 +- test/dm/test-fdt.c | 39 ++-- test/dm/test-uclass.c | 2 +- 7 files changed, 518 insertions(+), 27 deletions(-) create mode 100644 test/dm/adjunct.c
arch/sandbox/dts/test.dts +4 -0
@@ -536,6 +536,10 @@ compatible = "google,another-fdt-test"; }; + test-adj { + compatible = "denx,u-boot-test-adj"; + }; + e-test { reg = <3 1>; ping-expect = <6>;
drivers/misc/test_drv.c +34 -1
@@ -200,7 +200,7 @@ int testfdt_ping(struct udevice *dev, int pingval, int *pingret) {const struct test_ops *ops =device_get_ops (dev); -if (!ops->ping) +if (!ops || !ops->ping)return -ENOSYS ;return ops->ping (dev, pingval, pingret);
@@ -229,3 +229,36 @@ UCLASS_DRIVER(testfdtm) = { .id = UCLASS_TEST_FDT_MANUAL, .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ, }; + +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) + +static int testadj_ping (struct udevice *dev,int pingval,int *pingret) +{ + *pingret = pingval +100 ; + +return 0 ; +} + +static const struct test_ops testadj_ops = { + .ping = testadj_ping, +}; + +static const struct driver_adjunct testadj_adjuncts[] = { + {UCLASS_TEST_FDT , &testadj_ops }, + { } +}; + +static const struct udevice_id testadj_ids[] = { + { .compatible ="denx,u-boot-test-adj" }, + { } +}; + +U_BOOT_DRIVER (denx_u_boot_test_adj) = { + .name ="testadj_drv" , + .of_match = testadj_ids, + .id =UCLASS_TEST , + .adjuncts = testadj_adjuncts, + .priv_auto =sizeof (struct dm_test_priv ), + .plat_auto =sizeof (struct dm_test_pdata ), +}; +#endif /* DM_UC_ADJUNCT */
test/dm/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_DM_GPIO) += gpio.o obj-y += irq.o endif obj-$(CONFIG_ADC) += adc.o +obj-$(CONFIG_DM_UC_ADJUNCT) += adjunct.o obj-$(CONFIG_AES_SOFTWARE) += aes.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_AXI) += axi.o
test/dm/adjunct.c new file +455 -0
455 lines not on this page · raw message
test/dm/bus.c +3 -6
@@ -23,19 +23,16 @@ DECLARE_GLOBAL_DATA_PTR;/* Test that we can probe for children */ static int dm_test_bus_children (struct unit_test_state *uts) { -int num_devices =9 ; +int num_devices =10 ;struct udevice *bus; -struct uclass *uc; -ut_assertok (uclass_get (UCLASS_TEST_FDT , &uc)); -ut_asserteq (num_devices,list_count_nodes (&uc->dev_head)); +ut_asserteq (num_devices,uclass_id_count (UCLASS_TEST_FDT ));/* Probe the bus, which should yield 3 more devices */ ut_assertok (uclass_get_device (UCLASS_TEST_BUS ,0 , &bus)); num_devices +=3 ; -ut_assertok (uclass_get (UCLASS_TEST_FDT , &uc)); -ut_asserteq (num_devices,list_count_nodes (&uc->dev_head)); +ut_asserteq (num_devices,uclass_id_count (UCLASS_TEST_FDT ));ut_assert (!dm_check_devices (uts, num_devices));
test/dm/test-fdt.c +20 -19
@@ -129,6 +129,10 @@ int dm_check_devices(struct unit_test_state *uts, int num_devices) ret =uclass_get_device (UCLASS_TEST_FDT , i, &dev);ut_assert (!ret); +/* Skip adjunct members - they are tested separately */ +if (device_get_uclass_id (dev) !=UCLASS_TEST_FDT ) +continue ; +/* * Get the 'ping-expect' property, which tells us what the * ping add should be. We don't use the plat because we
@@ -150,20 +154,16 @@ int dm_check_devices(struct unit_test_state *uts, int num_devices)/* Test that FDT-based binding works correctly */ static int dm_test_fdt (struct unit_test_state *uts) { -const int num_devices =9 ; +const int num_devices =10 ;struct udevice *dev; -struct uclass *uc;int ret;int i; ret =dm_extended_scan (false);ut_assert (!ret); - ret =uclass_get (UCLASS_TEST_FDT , &uc); -ut_assert (!ret); -/* These are num_devices compatible root-level device tree nodes */ -ut_asserteq (num_devices,list_count_nodes (&uc->dev_head)); +ut_asserteq (num_devices,uclass_id_count (UCLASS_TEST_FDT ));/* Each should have platform data but no private data */ for (i =0 ; i < num_devices; i++) {
@@ -271,10 +271,10 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)ut_asserteq_str ("d-test" , dev->name);ut_asserteq (13 ,dev_seq (dev)); -/* g-test gets the next value after f-test */ -ut_assertok (uclass_get_device_by_seq (UCLASS_TEST_FDT ,15 , &dev)); +/* g-test gets the next value after f-test (adjunct takes 14) */ +ut_assertok (uclass_get_device_by_seq (UCLASS_TEST_FDT ,16 , &dev));ut_asserteq_str ("g-test" , dev->name); -ut_asserteq (15 ,dev_seq (dev)); +ut_asserteq (16 ,dev_seq (dev));/* And we should still have holes in our sequence numbers */ ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 0,
@@ -342,21 +342,22 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)* last alias is 12, so we have: * * 13 d-test -* 14 f-test -* 15 g-test -* 16 h-test -* 17 another-test -* 18 chosen-test +* 14 test-adj (adjunct) +* 15 f-test +* 16 g-test +* 17 h-test +* 18 another-test +* 19 chosen-test * -* So next available is 19 +* So next available is 20 */ ut_assertok (device_bind (dm_root (),DM_DRIVER_GET (denx_u_boot_fdt_test),"fred" ,NULL ,ofnode_null (), &dev)); -ut_asserteq (19 ,dev_seq (dev)); +ut_asserteq (20 ,dev_seq (dev));ut_assertok (device_bind (dm_root (),DM_DRIVER_GET (denx_u_boot_fdt_test),"fred2" ,NULL ,ofnode_null (), &dev)); -ut_asserteq (20 ,dev_seq (dev)); +ut_asserteq (21 ,dev_seq (dev));return 0 ; }
@@ -467,12 +468,12 @@ static int dm_test_uclass_foreach(struct unit_test_state *uts) count =0 ;uclass_id_foreach_dev (UCLASS_TEST_FDT , dev, uc) count++; -ut_asserteq (9 , count); +ut_asserteq (10 , count); count =0 ;uclass_foreach_dev (dev, uc) count++; -ut_asserteq (9 , count); +ut_asserteq (10 , count);return 0 ; }
test/dm/test-uclass.c +1 -1
@@ -78,7 +78,7 @@ static int test_post_probe(struct udevice *dev) priv->base_add =0 ;if (uts->skip_post_probe)return 0 ; -if (&prev->ucm.uc_node != &uc->dev_head) { +if (&prev->ucm.uc_node != &uc->dev_head &&device_active (prev)) {struct dm_test_uclass_perdev_priv *prev_uc_priv =dev_get_uclass_priv (prev);struct dm_test_pdata *pdata =dev_get_plat (prev);
Signature · 1 line
2.43.0
RFC PATCH 13/15 doc: dm: Document uclass adjunct support
In reply to Simon GlassAdd a section to the driver model design document describing uclass
adjuncts: what problem they solve, how to register them, and the key design decisions (probe-time registration, passive lifecycle, shared iteration lists, automatic data allocation).
---
doc/develop/driver-model/design.rst | 134 ++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+)
doc/develop/driver-model/design.rst +134 -0
@@ -1101,6 +1101,140 @@ While the current implementation is quite simple, it will get evolved as the feature is more extensively used in U-Boot subsystems. +Uclass Adjuncts +--------------- + +In U-Boot's driver model, each device belongs to exactly one uclass. When +hardware exposes multiple types of functionality (e.g. a Qualcomm clock +controller that also provides resets and power domains, or a PMIC that also +provides sysreset), drivers must work around this by creating child devices +in different uclasses via ``device_bind_driver_to_node()``. This creates +separate ``U_BOOT_DRIVER`` declarations, ``dev_get_priv(dev->parent)`` +indirection, and scaffolding that has no counterpart in Linux. + +Uclass adjuncts (``CONFIG_DM_UC_ADJUNCT``) allow a device to register in +additional uclasses without creating child devices. Each adjunct carries its +own ops pointer, per-device uclass private data, and sequence number, just +like a primary uclass membership. + +Adjuncts are declared statically in the driver using a sentinel-terminated +array of ``struct driver_adjunct``:: + + static const struct driver_adjunct my_adjuncts[] = { + { UCLASS_RESET, &my_reset_ops }, + { UCLASS_POWER_DOMAIN, &my_pd_ops }, + { } + }; + + U_BOOT_DRIVER(my_driver) = { + .name = "my_driver", + .id = UCLASS_CLK, + .adjuncts = my_adjuncts, + ... + }; + +Driver model registers static adjuncts automatically at bind time and +allocates their private data at probe time. Adjuncts may also be +registered dynamically using ``device_add_uclass_adj()`` for cases where +membership is conditional (e.g. based on device-tree properties):: + + static int my_driver_probe(struct udevice *dev) + { + if (dev_read_bool(dev, "has-reset")) + device_add_uclass_adj(dev, UCLASS_RESET, &my_reset_ops); + + return 0; + } + +The device then appears in lookup functions for each adjunct uclass (e.g. +``uclass_find_device_by_ofnode()`` for ``UCLASS_RESET`` finds this device). +Subsystem code retrieves the adjunct ops with ``device_get_uclass_ops()``:: + + const struct reset_ops *ops = device_get_uclass_ops(dev, UCLASS_RESET); + +``device_add_uclass_adj()`` binds the adjunct (allocating uclass platform +data and a sequence number) and, if the device is already probed, also +allocates uclass private data. Per-device uclass platform and private data +are allocated automatically if the adjunct's uclass driver requests them +via ``per_device_plat_auto`` / ``per_device_auto``. Sequence numbers are +allocated from the adjunct uclass's namespace to avoid collisions. + +Adjunct uclasses participate in lifecycle hooks: ``post_bind`` is called +when the adjunct is bound, ``post_probe`` when private data is allocated, +``pre_remove`` when private data is freed, and ``pre_unbind`` when the +adjunct is torn down. Child hooks (``child_post_bind``, etc.) do not apply +to adjuncts since they do not change the parent-child relationship. + +At remove time, ``device_remove_adjs()`` calls ``pre_remove`` and frees only +the uclass private data; the adjunct remains bound. +``device_unbind_adjs()`` at unbind time calls ``pre_unbind`` and fully +tears down the adjunct memberships. + +Primary and adjunct entries share the same ``dev_head`` list on each +uclass. Adjuncts are full members of their uclass: they have sequence +numbers, appear in iteration, and are found by lookup functions. This +means a lookup may return a device whose primary uclass differs from the +one searched. This is by design: the device genuinely provides that +uclass's functionality. + +All ``uclass_`` lookup and iteration functions include adjuncts: + +- Attribute lookups: ``uclass_find_device_by_ofnode()``, + ``uclass_find_device_by_name()``, ``uclass_find_device_by_seq()``, + ``uclass_find_device_by_phandle()``, ``uclass_get_device_by_driver()`` +- Index-based: ``uclass_find_device()``, ``uclass_id_count()`` +- Iteration: ``uclass_foreach_dev()``, ``uclass_foreach_dev_safe()``, + ``uclass_foreach_dev_probe()`` + +The only exceptions are ``uclass_find_first_device()`` and +``uclass_find_next_device()``, which use ``struct udevice *`` as the +iteration cursor. For an adjunct entry, ``dev->ucm.uc_node`` points into +the primary uclass's list rather than the adjunct uclass's, so there is +no way to advance to the next member. The following functions all skip +adjuncts for this reason: + +- ``uclass_find_first_device()`` / ``uclass_find_next_device()`` +- ``uclass_first_device()`` / ``uclass_next_device()`` +- ``uclass_first_device_err()`` / ``uclass_next_device_err()`` +- ``uclass_first_device_check()`` / ``uclass_next_device_check()`` +- ``uclass_probe_all()`` + +Code that needs to iterate all members including adjuncts should use +``uclass_foreach_dev()`` or the ``ucm_`` API instead. + +The ``ucm_`` API provides adjunct-aware iteration and lookup using +``struct uclass_member *`` as the cursor. Since the cursor sits directly on +the uclass's member list, it can traverse all entries including adjuncts +without ambiguity. The API mirrors the existing ``uclass_`` iterator +functions: + +- ``ucm_find_first()`` / ``ucm_find_next()`` -- iterate without probing +- ``ucm_first()`` / ``ucm_next()`` -- probe and skip failures +- ``ucm_first_check()`` / ``ucm_next_check()`` -- probe and report errors +- ``ucm_first_drvdata()`` -- find by driver data +- ``ucm_try_first()`` -- no probe, NULL on missing uclass +- ``ucm_find_seq()`` -- find by sequence number +- ``ucm_find_by_ofnode()`` -- find by device-tree node + +Use ``ucm->dev`` to obtain the device from a member pointer. + +``device_get_uclass_ops()`` resolves ops for a given uclass ID, searching +both primary and adjunct memberships. ``device_get_uclass_priv()`` +and ``device_get_uclass_plat()`` do the same for per-device uclass +private and platform data. Subsystem code should use these instead of the +plain ``dev_get_uclass_*()`` accessors when the device may have been found +via an adjunct lookup. When ``CONFIG_DM_UC_ADJUNCT`` is disabled, these map +to the plain accessors with no overhead. + +``dev_get_priv()`` and ``dev_get_plat()`` always return the driver's own +data, regardless of which uclass the device was found through. This is one +of the main benefits of adjuncts over child devices: no +``dev_get_parent()`` indirection is needed. + +When ``CONFIG_DM_UC_ADJUNCT`` is disabled, all adjunct functions are +stubbed as inlines so callers do not need ``#ifdef`` guards. + + Changes since v1 ----------------
Signature · 1 line
2.43.0
RFC PATCH 14/15 sysreset: Use device_get_uclass_ops() for adjunct support
In reply to Simon GlassUpdate sysreset_get_ops() to use device_get_uclass_ops() instead of directly accessing dev->driver->ops. This resolves the correct ops pointer for both primary sysreset drivers and adjunct registrations.
When DM_UC_ADJUNCT is disabled, device_get_uclass_ops() maps to device_get_ops() so there is no code-size cost.
Other uclass headers with a similar xxx_get_ops() macro can adopt the same pattern to support adjuncts.
---
include/sysreset.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
include/sysreset.h +8 -1
@@ -7,6 +7,8 @@#ifndef __SYSRESET_H#define __SYSRESET_H +#include <linux/kconfig.h> +struct udevice ;/**
@@ -62,7 +64,12 @@ struct sysreset_ops {int (*get_last)(struct udevice *dev); }; -#define sysreset_get_ops (dev) ((struct sysreset_ops *)(dev)->driver->ops) +#if CONFIG_IS_ENABLED (DM_UC_ADJUNCT ) +#define sysreset_get_ops (dev) \ + ((struct sysreset_ops *)device_get_uclass_ops(dev, UCLASS_SYSRESET)) +#else +#define sysreset_get_ops (dev) ((struct sysreset_ops *)(dev)->driver->ops) +#endif /** * sysreset_request() - request a sysreset
Signature · 1 line
2.43.0
RFC PATCH 15/15 power: pmic: raa215300: Convert sysreset to uclass adjunct
In reply to Simon GlassConvert the RAA215300 PMIC's sysreset support from the child-device pattern to use uclass adjuncts. Previously the PMIC driver's bind function created a separate child device with a dedicated sysreset driver. Now the PMIC driver registers itself as a sysreset adjunct during probe, keeping all the functionality in a single device.
The key change is that raa215300_sysreset_request() no longer needs dev_get_parent() to reach the PMIC, since the device itself is the PMIC.
Remove the now-unused sysreset_raa215300.c driver.
---
drivers/power/pmic/raa215300.c | 60 ++++++++++++++++++++++----- drivers/sysreset/Kconfig | 3 ++ drivers/sysreset/Makefile | 1 - drivers/sysreset/sysreset_raa215300.c | 58 -------------------------- 4 files changed, 52 insertions(+), 70 deletions(-) delete mode 100644 drivers/sysreset/sysreset_raa215300.c
drivers/power/pmic/raa215300.c +49 -11
@@ -5,11 +5,14 @@#include <dm.h> #include <dm/device-internal.h> -#include <dm/lists.h> #include <i2c.h> #include <power/pmic.h> +#include <sysreset.h> -#define RAA215300_REG_COUNT 0x80 +#define RAA215300_REG_COUNT 0x80 +#define RAA215300_REG_SWRESET 0x6D +#define RAA215300_COLD_RESET BIT(0) +#define RAA215300_WARM_RESET BIT(1)static int raa215300_reg_count (struct udevice *dev) {
@@ -27,24 +30,59 @@ static const struct udevice_id raa215300_ids[] = { {/* sentinel */ } }; -static int raa215300_bind (struct udevice *dev) +#if IS_ENABLED (CONFIG_SYSRESET_RAA215300 ) +static int raa215300_sysreset_request (struct udevice *dev, +enum sysreset_t type) { -if (IS_ENABLED (CONFIG_SYSRESET_RAA215300 )) { -struct driver *drv =lists_driver_lookup_name ("raa215300_sysreset" ); -if (!drv) -return -ENOENT ; +int ret; +u8 val; -return device_bind (dev, drv, dev->name,NULL ,dev_ofnode (dev), -NULL ); +/* +* The RAA215300 documentation names the available reset types +* differently to U-Boot: +* +* - A "warm" reset via the RAA215300 PMIC will fully reset the SoC +* (CPU & GPIOs), so this corresponds to SYSRESET_COLD. +* +* - A "cold" reset via the RAA215300 PMIC will cycle all power supply +* rails, so this corresponds to SYSRESET_POWER. +*/ +switch (type) { +case SYSRESET_COLD : + val =RAA215300_WARM_RESET ; +break ; + +case SYSRESET_POWER : + val =RAA215300_COLD_RESET ; +break ; + +default : +return -EPROTONOSUPPORT ; } -return 0 ; + ret =pmic_reg_write (dev,RAA215300_REG_SWRESET , val); +if (ret) +return ret; + +return -EINPROGRESS ; } +static struct sysreset_ops raa215300_sysreset_ops = { + .request = raa215300_sysreset_request, +}; + +static const struct driver_adjunct raa215300_adjuncts[] = { + {UCLASS_SYSRESET , &raa215300_sysreset_ops }, + { } +}; +#endif +U_BOOT_DRIVER (raa215300_pmic) = { .name ="raa215300_pmic" , .id =UCLASS_PMIC , .of_match = raa215300_ids, - .bind = raa215300_bind, .ops = &raa215300_ops, +#if IS_ENABLED(CONFIG_SYSRESET_RAA215300) + .adjuncts = raa215300_adjuncts, +#endif };
drivers/sysreset/Kconfig +3 -0
@@ -290,8 +290,11 @@ config SYSRESET_MPC83XX config SYSRESET_RAA215300 bool "Support sysreset via Renesas RAA215300 PMIC" depends on PMIC_RAA215300 + select DM_UC_ADJUNCT help Add support for the system reboot via the Renesas RAA215300 PMIC. + Uses the uclass adjunct feature to register the PMIC as a + sysreset device without creating a separate child device. config SYSRESET_QCOM_PSHOLD bool "Support sysreset for Qualcomm SoCs via PSHOLD"
drivers/sysreset/Makefile +0 -1
@@ -29,7 +29,6 @@ obj-$(CONFIG_SYSRESET_WATCHDOG) += sysreset_watchdog.o obj-$(CONFIG_SYSRESET_RESETCTL) += sysreset_resetctl.o obj-$(CONFIG_$(PHASE_)SYSRESET_AT91) += sysreset_at91.o obj-$(CONFIG_$(PHASE_)SYSRESET_X86) += sysreset_x86.o -obj-$(CONFIG_SYSRESET_RAA215300) += sysreset_raa215300.o obj-$(CONFIG_SYSRESET_QCOM_PSHOLD) += sysreset_qcom-pshold.o obj-$(CONFIG_TARGET_XTFPGA) += sysreset_xtfpga.o obj-$(CONFIG_SYSRESET_QEMU_VIRT_CTRL) += sysreset_qemu_virt_ctrl.o
drivers/sysreset/sysreset_raa215300.c deleted +0 -58
58 lines not on this page · raw message
Signature · 1 line
2.43.0
чт, 19 бер. 2026 р. о 23:36 Simon Glass <[email protected]> пише:
Quoted 5 lines
[Note: this is marked RFC as I am still not sure that this is the best approach. But this is my third redesign so I think it makes sense to get some feedback before trying to refine it further]
Hello Simon!
With all do respect how this change improves current situation? From what I can see introducing multi-uclass will bring only chaos and confusion.
Quoted 4 lines
U-Boot's driver model requires each device to belong to exactly one uclass. Multi-function hardware must work around this by creating child devices in different uclasses via
device_bind_driver_to_node(), with a NOP parent device.
Example you are targeting behaves as it should. MFD can have a multiple cell linked to the parent node and/or its subnodes, this is not a workaround, this is how Linux MFD operate too. And a parent may not be a NOP device, it may be a core providing access or misc communication functions (like PMICs do).
Quoted 17 lines
This is quite common: at least 8 PMIC drivers bind sysreset children, every Qualcomm GCC driver (15+ platforms) does this and several PHY drivers bind clock children.
This series adds uclass adjuncts, which allow a device to register in additional uclasses without creating child devices. Each adjunct carries its own ops pointer, per-device uclass private/platform data, and sequence number.
With this series, uclass lookup and iteration functions include adjunct registrations alongside primary devices. The
uclass_foreach_dev()iterator walks all entries in the uclass, including adjunct ones. Iterators that use a struct udevice * to iterate (uclass_find_first_device()etc.) only see primary devices, since they navigate via the embedded primary ucm.
Quoted 5 lines
A new
ucm_iterator API uses structuclass_member* as the cursor, enabling adjunct-aware iteration and lookup. It provides find, probe, check, drvdata, seq and ofnode variants.uclass_foreach_dev_probe()uses this internally so that it includes adjuncts.
It seems to be overcomplication. ATM cells can be bound to the parent device node and called by the UCLASS from the parent node. For example, if PMIC has gpio cells and does not expose them as an individual node then gpio driver can be bound to parents node and used as a gpio function provider which matches what OF schema expects pretty accurately.
Quoted 11 lines
As a concrete example, a Qualcomm GCC driver could register as
UCLASS_CLK(primary) with adjunctUCLASS_RESETandUCLASS_POWER_DOMAIN, thus removing theUCLASS_NOPcontainer and theqcom_cc_bind()function. The raa215300 PMIC conversion in this series demonstrates the pattern: one device, no child sysreset driver, nodev_get_priv(dev->parent)indirection.The mechanism is enabled by a new
CONFIG_DM_UC_ADJUNCToption. Code size is largely neutral without this, except for the change to adddev_int_set_seq()which is used by PCI boards.
So you basically propose to squash everything into a single enormous driver coding every function that MFD provides instead of keeping existing layout of separate cells with dedicated function. This seems to be a maintainers hell.
Quoted 10 lines
Note that a couple of linker-list fixes are included so that sandbox will start up correctly. It still does not pass all tests though, due to various bugs surfaced by this series. If we go ahead, we will need at least one precursor series to resolve these pre-existing problems.
This is an RFC. The next steps could be:
- Convert one Qualcomm GCC driver to use adjuncts
- Convert one RK8xx PMIC from child-sysreset to adjunct
- Update per-subsystem ops accessors (clk_dev_ops(), etc.)
Hi Svyatoslav,
Quoted 67 lines · Svyatoslav Ryhel
чт, 19 бер. 2026 р. о 23:36 Simon Glass <[email protected]> пише:
Quoted 5 lines
[Note: this is marked RFC as I am still not sure that this is the best approach. But this is my third redesign so I think it makes sense to get some feedback before trying to refine it further]
Hello Simon!
With all do respect how this change improves current situation? From what I can see introducing multi-uclass will bring only chaos and confusion.
Quoted 4 lines
U-Boot's driver model requires each device to belong to exactly one uclass. Multi-function hardware must work around this by creating child devices in different uclasses via
device_bind_driver_to_node(), with a NOP parent device.Example you are targeting behaves as it should. MFD can have a multiple cell linked to the parent node and/or its subnodes, this is not a workaround, this is how Linux MFD operate too. And a parent may not be a NOP device, it may be a core providing access or misc communication functions (like PMICs do).
Quoted 17 lines
This is quite common: at least 8 PMIC drivers bind sysreset children, every Qualcomm GCC driver (15+ platforms) does this and several PHY drivers bind clock children.
This series adds uclass adjuncts, which allow a device to register in additional uclasses without creating child devices. Each adjunct carries its own ops pointer, per-device uclass private/platform data, and sequence number.
With this series, uclass lookup and iteration functions include adjunct registrations alongside primary devices. The
uclass_foreach_dev()iterator walks all entries in the uclass, including adjunct ones. Iterators that use a struct udevice * to iterate (uclass_find_first_device()etc.) only see primary devices, since they navigate via the embedded primary ucm.Quoted 5 lines
A new
ucm_iterator API uses structuclass_member* as the cursor, enabling adjunct-aware iteration and lookup. It provides find, probe, check, drvdata, seq and ofnode variants.uclass_foreach_dev_probe()uses this internally so that it includes adjuncts.It seems to be overcomplication. ATM cells can be bound to the parent device node and called by the UCLASS from the parent node. For example, if PMIC has gpio cells and does not expose them as an individual node then gpio driver can be bound to parents node and used as a gpio function provider which matches what OF schema expects pretty accurately.
Quoted 11 lines
As a concrete example, a Qualcomm GCC driver could register as
UCLASS_CLK(primary) with adjunctUCLASS_RESETandUCLASS_POWER_DOMAIN, thus removing theUCLASS_NOPcontainer and theqcom_cc_bind()function. The raa215300 PMIC conversion in this series demonstrates the pattern: one device, no child sysreset driver, nodev_get_priv(dev->parent)indirection.The mechanism is enabled by a new
CONFIG_DM_UC_ADJUNCToption. Code size is largely neutral without this, except for the change to adddev_int_set_seq()which is used by PCI boards.
Quoted 15 lines
So you basically propose to squash everything into a single enormous driver coding every function that MFD provides instead of keeping existing layout of separate cells with dedicated function. This seems to be a maintainers hell.
Quoted 10 lines
Note that a couple of linker-list fixes are included so that sandbox will start up correctly. It still does not pass all tests though, due to various bugs surfaced by this series. If we go ahead, we will need at least one precursor series to resolve these pre-existing problems.
This is an RFC. The next steps could be:
- Convert one Qualcomm GCC driver to use adjuncts
- Convert one RK8xx PMIC from child-sysreset to adjunct
- Update per-subsystem ops accessors (clk_dev_ops(), etc.)
Just to clarify, the goal here is not to squash all MFDs into one. It is not intended to move away from how Linux handles a particular subsystem (quite the opposite!)
This is really just aimed at allowing a driver to support multiple uclasses, in cases where that is useful. It can actually simplify certain drivers, since they can have their state in one place rather than having to deal with the parent/child relationships and multiple priv/plat data. I have had quite a few bugs calling an operation on dev instead of dev->parent as well. I still believe that modelling a PMIC with child devices for CLK, REGULATOR, SYSRESET and GPIO makes sense in many cases. But now it becomes optional. Ssee the example in this series, which I hope you will agree does actually simplify the driver.
The original design of driver model was based on uclass being associated with a particular API, with a device being in a single uclass. This series is really just looking at what it might look like if we relaxed that contraint.
I've been thinking about doing this for years...the most recent impetus comes from the clk/reset/power domain discussion on irc and Casey's recent series, although in fact that seems to be heading towards mostly separate infra rather than enhancing driver model. I would like to steer it towards still integrating fully with clk - e.g. using clk_get_by_index(), etc.
Regards,
Simon
On Thu, Mar 19, 2026 at 03:35:30PM -0600, Simon Glass wrote:
[snip]
Quoted 4 lines
Note that a couple of linker-list fixes are included so that sandbox will start up correctly. It still does not pass all tests though, due to various bugs surfaced by this series. If we go ahead, we will need at least one precursor series to resolve these pre-existing problems.
I assume that the first two, linker-list, patches pass CI on their own. Since we hit those issues as part of lwIP development, can you please just post them on their own so they can be merged soon? Thanks.
Signature · 1 line
Tom
Hi Tom,
Quoted 4 lines · Tom Rini
On Thu, Mar 19, 2026 at 03:35:30PM -0600, Simon Glass wrote:
[snip]
Quoted 8 lines
Quoted 4 lines
Note that a couple of linker-list fixes are included so that sandbox will start up correctly. It still does not pass all tests though, due to various bugs surfaced by this series. If we go ahead, we will need at least one precursor series to resolve these pre-existing problems.
I assume that the first two, linker-list, patches pass CI on their own. Since we hit those issues as part of lwIP development, can you please just post them on their own so they can be merged soon? Thanks.
Yes they are independent. I can post them separately.
Regards,
Simon