]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/XenPlatformPei/ClearCache.c
.mailmap: Add an entry for Michael Kubacki
[mirror_edk2.git] / OvmfPkg / XenPlatformPei / ClearCache.c
CommitLineData
3b96221f
AP
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 Copyright (c) 2019, Citrix Systems, Inc.\r
10\r
11 SPDX-License-Identifier: BSD-2-Clause-Patent\r
12**/\r
13\r
14#include <Library/CacheMaintenanceLib.h>\r
15#include <Library/DebugLib.h>\r
16#include <Library/PeiServicesLib.h>\r
17#include <Ppi/MpServices.h>\r
18\r
19#include "Platform.h"\r
20\r
21/**\r
22 Invalidate data & instruction caches.\r
23 All APs execute this function in parallel. The BSP executes the function\r
24 separately.\r
25\r
26 @param[in,out] WorkSpace Pointer to the input/output argument workspace\r
27 shared by all processors.\r
28**/\r
29STATIC\r
30VOID\r
31EFIAPI\r
32ClearCache (\r
33 IN OUT VOID *WorkSpace\r
34 )\r
35{\r
36 WriteBackInvalidateDataCache ();\r
37 InvalidateInstructionCache ();\r
38}\r
39\r
40/**\r
41 Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available.\r
42\r
43 @param[in] PeiServices Indirect reference to the PEI Services Table.\r
44 @param[in] NotifyDescriptor Address of the notification descriptor data\r
45 structure.\r
46 @param[in] Ppi Address of the PPI that was installed.\r
47\r
48 @return Status of the notification. The status code returned from this\r
49 function is ignored.\r
50**/\r
51STATIC\r
52EFI_STATUS\r
53EFIAPI\r
54ClearCacheOnMpServicesAvailable (\r
55 IN EFI_PEI_SERVICES **PeiServices,\r
56 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
57 IN VOID *Ppi\r
58 )\r
59{\r
60 EFI_PEI_MP_SERVICES_PPI *MpServices;\r
61 EFI_STATUS Status;\r
62\r
63 DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));\r
64\r
65 //\r
66 // Clear cache on all the APs in parallel.\r
67 //\r
68 MpServices = Ppi;\r
69 Status = MpServices->StartupAllAPs (\r
70 (CONST EFI_PEI_SERVICES **)PeiServices,\r
71 MpServices,\r
72 ClearCache, // Procedure\r
73 FALSE, // SingleThread\r
74 0, // TimeoutInMicroSeconds: inf.\r
75 NULL // ProcedureArgument\r
76 );\r
77 if (EFI_ERROR (Status) && Status != EFI_NOT_STARTED) {\r
78 DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));\r
79 return Status;\r
80 }\r
81\r
82 //\r
83 // Now clear cache on the BSP too.\r
84 //\r
85 ClearCache (NULL);\r
86 return EFI_SUCCESS;\r
87}\r
88\r
89//\r
90// Notification object for registering the callback, for when\r
91// EFI_PEI_MP_SERVICES_PPI becomes available.\r
92//\r
93STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify = {\r
94 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags\r
95 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
96 &gEfiPeiMpServicesPpiGuid, // Guid\r
97 ClearCacheOnMpServicesAvailable // Notify\r
98};\r
99\r
100VOID\r
101InstallClearCacheCallback (\r
102 VOID\r
103 )\r
104{\r
105 EFI_STATUS Status;\r
106\r
107 Status = PeiServicesNotifyPpi (&mMpServicesNotify);\r
108 if (EFI_ERROR (Status)) {\r
109 DEBUG ((DEBUG_ERROR, "%a: failed to set up MP Services callback: %r\n",\r
110 __FUNCTION__, Status));\r
111 }\r
112}\r