ARM: 7742/1: topology: export cpu_topology
[pandora-kernel.git] / arch / arm / kernel / smp.c
index d88ff02..bfa0eeb 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/cache.h>
 #include <linux/profile.h>
 #include <linux/errno.h>
-#include <linux/ftrace.h>
 #include <linux/mm.h>
 #include <linux/err.h>
 #include <linux/cpu.h>
@@ -31,6 +30,8 @@
 #include <asm/cacheflush.h>
 #include <asm/cpu.h>
 #include <asm/cputype.h>
+#include <asm/exception.h>
+#include <asm/topology.h>
 #include <asm/mmu_context.h>
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -39,6 +40,7 @@
 #include <asm/tlbflush.h>
 #include <asm/ptrace.h>
 #include <asm/localtimer.h>
+#include <asm/smp_plat.h>
 
 /*
  * as from 2.5, kernels no longer have an init_tasks structure
@@ -259,6 +261,20 @@ void __ref cpu_die(void)
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
+int __cpu_logical_map[NR_CPUS];
+
+void __init smp_setup_processor_id(void)
+{
+       int i;
+       u32 cpu = is_smp() ? read_cpuid_mpidr() & 0xff : 0;
+
+       cpu_logical_map(0) = cpu;
+       for (i = 1; i < NR_CPUS; ++i)
+               cpu_logical_map(i) = i == cpu ? 0 : i;
+
+       printk(KERN_INFO "Booting Linux on physical CPU %d\n", cpu);
+}
+
 /*
  * Called by both boot and secondaries to move global data into
  * per-processor storage.
@@ -268,6 +284,8 @@ static void __cpuinit smp_store_cpu_info(unsigned int cpuid)
        struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
 
        cpu_info->loops_per_jiffy = loops_per_jiffy;
+
+       store_cpu_topology(cpuid);
 }
 
 /*
@@ -277,20 +295,26 @@ static void __cpuinit smp_store_cpu_info(unsigned int cpuid)
 asmlinkage void __cpuinit secondary_start_kernel(void)
 {
        struct mm_struct *mm = &init_mm;
-       unsigned int cpu = smp_processor_id();
+       unsigned int cpu;
 
-       printk("CPU%u: Booted secondary processor\n", cpu);
+       /*
+        * The identity mapping is uncached (strongly ordered), so
+        * switch away from it before attempting any exclusive accesses.
+        */
+       cpu_switch_mm(mm->pgd, mm);
+       enter_lazy_tlb(mm, current);
+       local_flush_tlb_all();
 
        /*
         * All kernel threads share the same mm context; grab a
         * reference and switch to it.
         */
+       cpu = smp_processor_id();
        atomic_inc(&mm->mm_count);
        current->active_mm = mm;
        cpumask_set_cpu(cpu, mm_cpumask(mm));
-       cpu_switch_mm(mm->pgd, mm);
-       enter_lazy_tlb(mm, current);
-       local_flush_tlb_all();
+
+       printk("CPU%u: Booted secondary processor\n", cpu);
 
        cpu_init();
        preempt_disable();
@@ -301,17 +325,7 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
         */
        platform_secondary_init(cpu);
 
-       /*
-        * Enable local interrupts.
-        */
        notify_cpu_starting(cpu);
-       local_irq_enable();
-       local_fiq_enable();
-
-       /*
-        * Setup the percpu timer for this CPU.
-        */
-       percpu_timer_setup();
 
        calibrate_delay();
 
@@ -323,9 +337,22 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
         * before we continue.
         */
        set_cpu_online(cpu, true);
+
+       /*
+        * Setup the percpu timer for this CPU.
+        */
+       percpu_timer_setup();
+
        while (!cpu_active(cpu))
                cpu_relax();
 
+       /*
+        * cpu_active bit is set, so it's safe to enalbe interrupts
+        * now.
+        */
+       local_irq_enable();
+       local_fiq_enable();
+
        /*
         * OK, it's off to the idle thread for us
         */
@@ -358,6 +385,8 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
 {
        unsigned int ncores = num_possible_cpus();
 
+       init_cpu_topology();
+
        smp_store_cpu_info(smp_processor_id());
 
        /*
@@ -437,10 +466,6 @@ u64 smp_irq_stat_cpu(unsigned int cpu)
        for (i = 0; i < NR_IPI; i++)
                sum += __get_irq_stat(cpu, ipi_irqs[i]);
 
-#ifdef CONFIG_LOCAL_TIMERS
-       sum += __get_irq_stat(cpu, local_timer_irqs);
-#endif
-
        return sum;
 }
 
@@ -452,37 +477,8 @@ static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
 static void ipi_timer(void)
 {
        struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
-       irq_enter();
        evt->event_handler(evt);
-       irq_exit();
-}
-
-#ifdef CONFIG_LOCAL_TIMERS
-asmlinkage void __exception_irq_entry do_local_timer(struct pt_regs *regs)
-{
-       struct pt_regs *old_regs = set_irq_regs(regs);
-       int cpu = smp_processor_id();
-
-       if (local_timer_ack()) {
-               __inc_irq_stat(cpu, local_timer_irqs);
-               ipi_timer();
-       }
-
-       set_irq_regs(old_regs);
-}
-
-void show_local_irqs(struct seq_file *p, int prec)
-{
-       unsigned int cpu;
-
-       seq_printf(p, "%*s: ", prec, "LOC");
-
-       for_each_present_cpu(cpu)
-               seq_printf(p, "%10u ", __get_irq_stat(cpu, local_timer_irqs));
-
-       seq_printf(p, " Local timer interrupts\n");
 }
-#endif
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 static void smp_timer_broadcast(const struct cpumask *mask)
@@ -534,11 +530,11 @@ static void percpu_timer_stop(void)
        unsigned int cpu = smp_processor_id();
        struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
 
-       evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt);
+       local_timer_stop(evt);
 }
 #endif
 
-static DEFINE_SPINLOCK(stop_lock);
+static DEFINE_RAW_SPINLOCK(stop_lock);
 
 /*
  * ipi_cpu_stop - handle IPI from smp_send_stop()
@@ -547,10 +543,10 @@ static void ipi_cpu_stop(unsigned int cpu)
 {
        if (system_state == SYSTEM_BOOTING ||
            system_state == SYSTEM_RUNNING) {
-               spin_lock(&stop_lock);
+               raw_spin_lock(&stop_lock);
                printk(KERN_CRIT "CPU%u: stopping\n", cpu);
                dump_stack();
-               spin_unlock(&stop_lock);
+               raw_spin_unlock(&stop_lock);
        }
 
        set_cpu_online(cpu, false);
@@ -566,6 +562,11 @@ static void ipi_cpu_stop(unsigned int cpu)
  * Main handler for inter-processor interrupts
  */
 asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
+{
+       handle_IPI(ipinr, regs);
+}
+
+void handle_IPI(int ipinr, struct pt_regs *regs)
 {
        unsigned int cpu = smp_processor_id();
        struct pt_regs *old_regs = set_irq_regs(regs);
@@ -575,7 +576,9 @@ asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
 
        switch (ipinr) {
        case IPI_TIMER:
+               irq_enter();
                ipi_timer();
+               irq_exit();
                break;
 
        case IPI_RESCHEDULE:
@@ -583,15 +586,21 @@ asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
                break;
 
        case IPI_CALL_FUNC:
+               irq_enter();
                generic_smp_call_function_interrupt();
+               irq_exit();
                break;
 
        case IPI_CALL_FUNC_SINGLE:
+               irq_enter();
                generic_smp_call_function_single_interrupt();
+               irq_exit();
                break;
 
        case IPI_CPU_STOP:
+               irq_enter();
                ipi_cpu_stop(cpu);
+               irq_exit();
                break;
 
        default: