malta-init.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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/bootinfo.h>
  26. #include <asm/gt64120.h>
  27. #include <asm/io.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/smp-ops.h>
  30. #include <asm/traps.h>
  31. #include <asm/gcmpregs.h>
  32. #include <asm/mips-boards/prom.h>
  33. #include <asm/mips-boards/generic.h>
  34. #include <asm/mips-boards/bonito64.h>
  35. #include <asm/mips-boards/msc01_pci.h>
  36. #include <asm/mips-boards/malta.h>
  37. int prom_argc;
  38. int *_prom_argv, *_prom_envp;
  39. /*
  40. * YAMON (32-bit PROM) pass arguments and environment as 32-bit pointer.
  41. * This macro take care of sign extension, if running in 64-bit mode.
  42. */
  43. #define prom_envp(index) ((char *)(long)_prom_envp[(index)])
  44. int init_debug;
  45. static int mips_revision_corid;
  46. int mips_revision_sconid;
  47. /* Bonito64 system controller register base. */
  48. unsigned long _pcictrl_bonito;
  49. unsigned long _pcictrl_bonito_pcicfg;
  50. /* GT64120 system controller register base */
  51. unsigned long _pcictrl_gt64120;
  52. /* MIPS System controller register base */
  53. unsigned long _pcictrl_msc;
  54. char *prom_getenv(char *envname)
  55. {
  56. /*
  57. * Return a pointer to the given environment variable.
  58. * In 64-bit mode: we're using 64-bit pointers, but all pointers
  59. * in the PROM structures are only 32-bit, so we need some
  60. * workarounds, if we are running in 64-bit mode.
  61. */
  62. int i, index=0;
  63. i = strlen(envname);
  64. while (prom_envp(index)) {
  65. if(strncmp(envname, prom_envp(index), i) == 0) {
  66. return(prom_envp(index+1));
  67. }
  68. index += 2;
  69. }
  70. return NULL;
  71. }
  72. static inline unsigned char str2hexnum(unsigned char c)
  73. {
  74. if (c >= '0' && c <= '9')
  75. return c - '0';
  76. if (c >= 'a' && c <= 'f')
  77. return c - 'a' + 10;
  78. return 0; /* foo */
  79. }
  80. static inline void str2eaddr(unsigned char *ea, unsigned char *str)
  81. {
  82. int i;
  83. for (i = 0; i < 6; i++) {
  84. unsigned char num;
  85. if((*str == '.') || (*str == ':'))
  86. str++;
  87. num = str2hexnum(*str++) << 4;
  88. num |= (str2hexnum(*str++));
  89. ea[i] = num;
  90. }
  91. }
  92. int get_ethernet_addr(char *ethernet_addr)
  93. {
  94. char *ethaddr_str;
  95. ethaddr_str = prom_getenv("ethaddr");
  96. if (!ethaddr_str) {
  97. printk("ethaddr not set in boot prom\n");
  98. return -1;
  99. }
  100. str2eaddr(ethernet_addr, ethaddr_str);
  101. if (init_debug > 1) {
  102. int i;
  103. printk("get_ethernet_addr: ");
  104. for (i=0; i<5; i++)
  105. printk("%02x:", (unsigned char)*(ethernet_addr+i));
  106. printk("%02x\n", *(ethernet_addr+i));
  107. }
  108. return 0;
  109. }
  110. #ifdef CONFIG_SERIAL_8250_CONSOLE
  111. static void __init console_config(void)
  112. {
  113. char console_string[40];
  114. int baud = 0;
  115. char parity = '\0', bits = '\0', flow = '\0';
  116. char *s;
  117. if ((strstr(prom_getcmdline(), "console=")) == NULL) {
  118. s = prom_getenv("modetty0");
  119. if (s) {
  120. while (*s >= '0' && *s <= '9')
  121. baud = baud*10 + *s++ - '0';
  122. if (*s == ',') s++;
  123. if (*s) parity = *s++;
  124. if (*s == ',') s++;
  125. if (*s) bits = *s++;
  126. if (*s == ',') s++;
  127. if (*s == 'h') flow = 'r';
  128. }
  129. if (baud == 0)
  130. baud = 38400;
  131. if (parity != 'n' && parity != 'o' && parity != 'e')
  132. parity = 'n';
  133. if (bits != '7' && bits != '8')
  134. bits = '8';
  135. if (flow == '\0')
  136. flow = 'r';
  137. sprintf(console_string, " console=ttyS0,%d%c%c%c", baud, parity, bits, flow);
  138. strcat(prom_getcmdline(), console_string);
  139. pr_info("Config serial console:%s\n", console_string);
  140. }
  141. }
  142. #endif
  143. static void __init mips_nmi_setup(void)
  144. {
  145. void *base;
  146. extern char except_vec_nmi;
  147. base = cpu_has_veic ?
  148. (void *)(CAC_BASE + 0xa80) :
  149. (void *)(CAC_BASE + 0x380);
  150. memcpy(base, &except_vec_nmi, 0x80);
  151. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  152. }
  153. static void __init mips_ejtag_setup(void)
  154. {
  155. void *base;
  156. extern char except_vec_ejtag_debug;
  157. base = cpu_has_veic ?
  158. (void *)(CAC_BASE + 0xa00) :
  159. (void *)(CAC_BASE + 0x300);
  160. memcpy(base, &except_vec_ejtag_debug, 0x80);
  161. flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
  162. }
  163. extern struct plat_smp_ops msmtc_smp_ops;
  164. void __init prom_init(void)
  165. {
  166. prom_argc = fw_arg0;
  167. _prom_argv = (int *) fw_arg1;
  168. _prom_envp = (int *) fw_arg2;
  169. mips_display_message("LINUX");
  170. /*
  171. * early setup of _pcictrl_bonito so that we can determine
  172. * the system controller on a CORE_EMUL board
  173. */
  174. _pcictrl_bonito = (unsigned long)ioremap(BONITO_REG_BASE, BONITO_REG_SIZE);
  175. mips_revision_corid = MIPS_REVISION_CORID;
  176. if (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL) {
  177. if (BONITO_PCIDID == 0x0001df53 ||
  178. BONITO_PCIDID == 0x0003df53)
  179. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_BON;
  180. else
  181. mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
  182. }
  183. mips_revision_sconid = MIPS_REVISION_SCONID;
  184. if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
  185. switch (mips_revision_corid) {
  186. case MIPS_REVISION_CORID_QED_RM5261:
  187. case MIPS_REVISION_CORID_CORE_LV:
  188. case MIPS_REVISION_CORID_CORE_FPGA:
  189. case MIPS_REVISION_CORID_CORE_FPGAR2:
  190. mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
  191. break;
  192. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  193. case MIPS_REVISION_CORID_BONITO64:
  194. case MIPS_REVISION_CORID_CORE_20K:
  195. mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
  196. break;
  197. case MIPS_REVISION_CORID_CORE_MSC:
  198. case MIPS_REVISION_CORID_CORE_FPGA2:
  199. case MIPS_REVISION_CORID_CORE_24K:
  200. /*
  201. * SOCit/ROCit support is essentially identical
  202. * but make an attempt to distinguish them
  203. */
  204. mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
  205. break;
  206. case MIPS_REVISION_CORID_CORE_FPGA3:
  207. case MIPS_REVISION_CORID_CORE_FPGA4:
  208. case MIPS_REVISION_CORID_CORE_FPGA5:
  209. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  210. default:
  211. /* See above */
  212. mips_revision_sconid = MIPS_REVISION_SCON_ROCIT;
  213. break;
  214. }
  215. }
  216. switch (mips_revision_sconid) {
  217. u32 start, map, mask, data;
  218. case MIPS_REVISION_SCON_GT64120:
  219. /*
  220. * Setup the North bridge to do Master byte-lane swapping
  221. * when running in bigendian.
  222. */
  223. _pcictrl_gt64120 = (unsigned long)ioremap(MIPS_GT_BASE, 0x2000);
  224. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  225. GT_WRITE(GT_PCI0_CMD_OFS, GT_PCI0_CMD_MBYTESWAP_BIT |
  226. GT_PCI0_CMD_SBYTESWAP_BIT);
  227. #else
  228. GT_WRITE(GT_PCI0_CMD_OFS, 0);
  229. #endif
  230. /* Fix up PCI I/O mapping if necessary (for Atlas). */
  231. start = GT_READ(GT_PCI0IOLD_OFS);
  232. map = GT_READ(GT_PCI0IOREMAP_OFS);
  233. if ((start & map) != 0) {
  234. map &= ~start;
  235. GT_WRITE(GT_PCI0IOREMAP_OFS, map);
  236. }
  237. set_io_port_base(MALTA_GT_PORT_BASE);
  238. break;
  239. case MIPS_REVISION_SCON_BONITO:
  240. _pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
  241. /*
  242. * Disable Bonito IOBC.
  243. */
  244. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  245. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  246. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  247. /*
  248. * Setup the North bridge to do Master byte-lane swapping
  249. * when running in bigendian.
  250. */
  251. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  252. BONITO_BONGENCFG = BONITO_BONGENCFG &
  253. ~(BONITO_BONGENCFG_MSTRBYTESWAP |
  254. BONITO_BONGENCFG_BYTESWAP);
  255. #else
  256. BONITO_BONGENCFG = BONITO_BONGENCFG |
  257. BONITO_BONGENCFG_MSTRBYTESWAP |
  258. BONITO_BONGENCFG_BYTESWAP;
  259. #endif
  260. set_io_port_base(MALTA_BONITO_PORT_BASE);
  261. break;
  262. case MIPS_REVISION_SCON_SOCIT:
  263. case MIPS_REVISION_SCON_ROCIT:
  264. _pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
  265. mips_pci_controller:
  266. mb();
  267. MSC_READ(MSC01_PCI_CFG, data);
  268. MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
  269. wmb();
  270. /* Fix up lane swapping. */
  271. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  272. MSC_WRITE(MSC01_PCI_SWAP, MSC01_PCI_SWAP_NOSWAP);
  273. #else
  274. MSC_WRITE(MSC01_PCI_SWAP,
  275. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_IO_SHF |
  276. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_MEM_SHF |
  277. MSC01_PCI_SWAP_BYTESWAP << MSC01_PCI_SWAP_BAR0_SHF);
  278. #endif
  279. /* Fix up target memory mapping. */
  280. MSC_READ(MSC01_PCI_BAR0, mask);
  281. MSC_WRITE(MSC01_PCI_P2SCMSKL, mask & MSC01_PCI_BAR0_SIZE_MSK);
  282. /* Don't handle target retries indefinitely. */
  283. if ((data & MSC01_PCI_CFG_MAXRTRY_MSK) ==
  284. MSC01_PCI_CFG_MAXRTRY_MSK)
  285. data = (data & ~(MSC01_PCI_CFG_MAXRTRY_MSK <<
  286. MSC01_PCI_CFG_MAXRTRY_SHF)) |
  287. ((MSC01_PCI_CFG_MAXRTRY_MSK - 1) <<
  288. MSC01_PCI_CFG_MAXRTRY_SHF);
  289. wmb();
  290. MSC_WRITE(MSC01_PCI_CFG, data);
  291. mb();
  292. set_io_port_base(MALTA_MSC_PORT_BASE);
  293. break;
  294. case MIPS_REVISION_SCON_SOCITSC:
  295. case MIPS_REVISION_SCON_SOCITSCP:
  296. _pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
  297. goto mips_pci_controller;
  298. default:
  299. /* Unknown system controller */
  300. mips_display_message("SC Error");
  301. while (1); /* We die here... */
  302. }
  303. board_nmi_handler_setup = mips_nmi_setup;
  304. board_ejtag_handler_setup = mips_ejtag_setup;
  305. prom_init_cmdline();
  306. prom_meminit();
  307. #ifdef CONFIG_SERIAL_8250_CONSOLE
  308. console_config();
  309. #endif
  310. /* Early detection of CMP support */
  311. if (gcmp_probe(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ))
  312. if (!register_cmp_smp_ops())
  313. return;
  314. if (!register_vsmp_smp_ops())
  315. return;
  316. #ifdef CONFIG_MIPS_MT_SMTC
  317. register_smp_ops(&msmtc_smp_ops);
  318. #endif
  319. }