3 # Copyright (c) 2016, 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.
17 #include <Library/ArmLib.h>
18 #include <Library/ArmMmuLib.h>
19 #include <Library/CacheMaintenanceLib.h>
20 #include <Library/DebugLib.h>
24 ArmMmuPeiLibConstructor (
25 IN EFI_PEI_FILE_HANDLE FileHandle
,
26 IN CONST EFI_PEI_SERVICES
**PeiServices
29 extern UINT32 ArmReplaceLiveTranslationEntrySize
;
31 EFI_FV_FILE_INFO FileInfo
;
34 ASSERT (FileHandle
!= NULL
);
36 Status
= (*PeiServices
)->FfsGetFileInfo (FileHandle
, &FileInfo
);
37 ASSERT_EFI_ERROR (Status
);
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.
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"));
51 DEBUG ((EFI_D_INFO
, "ArmMmuLib: performing cache maintenance on shadowed PEIM\n"));
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
56 WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry
,
57 ArmReplaceLiveTranslationEntrySize
);
60 return RETURN_SUCCESS
;