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