Merge ../linux-2.6-x86
[safe/jmp/linux-2.6] / arch / x86 / kernel / smpboot.c
index 0133a95..9d58134 100644 (file)
@@ -52,6 +52,7 @@
 #include <asm/desc.h>
 #include <asm/nmi.h>
 #include <asm/irq.h>
+#include <asm/idle.h>
 #include <asm/smp.h>
 #include <asm/trampoline.h>
 #include <asm/cpu.h>
@@ -61,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>
@@ -100,14 +102,8 @@ EXPORT_SYMBOL(smp_num_siblings);
 /* Last level cache ID of each logical CPU */
 DEFINE_PER_CPU(u16, cpu_llc_id) = BAD_APICID;
 
-/* bitmap of online cpus */
-cpumask_t cpu_online_map __read_mostly;
-EXPORT_SYMBOL(cpu_online_map);
-
 cpumask_t cpu_callin_map;
 cpumask_t cpu_callout_map;
-cpumask_t cpu_possible_map;
-EXPORT_SYMBOL(cpu_possible_map);
 
 /* representing HT siblings of each logical CPU */
 DEFINE_PER_CPU(cpumask_t, cpu_sibling_map);
@@ -258,6 +254,7 @@ static void __cpuinit smp_callin(void)
        end_local_APIC_setup();
        map_cpu_to_logical_apicid();
 
+       notify_cpu_starting(cpuid);
        /*
         * Get our bogomips.
         *
@@ -280,6 +277,8 @@ static void __cpuinit smp_callin(void)
        cpu_set(cpuid, cpu_callin_map);
 }
 
+static int __cpuinitdata unsafe_smp;
+
 /*
  * Activate a secondary processor.
  */
@@ -332,14 +331,17 @@ static void __cpuinit start_secondary(void *unused)
         * does not change while we are assigning vectors to cpus.  Holding
         * this lock ensures we don't half assign or remove an irq from a cpu.
         */
-       ipi_call_lock_irq();
+       ipi_call_lock();
        lock_vector_lock();
        __setup_vector_irq(smp_processor_id());
        cpu_set(smp_processor_id(), cpu_online_map);
        unlock_vector_lock();
-       ipi_call_unlock_irq();
+       ipi_call_unlock();
        per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
 
+       /* enable local interrupts */
+       local_irq_enable();
+
        setup_secondary_clock();
 
        wmb();
@@ -392,7 +394,7 @@ static void __cpuinit smp_apply_quirks(struct cpuinfo_x86 *c)
                                goto valid_k7;
 
                /* If we get here, not a certified SMP capable AMD system. */
-               add_taint(TAINT_UNSAFE_SMP);
+               unsafe_smp = 1;
        }
 
 valid_k7:
@@ -409,12 +411,10 @@ static void __cpuinit smp_checks(void)
         * Don't taint if we are running SMP kernel on a single non-MP
         * approved Athlon
         */
-       if (tainted & TAINT_UNSAFE_SMP) {
-               if (num_online_cpus())
-                       printk(KERN_INFO "WARNING: This combination of AMD"
-                               "processors is not suitable for SMP.\n");
-               else
-                       tainted &= ~TAINT_UNSAFE_SMP;
+       if (unsafe_smp && num_online_cpus() > 1) {
+               printk(KERN_INFO "WARNING: This combination of AMD"
+                       "processors is not suitable for SMP.\n");
+               add_taint(TAINT_UNSAFE_SMP);
        }
 }
 
@@ -531,17 +531,17 @@ 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" };
        int timeout;
        u32 status;
 
-       printk(KERN_INFO "Inquiring remote APIC #%d...\n", apicid);
+       printk(KERN_INFO "Inquiring remote APIC 0x%x...\n", apicid);
 
        for (i = 0; i < ARRAY_SIZE(regs); i++) {
-               printk(KERN_INFO "... APIC #%d %s: ", apicid, names[i]);
+               printk(KERN_INFO "... APIC 0x%x %s: ", apicid, names[i]);
 
                /*
                 * Wait for idle.
@@ -570,14 +570,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;
@@ -594,10 +593,12 @@ wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
         * Give the other CPU some time to accept the IPI.
         */
        udelay(200);
-       maxlvt = lapic_get_maxlvt();
-       if (maxlvt > 3)                 /* Due to the Pentium erratum 3AP.  */
-               apic_write(APIC_ESR, 0);
-       accept_status = (apic_read(APIC_ESR) & 0xEF);
+       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);
+               accept_status = (apic_read(APIC_ESR) & 0xEF);
+       }
        pr_debug("NMI sent.\n");
 
        if (send_status)
@@ -607,11 +608,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)
+int __devinit
+wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
 {
        unsigned long send_status, accept_status = 0;
        int maxlvt, num_starts, j;
@@ -730,7 +729,6 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
 
        return (send_status | accept_status);
 }
-#endif /* WAKE_SECONDARY_VIA_INIT */
 
 struct create_idle {
        struct work_struct work;
@@ -749,6 +747,14 @@ static void __cpuinit do_fork_idle(struct work_struct *work)
 }
 
 #ifdef CONFIG_X86_64
+
+/* __ref because it's safe to call free_bootmem when after_bootmem == 0. */
+static void __ref free_bootmem_pda(struct x8664_pda *oldpda)
+{
+       if (!after_bootmem)
+               free_bootmem((unsigned long)oldpda, sizeof(*oldpda));
+}
+
 /*
  * Allocate node local memory for the AP pda.
  *
@@ -777,8 +783,7 @@ int __cpuinit get_local_pda(int cpu)
 
        if (oldpda) {
                memcpy(newpda, oldpda, size);
-               if (!after_bootmem)
-                       free_bootmem((unsigned long)oldpda, size);
+               free_bootmem_pda(oldpda);
        }
 
        newpda->in_bootmem = 0;
@@ -860,7 +865,7 @@ do_rest:
        start_ip = setup_trampoline();
 
        /* So we see what's up   */
-       printk(KERN_INFO "Booting processor %d/%d ip %lx\n",
+       printk(KERN_INFO "Booting processor %d APIC 0x%x ip 0x%lx\n",
                          cpu, apicid, start_ip);
 
        /*
@@ -879,9 +884,11 @@ do_rest:
                smpboot_setup_warm_reset_vector(start_ip);
                /*
                 * Be paranoid about clearing APIC errors.
-               */
-               apic_write(APIC_ESR, 0);
-               apic_read(APIC_ESR);
+               */
+               if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
+                       apic_write(APIC_ESR, 0);
+                       apic_read(APIC_ESR);
+               }
        }
 
        /*
@@ -987,17 +994,7 @@ int __cpuinit native_cpu_up(unsigned int cpu)
        flush_tlb_all();
        low_mappings = 1;
 
-#ifdef CONFIG_X86_PC
-       if (def_to_bigsmp && apicid > 8) {
-               printk(KERN_WARNING
-                       "More than 8 CPUs detected - skipping them.\n"
-                       "Use CONFIG_X86_GENERICARCH and CONFIG_X86_BIGSMP.\n");
-               err = -1;
-       } else
-               err = do_boot_cpu(apicid, cpu);
-#else
        err = do_boot_cpu(apicid, cpu);
-#endif
 
        zap_low_mappings();
        low_mappings = 0;
@@ -1051,6 +1048,34 @@ static __init void disable_smp(void)
 static int __init smp_sanity_check(unsigned max_cpus)
 {
        preempt_disable();
+
+#if defined(CONFIG_X86_PC) && defined(CONFIG_X86_32)
+       if (def_to_bigsmp && nr_cpu_ids > 8) {
+               unsigned int cpu;
+               unsigned nr;
+
+               printk(KERN_WARNING
+                      "More than 8 CPUs detected - skipping them.\n"
+                      "Use CONFIG_X86_GENERICARCH and CONFIG_X86_BIGSMP.\n");
+
+               nr = 0;
+               for_each_present_cpu(cpu) {
+                       if (nr >= 8)
+                               cpu_clear(cpu, cpu_present_map);
+                       nr++;
+               }
+
+               nr = 0;
+               for_each_possible_cpu(cpu) {
+                       if (nr >= 8)
+                               cpu_clear(cpu, cpu_possible_map);
+                       nr++;
+               }
+
+               nr_cpu_ids = 8;
+       }
+#endif
+
        if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
                printk(KERN_WARNING "weird, boot CPU (#%d) not listed"
                                    "by the BIOS.\n", hard_smp_processor_id());
@@ -1196,6 +1221,9 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
        printk(KERN_INFO "CPU%d: ", 0);
        print_cpu_info(&cpu_data(0));
        setup_boot_clock();
+
+       if (is_uv_system())
+               uv_system_init();
 out:
        preempt_enable();
 }
@@ -1226,39 +1254,6 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
        check_nmi_watchdog();
 }
 
-#ifdef CONFIG_HOTPLUG_CPU
-
-static void remove_siblinginfo(int cpu)
-{
-       int sibling;
-       struct cpuinfo_x86 *c = &cpu_data(cpu);
-
-       for_each_cpu_mask_nr(sibling, per_cpu(cpu_core_map, cpu)) {
-               cpu_clear(cpu, per_cpu(cpu_core_map, sibling));
-               /*/
-                * last thread sibling in this cpu core going down
-                */
-               if (cpus_weight(per_cpu(cpu_sibling_map, cpu)) == 1)
-                       cpu_data(sibling).booted_cores--;
-       }
-
-       for_each_cpu_mask_nr(sibling, per_cpu(cpu_sibling_map, cpu))
-               cpu_clear(cpu, per_cpu(cpu_sibling_map, sibling));
-       cpus_clear(per_cpu(cpu_sibling_map, cpu));
-       cpus_clear(per_cpu(cpu_core_map, cpu));
-       c->phys_proc_id = 0;
-       c->cpu_core_id = 0;
-       cpu_clear(cpu, cpu_sibling_setup_map);
-}
-
-static int additional_cpus __initdata = -1;
-
-static __init int setup_additional_cpus(char *s)
-{
-       return s && get_option(&s, &additional_cpus) ? 0 : -EINVAL;
-}
-early_param("additional_cpus", setup_additional_cpus);
-
 /*
  * cpu_possible_map should be static, it cannot change as cpu's
  * are onlined, or offlined. The reason is per-cpu data-structures
@@ -1278,24 +1273,13 @@ early_param("additional_cpus", setup_additional_cpus);
  */
 __init void prefill_possible_map(void)
 {
-       int i;
-       int possible;
+       int i, possible;
 
        /* no processor from mptable or madt */
        if (!num_processors)
                num_processors = 1;
 
-#ifdef CONFIG_HOTPLUG_CPU
-       if (additional_cpus == -1) {
-               if (disabled_cpus > 0)
-                       additional_cpus = disabled_cpus;
-               else
-                       additional_cpus = 0;
-       }
-#else
-       additional_cpus = 0;
-#endif
-       possible = num_processors + additional_cpus;
+       possible = num_processors + disabled_cpus;
        if (possible > NR_CPUS)
                possible = NR_CPUS;
 
@@ -1308,6 +1292,31 @@ __init void prefill_possible_map(void)
        nr_cpu_ids = possible;
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+
+static void remove_siblinginfo(int cpu)
+{
+       int sibling;
+       struct cpuinfo_x86 *c = &cpu_data(cpu);
+
+       for_each_cpu_mask_nr(sibling, per_cpu(cpu_core_map, cpu)) {
+               cpu_clear(cpu, per_cpu(cpu_core_map, sibling));
+               /*/
+                * last thread sibling in this cpu core going down
+                */
+               if (cpus_weight(per_cpu(cpu_sibling_map, cpu)) == 1)
+                       cpu_data(sibling).booted_cores--;
+       }
+
+       for_each_cpu_mask_nr(sibling, per_cpu(cpu_sibling_map, cpu))
+               cpu_clear(cpu, per_cpu(cpu_sibling_map, sibling));
+       cpus_clear(per_cpu(cpu_sibling_map, cpu));
+       cpus_clear(per_cpu(cpu_core_map, cpu));
+       c->phys_proc_id = 0;
+       c->cpu_core_id = 0;
+       cpu_clear(cpu, cpu_sibling_setup_map);
+}
+
 static void __ref remove_cpu_from_maps(int cpu)
 {
        cpu_clear(cpu, cpu_online_map);
@@ -1318,25 +1327,9 @@ static void __ref remove_cpu_from_maps(int cpu)
        numa_remove_cpu(cpu);
 }
 
-int __cpu_disable(void)
+void cpu_disable_common(void)
 {
        int cpu = smp_processor_id();
-
-       /*
-        * Perhaps use cpufreq to drop frequency, but that could go
-        * into generic code.
-        *
-        * We won't take down the boot processor on i386 due to some
-        * interrupts only being able to be serviced by the BSP.
-        * Especially so if we're not using an IOAPIC   -zwane
-        */
-       if (cpu == 0)
-               return -EBUSY;
-
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               stop_apic_nmi_watchdog(NULL);
-       clear_local_APIC();
-
        /*
         * HACK:
         * Allow any queued timer interrupts to get serviced
@@ -1354,10 +1347,32 @@ int __cpu_disable(void)
        remove_cpu_from_maps(cpu);
        unlock_vector_lock();
        fixup_irqs(cpu_online_map);
+}
+
+int native_cpu_disable(void)
+{
+       int cpu = smp_processor_id();
+
+       /*
+        * Perhaps use cpufreq to drop frequency, but that could go
+        * into generic code.
+        *
+        * We won't take down the boot processor on i386 due to some
+        * interrupts only being able to be serviced by the BSP.
+        * Especially so if we're not using an IOAPIC   -zwane
+        */
+       if (cpu == 0)
+               return -EBUSY;
+
+       if (nmi_watchdog == NMI_LOCAL_APIC)
+               stop_apic_nmi_watchdog(NULL);
+       clear_local_APIC();
+
+       cpu_disable_common();
        return 0;
 }
 
-void __cpu_die(unsigned int cpu)
+void native_cpu_die(unsigned int cpu)
 {
        /* We don't do anything here: idle task is faking death itself. */
        unsigned int i;
@@ -1374,29 +1389,45 @@ void __cpu_die(unsigned int cpu)
        }
        printk(KERN_ERR "CPU %u didn't die...\n", cpu);
 }
+
+void play_dead_common(void)
+{
+       idle_task_exit();
+       reset_lazy_tlbstate();
+       irq_ctx_exit(raw_smp_processor_id());
+       c1e_remove_cpu(raw_smp_processor_id());
+
+       mb();
+       /* Ack it */
+       __get_cpu_var(cpu_state) = CPU_DEAD;
+
+       /*
+        * With physical CPU hotplug, we should halt the cpu
+        */
+       local_irq_disable();
+}
+
+void native_play_dead(void)
+{
+       play_dead_common();
+       wbinvd_halt();
+}
+
 #else /* ... !CONFIG_HOTPLUG_CPU */
-int __cpu_disable(void)
+int native_cpu_disable(void)
 {
        return -ENOSYS;
 }
 
-void __cpu_die(unsigned int cpu)
+void native_cpu_die(unsigned int cpu)
 {
        /* We said "no" in __cpu_disable */
        BUG();
 }
-#endif
 
-/*
- * If the BIOS enumerates physical processors before logical,
- * maxcpus=N at enumeration-time can be used to disable HT.
- */
-static int __init parse_maxcpus(char *arg)
+void native_play_dead(void)
 {
-       extern unsigned int maxcpus;
-
-       if (arg)
-               maxcpus = simple_strtoul(arg, NULL, 0);
-       return 0;
+       BUG();
 }
-early_param("maxcpus", parse_maxcpus);
+
+#endif