11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds ** SMP Support 31da177e4SLinus Torvalds ** 41da177e4SLinus Torvalds ** Copyright (C) 1999 Walt Drummond <drummond@valinux.com> 51da177e4SLinus Torvalds ** Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com> 61da177e4SLinus Torvalds ** Copyright (C) 2001,2004 Grant Grundler <grundler@parisc-linux.org> 71da177e4SLinus Torvalds ** 81da177e4SLinus Torvalds ** Lots of stuff stolen from arch/alpha/kernel/smp.c 91da177e4SLinus Torvalds ** ...and then parisc stole from arch/ia64/kernel/smp.c. Thanks David! :^) 101da177e4SLinus Torvalds ** 111da177e4SLinus Torvalds ** Thanks to John Curry and Ullas Ponnadi. I learned alot from their work. 121da177e4SLinus Torvalds ** -grant (1/12/2001) 131da177e4SLinus Torvalds ** 141da177e4SLinus Torvalds ** This program is free software; you can redistribute it and/or modify 151da177e4SLinus Torvalds ** it under the terms of the GNU General Public License as published by 161da177e4SLinus Torvalds ** the Free Software Foundation; either version 2 of the License, or 171da177e4SLinus Torvalds ** (at your option) any later version. 181da177e4SLinus Torvalds */ 191da177e4SLinus Torvalds #undef ENTRY_SYS_CPUS /* syscall support for iCOD-like functionality */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include <linux/types.h> 231da177e4SLinus Torvalds #include <linux/spinlock.h> 241da177e4SLinus Torvalds #include <linux/slab.h> 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #include <linux/kernel.h> 271da177e4SLinus Torvalds #include <linux/module.h> 281da177e4SLinus Torvalds #include <linux/sched.h> 291da177e4SLinus Torvalds #include <linux/init.h> 301da177e4SLinus Torvalds #include <linux/interrupt.h> 311da177e4SLinus Torvalds #include <linux/smp.h> 321da177e4SLinus Torvalds #include <linux/kernel_stat.h> 331da177e4SLinus Torvalds #include <linux/mm.h> 341da177e4SLinus Torvalds #include <linux/delay.h> 351da177e4SLinus Torvalds #include <linux/bitops.h> 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #include <asm/system.h> 381da177e4SLinus Torvalds #include <asm/atomic.h> 391da177e4SLinus Torvalds #include <asm/current.h> 401da177e4SLinus Torvalds #include <asm/delay.h> 411b2425e3SMatthew Wilcox #include <asm/tlbflush.h> 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #include <asm/io.h> 441da177e4SLinus Torvalds #include <asm/irq.h> /* for CPU_IRQ_REGION and friends */ 451da177e4SLinus Torvalds #include <asm/mmu_context.h> 461da177e4SLinus Torvalds #include <asm/page.h> 471da177e4SLinus Torvalds #include <asm/pgtable.h> 481da177e4SLinus Torvalds #include <asm/pgalloc.h> 491da177e4SLinus Torvalds #include <asm/processor.h> 501da177e4SLinus Torvalds #include <asm/ptrace.h> 511da177e4SLinus Torvalds #include <asm/unistd.h> 521da177e4SLinus Torvalds #include <asm/cacheflush.h> 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds #define kDEBUG 0 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds DEFINE_SPINLOCK(smp_lock); 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds volatile struct task_struct *smp_init_current_idle_task; 591da177e4SLinus Torvalds 608039de10SHelge Deller static volatile int cpu_now_booting __read_mostly = 0; /* track which CPU is booting */ 611da177e4SLinus Torvalds 628039de10SHelge Deller static int parisc_max_cpus __read_mostly = 1; 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds /* online cpus are ones that we've managed to bring up completely 651da177e4SLinus Torvalds * possible cpus are all valid cpu 661da177e4SLinus Torvalds * present cpus are all detected cpu 671da177e4SLinus Torvalds * 681da177e4SLinus Torvalds * On startup we bring up the "possible" cpus. Since we discover 691da177e4SLinus Torvalds * CPUs later, we add them as hotplug, so the possible cpu mask is 701da177e4SLinus Torvalds * empty in the beginning. 711da177e4SLinus Torvalds */ 721da177e4SLinus Torvalds 738039de10SHelge Deller cpumask_t cpu_online_map __read_mostly = CPU_MASK_NONE; /* Bitmap of online CPUs */ 748039de10SHelge Deller cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL; /* Bitmap of Present CPUs */ 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds EXPORT_SYMBOL(cpu_online_map); 771da177e4SLinus Torvalds EXPORT_SYMBOL(cpu_possible_map); 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds struct smp_call_struct { 811da177e4SLinus Torvalds void (*func) (void *info); 821da177e4SLinus Torvalds void *info; 831da177e4SLinus Torvalds long wait; 841da177e4SLinus Torvalds atomic_t unstarted_count; 851da177e4SLinus Torvalds atomic_t unfinished_count; 861da177e4SLinus Torvalds }; 871da177e4SLinus Torvalds static volatile struct smp_call_struct *smp_call_function_data; 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds enum ipi_message_type { 901da177e4SLinus Torvalds IPI_NOP=0, 911da177e4SLinus Torvalds IPI_RESCHEDULE=1, 921da177e4SLinus Torvalds IPI_CALL_FUNC, 931da177e4SLinus Torvalds IPI_CPU_START, 941da177e4SLinus Torvalds IPI_CPU_STOP, 951da177e4SLinus Torvalds IPI_CPU_TEST 961da177e4SLinus Torvalds }; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds /********** SMP inter processor interrupt and communication routines */ 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #undef PER_CPU_IRQ_REGION 1021da177e4SLinus Torvalds #ifdef PER_CPU_IRQ_REGION 1031da177e4SLinus Torvalds /* XXX REVISIT Ignore for now. 1041da177e4SLinus Torvalds ** *May* need this "hook" to register IPI handler 1051da177e4SLinus Torvalds ** once we have perCPU ExtIntr switch tables. 1061da177e4SLinus Torvalds */ 1071da177e4SLinus Torvalds static void 1081da177e4SLinus Torvalds ipi_init(int cpuid) 1091da177e4SLinus Torvalds { 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* If CPU is present ... */ 1121da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 1131da177e4SLinus Torvalds /* *and* running (not stopped) ... */ 1141da177e4SLinus Torvalds #error iCOD support wants state checked here. 1151da177e4SLinus Torvalds #endif 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds #error verify IRQ_OFFSET(IPI_IRQ) is ipi_interrupt() in new IRQ region 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds if(cpu_online(cpuid) ) 1201da177e4SLinus Torvalds { 1211da177e4SLinus Torvalds switch_to_idle_task(current); 1221da177e4SLinus Torvalds } 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds return; 1251da177e4SLinus Torvalds } 1261da177e4SLinus Torvalds #endif 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds /* 1301da177e4SLinus Torvalds ** Yoink this CPU from the runnable list... 1311da177e4SLinus Torvalds ** 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds static void 1341da177e4SLinus Torvalds halt_processor(void) 1351da177e4SLinus Torvalds { 1361da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 1371da177e4SLinus Torvalds #error halt_processor() needs rework 1381da177e4SLinus Torvalds /* 1391da177e4SLinus Torvalds ** o migrate I/O interrupts off this CPU. 1401da177e4SLinus Torvalds ** o leave IPI enabled - __cli() will disable IPI. 1411da177e4SLinus Torvalds ** o leave CPU in online map - just change the state 1421da177e4SLinus Torvalds */ 1431da177e4SLinus Torvalds cpu_data[this_cpu].state = STATE_STOPPED; 1441da177e4SLinus Torvalds mark_bh(IPI_BH); 1451da177e4SLinus Torvalds #else 1461da177e4SLinus Torvalds /* REVISIT : redirect I/O Interrupts to another CPU? */ 1471da177e4SLinus Torvalds /* REVISIT : does PM *know* this CPU isn't available? */ 1481da177e4SLinus Torvalds cpu_clear(smp_processor_id(), cpu_online_map); 1491da177e4SLinus Torvalds local_irq_disable(); 1501da177e4SLinus Torvalds for (;;) 1511da177e4SLinus Torvalds ; 1521da177e4SLinus Torvalds #endif 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds irqreturn_t 157c7753f18SMatthew Wilcox ipi_interrupt(int irq, void *dev_id) 1581da177e4SLinus Torvalds { 1591da177e4SLinus Torvalds int this_cpu = smp_processor_id(); 1601da177e4SLinus Torvalds struct cpuinfo_parisc *p = &cpu_data[this_cpu]; 1611da177e4SLinus Torvalds unsigned long ops; 1621da177e4SLinus Torvalds unsigned long flags; 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds /* Count this now; we may make a call that never returns. */ 1651da177e4SLinus Torvalds p->ipi_count++; 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds mb(); /* Order interrupt and bit testing. */ 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds for (;;) { 1701da177e4SLinus Torvalds spin_lock_irqsave(&(p->lock),flags); 1711da177e4SLinus Torvalds ops = p->pending_ipi; 1721da177e4SLinus Torvalds p->pending_ipi = 0; 1731da177e4SLinus Torvalds spin_unlock_irqrestore(&(p->lock),flags); 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds mb(); /* Order bit clearing and data access. */ 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds if (!ops) 1781da177e4SLinus Torvalds break; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds while (ops) { 1811da177e4SLinus Torvalds unsigned long which = ffz(~ops); 1821da177e4SLinus Torvalds 183d911aed8SJames Bottomley ops &= ~(1 << which); 184d911aed8SJames Bottomley 1851da177e4SLinus Torvalds switch (which) { 186d911aed8SJames Bottomley case IPI_NOP: 187d911aed8SJames Bottomley #if (kDEBUG>=100) 188d911aed8SJames Bottomley printk(KERN_DEBUG "CPU%d IPI_NOP\n",this_cpu); 189d911aed8SJames Bottomley #endif /* kDEBUG */ 190d911aed8SJames Bottomley break; 191d911aed8SJames Bottomley 1921da177e4SLinus Torvalds case IPI_RESCHEDULE: 1931da177e4SLinus Torvalds #if (kDEBUG>=100) 1941da177e4SLinus Torvalds printk(KERN_DEBUG "CPU%d IPI_RESCHEDULE\n",this_cpu); 1951da177e4SLinus Torvalds #endif /* kDEBUG */ 1961da177e4SLinus Torvalds /* 1971da177e4SLinus Torvalds * Reschedule callback. Everything to be 1981da177e4SLinus Torvalds * done is done by the interrupt return path. 1991da177e4SLinus Torvalds */ 2001da177e4SLinus Torvalds break; 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds case IPI_CALL_FUNC: 2031da177e4SLinus Torvalds #if (kDEBUG>=100) 2041da177e4SLinus Torvalds printk(KERN_DEBUG "CPU%d IPI_CALL_FUNC\n",this_cpu); 2051da177e4SLinus Torvalds #endif /* kDEBUG */ 2061da177e4SLinus Torvalds { 2071da177e4SLinus Torvalds volatile struct smp_call_struct *data; 2081da177e4SLinus Torvalds void (*func)(void *info); 2091da177e4SLinus Torvalds void *info; 2101da177e4SLinus Torvalds int wait; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds data = smp_call_function_data; 2131da177e4SLinus Torvalds func = data->func; 2141da177e4SLinus Torvalds info = data->info; 2151da177e4SLinus Torvalds wait = data->wait; 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds mb(); 2181da177e4SLinus Torvalds atomic_dec ((atomic_t *)&data->unstarted_count); 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds /* At this point, *data can't 2211da177e4SLinus Torvalds * be relied upon. 2221da177e4SLinus Torvalds */ 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds (*func)(info); 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds /* Notify the sending CPU that the 2271da177e4SLinus Torvalds * task is done. 2281da177e4SLinus Torvalds */ 2291da177e4SLinus Torvalds mb(); 2301da177e4SLinus Torvalds if (wait) 2311da177e4SLinus Torvalds atomic_dec ((atomic_t *)&data->unfinished_count); 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds break; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds case IPI_CPU_START: 2361da177e4SLinus Torvalds #if (kDEBUG>=100) 2371da177e4SLinus Torvalds printk(KERN_DEBUG "CPU%d IPI_CPU_START\n",this_cpu); 2381da177e4SLinus Torvalds #endif /* kDEBUG */ 2391da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 2401da177e4SLinus Torvalds p->state = STATE_RUNNING; 2411da177e4SLinus Torvalds #endif 2421da177e4SLinus Torvalds break; 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds case IPI_CPU_STOP: 2451da177e4SLinus Torvalds #if (kDEBUG>=100) 2461da177e4SLinus Torvalds printk(KERN_DEBUG "CPU%d IPI_CPU_STOP\n",this_cpu); 2471da177e4SLinus Torvalds #endif /* kDEBUG */ 2481da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 2491da177e4SLinus Torvalds #else 2501da177e4SLinus Torvalds halt_processor(); 2511da177e4SLinus Torvalds #endif 2521da177e4SLinus Torvalds break; 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds case IPI_CPU_TEST: 2551da177e4SLinus Torvalds #if (kDEBUG>=100) 2561da177e4SLinus Torvalds printk(KERN_DEBUG "CPU%d is alive!\n",this_cpu); 2571da177e4SLinus Torvalds #endif /* kDEBUG */ 2581da177e4SLinus Torvalds break; 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds default: 2611da177e4SLinus Torvalds printk(KERN_CRIT "Unknown IPI num on CPU%d: %lu\n", 2621da177e4SLinus Torvalds this_cpu, which); 2631da177e4SLinus Torvalds return IRQ_NONE; 2641da177e4SLinus Torvalds } /* Switch */ 2657085689eSJames Bottomley /* let in any pending interrupts */ 2667085689eSJames Bottomley local_irq_enable(); 2677085689eSJames Bottomley local_irq_disable(); 2681da177e4SLinus Torvalds } /* while (ops) */ 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds return IRQ_HANDLED; 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds static inline void 2751da177e4SLinus Torvalds ipi_send(int cpu, enum ipi_message_type op) 2761da177e4SLinus Torvalds { 2771da177e4SLinus Torvalds struct cpuinfo_parisc *p = &cpu_data[cpu]; 2781da177e4SLinus Torvalds unsigned long flags; 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds spin_lock_irqsave(&(p->lock),flags); 2811da177e4SLinus Torvalds p->pending_ipi |= 1 << op; 2821da177e4SLinus Torvalds gsc_writel(IPI_IRQ - CPU_IRQ_BASE, cpu_data[cpu].hpa); 2831da177e4SLinus Torvalds spin_unlock_irqrestore(&(p->lock),flags); 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds static inline void 2881da177e4SLinus Torvalds send_IPI_single(int dest_cpu, enum ipi_message_type op) 2891da177e4SLinus Torvalds { 2901da177e4SLinus Torvalds if (dest_cpu == NO_PROC_ID) { 2911da177e4SLinus Torvalds BUG(); 2921da177e4SLinus Torvalds return; 2931da177e4SLinus Torvalds } 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds ipi_send(dest_cpu, op); 2961da177e4SLinus Torvalds } 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds static inline void 2991da177e4SLinus Torvalds send_IPI_allbutself(enum ipi_message_type op) 3001da177e4SLinus Torvalds { 3011da177e4SLinus Torvalds int i; 3021da177e4SLinus Torvalds 303394e3902SAndrew Morton for_each_online_cpu(i) { 304394e3902SAndrew Morton if (i != smp_processor_id()) 3051da177e4SLinus Torvalds send_IPI_single(i, op); 3061da177e4SLinus Torvalds } 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds inline void 3111da177e4SLinus Torvalds smp_send_stop(void) { send_IPI_allbutself(IPI_CPU_STOP); } 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds static inline void 3141da177e4SLinus Torvalds smp_send_start(void) { send_IPI_allbutself(IPI_CPU_START); } 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds void 3171da177e4SLinus Torvalds smp_send_reschedule(int cpu) { send_IPI_single(cpu, IPI_RESCHEDULE); } 3181da177e4SLinus Torvalds 319d911aed8SJames Bottomley void 320d911aed8SJames Bottomley smp_send_all_nop(void) 321d911aed8SJames Bottomley { 322d911aed8SJames Bottomley send_IPI_allbutself(IPI_NOP); 323d911aed8SJames Bottomley } 324d911aed8SJames Bottomley 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds /** 3271da177e4SLinus Torvalds * Run a function on all other CPUs. 3281da177e4SLinus Torvalds * <func> The function to run. This must be fast and non-blocking. 3291da177e4SLinus Torvalds * <info> An arbitrary pointer to pass to the function. 3301da177e4SLinus Torvalds * <retry> If true, keep retrying until ready. 3311da177e4SLinus Torvalds * <wait> If true, wait until function has completed on other CPUs. 3321da177e4SLinus Torvalds * [RETURNS] 0 on success, else a negative status code. 3331da177e4SLinus Torvalds * 3341da177e4SLinus Torvalds * Does not return until remote CPUs are nearly ready to execute <func> 3351da177e4SLinus Torvalds * or have executed. 3361da177e4SLinus Torvalds */ 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds int 3391da177e4SLinus Torvalds smp_call_function (void (*func) (void *info), void *info, int retry, int wait) 3401da177e4SLinus Torvalds { 3411da177e4SLinus Torvalds struct smp_call_struct data; 3421da177e4SLinus Torvalds unsigned long timeout; 3431da177e4SLinus Torvalds static DEFINE_SPINLOCK(lock); 3441da177e4SLinus Torvalds int retries = 0; 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds if (num_online_cpus() < 2) 3471da177e4SLinus Torvalds return 0; 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds /* Can deadlock when called with interrupts disabled */ 3501da177e4SLinus Torvalds WARN_ON(irqs_disabled()); 3519a8b4584SJames Bottomley 3529a8b4584SJames Bottomley /* can also deadlock if IPIs are disabled */ 3539a8b4584SJames Bottomley WARN_ON((get_eiem() & (1UL<<(CPU_IRQ_MAX - IPI_IRQ))) == 0); 3549a8b4584SJames Bottomley 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvalds data.func = func; 3571da177e4SLinus Torvalds data.info = info; 3581da177e4SLinus Torvalds data.wait = wait; 3591da177e4SLinus Torvalds atomic_set(&data.unstarted_count, num_online_cpus() - 1); 3601da177e4SLinus Torvalds atomic_set(&data.unfinished_count, num_online_cpus() - 1); 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds if (retry) { 3631da177e4SLinus Torvalds spin_lock (&lock); 3641da177e4SLinus Torvalds while (smp_call_function_data != 0) 3651da177e4SLinus Torvalds barrier(); 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds else { 3681da177e4SLinus Torvalds spin_lock (&lock); 3691da177e4SLinus Torvalds if (smp_call_function_data) { 3701da177e4SLinus Torvalds spin_unlock (&lock); 3711da177e4SLinus Torvalds return -EBUSY; 3721da177e4SLinus Torvalds } 3731da177e4SLinus Torvalds } 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds smp_call_function_data = &data; 3761da177e4SLinus Torvalds spin_unlock (&lock); 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds /* Send a message to all other CPUs and wait for them to respond */ 3791da177e4SLinus Torvalds send_IPI_allbutself(IPI_CALL_FUNC); 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvalds retry: 3821da177e4SLinus Torvalds /* Wait for response */ 3831da177e4SLinus Torvalds timeout = jiffies + HZ; 3841da177e4SLinus Torvalds while ( (atomic_read (&data.unstarted_count) > 0) && 3851da177e4SLinus Torvalds time_before (jiffies, timeout) ) 3861da177e4SLinus Torvalds barrier (); 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds if (atomic_read (&data.unstarted_count) > 0) { 3891da177e4SLinus Torvalds printk(KERN_CRIT "SMP CALL FUNCTION TIMED OUT! (cpu=%d), try %d\n", 3901da177e4SLinus Torvalds smp_processor_id(), ++retries); 3911da177e4SLinus Torvalds goto retry; 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds /* We either got one or timed out. Release the lock */ 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds mb(); 3961da177e4SLinus Torvalds smp_call_function_data = NULL; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds while (wait && atomic_read (&data.unfinished_count) > 0) 3991da177e4SLinus Torvalds barrier (); 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds return 0; 4021da177e4SLinus Torvalds } 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds EXPORT_SYMBOL(smp_call_function); 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds /* 4071da177e4SLinus Torvalds * Flush all other CPU's tlb and then mine. Do this with on_each_cpu() 4081da177e4SLinus Torvalds * as we want to ensure all TLB's flushed before proceeding. 4091da177e4SLinus Torvalds */ 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds void 4121da177e4SLinus Torvalds smp_flush_tlb_all(void) 4131da177e4SLinus Torvalds { 4141b2425e3SMatthew Wilcox on_each_cpu(flush_tlb_all_local, NULL, 1, 1); 4151da177e4SLinus Torvalds } 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds /* 4181da177e4SLinus Torvalds * Called by secondaries to update state and initialize CPU registers. 4191da177e4SLinus Torvalds */ 4201da177e4SLinus Torvalds static void __init 4211da177e4SLinus Torvalds smp_cpu_init(int cpunum) 4221da177e4SLinus Torvalds { 42356f335c8SGrant Grundler extern int init_per_cpu(int); /* arch/parisc/kernel/processor.c */ 4241da177e4SLinus Torvalds extern void init_IRQ(void); /* arch/parisc/kernel/irq.c */ 42556f335c8SGrant Grundler extern void start_cpu_itimer(void); /* arch/parisc/kernel/time.c */ 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds /* Set modes and Enable floating point coprocessor */ 4281da177e4SLinus Torvalds (void) init_per_cpu(cpunum); 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds disable_sr_hashing(); 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds mb(); 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds /* Well, support 2.4 linux scheme as well. */ 4351da177e4SLinus Torvalds if (cpu_test_and_set(cpunum, cpu_online_map)) 4361da177e4SLinus Torvalds { 4371da177e4SLinus Torvalds extern void machine_halt(void); /* arch/parisc.../process.c */ 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds printk(KERN_CRIT "CPU#%d already initialized!\n", cpunum); 4401da177e4SLinus Torvalds machine_halt(); 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds /* Initialise the idle task for this CPU */ 4441da177e4SLinus Torvalds atomic_inc(&init_mm.mm_count); 4451da177e4SLinus Torvalds current->active_mm = &init_mm; 4461da177e4SLinus Torvalds if(current->mm) 4471da177e4SLinus Torvalds BUG(); 4481da177e4SLinus Torvalds enter_lazy_tlb(&init_mm, current); 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds init_IRQ(); /* make sure no IRQ's are enabled or pending */ 45156f335c8SGrant Grundler start_cpu_itimer(); 4521da177e4SLinus Torvalds } 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds /* 4561da177e4SLinus Torvalds * Slaves start using C here. Indirectly called from smp_slave_stext. 4571da177e4SLinus Torvalds * Do what start_kernel() and main() do for boot strap processor (aka monarch) 4581da177e4SLinus Torvalds */ 4591da177e4SLinus Torvalds void __init smp_callin(void) 4601da177e4SLinus Torvalds { 4611da177e4SLinus Torvalds int slave_id = cpu_now_booting; 4621da177e4SLinus Torvalds #if 0 4631da177e4SLinus Torvalds void *istack; 4641da177e4SLinus Torvalds #endif 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds smp_cpu_init(slave_id); 4675bfb5d69SNick Piggin preempt_disable(); 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds #if 0 /* NOT WORKING YET - see entry.S */ 4701da177e4SLinus Torvalds istack = (void *)__get_free_pages(GFP_KERNEL,ISTACK_ORDER); 4711da177e4SLinus Torvalds if (istack == NULL) { 4721da177e4SLinus Torvalds printk(KERN_CRIT "Failed to allocate interrupt stack for cpu %d\n",slave_id); 4731da177e4SLinus Torvalds BUG(); 4741da177e4SLinus Torvalds } 4751da177e4SLinus Torvalds mtctl(istack,31); 4761da177e4SLinus Torvalds #endif 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds flush_cache_all_local(); /* start with known state */ 4791b2425e3SMatthew Wilcox flush_tlb_all_local(NULL); 4801da177e4SLinus Torvalds 4811da177e4SLinus Torvalds local_irq_enable(); /* Interrupts have been off until now */ 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds cpu_idle(); /* Wait for timer to schedule some work */ 4841da177e4SLinus Torvalds 4851da177e4SLinus Torvalds /* NOTREACHED */ 4861da177e4SLinus Torvalds panic("smp_callin() AAAAaaaaahhhh....\n"); 4871da177e4SLinus Torvalds } 4881da177e4SLinus Torvalds 4891da177e4SLinus Torvalds /* 4901da177e4SLinus Torvalds * Bring one cpu online. 4911da177e4SLinus Torvalds */ 4921da177e4SLinus Torvalds int __init smp_boot_one_cpu(int cpuid) 4931da177e4SLinus Torvalds { 4941da177e4SLinus Torvalds struct task_struct *idle; 4951da177e4SLinus Torvalds long timeout; 4961da177e4SLinus Torvalds 4971da177e4SLinus Torvalds /* 4981da177e4SLinus Torvalds * Create an idle task for this CPU. Note the address wed* give 4991da177e4SLinus Torvalds * to kernel_thread is irrelevant -- it's going to start 5001da177e4SLinus Torvalds * where OS_BOOT_RENDEVZ vector in SAL says to start. But 5011da177e4SLinus Torvalds * this gets all the other task-y sort of data structures set 5021da177e4SLinus Torvalds * up like we wish. We need to pull the just created idle task 5031da177e4SLinus Torvalds * off the run queue and stuff it into the init_tasks[] array. 5041da177e4SLinus Torvalds * Sheesh . . . 5051da177e4SLinus Torvalds */ 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds idle = fork_idle(cpuid); 5081da177e4SLinus Torvalds if (IS_ERR(idle)) 5091da177e4SLinus Torvalds panic("SMP: fork failed for CPU:%d", cpuid); 5101da177e4SLinus Torvalds 51140f1f0deSAl Viro task_thread_info(idle)->cpu = cpuid; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds /* Let _start know what logical CPU we're booting 5141da177e4SLinus Torvalds ** (offset into init_tasks[],cpu_data[]) 5151da177e4SLinus Torvalds */ 5161da177e4SLinus Torvalds cpu_now_booting = cpuid; 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds /* 5191da177e4SLinus Torvalds ** boot strap code needs to know the task address since 5201da177e4SLinus Torvalds ** it also contains the process stack. 5211da177e4SLinus Torvalds */ 5221da177e4SLinus Torvalds smp_init_current_idle_task = idle ; 5231da177e4SLinus Torvalds mb(); 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds printk("Releasing cpu %d now, hpa=%lx\n", cpuid, cpu_data[cpuid].hpa); 5261da177e4SLinus Torvalds 5271da177e4SLinus Torvalds /* 5281da177e4SLinus Torvalds ** This gets PDC to release the CPU from a very tight loop. 5291da177e4SLinus Torvalds ** 5301da177e4SLinus Torvalds ** From the PA-RISC 2.0 Firmware Architecture Reference Specification: 5311da177e4SLinus Torvalds ** "The MEM_RENDEZ vector specifies the location of OS_RENDEZ which 5321da177e4SLinus Torvalds ** is executed after receiving the rendezvous signal (an interrupt to 5331da177e4SLinus Torvalds ** EIR{0}). MEM_RENDEZ is valid only when it is nonzero and the 5341da177e4SLinus Torvalds ** contents of memory are valid." 5351da177e4SLinus Torvalds */ 5361da177e4SLinus Torvalds gsc_writel(TIMER_IRQ - CPU_IRQ_BASE, cpu_data[cpuid].hpa); 5371da177e4SLinus Torvalds mb(); 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds /* 5401da177e4SLinus Torvalds * OK, wait a bit for that CPU to finish staggering about. 5411da177e4SLinus Torvalds * Slave will set a bit when it reaches smp_cpu_init(). 5421da177e4SLinus Torvalds * Once the "monarch CPU" sees the bit change, it can move on. 5431da177e4SLinus Torvalds */ 5441da177e4SLinus Torvalds for (timeout = 0; timeout < 10000; timeout++) { 5451da177e4SLinus Torvalds if(cpu_online(cpuid)) { 5461da177e4SLinus Torvalds /* Which implies Slave has started up */ 5471da177e4SLinus Torvalds cpu_now_booting = 0; 5481da177e4SLinus Torvalds smp_init_current_idle_task = NULL; 5491da177e4SLinus Torvalds goto alive ; 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds udelay(100); 5521da177e4SLinus Torvalds barrier(); 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds put_task_struct(idle); 5561da177e4SLinus Torvalds idle = NULL; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds printk(KERN_CRIT "SMP: CPU:%d is stuck.\n", cpuid); 5591da177e4SLinus Torvalds return -1; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds alive: 5621da177e4SLinus Torvalds /* Remember the Slave data */ 5631da177e4SLinus Torvalds #if (kDEBUG>=100) 5641da177e4SLinus Torvalds printk(KERN_DEBUG "SMP: CPU:%d came alive after %ld _us\n", 5651da177e4SLinus Torvalds cpuid, timeout * 100); 5661da177e4SLinus Torvalds #endif /* kDEBUG */ 5671da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 5681da177e4SLinus Torvalds cpu_data[cpuid].state = STATE_RUNNING; 5691da177e4SLinus Torvalds #endif 5701da177e4SLinus Torvalds return 0; 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds void __devinit smp_prepare_boot_cpu(void) 5741da177e4SLinus Torvalds { 5751da177e4SLinus Torvalds int bootstrap_processor=cpu_data[0].cpuid; /* CPU ID of BSP */ 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 5781da177e4SLinus Torvalds cpu_data[0].state = STATE_RUNNING; 5791da177e4SLinus Torvalds #endif 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds /* Setup BSP mappings */ 5821da177e4SLinus Torvalds printk("SMP: bootstrap CPU ID is %d\n",bootstrap_processor); 5831da177e4SLinus Torvalds 5841da177e4SLinus Torvalds cpu_set(bootstrap_processor, cpu_online_map); 5851da177e4SLinus Torvalds cpu_set(bootstrap_processor, cpu_present_map); 5861da177e4SLinus Torvalds } 5871da177e4SLinus Torvalds 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds /* 5911da177e4SLinus Torvalds ** inventory.c:do_inventory() hasn't yet been run and thus we 5921da177e4SLinus Torvalds ** don't 'discover' the additional CPU's until later. 5931da177e4SLinus Torvalds */ 5941da177e4SLinus Torvalds void __init smp_prepare_cpus(unsigned int max_cpus) 5951da177e4SLinus Torvalds { 5961da177e4SLinus Torvalds cpus_clear(cpu_present_map); 5971da177e4SLinus Torvalds cpu_set(0, cpu_present_map); 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds parisc_max_cpus = max_cpus; 6001da177e4SLinus Torvalds if (!max_cpus) 6011da177e4SLinus Torvalds printk(KERN_INFO "SMP mode deactivated.\n"); 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds void smp_cpus_done(unsigned int cpu_max) 6061da177e4SLinus Torvalds { 6071da177e4SLinus Torvalds return; 6081da177e4SLinus Torvalds } 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds 611b282b6f8SGautham R Shenoy int __cpuinit __cpu_up(unsigned int cpu) 6121da177e4SLinus Torvalds { 6131da177e4SLinus Torvalds if (cpu != 0 && cpu < parisc_max_cpus) 6141da177e4SLinus Torvalds smp_boot_one_cpu(cpu); 6151da177e4SLinus Torvalds 6161da177e4SLinus Torvalds return cpu_online(cpu) ? 0 : -ENOSYS; 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds #ifdef ENTRY_SYS_CPUS 6221da177e4SLinus Torvalds /* Code goes along with: 6231da177e4SLinus Torvalds ** entry.s: ENTRY_NAME(sys_cpus) / * 215, for cpu stat * / 6241da177e4SLinus Torvalds */ 6251da177e4SLinus Torvalds int sys_cpus(int argc, char **argv) 6261da177e4SLinus Torvalds { 6271da177e4SLinus Torvalds int i,j=0; 6281da177e4SLinus Torvalds extern int current_pid(int cpu); 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds if( argc > 2 ) { 6311da177e4SLinus Torvalds printk("sys_cpus:Only one argument supported\n"); 6321da177e4SLinus Torvalds return (-1); 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds if ( argc == 1 ){ 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvalds #ifdef DUMP_MORE_STATE 637394e3902SAndrew Morton for_each_online_cpu(i) { 6381da177e4SLinus Torvalds int cpus_per_line = 4; 639394e3902SAndrew Morton 6401da177e4SLinus Torvalds if (j++ % cpus_per_line) 6411da177e4SLinus Torvalds printk(" %3d",i); 6421da177e4SLinus Torvalds else 6431da177e4SLinus Torvalds printk("\n %3d",i); 6441da177e4SLinus Torvalds } 6451da177e4SLinus Torvalds printk("\n"); 6461da177e4SLinus Torvalds #else 6471da177e4SLinus Torvalds printk("\n 0\n"); 6481da177e4SLinus Torvalds #endif 6491da177e4SLinus Torvalds } else if((argc==2) && !(strcmp(argv[1],"-l"))) { 6501da177e4SLinus Torvalds printk("\nCPUSTATE TASK CPUNUM CPUID HARDCPU(HPA)\n"); 6511da177e4SLinus Torvalds #ifdef DUMP_MORE_STATE 652394e3902SAndrew Morton for_each_online_cpu(i) { 6531da177e4SLinus Torvalds if (cpu_data[i].cpuid != NO_PROC_ID) { 6541da177e4SLinus Torvalds switch(cpu_data[i].state) { 6551da177e4SLinus Torvalds case STATE_RENDEZVOUS: 6561da177e4SLinus Torvalds printk("RENDEZVS "); 6571da177e4SLinus Torvalds break; 6581da177e4SLinus Torvalds case STATE_RUNNING: 6591da177e4SLinus Torvalds printk((current_pid(i)!=0) ? "RUNNING " : "IDLING "); 6601da177e4SLinus Torvalds break; 6611da177e4SLinus Torvalds case STATE_STOPPED: 6621da177e4SLinus Torvalds printk("STOPPED "); 6631da177e4SLinus Torvalds break; 6641da177e4SLinus Torvalds case STATE_HALTED: 6651da177e4SLinus Torvalds printk("HALTED "); 6661da177e4SLinus Torvalds break; 6671da177e4SLinus Torvalds default: 6681da177e4SLinus Torvalds printk("%08x?", cpu_data[i].state); 6691da177e4SLinus Torvalds break; 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds if(cpu_online(i)) { 6721da177e4SLinus Torvalds printk(" %4d",current_pid(i)); 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds printk(" %6d",cpu_number_map(i)); 6751da177e4SLinus Torvalds printk(" %5d",i); 6761da177e4SLinus Torvalds printk(" 0x%lx\n",cpu_data[i].hpa); 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds } 6791da177e4SLinus Torvalds #else 6801da177e4SLinus Torvalds printk("\n%s %4d 0 0 --------", 6811da177e4SLinus Torvalds (current->pid)?"RUNNING ": "IDLING ",current->pid); 6821da177e4SLinus Torvalds #endif 6831da177e4SLinus Torvalds } else if ((argc==2) && !(strcmp(argv[1],"-s"))) { 6841da177e4SLinus Torvalds #ifdef DUMP_MORE_STATE 6851da177e4SLinus Torvalds printk("\nCPUSTATE CPUID\n"); 686394e3902SAndrew Morton for_each_online_cpu(i) { 6871da177e4SLinus Torvalds if (cpu_data[i].cpuid != NO_PROC_ID) { 6881da177e4SLinus Torvalds switch(cpu_data[i].state) { 6891da177e4SLinus Torvalds case STATE_RENDEZVOUS: 6901da177e4SLinus Torvalds printk("RENDEZVS");break; 6911da177e4SLinus Torvalds case STATE_RUNNING: 6921da177e4SLinus Torvalds printk((current_pid(i)!=0) ? "RUNNING " : "IDLING"); 6931da177e4SLinus Torvalds break; 6941da177e4SLinus Torvalds case STATE_STOPPED: 6951da177e4SLinus Torvalds printk("STOPPED ");break; 6961da177e4SLinus Torvalds case STATE_HALTED: 6971da177e4SLinus Torvalds printk("HALTED ");break; 6981da177e4SLinus Torvalds default: 6991da177e4SLinus Torvalds } 7001da177e4SLinus Torvalds printk(" %5d\n",i); 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds #else 7041da177e4SLinus Torvalds printk("\n%s CPU0",(current->pid==0)?"RUNNING ":"IDLING "); 7051da177e4SLinus Torvalds #endif 7061da177e4SLinus Torvalds } else { 7071da177e4SLinus Torvalds printk("sys_cpus:Unknown request\n"); 7081da177e4SLinus Torvalds return (-1); 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds return 0; 7111da177e4SLinus Torvalds } 7121da177e4SLinus Torvalds #endif /* ENTRY_SYS_CPUS */ 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 7151da177e4SLinus Torvalds int __init 7161da177e4SLinus Torvalds setup_profiling_timer(unsigned int multiplier) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds return -EINVAL; 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds #endif 721