Group QEMU platform setup together and move to paravirt.c.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/src/coreboot.c b/src/coreboot.c
index c0c6653..0d44834 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -13,6 +13,8 @@
#include "disk.h" // MAXDESCSIZE
#include "config.h" // CONFIG_*
#include "acpi.h" // find_pmtimer
+#include "pci.h" // pci_probe_devices
+
/****************************************************************
* Memory map
@@ -125,6 +127,9 @@
void
coreboot_preinit(void)
{
+ if (!CONFIG_COREBOOT)
+ return;
+
dprintf(3, "Attempting to find coreboot table\n");
// Find coreboot table.
@@ -204,10 +209,14 @@
}
void
-coreboot_biostable_setup(void)
+coreboot_platform_setup(void)
{
+ if (!CONFIG_COREBOOT)
+ return;
+ pci_probe_devices();
+
struct cb_memory *cbm = CBMemTable;
- if (! CONFIG_COREBOOT || !cbm)
+ if (!cbm)
return;
dprintf(3, "Relocating coreboot bios tables\n");
diff --git a/src/mtrr.c b/src/mtrr.c
index 0575b14..56f85f9 100644
--- a/src/mtrr.c
+++ b/src/mtrr.c
@@ -6,7 +6,6 @@
#include "util.h" // dprintf
#include "config.h" // CONFIG_*
-#include "paravirt.h" // runningOnXen
#include "pci.h" // pcimem_start
#define MSR_MTRRcap 0x000000fe
@@ -34,7 +33,7 @@
void mtrr_setup(void)
{
- if (!CONFIG_MTRR_INIT || runningOnXen())
+ if (!CONFIG_MTRR_INIT)
return;
u32 eax, ebx, ecx, edx, cpuid_features;
diff --git a/src/paravirt.c b/src/paravirt.c
index aa4a421..f76b47f 100644
--- a/src/paravirt.c
+++ b/src/paravirt.c
@@ -19,6 +19,7 @@
#include "acpi.h" // acpi_setup
#include "mptable.h" // mptable_setup
#include "pci.h" // create_pirtable
+#include "xen.h" // xen_biostable_setup
/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
* should be used to determine that a VM is running under KVM.
@@ -45,11 +46,16 @@
}
void
-qemu_ramsize_preinit(void)
+qemu_preinit(void)
{
if (!CONFIG_QEMU)
return;
+ if (runningOnXen()) {
+ xen_ramsize_preinit();
+ return;
+ }
+
PlatformRunningOn = PF_QEMU;
kvm_preinit();
@@ -77,8 +83,27 @@
}
void
-qemu_biostable_setup(void)
+qemu_platform_setup(void)
{
+ if (!CONFIG_QEMU)
+ return;
+
+ if (runningOnXen()) {
+ pci_probe_devices();
+ xen_hypercall_setup();
+ xen_biostable_setup();
+ return;
+ }
+
+ // Initialize pci
+ pci_setup();
+ smm_setup();
+
+ // Initialize mtrr and smp
+ mtrr_setup();
+ smp_setup();
+
+ // Create bios tables
pirtable_setup();
mptable_setup();
smbios_setup();
diff --git a/src/paravirt.h b/src/paravirt.h
index 4438273..96b35ba 100644
--- a/src/paravirt.h
+++ b/src/paravirt.h
@@ -23,8 +23,8 @@
return CONFIG_QEMU && GET_GLOBAL(PlatformRunningOn) & PF_KVM;
}
-void qemu_ramsize_preinit(void);
-void qemu_biostable_setup(void);
+void qemu_preinit(void);
+void qemu_platform_setup(void);
void qemu_cfg_init(void);
#endif
diff --git a/src/pciinit.c b/src/pciinit.c
index 1d34653..d757ab6 100644
--- a/src/pciinit.c
+++ b/src/pciinit.c
@@ -11,7 +11,6 @@
#include "pci_regs.h" // PCI_COMMAND
#include "ioport.h" // PORT_ATA1_CMD_BASE
#include "config.h" // CONFIG_*
-#include "paravirt.h" // runningOnXen
#include "memmap.h" // add_e820
#include "dev-q35.h"
@@ -734,11 +733,8 @@
void
pci_setup(void)
{
- if (!CONFIG_QEMU || runningOnXen()) {
- // PCI setup already done by coreboot or Xen - just do probe.
- pci_probe_devices();
+ if (!CONFIG_QEMU)
return;
- }
dprintf(3, "pci setup\n");
diff --git a/src/post.c b/src/post.c
index 3af3638..f2eded9 100644
--- a/src/post.c
+++ b/src/post.c
@@ -159,24 +159,9 @@
mathcp_setup();
timer_setup();
- // Initialize pci
- pci_setup();
- smm_setup();
-
- // Initialize mtrr and smp
- mtrr_setup();
- smp_setup();
-
- // Setup Xen hypercalls
- xen_hypercall_setup();
-
- // Setup external BIOS interface tables
- if (CONFIG_COREBOOT)
- coreboot_biostable_setup();
- else if (runningOnXen())
- xen_biostable_setup();
- else
- qemu_biostable_setup();
+ // Platform specific setup
+ qemu_platform_setup();
+ coreboot_platform_setup();
}
void
@@ -314,12 +299,8 @@
dopost(void)
{
// Detect ram and setup internal malloc.
- if (CONFIG_COREBOOT)
- coreboot_preinit();
- else if (runningOnXen())
- xen_ramsize_preinit();
- else
- qemu_ramsize_preinit();
+ qemu_preinit();
+ coreboot_preinit();
malloc_preinit();
// Relocate initialization code and call maininit().
diff --git a/src/smm.c b/src/smm.c
index 4128296..490a626 100644
--- a/src/smm.c
+++ b/src/smm.c
@@ -10,7 +10,6 @@
#include "config.h" // CONFIG_*
#include "ioport.h" // outb
#include "pci_ids.h" // PCI_VENDOR_ID_INTEL
-#include "paravirt.h" // runningOnXen
#include "dev-q35.h"
ASM32FLAT(
@@ -184,7 +183,7 @@
void
smm_setup(void)
{
- if (!CONFIG_USE_SMM || runningOnXen())
+ if (!CONFIG_USE_SMM)
return;
dprintf(3, "init smm\n");
diff --git a/src/util.h b/src/util.h
index 0659d24..8875d95 100644
--- a/src/util.h
+++ b/src/util.h
@@ -327,7 +327,7 @@
extern const char *CBvendor, *CBpart;
struct cbfs_file;
void cbfs_run_payload(struct cbfs_file *file);
-void coreboot_biostable_setup(void);
+void coreboot_platform_setup(void);
void cbfs_payload_setup(void);
void coreboot_preinit(void);
void coreboot_cbfs_init(void);