i386: Cleanup APIC ID to CPU ID mapping macros
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Thu, 12 May 2011 07:31:34 +0000 (15:31 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 13 May 2011 02:17:28 +0000 (10:17 +0800)
sys/platform/pc32/apic/ioapic.c
sys/platform/pc32/apic/lapic.c
sys/platform/pc32/apic/lapic.h
sys/platform/pc32/i386/mp_machdep.c
sys/platform/pc32/i386/mptable.c

index 42cb2ba..ce0658d 100644 (file)
@@ -514,7 +514,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);
index a5d5d25..9b989b3 100644 (file)
@@ -83,11 +83,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];
 
 /*
  * Enable LAPIC, configure interrupts.
@@ -500,7 +499,7 @@ single_apic_ipi(int cpu, int vector, int delivery_mode)
            write_eflags(eflags);
        }
        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 */
@@ -532,7 +531,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 */
@@ -631,7 +630,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;
@@ -655,7 +654,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);
@@ -685,6 +684,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;
 }
index 701c860..2271bbe 100644 (file)
 #include <machine_base/apic/apicreg.h>
 
 /*
- * 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 <sys/queue.h>
@@ -54,8 +54,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);
index 675d272..29e0ff6 100644 (file)
@@ -225,9 +225,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");
@@ -466,7 +466,8 @@ start_all_aps(u_int boot_addr)
                /* attempt to start the Application Processor */
                CHECK_INIT(99); /* setup checkpoints */
                if (!start_ap(gd, boot_addr, smibest)) {
-                       kprintf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
+                       kprintf("AP #%d (PHY# %d) failed!\n", x,
+                           CPUID_TO_APICID(x));
                        CHECK_PRINT("trace");   /* show checkpoints */
                        /* better panic as the AP may be running loose */
                        kprintf("panic y/n? [y] ");
@@ -613,7 +614,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;
@@ -942,7 +943,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
@@ -992,10 +993,10 @@ 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\n", apic_id);
+       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\n", cpu_id);
                kprintf("PTD[MPPTDI] = %p\n", (void *)PTD[MPPTDI]);
                panic("cpuid mismatch! boom!!");
        }
index efadb9c..b197877 100644 (file)
@@ -731,8 +731,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)