AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuPstateTables.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA CPU Pstate Table Functions declarations.
6  *
7  * Contains code that declares the AGESA CPU _PSS related APIs
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Feature
12  * @e \$Revision: 44702 $   @e \$Date: 2011-01-04 15:54:00 -0700 (Tue, 04 Jan 2011) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (C) 2012 Advanced Micro Devices, Inc.
19  * All rights reserved.
20  *
21  * 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.
31  *
32  * 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.
42  *
43  ******************************************************************************
44  */
45
46 #ifndef _CPU_PSTATE_TABLES_H_
47 #define _CPU_PSTATE_TABLES_H_
48
49 /*----------------------------------------------------------------------------------------
50  *          M I X E D   (Definitions And Macros / Typedefs, Structures, Enums)
51  *----------------------------------------------------------------------------------------
52  */
53 //  Forward declaration needed for multi-structure mutual references
54 AGESA_FORWARD_DECLARATION (PSTATE_CPU_FAMILY_SERVICES);
55
56 /*----------------------------------------------------------------------------------------
57  *                 D E F I N I T I O N S     A N D     M A C R O S
58  *----------------------------------------------------------------------------------------
59  */
60
61 /*----------------------------------------------------------------------------------------
62  *                    T Y P E D E F S     A N D     S T R U C T U R E S
63  *----------------------------------------------------------------------------------------
64  */
65 /// P-state structure for each state
66 typedef struct {
67   IN OUT   UINT32               PStateEnable;                ///< Pstate enable
68   IN OUT   UINT32               CoreFreq;                    ///< MHz
69   IN OUT   UINT32               Power;                       ///< milliWatts
70   IN OUT   UINT32               IddValue;                    ///< Current value field
71   IN OUT   UINT32               IddDiv;                      ///< Current divisor field
72   IN OUT   UINT32               SwPstateNumber;              ///< Software P-state number
73 } S_PSTATE_VALUES;
74
75 /// P-state structure for each core
76 typedef struct {
77   IN OUT   UINT8                PStateMaxValue;              ///< Max p-state number in this core
78   IN OUT   UINT8                HtcPstateLimit;              ///< Htc limit
79   IN OUT   UINT8                HtcCapable;                  ///< Htc capable
80   IN OUT   UINT8                LocalApicId;                 ///< Local Apic Id
81   IN OUT   UINT8                NumberOfBoostedStates;       ///< Number of boost P-states
82   IN OUT   S_PSTATE_VALUES      PStateStruct[1];             ///< P state struc
83 } S_PSTATE;
84
85 /// P-state structure for each node
86 typedef struct {
87   IN       UINT8                SetPState0;                  ///< If value = 0x55 (Don't set PState0)
88   IN       UINT8                TotalCoresInNode;            ///< core number per node
89   IN       UINT16               PStateLevelingSizeOfBytes;   ///< Size
90   IN       BOOLEAN              OnlyOneEnabledPState;        ///< Only P0
91   IN       UINT8                InitStruct;                  ///< Init struc
92   IN       BOOLEAN              AllCpusHaveIdenticalPStates; ///< Have Identical p state
93   IN       UINT8                CreateAcpiTables;            ///< Create table flag
94   IN       UINT8                SocketNumber;                ///< Physical socket number of this socket
95   IN       UINT8                Reserved[2];                 ///< Reserved.
96   IN OUT   S_PSTATE             PStateCoreStruct[1];         ///< P state core struc
97 } PSTATE_LEVELING;
98
99 /// P-state structure for whole system
100 typedef struct {
101   IN OUT   UINT32               TotalSocketInSystem;         ///< Total node number in system
102   IN OUT   UINT32               SizeOfBytes;                 ///< Structure size
103   IN OUT   PSTATE_LEVELING      PStateLevelingStruc[1];      ///< P state level structure
104 } S_CPU_AMD_PSTATE;
105
106 /*---------------------------------------------------------------------------------------*/
107 /**
108  *  Family specific call to check if PSD need to be generated.
109  *
110  * @param[in]     PstateCpuFamilyServices  Pstate CPU services.
111  * @param[in,out] PlatformConfig     Contains the runtime modifiable feature input data.
112  * @param[in]     StdHeader          Config Handle for library, services.
113  *
114  * @retval       TRUE               PSD need to be generated
115  * @retval       FALSE              PSD does NOT need to be generated
116  *
117  */
118 typedef BOOLEAN F_PSTATE_PSD_IS_NEEDED (
119   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
120   IN OUT   PLATFORM_CONFIGURATION *PlatformConfig,
121   IN       AMD_CONFIG_PARAMS *StdHeader
122   );
123
124 /// Reference to a Method.
125 typedef F_PSTATE_PSD_IS_NEEDED *PF_PSTATE_PSD_IS_NEEDED;
126
127
128 /*---------------------------------------------------------------------------------------*/
129 /**
130  *  Family specific call to check if Pstate PSD is dependent.
131  *
132  * @param[in]     PstateCpuFamilyServices  Pstate CPU services.
133  * @param[in,out] PlatformConfig     Contains the runtime modifiable feature input data.
134  * @param[in]     StdHeader          Config Handle for library, services.
135  *
136  * @retval       TRUE               PSD is dependent.
137  * @retval       FALSE              PSD is independent.
138  *
139  */
140 typedef BOOLEAN F_PSTATE_PSD_IS_DEPENDENT (
141   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
142   IN OUT   PLATFORM_CONFIGURATION *PlatformConfig,
143   IN       AMD_CONFIG_PARAMS *StdHeader
144   );
145
146 /// Reference to a Method.
147 typedef F_PSTATE_PSD_IS_DEPENDENT *PF_PSTATE_PSD_IS_DEPENDENT;
148
149 /**
150  *  Family specific call to set core TscFreqSel.
151  *
152  * @param[in]     PstateCpuFamilyServices  Pstate CPU services.
153  * @param[in]     StdHeader          Config Handle for library, services.
154  *
155  */
156 typedef VOID F_PSTATE_SET_TSC_FREQ_SEL (
157   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
158   IN       AMD_CONFIG_PARAMS *StdHeader
159   );
160
161 /// Reference to a Method.
162 typedef F_PSTATE_SET_TSC_FREQ_SEL *PF_PSTATE_SET_TSC_FREQ_SEL;
163
164 /**
165  *  Family specific call to get CPU pstate transition latency for current socket.
166  *
167  *  @param[in]     PstateCpuFamilyServices        Pstate CPU services.
168  *  @param[in]     PStateLevelingBufferStructPtr  Pstate row data buffer pointer.
169  *  @param[in]     PciAddress                     Pci address struct.
170  *  @param[out]    TransitionLatency              Pstate Transition latency result.
171  *  @param[in]     StdHeader                      Handle of Header for calling lib functions and services.
172  *
173  */
174 typedef AGESA_STATUS F_CPU_PSTATE_TRANSITION_LATENCY (
175   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
176   IN       PSTATE_LEVELING        *PStateLevelingBufferStructPtr,
177   IN       PCI_ADDR               *PciAddress,
178      OUT   UINT32                 *TransitionLatency,
179   IN       AMD_CONFIG_PARAMS      *StdHeader
180   );
181
182 /// Reference to a Method.
183 typedef F_CPU_PSTATE_TRANSITION_LATENCY *PF_CPU_PSTATE_TRANSITION_LATENCY;
184
185 /**
186  *  Family specific call to get the desired P-state's frequency in megahertz.
187  *
188  *  @param[in]     PstateCpuFamilyServices Pstate CPU services.
189  *  @param[in]     StateNumber             P-state number.
190  *  @param[out]    PowerInMw               P-state frequency in megahertz.
191  *  @param[in]     StdHeader               Handle of Header for calling lib functions and services.
192  *
193  */
194 typedef AGESA_STATUS F_CPU_GET_PSTATE_FREQ (
195   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
196   IN       UINT8 StateNumber,
197      OUT   UINT32 *FreqInMHz,
198   IN       AMD_CONFIG_PARAMS *StdHeader
199   );
200
201 /// Reference to a Method.
202 typedef F_CPU_GET_PSTATE_FREQ *PF_CPU_GET_PSTATE_FREQ;
203
204 /**
205  *  Family specific call to set the system wide P-state settings on the current core.
206  *
207  *  @param[in]     PstateCpuFamilyServices Pstate CPU services.
208  *  @param[in]     CpuAmdPState            The current core's P-state data.
209  *  @param[in]     StdHeader               Handle of Header for calling lib functions and services.
210  *
211  */
212 typedef AGESA_STATUS F_CPU_SET_PSTATE_LEVELING_REG (
213   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
214   IN       S_CPU_AMD_PSTATE   *CpuAmdPState,
215   IN       AMD_CONFIG_PARAMS  *StdHeader
216   );
217
218 /// Reference to a Method.
219 typedef F_CPU_SET_PSTATE_LEVELING_REG *PF_CPU_SET_PSTATE_LEVELING_REG;
220
221 /**
222  *  Family specific call to get the desired P-state's rated power in milliwatts.
223  *
224  *  @param[in]     PstateCpuFamilyServices Pstate CPU services.
225  *  @param[in]     StateNumber             P-state number.
226  *  @param[out]    PowerInMw               P-state power in milliwatts.
227  *  @param[in]     StdHeader               Handle of Header for calling lib functions and services.
228  *
229  */
230 typedef AGESA_STATUS F_CPU_GET_PSTATE_POWER (
231   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
232   IN       UINT8 StateNumber,
233      OUT   UINT32 *PowerInMw,
234   IN       AMD_CONFIG_PARAMS *StdHeader
235   );
236
237 /// Reference to a Method.
238 typedef F_CPU_GET_PSTATE_POWER *PF_CPU_GET_PSTATE_POWER;
239
240 /**
241  *  Family specific call to get CPU Pstate Max State.
242  *
243  *  @param[in]     PstateCpuFamilyServices        Pstate CPU services.
244  *  @param[out]    MaxPStateNumber                The max hw pstate value on the current socket.
245  *  @param[out]    NumberOfBoostStates            The number of boosted P-states on the current socket.
246  *  @param[in]     StdHeader                      Handle of Header for calling lib functions and services.
247  *
248  */
249 typedef AGESA_STATUS F_CPU_GET_PSTATE_MAX_STATE (
250   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
251      OUT   UINT32              *MaxPStateNumber,
252      OUT   UINT8               *NumberOfBoostStates,
253   IN       AMD_CONFIG_PARAMS   *StdHeader
254   );
255
256 /// Reference to a Method.
257 typedef F_CPU_GET_PSTATE_MAX_STATE *PF_CPU_GET_PSTATE_MAX_STATE;
258
259 /**
260  *  Family specific call to get CPU pstate register information.
261  *
262  *  @param[in]     PstateCpuFamilyServices        Pstate CPU services.
263  *  @param[in]     PState                         Input hardware Pstate number for query.
264  *  @param[out]    PStateEnabled                  Boolean flag return pstate enable.
265  *  @param[in,out] IddVal                         Pstate current value.
266  *  @param[in,out] IddDiv                         Pstate current divisor.
267  *  @param[out]    SwPstateNumber                 Software P-state number.
268  *  @param[in]     StdHeader                      Handle of Header for calling lib functions and services.
269  *
270  */
271 typedef AGESA_STATUS F_CPU_GET_PSTATE_REGISTER_INFO (
272   IN       PSTATE_CPU_FAMILY_SERVICES *PstateCpuServices,
273   IN       UINT32              PState,
274      OUT   BOOLEAN             *PStateEnabled,
275   IN OUT   UINT32              *IddVal,
276   IN OUT   UINT32              *IddDiv,
277      OUT   UINT32              *SwPstateNumber,
278   IN       AMD_CONFIG_PARAMS   *StdHeader
279   );
280
281 /// Reference to a Method.
282 typedef F_CPU_GET_PSTATE_REGISTER_INFO *PF_CPU_GET_PSTATE_REGISTER_INFO;
283
284 /**
285  * Provide the interface to the Pstate dependent Family Specific Services.
286  *
287  * Use the methods or data in this struct to adapt the feature code to a specific cpu family or model (or stepping!).
288  * Each supported Family must provide an implementation for all methods in this interface, even if the
289  * implementation is a CommonReturn().
290  */
291 struct _PSTATE_CPU_FAMILY_SERVICES {
292   UINT16          Revision;                                         ///< Interface version
293   // Public Methods.
294   PF_PSTATE_PSD_IS_NEEDED IsPstatePsdNeeded;                        ///< Method: Family specific call to check if PSD need to be generated.
295   PF_PSTATE_PSD_IS_DEPENDENT IsPstatePsdDependent;                  ///< Method: Family specific call to check if PSD is dependent.
296   PF_PSTATE_SET_TSC_FREQ_SEL CpuSetTscFreqSel;                      ///< Method: Family specific call to set core TscFreqSel.
297   PF_CPU_PSTATE_TRANSITION_LATENCY GetPstateLatency;                ///< Method: Family specific call to get pstate transition latency.
298   PF_CPU_GET_PSTATE_FREQ GetPstateFrequency;                        ///< Method: Family specific call to get the desired P-state's frequency in megahertz.
299   PF_CPU_SET_PSTATE_LEVELING_REG SetPStateLevelReg;                 ///< Method: Family specific call to set the system wide P-state settings on the current core.
300   PF_CPU_GET_PSTATE_POWER GetPstatePower;                           ///< Method: Family specific call to get the desired P-state's rated power in milliwatts.
301   PF_CPU_GET_PSTATE_MAX_STATE GetPstateMaxState;                    ///< Method: Family specific call to get pstate max state number.
302   PF_CPU_GET_PSTATE_REGISTER_INFO GetPstateRegisterInfo;            ///< Method: Family specific call to get pstate register information.
303 };
304
305
306 /*----------------------------------------------------------------------------------------
307  *                          F U N C T I O N S     P R O T O T Y P E
308  *----------------------------------------------------------------------------------------
309  */
310 AGESA_STATUS
311 PStateGatherData (
312   IN       PLATFORM_CONFIGURATION *PlatformConfig,
313   IN OUT   S_CPU_AMD_PSTATE       *PStateStrucPtr,
314   IN       AMD_CONFIG_PARAMS      *StdHeader
315   );
316
317 AGESA_STATUS
318 PStateLeveling (
319   IN OUT   S_CPU_AMD_PSTATE  *PStateStrucPtr,
320   IN       AMD_CONFIG_PARAMS *StdHeader
321   );
322
323 AGESA_STATUS
324 CpuGetPStateLevelStructure (
325      OUT   PSTATE_LEVELING     **PStateBufferPtr,
326   IN       S_CPU_AMD_PSTATE    *CpuAmdPState,
327   IN       UINT32              LogicalSocketNumber,
328   IN       AMD_CONFIG_PARAMS   *StdHeader
329   );
330
331 #endif  // _CPU_PSTATE_TABLES_H_