malta-init.c 9.8 KB

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