]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c
ArmPkg/ArmMmuLib: support page tables in cacheable memory only
[mirror_edk2.git] / ArmPkg / Library / ArmMmuLib / AArch64 / ArmMmuPeiLibConstructor.c
1 #/* @file
2 #
3 # Copyright (c) 2016, Linaro Limited. All rights reserved.
4 #
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
9 #
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.
12 #
13 #*/
14
15 #include <Base.h>
16
17 #include <Library/ArmLib.h>
18 #include <Library/ArmMmuLib.h>
19 #include <Library/CacheMaintenanceLib.h>
20 #include <Library/DebugLib.h>
21
22 EFI_STATUS
23 EFIAPI
24 ArmMmuPeiLibConstructor (
25 IN EFI_PEI_FILE_HANDLE FileHandle,
26 IN CONST EFI_PEI_SERVICES **PeiServices
27 )
28 {
29 extern UINT32 ArmReplaceLiveTranslationEntrySize;
30
31 EFI_FV_FILE_INFO FileInfo;
32 EFI_STATUS Status;
33
34 ASSERT (FileHandle != NULL);
35
36 Status = (*PeiServices)->FfsGetFileInfo (FileHandle, &FileInfo);
37 ASSERT_EFI_ERROR (Status);
38
39 //
40 // Some platforms do not cope very well with cache maintenance being
41 // performed on regions backed by NOR flash. Since the firmware image
42 // can be assumed to be clean to the PoC when running XIP, even when PEI
43 // is executing from DRAM, we only need to perform the cache maintenance
44 // when not executing in place.
45 //
46 if ((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry &&
47 ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >=
48 (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize)) {
49 DEBUG ((EFI_D_INFO, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n"));
50 } else {
51 DEBUG ((EFI_D_INFO, "ArmMmuLib: performing cache maintenance on shadowed PEIM\n"));
52 //
53 // The ArmReplaceLiveTranslationEntry () helper function may be invoked
54 // with the MMU off so we have to ensure that it gets cleaned to the PoC
55 //
56 WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry,
57 ArmReplaceLiveTranslationEntrySize);
58 }
59
60 return RETURN_SUCCESS;
61 }