]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c
8ce63b4596e2c08148116031e48729ebf219fb5e
[mirror_edk2.git] / ArmPlatformPkg / ArmVirtualizationPkg / Library / ArmVirtualizationMemoryInitPeiLib / ArmVirtualizationMemoryInitPeiLib.c
1 /** @file
2 *
3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 * Copyright (c) 2014, Linaro Limited. All rights reserved.
5 *
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
10 *
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 *
14 **/
15
16 #include <PiPei.h>
17
18 #include <Library/ArmPlatformLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/CacheMaintenanceLib.h>
24
25 VOID
26 BuildMemoryTypeInformationHob (
27 VOID
28 );
29
30 VOID
31 InitMmu (
32 VOID
33 )
34 {
35 ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
36 VOID *TranslationTableBase;
37 UINTN TranslationTableSize;
38 RETURN_STATUS Status;
39
40 // Get Virtual Memory Map from the Platform Library
41 ArmPlatformGetVirtualMemoryMap (&MemoryTable);
42
43 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
44 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
45 Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
46 if (EFI_ERROR (Status)) {
47 DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));
48 }
49 }
50
51 EFI_STATUS
52 EFIAPI
53 MemoryPeim (
54 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,
55 IN UINT64 UefiMemorySize
56 )
57 {
58 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
59
60 // Ensure PcdSystemMemorySize has been set
61 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
62
63 //
64 // Now, the permanent memory has been installed, we can call AllocatePages()
65 //
66 ResourceAttributes = (
67 EFI_RESOURCE_ATTRIBUTE_PRESENT |
68 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
69 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
70 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
71 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
72 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
73 EFI_RESOURCE_ATTRIBUTE_TESTED
74 );
75
76 BuildResourceDescriptorHob (
77 EFI_RESOURCE_SYSTEM_MEMORY,
78 ResourceAttributes,
79 PcdGet64 (PcdSystemMemoryBase),
80 PcdGet64 (PcdSystemMemorySize)
81 );
82
83 //
84 // When running under virtualization, the PI/UEFI memory region may be
85 // clean but not invalidated in system caches or in lower level caches
86 // on other CPUs. So invalidate the region by virtual address, to ensure
87 // that the contents we put there with the caches and MMU off will still
88 // be visible after turning them on.
89 //
90 InvalidateDataCacheRange ((VOID*)(UINTN)UefiMemoryBase, UefiMemorySize);
91
92 // Build Memory Allocation Hob
93 InitMmu ();
94
95 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
96 // Optional feature that helps prevent EFI memory map fragmentation.
97 BuildMemoryTypeInformationHob ();
98 }
99
100 return EFI_SUCCESS;
101 }