ACPI: buffer array too short in drivers/acpi/system.c
[linux-2.6/sactl.git] / arch / sparc64 / kernel / mdesc.c
blob856659bb13116ed7444c263ec1a9f8087c660ec7
1 /* mdesc.c: Sun4V machine description handling.
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>
9 #include <linux/list.h>
10 #include <linux/slab.h>
11 #include <linux/mm.h>
12 #include <linux/miscdevice.h>
14 #include <asm/hypervisor.h>
15 #include <asm/mdesc.h>
16 #include <asm/prom.h>
17 #include <asm/oplib.h>
18 #include <asm/smp.h>
20 /* Unlike the OBP device tree, the machine description is a full-on
21 * DAG. An arbitrary number of ARCs are possible from one
22 * node to other nodes and thus we can't use the OBP device_node
23 * data structure to represent these nodes inside of the kernel.
25 * Actually, it isn't even a DAG, because there are back pointers
26 * which create cycles in the graph.
28 * mdesc_hdr and mdesc_elem describe the layout of the data structure
29 * we get from the Hypervisor.
31 struct mdesc_hdr {
32 u32 version; /* Transport version */
33 u32 node_sz; /* node block size */
34 u32 name_sz; /* name block size */
35 u32 data_sz; /* data block size */
36 } __attribute__((aligned(16)));
38 struct mdesc_elem {
39 u8 tag;
40 #define MD_LIST_END 0x00
41 #define MD_NODE 0x4e
42 #define MD_NODE_END 0x45
43 #define MD_NOOP 0x20
44 #define MD_PROP_ARC 0x61
45 #define MD_PROP_VAL 0x76
46 #define MD_PROP_STR 0x73
47 #define MD_PROP_DATA 0x64
48 u8 name_len;
49 u16 resv;
50 u32 name_offset;
51 union {
52 struct {
53 u32 data_len;
54 u32 data_offset;
55 } data;
56 u64 val;
57 } d;
60 struct mdesc_mem_ops {
61 struct mdesc_handle *(*alloc)(unsigned int mdesc_size);
62 void (*free)(struct mdesc_handle *handle);
65 struct mdesc_handle {
66 struct list_head list;
67 struct mdesc_mem_ops *mops;
68 void *self_base;
69 atomic_t refcnt;
70 unsigned int handle_size;
71 struct mdesc_hdr mdesc;
74 static void mdesc_handle_init(struct mdesc_handle *hp,
75 unsigned int handle_size,
76 void *base)
78 BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1));
80 memset(hp, 0, handle_size);
81 INIT_LIST_HEAD(&hp->list);
82 hp->self_base = base;
83 atomic_set(&hp->refcnt, 1);
84 hp->handle_size = handle_size;
87 static struct mdesc_handle * __init mdesc_bootmem_alloc(unsigned int mdesc_size)
89 struct mdesc_handle *hp;
90 unsigned int handle_size, alloc_size;
92 handle_size = (sizeof(struct mdesc_handle) -
93 sizeof(struct mdesc_hdr) +
94 mdesc_size);
95 alloc_size = PAGE_ALIGN(handle_size);
97 hp = __alloc_bootmem(alloc_size, PAGE_SIZE, 0UL);
98 if (hp)
99 mdesc_handle_init(hp, handle_size, hp);
101 return hp;
104 static void mdesc_bootmem_free(struct mdesc_handle *hp)
106 unsigned int alloc_size, handle_size = hp->handle_size;
107 unsigned long start, end;
109 BUG_ON(atomic_read(&hp->refcnt) != 0);
110 BUG_ON(!list_empty(&hp->list));
112 alloc_size = PAGE_ALIGN(handle_size);
114 start = (unsigned long) hp;
115 end = start + alloc_size;
117 while (start < end) {
118 struct page *p;
120 p = virt_to_page(start);
121 ClearPageReserved(p);
122 __free_page(p);
123 start += PAGE_SIZE;
127 static struct mdesc_mem_ops bootmem_mdesc_ops = {
128 .alloc = mdesc_bootmem_alloc,
129 .free = mdesc_bootmem_free,
132 static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
134 unsigned int handle_size;
135 void *base;
137 handle_size = (sizeof(struct mdesc_handle) -
138 sizeof(struct mdesc_hdr) +
139 mdesc_size);
141 base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
142 if (base) {
143 struct mdesc_handle *hp;
144 unsigned long addr;
146 addr = (unsigned long)base;
147 addr = (addr + 15UL) & ~15UL;
148 hp = (struct mdesc_handle *) addr;
150 mdesc_handle_init(hp, handle_size, base);
151 return hp;
154 return NULL;
157 static void mdesc_kfree(struct mdesc_handle *hp)
159 BUG_ON(atomic_read(&hp->refcnt) != 0);
160 BUG_ON(!list_empty(&hp->list));
162 kfree(hp->self_base);
165 static struct mdesc_mem_ops kmalloc_mdesc_memops = {
166 .alloc = mdesc_kmalloc,
167 .free = mdesc_kfree,
170 static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size,
171 struct mdesc_mem_ops *mops)
173 struct mdesc_handle *hp = mops->alloc(mdesc_size);
175 if (hp)
176 hp->mops = mops;
178 return hp;
181 static void mdesc_free(struct mdesc_handle *hp)
183 hp->mops->free(hp);
186 static struct mdesc_handle *cur_mdesc;
187 static LIST_HEAD(mdesc_zombie_list);
188 static DEFINE_SPINLOCK(mdesc_lock);
190 struct mdesc_handle *mdesc_grab(void)
192 struct mdesc_handle *hp;
193 unsigned long flags;
195 spin_lock_irqsave(&mdesc_lock, flags);
196 hp = cur_mdesc;
197 if (hp)
198 atomic_inc(&hp->refcnt);
199 spin_unlock_irqrestore(&mdesc_lock, flags);
201 return hp;
203 EXPORT_SYMBOL(mdesc_grab);
205 void mdesc_release(struct mdesc_handle *hp)
207 unsigned long flags;
209 spin_lock_irqsave(&mdesc_lock, flags);
210 if (atomic_dec_and_test(&hp->refcnt)) {
211 list_del_init(&hp->list);
212 hp->mops->free(hp);
214 spin_unlock_irqrestore(&mdesc_lock, flags);
216 EXPORT_SYMBOL(mdesc_release);
218 static DEFINE_MUTEX(mdesc_mutex);
219 static struct mdesc_notifier_client *client_list;
221 void mdesc_register_notifier(struct mdesc_notifier_client *client)
223 u64 node;
225 mutex_lock(&mdesc_mutex);
226 client->next = client_list;
227 client_list = client;
229 mdesc_for_each_node_by_name(cur_mdesc, node, client->node_name)
230 client->add(cur_mdesc, node);
232 mutex_unlock(&mdesc_mutex);
235 static const u64 *parent_cfg_handle(struct mdesc_handle *hp, u64 node)
237 const u64 *id;
238 u64 a;
240 id = NULL;
241 mdesc_for_each_arc(a, hp, node, MDESC_ARC_TYPE_BACK) {
242 u64 target;
244 target = mdesc_arc_target(hp, a);
245 id = mdesc_get_property(hp, target,
246 "cfg-handle", NULL);
247 if (id)
248 break;
251 return id;
254 /* Run 'func' on nodes which are in A but not in B. */
255 static void invoke_on_missing(const char *name,
256 struct mdesc_handle *a,
257 struct mdesc_handle *b,
258 void (*func)(struct mdesc_handle *, u64))
260 u64 node;
262 mdesc_for_each_node_by_name(a, node, name) {
263 int found = 0, is_vdc_port = 0;
264 const char *name_prop;
265 const u64 *id;
266 u64 fnode;
268 name_prop = mdesc_get_property(a, node, "name", NULL);
269 if (name_prop && !strcmp(name_prop, "vdc-port")) {
270 is_vdc_port = 1;
271 id = parent_cfg_handle(a, node);
272 } else
273 id = mdesc_get_property(a, node, "id", NULL);
275 if (!id) {
276 printk(KERN_ERR "MD: Cannot find ID for %s node.\n",
277 (name_prop ? name_prop : name));
278 continue;
281 mdesc_for_each_node_by_name(b, fnode, name) {
282 const u64 *fid;
284 if (is_vdc_port) {
285 name_prop = mdesc_get_property(b, fnode,
286 "name", NULL);
287 if (!name_prop ||
288 strcmp(name_prop, "vdc-port"))
289 continue;
290 fid = parent_cfg_handle(b, fnode);
291 if (!fid) {
292 printk(KERN_ERR "MD: Cannot find ID "
293 "for vdc-port node.\n");
294 continue;
296 } else
297 fid = mdesc_get_property(b, fnode,
298 "id", NULL);
300 if (*id == *fid) {
301 found = 1;
302 break;
305 if (!found)
306 func(a, node);
310 static void notify_one(struct mdesc_notifier_client *p,
311 struct mdesc_handle *old_hp,
312 struct mdesc_handle *new_hp)
314 invoke_on_missing(p->node_name, old_hp, new_hp, p->remove);
315 invoke_on_missing(p->node_name, new_hp, old_hp, p->add);
318 static void mdesc_notify_clients(struct mdesc_handle *old_hp,
319 struct mdesc_handle *new_hp)
321 struct mdesc_notifier_client *p = client_list;
323 while (p) {
324 notify_one(p, old_hp, new_hp);
325 p = p->next;
329 void mdesc_update(void)
331 unsigned long len, real_len, status;
332 struct mdesc_handle *hp, *orig_hp;
333 unsigned long flags;
335 mutex_lock(&mdesc_mutex);
337 (void) sun4v_mach_desc(0UL, 0UL, &len);
339 hp = mdesc_alloc(len, &kmalloc_mdesc_memops);
340 if (!hp) {
341 printk(KERN_ERR "MD: mdesc alloc fails\n");
342 goto out;
345 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
346 if (status != HV_EOK || real_len > len) {
347 printk(KERN_ERR "MD: mdesc reread fails with %lu\n",
348 status);
349 atomic_dec(&hp->refcnt);
350 mdesc_free(hp);
351 goto out;
354 spin_lock_irqsave(&mdesc_lock, flags);
355 orig_hp = cur_mdesc;
356 cur_mdesc = hp;
357 spin_unlock_irqrestore(&mdesc_lock, flags);
359 mdesc_notify_clients(orig_hp, hp);
361 spin_lock_irqsave(&mdesc_lock, flags);
362 if (atomic_dec_and_test(&orig_hp->refcnt))
363 mdesc_free(orig_hp);
364 else
365 list_add(&orig_hp->list, &mdesc_zombie_list);
366 spin_unlock_irqrestore(&mdesc_lock, flags);
368 out:
369 mutex_unlock(&mdesc_mutex);
372 static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
374 return (struct mdesc_elem *) (mdesc + 1);
377 static void *name_block(struct mdesc_hdr *mdesc)
379 return ((void *) node_block(mdesc)) + mdesc->node_sz;
382 static void *data_block(struct mdesc_hdr *mdesc)
384 return ((void *) name_block(mdesc)) + mdesc->name_sz;
387 u64 mdesc_node_by_name(struct mdesc_handle *hp,
388 u64 from_node, const char *name)
390 struct mdesc_elem *ep = node_block(&hp->mdesc);
391 const char *names = name_block(&hp->mdesc);
392 u64 last_node = hp->mdesc.node_sz / 16;
393 u64 ret;
395 if (from_node == MDESC_NODE_NULL) {
396 ret = from_node = 0;
397 } else if (from_node >= last_node) {
398 return MDESC_NODE_NULL;
399 } else {
400 ret = ep[from_node].d.val;
403 while (ret < last_node) {
404 if (ep[ret].tag != MD_NODE)
405 return MDESC_NODE_NULL;
406 if (!strcmp(names + ep[ret].name_offset, name))
407 break;
408 ret = ep[ret].d.val;
410 if (ret >= last_node)
411 ret = MDESC_NODE_NULL;
412 return ret;
414 EXPORT_SYMBOL(mdesc_node_by_name);
416 const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
417 const char *name, int *lenp)
419 const char *names = name_block(&hp->mdesc);
420 u64 last_node = hp->mdesc.node_sz / 16;
421 void *data = data_block(&hp->mdesc);
422 struct mdesc_elem *ep;
424 if (node == MDESC_NODE_NULL || node >= last_node)
425 return NULL;
427 ep = node_block(&hp->mdesc) + node;
428 ep++;
429 for (; ep->tag != MD_NODE_END; ep++) {
430 void *val = NULL;
431 int len = 0;
433 switch (ep->tag) {
434 case MD_PROP_VAL:
435 val = &ep->d.val;
436 len = 8;
437 break;
439 case MD_PROP_STR:
440 case MD_PROP_DATA:
441 val = data + ep->d.data.data_offset;
442 len = ep->d.data.data_len;
443 break;
445 default:
446 break;
448 if (!val)
449 continue;
451 if (!strcmp(names + ep->name_offset, name)) {
452 if (lenp)
453 *lenp = len;
454 return val;
458 return NULL;
460 EXPORT_SYMBOL(mdesc_get_property);
462 u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
464 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
465 const char *names = name_block(&hp->mdesc);
466 u64 last_node = hp->mdesc.node_sz / 16;
468 if (from == MDESC_NODE_NULL || from >= last_node)
469 return MDESC_NODE_NULL;
471 ep = base + from;
473 ep++;
474 for (; ep->tag != MD_NODE_END; ep++) {
475 if (ep->tag != MD_PROP_ARC)
476 continue;
478 if (strcmp(names + ep->name_offset, arc_type))
479 continue;
481 return ep - base;
484 return MDESC_NODE_NULL;
486 EXPORT_SYMBOL(mdesc_next_arc);
488 u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
490 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
492 ep = base + arc;
494 return ep->d.val;
496 EXPORT_SYMBOL(mdesc_arc_target);
498 const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
500 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
501 const char *names = name_block(&hp->mdesc);
502 u64 last_node = hp->mdesc.node_sz / 16;
504 if (node == MDESC_NODE_NULL || node >= last_node)
505 return NULL;
507 ep = base + node;
508 if (ep->tag != MD_NODE)
509 return NULL;
511 return names + ep->name_offset;
513 EXPORT_SYMBOL(mdesc_node_name);
515 static void __init report_platform_properties(void)
517 struct mdesc_handle *hp = mdesc_grab();
518 u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
519 const char *s;
520 const u64 *v;
522 if (pn == MDESC_NODE_NULL) {
523 prom_printf("No platform node in machine-description.\n");
524 prom_halt();
527 s = mdesc_get_property(hp, pn, "banner-name", NULL);
528 printk("PLATFORM: banner-name [%s]\n", s);
529 s = mdesc_get_property(hp, pn, "name", NULL);
530 printk("PLATFORM: name [%s]\n", s);
532 v = mdesc_get_property(hp, pn, "hostid", NULL);
533 if (v)
534 printk("PLATFORM: hostid [%08lx]\n", *v);
535 v = mdesc_get_property(hp, pn, "serial#", NULL);
536 if (v)
537 printk("PLATFORM: serial# [%08lx]\n", *v);
538 v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
539 printk("PLATFORM: stick-frequency [%08lx]\n", *v);
540 v = mdesc_get_property(hp, pn, "mac-address", NULL);
541 if (v)
542 printk("PLATFORM: mac-address [%lx]\n", *v);
543 v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
544 if (v)
545 printk("PLATFORM: watchdog-resolution [%lu ms]\n", *v);
546 v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
547 if (v)
548 printk("PLATFORM: watchdog-max-timeout [%lu ms]\n", *v);
549 v = mdesc_get_property(hp, pn, "max-cpus", NULL);
550 if (v)
551 printk("PLATFORM: max-cpus [%lu]\n", *v);
553 #ifdef CONFIG_SMP
555 int max_cpu, i;
557 if (v) {
558 max_cpu = *v;
559 if (max_cpu > NR_CPUS)
560 max_cpu = NR_CPUS;
561 } else {
562 max_cpu = NR_CPUS;
564 for (i = 0; i < max_cpu; i++)
565 cpu_set(i, cpu_possible_map);
567 #endif
569 mdesc_release(hp);
572 static void __devinit fill_in_one_cache(cpuinfo_sparc *c,
573 struct mdesc_handle *hp,
574 u64 mp)
576 const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
577 const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
578 const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
579 const char *type;
580 int type_len;
582 type = mdesc_get_property(hp, mp, "type", &type_len);
584 switch (*level) {
585 case 1:
586 if (of_find_in_proplist(type, "instn", type_len)) {
587 c->icache_size = *size;
588 c->icache_line_size = *line_size;
589 } else if (of_find_in_proplist(type, "data", type_len)) {
590 c->dcache_size = *size;
591 c->dcache_line_size = *line_size;
593 break;
595 case 2:
596 c->ecache_size = *size;
597 c->ecache_line_size = *line_size;
598 break;
600 default:
601 break;
604 if (*level == 1) {
605 u64 a;
607 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
608 u64 target = mdesc_arc_target(hp, a);
609 const char *name = mdesc_node_name(hp, target);
611 if (!strcmp(name, "cache"))
612 fill_in_one_cache(c, hp, target);
617 static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp,
618 int core_id)
620 u64 a;
622 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
623 u64 t = mdesc_arc_target(hp, a);
624 const char *name;
625 const u64 *id;
627 name = mdesc_node_name(hp, t);
628 if (!strcmp(name, "cpu")) {
629 id = mdesc_get_property(hp, t, "id", NULL);
630 if (*id < NR_CPUS)
631 cpu_data(*id).core_id = core_id;
632 } else {
633 u64 j;
635 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) {
636 u64 n = mdesc_arc_target(hp, j);
637 const char *n_name;
639 n_name = mdesc_node_name(hp, n);
640 if (strcmp(n_name, "cpu"))
641 continue;
643 id = mdesc_get_property(hp, n, "id", NULL);
644 if (*id < NR_CPUS)
645 cpu_data(*id).core_id = core_id;
651 static void __devinit set_core_ids(struct mdesc_handle *hp)
653 int idx;
654 u64 mp;
656 idx = 1;
657 mdesc_for_each_node_by_name(hp, mp, "cache") {
658 const u64 *level;
659 const char *type;
660 int len;
662 level = mdesc_get_property(hp, mp, "level", NULL);
663 if (*level != 1)
664 continue;
666 type = mdesc_get_property(hp, mp, "type", &len);
667 if (!of_find_in_proplist(type, "instn", len))
668 continue;
670 mark_core_ids(hp, mp, idx);
672 idx++;
676 static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp,
677 int proc_id)
679 u64 a;
681 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
682 u64 t = mdesc_arc_target(hp, a);
683 const char *name;
684 const u64 *id;
686 name = mdesc_node_name(hp, t);
687 if (strcmp(name, "cpu"))
688 continue;
690 id = mdesc_get_property(hp, t, "id", NULL);
691 if (*id < NR_CPUS)
692 cpu_data(*id).proc_id = proc_id;
696 static void __devinit __set_proc_ids(struct mdesc_handle *hp,
697 const char *exec_unit_name)
699 int idx;
700 u64 mp;
702 idx = 0;
703 mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
704 const char *type;
705 int len;
707 type = mdesc_get_property(hp, mp, "type", &len);
708 if (!of_find_in_proplist(type, "int", len) &&
709 !of_find_in_proplist(type, "integer", len))
710 continue;
712 mark_proc_ids(hp, mp, idx);
714 idx++;
718 static void __devinit set_proc_ids(struct mdesc_handle *hp)
720 __set_proc_ids(hp, "exec_unit");
721 __set_proc_ids(hp, "exec-unit");
724 static void __devinit get_one_mondo_bits(const u64 *p, unsigned int *mask,
725 unsigned char def)
727 u64 val;
729 if (!p)
730 goto use_default;
731 val = *p;
733 if (!val || val >= 64)
734 goto use_default;
736 *mask = ((1U << val) * 64U) - 1U;
737 return;
739 use_default:
740 *mask = ((1U << def) * 64U) - 1U;
743 static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp,
744 struct trap_per_cpu *tb)
746 const u64 *val;
748 val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
749 get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7);
751 val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
752 get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7);
754 val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
755 get_one_mondo_bits(val, &tb->resum_qmask, 6);
757 val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
758 get_one_mondo_bits(val, &tb->nonresum_qmask, 2);
761 void __devinit mdesc_fill_in_cpu_data(cpumask_t mask)
763 struct mdesc_handle *hp = mdesc_grab();
764 u64 mp;
766 ncpus_probed = 0;
767 mdesc_for_each_node_by_name(hp, mp, "cpu") {
768 const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
769 const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
770 struct trap_per_cpu *tb;
771 cpuinfo_sparc *c;
772 int cpuid;
773 u64 a;
775 ncpus_probed++;
777 cpuid = *id;
779 #ifdef CONFIG_SMP
780 if (cpuid >= NR_CPUS) {
781 printk(KERN_WARNING "Ignoring CPU %d which is "
782 ">= NR_CPUS (%d)\n",
783 cpuid, NR_CPUS);
784 continue;
786 if (!cpu_isset(cpuid, mask))
787 continue;
788 #else
789 /* On uniprocessor we only want the values for the
790 * real physical cpu the kernel booted onto, however
791 * cpu_data() only has one entry at index 0.
793 if (cpuid != real_hard_smp_processor_id())
794 continue;
795 cpuid = 0;
796 #endif
798 c = &cpu_data(cpuid);
799 c->clock_tick = *cfreq;
801 tb = &trap_block[cpuid];
802 get_mondo_data(hp, mp, tb);
804 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
805 u64 j, t = mdesc_arc_target(hp, a);
806 const char *t_name;
808 t_name = mdesc_node_name(hp, t);
809 if (!strcmp(t_name, "cache")) {
810 fill_in_one_cache(c, hp, t);
811 continue;
814 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
815 u64 n = mdesc_arc_target(hp, j);
816 const char *n_name;
818 n_name = mdesc_node_name(hp, n);
819 if (!strcmp(n_name, "cache"))
820 fill_in_one_cache(c, hp, n);
824 #ifdef CONFIG_SMP
825 cpu_set(cpuid, cpu_present_map);
826 #endif
828 c->core_id = 0;
829 c->proc_id = -1;
832 #ifdef CONFIG_SMP
833 sparc64_multi_core = 1;
834 #endif
836 set_core_ids(hp);
837 set_proc_ids(hp);
839 smp_fill_in_sib_core_maps();
841 mdesc_release(hp);
844 static ssize_t mdesc_read(struct file *file, char __user *buf,
845 size_t len, loff_t *offp)
847 struct mdesc_handle *hp = mdesc_grab();
848 int err;
850 if (!hp)
851 return -ENODEV;
853 err = hp->handle_size;
854 if (len < hp->handle_size)
855 err = -EMSGSIZE;
856 else if (copy_to_user(buf, &hp->mdesc, hp->handle_size))
857 err = -EFAULT;
858 mdesc_release(hp);
860 return err;
863 static const struct file_operations mdesc_fops = {
864 .read = mdesc_read,
865 .owner = THIS_MODULE,
868 static struct miscdevice mdesc_misc = {
869 .minor = MISC_DYNAMIC_MINOR,
870 .name = "mdesc",
871 .fops = &mdesc_fops,
874 static int __init mdesc_misc_init(void)
876 return misc_register(&mdesc_misc);
879 __initcall(mdesc_misc_init);
881 void __init sun4v_mdesc_init(void)
883 struct mdesc_handle *hp;
884 unsigned long len, real_len, status;
885 cpumask_t mask;
887 (void) sun4v_mach_desc(0UL, 0UL, &len);
889 printk("MDESC: Size is %lu bytes.\n", len);
891 hp = mdesc_alloc(len, &bootmem_mdesc_ops);
892 if (hp == NULL) {
893 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
894 prom_halt();
897 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
898 if (status != HV_EOK || real_len > len) {
899 prom_printf("sun4v_mach_desc fails, err(%lu), "
900 "len(%lu), real_len(%lu)\n",
901 status, len, real_len);
902 mdesc_free(hp);
903 prom_halt();
906 cur_mdesc = hp;
908 report_platform_properties();
910 cpus_setall(mask);
911 mdesc_fill_in_cpu_data(mask);