mdesc.c 16 KB

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