qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Pratik Parvati <pratikp@vayavyalabs.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	qemu-devel@nongnu.org, "Eduardo Habkost" <ehabkost@redhat.com>
Subject: Re: sysbus_create_simple Vs qdev_create
Date: Wed, 15 Jul 2020 16:37:18 +0200	[thread overview]
Message-ID: <87lfjkvo81.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CA+aXn+Guvt34PDD=N3FsD5w1C-aDXZ7gS8H_AZN-JEM8j8wBiQ@mail.gmail.com> (Pratik Parvati's message of "Wed, 15 Jul 2020 19:28:24 +0530")

Pratik Parvati <pratikp@vayavyalabs.com> writes:

> Hi Markus and Philippe,
>
> Thanks for your reply. Now I am pretty clear about Qdev and sysbus helper
> function.
>
> Can you please explain to me in brief on buses and device hierarchies (i.e.
> BusState and DeviceState) and how they are related to each other? As I can
> see, the DeviceState class inherits the BusState
>
> struct DeviceState {
>     /*< private >*/
>     Object parent_obj;
>     /*< public >*/
>
>     const char *id;
>     char *canonical_path;
>     bool realized;
>     bool pending_deleted_event;
>     QemuOpts *opts;
>     int hotplugged;
>     bool allow_unplug_during_migration;
>     BusState *parent_bus; \\ BusState is inherited here
>     QLIST_HEAD(, NamedGPIOList) gpios;
>     QLIST_HEAD(, BusState) child_bus;
>     int num_child_bus;
>     int instance_id_alias;
>     int alias_required_for_version;
>     ResettableState reset;
> };
>
> and BusState, in turn, inherits the DeviceState as
>
> /**
>  * BusState:
>  * @hotplug_handler: link to a hotplug handler associated with bus.
>  * @reset: ResettableState for the bus; handled by Resettable interface.
>  */struct BusState {
>     Object obj;
>     DeviceState *parent; \\ DeviceState is inherited here
>     char *name;
>     HotplugHandler *hotplug_handler;
>     int max_index;
>     bool realized;
>     int num_children;
>     QTAILQ_HEAD(, BusChild) children;
>     QLIST_ENTRY(BusState) sibling;
>     ResettableState reset;
> };
>
> I am a bit confused. Can you brief me this relation!

We sorely lack introductory documentation on both qdev and QOM.  I
believe most developers are more or less confused about them most of the
time.  I've done a bit of work on both, so I'm probably less confused
than average.  I'm cc'ing maintainers in the hope of reducing average
confusion among participants in this thread.

DeviceState does not inherit from BusState, and BusState does not
inherit from DeviceState.  The relation you marked in the code is
actually "has a".

A DeviceState may have a BusState, namely the bus the device is plugged
into.  "May", because some devices are bus-less (their
DEVICE_GET_CLASS(dev)->bus_type is null), and the others get plugged
into their bus only at realize time.

Example: PCI device "pci-serial" plugs into a PCI bus.

Example: device "serial" does not plug into a bus (its used as component
device of "pci-serial" and other devices).

Example: device "pc-dimm" does not plug into a bus.

A bus has a DeviceState, namely the device providing this bus.

Example: device "i440FX-pcihost" provides PCI bus "pci.0".

Both DeviceState and BusState are QOM subtypes of Object.  I prefer to
avoid use of "inherit" for that, because it can mean different things to
different people.



  parent reply	other threads:[~2020-07-15 14:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 16:09 sysbus_create_simple Vs qdev_create Pratik Parvati
2020-07-14 16:17 ` Pratik Parvati
2020-07-14 17:02   ` Philippe Mathieu-Daudé
2020-07-15  8:32     ` Markus Armbruster
2020-07-15 13:58       ` Pratik Parvati
2020-07-15 14:11         ` Peter Maydell
2020-07-15 14:37         ` Markus Armbruster [this message]
2020-07-16 22:21           ` Eduardo Habkost
2020-07-17  5:10             ` Markus Armbruster
2020-07-17 16:23               ` Eduardo Habkost
2020-07-17 16:30                 ` Daniel P. Berrangé
2020-07-17 17:15                   ` Peter Maydell
2020-07-20  7:39                     ` Markus Armbruster
2020-07-20  7:38                 ` Markus Armbruster
2020-07-20 15:59                   ` Eduardo Habkost
2020-07-21  6:00                     ` Markus Armbruster
2020-07-27 14:29                       ` Paolo Bonzini
2020-07-28  7:19                         ` Markus Armbruster
2020-07-28 17:38                           ` Paolo Bonzini
2020-07-28 22:47                             ` Eduardo Habkost
2020-07-29  9:54                               ` Paolo Bonzini
2020-07-29 13:18                                 ` Markus Armbruster
2020-07-29 16:08                                   ` Paolo Bonzini
2020-07-30 10:03                                     ` Markus Armbruster
2020-07-30 11:09                                       ` Paolo Bonzini
2020-07-30 12:36                                         ` Markus Armbruster
2020-07-30 13:38                                           ` Paolo Bonzini
2020-07-29 14:32                                 ` Eduardo Habkost
2020-07-29 16:01                                   ` Paolo Bonzini
2020-07-29 16:08                                     ` Eduardo Habkost
2020-07-29 16:14                                       ` Paolo Bonzini
2020-07-29  7:46                             ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lfjkvo81.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=pratikp@vayavyalabs.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).