more changes on original files
[linux-2.4.git] / asm-sparc / smp.h
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/config.h>
10 #include <linux/threads.h>
11 #include <asm/head.h>
12 #include <asm/btfixup.h>
13
14 #ifndef __ASSEMBLY__
15 /* PROM provided per-processor information we need
16  * to start them all up.
17  */
18
19 struct prom_cpuinfo {
20         int prom_node;
21         int mid;
22 };
23 extern int linux_num_cpus;      /* number of CPUs probed  */
24
25 #endif /* !(__ASSEMBLY__) */
26
27 #ifdef CONFIG_SMP
28
29 #ifndef __ASSEMBLY__
30
31 #include <asm/ptrace.h>
32 #include <asm/asi.h>
33
34 extern struct prom_cpuinfo linux_cpus[NR_CPUS];
35
36 /* Per processor Sparc parameters we need. */
37
38 struct cpuinfo_sparc {
39         unsigned long udelay_val; /* that's it */
40         unsigned short next;
41         unsigned short mid;
42 };
43
44 extern struct cpuinfo_sparc cpu_data[NR_CPUS];
45 extern unsigned long cpu_offset[NR_CPUS];
46
47 /*
48  *      Private routines/data
49  */
50  
51 extern int smp_found_cpus;
52 extern unsigned char boot_cpu_id;
53 extern unsigned long cpu_present_map;
54 #define cpu_online_map cpu_present_map
55
56 typedef void (*smpfunc_t)(unsigned long, unsigned long, unsigned long,
57                        unsigned long, unsigned long);
58
59 /*
60  *      General functions that each host system must provide.
61  */
62  
63 void sun4m_init_smp(void);
64 void sun4d_init_smp(void);
65
66 void smp_callin(void);
67 void smp_boot_cpus(void);
68 void smp_store_cpu_info(int);
69
70 struct seq_file;
71 void smp_bogo_info(struct seq_file *);
72 void smp_info(struct seq_file *);
73
74 BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
75 BTFIXUPDEF_CALL(void, smp_message_pass, int, int, unsigned long, int)
76 BTFIXUPDEF_CALL(int, __smp_processor_id, void)
77 BTFIXUPDEF_BLACKBOX(smp_processor_id)
78 BTFIXUPDEF_BLACKBOX(load_current)
79
80 #define smp_cross_call(func,arg1,arg2,arg3,arg4,arg5) BTFIXUP_CALL(smp_cross_call)(func,arg1,arg2,arg3,arg4,arg5)
81 #define smp_message_pass(target,msg,data,wait) BTFIXUP_CALL(smp_message_pass)(target,msg,data,wait)
82
83 extern __inline__ void xc0(smpfunc_t func) { smp_cross_call(func, 0, 0, 0, 0, 0); }
84 extern __inline__ void xc1(smpfunc_t func, unsigned long arg1)
85 { smp_cross_call(func, arg1, 0, 0, 0, 0); }
86 extern __inline__ void xc2(smpfunc_t func, unsigned long arg1, unsigned long arg2)
87 { smp_cross_call(func, arg1, arg2, 0, 0, 0); }
88 extern __inline__ void xc3(smpfunc_t func, unsigned long arg1, unsigned long arg2,
89                            unsigned long arg3)
90 { smp_cross_call(func, arg1, arg2, arg3, 0, 0); }
91 extern __inline__ void xc4(smpfunc_t func, unsigned long arg1, unsigned long arg2,
92                            unsigned long arg3, unsigned long arg4)
93 { smp_cross_call(func, arg1, arg2, arg3, arg4, 0); }
94 extern __inline__ void xc5(smpfunc_t func, unsigned long arg1, unsigned long arg2,
95                            unsigned long arg3, unsigned long arg4, unsigned long arg5)
96 { smp_cross_call(func, arg1, arg2, arg3, arg4, arg5); }
97
98 extern __inline__ int smp_call_function(void (*func)(void *info), void *info, int nonatomic, int wait)
99 {
100         xc1((smpfunc_t)func, (unsigned long)info);
101         return 0;
102 }
103
104 extern __volatile__ int __cpu_number_map[NR_CPUS];
105 extern __volatile__ int __cpu_logical_map[NR_CPUS];
106 extern unsigned long smp_proc_in_lock[NR_CPUS];
107
108 extern __inline__ int cpu_logical_map(int cpu)
109 {
110         return __cpu_logical_map[cpu];
111 }
112 extern __inline__ int cpu_number_map(int cpu)
113 {
114         return __cpu_number_map[cpu];
115 }
116
117 extern __inline__ int hard_smp4m_processor_id(void)
118 {
119         int cpuid;
120
121         __asm__ __volatile__("rd %%tbr, %0\n\t"
122                              "srl %0, 12, %0\n\t"
123                              "and %0, 3, %0\n\t" :
124                              "=&r" (cpuid));
125         return cpuid;
126 }
127
128 extern __inline__ int hard_smp4d_processor_id(void)
129 {
130         int cpuid;
131
132         __asm__ __volatile__("lda [%%g0] %1, %0\n\t" :
133                              "=&r" (cpuid) : "i" (ASI_M_VIKING_TMP1));
134         return cpuid;
135 }
136
137 #ifndef MODULE
138 extern __inline__ int hard_smp_processor_id(void)
139 {
140         int cpuid;
141
142         /* Black box - sun4m
143                 __asm__ __volatile__("rd %%tbr, %0\n\t"
144                                      "srl %0, 12, %0\n\t"
145                                      "and %0, 3, %0\n\t" :
146                                      "=&r" (cpuid));
147                      - sun4d
148                 __asm__ __volatile__("lda [%g0] ASI_M_VIKING_TMP1, %0\n\t"
149                                      "nop; nop" :
150                                      "=&r" (cpuid));
151            See btfixup.h and btfixupprep.c to understand how a blackbox works.
152          */
153         __asm__ __volatile__("sethi %%hi(___b_smp_processor_id), %0\n\t"
154                              "sethi %%hi(boot_cpu_id), %0\n\t"
155                              "ldub [%0 + %%lo(boot_cpu_id)], %0\n\t" :
156                              "=&r" (cpuid));
157         return cpuid;
158 }
159 #else
160 extern __inline__ int hard_smp_processor_id(void)
161 {
162         int cpuid;
163         
164         __asm__ __volatile__("mov %%o7, %%g1\n\t"
165                              "call ___f___smp_processor_id\n\t"
166                              " nop\n\t"
167                              "mov %%g2, %0\n\t" : "=r"(cpuid) : : "g1", "g2");
168         return cpuid;
169 }
170 #endif
171
172 #define smp_processor_id() hard_smp_processor_id()
173 /* XXX We really need to implement this now.  -DaveM */
174 extern __inline__ void smp_send_reschedule(int cpu) { }
175 extern __inline__ void smp_send_stop(void) { }
176
177 #endif /* !(__ASSEMBLY__) */
178
179 /* Sparc specific messages. */
180 #define MSG_CROSS_CALL         0x0005       /* run func on cpus */
181
182 /* Empirical PROM processor mailbox constants.  If the per-cpu mailbox
183  * contains something other than one of these then the ipi is from
184  * Linux's active_kernel_processor.  This facility exists so that
185  * the boot monitor can capture all the other cpus when one catches
186  * a watchdog reset or the user enters the monitor using L1-A keys.
187  */
188 #define MBOX_STOPCPU          0xFB
189 #define MBOX_IDLECPU          0xFC
190 #define MBOX_IDLECPU2         0xFD
191 #define MBOX_STOPCPU2         0xFE
192
193 #define PROC_CHANGE_PENALTY     15
194
195 #endif /* !(CONFIG_SMP) */
196
197 #define NO_PROC_ID            0xFF
198
199 #endif /* !(_SPARC_SMP_H) */