]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/PlatformPei/ClearCache.c
ArmPkg/OpteeLib: Add dummy RPC handler
[mirror_edk2.git] / OvmfPkg / PlatformPei / ClearCache.c
CommitLineData
d20ae95a
MAL
1/**@file\r
2 Install a callback to clear cache on all processors.\r
3 This is for conformance with the TCG "Platform Reset Attack Mitigation\r
4 Specification". Because clearing the CPU caches at boot doesn't impact\r
5 performance significantly, do it unconditionally, for simplicity's\r
6 sake.\r
7\r
8 Copyright (C) 2018, Red Hat, Inc.\r
9\r
10 This program and the accompanying materials are licensed and made available\r
11 under the terms and conditions of the BSD License which accompanies this\r
12 distribution. The full text of the license may be found at\r
13 http://opensource.org/licenses/bsd-license.php\r
14\r
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
16 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17**/\r
18\r
19#include <Library/CacheMaintenanceLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Ppi/MpServices.h>\r
23\r
24#include "Platform.h"\r
25\r
26/**\r
27 Invalidate data & instruction caches.\r
28 All APs execute this function in parallel. The BSP executes the function\r
29 separately.\r
30\r
31 @param[in,out] WorkSpace Pointer to the input/output argument workspace\r
32 shared by all processors.\r
33**/\r
34STATIC\r
35VOID\r
36EFIAPI\r
37ClearCache (\r
38 IN OUT VOID *WorkSpace\r
39 )\r
40{\r
41 WriteBackInvalidateDataCache ();\r
42 InvalidateInstructionCache ();\r
43}\r
44\r
45/**\r
46 Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available.\r
47\r
48 @param[in] PeiServices Indirect reference to the PEI Services Table.\r
49 @param[in] NotifyDescriptor Address of the notification descriptor data\r
50 structure.\r
51 @param[in] Ppi Address of the PPI that was installed.\r
52\r
53 @return Status of the notification. The status code returned from this\r
54 function is ignored.\r
55**/\r
56STATIC\r
57EFI_STATUS\r
58EFIAPI\r
59ClearCacheOnMpServicesAvailable (\r
60 IN EFI_PEI_SERVICES **PeiServices,\r
61 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
62 IN VOID *Ppi\r
63 )\r
64{\r
65 EFI_PEI_MP_SERVICES_PPI *MpServices;\r
66 EFI_STATUS Status;\r
67\r
68 DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));\r
69\r
70 //\r
71 // Clear cache on all the APs in parallel.\r
72 //\r
73 MpServices = Ppi;\r
74 Status = MpServices->StartupAllAPs (\r
75 (CONST EFI_PEI_SERVICES **)PeiServices,\r
76 MpServices,\r
77 ClearCache, // Procedure\r
78 FALSE, // SingleThread\r
79 0, // TimeoutInMicroSeconds: inf.\r
80 NULL // ProcedureArgument\r
81 );\r
82 if (EFI_ERROR (Status) && Status != EFI_NOT_STARTED) {\r
83 DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));\r
84 return Status;\r
85 }\r
86\r
87 //\r
88 // Now clear cache on the BSP too.\r
89 //\r
90 ClearCache (NULL);\r
91 return EFI_SUCCESS;\r
92}\r
93\r
94//\r
95// Notification object for registering the callback, for when\r
96// EFI_PEI_MP_SERVICES_PPI becomes available.\r
97//\r
98STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify = {\r
99 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags\r
100 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
101 &gEfiPeiMpServicesPpiGuid, // Guid\r
102 ClearCacheOnMpServicesAvailable // Notify\r
103};\r
104\r
105VOID\r
106InstallClearCacheCallback (\r
107 VOID\r
108 )\r
109{\r
110 EFI_STATUS Status;\r
111\r
112 Status = PeiServicesNotifyPpi (&mMpServicesNotify);\r
113 if (EFI_ERROR (Status)) {\r
114 DEBUG ((DEBUG_ERROR, "%a: failed to set up MP Services callback: %r\n",\r
115 __FUNCTION__, Status));\r
116 }\r
117}\r