init.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * 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>
  6. *
  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. #include <asm/bootinfo.h>
  27. #include <asm/gt64120.h>
  28. #include <asm/io.h>
  29. #include <asm/system.h>
  30. #include <asm/cacheflush.h>
  31. #include <asm/traps.h>
  32. #include <asm/mips-boards/prom.h>
  33. #include <asm/mips-boards/generic.h>
  34. #include <asm/mips-boards/bonito64.h>
  35. #include <asm/mips-boards/msc01_pci.h>
  36. #include <asm/mips-boards/malta.h>
  37. #ifdef CONFIG_KGDB
  38. extern int rs_kgdb_hook(int, int);
  39. extern int rs_putDebugChar(char);
  40. extern char rs_getDebugChar(void);
  41. extern int saa9730_kgdb_hook(int);
  42. extern int saa9730_putDebugChar(char);
  43. extern char saa9730_getDebugChar(void);
  44. #endif
  45. int prom_argc;
  46. int *_prom_argv, *_prom_envp;
  47. /*
  48. * YAMON (32-bit PROM) pass arguments and environment as 32-bit pointer.
  49. * This macro take care of sign extension, if running in 64-bit mode.
  50. */
  51. #define prom_envp(index) ((char *)(long)_prom_envp[(index)])
  52. int init_debug = 0;
  53. unsigned int mips_revision_corid;
  54. /* Bonito64 system controller register base. */
  55. unsigned long _pcictrl_bonito;
  56. unsigned long _pcictrl_bonito_pcicfg;
  57. /* GT64120 system controller register base */
  58. unsigned long _pcictrl_gt64120;
  59. /* MIPS System controller register base */
  60. unsigned long _pcictrl_msc;
  61. char *prom_getenv(char *envname)
  62. {
  63. /*
  64. * Return a pointer to the given environment variable.
  65. * In 64-bit mode: we're using 64-bit pointers, but all pointers
  66. * in the PROM structures are only 32-bit, so we need some
  67. * workarounds, if we are running in 64-bit mode.
  68. */
  69. int i, index=0;
  70. i = strlen(envname);
  71. while (prom_envp(index)) {
  72. if(strncmp(envname, prom_envp(index), i) == 0) {
  73. return(prom_envp(index+1));
  74. }
  75. index += 2;
  76. }
  77. return NULL;
  78. }
  79. static inline unsigned char str2hexnum(unsigned char c)
  80. {
  81. if (c >= '0' && c <= '9')
  82. return c - '0';
  83. if (c >= 'a' && c <= 'f')
  84. return c - 'a' + 10;
  85. return 0; /* foo */
  86. }
  87. static inline void str2eaddr(unsigned char *ea, unsigned char *str)
  88. {
  89. int i;
  90. for (i = 0; i < 6; i++) {
  91. unsigned char num;
  92. if((*str == '.') || (*str == ':'))
  93. str++;
  94. num = str2hexnum(*str++) << 4;
  95. num |= (str2hexnum(*str++));
  96. ea[i] = num;
  97. }
  98. }
  99. int get_ethernet_addr(char *ethernet_addr)
  100. {
  101. char *ethaddr_str;
  102. ethaddr_str = prom_getenv("ethaddr");
  103. if (!ethaddr_str) {
  104. printk("ethaddr not set in boot prom\n");
  105. return -1;
  106. }
  107. str2eaddr(ethernet_addr, ethaddr_str);
  108. if (init_debug > 1) {
  109. int i;
  110. printk("get_ethernet_addr: ");
  111. for (i=0; i<5; i++)
  112. printk("%02x:", (unsigned char)*(ethernet_addr+i));
  113. printk("%02x\n", *(ethernet_addr+i));
  114. }
  115. return 0;
  116. }
  117. #ifdef CONFIG_SERIAL_8250_CONSOLE
  118. static void __init console_config(void)
  119. {
  120. char console_string[40];
  121. int baud = 0;
  122. char parity = '\0', bits = '\0', flow = '\0';
  123. char *s;
  124. if ((strstr(prom_getcmdline(), "console=ttyS")) == NULL) {
  125. s = prom_getenv("modetty0");
  126. if (s) {
  127. while (*s >= '0' && *s <= '9')
  128. baud = baud*10 + *s++ - '0';
  129. if (*s == ',') s++;
  130. if (*s) parity = *s++;
  131. if (*s == ',') s++;
  132. if (*s) bits = *s++;
  133. if (*s == ',') s++;
  134. if (*s == 'h') flow = 'r';
  135. }
  136. if (baud == 0)
  137. baud = 38400;
  138. if (parity != 'n' && parity != 'o' && parity != 'e')
  139. parity = 'n';
  140. if (bits != '7' && bits != '8')
  141. bits = '8';
  142. if (flow == '\0')
  143. flow = 'r';
  144. sprintf (console_string, " console=ttyS0,%d%c%c%c", baud, parity, bits, flow);
  145. strcat (prom_getcmdline(), console_string);
  146. prom_printf("Config serial console:%s\n", console_string);
  147. }
  148. }
  149. #endif
  150. #ifdef CONFIG_KGDB
  151. void __init kgdb_config (void)
  152. {
  153. extern int (*generic_putDebugChar)(char);
  154. extern char (*generic_getDebugChar)(void);
  155. char *argptr;
  156. int line, speed;
  157. argptr = prom_getcmdline();
  158. if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
  159. argptr += strlen("kgdb=ttyS");
  160. if (*argptr != '0' && *argptr != '1')
  161. printk("KGDB: Unknown serial line /dev/ttyS%c, "
  162. "falling back to /dev/ttyS1\n", *argptr);
  163. line = *argptr == '0' ? 0 : 1;
  164. printk("KGDB: Using serial line /dev/ttyS%d for session\n", line);
  165. speed = 0;
  166. if (*++argptr == ',')
  167. {
  168. int c;
  169. while ((c = *++argptr) && ('0' <= c && c <= '9'))
  170. speed = speed * 10 + c - '0';
  171. }
  172. #ifdef CONFIG_MIPS_ATLAS
  173. if (line == 1) {
  174. speed = saa9730_kgdb_hook(speed);
  175. generic_putDebugChar = saa9730_putDebugChar;
  176. generic_getDebugChar = saa9730_getDebugChar;
  177. }
  178. else
  179. #endif
  180. {
  181. speed = rs_kgdb_hook(line, speed);
  182. generic_putDebugChar = rs_putDebugChar;
  183. generic_getDebugChar = rs_getDebugChar;
  184. }
  185. prom_printf("KGDB: Using serial line /dev/ttyS%d at %d for session, "
  186. "please connect your debugger\n", line ? 1 : 0, speed);
  187. {
  188. char *s;
  189. for (s = "Please connect GDB to this port\r\n"; *s; )
  190. generic_putDebugChar (*s++);
  191. }
  192. /* Breakpoint is invoked after interrupts are initialised */
  193. }
  194. }
  195. #endif
  196. void __init mips_nmi_setup (void)
  197. {
  198. void *base;
  199. extern char except_vec_nmi;
  200. base = cpu_has_veic ?
  201. (void *)(CAC_BASE + 0xa80) :
  202. (void *)(CAC_BASE + 0x380);
  203. memcpy(base, &except_vec_nmi, 0x80);
  204. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  205. }
  206. void __init mips_ejtag_setup (void)
  207. {
  208. void *base;
  209. extern char except_vec_ejtag_debug;
  210. base = cpu_has_veic ?
  211. (void *)(CAC_BASE + 0xa00) :
  212. (void *)(CAC_BASE + 0x300);
  213. memcpy(base, &except_vec_ejtag_debug, 0x80);
  214. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  215. }
  216. void __init prom_init(void)
  217. {
  218. u32 start, map, mask, data;
  219. prom_argc = fw_arg0;
  220. _prom_argv = (int *) fw_arg1;
  221. _prom_envp = (int *) fw_arg2;
  222. mips_display_message("LINUX");
  223. #ifdef CONFIG_MIPS_SEAD
  224. set_io_port_base(KSEG1);
  225. #else
  226. /*
  227. * early setup of _pcictrl_bonito so that we can determine
  228. * the system controller on a CORE_EMUL board
  229. */
  230. _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
  231. mips_revision_corid = MIPS_REVISION_CORID;
  232. if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
  233. if (BONITO_PCIDID == 0x0001df53 ||
  234. BONITO_PCIDID == 0x0003df53)
  235. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
  236. else
  237. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
  238. }
  239. switch(mips_revision_corid) {
  240. case MIPS_REVISION_CORID_QED_RM5261:
  241. case MIPS_REVISION_CORID_CORE_LV:
  242. case MIPS_REVISION_CORID_CORE_FPGA:
  243. case MIPS_REVISION_CORID_CORE_FPGAR2:
  244. /*
  245. * Setup the North bridge to do Master byte-lane swapping
  246. * when running in bigendian.
  247. */
  248. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  249. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  250. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  251. GT_PCI0_CMD_SBYTESWAP_BIT);
  252. #else
  253. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  254. #endif
  255. /* Fix up PCI I/O mapping if necessary (for Atlas). */
  256. start = GT_READ(GT_PCI0IOLD_OFS);
  257. map = GT_READ(GT_PCI0IOREMAP_OFS);
  258. if ((start & map) != 0) {
  259. map &= ~start;
  260. GT_WRITE(GT_PCI0IOREMAP_OFS, map);
  261. }
  262. set_io_port_base(MALTA_GT_PORT_BASE);
  263. break;
  264. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  265. case MIPS_REVISION_CORID_BONITO64:
  266. case MIPS_REVISION_CORID_CORE_20K:
  267. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  268. /*
  269. * Disable Bonito IOBC.
  270. */
  271. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  272. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  273. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  274. /*
  275. * Setup the North bridge to do Master byte-lane swapping
  276. * when running in bigendian.
  277. */
  278. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  279. BONITO_BONGENCFG = BONITO_BONGENCFG &
  280. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  281. BONITO_BONGENCFG_BYTESWAP);
  282. #else
  283. BONITO_BONGENCFG = BONITO_BONGENCFG |
  284. BONITO_BONGENCFG_MSTRBYTESWAP |
  285. BONITO_BONGENCFG_BYTESWAP;
  286. #endif
  287. set_io_port_base(MALTA_BONITO_PORT_BASE);
  288. break;
  289. case MIPS_REVISION_CORID_CORE_MSC:
  290. case MIPS_REVISION_CORID_CORE_FPGA2:
  291. case MIPS_REVISION_CORID_CORE_FPGA3:
  292. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  293. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  294. mb();
  295. MSC_READ(MSC01_PCI_CFG, data);
  296. MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
  297. wmb();
  298. /* Fix up lane swapping. */
  299. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  300. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  301. #else
  302. MSC_WRITE(MSC01_PCI_SWAP,
  303. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  304. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  305. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  306. #endif
  307. /* Fix up target memory mapping. */
  308. MSC_READ(MSC01_PCI_BAR0, mask);
  309. MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
  310. /* Don't handle target retries indefinitely. */
  311. if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
  312. MSC01_PCI_CFG_MAXRTRY_MSK)
  313. data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
  314. MSC01_PCI_CFG_MAXRTRY_SHF)) |
  315. ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
  316. MSC01_PCI_CFG_MAXRTRY_SHF);
  317. wmb();
  318. MSC_WRITE(MSC01_PCI_CFG, data);
  319. mb();
  320. set_io_port_base(MALTA_MSC_PORT_BASE);
  321. break;
  322. default:
  323. /* Unknown Core card */
  324. mips_display_message("CC Error");
  325. while(1); /* We die here... */
  326. }
  327. #endif
  328. board_nmi_handler_setup = mips_nmi_setup;
  329. board_ejtag_handler_setup = mips_ejtag_setup;
  330. prom_printf("\nLINUX started...\n");
  331. prom_init_cmdline();
  332. prom_meminit();
  333. #ifdef CONFIG_SERIAL_8250_CONSOLE
  334. console_config();
  335. #endif
  336. }