Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Written by: Garry Forsgren, Unisys Corporation |
| 3 | * Natalie Protasevich, Unisys Corporation |
| 4 | * This file contains the code to configure and interface |
| 5 | * with Unisys ES7000 series hardware system manager. |
| 6 | * |
| 7 | * Copyright (c) 2003 Unisys Corporation. All Rights Reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it would be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 19 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 20 | * |
| 21 | * Contact information: Unisys Corporation, Township Line & Union Meeting |
| 22 | * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or: |
| 23 | * |
| 24 | * http://www.unisys.com |
| 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/smp.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/spinlock.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/notifier.h> |
| 35 | #include <linux/reboot.h> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/acpi.h> |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/nmi.h> |
| 40 | #include <asm/smp.h> |
| 41 | #include <asm/apicdef.h> |
Vivek Goyal | 071922c | 2007-07-06 02:39:55 -0700 | [diff] [blame] | 42 | #include <mach_mpparse.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
Yinghai Lu | 1625324 | 2008-08-27 23:01:16 -0700 | [diff] [blame] | 45 | * ES7000 chipsets |
| 46 | */ |
| 47 | |
| 48 | #define NON_UNISYS 0 |
| 49 | #define ES7000_CLASSIC 1 |
| 50 | #define ES7000_ZORRO 2 |
| 51 | |
| 52 | |
| 53 | #define MIP_REG 1 |
| 54 | #define MIP_PSAI_REG 4 |
| 55 | |
| 56 | #define MIP_BUSY 1 |
| 57 | #define MIP_SPIN 0xf0000 |
| 58 | #define MIP_VALID 0x0100000000000000ULL |
| 59 | #define MIP_PORT(VALUE) ((VALUE >> 32) & 0xffff) |
| 60 | |
| 61 | #define MIP_RD_LO(VALUE) (VALUE & 0xffffffff) |
| 62 | |
| 63 | struct mip_reg_info { |
| 64 | unsigned long long mip_info; |
| 65 | unsigned long long delivery_info; |
| 66 | unsigned long long host_reg; |
| 67 | unsigned long long mip_reg; |
| 68 | }; |
| 69 | |
| 70 | struct part_info { |
| 71 | unsigned char type; |
| 72 | unsigned char length; |
| 73 | unsigned char part_id; |
| 74 | unsigned char apic_mode; |
| 75 | unsigned long snum; |
| 76 | char ptype[16]; |
| 77 | char sname[64]; |
| 78 | char pname[64]; |
| 79 | }; |
| 80 | |
| 81 | struct psai { |
| 82 | unsigned long long entry_type; |
| 83 | unsigned long long addr; |
| 84 | unsigned long long bep_addr; |
| 85 | }; |
| 86 | |
| 87 | struct es7000_mem_info { |
| 88 | unsigned char type; |
| 89 | unsigned char length; |
| 90 | unsigned char resv[6]; |
| 91 | unsigned long long start; |
| 92 | unsigned long long size; |
| 93 | }; |
| 94 | |
| 95 | struct es7000_oem_table { |
| 96 | unsigned long long hdr; |
| 97 | struct mip_reg_info mip; |
| 98 | struct part_info pif; |
| 99 | struct es7000_mem_info shm; |
| 100 | struct psai psai; |
| 101 | }; |
| 102 | |
| 103 | #ifdef CONFIG_ACPI |
| 104 | |
| 105 | struct oem_table { |
| 106 | struct acpi_table_header Header; |
| 107 | u32 OEMTableAddr; |
| 108 | u32 OEMTableSize; |
| 109 | }; |
| 110 | |
| 111 | extern int find_unisys_acpi_oem_table(unsigned long *oem_addr); |
Yinghai Lu | a73aaed | 2008-09-14 02:33:14 -0700 | [diff] [blame] | 112 | extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr); |
Yinghai Lu | 1625324 | 2008-08-27 23:01:16 -0700 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | struct mip_reg { |
| 116 | unsigned long long off_0; |
| 117 | unsigned long long off_8; |
| 118 | unsigned long long off_10; |
| 119 | unsigned long long off_18; |
| 120 | unsigned long long off_20; |
| 121 | unsigned long long off_28; |
| 122 | unsigned long long off_30; |
| 123 | unsigned long long off_38; |
| 124 | }; |
| 125 | |
| 126 | #define MIP_SW_APIC 0x1020b |
| 127 | #define MIP_FUNC(VALUE) (VALUE & 0xff) |
| 128 | |
| 129 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | * ES7000 Globals |
| 131 | */ |
| 132 | |
Adrian Bunk | fb7ae26 | 2007-10-17 18:04:37 +0200 | [diff] [blame] | 133 | static volatile unsigned long *psai = NULL; |
| 134 | static struct mip_reg *mip_reg; |
| 135 | static struct mip_reg *host_reg; |
| 136 | static int mip_port; |
| 137 | static unsigned long mip_addr, host_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Alexey Starikovskiy | 32c5061 | 2008-05-14 19:02:51 +0400 | [diff] [blame] | 139 | int es7000_plat; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* |
| 142 | * GSI override for ES7000 platforms. |
| 143 | */ |
| 144 | |
| 145 | static unsigned int base; |
| 146 | |
| 147 | static int |
| 148 | es7000_rename_gsi(int ioapic, int gsi) |
| 149 | { |
Natalie.Protasevich@unisys.com | 9338316 | 2005-10-30 14:59:38 -0800 | [diff] [blame] | 150 | if (es7000_plat == ES7000_ZORRO) |
| 151 | return gsi; |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | if (!base) { |
| 154 | int i; |
| 155 | for (i = 0; i < nr_ioapics; i++) |
| 156 | base += nr_ioapic_registers[i]; |
| 157 | } |
| 158 | |
Yinghai Lu | c7e7964 | 2008-07-25 02:17:33 -0700 | [diff] [blame] | 159 | if (!ioapic && (gsi < 16)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | gsi += base; |
| 161 | return gsi; |
| 162 | } |
| 163 | |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 164 | void __init |
Natalie.Protasevich@unisys.com | 9338316 | 2005-10-30 14:59:38 -0800 | [diff] [blame] | 165 | setup_unisys(void) |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 166 | { |
| 167 | /* |
| 168 | * Determine the generation of the ES7000 currently running. |
| 169 | * |
| 170 | * es7000_plat = 1 if the machine is a 5xx ES7000 box |
| 171 | * es7000_plat = 2 if the machine is a x86_64 ES7000 box |
| 172 | * |
| 173 | */ |
| 174 | if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2)) |
Natalie.Protasevich@unisys.com | 9338316 | 2005-10-30 14:59:38 -0800 | [diff] [blame] | 175 | es7000_plat = ES7000_ZORRO; |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 176 | else |
Natalie.Protasevich@unisys.com | 9338316 | 2005-10-30 14:59:38 -0800 | [diff] [blame] | 177 | es7000_plat = ES7000_CLASSIC; |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 178 | ioapic_renumber_irq = es7000_rename_gsi; |
| 179 | } |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Parse the OEM Table |
| 183 | */ |
| 184 | |
| 185 | int __init |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 186 | parse_unisys_oem (char *oemptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | int i; |
| 189 | int success = 0; |
| 190 | unsigned char type, size; |
| 191 | unsigned long val; |
| 192 | char *tp = NULL; |
| 193 | struct psai *psaip = NULL; |
| 194 | struct mip_reg_info *mi; |
| 195 | struct mip_reg *host, *mip; |
| 196 | |
| 197 | tp = oemptr; |
| 198 | |
| 199 | tp += 8; |
| 200 | |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 201 | for (i=0; i <= 6; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | type = *tp++; |
| 203 | size = *tp++; |
| 204 | tp -= 2; |
| 205 | switch (type) { |
| 206 | case MIP_REG: |
| 207 | mi = (struct mip_reg_info *)tp; |
| 208 | val = MIP_RD_LO(mi->host_reg); |
| 209 | host_addr = val; |
| 210 | host = (struct mip_reg *)val; |
| 211 | host_reg = __va(host); |
| 212 | val = MIP_RD_LO(mi->mip_reg); |
| 213 | mip_port = MIP_PORT(mi->mip_info); |
| 214 | mip_addr = val; |
| 215 | mip = (struct mip_reg *)val; |
| 216 | mip_reg = __va(mip); |
Thomas Gleixner | 5171c30 | 2008-07-21 21:58:34 +0200 | [diff] [blame] | 217 | pr_debug("es7000_mipcfg: host_reg = 0x%lx \n", |
| 218 | (unsigned long)host_reg); |
| 219 | pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n", |
| 220 | (unsigned long)mip_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | success++; |
| 222 | break; |
| 223 | case MIP_PSAI_REG: |
| 224 | psaip = (struct psai *)tp; |
| 225 | if (tp != NULL) { |
| 226 | if (psaip->addr) |
| 227 | psai = __va(psaip->addr); |
| 228 | else |
| 229 | psai = NULL; |
| 230 | success++; |
| 231 | } |
| 232 | break; |
| 233 | default: |
| 234 | break; |
| 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | tp += size; |
| 237 | } |
| 238 | |
| 239 | if (success < 2) { |
Natalie.Protasevich@unisys.com | 9338316 | 2005-10-30 14:59:38 -0800 | [diff] [blame] | 240 | es7000_plat = NON_UNISYS; |
Natalie.Protasevich@unisys.com | 56f1d5d | 2005-09-03 15:56:34 -0700 | [diff] [blame] | 241 | } else |
| 242 | setup_unisys(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return es7000_plat; |
| 244 | } |
| 245 | |
Natalie.Protasevich@unisys.com | e5428ed | 2006-03-23 02:59:36 -0800 | [diff] [blame] | 246 | #ifdef CONFIG_ACPI |
Yinghai Lu | a73aaed | 2008-09-14 02:33:14 -0700 | [diff] [blame] | 247 | static unsigned long oem_addrX; |
| 248 | static unsigned long oem_size; |
| 249 | int __init find_unisys_acpi_oem_table(unsigned long *oem_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 251 | struct acpi_table_header *header = NULL; |
| 252 | int i = 0; |
Yinghai Lu | a73aaed | 2008-09-14 02:33:14 -0700 | [diff] [blame] | 253 | acpi_size tbl_size; |
| 254 | |
| 255 | while (ACPI_SUCCESS(acpi_get_table_with_size("OEM1", i++, &header, &tbl_size))) { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 256 | if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) { |
| 257 | struct oem_table *t = (struct oem_table *)header; |
Yinghai Lu | a73aaed | 2008-09-14 02:33:14 -0700 | [diff] [blame] | 258 | |
| 259 | oem_addrX = t->OEMTableAddr; |
| 260 | oem_size = t->OEMTableSize; |
| 261 | early_acpi_os_unmap_memory(header, tbl_size); |
| 262 | |
| 263 | *oem_addr = (unsigned long)__acpi_map_table(oem_addrX, |
| 264 | oem_size); |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 265 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
Yinghai Lu | a73aaed | 2008-09-14 02:33:14 -0700 | [diff] [blame] | 267 | early_acpi_os_unmap_memory(header, tbl_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | return -1; |
| 270 | } |
Yinghai Lu | a73aaed | 2008-09-14 02:33:14 -0700 | [diff] [blame] | 271 | |
| 272 | void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr) |
| 273 | { |
| 274 | if (!oem_addr) |
| 275 | return; |
| 276 | |
| 277 | __acpi_unmap_table((char *)oem_addr, oem_size); |
| 278 | } |
Natalie.Protasevich@unisys.com | e5428ed | 2006-03-23 02:59:36 -0800 | [diff] [blame] | 279 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | static void |
| 282 | es7000_spin(int n) |
| 283 | { |
| 284 | int i = 0; |
| 285 | |
| 286 | while (i++ < n) |
| 287 | rep_nop(); |
| 288 | } |
| 289 | |
| 290 | static int __init |
| 291 | es7000_mip_write(struct mip_reg *mip_reg) |
| 292 | { |
| 293 | int status = 0; |
| 294 | int spin; |
| 295 | |
| 296 | spin = MIP_SPIN; |
| 297 | while (((unsigned long long)host_reg->off_38 & |
| 298 | (unsigned long long)MIP_VALID) != 0) { |
| 299 | if (--spin <= 0) { |
| 300 | printk("es7000_mip_write: Timeout waiting for Host Valid Flag"); |
| 301 | return -1; |
| 302 | } |
| 303 | es7000_spin(MIP_SPIN); |
| 304 | } |
| 305 | |
| 306 | memcpy(host_reg, mip_reg, sizeof(struct mip_reg)); |
| 307 | outb(1, mip_port); |
| 308 | |
| 309 | spin = MIP_SPIN; |
| 310 | |
| 311 | while (((unsigned long long)mip_reg->off_38 & |
| 312 | (unsigned long long)MIP_VALID) == 0) { |
| 313 | if (--spin <= 0) { |
| 314 | printk("es7000_mip_write: Timeout waiting for MIP Valid Flag"); |
| 315 | return -1; |
| 316 | } |
| 317 | es7000_spin(MIP_SPIN); |
| 318 | } |
| 319 | |
| 320 | status = ((unsigned long long)mip_reg->off_0 & |
| 321 | (unsigned long long)0xffff0000000000ULL) >> 48; |
| 322 | mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 & |
| 323 | (unsigned long long)~MIP_VALID); |
| 324 | return status; |
| 325 | } |
| 326 | |
| 327 | int |
| 328 | es7000_start_cpu(int cpu, unsigned long eip) |
| 329 | { |
| 330 | unsigned long vect = 0, psaival = 0; |
| 331 | |
| 332 | if (psai == NULL) |
| 333 | return -1; |
| 334 | |
| 335 | vect = ((unsigned long)__pa(eip)/0x1000) << 16; |
| 336 | psaival = (0x1000000 | vect | cpu); |
| 337 | |
| 338 | while (*psai & 0x1000000) |
| 339 | ; |
| 340 | |
| 341 | *psai = psaival; |
| 342 | |
| 343 | return 0; |
| 344 | |
| 345 | } |
| 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | void __init |
Adrian Bunk | fb7ae26 | 2007-10-17 18:04:37 +0200 | [diff] [blame] | 348 | es7000_sw_apic(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | if (es7000_plat) { |
| 351 | int mip_status; |
| 352 | struct mip_reg es7000_mip_reg; |
| 353 | |
| 354 | printk("ES7000: Enabling APIC mode.\n"); |
| 355 | memset(&es7000_mip_reg, 0, sizeof(struct mip_reg)); |
| 356 | es7000_mip_reg.off_0 = MIP_SW_APIC; |
| 357 | es7000_mip_reg.off_38 = (MIP_VALID); |
| 358 | while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0) |
| 359 | printk("es7000_sw_apic: command failed, status = %x\n", |
| 360 | mip_status); |
| 361 | return; |
| 362 | } |
| 363 | } |