]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/AArch64/AArch64PeiLibConstructor.c
ArmVirtPkg: replace all ArmLib resolutions with ArmBaseLib
[mirror_edk2.git] / ArmPkg / Library / ArmLib / AArch64 / AArch64PeiLibConstructor.c
CommitLineData
469e1e1e
AB
1#/* @file\r
2#\r
3# Copyright (c) 2016, Linaro Limited. All rights reserved.\r
4#\r
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13#*/\r
14\r
15#include <Base.h>\r
16\r
17#include <Library/ArmLib.h>\r
18#include <Library/CacheMaintenanceLib.h>\r
19#include <Library/DebugLib.h>\r
20\r
21//\r
22// This is a hack. We define a weak symbol with external linkage, which may or\r
23// may not be overridden by a non-weak alternative that is defined with a non\r
24// zero value in the object that contains the MMU routines. Since static\r
25// libraries are pulled in on a per-object basis, and since the MMU object will\r
26// only be pulled in if any of its other symbols are referenced by the client\r
27// module, we can use the value below to figure out whether the MMU routines are\r
28// in use by this module, and decide whether cache maintenance of the function\r
29// ArmReplaceLiveTranslationEntry () is required.\r
30//\r
31INT32 __attribute__((weak)) HaveMmuRoutines;\r
32\r
33EFI_STATUS\r
34EFIAPI\r
35AArch64LibConstructor (\r
36 IN EFI_PEI_FILE_HANDLE FileHandle,\r
37 IN CONST EFI_PEI_SERVICES **PeiServices\r
38 )\r
39{\r
40 extern UINT32 ArmReplaceLiveTranslationEntrySize;\r
41\r
42 EFI_FV_FILE_INFO FileInfo;\r
43 EFI_STATUS Status;\r
44\r
45 if (HaveMmuRoutines == 0) {\r
46 return RETURN_SUCCESS;\r
47 }\r
48\r
49 ASSERT (FileHandle != NULL);\r
50\r
51 Status = (*PeiServices)->FfsGetFileInfo (FileHandle, &FileInfo);\r
52 ASSERT_EFI_ERROR (Status);\r
53\r
54 //\r
55 // Some platforms do not cope very well with cache maintenance being\r
56 // performed on regions backed by NOR flash. Since the cache maintenance\r
57 // is unnecessary to begin with in that case, perform it only when not\r
58 // executing in place.\r
59 //\r
60 if ((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry &&\r
61 ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >=\r
62 (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize)) {\r
63 DEBUG ((EFI_D_INFO, "ArmLib: skipping cache maintence on XIP PEIM\n"));\r
64 } else {\r
65 DEBUG ((EFI_D_INFO, "ArmLib: performing cache maintence on shadowed PEIM\n"));\r
66 //\r
67 // The ArmReplaceLiveTranslationEntry () helper function may be invoked\r
68 // with the MMU off so we have to ensure that it gets cleaned to the PoC\r
69 //\r
70 WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry,\r
71 ArmReplaceLiveTranslationEntrySize);\r
72 }\r
73\r
74 return RETURN_SUCCESS;\r
75}\r