blob: d821b13d24a0a286fbeae6e07d332b96f0e7cc28 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +00002 * Copyright (C) 1999, 2000, 2004, 2005 MIPS Technologies, Inc.
3 * All rights reserved.
4 * Authors: Carsten Langgaard <carstenl@mips.com>
5 * Maciej W. Rozycki <macro@mips.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can distribute it and/or modify it
8 * under the terms of the GNU General Public License (Version 2) as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
19 *
20 * PROM library initialisation code.
21 */
22#include <linux/config.h>
23#include <linux/init.h>
24#include <linux/string.h>
25#include <linux/kernel.h>
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/bootinfo.h>
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +000028#include <asm/gt64120.h>
29#include <asm/io.h>
30#include <asm/system.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/mips-boards/prom.h>
33#include <asm/mips-boards/generic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/mips-boards/bonito64.h>
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +000035#include <asm/mips-boards/msc01_pci.h>
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/mips-boards/malta.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#ifdef CONFIG_KGDB
40extern int rs_kgdb_hook(int, int);
41extern int rs_putDebugChar(char);
42extern char rs_getDebugChar(void);
43extern int saa9730_kgdb_hook(int);
44extern int saa9730_putDebugChar(char);
45extern char saa9730_getDebugChar(void);
46#endif
47
48int prom_argc;
49int *_prom_argv, *_prom_envp;
50
51/*
52 * YAMON (32-bit PROM) pass arguments and environment as 32-bit pointer.
53 * This macro take care of sign extension, if running in 64-bit mode.
54 */
55#define prom_envp(index) ((char *)(long)_prom_envp[(index)])
56
57int init_debug = 0;
58
59unsigned int mips_revision_corid;
60
61/* Bonito64 system controller register base. */
62unsigned long _pcictrl_bonito;
63unsigned long _pcictrl_bonito_pcicfg;
64
65/* GT64120 system controller register base */
66unsigned long _pcictrl_gt64120;
67
68/* MIPS System controller register base */
69unsigned long _pcictrl_msc;
70
71char *prom_getenv(char *envname)
72{
73 /*
74 * Return a pointer to the given environment variable.
75 * In 64-bit mode: we're using 64-bit pointers, but all pointers
76 * in the PROM structures are only 32-bit, so we need some
77 * workarounds, if we are running in 64-bit mode.
78 */
79 int i, index=0;
80
81 i = strlen(envname);
82
83 while (prom_envp(index)) {
84 if(strncmp(envname, prom_envp(index), i) == 0) {
85 return(prom_envp(index+1));
86 }
87 index += 2;
88 }
89
90 return NULL;
91}
92
93static inline unsigned char str2hexnum(unsigned char c)
94{
95 if (c >= '0' && c <= '9')
96 return c - '0';
97 if (c >= 'a' && c <= 'f')
98 return c - 'a' + 10;
99 return 0; /* foo */
100}
101
102static inline void str2eaddr(unsigned char *ea, unsigned char *str)
103{
104 int i;
105
106 for (i = 0; i < 6; i++) {
107 unsigned char num;
108
109 if((*str == '.') || (*str == ':'))
110 str++;
111 num = str2hexnum(*str++) << 4;
112 num |= (str2hexnum(*str++));
113 ea[i] = num;
114 }
115}
116
117int get_ethernet_addr(char *ethernet_addr)
118{
119 char *ethaddr_str;
120
121 ethaddr_str = prom_getenv("ethaddr");
122 if (!ethaddr_str) {
123 printk("ethaddr not set in boot prom\n");
124 return -1;
125 }
126 str2eaddr(ethernet_addr, ethaddr_str);
127
128 if (init_debug > 1) {
129 int i;
130 printk("get_ethernet_addr: ");
131 for (i=0; i<5; i++)
132 printk("%02x:", (unsigned char)*(ethernet_addr+i));
133 printk("%02x\n", *(ethernet_addr+i));
134 }
135
136 return 0;
137}
138
139#ifdef CONFIG_SERIAL_8250_CONSOLE
140static void __init console_config(void)
141{
142 char console_string[40];
143 int baud = 0;
144 char parity = '\0', bits = '\0', flow = '\0';
145 char *s;
146
147 if ((strstr(prom_getcmdline(), "console=ttyS")) == NULL) {
148 s = prom_getenv("modetty0");
149 if (s) {
150 while (*s >= '0' && *s <= '9')
151 baud = baud*10 + *s++ - '0';
152 if (*s == ',') s++;
153 if (*s) parity = *s++;
154 if (*s == ',') s++;
155 if (*s) bits = *s++;
156 if (*s == ',') s++;
157 if (*s == 'h') flow = 'r';
158 }
159 if (baud == 0)
160 baud = 38400;
161 if (parity != 'n' && parity != 'o' && parity != 'e')
162 parity = 'n';
163 if (bits != '7' && bits != '8')
164 bits = '8';
165 if (flow == '\0')
166 flow = 'r';
167 sprintf (console_string, " console=ttyS0,%d%c%c%c", baud, parity, bits, flow);
168 strcat (prom_getcmdline(), console_string);
169 prom_printf("Config serial console:%s\n", console_string);
170 }
171}
172#endif
173
174#ifdef CONFIG_KGDB
175void __init kgdb_config (void)
176{
177 extern int (*generic_putDebugChar)(char);
178 extern char (*generic_getDebugChar)(void);
179 char *argptr;
180 int line, speed;
181
182 argptr = prom_getcmdline();
183 if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
184 argptr += strlen("kgdb=ttyS");
185 if (*argptr != '0' && *argptr != '1')
186 printk("KGDB: Unknown serial line /dev/ttyS%c, "
187 "falling back to /dev/ttyS1\n", *argptr);
188 line = *argptr == '0' ? 0 : 1;
189 printk("KGDB: Using serial line /dev/ttyS%d for session\n", line);
190
191 speed = 0;
192 if (*++argptr == ',')
193 {
194 int c;
195 while ((c = *++argptr) && ('0' <= c && c <= '9'))
196 speed = speed * 10 + c - '0';
197 }
198#ifdef CONFIG_MIPS_ATLAS
199 if (line == 1) {
200 speed = saa9730_kgdb_hook(speed);
201 generic_putDebugChar = saa9730_putDebugChar;
202 generic_getDebugChar = saa9730_getDebugChar;
203 }
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700204 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#endif
206 {
207 speed = rs_kgdb_hook(line, speed);
208 generic_putDebugChar = rs_putDebugChar;
209 generic_getDebugChar = rs_getDebugChar;
210 }
211
212 prom_printf("KGDB: Using serial line /dev/ttyS%d at %d for session, "
213 "please connect your debugger\n", line ? 1 : 0, speed);
214
215 {
216 char *s;
217 for (s = "Please connect GDB to this port\r\n"; *s; )
218 generic_putDebugChar (*s++);
219 }
220
221 kgdb_enabled = 1;
222 /* Breakpoint is invoked after interrupts are initialised */
223 }
224}
225#endif
226
227void __init prom_init(void)
228{
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000229 u32 start, map, mask, data;
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 prom_argc = fw_arg0;
232 _prom_argv = (int *) fw_arg1;
233 _prom_envp = (int *) fw_arg2;
234
235 mips_display_message("LINUX");
236
237#ifdef CONFIG_MIPS_SEAD
238 set_io_port_base(KSEG1);
239#else
240 /*
241 * early setup of _pcictrl_bonito so that we can determine
242 * the system controller on a CORE_EMUL board
243 */
244 _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
245
246 mips_revision_corid = MIPS_REVISION_CORID;
247
248 if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700249 if (BONITO_PCIDID == 0x0001df53 ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 BONITO_PCIDID == 0x0003df53)
251 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
252 else
253 mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
254 }
255 switch(mips_revision_corid) {
256 case MIPS_REVISION_CORID_QED_RM5261:
257 case MIPS_REVISION_CORID_CORE_LV:
258 case MIPS_REVISION_CORID_CORE_FPGA:
259 case MIPS_REVISION_CORID_CORE_FPGAR2:
260 /*
261 * Setup the North bridge to do Master byte-lane swapping
262 * when running in bigendian.
263 */
264 _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
265
266#ifdef CONFIG_CPU_LITTLE_ENDIAN
267 GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
268 GT_PCI0_CMD_SBYTESWAP_BIT);
269#else
270 GT_WRITE(GT_PCI0_CMD_OFS, 0);
271#endif
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000272 /* Fix up PCI I/O mapping if necessary (for Atlas). */
273 start = GT_READ(GT_PCI0IOLD_OFS);
274 map = GT_READ(GT_PCI0IOREMAP_OFS);
275 if ((start & map) != 0) {
276 map &= ~start;
277 GT_WRITE(GT_PCI0IOREMAP_OFS, map);
278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 set_io_port_base(MALTA_GT_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 break;
282
283 case MIPS_REVISION_CORID_CORE_EMUL_BON:
284 case MIPS_REVISION_CORID_BONITO64:
285 case MIPS_REVISION_CORID_CORE_20K:
286 _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
287
288 /*
289 * Disable Bonito IOBC.
290 */
291 BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
292 ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
293 BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
294
295 /*
296 * Setup the North bridge to do Master byte-lane swapping
297 * when running in bigendian.
298 */
299#ifdef CONFIG_CPU_LITTLE_ENDIAN
300 BONITO_BONGENCFG = BONITO_BONGENCFG &
301 ~(BONITO_BONGENCFG_MSTRBYTESWAP |
302 BONITO_BONGENCFG_BYTESWAP);
303#else
304 BONITO_BONGENCFG = BONITO_BONGENCFG |
305 BONITO_BONGENCFG_MSTRBYTESWAP |
306 BONITO_BONGENCFG_BYTESWAP;
307#endif
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 set_io_port_base(MALTA_BONITO_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 break;
311
312 case MIPS_REVISION_CORID_CORE_MSC:
313 case MIPS_REVISION_CORID_CORE_FPGA2:
314 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700315 _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000317 mb();
318 MSC_READ(MSC01_PCI_CFG, data);
319 MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
320 wmb();
321
322 /* Fix up lane swapping. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#ifdef CONFIG_CPU_LITTLE_ENDIAN
324 MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
325#else
326 MSC_WRITE(MSC01_PCI_SWAP,
327 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
328 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
329 MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
330#endif
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000331 /* Fix up target memory mapping. */
332 MSC_READ(MSC01_PCI_BAR0, mask);
333 MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Maciej W. Rozyckiaa0980b82005-02-01 20:18:59 +0000335 /* Don't handle target retries indefinitely. */
336 if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
337 MSC01_PCI_CFG_MAXRTRY_MSK)
338 data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
339 MSC01_PCI_CFG_MAXRTRY_SHF)) |
340 ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
341 MSC01_PCI_CFG_MAXRTRY_SHF);
342
343 wmb();
344 MSC_WRITE(MSC01_PCI_CFG, data);
345 mb();
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 set_io_port_base(MALTA_MSC_PORT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 break;
349
350 default:
351 /* Unknown Core card */
352 mips_display_message("CC Error");
353 while(1); /* We die here... */
354 }
355#endif
356 prom_printf("\nLINUX started...\n");
357 prom_init_cmdline();
358 prom_meminit();
359#ifdef CONFIG_SERIAL_8250_CONSOLE
360 console_config();
361#endif
362}