sniprom.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Big Endian PROM code for SNI RM machines
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2005-2006 Florian Lohoff (flo@rfc822.org)
  9. * Copyright (C) 2005-2006 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/string.h>
  14. #include <linux/console.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/sni.h>
  17. #include <asm/mipsprom.h>
  18. #include <asm/bootinfo.h>
  19. /* special SNI prom calls */
  20. /*
  21. * This does not exist in all proms - SINIX compares
  22. * the prom env variable "version" against "2.0008"
  23. * or greater. If lesser it tries to probe interesting
  24. * registers
  25. */
  26. #define PROM_GET_MEMCONF 58
  27. #define PROM_VEC (u64 *)CKSEG1ADDR(0x1fc00000)
  28. #define PROM_ENTRY(x) (PROM_VEC + (x))
  29. #define DEBUG
  30. #ifdef DEBUG
  31. #define DBG_PRINTF(x...) prom_printf(x)
  32. #else
  33. #define DBG_PRINTF(x...)
  34. #endif
  35. static int *(*__prom_putchar)(int) = (int *(*)(int))PROM_ENTRY(PROM_PUTCHAR);
  36. static char *(*__prom_getenv)(char *) = (char *(*)(char *))PROM_ENTRY(PROM_GETENV);
  37. static void (*__prom_get_memconf)(void *) = (void (*)(void *))PROM_ENTRY(PROM_GET_MEMCONF);
  38. char *prom_getenv (char *s)
  39. {
  40. return __prom_getenv(s);
  41. }
  42. void prom_printf(char *fmt, ...)
  43. {
  44. va_list args;
  45. char ppbuf[1024];
  46. char *bptr;
  47. va_start(args, fmt);
  48. vsprintf(ppbuf, fmt, args);
  49. bptr = ppbuf;
  50. while (*bptr != 0) {
  51. if (*bptr == '\n')
  52. __prom_putchar('\r');
  53. __prom_putchar(*bptr++);
  54. }
  55. va_end(args);
  56. }
  57. void __init prom_free_prom_memory(void)
  58. {
  59. }
  60. /*
  61. * /proc/cpuinfo system type
  62. *
  63. */
  64. static const char *systype = "Unknown";
  65. const char *get_system_type(void)
  66. {
  67. return systype;
  68. }
  69. #define SNI_IDPROM_BASE 0xbff00000
  70. #define SNI_IDPROM_MEMSIZE (SNI_IDPROM_BASE+0x28) /* Memsize in 16MB quantities */
  71. #define SNI_IDPROM_BRDTYPE (SNI_IDPROM_BASE+0x29) /* Board Type */
  72. #define SNI_IDPROM_CPUTYPE (SNI_IDPROM_BASE+0x30) /* CPU Type */
  73. #define SNI_IDPROM_SIZE 0x1000
  74. #ifdef DEBUG
  75. static void sni_idprom_dump(void)
  76. {
  77. int i;
  78. prom_printf("SNI IDProm dump:\n");
  79. for (i = 0; i < 256; i++) {
  80. if (i%16 == 0)
  81. prom_printf("%04x ", i);
  82. prom_printf("%02x ", *(unsigned char *) (SNI_IDPROM_BASE + i));
  83. if (i % 16 == 15)
  84. prom_printf("\n");
  85. }
  86. }
  87. #endif
  88. static void sni_mem_init(void )
  89. {
  90. int i, memsize;
  91. struct membank {
  92. u32 size;
  93. u32 base;
  94. u32 size2;
  95. u32 pad1;
  96. u32 pad2;
  97. } memconf[8];
  98. /* MemSIZE from prom in 16MByte chunks */
  99. memsize = *((unsigned char *) SNI_IDPROM_MEMSIZE) * 16;
  100. DBG_PRINTF("IDProm memsize: %lu MByte\n", memsize);
  101. /* get memory bank layout from prom */
  102. __prom_get_memconf(&memconf);
  103. DBG_PRINTF("prom_get_mem_conf memory configuration:\n");
  104. for (i = 0;i < 8 && memconf[i].size; i++) {
  105. if (sni_brd_type == SNI_BRD_PCI_TOWER ||
  106. sni_brd_type == SNI_BRD_PCI_TOWER_CPLUS) {
  107. if (memconf[i].base >= 0x20000000 &&
  108. memconf[i].base < 0x30000000) {
  109. memconf[i].base -= 0x20000000;
  110. }
  111. }
  112. DBG_PRINTF("Bank%d: %08x @ %08x\n", i,
  113. memconf[i].size, memconf[i].base);
  114. add_memory_region(memconf[i].base, memconf[i].size, BOOT_MEM_RAM);
  115. }
  116. }
  117. static void __init sni_console_setup(void)
  118. {
  119. char *ctype;
  120. char *cdev;
  121. char *baud;
  122. int port;
  123. static char options[8];
  124. cdev = prom_getenv ("console_dev");
  125. if (strncmp (cdev, "tty", 3) == 0) {
  126. ctype = prom_getenv ("console");
  127. switch (*ctype) {
  128. default:
  129. case 'l':
  130. port = 0;
  131. baud = prom_getenv("lbaud");
  132. break;
  133. case 'r':
  134. port = 1;
  135. baud = prom_getenv("rbaud");
  136. break;
  137. }
  138. if (baud)
  139. strcpy(options, baud);
  140. add_preferred_console("ttyS", port, baud ? options : NULL);
  141. }
  142. }
  143. void __init prom_init(void)
  144. {
  145. int argc = fw_arg0;
  146. char **argv = (void *)fw_arg1;
  147. int i;
  148. int cputype;
  149. sni_brd_type = *(unsigned char *)SNI_IDPROM_BRDTYPE;
  150. cputype = *(unsigned char *)SNI_IDPROM_CPUTYPE;
  151. switch (sni_brd_type) {
  152. case SNI_BRD_TOWER_OASIC:
  153. switch (cputype) {
  154. case SNI_CPU_M8030:
  155. systype = "RM400-330";
  156. break;
  157. case SNI_CPU_M8031:
  158. systype = "RM400-430";
  159. break;
  160. case SNI_CPU_M8037:
  161. systype = "RM400-530";
  162. break;
  163. case SNI_CPU_M8034:
  164. systype = "RM400-730";
  165. break;
  166. default:
  167. systype = "RM400-xxx";
  168. break;
  169. }
  170. break;
  171. case SNI_BRD_MINITOWER:
  172. switch (cputype) {
  173. case SNI_CPU_M8021:
  174. case SNI_CPU_M8043:
  175. systype = "RM400-120";
  176. break;
  177. case SNI_CPU_M8040:
  178. systype = "RM400-220";
  179. break;
  180. case SNI_CPU_M8053:
  181. systype = "RM400-225";
  182. break;
  183. case SNI_CPU_M8050:
  184. systype = "RM400-420";
  185. break;
  186. default:
  187. systype = "RM400-xxx";
  188. break;
  189. }
  190. break;
  191. case SNI_BRD_PCI_TOWER:
  192. systype = "RM400-Cxx";
  193. break;
  194. case SNI_BRD_RM200:
  195. systype = "RM200-xxx";
  196. break;
  197. case SNI_BRD_PCI_MTOWER:
  198. systype = "RM300-Cxx";
  199. break;
  200. case SNI_BRD_PCI_DESKTOP:
  201. switch (read_c0_prid() & 0xff00) {
  202. case PRID_IMP_R4600:
  203. case PRID_IMP_R4700:
  204. systype = "RM200-C20";
  205. break;
  206. case PRID_IMP_R5000:
  207. systype = "RM200-C40";
  208. break;
  209. default:
  210. systype = "RM200-Cxx";
  211. break;
  212. }
  213. break;
  214. case SNI_BRD_PCI_TOWER_CPLUS:
  215. systype = "RM400-Exx";
  216. break;
  217. case SNI_BRD_PCI_MTOWER_CPLUS:
  218. systype = "RM300-Exx";
  219. break;
  220. }
  221. DBG_PRINTF("Found SNI brdtype %02x name %s\n", sni_brd_type,systype);
  222. #ifdef DEBUG
  223. sni_idprom_dump();
  224. #endif
  225. sni_mem_init();
  226. sni_console_setup();
  227. /* copy prom cmdline parameters to kernel cmdline */
  228. for (i = 1; i < argc; i++) {
  229. strcat(arcs_cmdline, argv[i]);
  230. if (i < (argc - 1))
  231. strcat(arcs_cmdline, " ");
  232. }
  233. }