prom.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: jsun@mvista.com or jsun@junsun.net
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/config.h>
  11. #include <linux/init.h>
  12. #include <linux/mm.h>
  13. #include <linux/sched.h>
  14. #include <linux/bootmem.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/bootinfo.h>
  17. #include <asm/ddb5xxx/ddb5xxx.h>
  18. #include <asm/debug.h>
  19. const char *get_system_type(void)
  20. {
  21. switch (mips_machtype) {
  22. case MACH_NEC_DDB5074: return "NEC DDB Vrc-5074";
  23. case MACH_NEC_DDB5476: return "NEC DDB Vrc-5476";
  24. case MACH_NEC_DDB5477: return "NEC DDB Vrc-5477";
  25. case MACH_NEC_ROCKHOPPER: return "NEC Rockhopper";
  26. case MACH_NEC_ROCKHOPPERII: return "NEC RockhopperII";
  27. default: return "Unknown NEC board";
  28. }
  29. }
  30. #if defined(CONFIG_DDB5477)
  31. void ddb5477_runtime_detection(void);
  32. #endif
  33. /* [jsun@junsun.net] PMON passes arguments in C main() style */
  34. void __init prom_init(void)
  35. {
  36. int argc = fw_arg0;
  37. char **arg = (char**) fw_arg1;
  38. int i;
  39. /* if user passes kernel args, ignore the default one */
  40. if (argc > 1)
  41. arcs_cmdline[0] = '\0';
  42. /* arg[0] is "g", the rest is boot parameters */
  43. for (i = 1; i < argc; i++) {
  44. if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
  45. >= sizeof(arcs_cmdline))
  46. break;
  47. strcat(arcs_cmdline, arg[i]);
  48. strcat(arcs_cmdline, " ");
  49. }
  50. mips_machgroup = MACH_GROUP_NEC_DDB;
  51. #if defined(CONFIG_DDB5476)
  52. mips_machtype = MACH_NEC_DDB5476;
  53. add_memory_region(0, DDB_SDRAM_SIZE, BOOT_MEM_RAM);
  54. #elif defined(CONFIG_DDB5477)
  55. ddb5477_runtime_detection();
  56. add_memory_region(0, board_ram_size, BOOT_MEM_RAM);
  57. #endif
  58. }
  59. unsigned long __init prom_free_prom_memory(void)
  60. {
  61. return 0;
  62. }
  63. #if defined(CONFIG_DDB5477)
  64. #define DEFAULT_LCS1_BASE 0x19000000
  65. #define TESTVAL1 'K'
  66. #define TESTVAL2 'S'
  67. int board_ram_size;
  68. void ddb5477_runtime_detection(void)
  69. {
  70. volatile char *test_offset;
  71. char saved_test_byte;
  72. /* Determine if this is a DDB5477 board, or a BSB-VR0300
  73. base board. We can tell by checking for the location of
  74. the NVRAM. It lives at the beginning of LCS1 on the DDB5477,
  75. and the beginning of LCS1 on the BSB-VR0300 is flash memory.
  76. The first 2K of the NVRAM are reserved, so don't we'll poke
  77. around just after that.
  78. */
  79. /* We can only use the PCI bus to distinquish between
  80. the Rockhopper and RockhopperII backplanes and this must
  81. wait until ddb5477_board_init() in setup.c after the 5477
  82. is initialized. So, until then handle
  83. both Rockhopper and RockhopperII backplanes as Rockhopper 1
  84. */
  85. test_offset = (char *)KSEG1ADDR(DEFAULT_LCS1_BASE + 0x800);
  86. saved_test_byte = *test_offset;
  87. *test_offset = TESTVAL1;
  88. if (*test_offset != TESTVAL1) {
  89. /* We couldn't set our test value, so it must not be NVRAM,
  90. so it's a BSB_VR0300 */
  91. mips_machtype = MACH_NEC_ROCKHOPPER;
  92. } else {
  93. /* We may have gotten lucky, and the TESTVAL1 was already
  94. stored at the test location, so we must check a second
  95. test value */
  96. *test_offset = TESTVAL2;
  97. if (*test_offset != TESTVAL2) {
  98. /* OK, we couldn't set this value either, so it must
  99. definately be a BSB_VR0300 */
  100. mips_machtype = MACH_NEC_ROCKHOPPER;
  101. } else {
  102. /* We could change the value twice, so it must be
  103. NVRAM, so it's a DDB_VRC5477 */
  104. mips_machtype = MACH_NEC_DDB5477;
  105. }
  106. }
  107. /* Restore the original byte */
  108. *test_offset = saved_test_byte;
  109. /* before we know a better way, we will trust PMON for getting
  110. * RAM size
  111. */
  112. board_ram_size = 1 << (36 - (ddb_in32(DDB_SDRAM0) & 0xf));
  113. db_run(printk("DDB run-time detection : %s, %d MB RAM\n",
  114. mips_machtype == MACH_NEC_DDB5477 ?
  115. "DDB5477" : "Rockhopper",
  116. board_ram_size >> 20));
  117. /* we can't handle ram size > 128 MB */
  118. db_assert(board_ram_size <= (128 << 20));
  119. }
  120. #endif