Re: Device tree representation of (hotplug) connectors: discussion at ELCE

David Gibson
2025-09-19T04:53:15Z

[-- Attachment #1: Type: text/plain, Size: 6580 bytes --]

On Thu, Sep 18, 2025 at 09:44:09AM +0200, Herve Codina wrote:
> Hi David,
>
> On Thu, 18 Sep 2025 13:16:32 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> ...
>
> > > > Thoughts above suggest a different direction, but here's what I was
> > > > thinking before:
> > > >
> > > > base board:
> > > >
> > > > connector {
> > > > /export/ "i2c" &i2c0;
> > > > };
> > > >
> > > > addon:
> > > > eeprom@10 {
> > > > compatible = "foo,eeprom";
> > > > bus-reg = <&i2c 0x10>;
> > > > }
> > > >
> > > > Or, if the addon had multiple i2c devices, maybe something like:
> > > >
> > > > board-i2c {
> > > > compatible = "i2c-simple-bridge";
> > > > bus-ranges = <&i2c 0 0x3ff>; /* Whole addr space */
> > > > eeprom@10 {
> > > > compatible = "foo,eeprom";
> > > > reg = <0x10>;
> > > > }
> > > > widget@20 {
> > > > compatible = "vendor,widget";
> > > > reg = <0x20>;
> > > > }
> > > > }
> > > >
> > > > Writing that, I realise I2C introduces some complications for this.
> > > > Because it has #size-cells = <0>, ranges doesn't really work (without
> > > > listing every single address to be translated). Likewise, because we
> > > > always need the parent bus phandle, we can't use the trick of an empty
> > > > 'ranges' to mean an identity mapping.
> > > >
> > > > We could invent encodings to address those, but given the addon with
> > > > multiple connectors case provides another incentive for a single
> > > > connector to allow adding nodes in multiple (but strictly enumerated)
> > > > places in the base device tree provides a better approach.
> > >
> > > and the "place in base device tree" is the goal of the extension bus.
> > >
> > > The strict enumeration of nodes enumerated is done by two means:
> > > - extension busses at connector level
> > > Those extensions are described as connector sub-nodes.
> > > The addon DT can only add nodes in those sub-nodes to describe devices
> > > connected to the relared extension bus.
> > > - export symbols
> > > An addon DT can only use symbols exported to reference symbols outside
> > > the addon DT itself.
> > >
> > > Can I assume that bus extensions we proposed (i2c-bus-extension and
> > > spi-bus-extension) could be a correct solution ?
> >
> > Maybe? I prefer the idea of a universal mechanism, not one that's
> > defined per-bus-type.
> >
> >
> > Also, IIUC the way bus extension operates is a bit different - nodes
> > would be "physically" added under the bus extension node, but treated
> > logically as if they go under the main bus. What I'm proposing here
> > is something at the actualy overlay application layer that allows
> > nodes to be added to different parts of the base device tree - so you
> > could add your i2c device under the main i2c bus.
>
> I think we should avoid this kind of node dispatching here and there in
> the base DT.

Until I saw Geert's multi-connector case, I would have agreed. That
case makes me thing differently: in order to support that case we
already have to handle adding information in multiple places (under
all of the connectors the addon uses). Given we have to handle that
anyway, I wonder if it makes more sense to lean into that, and allow
updates to multiple (strictly enumerated) places.

> We work on decoupling busses wired to a connector and dispatching nodes
> looks like this decoupling is ignored.

I don't really follow what you're saying here.

> IMHO, keeping devices available on an addon board as nodes under the
> connector is a real hardware representation.

It's *a* real hardware representation, but it's not the only real
hardware representation. Placing the new nodes under connectors
prioritises the physical connections. Placing them under various
nodes on the base board prioritises the logical-bus connections. I'd
argue that the latter is slightly more important, since the primary
consumer of the device tree is the OS, to which the logical
connections are usually more important.

But in any case, real hardware isn't necessarily a tree, so we have to
compromise somewhere.

> Also, at runtime, once an addon board DT is applied, when you look at
> your current DT either using /proc/device-tree or some links such as
> /sys/bus/devices/.../of_node, the connector and extension bus appear
> and clearly identify devices behind the connector.

That's certainly nice, but we already lose this in the multi-connector
case, so I don't think it can be a hard requirement.

> > That approach does complicate removal, but its not as bad as overlays
> > at the moment, because a) it could be limited to adding new nodes, not
> > modifying existing ones and b) the connector would specify exactly the
> > places that additions are allowed.
>
> I think bus extensions comply with a) and b).

Bus extensions aren't directly relevant to (a) and (b) - those are
about the actual overlay/addon application mechanism. Bus extensions
are one of several possible approaches to allowing a more restrictive
(and therefore manageable) way of dynamically updating the dt, while
still being able to represent multi-bus devices.

> Yes, bus extensions need to be handled per-bus types but they have the
> advantage of keeping the hardware reality well described and visible at
> runtime in term of "wiring" topology.
>
> Whatever the solution, this will already be handled per-bus types.
> Only busses that support runtime DT node addition/removal (OF_RECONFIG_*
> notifications in the kernel implementation) will support adding or
> removing nodes.

First, I don't see that the implementation need affect the spec here.
Second, bus-reg has possible applications even if there isn't dynamic
reconfiguration.
>
> Your approach is more complex, dispatch node here and there and actually
> is also a per-bus types solution.

Again, I don't follow you.

> I think, in order to choose between both solutions, the main question is:
> Do we want to dispatch nodes provided by an addon DT everywhere in the base
> DT ?
>
> IMHO, the answer is no.

Everywhere, no, absolutely not. That's one of the things that's awful
about the current overlay mechanism.

Multiple places - as specified by the base board / connector, maybe.

--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]