Merge branch 'linus' into x86/x2apic
[sfrench/cifs-2.6.git] / arch / x86 / kernel / smpboot.c
index 09b98cd6332cd8ef2a742de580eece1b2ba51952..626618bf2f819f378053ba4be9476c0bf9a70903 100644 (file)
@@ -123,7 +123,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
 
 static atomic_t init_deasserted;
 
-static int boot_cpu_logical_apicid;
 
 /* representing cpus for which sibling maps can be computed */
 static cpumask_t cpu_sibling_setup_map;
@@ -165,6 +164,8 @@ static void unmap_cpu_to_node(int cpu)
 #endif
 
 #ifdef CONFIG_X86_32
+static int boot_cpu_logical_apicid;
+
 u8 cpu_2_logical_apicid[NR_CPUS] __read_mostly =
                                        { [0 ... NR_CPUS-1] = BAD_APICID };
 
@@ -210,13 +211,13 @@ static void __cpuinit smp_callin(void)
        /*
         * (This works even if the APIC is not enabled.)
         */
-       phys_id = GET_APIC_ID(read_apic_id());
+       phys_id = read_apic_id();
        cpuid = smp_processor_id();
        if (cpu_isset(cpuid, cpu_callin_map)) {
                panic("%s: phys CPU#%d, CPU#%d already present??\n", __func__,
                                        phys_id, cpuid);
        }
-       Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
+       pr_debug("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
 
        /*
         * STARTUP IPIs are fragile beasts as they might sometimes
@@ -251,7 +252,7 @@ static void __cpuinit smp_callin(void)
         * boards)
         */
 
-       Dprintk("CALLIN, before setup_local_APIC().\n");
+       pr_debug("CALLIN, before setup_local_APIC().\n");
        smp_callin_clear_local_apic();
        setup_local_APIC();
        end_local_APIC_setup();
@@ -266,7 +267,7 @@ static void __cpuinit smp_callin(void)
        local_irq_enable();
        calibrate_delay();
        local_irq_disable();
-       Dprintk("Stack at about %p\n", &cpuid);
+       pr_debug("Stack at about %p\n", &cpuid);
 
        /*
         * Save our processor parameters
@@ -513,7 +514,7 @@ static void impress_friends(void)
        /*
         * Allow the user to impress friends.
         */
-       Dprintk("Before bogomips.\n");
+       pr_debug("Before bogomips.\n");
        for_each_possible_cpu(cpu)
                if (cpu_isset(cpu, cpu_callout_map))
                        bogosum += cpu_data(cpu).loops_per_jiffy;
@@ -523,7 +524,7 @@ static void impress_friends(void)
                bogosum/(500000/HZ),
                (bogosum/(5000/HZ))%100);
 
-       Dprintk("Before bogocount - setting activated=1.\n");
+       pr_debug("Before bogocount - setting activated=1.\n");
 }
 
 static inline void __inquire_remote_apic(int apicid)
@@ -546,8 +547,7 @@ static inline void __inquire_remote_apic(int apicid)
                        printk(KERN_CONT
                               "a previous APIC delivery may have failed\n");
 
-               apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
-               apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
+               apic_icr_write(APIC_DM_REMRD | regs[i], apicid);
 
                timeout = 0;
                do {
@@ -579,29 +579,22 @@ wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
        int maxlvt;
 
        /* Target chip */
-       apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(logical_apicid));
-
        /* Boot on the stack */
        /* Kick the second */
-       apic_write_around(APIC_ICR, APIC_DM_NMI | APIC_DEST_LOGICAL);
+       apic_icr_write(APIC_DM_NMI | APIC_DEST_LOGICAL, logical_apicid);
 
-       Dprintk("Waiting for send to finish...\n");
+       pr_debug("Waiting for send to finish...\n");
        send_status = safe_apic_wait_icr_idle();
 
        /*
         * Give the other CPU some time to accept the IPI.
         */
        udelay(200);
-       /*
-        * Due to the Pentium erratum 3AP.
-        */
        maxlvt = lapic_get_maxlvt();
-       if (maxlvt > 3) {
-               apic_read_around(APIC_SPIV);
+       if (maxlvt > 3)                 /* Due to the Pentium erratum 3AP.  */
                apic_write(APIC_ESR, 0);
-       }
        accept_status = (apic_read(APIC_ESR) & 0xEF);
-       Dprintk("NMI sent.\n");
+       pr_debug("NMI sent.\n");
 
        if (send_status)
                printk(KERN_ERR "APIC never delivered???\n");
@@ -625,42 +618,40 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
                return send_status;
        }
 
+       maxlvt = lapic_get_maxlvt();
+
        /*
         * Be paranoid about clearing APIC errors.
         */
        if (APIC_INTEGRATED(apic_version[phys_apicid])) {
-               apic_read_around(APIC_SPIV);
-               apic_write(APIC_ESR, 0);
+               if (maxlvt > 3)         /* Due to the Pentium erratum 3AP.  */
+                       apic_write(APIC_ESR, 0);
                apic_read(APIC_ESR);
        }
 
-       Dprintk("Asserting INIT.\n");
+       pr_debug("Asserting INIT.\n");
 
        /*
         * Turn INIT on target chip
         */
-       apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
-
        /*
         * Send IPI
         */
-       apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
-                               | APIC_DM_INIT);
+       apic_icr_write(APIC_INT_LEVELTRIG | APIC_INT_ASSERT | APIC_DM_INIT,
+                      phys_apicid);
 
-       Dprintk("Waiting for send to finish...\n");
+       pr_debug("Waiting for send to finish...\n");
        send_status = safe_apic_wait_icr_idle();
 
        mdelay(10);
 
-       Dprintk("Deasserting INIT.\n");
+       pr_debug("Deasserting INIT.\n");
 
        /* Target chip */
-       apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
-
        /* Send IPI */
-       apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
+       apic_icr_write(APIC_INT_LEVELTRIG | APIC_DM_INIT, phys_apicid);
 
-       Dprintk("Waiting for send to finish...\n");
+       pr_debug("Waiting for send to finish...\n");
        send_status = safe_apic_wait_icr_idle();
 
        mb();
@@ -687,55 +678,46 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
        /*
         * Run STARTUP IPI loop.
         */
-       Dprintk("#startup loops: %d.\n", num_starts);
-
-       maxlvt = lapic_get_maxlvt();
+       pr_debug("#startup loops: %d.\n", num_starts);
 
        for (j = 1; j <= num_starts; j++) {
-               Dprintk("Sending STARTUP #%d.\n", j);
-               apic_read_around(APIC_SPIV);
-               apic_write(APIC_ESR, 0);
+               pr_debug("Sending STARTUP #%d.\n", j);
+               if (maxlvt > 3)         /* Due to the Pentium erratum 3AP.  */
+                       apic_write(APIC_ESR, 0);
                apic_read(APIC_ESR);
-               Dprintk("After apic_write.\n");
+               pr_debug("After apic_write.\n");
 
                /*
                 * STARTUP IPI
                 */
 
                /* Target chip */
-               apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
-
                /* Boot on the stack */
                /* Kick the second */
-               apic_write_around(APIC_ICR, APIC_DM_STARTUP
-                                       | (start_eip >> 12));
+               apic_icr_write(APIC_DM_STARTUP | (start_eip >> 12),
+                              phys_apicid);
 
                /*
                 * Give the other CPU some time to accept the IPI.
                 */
                udelay(300);
 
-               Dprintk("Startup point 1.\n");
+               pr_debug("Startup point 1.\n");
 
-               Dprintk("Waiting for send to finish...\n");
+               pr_debug("Waiting for send to finish...\n");
                send_status = safe_apic_wait_icr_idle();
 
                /*
                 * Give the other CPU some time to accept the IPI.
                 */
                udelay(200);
-               /*
-                * Due to the Pentium erratum 3AP.
-                */
-               if (maxlvt > 3) {
-                       apic_read_around(APIC_SPIV);
+               if (maxlvt > 3)         /* Due to the Pentium erratum 3AP.  */
                        apic_write(APIC_ESR, 0);
-               }
                accept_status = (apic_read(APIC_ESR) & 0xEF);
                if (send_status || accept_status)
                        break;
        }
-       Dprintk("After Startup.\n");
+       pr_debug("After Startup.\n");
 
        if (send_status)
                printk(KERN_ERR "APIC never delivered???\n");
@@ -768,7 +750,7 @@ static void __cpuinit do_fork_idle(struct work_struct *work)
  *
  * Must be called after the _cpu_pda pointer table is initialized.
  */
-static int __cpuinit get_local_pda(int cpu)
+int __cpuinit get_local_pda(int cpu)
 {
        struct x8664_pda *oldpda, *newpda;
        unsigned long size = sizeof(struct x8664_pda);
@@ -886,7 +868,7 @@ do_rest:
 
        if (get_uv_system_type() != UV_NON_UNIQUE_APIC) {
 
-               Dprintk("Setting warm reset code and vector.\n");
+               pr_debug("Setting warm reset code and vector.\n");
 
                store_NMI_vector(&nmi_high, &nmi_low);
 
@@ -907,9 +889,9 @@ do_rest:
                /*
                 * allow APs to start initializing.
                 */
-               Dprintk("Before Callout %d.\n", cpu);
+               pr_debug("Before Callout %d.\n", cpu);
                cpu_set(cpu, cpu_callout_map);
-               Dprintk("After Callout %d.\n", cpu);
+               pr_debug("After Callout %d.\n", cpu);
 
                /*
                 * Wait 5s total for a response
@@ -922,10 +904,10 @@ do_rest:
 
                if (cpu_isset(cpu, cpu_callin_map)) {
                        /* number CPUs logically, starting from 1 (BSP is 0) */
-                       Dprintk("OK.\n");
+                       pr_debug("OK.\n");
                        printk(KERN_INFO "CPU%d: ", cpu);
                        print_cpu_info(&cpu_data(cpu));
-                       Dprintk("CPU has booted.\n");
+                       pr_debug("CPU has booted.\n");
                } else {
                        boot_error = 1;
                        if (*((volatile unsigned char *)trampoline_base)
@@ -970,7 +952,7 @@ int __cpuinit native_cpu_up(unsigned int cpu)
 
        WARN_ON(irqs_disabled());
 
-       Dprintk("++++++++++++++++++++=_---CPU UP  %u\n", cpu);
+       pr_debug("++++++++++++++++++++=_---CPU UP  %u\n", cpu);
 
        if (apicid == BAD_APICID || apicid == boot_cpu_physical_apicid ||
            !physid_isset(apicid, phys_cpu_present_map)) {
@@ -982,7 +964,7 @@ int __cpuinit native_cpu_up(unsigned int cpu)
         * Already booted CPU?
         */
        if (cpu_isset(cpu, cpu_callin_map)) {
-               Dprintk("do_boot_cpu %d Already started\n", cpu);
+               pr_debug("do_boot_cpu %d Already started\n", cpu);
                return -ENOSYS;
        }
 
@@ -1009,7 +991,7 @@ int __cpuinit native_cpu_up(unsigned int cpu)
        err = do_boot_cpu(apicid, cpu);
 #endif
        if (err) {
-               Dprintk("do_boot_cpu failed %d\n", err);
+               pr_debug("do_boot_cpu failed %d\n", err);
                return -EIO;
        }
 
@@ -1147,10 +1129,17 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
         * Setup boot CPU information
         */
        smp_store_cpu_info(0); /* Final full version of the data */
+#ifdef CONFIG_X86_32
        boot_cpu_logical_apicid = logical_smp_processor_id();
+#endif
        current_thread_info()->cpu = 0;  /* needed? */
        set_cpu_sibling_map(0);
 
+#ifdef CONFIG_X86_64
+       enable_IR_x2apic();
+       setup_apic_routing();
+#endif
+
        if (smp_sanity_check(max_cpus) < 0) {
                printk(KERN_INFO "SMP disabled\n");
                disable_smp();
@@ -1158,9 +1147,9 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
        }
 
        preempt_disable();
-       if (GET_APIC_ID(read_apic_id()) != boot_cpu_physical_apicid) {
+       if (read_apic_id() != boot_cpu_physical_apicid) {
                panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
-                    GET_APIC_ID(read_apic_id()), boot_cpu_physical_apicid);
+                    read_apic_id(), boot_cpu_physical_apicid);
                /* Or can we switch back to PIC here? */
        }
        preempt_enable();
@@ -1213,7 +1202,7 @@ void __init native_smp_prepare_boot_cpu(void)
 
 void __init native_smp_cpus_done(unsigned int max_cpus)
 {
-       Dprintk("Boot done.\n");
+       pr_debug("Boot done.\n");
 
        impress_friends();
        smp_checks();
@@ -1311,7 +1300,7 @@ static void __ref remove_cpu_from_maps(int cpu)
        cpu_clear(cpu, cpu_callout_map);
        cpu_clear(cpu, cpu_callin_map);
        /* was set by cpu_init() */
-       clear_bit(cpu, (unsigned long *)&cpu_initialized);
+       cpu_clear(cpu, cpu_initialized);
        numa_remove_cpu(cpu);
 }
 
@@ -1390,7 +1379,8 @@ static int __init parse_maxcpus(char *arg)
 {
        extern unsigned int maxcpus;
 
-       maxcpus = simple_strtoul(arg, NULL, 0);
+       if (arg)
+               maxcpus = simple_strtoul(arg, NULL, 0);
        return 0;
 }
 early_param("maxcpus", parse_maxcpus);