e820_64.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Handle the memory map.
  3. * The functions here do the job until bootmem takes over.
  4. *
  5. * Getting sanitize_e820_map() in sync with i386 version by applying change:
  6. * - Provisions for empty E820 memory regions (reported by certain BIOSes).
  7. * Alex Achenbach <xela@slit.de>, December 2002.
  8. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/ioport.h>
  16. #include <linux/string.h>
  17. #include <linux/kexec.h>
  18. #include <linux/module.h>
  19. #include <linux/mm.h>
  20. #include <linux/pfn.h>
  21. #include <linux/pci.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/page.h>
  24. #include <asm/e820.h>
  25. #include <asm/proto.h>
  26. #include <asm/setup.h>
  27. #include <asm/sections.h>
  28. #include <asm/kdebug.h>
  29. #include <asm/trampoline.h>
  30. /*
  31. * PFN of last memory page.
  32. */
  33. unsigned long end_pfn;
  34. /*
  35. * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
  36. * The direct mapping extends to max_pfn_mapped, so that we can directly access
  37. * apertures, ACPI and other tables without having to play with fixmaps.
  38. */
  39. unsigned long max_pfn_mapped;
  40. /*
  41. * Mark e820 reserved areas as busy for the resource manager.
  42. */
  43. void __init e820_reserve_resources(void)
  44. {
  45. int i;
  46. struct resource *res;
  47. res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
  48. for (i = 0; i < e820.nr_map; i++) {
  49. switch (e820.map[i].type) {
  50. case E820_RAM: res->name = "System RAM"; break;
  51. case E820_ACPI: res->name = "ACPI Tables"; break;
  52. case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
  53. default: res->name = "reserved";
  54. }
  55. res->start = e820.map[i].addr;
  56. res->end = res->start + e820.map[i].size - 1;
  57. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  58. insert_resource(&iomem_resource, res);
  59. res++;
  60. }
  61. }
  62. static void early_panic(char *msg)
  63. {
  64. early_printk(msg);
  65. panic(msg);
  66. }
  67. /* We're not void only for x86 32-bit compat */
  68. char *__init machine_specific_memory_setup(void)
  69. {
  70. char *who = "BIOS-e820";
  71. int new_nr;
  72. /*
  73. * Try to copy the BIOS-supplied E820-map.
  74. *
  75. * Otherwise fake a memory map; one section from 0k->640k,
  76. * the next section from 1mb->appropriate_mem_k
  77. */
  78. new_nr = boot_params.e820_entries;
  79. sanitize_e820_map(boot_params.e820_map,
  80. ARRAY_SIZE(boot_params.e820_map),
  81. &new_nr);
  82. boot_params.e820_entries = new_nr;
  83. if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries) < 0)
  84. early_panic("Cannot find a valid memory map");
  85. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  86. e820_print_map(who);
  87. /* In case someone cares... */
  88. return who;
  89. }
  90. static int __init parse_memopt(char *p)
  91. {
  92. if (!p)
  93. return -EINVAL;
  94. end_user_pfn = memparse(p, &p);
  95. end_user_pfn >>= PAGE_SHIFT;
  96. return 0;
  97. }
  98. early_param("mem", parse_memopt);
  99. static int userdef __initdata;
  100. static int __init parse_memmap_opt(char *p)
  101. {
  102. char *oldp;
  103. unsigned long long start_at, mem_size;
  104. if (!strcmp(p, "exactmap")) {
  105. #ifdef CONFIG_CRASH_DUMP
  106. /*
  107. * If we are doing a crash dump, we still need to know
  108. * the real mem size before original memory map is
  109. * reset.
  110. */
  111. e820_register_active_regions(0, 0, -1UL);
  112. saved_max_pfn = e820_end_of_ram();
  113. remove_all_active_ranges();
  114. #endif
  115. e820.nr_map = 0;
  116. userdef = 1;
  117. return 0;
  118. }
  119. oldp = p;
  120. mem_size = memparse(p, &p);
  121. if (p == oldp)
  122. return -EINVAL;
  123. userdef = 1;
  124. if (*p == '@') {
  125. start_at = memparse(p+1, &p);
  126. add_memory_region(start_at, mem_size, E820_RAM);
  127. } else if (*p == '#') {
  128. start_at = memparse(p+1, &p);
  129. add_memory_region(start_at, mem_size, E820_ACPI);
  130. } else if (*p == '$') {
  131. start_at = memparse(p+1, &p);
  132. add_memory_region(start_at, mem_size, E820_RESERVED);
  133. } else {
  134. end_user_pfn = (mem_size >> PAGE_SHIFT);
  135. }
  136. return *p == '\0' ? 0 : -EINVAL;
  137. }
  138. early_param("memmap", parse_memmap_opt);
  139. void __init finish_e820_parsing(void)
  140. {
  141. if (userdef) {
  142. int nr = e820.nr_map;
  143. if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
  144. early_panic("Invalid user supplied memory map");
  145. e820.nr_map = nr;
  146. printk(KERN_INFO "user-defined physical RAM map:\n");
  147. e820_print_map("user");
  148. }
  149. }
  150. int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
  151. {
  152. int i;
  153. if (slot < 0 || slot >= e820.nr_map)
  154. return -1;
  155. for (i = slot; i < e820.nr_map; i++) {
  156. if (e820.map[i].type != E820_RAM)
  157. continue;
  158. break;
  159. }
  160. if (i == e820.nr_map || e820.map[i].addr > (max_pfn << PAGE_SHIFT))
  161. return -1;
  162. *addr = e820.map[i].addr;
  163. *size = min_t(u64, e820.map[i].size + e820.map[i].addr,
  164. max_pfn << PAGE_SHIFT) - *addr;
  165. return i + 1;
  166. }