diff mbox

[1/8] qdev/pci: add pci_create_noinit()

Message ID 1252672351-12937-2-git-send-email-kraxel@redhat.com
State Superseded
Headers show

Commit Message

Gerd Hoffmann Sept. 11, 2009, 12:32 p.m. UTC
Like pci_create_simple() but doesn't call qdev_init(), so one can
set properties before initializing the device.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci.c |   11 ++++++++---
 hw/pci.h |    1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Markus Armbruster Sept. 11, 2009, 2:14 p.m. UTC | #1
Gerd Hoffmann <kraxel@redhat.com> writes:

> Like pci_create_simple() but doesn't call qdev_init(), so one can
> set properties before initializing the device.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/pci.c |   11 ++++++++---
>  hw/pci.h |    1 +
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index c12b0be..64d70ed 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -923,15 +923,20 @@ void pci_qdev_register_many(PCIDeviceInfo *info)
>      }
>  }
>  
> -PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
> +PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
>  {
>      DeviceState *dev;
>  
>      dev = qdev_create(&bus->qbus, name);
>      qdev_prop_set_uint32(dev, "addr", devfn);
> -    qdev_init(dev);
> +    return DO_UPCAST(PCIDevice, qdev, dev);
> +}

Okay, this is qdev_create() specialized for PCI.  What about calling it
just pci_create()?

>  
> -    return (PCIDevice *)dev;
> +PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
> +{
> +    PCIDevice *dev = pci_create_noinit(bus, devfn, name);
> +    qdev_init(&dev->qdev);
> +    return dev;
>  }
>  
>  static int pci_find_space(PCIDevice *pdev, uint8_t size)
> diff --git a/hw/pci.h b/hw/pci.h
> index 6196b6a..e7bf33a 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -328,6 +328,7 @@ void pci_qdev_register(PCIDeviceInfo *info);
>  void pci_qdev_register_many(PCIDeviceInfo *info);
>  
>  PCIDevice *pci_create(const char *name, const char *devaddr);
> +PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name);
>  PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
>  
>  /* lsi53c895a.c */
Gerd Hoffmann Sept. 11, 2009, 2:28 p.m. UTC | #2
>> -PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
>> +PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
>>   {
>>       DeviceState *dev;
>>
>>       dev = qdev_create(&bus->qbus, name);
>>       qdev_prop_set_uint32(dev, "addr", devfn);
>> -    qdev_init(dev);
>> +    return DO_UPCAST(PCIDevice, qdev, dev);
>> +}
>
> Okay, this is qdev_create() specialized for PCI.  What about calling it
> just pci_create()?

pci_create() should go away once it has no more users.  It doesn't 
accept a pcibus parameter as it should.

cheers,
   Gerd
Markus Armbruster Sept. 11, 2009, 2:57 p.m. UTC | #3
Gerd Hoffmann <kraxel@redhat.com> writes:

>>> -PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
>>> +PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
>>>   {
>>>       DeviceState *dev;
>>>
>>>       dev = qdev_create(&bus->qbus, name);
>>>       qdev_prop_set_uint32(dev, "addr", devfn);
>>> -    qdev_init(dev);
>>> +    return DO_UPCAST(PCIDevice, qdev, dev);
>>> +}
>>
>> Okay, this is qdev_create() specialized for PCI.  What about calling it
>> just pci_create()?
>
> pci_create() should go away once it has no more users.  It doesn't
> accept a pcibus parameter as it should.

I missed the fact that pci_create() already exists.  That's a pity.
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index c12b0be..64d70ed 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -923,15 +923,20 @@  void pci_qdev_register_many(PCIDeviceInfo *info)
     }
 }
 
-PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
 {
     DeviceState *dev;
 
     dev = qdev_create(&bus->qbus, name);
     qdev_prop_set_uint32(dev, "addr", devfn);
-    qdev_init(dev);
+    return DO_UPCAST(PCIDevice, qdev, dev);
+}
 
-    return (PCIDevice *)dev;
+PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+{
+    PCIDevice *dev = pci_create_noinit(bus, devfn, name);
+    qdev_init(&dev->qdev);
+    return dev;
 }
 
 static int pci_find_space(PCIDevice *pdev, uint8_t size)
diff --git a/hw/pci.h b/hw/pci.h
index 6196b6a..e7bf33a 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -328,6 +328,7 @@  void pci_qdev_register(PCIDeviceInfo *info);
 void pci_qdev_register_many(PCIDeviceInfo *info);
 
 PCIDevice *pci_create(const char *name, const char *devaddr);
+PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name);
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
 /* lsi53c895a.c */