blob: 6dc796280589221f12526111647e20a9eb0911fc [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>
Paul Gortmaker7b64db62011-07-18 15:57:46 -040014#include <linux/export.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070015
Sam Ravnborg6e6ab2e2008-12-26 15:33:07 -080016#include <asm/cpudata.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070017#include <asm/hypervisor.h>
18#include <asm/mdesc.h>
19#include <asm/prom.h>
Paul Gortmakercd66bc42011-09-19 21:15:28 -040020#include <asm/uaccess.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070021#include <asm/oplib.h>
22#include <asm/smp.h>
23
24/* Unlike the OBP device tree, the machine description is a full-on
25 * DAG. An arbitrary number of ARCs are possible from one
26 * node to other nodes and thus we can't use the OBP device_node
27 * data structure to represent these nodes inside of the kernel.
28 *
29 * Actually, it isn't even a DAG, because there are back pointers
30 * which create cycles in the graph.
31 *
32 * mdesc_hdr and mdesc_elem describe the layout of the data structure
33 * we get from the Hypervisor.
34 */
35struct mdesc_hdr {
36 u32 version; /* Transport version */
37 u32 node_sz; /* node block size */
38 u32 name_sz; /* name block size */
39 u32 data_sz; /* data block size */
David S. Miller43fdf272007-07-12 13:47:50 -070040} __attribute__((aligned(16)));
David S. Miller5cbc3072007-05-25 15:49:59 -070041
42struct mdesc_elem {
43 u8 tag;
44#define MD_LIST_END 0x00
45#define MD_NODE 0x4e
46#define MD_NODE_END 0x45
47#define MD_NOOP 0x20
48#define MD_PROP_ARC 0x61
49#define MD_PROP_VAL 0x76
50#define MD_PROP_STR 0x73
51#define MD_PROP_DATA 0x64
52 u8 name_len;
53 u16 resv;
54 u32 name_offset;
55 union {
56 struct {
57 u32 data_len;
58 u32 data_offset;
59 } data;
60 u64 val;
61 } d;
62};
63
David S. Miller43fdf272007-07-12 13:47:50 -070064struct mdesc_mem_ops {
65 struct mdesc_handle *(*alloc)(unsigned int mdesc_size);
66 void (*free)(struct mdesc_handle *handle);
67};
David S. Miller5cbc3072007-05-25 15:49:59 -070068
David S. Miller43fdf272007-07-12 13:47:50 -070069struct mdesc_handle {
70 struct list_head list;
71 struct mdesc_mem_ops *mops;
72 void *self_base;
73 atomic_t refcnt;
74 unsigned int handle_size;
75 struct mdesc_hdr mdesc;
76};
David S. Miller5cbc3072007-05-25 15:49:59 -070077
David S. Miller43fdf272007-07-12 13:47:50 -070078static void mdesc_handle_init(struct mdesc_handle *hp,
79 unsigned int handle_size,
80 void *base)
David S. Miller5cbc3072007-05-25 15:49:59 -070081{
David S. Miller43fdf272007-07-12 13:47:50 -070082 BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1));
83
84 memset(hp, 0, handle_size);
85 INIT_LIST_HEAD(&hp->list);
86 hp->self_base = base;
87 atomic_set(&hp->refcnt, 1);
88 hp->handle_size = handle_size;
David S. Miller5cbc3072007-05-25 15:49:59 -070089}
90
Yinghai Lu95f72d12010-07-12 14:36:09 +100091static struct mdesc_handle * __init mdesc_memblock_alloc(unsigned int mdesc_size)
David S. Miller5cbc3072007-05-25 15:49:59 -070092{
David S. Miller43fdf272007-07-12 13:47:50 -070093 unsigned int handle_size, alloc_size;
David S. Miller4a283332008-02-13 19:22:23 -080094 struct mdesc_handle *hp;
95 unsigned long paddr;
David S. Miller5cbc3072007-05-25 15:49:59 -070096
David S. Miller43fdf272007-07-12 13:47:50 -070097 handle_size = (sizeof(struct mdesc_handle) -
98 sizeof(struct mdesc_hdr) +
99 mdesc_size);
100 alloc_size = PAGE_ALIGN(handle_size);
David S. Miller5cbc3072007-05-25 15:49:59 -0700101
Yinghai Lu95f72d12010-07-12 14:36:09 +1000102 paddr = memblock_alloc(alloc_size, PAGE_SIZE);
David S. Miller43fdf272007-07-12 13:47:50 -0700103
David S. Miller4a283332008-02-13 19:22:23 -0800104 hp = NULL;
105 if (paddr) {
106 hp = __va(paddr);
107 mdesc_handle_init(hp, handle_size, hp);
108 }
David S. Miller43fdf272007-07-12 13:47:50 -0700109 return hp;
110}
111
David S. Miller3628aa02011-03-30 17:37:56 -0700112static void __init mdesc_memblock_free(struct mdesc_handle *hp)
David S. Miller43fdf272007-07-12 13:47:50 -0700113{
David S. Milleradfe67d2009-12-11 01:16:46 -0800114 unsigned int alloc_size;
115 unsigned long start;
David S. Miller43fdf272007-07-12 13:47:50 -0700116
117 BUG_ON(atomic_read(&hp->refcnt) != 0);
118 BUG_ON(!list_empty(&hp->list));
119
David S. Milleradfe67d2009-12-11 01:16:46 -0800120 alloc_size = PAGE_ALIGN(hp->handle_size);
121 start = __pa(hp);
122 free_bootmem_late(start, alloc_size);
David S. Miller5cbc3072007-05-25 15:49:59 -0700123}
124
Yinghai Lu95f72d12010-07-12 14:36:09 +1000125static struct mdesc_mem_ops memblock_mdesc_ops = {
126 .alloc = mdesc_memblock_alloc,
127 .free = mdesc_memblock_free,
David S. Miller43fdf272007-07-12 13:47:50 -0700128};
129
130static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
David S. Miller5cbc3072007-05-25 15:49:59 -0700131{
David S. Miller43fdf272007-07-12 13:47:50 -0700132 unsigned int handle_size;
133 void *base;
David S. Miller5cbc3072007-05-25 15:49:59 -0700134
David S. Miller43fdf272007-07-12 13:47:50 -0700135 handle_size = (sizeof(struct mdesc_handle) -
136 sizeof(struct mdesc_hdr) +
137 mdesc_size);
David S. Miller5cbc3072007-05-25 15:49:59 -0700138
David S. Miller920c3ed2007-07-17 21:37:35 -0700139 base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
David S. Miller43fdf272007-07-12 13:47:50 -0700140 if (base) {
141 struct mdesc_handle *hp;
142 unsigned long addr;
143
144 addr = (unsigned long)base;
145 addr = (addr + 15UL) & ~15UL;
146 hp = (struct mdesc_handle *) addr;
147
148 mdesc_handle_init(hp, handle_size, base);
149 return hp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700150 }
David S. Miller43fdf272007-07-12 13:47:50 -0700151
David S. Miller5cbc3072007-05-25 15:49:59 -0700152 return NULL;
153}
154
David S. Miller43fdf272007-07-12 13:47:50 -0700155static void mdesc_kfree(struct mdesc_handle *hp)
David S. Miller5cbc3072007-05-25 15:49:59 -0700156{
David S. Miller43fdf272007-07-12 13:47:50 -0700157 BUG_ON(atomic_read(&hp->refcnt) != 0);
158 BUG_ON(!list_empty(&hp->list));
David S. Miller5cbc3072007-05-25 15:49:59 -0700159
David S. Miller43fdf272007-07-12 13:47:50 -0700160 kfree(hp->self_base);
161}
162
163static struct mdesc_mem_ops kmalloc_mdesc_memops = {
164 .alloc = mdesc_kmalloc,
165 .free = mdesc_kfree,
166};
167
168static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size,
169 struct mdesc_mem_ops *mops)
170{
171 struct mdesc_handle *hp = mops->alloc(mdesc_size);
172
173 if (hp)
174 hp->mops = mops;
175
176 return hp;
177}
178
179static void mdesc_free(struct mdesc_handle *hp)
180{
181 hp->mops->free(hp);
182}
183
184static struct mdesc_handle *cur_mdesc;
185static LIST_HEAD(mdesc_zombie_list);
186static DEFINE_SPINLOCK(mdesc_lock);
187
188struct mdesc_handle *mdesc_grab(void)
189{
190 struct mdesc_handle *hp;
191 unsigned long flags;
192
193 spin_lock_irqsave(&mdesc_lock, flags);
194 hp = cur_mdesc;
195 if (hp)
196 atomic_inc(&hp->refcnt);
197 spin_unlock_irqrestore(&mdesc_lock, flags);
198
199 return hp;
200}
201EXPORT_SYMBOL(mdesc_grab);
202
203void mdesc_release(struct mdesc_handle *hp)
204{
205 unsigned long flags;
206
207 spin_lock_irqsave(&mdesc_lock, flags);
208 if (atomic_dec_and_test(&hp->refcnt)) {
209 list_del_init(&hp->list);
210 hp->mops->free(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700211 }
David S. Miller43fdf272007-07-12 13:47:50 -0700212 spin_unlock_irqrestore(&mdesc_lock, flags);
David S. Miller5cbc3072007-05-25 15:49:59 -0700213}
David S. Miller43fdf272007-07-12 13:47:50 -0700214EXPORT_SYMBOL(mdesc_release);
David S. Miller5cbc3072007-05-25 15:49:59 -0700215
David S. Miller920c3ed2007-07-17 21:37:35 -0700216static DEFINE_MUTEX(mdesc_mutex);
217static struct mdesc_notifier_client *client_list;
218
219void mdesc_register_notifier(struct mdesc_notifier_client *client)
220{
221 u64 node;
222
223 mutex_lock(&mdesc_mutex);
224 client->next = client_list;
225 client_list = client;
226
227 mdesc_for_each_node_by_name(cur_mdesc, node, client->node_name)
228 client->add(cur_mdesc, node);
229
230 mutex_unlock(&mdesc_mutex);
231}
232
David S. Miller91ba3c22007-07-18 15:15:45 -0700233static const u64 *parent_cfg_handle(struct mdesc_handle *hp, u64 node)
234{
235 const u64 *id;
236 u64 a;
237
238 id = NULL;
239 mdesc_for_each_arc(a, hp, node, MDESC_ARC_TYPE_BACK) {
240 u64 target;
241
242 target = mdesc_arc_target(hp, a);
243 id = mdesc_get_property(hp, target,
244 "cfg-handle", NULL);
245 if (id)
246 break;
247 }
248
249 return id;
250}
251
David S. Miller920c3ed2007-07-17 21:37:35 -0700252/* Run 'func' on nodes which are in A but not in B. */
253static void invoke_on_missing(const char *name,
254 struct mdesc_handle *a,
255 struct mdesc_handle *b,
256 void (*func)(struct mdesc_handle *, u64))
257{
258 u64 node;
259
260 mdesc_for_each_node_by_name(a, node, name) {
David S. Miller91ba3c22007-07-18 15:15:45 -0700261 int found = 0, is_vdc_port = 0;
262 const char *name_prop;
263 const u64 *id;
David S. Miller920c3ed2007-07-17 21:37:35 -0700264 u64 fnode;
265
David S. Miller91ba3c22007-07-18 15:15:45 -0700266 name_prop = mdesc_get_property(a, node, "name", NULL);
267 if (name_prop && !strcmp(name_prop, "vdc-port")) {
268 is_vdc_port = 1;
269 id = parent_cfg_handle(a, node);
270 } else
271 id = mdesc_get_property(a, node, "id", NULL);
272
273 if (!id) {
274 printk(KERN_ERR "MD: Cannot find ID for %s node.\n",
275 (name_prop ? name_prop : name));
276 continue;
277 }
278
David S. Miller920c3ed2007-07-17 21:37:35 -0700279 mdesc_for_each_node_by_name(b, fnode, name) {
David S. Miller91ba3c22007-07-18 15:15:45 -0700280 const u64 *fid;
281
282 if (is_vdc_port) {
283 name_prop = mdesc_get_property(b, fnode,
284 "name", NULL);
285 if (!name_prop ||
286 strcmp(name_prop, "vdc-port"))
287 continue;
288 fid = parent_cfg_handle(b, fnode);
289 if (!fid) {
290 printk(KERN_ERR "MD: Cannot find ID "
291 "for vdc-port node.\n");
292 continue;
293 }
294 } else
295 fid = mdesc_get_property(b, fnode,
296 "id", NULL);
David S. Miller920c3ed2007-07-17 21:37:35 -0700297
298 if (*id == *fid) {
299 found = 1;
300 break;
301 }
302 }
303 if (!found)
304 func(a, node);
305 }
306}
307
308static void notify_one(struct mdesc_notifier_client *p,
309 struct mdesc_handle *old_hp,
310 struct mdesc_handle *new_hp)
311{
312 invoke_on_missing(p->node_name, old_hp, new_hp, p->remove);
313 invoke_on_missing(p->node_name, new_hp, old_hp, p->add);
314}
315
316static void mdesc_notify_clients(struct mdesc_handle *old_hp,
317 struct mdesc_handle *new_hp)
318{
319 struct mdesc_notifier_client *p = client_list;
320
321 while (p) {
322 notify_one(p, old_hp, new_hp);
323 p = p->next;
324 }
325}
326
David S. Miller778feeb2007-07-16 16:50:36 -0700327void mdesc_update(void)
David S. Miller5cbc3072007-05-25 15:49:59 -0700328{
David S. Miller43fdf272007-07-12 13:47:50 -0700329 unsigned long len, real_len, status;
330 struct mdesc_handle *hp, *orig_hp;
331 unsigned long flags;
David S. Miller5cbc3072007-05-25 15:49:59 -0700332
David S. Miller920c3ed2007-07-17 21:37:35 -0700333 mutex_lock(&mdesc_mutex);
334
David S. Miller43fdf272007-07-12 13:47:50 -0700335 (void) sun4v_mach_desc(0UL, 0UL, &len);
David S. Miller5cbc3072007-05-25 15:49:59 -0700336
David S. Miller43fdf272007-07-12 13:47:50 -0700337 hp = mdesc_alloc(len, &kmalloc_mdesc_memops);
338 if (!hp) {
339 printk(KERN_ERR "MD: mdesc alloc fails\n");
David S. Miller920c3ed2007-07-17 21:37:35 -0700340 goto out;
David S. Miller5cbc3072007-05-25 15:49:59 -0700341 }
342
David S. Miller43fdf272007-07-12 13:47:50 -0700343 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
344 if (status != HV_EOK || real_len > len) {
345 printk(KERN_ERR "MD: mdesc reread fails with %lu\n",
346 status);
347 atomic_dec(&hp->refcnt);
348 mdesc_free(hp);
David S. Miller920c3ed2007-07-17 21:37:35 -0700349 goto out;
David S. Miller5cbc3072007-05-25 15:49:59 -0700350 }
David S. Miller43fdf272007-07-12 13:47:50 -0700351
352 spin_lock_irqsave(&mdesc_lock, flags);
353 orig_hp = cur_mdesc;
354 cur_mdesc = hp;
David S. Miller920c3ed2007-07-17 21:37:35 -0700355 spin_unlock_irqrestore(&mdesc_lock, flags);
David S. Miller43fdf272007-07-12 13:47:50 -0700356
David S. Miller920c3ed2007-07-17 21:37:35 -0700357 mdesc_notify_clients(orig_hp, hp);
358
359 spin_lock_irqsave(&mdesc_lock, flags);
David S. Miller43fdf272007-07-12 13:47:50 -0700360 if (atomic_dec_and_test(&orig_hp->refcnt))
361 mdesc_free(orig_hp);
362 else
363 list_add(&orig_hp->list, &mdesc_zombie_list);
364 spin_unlock_irqrestore(&mdesc_lock, flags);
David S. Miller920c3ed2007-07-17 21:37:35 -0700365
366out:
367 mutex_unlock(&mdesc_mutex);
David S. Miller5cbc3072007-05-25 15:49:59 -0700368}
369
David S. Miller43fdf272007-07-12 13:47:50 -0700370static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
David S. Miller5cbc3072007-05-25 15:49:59 -0700371{
372 return (struct mdesc_elem *) (mdesc + 1);
373}
374
David S. Miller43fdf272007-07-12 13:47:50 -0700375static void *name_block(struct mdesc_hdr *mdesc)
David S. Miller5cbc3072007-05-25 15:49:59 -0700376{
377 return ((void *) node_block(mdesc)) + mdesc->node_sz;
378}
379
David S. Miller43fdf272007-07-12 13:47:50 -0700380static void *data_block(struct mdesc_hdr *mdesc)
David S. Miller5cbc3072007-05-25 15:49:59 -0700381{
382 return ((void *) name_block(mdesc)) + mdesc->name_sz;
383}
384
David S. Miller43fdf272007-07-12 13:47:50 -0700385u64 mdesc_node_by_name(struct mdesc_handle *hp,
386 u64 from_node, const char *name)
David S. Miller5cbc3072007-05-25 15:49:59 -0700387{
David S. Miller43fdf272007-07-12 13:47:50 -0700388 struct mdesc_elem *ep = node_block(&hp->mdesc);
389 const char *names = name_block(&hp->mdesc);
390 u64 last_node = hp->mdesc.node_sz / 16;
391 u64 ret;
David S. Miller5cbc3072007-05-25 15:49:59 -0700392
David S. Miller778feeb2007-07-16 16:50:36 -0700393 if (from_node == MDESC_NODE_NULL) {
394 ret = from_node = 0;
395 } else if (from_node >= last_node) {
David S. Miller43fdf272007-07-12 13:47:50 -0700396 return MDESC_NODE_NULL;
David S. Miller778feeb2007-07-16 16:50:36 -0700397 } else {
398 ret = ep[from_node].d.val;
399 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700400
David S. Miller43fdf272007-07-12 13:47:50 -0700401 while (ret < last_node) {
402 if (ep[ret].tag != MD_NODE)
403 return MDESC_NODE_NULL;
404 if (!strcmp(names + ep[ret].name_offset, name))
405 break;
406 ret = ep[ret].d.val;
407 }
408 if (ret >= last_node)
409 ret = MDESC_NODE_NULL;
410 return ret;
411}
412EXPORT_SYMBOL(mdesc_node_by_name);
David S. Miller5cbc3072007-05-25 15:49:59 -0700413
David S. Miller43fdf272007-07-12 13:47:50 -0700414const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
415 const char *name, int *lenp)
416{
417 const char *names = name_block(&hp->mdesc);
418 u64 last_node = hp->mdesc.node_sz / 16;
419 void *data = data_block(&hp->mdesc);
420 struct mdesc_elem *ep;
421
422 if (node == MDESC_NODE_NULL || node >= last_node)
423 return NULL;
424
425 ep = node_block(&hp->mdesc) + node;
426 ep++;
427 for (; ep->tag != MD_NODE_END; ep++) {
428 void *val = NULL;
429 int len = 0;
430
431 switch (ep->tag) {
432 case MD_PROP_VAL:
433 val = &ep->d.val;
434 len = 8;
David S. Miller5cbc3072007-05-25 15:49:59 -0700435 break;
436
David S. Miller43fdf272007-07-12 13:47:50 -0700437 case MD_PROP_STR:
438 case MD_PROP_DATA:
439 val = data + ep->d.data.data_offset;
440 len = ep->d.data.data_len;
441 break;
David S. Miller5cbc3072007-05-25 15:49:59 -0700442
David S. Miller43fdf272007-07-12 13:47:50 -0700443 default:
David S. Miller5cbc3072007-05-25 15:49:59 -0700444 break;
445 }
David S. Miller43fdf272007-07-12 13:47:50 -0700446 if (!val)
447 continue;
David S. Miller5cbc3072007-05-25 15:49:59 -0700448
David S. Miller43fdf272007-07-12 13:47:50 -0700449 if (!strcmp(names + ep->name_offset, name)) {
450 if (lenp)
451 *lenp = len;
452 return val;
David S. Miller5cbc3072007-05-25 15:49:59 -0700453 }
454 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700455
David S. Miller43fdf272007-07-12 13:47:50 -0700456 return NULL;
457}
458EXPORT_SYMBOL(mdesc_get_property);
459
460u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
David S. Miller5cbc3072007-05-25 15:49:59 -0700461{
David S. Miller43fdf272007-07-12 13:47:50 -0700462 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
463 const char *names = name_block(&hp->mdesc);
464 u64 last_node = hp->mdesc.node_sz / 16;
David S. Miller5cbc3072007-05-25 15:49:59 -0700465
David S. Miller43fdf272007-07-12 13:47:50 -0700466 if (from == MDESC_NODE_NULL || from >= last_node)
467 return MDESC_NODE_NULL;
468
469 ep = base + from;
470
471 ep++;
472 for (; ep->tag != MD_NODE_END; ep++) {
473 if (ep->tag != MD_PROP_ARC)
474 continue;
475
476 if (strcmp(names + ep->name_offset, arc_type))
477 continue;
478
479 return ep - base;
David S. Miller5cbc3072007-05-25 15:49:59 -0700480 }
David S. Miller43fdf272007-07-12 13:47:50 -0700481
482 return MDESC_NODE_NULL;
David S. Miller5cbc3072007-05-25 15:49:59 -0700483}
David S. Miller43fdf272007-07-12 13:47:50 -0700484EXPORT_SYMBOL(mdesc_next_arc);
485
486u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
487{
488 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
489
490 ep = base + arc;
491
492 return ep->d.val;
493}
494EXPORT_SYMBOL(mdesc_arc_target);
495
496const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
497{
498 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
499 const char *names = name_block(&hp->mdesc);
500 u64 last_node = hp->mdesc.node_sz / 16;
501
502 if (node == MDESC_NODE_NULL || node >= last_node)
503 return NULL;
504
505 ep = base + node;
506 if (ep->tag != MD_NODE)
507 return NULL;
508
509 return names + ep->name_offset;
510}
511EXPORT_SYMBOL(mdesc_node_name);
David S. Miller5cbc3072007-05-25 15:49:59 -0700512
David S. Miller961f65f2011-08-05 02:38:27 -0700513static u64 max_cpus = 64;
514
David S. Miller5cbc3072007-05-25 15:49:59 -0700515static void __init report_platform_properties(void)
516{
David S. Miller43fdf272007-07-12 13:47:50 -0700517 struct mdesc_handle *hp = mdesc_grab();
518 u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
David S. Miller5cbc3072007-05-25 15:49:59 -0700519 const char *s;
520 const u64 *v;
521
David S. Miller43fdf272007-07-12 13:47:50 -0700522 if (pn == MDESC_NODE_NULL) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700523 prom_printf("No platform node in machine-description.\n");
524 prom_halt();
525 }
526
David S. Miller43fdf272007-07-12 13:47:50 -0700527 s = mdesc_get_property(hp, pn, "banner-name", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700528 printk("PLATFORM: banner-name [%s]\n", s);
David S. Miller43fdf272007-07-12 13:47:50 -0700529 s = mdesc_get_property(hp, pn, "name", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700530 printk("PLATFORM: name [%s]\n", s);
531
David S. Miller43fdf272007-07-12 13:47:50 -0700532 v = mdesc_get_property(hp, pn, "hostid", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700533 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800534 printk("PLATFORM: hostid [%08llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700535 v = mdesc_get_property(hp, pn, "serial#", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700536 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800537 printk("PLATFORM: serial# [%08llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700538 v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
Sam Ravnborg90181132009-01-06 13:19:28 -0800539 printk("PLATFORM: stick-frequency [%08llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700540 v = mdesc_get_property(hp, pn, "mac-address", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700541 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800542 printk("PLATFORM: mac-address [%llx]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700543 v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700544 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800545 printk("PLATFORM: watchdog-resolution [%llu ms]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700546 v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700547 if (v)
Sam Ravnborg90181132009-01-06 13:19:28 -0800548 printk("PLATFORM: watchdog-max-timeout [%llu ms]\n", *v);
David S. Miller43fdf272007-07-12 13:47:50 -0700549 v = mdesc_get_property(hp, pn, "max-cpus", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700550 if (v) {
551 max_cpus = *v;
552 printk("PLATFORM: max-cpus [%llu]\n", max_cpus);
553 }
David S. Miller43fdf272007-07-12 13:47:50 -0700554
David S. Miller4f0234f2007-07-13 16:03:42 -0700555#ifdef CONFIG_SMP
556 {
557 int max_cpu, i;
558
559 if (v) {
560 max_cpu = *v;
561 if (max_cpu > NR_CPUS)
562 max_cpu = NR_CPUS;
563 } else {
564 max_cpu = NR_CPUS;
565 }
566 for (i = 0; i < max_cpu; i++)
Rusty Russell89229072009-03-16 14:40:23 +1030567 set_cpu_possible(i, true);
David S. Miller4f0234f2007-07-13 16:03:42 -0700568 }
569#endif
570
David S. Miller43fdf272007-07-12 13:47:50 -0700571 mdesc_release(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700572}
573
David S. Miller5052f522009-04-08 19:55:47 -0700574static void __cpuinit fill_in_one_cache(cpuinfo_sparc *c,
David S. Miller4f0234f2007-07-13 16:03:42 -0700575 struct mdesc_handle *hp,
576 u64 mp)
David S. Miller5cbc3072007-05-25 15:49:59 -0700577{
David S. Miller43fdf272007-07-12 13:47:50 -0700578 const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
579 const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
580 const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700581 const char *type;
582 int type_len;
583
David S. Miller43fdf272007-07-12 13:47:50 -0700584 type = mdesc_get_property(hp, mp, "type", &type_len);
David S. Miller5cbc3072007-05-25 15:49:59 -0700585
586 switch (*level) {
587 case 1:
David S. Miller46bcea72007-08-07 18:46:36 -0700588 if (of_find_in_proplist(type, "instn", type_len)) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700589 c->icache_size = *size;
590 c->icache_line_size = *line_size;
David S. Miller46bcea72007-08-07 18:46:36 -0700591 } else if (of_find_in_proplist(type, "data", type_len)) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700592 c->dcache_size = *size;
593 c->dcache_line_size = *line_size;
594 }
595 break;
596
597 case 2:
598 c->ecache_size = *size;
599 c->ecache_line_size = *line_size;
600 break;
601
602 default:
603 break;
604 }
605
606 if (*level == 1) {
David S. Miller43fdf272007-07-12 13:47:50 -0700607 u64 a;
David S. Miller5cbc3072007-05-25 15:49:59 -0700608
David S. Miller43fdf272007-07-12 13:47:50 -0700609 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
610 u64 target = mdesc_arc_target(hp, a);
611 const char *name = mdesc_node_name(hp, target);
David S. Miller5cbc3072007-05-25 15:49:59 -0700612
David S. Miller43fdf272007-07-12 13:47:50 -0700613 if (!strcmp(name, "cache"))
614 fill_in_one_cache(c, hp, target);
David S. Miller5cbc3072007-05-25 15:49:59 -0700615 }
616 }
617}
618
David S. Miller5052f522009-04-08 19:55:47 -0700619static void __cpuinit mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id)
David S. Miller5cbc3072007-05-25 15:49:59 -0700620{
David S. Miller43fdf272007-07-12 13:47:50 -0700621 u64 a;
David S. Miller5cbc3072007-05-25 15:49:59 -0700622
David S. Miller43fdf272007-07-12 13:47:50 -0700623 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
624 u64 t = mdesc_arc_target(hp, a);
625 const char *name;
David S. Miller5cbc3072007-05-25 15:49:59 -0700626 const u64 *id;
627
David S. Miller43fdf272007-07-12 13:47:50 -0700628 name = mdesc_node_name(hp, t);
629 if (!strcmp(name, "cpu")) {
630 id = mdesc_get_property(hp, t, "id", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700631 if (*id < NR_CPUS)
632 cpu_data(*id).core_id = core_id;
633 } else {
David S. Miller43fdf272007-07-12 13:47:50 -0700634 u64 j;
David S. Miller5cbc3072007-05-25 15:49:59 -0700635
David S. Miller43fdf272007-07-12 13:47:50 -0700636 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) {
637 u64 n = mdesc_arc_target(hp, j);
638 const char *n_name;
David S. Miller5cbc3072007-05-25 15:49:59 -0700639
David S. Miller43fdf272007-07-12 13:47:50 -0700640 n_name = mdesc_node_name(hp, n);
641 if (strcmp(n_name, "cpu"))
David S. Miller5cbc3072007-05-25 15:49:59 -0700642 continue;
643
David S. Miller43fdf272007-07-12 13:47:50 -0700644 id = mdesc_get_property(hp, n, "id", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700645 if (*id < NR_CPUS)
646 cpu_data(*id).core_id = core_id;
647 }
648 }
649 }
650}
651
David S. Miller5052f522009-04-08 19:55:47 -0700652static void __cpuinit set_core_ids(struct mdesc_handle *hp)
David S. Miller5cbc3072007-05-25 15:49:59 -0700653{
David S. Miller5cbc3072007-05-25 15:49:59 -0700654 int idx;
David S. Miller43fdf272007-07-12 13:47:50 -0700655 u64 mp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700656
657 idx = 1;
David S. Miller43fdf272007-07-12 13:47:50 -0700658 mdesc_for_each_node_by_name(hp, mp, "cache") {
659 const u64 *level;
David S. Miller5cbc3072007-05-25 15:49:59 -0700660 const char *type;
661 int len;
662
David S. Miller43fdf272007-07-12 13:47:50 -0700663 level = mdesc_get_property(hp, mp, "level", NULL);
David S. Miller5cbc3072007-05-25 15:49:59 -0700664 if (*level != 1)
665 continue;
666
David S. Miller43fdf272007-07-12 13:47:50 -0700667 type = mdesc_get_property(hp, mp, "type", &len);
David S. Miller46bcea72007-08-07 18:46:36 -0700668 if (!of_find_in_proplist(type, "instn", len))
David S. Miller5cbc3072007-05-25 15:49:59 -0700669 continue;
670
David S. Miller43fdf272007-07-12 13:47:50 -0700671 mark_core_ids(hp, mp, idx);
David S. Miller5cbc3072007-05-25 15:49:59 -0700672
673 idx++;
674 }
675}
676
David S. Miller5052f522009-04-08 19:55:47 -0700677static void __cpuinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id)
David S. Millerf78eae22007-06-04 17:01:39 -0700678{
David S. Miller43fdf272007-07-12 13:47:50 -0700679 u64 a;
David S. Millerf78eae22007-06-04 17:01:39 -0700680
David S. Miller43fdf272007-07-12 13:47:50 -0700681 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
682 u64 t = mdesc_arc_target(hp, a);
683 const char *name;
David S. Millerf78eae22007-06-04 17:01:39 -0700684 const u64 *id;
685
David S. Miller43fdf272007-07-12 13:47:50 -0700686 name = mdesc_node_name(hp, t);
687 if (strcmp(name, "cpu"))
David S. Millerf78eae22007-06-04 17:01:39 -0700688 continue;
689
David S. Miller43fdf272007-07-12 13:47:50 -0700690 id = mdesc_get_property(hp, t, "id", NULL);
David S. Millerf78eae22007-06-04 17:01:39 -0700691 if (*id < NR_CPUS)
692 cpu_data(*id).proc_id = proc_id;
693 }
694}
695
David S. Miller5052f522009-04-08 19:55:47 -0700696static void __cpuinit __set_proc_ids(struct mdesc_handle *hp, const char *exec_unit_name)
David S. Millerf78eae22007-06-04 17:01:39 -0700697{
David S. Millerf78eae22007-06-04 17:01:39 -0700698 int idx;
David S. Miller43fdf272007-07-12 13:47:50 -0700699 u64 mp;
David S. Millerf78eae22007-06-04 17:01:39 -0700700
701 idx = 0;
David S. Miller43fdf272007-07-12 13:47:50 -0700702 mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
David S. Millerf78eae22007-06-04 17:01:39 -0700703 const char *type;
704 int len;
705
David S. Miller43fdf272007-07-12 13:47:50 -0700706 type = mdesc_get_property(hp, mp, "type", &len);
David S. Miller46bcea72007-08-07 18:46:36 -0700707 if (!of_find_in_proplist(type, "int", len) &&
708 !of_find_in_proplist(type, "integer", len))
David S. Millerf78eae22007-06-04 17:01:39 -0700709 continue;
710
David S. Miller43fdf272007-07-12 13:47:50 -0700711 mark_proc_ids(hp, mp, idx);
David S. Millerf78eae22007-06-04 17:01:39 -0700712
713 idx++;
714 }
715}
716
David S. Miller5052f522009-04-08 19:55:47 -0700717static void __cpuinit set_proc_ids(struct mdesc_handle *hp)
David S. Millerf78eae22007-06-04 17:01:39 -0700718{
David S. Miller43fdf272007-07-12 13:47:50 -0700719 __set_proc_ids(hp, "exec_unit");
720 __set_proc_ids(hp, "exec-unit");
David S. Millerf78eae22007-06-04 17:01:39 -0700721}
722
David S. Miller5052f522009-04-08 19:55:47 -0700723static void __cpuinit get_one_mondo_bits(const u64 *p, unsigned int *mask,
David S. Miller961f65f2011-08-05 02:38:27 -0700724 unsigned long def, unsigned long max)
David S. Miller5cbc3072007-05-25 15:49:59 -0700725{
726 u64 val;
727
728 if (!p)
729 goto use_default;
730 val = *p;
731
732 if (!val || val >= 64)
733 goto use_default;
734
David S. Miller961f65f2011-08-05 02:38:27 -0700735 if (val > max)
736 val = max;
737
David S. Miller5cbc3072007-05-25 15:49:59 -0700738 *mask = ((1U << val) * 64U) - 1U;
739 return;
740
741use_default:
742 *mask = ((1U << def) * 64U) - 1U;
743}
744
David S. Miller5052f522009-04-08 19:55:47 -0700745static void __cpuinit get_mondo_data(struct mdesc_handle *hp, u64 mp,
David S. Miller4f0234f2007-07-13 16:03:42 -0700746 struct trap_per_cpu *tb)
David S. Miller5cbc3072007-05-25 15:49:59 -0700747{
David S. Miller961f65f2011-08-05 02:38:27 -0700748 static int printed;
David S. Miller5cbc3072007-05-25 15:49:59 -0700749 const u64 *val;
750
David S. Miller43fdf272007-07-12 13:47:50 -0700751 val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700752 get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7, ilog2(max_cpus * 2));
David S. Miller5cbc3072007-05-25 15:49:59 -0700753
David S. Miller43fdf272007-07-12 13:47:50 -0700754 val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700755 get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7, 8);
David S. Miller5cbc3072007-05-25 15:49:59 -0700756
David S. Miller43fdf272007-07-12 13:47:50 -0700757 val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700758 get_one_mondo_bits(val, &tb->resum_qmask, 6, 7);
David S. Miller5cbc3072007-05-25 15:49:59 -0700759
David S. Miller43fdf272007-07-12 13:47:50 -0700760 val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
David S. Miller961f65f2011-08-05 02:38:27 -0700761 get_one_mondo_bits(val, &tb->nonresum_qmask, 2, 2);
762 if (!printed++) {
763 pr_info("SUN4V: Mondo queue sizes "
764 "[cpu(%u) dev(%u) r(%u) nr(%u)]\n",
765 tb->cpu_mondo_qmask + 1,
766 tb->dev_mondo_qmask + 1,
767 tb->resum_qmask + 1,
768 tb->nonresum_qmask + 1);
769 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700770}
771
David S. Miller5052f522009-04-08 19:55:47 -0700772static 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 -0700773{
David S. Miller43fdf272007-07-12 13:47:50 -0700774 struct mdesc_handle *hp = mdesc_grab();
David S. Miller5052f522009-04-08 19:55:47 -0700775 void *ret = NULL;
David S. Miller43fdf272007-07-12 13:47:50 -0700776 u64 mp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700777
David S. Miller43fdf272007-07-12 13:47:50 -0700778 mdesc_for_each_node_by_name(hp, mp, "cpu") {
779 const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
David S. Miller5052f522009-04-08 19:55:47 -0700780 int cpuid = *id;
David S. Miller5cbc3072007-05-25 15:49:59 -0700781
782#ifdef CONFIG_SMP
David S. Miller8a177c42007-09-16 14:45:06 -0700783 if (cpuid >= NR_CPUS) {
784 printk(KERN_WARNING "Ignoring CPU %d which is "
785 ">= NR_CPUS (%d)\n",
786 cpuid, NR_CPUS);
David S. Miller5cbc3072007-05-25 15:49:59 -0700787 continue;
David S. Miller8a177c42007-09-16 14:45:06 -0700788 }
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700789 if (!cpumask_test_cpu(cpuid, mask))
David S. Miller4f0234f2007-07-13 16:03:42 -0700790 continue;
David S. Miller5cbc3072007-05-25 15:49:59 -0700791#endif
792
David S. Miller5052f522009-04-08 19:55:47 -0700793 ret = func(hp, mp, cpuid, arg);
794 if (ret)
795 goto out;
796 }
797out:
798 mdesc_release(hp);
799 return ret;
800}
David S. Miller5cbc3072007-05-25 15:49:59 -0700801
David S. Miller5052f522009-04-08 19:55:47 -0700802static void * __cpuinit record_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg)
803{
804 ncpus_probed++;
805#ifdef CONFIG_SMP
806 set_cpu_present(cpuid, true);
807#endif
808 return NULL;
809}
David S. Miller5cbc3072007-05-25 15:49:59 -0700810
David S. Miller5052f522009-04-08 19:55:47 -0700811void __cpuinit mdesc_populate_present_mask(cpumask_t *mask)
812{
813 if (tlb_type != hypervisor)
814 return;
David S. Miller5cbc3072007-05-25 15:49:59 -0700815
David S. Miller5052f522009-04-08 19:55:47 -0700816 ncpus_probed = 0;
817 mdesc_iterate_over_cpus(record_one_cpu, NULL, mask);
818}
David S. Miller5cbc3072007-05-25 15:49:59 -0700819
David S. Miller5052f522009-04-08 19:55:47 -0700820static void * __cpuinit fill_in_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg)
821{
822 const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
823 struct trap_per_cpu *tb;
824 cpuinfo_sparc *c;
825 u64 a;
David S. Miller5cbc3072007-05-25 15:49:59 -0700826
David S. Miller5052f522009-04-08 19:55:47 -0700827#ifndef CONFIG_SMP
828 /* On uniprocessor we only want the values for the
829 * real physical cpu the kernel booted onto, however
830 * cpu_data() only has one entry at index 0.
831 */
832 if (cpuid != real_hard_smp_processor_id())
833 return NULL;
834 cpuid = 0;
835#endif
836
837 c = &cpu_data(cpuid);
838 c->clock_tick = *cfreq;
839
840 tb = &trap_block[cpuid];
841 get_mondo_data(hp, mp, tb);
842
843 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
844 u64 j, t = mdesc_arc_target(hp, a);
845 const char *t_name;
846
847 t_name = mdesc_node_name(hp, t);
848 if (!strcmp(t_name, "cache")) {
849 fill_in_one_cache(c, hp, t);
850 continue;
David S. Miller5cbc3072007-05-25 15:49:59 -0700851 }
852
David S. Miller5052f522009-04-08 19:55:47 -0700853 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
854 u64 n = mdesc_arc_target(hp, j);
855 const char *n_name;
David S. Miller5cbc3072007-05-25 15:49:59 -0700856
David S. Miller5052f522009-04-08 19:55:47 -0700857 n_name = mdesc_node_name(hp, n);
858 if (!strcmp(n_name, "cache"))
859 fill_in_one_cache(c, hp, n);
860 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700861 }
862
David S. Miller5052f522009-04-08 19:55:47 -0700863 c->core_id = 0;
864 c->proc_id = -1;
865
866 return NULL;
867}
868
David S. Millera2094502009-04-01 03:15:11 -0700869void __cpuinit mdesc_fill_in_cpu_data(cpumask_t *mask)
David S. Miller5052f522009-04-08 19:55:47 -0700870{
871 struct mdesc_handle *hp;
872
David S. Millera2094502009-04-01 03:15:11 -0700873 mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, mask);
David S. Miller5052f522009-04-08 19:55:47 -0700874
David S. Millera2f9f6b2007-06-04 21:48:33 -0700875#ifdef CONFIG_SMP
876 sparc64_multi_core = 1;
877#endif
878
David S. Miller5052f522009-04-08 19:55:47 -0700879 hp = mdesc_grab();
880
David S. Miller43fdf272007-07-12 13:47:50 -0700881 set_core_ids(hp);
882 set_proc_ids(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700883
David S. Miller43fdf272007-07-12 13:47:50 -0700884 mdesc_release(hp);
David S. Miller5052f522009-04-08 19:55:47 -0700885
886 smp_fill_in_sib_core_maps();
David S. Miller5cbc3072007-05-25 15:49:59 -0700887}
888
David S. Miller0fdb7f92007-08-15 21:02:23 -0700889static ssize_t mdesc_read(struct file *file, char __user *buf,
890 size_t len, loff_t *offp)
891{
892 struct mdesc_handle *hp = mdesc_grab();
893 int err;
894
895 if (!hp)
896 return -ENODEV;
897
898 err = hp->handle_size;
899 if (len < hp->handle_size)
900 err = -EMSGSIZE;
901 else if (copy_to_user(buf, &hp->mdesc, hp->handle_size))
902 err = -EFAULT;
903 mdesc_release(hp);
904
905 return err;
906}
907
908static const struct file_operations mdesc_fops = {
909 .read = mdesc_read,
910 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200911 .llseek = noop_llseek,
David S. Miller0fdb7f92007-08-15 21:02:23 -0700912};
913
914static struct miscdevice mdesc_misc = {
915 .minor = MISC_DYNAMIC_MINOR,
916 .name = "mdesc",
917 .fops = &mdesc_fops,
918};
919
920static int __init mdesc_misc_init(void)
921{
922 return misc_register(&mdesc_misc);
923}
924
925__initcall(mdesc_misc_init);
926
David S. Miller5cbc3072007-05-25 15:49:59 -0700927void __init sun4v_mdesc_init(void)
928{
David S. Miller43fdf272007-07-12 13:47:50 -0700929 struct mdesc_handle *hp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700930 unsigned long len, real_len, status;
931
932 (void) sun4v_mach_desc(0UL, 0UL, &len);
933
934 printk("MDESC: Size is %lu bytes.\n", len);
935
Yinghai Lu95f72d12010-07-12 14:36:09 +1000936 hp = mdesc_alloc(len, &memblock_mdesc_ops);
David S. Miller43fdf272007-07-12 13:47:50 -0700937 if (hp == NULL) {
938 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
939 prom_halt();
940 }
David S. Miller5cbc3072007-05-25 15:49:59 -0700941
David S. Miller43fdf272007-07-12 13:47:50 -0700942 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
David S. Miller5cbc3072007-05-25 15:49:59 -0700943 if (status != HV_EOK || real_len > len) {
944 prom_printf("sun4v_mach_desc fails, err(%lu), "
945 "len(%lu), real_len(%lu)\n",
946 status, len, real_len);
David S. Miller43fdf272007-07-12 13:47:50 -0700947 mdesc_free(hp);
David S. Miller5cbc3072007-05-25 15:49:59 -0700948 prom_halt();
949 }
950
David S. Miller43fdf272007-07-12 13:47:50 -0700951 cur_mdesc = hp;
David S. Miller5cbc3072007-05-25 15:49:59 -0700952
953 report_platform_properties();
David S. Miller5cbc3072007-05-25 15:49:59 -0700954}