diff mbox

[v2,2/5] hw:pci-host:piix: split i440fx_init

Message ID 20140731091050.GA31192@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin July 31, 2014, 9:10 a.m. UTC
On Thu, Jul 31, 2014 at 02:31:36PM +0800, Tiejun Chen wrote:
> We'd like to split i440fx_init and then we can share something
> with other stuff.
> 
> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>

I think this is too much work for very little benefit.
Just pass const char *type to i440fx_init.

-->

i440fx: make type configurable at run-time

Xen wants to supply a different pci host device,
inheriting i440fx. Make this configurable.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

--

Comments

Tiejun Chen July 31, 2014, 9:26 a.m. UTC | #1
On 2014/7/31 17:10, Michael S. Tsirkin wrote:
> On Thu, Jul 31, 2014 at 02:31:36PM +0800, Tiejun Chen wrote:
>> We'd like to split i440fx_init and then we can share something
>> with other stuff.
>>
>> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
>
> I think this is too much work for very little benefit.
> Just pass const char *type to i440fx_init.

You know we will introduce that faked PCIe device represented that PCH 
later, so how to distinguish them? Are you saying I should check the 
type like this?

if(Xen-Type)
{}
else
{}

If so, actually this is mostly same as my original implementation,

"
@@ -333,8 +348,15 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     object_property_add_child(qdev_get_machine(), "i440fx", 
OBJECT(dev), NULL);
     qdev_init_nofail(dev);

-    d = pci_create_simple(b, 0, TYPE_I440FX_PCI_DEVICE);
-    *pi440fx_state = I440FX_PCI_DEVICE(d);
+    if (xen_enabled() && xen_has_gfx_passthru) {
+        d = pci_create_simple(b, 0, TYPE_I440FX_XEN_PCI_DEVICE);
+        *pi440fx_state = I440FX_XEN_PCI_DEVICE(d);
+        pci_create_pch(b);
+    } else {
+        d = pci_create_simple(b, 0, TYPE_I440FX_PCI_DEVICE);
+        *pi440fx_state = I440FX_PCI_DEVICE(d);
+    }
+
     f = *pi440fx_state;
     f->system_memory = address_space_mem;
     f->pci_address_space = pci_address_space;
"

But as I said to you last time, Paolo doesn't like we walk the common 
codes :)

Tiejun

>
> -->
>
> i440fx: make type configurable at run-time
>
> Xen wants to supply a different pci host device,
> inheriting i440fx. Make this configurable.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> --
>
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index be8fdfe..72e612b 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -230,7 +230,8 @@ extern int no_hpet;
>   struct PCII440FXState;
>   typedef struct PCII440FXState PCII440FXState;
>
> -PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
> +PCIBus *i440fx_init(const char *type,
> +                    PCII440FXState **pi440fx_state, int *piix_devfn,
>                       ISABus **isa_bus, qemu_irq *pic,
>                       MemoryRegion *address_space_mem,
>                       MemoryRegion *address_space_io,
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 31125b7..5fefde6 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -194,7 +194,8 @@ static void pc_init1(MachineState *machine,
>       }
>
>       if (pci_enabled) {
> -        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
> +        pci_bus = i440fx_init(TYPE_I440FX_PCI_HOST_BRIDGE,
> +                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
>                                 system_memory, system_io, machine->ram_size,
>                                 below_4g_mem_size,
>                                 above_4g_mem_size,
> diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
> index e0e0946..f0c5b5d 100644
> --- a/hw/pci-host/piix.c
> +++ b/hw/pci-host/piix.c
> @@ -305,7 +305,8 @@ static int i440fx_initfn(PCIDevice *dev)
>       return 0;
>   }
>
> -PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
> +PCIBus *i440fx_init(const char *type,
> +                    PCII440FXState **pi440fx_state,
>                       int *piix3_devfn,
>                       ISABus **isa_bus, qemu_irq *pic,
>                       MemoryRegion *address_space_mem,
> @@ -325,7 +326,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
>       unsigned i;
>       I440FXState *i440fx;
>
> -    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST_BRIDGE);
> +    dev = qdev_create(NULL, type);
>       s = PCI_HOST_BRIDGE(dev);
>       b = pci_bus_new(dev, NULL, pci_address_space,
>                       address_space_io, 0, TYPE_PCI_BUS);
>
>
diff mbox

Patch

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index be8fdfe..72e612b 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -230,7 +230,8 @@  extern int no_hpet;
 struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
+PCIBus *i440fx_init(const char *type,
+                    PCII440FXState **pi440fx_state, int *piix_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 31125b7..5fefde6 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -194,7 +194,8 @@  static void pc_init1(MachineState *machine,
     }
 
     if (pci_enabled) {
-        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
+        pci_bus = i440fx_init(TYPE_I440FX_PCI_HOST_BRIDGE,
+                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
                               system_memory, system_io, machine->ram_size,
                               below_4g_mem_size,
                               above_4g_mem_size,
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index e0e0946..f0c5b5d 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -305,7 +305,8 @@  static int i440fx_initfn(PCIDevice *dev)
     return 0;
 }
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
+PCIBus *i440fx_init(const char *type,
+                    PCII440FXState **pi440fx_state,
                     int *piix3_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
@@ -325,7 +326,7 @@  PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     unsigned i;
     I440FXState *i440fx;
 
-    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST_BRIDGE);
+    dev = qdev_create(NULL, type);
     s = PCI_HOST_BRIDGE(dev);
     b = pci_bus_new(dev, NULL, pci_address_space,
                     address_space_io, 0, TYPE_PCI_BUS);