From: Anthony Liguori <anthony@codemonkey.ws>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC][PATCH 0/21] QEMU Object Model
Date: Wed, 27 Jul 2011 17:31:30 -0500 [thread overview]
Message-ID: <4E3091C2.3090605@codemonkey.ws> (raw)
In-Reply-To: <CAFEAcA9ScQ717m9sV8TPOtSodT4iHKyemy41nQoJMo35xkM4wg@mail.gmail.com>
On 07/27/2011 04:33 PM, Peter Maydell wrote:
> On 26 July 2011 15:02, Anthony Liguori<anthony@codemonkey.ws> wrote:
>> In my attempt at PCI modelling, I had something like:
>>
>> struct I440FX
>> {
>> Device parent;
>>
>> PciDevice slots[32];
>> };
>>
>> Which means that to attach to bus 0, slot 3, fn 0, you do:
>>
>> i440fx->slots[3] = mydevice
>
> So what I don't really understand about this model is why the PCI
> connection is "privileged" in the sense that 'mydevice' is actually
> an instance of something you can stick directly into one of the PCIBus
> device's slots.
Oh, it's not privileged at all. It just happens to be that modelling
something simple is simple. That's goodness.
The example that I used for most of my early testing was meant to be a
bit more interesting. I created a Source, Sink, XorGate, AndGate, and
OrGate and then used a config file to build a full working 8-bit adder.
You can see this at:
http://repo.or.cz/w/qemu/aliguori.git/blob/refs/heads/qdev2
Check out devices/gates and vm.cfg.
Here's a rough model of how it works:
struct XorGate
{
Device parent;
Pin out;
Pin *in[2];
};
In XorGate's initfn, it registers three properties, 'in[0]' and 'in[1]'
as 'socket<Pin>'s and 'out' as 'plug<Pin>'.
When XorGate is realized, it makes sure that both in[0] and in[1] have
been set (sockets are RW whereas plugs are RO). It then connects to the
edge event on the in[0] and in[1] pins and when either event fires, it
will compute a value, and set the level of out.
XorGate is-a Device, but so is Pin. The following things are valid:
(qemu) plug_create xor-gate gate0
(qemu) plug_create xor-gate gate1
(qemu) plug_create xor-gate gate2
(qemu) plug_get gate1 out
gate1::out
(qemu) plug_set xor-gate in[0] gate1::out
(qemu) plug_get gate2 out
gate2::out
(qemu) plug_set xor-gate in[1] gate2::out
Which creates a simple tree of two xor gates who's outputs are tied to
another xor gate. Or:
XorGate /
- XorGate / \
\
XorGate /
\
The 'out' property of XorGate is really a child device. All devices
(all plugs for that matter) have a global namespace. By convention,
uniqueness in name is guaranteed for child devices by reserving the '::'
separator and naming children based on 'parentname::propertyname'. But
for correctness, the right way to figure out the name of a child is by
reading the property.
So to answer your above question, a multi PCI slot graphics adapter is
simply:
struct GraphicsSlot {
PciDevice parent;
};
struct MultislotGraphicsCard {
Device parent;
GraphicsSlot slot[2];
};
Then conceptually:
mgc = new MultislotGraphicsCard();
i440fx->slot[1] = mgc.slot[0];
i440fx->slot[2] = mgc.slot[1];
You do not need to ever assign a device directly to a socket. This is a
fundamental different between QOM and qdev. There is no concept of
"parent bus". There's no concept of parent--even with composition.
Devices can have links to zero or more other Devices. They can also
create devices within themselves but those devices don't have any
special knowledge of that fact.
> I would expect that 'mydevice' would have a bunch of
> (effectively) interfaces it exposed, and you'd connect i440fx->slots[3]
> to mydevice.pciconnector or something. [Which ought to both let the
> PCIBus call functions implemented by the device, and vice versa.]
>
> (What would a model of a two-PCI-slot graphics card look like?)
>
> Maybe it would be better to use some other example. After all, the
> cases like PCI are the ones our device model already handles pretty
> well, so the interesting cases to look at are where we're not so
> good at it. What does the implementation of omap2_gpio look like,
> for instance? (it's not qdev at the moment but there's a set of
> patches on the list which make it so; the guts of the qdevification
> are http://patchwork.ozlabs.org/patch/103905/ .)
> That's a device which exposes:
> * 4,5, or 6 MMIO regions (depending on how many 'modules' the
> particular revision you ask for has)
> * a variably sized array of gpio inputs
> * ditto, gpio outputs
struct OmapGpio
{
Device parent;
size_t nb_regions;
MemoryRegion *regions;
size_t nb_out;
Pin *out;
size_t nb_in;
Pin **in;
};
void omap_gpio_set_nb_out(OmapGpio *obj, size_t value);
void omap_gpio_set_nb_in(OmapGpio *obj, size_t value);
void omap_gpio_set_nb_regions(OmapGpio *obj, size_t value);
At initfn(), you register three integer properties, 'nb_out', 'nb_in',
'nb_regions'.
In the respective setters, you allocate the appropriate array and then
unregister the old properties, and then register teh new ones. For
instance:
void omap_gpio_set_nb_out(OmapGpio *obj, size_t value)
{
/* remove old properties */
for (i = 0; i < obj->nb_out; i++) {
plug_del_property_plug(PLUG(obj), "out[%d]", i);
}
obj->out = realloc(obj->out, new_size);
obj->nb_out = value;
/* add new properties */
for (i = 0; i < obj->nb_out; i++) {
plug_add_property_plug(PLUG(obj), &obj->pin[i],
TYPE_PIN, "out[%d]", i);
}
}
This would let you work with the device like this:
[OmapGpio "gpio"]
nb_out = 4
nb_in = 2
in[0] = "foo.out[0]"
in[1] = "foo.out[1]"
[OmapFoo "foo"]
bar = "gpio.out[3]"
It's exactly this use-case which makes GObject unsuitable. Properties
need to be associated with the instance, not the class. qdev also
suffers from this problem.
Regards,
Anthony Liguori
> * for each 'module', three specific named outgoing gpio lines
> "mpu_irq", "dsp_irq" and "wakeup"
> * a number of omap_clk connections, where an omap_clk* represents
> a connection to the OMAP clock tree, and in practice is an
> interface where the omap_gpio can (a) call a function to
> ask "what rate is this clock running at?" and (b) provide
> a gpio line which will be raised when the clock ticks.
> [omap_gpio doesn't actually use its clock connections but
> other omap devices do; they're interesting because we have
> function calls going in both directions over the interface.]
>
> None of these exposed interfaces are particularly obviously
> more important than any of the others -- they're just all
> things that might need to be wired up.
>
> I'm particularly interested in how much effort is involved
> in defining ad-hoc platform-specific interface types like
> omap_clk.
>
> -- PMM
>
prev parent reply other threads:[~2011-07-27 22:31 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-25 1:44 [Qemu-devel] [RFC][PATCH 0/21] QEMU Object Model Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 01/21] qom: add make infrastructure Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 02/21] qom: convert QAPI to use Qconfig build system Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 03/21] qom: Add core type system Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 04/21] qom: add Plug class Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 05/21] plug: add Plug property type Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 06/21] plug: add socket " Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 07/21] plug: add generated property types Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 08/21] qom: add plug_create QMP command Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 09/21] qom: add plug_list " Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 10/21] qom: add plug_get " Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 11/21] qom: add plug_set " Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 12/21] qom: add plug_list_props " Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 13/21] qom: add plug_destroy command Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 14/21] qom: add example qsh command Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 15/21] qom: add Device class Anthony Liguori
2011-07-27 15:10 ` Peter Maydell
2011-07-27 16:07 ` Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 16/21] qom-devices: add a Pin class Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 17/21] qom: add CharDriver class Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 18/21] qom-chrdrv: add memory character driver Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 19/21] qom-chrdrv: add Socket base class Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 20/21] qom-chrdrv: add TCPServer class Anthony Liguori
2011-07-25 1:44 ` [Qemu-devel] [PATCH 21/21] qom-chrdrv: add UnixServer Anthony Liguori
2011-07-25 11:21 ` [Qemu-devel] [RFC][PATCH 0/21] QEMU Object Model Kevin Wolf
2011-07-25 12:45 ` Anthony Liguori
2011-07-25 13:08 ` Kevin Wolf
2011-07-25 13:10 ` Anthony Liguori
2011-07-26 12:59 ` Paolo Bonzini
2011-07-26 14:02 ` Anthony Liguori
2011-07-26 14:35 ` Paolo Bonzini
2011-07-26 15:34 ` Anthony Liguori
2011-07-26 18:26 ` Paolo Bonzini
2011-07-26 19:23 ` Anthony Liguori
2011-07-27 8:55 ` Paolo Bonzini
2011-07-27 12:48 ` Anthony Liguori
2011-07-27 15:33 ` Paolo Bonzini
2011-07-27 16:19 ` Anthony Liguori
2011-07-27 16:28 ` Anthony Liguori
2011-07-27 18:51 ` Paolo Bonzini
2011-07-27 20:01 ` Anthony Liguori
2011-07-28 7:36 ` Paolo Bonzini
2011-07-28 12:46 ` Anthony Liguori
2011-07-28 13:50 ` Paolo Bonzini
2011-07-28 14:03 ` Anthony Liguori
2011-07-28 14:41 ` Paolo Bonzini
2011-07-28 15:04 ` Anthony Liguori
2011-07-28 15:47 ` Paolo Bonzini
2011-07-28 17:59 ` Anthony Liguori
2011-07-29 7:19 ` Paolo Bonzini
2011-07-27 21:33 ` Peter Maydell
2011-07-27 22:31 ` Anthony Liguori [this message]
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=4E3091C2.3090605@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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).