QemuVirtMemInfoLib.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /** @file
  2. Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include <Base.h>
  6. #include <Library/ArmLib.h>
  7. #include <Library/BaseMemoryLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/MemoryAllocationLib.h>
  10. // Number of Virtual Memory Map Descriptors
  11. #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
  12. //
  13. // mach-virt's core peripherals such as the UART, the GIC and the RTC are
  14. // all mapped in the 'miscellaneous device I/O' region, which we just map
  15. // in its entirety rather than device by device. Note that it does not
  16. // cover any of the NOR flash banks or PCI resource windows.
  17. //
  18. #define MACH_VIRT_PERIPH_BASE 0x08000000
  19. #define MACH_VIRT_PERIPH_SIZE SIZE_128MB
  20. /**
  21. Return the Virtual Memory Map of your platform
  22. This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
  23. on your platform.
  24. @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
  25. describing a Physical-to-Virtual Memory
  26. mapping. This array must be ended by a
  27. zero-filled entry. The allocated memory
  28. will not be freed.
  29. **/
  30. VOID
  31. ArmVirtGetMemoryMap (
  32. OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
  33. )
  34. {
  35. ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
  36. ASSERT (VirtualMemoryMap != NULL);
  37. VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
  38. MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
  39. if (VirtualMemoryTable == NULL) {
  40. DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
  41. return;
  42. }
  43. // System DRAM
  44. VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
  45. VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
  46. VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);
  47. VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
  48. DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"
  49. "\tPhysicalBase: 0x%lX\n"
  50. "\tVirtualBase: 0x%lX\n"
  51. "\tLength: 0x%lX\n",
  52. __FUNCTION__,
  53. VirtualMemoryTable[0].PhysicalBase,
  54. VirtualMemoryTable[0].VirtualBase,
  55. VirtualMemoryTable[0].Length));
  56. // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
  57. VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE;
  58. VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE;
  59. VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE;
  60. VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
  61. // Map the FV region as normal executable memory
  62. VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
  63. VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
  64. VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize);
  65. VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
  66. // End of Table
  67. ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
  68. *VirtualMemoryMap = VirtualMemoryTable;
  69. }