[SeaBIOS] [Seabios RFC PATCH 1/1] get lapic IDs from fw_cfg

Eduardo Habkost ehabkost at redhat.com
Tue Jul 10 22:22:23 CEST 2012


This changes:
 - MADT table generation
 - SRAT table generation

Still missing:
 - The _MAT method on SSDT Processor entries still return the wrong APIC
   ID (breaking CPU hotplug)
 - The MPTable generation code doesn't take the new APIC IDs into
   account

Signed-off-by: Eduardo Habkost <ehabkost at redhat.com>
---
 src/acpi.c     |   64 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 src/paravirt.c |   12 +++++++++++
 src/paravirt.h |   13 ++++++++++++
 3 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/src/acpi.c b/src/acpi.c
index 8549304..f9eafad 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -311,21 +311,40 @@ build_madt(void)
                      + sizeof(struct madt_intsrcovr) * 16
                      + sizeof(struct madt_local_nmi));
 
-    struct multiple_apic_table *madt = malloc_high(madt_size);
+    struct fw_cfg_lapic_info_entry *lapics = NULL;
+    struct multiple_apic_table *madt = NULL;
+    u64 lapic_count = qemu_cfg_get_lapic_count();
+
+    if (lapic_count) {
+        lapics = malloc_tmphigh(sizeof(*lapics) * lapic_count);
+        if (!lapics) {
+            warn_noalloc();
+            goto out;
+        }
+    }
+
+    qemu_cfg_get_lapic_info(lapics, lapic_count);
+
+    madt = malloc_high(madt_size);
     if (!madt) {
         warn_noalloc();
-        return NULL;
+        goto out;
     }
+
     memset(madt, 0, madt_size);
     madt->local_apic_address = cpu_to_le32(BUILD_APIC_ADDR);
     madt->flags = cpu_to_le32(1);
     struct madt_processor_apic *apic = (void*)&madt[1];
     int i;
+    int last_apic_id = -1;
     for (i=0; i<MaxCountCPUs; i++) {
         apic->type = APIC_PROCESSOR;
         apic->length = sizeof(*apic);
         apic->processor_id = i;
-        apic->local_apic_id = i;
+        if (i < lapic_count)
+            last_apic_id = apic->local_apic_id = lapics[i].apic_id;
+        else
+            apic->local_apic_id = ++last_apic_id;
         if (i < CountCPUs)
             apic->flags = cpu_to_le32(1);
         else
@@ -371,6 +390,10 @@ build_madt(void)
     local_nmi++;
 
     build_header((void*)madt, APIC_SIGNATURE, (void*)local_nmi - (void*)madt, 1);
+
+out:
+    if (lapics)
+        free(lapics);
     return madt;
 }
 
@@ -616,20 +639,35 @@ acpi_build_srat_memory(struct srat_memory_affinity *numamem,
 static void *
 build_srat(void)
 {
+    struct fw_cfg_lapic_info_entry *lapics = NULL;
+    u64 lapic_count = 0;
+    struct system_resource_affinity_table *srat = NULL;
+    u64 *numadata = NULL;
     int nb_numa_nodes = qemu_cfg_get_numa_nodes();
 
     if (nb_numa_nodes == 0)
-        return NULL;
+        goto out;
 
-    u64 *numadata = malloc_tmphigh(sizeof(u64) * (MaxCountCPUs + nb_numa_nodes));
+    numadata = malloc_tmphigh(sizeof(u64) * (MaxCountCPUs + nb_numa_nodes));
     if (!numadata) {
         warn_noalloc();
-        return NULL;
+        goto out;
     }
 
     qemu_cfg_get_numa_data(numadata, MaxCountCPUs + nb_numa_nodes);
 
-    struct system_resource_affinity_table *srat;
+    lapic_count = qemu_cfg_get_lapic_count();
+
+    if (lapic_count) {
+        lapics = malloc_tmphigh(sizeof(*lapics) * lapic_count);
+        if (!lapics) {
+            warn_noalloc();
+            goto out;
+        }
+    }
+
+    qemu_cfg_get_lapic_info(lapics, lapic_count);
+
     int srat_size = sizeof(*srat) +
         sizeof(struct srat_processor_affinity) * MaxCountCPUs +
         sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2);
@@ -646,11 +684,15 @@ build_srat(void)
     struct srat_processor_affinity *core = (void*)(srat + 1);
     int i;
     u64 curnode;
+    int last_apic_id = -1;
 
     for (i = 0; i < MaxCountCPUs; ++i) {
         core->type = SRAT_PROCESSOR;
         core->length = sizeof(*core);
-        core->local_apic_id = i;
+        if (i < lapic_count)
+            last_apic_id = core->local_apic_id = lapics[i].apic_id;
+        else
+            core->local_apic_id = ++last_apic_id;
         curnode = *numadata++;
         core->proximity_lo = curnode;
         memset(core->proximity_hi, 0, 3);
@@ -704,7 +746,11 @@ build_srat(void)
 
     build_header((void*)srat, SRAT_SIGNATURE, srat_size, 1);
 
-    free(numadata);
+out:
+    if (lapics)
+        free(lapics);
+    if (numadata)
+        free(numadata);
     return srat;
 }
 
diff --git a/src/paravirt.c b/src/paravirt.c
index 2a98d53..674d512 100644
--- a/src/paravirt.c
+++ b/src/paravirt.c
@@ -293,6 +293,18 @@ void qemu_cfg_get_numa_data(u64 *data, int n)
         qemu_cfg_read((u8*)(data + i), sizeof(u64));
 }
 
+u64 qemu_cfg_get_lapic_count(void)
+{
+    u64 cnt;
+    qemu_cfg_read_entry(&cnt, QEMU_CFG_LAPIC_INFO, sizeof(cnt));
+    return cnt;
+}
+
+void qemu_cfg_get_lapic_info(struct fw_cfg_lapic_info_entry *entries, u64 n)
+{
+    qemu_cfg_read((u8*)entries, sizeof(struct fw_cfg_lapic_info_entry)*n);
+}
+
 u16 qemu_cfg_get_max_cpus(void)
 {
     u16 cnt;
diff --git a/src/paravirt.h b/src/paravirt.h
index a284c41..5e3e500 100644
--- a/src/paravirt.h
+++ b/src/paravirt.h
@@ -40,6 +40,8 @@ static inline int kvm_para_available(void)
 #define QEMU_CFG_SMBIOS_ENTRIES         (QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE          (QEMU_CFG_ARCH_LOCAL + 2)
 #define QEMU_CFG_E820_TABLE             (QEMU_CFG_ARCH_LOCAL + 3)
+#define QEMU_CFG_LAPIC_INFO             (QEMU_CFG_ARCH_LOCAL + 5)
+
 
 extern int qemu_cfg_present;
 
@@ -57,6 +59,17 @@ int qemu_cfg_smbios_load_external(int type, char **p, unsigned *nr_structs,
 int qemu_cfg_get_numa_nodes(void);
 void qemu_cfg_get_numa_data(u64 *data, int n);
 u16 qemu_cfg_get_max_cpus(void);
+
+struct fw_cfg_lapic_info_entry {
+    u8 apic_id;
+    u8 reserved1;
+    u16 reserved2;
+    u32 reserved3;
+} PACKED;
+
+u64 qemu_cfg_get_lapic_count(void);
+void qemu_cfg_get_lapic_info(struct fw_cfg_lapic_info_entry *entries, u64 n);
+
 struct e820_reservation {
     u64 address;
     u64 length;
-- 
1.7.10.4




More information about the SeaBIOS mailing list