3 * Copyright (c) 2014, Linaro Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/ArmPlatformLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <ArmPlatform.h>
23 // Number of Virtual Memory Map Descriptors
24 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 2
27 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
28 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
36 Return the Virtual Memory Map of your platform
38 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
41 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
42 describing a Physical-to-Virtual Memory
43 mapping. This array must be ended by a
48 ArmPlatformGetVirtualMemoryMap (
49 IN ARM_MEMORY_REGION_DESCRIPTOR
** VirtualMemoryMap
52 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
54 ASSERT (VirtualMemoryMap
!= NULL
);
56 VirtualMemoryTable
= AllocatePages (
58 sizeof (ARM_MEMORY_REGION_DESCRIPTOR
)
59 * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
63 if (VirtualMemoryTable
== NULL
) {
64 DEBUG ((EFI_D_ERROR
, "%a: Error: Failed AllocatePages()\n", __FUNCTION__
));
69 // Map the entire physical memory space as cached. The only device
70 // we care about is the GIC, which will be stage 2 mapped as a device
71 // by the hypervisor, which will override the cached mapping we install
74 VirtualMemoryTable
[0].PhysicalBase
= 0x0;
75 VirtualMemoryTable
[0].VirtualBase
= 0x0;
76 VirtualMemoryTable
[0].Length
= ArmGetPhysAddrTop ();
77 VirtualMemoryTable
[0].Attributes
= DDR_ATTRIBUTES_CACHED
;
80 ZeroMem (&VirtualMemoryTable
[1], sizeof (ARM_MEMORY_REGION_DESCRIPTOR
));
82 *VirtualMemoryMap
= VirtualMemoryTable
;