3 Copyright (c) 2016, Linaro Limited. All rights reserved.
4 Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/ArmLib.h>
12 #include <Library/ArmMmuLib.h>
13 #include <Library/CacheMaintenanceLib.h>
14 #include <Library/DebugLib.h>
18 ArmMmuPeiLibConstructor (
19 IN EFI_PEI_FILE_HANDLE FileHandle
,
20 IN CONST EFI_PEI_SERVICES
**PeiServices
23 extern UINT32 ArmReplaceLiveTranslationEntrySize
;
25 EFI_FV_FILE_INFO FileInfo
;
28 ASSERT (FileHandle
!= NULL
);
30 Status
= (*PeiServices
)->FfsGetFileInfo (FileHandle
, &FileInfo
);
31 ASSERT_EFI_ERROR (Status
);
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.
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"));
45 DEBUG ((EFI_D_INFO
, "ArmMmuLib: performing cache maintenance on shadowed PEIM\n"));
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
50 WriteBackDataCacheRange ((VOID
*)(UINTN
)ArmReplaceLiveTranslationEntry
,
51 ArmReplaceLiveTranslationEntrySize
);
54 return RETURN_SUCCESS
;