Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * PROM library initialisation code. |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 7 | * |
| 8 | * Copyright (C) 1999,2000,2004,2005,2012 MIPS Technologies, Inc. |
| 9 | * All rights reserved. |
| 10 | * Authors: Carsten Langgaard <carstenl@mips.com> |
| 11 | * Maciej W. Rozycki <macro@mips.com> |
| 12 | * Steven J. Hill <sjhill@mips.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/kernel.h> |
Peter Hurley | df519e7 | 2015-03-09 16:27:22 -0400 | [diff] [blame] | 17 | #include <linux/serial_core.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 19 | #include <asm/cacheflush.h> |
Ralf Baechle | 852fe31 | 2011-05-28 15:27:59 +0100 | [diff] [blame] | 20 | #include <asm/smp-ops.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 21 | #include <asm/traps.h> |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 22 | #include <asm/fw/fw.h> |
Paul Burton | 237036d | 2014-01-15 10:31:54 +0000 | [diff] [blame] | 23 | #include <asm/mips-cm.h> |
Paul Burton | 7dc2834 | 2014-01-15 10:31:55 +0000 | [diff] [blame] | 24 | #include <asm/mips-cpc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/mips-boards/generic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/mips-boards/malta.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Dmitri Vorobiev | d0cdfe2 | 2009-03-23 00:12:27 +0200 | [diff] [blame] | 28 | static int mips_revision_corid; |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 29 | int mips_revision_sconid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* Bonito64 system controller register base. */ |
| 32 | unsigned long _pcictrl_bonito; |
| 33 | unsigned long _pcictrl_bonito_pcicfg; |
| 34 | |
| 35 | /* GT64120 system controller register base */ |
| 36 | unsigned long _pcictrl_gt64120; |
| 37 | |
| 38 | /* MIPS System controller register base */ |
| 39 | unsigned long _pcictrl_msc; |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
| 42 | static void __init console_config(void) |
| 43 | { |
| 44 | char console_string[40]; |
| 45 | int baud = 0; |
| 46 | char parity = '\0', bits = '\0', flow = '\0'; |
| 47 | char *s; |
| 48 | |
Paul Burton | 23a91de | 2013-12-02 16:48:38 +0000 | [diff] [blame] | 49 | s = fw_getenv("modetty0"); |
| 50 | if (s) { |
| 51 | while (*s >= '0' && *s <= '9') |
| 52 | baud = baud*10 + *s++ - '0'; |
| 53 | if (*s == ',') |
| 54 | s++; |
| 55 | if (*s) |
| 56 | parity = *s++; |
| 57 | if (*s == ',') |
| 58 | s++; |
| 59 | if (*s) |
| 60 | bits = *s++; |
| 61 | if (*s == ',') |
| 62 | s++; |
| 63 | if (*s == 'h') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | flow = 'r'; |
Paul Burton | 23a91de | 2013-12-02 16:48:38 +0000 | [diff] [blame] | 65 | } |
| 66 | if (baud == 0) |
| 67 | baud = 38400; |
| 68 | if (parity != 'n' && parity != 'o' && parity != 'e') |
| 69 | parity = 'n'; |
| 70 | if (bits != '7' && bits != '8') |
| 71 | bits = '8'; |
| 72 | if (flow == '\0') |
| 73 | flow = 'r'; |
| 74 | |
| 75 | if ((strstr(fw_getcmdline(), "earlycon=")) == NULL) { |
| 76 | sprintf(console_string, "uart8250,io,0x3f8,%d%c%c", baud, |
| 77 | parity, bits); |
Peter Hurley | df519e7 | 2015-03-09 16:27:22 -0400 | [diff] [blame] | 78 | setup_earlycon(console_string); |
Paul Burton | 23a91de | 2013-12-02 16:48:38 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | if ((strstr(fw_getcmdline(), "console=")) == NULL) { |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 82 | sprintf(console_string, " console=ttyS0,%d%c%c%c", baud, |
| 83 | parity, bits, flow); |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 84 | strcat(fw_getcmdline(), console_string); |
Ralf Baechle | 36a8853 | 2007-03-01 11:56:43 +0000 | [diff] [blame] | 85 | pr_info("Config serial console:%s\n", console_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | #endif |
| 89 | |
Dmitri Vorobiev | cd2675f | 2008-04-01 02:03:20 +0400 | [diff] [blame] | 90 | static void __init mips_nmi_setup(void) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 91 | { |
| 92 | void *base; |
| 93 | extern char except_vec_nmi; |
| 94 | |
| 95 | base = cpu_has_veic ? |
| 96 | (void *)(CAC_BASE + 0xa80) : |
| 97 | (void *)(CAC_BASE + 0x380); |
| 98 | memcpy(base, &except_vec_nmi, 0x80); |
| 99 | flush_icache_range((unsigned long)base, (unsigned long)base + 0x80); |
| 100 | } |
| 101 | |
Dmitri Vorobiev | 33d69d2 | 2008-04-01 02:03:21 +0400 | [diff] [blame] | 102 | static void __init mips_ejtag_setup(void) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 103 | { |
| 104 | void *base; |
| 105 | extern char except_vec_ejtag_debug; |
| 106 | |
| 107 | base = cpu_has_veic ? |
| 108 | (void *)(CAC_BASE + 0xa00) : |
| 109 | (void *)(CAC_BASE + 0x300); |
| 110 | memcpy(base, &except_vec_ejtag_debug, 0x80); |
| 111 | flush_icache_range((unsigned long)base, (unsigned long)base + 0x80); |
| 112 | } |
| 113 | |
Ralf Baechle | 15d45cc | 2014-11-22 00:22:09 +0100 | [diff] [blame] | 114 | phys_addr_t mips_cpc_default_phys_base(void) |
Paul Burton | 7dc2834 | 2014-01-15 10:31:55 +0000 | [diff] [blame] | 115 | { |
| 116 | return CPC_BASE_ADDR; |
| 117 | } |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | void __init prom_init(void) |
| 120 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | mips_display_message("LINUX"); |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
| 124 | * early setup of _pcictrl_bonito so that we can determine |
| 125 | * the system controller on a CORE_EMUL board |
| 126 | */ |
| 127 | _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE); |
| 128 | |
| 129 | mips_revision_corid = MIPS_REVISION_CORID; |
| 130 | |
| 131 | if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) { |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 132 | if (BONITO_PCIDID == 0x0001df53 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | BONITO_PCIDID == 0x0003df53) |
| 134 | mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON; |
| 135 | else |
| 136 | mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC; |
| 137 | } |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 138 | |
| 139 | mips_revision_sconid = MIPS_REVISION_SCONID; |
| 140 | if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) { |
| 141 | switch (mips_revision_corid) { |
| 142 | case MIPS_REVISION_CORID_QED_RM5261: |
| 143 | case MIPS_REVISION_CORID_CORE_LV: |
| 144 | case MIPS_REVISION_CORID_CORE_FPGA: |
| 145 | case MIPS_REVISION_CORID_CORE_FPGAR2: |
| 146 | mips_revision_sconid = MIPS_REVISION_SCON_GT64120; |
| 147 | break; |
| 148 | case MIPS_REVISION_CORID_CORE_EMUL_BON: |
| 149 | case MIPS_REVISION_CORID_BONITO64: |
| 150 | case MIPS_REVISION_CORID_CORE_20K: |
| 151 | mips_revision_sconid = MIPS_REVISION_SCON_BONITO; |
| 152 | break; |
| 153 | case MIPS_REVISION_CORID_CORE_MSC: |
| 154 | case MIPS_REVISION_CORID_CORE_FPGA2: |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 155 | case MIPS_REVISION_CORID_CORE_24K: |
Chris Dearman | 3084024 | 2007-09-21 14:50:08 +0100 | [diff] [blame] | 156 | /* |
| 157 | * SOCit/ROCit support is essentially identical |
| 158 | * but make an attempt to distinguish them |
| 159 | */ |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 160 | mips_revision_sconid = MIPS_REVISION_SCON_SOCIT; |
| 161 | break; |
Chris Dearman | 3084024 | 2007-09-21 14:50:08 +0100 | [diff] [blame] | 162 | case MIPS_REVISION_CORID_CORE_FPGA3: |
| 163 | case MIPS_REVISION_CORID_CORE_FPGA4: |
| 164 | case MIPS_REVISION_CORID_CORE_FPGA5: |
| 165 | case MIPS_REVISION_CORID_CORE_EMUL_MSC: |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 166 | default: |
Chris Dearman | 3084024 | 2007-09-21 14:50:08 +0100 | [diff] [blame] | 167 | /* See above */ |
| 168 | mips_revision_sconid = MIPS_REVISION_SCON_ROCIT; |
| 169 | break; |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
| 173 | switch (mips_revision_sconid) { |
Ralf Baechle | f76b7ea | 2007-03-04 17:26:56 +0000 | [diff] [blame] | 174 | u32 start, map, mask, data; |
| 175 | |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 176 | case MIPS_REVISION_SCON_GT64120: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | /* |
| 178 | * Setup the North bridge to do Master byte-lane swapping |
| 179 | * when running in bigendian. |
| 180 | */ |
| 181 | _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000); |
| 182 | |
| 183 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 184 | GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT | |
| 185 | GT_PCI0_CMD_SBYTESWAP_BIT); |
| 186 | #else |
| 187 | GT_WRITE(GT_PCI0_CMD_OFS, 0); |
| 188 | #endif |
Maciej W. Rozycki | aa0980b | 2005-02-01 20:18:59 +0000 | [diff] [blame] | 189 | /* Fix up PCI I/O mapping if necessary (for Atlas). */ |
| 190 | start = GT_READ(GT_PCI0IOLD_OFS); |
| 191 | map = GT_READ(GT_PCI0IOREMAP_OFS); |
| 192 | if ((start & map) != 0) { |
| 193 | map &= ~start; |
| 194 | GT_WRITE(GT_PCI0IOREMAP_OFS, map); |
| 195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | set_io_port_base(MALTA_GT_PORT_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | break; |
| 199 | |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 200 | case MIPS_REVISION_SCON_BONITO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE); |
| 202 | |
| 203 | /* |
| 204 | * Disable Bonito IOBC. |
| 205 | */ |
| 206 | BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG & |
| 207 | ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED | |
| 208 | BONITO_PCIMEMBASECFG_MEMBASE1_CACHED); |
| 209 | |
| 210 | /* |
| 211 | * Setup the North bridge to do Master byte-lane swapping |
| 212 | * when running in bigendian. |
| 213 | */ |
| 214 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 215 | BONITO_BONGENCFG = BONITO_BONGENCFG & |
| 216 | ~(BONITO_BONGENCFG_MSTRBYTESWAP | |
| 217 | BONITO_BONGENCFG_BYTESWAP); |
| 218 | #else |
| 219 | BONITO_BONGENCFG = BONITO_BONGENCFG | |
| 220 | BONITO_BONGENCFG_MSTRBYTESWAP | |
| 221 | BONITO_BONGENCFG_BYTESWAP; |
| 222 | #endif |
| 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | set_io_port_base(MALTA_BONITO_PORT_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | break; |
| 226 | |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 227 | case MIPS_REVISION_SCON_SOCIT: |
| 228 | case MIPS_REVISION_SCON_ROCIT: |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 229 | _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000); |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 230 | mips_pci_controller: |
Maciej W. Rozycki | aa0980b | 2005-02-01 20:18:59 +0000 | [diff] [blame] | 231 | mb(); |
| 232 | MSC_READ(MSC01_PCI_CFG, data); |
| 233 | MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT); |
| 234 | wmb(); |
| 235 | |
| 236 | /* Fix up lane swapping. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 238 | MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP); |
| 239 | #else |
| 240 | MSC_WRITE(MSC01_PCI_SWAP, |
| 241 | MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF | |
| 242 | MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF | |
| 243 | MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF); |
| 244 | #endif |
Leonid Yegoshin | 2f284ea | 2014-01-17 13:11:29 +0000 | [diff] [blame] | 245 | #ifndef CONFIG_EVA |
Maciej W. Rozycki | aa0980b | 2005-02-01 20:18:59 +0000 | [diff] [blame] | 246 | /* Fix up target memory mapping. */ |
| 247 | MSC_READ(MSC01_PCI_BAR0, mask); |
| 248 | MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK); |
Leonid Yegoshin | 2f284ea | 2014-01-17 13:11:29 +0000 | [diff] [blame] | 249 | #else |
| 250 | /* |
| 251 | * Setup the Malta max (2GB) memory for PCI DMA in host bridge |
| 252 | * in transparent addressing mode, starting from 0x80000000. |
| 253 | */ |
| 254 | mask = PHYS_OFFSET | (1<<3); |
| 255 | MSC_WRITE(MSC01_PCI_BAR0, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Leonid Yegoshin | 2f284ea | 2014-01-17 13:11:29 +0000 | [diff] [blame] | 257 | mask = PHYS_OFFSET; |
| 258 | MSC_WRITE(MSC01_PCI_HEAD4, mask); |
| 259 | MSC_WRITE(MSC01_PCI_P2SCMSKL, mask); |
| 260 | MSC_WRITE(MSC01_PCI_P2SCMAPL, mask); |
| 261 | #endif |
Maciej W. Rozycki | aa0980b | 2005-02-01 20:18:59 +0000 | [diff] [blame] | 262 | /* Don't handle target retries indefinitely. */ |
| 263 | if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) == |
| 264 | MSC01_PCI_CFG_MAXRTRY_MSK) |
| 265 | data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK << |
| 266 | MSC01_PCI_CFG_MAXRTRY_SHF)) | |
| 267 | ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) << |
| 268 | MSC01_PCI_CFG_MAXRTRY_SHF); |
| 269 | |
| 270 | wmb(); |
| 271 | MSC_WRITE(MSC01_PCI_CFG, data); |
| 272 | mb(); |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | set_io_port_base(MALTA_MSC_PORT_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | break; |
| 276 | |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 277 | case MIPS_REVISION_SCON_SOCITSC: |
| 278 | case MIPS_REVISION_SCON_SOCITSCP: |
| 279 | _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000); |
| 280 | goto mips_pci_controller; |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | default: |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 283 | /* Unknown system controller */ |
| 284 | mips_display_message("SC Error"); |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 285 | while (1); /* We die here... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 287 | board_nmi_handler_setup = mips_nmi_setup; |
| 288 | board_ejtag_handler_setup = mips_ejtag_setup; |
| 289 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 290 | fw_init_cmdline(); |
| 291 | fw_meminit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
| 293 | console_config(); |
| 294 | #endif |
Ralf Baechle | af3a1f6 | 2011-03-29 11:43:19 +0200 | [diff] [blame] | 295 | /* Early detection of CMP support */ |
Paul Burton | 237036d | 2014-01-15 10:31:54 +0000 | [diff] [blame] | 296 | mips_cm_probe(); |
Paul Burton | 7dc2834 | 2014-01-15 10:31:55 +0000 | [diff] [blame] | 297 | mips_cpc_probe(); |
Ralf Baechle | 852fe31 | 2011-05-28 15:27:59 +0100 | [diff] [blame] | 298 | |
Paul Burton | e56b6aa | 2014-01-15 10:31:56 +0000 | [diff] [blame] | 299 | if (!register_cps_smp_ops()) |
| 300 | return; |
Paul Burton | 237036d | 2014-01-15 10:31:54 +0000 | [diff] [blame] | 301 | if (!register_cmp_smp_ops()) |
| 302 | return; |
Ralf Baechle | 852fe31 | 2011-05-28 15:27:59 +0100 | [diff] [blame] | 303 | if (!register_vsmp_smp_ops()) |
| 304 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |