[SPARC64]: SMP build fix.
[deliverable/linux.git] / arch / sparc64 / kernel / mdesc.c
CommitLineData
5cbc3073
DM
1/* mdesc.c: Sun4V machine description handling.
2 *
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
4 */
5#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/bootmem.h>
8#include <linux/log2.h>
43fdf274
DM
9#include <linux/list.h>
10#include <linux/slab.h>
8f3fff20 11#include <linux/mm.h>
5cbc3073
DM
12
13#include <asm/hypervisor.h>
14#include <asm/mdesc.h>
15#include <asm/prom.h>
16#include <asm/oplib.h>
17#include <asm/smp.h>
18
19/* Unlike the OBP device tree, the machine description is a full-on
20 * DAG. An arbitrary number of ARCs are possible from one
21 * node to other nodes and thus we can't use the OBP device_node
22 * data structure to represent these nodes inside of the kernel.
23 *
24 * Actually, it isn't even a DAG, because there are back pointers
25 * which create cycles in the graph.
26 *
27 * mdesc_hdr and mdesc_elem describe the layout of the data structure
28 * we get from the Hypervisor.
29 */
30struct mdesc_hdr {
31 u32 version; /* Transport version */
32 u32 node_sz; /* node block size */
33 u32 name_sz; /* name block size */
34 u32 data_sz; /* data block size */
43fdf274 35} __attribute__((aligned(16)));
5cbc3073
DM
36
37struct mdesc_elem {
38 u8 tag;
39#define MD_LIST_END 0x00
40#define MD_NODE 0x4e
41#define MD_NODE_END 0x45
42#define MD_NOOP 0x20
43#define MD_PROP_ARC 0x61
44#define MD_PROP_VAL 0x76
45#define MD_PROP_STR 0x73
46#define MD_PROP_DATA 0x64
47 u8 name_len;
48 u16 resv;
49 u32 name_offset;
50 union {
51 struct {
52 u32 data_len;
53 u32 data_offset;
54 } data;
55 u64 val;
56 } d;
57};
58
43fdf274
DM
59struct mdesc_mem_ops {
60 struct mdesc_handle *(*alloc)(unsigned int mdesc_size);
61 void (*free)(struct mdesc_handle *handle);
62};
5cbc3073 63
43fdf274
DM
64struct mdesc_handle {
65 struct list_head list;
66 struct mdesc_mem_ops *mops;
67 void *self_base;
68 atomic_t refcnt;
69 unsigned int handle_size;
70 struct mdesc_hdr mdesc;
71};
5cbc3073 72
43fdf274
DM
73static void mdesc_handle_init(struct mdesc_handle *hp,
74 unsigned int handle_size,
75 void *base)
5cbc3073 76{
43fdf274
DM
77 BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1));
78
79 memset(hp, 0, handle_size);
80 INIT_LIST_HEAD(&hp->list);
81 hp->self_base = base;
82 atomic_set(&hp->refcnt, 1);
83 hp->handle_size = handle_size;
5cbc3073
DM
84}
85
43fdf274 86static struct mdesc_handle *mdesc_bootmem_alloc(unsigned int mdesc_size)
5cbc3073 87{
43fdf274
DM
88 struct mdesc_handle *hp;
89 unsigned int handle_size, alloc_size;
5cbc3073 90
43fdf274
DM
91 handle_size = (sizeof(struct mdesc_handle) -
92 sizeof(struct mdesc_hdr) +
93 mdesc_size);
94 alloc_size = PAGE_ALIGN(handle_size);
5cbc3073 95
43fdf274
DM
96 hp = __alloc_bootmem(alloc_size, PAGE_SIZE, 0UL);
97 if (hp)
98 mdesc_handle_init(hp, handle_size, hp);
99
100 return hp;
5cbc3073
DM
101}
102
43fdf274 103static void mdesc_bootmem_free(struct mdesc_handle *hp)
5cbc3073 104{
43fdf274
DM
105 unsigned int alloc_size, handle_size = hp->handle_size;
106 unsigned long start, end;
5cbc3073 107
43fdf274
DM
108 BUG_ON(atomic_read(&hp->refcnt) != 0);
109 BUG_ON(!list_empty(&hp->list));
5cbc3073 110
43fdf274
DM
111 alloc_size = PAGE_ALIGN(handle_size);
112
113 start = (unsigned long) hp;
114 end = start + alloc_size;
115
116 while (start < end) {
117 struct page *p;
118
119 p = virt_to_page(start);
120 ClearPageReserved(p);
121 __free_page(p);
122 start += PAGE_SIZE;
5cbc3073 123 }
5cbc3073
DM
124}
125
43fdf274
DM
126static struct mdesc_mem_ops bootmem_mdesc_memops = {
127 .alloc = mdesc_bootmem_alloc,
128 .free = mdesc_bootmem_free,
129};
130
131static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
5cbc3073 132{
43fdf274
DM
133 unsigned int handle_size;
134 void *base;
5cbc3073 135
43fdf274
DM
136 handle_size = (sizeof(struct mdesc_handle) -
137 sizeof(struct mdesc_hdr) +
138 mdesc_size);
139
140 base = kmalloc(handle_size + 15, GFP_KERNEL);
141 if (base) {
142 struct mdesc_handle *hp;
143 unsigned long addr;
144
145 addr = (unsigned long)base;
146 addr = (addr + 15UL) & ~15UL;
147 hp = (struct mdesc_handle *) addr;
148
149 mdesc_handle_init(hp, handle_size, base);
150 return hp;
5cbc3073 151 }
43fdf274
DM
152
153 return NULL;
5cbc3073 154}
5cbc3073 155
43fdf274 156static void mdesc_kfree(struct mdesc_handle *hp)
5cbc3073 157{
43fdf274
DM
158 BUG_ON(atomic_read(&hp->refcnt) != 0);
159 BUG_ON(!list_empty(&hp->list));
160
161 kfree(hp->self_base);
5cbc3073 162}
5cbc3073 163
43fdf274
DM
164static struct mdesc_mem_ops kmalloc_mdesc_memops = {
165 .alloc = mdesc_kmalloc,
166 .free = mdesc_kfree,
167};
168
169static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size,
170 struct mdesc_mem_ops *mops)
5cbc3073 171{
43fdf274 172 struct mdesc_handle *hp = mops->alloc(mdesc_size);
5cbc3073 173
43fdf274
DM
174 if (hp)
175 hp->mops = mops;
5cbc3073 176
43fdf274
DM
177 return hp;
178}
5cbc3073 179
43fdf274 180static void mdesc_free(struct mdesc_handle *hp)
5cbc3073 181{
43fdf274
DM
182 hp->mops->free(hp);
183}
5cbc3073 184
43fdf274
DM
185static struct mdesc_handle *cur_mdesc;
186static LIST_HEAD(mdesc_zombie_list);
187static DEFINE_SPINLOCK(mdesc_lock);
5cbc3073 188
43fdf274
DM
189struct mdesc_handle *mdesc_grab(void)
190{
191 struct mdesc_handle *hp;
192 unsigned long flags;
5cbc3073 193
43fdf274
DM
194 spin_lock_irqsave(&mdesc_lock, flags);
195 hp = cur_mdesc;
196 if (hp)
197 atomic_inc(&hp->refcnt);
198 spin_unlock_irqrestore(&mdesc_lock, flags);
5cbc3073 199
43fdf274 200 return hp;
5cbc3073 201}
43fdf274 202EXPORT_SYMBOL(mdesc_grab);
5cbc3073 203
43fdf274 204void mdesc_release(struct mdesc_handle *hp)
5cbc3073 205{
43fdf274 206 unsigned long flags;
5cbc3073 207
43fdf274
DM
208 spin_lock_irqsave(&mdesc_lock, flags);
209 if (atomic_dec_and_test(&hp->refcnt)) {
210 list_del_init(&hp->list);
211 hp->mops->free(hp);
5cbc3073 212 }
43fdf274 213 spin_unlock_irqrestore(&mdesc_lock, flags);
5cbc3073 214}
43fdf274 215EXPORT_SYMBOL(mdesc_release);
5cbc3073 216
43fdf274 217static void do_mdesc_update(struct work_struct *work)
5cbc3073 218{
43fdf274
DM
219 unsigned long len, real_len, status;
220 struct mdesc_handle *hp, *orig_hp;
221 unsigned long flags;
222
223 (void) sun4v_mach_desc(0UL, 0UL, &len);
224
225 hp = mdesc_alloc(len, &kmalloc_mdesc_memops);
226 if (!hp) {
227 printk(KERN_ERR "MD: mdesc alloc fails\n");
228 return;
229 }
230
231 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
232 if (status != HV_EOK || real_len > len) {
233 printk(KERN_ERR "MD: mdesc reread fails with %lu\n",
234 status);
235 atomic_dec(&hp->refcnt);
236 mdesc_free(hp);
237 return;
238 }
5cbc3073 239
43fdf274
DM
240 spin_lock_irqsave(&mdesc_lock, flags);
241 orig_hp = cur_mdesc;
242 cur_mdesc = hp;
5cbc3073 243
43fdf274
DM
244 if (atomic_dec_and_test(&orig_hp->refcnt))
245 mdesc_free(orig_hp);
246 else
247 list_add(&orig_hp->list, &mdesc_zombie_list);
248 spin_unlock_irqrestore(&mdesc_lock, flags);
5cbc3073
DM
249}
250
43fdf274
DM
251static DECLARE_WORK(mdesc_update_work, do_mdesc_update);
252
253void mdesc_update(void)
254{
255 schedule_work(&mdesc_update_work);
256}
257
258static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
5cbc3073
DM
259{
260 return (struct mdesc_elem *) (mdesc + 1);
261}
262
43fdf274 263static void *name_block(struct mdesc_hdr *mdesc)
5cbc3073
DM
264{
265 return ((void *) node_block(mdesc)) + mdesc->node_sz;
266}
267
43fdf274 268static void *data_block(struct mdesc_hdr *mdesc)
5cbc3073
DM
269{
270 return ((void *) name_block(mdesc)) + mdesc->name_sz;
271}
272
43fdf274
DM
273u64 mdesc_node_by_name(struct mdesc_handle *hp,
274 u64 from_node, const char *name)
5cbc3073 275{
43fdf274
DM
276 struct mdesc_elem *ep = node_block(&hp->mdesc);
277 const char *names = name_block(&hp->mdesc);
278 u64 last_node = hp->mdesc.node_sz / 16;
279 u64 ret;
280
281 if (from_node == MDESC_NODE_NULL)
282 from_node = 0;
283
284 if (from_node >= last_node)
285 return MDESC_NODE_NULL;
286
287 ret = ep[from_node].d.val;
288 while (ret < last_node) {
289 if (ep[ret].tag != MD_NODE)
290 return MDESC_NODE_NULL;
291 if (!strcmp(names + ep[ret].name_offset, name))
292 break;
293 ret = ep[ret].d.val;
294 }
295 if (ret >= last_node)
296 ret = MDESC_NODE_NULL;
297 return ret;
298}
299EXPORT_SYMBOL(mdesc_node_by_name);
5cbc3073 300
43fdf274
DM
301const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
302 const char *name, int *lenp)
303{
304 const char *names = name_block(&hp->mdesc);
305 u64 last_node = hp->mdesc.node_sz / 16;
306 void *data = data_block(&hp->mdesc);
307 struct mdesc_elem *ep;
5cbc3073 308
43fdf274
DM
309 if (node == MDESC_NODE_NULL || node >= last_node)
310 return NULL;
5cbc3073 311
43fdf274
DM
312 ep = node_block(&hp->mdesc) + node;
313 ep++;
314 for (; ep->tag != MD_NODE_END; ep++) {
315 void *val = NULL;
316 int len = 0;
317
318 switch (ep->tag) {
319 case MD_PROP_VAL:
320 val = &ep->d.val;
321 len = 8;
5cbc3073
DM
322 break;
323
43fdf274
DM
324 case MD_PROP_STR:
325 case MD_PROP_DATA:
326 val = data + ep->d.data.data_offset;
327 len = ep->d.data.data_len;
328 break;
5cbc3073 329
43fdf274 330 default:
5cbc3073
DM
331 break;
332 }
43fdf274
DM
333 if (!val)
334 continue;
5cbc3073 335
43fdf274
DM
336 if (!strcmp(names + ep->name_offset, name)) {
337 if (lenp)
338 *lenp = len;
339 return val;
340 }
5cbc3073
DM
341 }
342
43fdf274
DM
343 return NULL;
344}
345EXPORT_SYMBOL(mdesc_get_property);
5cbc3073 346
43fdf274
DM
347u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
348{
349 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
350 const char *names = name_block(&hp->mdesc);
351 u64 last_node = hp->mdesc.node_sz / 16;
5cbc3073 352
43fdf274
DM
353 if (from == MDESC_NODE_NULL || from >= last_node)
354 return MDESC_NODE_NULL;
5cbc3073 355
43fdf274
DM
356 ep = base + from;
357
358 ep++;
359 for (; ep->tag != MD_NODE_END; ep++) {
360 if (ep->tag != MD_PROP_ARC)
361 continue;
362
363 if (strcmp(names + ep->name_offset, arc_type))
364 continue;
365
366 return ep - base;
5cbc3073 367 }
43fdf274
DM
368
369 return MDESC_NODE_NULL;
5cbc3073 370}
43fdf274 371EXPORT_SYMBOL(mdesc_next_arc);
5cbc3073 372
43fdf274 373u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
5cbc3073 374{
43fdf274
DM
375 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
376
377 ep = base + arc;
378
379 return ep->d.val;
5cbc3073 380}
43fdf274
DM
381EXPORT_SYMBOL(mdesc_arc_target);
382
383const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
384{
385 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
386 const char *names = name_block(&hp->mdesc);
387 u64 last_node = hp->mdesc.node_sz / 16;
388
389 if (node == MDESC_NODE_NULL || node >= last_node)
390 return NULL;
391
392 ep = base + node;
393 if (ep->tag != MD_NODE)
394 return NULL;
395
396 return names + ep->name_offset;
397}
398EXPORT_SYMBOL(mdesc_node_name);
5cbc3073
DM
399
400static void __init report_platform_properties(void)
401{
43fdf274
DM
402 struct mdesc_handle *hp = mdesc_grab();
403 u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
5cbc3073
DM
404 const char *s;
405 const u64 *v;
406
43fdf274 407 if (pn == MDESC_NODE_NULL) {
5cbc3073
DM
408 prom_printf("No platform node in machine-description.\n");
409 prom_halt();
410 }
411
43fdf274 412 s = mdesc_get_property(hp, pn, "banner-name", NULL);
5cbc3073 413 printk("PLATFORM: banner-name [%s]\n", s);
43fdf274 414 s = mdesc_get_property(hp, pn, "name", NULL);
5cbc3073
DM
415 printk("PLATFORM: name [%s]\n", s);
416
43fdf274 417 v = mdesc_get_property(hp, pn, "hostid", NULL);
5cbc3073
DM
418 if (v)
419 printk("PLATFORM: hostid [%08lx]\n", *v);
43fdf274 420 v = mdesc_get_property(hp, pn, "serial#", NULL);
5cbc3073
DM
421 if (v)
422 printk("PLATFORM: serial# [%08lx]\n", *v);
43fdf274 423 v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
5cbc3073 424 printk("PLATFORM: stick-frequency [%08lx]\n", *v);
43fdf274 425 v = mdesc_get_property(hp, pn, "mac-address", NULL);
5cbc3073
DM
426 if (v)
427 printk("PLATFORM: mac-address [%lx]\n", *v);
43fdf274 428 v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
5cbc3073
DM
429 if (v)
430 printk("PLATFORM: watchdog-resolution [%lu ms]\n", *v);
43fdf274 431 v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
5cbc3073
DM
432 if (v)
433 printk("PLATFORM: watchdog-max-timeout [%lu ms]\n", *v);
43fdf274 434 v = mdesc_get_property(hp, pn, "max-cpus", NULL);
5cbc3073
DM
435 if (v)
436 printk("PLATFORM: max-cpus [%lu]\n", *v);
43fdf274 437
4f0234f4
DM
438#ifdef CONFIG_SMP
439 {
440 int max_cpu, i;
441
442 if (v) {
443 max_cpu = *v;
444 if (max_cpu > NR_CPUS)
445 max_cpu = NR_CPUS;
446 } else {
447 max_cpu = NR_CPUS;
448 }
449 for (i = 0; i < max_cpu; i++)
450 cpu_set(i, cpu_possible_map);
451 }
452#endif
453
43fdf274 454 mdesc_release(hp);
5cbc3073
DM
455}
456
457static int inline find_in_proplist(const char *list, const char *match, int len)
458{
459 while (len > 0) {
460 int l;
461
462 if (!strcmp(list, match))
463 return 1;
464 l = strlen(list) + 1;
465 list += l;
466 len -= l;
467 }
468 return 0;
469}
470
4f0234f4
DM
471static void __devinit fill_in_one_cache(cpuinfo_sparc *c,
472 struct mdesc_handle *hp,
473 u64 mp)
5cbc3073 474{
43fdf274
DM
475 const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
476 const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
477 const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
5cbc3073
DM
478 const char *type;
479 int type_len;
480
43fdf274 481 type = mdesc_get_property(hp, mp, "type", &type_len);
5cbc3073
DM
482
483 switch (*level) {
484 case 1:
485 if (find_in_proplist(type, "instn", type_len)) {
486 c->icache_size = *size;
487 c->icache_line_size = *line_size;
488 } else if (find_in_proplist(type, "data", type_len)) {
489 c->dcache_size = *size;
490 c->dcache_line_size = *line_size;
491 }
492 break;
493
494 case 2:
495 c->ecache_size = *size;
496 c->ecache_line_size = *line_size;
497 break;
498
499 default:
500 break;
501 }
502
503 if (*level == 1) {
43fdf274 504 u64 a;
5cbc3073 505
43fdf274
DM
506 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
507 u64 target = mdesc_arc_target(hp, a);
508 const char *name = mdesc_node_name(hp, target);
5cbc3073 509
43fdf274
DM
510 if (!strcmp(name, "cache"))
511 fill_in_one_cache(c, hp, target);
5cbc3073
DM
512 }
513 }
514}
515
4f0234f4
DM
516static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp,
517 int core_id)
5cbc3073 518{
43fdf274 519 u64 a;
5cbc3073 520
43fdf274
DM
521 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
522 u64 t = mdesc_arc_target(hp, a);
523 const char *name;
5cbc3073
DM
524 const u64 *id;
525
43fdf274
DM
526 name = mdesc_node_name(hp, t);
527 if (!strcmp(name, "cpu")) {
528 id = mdesc_get_property(hp, t, "id", NULL);
5cbc3073
DM
529 if (*id < NR_CPUS)
530 cpu_data(*id).core_id = core_id;
531 } else {
43fdf274 532 u64 j;
5cbc3073 533
43fdf274
DM
534 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) {
535 u64 n = mdesc_arc_target(hp, j);
536 const char *n_name;
5cbc3073 537
43fdf274
DM
538 n_name = mdesc_node_name(hp, n);
539 if (strcmp(n_name, "cpu"))
5cbc3073
DM
540 continue;
541
43fdf274 542 id = mdesc_get_property(hp, n, "id", NULL);
5cbc3073
DM
543 if (*id < NR_CPUS)
544 cpu_data(*id).core_id = core_id;
545 }
546 }
547 }
548}
549
4f0234f4 550static void __devinit set_core_ids(struct mdesc_handle *hp)
5cbc3073 551{
5cbc3073 552 int idx;
43fdf274 553 u64 mp;
5cbc3073
DM
554
555 idx = 1;
43fdf274
DM
556 mdesc_for_each_node_by_name(hp, mp, "cache") {
557 const u64 *level;
5cbc3073
DM
558 const char *type;
559 int len;
560
43fdf274 561 level = mdesc_get_property(hp, mp, "level", NULL);
5cbc3073
DM
562 if (*level != 1)
563 continue;
564
43fdf274 565 type = mdesc_get_property(hp, mp, "type", &len);
5cbc3073
DM
566 if (!find_in_proplist(type, "instn", len))
567 continue;
568
43fdf274 569 mark_core_ids(hp, mp, idx);
5cbc3073
DM
570
571 idx++;
572 }
573}
574
4f0234f4
DM
575static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp,
576 int proc_id)
f78eae2e 577{
43fdf274 578 u64 a;
f78eae2e 579
43fdf274
DM
580 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
581 u64 t = mdesc_arc_target(hp, a);
582 const char *name;
f78eae2e
DM
583 const u64 *id;
584
43fdf274
DM
585 name = mdesc_node_name(hp, t);
586 if (strcmp(name, "cpu"))
f78eae2e
DM
587 continue;
588
43fdf274 589 id = mdesc_get_property(hp, t, "id", NULL);
f78eae2e
DM
590 if (*id < NR_CPUS)
591 cpu_data(*id).proc_id = proc_id;
592 }
593}
594
4f0234f4
DM
595static void __devinit __set_proc_ids(struct mdesc_handle *hp,
596 const char *exec_unit_name)
f78eae2e 597{
f78eae2e 598 int idx;
43fdf274 599 u64 mp;
f78eae2e
DM
600
601 idx = 0;
43fdf274 602 mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
f78eae2e
DM
603 const char *type;
604 int len;
605
43fdf274 606 type = mdesc_get_property(hp, mp, "type", &len);
f78eae2e
DM
607 if (!find_in_proplist(type, "int", len) &&
608 !find_in_proplist(type, "integer", len))
609 continue;
610
43fdf274 611 mark_proc_ids(hp, mp, idx);
f78eae2e
DM
612
613 idx++;
614 }
615}
616
4f0234f4 617static void __devinit set_proc_ids(struct mdesc_handle *hp)
f78eae2e 618{
43fdf274
DM
619 __set_proc_ids(hp, "exec_unit");
620 __set_proc_ids(hp, "exec-unit");
f78eae2e
DM
621}
622
4f0234f4
DM
623static void __devinit get_one_mondo_bits(const u64 *p, unsigned int *mask,
624 unsigned char def)
5cbc3073
DM
625{
626 u64 val;
627
628 if (!p)
629 goto use_default;
630 val = *p;
631
632 if (!val || val >= 64)
633 goto use_default;
634
635 *mask = ((1U << val) * 64U) - 1U;
636 return;
637
638use_default:
639 *mask = ((1U << def) * 64U) - 1U;
640}
641
4f0234f4
DM
642static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp,
643 struct trap_per_cpu *tb)
5cbc3073
DM
644{
645 const u64 *val;
646
43fdf274 647 val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
5cbc3073
DM
648 get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7);
649
43fdf274 650 val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
5cbc3073
DM
651 get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7);
652
43fdf274 653 val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
5cbc3073
DM
654 get_one_mondo_bits(val, &tb->resum_qmask, 6);
655
43fdf274 656 val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
5cbc3073
DM
657 get_one_mondo_bits(val, &tb->nonresum_qmask, 2);
658}
659
4f0234f4 660void __devinit mdesc_fill_in_cpu_data(cpumask_t mask)
5cbc3073 661{
43fdf274
DM
662 struct mdesc_handle *hp = mdesc_grab();
663 u64 mp;
5cbc3073
DM
664
665 ncpus_probed = 0;
43fdf274
DM
666 mdesc_for_each_node_by_name(hp, mp, "cpu") {
667 const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
668 const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
5cbc3073
DM
669 struct trap_per_cpu *tb;
670 cpuinfo_sparc *c;
5cbc3073 671 int cpuid;
43fdf274 672 u64 a;
5cbc3073
DM
673
674 ncpus_probed++;
675
676 cpuid = *id;
677
678#ifdef CONFIG_SMP
679 if (cpuid >= NR_CPUS)
680 continue;
4f0234f4
DM
681 if (!cpu_isset(cpuid, mask))
682 continue;
5cbc3073
DM
683#else
684 /* On uniprocessor we only want the values for the
685 * real physical cpu the kernel booted onto, however
686 * cpu_data() only has one entry at index 0.
687 */
688 if (cpuid != real_hard_smp_processor_id())
689 continue;
690 cpuid = 0;
691#endif
692
693 c = &cpu_data(cpuid);
694 c->clock_tick = *cfreq;
695
696 tb = &trap_block[cpuid];
43fdf274 697 get_mondo_data(hp, mp, tb);
5cbc3073 698
43fdf274
DM
699 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
700 u64 j, t = mdesc_arc_target(hp, a);
701 const char *t_name;
5cbc3073 702
43fdf274
DM
703 t_name = mdesc_node_name(hp, t);
704 if (!strcmp(t_name, "cache")) {
705 fill_in_one_cache(c, hp, t);
5cbc3073
DM
706 continue;
707 }
708
43fdf274
DM
709 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
710 u64 n = mdesc_arc_target(hp, j);
711 const char *n_name;
5cbc3073 712
43fdf274
DM
713 n_name = mdesc_node_name(hp, n);
714 if (!strcmp(n_name, "cache"))
715 fill_in_one_cache(c, hp, n);
5cbc3073
DM
716 }
717 }
718
719#ifdef CONFIG_SMP
720 cpu_set(cpuid, cpu_present_map);
5cbc3073
DM
721#endif
722
723 c->core_id = 0;
f78eae2e 724 c->proc_id = -1;
5cbc3073
DM
725 }
726
a2f9f6bb
DM
727#ifdef CONFIG_SMP
728 sparc64_multi_core = 1;
729#endif
730
43fdf274
DM
731 set_core_ids(hp);
732 set_proc_ids(hp);
5cbc3073
DM
733
734 smp_fill_in_sib_core_maps();
43fdf274
DM
735
736 mdesc_release(hp);
5cbc3073
DM
737}
738
739void __init sun4v_mdesc_init(void)
740{
43fdf274 741 struct mdesc_handle *hp;
5cbc3073 742 unsigned long len, real_len, status;
4f0234f4 743 cpumask_t mask;
5cbc3073
DM
744
745 (void) sun4v_mach_desc(0UL, 0UL, &len);
746
747 printk("MDESC: Size is %lu bytes.\n", len);
748
43fdf274
DM
749 hp = mdesc_alloc(len, &bootmem_mdesc_memops);
750 if (hp == NULL) {
751 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
752 prom_halt();
753 }
5cbc3073 754
43fdf274 755 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
5cbc3073
DM
756 if (status != HV_EOK || real_len > len) {
757 prom_printf("sun4v_mach_desc fails, err(%lu), "
758 "len(%lu), real_len(%lu)\n",
759 status, len, real_len);
43fdf274 760 mdesc_free(hp);
5cbc3073
DM
761 prom_halt();
762 }
763
43fdf274 764 cur_mdesc = hp;
5cbc3073
DM
765
766 report_platform_properties();
4f0234f4
DM
767
768 cpus_setall(mask);
769 mdesc_fill_in_cpu_data(mask);
5cbc3073 770}
This page took 0.073109 seconds and 5 git commands to generate.