Commit | Line | Data |
---|---|---|
3e8ad6bd JF |
1 | /** @file\r |
2 | CPU MP Initialize Library common functions.\r | |
3 | \r | |
4 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "MpLib.h"\r | |
16 | \r | |
17 | \r | |
9ebcf0f4 JF |
18 | /**\r |
19 | Detect whether Mwait-monitor feature is supported.\r | |
20 | \r | |
21 | @retval TRUE Mwait-monitor feature is supported.\r | |
22 | @retval FALSE Mwait-monitor feature is not supported.\r | |
23 | **/\r | |
24 | BOOLEAN\r | |
25 | IsMwaitSupport (\r | |
26 | VOID\r | |
27 | )\r | |
28 | {\r | |
29 | CPUID_VERSION_INFO_ECX VersionInfoEcx;\r | |
30 | \r | |
31 | AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, &VersionInfoEcx.Uint32, NULL);\r | |
32 | return (VersionInfoEcx.Bits.MONITOR == 1) ? TRUE : FALSE;\r | |
33 | }\r | |
34 | \r | |
35 | /**\r | |
36 | Get AP loop mode.\r | |
37 | \r | |
38 | @param[out] MonitorFilterSize Returns the largest monitor-line size in bytes.\r | |
39 | \r | |
40 | @return The AP loop mode.\r | |
41 | **/\r | |
42 | UINT8\r | |
43 | GetApLoopMode (\r | |
44 | OUT UINT32 *MonitorFilterSize\r | |
45 | )\r | |
46 | {\r | |
47 | UINT8 ApLoopMode;\r | |
48 | CPUID_MONITOR_MWAIT_EBX MonitorMwaitEbx;\r | |
49 | \r | |
50 | ASSERT (MonitorFilterSize != NULL);\r | |
51 | \r | |
52 | ApLoopMode = PcdGet8 (PcdCpuApLoopMode);\r | |
53 | ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);\r | |
54 | if (ApLoopMode == ApInMwaitLoop) {\r | |
55 | if (!IsMwaitSupport ()) {\r | |
56 | //\r | |
57 | // If processor does not support MONITOR/MWAIT feature,\r | |
58 | // force AP in Hlt-loop mode\r | |
59 | //\r | |
60 | ApLoopMode = ApInHltLoop;\r | |
61 | }\r | |
62 | }\r | |
63 | \r | |
64 | if (ApLoopMode != ApInMwaitLoop) {\r | |
65 | *MonitorFilterSize = sizeof (UINT32);\r | |
66 | } else {\r | |
67 | //\r | |
68 | // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes\r | |
69 | // CPUID.[EAX=05H].EDX: C-states supported using MWAIT\r | |
70 | //\r | |
71 | AsmCpuid (CPUID_MONITOR_MWAIT, NULL, &MonitorMwaitEbx.Uint32, NULL, NULL);\r | |
72 | *MonitorFilterSize = MonitorMwaitEbx.Bits.LargestMonitorLineSize;\r | |
73 | }\r | |
74 | \r | |
75 | return ApLoopMode;\r | |
76 | }\r | |
3e8ad6bd JF |
77 | /**\r |
78 | MP Initialize Library initialization.\r | |
79 | \r | |
80 | This service will allocate AP reset vector and wakeup all APs to do APs\r | |
81 | initialization.\r | |
82 | \r | |
83 | This service must be invoked before all other MP Initialize Library\r | |
84 | service are invoked.\r | |
85 | \r | |
86 | @retval EFI_SUCCESS MP initialization succeeds.\r | |
87 | @retval Others MP initialization fails.\r | |
88 | \r | |
89 | **/\r | |
90 | EFI_STATUS\r | |
91 | EFIAPI\r | |
92 | MpInitLibInitialize (\r | |
93 | VOID\r | |
94 | )\r | |
95 | {\r | |
f7f85d83 | 96 | MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r |
9ebcf0f4 JF |
97 | UINT32 MonitorFilterSize;\r |
98 | UINT8 ApLoopMode;\r | |
f7f85d83 JF |
99 | UINTN ApResetVectorSize;\r |
100 | \r | |
101 | AsmGetAddressMap (&AddressMap);\r | |
102 | ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_EXCHANGE_INFO);\r | |
9ebcf0f4 JF |
103 | ApLoopMode = GetApLoopMode (&MonitorFilterSize);\r |
104 | \r | |
f7f85d83 | 105 | return EFI_SUCCESS;\r |
3e8ad6bd JF |
106 | }\r |
107 | \r | |
108 | /**\r | |
109 | Gets detailed MP-related information on the requested processor at the\r | |
110 | instant this call is made. This service may only be called from the BSP.\r | |
111 | \r | |
112 | @param[in] ProcessorNumber The handle number of processor.\r | |
113 | @param[out] ProcessorInfoBuffer A pointer to the buffer where information for\r | |
114 | the requested processor is deposited.\r | |
115 | @param[out] HealthData Return processor health data.\r | |
116 | \r | |
117 | @retval EFI_SUCCESS Processor information was returned.\r | |
118 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
119 | @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r | |
120 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
121 | ProcessorNumber does not exist in the platform.\r | |
122 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_STATUS\r | |
126 | EFIAPI\r | |
127 | MpInitLibGetProcessorInfo (\r | |
128 | IN UINTN ProcessorNumber,\r | |
129 | OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,\r | |
130 | OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL\r | |
131 | )\r | |
132 | {\r | |
133 | return EFI_UNSUPPORTED;\r | |
134 | }\r | |
135 | /**\r | |
136 | This return the handle number for the calling processor. This service may be\r | |
137 | called from the BSP and APs.\r | |
138 | \r | |
139 | @param[out] ProcessorNumber Pointer to the handle number of AP.\r | |
140 | The range is from 0 to the total number of\r | |
141 | logical processors minus 1. The total number of\r | |
142 | logical processors can be retrieved by\r | |
143 | MpInitLibGetNumberOfProcessors().\r | |
144 | \r | |
145 | @retval EFI_SUCCESS The current processor handle number was returned\r | |
146 | in ProcessorNumber.\r | |
147 | @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r | |
148 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
149 | \r | |
150 | **/\r | |
151 | EFI_STATUS\r | |
152 | EFIAPI\r | |
153 | MpInitLibWhoAmI (\r | |
154 | OUT UINTN *ProcessorNumber\r | |
155 | )\r | |
156 | {\r | |
157 | return EFI_UNSUPPORTED;\r | |
158 | }\r | |
159 | /**\r | |
160 | Retrieves the number of logical processor in the platform and the number of\r | |
161 | those logical processors that are enabled on this boot. This service may only\r | |
162 | be called from the BSP.\r | |
163 | \r | |
164 | @param[out] NumberOfProcessors Pointer to the total number of logical\r | |
165 | processors in the system, including the BSP\r | |
166 | and disabled APs.\r | |
167 | @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical\r | |
168 | processors that exist in system, including\r | |
169 | the BSP.\r | |
170 | \r | |
171 | @retval EFI_SUCCESS The number of logical processors and enabled\r | |
172 | logical processors was retrieved.\r | |
173 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
174 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors\r | |
175 | is NULL.\r | |
176 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
177 | \r | |
178 | **/\r | |
179 | EFI_STATUS\r | |
180 | EFIAPI\r | |
181 | MpInitLibGetNumberOfProcessors (\r | |
182 | OUT UINTN *NumberOfProcessors, OPTIONAL\r | |
183 | OUT UINTN *NumberOfEnabledProcessors OPTIONAL\r | |
184 | )\r | |
185 | {\r | |
186 | return EFI_UNSUPPORTED;\r | |
187 | }\r |