memmap.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. memmap.c
  5. Abstract:
  6. This module implements support for returning the initial memory map on the
  7. TI PandaBoard.
  8. Author:
  9. Evan Green 27-Feb-2014
  10. Environment:
  11. Firmware
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <uefifw.h>
  17. #include "integfw.h"
  18. //
  19. // ---------------------------------------------------------------- Definitions
  20. //
  21. #define INTEGRATOR_MEMORY_MAP_SIZE \
  22. (sizeof(EfiIntegratorMemoryMap) / sizeof(EfiIntegratorMemoryMap[0]))
  23. #define INTEGRATOR_SDRAM_REGISTER (INTEGRATOR_CM_BASE + 0x20)
  24. #define INTEGRATOR_SDRAM_MASK 0x1C
  25. #define INTEGRATOR_SDRAM_32M 0x04
  26. #define INTEGRATOR_SDRAM_64M 0x08
  27. #define INTEGRATOR_SDRAM_128M 0x0C
  28. #define INTEGRATOR_SDRAM_256M 0x10
  29. //
  30. // ------------------------------------------------------ Data Type Definitions
  31. //
  32. //
  33. // ----------------------------------------------- Internal Function Prototypes
  34. //
  35. //
  36. // -------------------------------------------------------------------- Globals
  37. //
  38. //
  39. // Define the initial memory map.
  40. //
  41. EFI_MEMORY_DESCRIPTOR EfiIntegratorMemoryMap[] = {
  42. {
  43. EfiConventionalMemory,
  44. 0,
  45. INTEGRATOR_RAM_START,
  46. 0,
  47. INTEGRATOR_RAM_SIZE / EFI_PAGE_SIZE,
  48. 0
  49. },
  50. {
  51. EfiRuntimeServicesData,
  52. 0,
  53. INTEGRATOR_CM_BASE,
  54. 0,
  55. EFI_SIZE_TO_PAGES(INTEGRATOR_CM_SIZE),
  56. EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
  57. },
  58. {
  59. EfiRuntimeServicesData,
  60. 0,
  61. INTEGRATOR_PL031_RTC_BASE,
  62. 0,
  63. EFI_SIZE_TO_PAGES(INTEGRATOR_PL031_RTC_SIZE),
  64. EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
  65. },
  66. };
  67. //
  68. // ------------------------------------------------------------------ Functions
  69. //
  70. EFI_STATUS
  71. EfiPlatformGetInitialMemoryMap (
  72. EFI_MEMORY_DESCRIPTOR **Map,
  73. UINTN *MapSize
  74. )
  75. /*++
  76. Routine Description:
  77. This routine returns the initial platform memory map to the EFI core. The
  78. core maintains this memory map. The memory map returned does not need to
  79. take into account the firmware image itself or stack, the EFI core will
  80. reserve those regions automatically.
  81. Arguments:
  82. Map - Supplies a pointer where the array of memory descriptors constituting
  83. the initial memory map is returned on success. The EFI core will make
  84. a copy of these descriptors, so they can be in read-only or
  85. temporary memory.
  86. MapSize - Supplies a pointer where the number of elements in the initial
  87. memory map will be returned on success.
  88. Return Value:
  89. EFI status code.
  90. --*/
  91. {
  92. UINT32 Megabyte;
  93. UINT32 SdRamRegister;
  94. SdRamRegister = EfiReadRegister32((VOID *)INTEGRATOR_SDRAM_REGISTER);
  95. Megabyte = (1024 * 1024) / EFI_PAGE_SIZE;
  96. switch (SdRamRegister & INTEGRATOR_SDRAM_MASK) {
  97. case INTEGRATOR_SDRAM_32M:
  98. EfiIntegratorMemoryMap[0].NumberOfPages = 32 * Megabyte;
  99. break;
  100. case INTEGRATOR_SDRAM_64M:
  101. EfiIntegratorMemoryMap[0].NumberOfPages = 64 * Megabyte;
  102. break;
  103. case INTEGRATOR_SDRAM_128M:
  104. EfiIntegratorMemoryMap[0].NumberOfPages = 128 * Megabyte;
  105. break;
  106. case INTEGRATOR_SDRAM_256M:
  107. EfiIntegratorMemoryMap[0].NumberOfPages = 256 * Megabyte;
  108. break;
  109. default:
  110. break;
  111. }
  112. *Map = EfiIntegratorMemoryMap;
  113. *MapSize = INTEGRATOR_MEMORY_MAP_SIZE;
  114. return EFI_SUCCESS;
  115. }
  116. //
  117. // --------------------------------------------------------- Internal Functions
  118. //