uppermem.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Compute amount of lower and upper memory till the first hole. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/memory.h>
  20. #include <grub/mm.h>
  21. #include <grub/misc.h>
  22. #include <grub/cpu/memory.h>
  23. /* Helper for grub_mmap_get_lower. */
  24. static int
  25. lower_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
  26. void *data)
  27. {
  28. grub_uint64_t *lower = data;
  29. if (type != GRUB_MEMORY_AVAILABLE)
  30. return 0;
  31. if (addr == 0)
  32. *lower = size;
  33. return 0;
  34. }
  35. grub_uint64_t
  36. grub_mmap_get_lower (void)
  37. {
  38. grub_uint64_t lower = 0;
  39. grub_mmap_iterate (lower_hook, &lower);
  40. if (lower > GRUB_ARCH_LOWMEMMAXSIZE)
  41. lower = GRUB_ARCH_LOWMEMMAXSIZE;
  42. return lower;
  43. }
  44. /* Helper for grub_mmap_get_upper. */
  45. static int
  46. upper_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
  47. void *data)
  48. {
  49. grub_uint64_t *upper = data;
  50. if (type != GRUB_MEMORY_AVAILABLE)
  51. return 0;
  52. if (addr <= GRUB_ARCH_HIGHMEMPSTART && addr + size
  53. > GRUB_ARCH_HIGHMEMPSTART)
  54. *upper = addr + size - GRUB_ARCH_HIGHMEMPSTART;
  55. return 0;
  56. }
  57. grub_uint64_t
  58. grub_mmap_get_upper (void)
  59. {
  60. grub_uint64_t upper = 0;
  61. grub_mmap_iterate (upper_hook, &upper);
  62. return upper;
  63. }