malta-init.c 9.5 KB

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