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