init.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * PROM library initialisation code.
  19. */
  20. #include <linux/config.h>
  21. #include <linux/init.h>
  22. #include <linux/string.h>
  23. #include <linux/kernel.h>
  24. #include <asm/io.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/mips-boards/prom.h>
  27. #include <asm/mips-boards/generic.h>
  28. #ifdef CONFIG_MIPS_GT64120
  29. #include <asm/gt64120.h>
  30. #endif
  31. #include <asm/mips-boards/msc01_pci.h>
  32. #include <asm/mips-boards/bonito64.h>
  33. #ifdef CONFIG_MIPS_MALTA
  34. #include <asm/mips-boards/malta.h>
  35. #endif
  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. unsigned int mips_revision_corid;
  53. /* Bonito64 system controller register base. */
  54. unsigned long _pcictrl_bonito;
  55. unsigned long _pcictrl_bonito_pcicfg;
  56. /* GT64120 system controller register base */
  57. unsigned long _pcictrl_gt64120;
  58. /* MIPS System controller register base */
  59. unsigned long _pcictrl_msc;
  60. char *prom_getenv(char *envname)
  61. {
  62. /*
  63. * Return a pointer to the given environment variable.
  64. * In 64-bit mode: we're using 64-bit pointers, but all pointers
  65. * in the PROM structures are only 32-bit, so we need some
  66. * workarounds, if we are running in 64-bit mode.
  67. */
  68. int i, index=0;
  69. i = strlen(envname);
  70. while (prom_envp(index)) {
  71. if(strncmp(envname, prom_envp(index), i) == 0) {
  72. return(prom_envp(index+1));
  73. }
  74. index += 2;
  75. }
  76. return NULL;
  77. }
  78. static inline unsigned char str2hexnum(unsigned char c)
  79. {
  80. if (c >= '0' && c <= '9')
  81. return c - '0';
  82. if (c >= 'a' && c <= 'f')
  83. return c - 'a' + 10;
  84. return 0; /* foo */
  85. }
  86. static inline void str2eaddr(unsigned char *ea, unsigned char *str)
  87. {
  88. int i;
  89. for (i = 0; i < 6; i++) {
  90. unsigned char num;
  91. if((*str == '.') || (*str == ':'))
  92. str++;
  93. num = str2hexnum(*str++) << 4;
  94. num |= (str2hexnum(*str++));
  95. ea[i] = num;
  96. }
  97. }
  98. int get_ethernet_addr(char *ethernet_addr)
  99. {
  100. char *ethaddr_str;
  101. ethaddr_str = prom_getenv("ethaddr");
  102. if (!ethaddr_str) {
  103. printk("ethaddr not set in boot prom\n");
  104. return -1;
  105. }
  106. str2eaddr(ethernet_addr, ethaddr_str);
  107. if (init_debug > 1) {
  108. int i;
  109. printk("get_ethernet_addr: ");
  110. for (i=0; i<5; i++)
  111. printk("%02x:", (unsigned char)*(ethernet_addr+i));
  112. printk("%02x\n", *(ethernet_addr+i));
  113. }
  114. return 0;
  115. }
  116. #ifdef CONFIG_SERIAL_8250_CONSOLE
  117. static void __init console_config(void)
  118. {
  119. char console_string[40];
  120. int baud = 0;
  121. char parity = '\0', bits = '\0', flow = '\0';
  122. char *s;
  123. if ((strstr(prom_getcmdline(), "console=ttyS")) == NULL) {
  124. s = prom_getenv("modetty0");
  125. if (s) {
  126. while (*s >= '0' && *s <= '9')
  127. baud = baud*10 + *s++ - '0';
  128. if (*s == ',') s++;
  129. if (*s) parity = *s++;
  130. if (*s == ',') s++;
  131. if (*s) bits = *s++;
  132. if (*s == ',') s++;
  133. if (*s == 'h') flow = 'r';
  134. }
  135. if (baud == 0)
  136. baud = 38400;
  137. if (parity != 'n' && parity != 'o' && parity != 'e')
  138. parity = 'n';
  139. if (bits != '7' && bits != '8')
  140. bits = '8';
  141. if (flow == '\0')
  142. flow = 'r';
  143. sprintf (console_string, " console=ttyS0,%d%c%c%c", baud, parity, bits, flow);
  144. strcat (prom_getcmdline(), console_string);
  145. prom_printf("Config serial console:%s\n", console_string);
  146. }
  147. }
  148. #endif
  149. #ifdef CONFIG_KGDB
  150. void __init kgdb_config (void)
  151. {
  152. extern int (*generic_putDebugChar)(char);
  153. extern char (*generic_getDebugChar)(void);
  154. char *argptr;
  155. int line, speed;
  156. argptr = prom_getcmdline();
  157. if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
  158. argptr += strlen("kgdb=ttyS");
  159. if (*argptr != '0' && *argptr != '1')
  160. printk("KGDB: Unknown serial line /dev/ttyS%c, "
  161. "falling back to /dev/ttyS1\n", *argptr);
  162. line = *argptr == '0' ? 0 : 1;
  163. printk("KGDB: Using serial line /dev/ttyS%d for session\n", line);
  164. speed = 0;
  165. if (*++argptr == ',')
  166. {
  167. int c;
  168. while ((c = *++argptr) && ('0' <= c && c <= '9'))
  169. speed = speed * 10 + c - '0';
  170. }
  171. #ifdef CONFIG_MIPS_ATLAS
  172. if (line == 1) {
  173. speed = saa9730_kgdb_hook(speed);
  174. generic_putDebugChar = saa9730_putDebugChar;
  175. generic_getDebugChar = saa9730_getDebugChar;
  176. }
  177. else
  178. #endif
  179. {
  180. speed = rs_kgdb_hook(line, speed);
  181. generic_putDebugChar = rs_putDebugChar;
  182. generic_getDebugChar = rs_getDebugChar;
  183. }
  184. prom_printf("KGDB: Using serial line /dev/ttyS%d at %d for session, "
  185. "please connect your debugger\n", line ? 1 : 0, speed);
  186. {
  187. char *s;
  188. for (s = "Please connect GDB to this port\r\n"; *s; )
  189. generic_putDebugChar (*s++);
  190. }
  191. kgdb_enabled = 1;
  192. /* Breakpoint is invoked after interrupts are initialised */
  193. }
  194. }
  195. #endif
  196. void __init prom_init(void)
  197. {
  198. prom_argc = fw_arg0;
  199. _prom_argv = (int *) fw_arg1;
  200. _prom_envp = (int *) fw_arg2;
  201. mips_display_message("LINUX");
  202. #ifdef CONFIG_MIPS_SEAD
  203. set_io_port_base(KSEG1);
  204. #else
  205. /*
  206. * early setup of _pcictrl_bonito so that we can determine
  207. * the system controller on a CORE_EMUL board
  208. */
  209. _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
  210. mips_revision_corid = MIPS_REVISION_CORID;
  211. if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
  212. if (BONITO_PCIDID == 0x0001df53 ||
  213. BONITO_PCIDID == 0x0003df53)
  214. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
  215. else
  216. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
  217. }
  218. switch(mips_revision_corid) {
  219. case MIPS_REVISION_CORID_QED_RM5261:
  220. case MIPS_REVISION_CORID_CORE_LV:
  221. case MIPS_REVISION_CORID_CORE_FPGA:
  222. case MIPS_REVISION_CORID_CORE_FPGAR2:
  223. /*
  224. * Setup the North bridge to do Master byte-lane swapping
  225. * when running in bigendian.
  226. */
  227. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  228. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  229. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  230. GT_PCI0_CMD_SBYTESWAP_BIT);
  231. #else
  232. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  233. #endif
  234. #ifdef CONFIG_MIPS_MALTA
  235. set_io_port_base(MALTA_GT_PORT_BASE);
  236. #else
  237. set_io_port_base((unsigned long)ioremap(0, 0x20000000));
  238. #endif
  239. break;
  240. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  241. case MIPS_REVISION_CORID_BONITO64:
  242. case MIPS_REVISION_CORID_CORE_20K:
  243. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  244. /*
  245. * Disable Bonito IOBC.
  246. */
  247. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  248. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  249. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  250. /*
  251. * Setup the North bridge to do Master byte-lane swapping
  252. * when running in bigendian.
  253. */
  254. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  255. BONITO_BONGENCFG = BONITO_BONGENCFG &
  256. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  257. BONITO_BONGENCFG_BYTESWAP);
  258. #else
  259. BONITO_BONGENCFG = BONITO_BONGENCFG |
  260. BONITO_BONGENCFG_MSTRBYTESWAP |
  261. BONITO_BONGENCFG_BYTESWAP;
  262. #endif
  263. #ifdef CONFIG_MIPS_MALTA
  264. set_io_port_base(MALTA_BONITO_PORT_BASE);
  265. #else
  266. set_io_port_base((unsigned long)ioremap(0, 0x20000000));
  267. #endif
  268. break;
  269. case MIPS_REVISION_CORID_CORE_MSC:
  270. case MIPS_REVISION_CORID_CORE_FPGA2:
  271. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  272. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  273. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  274. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  275. #else
  276. MSC_WRITE(MSC01_PCI_SWAP,
  277. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  278. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  279. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  280. #endif
  281. #ifdef CONFIG_MIPS_MALTA
  282. set_io_port_base(MALTA_MSC_PORT_BASE);
  283. #else
  284. set_io_port_base((unsigned long)ioremap(0, 0x20000000));
  285. #endif
  286. break;
  287. default:
  288. /* Unknown Core card */
  289. mips_display_message("CC Error");
  290. while(1); /* We die here... */
  291. }
  292. #endif
  293. prom_printf("\nLINUX started...\n");
  294. prom_init_cmdline();
  295. prom_meminit();
  296. #ifdef CONFIG_SERIAL_8250_CONSOLE
  297. console_config();
  298. #endif
  299. }