dt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * Copyright (C) 2005-2006 Michael Ellerman, IBM Corporation
  3. * Copyright (C) 2000-2004, IBM Corporation
  4. *
  5. * Description:
  6. * This file contains all the routines to build a flattened device
  7. * tree for a legacy iSeries machine.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #undef DEBUG
  15. #include <linux/types.h>
  16. #include <linux/init.h>
  17. #include <linux/pci.h>
  18. #include <linux/pci_regs.h>
  19. #include <linux/pci_ids.h>
  20. #include <linux/threads.h>
  21. #include <linux/bitops.h>
  22. #include <linux/string.h>
  23. #include <linux/kernel.h>
  24. #include <linux/if_ether.h> /* ETH_ALEN */
  25. #include <asm/machdep.h>
  26. #include <asm/prom.h>
  27. #include <asm/lppaca.h>
  28. #include <asm/cputable.h>
  29. #include <asm/abs_addr.h>
  30. #include <asm/system.h>
  31. #include <asm/iseries/hv_types.h>
  32. #include <asm/iseries/hv_lp_config.h>
  33. #include <asm/iseries/hv_call_xm.h>
  34. #include <asm/iseries/it_exp_vpd_panel.h>
  35. #include <asm/udbg.h>
  36. #include "processor_vpd.h"
  37. #include "call_hpt.h"
  38. #include "call_pci.h"
  39. #include "pci.h"
  40. #ifdef DEBUG
  41. #define DBG(fmt...) udbg_printf(fmt)
  42. #else
  43. #define DBG(fmt...)
  44. #endif
  45. /*
  46. * These are created by the linker script at the start and end
  47. * of the section containing all the strings from this file.
  48. */
  49. extern char __dt_strings_start[];
  50. extern char __dt_strings_end[];
  51. struct iseries_flat_dt {
  52. struct boot_param_header header;
  53. u64 reserve_map[2];
  54. };
  55. static void * __initdata dt_data;
  56. /*
  57. * Putting these strings here keeps them out of the section
  58. * that we rename to .dt_strings using objcopy and capture
  59. * for the strings blob of the flattened device tree.
  60. */
  61. static char __initdata device_type_cpu[] = "cpu";
  62. static char __initdata device_type_memory[] = "memory";
  63. static char __initdata device_type_serial[] = "serial";
  64. static char __initdata device_type_network[] = "network";
  65. static char __initdata device_type_block[] = "block";
  66. static char __initdata device_type_byte[] = "byte";
  67. static char __initdata device_type_pci[] = "pci";
  68. static char __initdata device_type_vdevice[] = "vdevice";
  69. static char __initdata device_type_vscsi[] = "vscsi";
  70. /* EBCDIC to ASCII conversion routines */
  71. unsigned char e2a(unsigned char x)
  72. {
  73. switch (x) {
  74. case 0xF0:
  75. return '0';
  76. case 0xF1:
  77. return '1';
  78. case 0xF2:
  79. return '2';
  80. case 0xF3:
  81. return '3';
  82. case 0xF4:
  83. return '4';
  84. case 0xF5:
  85. return '5';
  86. case 0xF6:
  87. return '6';
  88. case 0xF7:
  89. return '7';
  90. case 0xF8:
  91. return '8';
  92. case 0xF9:
  93. return '9';
  94. case 0xC1:
  95. return 'A';
  96. case 0xC2:
  97. return 'B';
  98. case 0xC3:
  99. return 'C';
  100. case 0xC4:
  101. return 'D';
  102. case 0xC5:
  103. return 'E';
  104. case 0xC6:
  105. return 'F';
  106. case 0xC7:
  107. return 'G';
  108. case 0xC8:
  109. return 'H';
  110. case 0xC9:
  111. return 'I';
  112. case 0xD1:
  113. return 'J';
  114. case 0xD2:
  115. return 'K';
  116. case 0xD3:
  117. return 'L';
  118. case 0xD4:
  119. return 'M';
  120. case 0xD5:
  121. return 'N';
  122. case 0xD6:
  123. return 'O';
  124. case 0xD7:
  125. return 'P';
  126. case 0xD8:
  127. return 'Q';
  128. case 0xD9:
  129. return 'R';
  130. case 0xE2:
  131. return 'S';
  132. case 0xE3:
  133. return 'T';
  134. case 0xE4:
  135. return 'U';
  136. case 0xE5:
  137. return 'V';
  138. case 0xE6:
  139. return 'W';
  140. case 0xE7:
  141. return 'X';
  142. case 0xE8:
  143. return 'Y';
  144. case 0xE9:
  145. return 'Z';
  146. }
  147. return ' ';
  148. }
  149. EXPORT_SYMBOL(e2a);
  150. unsigned char* strne2a(unsigned char *dest, const unsigned char *src, size_t n)
  151. {
  152. int i;
  153. n = strnlen(src, n);
  154. for (i = 0; i < n; i++)
  155. dest[i] = e2a(src[i]);
  156. return dest;
  157. }
  158. static struct iseries_flat_dt * __init dt_init(void)
  159. {
  160. struct iseries_flat_dt *dt;
  161. unsigned long str_len;
  162. str_len = __dt_strings_end - __dt_strings_start;
  163. dt = (struct iseries_flat_dt *)ALIGN(klimit, 8);
  164. dt->header.off_mem_rsvmap =
  165. offsetof(struct iseries_flat_dt, reserve_map);
  166. dt->header.off_dt_strings = ALIGN(sizeof(*dt), 8);
  167. dt->header.off_dt_struct = dt->header.off_dt_strings
  168. + ALIGN(str_len, 8);
  169. dt_data = (void *)((unsigned long)dt + dt->header.off_dt_struct);
  170. dt->header.dt_strings_size = str_len;
  171. /* There is no notion of hardware cpu id on iSeries */
  172. dt->header.boot_cpuid_phys = smp_processor_id();
  173. memcpy((char *)dt + dt->header.off_dt_strings, __dt_strings_start,
  174. str_len);
  175. dt->header.magic = OF_DT_HEADER;
  176. dt->header.version = 0x10;
  177. dt->header.last_comp_version = 0x10;
  178. dt->reserve_map[0] = 0;
  179. dt->reserve_map[1] = 0;
  180. return dt;
  181. }
  182. static void __init dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  183. {
  184. *((u32 *)dt_data) = value;
  185. dt_data += sizeof(u32);
  186. }
  187. #ifdef notyet
  188. static void __init dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  189. {
  190. *((u64 *)dt_data) = value;
  191. dt_data += sizeof(u64);
  192. }
  193. #endif
  194. static void __init dt_push_bytes(struct iseries_flat_dt *dt, const char *data,
  195. int len)
  196. {
  197. memcpy(dt_data, data, len);
  198. dt_data += ALIGN(len, 4);
  199. }
  200. static void __init dt_start_node(struct iseries_flat_dt *dt, const char *name)
  201. {
  202. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  203. dt_push_bytes(dt, name, strlen(name) + 1);
  204. }
  205. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  206. static void __init dt_prop(struct iseries_flat_dt *dt, const char *name,
  207. const void *data, int len)
  208. {
  209. unsigned long offset;
  210. dt_push_u32(dt, OF_DT_PROP);
  211. /* Length of the data */
  212. dt_push_u32(dt, len);
  213. offset = name - __dt_strings_start;
  214. /* The offset of the properties name in the string blob. */
  215. dt_push_u32(dt, (u32)offset);
  216. /* The actual data. */
  217. dt_push_bytes(dt, data, len);
  218. }
  219. static void __init dt_prop_str(struct iseries_flat_dt *dt, const char *name,
  220. const char *data)
  221. {
  222. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  223. }
  224. static void __init dt_prop_u32(struct iseries_flat_dt *dt, const char *name,
  225. u32 data)
  226. {
  227. dt_prop(dt, name, &data, sizeof(u32));
  228. }
  229. #ifdef notyet
  230. static void __init dt_prop_u64(struct iseries_flat_dt *dt, const char *name,
  231. u64 data)
  232. {
  233. dt_prop(dt, name, &data, sizeof(u64));
  234. }
  235. #endif
  236. static void __init dt_prop_u64_list(struct iseries_flat_dt *dt,
  237. const char *name, u64 *data, int n)
  238. {
  239. dt_prop(dt, name, data, sizeof(u64) * n);
  240. }
  241. static void __init dt_prop_u32_list(struct iseries_flat_dt *dt,
  242. const char *name, u32 *data, int n)
  243. {
  244. dt_prop(dt, name, data, sizeof(u32) * n);
  245. }
  246. #ifdef notyet
  247. static void __init dt_prop_empty(struct iseries_flat_dt *dt, const char *name)
  248. {
  249. dt_prop(dt, name, NULL, 0);
  250. }
  251. #endif
  252. static void __init dt_cpus(struct iseries_flat_dt *dt)
  253. {
  254. unsigned char buf[32];
  255. unsigned char *p;
  256. unsigned int i, index;
  257. struct IoHriProcessorVpd *d;
  258. u32 pft_size[2];
  259. /* yuck */
  260. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  261. p = strchr(buf, ' ');
  262. if (!p) p = buf + strlen(buf);
  263. dt_start_node(dt, "cpus");
  264. dt_prop_u32(dt, "#address-cells", 1);
  265. dt_prop_u32(dt, "#size-cells", 0);
  266. pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */
  267. pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
  268. for (i = 0; i < NR_CPUS; i++) {
  269. if (lppaca[i].dyn_proc_status >= 2)
  270. continue;
  271. snprintf(p, 32 - (p - buf), "@%d", i);
  272. dt_start_node(dt, buf);
  273. dt_prop_str(dt, "device_type", device_type_cpu);
  274. index = lppaca[i].dyn_hv_phys_proc_index;
  275. d = &xIoHriProcessorVpd[index];
  276. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  277. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  278. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  279. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  280. /* magic conversions to Hz copied from old code */
  281. dt_prop_u32(dt, "clock-frequency",
  282. ((1UL << 34) * 1000000) / d->xProcFreq);
  283. dt_prop_u32(dt, "timebase-frequency",
  284. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  285. dt_prop_u32(dt, "reg", i);
  286. dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
  287. dt_end_node(dt);
  288. }
  289. dt_end_node(dt);
  290. }
  291. static void __init dt_model(struct iseries_flat_dt *dt)
  292. {
  293. char buf[16] = "IBM,";
  294. /* N.B. lparcfg.c knows about the "IBM," prefixes ... */
  295. /* "IBM," + mfgId[2:3] + systemSerial[1:5] */
  296. strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2);
  297. strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5);
  298. buf[11] = '\0';
  299. dt_prop_str(dt, "system-id", buf);
  300. /* "IBM," + machineType[0:4] */
  301. strne2a(buf + 4, xItExtVpdPanel.machineType, 4);
  302. buf[8] = '\0';
  303. dt_prop_str(dt, "model", buf);
  304. dt_prop_str(dt, "compatible", "IBM,iSeries");
  305. dt_prop_u32(dt, "ibm,partition-no", HvLpConfig_getLpIndex());
  306. }
  307. static void __init dt_do_vdevice(struct iseries_flat_dt *dt,
  308. const char *name, u32 reg, int unit,
  309. const char *type, const char *compat, int end)
  310. {
  311. char buf[32];
  312. snprintf(buf, 32, "%s@%08x", name, reg + ((unit >= 0) ? unit : 0));
  313. dt_start_node(dt, buf);
  314. dt_prop_str(dt, "device_type", type);
  315. if (compat)
  316. dt_prop_str(dt, "compatible", compat);
  317. dt_prop_u32(dt, "reg", reg + ((unit >= 0) ? unit : 0));
  318. if (unit >= 0)
  319. dt_prop_u32(dt, "linux,unit_address", unit);
  320. if (end)
  321. dt_end_node(dt);
  322. }
  323. static void __init dt_vdevices(struct iseries_flat_dt *dt)
  324. {
  325. u32 reg = 0;
  326. HvLpIndexMap vlan_map;
  327. int i;
  328. dt_start_node(dt, "vdevice");
  329. dt_prop_str(dt, "device_type", device_type_vdevice);
  330. dt_prop_str(dt, "compatible", "IBM,iSeries-vdevice");
  331. dt_prop_u32(dt, "#address-cells", 1);
  332. dt_prop_u32(dt, "#size-cells", 0);
  333. dt_do_vdevice(dt, "vty", reg, -1, device_type_serial, NULL, 1);
  334. reg++;
  335. dt_do_vdevice(dt, "v-scsi", reg, -1, device_type_vscsi,
  336. "IBM,v-scsi", 1);
  337. reg++;
  338. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  339. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  340. unsigned char mac_addr[ETH_ALEN];
  341. if ((vlan_map & (0x8000 >> i)) == 0)
  342. continue;
  343. dt_do_vdevice(dt, "l-lan", reg, i, device_type_network,
  344. "IBM,iSeries-l-lan", 0);
  345. mac_addr[0] = 0x02;
  346. mac_addr[1] = 0x01;
  347. mac_addr[2] = 0xff;
  348. mac_addr[3] = i;
  349. mac_addr[4] = 0xff;
  350. mac_addr[5] = HvLpConfig_getLpIndex_outline();
  351. dt_prop(dt, "local-mac-address", (char *)mac_addr, ETH_ALEN);
  352. dt_prop(dt, "mac-address", (char *)mac_addr, ETH_ALEN);
  353. dt_prop_u32(dt, "max-frame-size", 9000);
  354. dt_prop_u32(dt, "address-bits", 48);
  355. dt_end_node(dt);
  356. }
  357. reg += HVMAXARCHITECTEDVIRTUALLANS;
  358. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
  359. dt_do_vdevice(dt, "viodasd", reg, i, device_type_block,
  360. "IBM,iSeries-viodasd", 1);
  361. reg += HVMAXARCHITECTEDVIRTUALDISKS;
  362. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
  363. dt_do_vdevice(dt, "viocd", reg, i, device_type_block,
  364. "IBM,iSeries-viocd", 1);
  365. reg += HVMAXARCHITECTEDVIRTUALCDROMS;
  366. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
  367. dt_do_vdevice(dt, "viotape", reg, i, device_type_byte,
  368. "IBM,iSeries-viotape", 1);
  369. dt_end_node(dt);
  370. }
  371. struct pci_class_name {
  372. u16 code;
  373. const char *name;
  374. const char *type;
  375. };
  376. static struct pci_class_name __initdata pci_class_name[] = {
  377. { PCI_CLASS_NETWORK_ETHERNET, "ethernet", device_type_network },
  378. };
  379. static struct pci_class_name * __init dt_find_pci_class_name(u16 class_code)
  380. {
  381. struct pci_class_name *cp;
  382. for (cp = pci_class_name;
  383. cp < &pci_class_name[ARRAY_SIZE(pci_class_name)]; cp++)
  384. if (cp->code == class_code)
  385. return cp;
  386. return NULL;
  387. }
  388. /*
  389. * This assumes that the node slot is always on the primary bus!
  390. */
  391. static void __init scan_bridge_slot(struct iseries_flat_dt *dt,
  392. HvBusNumber bus, struct HvCallPci_BridgeInfo *bridge_info)
  393. {
  394. HvSubBusNumber sub_bus = bridge_info->subBusNumber;
  395. u16 vendor_id;
  396. u16 device_id;
  397. u32 class_id;
  398. int err;
  399. char buf[32];
  400. u32 reg[5];
  401. int id_sel = ISERIES_GET_DEVICE_FROM_SUBBUS(sub_bus);
  402. int function = ISERIES_GET_FUNCTION_FROM_SUBBUS(sub_bus);
  403. HvAgentId eads_id_sel = ISERIES_PCI_AGENTID(id_sel, function);
  404. u8 devfn;
  405. struct pci_class_name *cp;
  406. /*
  407. * Connect all functions of any device found.
  408. */
  409. for (id_sel = 1; id_sel <= bridge_info->maxAgents; id_sel++) {
  410. for (function = 0; function < 8; function++) {
  411. HvAgentId agent_id = ISERIES_PCI_AGENTID(id_sel,
  412. function);
  413. err = HvCallXm_connectBusUnit(bus, sub_bus,
  414. agent_id, 0);
  415. if (err) {
  416. if (err != 0x302)
  417. DBG("connectBusUnit(%x, %x, %x) %x\n",
  418. bus, sub_bus, agent_id, err);
  419. continue;
  420. }
  421. err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
  422. PCI_VENDOR_ID, &vendor_id);
  423. if (err) {
  424. DBG("ReadVendor(%x, %x, %x) %x\n",
  425. bus, sub_bus, agent_id, err);
  426. continue;
  427. }
  428. err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
  429. PCI_DEVICE_ID, &device_id);
  430. if (err) {
  431. DBG("ReadDevice(%x, %x, %x) %x\n",
  432. bus, sub_bus, agent_id, err);
  433. continue;
  434. }
  435. err = HvCallPci_configLoad32(bus, sub_bus, agent_id,
  436. PCI_CLASS_REVISION , &class_id);
  437. if (err) {
  438. DBG("ReadClass(%x, %x, %x) %x\n",
  439. bus, sub_bus, agent_id, err);
  440. continue;
  441. }
  442. devfn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(eads_id_sel),
  443. function);
  444. cp = dt_find_pci_class_name(class_id >> 16);
  445. if (cp && cp->name)
  446. strncpy(buf, cp->name, sizeof(buf) - 1);
  447. else
  448. snprintf(buf, sizeof(buf), "pci%x,%x",
  449. vendor_id, device_id);
  450. buf[sizeof(buf) - 1] = '\0';
  451. snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
  452. "@%x", PCI_SLOT(devfn));
  453. buf[sizeof(buf) - 1] = '\0';
  454. if (function != 0)
  455. snprintf(buf + strlen(buf),
  456. sizeof(buf) - strlen(buf),
  457. ",%x", function);
  458. dt_start_node(dt, buf);
  459. reg[0] = (bus << 16) | (devfn << 8);
  460. reg[1] = 0;
  461. reg[2] = 0;
  462. reg[3] = 0;
  463. reg[4] = 0;
  464. dt_prop_u32_list(dt, "reg", reg, 5);
  465. if (cp && (cp->type || cp->name))
  466. dt_prop_str(dt, "device_type",
  467. cp->type ? cp->type : cp->name);
  468. dt_prop_u32(dt, "vendor-id", vendor_id);
  469. dt_prop_u32(dt, "device-id", device_id);
  470. dt_prop_u32(dt, "class-code", class_id >> 8);
  471. dt_prop_u32(dt, "revision-id", class_id & 0xff);
  472. dt_prop_u32(dt, "linux,subbus", sub_bus);
  473. dt_prop_u32(dt, "linux,agent-id", agent_id);
  474. dt_prop_u32(dt, "linux,logical-slot-number",
  475. bridge_info->logicalSlotNumber);
  476. dt_end_node(dt);
  477. }
  478. }
  479. }
  480. static void __init scan_bridge(struct iseries_flat_dt *dt, HvBusNumber bus,
  481. HvSubBusNumber sub_bus, int id_sel)
  482. {
  483. struct HvCallPci_BridgeInfo bridge_info;
  484. HvAgentId agent_id;
  485. int function;
  486. int ret;
  487. /* Note: hvSubBus and irq is always be 0 at this level! */
  488. for (function = 0; function < 8; ++function) {
  489. agent_id = ISERIES_PCI_AGENTID(id_sel, function);
  490. ret = HvCallXm_connectBusUnit(bus, sub_bus, agent_id, 0);
  491. if (ret != 0) {
  492. if (ret != 0xb)
  493. DBG("connectBusUnit(%x, %x, %x) %x\n",
  494. bus, sub_bus, agent_id, ret);
  495. continue;
  496. }
  497. DBG("found device at bus %d idsel %d func %d (AgentId %x)\n",
  498. bus, id_sel, function, agent_id);
  499. ret = HvCallPci_getBusUnitInfo(bus, sub_bus, agent_id,
  500. iseries_hv_addr(&bridge_info),
  501. sizeof(struct HvCallPci_BridgeInfo));
  502. if (ret != 0)
  503. continue;
  504. DBG("bridge info: type %x subbus %x "
  505. "maxAgents %x maxsubbus %x logslot %x\n",
  506. bridge_info.busUnitInfo.deviceType,
  507. bridge_info.subBusNumber,
  508. bridge_info.maxAgents,
  509. bridge_info.maxSubBusNumber,
  510. bridge_info.logicalSlotNumber);
  511. if (bridge_info.busUnitInfo.deviceType ==
  512. HvCallPci_BridgeDevice)
  513. scan_bridge_slot(dt, bus, &bridge_info);
  514. else
  515. DBG("PCI: Invalid Bridge Configuration(0x%02X)",
  516. bridge_info.busUnitInfo.deviceType);
  517. }
  518. }
  519. static void __init scan_phb(struct iseries_flat_dt *dt, HvBusNumber bus)
  520. {
  521. struct HvCallPci_DeviceInfo dev_info;
  522. const HvSubBusNumber sub_bus = 0; /* EADs is always 0. */
  523. int err;
  524. int id_sel;
  525. const int max_agents = 8;
  526. /*
  527. * Probe for EADs Bridges
  528. */
  529. for (id_sel = 1; id_sel < max_agents; ++id_sel) {
  530. err = HvCallPci_getDeviceInfo(bus, sub_bus, id_sel,
  531. iseries_hv_addr(&dev_info),
  532. sizeof(struct HvCallPci_DeviceInfo));
  533. if (err) {
  534. if (err != 0x302)
  535. DBG("getDeviceInfo(%x, %x, %x) %x\n",
  536. bus, sub_bus, id_sel, err);
  537. continue;
  538. }
  539. if (dev_info.deviceType != HvCallPci_NodeDevice) {
  540. DBG("PCI: Invalid System Configuration"
  541. "(0x%02X) for bus 0x%02x id 0x%02x.\n",
  542. dev_info.deviceType, bus, id_sel);
  543. continue;
  544. }
  545. scan_bridge(dt, bus, sub_bus, id_sel);
  546. }
  547. }
  548. static void __init dt_pci_devices(struct iseries_flat_dt *dt)
  549. {
  550. HvBusNumber bus;
  551. char buf[32];
  552. u32 buses[2];
  553. int phb_num = 0;
  554. /* Check all possible buses. */
  555. for (bus = 0; bus < 256; bus++) {
  556. int err = HvCallXm_testBus(bus);
  557. if (err) {
  558. /*
  559. * Check for Unexpected Return code, a clue that
  560. * something has gone wrong.
  561. */
  562. if (err != 0x0301)
  563. DBG("Unexpected Return on Probe(0x%02X) "
  564. "0x%04X\n", bus, err);
  565. continue;
  566. }
  567. DBG("bus %d appears to exist\n", bus);
  568. snprintf(buf, 32, "pci@%d", phb_num);
  569. dt_start_node(dt, buf);
  570. dt_prop_str(dt, "device_type", device_type_pci);
  571. dt_prop_str(dt, "compatible", "IBM,iSeries-Logical-PHB");
  572. dt_prop_u32(dt, "#address-cells", 3);
  573. dt_prop_u32(dt, "#size-cells", 2);
  574. buses[0] = buses[1] = bus;
  575. dt_prop_u32_list(dt, "bus-range", buses, 2);
  576. scan_phb(dt, bus);
  577. dt_end_node(dt);
  578. phb_num++;
  579. }
  580. }
  581. static void dt_finish(struct iseries_flat_dt *dt)
  582. {
  583. dt_push_u32(dt, OF_DT_END);
  584. dt->header.totalsize = (unsigned long)dt_data - (unsigned long)dt;
  585. klimit = ALIGN((unsigned long)dt_data, 8);
  586. }
  587. void * __init build_flat_dt(unsigned long phys_mem_size)
  588. {
  589. struct iseries_flat_dt *iseries_dt;
  590. u64 tmp[2];
  591. iseries_dt = dt_init();
  592. dt_start_node(iseries_dt, "");
  593. dt_prop_u32(iseries_dt, "#address-cells", 2);
  594. dt_prop_u32(iseries_dt, "#size-cells", 2);
  595. dt_model(iseries_dt);
  596. /* /memory */
  597. dt_start_node(iseries_dt, "memory@0");
  598. dt_prop_str(iseries_dt, "device_type", device_type_memory);
  599. tmp[0] = 0;
  600. tmp[1] = phys_mem_size;
  601. dt_prop_u64_list(iseries_dt, "reg", tmp, 2);
  602. dt_end_node(iseries_dt);
  603. /* /chosen */
  604. dt_start_node(iseries_dt, "chosen");
  605. dt_prop_str(iseries_dt, "bootargs", cmd_line);
  606. dt_end_node(iseries_dt);
  607. dt_cpus(iseries_dt);
  608. dt_vdevices(iseries_dt);
  609. dt_pci_devices(iseries_dt);
  610. dt_end_node(iseries_dt);
  611. dt_finish(iseries_dt);
  612. return iseries_dt;
  613. }