malta-init.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 <[email protected]>
  11. * Maciej W. Rozycki <[email protected]>
  12. * Steven J. Hill <[email protected]>
  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. base = cpu_has_veic ?
  84. (void *)(CAC_BASE + 0xa80) :
  85. (void *)(CAC_BASE + 0x380);
  86. memcpy(base, except_vec_nmi, 0x80);
  87. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  88. }
  89. static void __init mips_ejtag_setup(void)
  90. {
  91. void *base;
  92. extern char except_vec_ejtag_debug[];
  93. base = cpu_has_veic ?
  94. (void *)(CAC_BASE + 0xa00) :
  95. (void *)(CAC_BASE + 0x300);
  96. memcpy(base, except_vec_ejtag_debug, 0x80);
  97. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  98. }
  99. phys_addr_t mips_cpc_default_phys_base(void)
  100. {
  101. return CPC_BASE_ADDR;
  102. }
  103. void __init prom_init(void)
  104. {
  105. /*
  106. * early setup of _pcictrl_bonito so that we can determine
  107. * the system controller on a CORE_EMUL board
  108. */
  109. _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
  110. mips_revision_corid = MIPS_REVISION_CORID;
  111. if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
  112. if (BONITO_PCIDID == 0x0001df53 ||
  113. BONITO_PCIDID == 0x0003df53)
  114. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
  115. else
  116. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
  117. }
  118. mips_revision_sconid = MIPS_REVISION_SCONID;
  119. if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
  120. switch (mips_revision_corid) {
  121. case MIPS_REVISION_CORID_QED_RM5261:
  122. case MIPS_REVISION_CORID_CORE_LV:
  123. case MIPS_REVISION_CORID_CORE_FPGA:
  124. case MIPS_REVISION_CORID_CORE_FPGAR2:
  125. mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
  126. break;
  127. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  128. case MIPS_REVISION_CORID_BONITO64:
  129. case MIPS_REVISION_CORID_CORE_20K:
  130. mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
  131. break;
  132. case MIPS_REVISION_CORID_CORE_MSC:
  133. case MIPS_REVISION_CORID_CORE_FPGA2:
  134. case MIPS_REVISION_CORID_CORE_24K:
  135. /*
  136. * SOCit/ROCit support is essentially identical
  137. * but make an attempt to distinguish them
  138. */
  139. mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
  140. break;
  141. case MIPS_REVISION_CORID_CORE_FPGA3:
  142. case MIPS_REVISION_CORID_CORE_FPGA4:
  143. case MIPS_REVISION_CORID_CORE_FPGA5:
  144. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  145. default:
  146. /* See above */
  147. mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
  148. break;
  149. }
  150. }
  151. switch (mips_revision_sconid) {
  152. u32 start, map, mask, data;
  153. case MIPS_REVISION_SCON_GT64120:
  154. /*
  155. * Setup the North bridge to do Master byte-lane swapping
  156. * when running in bigendian.
  157. */
  158. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  159. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  160. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  161. GT_PCI0_CMD_SBYTESWAP_BIT);
  162. #else
  163. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  164. #endif
  165. /* Fix up PCI I/O mapping if necessary (for Atlas). */
  166. start = GT_READ(GT_PCI0IOLD_OFS);
  167. map = GT_READ(GT_PCI0IOREMAP_OFS);
  168. if ((start & map) != 0) {
  169. map &= ~start;
  170. GT_WRITE(GT_PCI0IOREMAP_OFS, map);
  171. }
  172. set_io_port_base(MALTA_GT_PORT_BASE);
  173. break;
  174. case MIPS_REVISION_SCON_BONITO:
  175. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  176. /*
  177. * Disable Bonito IOBC.
  178. */
  179. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  180. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  181. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  182. /*
  183. * Setup the North bridge to do Master byte-lane swapping
  184. * when running in bigendian.
  185. */
  186. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  187. BONITO_BONGENCFG = BONITO_BONGENCFG &
  188. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  189. BONITO_BONGENCFG_BYTESWAP);
  190. #else
  191. BONITO_BONGENCFG = BONITO_BONGENCFG |
  192. BONITO_BONGENCFG_MSTRBYTESWAP |
  193. BONITO_BONGENCFG_BYTESWAP;
  194. #endif
  195. set_io_port_base(MALTA_BONITO_PORT_BASE);
  196. break;
  197. case MIPS_REVISION_SCON_SOCIT:
  198. case MIPS_REVISION_SCON_ROCIT:
  199. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  200. mips_pci_controller:
  201. mb();
  202. MSC_READ(MSC01_PCI_CFG, data);
  203. MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
  204. wmb();
  205. /* Fix up lane swapping. */
  206. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  207. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  208. #else
  209. MSC_WRITE(MSC01_PCI_SWAP,
  210. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  211. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  212. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  213. #endif
  214. /*
  215. * Setup the Malta max (2GB) memory for PCI DMA in host bridge
  216. * in transparent addressing mode.
  217. */
  218. mask = PHYS_OFFSET | PCI_BASE_ADDRESS_MEM_PREFETCH;
  219. MSC_WRITE(MSC01_PCI_BAR0, mask);
  220. MSC_WRITE(MSC01_PCI_HEAD4, mask);
  221. mask &= MSC01_PCI_BAR0_SIZE_MSK;
  222. MSC_WRITE(MSC01_PCI_P2SCMSKL, mask);
  223. MSC_WRITE(MSC01_PCI_P2SCMAPL, mask);
  224. /* Don't handle target retries indefinitely. */
  225. if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
  226. MSC01_PCI_CFG_MAXRTRY_MSK)
  227. data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
  228. MSC01_PCI_CFG_MAXRTRY_SHF)) |
  229. ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
  230. MSC01_PCI_CFG_MAXRTRY_SHF);
  231. wmb();
  232. MSC_WRITE(MSC01_PCI_CFG, data);
  233. mb();
  234. set_io_port_base(MALTA_MSC_PORT_BASE);
  235. break;
  236. case MIPS_REVISION_SCON_SOCITSC:
  237. case MIPS_REVISION_SCON_SOCITSCP:
  238. _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
  239. goto mips_pci_controller;
  240. default:
  241. /* Unknown system controller */
  242. while (1); /* We die here... */
  243. }
  244. board_nmi_handler_setup = mips_nmi_setup;
  245. board_ejtag_handler_setup = mips_ejtag_setup;
  246. fw_init_cmdline();
  247. fw_meminit();
  248. #ifdef CONFIG_SERIAL_8250_CONSOLE
  249. console_config();
  250. #endif
  251. /* Early detection of CMP support */
  252. mips_cpc_probe();
  253. if (!register_cps_smp_ops())
  254. return;
  255. if (!register_cmp_smp_ops())
  256. return;
  257. if (!register_vsmp_smp_ops())
  258. return;
  259. register_up_smp_ops();
  260. }