prom.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright 2002 Momentum Computer Inc.
  3. * Author: Matthew Dharm <mdharm@momenco.com>
  4. *
  5. * Louis Hamilton, Red Hat, Inc.
  6. * hamilton@redhat.com [MIPS64 modifications]
  7. *
  8. * Based on Ocelot Linux port, which is
  9. * Copyright 2001 MontaVista Software Inc.
  10. * Author: jsun@mvista.com or jsun@junsun.net
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * Added changes for SMP - Manish Lachwani (lachwani@pmc-sierra.com)
  18. */
  19. #include <linux/config.h>
  20. #include <linux/init.h>
  21. #include <linux/mm.h>
  22. #include <linux/sched.h>
  23. #include <linux/bootmem.h>
  24. #include <asm/addrspace.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/mv64340.h>
  27. #include <asm/pmon.h>
  28. #include "jaguar_atx_fpga.h"
  29. extern void ja_setup_console(void);
  30. struct callvectors *debug_vectors;
  31. extern unsigned long cpu_clock;
  32. const char *get_system_type(void)
  33. {
  34. return "Momentum Jaguar-ATX";
  35. }
  36. #ifdef CONFIG_MV643XX_ETH
  37. extern unsigned char prom_mac_addr_base[6];
  38. static void burn_clocks(void)
  39. {
  40. int i;
  41. /* this loop should burn at least 1us -- this should be plenty */
  42. for (i = 0; i < 0x10000; i++)
  43. ;
  44. }
  45. static u8 exchange_bit(u8 val, u8 cs)
  46. {
  47. /* place the data */
  48. JAGUAR_FPGA_WRITE((val << 2) | cs, EEPROM_MODE);
  49. burn_clocks();
  50. /* turn the clock on */
  51. JAGUAR_FPGA_WRITE((val << 2) | cs | 0x2, EEPROM_MODE);
  52. burn_clocks();
  53. /* turn the clock off and read-strobe */
  54. JAGUAR_FPGA_WRITE((val << 2) | cs | 0x10, EEPROM_MODE);
  55. /* return the data */
  56. return ((JAGUAR_FPGA_READ(EEPROM_MODE) >> 3) & 0x1);
  57. }
  58. void get_mac(char dest[6])
  59. {
  60. u8 read_opcode[12] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  61. int i,j;
  62. for (i = 0; i < 12; i++)
  63. exchange_bit(read_opcode[i], 1);
  64. for (j = 0; j < 6; j++) {
  65. dest[j] = 0;
  66. for (i = 0; i < 8; i++) {
  67. dest[j] <<= 1;
  68. dest[j] |= exchange_bit(0, 1);
  69. }
  70. }
  71. /* turn off CS */
  72. exchange_bit(0,0);
  73. }
  74. #endif
  75. #ifdef CONFIG_64BIT
  76. unsigned long signext(unsigned long addr)
  77. {
  78. addr &= 0xffffffff;
  79. return (unsigned long)((int)addr);
  80. }
  81. void *get_arg(unsigned long args, int arc)
  82. {
  83. unsigned long ul;
  84. unsigned char *puc, uc;
  85. args += (arc * 4);
  86. ul = (unsigned long)signext(args);
  87. puc = (unsigned char *)ul;
  88. if (puc == 0)
  89. return (void *)0;
  90. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  91. uc = *puc++;
  92. l = (unsigned long)uc;
  93. uc = *puc++;
  94. ul |= (((unsigned long)uc) << 8);
  95. uc = *puc++;
  96. ul |= (((unsigned long)uc) << 16);
  97. uc = *puc++;
  98. ul |= (((unsigned long)uc) << 24);
  99. #else
  100. uc = *puc++;
  101. ul = ((unsigned long)uc) << 24;
  102. uc = *puc++;
  103. ul |= (((unsigned long)uc) << 16);
  104. uc = *puc++;
  105. ul |= (((unsigned long)uc) << 8);
  106. uc = *puc++;
  107. ul |= ((unsigned long)uc);
  108. #endif
  109. ul = signext(ul);
  110. return (void *)ul;
  111. }
  112. char *arg64(unsigned long addrin, int arg_index)
  113. {
  114. unsigned long args;
  115. char *p;
  116. args = signext(addrin);
  117. p = (char *)get_arg(args, arg_index);
  118. return p;
  119. }
  120. #endif /* CONFIG_64BIT */
  121. /* PMON passes arguments in C main() style */
  122. void __init prom_init(void)
  123. {
  124. int argc = fw_arg0;
  125. char **arg = (char **) fw_arg1;
  126. char **env = (char **) fw_arg2;
  127. struct callvectors *cv = (struct callvectors *) fw_arg3;
  128. int i;
  129. #ifdef CONFIG_SERIAL_8250_CONSOLE
  130. // ja_setup_console(); /* The very first thing. */
  131. #endif
  132. #ifdef CONFIG_64BIT
  133. char *ptr;
  134. printk("Mips64 Jaguar-ATX\n");
  135. /* save the PROM vectors for debugging use */
  136. debug_vectors = (struct callvectors *)signext((unsigned long)cv);
  137. /* arg[0] is "g", the rest is boot parameters */
  138. arcs_cmdline[0] = '\0';
  139. for (i = 1; i < argc; i++) {
  140. ptr = (char *)arg64((unsigned long)arg, i);
  141. if ((strlen(arcs_cmdline) + strlen(ptr) + 1) >=
  142. sizeof(arcs_cmdline))
  143. break;
  144. strcat(arcs_cmdline, ptr);
  145. strcat(arcs_cmdline, " ");
  146. }
  147. i = 0;
  148. while (1) {
  149. ptr = (char *)arg64((unsigned long)env, i);
  150. if (! ptr)
  151. break;
  152. if (strncmp("gtbase", ptr, strlen("gtbase")) == 0) {
  153. marvell_base = simple_strtol(ptr + strlen("gtbase="),
  154. NULL, 16);
  155. if ((marvell_base & 0xffffffff00000000) == 0)
  156. marvell_base |= 0xffffffff00000000;
  157. printk("marvell_base set to 0x%016lx\n", marvell_base);
  158. }
  159. if (strncmp("cpuclock", ptr, strlen("cpuclock")) == 0) {
  160. cpu_clock = simple_strtol(ptr + strlen("cpuclock="),
  161. NULL, 10);
  162. printk("cpu_clock set to %d\n", cpu_clock);
  163. }
  164. i++;
  165. }
  166. printk("arcs_cmdline: %s\n", arcs_cmdline);
  167. #else /* CONFIG_64BIT */
  168. /* save the PROM vectors for debugging use */
  169. debug_vectors = cv;
  170. /* arg[0] is "g", the rest is boot parameters */
  171. arcs_cmdline[0] = '\0';
  172. for (i = 1; i < argc; i++) {
  173. if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
  174. >= sizeof(arcs_cmdline))
  175. break;
  176. strcat(arcs_cmdline, arg[i]);
  177. strcat(arcs_cmdline, " ");
  178. }
  179. while (*env) {
  180. if (strncmp("gtbase", *env, strlen("gtbase")) == 0) {
  181. marvell_base = simple_strtol(*env + strlen("gtbase="),
  182. NULL, 16);
  183. }
  184. if (strncmp("cpuclock", *env, strlen("cpuclock")) == 0) {
  185. cpu_clock = simple_strtol(*env + strlen("cpuclock="),
  186. NULL, 10);
  187. }
  188. env++;
  189. }
  190. #endif /* CONFIG_64BIT */
  191. mips_machgroup = MACH_GROUP_MOMENCO;
  192. mips_machtype = MACH_MOMENCO_JAGUAR_ATX;
  193. #ifdef CONFIG_MV643XX_ETH
  194. /* get the base MAC address for on-board ethernet ports */
  195. get_mac(prom_mac_addr_base);
  196. #endif
  197. }
  198. void __init prom_free_prom_memory(void)
  199. {
  200. }
  201. void __init prom_fixup_mem_map(unsigned long start, unsigned long end)
  202. {
  203. }
  204. int prom_boot_secondary(int cpu, unsigned long sp, unsigned long gp)
  205. {
  206. /* Clear the semaphore */
  207. *(volatile uint32_t *)(0xbb000a68) = 0x80000000;
  208. return 1;
  209. }
  210. void prom_init_secondary(void)
  211. {
  212. clear_c0_config(CONF_CM_CMASK);
  213. set_c0_config(0x2);
  214. clear_c0_status(ST0_IM);
  215. set_c0_status(0x1ffff);
  216. }
  217. void prom_smp_finish(void)
  218. {
  219. }