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