1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mmzone.h> /* for numnodes */
#include <asm/sn/types.h>
#include <asm/sn/sn0/addrs.h>
#include <asm/sn/sn0/hubni.h>
#include <asm/sn/sn0/hubio.h>
#include <asm/sn/klconfig.h>
#include <asm/ioc3.h>
#include <asm/mipsregs.h>
#include <asm/sn/gda.h>
#include <asm/sn/intr.h>
#include <asm/current.h>
#include <asm/smp.h>
#include <asm/processor.h>
#include <asm/sn/launch.h>
#define CPU_NONE (cpuid_t)-1
#define CPUMASK_CLRALL(p) (p) = 0
#define CPUMASK_SETB(p, bit) (p) |= 1 << (bit)
#define CPUMASK_CLRB(p, bit) (p) &= ~(1ULL << (bit))
#define CPUMASK_TSTB(p, bit) ((p) & (1ULL << (bit)))
cpumask_t boot_cpumask;
static volatile cpumask_t boot_barrier;
hubreg_t region_mask = 0;
static int fine_mode = 0;
int maxcpus;
cnodeid_t nasid_to_compact_node[MAX_NASIDS];
nasid_t compact_to_nasid_node[MAX_COMPACT_NODES];
cnodeid_t cpuid_to_compact_node[MAXCPUS];
hubreg_t get_region(cnodeid_t cnode)
{
if (fine_mode)
return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_FINEREG_SHFT;
else
return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_COARSEREG_SHFT;
}
static void gen_region_mask(hubreg_t *region_mask, int maxnodes)
{
cnodeid_t cnode;
(*region_mask) = 0;
for (cnode = 0; cnode < maxnodes; cnode++) {
(*region_mask) |= 1ULL << get_region(cnode);
}
}
int is_fine_dirmode(void)
{
return (((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_REGIONSIZE_MASK)
>> NSRI_REGIONSIZE_SHFT) & REGIONSIZE_FINE);
}
nasid_t get_actual_nasid(lboard_t *brd)
{
klhub_t *hub;
if (!brd)
return INVALID_NASID;
/* find out if we are a completely disabled brd. */
hub = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);
if (!hub)
return INVALID_NASID;
if (!(hub->hub_info.flags & KLINFO_ENABLE)) /* disabled node brd */
return hub->hub_info.physid;
else
return brd->brd_nasid;
}
int do_cpumask(cnodeid_t cnode, nasid_t nasid, cpumask_t *boot_cpumask,
int *highest)
{
lboard_t *brd;
klcpu_t *acpu;
int cpus_found = 0;
cpuid_t cpuid;
brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
do {
acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
while (acpu) {
cpuid = acpu->cpu_info.virtid;
/* cnode is not valid for completely disabled brds */
if (get_actual_nasid(brd) == brd->brd_nasid)
cpuid_to_compact_node[cpuid] = cnode;
if (cpuid > *highest)
*highest = cpuid;
/* Only let it join in if it's marked enabled */
if (acpu->cpu_info.flags & KLINFO_ENABLE) {
CPUMASK_SETB(*boot_cpumask, cpuid);
cpus_found++;
}
acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
KLSTRUCT_CPU);
}
brd = KLCF_NEXT(brd);
if (brd)
brd = find_lboard(brd,KLTYPE_IP27);
else
break;
} while (brd);
return cpus_found;
}
cpuid_t cpu_node_probe(cpumask_t *boot_cpumask, int *numnodes)
{
int i, cpus = 0, highest = 0;
gda_t *gdap = GDA;
nasid_t nasid;
/*
* Initialize the arrays to invalid nodeid (-1)
*/
for (i = 0; i < MAX_COMPACT_NODES; i++)
compact_to_nasid_node[i] = INVALID_NASID;
for (i = 0; i < MAX_NASIDS; i++)
nasid_to_compact_node[i] = INVALID_CNODEID;
for (i = 0; i < MAXCPUS; i++)
cpuid_to_compact_node[i] = INVALID_CNODEID;
*numnodes = 0;
for (i = 0; i < MAX_COMPACT_NODES; i++) {
if ((nasid = gdap->g_nasidtable[i]) == INVALID_NASID) {
break;
} else {
compact_to_nasid_node[i] = nasid;
nasid_to_compact_node[nasid] = i;
(*numnodes)++;
cpus += do_cpumask(i, nasid, boot_cpumask, &highest);
}
}
/*
* Cpus are numbered in order of cnodes. Currently, disabled
* cpus are not numbered.
*/
return(highest + 1);
}
void alloc_cpupda(int i)
{
cnodeid_t node;
nasid_t nasid;
node = get_cpu_cnode(i);
nasid = COMPACT_TO_NASID_NODEID(node);
cputonasid(i) = nasid;
cputocnode(i) = node;
cputoslice(i) = get_cpu_slice(i);
}
int cpu_enabled(cpuid_t cpu)
{
if (cpu == CPU_NONE)
return 0;
return (CPUMASK_TSTB(boot_cpumask, cpu) != 0);
}
void initpdas(void)
{
cpuid_t i;
for (i = 0; i < maxcpus; i++)
if (cpu_enabled(i))
alloc_cpupda(i);
}
void mlreset (void)
{
int i;
fine_mode = is_fine_dirmode();
/*
* Probe for all CPUs - this creates the cpumask and
* sets up the mapping tables.
*/
CPUMASK_CLRALL(boot_cpumask);
maxcpus = cpu_node_probe(&boot_cpumask, &numnodes);
initpdas();
gen_region_mask(®ion_mask, numnodes);
/*
* Set all nodes' calias sizes to 8k
*/
for (i = 0; i < numnodes; i++) {
nasid_t nasid;
nasid = COMPACT_TO_NASID_NODEID(i);
/*
* Always have node 0 in the region mask, otherwise
* CALIAS accesses get exceptions since the hub
* thinks it is a node 0 address.
*/
REMOTE_HUB_S(nasid, PI_REGION_PRESENT, (region_mask | 1));
REMOTE_HUB_S(nasid, PI_CALIAS_SIZE, PI_CALIAS_SIZE_0);
#ifdef LATER
/*
* Set up all hubs to have a big window pointing at
* widget 0. Memory mode, widget 0, offset 0
*/
REMOTE_HUB_S(nasid, IIO_ITTE(SWIN0_BIGWIN),
((HUB_PIO_MAP_TO_MEM << IIO_ITTE_IOSP_SHIFT) |
(0 << IIO_ITTE_WIDGET_SHIFT)));
#endif
}
}
void intr_clear_bits(nasid_t nasid, volatile hubreg_t *pend, int base_level,
char *name)
{
volatile hubreg_t bits;
int i;
/* Check pending interrupts */
if ((bits = HUB_L(pend)) != 0)
for (i = 0; i < N_INTPEND_BITS; i++)
if (bits & (1 << i))
LOCAL_HUB_CLR_INTR(base_level + i);
}
void intr_clear_all(nasid_t nasid)
{
REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
intr_clear_bits(nasid, REMOTE_HUB_ADDR(nasid, PI_INT_PEND0),
INT_PEND0_BASELVL, "INT_PEND0");
intr_clear_bits(nasid, REMOTE_HUB_ADDR(nasid, PI_INT_PEND1),
INT_PEND1_BASELVL, "INT_PEND1");
}
void sn_mp_setup(void)
{
cnodeid_t cnode;
#if 0
cpuid_t cpu;
#endif
for (cnode = 0; cnode < numnodes; cnode++) {
#if 0
init_platform_nodepda();
#endif
intr_clear_all(COMPACT_TO_NASID_NODEID(cnode));
}
#if 0
for (cpu = 0; cpu < maxcpus; cpu++) {
init_platform_pda();
}
#endif
}
void per_cpu_init(void)
{
#if 0
cpuid_t cpu = getcpuid();
cnodeid_t cnode = get_compact_nodeid();
intr_init();
per_hub_init(cnode);
install_cpuintr(cpu);
install_tlbintr(cpu);
#endif
}
void allowboot(void)
{
int num_cpus = 0;
cpuid_t cpu;
cnodeid_t cnode;
sn_mp_setup();
per_cpu_init();
#if 0
bte_lateinit();
ecc_init();
#endif
boot_barrier = boot_cpumask;
/* Launch slaves. */
for (cpu = 0; cpu < maxcpus; cpu++) {
if (cpu == smp_processor_id()) {
num_cpus++;
/* We're already started, clear our bit */
CPUMASK_CLRB(boot_barrier, cpu);
continue;
}
/* Skip holes in CPU space */
if (CPUMASK_TSTB(boot_cpumask, cpu)) {
num_cpus++;
/*
* Launch a slave into bootstrap().
* It doesn't take an argument, and we'll
* take care of sp and gp when we get there.
*/
LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu), 0, 0, 0, 0);
}
}
#ifdef LATER
Wait logic goes here.
#endif
for (cnode = 0; cnode < numnodes; cnode++) {
#if 0
if (cnodetocpu(cnode) == -1) {
printk("Initializing headless hub,cnode %d", cnode);
per_hub_init(cnode);
}
#endif
}
#if 0
cpu_io_setup();
init_mfhi_war();
#endif
}
|