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