0a122b
From b70ff3a2191f959098f12965c4c7e5adb60be59e Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <b70ff3a2191f959098f12965c4c7e5adb60be59e.1387298827.git.minovotn@redhat.com>
0a122b
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
From: "Michael S. Tsirkin" <mst@redhat.com>
0a122b
Date: Tue, 17 Dec 2013 15:17:24 +0100
0a122b
Subject: [PATCH 14/56] pc: pass PCI hole ranges to Guests
0a122b
0a122b
RH-Author: Michael S. Tsirkin <mst@redhat.com>
0a122b
Message-id: <1387293161-4085-15-git-send-email-mst@redhat.com>
0a122b
Patchwork-id: 56320
0a122b
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 14/57] pc: pass PCI hole ranges to Guests
0a122b
Bugzilla: 1034876
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
0a122b
Guest currently has to jump through lots of hoops to guess the PCI hole
0a122b
ranges.  It's fragile, and makes us change BIOS each time we add a new
0a122b
chipset.  Let's report the window in a ROM file, to make BIOS do exactly
0a122b
what QEMU intends.
0a122b
0a122b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
(cherry picked from commit f8c457b88d72a48989f190bc3d7b79f4f3b7d11c)
0a122b
0a122b
Conflicts:
0a122b
	hw/i386/pc_piix.c
0a122b
	hw/i386/pc_q35.c
0a122b
---
0a122b
 include/hw/i386/pc.h |  1 +
0a122b
 hw/i386/pc.c         | 26 ++++++++++++++++++++++++++
0a122b
 hw/i386/pc_piix.c    | 16 +++++++++++++++-
0a122b
 hw/i386/pc_q35.c     | 12 ++++++++++--
0a122b
 4 files changed, 52 insertions(+), 3 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 hw/i386/pc.c         | 26 ++++++++++++++++++++++++++
0a122b
 hw/i386/pc_piix.c    | 16 +++++++++++++++-
0a122b
 hw/i386/pc_q35.c     | 12 ++++++++++--
0a122b
 include/hw/i386/pc.h |  1 +
0a122b
 4 files changed, 52 insertions(+), 3 deletions(-)
0a122b
0a122b
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
0a122b
index 68a8e1b..238f6a0 100644
0a122b
--- a/hw/i386/pc.c
0a122b
+++ b/hw/i386/pc.c
0a122b
@@ -985,6 +985,31 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
0a122b
     }
0a122b
 }
0a122b
 
0a122b
+/* pci-info ROM file. Little endian format */
0a122b
+typedef struct PcRomPciInfo {
0a122b
+    uint64_t w32_min;
0a122b
+    uint64_t w32_max;
0a122b
+    uint64_t w64_min;
0a122b
+    uint64_t w64_max;
0a122b
+} PcRomPciInfo;
0a122b
+
0a122b
+static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
0a122b
+{
0a122b
+    PcRomPciInfo *info;
0a122b
+    if (!guest_info->has_pci_info) {
0a122b
+        return;
0a122b
+    }
0a122b
+
0a122b
+    info = g_malloc(sizeof *info);
0a122b
+    info->w32_min = cpu_to_le64(guest_info->pci_info.w32.begin);
0a122b
+    info->w32_max = cpu_to_le64(guest_info->pci_info.w32.end);
0a122b
+    info->w64_min = cpu_to_le64(guest_info->pci_info.w64.begin);
0a122b
+    info->w64_max = cpu_to_le64(guest_info->pci_info.w64.end);
0a122b
+    /* Pass PCI hole info to guest via a side channel.
0a122b
+     * Required so guest PCI enumeration does the right thing. */
0a122b
+    fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
0a122b
+}
0a122b
+
0a122b
 typedef struct PcGuestInfoState {
0a122b
     PcGuestInfo info;
0a122b
     Notifier machine_done;
0a122b
@@ -996,6 +1021,7 @@ void pc_guest_info_machine_done(Notifier *notifier, void *data)
0a122b
     PcGuestInfoState *guest_info_state = container_of(notifier,
0a122b
                                                       PcGuestInfoState,
0a122b
                                                       machine_done);
0a122b
+    pc_fw_cfg_guest_info(&guest_info_state->info);
0a122b
 }
0a122b
 
0a122b
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
0a122b
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
0a122b
index 3a77998..6d50a4e 100644
0a122b
--- a/hw/i386/pc_piix.c
0a122b
+++ b/hw/i386/pc_piix.c
0a122b
@@ -59,6 +59,7 @@ static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
0a122b
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
0a122b
 
0a122b
 static bool smbios_type1_defaults = true;
0a122b
+static bool has_pci_info = true;
0a122b
 
0a122b
 /* PC hardware initialisation */
0a122b
 static void pc_init1(QEMUMachineInitArgs *args,
0a122b
@@ -122,6 +123,7 @@ static void pc_init1(QEMUMachineInitArgs *args,
0a122b
     }
0a122b
 
0a122b
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
0a122b
+    guest_info->has_pci_info = has_pci_info;
0a122b
 
0a122b
     /* Set PCI window size the way seabios has always done it. */
0a122b
     /* Power of 2 so bios can cover it with a single MTRR */
0a122b
@@ -248,8 +250,15 @@ static void pc_init_pci(QEMUMachineInitArgs *args)
0a122b
 
0a122b
 #if 0 /* Disabled for Red Hat Enterprise Linux */
0a122b
 
0a122b
+static void pc_init_pci_1_5(QEMUMachineInitArgs *args)
0a122b
+{
0a122b
+    has_pci_info = false;
0a122b
+    pc_init_pci(args);
0a122b
+}
0a122b
+
0a122b
 static void pc_init_pci_1_4(QEMUMachineInitArgs *args)
0a122b
 {
0a122b
+    has_pci_info = false;
0a122b
     x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
0a122b
     x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ);
0a122b
     pc_init_pci(args);
0a122b
@@ -257,6 +266,7 @@ static void pc_init_pci_1_4(QEMUMachineInitArgs *args)
0a122b
 
0a122b
 static void pc_init_pci_1_3(QEMUMachineInitArgs *args)
0a122b
 {
0a122b
+    has_pci_info = false;
0a122b
     enable_compat_apic_id_mode();
0a122b
     pc_init_pci(args);
0a122b
 }
0a122b
@@ -264,6 +274,7 @@ static void pc_init_pci_1_3(QEMUMachineInitArgs *args)
0a122b
 /* PC machine init function for pc-1.1 to pc-1.2 */
0a122b
 static void pc_init_pci_1_2(QEMUMachineInitArgs *args)
0a122b
 {
0a122b
+    has_pci_info = false;
0a122b
     disable_kvm_pv_eoi();
0a122b
     enable_compat_apic_id_mode();
0a122b
     pc_init_pci(args);
0a122b
@@ -272,6 +283,7 @@ static void pc_init_pci_1_2(QEMUMachineInitArgs *args)
0a122b
 /* PC machine init function for pc-0.14 to pc-1.0 */
0a122b
 static void pc_init_pci_1_0(QEMUMachineInitArgs *args)
0a122b
 {
0a122b
+    has_pci_info = false;
0a122b
     disable_kvm_pv_eoi();
0a122b
     enable_compat_apic_id_mode();
0a122b
     pc_init_pci(args);
0a122b
@@ -280,6 +292,7 @@ static void pc_init_pci_1_0(QEMUMachineInitArgs *args)
0a122b
 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
0a122b
 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
0a122b
 {
0a122b
+    has_pci_info = false;
0a122b
     disable_kvm_pv_eoi();
0a122b
     enable_compat_apic_id_mode();
0a122b
     pc_init1(args, get_system_memory(), get_system_io(), 1, 0);
0a122b
@@ -290,6 +303,7 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
0a122b
     if (!args->cpu_model) {
0a122b
         args->cpu_model = "486";
0a122b
     }
0a122b
+    has_pci_info = false;
0a122b
     disable_kvm_pv_eoi();
0a122b
     enable_compat_apic_id_mode();
0a122b
     pc_init1(args, get_system_memory(), get_system_io(), 0, 1);
0a122b
@@ -310,7 +324,7 @@ static QEMUMachine pc_i440fx_machine_v1_5 = {
0a122b
     .name = "pc-i440fx-1.5",
0a122b
     .alias = "pc",
0a122b
     .desc = "Standard PC (i440FX + PIIX, 1996)",
0a122b
-    .init = pc_init_pci,
0a122b
+    .init = pc_init_pci_1_5,
0a122b
     .hot_add_cpu = pc_hot_add_cpu,
0a122b
     .max_cpus = 255,
0a122b
     .is_default = 1,
0a122b
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
0a122b
index 9fab93c..7a58b61 100644
0a122b
--- a/hw/i386/pc_q35.c
0a122b
+++ b/hw/i386/pc_q35.c
0a122b
@@ -49,6 +49,7 @@
0a122b
 #define MAX_SATA_PORTS     6
0a122b
 
0a122b
 static bool smbios_type1_defaults = true;
0a122b
+static bool has_pci_info = true;
0a122b
 
0a122b
 /* PC hardware initialisation */
0a122b
 static void pc_q35_init(QEMUMachineInitArgs *args)
0a122b
@@ -108,6 +109,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
0a122b
     }
0a122b
 
0a122b
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
0a122b
+    guest_info->has_pci_info = has_pci_info;
0a122b
 
0a122b
     /* allocate ram and load rom/bios */
0a122b
     if (!xen_enabled()) {
0a122b
@@ -213,18 +215,24 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
0a122b
 
0a122b
 #if 0 /* Disabled for Red Hat Enterprise Linux */
0a122b
 
0a122b
+static void pc_q35_init_1_5(QEMUMachineInitArgs *args)
0a122b
+{
0a122b
+    has_pci_info = false;
0a122b
+    pc_q35_init(args);
0a122b
+}
0a122b
+
0a122b
 static void pc_q35_init_1_4(QEMUMachineInitArgs *args)
0a122b
 {
0a122b
     x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
0a122b
     x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ);
0a122b
-    pc_q35_init(args);
0a122b
+    pc_q35_init_1_5(args);
0a122b
 }
0a122b
 
0a122b
 static QEMUMachine pc_q35_machine_v1_5 = {
0a122b
     .name = "pc-q35-1.5",
0a122b
     .alias = "q35",
0a122b
     .desc = "Standard PC (Q35 + ICH9, 2009)",
0a122b
-    .init = pc_q35_init,
0a122b
+    .init = pc_q35_init_1_5,
0a122b
     .hot_add_cpu = pc_hot_add_cpu,
0a122b
     .max_cpus = 255,
0a122b
     .compat_props = (GlobalProperty[]) {
0a122b
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
0a122b
index 2518db6..2992464 100644
0a122b
--- a/include/hw/i386/pc.h
0a122b
+++ b/include/hw/i386/pc.h
0a122b
@@ -21,6 +21,7 @@ typedef struct PcPciInfo {
0a122b
 
0a122b
 struct PcGuestInfo {
0a122b
     PcPciInfo pci_info;
0a122b
+    bool has_pci_info;
0a122b
     FWCfgState *fw_cfg;
0a122b
 };
0a122b
 
0a122b
-- 
0a122b
1.7.11.7
0a122b