]>
Commit | Line | Data |
---|---|---|
1 | /**@file\r | |
2 | Install a callback when necessary for setting the Feature Control MSR on all\r | |
3 | processors.\r | |
4 | \r | |
5 | Copyright (C) 2016, Red Hat, Inc.\r | |
6 | \r | |
7 | This program and the accompanying materials are licensed and made available\r | |
8 | under the terms and conditions of the BSD License which accompanies this\r | |
9 | distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
13 | WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | **/\r | |
15 | \r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/PeiServicesLib.h>\r | |
18 | #include <Library/QemuFwCfgLib.h>\r | |
19 | #include <Ppi/MpServices.h>\r | |
20 | #include <Register/Msr/Core2Msr.h>\r | |
21 | \r | |
22 | #include "Platform.h"\r | |
23 | \r | |
24 | //\r | |
25 | // The value to be written to the Feature Control MSR, retrieved from fw_cfg.\r | |
26 | //\r | |
27 | STATIC UINT64 mFeatureControlValue;\r | |
28 | \r | |
29 | /**\r | |
30 | Write the Feature Control MSR on an Application Processor or the Boot\r | |
31 | Processor.\r | |
32 | \r | |
33 | All APs execute this function in parallel. The BSP executes the function\r | |
34 | separately.\r | |
35 | \r | |
36 | @param[in,out] WorkSpace Pointer to the input/output argument workspace\r | |
37 | shared by all processors.\r | |
38 | **/\r | |
39 | STATIC\r | |
40 | VOID\r | |
41 | EFIAPI\r | |
42 | WriteFeatureControl (\r | |
43 | IN OUT VOID *WorkSpace\r | |
44 | )\r | |
45 | {\r | |
46 | AsmWriteMsr64 (MSR_CORE2_FEATURE_CONTROL, mFeatureControlValue);\r | |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available.\r | |
51 | \r | |
52 | @param[in] PeiServices Indirect reference to the PEI Services Table.\r | |
53 | @param[in] NotifyDescriptor Address of the notification descriptor data\r | |
54 | structure.\r | |
55 | @param[in] Ppi Address of the PPI that was installed.\r | |
56 | \r | |
57 | @return Status of the notification. The status code returned from this\r | |
58 | function is ignored.\r | |
59 | **/\r | |
60 | STATIC\r | |
61 | EFI_STATUS\r | |
62 | EFIAPI\r | |
63 | OnMpServicesAvailable (\r | |
64 | IN EFI_PEI_SERVICES **PeiServices,\r | |
65 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
66 | IN VOID *Ppi\r | |
67 | )\r | |
68 | {\r | |
69 | EFI_PEI_MP_SERVICES_PPI *MpServices;\r | |
70 | EFI_STATUS Status;\r | |
71 | \r | |
72 | DEBUG ((EFI_D_VERBOSE, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));\r | |
73 | \r | |
74 | //\r | |
75 | // Write the MSR on all the APs in parallel.\r | |
76 | //\r | |
77 | MpServices = Ppi;\r | |
78 | Status = MpServices->StartupAllAPs (\r | |
79 | (CONST EFI_PEI_SERVICES **)PeiServices,\r | |
80 | MpServices,\r | |
81 | WriteFeatureControl, // Procedure\r | |
82 | FALSE, // SingleThread\r | |
83 | 0, // TimeoutInMicroSeconds: inf.\r | |
84 | NULL // ProcedureArgument\r | |
85 | );\r | |
86 | if (EFI_ERROR (Status) && Status != EFI_NOT_STARTED) {\r | |
87 | DEBUG ((EFI_D_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));\r | |
88 | return Status;\r | |
89 | }\r | |
90 | \r | |
91 | //\r | |
92 | // Now write the MSR on the BSP too.\r | |
93 | //\r | |
94 | WriteFeatureControl (NULL);\r | |
95 | return EFI_SUCCESS;\r | |
96 | }\r | |
97 | \r | |
98 | //\r | |
99 | // Notification object for registering the callback, for when\r | |
100 | // EFI_PEI_MP_SERVICES_PPI becomes available.\r | |
101 | //\r | |
102 | STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify = {\r | |
103 | EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags\r | |
104 | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r | |
105 | &gEfiPeiMpServicesPpiGuid, // Guid\r | |
106 | OnMpServicesAvailable // Notify\r | |
107 | };\r | |
108 | \r | |
109 | VOID\r | |
110 | InstallFeatureControlCallback (\r | |
111 | VOID\r | |
112 | )\r | |
113 | {\r | |
114 | EFI_STATUS Status;\r | |
115 | FIRMWARE_CONFIG_ITEM FwCfgItem;\r | |
116 | UINTN FwCfgSize;\r | |
117 | \r | |
118 | Status = QemuFwCfgFindFile ("etc/msr_feature_control", &FwCfgItem,\r | |
119 | &FwCfgSize);\r | |
120 | if (EFI_ERROR (Status) || FwCfgSize != sizeof mFeatureControlValue) {\r | |
121 | //\r | |
122 | // Nothing to do.\r | |
123 | //\r | |
124 | return;\r | |
125 | }\r | |
126 | QemuFwCfgSelectItem (FwCfgItem);\r | |
127 | QemuFwCfgReadBytes (sizeof mFeatureControlValue, &mFeatureControlValue);\r | |
128 | \r | |
129 | Status = PeiServicesNotifyPpi (&mMpServicesNotify);\r | |
130 | if (EFI_ERROR (Status)) {\r | |
131 | DEBUG ((EFI_D_ERROR, "%a: failed to set up MP Services callback: %r\n",\r | |
132 | __FUNCTION__, Status));\r | |
133 | }\r | |
134 | }\r |