2 Install a callback to clear cache on all processors.
3 This is for conformance with the TCG "Platform Reset Attack Mitigation
4 Specification". Because clearing the CPU caches at boot doesn't impact
5 performance significantly, do it unconditionally, for simplicity's
8 Copyright (C) 2018, Red Hat, Inc.
9 Copyright (c) 2019, Citrix Systems, Inc.
11 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Library/CacheMaintenanceLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/PeiServicesLib.h>
17 #include <Ppi/MpServices.h>
22 Invalidate data & instruction caches.
23 All APs execute this function in parallel. The BSP executes the function
26 @param[in,out] WorkSpace Pointer to the input/output argument workspace
27 shared by all processors.
33 IN OUT VOID
*WorkSpace
36 WriteBackInvalidateDataCache ();
37 InvalidateInstructionCache ();
41 Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available.
43 @param[in] PeiServices Indirect reference to the PEI Services Table.
44 @param[in] NotifyDescriptor Address of the notification descriptor data
46 @param[in] Ppi Address of the PPI that was installed.
48 @return Status of the notification. The status code returned from this
54 ClearCacheOnMpServicesAvailable (
55 IN EFI_PEI_SERVICES
**PeiServices
,
56 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
60 EFI_PEI_MP_SERVICES_PPI
*MpServices
;
63 DEBUG ((DEBUG_INFO
, "%a: %a\n", gEfiCallerBaseName
, __FUNCTION__
));
66 // Clear cache on all the APs in parallel.
69 Status
= MpServices
->StartupAllAPs (
70 (CONST EFI_PEI_SERVICES
**)PeiServices
,
72 ClearCache
, // Procedure
73 FALSE
, // SingleThread
74 0, // TimeoutInMicroSeconds: inf.
75 NULL
// ProcedureArgument
77 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
78 DEBUG ((DEBUG_ERROR
, "%a: StartupAllAps(): %r\n", __FUNCTION__
, Status
));
83 // Now clear cache on the BSP too.
90 // Notification object for registering the callback, for when
91 // EFI_PEI_MP_SERVICES_PPI becomes available.
93 STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify
= {
94 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| // Flags
95 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
96 &gEfiPeiMpServicesPpiGuid
, // Guid
97 ClearCacheOnMpServicesAvailable
// Notify
101 InstallClearCacheCallback (
107 Status
= PeiServicesNotifyPpi (&mMpServicesNotify
);
108 if (EFI_ERROR (Status
)) {
111 "%a: failed to set up MP Services callback: %r\n",