AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuIoCstate.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA CPU IO Cstate feature support code.
6  *
7  * Contains code that declares the AGESA CPU IO Cstate related APIs
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Feature
12  * @e \$Revision: 44324 $   @e \$Date: 2010-12-22 02:16:51 -0700 (Wed, 22 Dec 2010) $
13  */
14 /*
15  ******************************************************************************
16  *
17  * Copyright (C) 2012 Advanced Micro Devices, Inc.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are met:
22  *     * Redistributions of source code must retain the above copyright
23  *       notice, this list of conditions and the following disclaimer.
24  *     * Redistributions in binary form must reproduce the above copyright
25  *       notice, this list of conditions and the following disclaimer in the
26  *       documentation and/or other materials provided with the distribution.
27  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
28  *       its contributors may be used to endorse or promote products derived
29  *       from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *
42  ******************************************************************************
43  */
44
45 #ifndef _CPU_IO_CSTATE_H_
46 #define _CPU_IO_CSTATE_H_
47
48 /*----------------------------------------------------------------------------------------
49  *          M I X E D   (Definitions And Macros / Typedefs, Structures, Enums)
50  *----------------------------------------------------------------------------------------
51  */
52 //  Forward declaration needed for multi-structure mutual references
53 AGESA_FORWARD_DECLARATION (IO_CSTATE_FAMILY_SERVICES);
54
55 /*----------------------------------------------------------------------------------------
56  *                 D E F I N I T I O N S     A N D     M A C R O S
57  *----------------------------------------------------------------------------------------
58  */
59 // Defines for ACPI C-State Objects
60 #define   CST_NAME__            '_'
61 #define   CST_NAME_C            'C'
62 #define   CST_NAME_S            'S'
63 #define   CST_NAME_T            'T'
64 #define   CST_LENGTH            (CST_BODY_SIZE - 1)
65 #define   CST_NUM_OF_ELEMENTS   0x02
66 #define   CST_COUNT             0x01
67 #define   CST_PKG_LENGTH        (CST_BODY_SIZE - 6) // CST_BODY_SIZE - PkgHeader - Count Buffer
68 #define   CST_PKG_ELEMENTS      0x04
69 #define   CST_SUBPKG_LENGTH     0x14
70 #define   CST_SUBPKG_ELEMENTS   0x0A
71 #define   CST_GDR_LENGTH        0x000C
72 #define   CST_C1_TYPE           0x01
73 #define   CST_C2_TYPE           0x02
74
75 #define   CSD_NAME_D            'D'
76 #define   CSD_COORD_TYPE_HW_ALL 0xFE
77
78 /*----------------------------------------------------------------------------------------
79  *                    T Y P E D E F S     A N D     S T R U C T U R E S
80  *----------------------------------------------------------------------------------------
81  */
82 /* AML code definition */
83
84 /// CST Header
85 typedef struct _CST_HEADER_STRUCT {
86   UINT8   NameOpcode;      ///< Name Opcode
87   UINT8   CstName_a__;     ///< String "_"
88   UINT8   CstName_a_C;     ///< String "C"
89   UINT8   CstName_a_S;     ///< String "S"
90   UINT8   CstName_a_T;     ///< String "T"
91 } CST_HEADER_STRUCT;
92 #define CST_HEADER_SIZE 5
93
94 /// CST Body
95 typedef struct _CST_BODY_STRUCT {
96   UINT8   PkgOpcode;       ///< Package Opcode
97   UINT8   PkgLength;       ///< Package Length
98   UINT8   PkgElements;     ///< Number of Elements
99   UINT8   BytePrefix;      ///< Byte Prefix Opcode
100   UINT8   Count;           ///< Number of Cstate info packages
101   UINT8   PkgOpcode2;      ///< Package Opcode
102   UINT8   PkgLength2;      ///< Package Length
103   UINT8   PkgElements2;    ///< Number of Elements
104   UINT8   BufferOpcode;    ///< Buffer Opcode
105   UINT8   BufferLength;    ///< Buffer Length
106   UINT8   BufferElements;  ///< Number of Elements
107   UINT8   BufferOpcode2;   ///< Buffer Opcode
108   UINT8   GdrOpcode;       ///< Generic Register Descriptor Opcode
109   UINT16  GdrLength;       ///< Descriptor Length
110   UINT8   AddrSpaceId;     ///< Address Space ID
111   UINT8   RegBitWidth;     ///< Register Bit Width
112   UINT8   RegBitOffset;    ///< Register Bit Offset
113   UINT8   AddressSize;     ///< Address Size
114   UINT64  RegisterAddr;    ///< Register Address
115   UINT16  EndTag;          ///< End Tag Descriptor
116   UINT8   BytePrefix2;     ///< Byte Prefix Opcode
117   UINT8   Type;            ///< Type
118   UINT8   WordPrefix;      ///< Word Prefix Opcode
119   UINT16  Latency;         ///< Latency
120   UINT8   DWordPrefix;     ///< Dword Prefix Opcode
121   UINT32  Power;           ///< Power
122 } CST_BODY_STRUCT;
123 #define CST_BODY_SIZE 39
124
125 /// CSD Header
126 typedef struct _CSD_HEADER_STRUCT {
127   UINT8   NameOpcode;     ///< Name Opcode
128   UINT8   CsdName_a__;    ///< String "_"
129   UINT8   CsdName_a_C;    ///< String "C"
130   UINT8   CsdName_a_S;    ///< String "S"
131   UINT8   CsdName_a_D;    ///< String "D"
132 } CSD_HEADER_STRUCT;
133 #define CSD_HEADER_SIZE 5
134
135 /// CSD Body
136 typedef struct _CSD_BODY_STRUCT {
137   UINT8   PkgOpcode;      ///< Package Opcode
138   UINT8   PkgLength;      ///< Package Length
139   UINT8   PkgElements;    ///< Number of Elements
140   UINT8   PkgOpcode2;     ///< Package Opcode
141   UINT8   PkgLength2;     ///< Package Length
142   UINT8   PkgElements2;   ///< Number of Elements
143   UINT8   BytePrefix;     ///< Byte Prefix Opcode
144   UINT8   NumEntries;     ///< Number of Entries
145   UINT8   BytePrefix2;    ///< Byte Prefix Opcode
146   UINT8   Revision;       ///< Revision
147   UINT8   DWordPrefix;    ///< DWord Prefix Opcode
148   UINT32  Domain;         ///< Dependency Domain Number
149   UINT8   DWordPrefix2;   ///< DWord Prefix Opcode
150   UINT32  CoordType;      ///< Coordination Type
151   UINT8   DWordPrefix3;   ///< Dword Prefix Opcode
152   UINT32  NumProcessors;  ///< Number of Processors in the Domain
153   UINT8   DWordPrefix4;   ///< Dword Prefix Opcode
154   UINT32  Index;          ///< Index of C-State entry for which dependency applies
155 } CSD_BODY_STRUCT;
156 #define CSD_BODY_SIZE 30
157
158 /// input for create _CST
159 typedef struct _ACPI_CST_CREATE_INPUT {
160   IO_CSTATE_FAMILY_SERVICES *IoCstateServices;    ///< Family service of IoCstate
161   UINT8                     LocalApicId;    ///< Local Apic for create _CST
162   VOID                      **PstateAcpiBufferPtr;  ///< buffer for fill _CST
163 } ACPI_CST_CREATE_INPUT ;
164
165 /// input for get _CST
166 typedef struct _ACPI_CST_GET_INPUT {
167   IO_CSTATE_FAMILY_SERVICES *IoCstateServices;    ///< Family service of IoCstate
168   PLATFORM_CONFIGURATION    *PlatformConfig;  ///< platform config
169   UINT32                    *CStateAcpiObjSizePtr;  ///< Point to size of _CST
170 } ACPI_CST_GET_INPUT ;
171
172
173 /*---------------------------------------------------------------------------------------*/
174 /**
175  *  Family specific call to check if IO Cstate is supported.
176  *
177  * @param[in]    IoCstateServices   IO Cstate services.
178  * @param[in]    Socket             Zero-based socket number.
179  * @param[in]    StdHeader          Config Handle for library, services.
180  *
181  * @retval       TRUE               IO Cstate is supported.
182  * @retval       FALSE              IO Cstate is not supported.
183  *
184  */
185 typedef BOOLEAN F_IO_CSTATE_IS_SUPPORTED (
186   IN       IO_CSTATE_FAMILY_SERVICES *IoCstateServices,
187   IN       UINT32                    Socket,
188   IN       AMD_CONFIG_PARAMS         *StdHeader
189   );
190
191 /*---------------------------------------------------------------------------------------*/
192 /**
193  *  Family specific call to enable IO Cstate.
194  *
195  * @param[in]    IoCstateServices   IO Cstate services.
196  * @param[in]    EntryPoint         Timepoint designator.
197  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
198  * @param[in]    StdHeader          Config Handle for library, services.
199  *
200  * @return       Family specific error value.
201  *
202  */
203 typedef AGESA_STATUS F_IO_CSTATE_INIT (
204   IN       IO_CSTATE_FAMILY_SERVICES      *IoCstateServices,
205   IN       UINT64                  EntryPoint,
206   IN       PLATFORM_CONFIGURATION  *PlatformConfig,
207   IN       AMD_CONFIG_PARAMS       *StdHeader
208   );
209
210 /*---------------------------------------------------------------------------------------*/
211 /**
212  *  Family specific call to return the size of ACPI C-State Objects
213  *
214  * @param[in]    IoCstateServices   IO Cstate services.
215  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data
216  * @param[in]    StdHeader          Config Handle for library, services.
217  *
218  * @retval       Size of ACPI C-State Objects
219  *
220  */
221 typedef UINT32 F_IO_CSTATE_GET_CST_SIZE (
222   IN       IO_CSTATE_FAMILY_SERVICES   *IoCstateServices,
223   IN       PLATFORM_CONFIGURATION      *PlatformConfig,
224   IN       AMD_CONFIG_PARAMS           *StdHeader
225   );
226
227 /*---------------------------------------------------------------------------------------*/
228 /**
229  *  Family specific call to create ACPI C-State Objects
230  *
231  * @param[in]      IoCstateServices      IO Cstate services.
232  * @param[in]      LocalApicId           Local Apic Id
233  * @param[in, out] PstateAcpiBufferPtr   Pointer to Pstate data buffer
234  * @param[in]      StdHeader             Config Handle for library, services.
235  *
236  */
237 typedef VOID F_IO_CSTATE_CREATE_CST (
238   IN       IO_CSTATE_FAMILY_SERVICES   *IoCstateServices,
239   IN       UINT8                       LocalApicId,
240   IN OUT   VOID                        **PstateAcpiBufferPtr,
241   IN       AMD_CONFIG_PARAMS           *StdHeader
242   );
243
244 /*---------------------------------------------------------------------------------------*/
245 /**
246  *  Family specific call to check whether CSD object should be created.
247  *
248  * @param[in]      IoCstateServices      IO Cstate services.
249  * @param[in]      StdHeader             Config Handle for library, services.
250  *
251  * @retval         TRUE                  CSD Object should be created.
252  * @retval         FALSE                 CSD Object should not be created.
253  *
254  */
255 typedef BOOLEAN F_IO_CSTATE_IS_CSD_GENERATED (
256   IN       IO_CSTATE_FAMILY_SERVICES   *IoCstateServices,
257   IN       AMD_CONFIG_PARAMS           *StdHeader
258   );
259
260 /// Reference to a Method
261 typedef F_IO_CSTATE_IS_SUPPORTED     *PF_IO_CSTATE_IS_SUPPORTED;
262 typedef F_IO_CSTATE_INIT             *PF_IO_CSTATE_INIT;
263 typedef F_IO_CSTATE_GET_CST_SIZE     *PF_IO_CSTATE_GET_CST_SIZE;
264 typedef F_IO_CSTATE_CREATE_CST       *PF_IO_CSTATE_CREATE_CST;
265 typedef F_IO_CSTATE_IS_CSD_GENERATED *PF_IO_CSTATE_IS_CSD_GENERATED;
266
267 /**
268  * Provide the interface to the IO Cstate Family Specific Services.
269  *
270  * Use the methods or data in this struct to adapt the feature code to a specific cpu family or model (or stepping!).
271  * Each supported Family must provide an implementation for all methods in this interface, even if the
272  * implementation is a CommonReturn().
273  */
274 struct _IO_CSTATE_FAMILY_SERVICES {
275   UINT16          Revision;                                  ///< Interface version
276   // Public Methods.
277   PF_IO_CSTATE_IS_SUPPORTED     IsIoCstateSupported;         ///< Method: Family specific call to check if IO Cstate is supported.
278   PF_IO_CSTATE_INIT             InitializeIoCstate;          ///< Method: Family specific call to enable IO Cstate
279   PF_IO_CSTATE_GET_CST_SIZE     GetAcpiCstObj;               ///< Method: Family specific call to return the size of ACPI CST objects.
280   PF_IO_CSTATE_CREATE_CST       CreateAcpiCstObj;            ///< Method: Family specific call to create ACPI CST object
281   PF_IO_CSTATE_IS_CSD_GENERATED IsCsdObjGenerated;           ///< Method: Family specific call to check whether CSD Object should be created.
282 };
283
284 #endif  // _CPU_IO_CSTATE_H_