Skip to contentSkip to conversation

xen: introduce new machine for IGD passthrough

PATCH In review Tiejun Chen 2 participants 14 messages Jul 31, 2014 – Aug 6, 2014

lore
Share & tools
lore
#0 lore raw

v3 cover xen: introduce new machine for IGD passthrough

v3:

* Drop patch #4
* Add one patch #1 from Michael
* Rebase

v2:

* Fix some coding style
* New patch to separate i440fx_init
* Just add prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough
* Based on patch #2 to regenerate
* Unify prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough like patch #3
* Test: boot with a preinstalled ubuntu 14.04 ./i386-softmmu/qemu-system-i386 -hda test.img -m 2560 -boot c -machine pc

As we discussed we need to create a separate machine to support current IGD passthrough.

----------------------------------------------------------------
Tiejun Chen (4):
i440fx: make types configurable at run-time hw:i386:pc_piix: split pc_init1() xen:hw:pci-host:piix: create host bridge to passthrough xen:hw:i386:pc_piix: introduce new machine for IGD passthrough

 hw/i386/pc_piix.c    | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
 hw/pci-host/piix.c   |  50 ++++++++++++++++++++++++++++++++++----
 include/hw/i386/pc.h |   8 ++++++-
 3 files changed, 254 insertions(+), 31 deletions(-)

Thanks
Tiejun

#1 lore raw

PATCH v3 1/4 i440fx: make types configurable at run-time

Xen wants to supply a different pci and host devices, inheriting i440fx devices. Make types configurable.

---
 hw/i386/pc_piix.c    | 4 +++-
 hw/pci-host/piix.c   | 9 ++++-----
 include/hw/i386/pc.h | 6 +++++-
 3 files changed, 12 insertions(+), 7 deletions(-)

v3:

* New patch from Michael

hw/i386/pc_piix.c +3 -1
index 9694f88..928c12c 100644
@@ -194,7 +194,9 @@ 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,
+                              TYPE_I440FX_PCI_DEVICE,
+                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
                               system_memory, system_io, machine->ram_size,
                               below_4g_mem_size,
                               above_4g_mem_size,
hw/pci-host/piix.c +4 -5
index e0e0946..0cd82b8 100644
@@ -40,7 +40,6 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
-#define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
 #define I440FX_PCI_HOST_BRIDGE(obj) \
     OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST_BRIDGE)
 
@@ -91,7 +90,6 @@ typedef struct PIIX3State {
     MemoryRegion rcr_mem;
 } PIIX3State;
 
-#define TYPE_I440FX_PCI_DEVICE "i440FX"
 #define I440FX_PCI_DEVICE(obj) \
     OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE)
 
@@ -305,7 +303,8 @@ static int i440fx_initfn(PCIDevice *dev)
     return 0;
 }
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
+PCIBus *i440fx_init(const char *host_type, const char *pci_type,
+                    PCII440FXState **pi440fx_state,
                     int *piix3_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
@@ -325,7 +324,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     unsigned i;
     I440FXState *i440fx;
 
-    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST_BRIDGE);
+    dev = qdev_create(NULL, host_type);
     s = PCI_HOST_BRIDGE(dev);
     b = pci_bus_new(dev, NULL, pci_address_space,
                     address_space_io, 0, TYPE_PCI_BUS);
@@ -333,7 +332,7 @@ 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);
+    d = pci_create_simple(b, 0, pci_type);
     *pi440fx_state = I440FX_PCI_DEVICE(d);
     f = *pi440fx_state;
     f->system_memory = address_space_mem;
include/hw/i386/pc.h +5 -1
index f4b9b2b..9778a71 100644
@@ -230,7 +230,11 @@ extern int no_hpet;
 struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
+#define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
+#define TYPE_I440FX_PCI_DEVICE "i440FX"
+
+PCIBus *i440fx_init(const char *host_type, const char *pci_type,
+                    PCII440FXState **pi440fx_state, int *piix_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
Signature · 1 line
1.9.1
#2 lore raw

Re: [Qemu-devel] [v3][PATCH 1/4] i440fx: make types configurable at run-time

Quoted 5 lines · Tiejun Chen

Xen wants to supply a different pci and host devices, inheriting i440fx devices. Make types configurable.

You should have a From: line too, otherwise
git will set the Author field incorrectly.

Quoted 92 lines
---
 hw/i386/pc_piix.c    | 4 +++-
 hw/pci-host/piix.c   | 9 ++++-----
 include/hw/i386/pc.h | 6 +++++-
 3 files changed, 12 insertions(+), 7 deletions(-)

v3:

* New patch from Michael

hw/i386/pc_piix.c +3 -1
index 9694f88..928c12c 100644
@@ -194,7 +194,9 @@ 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,
+                              TYPE_I440FX_PCI_DEVICE,
+                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
                               system_memory, system_io, machine->ram_size,
                               below_4g_mem_size,
                               above_4g_mem_size,
hw/pci-host/piix.c +4 -5
index e0e0946..0cd82b8 100644
@@ -40,7 +40,6 @@
  * http://download.intel.com/design/chipsets/datashts/29054901.pdf
  */
 
-#define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
 #define I440FX_PCI_HOST_BRIDGE(obj) \
     OBJECT_CHECK(I440FXState, (obj), TYPE_I440FX_PCI_HOST_BRIDGE)
 
@@ -91,7 +90,6 @@ typedef struct PIIX3State {
     MemoryRegion rcr_mem;
 } PIIX3State;
 
-#define TYPE_I440FX_PCI_DEVICE "i440FX"
 #define I440FX_PCI_DEVICE(obj) \
     OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE)
 
@@ -305,7 +303,8 @@ static int i440fx_initfn(PCIDevice *dev)
     return 0;
 }
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
+PCIBus *i440fx_init(const char *host_type, const char *pci_type,
+                    PCII440FXState **pi440fx_state,
                     int *piix3_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
@@ -325,7 +324,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     unsigned i;
     I440FXState *i440fx;
 
-    dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST_BRIDGE);
+    dev = qdev_create(NULL, host_type);
     s = PCI_HOST_BRIDGE(dev);
     b = pci_bus_new(dev, NULL, pci_address_space,
                     address_space_io, 0, TYPE_PCI_BUS);
@@ -333,7 +332,7 @@ 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);
+    d = pci_create_simple(b, 0, pci_type);
     *pi440fx_state = I440FX_PCI_DEVICE(d);
     f = *pi440fx_state;
     f->system_memory = address_space_mem;
include/hw/i386/pc.h +5 -1
index f4b9b2b..9778a71 100644
@@ -230,7 +230,11 @@ extern int no_hpet;
 struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
+#define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
+#define TYPE_I440FX_PCI_DEVICE "i440FX"
+
+PCIBus *i440fx_init(const char *host_type, const char *pci_type,
+                    PCII440FXState **pi440fx_state, int *piix_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
Signature · 1 line
1.9.1
#3 lore raw

Re: [Qemu-devel] [v3][PATCH 1/4] i440fx: make types configurable at run-time

Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Tiejun Chen

Xen wants to supply a different pci and host devices, inheriting i440fx devices. Make types configurable.

You should have a From: line too, otherwise
git will set the Author field incorrectly.

Will update as follows:

From: Michael S. Tsirkin <[email protected]>

Thanks
Tiejun

#4 lore raw

PATCH v3 2/4 hw:i386:pc_piix: split pc_init1()

In reply to Tiejun Chen

We'd like to split pc_init1 and then we can share something with other stuff.

---
 hw/i386/pc_piix.c | 117 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 93 insertions(+), 24 deletions(-)

v3:

* Rebase

v2:

* Fix some coding style

hw/i386/pc_piix.c +93 -24
index 928c12c..0c40b06 100644
@@ -71,36 +71,29 @@ static bool smbios_legacy_mode;
 static bool gigabyte_align = true;
 static bool has_reserved_memory = true;
 
-/* PC hardware initialisation */
-static void pc_init1(MachineState *machine,
-                     int pci_enabled,
-                     int kvmclock_enabled)
+static ram_addr_t below_4g_mem_size;
+static ram_addr_t above_4g_mem_size;
+static void pc_machine_base_init(MachineState *machine,
+                                 int pci_enabled,
+                                 int kvmclock_enabled,
+                                 DeviceState **pc_icc_bridge,
+                                 MemoryRegion **pc_ram_memory,
+                                 MemoryRegion **pc_pci_memory,
+                                 qemu_irq **pc_gsi,
+                                 GSIState **pc_gsi_state,
+                                 FWCfgState **pc_fw_cfg)
 {
     PCMachineState *pc_machine = PC_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
-    MemoryRegion *system_io = get_system_io();
-    int i;
-    ram_addr_t below_4g_mem_size, above_4g_mem_size;
-    PCIBus *pci_bus;
-    ISABus *isa_bus;
-    PCII440FXState *i440fx_state;
-    int piix3_devfn = -1;
-    qemu_irq *cpu_irq;
-    qemu_irq *gsi;
-    qemu_irq *i8259;
-    qemu_irq *smi_irq;
-    GSIState *gsi_state;
-    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    BusState *idebus[MAX_IDE_BUS];
-    ISADevice *rtc_state;
-    ISADevice *floppy;
-    MemoryRegion *ram_memory;
-    MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
-    DeviceState *icc_bridge;
-    FWCfgState *fw_cfg = NULL;
     PcGuestInfo *guest_info;
     ram_addr_t lowmem;
+    DeviceState *icc_bridge;
+    MemoryRegion *ram_memory;
+    MemoryRegion *pci_memory;
+    qemu_irq *gsi;
+    GSIState *gsi_state;
+    FWCfgState *fw_cfg;
 
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
      * If it doesn't, we need to split it in chunks below and above 4G.
@@ -193,6 +186,31 @@ static void pc_init1(MachineState *machine,
         gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
     }
 
+    *pc_icc_bridge = icc_bridge;
+    *pc_ram_memory = ram_memory;
+    *pc_pci_memory = pci_memory;
+    *pc_gsi = gsi;
+    *pc_gsi_state = gsi_state;
+    *pc_fw_cfg = fw_cfg;
+}
+
+static void pc_machine_pci_bus_init(MachineState *machine,
+                                    int pci_enabled,
+                                    PCII440FXState **pc_i440fx_state,
+                                    int *pc_piix3_devfn,
+                                    PCIBus **pc_pci_bus,
+                                    ISABus **pc_isa_bus,
+                                    qemu_irq *gsi,
+                                    MemoryRegion *pci_memory,
+                                    MemoryRegion *ram_memory)
+{
+    MemoryRegion *system_memory = get_system_memory();
+    MemoryRegion *system_io = get_system_io();
+    PCII440FXState *i440fx_state;
+    int piix3_devfn;
+    PCIBus *pci_bus;
+    ISABus *isa_bus;
+
     if (pci_enabled) {
         pci_bus = i440fx_init(TYPE_I440FX_PCI_HOST_BRIDGE,
                               TYPE_I440FX_PCI_DEVICE,
@@ -207,6 +225,33 @@ static void pc_init1(MachineState *machine,
         isa_bus = isa_bus_new(NULL, system_io);
         no_hpet = 1;
     }
+
+    *pc_i440fx_state = i440fx_state;
+    *pc_piix3_devfn = piix3_devfn;
+    *pc_pci_bus = pci_bus;
+    *pc_isa_bus = isa_bus;
+}
+
+static void pc_machine_device_init(MachineState *machine,
+                                   int pci_enabled,
+                                   GSIState *gsi_state,
+                                   DeviceState *icc_bridge,
+                                   int piix3_devfn,
+                                   FWCfgState *fw_cfg,
+                                   PCIBus *pci_bus,
+                                   ISABus *isa_bus,
+                                   qemu_irq *gsi)
+{
+    int i;
+    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
+    BusState *idebus[MAX_IDE_BUS];
+    qemu_irq *smi_irq;
+    PCMachineState *pc_machine = PC_MACHINE(machine);
+    qemu_irq *cpu_irq;
+    qemu_irq *i8259;
+    ISADevice *rtc_state;
+    ISADevice *floppy;
+
     isa_bus_irqs(isa_bus, gsi);
 
     if (kvm_irqchip_in_kernel()) {
@@ -294,6 +339,30 @@ static void pc_init1(MachineState *machine,
     }
 }
 
+/* PC hardware initialisation */
+static void pc_init1(MachineState *machine,
+                     int pci_enabled,
+                     int kvmclock_enabled)
+{
+    PCIBus *pci_bus = NULL;
+    ISABus *isa_bus = NULL;
+    PCII440FXState *i440fx_state = NULL;
+    int piix3_devfn = -1;
+    qemu_irq *gsi = NULL;
+    GSIState *gsi_state = NULL;
+    MemoryRegion *ram_memory = NULL;
+    MemoryRegion *pci_memory = NULL;
+    DeviceState *icc_bridge = NULL;
+    FWCfgState *fw_cfg = NULL;
+
+    pc_machine_base_init(machine, pci_enabled, kvmclock_enabled, &icc_bridge,
+                         &ram_memory, &pci_memory, &gsi, &gsi_state, &fw_cfg);
+    pc_machine_pci_bus_init(machine, pci_enabled, &i440fx_state, &piix3_devfn,
+                            &pci_bus, &isa_bus, gsi, pci_memory, ram_memory);
+    pc_machine_device_init(machine, pci_enabled, gsi_state, icc_bridge,
+                           piix3_devfn, fw_cfg, pci_bus, isa_bus, gsi);
+}
+
 static void pc_init_pci(MachineState *machine)
 {
     pc_init1(machine, 1, 1);
Signature · 1 line
1.9.1
#5 lore raw

Re: [Qemu-devel] [v3][PATCH 2/4] hw:i386:pc_piix: split pc_init1()

Quoted 4 lines · Tiejun Chen

We'd like to split pc_init1 and then we can share something with other stuff.

With patch 1 in place, this should not be
necessary - just propage the correct types
around.

Quoted 169 lines
---
 hw/i386/pc_piix.c | 117 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 93 insertions(+), 24 deletions(-)

v3:

* Rebase

v2:

* Fix some coding style

hw/i386/pc_piix.c +93 -24
index 928c12c..0c40b06 100644
@@ -71,36 +71,29 @@ static bool smbios_legacy_mode;
 static bool gigabyte_align = true;
 static bool has_reserved_memory = true;
 
-/* PC hardware initialisation */
-static void pc_init1(MachineState *machine,
-                     int pci_enabled,
-                     int kvmclock_enabled)
+static ram_addr_t below_4g_mem_size;
+static ram_addr_t above_4g_mem_size;
+static void pc_machine_base_init(MachineState *machine,
+                                 int pci_enabled,
+                                 int kvmclock_enabled,
+                                 DeviceState **pc_icc_bridge,
+                                 MemoryRegion **pc_ram_memory,
+                                 MemoryRegion **pc_pci_memory,
+                                 qemu_irq **pc_gsi,
+                                 GSIState **pc_gsi_state,
+                                 FWCfgState **pc_fw_cfg)
 {
     PCMachineState *pc_machine = PC_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
-    MemoryRegion *system_io = get_system_io();
-    int i;
-    ram_addr_t below_4g_mem_size, above_4g_mem_size;
-    PCIBus *pci_bus;
-    ISABus *isa_bus;
-    PCII440FXState *i440fx_state;
-    int piix3_devfn = -1;
-    qemu_irq *cpu_irq;
-    qemu_irq *gsi;
-    qemu_irq *i8259;
-    qemu_irq *smi_irq;
-    GSIState *gsi_state;
-    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    BusState *idebus[MAX_IDE_BUS];
-    ISADevice *rtc_state;
-    ISADevice *floppy;
-    MemoryRegion *ram_memory;
-    MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
-    DeviceState *icc_bridge;
-    FWCfgState *fw_cfg = NULL;
     PcGuestInfo *guest_info;
     ram_addr_t lowmem;
+    DeviceState *icc_bridge;
+    MemoryRegion *ram_memory;
+    MemoryRegion *pci_memory;
+    qemu_irq *gsi;
+    GSIState *gsi_state;
+    FWCfgState *fw_cfg;
 
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
      * If it doesn't, we need to split it in chunks below and above 4G.
@@ -193,6 +186,31 @@ static void pc_init1(MachineState *machine,
         gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
     }
 
+    *pc_icc_bridge = icc_bridge;
+    *pc_ram_memory = ram_memory;
+    *pc_pci_memory = pci_memory;
+    *pc_gsi = gsi;
+    *pc_gsi_state = gsi_state;
+    *pc_fw_cfg = fw_cfg;
+}
+
+static void pc_machine_pci_bus_init(MachineState *machine,
+                                    int pci_enabled,
+                                    PCII440FXState **pc_i440fx_state,
+                                    int *pc_piix3_devfn,
+                                    PCIBus **pc_pci_bus,
+                                    ISABus **pc_isa_bus,
+                                    qemu_irq *gsi,
+                                    MemoryRegion *pci_memory,
+                                    MemoryRegion *ram_memory)
+{
+    MemoryRegion *system_memory = get_system_memory();
+    MemoryRegion *system_io = get_system_io();
+    PCII440FXState *i440fx_state;
+    int piix3_devfn;
+    PCIBus *pci_bus;
+    ISABus *isa_bus;
+
     if (pci_enabled) {
         pci_bus = i440fx_init(TYPE_I440FX_PCI_HOST_BRIDGE,
                               TYPE_I440FX_PCI_DEVICE,
@@ -207,6 +225,33 @@ static void pc_init1(MachineState *machine,
         isa_bus = isa_bus_new(NULL, system_io);
         no_hpet = 1;
     }
+
+    *pc_i440fx_state = i440fx_state;
+    *pc_piix3_devfn = piix3_devfn;
+    *pc_pci_bus = pci_bus;
+    *pc_isa_bus = isa_bus;
+}
+
+static void pc_machine_device_init(MachineState *machine,
+                                   int pci_enabled,
+                                   GSIState *gsi_state,
+                                   DeviceState *icc_bridge,
+                                   int piix3_devfn,
+                                   FWCfgState *fw_cfg,
+                                   PCIBus *pci_bus,
+                                   ISABus *isa_bus,
+                                   qemu_irq *gsi)
+{
+    int i;
+    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
+    BusState *idebus[MAX_IDE_BUS];
+    qemu_irq *smi_irq;
+    PCMachineState *pc_machine = PC_MACHINE(machine);
+    qemu_irq *cpu_irq;
+    qemu_irq *i8259;
+    ISADevice *rtc_state;
+    ISADevice *floppy;
+
     isa_bus_irqs(isa_bus, gsi);
 
     if (kvm_irqchip_in_kernel()) {
@@ -294,6 +339,30 @@ static void pc_init1(MachineState *machine,
     }
 }
 
+/* PC hardware initialisation */
+static void pc_init1(MachineState *machine,
+                     int pci_enabled,
+                     int kvmclock_enabled)
+{
+    PCIBus *pci_bus = NULL;
+    ISABus *isa_bus = NULL;
+    PCII440FXState *i440fx_state = NULL;
+    int piix3_devfn = -1;
+    qemu_irq *gsi = NULL;
+    GSIState *gsi_state = NULL;
+    MemoryRegion *ram_memory = NULL;
+    MemoryRegion *pci_memory = NULL;
+    DeviceState *icc_bridge = NULL;
+    FWCfgState *fw_cfg = NULL;
+
+    pc_machine_base_init(machine, pci_enabled, kvmclock_enabled, &icc_bridge,
+                         &ram_memory, &pci_memory, &gsi, &gsi_state, &fw_cfg);
+    pc_machine_pci_bus_init(machine, pci_enabled, &i440fx_state, &piix3_devfn,
+                            &pci_bus, &isa_bus, gsi, pci_memory, ram_memory);
+    pc_machine_device_init(machine, pci_enabled, gsi_state, icc_bridge,
+                           piix3_devfn, fw_cfg, pci_bus, isa_bus, gsi);
+}
+
 static void pc_init_pci(MachineState *machine)
 {
     pc_init1(machine, 1, 1);
Signature · 1 line
1.9.1
#6 lore raw

Re: [Qemu-devel] [v3][PATCH 2/4] hw:i386:pc_piix: split pc_init1()

Quoted 10 lines · Michael S. Tsirkin
Quoted 4 lines · Tiejun Chen

We'd like to split pc_init1 and then we can share something with other stuff.

With patch 1 in place, this should not be
necessary - just propage the correct types
around.

Will rebase this in next version.

Thanks
Tiejun

#7 lore raw

PATCH v3 3/4 xen:hw:pci-host:piix: create host bridge to passthrough

In reply to Tiejun Chen

Implement a pci host bridge specific to passthrough. Actually this just inherits the standard one.

This is based on http://patchwork.ozlabs.org/patch/363810/.

---
 hw/pci-host/piix.c   | 41 +++++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h |  2 ++
 2 files changed, 43 insertions(+)

v3:

* Rebase

v2:

* Just add prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough

hw/pci-host/piix.c +41 -0
index 0cd82b8..26ba1e5 100644
@@ -93,6 +93,9 @@ typedef struct PIIX3State {
 #define I440FX_PCI_DEVICE(obj) \
     OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE)
 
+#define XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(obj) \
+    OBJECT_CHECK(PCII440FXState, (obj), TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE)
+
 struct PCII440FXState {
     /*< private >*/
     PCIDevice parent_obj;
@@ -303,6 +306,16 @@ static int i440fx_initfn(PCIDevice *dev)
     return 0;
 }
 
+static int xen_igd_passthrough_i440fx_initfn(PCIDevice *dev)
+{
+    PCII440FXState *d = XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(dev);
+
+    dev->config[I440FX_SMRAM] = 0x02;
+
+    cpu_smm_register(&i440fx_set_smm, d);
+    return 0;
+}
+
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     PCII440FXState **pi440fx_state,
                     int *piix3_devfn,
@@ -703,6 +716,33 @@ static const TypeInfo i440fx_info = {
     .class_init    = i440fx_class_init,
 };
 
+static void xen_igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = xen_igd_passthrough_i440fx_initfn;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82441;
+    k->revision = 0x02;
+    k->class_id = PCI_CLASS_BRIDGE_HOST;
+    dc->desc = "IGD PT XEN Host bridge";
+    dc->vmsd = &vmstate_i440fx;
+    /*
+     * PCI-facing part of the host bridge, not usable without the
+     * host-facing part, which can't be device_add'ed, yet.
+     */
+    dc->cannot_instantiate_with_device_add_yet = true;
+    dc->hotpluggable   = false;
+}
+
+static const TypeInfo xen_igd_passthrough_i440fx_info = {
+    .name          = TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE,
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(PCII440FXState),
+    .class_init    = xen_igd_passthrough_i440fx_class_init,
+};
+
 static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
                                                 PCIBus *rootbus)
 {
@@ -744,6 +784,7 @@ static const TypeInfo i440fx_pcihost_info = {
 static void i440fx_register_types(void)
 {
     type_register_static(&i440fx_info);
+    type_register_static(&xen_igd_passthrough_i440fx_info);
     type_register_static(&piix3_info);
     type_register_static(&piix3_xen_info);
     type_register_static(&i440fx_pcihost_info);
include/hw/i386/pc.h +2 -0
index 9778a71..98ae1a3 100644
@@ -233,6 +233,8 @@ typedef struct PCII440FXState PCII440FXState;
 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
 #define TYPE_I440FX_PCI_DEVICE "i440FX"
 
+#define TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "xen-igd-passthrough-i440FX"
+
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     PCII440FXState **pi440fx_state, int *piix_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
Signature · 1 line
1.9.1
#8 lore raw

Re: [Qemu-devel] [v3][PATCH 3/4] xen:hw:pci-host:piix: create host bridge to passthrough

Quoted 37 lines · Tiejun Chen

Implement a pci host bridge specific to passthrough. Actually this just inherits the standard one.

This is based on http://patchwork.ozlabs.org/patch/363810/.

---
 hw/pci-host/piix.c   | 41 +++++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h |  2 ++
 2 files changed, 43 insertions(+)

v3:

* Rebase

v2:

* Just add prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough

hw/pci-host/piix.c +3 -0
index 0cd82b8..26ba1e5 100644
@@ -93,6 +93,9 @@ typedef struct PIIX3State {
 #define I440FX_PCI_DEVICE(obj) \
     OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE)
 
+#define XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(obj) \
+    OBJECT_CHECK(PCII440FXState, (obj), TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE)
+
 struct PCII440FXState {
     /*< private >*/
     PCIDevice parent_obj;
@@ -303,6 +306,16 @@ static int i440fx_initfn(PCIDevice *dev)
     return 0;
 }
 

hw/pci-host/piix.c static int i440fx_initfn(PCIDevice *dev) · line 318

Quoted 10 lines
hw/pci-host/piix.c +10 -0
+static int xen_igd_passthrough_i440fx_initfn(PCIDevice *dev)
+{
+    PCII440FXState *d = XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(dev);
+
+    dev->config[I440FX_SMRAM] = 0x02;
+
+    cpu_smm_register(&i440fx_set_smm, d);
+    return 0;
+}
+

This is exactly i440fx_initfn.
Don't copy and paste code like this, reuse existing functions.

Quoted 60 lines
hw/pci-host/piix.c +28 -0
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     PCII440FXState **pi440fx_state,
                     int *piix3_devfn,
@@ -703,6 +716,33 @@ static const TypeInfo i440fx_info = {
     .class_init    = i440fx_class_init,
 };
 
+static void xen_igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = xen_igd_passthrough_i440fx_initfn;
+    k->vendor_id = PCI_VENDOR_ID_INTEL;
+    k->device_id = PCI_DEVICE_ID_INTEL_82441;
+    k->revision = 0x02;
+    k->class_id = PCI_CLASS_BRIDGE_HOST;
+    dc->desc = "IGD PT XEN Host bridge";
+    dc->vmsd = &vmstate_i440fx;
+    /*
+     * PCI-facing part of the host bridge, not usable without the
+     * host-facing part, which can't be device_add'ed, yet.
+     */
+    dc->cannot_instantiate_with_device_add_yet = true;
+    dc->hotpluggable   = false;
+}
+
+static const TypeInfo xen_igd_passthrough_i440fx_info = {
+    .name          = TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE,
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(PCII440FXState),
+    .class_init    = xen_igd_passthrough_i440fx_class_init,
+};
+
 static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
                                                 PCIBus *rootbus)
 {
@@ -744,6 +784,7 @@ static const TypeInfo i440fx_pcihost_info = {
 static void i440fx_register_types(void)
 {
     type_register_static(&i440fx_info);
+    type_register_static(&xen_igd_passthrough_i440fx_info);
     type_register_static(&piix3_info);
     type_register_static(&piix3_xen_info);
     type_register_static(&i440fx_pcihost_info);
include/hw/i386/pc.h +2 -0
index 9778a71..98ae1a3 100644
@@ -233,6 +233,8 @@ typedef struct PCII440FXState PCII440FXState;
 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
 #define TYPE_I440FX_PCI_DEVICE "i440FX"
 
+#define TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "xen-igd-passthrough-i440FX"
+
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     PCII440FXState **pi440fx_state, int *piix_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
Signature · 1 line
1.9.1
#9 lore raw

Re: [Qemu-devel] [v3][PATCH 3/4] xen:hw:pci-host:piix: create host bridge to passthrough

Quoted 38 lines · Michael S. Tsirkin
Quoted 37 lines · Tiejun Chen

Implement a pci host bridge specific to passthrough. Actually this just inherits the standard one.

This is based on http://patchwork.ozlabs.org/patch/363810/.

---
  hw/pci-host/piix.c   | 41 +++++++++++++++++++++++++++++++++++++++++
  include/hw/i386/pc.h |  2 ++
  2 files changed, 43 insertions(+)

v3:

* Rebase

v2:

* Just add prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough

hw/pci-host/piix.c +3 -0
index 0cd82b8..26ba1e5 100644
@@ -93,6 +93,9 @@ typedef struct PIIX3State {
  #define I440FX_PCI_DEVICE(obj) \
      OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE)
 
+#define XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(obj) \
+    OBJECT_CHECK(PCII440FXState, (obj), TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE)
+
  struct PCII440FXState {
      /*< private >*/
      PCIDevice parent_obj;
@@ -303,6 +306,16 @@ static int i440fx_initfn(PCIDevice *dev)
      return 0;
  }
 
Quoted 14 lines

hw/pci-host/piix.c static int i440fx_initfn(PCIDevice *dev) · line 318

Quoted 10 lines
hw/pci-host/piix.c +10 -0
+static int xen_igd_passthrough_i440fx_initfn(PCIDevice *dev)
+{
+    PCII440FXState *d = XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(dev);
+
+    dev->config[I440FX_SMRAM] = 0x02;
+
+    cpu_smm_register(&i440fx_set_smm, d);
+    return 0;
+}
+

This is exactly i440fx_initfn.
Don't copy and paste code like this, reuse existing functions.

We can't reuse i440fx_initfn() simply after we introduce XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE(). But with a further concern I think we also pass type into I440FX_PCI_DEVIC() to index different objects here. Please see next version.

Thanks
Tiejun

#10 lore raw

PATCH v3 4/4 xen:hw:i386:pc_piix: introduce new machine for IGD passthrough

In reply to Tiejun Chen

Now we can introduce a new machine, xenigd, specific to IGD passthrough. This can avoid involving other common codes.

---
 hw/i386/pc_piix.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)

v3:

* Rebase

v2:

* Unify prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough like patch #3

hw/i386/pc_piix.c +106 -0
index 0c40b06..cde39d6 100644
@@ -232,6 +232,46 @@ static void pc_machine_pci_bus_init(MachineState *machine,
     *pc_isa_bus = isa_bus;
 }
 
+#ifdef CONFIG_XEN
+static void xen_igd_passthrough_pc_machine_pci_bus_init(MachineState *machine,
+                                                        int pci_enabled,
+                                                        PCII440FXState **pc_i440fx_state,
+                                                        int *pc_piix3_devfn,
+                                                        PCIBus **pc_pci_bus,
+                                                        ISABus **pc_isa_bus,
+                                                        qemu_irq *gsi,
+                                                        MemoryRegion *pci_memory,
+                                                        MemoryRegion *ram_memory)
+{
+    MemoryRegion *system_memory = get_system_memory();
+    MemoryRegion *system_io = get_system_io();
+    PCII440FXState *i440fx_state;
+    int piix3_devfn;
+    PCIBus *pci_bus;
+    ISABus *isa_bus;
+
+    if (pci_enabled) {
+        pci_bus = i440fx_init(TYPE_I440FX_PCI_HOST_BRIDGE,
+                              TYPE_XEN_IGD_PASSTHROUGH_I440FX_PCI_DEVICE,
+                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
+                              system_memory, system_io, machine->ram_size,
+                              below_4g_mem_size,
+                              above_4g_mem_size,
+                              pci_memory, ram_memory);
+    } else {
+        pci_bus = NULL;
+        i440fx_state = NULL;
+        isa_bus = isa_bus_new(NULL, system_io);
+        no_hpet = 1;
+    }
+
+    *pc_i440fx_state = i440fx_state;
+    *pc_piix3_devfn = piix3_devfn;
+    *pc_pci_bus = pci_bus;
+    *pc_isa_bus = isa_bus;
+}
+#endif
+
 static void pc_machine_device_init(MachineState *machine,
                                    int pci_enabled,
                                    GSIState *gsi_state,
@@ -368,6 +408,38 @@ static void pc_init_pci(MachineState *machine)
     pc_init1(machine, 1, 1);
 }
 
+#ifdef CONFIG_XEN
+static void xen_igd_passthrough_pc_init1(MachineState *machine,
+                                         int pci_enabled,
+                                         int kvmclock_enabled)
+{
+    PCIBus *pci_bus = NULL;
+    ISABus *isa_bus = NULL;
+    PCII440FXState *i440fx_state = NULL;
+    int piix3_devfn = -1;
+    qemu_irq *gsi = NULL;
+    GSIState *gsi_state = NULL;
+    MemoryRegion *ram_memory = NULL;
+    MemoryRegion *pci_memory = NULL;
+    DeviceState *icc_bridge = NULL;
+    FWCfgState *fw_cfg = NULL;
+
+    pc_machine_base_init(machine, pci_enabled, kvmclock_enabled, &icc_bridge,
+                         &ram_memory, &pci_memory, &gsi, &gsi_state, &fw_cfg);
+    xen_igd_passthrough_pc_machine_pci_bus_init(machine, pci_enabled,
+                                                &i440fx_state, &piix3_devfn,
+                                                &pci_bus, &isa_bus, gsi,
+                                                pci_memory, ram_memory);
+    pc_machine_device_init(machine, pci_enabled, gsi_state, icc_bridge,
+                           piix3_devfn, fw_cfg, pci_bus, isa_bus, gsi);
+}
+
+static void xen_igd_passthrough_pc_init_pci(MachineState *machine)
+{
+    xen_igd_passthrough_pc_init1(machine, 1, 1);
+}
+#endif
+
 static void pc_compat_2_0(MachineState *machine)
 {
     /* This value depends on the actual DSDT and SSDT compiled into
@@ -514,6 +586,18 @@ static void pc_xen_hvm_init(MachineState *machine)
         pci_create_simple(bus, -1, "xen-platform");
     }
 }
+
+static void xen_igd_passthrough_pc_hvm_init(MachineState *machine)
+{
+    PCIBus *bus;
+
+    xen_igd_passthrough_pc_init_pci(machine);
+
+    bus = pci_find_primary_bus();
+    if (bus != NULL) {
+        pci_create_simple(bus, -1, "xen-platform");
+    }
+}
 #endif
 
 #define PC_I440FX_MACHINE_OPTIONS \
@@ -963,6 +1047,27 @@ static QEMUMachine xenfv_machine = {
         { /* end of list */ }
     },
 };
+
+static QEMUMachine xenigd_machine = {
+    PC_COMMON_MACHINE_OPTIONS,
+    .name = "xenigd",
+    .desc = "Xen Fully-virtualized PC specific to IGD",
+    .init = xen_igd_passthrough_pc_hvm_init,
+    .max_cpus = HVM_MAX_VCPUS,
+    .default_machine_opts = "accel=xen",
+    .hot_add_cpu = pc_hot_add_cpu,
+    .compat_props = (GlobalProperty[]) {
+        /* xenfv has no fwcfg and so does not load acpi from QEMU.
+         * as such new acpi features don't work.
+         */
+        {
+            .driver   = "PIIX4_PM",
+            .property = "acpi-pci-hotplug-with-bridge-support",
+            .value    = "off",
+        },
+        { /* end of list */ }
+    },
+};
 #endif
 
 static void pc_machine_init(void)
@@ -986,6 +1091,7 @@ static void pc_machine_init(void)
     qemu_register_pc_machine(&isapc_machine);
 #ifdef CONFIG_XEN
     qemu_register_pc_machine(&xenfv_machine);
+    qemu_register_pc_machine(&xenigd_machine);
 #endif
 }
 
Signature · 1 line
1.9.1
#11 lore raw
In reply to Tiejun Chen
Quoted 8 lines · Tiejun Chen

v3:

* Drop patch #4
* Add one patch #1 from Michael
* Rebase

v2:

Quoted 7 lines

* Fix some coding style
* New patch to separate i440fx_init
* Just add prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough
* Based on patch #2 to regenerate
* Unify prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough like patch #3
* Test: boot with a preinstalled ubuntu 14.04 ./i386-softmmu/qemu-system-i386 -hda test.img -m 2560 -boot c -machine pc

In plus, ./i386-softmmu/qemu-system-i386 -hda winxp-32.img -m 2560 -boot c -machine pc

Thanks
Tiejun

Quoted 24 lines

As we discussed we need to create a separate machine to support current IGD passthrough.

----------------------------------------------------------------
Tiejun Chen (4):
i440fx: make types configurable at run-time hw:i386:pc_piix: split pc_init1() xen:hw:pci-host:piix: create host bridge to passthrough xen:hw:i386:pc_piix: introduce new machine for IGD passthrough

  hw/i386/pc_piix.c    | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
  hw/pci-host/piix.c   |  50 ++++++++++++++++++++++++++++++++++----
  include/hw/i386/pc.h |   8 ++++++-
  3 files changed, 254 insertions(+), 31 deletions(-)

Thanks
Tiejun

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw
In reply to Tiejun Chen
Quoted 5 lines · Tiejun Chen

v3:

* Drop patch #4
* Add one patch #1 from Michael
* Rebase

You added my patch but don't use it, so most of
my comment weren't addressed.
Do you plan to send v4 to address them?

Quoted 27 lines

v2:

* Fix some coding style
* New patch to separate i440fx_init
* Just add prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough
* Based on patch #2 to regenerate
* Unify prefix with XEN_IGD_PASSTHROUGH/xen_igd_passthrough like patch #3
* Test: boot with a preinstalled ubuntu 14.04 ./i386-softmmu/qemu-system-i386 -hda test.img -m 2560 -boot c -machine pc

As we discussed we need to create a separate machine to support current IGD passthrough.

----------------------------------------------------------------
Tiejun Chen (4):
i440fx: make types configurable at run-time hw:i386:pc_piix: split pc_init1() xen:hw:pci-host:piix: create host bridge to passthrough xen:hw:i386:pc_piix: introduce new machine for IGD passthrough

 hw/i386/pc_piix.c    | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
 hw/pci-host/piix.c   |  50 ++++++++++++++++++++++++++++++++++----
 include/hw/i386/pc.h |   8 ++++++-
 3 files changed, 254 insertions(+), 31 deletions(-)

Thanks
Tiejun

#13 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 5 lines · Tiejun Chen

v3:

* Drop patch #4
* Add one patch #1 from Michael
* Rebase

You added my patch but don't use it, so most of
my comment weren't addressed.

I guess I should cover those comments and posted some reply as well. But maybe something is confused.

Quoted 2 lines

Do you plan to send v4 to address them?

Anyway, I will send v4 to narrow down that gap to your expectoration.

Thanks
Tiejun