blob: f51d41f72f451cb353fa8ec28dc2bb9f67e955bb [file] [log] [blame]
zbao7d94cf92012-07-02 14:19:14 +08001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * AMD CPU Services
6 *
7 * Related to the General Services API's, but for the CPU component.
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: CPU
12 * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $
13 *
14 */
15/*
16 ******************************************************************************
17 *
Siyuan Wang641f00c2013-06-08 11:50:55 +080018 * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc.
19 * All rights reserved.
zbao7d94cf92012-07-02 14:19:14 +080020 *
Siyuan Wang641f00c2013-06-08 11:50:55 +080021 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 * its contributors may be used to endorse or promote products derived
30 * from this software without specific prior written permission.
zbao7d94cf92012-07-02 14:19:14 +080031 *
Siyuan Wang641f00c2013-06-08 11:50:55 +080032 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
zbao7d94cf92012-07-02 14:19:14 +080042 ******************************************************************************
43 */
44
45#ifndef _CPU_SERVICES_H_
46#define _CPU_SERVICES_H_
47
48/*----------------------------------------------------------------------------------------
49 * M I X E D (Definitions And Macros / Typedefs, Structures, Enums)
50 *----------------------------------------------------------------------------------------
51 */
52
53/*----------------------------------------------------------------------------------------
54 * D E F I N I T I O N S A N D M A C R O S
55 *----------------------------------------------------------------------------------------
56 */
57 /// WARM RESET STATE_BITS
58#define WR_STATE_COLD 00
59#define WR_STATE_RESET 01
60#define WR_STATE_EARLY 02
61#define WR_STATE_POST 03
62
63/*----------------------------------------------------------------------------------------
64 * T Y P E D E F S, S T R U C T U R E S, E N U M S
65 *----------------------------------------------------------------------------------------
66 */
67
68/**
69 * The role of primary core for each compute unit can be relative to the cores' launch order.
70 *
71 * One core of a compute unit is always given the role as primary. In different feature algorithms
72 * the core performing the primary core role can be designated relative to compute order. In most cases,
73 * the primary core is the first core of a compute unit to execute. However, in some cases the primary core
74 * role is associated with the last core to execute.
75 *
76 * If the launch order is strictly ascending, then first core is the lowest number and last core is highest.
77 * But if the launch order is not ascending, the first and last core follow the launch order, not the numbering order.
78 *
79 * Note that for compute units with only one core (AllCoresMapping), that core is primary for both orderings.
80 * (This includes processors without hardware compute units.)
81 *
82 */
83typedef enum {
84 FirstCoreIsComputeUnitPrimary, ///< the primary core role associates with the first core.
85 LastCoreIsComputeUnitPrimary, ///< the primary core role associates with the last core.
86 MaxComputeUnitPrimarySelector, ///< limit check.
87} COMPUTE_UNIT_PRIMARY_SELECTOR;
88
89/**
90 * The supported Core to Compute unit mappings.
91 */
92typedef enum {
93 AllCoresMapping, ///< All Cores are primary cores
94 EvenCoresMapping, ///< Compute units are even/odd core pairs.
95 BitMapMapping, ///< Currently not supported by any family, arbitrary core
96 ///< to compute unit mapping.
97 MaxComputeUnitMapping ///< Not a mapping, use for limit check.
98} COMPUTE_UNIT_MAPPING;
99
100/**
101 * Core Pair Map entry.
102 * Provide for interpreting the core pairing for the processor's compute units.
103 *
104 * HT_LIST_TERMINAL as an Enabled value means the end of a list of map structs.
105 * Zero as an Enabled value implies Compute Units are not supported by the processor
106 * and the mapping is assumed to be AllCoresMapping.
107 *
108 */
109typedef struct {
110 UINT8 Enabled; ///< The value of the Enabled Compute Units
111 UINT8 DualCore; ///< The value of the Dual Core Compute Units
112 COMPUTE_UNIT_MAPPING Mapping; ///< When the processor module matches these values, use this mapping method.
113} CORE_PAIR_MAP;
114
115//----------------------------------------------------------------------------
116// CPU SYSTEM INFO TYPEDEFS, STRUCTURES, ENUMS
117//
118//----------------------------------------------------------------------------
119/// SYSTEM INFO
120typedef struct _SYSTEM_INFO {
121 UINT32 TotalNumberOfSockets; ///< Total Number of Sockets
122 UINT32 TotalNumberOfCores; ///< Total Number Of Cores
123 UINT32 CurrentSocketNum; ///< Current Socket Number
124 UINT32 CurrentCoreNum; ///< Current Core Number
125 UINT32 CurrentCoreApicId; ///< Current Core Apic ID
126 UINT32 CurrentLogicalCpuId; ///< Current Logical CPU ID
127} SYSTEM_INFO;
128
129/// WARM_RESET_REQUEST
130typedef struct _WARM_RESET_REQUEST {
131 UINT8 RequestBit:1; ///< Request Bit
132 UINT8 StateBits:2; ///< State Bits
133 UINT8 PostStage:2; ///< Post Stage
134 UINT8 Reserved:(8 - 5); ///< Reserved
135} WARM_RESET_REQUEST;
136/*----------------------------------------------------------------------------------------
137 * F U N C T I O N P R O T O T Y P E
138 *----------------------------------------------------------------------------------------
139 */
140
141VOID
142GetCurrentNodeNum (
143 OUT UINT32 *Node,
144 IN AMD_CONFIG_PARAMS *StdHeader
145 );
146
147/**
148 * Get the current Platform's number of Sockets, regardless of how many are populated.
149 *
150 */
151UINT32
152GetPlatformNumberOfSockets ( VOID );
153
154/**
155 * Get the number of Modules to check presence in each Processor.
156 *
157 */
158UINT32
159GetPlatformNumberOfModules ( VOID );
160
161BOOLEAN
162IsProcessorPresent (
163 IN UINT32 Socket,
164 IN AMD_CONFIG_PARAMS *StdHeader
165 );
166
167/**
168 * For a specific Node, get its Socket and Module ids.
169 *
170 */
171BOOLEAN
172GetSocketModuleOfNode (
173 IN UINT32 Node,
174 OUT UINT32 *Socket,
175 OUT UINT32 *Module,
176 IN AMD_CONFIG_PARAMS *StdHeader
177 );
178
179/**
180 * Get the current core's Processor APIC Index.
181 */
182UINT32
183GetProcessorApicIndex (
184 IN UINT32 Node,
185 IN AMD_CONFIG_PARAMS *StdHeader
186 );
187
188/**
189 * Provide the number of installed processors (not Nodes! and not Sockets!)
190 */
191UINT32
192GetNumberOfProcessors (
193 IN AMD_CONFIG_PARAMS *StdHeader
194 );
195
196VOID
197GetActiveCoresInCurrentSocket (
198 OUT UINT32 *CoreCount,
199 IN AMD_CONFIG_PARAMS *StdHeader
200 );
201
202BOOLEAN
203GetActiveCoresInGivenSocket (
204 IN UINT32 Socket,
205 OUT UINT32 *CoreCount,
206 IN AMD_CONFIG_PARAMS *StdHeader
207 );
208
209UINTN
210GetActiveCoresInCurrentModule (
211 IN AMD_CONFIG_PARAMS *StdHeader
212 );
213
214UINTN
215GetNumberOfCompUnitsInCurrentModule (
216 IN AMD_CONFIG_PARAMS *StdHeader
217 );
218
219BOOLEAN
220GetGivenModuleCoreRange (
221 IN UINT32 Socket,
222 IN UINT32 Module,
223 OUT UINT32 *LowCore,
224 OUT UINT32 *HighCore,
225 IN AMD_CONFIG_PARAMS *StdHeader
226 );
227
228VOID
229GetCurrentCore (
230 OUT UINT32 *Core,
231 IN AMD_CONFIG_PARAMS *StdHeader
232 );
233
234VOID
235GetCurrentNodeAndCore (
236 OUT UINT32 *Node,
237 OUT UINT32 *Core,
238 IN AMD_CONFIG_PARAMS *StdHeader
239 );
240
241BOOLEAN
242IsCurrentCorePrimary (
243 IN AMD_CONFIG_PARAMS *StdHeader
244 );
245
246VOID
247GetApMailbox (
248 OUT UINT32 *ApMailboxInfo,
249 IN AMD_CONFIG_PARAMS *StdHeader
250 );
251
252VOID
253CacheApMailbox (
254 IN AMD_CONFIG_PARAMS *StdHeader
255 );
256
257UINTN
258GetSystemDegree (
259 IN AMD_CONFIG_PARAMS *StdHeader
260 );
261
262BOOLEAN
263GetNodeId (
264 IN UINT32 SocketId,
265 IN UINT32 ModuleId,
266 OUT UINT8 *NodeId,
267 IN AMD_CONFIG_PARAMS *StdHeader
268 );
269
270VOID
271WaitMicroseconds (
272 IN UINT32 Microseconds,
273 IN AMD_CONFIG_PARAMS *StdHeader
274 );
275
276/**
277 * Get the compute unit mapping algorithm.
278 */
279COMPUTE_UNIT_MAPPING
280GetComputeUnitMapping (
281 IN AMD_CONFIG_PARAMS *StdHeader
282 );
283
284/**
285 * Does the current core have the role of primary core for the compute unit?
286 */
287BOOLEAN
288IsCorePairPrimary (
289 IN COMPUTE_UNIT_PRIMARY_SELECTOR Selector,
290 IN AMD_CONFIG_PARAMS *StdHeader
291 );
292
293/**
294 * Are the two specified cores shared in a compute unit?
295 */
296BOOLEAN
297AreCoresPaired (
298 IN UINT32 Socket,
299 IN UINT32 Module,
300 IN UINT32 CoreA,
301 IN UINT32 CoreB,
302 IN AMD_CONFIG_PARAMS *StdHeader
303 );
304
305VOID
306SetWarmResetFlag (
307 IN AMD_CONFIG_PARAMS *StdHeader,
308 IN WARM_RESET_REQUEST *Request
309 );
310
311VOID
312GetWarmResetFlag (
313 IN AMD_CONFIG_PARAMS *StdHeader,
314 OUT WARM_RESET_REQUEST *Request
315 );
316
317BOOLEAN
318IsWarmReset (
319 IN AMD_CONFIG_PARAMS *StdHeader
320 );
321
322AGESA_STATUS
323CheckBistStatus (
324 IN AMD_CONFIG_PARAMS *StdHeader
325 );
326
327VOID
328SetWarmResetAtEarly (
329 IN UINT32 Data,
330 IN AMD_CONFIG_PARAMS *StdHeader
331);
332
333#endif // _CPU_SERVICES_H_