[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 00/18] qom: dynamic properties and compositio

From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH v2 00/18] qom: dynamic properties and composition tree (v2)
Date: Mon, 05 Dec 2011 09:04:49 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13

On 12/05/2011 08:50 AM, Peter Maydell wrote:
On 5 December 2011 14:36, Anthony Liguori<address@hidden>  wrote:
struct LSIDevice {
    PCIDevice parent;

static void lsi_command_complete(SCSIBus *bus, SCSIRequest *req)
   LSIDevice *dev = LSI_DEVICE(bus);

What is the LSI_DEVICE macro actually doing here? I assume
it's not just a cast...


It's quite literally dynamic_cast<LSIDevice>(bus) in C++.

static void lsi_scsi_bus_initfn(Interface *iface)
   SCSIBus *bus = SCSI_BUS(iface);

   bus->command_complete = lsi_command_complete;

TypeInfo lsi_device_info = {
  .name = TYPE_LSI,
  .parent = TYPE_PCI_DEVICE,
  .interfaces = (Interface[]){
        .name = TYPE_SCSI_BUS,
        .interface_initfn = lsi_scsi_bus_initfn,
     }, {


Perhaps hidden with some macro that lets me just write
SCSI_BUS_INTERFACE(dev), but that's the idea; such a lookup function is
pretty much what all object models do. GObject has

If I understood everything so far, then here is my question. Are
interfaces properties?

No.  A device is-a interface.  Hopefully the above example will make it more

Saying a device is-a interface doesn't match reality. Devices
have multiple interfaces with the rest of the world.

There are two ways a device can interact with the rest of the world. It can expose a portion of it's functionality (such as an IRQ) via a child object. This is how it would expose MemoryRegions too.

You can take a subset of the exposed children (and perhaps some mapping logic), and for an ad-hoc interface.

But sometimes, you want the entire device to act like a specific thing. In this case, you want the LSIDevice to act like SCSIBus. Interfaces are just a more formal form of what would otherwise be an ad-hoc interface.

(This is
one of the major reasons why SysBus exists: it provides a suboptimal
but usuable model of this for the two most common kinds of interface,
MMIO regions and random gpio.)

My expectation is that most things that use SysBus today would not implement any interfaces. They would just expose child properties.


Anthony Liguori

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]