]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
x86: fix wakeup_cpu with numaq/es7000, v2
authorYinghai Lu <yinghai@kernel.org>
Sun, 16 Nov 2008 11:12:49 +0000 (03:12 -0800)
committerIngo Molnar <mingo@elte.hu>
Mon, 17 Nov 2008 16:57:34 +0000 (17:57 +0100)
Impact: fix secondary-CPU wakeup/init path with numaq and es7000

While looking at wakeup_secondary_cpu for WAKE_SECONDARY_VIA_NMI:

|#ifdef WAKE_SECONDARY_VIA_NMI
|/*
| * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
| * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
| * won't ... remember to clear down the APIC, etc later.
| */
|static int __devinit
|wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
|{
|        unsigned long send_status, accept_status = 0;
|        int maxlvt;
|...
|        if (APIC_INTEGRATED(apic_version[phys_apicid])) {
|                maxlvt = lapic_get_maxlvt();

I noticed that there is no warning about undefined phys_apicid...

because WAKE_SECONDARY_VIA_NMI and WAKE_SECONDARY_VIA_INIT can not be
defined at the same time. So NUMAQ is using wrong wakeup_secondary_cpu.

WAKE_SECONDARY_VIA_NMI, WAKE_SECONDARY_VIA_INIT and
WAKE_SECONDARY_VIA_MIP are variants of a weird and fragile
preprocessor-driven "HAL" mechanisms to specify the kind of secondary-CPU
wakeup strategy a given x86 kernel will use.

The vast majority of systems want to use INIT for secondary wakeup - NUMAQ
uses an NMI, (old-style-) ES7000 uses 'MIP' (a firmware driven in-memory
flag to let secondaries continue).

So convert these mechanisms to x86_quirks and add a
->wakeup_secondary_cpu() method to specify the rare exception
to the sane default.

Extend genapic accordingly as well, for 32-bit.

While looking further, I noticed that functions in wakecup.h for numaq
and es7000 are different to the default in mach_wakecpu.h - but smpboot.c
will only use default mach_wakecpu.h with smphook.h.

So we need to add mach_wakecpu.h for mach_generic, to properly support
numaq and es7000, and vectorize the following SMP init methods:

int trampoline_phys_low;
int trampoline_phys_high;
void (*wait_for_init_deassert)(atomic_t *deassert);
void (*smp_callin_clear_local_apic)(void);
void (*store_NMI_vector)(unsigned short *high, unsigned short *low);
void (*restore_NMI_vector)(unsigned short *high, unsigned short *low);
void (*inquire_remote_apic)(int apicid);

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
15 files changed:
arch/x86/include/asm/bigsmp/apic.h
arch/x86/include/asm/es7000/apic.h
arch/x86/include/asm/es7000/wakecpu.h
arch/x86/include/asm/genapic_32.h
arch/x86/include/asm/mach-default/mach_wakecpu.h
arch/x86/include/asm/mach-default/smpboot_hooks.h
arch/x86/include/asm/mach-generic/mach_wakecpu.h [new file with mode: 0644]
arch/x86/include/asm/numaq/wakecpu.h
arch/x86/include/asm/setup.h
arch/x86/kernel/es7000_32.c
arch/x86/kernel/numaq_32.c
arch/x86/kernel/smpboot.c
arch/x86/mach-generic/bigsmp.c
arch/x86/mach-generic/default.c
arch/x86/mach-generic/summit.c

index 1d9543b9d35824c259a1110005866be3d1f54a4e..ce547f24a1cd30da5da6a9fc088d4a94cae2f7c8 100644 (file)
@@ -24,8 +24,6 @@ static inline cpumask_t target_cpus(void)
 #define INT_DELIVERY_MODE      (dest_Fixed)
 #define INT_DEST_MODE          (0)    /* phys delivery to target proc */
 #define NO_BALANCE_IRQ         (0)
-#define WAKE_SECONDARY_VIA_INIT
-
 
 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
 {
index 380f0b4f17edfcf5c1e1440baed7231e07cdb684..9d8cf776c2857655e6a1a4dea5b489e6e2d02a43 100644 (file)
@@ -23,8 +23,6 @@ static inline cpumask_t target_cpus(void)
 #define INT_DELIVERY_MODE      (dest_LowestPrio)
 #define INT_DEST_MODE          (1)    /* logical delivery broadcast to all procs */
 #define NO_BALANCE_IRQ         (1)
-#undef  WAKE_SECONDARY_VIA_INIT
-#define WAKE_SECONDARY_VIA_MIP
 #else
 #define APIC_DFR_VALUE         (APIC_DFR_FLAT)
 #define INT_DELIVERY_MODE      (dest_Fixed)
@@ -32,7 +30,6 @@ static inline cpumask_t target_cpus(void)
 #define NO_BALANCE_IRQ         (0)
 #undef  APIC_DEST_LOGICAL
 #define APIC_DEST_LOGICAL      0x0
-#define WAKE_SECONDARY_VIA_INIT
 #endif
 
 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
index 3984934619136119dfd7d95045d5930ab415e917..78f0daaee436333d9162013c62324dfe66bb1b9b 100644 (file)
@@ -1,36 +1,12 @@
 #ifndef __ASM_ES7000_WAKECPU_H
 #define __ASM_ES7000_WAKECPU_H
 
-/*
- * This file copes with machines that wakeup secondary CPUs by the
- * INIT, INIT, STARTUP sequence.
- */
-
-#ifdef CONFIG_ES7000_CLUSTERED_APIC
-#define WAKE_SECONDARY_VIA_MIP
-#else
-#define WAKE_SECONDARY_VIA_INIT
-#endif
-
-#ifdef WAKE_SECONDARY_VIA_MIP
-extern int es7000_start_cpu(int cpu, unsigned long eip);
-static inline int
-wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
-{
-       int boot_error = 0;
-       boot_error = es7000_start_cpu(phys_apicid, start_eip);
-       return boot_error;
-}
-#endif
-
-#define TRAMPOLINE_LOW phys_to_virt(0x467)
-#define TRAMPOLINE_HIGH phys_to_virt(0x469)
-
-#define boot_cpu_apicid boot_cpu_physical_apicid
+#define TRAMPOLINE_PHYS_LOW    0x467
+#define TRAMPOLINE_PHYS_HIGH   0x469
 
 static inline void wait_for_init_deassert(atomic_t *deassert)
 {
-#ifdef WAKE_SECONDARY_VIA_INIT
+#ifndef CONFIG_ES7000_CLUSTERED_APIC
        while (!atomic_read(deassert))
                cpu_relax();
 #endif
@@ -50,9 +26,12 @@ static inline void restore_NMI_vector(unsigned short *high, unsigned short *low)
 {
 }
 
-#define inquire_remote_apic(apicid) do {               \
-               if (apic_verbosity >= APIC_DEBUG)       \
-                       __inquire_remote_apic(apicid);  \
-       } while (0)
+extern void __inquire_remote_apic(int apicid);
+
+static inline void inquire_remote_apic(int apicid)
+{
+       if (apic_verbosity >= APIC_DEBUG)
+               __inquire_remote_apic(apicid);
+}
 
 #endif /* __ASM_MACH_WAKECPU_H */
index 5cbd4fcc06fd20425ce21ead1386c47d92d0b152..39bd8c1db3f5fecf26ba2ace87822e531dcc045f 100644 (file)
@@ -2,6 +2,7 @@
 #define _ASM_X86_GENAPIC_32_H
 
 #include <asm/mpspec.h>
+#include <asm/atomic.h>
 
 /*
  * Generic APIC driver interface.
@@ -65,6 +66,13 @@ struct genapic {
        void (*send_IPI_allbutself)(int vector);
        void (*send_IPI_all)(int vector);
 #endif
+       int trampoline_phys_low;
+       int trampoline_phys_high;
+       void (*wait_for_init_deassert)(atomic_t *deassert);
+       void (*smp_callin_clear_local_apic)(void);
+       void (*store_NMI_vector)(unsigned short *high, unsigned short *low);
+       void (*restore_NMI_vector)(unsigned short *high, unsigned short *low);
+       void (*inquire_remote_apic)(int apicid);
 };
 
 #define APICFUNC(x) .x = x,
@@ -105,13 +113,20 @@ struct genapic {
        APICFUNC(get_apic_id)                           \
        .apic_id_mask = APIC_ID_MASK,                   \
        APICFUNC(cpu_mask_to_apicid)                    \
-       APICFUNC(vector_allocation_domain)                      \
+       APICFUNC(vector_allocation_domain)              \
        APICFUNC(acpi_madt_oem_check)                   \
        IPIFUNC(send_IPI_mask)                          \
        IPIFUNC(send_IPI_allbutself)                    \
        IPIFUNC(send_IPI_all)                           \
        APICFUNC(enable_apic_mode)                      \
        APICFUNC(phys_pkg_id)                           \
+       .trampoline_phys_low = TRAMPOLINE_PHYS_LOW,             \
+       .trampoline_phys_high = TRAMPOLINE_PHYS_HIGH,           \
+       APICFUNC(wait_for_init_deassert)                \
+       APICFUNC(smp_callin_clear_local_apic)           \
+       APICFUNC(store_NMI_vector)                      \
+       APICFUNC(restore_NMI_vector)                    \
+       APICFUNC(inquire_remote_apic)                   \
 }
 
 extern struct genapic *genapic;
index 9d80db91e9926f040445ebffeb44cac66ce8f4d3..ceb01366014629ba1c8220dff2a95bb313a2bf30 100644 (file)
@@ -1,17 +1,8 @@
 #ifndef _ASM_X86_MACH_DEFAULT_MACH_WAKECPU_H
 #define _ASM_X86_MACH_DEFAULT_MACH_WAKECPU_H
 
-/* 
- * This file copes with machines that wakeup secondary CPUs by the
- * INIT, INIT, STARTUP sequence.
- */
-
-#define WAKE_SECONDARY_VIA_INIT
-
-#define TRAMPOLINE_LOW phys_to_virt(0x467)
-#define TRAMPOLINE_HIGH phys_to_virt(0x469)
-
-#define boot_cpu_apicid boot_cpu_physical_apicid
+#define TRAMPOLINE_PHYS_LOW (0x467)
+#define TRAMPOLINE_PHYS_HIGH (0x469)
 
 static inline void wait_for_init_deassert(atomic_t *deassert)
 {
@@ -33,9 +24,12 @@ static inline void restore_NMI_vector(unsigned short *high, unsigned short *low)
 {
 }
 
-#define inquire_remote_apic(apicid) do {               \
-               if (apic_verbosity >= APIC_DEBUG)       \
-                       __inquire_remote_apic(apicid);  \
-       } while (0)
+extern void __inquire_remote_apic(int apicid);
+
+static inline void inquire_remote_apic(int apicid)
+{
+       if (apic_verbosity >= APIC_DEBUG)
+               __inquire_remote_apic(apicid);
+}
 
 #endif /* _ASM_X86_MACH_DEFAULT_MACH_WAKECPU_H */
index dbab36d64d48f2b15aa6be7dea09e9feb91f869f..23bf52103b8905e662e3b9e5491b89d5b8c8c933 100644 (file)
@@ -13,9 +13,11 @@ static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
        CMOS_WRITE(0xa, 0xf);
        local_flush_tlb();
        pr_debug("1.\n");
-       *((volatile unsigned short *) TRAMPOLINE_HIGH) = start_eip >> 4;
+       *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_HIGH)) =
+                                                                start_eip >> 4;
        pr_debug("2.\n");
-       *((volatile unsigned short *) TRAMPOLINE_LOW) = start_eip & 0xf;
+       *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) =
+                                                        start_eip & 0xf;
        pr_debug("3.\n");
 }
 
@@ -32,7 +34,7 @@ static inline void smpboot_restore_warm_reset_vector(void)
         */
        CMOS_WRITE(0, 0xf);
 
-       *((volatile long *) phys_to_virt(0x467)) = 0;
+       *((volatile long *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = 0;
 }
 
 static inline void __init smpboot_setup_io_apic(void)
diff --git a/arch/x86/include/asm/mach-generic/mach_wakecpu.h b/arch/x86/include/asm/mach-generic/mach_wakecpu.h
new file mode 100644 (file)
index 0000000..1ab16b1
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _ASM_X86_MACH_GENERIC_MACH_WAKECPU_H
+#define _ASM_X86_MACH_GENERIC_MACH_WAKECPU_H
+
+#define TRAMPOLINE_PHYS_LOW (genapic->trampoline_phys_low)
+#define TRAMPOLINE_PHYS_HIGH (genapic->trampoline_phys_high)
+#define wait_for_init_deassert (genapic->wait_for_init_deassert)
+#define smp_callin_clear_local_apic (genapic->smp_callin_clear_local_apic)
+#define store_NMI_vector (genapic->store_NMI_vector)
+#define restore_NMI_vector (genapic->restore_NMI_vector)
+#define inquire_remote_apic (genapic->inquire_remote_apic)
+
+#endif /* _ASM_X86_MACH_GENERIC_MACH_APIC_H */
index c577bda5b1c52c768047d1e664e0040356b57176..6f499df8eddbfd4246132bd570b87bfde68b4e00 100644 (file)
@@ -3,12 +3,8 @@
 
 /* This file copes with machines that wakeup secondary CPUs by NMIs */
 
-#define WAKE_SECONDARY_VIA_NMI
-
-#define TRAMPOLINE_LOW phys_to_virt(0x8)
-#define TRAMPOLINE_HIGH phys_to_virt(0xa)
-
-#define boot_cpu_apicid boot_cpu_logical_apicid
+#define TRAMPOLINE_PHYS_LOW (0x8)
+#define TRAMPOLINE_PHYS_HIGH (0xa)
 
 /* We don't do anything here because we use NMI's to boot instead */
 static inline void wait_for_init_deassert(atomic_t *deassert)
@@ -27,17 +23,23 @@ static inline void smp_callin_clear_local_apic(void)
 static inline void store_NMI_vector(unsigned short *high, unsigned short *low)
 {
        printk("Storing NMI vector\n");
-       *high = *((volatile unsigned short *) TRAMPOLINE_HIGH);
-       *low = *((volatile unsigned short *) TRAMPOLINE_LOW);
+       *high =
+         *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_HIGH));
+       *low =
+         *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_LOW));
 }
 
 static inline void restore_NMI_vector(unsigned short *high, unsigned short *low)
 {
        printk("Restoring NMI vector\n");
-       *((volatile unsigned short *) TRAMPOLINE_HIGH) = *high;
-       *((volatile unsigned short *) TRAMPOLINE_LOW) = *low;
+       *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_HIGH)) =
+                                                                *high;
+       *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) =
+                                                                *low;
 }
 
-#define inquire_remote_apic(apicid) {}
+static inline void inquire_remote_apic(int apicid)
+{
+}
 
 #endif /* __ASM_NUMAQ_WAKECPU_H */
index f12d37237465df8b0a181d37685b212c0dd70cd1..40b2d330491150555b4751eb56fb84b2f2ba6fdc 100644 (file)
@@ -16,6 +16,7 @@ static inline void visws_early_detect(void) { }
 static inline int is_visws_box(void) { return 0; }
 #endif
 
+extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip);
 /*
  * Any setup quirks to be performed?
  */
@@ -39,6 +40,7 @@ struct x86_quirks {
        void (*smp_read_mpc_oem)(struct mp_config_oemtable *oemtable,
                                     unsigned short oemsize);
        int (*setup_ioapic_ids)(void);
+       int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip);
 };
 
 extern struct x86_quirks *x86_quirks;
index f454c78fcef6c7172db2fc0088548974f2f083e1..bed10dddf099a8e2a670f8c8a899cf2f6b979119 100644 (file)
@@ -40,6 +40,7 @@
 #include <asm/smp.h>
 #include <asm/apicdef.h>
 #include <mach_mpparse.h>
+#include <asm/setup.h>
 
 /*
  * ES7000 chipsets
@@ -161,6 +162,26 @@ es7000_rename_gsi(int ioapic, int gsi)
        return gsi;
 }
 
+#ifdef CONFIG_ES7000_CLUSTERED_APIC
+static int wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
+{
+       unsigned long vect = 0, psaival = 0;
+
+       if (psai == NULL)
+               return -1;
+
+       vect = ((unsigned long)__pa(eip)/0x1000) << 16;
+       psaival = (0x1000000 | vect | cpu);
+
+       while (*psai & 0x1000000)
+               ;
+
+       *psai = psaival;
+
+       return 0;
+}
+#endif
+
 void __init
 setup_unisys(void)
 {
@@ -176,6 +197,9 @@ setup_unisys(void)
        else
                es7000_plat = ES7000_CLASSIC;
        ioapic_renumber_irq = es7000_rename_gsi;
+#ifdef CONFIG_ES7000_CLUSTERED_APIC
+       x86_quirks->wakeup_secondary_cpu = wakeup_secondary_cpu_via_mip;
+#endif
 }
 
 /*
@@ -324,26 +348,6 @@ es7000_mip_write(struct mip_reg *mip_reg)
        return status;
 }
 
-int
-es7000_start_cpu(int cpu, unsigned long eip)
-{
-       unsigned long vect = 0, psaival = 0;
-
-       if (psai == NULL)
-               return -1;
-
-       vect = ((unsigned long)__pa(eip)/0x1000) << 16;
-       psaival = (0x1000000 | vect | cpu);
-
-       while (*psai & 0x1000000)
-                ;
-
-       *psai = psaival;
-
-       return 0;
-
-}
-
 void __init
 es7000_sw_apic(void)
 {
index 4caff39078e0d386a0f1d2783fbc7e081582d9a9..745891b7d0fb93fc35c22e31605a86cd79e1d445 100644 (file)
@@ -250,6 +250,7 @@ static struct x86_quirks numaq_x86_quirks __initdata = {
        .mpc_oem_pci_bus        = mpc_oem_pci_bus,
        .smp_read_mpc_oem       = smp_read_mpc_oem,
        .setup_ioapic_ids       = numaq_setup_ioapic_ids,
+       .wakeup_secondary_cpu   = wakeup_secondary_cpu_via_nmi,
 };
 
 void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
index 7b1093397319766b2e4848a5a883b0dc35f49804..498c1ef37fe0e26988a31ac65ca63a3b8507b4ae 100644 (file)
@@ -62,6 +62,7 @@
 #include <asm/mtrr.h>
 #include <asm/vmi.h>
 #include <asm/genapic.h>
+#include <asm/setup.h>
 #include <linux/mc146818rtc.h>
 
 #include <mach_apic.h>
@@ -536,7 +537,7 @@ static void impress_friends(void)
        pr_debug("Before bogocount - setting activated=1.\n");
 }
 
-static inline void __inquire_remote_apic(int apicid)
+void __inquire_remote_apic(int apicid)
 {
        unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
        char *names[] = { "ID", "VERSION", "SPIV" };
@@ -575,14 +576,13 @@ static inline void __inquire_remote_apic(int apicid)
        }
 }
 
-#ifdef WAKE_SECONDARY_VIA_NMI
 /*
  * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
  * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
  * won't ... remember to clear down the APIC, etc later.
  */
-static int __devinit
-wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
+int __devinit
+wakeup_secondary_cpu_via_nmi(int logical_apicid, unsigned long start_eip)
 {
        unsigned long send_status, accept_status = 0;
        int maxlvt;
@@ -599,7 +599,7 @@ wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
         * Give the other CPU some time to accept the IPI.
         */
        udelay(200);
-       if (APIC_INTEGRATED(apic_version[phys_apicid])) {
+       if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
                maxlvt = lapic_get_maxlvt();
                if (maxlvt > 3)                 /* Due to the Pentium erratum 3AP.  */
                        apic_write(APIC_ESR, 0);
@@ -614,11 +614,9 @@ wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
 
        return (send_status | accept_status);
 }
-#endif /* WAKE_SECONDARY_VIA_NMI */
 
-#ifdef WAKE_SECONDARY_VIA_INIT
 static int __devinit
-wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
+wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
 {
        unsigned long send_status, accept_status = 0;
        int maxlvt, num_starts, j;
@@ -737,7 +735,15 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
 
        return (send_status | accept_status);
 }
-#endif /* WAKE_SECONDARY_VIA_INIT */
+
+static int __devinit
+wakeup_secondary_cpu(int apicid, unsigned long start_eip)
+{
+       if (x86_quirks->wakeup_secondary_cpu)
+               return x86_quirks->wakeup_secondary_cpu(apicid, start_eip);
+
+       return wakeup_secondary_cpu_via_init(apicid, start_eip);
+}
 
 struct create_idle {
        struct work_struct work;
index 3c3b471ea496225e5a53029b92cfd5eeee658e43..3624a364b7f37ad8f7105956c15f4e1385dd66e8 100644 (file)
@@ -17,6 +17,7 @@
 #include <asm/bigsmp/apic.h>
 #include <asm/bigsmp/ipi.h>
 #include <asm/mach-default/mach_mpparse.h>
+#include <asm/mach-default/mach_wakecpu.h>
 
 static int dmi_bigsmp; /* can be set by dmi scanners */
 
index 9e835a11a13a7cba9c16f2de4e5db0e54d9ecbc5..e63a4a76d8cdd2a966aec1299d941b5e5fb7196b 100644 (file)
@@ -16,6 +16,7 @@
 #include <asm/mach-default/mach_apic.h>
 #include <asm/mach-default/mach_ipi.h>
 #include <asm/mach-default/mach_mpparse.h>
+#include <asm/mach-default/mach_wakecpu.h>
 
 /* should be called last. */
 static int probe_default(void)
index 6272b5e69da62b28f660105d9a8788e4944432b3..2c6d234e0009ccd5b2ca50db816f599a5cd133b3 100644 (file)
@@ -16,6 +16,7 @@
 #include <asm/summit/apic.h>
 #include <asm/summit/ipi.h>
 #include <asm/summit/mpparse.h>
+#include <asm/mach-default/mach_wakecpu.h>
 
 static int probe_summit(void)
 {