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