diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2006-05-19 03:00:04 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-05-24 02:08:57 -0400 |
commit | c81014f603db26e1ed818decebd3b594606e20a6 (patch) | |
tree | 8777dbf5e18f062c921a46929af996d953cf443e | |
parent | 9ceb19093b5e5f037c6b47df0607dd567283287d (diff) |
[PATCH] powerpc: split device tree stuff out of iseries/setup.c
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r-- | arch/powerpc/platforms/iseries/Makefile | 2 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/dt.c | 618 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/setup.c | 578 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/setup.h | 2 |
4 files changed, 622 insertions, 578 deletions
diff --git a/arch/powerpc/platforms/iseries/Makefile b/arch/powerpc/platforms/iseries/Makefile index 7e67a20c18..32306214a3 100644 --- a/arch/powerpc/platforms/iseries/Makefile +++ b/arch/powerpc/platforms/iseries/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | EXTRA_CFLAGS += -mno-minimal-toc | 1 | EXTRA_CFLAGS += -mno-minimal-toc |
2 | 2 | ||
3 | obj-y += hvlog.o hvlpconfig.o lpardata.o setup.o mf.o lpevents.o \ | 3 | obj-y += hvlog.o hvlpconfig.o lpardata.o setup.o dt.o mf.o lpevents.o \ |
4 | hvcall.o proc.o htab.o iommu.o misc.o irq.o | 4 | hvcall.o proc.o htab.o iommu.o misc.o irq.o |
5 | obj-$(CONFIG_PCI) += pci.o vpdinfo.o | 5 | obj-$(CONFIG_PCI) += pci.o vpdinfo.o |
6 | obj-$(CONFIG_SMP) += smp.o | 6 | obj-$(CONFIG_SMP) += smp.o |
diff --git a/arch/powerpc/platforms/iseries/dt.c b/arch/powerpc/platforms/iseries/dt.c new file mode 100644 index 0000000000..93d4233e73 --- /dev/null +++ b/arch/powerpc/platforms/iseries/dt.c | |||
@@ -0,0 +1,618 @@ | |||
1 | /* | ||
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> | ||
33 | #include <asm/iseries/hv_types.h> | ||
34 | #include <asm/iseries/hv_lp_config.h> | ||
35 | #include <asm/iseries/hv_call_xm.h> | ||
36 | #include <asm/iseries/it_exp_vpd_panel.h> | ||
37 | #include <asm/udbg.h> | ||
38 | |||
39 | #include "processor_vpd.h" | ||
40 | #include "call_hpt.h" | ||
41 | #include "call_pci.h" | ||
42 | #include "pci.h" | ||
43 | |||
44 | #ifdef DEBUG | ||
45 | #define DBG(fmt...) udbg_printf(fmt) | ||
46 | #else | ||
47 | #define DBG(fmt...) | ||
48 | #endif | ||
49 | |||
50 | struct blob { | ||
51 | unsigned char data[PAGE_SIZE * 2]; | ||
52 | unsigned long next; | ||
53 | }; | ||
54 | |||
55 | struct iseries_flat_dt { | ||
56 | struct boot_param_header header; | ||
57 | u64 reserve_map[2]; | ||
58 | struct blob dt; | ||
59 | struct blob strings; | ||
60 | }; | ||
61 | |||
62 | static struct iseries_flat_dt iseries_dt; | ||
63 | |||
64 | static void __init dt_init(struct iseries_flat_dt *dt) | ||
65 | { | ||
66 | dt->header.off_mem_rsvmap = | ||
67 | offsetof(struct iseries_flat_dt, reserve_map); | ||
68 | dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt); | ||
69 | dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings); | ||
70 | dt->header.totalsize = sizeof(struct iseries_flat_dt); | ||
71 | dt->header.dt_strings_size = sizeof(struct blob); | ||
72 | |||
73 | /* There is no notion of hardware cpu id on iSeries */ | ||
74 | dt->header.boot_cpuid_phys = smp_processor_id(); | ||
75 | |||
76 | dt->dt.next = (unsigned long)&dt->dt.data; | ||
77 | dt->strings.next = (unsigned long)&dt->strings.data; | ||
78 | |||
79 | dt->header.magic = OF_DT_HEADER; | ||
80 | dt->header.version = 0x10; | ||
81 | dt->header.last_comp_version = 0x10; | ||
82 | |||
83 | dt->reserve_map[0] = 0; | ||
84 | dt->reserve_map[1] = 0; | ||
85 | } | ||
86 | |||
87 | static void __init dt_check_blob(struct blob *b) | ||
88 | { | ||
89 | if (b->next >= (unsigned long)&b->next) { | ||
90 | DBG("Ran out of space in flat device tree blob!\n"); | ||
91 | BUG(); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | static void __init dt_push_u32(struct iseries_flat_dt *dt, u32 value) | ||
96 | { | ||
97 | *((u32*)dt->dt.next) = value; | ||
98 | dt->dt.next += sizeof(u32); | ||
99 | |||
100 | dt_check_blob(&dt->dt); | ||
101 | } | ||
102 | |||
103 | #ifdef notyet | ||
104 | static void __init dt_push_u64(struct iseries_flat_dt *dt, u64 value) | ||
105 | { | ||
106 | *((u64*)dt->dt.next) = value; | ||
107 | dt->dt.next += sizeof(u64); | ||
108 | |||
109 | dt_check_blob(&dt->dt); | ||
110 | } | ||
111 | #endif | ||
112 | |||
113 | static unsigned long __init dt_push_bytes(struct blob *blob, char *data, int len) | ||
114 | { | ||
115 | unsigned long start = blob->next - (unsigned long)blob->data; | ||
116 | |||
117 | memcpy((char *)blob->next, data, len); | ||
118 | blob->next = _ALIGN(blob->next + len, 4); | ||
119 | |||
120 | dt_check_blob(blob); | ||
121 | |||
122 | return start; | ||
123 | } | ||
124 | |||
125 | static void __init dt_start_node(struct iseries_flat_dt *dt, char *name) | ||
126 | { | ||
127 | dt_push_u32(dt, OF_DT_BEGIN_NODE); | ||
128 | dt_push_bytes(&dt->dt, name, strlen(name) + 1); | ||
129 | } | ||
130 | |||
131 | #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE) | ||
132 | |||
133 | static void __init dt_prop(struct iseries_flat_dt *dt, char *name, | ||
134 | char *data, int len) | ||
135 | { | ||
136 | unsigned long offset; | ||
137 | |||
138 | dt_push_u32(dt, OF_DT_PROP); | ||
139 | |||
140 | /* Length of the data */ | ||
141 | dt_push_u32(dt, len); | ||
142 | |||
143 | /* Put the property name in the string blob. */ | ||
144 | offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1); | ||
145 | |||
146 | /* The offset of the properties name in the string blob. */ | ||
147 | dt_push_u32(dt, (u32)offset); | ||
148 | |||
149 | /* The actual data. */ | ||
150 | dt_push_bytes(&dt->dt, data, len); | ||
151 | } | ||
152 | |||
153 | static void __init dt_prop_str(struct iseries_flat_dt *dt, char *name, | ||
154 | char *data) | ||
155 | { | ||
156 | dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */ | ||
157 | } | ||
158 | |||
159 | static void __init dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data) | ||
160 | { | ||
161 | dt_prop(dt, name, (char *)&data, sizeof(u32)); | ||
162 | } | ||
163 | |||
164 | static void __init dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data) | ||
165 | { | ||
166 | dt_prop(dt, name, (char *)&data, sizeof(u64)); | ||
167 | } | ||
168 | |||
169 | static void __init dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, | ||
170 | u64 *data, int n) | ||
171 | { | ||
172 | dt_prop(dt, name, (char *)data, sizeof(u64) * n); | ||
173 | } | ||
174 | |||
175 | static void __init dt_prop_u32_list(struct iseries_flat_dt *dt, char *name, | ||
176 | u32 *data, int n) | ||
177 | { | ||
178 | dt_prop(dt, name, (char *)data, sizeof(u32) * n); | ||
179 | } | ||
180 | |||
181 | #ifdef notyet | ||
182 | static void __init dt_prop_empty(struct iseries_flat_dt *dt, char *name) | ||
183 | { | ||
184 | dt_prop(dt, name, NULL, 0); | ||
185 | } | ||
186 | #endif | ||
187 | |||
188 | static void __init dt_cpus(struct iseries_flat_dt *dt) | ||
189 | { | ||
190 | unsigned char buf[32]; | ||
191 | unsigned char *p; | ||
192 | unsigned int i, index; | ||
193 | struct IoHriProcessorVpd *d; | ||
194 | u32 pft_size[2]; | ||
195 | |||
196 | /* yuck */ | ||
197 | snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name); | ||
198 | p = strchr(buf, ' '); | ||
199 | if (!p) p = buf + strlen(buf); | ||
200 | |||
201 | dt_start_node(dt, "cpus"); | ||
202 | dt_prop_u32(dt, "#address-cells", 1); | ||
203 | dt_prop_u32(dt, "#size-cells", 0); | ||
204 | |||
205 | pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */ | ||
206 | pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE); | ||
207 | |||
208 | for (i = 0; i < NR_CPUS; i++) { | ||
209 | if (lppaca[i].dyn_proc_status >= 2) | ||
210 | continue; | ||
211 | |||
212 | snprintf(p, 32 - (p - buf), "@%d", i); | ||
213 | dt_start_node(dt, buf); | ||
214 | |||
215 | dt_prop_str(dt, "device_type", "cpu"); | ||
216 | |||
217 | index = lppaca[i].dyn_hv_phys_proc_index; | ||
218 | d = &xIoHriProcessorVpd[index]; | ||
219 | |||
220 | dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024); | ||
221 | dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize); | ||
222 | |||
223 | dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024); | ||
224 | dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize); | ||
225 | |||
226 | /* magic conversions to Hz copied from old code */ | ||
227 | dt_prop_u32(dt, "clock-frequency", | ||
228 | ((1UL << 34) * 1000000) / d->xProcFreq); | ||
229 | dt_prop_u32(dt, "timebase-frequency", | ||
230 | ((1UL << 32) * 1000000) / d->xTimeBaseFreq); | ||
231 | |||
232 | dt_prop_u32(dt, "reg", i); | ||
233 | |||
234 | dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2); | ||
235 | |||
236 | dt_end_node(dt); | ||
237 | } | ||
238 | |||
239 | dt_end_node(dt); | ||
240 | } | ||
241 | |||
242 | static void __init dt_model(struct iseries_flat_dt *dt) | ||
243 | { | ||
244 | char buf[16] = "IBM,"; | ||
245 | |||
246 | /* "IBM," + mfgId[2:3] + systemSerial[1:5] */ | ||
247 | strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2); | ||
248 | strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5); | ||
249 | buf[11] = '\0'; | ||
250 | dt_prop_str(dt, "system-id", buf); | ||
251 | |||
252 | /* "IBM," + machineType[0:4] */ | ||
253 | strne2a(buf + 4, xItExtVpdPanel.machineType, 4); | ||
254 | buf[8] = '\0'; | ||
255 | dt_prop_str(dt, "model", buf); | ||
256 | |||
257 | dt_prop_str(dt, "compatible", "IBM,iSeries"); | ||
258 | } | ||
259 | |||
260 | static void __init dt_vdevices(struct iseries_flat_dt *dt) | ||
261 | { | ||
262 | u32 reg = 0; | ||
263 | HvLpIndexMap vlan_map; | ||
264 | int i; | ||
265 | char buf[32]; | ||
266 | |||
267 | dt_start_node(dt, "vdevice"); | ||
268 | dt_prop_str(dt, "device_type", "vdevice"); | ||
269 | dt_prop_str(dt, "compatible", "IBM,iSeries-vdevice"); | ||
270 | dt_prop_u32(dt, "#address-cells", 1); | ||
271 | dt_prop_u32(dt, "#size-cells", 0); | ||
272 | |||
273 | snprintf(buf, sizeof(buf), "vty@%08x", reg); | ||
274 | dt_start_node(dt, buf); | ||
275 | dt_prop_str(dt, "device_type", "serial"); | ||
276 | dt_prop_u32(dt, "reg", reg); | ||
277 | dt_end_node(dt); | ||
278 | reg++; | ||
279 | |||
280 | snprintf(buf, sizeof(buf), "v-scsi@%08x", reg); | ||
281 | dt_start_node(dt, buf); | ||
282 | dt_prop_str(dt, "device_type", "vscsi"); | ||
283 | dt_prop_str(dt, "compatible", "IBM,v-scsi"); | ||
284 | dt_prop_u32(dt, "reg", reg); | ||
285 | dt_end_node(dt); | ||
286 | reg++; | ||
287 | |||
288 | vlan_map = HvLpConfig_getVirtualLanIndexMap(); | ||
289 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) { | ||
290 | unsigned char mac_addr[ETH_ALEN]; | ||
291 | |||
292 | if ((vlan_map & (0x8000 >> i)) == 0) | ||
293 | continue; | ||
294 | snprintf(buf, 32, "l-lan@%08x", reg + i); | ||
295 | dt_start_node(dt, buf); | ||
296 | dt_prop_str(dt, "device_type", "network"); | ||
297 | dt_prop_str(dt, "compatible", "IBM,iSeries-l-lan"); | ||
298 | dt_prop_u32(dt, "reg", reg + i); | ||
299 | dt_prop_u32(dt, "linux,unit_address", i); | ||
300 | |||
301 | mac_addr[0] = 0x02; | ||
302 | mac_addr[1] = 0x01; | ||
303 | mac_addr[2] = 0xff; | ||
304 | mac_addr[3] = i; | ||
305 | mac_addr[4] = 0xff; | ||
306 | mac_addr[5] = HvLpConfig_getLpIndex_outline(); | ||
307 | dt_prop(dt, "local-mac-address", (char *)mac_addr, ETH_ALEN); | ||
308 | dt_prop(dt, "mac-address", (char *)mac_addr, ETH_ALEN); | ||
309 | dt_prop_u32(dt, "max-frame-size", 9000); | ||
310 | dt_prop_u32(dt, "address-bits", 48); | ||
311 | |||
312 | dt_end_node(dt); | ||
313 | } | ||
314 | reg += HVMAXARCHITECTEDVIRTUALLANS; | ||
315 | |||
316 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++) { | ||
317 | snprintf(buf, 32, "viodasd@%08x", reg + i); | ||
318 | dt_start_node(dt, buf); | ||
319 | dt_prop_str(dt, "device_type", "block"); | ||
320 | dt_prop_str(dt, "compatible", "IBM,iSeries-viodasd"); | ||
321 | dt_prop_u32(dt, "reg", reg + i); | ||
322 | dt_prop_u32(dt, "linux,unit_address", i); | ||
323 | dt_end_node(dt); | ||
324 | } | ||
325 | reg += HVMAXARCHITECTEDVIRTUALDISKS; | ||
326 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++) { | ||
327 | snprintf(buf, 32, "viocd@%08x", reg + i); | ||
328 | dt_start_node(dt, buf); | ||
329 | dt_prop_str(dt, "device_type", "block"); | ||
330 | dt_prop_str(dt, "compatible", "IBM,iSeries-viocd"); | ||
331 | dt_prop_u32(dt, "reg", reg + i); | ||
332 | dt_prop_u32(dt, "linux,unit_address", i); | ||
333 | dt_end_node(dt); | ||
334 | } | ||
335 | reg += HVMAXARCHITECTEDVIRTUALCDROMS; | ||
336 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++) { | ||
337 | snprintf(buf, 32, "viotape@%08x", reg + i); | ||
338 | dt_start_node(dt, buf); | ||
339 | dt_prop_str(dt, "device_type", "byte"); | ||
340 | dt_prop_str(dt, "compatible", "IBM,iSeries-viotape"); | ||
341 | dt_prop_u32(dt, "reg", reg + i); | ||
342 | dt_prop_u32(dt, "linux,unit_address", i); | ||
343 | dt_end_node(dt); | ||
344 | } | ||
345 | |||
346 | dt_end_node(dt); | ||
347 | } | ||
348 | |||
349 | struct pci_class_name { | ||
350 | u16 code; | ||
351 | char *name; | ||
352 | char *type; | ||
353 | }; | ||
354 | |||
355 | static struct pci_class_name __initdata pci_class_name[] = { | ||
356 | { PCI_CLASS_NETWORK_ETHERNET, "ethernet", "network" }, | ||
357 | }; | ||
358 | |||
359 | static struct pci_class_name * __init dt_find_pci_class_name(u16 class_code) | ||
360 | { | ||
361 | struct pci_class_name *cp; | ||
362 | |||
363 | for (cp = pci_class_name; | ||
364 | cp < &pci_class_name[ARRAY_SIZE(pci_class_name)]; cp++) | ||
365 | if (cp->code == class_code) | ||
366 | return cp; | ||
367 | return NULL; | ||
368 | } | ||
369 | |||
370 | /* | ||
371 | * This assumes that the node slot is always on the primary bus! | ||
372 | */ | ||
373 | static void __init scan_bridge_slot(struct iseries_flat_dt *dt, | ||
374 | HvBusNumber bus, struct HvCallPci_BridgeInfo *bridge_info) | ||
375 | { | ||
376 | HvSubBusNumber sub_bus = bridge_info->subBusNumber; | ||
377 | u16 vendor_id; | ||
378 | u16 device_id; | ||
379 | u32 class_id; | ||
380 | int err; | ||
381 | char buf[32]; | ||
382 | u32 reg[5]; | ||
383 | int id_sel = ISERIES_GET_DEVICE_FROM_SUBBUS(sub_bus); | ||
384 | int function = ISERIES_GET_FUNCTION_FROM_SUBBUS(sub_bus); | ||
385 | HvAgentId eads_id_sel = ISERIES_PCI_AGENTID(id_sel, function); | ||
386 | u8 devfn; | ||
387 | struct pci_class_name *cp; | ||
388 | |||
389 | /* | ||
390 | * Connect all functions of any device found. | ||
391 | */ | ||
392 | for (id_sel = 1; id_sel <= bridge_info->maxAgents; id_sel++) { | ||
393 | for (function = 0; function < 8; function++) { | ||
394 | HvAgentId agent_id = ISERIES_PCI_AGENTID(id_sel, | ||
395 | function); | ||
396 | err = HvCallXm_connectBusUnit(bus, sub_bus, | ||
397 | agent_id, 0); | ||
398 | if (err) { | ||
399 | if (err != 0x302) | ||
400 | printk(KERN_DEBUG | ||
401 | "connectBusUnit(%x, %x, %x) " | ||
402 | "== %x\n", | ||
403 | bus, sub_bus, agent_id, err); | ||
404 | continue; | ||
405 | } | ||
406 | |||
407 | err = HvCallPci_configLoad16(bus, sub_bus, agent_id, | ||
408 | PCI_VENDOR_ID, &vendor_id); | ||
409 | if (err) { | ||
410 | printk(KERN_DEBUG | ||
411 | "ReadVendor(%x, %x, %x) == %x\n", | ||
412 | bus, sub_bus, agent_id, err); | ||
413 | continue; | ||
414 | } | ||
415 | err = HvCallPci_configLoad16(bus, sub_bus, agent_id, | ||
416 | PCI_DEVICE_ID, &device_id); | ||
417 | if (err) { | ||
418 | printk(KERN_DEBUG | ||
419 | "ReadDevice(%x, %x, %x) == %x\n", | ||
420 | bus, sub_bus, agent_id, err); | ||
421 | continue; | ||
422 | } | ||
423 | err = HvCallPci_configLoad32(bus, sub_bus, agent_id, | ||
424 | PCI_CLASS_REVISION , &class_id); | ||
425 | if (err) { | ||
426 | printk(KERN_DEBUG | ||
427 | "ReadClass(%x, %x, %x) == %x\n", | ||
428 | bus, sub_bus, agent_id, err); | ||
429 | continue; | ||
430 | } | ||
431 | |||
432 | devfn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(eads_id_sel), | ||
433 | function); | ||
434 | cp = dt_find_pci_class_name(class_id >> 16); | ||
435 | if (cp && cp->name) | ||
436 | strncpy(buf, cp->name, sizeof(buf) - 1); | ||
437 | else | ||
438 | snprintf(buf, sizeof(buf), "pci%x,%x", | ||
439 | vendor_id, device_id); | ||
440 | buf[sizeof(buf) - 1] = '\0'; | ||
441 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
442 | "@%x", PCI_SLOT(devfn)); | ||
443 | buf[sizeof(buf) - 1] = '\0'; | ||
444 | if (function != 0) | ||
445 | snprintf(buf + strlen(buf), | ||
446 | sizeof(buf) - strlen(buf), | ||
447 | ",%x", function); | ||
448 | dt_start_node(dt, buf); | ||
449 | reg[0] = (bus << 16) | (devfn << 8); | ||
450 | reg[1] = 0; | ||
451 | reg[2] = 0; | ||
452 | reg[3] = 0; | ||
453 | reg[4] = 0; | ||
454 | dt_prop_u32_list(dt, "reg", reg, 5); | ||
455 | if (cp && (cp->type || cp->name)) | ||
456 | dt_prop_str(dt, "device_type", | ||
457 | cp->type ? cp->type : cp->name); | ||
458 | dt_prop_u32(dt, "vendor-id", vendor_id); | ||
459 | dt_prop_u32(dt, "device-id", device_id); | ||
460 | dt_prop_u32(dt, "class-code", class_id >> 8); | ||
461 | dt_prop_u32(dt, "revision-id", class_id & 0xff); | ||
462 | dt_prop_u32(dt, "linux,subbus", sub_bus); | ||
463 | dt_prop_u32(dt, "linux,agent-id", agent_id); | ||
464 | dt_prop_u32(dt, "linux,logical-slot-number", | ||
465 | bridge_info->logicalSlotNumber); | ||
466 | dt_end_node(dt); | ||
467 | |||
468 | } | ||
469 | } | ||
470 | } | ||
471 | |||
472 | static void __init scan_bridge(struct iseries_flat_dt *dt, HvBusNumber bus, | ||
473 | HvSubBusNumber sub_bus, int id_sel) | ||
474 | { | ||
475 | struct HvCallPci_BridgeInfo bridge_info; | ||
476 | HvAgentId agent_id; | ||
477 | int function; | ||
478 | int ret; | ||
479 | |||
480 | /* Note: hvSubBus and irq is always be 0 at this level! */ | ||
481 | for (function = 0; function < 8; ++function) { | ||
482 | agent_id = ISERIES_PCI_AGENTID(id_sel, function); | ||
483 | ret = HvCallXm_connectBusUnit(bus, sub_bus, agent_id, 0); | ||
484 | if (ret != 0) { | ||
485 | if (ret != 0xb) | ||
486 | printk(KERN_DEBUG "connectBusUnit(%x, %x, %x) " | ||
487 | "== %x\n", | ||
488 | bus, sub_bus, agent_id, ret); | ||
489 | continue; | ||
490 | } | ||
491 | printk("found device at bus %d idsel %d func %d (AgentId %x)\n", | ||
492 | bus, id_sel, function, agent_id); | ||
493 | ret = HvCallPci_getBusUnitInfo(bus, sub_bus, agent_id, | ||
494 | iseries_hv_addr(&bridge_info), | ||
495 | sizeof(struct HvCallPci_BridgeInfo)); | ||
496 | if (ret != 0) | ||
497 | continue; | ||
498 | printk("bridge info: type %x subbus %x " | ||
499 | "maxAgents %x maxsubbus %x logslot %x\n", | ||
500 | bridge_info.busUnitInfo.deviceType, | ||
501 | bridge_info.subBusNumber, | ||
502 | bridge_info.maxAgents, | ||
503 | bridge_info.maxSubBusNumber, | ||
504 | bridge_info.logicalSlotNumber); | ||
505 | if (bridge_info.busUnitInfo.deviceType == | ||
506 | HvCallPci_BridgeDevice) | ||
507 | scan_bridge_slot(dt, bus, &bridge_info); | ||
508 | else | ||
509 | printk("PCI: Invalid Bridge Configuration(0x%02X)", | ||
510 | bridge_info.busUnitInfo.deviceType); | ||
511 | } | ||
512 | } | ||
513 | |||
514 | static void __init scan_phb(struct iseries_flat_dt *dt, HvBusNumber bus) | ||
515 | { | ||
516 | struct HvCallPci_DeviceInfo dev_info; | ||
517 | const HvSubBusNumber sub_bus = 0; /* EADs is always 0. */ | ||
518 | int err; | ||
519 | int id_sel; | ||
520 | const int max_agents = 8; | ||
521 | |||
522 | /* | ||
523 | * Probe for EADs Bridges | ||
524 | */ | ||
525 | for (id_sel = 1; id_sel < max_agents; ++id_sel) { | ||
526 | err = HvCallPci_getDeviceInfo(bus, sub_bus, id_sel, | ||
527 | iseries_hv_addr(&dev_info), | ||
528 | sizeof(struct HvCallPci_DeviceInfo)); | ||
529 | if (err) { | ||
530 | if (err != 0x302) | ||
531 | printk(KERN_DEBUG "getDeviceInfo(%x, %x, %x) " | ||
532 | "== %x\n", | ||
533 | bus, sub_bus, id_sel, err); | ||
534 | continue; | ||
535 | } | ||
536 | if (dev_info.deviceType != HvCallPci_NodeDevice) { | ||
537 | printk(KERN_DEBUG "PCI: Invalid System Configuration" | ||
538 | "(0x%02X) for bus 0x%02x id 0x%02x.\n", | ||
539 | dev_info.deviceType, bus, id_sel); | ||
540 | continue; | ||
541 | } | ||
542 | scan_bridge(dt, bus, sub_bus, id_sel); | ||
543 | } | ||
544 | } | ||
545 | |||
546 | static void __init dt_pci_devices(struct iseries_flat_dt *dt) | ||
547 | { | ||
548 | HvBusNumber bus; | ||
549 | char buf[32]; | ||
550 | u32 buses[2]; | ||
551 | int phb_num = 0; | ||
552 | |||
553 | /* Check all possible buses. */ | ||
554 | for (bus = 0; bus < 256; bus++) { | ||
555 | int err = HvCallXm_testBus(bus); | ||
556 | |||
557 | if (err) { | ||
558 | /* | ||
559 | * Check for Unexpected Return code, a clue that | ||
560 | * something has gone wrong. | ||
561 | */ | ||
562 | if (err != 0x0301) | ||
563 | printk(KERN_ERR "Unexpected Return on Probe" | ||
564 | "(0x%02X): 0x%04X", bus, err); | ||
565 | continue; | ||
566 | } | ||
567 | printk("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", "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 | |||
582 | void * __init build_flat_dt(unsigned long phys_mem_size) | ||
583 | { | ||
584 | u64 tmp[2]; | ||
585 | |||
586 | dt_init(&iseries_dt); | ||
587 | |||
588 | dt_start_node(&iseries_dt, ""); | ||
589 | |||
590 | dt_prop_u32(&iseries_dt, "#address-cells", 2); | ||
591 | dt_prop_u32(&iseries_dt, "#size-cells", 2); | ||
592 | dt_model(&iseries_dt); | ||
593 | |||
594 | /* /memory */ | ||
595 | dt_start_node(&iseries_dt, "memory@0"); | ||
596 | dt_prop_str(&iseries_dt, "name", "memory"); | ||
597 | dt_prop_str(&iseries_dt, "device_type", "memory"); | ||
598 | tmp[0] = 0; | ||
599 | tmp[1] = phys_mem_size; | ||
600 | dt_prop_u64_list(&iseries_dt, "reg", tmp, 2); | ||
601 | dt_end_node(&iseries_dt); | ||
602 | |||
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 | |||
608 | dt_cpus(&iseries_dt); | ||
609 | |||
610 | dt_vdevices(&iseries_dt); | ||
611 | dt_pci_devices(&iseries_dt); | ||
612 | |||
613 | dt_end_node(&iseries_dt); | ||
614 | |||
615 | dt_push_u32(&iseries_dt, OF_DT_END); | ||
616 | |||
617 | return &iseries_dt; | ||
618 | } | ||
diff --git a/arch/powerpc/platforms/iseries/setup.c b/arch/powerpc/platforms/iseries/setup.c index 5661bd0d42..617c724c45 100644 --- a/arch/powerpc/platforms/iseries/setup.c +++ b/arch/powerpc/platforms/iseries/setup.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include <linux/major.h> | 28 | #include <linux/major.h> |
29 | #include <linux/root_dev.h> | 29 | #include <linux/root_dev.h> |
30 | #include <linux/kernel.h> | 30 | #include <linux/kernel.h> |
31 | #include <linux/if_ether.h> /* ETH_ALEN */ | ||
32 | 31 | ||
33 | #include <asm/processor.h> | 32 | #include <asm/processor.h> |
34 | #include <asm/machdep.h> | 33 | #include <asm/machdep.h> |
@@ -46,13 +45,11 @@ | |||
46 | #include <asm/cache.h> | 45 | #include <asm/cache.h> |
47 | #include <asm/sections.h> | 46 | #include <asm/sections.h> |
48 | #include <asm/abs_addr.h> | 47 | #include <asm/abs_addr.h> |
49 | #include <asm/iseries/hv_types.h> | ||
50 | #include <asm/iseries/hv_lp_config.h> | 48 | #include <asm/iseries/hv_lp_config.h> |
51 | #include <asm/iseries/hv_call_event.h> | 49 | #include <asm/iseries/hv_call_event.h> |
52 | #include <asm/iseries/hv_call_xm.h> | 50 | #include <asm/iseries/hv_call_xm.h> |
53 | #include <asm/iseries/it_lp_queue.h> | 51 | #include <asm/iseries/it_lp_queue.h> |
54 | #include <asm/iseries/mf.h> | 52 | #include <asm/iseries/mf.h> |
55 | #include <asm/iseries/it_exp_vpd_panel.h> | ||
56 | #include <asm/iseries/hv_lp_event.h> | 53 | #include <asm/iseries/hv_lp_event.h> |
57 | #include <asm/iseries/lpar_map.h> | 54 | #include <asm/iseries/lpar_map.h> |
58 | #include <asm/udbg.h> | 55 | #include <asm/udbg.h> |
@@ -66,8 +63,6 @@ | |||
66 | #include "main_store.h" | 63 | #include "main_store.h" |
67 | #include "call_sm.h" | 64 | #include "call_sm.h" |
68 | #include "call_hpt.h" | 65 | #include "call_hpt.h" |
69 | #include "call_pci.h" | ||
70 | #include "pci.h" | ||
71 | 66 | ||
72 | #ifdef DEBUG | 67 | #ifdef DEBUG |
73 | #define DBG(fmt...) udbg_printf(fmt) | 68 | #define DBG(fmt...) udbg_printf(fmt) |
@@ -711,575 +706,6 @@ define_machine(iseries) { | |||
711 | /* XXX Implement enable_pmcs for iSeries */ | 706 | /* XXX Implement enable_pmcs for iSeries */ |
712 | }; | 707 | }; |
713 | 708 | ||
714 | struct blob { | ||
715 | unsigned char data[PAGE_SIZE * 2]; | ||
716 | unsigned long next; | ||
717 | }; | ||
718 | |||
719 | struct iseries_flat_dt { | ||
720 | struct boot_param_header header; | ||
721 | u64 reserve_map[2]; | ||
722 | struct blob dt; | ||
723 | struct blob strings; | ||
724 | }; | ||
725 | |||
726 | static struct iseries_flat_dt iseries_dt; | ||
727 | |||
728 | static void __init dt_init(struct iseries_flat_dt *dt) | ||
729 | { | ||
730 | dt->header.off_mem_rsvmap = | ||
731 | offsetof(struct iseries_flat_dt, reserve_map); | ||
732 | dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt); | ||
733 | dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings); | ||
734 | dt->header.totalsize = sizeof(struct iseries_flat_dt); | ||
735 | dt->header.dt_strings_size = sizeof(struct blob); | ||
736 | |||
737 | /* There is no notion of hardware cpu id on iSeries */ | ||
738 | dt->header.boot_cpuid_phys = smp_processor_id(); | ||
739 | |||
740 | dt->dt.next = (unsigned long)&dt->dt.data; | ||
741 | dt->strings.next = (unsigned long)&dt->strings.data; | ||
742 | |||
743 | dt->header.magic = OF_DT_HEADER; | ||
744 | dt->header.version = 0x10; | ||
745 | dt->header.last_comp_version = 0x10; | ||
746 | |||
747 | dt->reserve_map[0] = 0; | ||
748 | dt->reserve_map[1] = 0; | ||
749 | } | ||
750 | |||
751 | static void __init dt_check_blob(struct blob *b) | ||
752 | { | ||
753 | if (b->next >= (unsigned long)&b->next) { | ||
754 | DBG("Ran out of space in flat device tree blob!\n"); | ||
755 | BUG(); | ||
756 | } | ||
757 | } | ||
758 | |||
759 | static void __init dt_push_u32(struct iseries_flat_dt *dt, u32 value) | ||
760 | { | ||
761 | *((u32*)dt->dt.next) = value; | ||
762 | dt->dt.next += sizeof(u32); | ||
763 | |||
764 | dt_check_blob(&dt->dt); | ||
765 | } | ||
766 | |||
767 | #ifdef notyet | ||
768 | static void __init dt_push_u64(struct iseries_flat_dt *dt, u64 value) | ||
769 | { | ||
770 | *((u64*)dt->dt.next) = value; | ||
771 | dt->dt.next += sizeof(u64); | ||
772 | |||
773 | dt_check_blob(&dt->dt); | ||
774 | } | ||
775 | #endif | ||
776 | |||
777 | static unsigned long __init dt_push_bytes(struct blob *blob, char *data, int len) | ||
778 | { | ||
779 | unsigned long start = blob->next - (unsigned long)blob->data; | ||
780 | |||
781 | memcpy((char *)blob->next, data, len); | ||
782 | blob->next = _ALIGN(blob->next + len, 4); | ||
783 | |||
784 | dt_check_blob(blob); | ||
785 | |||
786 | return start; | ||
787 | } | ||
788 | |||
789 | static void __init dt_start_node(struct iseries_flat_dt *dt, char *name) | ||
790 | { | ||
791 | dt_push_u32(dt, OF_DT_BEGIN_NODE); | ||
792 | dt_push_bytes(&dt->dt, name, strlen(name) + 1); | ||
793 | } | ||
794 | |||
795 | #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE) | ||
796 | |||
797 | static void __init dt_prop(struct iseries_flat_dt *dt, char *name, | ||
798 | char *data, int len) | ||
799 | { | ||
800 | unsigned long offset; | ||
801 | |||
802 | dt_push_u32(dt, OF_DT_PROP); | ||
803 | |||
804 | /* Length of the data */ | ||
805 | dt_push_u32(dt, len); | ||
806 | |||
807 | /* Put the property name in the string blob. */ | ||
808 | offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1); | ||
809 | |||
810 | /* The offset of the properties name in the string blob. */ | ||
811 | dt_push_u32(dt, (u32)offset); | ||
812 | |||
813 | /* The actual data. */ | ||
814 | dt_push_bytes(&dt->dt, data, len); | ||
815 | } | ||
816 | |||
817 | static void __init dt_prop_str(struct iseries_flat_dt *dt, char *name, | ||
818 | char *data) | ||
819 | { | ||
820 | dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */ | ||
821 | } | ||
822 | |||
823 | static void __init dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data) | ||
824 | { | ||
825 | dt_prop(dt, name, (char *)&data, sizeof(u32)); | ||
826 | } | ||
827 | |||
828 | static void __init dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data) | ||
829 | { | ||
830 | dt_prop(dt, name, (char *)&data, sizeof(u64)); | ||
831 | } | ||
832 | |||
833 | static void __init dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, | ||
834 | u64 *data, int n) | ||
835 | { | ||
836 | dt_prop(dt, name, (char *)data, sizeof(u64) * n); | ||
837 | } | ||
838 | |||
839 | static void __init dt_prop_u32_list(struct iseries_flat_dt *dt, char *name, | ||
840 | u32 *data, int n) | ||
841 | { | ||
842 | dt_prop(dt, name, (char *)data, sizeof(u32) * n); | ||
843 | } | ||
844 | |||
845 | #ifdef notyet | ||
846 | static void __init dt_prop_empty(struct iseries_flat_dt *dt, char *name) | ||
847 | { | ||
848 | dt_prop(dt, name, NULL, 0); | ||
849 | } | ||
850 | #endif | ||
851 | |||
852 | static void __init dt_cpus(struct iseries_flat_dt *dt) | ||
853 | { | ||
854 | unsigned char buf[32]; | ||
855 | unsigned char *p; | ||
856 | unsigned int i, index; | ||
857 | struct IoHriProcessorVpd *d; | ||
858 | u32 pft_size[2]; | ||
859 | |||
860 | /* yuck */ | ||
861 | snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name); | ||
862 | p = strchr(buf, ' '); | ||
863 | if (!p) p = buf + strlen(buf); | ||
864 | |||
865 | dt_start_node(dt, "cpus"); | ||
866 | dt_prop_u32(dt, "#address-cells", 1); | ||
867 | dt_prop_u32(dt, "#size-cells", 0); | ||
868 | |||
869 | pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */ | ||
870 | pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE); | ||
871 | |||
872 | for (i = 0; i < NR_CPUS; i++) { | ||
873 | if (lppaca[i].dyn_proc_status >= 2) | ||
874 | continue; | ||
875 | |||
876 | snprintf(p, 32 - (p - buf), "@%d", i); | ||
877 | dt_start_node(dt, buf); | ||
878 | |||
879 | dt_prop_str(dt, "device_type", "cpu"); | ||
880 | |||
881 | index = lppaca[i].dyn_hv_phys_proc_index; | ||
882 | d = &xIoHriProcessorVpd[index]; | ||
883 | |||
884 | dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024); | ||
885 | dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize); | ||
886 | |||
887 | dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024); | ||
888 | dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize); | ||
889 | |||
890 | /* magic conversions to Hz copied from old code */ | ||
891 | dt_prop_u32(dt, "clock-frequency", | ||
892 | ((1UL << 34) * 1000000) / d->xProcFreq); | ||
893 | dt_prop_u32(dt, "timebase-frequency", | ||
894 | ((1UL << 32) * 1000000) / d->xTimeBaseFreq); | ||
895 | |||
896 | dt_prop_u32(dt, "reg", i); | ||
897 | |||
898 | dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2); | ||
899 | |||
900 | dt_end_node(dt); | ||
901 | } | ||
902 | |||
903 | dt_end_node(dt); | ||
904 | } | ||
905 | |||
906 | static void __init dt_model(struct iseries_flat_dt *dt) | ||
907 | { | ||
908 | char buf[16] = "IBM,"; | ||
909 | |||
910 | /* "IBM," + mfgId[2:3] + systemSerial[1:5] */ | ||
911 | strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2); | ||
912 | strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5); | ||
913 | buf[11] = '\0'; | ||
914 | dt_prop_str(dt, "system-id", buf); | ||
915 | |||
916 | /* "IBM," + machineType[0:4] */ | ||
917 | strne2a(buf + 4, xItExtVpdPanel.machineType, 4); | ||
918 | buf[8] = '\0'; | ||
919 | dt_prop_str(dt, "model", buf); | ||
920 | |||
921 | dt_prop_str(dt, "compatible", "IBM,iSeries"); | ||
922 | } | ||
923 | |||
924 | static void __init dt_vdevices(struct iseries_flat_dt *dt) | ||
925 | { | ||
926 | u32 reg = 0; | ||
927 | HvLpIndexMap vlan_map; | ||
928 | int i; | ||
929 | char buf[32]; | ||
930 | |||
931 | dt_start_node(dt, "vdevice"); | ||
932 | dt_prop_str(dt, "device_type", "vdevice"); | ||
933 | dt_prop_str(dt, "compatible", "IBM,iSeries-vdevice"); | ||
934 | dt_prop_u32(dt, "#address-cells", 1); | ||
935 | dt_prop_u32(dt, "#size-cells", 0); | ||
936 | |||
937 | snprintf(buf, sizeof(buf), "vty@%08x", reg); | ||
938 | dt_start_node(dt, buf); | ||
939 | dt_prop_str(dt, "device_type", "serial"); | ||
940 | dt_prop_u32(dt, "reg", reg); | ||
941 | dt_end_node(dt); | ||
942 | reg++; | ||
943 | |||
944 | snprintf(buf, sizeof(buf), "v-scsi@%08x", reg); | ||
945 | dt_start_node(dt, buf); | ||
946 | dt_prop_str(dt, "device_type", "vscsi"); | ||
947 | dt_prop_str(dt, "compatible", "IBM,v-scsi"); | ||
948 | dt_prop_u32(dt, "reg", reg); | ||
949 | dt_end_node(dt); | ||
950 | reg++; | ||
951 | |||
952 | vlan_map = HvLpConfig_getVirtualLanIndexMap(); | ||
953 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) { | ||
954 | unsigned char mac_addr[ETH_ALEN]; | ||
955 | |||
956 | if ((vlan_map & (0x8000 >> i)) == 0) | ||
957 | continue; | ||
958 | snprintf(buf, 32, "l-lan@%08x", reg + i); | ||
959 | dt_start_node(dt, buf); | ||
960 | dt_prop_str(dt, "device_type", "network"); | ||
961 | dt_prop_str(dt, "compatible", "IBM,iSeries-l-lan"); | ||
962 | dt_prop_u32(dt, "reg", reg + i); | ||
963 | dt_prop_u32(dt, "linux,unit_address", i); | ||
964 | |||
965 | mac_addr[0] = 0x02; | ||
966 | mac_addr[1] = 0x01; | ||
967 | mac_addr[2] = 0xff; | ||
968 | mac_addr[3] = i; | ||
969 | mac_addr[4] = 0xff; | ||
970 | mac_addr[5] = HvLpConfig_getLpIndex_outline(); | ||
971 | dt_prop(dt, "local-mac-address", (char *)mac_addr, ETH_ALEN); | ||
972 | dt_prop(dt, "mac-address", (char *)mac_addr, ETH_ALEN); | ||
973 | dt_prop_u32(dt, "max-frame-size", 9000); | ||
974 | dt_prop_u32(dt, "address-bits", 48); | ||
975 | |||
976 | dt_end_node(dt); | ||
977 | } | ||
978 | reg += HVMAXARCHITECTEDVIRTUALLANS; | ||
979 | |||
980 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++) { | ||
981 | snprintf(buf, 32, "viodasd@%08x", reg + i); | ||
982 | dt_start_node(dt, buf); | ||
983 | dt_prop_str(dt, "device_type", "block"); | ||
984 | dt_prop_str(dt, "compatible", "IBM,iSeries-viodasd"); | ||
985 | dt_prop_u32(dt, "reg", reg + i); | ||
986 | dt_prop_u32(dt, "linux,unit_address", i); | ||
987 | dt_end_node(dt); | ||
988 | } | ||
989 | reg += HVMAXARCHITECTEDVIRTUALDISKS; | ||
990 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++) { | ||
991 | snprintf(buf, 32, "viocd@%08x", reg + i); | ||
992 | dt_start_node(dt, buf); | ||
993 | dt_prop_str(dt, "device_type", "block"); | ||
994 | dt_prop_str(dt, "compatible", "IBM,iSeries-viocd"); | ||
995 | dt_prop_u32(dt, "reg", reg + i); | ||
996 | dt_prop_u32(dt, "linux,unit_address", i); | ||
997 | dt_end_node(dt); | ||
998 | } | ||
999 | reg += HVMAXARCHITECTEDVIRTUALCDROMS; | ||
1000 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++) { | ||
1001 | snprintf(buf, 32, "viotape@%08x", reg + i); | ||
1002 | dt_start_node(dt, buf); | ||
1003 | dt_prop_str(dt, "device_type", "byte"); | ||
1004 | dt_prop_str(dt, "compatible", "IBM,iSeries-viotape"); | ||
1005 | dt_prop_u32(dt, "reg", reg + i); | ||
1006 | dt_prop_u32(dt, "linux,unit_address", i); | ||
1007 | dt_end_node(dt); | ||
1008 | } | ||
1009 | |||
1010 | dt_end_node(dt); | ||
1011 | } | ||
1012 | |||
1013 | struct pci_class_name { | ||
1014 | u16 code; | ||
1015 | char *name; | ||
1016 | char *type; | ||
1017 | }; | ||
1018 | |||
1019 | static struct pci_class_name __initdata pci_class_name[] = { | ||
1020 | { PCI_CLASS_NETWORK_ETHERNET, "ethernet", "network" }, | ||
1021 | }; | ||
1022 | |||
1023 | static struct pci_class_name * __init dt_find_pci_class_name(u16 class_code) | ||
1024 | { | ||
1025 | struct pci_class_name *cp; | ||
1026 | |||
1027 | for (cp = pci_class_name; | ||
1028 | cp < &pci_class_name[ARRAY_SIZE(pci_class_name)]; cp++) | ||
1029 | if (cp->code == class_code) | ||
1030 | return cp; | ||
1031 | return NULL; | ||
1032 | } | ||
1033 | |||
1034 | /* | ||
1035 | * This assumes that the node slot is always on the primary bus! | ||
1036 | */ | ||
1037 | static void __init scan_bridge_slot(struct iseries_flat_dt *dt, | ||
1038 | HvBusNumber bus, struct HvCallPci_BridgeInfo *bridge_info) | ||
1039 | { | ||
1040 | HvSubBusNumber sub_bus = bridge_info->subBusNumber; | ||
1041 | u16 vendor_id; | ||
1042 | u16 device_id; | ||
1043 | u32 class_id; | ||
1044 | int err; | ||
1045 | char buf[32]; | ||
1046 | u32 reg[5]; | ||
1047 | int id_sel = ISERIES_GET_DEVICE_FROM_SUBBUS(sub_bus); | ||
1048 | int function = ISERIES_GET_FUNCTION_FROM_SUBBUS(sub_bus); | ||
1049 | HvAgentId eads_id_sel = ISERIES_PCI_AGENTID(id_sel, function); | ||
1050 | u8 devfn; | ||
1051 | struct pci_class_name *cp; | ||
1052 | |||
1053 | /* | ||
1054 | * Connect all functions of any device found. | ||
1055 | */ | ||
1056 | for (id_sel = 1; id_sel <= bridge_info->maxAgents; id_sel++) { | ||
1057 | for (function = 0; function < 8; function++) { | ||
1058 | HvAgentId agent_id = ISERIES_PCI_AGENTID(id_sel, | ||
1059 | function); | ||
1060 | err = HvCallXm_connectBusUnit(bus, sub_bus, | ||
1061 | agent_id, 0); | ||
1062 | if (err) { | ||
1063 | if (err != 0x302) | ||
1064 | printk(KERN_DEBUG | ||
1065 | "connectBusUnit(%x, %x, %x) " | ||
1066 | "== %x\n", | ||
1067 | bus, sub_bus, agent_id, err); | ||
1068 | continue; | ||
1069 | } | ||
1070 | |||
1071 | err = HvCallPci_configLoad16(bus, sub_bus, agent_id, | ||
1072 | PCI_VENDOR_ID, &vendor_id); | ||
1073 | if (err) { | ||
1074 | printk(KERN_DEBUG | ||
1075 | "ReadVendor(%x, %x, %x) == %x\n", | ||
1076 | bus, sub_bus, agent_id, err); | ||
1077 | continue; | ||
1078 | } | ||
1079 | err = HvCallPci_configLoad16(bus, sub_bus, agent_id, | ||
1080 | PCI_DEVICE_ID, &device_id); | ||
1081 | if (err) { | ||
1082 | printk(KERN_DEBUG | ||
1083 | "ReadDevice(%x, %x, %x) == %x\n", | ||
1084 | bus, sub_bus, agent_id, err); | ||
1085 | continue; | ||
1086 | } | ||
1087 | err = HvCallPci_configLoad32(bus, sub_bus, agent_id, | ||
1088 | PCI_CLASS_REVISION , &class_id); | ||
1089 | if (err) { | ||
1090 | printk(KERN_DEBUG | ||
1091 | "ReadClass(%x, %x, %x) == %x\n", | ||
1092 | bus, sub_bus, agent_id, err); | ||
1093 | continue; | ||
1094 | } | ||
1095 | |||
1096 | devfn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(eads_id_sel), | ||
1097 | function); | ||
1098 | cp = dt_find_pci_class_name(class_id >> 16); | ||
1099 | if (cp && cp->name) | ||
1100 | strncpy(buf, cp->name, sizeof(buf) - 1); | ||
1101 | else | ||
1102 | snprintf(buf, sizeof(buf), "pci%x,%x", | ||
1103 | vendor_id, device_id); | ||
1104 | buf[sizeof(buf) - 1] = '\0'; | ||
1105 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1106 | "@%x", PCI_SLOT(devfn)); | ||
1107 | buf[sizeof(buf) - 1] = '\0'; | ||
1108 | if (function != 0) | ||
1109 | snprintf(buf + strlen(buf), | ||
1110 | sizeof(buf) - strlen(buf), | ||
1111 | ",%x", function); | ||
1112 | dt_start_node(dt, buf); | ||
1113 | reg[0] = (bus << 16) | (devfn << 8); | ||
1114 | reg[1] = 0; | ||
1115 | reg[2] = 0; | ||
1116 | reg[3] = 0; | ||
1117 | reg[4] = 0; | ||
1118 | dt_prop_u32_list(dt, "reg", reg, 5); | ||
1119 | if (cp && (cp->type || cp->name)) | ||
1120 | dt_prop_str(dt, "device_type", | ||
1121 | cp->type ? cp->type : cp->name); | ||
1122 | dt_prop_u32(dt, "vendor-id", vendor_id); | ||
1123 | dt_prop_u32(dt, "device-id", device_id); | ||
1124 | dt_prop_u32(dt, "class-code", class_id >> 8); | ||
1125 | dt_prop_u32(dt, "revision-id", class_id & 0xff); | ||
1126 | dt_prop_u32(dt, "linux,subbus", sub_bus); | ||
1127 | dt_prop_u32(dt, "linux,agent-id", agent_id); | ||
1128 | dt_prop_u32(dt, "linux,logical-slot-number", | ||
1129 | bridge_info->logicalSlotNumber); | ||
1130 | dt_end_node(dt); | ||
1131 | |||
1132 | } | ||
1133 | } | ||
1134 | } | ||
1135 | |||
1136 | static void __init scan_bridge(struct iseries_flat_dt *dt, HvBusNumber bus, | ||
1137 | HvSubBusNumber sub_bus, int id_sel) | ||
1138 | { | ||
1139 | struct HvCallPci_BridgeInfo bridge_info; | ||
1140 | HvAgentId agent_id; | ||
1141 | int function; | ||
1142 | int ret; | ||
1143 | |||
1144 | /* Note: hvSubBus and irq is always be 0 at this level! */ | ||
1145 | for (function = 0; function < 8; ++function) { | ||
1146 | agent_id = ISERIES_PCI_AGENTID(id_sel, function); | ||
1147 | ret = HvCallXm_connectBusUnit(bus, sub_bus, agent_id, 0); | ||
1148 | if (ret != 0) { | ||
1149 | if (ret != 0xb) | ||
1150 | printk(KERN_DEBUG "connectBusUnit(%x, %x, %x) " | ||
1151 | "== %x\n", | ||
1152 | bus, sub_bus, agent_id, ret); | ||
1153 | continue; | ||
1154 | } | ||
1155 | printk("found device at bus %d idsel %d func %d (AgentId %x)\n", | ||
1156 | bus, id_sel, function, agent_id); | ||
1157 | ret = HvCallPci_getBusUnitInfo(bus, sub_bus, agent_id, | ||
1158 | iseries_hv_addr(&bridge_info), | ||
1159 | sizeof(struct HvCallPci_BridgeInfo)); | ||
1160 | if (ret != 0) | ||
1161 | continue; | ||
1162 | printk("bridge info: type %x subbus %x " | ||
1163 | "maxAgents %x maxsubbus %x logslot %x\n", | ||
1164 | bridge_info.busUnitInfo.deviceType, | ||
1165 | bridge_info.subBusNumber, | ||
1166 | bridge_info.maxAgents, | ||
1167 | bridge_info.maxSubBusNumber, | ||
1168 | bridge_info.logicalSlotNumber); | ||
1169 | if (bridge_info.busUnitInfo.deviceType == | ||
1170 | HvCallPci_BridgeDevice) | ||
1171 | scan_bridge_slot(dt, bus, &bridge_info); | ||
1172 | else | ||
1173 | printk("PCI: Invalid Bridge Configuration(0x%02X)", | ||
1174 | bridge_info.busUnitInfo.deviceType); | ||
1175 | } | ||
1176 | } | ||
1177 | |||
1178 | static void __init scan_phb(struct iseries_flat_dt *dt, HvBusNumber bus) | ||
1179 | { | ||
1180 | struct HvCallPci_DeviceInfo dev_info; | ||
1181 | const HvSubBusNumber sub_bus = 0; /* EADs is always 0. */ | ||
1182 | int err; | ||
1183 | int id_sel; | ||
1184 | const int max_agents = 8; | ||
1185 | |||
1186 | /* | ||
1187 | * Probe for EADs Bridges | ||
1188 | */ | ||
1189 | for (id_sel = 1; id_sel < max_agents; ++id_sel) { | ||
1190 | err = HvCallPci_getDeviceInfo(bus, sub_bus, id_sel, | ||
1191 | iseries_hv_addr(&dev_info), | ||
1192 | sizeof(struct HvCallPci_DeviceInfo)); | ||
1193 | if (err) { | ||
1194 | if (err != 0x302) | ||
1195 | printk(KERN_DEBUG "getDeviceInfo(%x, %x, %x) " | ||
1196 | "== %x\n", | ||
1197 | bus, sub_bus, id_sel, err); | ||
1198 | continue; | ||
1199 | } | ||
1200 | if (dev_info.deviceType != HvCallPci_NodeDevice) { | ||
1201 | printk(KERN_DEBUG "PCI: Invalid System Configuration" | ||
1202 | "(0x%02X) for bus 0x%02x id 0x%02x.\n", | ||
1203 | dev_info.deviceType, bus, id_sel); | ||
1204 | continue; | ||
1205 | } | ||
1206 | scan_bridge(dt, bus, sub_bus, id_sel); | ||
1207 | } | ||
1208 | } | ||
1209 | |||
1210 | static void __init dt_pci_devices(struct iseries_flat_dt *dt) | ||
1211 | { | ||
1212 | HvBusNumber bus; | ||
1213 | char buf[32]; | ||
1214 | u32 buses[2]; | ||
1215 | int phb_num = 0; | ||
1216 | |||
1217 | /* Check all possible buses. */ | ||
1218 | for (bus = 0; bus < 256; bus++) { | ||
1219 | int err = HvCallXm_testBus(bus); | ||
1220 | |||
1221 | if (err) { | ||
1222 | /* | ||
1223 | * Check for Unexpected Return code, a clue that | ||
1224 | * something has gone wrong. | ||
1225 | */ | ||
1226 | if (err != 0x0301) | ||
1227 | printk(KERN_ERR "Unexpected Return on Probe" | ||
1228 | "(0x%02X): 0x%04X", bus, err); | ||
1229 | continue; | ||
1230 | } | ||
1231 | printk("bus %d appears to exist\n", bus); | ||
1232 | snprintf(buf, 32, "pci@%d", phb_num); | ||
1233 | dt_start_node(dt, buf); | ||
1234 | dt_prop_str(dt, "device_type", "pci"); | ||
1235 | dt_prop_str(dt, "compatible", "IBM,iSeries-Logical-PHB"); | ||
1236 | dt_prop_u32(dt, "#address-cells", 3); | ||
1237 | dt_prop_u32(dt, "#size-cells", 2); | ||
1238 | buses[0] = buses[1] = bus; | ||
1239 | dt_prop_u32_list(dt, "bus-range", buses, 2); | ||
1240 | scan_phb(dt, bus); | ||
1241 | dt_end_node(dt); | ||
1242 | phb_num++; | ||
1243 | } | ||
1244 | } | ||
1245 | |||
1246 | static void __init build_flat_dt(struct iseries_flat_dt *dt, | ||
1247 | unsigned long phys_mem_size) | ||
1248 | { | ||
1249 | u64 tmp[2]; | ||
1250 | |||
1251 | dt_init(dt); | ||
1252 | |||
1253 | dt_start_node(dt, ""); | ||
1254 | |||
1255 | dt_prop_u32(dt, "#address-cells", 2); | ||
1256 | dt_prop_u32(dt, "#size-cells", 2); | ||
1257 | dt_model(dt); | ||
1258 | |||
1259 | /* /memory */ | ||
1260 | dt_start_node(dt, "memory@0"); | ||
1261 | dt_prop_str(dt, "name", "memory"); | ||
1262 | dt_prop_str(dt, "device_type", "memory"); | ||
1263 | tmp[0] = 0; | ||
1264 | tmp[1] = phys_mem_size; | ||
1265 | dt_prop_u64_list(dt, "reg", tmp, 2); | ||
1266 | dt_end_node(dt); | ||
1267 | |||
1268 | /* /chosen */ | ||
1269 | dt_start_node(dt, "chosen"); | ||
1270 | dt_prop_str(dt, "bootargs", cmd_line); | ||
1271 | dt_end_node(dt); | ||
1272 | |||
1273 | dt_cpus(dt); | ||
1274 | |||
1275 | dt_vdevices(dt); | ||
1276 | dt_pci_devices(dt); | ||
1277 | |||
1278 | dt_end_node(dt); | ||
1279 | |||
1280 | dt_push_u32(dt, OF_DT_END); | ||
1281 | } | ||
1282 | |||
1283 | void * __init iSeries_early_setup(void) | 709 | void * __init iSeries_early_setup(void) |
1284 | { | 710 | { |
1285 | unsigned long phys_mem_size; | 711 | unsigned long phys_mem_size; |
@@ -1294,9 +720,7 @@ void * __init iSeries_early_setup(void) | |||
1294 | 720 | ||
1295 | iSeries_get_cmdline(); | 721 | iSeries_get_cmdline(); |
1296 | 722 | ||
1297 | build_flat_dt(&iseries_dt, phys_mem_size); | 723 | return (void *) __pa(build_flat_dt(phys_mem_size)); |
1298 | |||
1299 | return (void *) __pa(&iseries_dt); | ||
1300 | } | 724 | } |
1301 | 725 | ||
1302 | static void hvputc(char c) | 726 | static void hvputc(char c) |
diff --git a/arch/powerpc/platforms/iseries/setup.h b/arch/powerpc/platforms/iseries/setup.h index 5213044ec4..0a47ac53c9 100644 --- a/arch/powerpc/platforms/iseries/setup.h +++ b/arch/powerpc/platforms/iseries/setup.h | |||
@@ -21,4 +21,6 @@ extern unsigned long iSeries_get_boot_time(void); | |||
21 | extern int iSeries_set_rtc_time(struct rtc_time *tm); | 21 | extern int iSeries_set_rtc_time(struct rtc_time *tm); |
22 | extern void iSeries_get_rtc_time(struct rtc_time *tm); | 22 | extern void iSeries_get_rtc_time(struct rtc_time *tm); |
23 | 23 | ||
24 | extern void *build_flat_dt(unsigned long phys_mem_size); | ||
25 | |||
24 | #endif /* __ISERIES_SETUP_H__ */ | 26 | #endif /* __ISERIES_SETUP_H__ */ |