AMD Agesa macro expansion fix
[coreboot.git] / src / vendorcode / amd / agesa / f12 / Proc / CPU / cpuEarlyInit.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU Reset API, and related functions and structures.
6  *
7  * Contains code that initialized the CPU after early reset.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU
12  * @e \$Revision: 44324 $   @e \$Date: 2010-12-22 17:16:51 +0800 (Wed, 22 Dec 2010) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (c) 2011, 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 #ifndef _CPU_EARLY_INIT_H_
46 #define _CPU_EARLY_INIT_H_
47
48
49 /*---------------------------------------------------------------------------------------
50  *          M I X E D   (Definitions And Macros / Typedefs, Structures, Enums)
51  *---------------------------------------------------------------------------------------
52  */
53 AGESA_FORWARD_DECLARATION (CPU_CORE_LEVELING_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 //----------------------------------------------------------------------------
60 //                         CPU BRAND ID TYPEDEFS, STRUCTURES, ENUMS
61 //
62 //----------------------------------------------------------------------------
63 #define CPU_BRAND_ID_LENGTH     48            // Total number of characters supported
64 #define LOW_NODE_DEVICEID       24
65 #define NB_CAPABILITIES         0xE8          //Function 3 Registers
66 //----------------------------------------------------------------------------
67 //                         CPU MICROCODE PATCH TYPEDEFS, STRUCTURES, ENUMS
68 //
69 //----------------------------------------------------------------------------
70 /* All lengths are in bytes */
71 #define MICROCODE_TRIADE_SIZE           28
72 #define MICROCODE_HEADER_LENGTH         64
73
74 /* Offsets in UCODE PATCH Header */
75 /* Note: Header is 64 bytes      */
76 #define DATE_CODE_OFFSET                0   // 4 bytes
77 #define PATCH_ID                        4   // 4 bytes
78 #define MICROCODE_PATH_DATA_ID          8   // 2 bytes
79 #define MICROCODE_PATCH_DATA_LENGTH     10  // 1 byte
80 #define MICROCODE_PATCH_DATA_CHECKSUM   12  // 4 bytes
81 #define CHIPSET_1_DEVICE_ID             16  // 4 bytes
82 #define CHIPSET_2_DEVICE_ID             20  // 4 bytes
83 #define PROCESSOR_REV_ID                24  // 2 bytes
84 #define CHIPSET_1_REV_ID                26  // 1 byte
85 #define CHIPSET_2_REV_ID                27  // 1 byte
86
87 #define MICROCODE_PATCH_2K_SIZE    2048
88 #define MICROCODE_PATCH_4K_SIZE    4096
89 /*---------------------------------------------------------------------------------------
90  *               T Y P E D E F S,   S T R U C T U R E S,    E N U M S
91  *---------------------------------------------------------------------------------------
92  */
93 //----------------------------------------------------------------------------
94 //                         CPU BRAND ID TYPEDEFS, STRUCTURES, ENUMS
95 //
96 //----------------------------------------------------------------------------
97 /// A structure representing BrandId[15:0] from
98 /// CPUID Fn8000_0001_EBX
99 typedef struct {
100   UINT8           String1:4;   ///< An index to a string value used to create the name string
101   UINT8           String2:4;   ///< An index to a string value used to create the name string
102   UINT8           Page:1;      ///< An index to the appropriate page for the String1, String2, and Model values
103   UINT8           Model:7;     ///< A field used to create the model number in the name string
104   UINT8           Socket:4;    ///< Specifies the package type
105   UINT8           Cores:4;     ///< Identifies how many physical cores are present
106 } AMD_CPU_BRAND_DATA;
107
108 /// A structure containing string1 and string2 values
109 /// as well as information pertaining to their usage
110 typedef struct {
111   IN       UINT8  Cores;              ///< Appropriate number of physical cores
112   IN       UINT8  Page;               ///< This string's page number
113   IN       UINT8  Index;              ///< String index
114   IN       UINT8  Socket;             ///< Package type information
115   IN       CONST CHAR8 *Stringstart;  ///< The literal string
116   IN       UINT8  Stringlength;       ///< Number of characters in the string
117 } AMD_CPU_BRAND;
118
119 /// An entire CPU brand table.
120 typedef struct {
121   UINT8 NumberOfEntries;        ///< The number of entries in the table.
122   CONST AMD_CPU_BRAND  *Table;  ///< The table entries.
123 } CPU_BRAND_TABLE;
124
125 //----------------------------------------------------------------------------
126 //                         CPU MICROCODE PATCH TYPEDEFS, STRUCTURES, ENUMS
127 //
128 //----------------------------------------------------------------------------
129 /// Microcode patch field definitions
130 typedef struct {
131   UINT32   DateCode;                   ///< Date of patch creation
132   UINT32   PatchID;                    ///< Patch level
133   UINT16   MicrocodePatchDataID;       ///< Internal use only
134   UINT8    MicrocodePatchDataLength;   ///< Internal use only
135   UINT8    InitializationFlag;         ///< Internal use only
136   UINT32   MicrocodePatchDataChecksum; ///< Doubleword sum of data block
137   UINT32   Chipset1DeviceID;           ///< Device ID of 1st HT device to match
138   UINT32   Chipset2DeviceID;           ///< Device ID of 2nd HT device to match
139   UINT16   ProcessorRevisionID;        ///< Equivalent ID
140   UINT8    Chipset1RevisionID;         ///< Revision level of 1st HT device to match
141   UINT8    Chipset2RevisionID;         ///< Revision level of 2nd HT device to match
142   UINT8    BiosApiRevision;            ///< BIOS INT 15 API revision required
143   UINT8    Reserved1[3];               ///< Reserved
144   UINT32   MatchRegister0;             ///< Internal use only
145   UINT32   MatchRegister1;             ///< Internal use only
146   UINT32   MatchRegister2;             ///< Internal use only
147   UINT32   MatchRegister3;             ///< Internal use only
148   UINT32   MatchRegister4;             ///< Internal use only
149   UINT32   MatchRegister5;             ///< Internal use only
150   UINT32   MatchRegister6;             ///< Internal use only
151   UINT32   MatchRegister7;             ///< Internal use only
152   UINT8    PatchDataBlock[896];        ///< Raw patch data
153   UINT8    Reserved2[896];             ///< Reserved
154   UINT8    X86CodePresent;             ///< Boolean to determine if executable code exists
155   UINT8    X86CodeEntry[191];          ///< Code to execute if X86CodePresent != 0
156 } MICROCODE_PATCH;
157
158 /// Two kilobyte array containing the raw
159 /// microcode patch binary data
160 typedef struct {
161   IN       UINT8   MicrocodePatches[MICROCODE_PATCH_2K_SIZE];  ///< 2k UINT8 elements
162 } MICROCODE_PATCHES;
163
164 /// Four kilobyte array containing the raw
165 /// microcode patch binary data
166 typedef struct {
167   IN       UINT8   MicrocodePatches[MICROCODE_PATCH_4K_SIZE];  ///< 4k UINT8 elements
168 } MICROCODE_PATCHES_4K;
169
170 /**
171  *  Set down core register
172  *
173  *  @CpuServiceInstances
174  *
175  * @param[in]      FamilySpecificServices  The current Family Specific Services.
176  * @param[in]      Socket        Socket ID.
177  * @param[in]      Module        Module ID in socket.
178  * @param[in]      LeveledCores  Number of core.
179  * @param[in]      CoreLevelMode Core level mode.
180  * @param[in]      StdHeader     Header for library and services.
181  *
182  * @retval         TRUE          Down Core register is updated.
183  * @retval         FALSE         Down Core register is not updated.
184  */
185 typedef BOOLEAN (F_CPU_SET_DOWN_CORE_REGISTER) (
186   IN       CPU_CORE_LEVELING_FAMILY_SERVICES  *FamilySpecificServices,
187   IN       UINT32 *Socket,
188   IN       UINT32 *Module,
189   IN       UINT32 *LeveledCores,
190   IN       CORE_LEVELING_TYPE CoreLevelMode,
191   IN       AMD_CONFIG_PARAMS *StdHeader
192   );
193
194 /// Reference to a method
195 typedef F_CPU_SET_DOWN_CORE_REGISTER *PF_CPU_SET_DOWN_CORE_REGISTER;
196
197 /**
198  * Provide the interface to the Core Leveling Family Specific Services.
199  *
200  * Use the methods or data in this struct to adapt the feature code to a specific cpu family or model (or stepping!).
201  * Each supported Family must provide an implementation for all methods in this interface, even if the
202  * implementation is a CommonReturn().
203  */
204 struct _CPU_CORE_LEVELING_FAMILY_SERVICES {             // See Forward Declaration above
205   UINT16          Revision;                             ///< Interface version
206   // Public Methods.
207   PF_CPU_SET_DOWN_CORE_REGISTER SetDownCoreRegister;    ///< Method: Set down core register.
208 };
209
210 //----------------------------------------------------------------------------
211 //                         CPU PERFORM EARLY INIT ON CORE
212 //
213 //----------------------------------------------------------------------------
214 /// Flag definition.
215 #define PERFORM_EARLY_WARM_RESET    0x1        // bit 0 --- the related function needs to be run if it's warm reset
216 #define PERFORM_EARLY_COLD_BOOT     0x2        // bit 1 --- the related function needs to be run if it's cold boot
217
218 #define PERFORM_EARLY_ANY_CONDITION 0xFFFFFFFF // the related function always needs to be run
219 /*---------------------------------------------------------------------------------------
220  *                        F U N C T I O N    P R O T O T Y P E
221  *---------------------------------------------------------------------------------------
222  */
223
224 //                   These are   P U B L I C   functions, used by IBVs
225 AGESA_STATUS
226 AmdCpuEarly (
227   IN       AMD_CONFIG_PARAMS      *StdHeader,
228   IN       PLATFORM_CONFIGURATION *PlatformConfig
229   );
230
231 //                   These are   P U B L I C   functions, used by AGESA
232 VOID
233 SetBrandIdRegisters (
234   IN OUT   AMD_CONFIG_PARAMS *StdHeader
235   );
236
237 AGESA_STATUS
238 PmInitializationAtEarly (
239   IN       AMD_CPU_EARLY_PARAMS *CpuEarlyParams,
240   IN       AMD_CONFIG_PARAMS    *StdHeader
241   );
242
243 BOOLEAN
244 LoadMicrocodePatch (
245   IN OUT   AMD_CONFIG_PARAMS *StdHeader
246   );
247 #endif  // _CPU_EARLY_INIT_H_
248