AMD Agesa macro expansion fix
[coreboot.git] / src / vendorcode / amd / agesa / f12 / Proc / CPU / cpuRegisters.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU Register Table Related Functions
6  *
7  * Contains the definition of the CPU CPUID MSRs and PCI registers with BKDG recommended values
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU
12  * @e \$Revision: 45621 $   @e \$Date: 2011-01-19 16:12:16 +0800 (Wed, 19 Jan 2011) $
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_REGISTERS_H_
46 #define _CPU_REGISTERS_H_
47
48 #include "cpuFamRegisters.h"
49 /*
50  *--------------------------------------------------------------
51  *
52  *                      M O D U L E S    U S E D
53  *
54  *---------------------------------------------------------------
55  */
56
57 /*
58  *--------------------------------------------------------------
59  *
60  *                      D E F I N I T I O N S  /  M A C R O S
61  *
62  *---------------------------------------------------------------
63  */
64
65 #define BIT0        0x0000000000000001ull
66 #define BIT1        0x0000000000000002ull
67 #define BIT2        0x0000000000000004ull
68 #define BIT3        0x0000000000000008ull
69 #define BIT4        0x0000000000000010ull
70 #define BIT5        0x0000000000000020ull
71 #define BIT6        0x0000000000000040ull
72 #define BIT7        0x0000000000000080ull
73 #define BIT8        0x0000000000000100ull
74 #define BIT9        0x0000000000000200ull
75 #define BIT10       0x0000000000000400ull
76 #define BIT11       0x0000000000000800ull
77 #define BIT12       0x0000000000001000ull
78 #define BIT13       0x0000000000002000ull
79 #define BIT14       0x0000000000004000ull
80 #define BIT15       0x0000000000008000ull
81 #define BIT16       0x0000000000010000ull
82 #define BIT17       0x0000000000020000ull
83 #define BIT18       0x0000000000040000ull
84 #define BIT19       0x0000000000080000ull
85 #define BIT20       0x0000000000100000ull
86 #define BIT21       0x0000000000200000ull
87 #define BIT22       0x0000000000400000ull
88 #define BIT23       0x0000000000800000ull
89 #define BIT24       0x0000000001000000ull
90 #define BIT25       0x0000000002000000ull
91 #define BIT26       0x0000000004000000ull
92 #define BIT27       0x0000000008000000ull
93 #define BIT28       0x0000000010000000ull
94 #define BIT29       0x0000000020000000ull
95 #define BIT30       0x0000000040000000ull
96 #define BIT31       0x0000000080000000ull
97 #define BIT32       0x0000000100000000ull
98 #define BIT33       0x0000000200000000ull
99 #define BIT34       0x0000000400000000ull
100 #define BIT35       0x0000000800000000ull
101 #define BIT36       0x0000001000000000ull
102 #define BIT37       0x0000002000000000ull
103 #define BIT38       0x0000004000000000ull
104 #define BIT39       0x0000008000000000ull
105 #define BIT40       0x0000010000000000ull
106 #define BIT41       0x0000020000000000ull
107 #define BIT42       0x0000040000000000ull
108 #define BIT43       0x0000080000000000ull
109 #define BIT44       0x0000100000000000ull
110 #define BIT45       0x0000200000000000ull
111 #define BIT46       0x0000400000000000ull
112 #define BIT47       0x0000800000000000ull
113 #define BIT48       0x0001000000000000ull
114 #define BIT49       0x0002000000000000ull
115 #define BIT50       0x0004000000000000ull
116 #define BIT51       0x0008000000000000ull
117 #define BIT52       0x0010000000000000ull
118 #define BIT53       0x0020000000000000ull
119 #define BIT54       0x0040000000000000ull
120 #define BIT55       0x0080000000000000ull
121 #define BIT56       0x0100000000000000ull
122 #define BIT57       0x0200000000000000ull
123 #define BIT58       0x0400000000000000ull
124 #define BIT59       0x0800000000000000ull
125 #define BIT60       0x1000000000000000ull
126 #define BIT61       0x2000000000000000ull
127 #define BIT62       0x4000000000000000ull
128 #define BIT63       0x8000000000000000ull
129
130 /// CPUID related registers
131 #define AMD_CPUID_FMF               0x80000001  // Family Model Features information
132 #define AMD_CPUID_APICID_LPC_BID    0x00000001  // Local APIC ID, Logical Processor Count, Brand ID
133 #define AMD_CPUID_L2L3Cache_L2TLB   0x80000006
134 #define AMD_CPUID_TLB_L1Cache       0x80000005
135 #define AMD_CPUID_APM               0x80000007
136 #define LOCAL_APIC_ID               24
137 #define LOGICAL_PROCESSOR_COUNT     16
138 #define AMD_CPUID_ASIZE_PCCOUNT     0x80000008  // Address Size, Physical Core Count
139
140 /// CPU Logical ID Transfer
141 typedef struct {
142   UINT32         RawId;                         ///< RawID
143   UINT64         LogicalId;                     ///< LogicalID
144 } CPU_LOGICAL_ID_XLAT;
145
146 /// Logical CPU ID Table
147 typedef struct {
148   IN       UINT32  Elements;                    ///< Number of Elements
149   IN       CPU_LOGICAL_ID_XLAT *LogicalIdTable; ///< CPU Logical ID Transfer table Pointer
150 } LOGICAL_ID_TABLE;
151
152 // MSRs
153 // ------------------------
154 #define MCG_CTL_P                   0x00000100              // bit 8  for MCG_CTL_P under MSRR
155 #define MSR_MCG_CAP                 0x00000179
156 #define MSR_MC0_CTL                 0x00000400
157
158 #define MSR_APIC_BAR                0x0000001B
159 #define MSR_PATCH_LEVEL             0x0000008B
160
161 #define CPUID_LONG_MODE_ADDR        0x80000008
162 #define AMD_CPUID_FMF               0x80000001
163
164 #define MSR_EXTENDED_FEATURE_EN     0xC0000080
165 #define MSR_MC_MISC_LINK_THRESHOLD  0xC0000408
166 #define MSR_MC_MISC_L3_THRESHOLD    0xC0000409
167 #define MSR_PATCH_LOADER            0xC0010020
168
169 /// Patch Loader Register
170 typedef struct {
171   UINT64 PatchBase:32;                ///< Linear address of patch header address block
172   UINT64 SBZ:32;                      ///< Should be zero
173 } PATCH_LOADER_MSR;
174
175 #define MSR_SYS_CFG                 0xC0010010      // SYSCFG - F15 Shared
176 #define MSR_TOM2                    0xC001001D      // TOP_MEM2 - F15 Shared
177 #define MSR_MC0_CTL_MASK            0xC0010044      // MC0 Control Mask
178 #define MSR_MC1_CTL_MASK            0xC0010045      // MC1 Control Mask
179 #define MSR_MC2_CTL_MASK            0xC0010046      // MC2 Control Mask
180 #define MSR_MC4_CTL_MASK            0xC0010048      // MC4 Control Mask
181
182 #define MSR_CPUID_FEATS             0xC0011004      // CPUID Features
183 #define MSR_CPUID_EXT_FEATS         0xC0011005      // CPUID Extended Features
184 #define MSR_HWCR                    0xC0010015
185 #define MSR_NB_CFG                  0xC001001F      // NB Config
186 #define ENABLE_CF8_EXT_CFG          0x00004000      // [46]
187 #define INIT_APIC_CPUID_LO          0x00400000      // [54]
188 #define MSR_LS_CFG                  0xC0011020
189 #define MSR_IC_CFG                  0xC0011021      // ICache Config - F15 Shared
190 #define MSR_DC_CFG                  0xC0011022
191 #define MSR_ME_CFG                  0xC0011029
192 #define MSR_BU_CFG                  0xC0011023
193 #define MSR_CU_CFG                  0xC0011023      // F15 Shared
194 #define MSR_DE_CFG                  0xC0011029      // F15 Shared
195 #define MSR_BU_CFG2                 0xC001102A
196 #define MSR_CU_CFG2                 0xC001102A      // F15 Shared
197 #define MSR_BU_CFG3                 0xC001102B
198 #define MSR_CU_CFG3                 0xC001102B      // F15 Shared
199 #define MSR_LS_CFG2                 0xC001102D
200 #define MSR_IBS_OP_DATA3            0xC0011037
201 #define MSR_C001_1070               0xC0011070      // F15 Shared
202
203
204 #define MSR_CPUID_NAME_STRING0      0xC0010030      // First CPUID namestring register
205 #define MSR_CPUID_NAME_STRING1      0xC0010031
206 #define MSR_CPUID_NAME_STRING2      0XC0010032
207 #define MSR_CPUID_NAME_STRING3      0xC0010033
208 #define MSR_CPUID_NAME_STRING4      0xC0010034
209 #define MSR_CPUID_NAME_STRING5      0xC0010035      // Last CPUID namestring register
210 #define MSR_MMIO_Cfg_Base           0xC0010058      // MMIO Configuration Base Address Register
211 #define MSR_BIST                    0xC0010060      // BIST Results register
212 #define MSR_OSVW_ID_Length          0xC0010140
213 #define MSR_OSVW_Status             0xC0010141
214 #define MSR_PERF_CONTROL3           0xC0010003      // Perfromance control register number 3
215 #define MSR_PERF_COUNTER3           0xC0010007      // Performance counter register number 3
216 #define PERF_RESERVE_BIT_MASK       0x030FFFDFFFFF  // Mask of the Performance control Reserve bits
217 #define PERF_CAR_CORRUPTION_EVENT   0x040040F0E2    // Configure the controller to capture the
218                                                     // CAR Corruption
219 // FUNC_0 registers
220 // ----------------
221 #define HT_LINK_FREQ_OFFSET         8           // Link HT Frequency from capability base
222 #define HT_LINK_CONTROL_REG_OFFSET  4
223 #define HT_LINK_TYPE_REG_OFFSET     0x18
224 #define HT_LINK_EXTENDED_FREQ       0x1C
225 #define HT_LINK_HOST_CAP_MAX        0x20        // HT Host Capability offsets are less than its size.
226 #define HT_CAPABILITIES_POINTER     0x34
227 #define NODE_ID                     0x60
228 #define HT_INIT_CTRL                0x6C
229 #define HT_INIT_CTRL_REQ_DIS        0x02        // [1] = ReqDis
230 #define HT_INIT_COLD_RST_DET        BIT4
231 #define HT_INIT_BIOS_RST_DET_0      BIT5
232 #define HT_INIT_BIOS_RST_DET_1      BIT9
233 #define HT_INIT_BIOS_RST_DET_2      BIT10
234 #define HT_INIT_BIOS_RST_DET        BIT9 | BIT10
235 #define HT_TRANS_CTRL               0x68
236 #define HT_TRANS_CTRL_CPU1_EN       0x00000020  // [5] = CPU1 Enable
237 #define HT_LINK_CONTROL_0           0x84
238 #define HT_LINK_FREQ_0              0x88        // Link HT Frequency
239 #define EXTENDED_NODE_ID            0x160
240 #define ECS_HT_TRANS_CTRL           0x168
241 #define ECS_HT_TRANS_CTRL_CPU2_EN   0x00000001  // [0] = CPU2 Enable
242 #define ECS_HT_TRANS_CTRL_CPU3_EN   0x00000002  // [1] = CPU3 Enable
243 #define ECS_HT_TRANS_CTRL_CPU4_EN   0x00000004  // [2] = CPU4 Enable
244 #define ECS_HT_TRANS_CTRL_CPU5_EN   0x00000008  // [3] = CPU5 Enable
245
246 #define CORE_CTRL                   0x1DC
247 #define CORE_CTRL_CORE1_EN          0x00000002
248 #define CORE_CTRL_CORE2_EN          0x00000004
249 #define CORE_CTRL_CORE3_EN          0x00000008
250 #define CORE_CTRL_CORE4_EN          0x00000010
251 #define CORE_CTRL_CORE5_EN          0x00000020
252 #define CORE_CTRL_CORE6_EN          0x00000040
253 #define CORE_CTRL_CORE7_EN          0x00000080
254
255 // FUNC_3 registers
256 // ----------------
257 #define HARDWARE_THERMAL_CTRL_REG       0x64
258 #define SOFTWARE_THERMAL_CTRL_REG       0x68
259
260 #define ACPI_PSC_0_REG                  0x80    // ACPI Power State Control Registers
261 #define ACPI_PSC_4_REG                  0x84
262
263 #define NB_CFG_HIGH_REG                 0x8C
264 #define POWER_CTRL_MISCELLANEOUS_REG    0xA0
265 #define CLOCK_POWER_TIMING_CTRL2_REG    0xDC
266 #define NORTH_BRIDGE_CAPABILITIES_REG   0xE8
267 #define MULTI_NODE_CPU                  29
268 #define CPUID_FMR                       0xFC    // Family / Model registers
269 #define DOWNCORE_CTRL                   0x190   // Downcore Control Register
270
271 #define LINK_TO_XCS_TOKEN_COUNT_REG_3X148 0x148
272 #define REG_HT4_PHY_OFFSET_BASE_4X180    0x180
273 #define REG_HT4_PHY_DATA_PORT_BASE_4X184 0x184
274
275 #define HTPHY_OFFSET_MASK         0xE00001FF
276 #define HTPHY_WRITE_CMD           0x40000000
277 #define HTPHY_IS_COMPLETE_MASK    0x80000000
278 #define HTPHY_DIRECT_MAP          0x20000000
279 #define HTPHY_DIRECT_OFFSET_MASK  0xE000FFFF
280
281 // FUNC_5 registers
282 // ----------------
283 #define COMPUTE_UNIT_STATUS       0x80
284 #define NORTH_BRIDGE_CAPABILITIES_2_REG  0x84
285
286
287 // Misc. defines.
288 #define PCI_DEV_BASE    24
289
290 #define CPU_STEPPING    0x0000000F
291 #define CPU_MODEL       0x000000F0
292 #define CPU_EMODEL      0x000F0000
293 #define CPU_EFAMILY     0x00F00000
294 #define CPU_FMS_MASK    CPU_EFAMILY | CPU_EMODEL | CPU_MODEL | CPU_STEPPING
295
296 #define HTPHY_SELECT        2
297 #define PCI_SELECT          1
298 #define MSR_SELECT          0
299
300 #define LOGICAL_ID      1
301 #define F_SCHEME        0
302 #define DR_SCHEME       1
303 #define GR_SCHEME       2
304
305 #define DR_NO_STRING        0
306 #define DR_SOCKET_C32       5
307 #define DR_SOCKET_ASB2      4
308 #define DR_SOCKET_G34       3
309 #define DR_SOCKET_S1G3      2
310 #define DR_SOCKET_S1G4      2
311 #define DR_SOCKET_AM3       1
312 #define DR_SOCKET_1207      0
313 #define LN_SOCKET_FM1       2
314 #define LN_SOCKET_FS1       1
315 #define LN_SOCKET_FP1       0
316 #define ON_SOCKET_FT1       0
317 #define OR_SOCKET_AM3       1
318 #define OR_SOCKET_G34       3
319 #define OR_SOCKET_C32       5
320 #define SOCKET_IGNORE       0xF
321
322 #define LAPIC_BASE_ADDR_MASK    0x0000FFFFFFFFF000ull
323 #define APIC_EXT_BRDCST_MASK    0x000E0000
324 #define APIC_ENABLE_BIT         0x00000800
325 #define LOCAL_APIC_ADDR         0xFEE00000
326 #define INT_CMD_REG_LO          0x300
327 #define INT_CMD_REG_HI          0x310
328 #define REMOTE_MSG_REG          0x380
329 #define REMOTE_READ_REG         0xC0
330 #define APIC_ID_REG             0x20
331 #define APIC20_ApicId           24
332 #define CMD_REG_TO_READ_DATA    0x338
333
334 #define MAX_CORE_ID_SIZE 8
335 #define MAX_CORE_ID_MASK ((1 << MAX_CORE_ID_SIZE) - 1)
336
337 /*-------------------------
338  * Default definitions
339  *-------------------------
340  */
341 #define DOWNCORE_MASK_SINGLE    0xFFFFFFFE
342 #define DOWNCORE_MASK_DUAL      0xFFFFFFFC
343 #define DOWNCORE_MASK_TRI       0xFFFFFFF8
344 #define DOWNCORE_MASK_FOUR      0xFFFFFFF0
345 #define DOWNCORE_MASK_FIVE      0xFFFFFFE0
346 #define DOWNCORE_MASK_SIX       0xFFFFFFC0
347 #define DOWNCORE_MASK_DUAL_COMPUTE_UNIT  0xFFFFFFFA
348 #define DOWNCORE_MASK_TRI_COMPUTE_UNIT   0xFFFFFFEA
349 #define DOWNCORE_MASK_FOUR_COMPUTE_UNIT  0xFFFFFFAA
350
351 #define DELIVERY_STATUS             BIT13
352 #define REMOTE_READ_STAT_MASK       0x00030000
353 #define REMOTE_DELIVERY_PENDING     0x00010000
354 #define REMOTE_DELIVERY_DONE        0x00020000
355
356 /*
357  * --------------------------------------------------------------------------------------
358  *
359  *             D E F I N E S    /   T Y P E D E F S   /  S T R U C T U R E S
360  *
361  * --------------------------------------------------------------------------------------
362  */
363
364 /// CpuEarly param type
365 typedef struct {
366   IN       UINT8                  MemInitPState;        ///< Pstate value during memory initial
367   IN       PLATFORM_CONFIGURATION PlatformConfig;       ///< Runtime configurable user options
368 } AMD_CPU_EARLY_PARAMS;
369
370 /// Enum - Will be used to access each structure
371 ///        related to each CPU family
372 typedef enum {
373   REVF,                                       ///< NPT, RevF
374   REVG,                                       ///< NPT, RevG
375   DEERHOUND,                                  ///< Family 10h, Deerhound
376   GRIFFIN                                     ///< Family 11h, Griffin
377 } CPU_FAMILY;
378
379 /// CPUID
380 typedef enum {
381   REG_EAX,                                    ///< EAX
382   REG_EBX,                                    ///< EBX
383   REG_ECX,                                    ///< ECX
384   REG_EDX                                     ///< EDX
385 } CPUID_REG;
386
387 #endif      // _CPU_REGISTERS_H_
388