malta-init.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * PROM library initialisation code.
  7. *
  8. * Copyright (C) 1999,2000,2004,2005,2012 MIPS Technologies, Inc.
  9. * All rights reserved.
  10. * Authors: Carsten Langgaard <carstenl@mips.com>
  11. * Maciej W. Rozycki <macro@mips.com>
  12. * Steven J. Hill <sjhill@mips.com>
  13. */
  14. #include <linux/init.h>
  15. #include <linux/string.h>
  16. #include <linux/kernel.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/smp-ops.h>
  19. #include <asm/traps.h>
  20. #include <asm/fw/fw.h>
  21. #include <asm/gcmpregs.h>
  22. #include <asm/mips-boards/generic.h>
  23. #include <asm/mips-boards/malta.h>
  24. static int mips_revision_corid;
  25. int mips_revision_sconid;
  26. /* Bonito64 system controller register base. */
  27. unsigned long _pcictrl_bonito;
  28. unsigned long _pcictrl_bonito_pcicfg;
  29. /* GT64120 system controller register base */
  30. unsigned long _pcictrl_gt64120;
  31. /* MIPS System controller register base */
  32. unsigned long _pcictrl_msc;
  33. #ifdef CONFIG_SERIAL_8250_CONSOLE
  34. static void __init console_config(void)
  35. {
  36. char console_string[40];
  37. int baud = 0;
  38. char parity = '\0', bits = '\0', flow = '\0';
  39. char *s;
  40. if ((strstr(fw_getcmdline(), "console=")) == NULL) {
  41. s = fw_getenv("modetty0");
  42. if (s) {
  43. while (*s >= '0' && *s <= '9')
  44. baud = baud*10 + *s++ - '0';
  45. if (*s == ',')
  46. s++;
  47. if (*s)
  48. parity = *s++;
  49. if (*s == ',')
  50. s++;
  51. if (*s)
  52. bits = *s++;
  53. if (*s == ',')
  54. s++;
  55. if (*s == 'h')
  56. flow = 'r';
  57. }
  58. if (baud == 0)
  59. baud = 38400;
  60. if (parity != 'n' && parity != 'o' && parity != 'e')
  61. parity = 'n';
  62. if (bits != '7' && bits != '8')
  63. bits = '8';
  64. if (flow == '\0')
  65. flow = 'r';
  66. sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
  67. parity, bits, flow);
  68. strcat(fw_getcmdline(), console_string);
  69. pr_info("Config serial console:%s\n", console_string);
  70. }
  71. }
  72. #endif
  73. static void __init mips_nmi_setup(void)
  74. {
  75. void *base;
  76. extern char except_vec_nmi;
  77. base = cpu_has_veic ?
  78. (void *)(CAC_BASE + 0xa80) :
  79. (void *)(CAC_BASE + 0x380);
  80. memcpy(base, &except_vec_nmi, 0x80);
  81. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  82. }
  83. static void __init mips_ejtag_setup(void)
  84. {
  85. void *base;
  86. extern char except_vec_ejtag_debug;
  87. base = cpu_has_veic ?
  88. (void *)(CAC_BASE + 0xa00) :
  89. (void *)(CAC_BASE + 0x300);
  90. memcpy(base, &except_vec_ejtag_debug, 0x80);
  91. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  92. }
  93. extern struct plat_smp_ops msmtc_smp_ops;
  94. void __init prom_init(void)
  95. {
  96. mips_display_message("LINUX");
  97. /*
  98. * early setup of _pcictrl_bonito so that we can determine
  99. * the system controller on a CORE_EMUL board
  100. */
  101. _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
  102. mips_revision_corid = MIPS_REVISION_CORID;
  103. if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
  104. if (BONITO_PCIDID == 0x0001df53 ||
  105. BONITO_PCIDID == 0x0003df53)
  106. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
  107. else
  108. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
  109. }
  110. mips_revision_sconid = MIPS_REVISION_SCONID;
  111. if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
  112. switch (mips_revision_corid) {
  113. case MIPS_REVISION_CORID_QED_RM5261:
  114. case MIPS_REVISION_CORID_CORE_LV:
  115. case MIPS_REVISION_CORID_CORE_FPGA:
  116. case MIPS_REVISION_CORID_CORE_FPGAR2:
  117. mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
  118. break;
  119. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  120. case MIPS_REVISION_CORID_BONITO64:
  121. case MIPS_REVISION_CORID_CORE_20K:
  122. mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
  123. break;
  124. case MIPS_REVISION_CORID_CORE_MSC:
  125. case MIPS_REVISION_CORID_CORE_FPGA2:
  126. case MIPS_REVISION_CORID_CORE_24K:
  127. /*
  128. * SOCit/ROCit support is essentially identical
  129. * but make an attempt to distinguish them
  130. */
  131. mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
  132. break;
  133. case MIPS_REVISION_CORID_CORE_FPGA3:
  134. case MIPS_REVISION_CORID_CORE_FPGA4:
  135. case MIPS_REVISION_CORID_CORE_FPGA5:
  136. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  137. default:
  138. /* See above */
  139. mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
  140. break;
  141. }
  142. }
  143. switch (mips_revision_sconid) {
  144. u32 start, map, mask, data;
  145. case MIPS_REVISION_SCON_GT64120:
  146. /*
  147. * Setup the North bridge to do Master byte-lane swapping
  148. * when running in bigendian.
  149. */
  150. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  151. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  152. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  153. GT_PCI0_CMD_SBYTESWAP_BIT);
  154. #else
  155. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  156. #endif
  157. /* Fix up PCI I/O mapping if necessary (for Atlas). */
  158. start = GT_READ(GT_PCI0IOLD_OFS);
  159. map = GT_READ(GT_PCI0IOREMAP_OFS);
  160. if ((start & map) != 0) {
  161. map &= ~start;
  162. GT_WRITE(GT_PCI0IOREMAP_OFS, map);
  163. }
  164. set_io_port_base(MALTA_GT_PORT_BASE);
  165. break;
  166. case MIPS_REVISION_SCON_BONITO:
  167. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  168. /*
  169. * Disable Bonito IOBC.
  170. */
  171. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  172. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  173. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  174. /*
  175. * Setup the North bridge to do Master byte-lane swapping
  176. * when running in bigendian.
  177. */
  178. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  179. BONITO_BONGENCFG = BONITO_BONGENCFG &
  180. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  181. BONITO_BONGENCFG_BYTESWAP);
  182. #else
  183. BONITO_BONGENCFG = BONITO_BONGENCFG |
  184. BONITO_BONGENCFG_MSTRBYTESWAP |
  185. BONITO_BONGENCFG_BYTESWAP;
  186. #endif
  187. set_io_port_base(MALTA_BONITO_PORT_BASE);
  188. break;
  189. case MIPS_REVISION_SCON_SOCIT:
  190. case MIPS_REVISION_SCON_ROCIT:
  191. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  192. mips_pci_controller:
  193. mb();
  194. MSC_READ(MSC01_PCI_CFG, data);
  195. MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
  196. wmb();
  197. /* Fix up lane swapping. */
  198. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  199. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  200. #else
  201. MSC_WRITE(MSC01_PCI_SWAP,
  202. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  203. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  204. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  205. #endif
  206. /* Fix up target memory mapping. */
  207. MSC_READ(MSC01_PCI_BAR0, mask);
  208. MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
  209. /* Don't handle target retries indefinitely. */
  210. if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
  211. MSC01_PCI_CFG_MAXRTRY_MSK)
  212. data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
  213. MSC01_PCI_CFG_MAXRTRY_SHF)) |
  214. ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
  215. MSC01_PCI_CFG_MAXRTRY_SHF);
  216. wmb();
  217. MSC_WRITE(MSC01_PCI_CFG, data);
  218. mb();
  219. set_io_port_base(MALTA_MSC_PORT_BASE);
  220. break;
  221. case MIPS_REVISION_SCON_SOCITSC:
  222. case MIPS_REVISION_SCON_SOCITSCP:
  223. _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
  224. goto mips_pci_controller;
  225. default:
  226. /* Unknown system controller */
  227. mips_display_message("SC Error");
  228. while (1); /* We die here... */
  229. }
  230. board_nmi_handler_setup = mips_nmi_setup;
  231. board_ejtag_handler_setup = mips_ejtag_setup;
  232. fw_init_cmdline();
  233. fw_meminit();
  234. #ifdef CONFIG_SERIAL_8250_CONSOLE
  235. console_config();
  236. #endif
  237. /* Early detection of CMP support */
  238. if (gcmp_probe(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ))
  239. if (!register_cmp_smp_ops())
  240. return;
  241. if (!register_vsmp_smp_ops())
  242. return;
  243. #ifdef CONFIG_MIPS_MT_SMTC
  244. register_smp_ops(&msmtc_smp_ops);
  245. #endif
  246. }