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