| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 1 | /* Sparc SS1000/SC2000 SMP support. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * | 
|  | 3 | * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | 
|  | 4 | * | 
|  | 5 | * Based on sun4m's smp.c, which is: | 
|  | 6 | * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) | 
|  | 7 | */ | 
|  | 8 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/interrupt.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/profile.h> | 
| Adrian Bunk | 6c81c32 | 2008-02-06 01:37:51 -0800 | [diff] [blame] | 11 | #include <linux/delay.h> | 
| Robert Reif | 4245e59 | 2008-10-12 20:52:26 -0700 | [diff] [blame] | 12 | #include <linux/cpu.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/sbi.h> | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 15 | #include <asm/mmu.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/tlbflush.h> | 
|  | 17 | #include <asm/cacheflush.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 19 | #include "kernel.h" | 
| Al Viro | 32231a6 | 2007-07-21 19:18:57 -0700 | [diff] [blame] | 20 | #include "irq.h" | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 21 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #define IRQ_CROSS_CALL		15 | 
|  | 23 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 24 | static volatile int smp_processors_ready; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static int smp_highest_cpu; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 |  | 
| David S. Miller | a638f25 | 2009-01-08 16:47:17 -0800 | [diff] [blame] | 27 | static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { | 
|  | 29 | __asm__ __volatile__("swap [%1], %0\n\t" : | 
|  | 30 | "=&r" (val), "=&r" (ptr) : | 
|  | 31 | "0" (val), "1" (ptr)); | 
|  | 32 | return val; | 
|  | 33 | } | 
|  | 34 |  | 
| Daniel Hellstrom | 55dd23e | 2011-05-02 00:08:54 +0000 | [diff] [blame] | 35 | static void smp4d_ipi_init(void); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static void smp_setup_percpu_timer(void); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  | 
| David S. Miller | 7b1af32 | 2008-09-02 01:17:41 -0700 | [diff] [blame] | 38 | static unsigned char cpu_leds[32]; | 
|  | 39 |  | 
|  | 40 | static inline void show_leds(int cpuid) | 
|  | 41 | { | 
|  | 42 | cpuid &= 0x1e; | 
|  | 43 | __asm__ __volatile__ ("stba %0, [%1] %2" : : | 
|  | 44 | "r" ((cpu_leds[cpuid] << 4) | cpu_leds[cpuid+1]), | 
|  | 45 | "r" (ECSR_BASE(cpuid) | BB_LEDS), | 
|  | 46 | "i" (ASI_M_CTL)); | 
|  | 47 | } | 
|  | 48 |  | 
| Al Viro | 409832f | 2008-11-22 17:33:54 +0000 | [diff] [blame] | 49 | void __cpuinit smp4d_callin(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { | 
|  | 51 | int cpuid = hard_smp4d_processor_id(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | unsigned long flags; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 53 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* Show we are alive */ | 
|  | 55 | cpu_leds[cpuid] = 0x6; | 
|  | 56 | show_leds(cpuid); | 
|  | 57 |  | 
|  | 58 | /* Enable level15 interrupt, disable level14 interrupt for now */ | 
|  | 59 | cc_set_imsk((cc_get_imsk() & ~0x8000) | 0x4000); | 
|  | 60 |  | 
|  | 61 | local_flush_cache_all(); | 
|  | 62 | local_flush_tlb_all(); | 
|  | 63 |  | 
| Manfred Spraul | e545a61 | 2008-09-07 16:57:22 +0200 | [diff] [blame] | 64 | notify_cpu_starting(cpuid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* | 
|  | 66 | * Unblock the master CPU _only_ when the scheduler state | 
|  | 67 | * of all secondary CPUs will be up-to-date, so after | 
|  | 68 | * the SMP initialization the master will be just allowed | 
|  | 69 | * to call the scheduler code. | 
|  | 70 | */ | 
|  | 71 | /* Get our local ticker going. */ | 
|  | 72 | smp_setup_percpu_timer(); | 
|  | 73 |  | 
|  | 74 | calibrate_delay(); | 
|  | 75 | smp_store_cpu_info(cpuid); | 
|  | 76 | local_flush_cache_all(); | 
|  | 77 | local_flush_tlb_all(); | 
|  | 78 |  | 
|  | 79 | /* Allow master to continue. */ | 
| David S. Miller | a638f25 | 2009-01-08 16:47:17 -0800 | [diff] [blame] | 80 | sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | local_flush_cache_all(); | 
|  | 82 | local_flush_tlb_all(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 83 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 84 | while ((unsigned long)current_set[cpuid] < PAGE_OFFSET) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | barrier(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 86 |  | 
|  | 87 | while (current_set[cpuid]->cpu != cpuid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | barrier(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 89 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Fix idle thread fields. */ | 
|  | 91 | __asm__ __volatile__("ld [%0], %%g6\n\t" | 
|  | 92 | : : "r" (¤t_set[cpuid]) | 
|  | 93 | : "memory" /* paranoid */); | 
|  | 94 |  | 
|  | 95 | cpu_leds[cpuid] = 0x9; | 
|  | 96 | show_leds(cpuid); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 97 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* Attach to the address space of init_task. */ | 
|  | 99 | atomic_inc(&init_mm.mm_count); | 
|  | 100 | current->active_mm = &init_mm; | 
|  | 101 |  | 
|  | 102 | local_flush_cache_all(); | 
|  | 103 | local_flush_tlb_all(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 104 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | local_irq_enable();	/* We don't allow PIL 14 yet */ | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 106 |  | 
| KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 107 | while (!cpumask_test_cpu(cpuid, &smp_commenced_mask)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | barrier(); | 
|  | 109 |  | 
|  | 110 | spin_lock_irqsave(&sun4d_imsk_lock, flags); | 
|  | 111 | cc_set_imsk(cc_get_imsk() & ~0x4000); /* Allow PIL 14 as well */ | 
|  | 112 | spin_unlock_irqrestore(&sun4d_imsk_lock, flags); | 
| Rusty Russell | fe73971 | 2009-03-16 14:40:22 +1030 | [diff] [blame] | 113 | set_cpu_online(cpuid, true); | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 114 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } | 
|  | 116 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* | 
|  | 118 | *	Cycle through the processors asking the PROM to start each one. | 
|  | 119 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | void __init smp4d_boot_cpus(void) | 
|  | 121 | { | 
| Daniel Hellstrom | 55dd23e | 2011-05-02 00:08:54 +0000 | [diff] [blame] | 122 | smp4d_ipi_init(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | if (boot_cpu_id) | 
|  | 124 | current_set[0] = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | smp_setup_percpu_timer(); | 
|  | 126 | local_flush_cache_all(); | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 127 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 |  | 
| Al Viro | b4cff84 | 2007-02-01 13:52:33 +0000 | [diff] [blame] | 129 | int __cpuinit smp4d_boot_one_cpu(int i) | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 130 | { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 131 | unsigned long *entry = &sun4d_cpu_startup; | 
|  | 132 | struct task_struct *p; | 
|  | 133 | int timeout; | 
|  | 134 | int cpu_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 136 | cpu_find_by_instance(i, &cpu_node, NULL); | 
|  | 137 | /* Cook up an idler for this guy. */ | 
|  | 138 | p = fork_idle(i); | 
|  | 139 | current_set[i] = task_thread_info(p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 141 | /* | 
|  | 142 | * Initialize the contexts table | 
|  | 143 | * Since the call to prom_startcpu() trashes the structure, | 
|  | 144 | * we need to re-initialize it for each cpu | 
|  | 145 | */ | 
|  | 146 | smp_penguin_ctable.which_io = 0; | 
|  | 147 | smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys; | 
|  | 148 | smp_penguin_ctable.reg_size = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 150 | /* whirrr, whirrr, whirrrrrrrrr... */ | 
|  | 151 | printk(KERN_INFO "Starting CPU %d at %p\n", i, entry); | 
|  | 152 | local_flush_cache_all(); | 
|  | 153 | prom_startcpu(cpu_node, | 
|  | 154 | &smp_penguin_ctable, 0, (char *)entry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 156 | printk(KERN_INFO "prom_startcpu returned :)\n"); | 
|  | 157 |  | 
|  | 158 | /* wheee... it's going... */ | 
|  | 159 | for (timeout = 0; timeout < 10000; timeout++) { | 
|  | 160 | if (cpu_callin_map[i]) | 
|  | 161 | break; | 
|  | 162 | udelay(200); | 
|  | 163 | } | 
|  | 164 |  | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 165 | if (!(cpu_callin_map[i])) { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 166 | printk(KERN_ERR "Processor %d is stuck.\n", i); | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 167 | return -ENODEV; | 
|  | 168 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } | 
|  | 170 | local_flush_cache_all(); | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 171 | return 0; | 
|  | 172 | } | 
|  | 173 |  | 
|  | 174 | void __init smp4d_smp_done(void) | 
|  | 175 | { | 
|  | 176 | int i, first; | 
|  | 177 | int *prev; | 
|  | 178 |  | 
|  | 179 | /* setup cpu list for irq rotation */ | 
|  | 180 | first = 0; | 
|  | 181 | prev = &first; | 
| Rusty Russell | ec7c14b | 2009-03-16 14:40:24 +1030 | [diff] [blame] | 182 | for_each_online_cpu(i) { | 
|  | 183 | *prev = i; | 
|  | 184 | prev = &cpu_data(i).next; | 
|  | 185 | } | 
| Raymond Burns | 8b3c848 | 2006-07-17 21:57:09 -0700 | [diff] [blame] | 186 | *prev = first; | 
|  | 187 | local_flush_cache_all(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* Ok, they are spinning and ready to go. */ | 
|  | 190 | smp_processors_ready = 1; | 
|  | 191 | sun4d_distribute_irqs(); | 
|  | 192 | } | 
|  | 193 |  | 
| Daniel Hellstrom | 55dd23e | 2011-05-02 00:08:54 +0000 | [diff] [blame] | 194 | /* Memory structure giving interrupt handler information about IPI generated */ | 
|  | 195 | struct sun4d_ipi_work { | 
|  | 196 | int single; | 
|  | 197 | int msk; | 
|  | 198 | int resched; | 
|  | 199 | }; | 
|  | 200 |  | 
|  | 201 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct sun4d_ipi_work, sun4d_ipi_work); | 
|  | 202 |  | 
|  | 203 | /* Initialize IPIs on the SUN4D SMP machine */ | 
|  | 204 | static void __init smp4d_ipi_init(void) | 
|  | 205 | { | 
|  | 206 | int cpu; | 
|  | 207 | struct sun4d_ipi_work *work; | 
|  | 208 |  | 
|  | 209 | printk(KERN_INFO "smp4d: setup IPI at IRQ %d\n", SUN4D_IPI_IRQ); | 
|  | 210 |  | 
|  | 211 | for_each_possible_cpu(cpu) { | 
|  | 212 | work = &per_cpu(sun4d_ipi_work, cpu); | 
|  | 213 | work->single = work->msk = work->resched = 0; | 
|  | 214 | } | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | void sun4d_ipi_interrupt(void) | 
|  | 218 | { | 
|  | 219 | struct sun4d_ipi_work *work = &__get_cpu_var(sun4d_ipi_work); | 
|  | 220 |  | 
|  | 221 | if (work->single) { | 
|  | 222 | work->single = 0; | 
|  | 223 | smp_call_function_single_interrupt(); | 
|  | 224 | } | 
|  | 225 | if (work->msk) { | 
|  | 226 | work->msk = 0; | 
|  | 227 | smp_call_function_interrupt(); | 
|  | 228 | } | 
|  | 229 | if (work->resched) { | 
|  | 230 | work->resched = 0; | 
|  | 231 | smp_resched_interrupt(); | 
|  | 232 | } | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | static void smp4d_ipi_single(int cpu) | 
|  | 236 | { | 
|  | 237 | struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu); | 
|  | 238 |  | 
|  | 239 | /* Mark work */ | 
|  | 240 | work->single = 1; | 
|  | 241 |  | 
|  | 242 | /* Generate IRQ on the CPU */ | 
|  | 243 | sun4d_send_ipi(cpu, SUN4D_IPI_IRQ); | 
|  | 244 | } | 
|  | 245 |  | 
|  | 246 | static void smp4d_ipi_mask_one(int cpu) | 
|  | 247 | { | 
|  | 248 | struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu); | 
|  | 249 |  | 
|  | 250 | /* Mark work */ | 
|  | 251 | work->msk = 1; | 
|  | 252 |  | 
|  | 253 | /* Generate IRQ on the CPU */ | 
|  | 254 | sun4d_send_ipi(cpu, SUN4D_IPI_IRQ); | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | static void smp4d_ipi_resched(int cpu) | 
|  | 258 | { | 
|  | 259 | struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu); | 
|  | 260 |  | 
|  | 261 | /* Mark work */ | 
|  | 262 | work->resched = 1; | 
|  | 263 |  | 
|  | 264 | /* Generate IRQ on the CPU (any IRQ will cause resched) */ | 
|  | 265 | sun4d_send_ipi(cpu, SUN4D_IPI_IRQ); | 
|  | 266 | } | 
|  | 267 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | static struct smp_funcall { | 
|  | 269 | smpfunc_t func; | 
|  | 270 | unsigned long arg1; | 
|  | 271 | unsigned long arg2; | 
|  | 272 | unsigned long arg3; | 
|  | 273 | unsigned long arg4; | 
|  | 274 | unsigned long arg5; | 
|  | 275 | unsigned char processors_in[NR_CPUS];  /* Set when ipi entered. */ | 
|  | 276 | unsigned char processors_out[NR_CPUS]; /* Set when ipi exited. */ | 
|  | 277 | } ccall_info __attribute__((aligned(8))); | 
|  | 278 |  | 
|  | 279 | static DEFINE_SPINLOCK(cross_call_lock); | 
|  | 280 |  | 
|  | 281 | /* Cross calls must be serialized, at least currently. */ | 
| David S. Miller | 66e4f8c | 2008-08-27 20:03:22 -0700 | [diff] [blame] | 282 | static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1, | 
|  | 283 | unsigned long arg2, unsigned long arg3, | 
|  | 284 | unsigned long arg4) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 286 | if (smp_processors_ready) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | register int high = smp_highest_cpu; | 
|  | 288 | unsigned long flags; | 
|  | 289 |  | 
|  | 290 | spin_lock_irqsave(&cross_call_lock, flags); | 
|  | 291 |  | 
|  | 292 | { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 293 | /* | 
|  | 294 | * If you make changes here, make sure | 
|  | 295 | * gcc generates proper code... | 
|  | 296 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | register smpfunc_t f asm("i0") = func; | 
|  | 298 | register unsigned long a1 asm("i1") = arg1; | 
|  | 299 | register unsigned long a2 asm("i2") = arg2; | 
|  | 300 | register unsigned long a3 asm("i3") = arg3; | 
|  | 301 | register unsigned long a4 asm("i4") = arg4; | 
| David S. Miller | 66e4f8c | 2008-08-27 20:03:22 -0700 | [diff] [blame] | 302 | register unsigned long a5 asm("i5") = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 |  | 
|  | 304 | __asm__ __volatile__( | 
|  | 305 | "std %0, [%6]\n\t" | 
|  | 306 | "std %2, [%6 + 8]\n\t" | 
|  | 307 | "std %4, [%6 + 16]\n\t" : : | 
|  | 308 | "r"(f), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), | 
|  | 309 | "r" (&ccall_info.func)); | 
|  | 310 | } | 
|  | 311 |  | 
|  | 312 | /* Init receive/complete mapping, plus fire the IPI's off. */ | 
|  | 313 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | register int i; | 
|  | 315 |  | 
| KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 316 | cpumask_clear_cpu(smp_processor_id(), &mask); | 
|  | 317 | cpumask_and(&mask, cpu_online_mask, &mask); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 318 | for (i = 0; i <= high; i++) { | 
| KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 319 | if (cpumask_test_cpu(i, &mask)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | ccall_info.processors_in[i] = 0; | 
|  | 321 | ccall_info.processors_out[i] = 0; | 
|  | 322 | sun4d_send_ipi(i, IRQ_CROSS_CALL); | 
|  | 323 | } | 
|  | 324 | } | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | { | 
|  | 328 | register int i; | 
|  | 329 |  | 
|  | 330 | i = 0; | 
|  | 331 | do { | 
| KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 332 | if (!cpumask_test_cpu(i, &mask)) | 
| David S. Miller | 66e4f8c | 2008-08-27 20:03:22 -0700 | [diff] [blame] | 333 | continue; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 334 | while (!ccall_info.processors_in[i]) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | barrier(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 336 | } while (++i <= high); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 |  | 
|  | 338 | i = 0; | 
|  | 339 | do { | 
| KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 340 | if (!cpumask_test_cpu(i, &mask)) | 
| David S. Miller | 66e4f8c | 2008-08-27 20:03:22 -0700 | [diff] [blame] | 341 | continue; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 342 | while (!ccall_info.processors_out[i]) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | barrier(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 344 | } while (++i <= high); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } | 
|  | 346 |  | 
|  | 347 | spin_unlock_irqrestore(&cross_call_lock, flags); | 
|  | 348 | } | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | /* Running cross calls. */ | 
|  | 352 | void smp4d_cross_call_irq(void) | 
|  | 353 | { | 
|  | 354 | int i = hard_smp4d_processor_id(); | 
|  | 355 |  | 
|  | 356 | ccall_info.processors_in[i] = 1; | 
|  | 357 | ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3, | 
|  | 358 | ccall_info.arg4, ccall_info.arg5); | 
|  | 359 | ccall_info.processors_out[i] = 1; | 
|  | 360 | } | 
|  | 361 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | void smp4d_percpu_timer_interrupt(struct pt_regs *regs) | 
|  | 363 | { | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 364 | struct pt_regs *old_regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | int cpu = hard_smp4d_processor_id(); | 
|  | 366 | static int cpu_tick[NR_CPUS]; | 
|  | 367 | static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd }; | 
|  | 368 |  | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 369 | old_regs = set_irq_regs(regs); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 370 | bw_get_prof_limit(cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | bw_clear_intr_mask(0, 1);	/* INTR_TABLE[0] & 1 is Profile IRQ */ | 
|  | 372 |  | 
|  | 373 | cpu_tick[cpu]++; | 
|  | 374 | if (!(cpu_tick[cpu] & 15)) { | 
|  | 375 | if (cpu_tick[cpu] == 0x60) | 
|  | 376 | cpu_tick[cpu] = 0; | 
|  | 377 | cpu_leds[cpu] = led_mask[cpu_tick[cpu] >> 4]; | 
|  | 378 | show_leds(cpu); | 
|  | 379 | } | 
|  | 380 |  | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 381 | profile_tick(CPU_PROFILING); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 383 | if (!--prof_counter(cpu)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | int user = user_mode(regs); | 
|  | 385 |  | 
|  | 386 | irq_enter(); | 
|  | 387 | update_process_times(user); | 
|  | 388 | irq_exit(); | 
|  | 389 |  | 
|  | 390 | prof_counter(cpu) = prof_multiplier(cpu); | 
|  | 391 | } | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 392 | set_irq_regs(old_regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } | 
|  | 394 |  | 
| Al Viro | 409832f | 2008-11-22 17:33:54 +0000 | [diff] [blame] | 395 | static void __cpuinit smp_setup_percpu_timer(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { | 
|  | 397 | int cpu = hard_smp4d_processor_id(); | 
|  | 398 |  | 
|  | 399 | prof_counter(cpu) = prof_multiplier(cpu) = 1; | 
|  | 400 | load_profile_irq(cpu, lvl14_resolution); | 
|  | 401 | } | 
|  | 402 |  | 
|  | 403 | void __init smp4d_blackbox_id(unsigned *addr) | 
|  | 404 | { | 
|  | 405 | int rd = *addr & 0x3e000000; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 406 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | addr[0] = 0xc0800800 | rd;		/* lda [%g0] ASI_M_VIKING_TMP1, reg */ | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 408 | addr[1] = 0x01000000;			/* nop */ | 
|  | 409 | addr[2] = 0x01000000;			/* nop */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } | 
|  | 411 |  | 
|  | 412 | void __init smp4d_blackbox_current(unsigned *addr) | 
|  | 413 | { | 
|  | 414 | int rd = *addr & 0x3e000000; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 415 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | addr[0] = 0xc0800800 | rd;		/* lda [%g0] ASI_M_VIKING_TMP1, reg */ | 
|  | 417 | addr[2] = 0x81282002 | rd | (rd >> 11);	/* sll reg, 2, reg */ | 
|  | 418 | addr[4] = 0x01000000;			/* nop */ | 
|  | 419 | } | 
|  | 420 |  | 
|  | 421 | void __init sun4d_init_smp(void) | 
|  | 422 | { | 
|  | 423 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 |  | 
|  | 425 | /* Patch ipi15 trap table */ | 
|  | 426 | t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 427 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* And set btfixup... */ | 
|  | 429 | BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id); | 
|  | 430 | BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current); | 
|  | 431 | BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM); | 
| Daniel Hellstrom | 55dd23e | 2011-05-02 00:08:54 +0000 | [diff] [blame] | 433 | BTFIXUPSET_CALL(smp_ipi_resched, smp4d_ipi_resched, BTFIXUPCALL_NORM); | 
|  | 434 | BTFIXUPSET_CALL(smp_ipi_single, smp4d_ipi_single, BTFIXUPCALL_NORM); | 
|  | 435 | BTFIXUPSET_CALL(smp_ipi_mask_one, smp4d_ipi_mask_one, BTFIXUPCALL_NORM); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 436 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | for (i = 0; i < NR_CPUS; i++) { | 
|  | 438 | ccall_info.processors_in[i] = 1; | 
|  | 439 | ccall_info.processors_out[i] = 1; | 
|  | 440 | } | 
|  | 441 | } |