blob: ea6d4d6c02f6eff55ada1a005cde0a99e66b6264 [file] [log] [blame]
David S. Miller5cbc3072007-05-25 15:49:59 -07001/* mdesc.c: Sun4V machine description handling.
2 *
David S. Miller4a283332008-02-13 19:22:23 -08003 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
David S. Miller5cbc3072007-05-25 15:49:59 -07004 */
5#include <linux/kernel.h>
6#include <linux/types.h>
Yinghai Lu95f72d12010-07-12 14:36:09 +10007#include <linux/memblock.h>
David S. Miller5cbc3072007-05-25 15:49:59 -07008#include <linux/log2.h>
David S. Miller43fdf272007-07-12 13:47:50 -07009#include <linux/list.h>
10#include <linux/slab.h>
David S. Miller8f3fff22007-07-14 00:54:55 -070011#include <linux/mm.h>
David S. Miller0fdb7f92007-08-15 21:02:23 -070012#include <linux/miscdevice.h>
David S. Milleradfe67d2009-12-11 01:16:46 -080013#include <linux/bootmem.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070014
Sam Ravnborg6e6ab2e2008-12-26 15:33:07 -080015#include <asm/cpudata.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070016#include <asm/hypervisor.h>
17#include <asm/mdesc.h>
18#include <asm/prom.h>
Paul Gortmakercd66bc42011-09-19 21:15:28 -040019#include <asm/uaccess.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070020#include <asm/oplib.h>
21#include <asm/smp.h>
22
23/* Unlike the OBP device tree, the machine description is a full-on
24 * DAG. An arbitrary number of ARCs are possible from one
25 * node to other nodes and thus we can't use the OBP device_node
26 * data structure to represent these nodes inside of the kernel.
27 *
28 * Actually, it isn't even a DAG, because there are back pointers
29 * which create cycles in the graph.
30 *
31 * mdesc_hdr and mdesc_elem describe the layout of the data structure
32 * we get from the Hypervisor.
33 */
34struct mdesc_hdr {
35 u32 version; /* Transport version */
36 u32 node_sz; /* node block size */
37 u32 name_sz; /* name block size */
38 u32 data_sz; /* data block size */
David S. Miller43fdf272007-07-12 13:47:50 -070039} __attribute__((aligned(16)));
David S. Miller5cbc3072007-05-25 15:49:59 -070040
41struct mdesc_elem {
42 u8 tag;
43#define MD_LIST_END 0x00
44#define MD_NODE 0x4e
45#define MD_NODE_END 0x45
46#define MD_NOOP 0x20
47#define MD_PROP_ARC 0x61
48#define MD_PROP_VAL 0x76
49#define MD_PROP_STR 0x73
50#define MD_PROP_DATA 0x64
51 u8 name_len;
52 u16 resv;
53 u32 name_offset;
54 union {
55 struct {
56 u32 data_len;
57 u32 data_offset;
58 } data;
59 u64 val;
60 } d;
61};
62
David S. Miller43fdf272007-07-12 13:47:50 -070063struct mdesc_mem_ops {
64 struct mdesc_handle *(*alloc)(unsigned int mdesc_size);
65 void (*free)(struct mdesc_handle *handle);
66};
David S. Miller5cbc3072007-05-25 15:49:59 -070067
David S. Miller43fdf272007-07-12 13:47:50 -070068struct mdesc_handle {
69 struct list_head list;
70 struct mdesc_mem_ops *mops;
71 void *self_base;
72 atomic_t refcnt;
73 unsigned int handle_size;
74 struct mdesc_hdr mdesc;
75};
David S. Miller5cbc3072007-05-25 15:49:59 -070076
David S. Miller43fdf272007-07-12 13:47:50 -070077static void mdesc_handle_init(struct mdesc_handle *hp,
78 unsigned int handle_size,
79 void *base)
David S. Miller5cbc3072007-05-25 15:49:59 -070080{
David S. Miller43fdf272007-07-12 13:47:50 -070081 BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1));
82
83 memset(hp, 0, handle_size);
84 INIT_LIST_HEAD(&hp->list);
85 hp->self_base = base;
86 atomic_set(&hp->refcnt, 1);
87 hp->handle_size = handle_size;
David S. Miller5cbc3072007-05-25 15:49:59 -070088}
89
Yinghai Lu95f72d12010-07-12 14:36:09 +100090static struct mdesc_handle * __init mdesc_memblock_alloc(unsigned int mdesc_size)
David S. Miller5cbc3072007-05-25 15:49:59 -070091{
David S. Miller43fdf272007-07-12 13:47:50 -070092 unsigned int handle_size, alloc_size;
David S. Miller4a283332008-02-13 19:22:23 -080093 struct mdesc_handle *hp;
94 unsigned long paddr;
David S. Miller5cbc3072007-05-25 15:49:59 -070095
David S. Miller43fdf272007-07-12 13:47:50 -070096 handle_size = (sizeof(struct mdesc_handle) -
97 sizeof(struct mdesc_hdr) +
98 mdesc_size);
99 alloc_size = PAGE_ALIGN(handle_size);
David S. Miller5cbc3072007-05-25 15:49:59 -0700100
Yinghai Lu95f72d12010-07-12 14:36:09 +1000101 paddr = memblock_alloc(alloc_size, PAGE_SIZE);
David S. Miller43fdf272007-07-12 13:47:50 -0700102
David S. Miller4a283332008-02-13 19:22:23 -0800103 hp = NULL;
104 if (paddr) {
105 hp = __va(paddr);
106 mdesc_handle_init(hp, handle_size, hp);
107 }
David S. Miller43fdf272007-07-12 13:47:50 -0700108 return hp;
109}
110
David S. Miller3628aa02011-03-30 17:37:56 -0700111static void __init mdesc_memblock_free(struct mdesc_handle *hp)
David S. Miller43fdf272007-07-12 13:47:50 -0700112{
David S. Milleradfe67d2009-12-11 01:16:46 -0800113 unsigned int alloc_size;
114 unsigned long start;
David S. Miller43fdf272007-07-12 13:47:50 -0700115
116 BUG_ON(atomic_read(&hp->refcnt) != 0);
117 BUG_ON(!list_empty(&hp->list));
118
David S. Milleradfe67d2009-12-11 01:16:46 -0800119 alloc_size = PAGE_ALIGN(hp->handle_size);
120 start = __pa(hp);
121 free_bootmem_late(start, alloc_size);
David S. Miller5cbc3072007-05-25 15:49:59 -0700122}
123
Yinghai Lu95f72d12010-07-12 14:36:09 +1000124static struct mdesc_mem_ops memblock_mdesc_ops = {
125 .alloc = mdesc_memblock_alloc,
126 .free = mdesc_memblock_free,
David S. Miller43fdf272007-07-12 13:47:50 -0700127};
128
129static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
David S. Miller5cbc3072007-05-25 15:49:59 -0700130{
David S. Miller43fdf272007-07-12 13:47:50 -0700131 unsigned int handle_size;
132 void *base;
David S. Miller5cbc3072007-05-25 15:49:59 -0700133
David S. Miller43fdf272007-07-12 13:47:50 -0700134 handle_size = (sizeof(struct mdesc_handle) -
135 sizeof(struct mdesc_hdr) +
136 mdesc_size);
David S. Miller5cbc3072007-05-25 15:49:59 -0700137
David S. Miller920c3ed2007-07-17 21:37:35 -0700138 base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
David S. Miller43fdf272007-07-12 13:47:50 -0700139 if (base) {
140 struct mdesc_handle *hp;
141 unsigned long addr;
142
143 addr = (unsigned long)base;
144 addr = (addr + 15UL) & ~15UL;
145 hp = (struct mdesc_handle *) addr;
146
147 mdesc_handle_init(hp, handle_size, base);
148 return hp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700149 }
David S. Miller43fdf272007-07-12 13:47:50 -0700150
David S. Miller5cbc3072007-05-25 15:49:59 -0700151 return NULL;
152}
153
David S. Miller43fdf272007-07-12 13:47:50 -0700154static void mdesc_kfree(struct mdesc_handle *hp)
David S. Miller5cbc3072007-05-25 15:49:59 -0700155{
David S. Miller43fdf272007-07-12 13:47:50 -0700156 BUG_ON(atomic_read(&hp->refcnt) != 0);
157 BUG_ON(!list_empty(&hp->list));
David S. Miller5cbc3072007-05-25 15:49:59 -0700158
David S. Miller43fdf272007-07-12 13:47:50 -0700159 kfree(hp->self_base);
160}
161
162static struct mdesc_mem_ops kmalloc_mdesc_memops = {
163 .alloc = mdesc_kmalloc,
164 .free = mdesc_kfree,
165};
166
167static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size,
168 struct mdesc_mem_ops *mops)
169{
170 struct mdesc_handle *hp = mops->alloc(mdesc_size);
171
172 if (hp)
173 hp->mops = mops;
174
175 return hp;
176}
177
178static void mdesc_free(struct mdesc_handle *hp)
179{
180 hp->mops->free(hp);
181}
182
183static struct mdesc_handle *cur_mdesc;
184static LIST_HEAD(mdesc_zombie_list);
185static DEFINE_SPINLOCK(mdesc_lock);
186
187struct mdesc_handle *mdesc_grab(void)
188{
189 struct mdesc_handle *hp;
190 unsigned long flags;
191
192 spin_lock_irqsave(&mdesc_lock, flags);
193 hp = cur_mdesc;
194 if (hp)
195 atomic_inc(&hp->refcnt);
196 spin_unlock_irqrestore(&mdesc_lock, flags);
197
198 return hp;
199}
200EXPORT_SYMBOL(mdesc_grab);
201
202void mdesc_release(struct mdesc_handle *hp)
203{
204 unsigned long flags;
205
206 spin_lock_irqsave(&mdesc_lock, flags);
207 if (atomic_dec_and_test(&hp->refcnt)) {
208 list_del_init(&hp->list);
209 hp->mops->free(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700210 }
David S. Miller43fdf272007-07-12 13:47:50 -0700211 spin_unlock_irqrestore(&mdesc_lock, flags);
David S. Miller5cbc3072007-05-25 15:49:59 -0700212}
David S. Miller43fdf272007-07-12 13:47:50 -0700213EXPORT_SYMBOL(mdesc_release);
David S. Miller5cbc3072007-05-25 15:49:59 -0700214
David S. Miller920c3ed2007-07-17 21:37:35 -0700215static DEFINE_MUTEX(mdesc_mutex);
216static struct mdesc_notifier_client *client_list;
217
218void mdesc_register_notifier(struct mdesc_notifier_client *client)
219{
220 u64 node;
221
222 mutex_lock(&mdesc_mutex);
223 client->next = client_list;
224 client_list = client;
225
226 mdesc_for_each_node_by_name(cur_mdesc, node, client->node_name)
227 client->add(cur_mdesc, node);
228
229 mutex_unlock(&mdesc_mutex);
230}
231
David S. Miller91ba3c22007-07-18 15:15:45 -0700232static const u64 *parent_cfg_handle(struct mdesc_handle *hp, u64 node)
233{
234 const u64 *id;
235 u64 a;
236
237 id = NULL;
238 mdesc_for_each_arc(a, hp, node, MDESC_ARC_TYPE_BACK) {
239 u64 target;
240
241 target = mdesc_arc_target(hp, a);
242 id = mdesc_get_property(hp, target,
243 "cfg-handle", NULL);
244 if (id)
245 break;
246 }
247
248 return id;
249}
250
David S. Miller920c3ed2007-07-17 21:37:35 -0700251/* Run 'func' on nodes which are in A but not in B. */
252static void invoke_on_missing(const char *name,
253 struct mdesc_handle *a,
254 struct mdesc_handle *b,
255 void (*func)(struct mdesc_handle *, u64))
256{
257 u64 node;
258
259 mdesc_for_each_node_by_name(a, node, name) {
David S. Miller91ba3c22007-07-18 15:15:45 -0700260 int found = 0, is_vdc_port = 0;
261 const char *name_prop;
262 const u64 *id;
David S. Miller920c3ed2007-07-17 21:37:35 -0700263 u64 fnode;
264
David S. Miller91ba3c22007-07-18 15:15:45 -0700265 name_prop = mdesc_get_property(a, node, "name", NULL);
266 if (name_prop && !strcmp(name_prop, "vdc-port")) {
267 is_vdc_port = 1;
268 id = parent_cfg_handle(a, node);
269 } else
270 id = mdesc_get_property(a, node, "id", NULL);
271
272 if (!id) {
273 printk(KERN_ERR "MD: Cannot find ID for %s node.\n",
274 (name_prop ? name_prop : name));
275 continue;
276 }
277
David S. Miller920c3ed2007-07-17 21:37:35 -0700278 mdesc_for_each_node_by_name(b, fnode, name) {
David S. Miller91ba3c22007-07-18 15:15:45 -0700279 const u64 *fid;
280
281 if (is_vdc_port) {
282 name_prop = mdesc_get_property(b, fnode,
283 "name", NULL);
284 if (!name_prop ||
285 strcmp(name_prop, "vdc-port"))
286 continue;
287 fid = parent_cfg_handle(b, fnode);
288 if (!fid) {
289 printk(KERN_ERR "MD: Cannot find ID "
290 "for vdc-port node.\n");
291 continue;
292 }
293 } else
294 fid = mdesc_get_property(b, fnode,
295 "id", NULL);
David S. Miller920c3ed2007-07-17 21:37:35 -0700296
297 if (*id == *fid) {
298 found = 1;
299 break;
300 }
301 }
302 if (!found)
303 func(a, node);
304 }
305}
306
307static void notify_one(struct mdesc_notifier_client *p,
308 struct mdesc_handle *old_hp,
309 struct mdesc_handle *new_hp)
310{
311 invoke_on_missing(p->node_name, old_hp, new_hp, p->remove);
312 invoke_on_missing(p->node_name, new_hp, old_hp, p->add);
313}
314
315static void mdesc_notify_clients(struct mdesc_handle *old_hp,
316 struct mdesc_handle *new_hp)
317{
318 struct mdesc_notifier_client *p = client_list;
319
320 while (p) {
321 notify_one(p, old_hp, new_hp);
322 p = p->next;
323 }
324}
325
David S. Miller778feeb2007-07-16 16:50:36 -0700326void mdesc_update(void)
David S. Miller5cbc3072007-05-25 15:49:59 -0700327{
David S. Miller43fdf272007-07-12 13:47:50 -0700328 unsigned long len, real_len, status;
329 struct mdesc_handle *hp, *orig_hp;
330 unsigned long flags;
David S. Miller5cbc3072007-05-25 15:49:59 -0700331
David S. Miller920c3ed2007-07-17 21:37:35 -0700332 mutex_lock(&mdesc_mutex);
333
David S. Miller43fdf272007-07-12 13:47:50 -0700334 (void) sun4v_mach_desc(0UL, 0UL, &len);
David S. Miller5cbc3072007-05-25 15:49:59 -0700335
David S. Miller43fdf272007-07-12 13:47:50 -0700336 hp = mdesc_alloc(len, &kmalloc_mdesc_memops);
337 if (!hp) {
338 printk(KERN_ERR "MD: mdesc alloc fails\n");
David S. Miller920c3ed2007-07-17 21:37:35 -0700339 goto out;
David S. Miller5cbc3072007-05-25 15:49:59 -0700340 }
341
David S. Miller43fdf272007-07-12 13:47:50 -0700342 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
343 if (status != HV_EOK || real_len > len) {
344 printk(KERN_ERR "MD: mdesc reread fails with %lu\n",
345 status);
346 atomic_dec(&hp->refcnt);
347 mdesc_free(hp);
David S. Miller920c3ed2007-07-17 21:37:35 -0700348 goto out;
David S. Miller5cbc3072007-05-25 15:49:59 -0700349 }
David S. Miller43fdf272007-07-12 13:47:50 -0700350
351 spin_lock_irqsave(&mdesc_lock, flags);
352 orig_hp = cur_mdesc;
353 cur_mdesc = hp;
David S. Miller920c3ed2007-07-17 21:37:35 -0700354 spin_unlock_irqrestore(&mdesc_lock, flags);
David S. Miller43fdf272007-07-12 13:47:50 -0700355
David S. Miller920c3ed2007-07-17 21:37:35 -0700356 mdesc_notify_clients(orig_hp, hp);
357
358 spin_lock_irqsave(&mdesc_lock, flags);
David S. Miller43fdf272007-07-12 13:47:50 -0700359 if (atomic_dec_and_test(&orig_hp->refcnt))
360 mdesc_free(orig_hp);
361 else
362 list_add(&orig_hp->list, &mdesc_zombie_list);
363 spin_unlock_irqrestore(&mdesc_lock, flags);
David S. Miller920c3ed2007-07-17 21:37:35 -0700364
365out:
366 mutex_unlock(&mdesc_mutex);
David S. Miller5cbc3072007-05-25 15:49:59 -0700367}
368
David S. Miller43fdf272007-07-12 13:47:50 -0700369static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
David S. Miller5cbc3072007-05-25 15:49:59 -0700370{
371 return (struct mdesc_elem *) (mdesc + 1);
372}
373
David S. Miller43fdf272007-07-12 13:47:50 -0700374static void *name_block(struct mdesc_hdr *mdesc)
David S. Miller5cbc3072007-05-25 15:49:59 -0700375{
376 return ((void *) node_block(mdesc)) + mdesc->node_sz;
377}
378
David S. Miller43fdf272007-07-12 13:47:50 -0700379static void *data_block(struct mdesc_hdr *mdesc)
David S. Miller5cbc3072007-05-25 15:49:59 -0700380{
381 return ((void *) name_block(mdesc)) + mdesc->name_sz;
382}
383
David S. Miller43fdf272007-07-12 13:47:50 -0700384u64 mdesc_node_by_name(struct mdesc_handle *hp,
385 u64 from_node, const char *name)
David S. Miller5cbc3072007-05-25 15:49:59 -0700386{
David S. Miller43fdf272007-07-12 13:47:50 -0700387 struct mdesc_elem *ep = node_block(&hp->mdesc);
388 const char *names = name_block(&hp->mdesc);
389 u64 last_node = hp->mdesc.node_sz / 16;
390 u64 ret;
David S. Miller5cbc3072007-05-25 15:49:59 -0700391
David S. Miller778feeb2007-07-16 16:50:36 -0700392 if (from_node == MDESC_NODE_NULL) {
393 ret = from_node = 0;
394 } else if (from_node >= last_node) {
David S. Miller43fdf272007-07-12 13:47:50 -0700395 return MDESC_NODE_NULL;
David S. Miller778feeb2007-07-16 16:50:36 -0700396 } else {
397 ret = ep[from_node].d.val;
398 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700399
David S. Miller43fdf272007-07-12 13:47:50 -0700400 while (ret < last_node) {
401 if (ep[ret].tag != MD_NODE)
402 return MDESC_NODE_NULL;
403 if (!strcmp(names + ep[ret].name_offset, name))
404 break;
405 ret = ep[ret].d.val;
406 }
407 if (ret >= last_node)
408 ret = MDESC_NODE_NULL;
409 return ret;
410}
411EXPORT_SYMBOL(mdesc_node_by_name);
David S. Miller5cbc3072007-05-25 15:49:59 -0700412
David S. Miller43fdf272007-07-12 13:47:50 -0700413const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
414 const char *name, int *lenp)
415{
416 const char *names = name_block(&hp->mdesc);
417 u64 last_node = hp->mdesc.node_sz / 16;
418 void *data = data_block(&hp->mdesc);
419 struct mdesc_elem *ep;
420
421 if (node == MDESC_NODE_NULL || node >= last_node)
422 return NULL;
423
424 ep = node_block(&hp->mdesc) + node;
425 ep++;
426 for (; ep->tag != MD_NODE_END; ep++) {
427 void *val = NULL;
428 int len = 0;
429
430 switch (ep->tag) {
431 case MD_PROP_VAL:
432 val = &ep->d.val;
433 len = 8;
David S. Miller5cbc3072007-05-25 15:49:59 -0700434 break;
435
David S. Miller43fdf272007-07-12 13:47:50 -0700436 case MD_PROP_STR:
437 case MD_PROP_DATA:
438 val = data + ep->d.data.data_offset;
439 len = ep->d.data.data_len;
440 break;
David S. Miller5cbc3072007-05-25 15:49:59 -0700441
David S. Miller43fdf272007-07-12 13:47:50 -0700442 default:
David S. Miller5cbc3072007-05-25 15:49:59 -0700443 break;
444 }
David S. Miller43fdf272007-07-12 13:47:50 -0700445 if (!val)
446 continue;
David S. Miller5cbc3072007-05-25 15:49:59 -0700447
David S. Miller43fdf272007-07-12 13:47:50 -0700448 if (!strcmp(names + ep->name_offset, name)) {
449 if (lenp)
450 *lenp = len;
451 return val;
David S. Miller5cbc3072007-05-25 15:49:59 -0700452 }
453 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700454
David S. Miller43fdf272007-07-12 13:47:50 -0700455 return NULL;
456}
457EXPORT_SYMBOL(mdesc_get_property);
458
459u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
David S. Miller5cbc3072007-05-25 15:49:59 -0700460{
David S. Miller43fdf272007-07-12 13:47:50 -0700461 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
462 const char *names = name_block(&hp->mdesc);
463 u64 last_node = hp->mdesc.node_sz / 16;
David S. Miller5cbc3072007-05-25 15:49:59 -0700464
David S. Miller43fdf272007-07-12 13:47:50 -0700465 if (from == MDESC_NODE_NULL || from >= last_node)
466 return MDESC_NODE_NULL;
467
468 ep = base + from;
469
470 ep++;
471 for (; ep->tag != MD_NODE_END; ep++) {
472 if (ep->tag != MD_PROP_ARC)
473 continue;
474
475 if (strcmp(names + ep->name_offset, arc_type))
476 continue;
477
478 return ep - base;
David S. Miller5cbc3072007-05-25 15:49:59 -0700479 }
David S. Miller43fdf272007-07-12 13:47:50 -0700480
481 return MDESC_NODE_NULL;
David S. Miller5cbc3072007-05-25 15:49:59 -0700482}
David S. Miller43fdf272007-07-12 13:47:50 -0700483EXPORT_SYMBOL(mdesc_next_arc);
484
485u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
486{
487 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
488
489 ep = base + arc;
490
491 return ep->d.val;
492}
493EXPORT_SYMBOL(mdesc_arc_target);
494
495const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
496{
497 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
498 const char *names = name_block(&hp->mdesc);
499 u64 last_node = hp->mdesc.node_sz / 16;
500
501 if (node == MDESC_NODE_NULL || node >= last_node)
502 return NULL;
503
504 ep = base + node;
505 if (ep->tag != MD_NODE)
506 return NULL;
507
508 return names + ep->name_offset;
509}
510EXPORT_SYMBOL(mdesc_node_name);
David S. Miller5cbc3072007-05-25 15:49:59 -0700511
David S. Miller961f65f2011-08-05 02:38:27 -0700512static u64 max_cpus = 64;
513
David S. Miller5cbc3072007-05-25 15:49:59 -0700514static void __init report_platform_properties(void)
515{
David S. Miller43fdf272007-07-12 13:47:50 -0700516 struct mdesc_handle *hp = mdesc_grab();
517 u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
David S. Miller5cbc3072007-05-25 15:49:59 -0700518 const char *s;
519 const u64 *v;
520
David S. Miller43fdf272007-07-12 13:47:50 -0700521 if (pn == MDESC_NODE_NULL) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700522 prom_printf("No platform node in machine-description.\n");
523 prom_halt();
524 }
525
David S. Miller43fdf272007-07-12 13:47:50 -0700526 s = mdesc_get_property(hp, pn, "banner-name", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700527 printk("PLATFORM: banner-name [%s]\n", s);
David S. Miller43fdf272007-07-12 13:47:50 -0700528 s = mdesc_get_property(hp, pn, "name", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700529 printk("PLATFORM: name [%s]\n", s);
530
David S. Miller43fdf272007-07-12 13:47:50 -0700531 v = mdesc_get_property(hp, pn, "hostid", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700532 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800533 printk("PLATFORM: hostid [%08llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700534 v = mdesc_get_property(hp, pn, "serial#", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700535 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800536 printk("PLATFORM: serial# [%08llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700537 v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
Sam Ravnborg90181132009-01-06 13:19:28 -0800538 printk("PLATFORM: stick-frequency [%08llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700539 v = mdesc_get_property(hp, pn, "mac-address", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700540 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800541 printk("PLATFORM: mac-address [%llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700542 v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700543 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800544 printk("PLATFORM: watchdog-resolution [%llu ms]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700545 v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700546 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800547 printk("PLATFORM: watchdog-max-timeout [%llu ms]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700548 v = mdesc_get_property(hp, pn, "max-cpus", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700549 if (v) {
550 max_cpus = *v;
551 printk("PLATFORM: max-cpus [%llu]\n", max_cpus);
552 }
David S. Miller43fdf272007-07-12 13:47:50 -0700553
David S. Miller4f0234f2007-07-13 16:03:42 -0700554#ifdef CONFIG_SMP
555 {
556 int max_cpu, i;
557
558 if (v) {
559 max_cpu = *v;
560 if (max_cpu > NR_CPUS)
561 max_cpu = NR_CPUS;
562 } else {
563 max_cpu = NR_CPUS;
564 }
565 for (i = 0; i < max_cpu; i++)
Rusty Russell89229072009-03-16 14:40:23 +1030566 set_cpu_possible(i, true);
David S. Miller4f0234f2007-07-13 16:03:42 -0700567 }
568#endif
569
David S. Miller43fdf272007-07-12 13:47:50 -0700570 mdesc_release(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700571}
572
David S. Miller5052f522009-04-08 19:55:47 -0700573static void __cpuinit fill_in_one_cache(cpuinfo_sparc *c,
David S. Miller4f0234f2007-07-13 16:03:42 -0700574 struct mdesc_handle *hp,
575 u64 mp)
David S. Miller5cbc3072007-05-25 15:49:59 -0700576{
David S. Miller43fdf272007-07-12 13:47:50 -0700577 const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
578 const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
579 const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700580 const char *type;
581 int type_len;
582
David S. Miller43fdf272007-07-12 13:47:50 -0700583 type = mdesc_get_property(hp, mp, "type", &type_len);
David S. Miller5cbc3072007-05-25 15:49:59 -0700584
585 switch (*level) {
586 case 1:
David S. Miller46bcea72007-08-07 18:46:36 -0700587 if (of_find_in_proplist(type, "instn", type_len)) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700588 c->icache_size = *size;
589 c->icache_line_size = *line_size;
David S. Miller46bcea72007-08-07 18:46:36 -0700590 } else if (of_find_in_proplist(type, "data", type_len)) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700591 c->dcache_size = *size;
592 c->dcache_line_size = *line_size;
593 }
594 break;
595
596 case 2:
597 c->ecache_size = *size;
598 c->ecache_line_size = *line_size;
599 break;
600
601 default:
602 break;
603 }
604
605 if (*level == 1) {
David S. Miller43fdf272007-07-12 13:47:50 -0700606 u64 a;
David S. Miller5cbc3072007-05-25 15:49:59 -0700607
David S. Miller43fdf272007-07-12 13:47:50 -0700608 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
609 u64 target = mdesc_arc_target(hp, a);
610 const char *name = mdesc_node_name(hp, target);
David S. Miller5cbc3072007-05-25 15:49:59 -0700611
David S. Miller43fdf272007-07-12 13:47:50 -0700612 if (!strcmp(name, "cache"))
613 fill_in_one_cache(c, hp, target);
David S. Miller5cbc3072007-05-25 15:49:59 -0700614 }
615 }
616}
617
David S. Miller5052f522009-04-08 19:55:47 -0700618static void __cpuinit mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id)
David S. Miller5cbc3072007-05-25 15:49:59 -0700619{
David S. Miller43fdf272007-07-12 13:47:50 -0700620 u64 a;
David S. Miller5cbc3072007-05-25 15:49:59 -0700621
David S. Miller43fdf272007-07-12 13:47:50 -0700622 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
623 u64 t = mdesc_arc_target(hp, a);
624 const char *name;
David S. Miller5cbc3072007-05-25 15:49:59 -0700625 const u64 *id;
626
David S. Miller43fdf272007-07-12 13:47:50 -0700627 name = mdesc_node_name(hp, t);
628 if (!strcmp(name, "cpu")) {
629 id = mdesc_get_property(hp, t, "id", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700630 if (*id < NR_CPUS)
631 cpu_data(*id).core_id = core_id;
632 } else {
David S. Miller43fdf272007-07-12 13:47:50 -0700633 u64 j;
David S. Miller5cbc3072007-05-25 15:49:59 -0700634
David S. Miller43fdf272007-07-12 13:47:50 -0700635 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) {
636 u64 n = mdesc_arc_target(hp, j);
637 const char *n_name;
David S. Miller5cbc3072007-05-25 15:49:59 -0700638
David S. Miller43fdf272007-07-12 13:47:50 -0700639 n_name = mdesc_node_name(hp, n);
640 if (strcmp(n_name, "cpu"))
David S. Miller5cbc3072007-05-25 15:49:59 -0700641 continue;
642
David S. Miller43fdf272007-07-12 13:47:50 -0700643 id = mdesc_get_property(hp, n, "id", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700644 if (*id < NR_CPUS)
645 cpu_data(*id).core_id = core_id;
646 }
647 }
648 }
649}
650
David S. Miller5052f522009-04-08 19:55:47 -0700651static void __cpuinit set_core_ids(struct mdesc_handle *hp)
David S. Miller5cbc3072007-05-25 15:49:59 -0700652{
David S. Miller5cbc3072007-05-25 15:49:59 -0700653 int idx;
David S. Miller43fdf272007-07-12 13:47:50 -0700654 u64 mp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700655
656 idx = 1;
David S. Miller43fdf272007-07-12 13:47:50 -0700657 mdesc_for_each_node_by_name(hp, mp, "cache") {
658 const u64 *level;
David S. Miller5cbc3072007-05-25 15:49:59 -0700659 const char *type;
660 int len;
661
David S. Miller43fdf272007-07-12 13:47:50 -0700662 level = mdesc_get_property(hp, mp, "level", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700663 if (*level != 1)
664 continue;
665
David S. Miller43fdf272007-07-12 13:47:50 -0700666 type = mdesc_get_property(hp, mp, "type", &len);
David S. Miller46bcea72007-08-07 18:46:36 -0700667 if (!of_find_in_proplist(type, "instn", len))
David S. Miller5cbc3072007-05-25 15:49:59 -0700668 continue;
669
David S. Miller43fdf272007-07-12 13:47:50 -0700670 mark_core_ids(hp, mp, idx);
David S. Miller5cbc3072007-05-25 15:49:59 -0700671
672 idx++;
673 }
674}
675
David S. Miller5052f522009-04-08 19:55:47 -0700676static void __cpuinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id)
David S. Millerf78eae22007-06-04 17:01:39 -0700677{
David S. Miller43fdf272007-07-12 13:47:50 -0700678 u64 a;
David S. Millerf78eae22007-06-04 17:01:39 -0700679
David S. Miller43fdf272007-07-12 13:47:50 -0700680 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
681 u64 t = mdesc_arc_target(hp, a);
682 const char *name;
David S. Millerf78eae22007-06-04 17:01:39 -0700683 const u64 *id;
684
David S. Miller43fdf272007-07-12 13:47:50 -0700685 name = mdesc_node_name(hp, t);
686 if (strcmp(name, "cpu"))
David S. Millerf78eae22007-06-04 17:01:39 -0700687 continue;
688
David S. Miller43fdf272007-07-12 13:47:50 -0700689 id = mdesc_get_property(hp, t, "id", NULL);
David S. Millerf78eae22007-06-04 17:01:39 -0700690 if (*id < NR_CPUS)
691 cpu_data(*id).proc_id = proc_id;
692 }
693}
694
David S. Miller5052f522009-04-08 19:55:47 -0700695static void __cpuinit __set_proc_ids(struct mdesc_handle *hp, const char *exec_unit_name)
David S. Millerf78eae22007-06-04 17:01:39 -0700696{
David S. Millerf78eae22007-06-04 17:01:39 -0700697 int idx;
David S. Miller43fdf272007-07-12 13:47:50 -0700698 u64 mp;
David S. Millerf78eae22007-06-04 17:01:39 -0700699
700 idx = 0;
David S. Miller43fdf272007-07-12 13:47:50 -0700701 mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
David S. Millerf78eae22007-06-04 17:01:39 -0700702 const char *type;
703 int len;
704
David S. Miller43fdf272007-07-12 13:47:50 -0700705 type = mdesc_get_property(hp, mp, "type", &len);
David S. Miller46bcea72007-08-07 18:46:36 -0700706 if (!of_find_in_proplist(type, "int", len) &&
707 !of_find_in_proplist(type, "integer", len))
David S. Millerf78eae22007-06-04 17:01:39 -0700708 continue;
709
David S. Miller43fdf272007-07-12 13:47:50 -0700710 mark_proc_ids(hp, mp, idx);
David S. Millerf78eae22007-06-04 17:01:39 -0700711
712 idx++;
713 }
714}
715
David S. Miller5052f522009-04-08 19:55:47 -0700716static void __cpuinit set_proc_ids(struct mdesc_handle *hp)
David S. Millerf78eae22007-06-04 17:01:39 -0700717{
David S. Miller43fdf272007-07-12 13:47:50 -0700718 __set_proc_ids(hp, "exec_unit");
719 __set_proc_ids(hp, "exec-unit");
David S. Millerf78eae22007-06-04 17:01:39 -0700720}
721
David S. Miller5052f522009-04-08 19:55:47 -0700722static void __cpuinit get_one_mondo_bits(const u64 *p, unsigned int *mask,
David S. Miller961f65f2011-08-05 02:38:27 -0700723 unsigned long def, unsigned long max)
David S. Miller5cbc3072007-05-25 15:49:59 -0700724{
725 u64 val;
726
727 if (!p)
728 goto use_default;
729 val = *p;
730
731 if (!val || val >= 64)
732 goto use_default;
733
David S. Miller961f65f2011-08-05 02:38:27 -0700734 if (val > max)
735 val = max;
736
David S. Miller5cbc3072007-05-25 15:49:59 -0700737 *mask = ((1U << val) * 64U) - 1U;
738 return;
739
740use_default:
741 *mask = ((1U << def) * 64U) - 1U;
742}
743
David S. Miller5052f522009-04-08 19:55:47 -0700744static void __cpuinit get_mondo_data(struct mdesc_handle *hp, u64 mp,
David S. Miller4f0234f2007-07-13 16:03:42 -0700745 struct trap_per_cpu *tb)
David S. Miller5cbc3072007-05-25 15:49:59 -0700746{
David S. Miller961f65f2011-08-05 02:38:27 -0700747 static int printed;
David S. Miller5cbc3072007-05-25 15:49:59 -0700748 const u64 *val;
749
David S. Miller43fdf272007-07-12 13:47:50 -0700750 val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700751 get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7, ilog2(max_cpus * 2));
David S. Miller5cbc3072007-05-25 15:49:59 -0700752
David S. Miller43fdf272007-07-12 13:47:50 -0700753 val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700754 get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7, 8);
David S. Miller5cbc3072007-05-25 15:49:59 -0700755
David S. Miller43fdf272007-07-12 13:47:50 -0700756 val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700757 get_one_mondo_bits(val, &tb->resum_qmask, 6, 7);
David S. Miller5cbc3072007-05-25 15:49:59 -0700758
David S. Miller43fdf272007-07-12 13:47:50 -0700759 val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700760 get_one_mondo_bits(val, &tb->nonresum_qmask, 2, 2);
761 if (!printed++) {
762 pr_info("SUN4V: Mondo queue sizes "
763 "[cpu(%u) dev(%u) r(%u) nr(%u)]\n",
764 tb->cpu_mondo_qmask + 1,
765 tb->dev_mondo_qmask + 1,
766 tb->resum_qmask + 1,
767 tb->nonresum_qmask + 1);
768 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700769}
770
David S. Miller5052f522009-04-08 19:55:47 -0700771static void * __cpuinit mdesc_iterate_over_cpus(void *(*func)(struct mdesc_handle *, u64, int, void *), void *arg, cpumask_t *mask)
David S. Miller5cbc3072007-05-25 15:49:59 -0700772{
David S. Miller43fdf272007-07-12 13:47:50 -0700773 struct mdesc_handle *hp = mdesc_grab();
David S. Miller5052f522009-04-08 19:55:47 -0700774 void *ret = NULL;
David S. Miller43fdf272007-07-12 13:47:50 -0700775 u64 mp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700776
David S. Miller43fdf272007-07-12 13:47:50 -0700777 mdesc_for_each_node_by_name(hp, mp, "cpu") {
778 const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
David S. Miller5052f522009-04-08 19:55:47 -0700779 int cpuid = *id;
David S. Miller5cbc3072007-05-25 15:49:59 -0700780
781#ifdef CONFIG_SMP
David S. Miller8a177c42007-09-16 14:45:06 -0700782 if (cpuid >= NR_CPUS) {
783 printk(KERN_WARNING "Ignoring CPU %d which is "
784 ">= NR_CPUS (%d)\n",
785 cpuid, NR_CPUS);
David S. Miller5cbc3072007-05-25 15:49:59 -0700786 continue;
David S. Miller8a177c42007-09-16 14:45:06 -0700787 }
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700788 if (!cpumask_test_cpu(cpuid, mask))
David S. Miller4f0234f2007-07-13 16:03:42 -0700789 continue;
David S. Miller5cbc3072007-05-25 15:49:59 -0700790#endif
791
David S. Miller5052f522009-04-08 19:55:47 -0700792 ret = func(hp, mp, cpuid, arg);
793 if (ret)
794 goto out;
795 }
796out:
797 mdesc_release(hp);
798 return ret;
799}
David S. Miller5cbc3072007-05-25 15:49:59 -0700800
David S. Miller5052f522009-04-08 19:55:47 -0700801static void * __cpuinit record_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg)
802{
803 ncpus_probed++;
804#ifdef CONFIG_SMP
805 set_cpu_present(cpuid, true);
806#endif
807 return NULL;
808}
David S. Miller5cbc3072007-05-25 15:49:59 -0700809
David S. Miller5052f522009-04-08 19:55:47 -0700810void __cpuinit mdesc_populate_present_mask(cpumask_t *mask)
811{
812 if (tlb_type != hypervisor)
813 return;
David S. Miller5cbc3072007-05-25 15:49:59 -0700814
David S. Miller5052f522009-04-08 19:55:47 -0700815 ncpus_probed = 0;
816 mdesc_iterate_over_cpus(record_one_cpu, NULL, mask);
817}
David S. Miller5cbc3072007-05-25 15:49:59 -0700818
David S. Miller5052f522009-04-08 19:55:47 -0700819static void * __cpuinit fill_in_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg)
820{
821 const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
822 struct trap_per_cpu *tb;
823 cpuinfo_sparc *c;
824 u64 a;
David S. Miller5cbc3072007-05-25 15:49:59 -0700825
David S. Miller5052f522009-04-08 19:55:47 -0700826#ifndef CONFIG_SMP
827 /* On uniprocessor we only want the values for the
828 * real physical cpu the kernel booted onto, however
829 * cpu_data() only has one entry at index 0.
830 */
831 if (cpuid != real_hard_smp_processor_id())
832 return NULL;
833 cpuid = 0;
834#endif
835
836 c = &cpu_data(cpuid);
837 c->clock_tick = *cfreq;
838
839 tb = &trap_block[cpuid];
840 get_mondo_data(hp, mp, tb);
841
842 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
843 u64 j, t = mdesc_arc_target(hp, a);
844 const char *t_name;
845
846 t_name = mdesc_node_name(hp, t);
847 if (!strcmp(t_name, "cache")) {
848 fill_in_one_cache(c, hp, t);
849 continue;
David S. Miller5cbc3072007-05-25 15:49:59 -0700850 }
851
David S. Miller5052f522009-04-08 19:55:47 -0700852 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
853 u64 n = mdesc_arc_target(hp, j);
854 const char *n_name;
David S. Miller5cbc3072007-05-25 15:49:59 -0700855
David S. Miller5052f522009-04-08 19:55:47 -0700856 n_name = mdesc_node_name(hp, n);
857 if (!strcmp(n_name, "cache"))
858 fill_in_one_cache(c, hp, n);
859 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700860 }
861
David S. Miller5052f522009-04-08 19:55:47 -0700862 c->core_id = 0;
863 c->proc_id = -1;
864
865 return NULL;
866}
867
David S. Millera2094502009-04-01 03:15:11 -0700868void __cpuinit mdesc_fill_in_cpu_data(cpumask_t *mask)
David S. Miller5052f522009-04-08 19:55:47 -0700869{
870 struct mdesc_handle *hp;
871
David S. Millera2094502009-04-01 03:15:11 -0700872 mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, mask);
David S. Miller5052f522009-04-08 19:55:47 -0700873
David S. Millera2f9f6b2007-06-04 21:48:33 -0700874#ifdef CONFIG_SMP
875 sparc64_multi_core = 1;
876#endif
877
David S. Miller5052f522009-04-08 19:55:47 -0700878 hp = mdesc_grab();
879
David S. Miller43fdf272007-07-12 13:47:50 -0700880 set_core_ids(hp);
881 set_proc_ids(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700882
David S. Miller43fdf272007-07-12 13:47:50 -0700883 mdesc_release(hp);
David S. Miller5052f522009-04-08 19:55:47 -0700884
885 smp_fill_in_sib_core_maps();
David S. Miller5cbc3072007-05-25 15:49:59 -0700886}
887
David S. Miller0fdb7f92007-08-15 21:02:23 -0700888static ssize_t mdesc_read(struct file *file, char __user *buf,
889 size_t len, loff_t *offp)
890{
891 struct mdesc_handle *hp = mdesc_grab();
892 int err;
893
894 if (!hp)
895 return -ENODEV;
896
897 err = hp->handle_size;
898 if (len < hp->handle_size)
899 err = -EMSGSIZE;
900 else if (copy_to_user(buf, &hp->mdesc, hp->handle_size))
901 err = -EFAULT;
902 mdesc_release(hp);
903
904 return err;
905}
906
907static const struct file_operations mdesc_fops = {
908 .read = mdesc_read,
909 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200910 .llseek = noop_llseek,
David S. Miller0fdb7f92007-08-15 21:02:23 -0700911};
912
913static struct miscdevice mdesc_misc = {
914 .minor = MISC_DYNAMIC_MINOR,
915 .name = "mdesc",
916 .fops = &mdesc_fops,
917};
918
919static int __init mdesc_misc_init(void)
920{
921 return misc_register(&mdesc_misc);
922}
923
924__initcall(mdesc_misc_init);
925
David S. Miller5cbc3072007-05-25 15:49:59 -0700926void __init sun4v_mdesc_init(void)
927{
David S. Miller43fdf272007-07-12 13:47:50 -0700928 struct mdesc_handle *hp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700929 unsigned long len, real_len, status;
930
931 (void) sun4v_mach_desc(0UL, 0UL, &len);
932
933 printk("MDESC: Size is %lu bytes.\n", len);
934
Yinghai Lu95f72d12010-07-12 14:36:09 +1000935 hp = mdesc_alloc(len, &memblock_mdesc_ops);
David S. Miller43fdf272007-07-12 13:47:50 -0700936 if (hp == NULL) {
937 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
938 prom_halt();
939 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700940
David S. Miller43fdf272007-07-12 13:47:50 -0700941 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
David S. Miller5cbc3072007-05-25 15:49:59 -0700942 if (status != HV_EOK || real_len > len) {
943 prom_printf("sun4v_mach_desc fails, err(%lu), "
944 "len(%lu), real_len(%lu)\n",
945 status, len, real_len);
David S. Miller43fdf272007-07-12 13:47:50 -0700946 mdesc_free(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700947 prom_halt();
948 }
949
David S. Miller43fdf272007-07-12 13:47:50 -0700950 cur_mdesc = hp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700951
952 report_platform_properties();
David S. Miller5cbc3072007-05-25 15:49:59 -0700953}