instead of the old fake apic. Signed-off-by: Avi Kivity <avi@xxxxxxxxxx> --- kvm/user/test/lib/x86/smp.c | 68 ++++++------------------------------------- kvm/user/test/lib/x86/smp.h | 2 +- kvm/user/test/x86/smptest.c | 10 +----- 3 files changed, 12 insertions(+), 68 deletions(-) diff --git a/kvm/user/test/lib/x86/smp.c b/kvm/user/test/lib/x86/smp.c index 92ebada..a3a5472 100644 --- a/kvm/user/test/lib/x86/smp.c +++ b/kvm/user/test/lib/x86/smp.c @@ -1,46 +1,11 @@ #include <libcflat.h> #include "smp.h" -#include "fake-apic.h" +#include "apic.h" +#include "fwcfg.h" #define IPI_VECTOR 0x20 -static int apic_read(int reg) -{ - unsigned short port = APIC_BASE + reg; - unsigned v; - - asm volatile ("in %1, %0" : "=a"(v) : "d"(port)); - return v; -} - -static void apic_write(int reg, unsigned v) -{ - unsigned short port = APIC_BASE + reg; - - asm volatile ("out %0, %1" : : "a"(v), "d"(port)); -} - -static int apic_get_cpu_count() -{ - return apic_read(APIC_REG_NCPU); -} - -static int apic_get_id() -{ - return apic_read(APIC_REG_ID); -} - -static void apic_set_ipi_vector(int vector) -{ - apic_write(APIC_REG_IPI_VECTOR, vector); -} - -static void apic_send_ipi(int cpu) -{ - apic_write(APIC_REG_SEND_IPI, cpu); -} - static struct spinlock ipi_lock; static void (*ipi_function)(void *data); static void *ipi_data; @@ -100,23 +65,25 @@ void spin_unlock(struct spinlock *lock) int cpu_count(void) { - return apic_get_cpu_count(); + return fwcfg_get_nb_cpus(); } int smp_id(void) { - return apic_get_id(); + return apic_read(APIC_ID); } void on_cpu(int cpu, void (*function)(void *data), void *data) { spin_lock(&ipi_lock); - if (cpu == apic_get_id()) + if (cpu == apic_id()) function(data); else { ipi_function = function; ipi_data = data; - apic_send_ipi(cpu); + apic_icr_write(APIC_INT_ASSERT | APIC_DEST_PHYSICAL | APIC_DM_FIXED + | IPI_VECTOR, + cpu); while (!ipi_done) ; ipi_done = 0; @@ -124,27 +91,10 @@ void on_cpu(int cpu, void (*function)(void *data), void *data) spin_unlock(&ipi_lock); } -static void (*smp_main_func)(void); -static volatile int smp_main_running; - -asm ("smp_init_entry: \n" - "incl smp_main_running \n" - "sti \n" - "call *smp_main_func"); - -void smp_init(void (*smp_main)(void)) +void smp_init(void) { int i; - void smp_init_entry(void); void ipi_entry(void); - apic_set_ipi_vector(IPI_VECTOR); - set_ipi_descriptor(smp_init_entry); - smp_main_func = smp_main; - for (i = 1; i < cpu_count(); ++i) { - apic_send_ipi(i); - while (smp_main_running < i) - ; - } set_ipi_descriptor(ipi_entry); } diff --git a/kvm/user/test/lib/x86/smp.h b/kvm/user/test/lib/x86/smp.h index bcf76a3..bac7e14 100644 --- a/kvm/user/test/lib/x86/smp.h +++ b/kvm/user/test/lib/x86/smp.h @@ -5,7 +5,7 @@ struct spinlock { int v; }; -void smp_init(void (*smp_main)(void)); +void smp_init(void); int cpu_count(void); int smp_id(void); diff --git a/kvm/user/test/x86/smptest.c b/kvm/user/test/x86/smptest.c index 7b1ba49..3780599 100644 --- a/kvm/user/test/x86/smptest.c +++ b/kvm/user/test/x86/smptest.c @@ -10,19 +10,13 @@ static void ipi_test(void *data) printf("but wrong cpu %d\n", smp_id()); } -static void smp_main(void) -{ - printf("smp main %d\n", smp_id()); - while (1) - asm volatile ("hlt" : : : "memory"); -} - int main() { int ncpus; int i; - smp_init(smp_main); + smp_init(); + ncpus = cpu_count(); printf("found %d cpus\n", ncpus); for (i = 0; i < ncpus; ++i) -- 1.6.4.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html