From fbac0dc48f2f58adc8e99287a04be5cd4fa8f975 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sat, 14 May 2011 22:49:28 +0800 Subject: [PATCH] x86_64: Cleanup APIC ID to CPU ID mapping macros --- sys/platform/pc64/apic/ioapic.c | 2 +- sys/platform/pc64/apic/lapic.c | 19 +++++++++---------- sys/platform/pc64/apic/lapic.h | 10 +++++----- sys/platform/pc64/x86_64/mp_machdep.c | 20 ++++++++++---------- sys/platform/pc64/x86_64/mptable.c | 3 +-- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/sys/platform/pc64/apic/ioapic.c b/sys/platform/pc64/apic/ioapic.c index e5a6c03c90..28e45f5d7e 100644 --- a/sys/platform/pc64/apic/ioapic.c +++ b/sys/platform/pc64/apic/ioapic.c @@ -509,7 +509,7 @@ ioapic_pin_prog(void *addr, int pin, int vec, } target = ioapic_read(addr, select + 1) & IOART_HI_DEST_RESV; - target |= (CPU_TO_ID(0) << IOART_HI_DEST_SHIFT) & + target |= (CPUID_TO_APICID(0) << IOART_HI_DEST_SHIFT) & IOART_HI_DEST_MASK; ioapic_write(addr, select, flags | vec); diff --git a/sys/platform/pc64/apic/lapic.c b/sys/platform/pc64/apic/lapic.c index 76e803feeb..1c9afa144d 100644 --- a/sys/platform/pc64/apic/lapic.c +++ b/sys/platform/pc64/apic/lapic.c @@ -85,11 +85,10 @@ static const uint32_t lapic_timer_divisors[] = { #define APIC_TIMER_NDIVISORS (int)(NELEM(lapic_timer_divisors)) /* - * APIC ID logical/physical mapping structures. - * We oversize these to simplify boot-time config. + * APIC ID <-> CPU ID mapping structures. */ -int cpu_num_to_apic_id[NAPICID]; -int apic_id_to_logical[NAPICID]; +int cpu_id_to_apic_id[NAPICID]; +int apic_id_to_cpu_id[NAPICID]; void lapic_eoi(void) @@ -566,7 +565,7 @@ single_apic_ipi(int cpu, int vector, int delivery_mode) write_rflags(rflags); } icr_hi = lapic->icr_hi & ~APIC_ID_MASK; - icr_hi |= (CPU_TO_ID(cpu) << 24); + icr_hi |= (CPUID_TO_APICID(cpu) << 24); lapic->icr_hi = icr_hi; /* build ICR_LOW */ @@ -598,7 +597,7 @@ single_apic_ipi_passive(int cpu, int vector, int delivery_mode) return(0); } icr_hi = lapic->icr_hi & ~APIC_ID_MASK; - icr_hi |= (CPU_TO_ID(cpu) << 24); + icr_hi |= (CPUID_TO_APICID(cpu) << 24); lapic->icr_hi = icr_hi; /* build IRC_LOW */ @@ -697,7 +696,7 @@ lapic_unused_apic_id(int start) int i; for (i = start; i < NAPICID; ++i) { - if (ID_TO_CPU(i) == -1) + if (APICID_TO_CPUID(i) == -1) return i; } return NAPICID; @@ -721,7 +720,7 @@ lapic_config(void) int error, i; for (i = 0; i < NAPICID; ++i) - ID_TO_CPU(i) = -1; + APICID_TO_CPUID(i) = -1; TAILQ_FOREACH(e, &lapic_enumerators, lapic_link) { error = e->lapic_probe(e); @@ -751,6 +750,6 @@ lapic_enumerator_register(struct lapic_enumerator *ne) void lapic_set_cpuid(int cpu_id, int apic_id) { - CPU_TO_ID(cpu_id) = apic_id; - ID_TO_CPU(apic_id) = cpu_id; + CPUID_TO_APICID(cpu_id) = apic_id; + APICID_TO_CPUID(apic_id) = cpu_id; } diff --git a/sys/platform/pc64/apic/lapic.h b/sys/platform/pc64/apic/lapic.h index df64109208..c509715780 100644 --- a/sys/platform/pc64/apic/lapic.h +++ b/sys/platform/pc64/apic/lapic.h @@ -33,10 +33,10 @@ #include /* - * the physical/logical APIC ID management macros + * APIC ID <-> CPU ID mapping macros */ -#define CPU_TO_ID(CPU) (cpu_num_to_apic_id[CPU]) -#define ID_TO_CPU(ID) (apic_id_to_logical[ID]) +#define CPUID_TO_APICID(cpu_id) (cpu_id_to_apic_id[(cpu_id)]) +#define APICID_TO_CPUID(apic_id) (apic_id_to_cpu_id[(apic_id)]) #ifndef _SYS_QUEUE_H_ #include @@ -55,8 +55,8 @@ struct lapic_enumerator { #ifdef SMP extern volatile lapic_t *lapic; -extern int cpu_num_to_apic_id[]; -extern int apic_id_to_logical[]; +extern int cpu_id_to_apic_id[]; +extern int apic_id_to_cpu_id[]; void apic_dump(char*); void lapic_init(boolean_t); diff --git a/sys/platform/pc64/x86_64/mp_machdep.c b/sys/platform/pc64/x86_64/mp_machdep.c index 5a56337802..e91ea5b4ee 100644 --- a/sys/platform/pc64/x86_64/mp_machdep.c +++ b/sys/platform/pc64/x86_64/mp_machdep.c @@ -221,9 +221,9 @@ mp_announce(void) POSTCODE(MP_ANNOUNCE_POST); kprintf("DragonFly/MP: Multiprocessor motherboard\n"); - kprintf(" cpu0 (BSP): apic id: %2d\n", CPU_TO_ID(0)); + kprintf(" cpu0 (BSP): apic id: %2d\n", CPUID_TO_APICID(0)); for (x = 1; x <= mp_naps; ++x) - kprintf(" cpu%d (AP): apic id: %2d\n", x, CPU_TO_ID(x)); + kprintf(" cpu%d (AP): apic id: %2d\n", x, CPUID_TO_APICID(x)); if (!apic_io_enable) kprintf(" Warning: APIC I/O disabled\n"); @@ -478,7 +478,7 @@ start_all_aps(u_int boot_addr) CHECK_INIT(99); /* setup checkpoints */ if (!start_ap(gd, boot_addr, smibest)) { kprintf("\nAP #%d (PHY# %d) failed!\n", - x, CPU_TO_ID(x)); + x, CPUID_TO_APICID(x)); CHECK_PRINT("trace"); /* show checkpoints */ /* better panic as the AP may be running loose */ kprintf("panic y/n? [y] "); @@ -627,7 +627,7 @@ start_ap(struct mdglobaldata *gd, u_int boot_addr, int smibest) POSTCODE(START_AP_POST); /* get the PHYSICAL APIC ID# */ - physical_cpu = CPU_TO_ID(gd->mi.gd_cpuid); + physical_cpu = CPUID_TO_APICID(gd->mi.gd_cpuid); /* calculate the vector */ vector = (boot_addr >> 12) & 0xff; @@ -960,7 +960,7 @@ restart_cpus(cpumask_t map) void ap_init(void) { - u_int apic_id; + int cpu_id; /* * Adjust smp_startup_mask to signal the BSP that we have started @@ -1006,11 +1006,11 @@ ap_init(void) mycpu->gd_other_cpus = smp_startup_mask & ~CPUMASK(mycpu->gd_cpuid); /* A quick check from sanity claus */ - apic_id = (apic_id_to_logical[(lapic->id & 0xff000000) >> 24]); - if (mycpu->gd_cpuid != apic_id) { - kprintf("SMP: cpuid = %d\n", mycpu->gd_cpuid); - kprintf("SMP: apic_id = %d lapicid %d\n", - apic_id, (lapic->id & 0xff000000) >> 24); + cpu_id = APICID_TO_CPUID((lapic->id & 0xff000000) >> 24); + if (mycpu->gd_cpuid != cpu_id) { + kprintf("SMP: assigned cpuid = %d\n", mycpu->gd_cpuid); + kprintf("SMP: actual cpuid = %d lapicid %d\n", + cpu_id, (lapic->id & 0xff000000) >> 24); #if JGXXX kprintf("PTD[MPPTDI] = %p\n", (void *)PTD[MPPTDI]); #endif diff --git a/sys/platform/pc64/x86_64/mptable.c b/sys/platform/pc64/x86_64/mptable.c index a70de73415..407f504d70 100644 --- a/sys/platform/pc64/x86_64/mptable.c +++ b/sys/platform/pc64/x86_64/mptable.c @@ -730,8 +730,7 @@ mptable_lapic_default(void) /* * Configure: * mp_naps - * ID_TO_CPU(N), APIC ID to logical CPU table - * CPU_TO_ID(N), logical CPU to APIC ID table + * APIC ID <-> CPU ID mappings */ static void mptable_lapic_enumerate(struct lapic_enumerator *e) -- 2.41.0