malta-init.c 7.8 KB

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