malta-init.c 7.7 KB

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