blob: 0371329f82e1e33847896a9a6d8c1b2963e1692a [file] [log] [blame]
Stephen Rothwellc81014f2006-05-19 17:00:04 +10001/*
2 * Copyright (c) 2005-2006 Michael Ellerman, IBM Corporation
3 *
4 * Description:
5 * This file contains all the routines to build a flattened device
6 * tree for a legacy iSeries machine.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14#undef DEBUG
15
16#include <linux/types.h>
17#include <linux/init.h>
18#include <linux/pci.h>
19#include <linux/pci_regs.h>
20#include <linux/pci_ids.h>
21#include <linux/threads.h>
22#include <linux/bitops.h>
23#include <linux/string.h>
24#include <linux/kernel.h>
25#include <linux/if_ether.h> /* ETH_ALEN */
26
27#include <asm/machdep.h>
28#include <asm/prom.h>
29#include <asm/lppaca.h>
30#include <asm/page.h>
31#include <asm/cputable.h>
32#include <asm/abs_addr.h>
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100033#include <asm/system.h>
Stephen Rothwellc81014f2006-05-19 17:00:04 +100034#include <asm/iseries/hv_types.h>
35#include <asm/iseries/hv_lp_config.h>
36#include <asm/iseries/hv_call_xm.h>
37#include <asm/iseries/it_exp_vpd_panel.h>
38#include <asm/udbg.h>
39
40#include "processor_vpd.h"
41#include "call_hpt.h"
42#include "call_pci.h"
43#include "pci.h"
44
45#ifdef DEBUG
46#define DBG(fmt...) udbg_printf(fmt)
47#else
48#define DBG(fmt...)
49#endif
50
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100051extern char __dt_strings_start[];
52extern char __dt_strings_end[];
53
Stephen Rothwellc81014f2006-05-19 17:00:04 +100054struct blob {
55 unsigned char data[PAGE_SIZE * 2];
56 unsigned long next;
57};
58
59struct iseries_flat_dt {
60 struct boot_param_header header;
61 u64 reserve_map[2];
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100062 struct blob *dt;
Stephen Rothwellc81014f2006-05-19 17:00:04 +100063};
64
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100065static struct iseries_flat_dt *iseries_dt;
Stephen Rothwellc81014f2006-05-19 17:00:04 +100066
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100067static struct iseries_flat_dt * __init dt_init(void)
Stephen Rothwellc81014f2006-05-19 17:00:04 +100068{
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100069 struct iseries_flat_dt *dt;
70 unsigned long str_len;
71
72 str_len = __dt_strings_end - __dt_strings_start;
73 dt = (struct iseries_flat_dt *)ALIGN(klimit, 8);
Stephen Rothwellc81014f2006-05-19 17:00:04 +100074 dt->header.off_mem_rsvmap =
75 offsetof(struct iseries_flat_dt, reserve_map);
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100076 dt->header.off_dt_strings = ALIGN(sizeof(*dt), 8);
77 dt->header.off_dt_struct = dt->header.off_dt_strings
78 + ALIGN(str_len, 8);
79 dt->dt = (struct blob *)((unsigned long)dt + dt->header.off_dt_struct);
80 klimit = ALIGN((unsigned long)(dt->dt) + sizeof(struct blob), 8);
81 dt->header.totalsize = klimit - (unsigned long)dt;
82 dt->header.dt_strings_size = str_len;
Stephen Rothwellc81014f2006-05-19 17:00:04 +100083
84 /* There is no notion of hardware cpu id on iSeries */
85 dt->header.boot_cpuid_phys = smp_processor_id();
86
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100087 dt->dt->next = (unsigned long)&dt->dt->data;
88 memcpy((char *)dt + dt->header.off_dt_strings, __dt_strings_start,
89 str_len);
Stephen Rothwellc81014f2006-05-19 17:00:04 +100090
91 dt->header.magic = OF_DT_HEADER;
92 dt->header.version = 0x10;
93 dt->header.last_comp_version = 0x10;
94
95 dt->reserve_map[0] = 0;
96 dt->reserve_map[1] = 0;
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +100097
98 return dt;
Stephen Rothwellc81014f2006-05-19 17:00:04 +100099}
100
101static void __init dt_check_blob(struct blob *b)
102{
103 if (b->next >= (unsigned long)&b->next) {
104 DBG("Ran out of space in flat device tree blob!\n");
105 BUG();
106 }
107}
108
109static void __init dt_push_u32(struct iseries_flat_dt *dt, u32 value)
110{
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000111 *((u32*)dt->dt->next) = value;
112 dt->dt->next += sizeof(u32);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000113
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000114 dt_check_blob(dt->dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000115}
116
117#ifdef notyet
118static void __init dt_push_u64(struct iseries_flat_dt *dt, u64 value)
119{
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000120 *((u64*)dt->dt->next) = value;
121 dt->dt->next += sizeof(u64);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000122
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000123 dt_check_blob(dt->dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000124}
125#endif
126
127static unsigned long __init dt_push_bytes(struct blob *blob, char *data, int len)
128{
129 unsigned long start = blob->next - (unsigned long)blob->data;
130
131 memcpy((char *)blob->next, data, len);
132 blob->next = _ALIGN(blob->next + len, 4);
133
134 dt_check_blob(blob);
135
136 return start;
137}
138
139static void __init dt_start_node(struct iseries_flat_dt *dt, char *name)
140{
141 dt_push_u32(dt, OF_DT_BEGIN_NODE);
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000142 dt_push_bytes(dt->dt, name, strlen(name) + 1);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000143}
144
145#define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
146
147static void __init dt_prop(struct iseries_flat_dt *dt, char *name,
148 char *data, int len)
149{
150 unsigned long offset;
151
152 dt_push_u32(dt, OF_DT_PROP);
153
154 /* Length of the data */
155 dt_push_u32(dt, len);
156
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000157 offset = name - __dt_strings_start;
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000158
159 /* The offset of the properties name in the string blob. */
160 dt_push_u32(dt, (u32)offset);
161
162 /* The actual data. */
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000163 dt_push_bytes(dt->dt, data, len);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000164}
165
166static void __init dt_prop_str(struct iseries_flat_dt *dt, char *name,
167 char *data)
168{
169 dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
170}
171
172static void __init dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
173{
174 dt_prop(dt, name, (char *)&data, sizeof(u32));
175}
176
177static void __init dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
178{
179 dt_prop(dt, name, (char *)&data, sizeof(u64));
180}
181
182static void __init dt_prop_u64_list(struct iseries_flat_dt *dt, char *name,
183 u64 *data, int n)
184{
185 dt_prop(dt, name, (char *)data, sizeof(u64) * n);
186}
187
188static void __init dt_prop_u32_list(struct iseries_flat_dt *dt, char *name,
189 u32 *data, int n)
190{
191 dt_prop(dt, name, (char *)data, sizeof(u32) * n);
192}
193
194#ifdef notyet
195static void __init dt_prop_empty(struct iseries_flat_dt *dt, char *name)
196{
197 dt_prop(dt, name, NULL, 0);
198}
199#endif
200
201static void __init dt_cpus(struct iseries_flat_dt *dt)
202{
203 unsigned char buf[32];
204 unsigned char *p;
205 unsigned int i, index;
206 struct IoHriProcessorVpd *d;
207 u32 pft_size[2];
208
209 /* yuck */
210 snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
211 p = strchr(buf, ' ');
212 if (!p) p = buf + strlen(buf);
213
214 dt_start_node(dt, "cpus");
215 dt_prop_u32(dt, "#address-cells", 1);
216 dt_prop_u32(dt, "#size-cells", 0);
217
218 pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */
219 pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
220
221 for (i = 0; i < NR_CPUS; i++) {
222 if (lppaca[i].dyn_proc_status >= 2)
223 continue;
224
225 snprintf(p, 32 - (p - buf), "@%d", i);
226 dt_start_node(dt, buf);
227
228 dt_prop_str(dt, "device_type", "cpu");
229
230 index = lppaca[i].dyn_hv_phys_proc_index;
231 d = &xIoHriProcessorVpd[index];
232
233 dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
234 dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
235
236 dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
237 dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
238
239 /* magic conversions to Hz copied from old code */
240 dt_prop_u32(dt, "clock-frequency",
241 ((1UL << 34) * 1000000) / d->xProcFreq);
242 dt_prop_u32(dt, "timebase-frequency",
243 ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
244
245 dt_prop_u32(dt, "reg", i);
246
247 dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
248
249 dt_end_node(dt);
250 }
251
252 dt_end_node(dt);
253}
254
255static void __init dt_model(struct iseries_flat_dt *dt)
256{
257 char buf[16] = "IBM,";
258
259 /* "IBM," + mfgId[2:3] + systemSerial[1:5] */
260 strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2);
261 strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5);
262 buf[11] = '\0';
263 dt_prop_str(dt, "system-id", buf);
264
265 /* "IBM," + machineType[0:4] */
266 strne2a(buf + 4, xItExtVpdPanel.machineType, 4);
267 buf[8] = '\0';
268 dt_prop_str(dt, "model", buf);
269
270 dt_prop_str(dt, "compatible", "IBM,iSeries");
271}
272
273static void __init dt_vdevices(struct iseries_flat_dt *dt)
274{
275 u32 reg = 0;
276 HvLpIndexMap vlan_map;
277 int i;
278 char buf[32];
279
280 dt_start_node(dt, "vdevice");
281 dt_prop_str(dt, "device_type", "vdevice");
282 dt_prop_str(dt, "compatible", "IBM,iSeries-vdevice");
283 dt_prop_u32(dt, "#address-cells", 1);
284 dt_prop_u32(dt, "#size-cells", 0);
285
286 snprintf(buf, sizeof(buf), "vty@%08x", reg);
287 dt_start_node(dt, buf);
288 dt_prop_str(dt, "device_type", "serial");
289 dt_prop_u32(dt, "reg", reg);
290 dt_end_node(dt);
291 reg++;
292
293 snprintf(buf, sizeof(buf), "v-scsi@%08x", reg);
294 dt_start_node(dt, buf);
295 dt_prop_str(dt, "device_type", "vscsi");
296 dt_prop_str(dt, "compatible", "IBM,v-scsi");
297 dt_prop_u32(dt, "reg", reg);
298 dt_end_node(dt);
299 reg++;
300
301 vlan_map = HvLpConfig_getVirtualLanIndexMap();
302 for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
303 unsigned char mac_addr[ETH_ALEN];
304
305 if ((vlan_map & (0x8000 >> i)) == 0)
306 continue;
307 snprintf(buf, 32, "l-lan@%08x", reg + i);
308 dt_start_node(dt, buf);
309 dt_prop_str(dt, "device_type", "network");
310 dt_prop_str(dt, "compatible", "IBM,iSeries-l-lan");
311 dt_prop_u32(dt, "reg", reg + i);
312 dt_prop_u32(dt, "linux,unit_address", i);
313
314 mac_addr[0] = 0x02;
315 mac_addr[1] = 0x01;
316 mac_addr[2] = 0xff;
317 mac_addr[3] = i;
318 mac_addr[4] = 0xff;
319 mac_addr[5] = HvLpConfig_getLpIndex_outline();
320 dt_prop(dt, "local-mac-address", (char *)mac_addr, ETH_ALEN);
321 dt_prop(dt, "mac-address", (char *)mac_addr, ETH_ALEN);
322 dt_prop_u32(dt, "max-frame-size", 9000);
323 dt_prop_u32(dt, "address-bits", 48);
324
325 dt_end_node(dt);
326 }
327 reg += HVMAXARCHITECTEDVIRTUALLANS;
328
329 for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++) {
330 snprintf(buf, 32, "viodasd@%08x", reg + i);
331 dt_start_node(dt, buf);
332 dt_prop_str(dt, "device_type", "block");
333 dt_prop_str(dt, "compatible", "IBM,iSeries-viodasd");
334 dt_prop_u32(dt, "reg", reg + i);
335 dt_prop_u32(dt, "linux,unit_address", i);
336 dt_end_node(dt);
337 }
338 reg += HVMAXARCHITECTEDVIRTUALDISKS;
339 for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++) {
340 snprintf(buf, 32, "viocd@%08x", reg + i);
341 dt_start_node(dt, buf);
342 dt_prop_str(dt, "device_type", "block");
343 dt_prop_str(dt, "compatible", "IBM,iSeries-viocd");
344 dt_prop_u32(dt, "reg", reg + i);
345 dt_prop_u32(dt, "linux,unit_address", i);
346 dt_end_node(dt);
347 }
348 reg += HVMAXARCHITECTEDVIRTUALCDROMS;
349 for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++) {
350 snprintf(buf, 32, "viotape@%08x", reg + i);
351 dt_start_node(dt, buf);
352 dt_prop_str(dt, "device_type", "byte");
353 dt_prop_str(dt, "compatible", "IBM,iSeries-viotape");
354 dt_prop_u32(dt, "reg", reg + i);
355 dt_prop_u32(dt, "linux,unit_address", i);
356 dt_end_node(dt);
357 }
358
359 dt_end_node(dt);
360}
361
362struct pci_class_name {
363 u16 code;
364 char *name;
365 char *type;
366};
367
368static struct pci_class_name __initdata pci_class_name[] = {
369 { PCI_CLASS_NETWORK_ETHERNET, "ethernet", "network" },
370};
371
372static struct pci_class_name * __init dt_find_pci_class_name(u16 class_code)
373{
374 struct pci_class_name *cp;
375
376 for (cp = pci_class_name;
377 cp < &pci_class_name[ARRAY_SIZE(pci_class_name)]; cp++)
378 if (cp->code == class_code)
379 return cp;
380 return NULL;
381}
382
383/*
384 * This assumes that the node slot is always on the primary bus!
385 */
386static void __init scan_bridge_slot(struct iseries_flat_dt *dt,
387 HvBusNumber bus, struct HvCallPci_BridgeInfo *bridge_info)
388{
389 HvSubBusNumber sub_bus = bridge_info->subBusNumber;
390 u16 vendor_id;
391 u16 device_id;
392 u32 class_id;
393 int err;
394 char buf[32];
395 u32 reg[5];
396 int id_sel = ISERIES_GET_DEVICE_FROM_SUBBUS(sub_bus);
397 int function = ISERIES_GET_FUNCTION_FROM_SUBBUS(sub_bus);
398 HvAgentId eads_id_sel = ISERIES_PCI_AGENTID(id_sel, function);
399 u8 devfn;
400 struct pci_class_name *cp;
401
402 /*
403 * Connect all functions of any device found.
404 */
405 for (id_sel = 1; id_sel <= bridge_info->maxAgents; id_sel++) {
406 for (function = 0; function < 8; function++) {
407 HvAgentId agent_id = ISERIES_PCI_AGENTID(id_sel,
408 function);
409 err = HvCallXm_connectBusUnit(bus, sub_bus,
410 agent_id, 0);
411 if (err) {
412 if (err != 0x302)
413 printk(KERN_DEBUG
414 "connectBusUnit(%x, %x, %x) "
415 "== %x\n",
416 bus, sub_bus, agent_id, err);
417 continue;
418 }
419
420 err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
421 PCI_VENDOR_ID, &vendor_id);
422 if (err) {
423 printk(KERN_DEBUG
424 "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 printk(KERN_DEBUG
432 "ReadDevice(%x, %x, %x) == %x\n",
433 bus, sub_bus, agent_id, err);
434 continue;
435 }
436 err = HvCallPci_configLoad32(bus, sub_bus, agent_id,
437 PCI_CLASS_REVISION , &class_id);
438 if (err) {
439 printk(KERN_DEBUG
440 "ReadClass(%x, %x, %x) == %x\n",
441 bus, sub_bus, agent_id, err);
442 continue;
443 }
444
445 devfn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(eads_id_sel),
446 function);
447 cp = dt_find_pci_class_name(class_id >> 16);
448 if (cp && cp->name)
449 strncpy(buf, cp->name, sizeof(buf) - 1);
450 else
451 snprintf(buf, sizeof(buf), "pci%x,%x",
452 vendor_id, device_id);
453 buf[sizeof(buf) - 1] = '\0';
454 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
455 "@%x", PCI_SLOT(devfn));
456 buf[sizeof(buf) - 1] = '\0';
457 if (function != 0)
458 snprintf(buf + strlen(buf),
459 sizeof(buf) - strlen(buf),
460 ",%x", function);
461 dt_start_node(dt, buf);
462 reg[0] = (bus << 16) | (devfn << 8);
463 reg[1] = 0;
464 reg[2] = 0;
465 reg[3] = 0;
466 reg[4] = 0;
467 dt_prop_u32_list(dt, "reg", reg, 5);
468 if (cp && (cp->type || cp->name))
469 dt_prop_str(dt, "device_type",
470 cp->type ? cp->type : cp->name);
471 dt_prop_u32(dt, "vendor-id", vendor_id);
472 dt_prop_u32(dt, "device-id", device_id);
473 dt_prop_u32(dt, "class-code", class_id >> 8);
474 dt_prop_u32(dt, "revision-id", class_id & 0xff);
475 dt_prop_u32(dt, "linux,subbus", sub_bus);
476 dt_prop_u32(dt, "linux,agent-id", agent_id);
477 dt_prop_u32(dt, "linux,logical-slot-number",
478 bridge_info->logicalSlotNumber);
479 dt_end_node(dt);
480
481 }
482 }
483}
484
485static void __init scan_bridge(struct iseries_flat_dt *dt, HvBusNumber bus,
486 HvSubBusNumber sub_bus, int id_sel)
487{
488 struct HvCallPci_BridgeInfo bridge_info;
489 HvAgentId agent_id;
490 int function;
491 int ret;
492
493 /* Note: hvSubBus and irq is always be 0 at this level! */
494 for (function = 0; function < 8; ++function) {
495 agent_id = ISERIES_PCI_AGENTID(id_sel, function);
496 ret = HvCallXm_connectBusUnit(bus, sub_bus, agent_id, 0);
497 if (ret != 0) {
498 if (ret != 0xb)
499 printk(KERN_DEBUG "connectBusUnit(%x, %x, %x) "
500 "== %x\n",
501 bus, sub_bus, agent_id, ret);
502 continue;
503 }
504 printk("found device at bus %d idsel %d func %d (AgentId %x)\n",
505 bus, id_sel, function, agent_id);
506 ret = HvCallPci_getBusUnitInfo(bus, sub_bus, agent_id,
507 iseries_hv_addr(&bridge_info),
508 sizeof(struct HvCallPci_BridgeInfo));
509 if (ret != 0)
510 continue;
511 printk("bridge info: type %x subbus %x "
512 "maxAgents %x maxsubbus %x logslot %x\n",
513 bridge_info.busUnitInfo.deviceType,
514 bridge_info.subBusNumber,
515 bridge_info.maxAgents,
516 bridge_info.maxSubBusNumber,
517 bridge_info.logicalSlotNumber);
518 if (bridge_info.busUnitInfo.deviceType ==
519 HvCallPci_BridgeDevice)
520 scan_bridge_slot(dt, bus, &bridge_info);
521 else
522 printk("PCI: Invalid Bridge Configuration(0x%02X)",
523 bridge_info.busUnitInfo.deviceType);
524 }
525}
526
527static void __init scan_phb(struct iseries_flat_dt *dt, HvBusNumber bus)
528{
529 struct HvCallPci_DeviceInfo dev_info;
530 const HvSubBusNumber sub_bus = 0; /* EADs is always 0. */
531 int err;
532 int id_sel;
533 const int max_agents = 8;
534
535 /*
536 * Probe for EADs Bridges
537 */
538 for (id_sel = 1; id_sel < max_agents; ++id_sel) {
539 err = HvCallPci_getDeviceInfo(bus, sub_bus, id_sel,
540 iseries_hv_addr(&dev_info),
541 sizeof(struct HvCallPci_DeviceInfo));
542 if (err) {
543 if (err != 0x302)
544 printk(KERN_DEBUG "getDeviceInfo(%x, %x, %x) "
545 "== %x\n",
546 bus, sub_bus, id_sel, err);
547 continue;
548 }
549 if (dev_info.deviceType != HvCallPci_NodeDevice) {
550 printk(KERN_DEBUG "PCI: Invalid System Configuration"
551 "(0x%02X) for bus 0x%02x id 0x%02x.\n",
552 dev_info.deviceType, bus, id_sel);
553 continue;
554 }
555 scan_bridge(dt, bus, sub_bus, id_sel);
556 }
557}
558
559static void __init dt_pci_devices(struct iseries_flat_dt *dt)
560{
561 HvBusNumber bus;
562 char buf[32];
563 u32 buses[2];
564 int phb_num = 0;
565
566 /* Check all possible buses. */
567 for (bus = 0; bus < 256; bus++) {
568 int err = HvCallXm_testBus(bus);
569
570 if (err) {
571 /*
572 * Check for Unexpected Return code, a clue that
573 * something has gone wrong.
574 */
575 if (err != 0x0301)
576 printk(KERN_ERR "Unexpected Return on Probe"
577 "(0x%02X): 0x%04X", bus, err);
578 continue;
579 }
580 printk("bus %d appears to exist\n", bus);
581 snprintf(buf, 32, "pci@%d", phb_num);
582 dt_start_node(dt, buf);
583 dt_prop_str(dt, "device_type", "pci");
584 dt_prop_str(dt, "compatible", "IBM,iSeries-Logical-PHB");
585 dt_prop_u32(dt, "#address-cells", 3);
586 dt_prop_u32(dt, "#size-cells", 2);
587 buses[0] = buses[1] = bus;
588 dt_prop_u32_list(dt, "bus-range", buses, 2);
589 scan_phb(dt, bus);
590 dt_end_node(dt);
591 phb_num++;
592 }
593}
594
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000595static void dt_finish(struct iseries_flat_dt *dt)
596{
597 dt_push_u32(dt, OF_DT_END);
598}
599
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000600void * __init build_flat_dt(unsigned long phys_mem_size)
601{
602 u64 tmp[2];
603
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000604 iseries_dt = dt_init();
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000605
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000606 dt_start_node(iseries_dt, "");
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000607
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000608 dt_prop_u32(iseries_dt, "#address-cells", 2);
609 dt_prop_u32(iseries_dt, "#size-cells", 2);
610 dt_model(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000611
612 /* /memory */
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000613 dt_start_node(iseries_dt, "memory@0");
614 dt_prop_str(iseries_dt, "name", "memory");
615 dt_prop_str(iseries_dt, "device_type", "memory");
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000616 tmp[0] = 0;
617 tmp[1] = phys_mem_size;
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000618 dt_prop_u64_list(iseries_dt, "reg", tmp, 2);
619 dt_end_node(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000620
621 /* /chosen */
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000622 dt_start_node(iseries_dt, "chosen");
623 dt_prop_str(iseries_dt, "bootargs", cmd_line);
624 dt_end_node(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000625
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000626 dt_cpus(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000627
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000628 dt_vdevices(iseries_dt);
629 dt_pci_devices(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000630
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000631 dt_end_node(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000632
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000633 dt_finish(iseries_dt);
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000634
Stephen Rothwellc4e3ea22006-05-19 17:04:48 +1000635 return iseries_dt;
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000636}