memory.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * memory.c: memory initialisation code.
  3. *
  4. * Copyright (C) 1998 Harald Koerfgen, Frieder Streffer and Paul M. Antoine
  5. * Copyright (C) 2000, 2002 Maciej W. Rozycki
  6. */
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mm.h>
  10. #include <linux/bootmem.h>
  11. #include <linux/types.h>
  12. #include <asm/addrspace.h>
  13. #include <asm/bootinfo.h>
  14. #include <asm/dec/machtype.h>
  15. #include <asm/dec/prom.h>
  16. #include <asm/page.h>
  17. #include <asm/sections.h>
  18. volatile unsigned long mem_err; /* So we know an error occurred */
  19. /*
  20. * Probe memory in 4MB chunks, waiting for an error to tell us we've fallen
  21. * off the end of real memory. Only suitable for the 2100/3100's (PMAX).
  22. */
  23. #define CHUNK_SIZE 0x400000
  24. static inline void pmax_setup_memory_region(void)
  25. {
  26. volatile unsigned char *memory_page, dummy;
  27. char old_handler[0x80];
  28. extern char genexcept_early;
  29. /* Install exception handler */
  30. memcpy(&old_handler, (void *)(CKSEG0 + 0x80), 0x80);
  31. memcpy((void *)(CKSEG0 + 0x80), &genexcept_early, 0x80);
  32. /* read unmapped and uncached (KSEG1)
  33. * DECstations have at least 4MB RAM
  34. * Assume less than 480MB of RAM, as this is max for 5000/2xx
  35. * FIXME this should be replaced by the first free page!
  36. */
  37. for (memory_page = (unsigned char *)CKSEG1 + CHUNK_SIZE;
  38. mem_err == 0 && memory_page < (unsigned char *)CKSEG1 + 0x1e00000;
  39. memory_page += CHUNK_SIZE) {
  40. dummy = *memory_page;
  41. }
  42. memcpy((void *)(CKSEG0 + 0x80), &old_handler, 0x80);
  43. add_memory_region(0, (unsigned long)memory_page - CKSEG1 - CHUNK_SIZE,
  44. BOOT_MEM_RAM);
  45. }
  46. /*
  47. * Use the REX prom calls to get hold of the memory bitmap, and thence
  48. * determine memory size.
  49. */
  50. static inline void rex_setup_memory_region(void)
  51. {
  52. int i, bitmap_size;
  53. unsigned long mem_start = 0, mem_size = 0;
  54. memmap *bm;
  55. /* some free 64k */
  56. bm = (memmap *)CKSEG0ADDR(0x28000);
  57. bitmap_size = rex_getbitmap(bm);
  58. for (i = 0; i < bitmap_size; i++) {
  59. /* FIXME: very simplistically only add full sets of pages */
  60. if (bm->bitmap[i] == 0xff)
  61. mem_size += (8 * bm->pagesize);
  62. else if (!mem_size)
  63. mem_start += (8 * bm->pagesize);
  64. else {
  65. add_memory_region(mem_start, mem_size, BOOT_MEM_RAM);
  66. mem_start += mem_size + (8 * bm->pagesize);
  67. mem_size = 0;
  68. }
  69. }
  70. if (mem_size)
  71. add_memory_region(mem_start, mem_size, BOOT_MEM_RAM);
  72. }
  73. void __init prom_meminit(u32 magic)
  74. {
  75. if (!prom_is_rex(magic))
  76. pmax_setup_memory_region();
  77. else
  78. rex_setup_memory_region();
  79. }
  80. void __init prom_free_prom_memory(void)
  81. {
  82. unsigned long end;
  83. /*
  84. * Free everything below the kernel itself but leave
  85. * the first page reserved for the exception handlers.
  86. */
  87. #if IS_ENABLED(CONFIG_DECLANCE)
  88. /*
  89. * Leave 128 KB reserved for Lance memory for
  90. * IOASIC DECstations.
  91. *
  92. * XXX: save this address for use in dec_lance.c?
  93. */
  94. if (IOASIC)
  95. end = __pa(&_text) - 0x00020000;
  96. else
  97. #endif
  98. end = __pa(&_text);
  99. free_init_pages("unused PROM memory", PAGE_SIZE, end);
  100. }