dt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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/udbg.h>
  35. #include "processor_vpd.h"
  36. #include "call_hpt.h"
  37. #include "call_pci.h"
  38. #include "pci.h"
  39. #include "it_exp_vpd_panel.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. static unsigned char __init e2a(unsigned char x)
  72. {
  73. switch (x) {
  74. case 0x81 ... 0x89:
  75. return x - 0x81 + 'a';
  76. case 0x91 ... 0x99:
  77. return x - 0x91 + 'j';
  78. case 0xA2 ... 0xA9:
  79. return x - 0xA2 + 's';
  80. case 0xC1 ... 0xC9:
  81. return x - 0xC1 + 'A';
  82. case 0xD1 ... 0xD9:
  83. return x - 0xD1 + 'J';
  84. case 0xE2 ... 0xE9:
  85. return x - 0xE2 + 'S';
  86. case 0xF0 ... 0xF9:
  87. return x - 0xF0 + '0';
  88. }
  89. return ' ';
  90. }
  91. static unsigned char * __init strne2a(unsigned char *dest,
  92. const unsigned char *src, size_t n)
  93. {
  94. int i;
  95. n = strnlen(src, n);
  96. for (i = 0; i < n; i++)
  97. dest[i] = e2a(src[i]);
  98. return dest;
  99. }
  100. static struct iseries_flat_dt * __init dt_init(void)
  101. {
  102. struct iseries_flat_dt *dt;
  103. unsigned long str_len;
  104. str_len = __dt_strings_end - __dt_strings_start;
  105. dt = (struct iseries_flat_dt *)ALIGN(klimit, 8);
  106. dt->header.off_mem_rsvmap =
  107. offsetof(struct iseries_flat_dt, reserve_map);
  108. dt->header.off_dt_strings = ALIGN(sizeof(*dt), 8);
  109. dt->header.off_dt_struct = dt->header.off_dt_strings
  110. + ALIGN(str_len, 8);
  111. dt_data = (void *)((unsigned long)dt + dt->header.off_dt_struct);
  112. dt->header.dt_strings_size = str_len;
  113. /* There is no notion of hardware cpu id on iSeries */
  114. dt->header.boot_cpuid_phys = smp_processor_id();
  115. memcpy((char *)dt + dt->header.off_dt_strings, __dt_strings_start,
  116. str_len);
  117. dt->header.magic = OF_DT_HEADER;
  118. dt->header.version = 0x10;
  119. dt->header.last_comp_version = 0x10;
  120. dt->reserve_map[0] = 0;
  121. dt->reserve_map[1] = 0;
  122. return dt;
  123. }
  124. static void __init dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  125. {
  126. *((u32 *)dt_data) = value;
  127. dt_data += sizeof(u32);
  128. }
  129. #ifdef notyet
  130. static void __init dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  131. {
  132. *((u64 *)dt_data) = value;
  133. dt_data += sizeof(u64);
  134. }
  135. #endif
  136. static void __init dt_push_bytes(struct iseries_flat_dt *dt, const char *data,
  137. int len)
  138. {
  139. memcpy(dt_data, data, len);
  140. dt_data += ALIGN(len, 4);
  141. }
  142. static void __init dt_start_node(struct iseries_flat_dt *dt, const char *name)
  143. {
  144. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  145. dt_push_bytes(dt, name, strlen(name) + 1);
  146. }
  147. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  148. static void __init dt_prop(struct iseries_flat_dt *dt, const char *name,
  149. const void *data, int len)
  150. {
  151. unsigned long offset;
  152. dt_push_u32(dt, OF_DT_PROP);
  153. /* Length of the data */
  154. dt_push_u32(dt, len);
  155. offset = name - __dt_strings_start;
  156. /* The offset of the properties name in the string blob. */
  157. dt_push_u32(dt, (u32)offset);
  158. /* The actual data. */
  159. dt_push_bytes(dt, data, len);
  160. }
  161. static void __init dt_prop_str(struct iseries_flat_dt *dt, const char *name,
  162. const char *data)
  163. {
  164. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  165. }
  166. static void __init dt_prop_u32(struct iseries_flat_dt *dt, const char *name,
  167. u32 data)
  168. {
  169. dt_prop(dt, name, &data, sizeof(u32));
  170. }
  171. #ifdef notyet
  172. static void __init dt_prop_u64(struct iseries_flat_dt *dt, const char *name,
  173. u64 data)
  174. {
  175. dt_prop(dt, name, &data, sizeof(u64));
  176. }
  177. #endif
  178. static void __init dt_prop_u64_list(struct iseries_flat_dt *dt,
  179. const char *name, u64 *data, int n)
  180. {
  181. dt_prop(dt, name, data, sizeof(u64) * n);
  182. }
  183. static void __init dt_prop_u32_list(struct iseries_flat_dt *dt,
  184. const char *name, u32 *data, int n)
  185. {
  186. dt_prop(dt, name, data, sizeof(u32) * n);
  187. }
  188. #ifdef notyet
  189. static void __init dt_prop_empty(struct iseries_flat_dt *dt, const char *name)
  190. {
  191. dt_prop(dt, name, NULL, 0);
  192. }
  193. #endif
  194. static void __init dt_cpus(struct iseries_flat_dt *dt)
  195. {
  196. unsigned char buf[32];
  197. unsigned char *p;
  198. unsigned int i, index;
  199. struct IoHriProcessorVpd *d;
  200. u32 pft_size[2];
  201. /* yuck */
  202. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  203. p = strchr(buf, ' ');
  204. if (!p) p = buf + strlen(buf);
  205. dt_start_node(dt, "cpus");
  206. dt_prop_u32(dt, "#address-cells", 1);
  207. dt_prop_u32(dt, "#size-cells", 0);
  208. pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */
  209. pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
  210. for (i = 0; i < NR_CPUS; i++) {
  211. if (lppaca[i].dyn_proc_status >= 2)
  212. continue;
  213. snprintf(p, 32 - (p - buf), "@%d", i);
  214. dt_start_node(dt, buf);
  215. dt_prop_str(dt, "device_type", device_type_cpu);
  216. index = lppaca[i].dyn_hv_phys_proc_index;
  217. d = &xIoHriProcessorVpd[index];
  218. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  219. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  220. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  221. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  222. /* magic conversions to Hz copied from old code */
  223. dt_prop_u32(dt, "clock-frequency",
  224. ((1UL << 34) * 1000000) / d->xProcFreq);
  225. dt_prop_u32(dt, "timebase-frequency",
  226. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  227. dt_prop_u32(dt, "reg", i);
  228. dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
  229. dt_end_node(dt);
  230. }
  231. dt_end_node(dt);
  232. }
  233. static void __init dt_model(struct iseries_flat_dt *dt)
  234. {
  235. char buf[16] = "IBM,";
  236. /* N.B. lparcfg.c knows about the "IBM," prefixes ... */
  237. /* "IBM," + mfgId[2:3] + systemSerial[1:5] */
  238. strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2);
  239. strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5);
  240. buf[11] = '\0';
  241. dt_prop_str(dt, "system-id", buf);
  242. /* "IBM," + machineType[0:4] */
  243. strne2a(buf + 4, xItExtVpdPanel.machineType, 4);
  244. buf[8] = '\0';
  245. dt_prop_str(dt, "model", buf);
  246. dt_prop_str(dt, "compatible", "IBM,iSeries");
  247. dt_prop_u32(dt, "ibm,partition-no", HvLpConfig_getLpIndex());
  248. }
  249. static void __init dt_do_vdevice(struct iseries_flat_dt *dt,
  250. const char *name, u32 reg, int unit,
  251. const char *type, const char *compat, int end)
  252. {
  253. char buf[32];
  254. snprintf(buf, 32, "%s@%08x", name, reg + ((unit >= 0) ? unit : 0));
  255. dt_start_node(dt, buf);
  256. dt_prop_str(dt, "device_type", type);
  257. if (compat)
  258. dt_prop_str(dt, "compatible", compat);
  259. dt_prop_u32(dt, "reg", reg + ((unit >= 0) ? unit : 0));
  260. if (unit >= 0)
  261. dt_prop_u32(dt, "linux,unit_address", unit);
  262. if (end)
  263. dt_end_node(dt);
  264. }
  265. static void __init dt_vdevices(struct iseries_flat_dt *dt)
  266. {
  267. u32 reg = 0;
  268. HvLpIndexMap vlan_map;
  269. int i;
  270. dt_start_node(dt, "vdevice");
  271. dt_prop_str(dt, "device_type", device_type_vdevice);
  272. dt_prop_str(dt, "compatible", "IBM,iSeries-vdevice");
  273. dt_prop_u32(dt, "#address-cells", 1);
  274. dt_prop_u32(dt, "#size-cells", 0);
  275. dt_do_vdevice(dt, "vty", reg, -1, device_type_serial,
  276. "IBM,iSeries-vty", 1);
  277. reg++;
  278. dt_do_vdevice(dt, "v-scsi", reg, -1, device_type_vscsi,
  279. "IBM,v-scsi", 1);
  280. reg++;
  281. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  282. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  283. unsigned char mac_addr[ETH_ALEN];
  284. if ((vlan_map & (0x8000 >> i)) == 0)
  285. continue;
  286. dt_do_vdevice(dt, "l-lan", reg, i, device_type_network,
  287. "IBM,iSeries-l-lan", 0);
  288. mac_addr[0] = 0x02;
  289. mac_addr[1] = 0x01;
  290. mac_addr[2] = 0xff;
  291. mac_addr[3] = i;
  292. mac_addr[4] = 0xff;
  293. mac_addr[5] = HvLpConfig_getLpIndex_outline();
  294. dt_prop(dt, "local-mac-address", (char *)mac_addr, ETH_ALEN);
  295. dt_prop(dt, "mac-address", (char *)mac_addr, ETH_ALEN);
  296. dt_prop_u32(dt, "max-frame-size", 9000);
  297. dt_prop_u32(dt, "address-bits", 48);
  298. dt_end_node(dt);
  299. }
  300. reg += HVMAXARCHITECTEDVIRTUALLANS;
  301. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
  302. dt_do_vdevice(dt, "viodasd", reg, i, device_type_block,
  303. "IBM,iSeries-viodasd", 1);
  304. reg += HVMAXARCHITECTEDVIRTUALDISKS;
  305. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
  306. dt_do_vdevice(dt, "viocd", reg, i, device_type_block,
  307. "IBM,iSeries-viocd", 1);
  308. reg += HVMAXARCHITECTEDVIRTUALCDROMS;
  309. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
  310. dt_do_vdevice(dt, "viotape", reg, i, device_type_byte,
  311. "IBM,iSeries-viotape", 1);
  312. dt_end_node(dt);
  313. }
  314. struct pci_class_name {
  315. u16 code;
  316. const char *name;
  317. const char *type;
  318. };
  319. static struct pci_class_name __initdata pci_class_name[] = {
  320. { PCI_CLASS_NETWORK_ETHERNET, "ethernet", device_type_network },
  321. };
  322. static struct pci_class_name * __init dt_find_pci_class_name(u16 class_code)
  323. {
  324. struct pci_class_name *cp;
  325. for (cp = pci_class_name;
  326. cp < &pci_class_name[ARRAY_SIZE(pci_class_name)]; cp++)
  327. if (cp->code == class_code)
  328. return cp;
  329. return NULL;
  330. }
  331. /*
  332. * This assumes that the node slot is always on the primary bus!
  333. */
  334. static void __init scan_bridge_slot(struct iseries_flat_dt *dt,
  335. HvBusNumber bus, struct HvCallPci_BridgeInfo *bridge_info)
  336. {
  337. HvSubBusNumber sub_bus = bridge_info->subBusNumber;
  338. u16 vendor_id;
  339. u16 device_id;
  340. u32 class_id;
  341. int err;
  342. char buf[32];
  343. u32 reg[5];
  344. int id_sel = ISERIES_GET_DEVICE_FROM_SUBBUS(sub_bus);
  345. int function = ISERIES_GET_FUNCTION_FROM_SUBBUS(sub_bus);
  346. HvAgentId eads_id_sel = ISERIES_PCI_AGENTID(id_sel, function);
  347. u8 devfn;
  348. struct pci_class_name *cp;
  349. /*
  350. * Connect all functions of any device found.
  351. */
  352. for (id_sel = 1; id_sel <= bridge_info->maxAgents; id_sel++) {
  353. for (function = 0; function < 8; function++) {
  354. HvAgentId agent_id = ISERIES_PCI_AGENTID(id_sel,
  355. function);
  356. err = HvCallXm_connectBusUnit(bus, sub_bus,
  357. agent_id, 0);
  358. if (err) {
  359. if (err != 0x302)
  360. DBG("connectBusUnit(%x, %x, %x) %x\n",
  361. bus, sub_bus, agent_id, err);
  362. continue;
  363. }
  364. err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
  365. PCI_VENDOR_ID, &vendor_id);
  366. if (err) {
  367. DBG("ReadVendor(%x, %x, %x) %x\n",
  368. bus, sub_bus, agent_id, err);
  369. continue;
  370. }
  371. err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
  372. PCI_DEVICE_ID, &device_id);
  373. if (err) {
  374. DBG("ReadDevice(%x, %x, %x) %x\n",
  375. bus, sub_bus, agent_id, err);
  376. continue;
  377. }
  378. err = HvCallPci_configLoad32(bus, sub_bus, agent_id,
  379. PCI_CLASS_REVISION , &class_id);
  380. if (err) {
  381. DBG("ReadClass(%x, %x, %x) %x\n",
  382. bus, sub_bus, agent_id, err);
  383. continue;
  384. }
  385. devfn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(eads_id_sel),
  386. function);
  387. cp = dt_find_pci_class_name(class_id >> 16);
  388. if (cp && cp->name)
  389. strncpy(buf, cp->name, sizeof(buf) - 1);
  390. else
  391. snprintf(buf, sizeof(buf), "pci%x,%x",
  392. vendor_id, device_id);
  393. buf[sizeof(buf) - 1] = '\0';
  394. snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
  395. "@%x", PCI_SLOT(devfn));
  396. buf[sizeof(buf) - 1] = '\0';
  397. if (function != 0)
  398. snprintf(buf + strlen(buf),
  399. sizeof(buf) - strlen(buf),
  400. ",%x", function);
  401. dt_start_node(dt, buf);
  402. reg[0] = (bus << 16) | (devfn << 8);
  403. reg[1] = 0;
  404. reg[2] = 0;
  405. reg[3] = 0;
  406. reg[4] = 0;
  407. dt_prop_u32_list(dt, "reg", reg, 5);
  408. if (cp && (cp->type || cp->name))
  409. dt_prop_str(dt, "device_type",
  410. cp->type ? cp->type : cp->name);
  411. dt_prop_u32(dt, "vendor-id", vendor_id);
  412. dt_prop_u32(dt, "device-id", device_id);
  413. dt_prop_u32(dt, "class-code", class_id >> 8);
  414. dt_prop_u32(dt, "revision-id", class_id & 0xff);
  415. dt_prop_u32(dt, "linux,subbus", sub_bus);
  416. dt_prop_u32(dt, "linux,agent-id", agent_id);
  417. dt_prop_u32(dt, "linux,logical-slot-number",
  418. bridge_info->logicalSlotNumber);
  419. dt_end_node(dt);
  420. }
  421. }
  422. }
  423. static void __init scan_bridge(struct iseries_flat_dt *dt, HvBusNumber bus,
  424. HvSubBusNumber sub_bus, int id_sel)
  425. {
  426. struct HvCallPci_BridgeInfo bridge_info;
  427. HvAgentId agent_id;
  428. int function;
  429. int ret;
  430. /* Note: hvSubBus and irq is always be 0 at this level! */
  431. for (function = 0; function < 8; ++function) {
  432. agent_id = ISERIES_PCI_AGENTID(id_sel, function);
  433. ret = HvCallXm_connectBusUnit(bus, sub_bus, agent_id, 0);
  434. if (ret != 0) {
  435. if (ret != 0xb)
  436. DBG("connectBusUnit(%x, %x, %x) %x\n",
  437. bus, sub_bus, agent_id, ret);
  438. continue;
  439. }
  440. DBG("found device at bus %d idsel %d func %d (AgentId %x)\n",
  441. bus, id_sel, function, agent_id);
  442. ret = HvCallPci_getBusUnitInfo(bus, sub_bus, agent_id,
  443. iseries_hv_addr(&bridge_info),
  444. sizeof(struct HvCallPci_BridgeInfo));
  445. if (ret != 0)
  446. continue;
  447. DBG("bridge info: type %x subbus %x "
  448. "maxAgents %x maxsubbus %x logslot %x\n",
  449. bridge_info.busUnitInfo.deviceType,
  450. bridge_info.subBusNumber,
  451. bridge_info.maxAgents,
  452. bridge_info.maxSubBusNumber,
  453. bridge_info.logicalSlotNumber);
  454. if (bridge_info.busUnitInfo.deviceType ==
  455. HvCallPci_BridgeDevice)
  456. scan_bridge_slot(dt, bus, &bridge_info);
  457. else
  458. DBG("PCI: Invalid Bridge Configuration(0x%02X)",
  459. bridge_info.busUnitInfo.deviceType);
  460. }
  461. }
  462. static void __init scan_phb(struct iseries_flat_dt *dt, HvBusNumber bus)
  463. {
  464. struct HvCallPci_DeviceInfo dev_info;
  465. const HvSubBusNumber sub_bus = 0; /* EADs is always 0. */
  466. int err;
  467. int id_sel;
  468. const int max_agents = 8;
  469. /*
  470. * Probe for EADs Bridges
  471. */
  472. for (id_sel = 1; id_sel < max_agents; ++id_sel) {
  473. err = HvCallPci_getDeviceInfo(bus, sub_bus, id_sel,
  474. iseries_hv_addr(&dev_info),
  475. sizeof(struct HvCallPci_DeviceInfo));
  476. if (err) {
  477. if (err != 0x302)
  478. DBG("getDeviceInfo(%x, %x, %x) %x\n",
  479. bus, sub_bus, id_sel, err);
  480. continue;
  481. }
  482. if (dev_info.deviceType != HvCallPci_NodeDevice) {
  483. DBG("PCI: Invalid System Configuration"
  484. "(0x%02X) for bus 0x%02x id 0x%02x.\n",
  485. dev_info.deviceType, bus, id_sel);
  486. continue;
  487. }
  488. scan_bridge(dt, bus, sub_bus, id_sel);
  489. }
  490. }
  491. static void __init dt_pci_devices(struct iseries_flat_dt *dt)
  492. {
  493. HvBusNumber bus;
  494. char buf[32];
  495. u32 buses[2];
  496. int phb_num = 0;
  497. /* Check all possible buses. */
  498. for (bus = 0; bus < 256; bus++) {
  499. int err = HvCallXm_testBus(bus);
  500. if (err) {
  501. /*
  502. * Check for Unexpected Return code, a clue that
  503. * something has gone wrong.
  504. */
  505. if (err != 0x0301)
  506. DBG("Unexpected Return on Probe(0x%02X) "
  507. "0x%04X\n", bus, err);
  508. continue;
  509. }
  510. DBG("bus %d appears to exist\n", bus);
  511. snprintf(buf, 32, "pci@%d", phb_num);
  512. dt_start_node(dt, buf);
  513. dt_prop_str(dt, "device_type", device_type_pci);
  514. dt_prop_str(dt, "compatible", "IBM,iSeries-Logical-PHB");
  515. dt_prop_u32(dt, "#address-cells", 3);
  516. dt_prop_u32(dt, "#size-cells", 2);
  517. buses[0] = buses[1] = bus;
  518. dt_prop_u32_list(dt, "bus-range", buses, 2);
  519. scan_phb(dt, bus);
  520. dt_end_node(dt);
  521. phb_num++;
  522. }
  523. }
  524. static void dt_finish(struct iseries_flat_dt *dt)
  525. {
  526. dt_push_u32(dt, OF_DT_END);
  527. dt->header.totalsize = (unsigned long)dt_data - (unsigned long)dt;
  528. klimit = ALIGN((unsigned long)dt_data, 8);
  529. }
  530. void * __init build_flat_dt(unsigned long phys_mem_size)
  531. {
  532. struct iseries_flat_dt *iseries_dt;
  533. u64 tmp[2];
  534. iseries_dt = dt_init();
  535. dt_start_node(iseries_dt, "");
  536. dt_prop_u32(iseries_dt, "#address-cells", 2);
  537. dt_prop_u32(iseries_dt, "#size-cells", 2);
  538. dt_model(iseries_dt);
  539. /* /memory */
  540. dt_start_node(iseries_dt, "memory@0");
  541. dt_prop_str(iseries_dt, "device_type", device_type_memory);
  542. tmp[0] = 0;
  543. tmp[1] = phys_mem_size;
  544. dt_prop_u64_list(iseries_dt, "reg", tmp, 2);
  545. dt_end_node(iseries_dt);
  546. /* /chosen */
  547. dt_start_node(iseries_dt, "chosen");
  548. dt_prop_str(iseries_dt, "bootargs", cmd_line);
  549. dt_end_node(iseries_dt);
  550. dt_cpus(iseries_dt);
  551. dt_vdevices(iseries_dt);
  552. dt_pci_devices(iseries_dt);
  553. dt_end_node(iseries_dt);
  554. dt_finish(iseries_dt);
  555. return iseries_dt;
  556. }