malta-init.c 7.7 KB

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