Patchwork [for-1.4,qom-cpu,4/9] target-i386/cpu: Introduce x86_cpu_apic_id_from_index() function

login
register
mail settings
Submitter Eduardo Habkost
Date Jan. 22, 2013, 8:25 p.m.
Message ID <1358886309-26258-5-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/214641/
State New
Headers show

Comments

Eduardo Habkost - Jan. 22, 2013, 8:25 p.m.
This function will be used by both the CPU initialization code and the
fw_cfg table initialization code.

Later this function will be updated to generate APIC IDs according to
the CPU topology.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2:
 - Rename to x86_cpu_apic_id_from_index()
---
 target-i386/cpu.c | 17 ++++++++++++++++-
 target-i386/cpu.h |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)
Andreas Färber - Jan. 23, 2013, 4:45 p.m.
Am 22.01.2013 21:25, schrieb Eduardo Habkost:
> This function will be used by both the CPU initialization code and the
> fw_cfg table initialization code.
> 
> Later this function will be updated to generate APIC IDs according to
> the CPU topology.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index f0f3df1..6c6c054 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2196,6 +2196,21 @@  void x86_cpu_realize(Object *obj, Error **errp)
     cpu_reset(CPU(cpu));
 }
 
+/* Calculates initial APIC ID for a specific CPU index
+ *
+ * Currently we need to be able to calculate the APIC ID from the CPU index
+ * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
+ * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
+ * all CPUs up to max_cpus.
+ */
+uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
+{
+    /* right now APIC ID == CPU index. this will eventually change to use
+     * the CPU topology configuration properly
+     */
+    return cpu_index;
+}
+
 static void x86_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
@@ -2230,7 +2245,7 @@  static void x86_cpu_initfn(Object *obj)
                         x86_cpuid_get_tsc_freq,
                         x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
 
-    env->cpuid_apic_id = cs->cpu_index;
+    env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
 
     /* init various static tables used in TCG mode */
     if (tcg_enabled() && !inited) {
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 9d4fcf9..9442f08 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1255,4 +1255,6 @@  void disable_kvm_pv_eoi(void);
 /* Return name of 32-bit register, from a R_* constant */
 const char *get_register_name_32(unsigned int reg);
 
+uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index);
+
 #endif /* CPU_I386_H */