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