prom.c 3.9 KB

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