prom.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. #include <linux/init.h>
  18. #include <linux/mm.h>
  19. #include <linux/sched.h>
  20. #include <linux/bootmem.h>
  21. #include <linux/mv643xx.h>
  22. #include <asm/addrspace.h>
  23. #include <asm/bootinfo.h>
  24. #include <asm/pmon.h>
  25. #include "ocelot_c_fpga.h"
  26. struct callvectors* debug_vectors;
  27. extern unsigned long marvell_base;
  28. extern unsigned int cpu_clock;
  29. const char *get_system_type(void)
  30. {
  31. #ifdef CONFIG_CPU_SR71000
  32. return "Momentum Ocelot-CS";
  33. #else
  34. return "Momentum Ocelot-C";
  35. #endif
  36. }
  37. #ifdef CONFIG_64BIT
  38. unsigned long signext(unsigned long addr)
  39. {
  40. addr &= 0xffffffff;
  41. return (unsigned long)((int)addr);
  42. }
  43. void *get_arg(unsigned long args, int arc)
  44. {
  45. unsigned long ul;
  46. unsigned char *puc, uc;
  47. args += (arc * 4);
  48. ul = (unsigned long)signext(args);
  49. puc = (unsigned char *)ul;
  50. if (puc == 0)
  51. return (void *)0;
  52. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  53. uc = *puc++;
  54. ul = (unsigned long)uc;
  55. uc = *puc++;
  56. ul |= (((unsigned long)uc) << 8);
  57. uc = *puc++;
  58. ul |= (((unsigned long)uc) << 16);
  59. uc = *puc++;
  60. ul |= (((unsigned long)uc) << 24);
  61. #else /* CONFIG_CPU_LITTLE_ENDIAN */
  62. uc = *puc++;
  63. ul = ((unsigned long)uc) << 24;
  64. uc = *puc++;
  65. ul |= (((unsigned long)uc) << 16);
  66. uc = *puc++;
  67. ul |= (((unsigned long)uc) << 8);
  68. uc = *puc++;
  69. ul |= ((unsigned long)uc);
  70. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  71. ul = signext(ul);
  72. return (void *)ul;
  73. }
  74. char *arg64(unsigned long addrin, int arg_index)
  75. {
  76. unsigned long args;
  77. char *p;
  78. args = signext(addrin);
  79. p = (char *)get_arg(args, arg_index);
  80. return p;
  81. }
  82. #endif /* CONFIG_64BIT */
  83. void __init prom_init(void)
  84. {
  85. int argc = fw_arg0;
  86. char **arg = (char **) fw_arg1;
  87. char **env = (char **) fw_arg2;
  88. struct callvectors *cv = (struct callvectors *) fw_arg3;
  89. int i;
  90. #ifdef CONFIG_64BIT
  91. char *ptr;
  92. printk("prom_init - MIPS64\n");
  93. /* save the PROM vectors for debugging use */
  94. debug_vectors = (struct callvectors *)signext((unsigned long)cv);
  95. /* arg[0] is "g", the rest is boot parameters */
  96. arcs_cmdline[0] = '\0';
  97. for (i = 1; i < argc; i++) {
  98. ptr = (char *)arg64((unsigned long)arg, i);
  99. if ((strlen(arcs_cmdline) + strlen(ptr) + 1) >=
  100. sizeof(arcs_cmdline))
  101. break;
  102. strcat(arcs_cmdline, ptr);
  103. strcat(arcs_cmdline, " ");
  104. }
  105. i = 0;
  106. while (1) {
  107. ptr = (char *)arg64((unsigned long)env, i);
  108. if (! ptr)
  109. break;
  110. if (strncmp("gtbase", ptr, strlen("gtbase")) == 0) {
  111. marvell_base = simple_strtol(ptr + strlen("gtbase="),
  112. NULL, 16);
  113. if ((marvell_base & 0xffffffff00000000) == 0)
  114. marvell_base |= 0xffffffff00000000;
  115. printk("marvell_base set to 0x%016lx\n", marvell_base);
  116. }
  117. if (strncmp("cpuclock", ptr, strlen("cpuclock")) == 0) {
  118. cpu_clock = simple_strtol(ptr + strlen("cpuclock="),
  119. NULL, 10);
  120. printk("cpu_clock set to %d\n", cpu_clock);
  121. }
  122. i++;
  123. }
  124. printk("arcs_cmdline: %s\n", arcs_cmdline);
  125. #else /* CONFIG_64BIT */
  126. /* save the PROM vectors for debugging use */
  127. debug_vectors = cv;
  128. /* arg[0] is "g", the rest is boot parameters */
  129. arcs_cmdline[0] = '\0';
  130. for (i = 1; i < argc; i++) {
  131. if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
  132. >= sizeof(arcs_cmdline))
  133. break;
  134. strcat(arcs_cmdline, arg[i]);
  135. strcat(arcs_cmdline, " ");
  136. }
  137. while (*env) {
  138. if (strncmp("gtbase", *env, strlen("gtbase")) == 0) {
  139. marvell_base = simple_strtol(*env + strlen("gtbase="),
  140. NULL, 16);
  141. }
  142. if (strncmp("cpuclock", *env, strlen("cpuclock")) == 0) {
  143. cpu_clock = simple_strtol(*env + strlen("cpuclock="),
  144. NULL, 10);
  145. }
  146. env++;
  147. }
  148. #endif /* CONFIG_64BIT */
  149. mips_machgroup = MACH_GROUP_MOMENCO;
  150. mips_machtype = MACH_MOMENCO_OCELOT_C;
  151. #ifndef CONFIG_64BIT
  152. debug_vectors->printf("Booting Linux kernel...\n");
  153. #endif
  154. }
  155. void __init prom_free_prom_memory(void)
  156. {
  157. }