memory.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * memory.c: PROM library functions for acquiring/using memory descriptors
  3. * given to us from the ARCS firmware.
  4. *
  5. * Copyright (C) 1996 by David S. Miller
  6. * Copyright (C) 1999, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 1999, 2000 by Silicon Graphics, Inc.
  8. *
  9. * PROM library functions for acquiring/using memory descriptors given to us
  10. * from the ARCS firmware. This is only used when CONFIG_ARC_MEMORY is set
  11. * because on some machines like SGI IP27 the ARC memory configuration data
  12. * completly bogus and alternate easier to use mechanisms are available.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/sched.h>
  18. #include <linux/mm.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/swap.h>
  21. #include <asm/sgialib.h>
  22. #include <asm/page.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/bootinfo.h>
  25. #undef DEBUG
  26. /*
  27. * For ARC firmware memory functions the unit of meassuring memory is always
  28. * a 4k page of memory
  29. */
  30. #define ARC_PAGE_SHIFT 12
  31. struct linux_mdesc * __init ArcGetMemoryDescriptor(struct linux_mdesc *Current)
  32. {
  33. return (struct linux_mdesc *) ARC_CALL1(get_mdesc, Current);
  34. }
  35. #ifdef DEBUG /* convenient for debugging */
  36. static char *arcs_mtypes[8] = {
  37. "Exception Block",
  38. "ARCS Romvec Page",
  39. "Free/Contig RAM",
  40. "Generic Free RAM",
  41. "Bad Memory",
  42. "Standalone Program Pages",
  43. "ARCS Temp Storage Area",
  44. "ARCS Permanent Storage Area"
  45. };
  46. static char *arc_mtypes[8] = {
  47. "Exception Block",
  48. "SystemParameterBlock",
  49. "FreeMemory",
  50. "Bad Memory",
  51. "LoadedProgram",
  52. "FirmwareTemporary",
  53. "FirmwarePermanent",
  54. "FreeContiguous"
  55. };
  56. #define mtypes(a) (prom_flags & PROM_FLAG_ARCS) ? arcs_mtypes[a.arcs] \
  57. : arc_mtypes[a.arc]
  58. #endif
  59. static inline int memtype_classify_arcs(union linux_memtypes type)
  60. {
  61. switch (type.arcs) {
  62. case arcs_fcontig:
  63. case arcs_free:
  64. return BOOT_MEM_RAM;
  65. case arcs_atmp:
  66. return BOOT_MEM_ROM_DATA;
  67. case arcs_eblock:
  68. case arcs_rvpage:
  69. case arcs_bmem:
  70. case arcs_prog:
  71. case arcs_aperm:
  72. return BOOT_MEM_RESERVED;
  73. default:
  74. BUG();
  75. }
  76. while(1); /* Nuke warning. */
  77. }
  78. static inline int memtype_classify_arc(union linux_memtypes type)
  79. {
  80. switch (type.arc) {
  81. case arc_free:
  82. case arc_fcontig:
  83. return BOOT_MEM_RAM;
  84. case arc_atmp:
  85. return BOOT_MEM_ROM_DATA;
  86. case arc_eblock:
  87. case arc_rvpage:
  88. case arc_bmem:
  89. case arc_prog:
  90. case arc_aperm:
  91. return BOOT_MEM_RESERVED;
  92. default:
  93. BUG();
  94. }
  95. while(1); /* Nuke warning. */
  96. }
  97. static int __init prom_memtype_classify(union linux_memtypes type)
  98. {
  99. if (prom_flags & PROM_FLAG_ARCS) /* SGI is ``different'' ... */
  100. return memtype_classify_arcs(type);
  101. return memtype_classify_arc(type);
  102. }
  103. void __init prom_meminit(void)
  104. {
  105. struct linux_mdesc *p;
  106. #ifdef DEBUG
  107. int i = 0;
  108. printk("ARCS MEMORY DESCRIPTOR dump:\n");
  109. p = ArcGetMemoryDescriptor(PROM_NULL_MDESC);
  110. while(p) {
  111. printk("[%d,%p]: base<%08lx> pages<%08lx> type<%s>\n",
  112. i, p, p->base, p->pages, mtypes(p->type));
  113. p = ArcGetMemoryDescriptor(p);
  114. i++;
  115. }
  116. #endif
  117. p = PROM_NULL_MDESC;
  118. while ((p = ArcGetMemoryDescriptor(p))) {
  119. unsigned long base, size;
  120. long type;
  121. base = p->base << ARC_PAGE_SHIFT;
  122. size = p->pages << ARC_PAGE_SHIFT;
  123. type = prom_memtype_classify(p->type);
  124. add_memory_region(base, size, type);
  125. }
  126. }
  127. void __init prom_free_prom_memory(void)
  128. {
  129. unsigned long addr;
  130. int i;
  131. if (prom_flags & PROM_FLAG_DONT_FREE_TEMP)
  132. return;
  133. for (i = 0; i < boot_mem_map.nr_map; i++) {
  134. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  135. continue;
  136. addr = boot_mem_map.map[i].addr;
  137. free_init_pages("prom memory",
  138. addr, addr + boot_mem_map.map[i].size);
  139. }
  140. }