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.
10 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/CacheMaintenanceLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Ppi/MpServices.h>
21 Invalidate data & instruction caches.
22 All APs execute this function in parallel. The BSP executes the function
25 @param[in,out] WorkSpace Pointer to the input/output argument workspace
26 shared by all processors.
32 IN OUT VOID
*WorkSpace
35 WriteBackInvalidateDataCache ();
36 InvalidateInstructionCache ();
40 Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available.
42 @param[in] PeiServices Indirect reference to the PEI Services Table.
43 @param[in] NotifyDescriptor Address of the notification descriptor data
45 @param[in] Ppi Address of the PPI that was installed.
47 @return Status of the notification. The status code returned from this
53 ClearCacheOnMpServicesAvailable (
54 IN EFI_PEI_SERVICES
**PeiServices
,
55 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
59 EFI_PEI_MP_SERVICES_PPI
*MpServices
;
62 DEBUG ((DEBUG_INFO
, "%a: %a\n", gEfiCallerBaseName
, __FUNCTION__
));
65 // Clear cache on all the APs in parallel.
68 Status
= MpServices
->StartupAllAPs (
69 (CONST EFI_PEI_SERVICES
**)PeiServices
,
71 ClearCache
, // Procedure
72 FALSE
, // SingleThread
73 0, // TimeoutInMicroSeconds: inf.
74 NULL
// ProcedureArgument
76 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
77 DEBUG ((DEBUG_ERROR
, "%a: StartupAllAps(): %r\n", __FUNCTION__
, Status
));
82 // Now clear cache on the BSP too.
89 // Notification object for registering the callback, for when
90 // EFI_PEI_MP_SERVICES_PPI becomes available.
92 STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify
= {
93 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| // Flags
94 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
95 &gEfiPeiMpServicesPpiGuid
, // Guid
96 ClearCacheOnMpServicesAvailable
// Notify
100 InstallClearCacheCallback (
106 Status
= PeiServicesNotifyPpi (&mMpServicesNotify
);
107 if (EFI_ERROR (Status
)) {
110 "%a: failed to set up MP Services callback: %r\n",