]>
Commit | Line | Data |
---|---|---|
ee1d736a ED |
1 | /** @file\r |
2 | Protected Processor Inventory Number(PPIN) feature.\r | |
3 | \r | |
7367cc6c | 4 | Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r |
0acd8697 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ee1d736a ED |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "CpuCommonFeatures.h"\r | |
10 | \r | |
84a45947 SZ |
11 | /**\r |
12 | Prepares for the data used by CPU feature detection and initialization.\r | |
13 | \r | |
14 | @param[in] NumberOfProcessors The number of CPUs in the platform.\r | |
15 | \r | |
16 | @return Pointer to a buffer of CPU related configuration data.\r | |
17 | \r | |
18 | @note This service could be called by BSP only.\r | |
19 | **/\r | |
20 | VOID *\r | |
21 | EFIAPI\r | |
22 | PpinGetConfigData (\r | |
053e878b | 23 | IN UINTN NumberOfProcessors\r |
84a45947 SZ |
24 | )\r |
25 | {\r | |
053e878b | 26 | VOID *ConfigData;\r |
84a45947 SZ |
27 | \r |
28 | ConfigData = AllocateZeroPool (sizeof (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER) * NumberOfProcessors);\r | |
29 | ASSERT (ConfigData != NULL);\r | |
30 | return ConfigData;\r | |
31 | }\r | |
32 | \r | |
ee1d736a | 33 | /**\r |
7367cc6c | 34 | Detects if Protected Processor Inventory Number feature supported on current\r |
ee1d736a ED |
35 | processor.\r |
36 | \r | |
37 | @param[in] ProcessorNumber The index of the CPU executing this function.\r | |
38 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r | |
39 | structure for the CPU executing this function.\r | |
40 | @param[in] ConfigData A pointer to the configuration buffer returned\r | |
41 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r | |
42 | CPU_FEATURE_GET_CONFIG_DATA was not provided in\r | |
43 | RegisterCpuFeature().\r | |
44 | \r | |
91ec57c4 MH |
45 | @retval TRUE Protected Processor Inventory Number feature is supported.\r |
46 | @retval FALSE Protected Processor Inventory Number feature is not supported.\r | |
ee1d736a ED |
47 | \r |
48 | @note This service could be called by BSP/APs.\r | |
49 | **/\r | |
50 | BOOLEAN\r | |
51 | EFIAPI\r | |
52 | PpinSupport (\r | |
53 | IN UINTN ProcessorNumber,\r | |
54 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r | |
55 | IN VOID *ConfigData OPTIONAL\r | |
56 | )\r | |
57 | {\r | |
053e878b MK |
58 | MSR_IVY_BRIDGE_PLATFORM_INFO_1_REGISTER PlatformInfo;\r |
59 | MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *MsrPpinCtrl;\r | |
ee1d736a | 60 | \r |
7367cc6c | 61 | if ((CpuInfo->DisplayFamily == 0x06) &&\r |
ee1d736a ED |
62 | ((CpuInfo->DisplayModel == 0x3E) || // Xeon E5 V2\r |
63 | (CpuInfo->DisplayModel == 0x56) || // Xeon Processor D Product\r | |
64 | (CpuInfo->DisplayModel == 0x4F) || // Xeon E5 v4, E7 v4\r | |
65 | (CpuInfo->DisplayModel == 0x55) || // Xeon Processor Scalable\r | |
66 | (CpuInfo->DisplayModel == 0x57) || // Xeon Phi processor 3200, 5200, 7200 series.\r | |
7367cc6c | 67 | (CpuInfo->DisplayModel == 0x85) // Future Xeon phi processor\r |
053e878b MK |
68 | ))\r |
69 | {\r | |
ee1d736a ED |
70 | //\r |
71 | // Check whether platform support this feature.\r | |
72 | //\r | |
73 | PlatformInfo.Uint64 = AsmReadMsr64 (MSR_IVY_BRIDGE_PLATFORM_INFO_1);\r | |
84a45947 | 74 | if (PlatformInfo.Bits.PPIN_CAP != 0) {\r |
053e878b | 75 | MsrPpinCtrl = (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *)ConfigData;\r |
84a45947 SZ |
76 | ASSERT (MsrPpinCtrl != NULL);\r |
77 | MsrPpinCtrl[ProcessorNumber].Uint64 = AsmReadMsr64 (MSR_IVY_BRIDGE_PPIN_CTL);\r | |
78 | return TRUE;\r | |
79 | }\r | |
ee1d736a ED |
80 | }\r |
81 | \r | |
82 | return FALSE;\r | |
83 | }\r | |
84 | \r | |
85 | /**\r | |
86 | Initializes Protected Processor Inventory Number feature to specific state.\r | |
87 | \r | |
88 | @param[in] ProcessorNumber The index of the CPU executing this function.\r | |
89 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r | |
90 | structure for the CPU executing this function.\r | |
91 | @param[in] ConfigData A pointer to the configuration buffer returned\r | |
92 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r | |
93 | CPU_FEATURE_GET_CONFIG_DATA was not provided in\r | |
94 | RegisterCpuFeature().\r | |
7367cc6c | 95 | @param[in] State If TRUE, then the Protected Processor Inventory\r |
ee1d736a | 96 | Number feature must be enabled.\r |
7367cc6c | 97 | If FALSE, then the Protected Processor Inventory\r |
ee1d736a ED |
98 | Number feature must be disabled.\r |
99 | \r | |
7367cc6c | 100 | @retval RETURN_SUCCESS Protected Processor Inventory Number feature is\r |
ee1d736a | 101 | initialized.\r |
7367cc6c | 102 | @retval RETURN_DEVICE_ERROR Device can't change state because it has been\r |
ee1d736a ED |
103 | locked.\r |
104 | \r | |
84a45947 | 105 | @note This service could be called by BSP only.\r |
ee1d736a ED |
106 | **/\r |
107 | RETURN_STATUS\r | |
108 | EFIAPI\r | |
109 | PpinInitialize (\r | |
110 | IN UINTN ProcessorNumber,\r | |
111 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r | |
4ec586b9 | 112 | IN VOID *ConfigData OPTIONAL,\r |
ee1d736a ED |
113 | IN BOOLEAN State\r |
114 | )\r | |
115 | {\r | |
053e878b | 116 | MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *MsrPpinCtrl;\r |
84a45947 | 117 | \r |
053e878b | 118 | MsrPpinCtrl = (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *)ConfigData;\r |
84a45947 | 119 | ASSERT (MsrPpinCtrl != NULL);\r |
ee1d736a ED |
120 | \r |
121 | //\r | |
84a45947 SZ |
122 | // Check whether processor already lock this register.\r |
123 | // If already locked, just based on the request state and\r | |
ee1d736a ED |
124 | // the current state to return the status.\r |
125 | //\r | |
84a45947 SZ |
126 | if (MsrPpinCtrl[ProcessorNumber].Bits.LockOut != 0) {\r |
127 | return MsrPpinCtrl[ProcessorNumber].Bits.Enable_PPIN == State ? RETURN_SUCCESS : RETURN_DEVICE_ERROR;\r | |
ee1d736a ED |
128 | }\r |
129 | \r | |
d28daadd ED |
130 | //\r |
131 | // Support function already check the processor which support PPIN feature, so this function not need\r | |
132 | // to check the processor again.\r | |
133 | //\r | |
6cfeeb71 DL |
134 | // The scope of the MSR_IVY_BRIDGE_PPIN_CTL is package level, only program MSR_IVY_BRIDGE_PPIN_CTL\r |
135 | // once for each package.\r | |
d28daadd | 136 | //\r |
6cfeeb71 | 137 | if ((CpuInfo->First.Thread == 0) || (CpuInfo->First.Core == 0)) {\r |
d28daadd ED |
138 | return RETURN_SUCCESS;\r |
139 | }\r | |
140 | \r | |
84a45947 SZ |
141 | if (State) {\r |
142 | //\r | |
143 | // Enable and Unlock.\r | |
144 | // According to SDM, once Enable_PPIN is set, attempt to write 1 to LockOut will cause #GP.\r | |
145 | //\r | |
146 | MsrPpinCtrl[ProcessorNumber].Bits.Enable_PPIN = 1;\r | |
053e878b | 147 | MsrPpinCtrl[ProcessorNumber].Bits.LockOut = 0;\r |
84a45947 SZ |
148 | } else {\r |
149 | //\r | |
150 | // Disable and Lock.\r | |
151 | // According to SDM, writing 1 to LockOut is permitted only if Enable_PPIN is clear.\r | |
152 | //\r | |
153 | MsrPpinCtrl[ProcessorNumber].Bits.Enable_PPIN = 0;\r | |
053e878b | 154 | MsrPpinCtrl[ProcessorNumber].Bits.LockOut = 1;\r |
84a45947 SZ |
155 | }\r |
156 | \r | |
157 | CPU_REGISTER_TABLE_WRITE64 (\r | |
ee1d736a ED |
158 | ProcessorNumber,\r |
159 | Msr,\r | |
160 | MSR_IVY_BRIDGE_PPIN_CTL,\r | |
84a45947 | 161 | MsrPpinCtrl[ProcessorNumber].Uint64\r |
ee1d736a ED |
162 | );\r |
163 | \r | |
164 | return RETURN_SUCCESS;\r | |
165 | }\r |