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