Skip to contentSkip to conversation

Guest startup time optimization

RFC PATCH In review Chao Peng 6 participants 26 messages Aug 25, 2016 – Sep 12, 2016

lore
Share & tools
lore

Chao Peng

author
#0 lore raw

v2 cover Guest startup time optimization

This patchset is trying to optimize guest startup time by disabling or simplifying some features in QEMU. The version 1 can be found at:
https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg04842.html

Unlike version 1, this version optimizes Q35 directly instead of introducing a totally new platform. But we still keep the design of skipping firmware as till now we don't have good idea to optimize firmware to get the comparable boot time.

The patchset is against commit 5f0e775 (Update version for v2.7.0-rc3 release) on master branch.

Basically this patchset introduces several switches to qemu comandline so that several features can be turned off in some use cases. The default behavior will not change in case no switches are provided.

Performance data:

feature(switches)       time saved in guest
-nosmbus                4ms
-nosata                 6ms
-nopic                  2ms
-nopit                  5ms
-static-prt             8ms
-nofw                   62ms

Thanks,
Chao

Chao Peng (9):
pc: make smbus configurable
pc: make sata configurable
pc: make pic configurable
pc: make pit configurable
acpi: build static _PRT
ich9: enable pm registers when there is no firmware
q35: initialize MMCFG base when there is no firmware
pc: support direct loading protected/long mode kernel
pc: skip firmware

Haozhong Zhang (3):
acpi: expose data structurs and functions of BIOS linker loader
acpi: expose acpi_checksum()
acpi: patch guest ACPI when there is no firmware

 hw/acpi/bios-linker-loader.c         |  83 +---------
 hw/acpi/core.c                       |   2 +-
 hw/acpi/nvdimm.c                     |   6 +-
 hw/i386/Makefile.objs                |   2 +-
 hw/i386/acpi-build-nofw.c            | 295 ++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c                 | 102 +++++++-----
 hw/i386/acpi-build.h                 |   5 +
 hw/i386/pc.c                         | 301 +++++++++++++++++++++++++++++++----
 hw/i386/pc_piix.c                    |   2 +-
 hw/i386/pc_q35.c                     |  60 ++++---
 hw/isa/lpc_ich9.c                    |  12 +-
 hw/pci-host/q35.c                    |  15 +-
 include/hw/acpi/acpi.h               |   2 +
 include/hw/acpi/bios-linker-loader.h |  85 ++++++++++
 include/hw/i386/pc.h                 |  16 +-
 15 files changed, 800 insertions(+), 188 deletions(-)
 create mode 100644 hw/i386/acpi-build-nofw.c
Signature · 1 line
1.8.3.1
author
#1 lore raw

RFC PATCH v2 1/12 pc: make smbus configurable

---
 hw/i386/pc.c         | 23 +++++++++++++++++++++++
 hw/i386/pc_q35.c     | 12 +++++++-----
 include/hw/i386/pc.h |  3 +++
 3 files changed, 33 insertions(+), 5 deletions(-)
hw/i386/pc.c +23 -0
index 022dd1b..66e1961 100644
@@ -2005,6 +2005,27 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
         pcmc->get_hotplug_handler(machine, dev) : NULL;
 }
 
+static void pc_machine_get_prop_bool(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    bool value = *(bool *)opaque;
+
+    visit_type_bool(v, name, &value, errp);
+}
+
+static void pc_machine_set_prop_bool(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    visit_type_bool(v, name, (bool *)opaque, errp);
+}
+
+#define PC_MACHINE_DEFINE_PROP_BOOL(pcms, prop, field, defval)      \
+        pcms->field = defval;                                       \
+        object_property_add(OBJECT(pcms), prop, "bool",             \
+                            pc_machine_get_prop_bool,               \
+                            pc_machine_set_prop_bool,               \
+                            NULL, &pcms->field, &error_abort);
+
 static void
 pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v,
                                           const char *name, void *opaque,
@@ -2168,6 +2189,8 @@ static void pc_machine_initfn(Object *obj)
     pcms->acpi_nvdimm_state.is_enabled = false;
     object_property_add_bool(obj, PC_MACHINE_NVDIMM, pc_machine_get_nvdimm,
                              pc_machine_set_nvdimm, &error_abort);
+
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SMBUS, smbus, true);
 }
 
 static void pc_machine_reset(void)
hw/i386/pc_q35.c +7 -5
index c0b9961..5bb19c1 100644
@@ -247,11 +247,13 @@ static void pc_q35_init(MachineState *machine)
         ehci_create_ich9_with_companions(host_bus, 0x1d);
     }
 
-    /* TODO: Populate SPD eeprom data.  */
-    smbus_eeprom_init(ich9_smb_init(host_bus,
-                                    PCI_DEVFN(ICH9_SMB_DEV, ICH9_SMB_FUNC),
-                                    0xb100),
-                      8, NULL, 0);
+    if (pcms->smbus) {
+        /* TODO: Populate SPD eeprom data.  */
+        smbus_eeprom_init(ich9_smb_init(host_bus,
+                                        PCI_DEVFN(ICH9_SMB_DEV, ICH9_SMB_FUNC),
+                                        0xb100),
+                          8, NULL, 0);
+    }
 
     pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
 
include/hw/i386/pc.h +3 -0
index 74c175c..aec809c 100644
@@ -76,6 +76,8 @@ struct PCMachineState {
     /* Address space used by IOAPIC device. All IOAPIC interrupts
      * will be translated to MSI messages in the address space. */
     AddressSpace *ioapic_as;
+
+    bool smbus;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -84,6 +86,7 @@ struct PCMachineState {
 #define PC_MACHINE_VMPORT           "vmport"
 #define PC_MACHINE_SMM              "smm"
 #define PC_MACHINE_NVDIMM           "nvdimm"
+#define PC_MACHINE_SMBUS            "smbus"
 
 /**
  * PCMachineClass:
Signature · 1 line
1.8.3.1
author
#3 lore raw

RFC PATCH v2 2/12 pc: make sata configurable

In reply to Chao Peng
---
 hw/i386/pc.c         | 12 +++++++-----
 hw/i386/pc_q35.c     | 25 +++++++++++++++----------
 include/hw/i386/pc.h |  2 ++
 3 files changed, 24 insertions(+), 15 deletions(-)
hw/i386/pc.c +7 -5
index 66e1961..99fb9aa 100644
@@ -397,13 +397,13 @@ static void pc_cmos_init_late(void *opaque)
     int i, trans;
 
     val = 0;
-    if (ide_get_geometry(arg->idebus[0], 0,
-                         &cylinders, &heads, &sectors) >= 0) {
+    if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 0,
+                                           &cylinders, &heads, &sectors) >= 0) {
         cmos_init_hd(s, 0x19, 0x1b, cylinders, heads, sectors);
         val |= 0xf0;
     }
-    if (ide_get_geometry(arg->idebus[0], 1,
-                         &cylinders, &heads, &sectors) >= 0) {
+    if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 1,
+                                           &cylinders, &heads, &sectors) >= 0) {
         cmos_init_hd(s, 0x1a, 0x24, cylinders, heads, sectors);
         val |= 0x0f;
     }
@@ -415,7 +415,8 @@ static void pc_cmos_init_late(void *opaque)
            geometry.  It is always such that: 1 <= sects <= 63, 1
            <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
            geometry can be different if a translation is done. */
-        if (ide_get_geometry(arg->idebus[i / 2], i % 2,
+        if (arg->idebus[i / 2] &&
+            ide_get_geometry(arg->idebus[i / 2], i % 2,
                              &cylinders, &heads, &sectors) >= 0) {
             trans = ide_get_bios_chs_trans(arg->idebus[i / 2], i % 2) - 1;
             assert((trans & ~3) == 0);
@@ -2191,6 +2192,7 @@ static void pc_machine_initfn(Object *obj)
                              pc_machine_set_nvdimm, &error_abort);
 
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SMBUS, smbus, true);
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SATA, sata, true);
 }
 
 static void pc_machine_reset(void)
hw/i386/pc_q35.c +15 -10
index 5bb19c1..88da970 100644
@@ -231,16 +231,21 @@ static void pc_q35_init(MachineState *machine)
     /* connect pm stuff to lpc */
     ich9_lpc_pm_init(lpc, pc_machine_is_smm_enabled(pcms));
 
-    /* ahci and SATA device, for q35 1 ahci controller is built-in */
-    ahci = pci_create_simple_multifunction(host_bus,
-                                           PCI_DEVFN(ICH9_SATA1_DEV,
-                                                     ICH9_SATA1_FUNC),
-                                           true, "ich9-ahci");
-    idebus[0] = qdev_get_child_bus(&ahci->qdev, "ide.0");
-    idebus[1] = qdev_get_child_bus(&ahci->qdev, "ide.1");
-    g_assert(MAX_SATA_PORTS == ICH_AHCI(ahci)->ahci.ports);
-    ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
-    ahci_ide_create_devs(ahci, hd);
+    if (pcms->sata) {
+        /* ahci and SATA device, for q35 1 ahci controller is built-in */
+        ahci = pci_create_simple_multifunction(host_bus,
+                                               PCI_DEVFN(ICH9_SATA1_DEV,
+                                                         ICH9_SATA1_FUNC),
+                                               true, "ich9-ahci");
+        idebus[0] = qdev_get_child_bus(&ahci->qdev, "ide.0");
+        idebus[1] = qdev_get_child_bus(&ahci->qdev, "ide.1");
+        g_assert(MAX_SATA_PORTS == ICH_AHCI(ahci)->ahci.ports);
+        ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
+        ahci_ide_create_devs(ahci, hd);
+    } else {
+        idebus[0] = idebus[1] = NULL;
+    }
+
 
     if (machine_usb(machine)) {
         /* Should we create 6 UHCI according to ich9 spec? */
include/hw/i386/pc.h +2 -0
index aec809c..f5be478 100644
@@ -78,6 +78,7 @@ struct PCMachineState {
     AddressSpace *ioapic_as;
 
     bool smbus;
+    bool sata;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -87,6 +88,7 @@ struct PCMachineState {
 #define PC_MACHINE_SMM              "smm"
 #define PC_MACHINE_NVDIMM           "nvdimm"
 #define PC_MACHINE_SMBUS            "smbus"
+#define PC_MACHINE_SATA             "sata"
 
 /**
  * PCMachineClass:
Signature · 1 line
1.8.3.1
author
#4 lore raw

RFC PATCH v2 3/12 pc: make pic configurable

In reply to Chao Peng
---
 hw/i386/pc.c         |  1 +
 hw/i386/pc_q35.c     | 21 ++++++++++++---------
 include/hw/i386/pc.h |  2 ++
 3 files changed, 15 insertions(+), 9 deletions(-)
hw/i386/pc.c +1 -0
index 99fb9aa..ea81283 100644
@@ -2193,6 +2193,7 @@ static void pc_machine_initfn(Object *obj)
 
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SMBUS, smbus, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SATA, sata, true);
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIC, pic, true);
 }
 
 static void pc_machine_reset(void)
hw/i386/pc_q35.c +12 -9
index 88da970..1a961cc 100644
@@ -202,17 +202,20 @@ static void pc_q35_init(MachineState *machine)
     pci_bus_set_route_irq_fn(host_bus, ich9_route_intx_pin_to_irq);
     isa_bus = ich9_lpc->isa_bus;
 
-    if (kvm_pic_in_kernel()) {
-        i8259 = kvm_i8259_init(isa_bus);
-    } else if (xen_enabled()) {
-        i8259 = xen_interrupt_controller_init();
-    } else {
-        i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq());
-    }
+    if (pcms->pic) {
+        if (kvm_pic_in_kernel()) {
+            i8259 = kvm_i8259_init(isa_bus);
+        } else if (xen_enabled()) {
+            i8259 = xen_interrupt_controller_init();
+        } else {
+            i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq());
+        }
 
-    for (i = 0; i < ISA_NUM_IRQS; i++) {
-        gsi_state->i8259_irq[i] = i8259[i];
+        for (i = 0; i < ISA_NUM_IRQS; i++) {
+            gsi_state->i8259_irq[i] = i8259[i];
+        }
     }
+
     if (pcmc->pci_enabled) {
         ioapic_init_gsi(gsi_state, "q35");
     }
include/hw/i386/pc.h +2 -0
index f5be478..d7972ea 100644
@@ -79,6 +79,7 @@ struct PCMachineState {
 
     bool smbus;
     bool sata;
+    bool pic;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -89,6 +90,7 @@ struct PCMachineState {
 #define PC_MACHINE_NVDIMM           "nvdimm"
 #define PC_MACHINE_SMBUS            "smbus"
 #define PC_MACHINE_SATA             "sata"
+#define PC_MACHINE_PIC              "pic"
 
 /**
  * PCMachineClass:
Signature · 1 line
1.8.3.1
author
#6 lore raw

RFC PATCH v2 5/12 acpi: build static _PRT

In reply to Chao Peng

...to reduce the interpretation burden for guest ACPI component.

---
 hw/i386/acpi-build.c | 31 ++++++++++++++++++++++++++++++-
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 ++
 3 files changed, 33 insertions(+), 1 deletion(-)
hw/i386/acpi-build.c +30 -1
index a26a4bb..60c0896 100644
@@ -1772,6 +1772,31 @@ static void build_q35_pci0_int(Aml *table)
     aml_append(table, sb_scope);
 }
 
+static void build_static_q35_pci0_int(Aml *table)
+{
+    int i, j;
+    Aml *method, *res, *pkg;
+    Aml *sb_scope = aml_scope("_SB");
+    Aml *pci0_scope = aml_scope("PCI0");
+
+    method = aml_method("_PRT", 0, AML_NOTSERIALIZED);
+    res = aml_package(128);
+    for (i = 0; i < 32; i++) {
+        for (j = 0; j < 4; j++) {
+            pkg = aml_package(4);
+            aml_append(pkg, aml_int((i << 16) | 0xffff));
+            aml_append(pkg, aml_int(j));
+            aml_append(pkg, aml_int(0));
+            aml_append(pkg, aml_int(0x10 + j));
+            aml_append(res, pkg);
+        }
+    }
+
+    aml_append(method, aml_return(res));
+    aml_append(pci0_scope, method);
+    aml_append(sb_scope, pci0_scope);
+}
+
 static void build_q35_isa_bridge(Aml *table)
 {
     Aml *dev;
@@ -2007,7 +2032,11 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         build_hpet_aml(dsdt);
         build_q35_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
-        build_q35_pci0_int(dsdt);
+        if (pcms->static_prt) {
+            build_static_q35_pci0_int(dsdt);
+        } else {
+            build_q35_pci0_int(dsdt);
+        }
     }
 
     if (pcmc->legacy_cpu_hotplug) {
hw/i386/pc.c +1 -0
index 1d62957..f479697 100644
@@ -2196,6 +2196,7 @@ static void pc_machine_initfn(Object *obj)
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SATA, sata, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIC, pic, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIT, pit, true);
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_STATIC_PRT, static_prt, false);
 }
 
 static void pc_machine_reset(void)
include/hw/i386/pc.h +2 -0
index 1dc7954..55ab09a 100644
@@ -81,6 +81,7 @@ struct PCMachineState {
     bool sata;
     bool pic;
     bool pit;
+    bool static_prt;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -93,6 +94,7 @@ struct PCMachineState {
 #define PC_MACHINE_SATA             "sata"
 #define PC_MACHINE_PIC              "pic"
 #define PC_MACHINE_PIT              "pit"
+#define PC_MACHINE_STATIC_PRT       "static-prt"
 
 /**
  * PCMachineClass:
Signature · 1 line
1.8.3.1
author
#5 lore raw

RFC PATCH v2 4/12 pc: make pit configurable

In reply to Chao Peng
---
 hw/i386/pc.c         | 6 ++++--
 hw/i386/pc_piix.c    | 2 +-
 hw/i386/pc_q35.c     | 2 +-
 include/hw/i386/pc.h | 5 ++++-
 4 files changed, 10 insertions(+), 5 deletions(-)
hw/i386/pc.c +4 -2
index ea81283..1d62957 100644
@@ -1520,7 +1520,8 @@ static const MemoryRegionOps ioportF0_io_ops = {
     },
 };
 
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(PCMachineState *pcms,
+                          ISABus *isa_bus, qemu_irq *gsi,
                           ISADevice **rtc_state,
                           bool create_fdctrl,
                           bool no_vmport,
@@ -1577,7 +1578,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
 
     qemu_register_boot_set(pc_boot_set, *rtc_state);
 
-    if (!xen_enabled()) {
+    if (!xen_enabled() && pcms->pit) {
         if (kvm_pit_in_kernel()) {
             pit = kvm_pit_init(isa_bus, 0x40);
         } else {
@@ -2194,6 +2195,7 @@ static void pc_machine_initfn(Object *obj)
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SMBUS, smbus, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SATA, sata, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIC, pic, true);
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIT, pit, true);
 }
 
 static void pc_machine_reset(void)
hw/i386/pc_piix.c +1 -1
index a07dc81..028dc0a 100644
@@ -235,7 +235,7 @@ static void pc_init1(MachineState *machine,
     }
 
     /* init basic PC hardware */
-    pc_basic_device_init(isa_bus, gsi, &rtc_state, true,
+    pc_basic_device_init(pcms, isa_bus, gsi, &rtc_state, true,
                          (pcms->vmport != ON_OFF_AUTO_ON), 0x4);
 
     pc_nic_init(isa_bus, pci_bus);
hw/i386/pc_q35.c +1 -1
index 1a961cc..d28b7b6 100644
@@ -228,7 +228,7 @@ static void pc_q35_init(MachineState *machine)
     }
 
     /* init basic PC hardware */
-    pc_basic_device_init(isa_bus, gsi, &rtc_state, !mc->no_floppy,
+    pc_basic_device_init(pcms, isa_bus, gsi, &rtc_state, !mc->no_floppy,
                          (pcms->vmport != ON_OFF_AUTO_ON), 0xff0104);
 
     /* connect pm stuff to lpc */
include/hw/i386/pc.h +4 -1
index d7972ea..1dc7954 100644
@@ -80,6 +80,7 @@ struct PCMachineState {
     bool smbus;
     bool sata;
     bool pic;
+    bool pit;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -91,6 +92,7 @@ struct PCMachineState {
 #define PC_MACHINE_SMBUS            "smbus"
 #define PC_MACHINE_SATA             "sata"
 #define PC_MACHINE_PIC              "pic"
+#define PC_MACHINE_PIT              "pit"
 
 /**
  * PCMachineClass:
@@ -262,7 +264,8 @@ void pc_memory_init(PCMachineState *pcms,
                     MemoryRegion **ram_memory);
 qemu_irq pc_allocate_cpu_irq(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(PCMachineState *pcms,
+                          ISABus *isa_bus, qemu_irq *gsi,
                           ISADevice **rtc_state,
                           bool create_fdctrl,
                           bool no_vmport,
Signature · 1 line
1.8.3.1
author
#8 lore raw

RFC PATCH v2 6/12 acpi: expose data structurs and functions of BIOS linker loader

In reply to Chao Peng

From: Haozhong Zhang <[email protected]>

Expose some data structures and functions of BIOS linker loader which will be used by later commits.

---
 hw/acpi/bios-linker-loader.c         | 83 +----------------------------------
 include/hw/acpi/bios-linker-loader.h | 85 ++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 82 deletions(-)
hw/acpi/bios-linker-loader.c +1 -82
index d963ebe..e9c19cf 100644
@@ -21,91 +21,10 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "hw/acpi/bios-linker-loader.h"
-#include "hw/nvram/fw_cfg.h"
 
 #include "qemu/bswap.h"
 
 /*
- * Linker/loader is a paravirtualized interface that passes commands to guest.
- * The commands can be used to request guest to
- * - allocate memory chunks and initialize them from QEMU FW CFG files
- * - link allocated chunks by storing pointer to one chunk into another
- * - calculate ACPI checksum of part of the chunk and store into same chunk
- */
-#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
-
-struct BiosLinkerLoaderEntry {
-    uint32_t command;
-    union {
-        /*
-         * COMMAND_ALLOCATE - allocate a table from @alloc.file
-         * subject to @alloc.align alignment (must be power of 2)
-         * and @alloc.zone (can be HIGH or FSEG) requirements.
-         *
-         * Must appear exactly once for each file, and before
-         * this file is referenced by any other command.
-         */
-        struct {
-            char file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t align;
-            uint8_t zone;
-        } alloc;
-
-        /*
-         * COMMAND_ADD_POINTER - patch the table (originating from
-         * @dest_file) at @pointer.offset, by adding a pointer to the table
-         * originating from @src_file. 1,2,4 or 8 byte unsigned
-         * addition is used depending on @pointer.size.
-         */
-        struct {
-            char dest_file[BIOS_LINKER_LOADER_FILESZ];
-            char src_file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t offset;
-            uint8_t size;
-        } pointer;
-
-        /*
-         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
-         * @cksum_start and @cksum_length fields,
-         * and then add the value at @cksum.offset.
-         * Checksum simply sums -X for each byte X in the range
-         * using 8-bit math.
-         */
-        struct {
-            char file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t offset;
-            uint32_t start;
-            uint32_t length;
-        } cksum;
-
-        /* padding */
-        char pad[124];
-    };
-} QEMU_PACKED;
-typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
-
-enum {
-    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
-    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
-    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
-};
-
-enum {
-    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
-    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
-};
-
-/*
- * BiosLinkerFileEntry:
- *
- * An internal type used for book-keeping file entries
- */
-typedef struct BiosLinkerFileEntry {
-    char *name; /* file name */
-    GArray *blob; /* data accosiated with @name */
-} BiosLinkerFileEntry;
-
-/*
  * bios_linker_loader_init: allocate a new linker object instance.
  *
  * After initialization, linker commands can be added, and will
@@ -137,7 +56,7 @@ void bios_linker_loader_cleanup(BIOSLinker *linker)
     g_free(linker);
 }
 
-static const BiosLinkerFileEntry *
+const BiosLinkerFileEntry *
 bios_linker_find_file(const BIOSLinker *linker, const char *name)
 {
     int i;
include/hw/acpi/bios-linker-loader.h +85 -0

101 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#9 lore raw

RFC PATCH v2 7/12 acpi: expose acpi_checksum()

In reply to Chao Peng

From: Haozhong Zhang <[email protected]>

It will be used in later commits.

---
 hw/acpi/core.c         | 2 +-
 include/hw/acpi/acpi.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
hw/acpi/core.c +1 -1
index e890a5d..95ba06d 100644
@@ -69,7 +69,7 @@ static void acpi_register_config(void)
 
 opts_init(acpi_register_config);
 
-static int acpi_checksum(const uint8_t *data, int len)
+int acpi_checksum(const uint8_t *data, int len)
 {
     int sum, i;
     sum = 0;
include/hw/acpi/acpi.h +2 -0
index 7b3d93c..fee6606 100644
@@ -189,4 +189,6 @@ struct AcpiSlicOem {
 };
 int acpi_get_slic_oem(AcpiSlicOem *oem);
 
+int acpi_checksum(const uint8_t *data, int len);
+
 #endif /* QEMU_HW_ACPI_H */
Signature · 1 line
1.8.3.1
author
#12 lore raw

RFC PATCH v2 10/12 q35: initialize MMCFG base when there is no firmware

In reply to Chao Peng
---
 hw/pci-host/q35.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
hw/pci-host/q35.c +13 -2
index e33d5a5..c5c5fe2 100644
@@ -448,9 +448,18 @@ static void mch_reset(DeviceState *qdev)
 {
     PCIDevice *d = PCI_DEVICE(qdev);
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    uint64_t pciexbar = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT;
 
-    pci_set_quad(d->config + MCH_HOST_BRIDGE_PCIEXBAR,
-                 MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT);
+    if (!pcms->fw_cfg) {
+        pciexbar |= MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M;
+        pciexbar |= MCH_HOST_BRIDGE_PCIEXBAREN;
+
+        e820_add_entry(MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT,
+                       MCH_HOST_BRIDGE_PCIEXBAR_MAX, E820_RESERVED);
+    }
+
+    pci_set_quad(d->config + MCH_HOST_BRIDGE_PCIEXBAR, pciexbar);
 
     d->config[MCH_HOST_BRIDGE_SMRAM] = MCH_HOST_BRIDGE_SMRAM_DEFAULT;
     d->config[MCH_HOST_BRIDGE_ESMRAMC] = MCH_HOST_BRIDGE_ESMRAMC_DEFAULT;
@@ -516,6 +525,8 @@ static void mch_realize(PCIDevice *d, Error **errp)
     init_pam(DEVICE(mch), mch->ram_memory, mch->system_memory,
              mch->pci_address_space, &mch->pam_regions[1],
              PAM_EXPAN_BASE, 12 * PAM_EXPAN_SIZE);
+
+    mch_reset(DEVICE(mch));
 }
 
 uint64_t mch_mcfg_base(void)
Signature · 1 line
1.8.3.1
author
#10 lore raw

RFC PATCH v2 8/12 acpi: patch guest ACPI when there is no firmware

In reply to Chao Peng

From: Haozhong Zhang <[email protected]>

Traditionally, guest firmware is responsible to patch ACPI tables generated by QEMU. However, no firmware is used with pc-lite and patching ACPI should be done in QEMU for pc-lite.

---
 hw/acpi/nvdimm.c          |   6 +-
 hw/i386/Makefile.objs     |   2 +-
 hw/i386/acpi-build-nofw.c | 295 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c      |  71 +++++------
 hw/i386/acpi-build.h      |   5 +
 5 files changed, 341 insertions(+), 38 deletions(-)
 create mode 100644 hw/i386/acpi-build-nofw.c
hw/acpi/nvdimm.c +4 -2
index e486128..a05463e 100644
@@ -770,8 +770,10 @@ void nvdimm_init_acpi_state(AcpiNVDIMMState *state, MemoryRegion *io,
 
     state->dsm_mem = g_array_new(false, true /* clear */, 1);
     acpi_data_push(state->dsm_mem, sizeof(NvdimmDsmIn));
-    fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data,
-                    state->dsm_mem->len);
+    if (fw_cfg) {
+        fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data,
+                        state->dsm_mem->len);
+    }
 }
 
 #define NVDIMM_COMMON_DSM      "NCAL"
hw/i386/Makefile.objs +1 -1
index 90e94ff..9d81af7 100644
@@ -6,5 +6,5 @@ obj-y += x86-iommu.o intel_iommu.o
 obj-$(CONFIG_XEN) += ../xenpv/ xen/
 
 obj-y += kvmvapic.o
-obj-y += acpi-build.o
+obj-y += acpi-build.o acpi-build-nofw.o
 obj-y += pci-assign-load-rom.o
hw/i386/acpi-build-nofw.c new file +295 -0

295 lines not on this page · raw message

hw/i386/acpi-build.c +36 -35

96 lines not on this page · raw message

hw/i386/acpi-build.h +5 -0
index 007332e..4e5f2e5 100644
@@ -2,6 +2,11 @@
 #ifndef HW_I386_ACPI_BUILD_H
 #define HW_I386_ACPI_BUILD_H
 
+#include "hw/i386/pc.h"
+#include "hw/acpi/bios-linker-loader.h"
+#include "qapi/error.h"
+
 void acpi_setup(void);
+void acpi_build_nofw(PCMachineState *pcms, BIOSLinker *linker, Error **errp);
 
 #endif
Signature · 1 line
1.8.3.1
author
#11 lore raw

RFC PATCH v2 9/12 ich9: enable pm registers when there is no firmware

In reply to Chao Peng
---
 hw/isa/lpc_ich9.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
hw/isa/lpc_ich9.c +10 -2
index 10d1ee8..28e9911 100644
@@ -484,6 +484,9 @@ static void ich9_lpc_reset(DeviceState *qdev)
 {
     PCIDevice *d = PCI_DEVICE(qdev);
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    uint32_t pm_base = ICH9_LPC_PMBASE_DEFAULT;
+    uint8_t lpc_ctlr = ICH9_LPC_ACPI_CTRL_DEFAULT;
     uint32_t rcba_old = pci_get_long(d->config + ICH9_LPC_RCBA);
     int i;
 
@@ -495,9 +498,14 @@ static void ich9_lpc_reset(DeviceState *qdev)
         pci_set_byte(d->config + ICH9_LPC_PIRQE_ROUT + i,
                      ICH9_LPC_PIRQ_ROUT_DEFAULT);
     }
-    pci_set_byte(d->config + ICH9_LPC_ACPI_CTRL, ICH9_LPC_ACPI_CTRL_DEFAULT);
 
-    pci_set_long(d->config + ICH9_LPC_PMBASE, ICH9_LPC_PMBASE_DEFAULT);
+    if (!pcms->fw_cfg) {
+        lpc_ctlr = ICH9_LPC_ACPI_CTRL_ACPI_EN;
+        pm_base = 0x600 | ICH9_LPC_PMBASE_RTE;
+    }
+
+    pci_set_byte(d->config + ICH9_LPC_ACPI_CTRL, lpc_ctlr);
+    pci_set_long(d->config + ICH9_LPC_PMBASE, pm_base);
     pci_set_long(d->config + ICH9_LPC_RCBA, ICH9_LPC_RCBA_DEFAULT);
 
     ich9_cc_reset(lpc);
Signature · 1 line
1.8.3.1
author
#13 lore raw

RFC PATCH v2 11/12 pc: support direct loading protected/long mode kernel

In reply to Chao Peng

Traditionally a PC follows the following booting steps:

    QEMU -> BIOS -> bootloader -> kernel realmode code
         -> kernel protected/longmode code.

This process takes lots of time. For light virtualization platform we let QEMU loads protected/long mode kernel directly, hence skipping several steps and speeding up the whole booting. We do this by filling the zero page per Linux booting protocol and then jumping to the kernel protected/long mode entry. Registers and paging should also be put in the correct state.

---
 hw/i386/pc.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 163 insertions(+), 3 deletions(-)
hw/i386/pc.c +163 -3
index f479697..4a368de 100644
@@ -85,6 +85,31 @@
 #define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 #define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
 
+#define BOOT_GDT                0x500
+#define BOOT_IDT                0x520
+#define BOOT_GDT_NULL           0
+#define BOOT_GDT_CODE           1
+#define BOOT_GDT_DATA           2
+#define BOOT_GDT_TSS            3
+#define BOOT_GDT_MAX            4
+#define BOOT_GDT_FLAGS_CODE     (DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK | \
+                                 DESC_R_MASK | DESC_A_MASK | DESC_G_MASK )
+#define BOOT_GDT_FLAGS_DATA     (DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |  \
+                                 DESC_A_MASK | DESC_B_MASK | DESC_G_MASK)
+#define BOOT_GDT_FLAGS_TSS      DESC_P_MASK | (11 << DESC_TYPE_SHIFT)
+#define BOOT_PML4               0x9000
+#define BOOT_PDPTE              0xA000
+#define BOOT_LOADER_SP          0x8000
+#define BOOT_CMDLINE_OFFSET     0x20000
+#define BOOT_ZEROPAGE_OFFSET    0x7000
+
+#define GDT_ENTRY(flags, base, limit)               \
+       ((((base)  & 0xff000000ULL) << (56-24)) |    \
+       (((flags) & 0x0000f0ffULL) << 40) |          \
+       (((limit) & 0x000f0000ULL) << (48-16)) |     \
+       (((base)  & 0x00ffffffULL) << 16) |          \
+       (((limit) & 0x0000ffffULL)))
+
 #define E820_NR_ENTRIES		16
 
 struct e820_entry {
@@ -98,6 +123,13 @@ struct e820_table {
     struct e820_entry entry[E820_NR_ENTRIES];
 } QEMU_PACKED __attribute((__aligned__(4)));
 
+struct kernel_boot_info {
+    uint64_t entry;
+    bool protected_mode;
+    bool long_mode;
+};
+
+static struct kernel_boot_info boot_info;
 static struct e820_table e820_reserve;
 static struct e820_entry *e820_table;
 static unsigned e820_entries;
@@ -665,6 +697,124 @@ bool e820_get_entry(int idx, uint32_t type, uint64_t *address, uint64_t *length)
     return false;
 }
 
+static void reset_cpu(CPUX86State *env)
+{
+    unsigned int flags = BOOT_GDT_FLAGS_CODE;
+
+    if (boot_info.long_mode) {
+        flags |= DESC_L_MASK;
+    }
+    cpu_x86_load_seg_cache(env, R_CS, BOOT_GDT_CODE * 8, 0, 0xfffff, flags);
+
+    cpu_x86_load_seg_cache(env, R_DS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_ES, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_FS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_GS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_SS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+
+    env->gdt.base = BOOT_GDT;
+    env->gdt.limit = BOOT_GDT_MAX * 8 - 1;
+
+    env->idt.base = BOOT_IDT;
+
+    env->tr.selector = BOOT_GDT_TSS * 8;
+    env->tr.flags = BOOT_GDT_FLAGS_TSS;
+
+    env->cr[3] = BOOT_PML4;
+    env->cr[0] |= (CR0_PG_MASK | CR0_PE_MASK);
+
+    if (boot_info.long_mode) {
+        env->cr[4] |= CR4_PAE_MASK;
+        cpu_load_efer(env, env->efer | MSR_EFER_LME | MSR_EFER_LMA);
+    }
+
+    env->regs[R_ESP] = BOOT_LOADER_SP;
+    env->regs[R_ESI] = BOOT_ZEROPAGE_OFFSET;
+    env->eip = boot_info.entry;
+}
+
+static void setup_seg_desc_tables(void)
+{
+    uint64_t idt = 0;
+    uint64_t gdt[BOOT_GDT_MAX] = {
+             [BOOT_GDT_NULL] = GDT_ENTRY(0, 0, 0),
+             [BOOT_GDT_CODE] = GDT_ENTRY(BOOT_GDT_FLAGS_CODE, 0, 0xFFFFF),
+             [BOOT_GDT_DATA] = GDT_ENTRY(BOOT_GDT_FLAGS_DATA, 0, 0xFFFFF),
+             [BOOT_GDT_TSS ] = GDT_ENTRY(BOOT_GDT_FLAGS_TSS, 0, 0xFFFFF)
+            };
+
+    if (boot_info.long_mode) {
+        gdt[BOOT_GDT_CODE] |= (1UL << (32 + DESC_L_SHIFT));
+    }
+
+    cpu_physical_memory_write((hwaddr)BOOT_GDT, gdt, sizeof(gdt));
+    cpu_physical_memory_write((hwaddr)BOOT_IDT, &idt, sizeof(idt));
+}
+
+static void setup_page_tables(void)
+{
+    void *p;
+    size_t len = 4096;
+
+    p = cpu_physical_memory_map(BOOT_PML4, &len, 1);
+    memset(p, 0, 4096);
+    *(uint64_t*)p = (uint64_t)(BOOT_PDPTE | 3);
+    cpu_physical_memory_unmap(p, len, 1, len);
+
+    len = 4096;
+    p = cpu_physical_memory_map(BOOT_PDPTE, &len, 1);
+    memset(p, 0, 4096);
+    *(uint64_t*)p = 0x83;
+    cpu_physical_memory_unmap(p, len, 1, len);
+}
+
+static void setup_kernel_zero_page(void)
+{
+    int i;
+    uint8_t *zero_page;
+    void *e820_map;
+    size_t zero_page_size = 4096;
+    MachineState *machine = MACHINE(qdev_get_machine());
+    size_t cmdline_size = strlen(machine->kernel_cmdline) + 1;
+
+    cpu_physical_memory_write((hwaddr)BOOT_CMDLINE_OFFSET,
+                               machine->kernel_cmdline, cmdline_size);
+
+    zero_page = cpu_physical_memory_map((hwaddr)BOOT_ZEROPAGE_OFFSET,
+                                        &zero_page_size, 1);
+    memset(zero_page, 0, zero_page_size);
+
+    /* hdr.type_of_loader */
+    zero_page[0x210] = 0xFF;
+    /* hdr.boot_flag */
+    stw_p(zero_page + 0x1fe, 0xAA55);
+    /* hdr.header */
+    stl_p(zero_page + 0x202, 0x53726448);
+    /* hdr.cmd_line_ptr */
+    stl_p(zero_page + 0x228, BOOT_CMDLINE_OFFSET);
+    /* hdr.cmdline_size */
+    stl_p(zero_page + 0x238, cmdline_size);
+    /* e820_entries */
+    zero_page[0x1e8] = e820_entries;
+    /* e820_map */
+    e820_map = zero_page + 0x2d0;
+    for (i = 0; i < e820_entries; i++) {
+        stq_p(e820_map, e820_table[i].address);
+        e820_map += 8;
+        stq_p(e820_map, e820_table[i].length);
+        e820_map += 8;
+        stl_p(e820_map, e820_table[i].type);
+        e820_map += 4;
+    }
+
+    cpu_physical_memory_unmap(zero_page, zero_page_size, 1, zero_page_size);
+}
+
 /* Enables contiguous-apic-ID mode, for compatibility */
 static bool compat_apic_id_mode;
 
@@ -2206,15 +2356,25 @@ static void pc_machine_reset(void)
 
     qemu_devices_reset();
 
-    /* Reset APIC after devices have been reset to cancel
-     * any changes that qemu_devices_reset() might have done.
-     */
     CPU_FOREACH(cs) {
         cpu = X86_CPU(cs);
 
+        /* Reset APIC after devices have been reset to cancel
+         * any changes that qemu_devices_reset() might have done.
+         */
         if (cpu->apic_state) {
             device_reset(cpu->apic_state);
         }
+
+        if (boot_info.protected_mode && cpu_is_bsp(cpu)) {
+            reset_cpu(&cpu->env);
+        }
+    }
+
+    if (boot_info.protected_mode) {
+        setup_seg_desc_tables();
+        setup_page_tables();
+        setup_kernel_zero_page();
     }
 }
 
Signature · 1 line
1.8.3.1
author
#14 lore raw

RFC PATCH v2 12/12 pc: skip firmware

In reply to Chao Peng

An ELF format kernel must be specified. Only linux is supported.

---
 hw/i386/pc.c         | 92 ++++++++++++++++++++++++++++++++++++++--------------
 include/hw/i386/pc.h |  2 ++
 2 files changed, 69 insertions(+), 25 deletions(-)
hw/i386/pc.c +67 -25
index 4a368de..1362810 100644
@@ -974,8 +974,43 @@ struct setup_data {
     uint8_t data[0];
 } __attribute__((packed));
 
-static void load_linux(PCMachineState *pcms,
-                       FWCfgState *fw_cfg)
+static void load_linux_efi(PCMachineState *pcms)
+{
+    unsigned char class;
+    MachineState *machine = MACHINE(pcms);
+    FILE *file = fopen(machine->kernel_filename, "rb");
+
+    if (!file) {
+        goto err;
+    }
+
+    if (fseek(file, EI_CLASS, 0) || fread(&class, 1, 1, file) != 1) {
+        fclose(file);
+        goto err;
+    }
+    fclose(file);
+
+    if (load_elf(machine->kernel_filename, NULL, NULL, &boot_info.entry,
+                   NULL, NULL, 0, EM_X86_64, 0, 0) < 0) {
+        goto err;
+    }
+
+    if (class == ELFCLASS64) {
+        boot_info.long_mode = true;
+    } else if (class != ELFCLASS32) {
+        goto err;
+    }
+
+    boot_info.protected_mode = true;
+    return;
+
+err:
+    fprintf(stderr, "qemu: could not load kernel '%s'\n",
+                    machine->kernel_filename);
+    exit(1);
+}
+
+static void load_linux_bzimage(PCMachineState *pcms, FWCfgState *fw_cfg)
 {
     uint16_t protocol;
     int setup_size, kernel_size, initrd_size = 0, cmdline_size;
@@ -1488,7 +1523,7 @@ void xen_load_linux(PCMachineState *pcms)
     fw_cfg = fw_cfg_init_io(FW_CFG_IO_BASE);
     rom_set_fw(fw_cfg);
 
-    load_linux(pcms, fw_cfg);
+    load_linux_bzimage(pcms, fw_cfg);
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
                !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -1506,7 +1541,7 @@ void pc_memory_init(PCMachineState *pcms,
     int linux_boot, i;
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
-    FWCfgState *fw_cfg;
+    FWCfgState *fw_cfg = NULL;
     MachineState *machine = MACHINE(pcms);
     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
 
@@ -1588,36 +1623,42 @@ void pc_memory_init(PCMachineState *pcms,
                                     &pcms->hotplug_memory.mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
+    if (pcms->fw) {
+        /* Initialize PC system firmware */
+        pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
 
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    vmstate_register_ram_global(option_rom_mr);
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        vmstate_register_ram_global(option_rom_mr);
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
 
-    fw_cfg = bochs_bios_init(&address_space_memory, pcms);
+        fw_cfg = bochs_bios_init(&address_space_memory, pcms);
 
-    rom_set_fw(fw_cfg);
+        rom_set_fw(fw_cfg);
 
-    if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) {
-        uint64_t *val = g_malloc(sizeof(*val));
-        PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
-        uint64_t res_mem_end = pcms->hotplug_memory.base;
+        if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) {
+            uint64_t *val = g_malloc(sizeof(*val));
+            PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
+            uint64_t res_mem_end = pcms->hotplug_memory.base;
 
-        if (!pcmc->broken_reserved_end) {
-            res_mem_end += memory_region_size(&pcms->hotplug_memory.mr);
+            if (!pcmc->broken_reserved_end) {
+                res_mem_end += memory_region_size(&pcms->hotplug_memory.mr);
+            }
+            *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
+            fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
         }
-        *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
-        fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
     }
 
     if (linux_boot) {
-        load_linux(pcms, fw_cfg);
+        if (pcms->fw) {
+            load_linux_bzimage(pcms, fw_cfg);
+        } else {
+            load_linux_efi(pcms);
+        }
     }
 
     for (i = 0; i < nb_option_roms; i++) {
@@ -2347,6 +2388,7 @@ static void pc_machine_initfn(Object *obj)
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIC, pic, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIT, pit, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_STATIC_PRT, static_prt, false);
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_FW, fw, true);
 }
 
 static void pc_machine_reset(void)
include/hw/i386/pc.h +2 -0
index 55ab09a..f5e01e1 100644
@@ -82,6 +82,7 @@ struct PCMachineState {
     bool pic;
     bool pit;
     bool static_prt;
+    bool fw;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -95,6 +96,7 @@ struct PCMachineState {
 #define PC_MACHINE_PIC              "pic"
 #define PC_MACHINE_PIT              "pit"
 #define PC_MACHINE_STATIC_PRT       "static-prt"
+#define PC_MACHINE_FW               "fw"
 
 /**
  * PCMachineClass:
Signature · 1 line
1.8.3.1
#7 lore raw

Re: [Qemu-devel] [RFC PATCH v2 05/12] acpi: build static _PRT

In reply to Chao Peng
Quoted 84 lines · Chao Peng

...to reduce the interpretation burden for guest ACPI component.

---
 hw/i386/acpi-build.c | 31 ++++++++++++++++++++++++++++++-
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 ++
 3 files changed, 33 insertions(+), 1 deletion(-)
hw/i386/acpi-build.c +30 -1
index a26a4bb..60c0896 100644
@@ -1772,6 +1772,31 @@ static void build_q35_pci0_int(Aml *table)
     aml_append(table, sb_scope);
 }
 
+static void build_static_q35_pci0_int(Aml *table)
+{
+    int i, j;
+    Aml *method, *res, *pkg;
+    Aml *sb_scope = aml_scope("_SB");
+    Aml *pci0_scope = aml_scope("PCI0");
+
+    method = aml_method("_PRT", 0, AML_NOTSERIALIZED);
+    res = aml_package(128);
+    for (i = 0; i < 32; i++) {
+        for (j = 0; j < 4; j++) {
+            pkg = aml_package(4);
+            aml_append(pkg, aml_int((i << 16) | 0xffff));
+            aml_append(pkg, aml_int(j));
+            aml_append(pkg, aml_int(0));
+            aml_append(pkg, aml_int(0x10 + j));
+            aml_append(res, pkg);
+        }
+    }
+
+    aml_append(method, aml_return(res));
+    aml_append(pci0_scope, method);
+    aml_append(sb_scope, pci0_scope);
+}
+
 static void build_q35_isa_bridge(Aml *table)
 {
     Aml *dev;
@@ -2007,7 +2032,11 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         build_hpet_aml(dsdt);
         build_q35_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
-        build_q35_pci0_int(dsdt);
+        if (pcms->static_prt) {
+            build_static_q35_pci0_int(dsdt);
+        } else {
+            build_q35_pci0_int(dsdt);
+        }
     }
 
     if (pcmc->legacy_cpu_hotplug) {
hw/i386/pc.c +1 -0
index 1d62957..f479697 100644
@@ -2196,6 +2196,7 @@ static void pc_machine_initfn(Object *obj)
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SATA, sata, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIC, pic, true);
     PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIT, pit, true);
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_STATIC_PRT, static_prt, false);
 }
 
 static void pc_machine_reset(void)
include/hw/i386/pc.h +1 -0
index 1dc7954..55ab09a 100644
@@ -81,6 +81,7 @@ struct PCMachineState {
     bool sata;
     bool pic;
     bool pit;
+    bool static_prt;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"

include/hw/i386/pc.h struct PCMachineState { · line 100

Quoted 7 lines
include/hw/i386/pc.h +1 -0
@@ -93,6 +94,7 @@ struct PCMachineState {
 #define PC_MACHINE_SATA             "sata"
 #define PC_MACHINE_PIC              "pic"
 #define PC_MACHINE_PIT              "pit"
+#define PC_MACHINE_STATIC_PRT       "static-prt"
 
 /**
  * PCMachineClass:

You can do this unconditionally, but it should match the contents of the q35 PRT.

Paolo

#15 lore raw

Re: [Qemu-devel] [RFC PATCH v2 12/12] pc: skip firmware

In reply to Chao Peng

hw/i386/pc.c struct setup_data { · line 977

Quoted 3 lines · Chao Peng
hw/i386/pc.c +1 -2
-static void load_linux(PCMachineState *pcms,
-                       FWCfgState *fw_cfg)
+static void load_linux_efi(PCMachineState *pcms)

ELF, not EFI.

Paolo

Quoted 34 lines
hw/i386/pc.c +34 -0
+{
+    unsigned char class;
+    MachineState *machine = MACHINE(pcms);
+    FILE *file = fopen(machine->kernel_filename, "rb");
+
+    if (!file) {
+        goto err;
+    }
+
+    if (fseek(file, EI_CLASS, 0) || fread(&class, 1, 1, file) != 1) {
+        fclose(file);
+        goto err;
+    }
+    fclose(file);
+
+    if (load_elf(machine->kernel_filename, NULL, NULL, &boot_info.entry,
+                   NULL, NULL, 0, EM_X86_64, 0, 0) < 0) {
+        goto err;
+    }
+
+    if (class == ELFCLASS64) {
+        boot_info.long_mode = true;
+    } else if (class != ELFCLASS32) {
+        goto err;
+    }
+
+    boot_info.protected_mode = true;
+    return;
+
+err:
+    fprintf(stderr, "qemu: could not load kernel '%s'\n",
+                    machine->kernel_filename);
+    exit(1);
+}
#16 lore raw
In reply to Chao Peng
Quoted 53 lines · Chao Peng

This patchset is trying to optimize guest startup time by disabling or simplifying some features in QEMU. The version 1 can be found at:
https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg04842.html

Unlike version 1, this version optimizes Q35 directly instead of introducing a totally new platform. But we still keep the design of skipping firmware as till now we don't have good idea to optimize firmware to get the comparable boot time.

The patchset is against commit 5f0e775 (Update version for v2.7.0-rc3 release) on master branch.

Basically this patchset introduces several switches to qemu comandline so that several features can be turned off in some use cases. The default behavior will not change in case no switches are provided.

Performance data:
feature(switches) time saved in guest

(quoted diff) +0 -6
-nosmbus                4ms
-nosata                 6ms
-nopic                  2ms
-nopit                  5ms
-static-prt             8ms
-nofw                   62ms

Thanks,
Chao

Chao Peng (9):
pc: make smbus configurable
pc: make sata configurable
pc: make pic configurable
pc: make pit configurable
acpi: build static _PRT
ich9: enable pm registers when there is no firmware
q35: initialize MMCFG base when there is no firmware
pc: support direct loading protected/long mode kernel
pc: skip firmware

Haozhong Zhang (3):
acpi: expose data structurs and functions of BIOS linker loader
acpi: expose acpi_checksum()
acpi: patch guest ACPI when there is no firmware

 hw/acpi/bios-linker-loader.c         |  83 +---------
 hw/acpi/core.c                       |   2 +-
 hw/acpi/nvdimm.c                     |   6 +-
 hw/i386/Makefile.objs                |   2 +-
 hw/i386/acpi-build-nofw.c            | 295 ++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c                 | 102 +++++++-----
 hw/i386/acpi-build.h                 |   5 +
 hw/i386/pc.c                         | 301 +++++++++++++++++++++++++++++++----
 hw/i386/pc_piix.c                    |   2 +-
Quoted 8 lines
 hw/i386/pc_q35.c                     |  60 ++++---
 hw/isa/lpc_ich9.c                    |  12 +-
 hw/pci-host/q35.c                    |  15 +-
 include/hw/acpi/acpi.h               |   2 +
 include/hw/acpi/bios-linker-loader.h |  85 ++++++++++
 include/hw/i386/pc.h                 |  16 +-
 15 files changed, 800 insertions(+), 188 deletions(-)
 create mode 100644 hw/i386/acpi-build-nofw.c

Patches 1-4 are okay, though I think it would be easier to add a -M q35-lite too that just removes the legacy devices. The -M q35-lite machine doesn't have to support versioning for now.

As you might expect, I don't agree with removing the firmware. There's room for much more optimization before duplicating firmware code in QEMU. I'd rather see numbers for:

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the cbfs flash hack (so that -kernel works), drop PCI bridge initialization, copy less than 64K of memory from ROM to 0xf0000;

2) Linux optimizations: using an uncompressed image to avoid the cost of copying and decompressing. QEMU can already load the image at the right place and the real mode stub can do little more than GDT/IDT setup.

3) PAM optimizations: for -M q35-lite initialize the machine with RAM from 0xc0000 to 1MB.

I know that you ultimately would like to mmap the kernel, but I would like to have a better understanding of where the time is spent.

Thanks,

Paolo

#17 lore raw
Quoted 60 lines · Paolo Bonzini
Quoted 57 lines · Chao Peng

This patchset is trying to optimize guest startup time by disabling or simplifying some features in QEMU. The version 1 can be found at:
https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg04842.html

Unlike version 1, this version optimizes Q35 directly instead of introducing a totally new platform. But we still keep the design of skipping firmware as till now we don't have good idea to optimize firmware to get the comparable boot time.

The patchset is against commit 5f0e775 (Update version for v2.7.0-rc3 release) on master branch.

Basically this patchset introduces several switches to qemu comandline so that several features can be turned off in some use cases. The default behavior will not change in case no switches are provided.

Performance data:
feature(switches) time saved in guest

(quoted diff) +0 -6
-nosmbus                4ms
-nosata                 6ms
-nopic                  2ms
-nopit                  5ms
-static-prt             8ms
-nofw                   62ms

Thanks,
Chao

Chao Peng (9):
pc: make smbus configurable
pc: make sata configurable
pc: make pic configurable
pc: make pit configurable
acpi: build static _PRT
ich9: enable pm registers when there is no firmware
q35: initialize MMCFG base when there is no firmware
pc: support direct loading protected/long mode kernel
pc: skip firmware

Haozhong Zhang (3):
acpi: expose data structurs and functions of BIOS linker loader
acpi: expose acpi_checksum()
acpi: patch guest ACPI when there is no firmware

 hw/acpi/bios-linker-loader.c         |  83 +---------
 hw/acpi/core.c                       |   2 +-
 hw/acpi/nvdimm.c                     |   6 +-
 hw/i386/Makefile.objs                |   2 +-
 hw/i386/acpi-build-nofw.c            | 295 ++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c                 | 102 +++++++-----
 hw/i386/acpi-build.h                 |   5 +
 hw/i386/pc.c                         | 301 +++++++++++++++++++++++++++++++----
 hw/i386/pc_piix.c                    |   2 +-
 hw/i386/pc_q35.c                     |  60 ++++---
 hw/isa/lpc_ich9.c                    |  12 +-
 hw/pci-host/q35.c                    |  15 +-
 include/hw/acpi/acpi.h               |   2 +
Quoted 8 lines
Quoted 4 lines
 include/hw/acpi/bios-linker-loader.h |  85 ++++++++++
 include/hw/i386/pc.h                 |  16 +-
 15 files changed, 800 insertions(+), 188 deletions(-)
 create mode 100644 hw/i386/acpi-build-nofw.c

Patches 1-4 are okay, though I think it would be easier to add a -M q35-lite too that just removes the legacy devices. The -M q35-lite machine doesn't have to support versioning for now.

Where q35-lite will be same as q35 with different defaults? Sure, I don't have a problem with this.
In particular this will allow things like "q35-lite but with sata" etc.

Quoted 21 lines

As you might expect, I don't agree with removing the firmware. There's room for much more optimization before duplicating firmware code in QEMU. I'd rather see numbers for:

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the cbfs flash hack (so that -kernel works), drop PCI bridge initialization, copy less than 64K of memory from ROM to 0xf0000;

2) Linux optimizations: using an uncompressed image to avoid the cost of copying and decompressing. QEMU can already load the image at the right place and the real mode stub can do little more than GDT/IDT setup.

3) PAM optimizations: for -M q35-lite initialize the machine with RAM from 0xc0000 to 1MB.

I know that you ultimately would like to mmap the kernel, but I would like to have a better understanding of where the time is spent.

Thanks,

Paolo

author
#18 lore raw
In reply to Paolo Bonzini
Quoted 4 lines

Patches 1-4 are okay, though I think it would be easier to add a -M q35-lite too that just removes the legacy devices.  The -M q35-lite machine doesn't have to support versioning for now.

Okay, this is also good to have in my mind.

Quoted 10 lines

As you might expect, I don't agree with removing the firmware.  There's
room for much more optimization before duplicating firmware code in QEMU.  I'd rather see numbers for:

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the cbfs flash hack (so that -kernel works), drop PCI bridge initialization,
copy less than 64K of memory from ROM to 0xf0000;

I can do the evaluation on qboot. Also adding Amnon Ilan, to see if there is some thing we can do for SeaBios.

Quoted 6 lines

2) Linux optimizations: using an uncompressed image to avoid the cost of
copying and decompressing.  QEMU can already load the image at the right
place and the real mode stub can do little more than GDT/IDT setup.

This works surely. I actually followed your suggestion in v1 to make kernel multiboot-compatible and then load that kernel in QEMU directly (Also skipped firmware but some changes in patch 11 would move from QEMU to guest kernel). This way we also gain benefit of doing mmap kernel as you talked below. Not sure if this is something you can accpet.

Quoted 10 lines

3) PAM optimizations: for -M q35-lite initialize the machine with RAM from 0xc0000 to 1MB.

I know that you ultimately would like to mmap the kernel, but I would like to have a better understanding of where the time is spent.

Thanks,

Paolo

#19 lore raw
Quoted 13 lines · Chao Peng
Quoted 4 lines

Patches 1-4 are okay, though I think it would be easier to add a -M q35-lite too that just removes the legacy devices.  The -M q35-lite machine doesn't have to support versioning for now.

Okay, this is also good to have in my mind.

Quoted 6 lines

As you might expect, I don't agree with removing the firmware.  There's
room for much more optimization before duplicating firmware code in QEMU.  I'd rather see numbers for:

Quoted 7 lines
Quoted 4 lines

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the cbfs flash hack (so that -kernel works), drop PCI bridge initialization,
copy less than 64K of memory from ROM to 0xf0000;

I can do the evaluation on qboot. Also adding Amnon Ilan, to see if there is some thing we can do for SeaBios.

AFAIK latest seabios already supports DMA.
It's easy to add more config options for seabios
if you are so inclined.

Quoted 7 lines
Quoted 6 lines

2) Linux optimizations: using an uncompressed image to avoid the cost of
copying and decompressing.  QEMU can already load the image at the right
place and the real mode stub can do little more than GDT/IDT setup.

Quoted 6 lines

This works surely. I actually followed your suggestion in v1 to make kernel multiboot-compatible and then load that kernel in QEMU directly (Also skipped firmware but some changes in patch 11 would move from QEMU to guest kernel). This way we also gain benefit of doing mmap kernel as you talked below. Not sure if this is something you can accpet.

I'm not sure I understand the question here. Accept what?

Quoted 10 lines
Quoted 10 lines

3) PAM optimizations: for -M q35-lite initialize the machine with RAM from 0xc0000 to 1MB.

I know that you ultimately would like to mmap the kernel, but I would like to have a better understanding of where the time is spent.

Thanks,

Paolo

#23 lore raw
In reply to Chao Peng
Quoted 11 lines · Chao Peng
Quoted 8 lines

As you might expect, I don't agree with removing the firmware. There's
room for much more optimization before duplicating firmware code in QEMU. I'd rather see numbers for:

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the cbfs flash hack (so that -kernel works), drop PCI bridge initialization, copy less than 64K of memory from ROM to 0xf0000;

I can do the evaluation on qboot. Also adding Amnon Ilan, to see if there is some thing we can do for SeaBios.

For SeaBIOS we can try dropping PAM and PCI, but not much more.

I've pushed fw_cfg DMA support and some PAM optimizations to qboot (it doesn't setup PAM if QEMU doesn't configure 0xf0000-0x100000 as ROM). I've left it for you to figure out which parts of PCI initialization can be removed.

Quoted 7 lines
Quoted 4 lines

2) Linux optimizations: using an uncompressed image to avoid the cost of copying and decompressing. QEMU can already load the image at the right place and the real mode stub can do little more than GDT/IDT setup.

This works surely. I actually followed your suggestion in v1 to make kernel multiboot-compatible and then load that kernel in QEMU directly

Please try posting the multiboot patches to the upstream x86 Linux mailing list. I am very interested in them, because I think it's the simplest way to compare qboot with direct kernel load. And as you say, it might make patch 11 a little smaller and possibly more acceptable.

Paolo

author
#20 lore raw
In reply to Michael S. Tsirkin
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the
cbfs flash hack (so that -kernel works), drop PCI bridge initialization,
copy less than 64K of memory from ROM to 0xf0000;

Quoted 6 lines
Quoted 2 lines

I can do the evaluation on qboot. Also adding Amnon Ilan, to see if there is some thing we can do for SeaBios.

AFAIK latest seabios already supports DMA.
It's easy to add more config options for seabios
if you are so inclined.

Yes, I tried that, the fw_cfg overhead in SeaBios/linuxboot optrom is already not a big issue for us. However, there are still some other code in SeaBIOS needs to be investigated.

Quoted 22 lines
Quoted 13 lines
Quoted 4 lines
Quoted 8 lines

2) Linux optimizations: using an uncompressed image to avoid the cost
of
copying and decompressing.  QEMU can already load the image at the
right
place and the real mode stub can do little more than GDT/IDT setup.

Quoted 8 lines

This works surely. I actually followed your suggestion in v1 to make
kernel multiboot-compatible and then load that kernel in QEMU directly
(Also skipped firmware but some changes in patch 11 would move from QEMU to guest kernel). This way we also gain benefit of doing mmap kernel as you talked below. Not sure if this is something you can accpet.

Quoted 2 lines

I'm not sure I understand the question here. Accept what?

I mean loading a multiboot kernel without the need for firmaware.

Thanks,
Chao

author
#24 lore raw
In reply to Paolo Bonzini
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines

2) Linux optimizations: using an uncompressed image to avoid the cost of copying and decompressing.  QEMU can already load the image
at the right place and the real mode stub can do little more than GDT/IDT setup.

This works surely. I actually followed your suggestion in v1 to make
kernel multiboot-compatible and then load that kernel in QEMU directly

Quoted 6 lines

Please try posting the multiboot patches to the upstream x86 Linux mailing list.  I am very interested in them, because I think it's the simplest way to compare qboot with direct kernel load.  And as you say,
it might make patch 11 a little smaller and possibly more acceptable.

OK, I will do that (and to see their feedbacks).

Thanks,
Chao

#25 lore raw
In reply to Paolo Bonzini
Quoted 15 lines · Paolo Bonzini
Quoted 11 lines · Chao Peng
Quoted 8 lines

As you might expect, I don't agree with removing the firmware. There's
room for much more optimization before duplicating firmware code in QEMU. I'd rather see numbers for:

1) qboot optimizations: adopt the fw_cfg DMA interface instead of the cbfs flash hack (so that -kernel works), drop PCI bridge initialization, copy less than 64K of memory from ROM to 0xf0000;

I can do the evaluation on qboot. Also adding Amnon Ilan, to see if there is some thing we can do for SeaBios.

Quoted 6 lines

For SeaBIOS we can try dropping PAM and PCI, but not much more.

I've pushed fw_cfg DMA support and some PAM optimizations to qboot (it doesn't setup PAM if QEMU doesn't configure 0xf0000-0x100000 as ROM). I've left it for you to figure out which parts of PCI initialization can be removed.

I think we can expose the plug an play OS flag to guest, upon seeing it, seabios can limit self to only enumerating boot devices. No boot devices -> skip pci init completely.

Quoted 14 lines
Quoted 7 lines
Quoted 4 lines

2) Linux optimizations: using an uncompressed image to avoid the cost of copying and decompressing. QEMU can already load the image at the right place and the real mode stub can do little more than GDT/IDT setup.

This works surely. I actually followed your suggestion in v1 to make kernel multiboot-compatible and then load that kernel in QEMU directly

Please try posting the multiboot patches to the upstream x86 Linux mailing list. I am very interested in them, because I think it's the simplest way to compare qboot with direct kernel load. And as you say, it might make patch 11 a little smaller and possibly more acceptable.

Paolo

#2 lore raw

Re: [Qemu-devel] [RFC PATCH v2 01/12] pc: make smbus configurable

In reply to Chao Peng
Quoted 25 lines · Chao Peng
---
 hw/i386/pc.c         | 23 +++++++++++++++++++++++
 hw/i386/pc_q35.c     | 12 +++++++-----
 include/hw/i386/pc.h |  3 +++
 3 files changed, 33 insertions(+), 5 deletions(-)
hw/i386/pc.c +10 -0
index 022dd1b..66e1961 100644
@@ -2005,6 +2005,27 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
         pcmc->get_hotplug_handler(machine, dev) : NULL;
 }
 
+static void pc_machine_get_prop_bool(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    bool value = *(bool *)opaque;
+
+    visit_type_bool(v, name, &value, errp);
+}
+
+static void pc_machine_set_prop_bool(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)

hw/i386/pc.c static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, · line 2027

Quoted 10 lines
hw/i386/pc.c +10 -0
+{
+    visit_type_bool(v, name, (bool *)opaque, errp);
+}
+
+#define PC_MACHINE_DEFINE_PROP_BOOL(pcms, prop, field, defval)      \
+        pcms->field = defval;                                       \
+        object_property_add(OBJECT(pcms), prop, "bool",             \
+                            pc_machine_get_prop_bool,               \
+                            pc_machine_set_prop_bool,               \
+                            NULL, &pcms->field, &error_abort);

This is triggers checkpatch.pl error:

ERROR: Macros with multiple statements should be enclosed in a do - while loop #76: FILE: hw/i386/pc.c:2022:

+#define PC_MACHINE_DEFINE_PROP_BOOL(pcms, prop, field, defval)      \
+        pcms->field = defval;                                       \
+        object_property_add(OBJECT(pcms), prop, "bool",             \
+                            pc_machine_get_prop_bool,               \
+                            pc_machine_set_prop_bool,               \

+ NULL, &pcms->field, &error_abort);

hw/i386/pc.c static void pc_machine_initfn(Object *obj) · line 2193

Quoted 10 lines
hw/i386/pc.c +3 -0
+
 static void
 pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v,
                                           const char *name, void *opaque,
@@ -2168,6 +2189,8 @@ static void pc_machine_initfn(Object *obj)
     pcms->acpi_nvdimm_state.is_enabled = false;
     object_property_add_bool(obj, PC_MACHINE_NVDIMM, pc_machine_get_nvdimm,
                              pc_machine_set_nvdimm, &error_abort);
+
+    PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_SMBUS, smbus, true);

I suggest using object_class_property_add_bool() and registering properties at class_init.

Quoted 2 lines
hw/i386/pc.c +0 -0
 }
 

[...]

Signature · 1 line
Eduardo
#21 lore raw
In reply to Chao Peng

Hi,

Quoted 7 lines
Quoted 3 lines

AFAIK latest seabios already supports DMA.
It's easy to add more config options for seabios
if you are so inclined.

Yes, I tried that, the fw_cfg overhead in SeaBios/linuxboot optrom is already not a big issue for us. However, there are still some other code in SeaBIOS needs to be investigated.

What exactly?

Also a few suggestions:
* Try the seabios master branch. There have been some improvements recently which are not in the 1.9 release.
* Use a stripped down config. When booting a kernel directly you don't need storage and usb drivers, also no keyboard. That all reduces init time.
* Initializing all pci devices (placing bars in address space and programming them) can probably be skipped and left to the linux kernel to handle. But when trying take care that the effect might be that we shift just startup time from seabios to linux kernel, the placement needs to happen somewhere after all.
* When discussing these things add the seabios list ([email protected]) to cc: Added the list now.

cheers,
Gerd

#22 lore raw
Quoted 3 lines · Gerd Hoffmann

* Initializing all pci devices (placing bars in address space and programming them) can probably be skipped and left to the linux kernel to handle.

When the coreboot project started out, in 1999, that turned out not to be the case. I don't know if the situation has improved since then.

//Peter