mdesc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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. static void do_mdesc_update(struct work_struct *work)
  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 DECLARE_WORK(mdesc_update_work, do_mdesc_update);
  208. void mdesc_update(void)
  209. {
  210. schedule_work(&mdesc_update_work);
  211. }
  212. static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
  213. {
  214. return (struct mdesc_elem *) (mdesc + 1);
  215. }
  216. static void *name_block(struct mdesc_hdr *mdesc)
  217. {
  218. return ((void *) node_block(mdesc)) + mdesc->node_sz;
  219. }
  220. static void *data_block(struct mdesc_hdr *mdesc)
  221. {
  222. return ((void *) name_block(mdesc)) + mdesc->name_sz;
  223. }
  224. u64 mdesc_node_by_name(struct mdesc_handle *hp,
  225. u64 from_node, const char *name)
  226. {
  227. struct mdesc_elem *ep = node_block(&hp->mdesc);
  228. const char *names = name_block(&hp->mdesc);
  229. u64 last_node = hp->mdesc.node_sz / 16;
  230. u64 ret;
  231. if (from_node == MDESC_NODE_NULL)
  232. from_node = 0;
  233. if (from_node >= last_node)
  234. return MDESC_NODE_NULL;
  235. ret = ep[from_node].d.val;
  236. while (ret < last_node) {
  237. if (ep[ret].tag != MD_NODE)
  238. return MDESC_NODE_NULL;
  239. if (!strcmp(names + ep[ret].name_offset, name))
  240. break;
  241. ret = ep[ret].d.val;
  242. }
  243. if (ret >= last_node)
  244. ret = MDESC_NODE_NULL;
  245. return ret;
  246. }
  247. EXPORT_SYMBOL(mdesc_node_by_name);
  248. const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
  249. const char *name, int *lenp)
  250. {
  251. const char *names = name_block(&hp->mdesc);
  252. u64 last_node = hp->mdesc.node_sz / 16;
  253. void *data = data_block(&hp->mdesc);
  254. struct mdesc_elem *ep;
  255. if (node == MDESC_NODE_NULL || node >= last_node)
  256. return NULL;
  257. ep = node_block(&hp->mdesc) + node;
  258. ep++;
  259. for (; ep->tag != MD_NODE_END; ep++) {
  260. void *val = NULL;
  261. int len = 0;
  262. switch (ep->tag) {
  263. case MD_PROP_VAL:
  264. val = &ep->d.val;
  265. len = 8;
  266. break;
  267. case MD_PROP_STR:
  268. case MD_PROP_DATA:
  269. val = data + ep->d.data.data_offset;
  270. len = ep->d.data.data_len;
  271. break;
  272. default:
  273. break;
  274. }
  275. if (!val)
  276. continue;
  277. if (!strcmp(names + ep->name_offset, name)) {
  278. if (lenp)
  279. *lenp = len;
  280. return val;
  281. }
  282. }
  283. return NULL;
  284. }
  285. EXPORT_SYMBOL(mdesc_get_property);
  286. u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
  287. {
  288. struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
  289. const char *names = name_block(&hp->mdesc);
  290. u64 last_node = hp->mdesc.node_sz / 16;
  291. if (from == MDESC_NODE_NULL || from >= last_node)
  292. return MDESC_NODE_NULL;
  293. ep = base + from;
  294. ep++;
  295. for (; ep->tag != MD_NODE_END; ep++) {
  296. if (ep->tag != MD_PROP_ARC)
  297. continue;
  298. if (strcmp(names + ep->name_offset, arc_type))
  299. continue;
  300. return ep - base;
  301. }
  302. return MDESC_NODE_NULL;
  303. }
  304. EXPORT_SYMBOL(mdesc_next_arc);
  305. u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
  306. {
  307. struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
  308. ep = base + arc;
  309. return ep->d.val;
  310. }
  311. EXPORT_SYMBOL(mdesc_arc_target);
  312. const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
  313. {
  314. struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
  315. const char *names = name_block(&hp->mdesc);
  316. u64 last_node = hp->mdesc.node_sz / 16;
  317. if (node == MDESC_NODE_NULL || node >= last_node)
  318. return NULL;
  319. ep = base + node;
  320. if (ep->tag != MD_NODE)
  321. return NULL;
  322. return names + ep->name_offset;
  323. }
  324. EXPORT_SYMBOL(mdesc_node_name);
  325. static void __init report_platform_properties(void)
  326. {
  327. struct mdesc_handle *hp = mdesc_grab();
  328. u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
  329. const char *s;
  330. const u64 *v;
  331. if (pn == MDESC_NODE_NULL) {
  332. prom_printf("No platform node in machine-description.\n");
  333. prom_halt();
  334. }
  335. s = mdesc_get_property(hp, pn, "banner-name", NULL);
  336. printk("PLATFORM: banner-name [%s]\n", s);
  337. s = mdesc_get_property(hp, pn, "name", NULL);
  338. printk("PLATFORM: name [%s]\n", s);
  339. v = mdesc_get_property(hp, pn, "hostid", NULL);
  340. if (v)
  341. printk("PLATFORM: hostid [%08lx]\n", *v);
  342. v = mdesc_get_property(hp, pn, "serial#", NULL);
  343. if (v)
  344. printk("PLATFORM: serial# [%08lx]\n", *v);
  345. v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
  346. printk("PLATFORM: stick-frequency [%08lx]\n", *v);
  347. v = mdesc_get_property(hp, pn, "mac-address", NULL);
  348. if (v)
  349. printk("PLATFORM: mac-address [%lx]\n", *v);
  350. v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
  351. if (v)
  352. printk("PLATFORM: watchdog-resolution [%lu ms]\n", *v);
  353. v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
  354. if (v)
  355. printk("PLATFORM: watchdog-max-timeout [%lu ms]\n", *v);
  356. v = mdesc_get_property(hp, pn, "max-cpus", NULL);
  357. if (v)
  358. printk("PLATFORM: max-cpus [%lu]\n", *v);
  359. #ifdef CONFIG_SMP
  360. {
  361. int max_cpu, i;
  362. if (v) {
  363. max_cpu = *v;
  364. if (max_cpu > NR_CPUS)
  365. max_cpu = NR_CPUS;
  366. } else {
  367. max_cpu = NR_CPUS;
  368. }
  369. for (i = 0; i < max_cpu; i++)
  370. cpu_set(i, cpu_possible_map);
  371. }
  372. #endif
  373. mdesc_release(hp);
  374. }
  375. static int inline find_in_proplist(const char *list, const char *match, int len)
  376. {
  377. while (len > 0) {
  378. int l;
  379. if (!strcmp(list, match))
  380. return 1;
  381. l = strlen(list) + 1;
  382. list += l;
  383. len -= l;
  384. }
  385. return 0;
  386. }
  387. static void __devinit fill_in_one_cache(cpuinfo_sparc *c,
  388. struct mdesc_handle *hp,
  389. u64 mp)
  390. {
  391. const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
  392. const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
  393. const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
  394. const char *type;
  395. int type_len;
  396. type = mdesc_get_property(hp, mp, "type", &type_len);
  397. switch (*level) {
  398. case 1:
  399. if (find_in_proplist(type, "instn", type_len)) {
  400. c->icache_size = *size;
  401. c->icache_line_size = *line_size;
  402. } else if (find_in_proplist(type, "data", type_len)) {
  403. c->dcache_size = *size;
  404. c->dcache_line_size = *line_size;
  405. }
  406. break;
  407. case 2:
  408. c->ecache_size = *size;
  409. c->ecache_line_size = *line_size;
  410. break;
  411. default:
  412. break;
  413. }
  414. if (*level == 1) {
  415. u64 a;
  416. mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
  417. u64 target = mdesc_arc_target(hp, a);
  418. const char *name = mdesc_node_name(hp, target);
  419. if (!strcmp(name, "cache"))
  420. fill_in_one_cache(c, hp, target);
  421. }
  422. }
  423. }
  424. static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp,
  425. int core_id)
  426. {
  427. u64 a;
  428. mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
  429. u64 t = mdesc_arc_target(hp, a);
  430. const char *name;
  431. const u64 *id;
  432. name = mdesc_node_name(hp, t);
  433. if (!strcmp(name, "cpu")) {
  434. id = mdesc_get_property(hp, t, "id", NULL);
  435. if (*id < NR_CPUS)
  436. cpu_data(*id).core_id = core_id;
  437. } else {
  438. u64 j;
  439. mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) {
  440. u64 n = mdesc_arc_target(hp, j);
  441. const char *n_name;
  442. n_name = mdesc_node_name(hp, n);
  443. if (strcmp(n_name, "cpu"))
  444. continue;
  445. id = mdesc_get_property(hp, n, "id", NULL);
  446. if (*id < NR_CPUS)
  447. cpu_data(*id).core_id = core_id;
  448. }
  449. }
  450. }
  451. }
  452. static void __devinit set_core_ids(struct mdesc_handle *hp)
  453. {
  454. int idx;
  455. u64 mp;
  456. idx = 1;
  457. mdesc_for_each_node_by_name(hp, mp, "cache") {
  458. const u64 *level;
  459. const char *type;
  460. int len;
  461. level = mdesc_get_property(hp, mp, "level", NULL);
  462. if (*level != 1)
  463. continue;
  464. type = mdesc_get_property(hp, mp, "type", &len);
  465. if (!find_in_proplist(type, "instn", len))
  466. continue;
  467. mark_core_ids(hp, mp, idx);
  468. idx++;
  469. }
  470. }
  471. static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp,
  472. int proc_id)
  473. {
  474. u64 a;
  475. mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
  476. u64 t = mdesc_arc_target(hp, a);
  477. const char *name;
  478. const u64 *id;
  479. name = mdesc_node_name(hp, t);
  480. if (strcmp(name, "cpu"))
  481. continue;
  482. id = mdesc_get_property(hp, t, "id", NULL);
  483. if (*id < NR_CPUS)
  484. cpu_data(*id).proc_id = proc_id;
  485. }
  486. }
  487. static void __devinit __set_proc_ids(struct mdesc_handle *hp,
  488. const char *exec_unit_name)
  489. {
  490. int idx;
  491. u64 mp;
  492. idx = 0;
  493. mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
  494. const char *type;
  495. int len;
  496. type = mdesc_get_property(hp, mp, "type", &len);
  497. if (!find_in_proplist(type, "int", len) &&
  498. !find_in_proplist(type, "integer", len))
  499. continue;
  500. mark_proc_ids(hp, mp, idx);
  501. idx++;
  502. }
  503. }
  504. static void __devinit set_proc_ids(struct mdesc_handle *hp)
  505. {
  506. __set_proc_ids(hp, "exec_unit");
  507. __set_proc_ids(hp, "exec-unit");
  508. }
  509. static void __devinit get_one_mondo_bits(const u64 *p, unsigned int *mask,
  510. unsigned char def)
  511. {
  512. u64 val;
  513. if (!p)
  514. goto use_default;
  515. val = *p;
  516. if (!val || val >= 64)
  517. goto use_default;
  518. *mask = ((1U << val) * 64U) - 1U;
  519. return;
  520. use_default:
  521. *mask = ((1U << def) * 64U) - 1U;
  522. }
  523. static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp,
  524. struct trap_per_cpu *tb)
  525. {
  526. const u64 *val;
  527. val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
  528. get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7);
  529. val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
  530. get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7);
  531. val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
  532. get_one_mondo_bits(val, &tb->resum_qmask, 6);
  533. val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
  534. get_one_mondo_bits(val, &tb->nonresum_qmask, 2);
  535. }
  536. void __devinit mdesc_fill_in_cpu_data(cpumask_t mask)
  537. {
  538. struct mdesc_handle *hp = mdesc_grab();
  539. u64 mp;
  540. ncpus_probed = 0;
  541. mdesc_for_each_node_by_name(hp, mp, "cpu") {
  542. const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
  543. const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
  544. struct trap_per_cpu *tb;
  545. cpuinfo_sparc *c;
  546. int cpuid;
  547. u64 a;
  548. ncpus_probed++;
  549. cpuid = *id;
  550. #ifdef CONFIG_SMP
  551. if (cpuid >= NR_CPUS)
  552. continue;
  553. if (!cpu_isset(cpuid, mask))
  554. continue;
  555. #else
  556. /* On uniprocessor we only want the values for the
  557. * real physical cpu the kernel booted onto, however
  558. * cpu_data() only has one entry at index 0.
  559. */
  560. if (cpuid != real_hard_smp_processor_id())
  561. continue;
  562. cpuid = 0;
  563. #endif
  564. c = &cpu_data(cpuid);
  565. c->clock_tick = *cfreq;
  566. tb = &trap_block[cpuid];
  567. get_mondo_data(hp, mp, tb);
  568. mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
  569. u64 j, t = mdesc_arc_target(hp, a);
  570. const char *t_name;
  571. t_name = mdesc_node_name(hp, t);
  572. if (!strcmp(t_name, "cache")) {
  573. fill_in_one_cache(c, hp, t);
  574. continue;
  575. }
  576. mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
  577. u64 n = mdesc_arc_target(hp, j);
  578. const char *n_name;
  579. n_name = mdesc_node_name(hp, n);
  580. if (!strcmp(n_name, "cache"))
  581. fill_in_one_cache(c, hp, n);
  582. }
  583. }
  584. #ifdef CONFIG_SMP
  585. cpu_set(cpuid, cpu_present_map);
  586. #endif
  587. c->core_id = 0;
  588. c->proc_id = -1;
  589. }
  590. #ifdef CONFIG_SMP
  591. sparc64_multi_core = 1;
  592. #endif
  593. set_core_ids(hp);
  594. set_proc_ids(hp);
  595. smp_fill_in_sib_core_maps();
  596. mdesc_release(hp);
  597. }
  598. void __init sun4v_mdesc_init(void)
  599. {
  600. struct mdesc_handle *hp;
  601. unsigned long len, real_len, status;
  602. cpumask_t mask;
  603. (void) sun4v_mach_desc(0UL, 0UL, &len);
  604. printk("MDESC: Size is %lu bytes.\n", len);
  605. hp = mdesc_alloc(len, &bootmem_mdesc_memops);
  606. if (hp == NULL) {
  607. prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
  608. prom_halt();
  609. }
  610. status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
  611. if (status != HV_EOK || real_len > len) {
  612. prom_printf("sun4v_mach_desc fails, err(%lu), "
  613. "len(%lu), real_len(%lu)\n",
  614. status, len, real_len);
  615. mdesc_free(hp);
  616. prom_halt();
  617. }
  618. cur_mdesc = hp;
  619. report_platform_properties();
  620. cpus_setall(mask);
  621. mdesc_fill_in_cpu_data(mask);
  622. }