init.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. {
  173. speed = rs_kgdb_hook(line, speed);
  174. generic_putDebugChar = rs_putDebugChar;
  175. generic_getDebugChar = rs_getDebugChar;
  176. }
  177. pr_info("KGDB: Using serial line /dev/ttyS%d at %d for "
  178. "session, please connect your debugger\n",
  179. line ? 1 : 0, speed);
  180. {
  181. char *s;
  182. for (s = "Please connect GDB to this port\r\n"; *s; )
  183. generic_putDebugChar(*s++);
  184. }
  185. /* Breakpoint is invoked after interrupts are initialised */
  186. }
  187. }
  188. #endif
  189. static void __init mips_nmi_setup(void)
  190. {
  191. void *base;
  192. extern char except_vec_nmi;
  193. base = cpu_has_veic ?
  194. (void *)(CAC_BASE + 0xa80) :
  195. (void *)(CAC_BASE + 0x380);
  196. memcpy(base, &except_vec_nmi, 0x80);
  197. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  198. }
  199. static void __init mips_ejtag_setup(void)
  200. {
  201. void *base;
  202. extern char except_vec_ejtag_debug;
  203. base = cpu_has_veic ?
  204. (void *)(CAC_BASE + 0xa00) :
  205. (void *)(CAC_BASE + 0x300);
  206. memcpy(base, &except_vec_ejtag_debug, 0x80);
  207. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  208. }
  209. extern struct plat_smp_ops msmtc_smp_ops;
  210. void __init prom_init(void)
  211. {
  212. prom_argc = fw_arg0;
  213. _prom_argv = (int *) fw_arg1;
  214. _prom_envp = (int *) fw_arg2;
  215. mips_display_message("LINUX");
  216. /*
  217. * early setup of _pcictrl_bonito so that we can determine
  218. * the system controller on a CORE_EMUL board
  219. */
  220. _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
  221. mips_revision_corid = MIPS_REVISION_CORID;
  222. if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
  223. if (BONITO_PCIDID == 0x0001df53 ||
  224. BONITO_PCIDID == 0x0003df53)
  225. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
  226. else
  227. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
  228. }
  229. mips_revision_sconid = MIPS_REVISION_SCONID;
  230. if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
  231. switch (mips_revision_corid) {
  232. case MIPS_REVISION_CORID_QED_RM5261:
  233. case MIPS_REVISION_CORID_CORE_LV:
  234. case MIPS_REVISION_CORID_CORE_FPGA:
  235. case MIPS_REVISION_CORID_CORE_FPGAR2:
  236. mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
  237. break;
  238. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  239. case MIPS_REVISION_CORID_BONITO64:
  240. case MIPS_REVISION_CORID_CORE_20K:
  241. mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
  242. break;
  243. case MIPS_REVISION_CORID_CORE_MSC:
  244. case MIPS_REVISION_CORID_CORE_FPGA2:
  245. case MIPS_REVISION_CORID_CORE_24K:
  246. /*
  247. * SOCit/ROCit support is essentially identical
  248. * but make an attempt to distinguish them
  249. */
  250. mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
  251. break;
  252. case MIPS_REVISION_CORID_CORE_FPGA3:
  253. case MIPS_REVISION_CORID_CORE_FPGA4:
  254. case MIPS_REVISION_CORID_CORE_FPGA5:
  255. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  256. default:
  257. /* See above */
  258. mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
  259. break;
  260. }
  261. }
  262. switch (mips_revision_sconid) {
  263. u32 start, map, mask, data;
  264. case MIPS_REVISION_SCON_GT64120:
  265. /*
  266. * Setup the North bridge to do Master byte-lane swapping
  267. * when running in bigendian.
  268. */
  269. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  270. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  271. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  272. GT_PCI0_CMD_SBYTESWAP_BIT);
  273. #else
  274. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  275. #endif
  276. /* Fix up PCI I/O mapping if necessary (for Atlas). */
  277. start = GT_READ(GT_PCI0IOLD_OFS);
  278. map = GT_READ(GT_PCI0IOREMAP_OFS);
  279. if ((start & map) != 0) {
  280. map &= ~start;
  281. GT_WRITE(GT_PCI0IOREMAP_OFS, map);
  282. }
  283. set_io_port_base(MALTA_GT_PORT_BASE);
  284. break;
  285. case MIPS_REVISION_SCON_BONITO:
  286. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  287. /*
  288. * Disable Bonito IOBC.
  289. */
  290. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  291. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  292. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  293. /*
  294. * Setup the North bridge to do Master byte-lane swapping
  295. * when running in bigendian.
  296. */
  297. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  298. BONITO_BONGENCFG = BONITO_BONGENCFG &
  299. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  300. BONITO_BONGENCFG_BYTESWAP);
  301. #else
  302. BONITO_BONGENCFG = BONITO_BONGENCFG |
  303. BONITO_BONGENCFG_MSTRBYTESWAP |
  304. BONITO_BONGENCFG_BYTESWAP;
  305. #endif
  306. set_io_port_base(MALTA_BONITO_PORT_BASE);
  307. break;
  308. case MIPS_REVISION_SCON_SOCIT:
  309. case MIPS_REVISION_SCON_ROCIT:
  310. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  311. mips_pci_controller:
  312. mb();
  313. MSC_READ(MSC01_PCI_CFG, data);
  314. MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
  315. wmb();
  316. /* Fix up lane swapping. */
  317. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  318. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  319. #else
  320. MSC_WRITE(MSC01_PCI_SWAP,
  321. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  322. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  323. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  324. #endif
  325. /* Fix up target memory mapping. */
  326. MSC_READ(MSC01_PCI_BAR0, mask);
  327. MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
  328. /* Don't handle target retries indefinitely. */
  329. if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
  330. MSC01_PCI_CFG_MAXRTRY_MSK)
  331. data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
  332. MSC01_PCI_CFG_MAXRTRY_SHF)) |
  333. ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
  334. MSC01_PCI_CFG_MAXRTRY_SHF);
  335. wmb();
  336. MSC_WRITE(MSC01_PCI_CFG, data);
  337. mb();
  338. set_io_port_base(MALTA_MSC_PORT_BASE);
  339. break;
  340. case MIPS_REVISION_SCON_SOCITSC:
  341. case MIPS_REVISION_SCON_SOCITSCP:
  342. _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
  343. goto mips_pci_controller;
  344. default:
  345. /* Unknown system controller */
  346. mips_display_message("SC Error");
  347. while (1); /* We die here... */
  348. }
  349. board_nmi_handler_setup = mips_nmi_setup;
  350. board_ejtag_handler_setup = mips_ejtag_setup;
  351. pr_info("\nLINUX started...\n");
  352. prom_init_cmdline();
  353. prom_meminit();
  354. #ifdef CONFIG_SERIAL_8250_CONSOLE
  355. console_config();
  356. #endif
  357. #ifdef CONFIG_MIPS_CMP
  358. register_smp_ops(&cmp_smp_ops);
  359. #endif
  360. #ifdef CONFIG_MIPS_MT_SMP
  361. register_smp_ops(&vsmp_smp_ops);
  362. #endif
  363. #ifdef CONFIG_MIPS_MT_SMTC
  364. register_smp_ops(&msmtc_smp_ops);
  365. #endif
  366. }