e820_64.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. static void early_panic(char *msg)
  41. {
  42. early_printk(msg);
  43. panic(msg);
  44. }
  45. /* We're not void only for x86 32-bit compat */
  46. char *__init machine_specific_memory_setup(void)
  47. {
  48. char *who = "BIOS-e820";
  49. int new_nr;
  50. /*
  51. * Try to copy the BIOS-supplied E820-map.
  52. *
  53. * Otherwise fake a memory map; one section from 0k->640k,
  54. * the next section from 1mb->appropriate_mem_k
  55. */
  56. new_nr = boot_params.e820_entries;
  57. sanitize_e820_map(boot_params.e820_map,
  58. ARRAY_SIZE(boot_params.e820_map),
  59. &new_nr);
  60. boot_params.e820_entries = new_nr;
  61. if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries) < 0)
  62. early_panic("Cannot find a valid memory map");
  63. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  64. e820_print_map(who);
  65. /* In case someone cares... */
  66. return who;
  67. }
  68. int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
  69. {
  70. int i;
  71. if (slot < 0 || slot >= e820.nr_map)
  72. return -1;
  73. for (i = slot; i < e820.nr_map; i++) {
  74. if (e820.map[i].type != E820_RAM)
  75. continue;
  76. break;
  77. }
  78. if (i == e820.nr_map || e820.map[i].addr > (max_pfn << PAGE_SHIFT))
  79. return -1;
  80. *addr = e820.map[i].addr;
  81. *size = min_t(u64, e820.map[i].size + e820.map[i].addr,
  82. max_pfn << PAGE_SHIFT) - *addr;
  83. return i + 1;
  84. }