Peter Maydell <[email protected]> writes:
> On Wed, 4 Mar 2026 at 12:25, Markus Armbruster <[email protected]> wrote:
>> We might be at a crossroads here.
>>
>> Paul Brook designed qdev around "a device plugs into some bus, and may
>> provide buses". To make this work, he added a main system bus to serve
>> as root of a single tree.
>>
>> The parent of a device in that tree is the bus it plugs into, and the
>> parent of a bus is the device that provides it, except for the main
>> system bus, which has no parent. "info qtree" shows this tree.
>>
>> Note a machine had just this one system bus back then.
>>
>> The system bus isn't something hardware people would call a bus.
>>
>> The qtree is a qdev thing. It is *not* the QOM composition tree ("info
>> qom-tree /").
>>
>> We actually abandoned "a device plugs into some bus" a long time ago.
>> Moe on that below.
>>
>> Qdev was later rebased onto QOM, as follows.
>>
>> A bus QOM type is a subtype of "bus".
>>
>> A device QOM type is a subtype of "device".
>>
>> If a device type has a @bus_type, then it plugs into a bus of that QOM
>> type. Such a concrete device is commonly[*] not a direct subtype of
>> "device". Instead, it's a subtype of the abstract device that plugs
>> into that bus type. Example: "isa-serial" is a direct subtype of
>> "isa-device", and it inherits its bus type "ISA" from there.
>>
>> If a device has no @bus_type, it doesn't plug into any bus. It doesn't
>> show up in "info qtree" (it does in "info qom-tree", of course).
>> Example: "serial" is a direct subtype of "device".
>>
>> This lets us build devices from components without having to make up
>> buses to connect them. Example: "isa-serial" has a direct QOM child of
>> type "serial". Good!
>>
>> Except infrastructure useful to such bus-less devices lives in sysbus,
>> where bus-less devices can't access it. This tempts us to make devices
>> sysbus devices just to be able to use the infrastructure, and to create
>> additional sysbuses.
>
> There is only one sysbus -- it is impossible to create more than one,
> and there wouldn't be much point in creating a second one anyway.
I was almost entirely mistaken there. However, you're not quite right,
either :)
We *can* create more than one system bus, and we in fact do: abstract
PCI device "macio" contains a "macio-bus", which is a subtype of the
system bus type. Its concrete subtypes are "macio-oldworld" and
"macio-newworld". To see the "macio-bus" in "info qtree", try machine
"g3beige".
But this is the rare exception. The rule is us doing something
differently undesirable.
Consider ARM machine "ast2700fc". Its core are three devices:
"ast2700-a2", "aspeed27x0ssp-coprocessor", and
"aspeed27x0tsp-coprocessor". All three contain component devices. The
QOM composition tree shows them as "/machine/ca35", "/machine/ssp", and
"/machine/tsp", i.e. they are direct children of the machine object.
Here's a closer look at a small part of the composition tree:
/machine (ast2700fc-machine)
[...]
/ca35 (ast2700-a2)
[...]
/ioexp[0] (aspeed.ast1700)
[...]
/uart (serial-mm)
/serial (serial)
/serial[0] (memory-region)
I'll refer back to this later.
A few components end up in the "/machine/unattached" orphanage instead
due to sloppy modelling.
My point is: the QOM composition tree actually reflects how devices are
built from components, except for the parts where we got sloppy, which
should be fixable.
The qtree (the thing shown by "info qtree") shows a different picture.
The three core devices are bus-less, and therefore not in the qtree.
Their components, however, are mostly sysbus devices, and therefore in
the qtree right under the root. Here are the parts of the qtree that
correspond to the QOM composition tree snippet above:
bus: main-system-bus
type System
[...]
dev: serial-mm, id ""
gpio-out "sysbus-irq" 1
regshift = 2 (0x2)
endianness = 2 (0x2)
mmio ffffffffffffffff/0000000000000020
dev: aspeed.ast1700, id ""
board-idx = 0 (0x0)
silicon-rev = 100794627 (0x6020103)
dram = "/machine/ca35/ca35-dram[0]"
mmio 0000000030000000/0000000001000000
The "aspeed.ast1700" and its "serial-mm" component are siblings. The
latter's "serial" component is bus-less, and therefore not in the qtree.
Bernhard's patches make it a sysbus device instead, and therefore add it
to the qtree as another sibling.
My point is: the qtree does not reflect how devices are built from
components / are wired together, at least not where sysbus devices are
involved.
>> We can elect to go down this path further: make more sysbus devices.
>> Create more sysbuses. If this is the right path, then bus-less devices
>> were a mistake, and we should consider eliminating them.
>>
>> Or we can pick the other branch: put the infrastructure where bus-less
>> devices can use it. If this is the right path, then sysbus is
>> obsolescent.
>
> I do think that at some point it would be good to move all that
> stuff into the base "device" class, and drop sysbus. The real
> problem, though, is reset. Currently reset propagates along the
> qtree (the tree of buses).
Unfortunately, the qtree is far removed from reality for sysbus devices.
Case in point: "aspeed.ast1700" and its component "serial-mm" are
siblings in the qtree. In what order will they be reset?
Physical hardware has reset lines. Devices generally wire up their
components' reset pins to their own. I believe the sane way to model
this is a reset tree.
> So something (like TYPE_SERIAL, and
> also like CPU objects) that is a direct child of TYPE_DEVICE does
> not get automatically reset. The major overriding reason why
> (as it currently stands) I favour making things sysbus devices
> and not plain devices is that devices that don't get reset are
> either broken or need all their users to take extra steps that
> most don't take, or do in a weird way. We can't just push the
> reset handling into TYPE_DEVICE because by definition it is tied
> to "being a thing on a bus, i.e. the sysbus".
>
> Disentangling reset is extremely painful -- I don't even know
> what it ought to be doing. Maybe propagating along the QOM tree?
I think this would make more sense. Unlike the qtree, the QOM
composition tree contains all devices, and reflects the actual
composition. It's certainly closer to the real reset tree than the
qtree is. Is it close enough? I don't know. If yes, there's our reset
tree. If no, I guess we could still use it as a base, with manually
corrected reset lines where the QOM composition tree is off.
> So for now, we muddle along.
>
> -- PMM