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