qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: ehabkost@redhat.com, mst@redhat.com, ghammer@redhat.com,
	lcapitulino@redhat.com, pbonzini@redhat.com, lersek@redhat.com
Subject: [Qemu-devel] [PATCH v17 8/9] pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment
Date: Tue, 19 Jan 2016 14:06:28 +0100	[thread overview]
Message-ID: <1453208789-42479-9-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1453208789-42479-1-git-send-email-imammedo@redhat.com>

currently slot for PIIX3 bridge is selected
dynamically but it's always in slot 1 for
existing machine types.
However it's easy to regress if another PCI
device were added before PIIX3 is created and
also requires passing around devfn of the
created bridge.
Replace dynamic slot assignment with a static
one like it's done for ICH9_LPC, explicitly
setting slot # for the bridge.
While at it cleanup IDE/USB/PIIX4_PM functions
assignment, replacing magic offsets with defines.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
Static assignment will help with adding other
functions to multifunction bridge in following
patch.
---
 hw/i386/pc_piix.c    | 17 ++++++++++-------
 hw/pci-host/piix.c   |  9 ++++-----
 include/hw/i386/pc.h |  8 +++++++-
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index df2b824..ae96272 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -73,7 +73,6 @@ static void pc_init1(MachineState *machine,
     PCIBus *pci_bus;
     ISABus *isa_bus;
     PCII440FXState *i440fx_state;
-    int piix3_devfn = -1;
     qemu_irq *gsi;
     qemu_irq *i8259;
     qemu_irq smi_irq;
@@ -180,7 +179,7 @@ static void pc_init1(MachineState *machine,
     if (pcmc->pci_enabled) {
         pci_bus = i440fx_init(host_type,
                               pci_type,
-                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
+                              &i440fx_state, &isa_bus, gsi,
                               system_memory, system_io, machine->ram_size,
                               pcms->below_4g_mem_size,
                               pcms->above_4g_mem_size,
@@ -230,9 +229,11 @@ static void pc_init1(MachineState *machine,
     if (pcmc->pci_enabled) {
         PCIDevice *dev;
         if (xen_enabled()) {
-            dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
+            dev = pci_piix3_xen_ide_init(pci_bus, hd,
+                PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_IDE_FUNC));
         } else {
-            dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+            dev = pci_piix3_ide_init(pci_bus, hd,
+                PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_IDE_FUNC));
         }
         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
@@ -255,7 +256,8 @@ static void pc_init1(MachineState *machine,
     pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
 
     if (pcmc->pci_enabled && usb_enabled()) {
-        pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
+        pci_create_simple(pci_bus, PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_USB_FUNC),
+                          "piix3-usb-uhci");
     }
 
     if (pcmc->pci_enabled && acpi_enabled) {
@@ -264,8 +266,9 @@ static void pc_init1(MachineState *machine,
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
         /* TODO: Populate SPD eeprom data.  */
-        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                              gsi[9], smi_irq,
+        smbus = piix4_pm_init(pci_bus,
+                              PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PIIX4_PM_FUNC),
+                              0xb100, gsi[9], smi_irq,
                               pc_machine_is_smm_enabled(pcms),
                               &piix4_pm);
         smbus_eeprom_init(smbus, 8, NULL, 0);
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index b0d7e31..b8bf1fc 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -310,7 +310,6 @@ static void i440fx_realize(PCIDevice *dev, Error **errp)
 
 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,
                     MemoryRegion *address_space_io,
@@ -382,13 +381,15 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
      * These additional routes can be discovered through ACPI. */
     if (xen_enabled()) {
         PCIDevice *pci_dev = pci_create_simple_multifunction(b,
-                             -1, true, "PIIX3-xen");
+                             PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PCI_FUNC),
+                             true, "PIIX3-xen");
         piix3 = PIIX3_PCI_DEVICE(pci_dev);
         pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
                 piix3, XEN_PIIX_NUM_PIRQS);
     } else {
         PCIDevice *pci_dev = pci_create_simple_multifunction(b,
-                             -1, true, "PIIX3");
+                             PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PCI_FUNC),
+                             true, "PIIX3");
         piix3 = PIIX3_PCI_DEVICE(pci_dev);
         pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
                 PIIX_NUM_PIRQS);
@@ -397,8 +398,6 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
     piix3->pic = pic;
     *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
 
-    *piix3_devfn = piix3->dev.devfn;
-
     ram_size = ram_size / 8 / 1024 / 1024;
     if (ram_size > 255) {
         ram_size = 255;
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 588a33c..ea0c1d7 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -288,8 +288,14 @@ typedef struct PCII440FXState PCII440FXState;
 
 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
 
+#define PIIX3_PCI_SLOT                       1
+#define PIIX3_PCI_FUNC                       0
+#define PIIX3_IDE_FUNC                       1
+#define PIIX3_USB_FUNC                       2
+#define PIIX3_PIIX4_PM_FUNC                  3
+
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
-                    PCII440FXState **pi440fx_state, int *piix_devfn,
+                    PCII440FXState **pi440fx_state,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
-- 
1.8.3.1

  parent reply	other threads:[~2016-01-19 13:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19 13:06 [Qemu-devel] [PATCH v17 0/9] Virtual Machine Generation ID Igor Mammedov
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 1/9] acpi: extend ACPI interface to provide access to ACPI registers and SCI irq Igor Mammedov
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 2/9] docs: vm generation id device's description Igor Mammedov
2016-01-20 16:40   ` Eric Blake
2016-01-21 12:43     ` Igor Mammedov
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 3/9] pc: add a Virtual Machine Generation ID device Igor Mammedov
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 4/9] tests: add a unit test for the vmgenid device Igor Mammedov
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 5/9] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands Igor Mammedov
2016-01-20 16:44   ` Eric Blake
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 6/9] qmp/hmp: add set-vm-generation-id commands Igor Mammedov
2016-01-20 16:48   ` Eric Blake
2016-01-21 12:46     ` Igor Mammedov
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 7/9] add MachineClass->default_props for setting default device properties Igor Mammedov
2016-01-23 14:59   ` Eduardo Habkost
2016-01-26 10:28     ` Igor Mammedov
2016-01-26 14:12       ` Eduardo Habkost
2016-01-19 13:06 ` Igor Mammedov [this message]
2016-01-19 13:06 ` [Qemu-devel] [PATCH v17 9/9] pc/q53: by default put vmgenid device as an function of ISA bridge Igor Mammedov
2016-01-19 14:48 ` [Qemu-devel] [PATCH v17 0/9] Virtual Machine Generation ID Igor Mammedov
2016-01-19 16:49   ` Laszlo Ersek
2016-01-20  9:18     ` Igor Mammedov
2016-01-20 14:20       ` Laszlo Ersek
2016-01-21 13:08         ` Igor Mammedov

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=1453208789-42479-9-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=ghammer@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).