blob: 0f3b881a3190fdcb993ea01234a2c304b1511f18 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Steven J. Hill49bffbd2013-03-25 15:05:40 -05002 * 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 Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * PROM library initialisation code.
Steven J. Hill49bffbd2013-03-25 15:05:40 -05007 *
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 Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/init.h>
15#include <linux/string.h>
16#include <linux/kernel.h>
Paul Burton422dd252016-09-19 22:21:21 +010017#include <linux/pci_regs.h>
Peter Hurleydf519e72015-03-09 16:27:22 -040018#include <linux/serial_core.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Ralf Baechlee01402b2005-07-14 15:57:16 +000020#include <asm/cacheflush.h>
Ralf Baechle852fe312011-05-28 15:27:59 +010021#include <asm/smp-ops.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000022#include <asm/traps.h>
Steven J. Hillb431f092013-03-25 14:47:05 -050023#include <asm/fw/fw.h>
Paul Burton237036d2014-01-15 10:31:54 +000024#include <asm/mips-cm.h>
Paul Burton7dc28342014-01-15 10:31:55 +000025#include <asm/mips-cpc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/mips-boards/generic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/mips-boards/malta.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Dmitri Vorobievd0cdfe22009-03-23 00:12:27 +020029static int mips_revision_corid;
Chris Dearmanb72c0522007-04-27 15:58:41 +010030int mips_revision_sconid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/* Bonito64 system controller register base. */
33unsigned long _pcictrl_bonito;
34unsigned long _pcictrl_bonito_pcicfg;
35
36/* GT64120 system controller register base */
37unsigned long _pcictrl_gt64120;
38
39/* MIPS System controller register base */
40unsigned long _pcictrl_msc;
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#ifdef CONFIG_SERIAL_8250_CONSOLE
43static void __init console_config(void)
44{
45 char console_string[40];
46 int baud = 0;
47 char parity = '\0', bits = '\0', flow = '\0';
48 char *s;
49
Paul Burton23a91de2013-12-02 16:48:38 +000050 s = fw_getenv("modetty0");
51 if (s) {
52 while (*s >= '0' && *s <= '9')
53 baud = baud*10 + *s++ - '0';
54 if (*s == ',')
55 s++;
56 if (*s)
57 parity = *s++;
58 if (*s == ',')
59 s++;
60 if (*s)
61 bits = *s++;
62 if (*s == ',')
63 s++;
64 if (*s == 'h')
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 flow = 'r';
Paul Burton23a91de2013-12-02 16:48:38 +000066 }
67 if (baud == 0)
68 baud = 38400;
69 if (parity != 'n' && parity != 'o' && parity != 'e')
70 parity = 'n';
71 if (bits != '7' && bits != '8')
72 bits = '8';
73 if (flow == '\0')
74 flow = 'r';
75
76 if ((strstr(fw_getcmdline(), "earlycon=")) == NULL) {
77 sprintf(console_string, "uart8250,io,0x3f8,%d%c%c", baud,
78 parity, bits);
Peter Hurleydf519e72015-03-09 16:27:22 -040079 setup_earlycon(console_string);
Paul Burton23a91de2013-12-02 16:48:38 +000080 }
81
82 if ((strstr(fw_getcmdline(), "console=")) == NULL) {
Steven J. Hill49bffbd2013-03-25 15:05:40 -050083 sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
84 parity, bits, flow);
Steven J. Hillb431f092013-03-25 14:47:05 -050085 strcat(fw_getcmdline(), console_string);
Ralf Baechle36a88532007-03-01 11:56:43 +000086 pr_info("Config serial console:%s\n", console_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88}
89#endif
90
Dmitri Vorobievcd2675f2008-04-01 02:03:20 +040091static void __init mips_nmi_setup(void)
Ralf Baechlee01402b2005-07-14 15:57:16 +000092{
93 void *base;
94 extern char except_vec_nmi;
95
96 base = cpu_has_veic ?
97 (void *)(CAC_BASE + 0xa80) :
98 (void *)(CAC_BASE + 0x380);
99 memcpy(base, &except_vec_nmi, 0x80);
100 flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
101}
102
Dmitri Vorobiev33d69d22008-04-01 02:03:21 +0400103static void __init mips_ejtag_setup(void)
Ralf Baechlee01402b2005-07-14 15:57:16 +0000104{
105 void *base;
106 extern char except_vec_ejtag_debug;
107
108 base = cpu_has_veic ?
109 (void *)(CAC_BASE + 0xa00) :
110 (void *)(CAC_BASE + 0x300);
111 memcpy(base, &except_vec_ejtag_debug, 0x80);
112 flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
113}
114
Ralf Baechle15d45cc2014-11-22 00:22:09 +0100115phys_addr_t mips_cpc_default_phys_base(void)
Paul Burton7dc28342014-01-15 10:31:55 +0000116{
117 return CPC_BASE_ADDR;
118}
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120void __init prom_init(void)
121{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 mips_display_message("LINUX");
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /*
125 * early setup of _pcictrl_bonito so that we can determine
126 * the system controller on a CORE_EMUL board
127 */
128 _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
129
130 mips_revision_corid = MIPS_REVISION_CORID;
131
132 if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700133 if (BONITO_PCIDID == 0x0001df53 ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 BONITO_PCIDID == 0x0003df53)
135 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
136 else
137 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
138 }
Chris Dearmanb72c0522007-04-27 15:58:41 +0100139
140 mips_revision_sconid = MIPS_REVISION_SCONID;
141 if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
142 switch (mips_revision_corid) {
143 case MIPS_REVISION_CORID_QED_RM5261:
144 case MIPS_REVISION_CORID_CORE_LV:
145 case MIPS_REVISION_CORID_CORE_FPGA:
146 case MIPS_REVISION_CORID_CORE_FPGAR2:
147 mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
148 break;
149 case MIPS_REVISION_CORID_CORE_EMUL_BON:
150 case MIPS_REVISION_CORID_BONITO64:
151 case MIPS_REVISION_CORID_CORE_20K:
152 mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
153 break;
154 case MIPS_REVISION_CORID_CORE_MSC:
155 case MIPS_REVISION_CORID_CORE_FPGA2:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100156 case MIPS_REVISION_CORID_CORE_24K:
Chris Dearman30840242007-09-21 14:50:08 +0100157 /*
158 * SOCit/ROCit support is essentially identical
159 * but make an attempt to distinguish them
160 */
Chris Dearmanb72c0522007-04-27 15:58:41 +0100161 mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
162 break;
Chris Dearman30840242007-09-21 14:50:08 +0100163 case MIPS_REVISION_CORID_CORE_FPGA3:
164 case MIPS_REVISION_CORID_CORE_FPGA4:
165 case MIPS_REVISION_CORID_CORE_FPGA5:
166 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100167 default:
Chris Dearman30840242007-09-21 14:50:08 +0100168 /* See above */
169 mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
170 break;
Chris Dearmanb72c0522007-04-27 15:58:41 +0100171 }
172 }
173
174 switch (mips_revision_sconid) {
Ralf Baechlef76b7ea2007-03-04 17:26:56 +0000175 u32 start, map, mask, data;
176
Chris Dearmanb72c0522007-04-27 15:58:41 +0100177 case MIPS_REVISION_SCON_GT64120:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 /*
179 * Setup the North bridge to do Master byte-lane swapping
180 * when running in bigendian.
181 */
182 _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
183
184#ifdef CONFIG_CPU_LITTLE_ENDIAN
185 GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
186 GT_PCI0_CMD_SBYTESWAP_BIT);
187#else
188 GT_WRITE(GT_PCI0_CMD_OFS, 0);
189#endif
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000190 /* Fix up PCI I/O mapping if necessary (for Atlas). */
191 start = GT_READ(GT_PCI0IOLD_OFS);
192 map = GT_READ(GT_PCI0IOREMAP_OFS);
193 if ((start & map) != 0) {
194 map &= ~start;
195 GT_WRITE(GT_PCI0IOREMAP_OFS, map);
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 set_io_port_base(MALTA_GT_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200
Chris Dearmanb72c0522007-04-27 15:58:41 +0100201 case MIPS_REVISION_SCON_BONITO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
203
204 /*
205 * Disable Bonito IOBC.
206 */
207 BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
208 ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
209 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
210
211 /*
212 * Setup the North bridge to do Master byte-lane swapping
213 * when running in bigendian.
214 */
215#ifdef CONFIG_CPU_LITTLE_ENDIAN
216 BONITO_BONGENCFG = BONITO_BONGENCFG &
217 ~(BONITO_BONGENCFG_MSTRBYTESWAP |
218 BONITO_BONGENCFG_BYTESWAP);
219#else
220 BONITO_BONGENCFG = BONITO_BONGENCFG |
221 BONITO_BONGENCFG_MSTRBYTESWAP |
222 BONITO_BONGENCFG_BYTESWAP;
223#endif
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 set_io_port_base(MALTA_BONITO_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 break;
227
Chris Dearmanb72c0522007-04-27 15:58:41 +0100228 case MIPS_REVISION_SCON_SOCIT:
229 case MIPS_REVISION_SCON_ROCIT:
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700230 _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500231mips_pci_controller:
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000232 mb();
233 MSC_READ(MSC01_PCI_CFG, data);
234 MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
235 wmb();
236
237 /* Fix up lane swapping. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#ifdef CONFIG_CPU_LITTLE_ENDIAN
239 MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
240#else
241 MSC_WRITE(MSC01_PCI_SWAP,
242 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
243 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
244 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
245#endif
Paul Burton422dd252016-09-19 22:21:21 +0100246
Leonid Yegoshin2f284ea2014-01-17 13:11:29 +0000247 /*
248 * Setup the Malta max (2GB) memory for PCI DMA in host bridge
Paul Burton422dd252016-09-19 22:21:21 +0100249 * in transparent addressing mode.
Leonid Yegoshin2f284ea2014-01-17 13:11:29 +0000250 */
Paul Burton422dd252016-09-19 22:21:21 +0100251 mask = PHYS_OFFSET | PCI_BASE_ADDRESS_MEM_PREFETCH;
Leonid Yegoshin2f284ea2014-01-17 13:11:29 +0000252 MSC_WRITE(MSC01_PCI_BAR0, mask);
Leonid Yegoshin2f284ea2014-01-17 13:11:29 +0000253 MSC_WRITE(MSC01_PCI_HEAD4, mask);
Paul Burton422dd252016-09-19 22:21:21 +0100254
255 mask &= MSC01_PCI_BAR0_SIZE_MSK;
Leonid Yegoshin2f284ea2014-01-17 13:11:29 +0000256 MSC_WRITE(MSC01_PCI_P2SCMSKL, mask);
257 MSC_WRITE(MSC01_PCI_P2SCMAPL, mask);
Paul Burton422dd252016-09-19 22:21:21 +0100258
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000259 /* Don't handle target retries indefinitely. */
260 if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
261 MSC01_PCI_CFG_MAXRTRY_MSK)
262 data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
263 MSC01_PCI_CFG_MAXRTRY_SHF)) |
264 ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
265 MSC01_PCI_CFG_MAXRTRY_SHF);
266
267 wmb();
268 MSC_WRITE(MSC01_PCI_CFG, data);
269 mb();
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 set_io_port_base(MALTA_MSC_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 break;
273
Chris Dearmanb72c0522007-04-27 15:58:41 +0100274 case MIPS_REVISION_SCON_SOCITSC:
275 case MIPS_REVISION_SCON_SOCITSCP:
276 _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
277 goto mips_pci_controller;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 default:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100280 /* Unknown system controller */
281 mips_display_message("SC Error");
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500282 while (1); /* We die here... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
Ralf Baechlee01402b2005-07-14 15:57:16 +0000284 board_nmi_handler_setup = mips_nmi_setup;
285 board_ejtag_handler_setup = mips_ejtag_setup;
286
Steven J. Hillb431f092013-03-25 14:47:05 -0500287 fw_init_cmdline();
288 fw_meminit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289#ifdef CONFIG_SERIAL_8250_CONSOLE
290 console_config();
291#endif
Ralf Baechleaf3a1f62011-03-29 11:43:19 +0200292 /* Early detection of CMP support */
Paul Burton7dc28342014-01-15 10:31:55 +0000293 mips_cpc_probe();
Ralf Baechle852fe312011-05-28 15:27:59 +0100294
Paul Burtone56b6aa2014-01-15 10:31:56 +0000295 if (!register_cps_smp_ops())
296 return;
Paul Burton237036d2014-01-15 10:31:54 +0000297 if (!register_cmp_smp_ops())
298 return;
Ralf Baechle852fe312011-05-28 15:27:59 +0100299 if (!register_vsmp_smp_ops())
300 return;
Paul Burtonecafe3e2015-09-22 11:58:43 -0700301 register_up_smp_ops();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}