xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Anthony Liguori" <aliguori@us.ibm.com>,
	xen-devel@lists.xensource.com,
	"Stefano Stabellini" <stefano.stabellini@eu.citrix.com>,
	"Alexander Graf" <agraf@suse.de>,
	qemu-devel@nongnu.org, "Blue Swirl" <blauwirbel@gmail.com>,
	"Andreas Färber" <andreas.faerber@web.de>,
	qemu-ppc@nongnu.org, "Paul Brook" <paul@codesourcery.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>
Subject: Re: [PATCH 26/28] pci: convert to QEMU Object Model
Date: Wed, 25 Jan 2012 07:34:13 -0600	[thread overview]
Message-ID: <4F2004D5.9060804@codemonkey.ws> (raw)
In-Reply-To: <20120125124124.GA22203@redhat.com>

On 01/25/2012 06:41 AM, Michael S. Tsirkin wrote:
> On Tue, Jan 24, 2012 at 01:33:18PM -0600, Anthony Liguori wrote:
>> diff --git a/hw/ac97.c b/hw/ac97.c
>> index 03be99b..33b85f5 100644
>> --- a/hw/ac97.c
>> +++ b/hw/ac97.c
>> @@ -1344,21 +1344,30 @@ int ac97_init (PCIBus *bus)
>>       return 0;
>>   }
>>
>> -static PCIDeviceInfo ac97_info = {
>> -    .qdev.name    = "AC97",
>> -    .qdev.desc    = "Intel 82801AA AC97 Audio",
>> -    .qdev.size    = sizeof (AC97LinkState),
>> -    .qdev.vmsd    =&vmstate_ac97,
>> -    .init         = ac97_initfn,
>> -    .exit         = ac97_exitfn,
>> -    .vendor_id    = PCI_VENDOR_ID_INTEL,
>> -    .device_id    = PCI_DEVICE_ID_INTEL_82801AA_5,
>> -    .revision     = 0x01,
>> -    .class_id     = PCI_CLASS_MULTIMEDIA_AUDIO,
>> -    .qdev.props   = (Property[]) {
>> -        DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
>> -        DEFINE_PROP_END_OF_LIST(),
>> -    }
>> +static Property ac97_properties[] = {
>> +    DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
>> +    DEFINE_PROP_END_OF_LIST(),
>> +};
>> +
>> +static void ac97_class_init(ObjectClass *klass, void *data)
>> +{
>> +    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
>> +
>> +    k->init = ac97_initfn;
>> +    k->exit = ac97_exitfn;
>> +    k->vendor_id = PCI_VENDOR_ID_INTEL;
>> +    k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
>> +    k->revision = 0x01;
>> +    k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
>> +}
>> +
>> +static DeviceInfo ac97_info = {
>> +    .name = "AC97",
>> +    .desc = "Intel 82801AA AC97 Audio",
>> +    .size = sizeof (AC97LinkState),
>> +    .vmsd =&vmstate_ac97,
>> +    .props = ac97_properties,
>> +    .class_init = ac97_class_init,
>>   };
>>
>>   static void ac97_register (void)
>
> So I have a question on this: the whole reason
> we moved class, vendor id etc away from device init
> functions to a table was to make it possible
> to perform queries, like list all available sound device
> types, or sort devices based on type, based on these tables.
>
> Another purpose was to remove the manually written description/name,
> embedding pci id database in qemu instead, and performing
> lookups based on device/vendor id.
>
> We never got these patches but it sounds like a genuinely useful
> functionality.
>
> Is this no longer possible?

There is one class instance per type.  It's initialized lazily but the types are 
always known.  IOW, ac97_class_init() is called once on the global 
PCIDeviceClass object, most likely very early during init.

These class objects can be searched and interacted with independently of any 
existing object.  What you're after is:

static void show_pci_device(ObjectClass *klass, void *opaque)
{
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);

     printf("Device %s is %02x:%02x\n",
            object_class_get_name(klass), pc->vendor_id, pc->device_id);
}

{
     ...
     object_class_foreach(show_pci_device, TYPE_PCI_DEVICE, false, NULL);
}

Regards,

Anthony Liguori

      reply	other threads:[~2012-01-25 13:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1327433600-7403-1-git-send-email-aliguori@us.ibm.com>
2012-01-24 19:33 ` [PATCH 26/28] pci: convert to QEMU Object Model Anthony Liguori
2012-01-25 12:41   ` Michael S. Tsirkin
2012-01-25 13:34     ` 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=4F2004D5.9060804@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=andreas.faerber@web.de \
    --cc=blauwirbel@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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).