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