1 /* smp.h: Sparc specific SMP stuff.
2  *
3  * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
4  */
5 
6 #ifndef _SPARC_SMP_H
7 #define _SPARC_SMP_H
8 
9 #include <linux/threads.h>
10 #include <asm/head.h>
11 #include <asm/btfixup.h>
12 
13 #ifndef __ASSEMBLY__
14 
15 #include <linux/cpumask.h>
16 
17 #endif /* __ASSEMBLY__ */
18 
19 #ifdef CONFIG_SMP
20 
21 #ifndef __ASSEMBLY__
22 
23 #include <asm/ptrace.h>
24 #include <asm/asi.h>
25 #include <asm/atomic.h>
26 
27 /*
28  *	Private routines/data
29  */
30 
31 extern unsigned char boot_cpu_id;
32 extern volatile unsigned long cpu_callin_map[NR_CPUS];
33 extern cpumask_t smp_commenced_mask;
34 extern struct linux_prom_registers smp_penguin_ctable;
35 
36 typedef void (*smpfunc_t)(unsigned long, unsigned long, unsigned long,
37 		       unsigned long, unsigned long);
38 
39 void cpu_panic(void);
40 extern void smp4m_irq_rotate(int cpu);
41 
42 /*
43  *	General functions that each host system must provide.
44  */
45 
46 void sun4m_init_smp(void);
47 void sun4d_init_smp(void);
48 
49 void smp_callin(void);
50 void smp_boot_cpus(void);
51 void smp_store_cpu_info(int);
52 
53 struct seq_file;
54 void smp_bogo(struct seq_file *);
55 void smp_info(struct seq_file *);
56 
BTFIXUPDEF_CALL(void,smp_cross_call,smpfunc_t,cpumask_t,unsigned long,unsigned long,unsigned long,unsigned long)57 BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, cpumask_t, unsigned long, unsigned long, unsigned long, unsigned long)
58 BTFIXUPDEF_CALL(int, __hard_smp_processor_id, void)
59 BTFIXUPDEF_BLACKBOX(hard_smp_processor_id)
60 BTFIXUPDEF_BLACKBOX(load_current)
61 
62 #define smp_cross_call(func,mask,arg1,arg2,arg3,arg4) BTFIXUP_CALL(smp_cross_call)(func,mask,arg1,arg2,arg3,arg4)
63 
64 static inline void xc0(smpfunc_t func) { smp_cross_call(func, cpu_online_map, 0, 0, 0, 0); }
xc1(smpfunc_t func,unsigned long arg1)65 static inline void xc1(smpfunc_t func, unsigned long arg1)
66 { smp_cross_call(func, cpu_online_map, arg1, 0, 0, 0); }
xc2(smpfunc_t func,unsigned long arg1,unsigned long arg2)67 static inline void xc2(smpfunc_t func, unsigned long arg1, unsigned long arg2)
68 { smp_cross_call(func, cpu_online_map, arg1, arg2, 0, 0); }
xc3(smpfunc_t func,unsigned long arg1,unsigned long arg2,unsigned long arg3)69 static inline void xc3(smpfunc_t func, unsigned long arg1, unsigned long arg2,
70 			   unsigned long arg3)
71 { smp_cross_call(func, cpu_online_map, arg1, arg2, arg3, 0); }
xc4(smpfunc_t func,unsigned long arg1,unsigned long arg2,unsigned long arg3,unsigned long arg4)72 static inline void xc4(smpfunc_t func, unsigned long arg1, unsigned long arg2,
73 			   unsigned long arg3, unsigned long arg4)
74 { smp_cross_call(func, cpu_online_map, arg1, arg2, arg3, arg4); }
75 
smp_call_function(void (* func)(void * info),void * info,int wait)76 static inline int smp_call_function(void (*func)(void *info), void *info, int wait)
77 {
78 	xc1((smpfunc_t)func, (unsigned long)info);
79 	return 0;
80 }
81 
smp_call_function_single(int cpuid,void (* func)(void * info),void * info,int wait)82 static inline int smp_call_function_single(int cpuid, void (*func) (void *info),
83 					   void *info, int wait)
84 {
85 	smp_cross_call((smpfunc_t)func, cpumask_of_cpu(cpuid),
86 		       (unsigned long) info, 0, 0, 0);
87 	return 0;
88 }
89 
cpu_logical_map(int cpu)90 static inline int cpu_logical_map(int cpu)
91 {
92 	return cpu;
93 }
94 
hard_smp4m_processor_id(void)95 static inline int hard_smp4m_processor_id(void)
96 {
97 	int cpuid;
98 
99 	__asm__ __volatile__("rd %%tbr, %0\n\t"
100 			     "srl %0, 12, %0\n\t"
101 			     "and %0, 3, %0\n\t" :
102 			     "=&r" (cpuid));
103 	return cpuid;
104 }
105 
hard_smp4d_processor_id(void)106 static inline int hard_smp4d_processor_id(void)
107 {
108 	int cpuid;
109 
110 	__asm__ __volatile__("lda [%%g0] %1, %0\n\t" :
111 			     "=&r" (cpuid) : "i" (ASI_M_VIKING_TMP1));
112 	return cpuid;
113 }
114 
hard_smpleon_processor_id(void)115 extern inline int hard_smpleon_processor_id(void)
116 {
117 	int cpuid;
118 	__asm__ __volatile__("rd     %%asr17,%0\n\t"
119 			     "srl    %0,28,%0" :
120 			     "=&r" (cpuid) : );
121 	return cpuid;
122 }
123 
124 #ifndef MODULE
hard_smp_processor_id(void)125 static inline int hard_smp_processor_id(void)
126 {
127 	int cpuid;
128 
129 	/* Black box - sun4m
130 		__asm__ __volatile__("rd %%tbr, %0\n\t"
131 				     "srl %0, 12, %0\n\t"
132 				     "and %0, 3, %0\n\t" :
133 				     "=&r" (cpuid));
134 	             - sun4d
135 		__asm__ __volatile__("lda [%g0] ASI_M_VIKING_TMP1, %0\n\t"
136 				     "nop; nop" :
137 				     "=&r" (cpuid));
138 	   See btfixup.h and btfixupprep.c to understand how a blackbox works.
139 	 */
140 	__asm__ __volatile__("sethi %%hi(___b_hard_smp_processor_id), %0\n\t"
141 			     "sethi %%hi(boot_cpu_id), %0\n\t"
142 			     "ldub [%0 + %%lo(boot_cpu_id)], %0\n\t" :
143 			     "=&r" (cpuid));
144 	return cpuid;
145 }
146 #else
hard_smp_processor_id(void)147 static inline int hard_smp_processor_id(void)
148 {
149 	int cpuid;
150 
151 	__asm__ __volatile__("mov %%o7, %%g1\n\t"
152 			     "call ___f___hard_smp_processor_id\n\t"
153 			     " nop\n\t"
154 			     "mov %%g2, %0\n\t" : "=r"(cpuid) : : "g1", "g2");
155 	return cpuid;
156 }
157 #endif
158 
159 #define raw_smp_processor_id()		(current_thread_info()->cpu)
160 
161 #define prof_multiplier(__cpu)		cpu_data(__cpu).multiplier
162 #define prof_counter(__cpu)		cpu_data(__cpu).counter
163 
164 void smp_setup_cpu_possible_map(void);
165 
166 #endif /* !(__ASSEMBLY__) */
167 
168 /* Sparc specific messages. */
169 #define MSG_CROSS_CALL         0x0005       /* run func on cpus */
170 
171 /* Empirical PROM processor mailbox constants.  If the per-cpu mailbox
172  * contains something other than one of these then the ipi is from
173  * Linux's active_kernel_processor.  This facility exists so that
174  * the boot monitor can capture all the other cpus when one catches
175  * a watchdog reset or the user enters the monitor using L1-A keys.
176  */
177 #define MBOX_STOPCPU          0xFB
178 #define MBOX_IDLECPU          0xFC
179 #define MBOX_IDLECPU2         0xFD
180 #define MBOX_STOPCPU2         0xFE
181 
182 #else /* SMP */
183 
184 #define hard_smp_processor_id()		0
185 #define smp_setup_cpu_possible_map() do { } while (0)
186 
187 #endif /* !(SMP) */
188 #endif /* !(_SPARC_SMP_H) */
189