init.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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/init.h>
  23. #include <linux/string.h>
  24. #include <linux/kernel.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/gt64120.h>
  27. #include <asm/io.h>
  28. #include <asm/system.h>
  29. #include <asm/cacheflush.h>
  30. #include <asm/traps.h>
  31. #include <asm/mips-boards/prom.h>
  32. #include <asm/mips-boards/generic.h>
  33. #include <asm/mips-boards/bonito64.h>
  34. #include <asm/mips-boards/msc01_pci.h>
  35. #include <asm/mips-boards/malta.h>
  36. #ifdef CONFIG_KGDB
  37. extern int rs_kgdb_hook(int, int);
  38. extern int rs_putDebugChar(char);
  39. extern char rs_getDebugChar(void);
  40. extern int saa9730_kgdb_hook(int);
  41. extern int saa9730_putDebugChar(char);
  42. extern char saa9730_getDebugChar(void);
  43. #endif
  44. int prom_argc;
  45. int *_prom_argv, *_prom_envp;
  46. /*
  47. * YAMON (32-bit PROM) pass arguments and environment as 32-bit pointer.
  48. * This macro take care of sign extension, if running in 64-bit mode.
  49. */
  50. #define prom_envp(index) ((char *)(long)_prom_envp[(index)])
  51. int init_debug = 0;
  52. int mips_revision_corid;
  53. int mips_revision_sconid;
  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=")) == 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. pr_info("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. pr_info("KGDB: Using serial line /dev/ttyS%d at %d for "
  186. "session, please connect your debugger\n",
  187. line ? 1 : 0, speed);
  188. {
  189. char *s;
  190. for (s = "Please connect GDB to this port\r\n"; *s; )
  191. generic_putDebugChar(*s++);
  192. }
  193. /* Breakpoint is invoked after interrupts are initialised */
  194. }
  195. }
  196. #endif
  197. void __init mips_nmi_setup(void)
  198. {
  199. void *base;
  200. extern char except_vec_nmi;
  201. base = cpu_has_veic ?
  202. (void *)(CAC_BASE + 0xa80) :
  203. (void *)(CAC_BASE + 0x380);
  204. memcpy(base, &except_vec_nmi, 0x80);
  205. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  206. }
  207. void __init mips_ejtag_setup(void)
  208. {
  209. void *base;
  210. extern char except_vec_ejtag_debug;
  211. base = cpu_has_veic ?
  212. (void *)(CAC_BASE + 0xa00) :
  213. (void *)(CAC_BASE + 0x300);
  214. memcpy(base, &except_vec_ejtag_debug, 0x80);
  215. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  216. }
  217. void __init prom_init(void)
  218. {
  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. mips_revision_sconid = MIPS_REVISION_SCONID;
  240. if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
  241. switch (mips_revision_corid) {
  242. case MIPS_REVISION_CORID_QED_RM5261:
  243. case MIPS_REVISION_CORID_CORE_LV:
  244. case MIPS_REVISION_CORID_CORE_FPGA:
  245. case MIPS_REVISION_CORID_CORE_FPGAR2:
  246. mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
  247. break;
  248. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  249. case MIPS_REVISION_CORID_BONITO64:
  250. case MIPS_REVISION_CORID_CORE_20K:
  251. mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
  252. break;
  253. case MIPS_REVISION_CORID_CORE_MSC:
  254. case MIPS_REVISION_CORID_CORE_FPGA2:
  255. case MIPS_REVISION_CORID_CORE_FPGA3:
  256. case MIPS_REVISION_CORID_CORE_FPGA4:
  257. case MIPS_REVISION_CORID_CORE_24K:
  258. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  259. mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
  260. break;
  261. default:
  262. mips_display_message("CC Error");
  263. while (1); /* We die here... */
  264. }
  265. }
  266. switch (mips_revision_sconid) {
  267. u32 start, map, mask, data;
  268. case MIPS_REVISION_SCON_GT64120:
  269. /*
  270. * Setup the North bridge to do Master byte-lane swapping
  271. * when running in bigendian.
  272. */
  273. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  274. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  275. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  276. GT_PCI0_CMD_SBYTESWAP_BIT);
  277. #else
  278. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  279. #endif
  280. /* Fix up PCI I/O mapping if necessary (for Atlas). */
  281. start = GT_READ(GT_PCI0IOLD_OFS);
  282. map = GT_READ(GT_PCI0IOREMAP_OFS);
  283. if ((start & map) != 0) {
  284. map &= ~start;
  285. GT_WRITE(GT_PCI0IOREMAP_OFS, map);
  286. }
  287. set_io_port_base(MALTA_GT_PORT_BASE);
  288. break;
  289. case MIPS_REVISION_SCON_BONITO:
  290. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  291. /*
  292. * Disable Bonito IOBC.
  293. */
  294. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  295. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  296. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  297. /*
  298. * Setup the North bridge to do Master byte-lane swapping
  299. * when running in bigendian.
  300. */
  301. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  302. BONITO_BONGENCFG = BONITO_BONGENCFG &
  303. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  304. BONITO_BONGENCFG_BYTESWAP);
  305. #else
  306. BONITO_BONGENCFG = BONITO_BONGENCFG |
  307. BONITO_BONGENCFG_MSTRBYTESWAP |
  308. BONITO_BONGENCFG_BYTESWAP;
  309. #endif
  310. set_io_port_base(MALTA_BONITO_PORT_BASE);
  311. break;
  312. case MIPS_REVISION_SCON_SOCIT:
  313. case MIPS_REVISION_SCON_ROCIT:
  314. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  315. mips_pci_controller:
  316. mb();
  317. MSC_READ(MSC01_PCI_CFG, data);
  318. MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
  319. wmb();
  320. /* Fix up lane swapping. */
  321. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  322. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  323. #else
  324. MSC_WRITE(MSC01_PCI_SWAP,
  325. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  326. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  327. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  328. #endif
  329. /* Fix up target memory mapping. */
  330. MSC_READ(MSC01_PCI_BAR0, mask);
  331. MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
  332. /* Don't handle target retries indefinitely. */
  333. if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
  334. MSC01_PCI_CFG_MAXRTRY_MSK)
  335. data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
  336. MSC01_PCI_CFG_MAXRTRY_SHF)) |
  337. ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
  338. MSC01_PCI_CFG_MAXRTRY_SHF);
  339. wmb();
  340. MSC_WRITE(MSC01_PCI_CFG, data);
  341. mb();
  342. set_io_port_base(MALTA_MSC_PORT_BASE);
  343. break;
  344. case MIPS_REVISION_SCON_SOCITSC:
  345. case MIPS_REVISION_SCON_SOCITSCP:
  346. _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
  347. goto mips_pci_controller;
  348. default:
  349. /* Unknown system controller */
  350. mips_display_message("SC Error");
  351. while (1); /* We die here... */
  352. }
  353. #endif
  354. board_nmi_handler_setup = mips_nmi_setup;
  355. board_ejtag_handler_setup = mips_ejtag_setup;
  356. pr_info("\nLINUX started...\n");
  357. prom_init_cmdline();
  358. prom_meminit();
  359. #ifdef CONFIG_SERIAL_8250_CONSOLE
  360. console_config();
  361. #endif
  362. }