2 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
13 * its contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /******************************************************************************
30 * AMD Generic Encapsulated Software Architecture
32 * $Workfile:: GccCar.inc $Revision:: 32932 $
34 * Description: GccCar.inc - AGESA cache-as-RAM setup Include File for GCC complier
36 ******************************************************************************/
40 BSP_STACK_BASE_ADDR = 0x30000 /* Base address for primary cores stack */
41 BSP_STACK_SIZE = 0x10000 /* 64KB for BSP core */
42 CORE0_STACK_BASE_ADDR = 0x80000 /* Base address for primary cores stack */
43 CORE0_STACK_SIZE = 0x4000 /* 16KB for primary cores */
44 CORE1_STACK_BASE_ADDR = 0x40000 /* Base address for AP cores */
45 CORE1_STACK_SIZE = 0x1000 /* 4KB for each AP cores */
47 APIC_BASE_ADDRESS = 0x0000001B
48 APIC_BSC = 8 /* Boot Strap Core */
50 AMD_MTRR_VARIABLE_BASE0 = 0x0200
51 AMD_MTRR_VARIABLE_BASE6 = 0x020C
52 AMD_MTRR_FIX64k_00000 = 0x0250
53 AMD_MTRR_FIX16k_80000 = 0x0258
54 AMD_MTRR_FIX16k_A0000 = 0x0259
55 AMD_MTRR_FIX4k_C0000 = 0x0268
56 AMD_MTRR_FIX4k_C8000 = 0x0269
57 AMD_MTRR_FIX4k_D0000 = 0x026A
58 AMD_MTRR_FIX4k_D8000 = 0x026B
59 AMD_MTRR_FIX4k_E0000 = 0x026C
60 AMD_MTRR_FIX4k_E8000 = 0x026D
61 AMD_MTRR_FIX4k_F0000 = 0x026E
62 AMD_MTRR_FIX4k_F8000 = 0x026F
64 AMD_MTRR_DEFTYPE = 0x02FF
65 WB_DRAM_TYPE = 0x1E /* MemType - memory type */
66 MTRR_DEF_TYPE_EN = 11 /* MtrrDefTypeEn - variable and fixed MTRRs default enabled */
67 MTRR_DEF_TYPE_FIX_EN = 10 /* MtrrDefTypeEn - fixed MTRRs default enabled */
69 HWCR = 0x0C0010015 /* Hardware Configuration */
70 INVD_WBINVD = 0x04 /* INVD to WBINVD conversion */
72 IORR_BASE = 0x0C0010016 /* IO Range Regusters Base/Mask, 2 pairs */
74 TOP_MEM = 0x0C001001A /* Top of Memory */
75 TOP_MEM2 = 0x0C001001D /* Top of Memory2 */
77 LS_CFG = 0x0C0011020 /* Load-Store Configuration */
78 DIS_SS = 28 /* Family 10h,12h,15h:Disable Streng Store functionality */
79 DIS_STREAM_ST = 28 /* Family 14h:DisStreamSt - Disable Streaming Store functionality */
81 IC_CFG = 0x0C0011021 /* Instruction Cache Config Register */
82 IC_DIS_SPEC_TLB_RLD = 9 /* Disable speculative TLB reloads */
83 DIS_IND = 14 /* Family 10-14h:Disable Indirect Branch Predictor */
84 DIS_I_CACHE = 14 /* Family 15h:DisICache - Disable Indirect Branch Predictor */
86 DC_CFG = 0x0C0011022 /* Data Cache Configuration */
87 DC_DIS_SPEC_TLB_RLD = 4 /* Disable speculative TLB reloads */
88 DIS_CLR_WBTOL2_SMC_HIT = 8 /* self modifying code check buffer bit */
89 DIS_HW_PF = 13 /* Hardware prefetches bit */
91 DE_CFG = 0x0C0011029 /* Decode Configuration */
92 CL_FLUSH_SERIALIZE = 23 /* Family 12h,15h: CL Flush Serialization */
94 BU_CFG2 = 0x0C001102A /* Family 10h: Bus Unit Configuration 2 */
95 CU_CFG2 = 0x0C001102A /* Family 15h: Combined Unit Configuration 2 */
96 F10_CL_LINES_TO_NB_DIS = 15 /* ClLinesToNbDis - allows WP code to be cached in L2 */
97 IC_DIS_SPEC_TLB_WR = 35 /* IcDisSpecTlbWr - ITLB speculative writes */
99 CU_CFG3 = 0x0C001102B /* Combined Unit Configuration 3 */
100 COMBINE_CR0_CD = 49 /* Combine CR0.CD for both cores of a compute unit */
103 CR0_PE = 1 # Protection Enable
104 CR0_NW = 29 # Not Write-through
105 CR0_CD = 30 # Cache Disable
106 CR0_PG = 31 # Paging Enable
108 /* CPUID Functions */
111 AMD_CPUID_FMF = 0x80000001 /* Family Model Features information */
112 AMD_CPUID_APIC = 0x80000008 /* Long Mode and APIC info., core count */
114 NB_CFG = 0x0C001001F /* Northbridge Configuration Register */
115 INIT_APIC_ID_CPU_ID_LO = 54 /* InitApicIdCpuIdLo - is core# in high or low half of APIC ID? */
117 MTRR_SYS_CFG = 0x0C0010010 /* System Configuration Register */
118 CHX_TO_DIRTY_DIS = 16 /* ChxToDirtyDis Change to dirty disable */
119 SYS_UC_LOCK_EN = 17 /* SysUcLockEn System lock command enable */
120 MTRR_FIX_DRAM_EN = 18 /* MtrrFixDramEn MTRR fixed RdDram and WrDram attributes enable */
121 MTRR_FIX_DRAM_MOD_EN = 19 /* MtrrFixDramModEn MTRR fixed RdDram and WrDram modification enable */
122 MTRR_VAR_DRAM_EN = 20 /* MtrrVarDramEn MTRR variable DRAM enable */
123 MTRR_TOM2_EN = 21 /* MtrrTom2En MTRR top of memory 2 enable */
125 PERF_CONTROL3 = 0x0C0010003 /* Performance event control three */
126 PERF_CONTROL3_RESERVE_L = 0x00200000 /* Preserve the reserved bits */
127 PERF_CONTROL3_RESERVE_H = 0x0FCF0 /* Preserve the reserved bits */
128 CONFIG_EVENT_L = 0x0F0E2 /* All cores with level detection */
129 CONFIG_EVENT_H = 4 /* Increment count by number of event */
130 /* occured in clock cycle */
131 EVENT_ENABLE = 22 /* Enable the event */
132 PERF_COUNTER3 = 0x0C0010007 /* Performance event counter three */
134 # Local use flags, in upper most byte if ESI
135 FLAG_UNKNOWN_FAMILY = 24 # Signals that the family# of the installed processor is not recognized
136 FLAG_STACK_REENTRY = 25 # Signals that the environment has made a re-entry (2nd) call to set up the stack
137 FLAG_IS_PRIMARY = 26 # Signals that this core is the primary within the comoute unit
139 CR0_MASK = ((1 << CR0_CD) | (1 << CR0_NW))
140 MSR_MASK = ((1 << MTRR_DEF_TYPE_EN)+(1 << MTRR_DEF_TYPE_FIX_EN))
142 /****************************************************************************
144 * CPU MACROS - PUBLIC
146 ****************************************************************************/
155 .macro AMD_CPUID arg0
158 .byte 0x0F, 0x0A2 /* Execute instruction */
160 xchg %ah, %al /* Ext model in al now */
161 rol $0x08, %eax /* Ext model in ah, model in al */
162 and $0x0FFCF, ax /* Keep 23:16, 7:6, 3:0 */
169 /****************************************************************************
171 * AMD_ENABLE_STACK_FAMILY_HOOK Macro - Stackless
173 * Set any family specific controls needed to enable the use of
174 * cache as general storage before main memory is available.
180 ****************************************************************************/
181 .macro AMD_ENABLE_STACK_FAMILY_HOOK
183 AMD_ENABLE_STACK_FAMILY_HOOK_F10
184 AMD_ENABLE_STACK_FAMILY_HOOK_F12
185 AMD_ENABLE_STACK_FAMILY_HOOK_F14
186 AMD_ENABLE_STACK_FAMILY_HOOK_F15
189 /****************************************************************************
191 * AMD_DISABLE_STACK_FAMILY_HOOK Macro - Stackless
193 * Return any family specific controls to their 'standard'
194 * settings for using cache with main memory.
200 ****************************************************************************/
201 .macro AMD_DISABLE_STACK_FAMILY_HOOK
203 AMD_DISABLE_STACK_FAMILY_HOOK_F10
204 AMD_DISABLE_STACK_FAMILY_HOOK_F12
205 AMD_DISABLE_STACK_FAMILY_HOOK_F14
206 AMD_DISABLE_STACK_FAMILY_HOOK_F15
210 /****************************************************************************
212 * GET_NODE_ID_CORE_ID Macro - Stackless
214 * Read family specific values to determine the node and core
215 * numbers for the core executing this code.
220 * SI[7:0] = Core# (0..N, relative to node)
221 * SI[15:8]= Node# (0..N)
222 * SI[23:16]= reserved
223 * SI[24]= flag: 1=Family Unrecognized
224 * SI[25]= flag: 1=Interface re-entry call
225 * SI[26]= flag: 1=Core is primary of compute unit
226 * SI[31:27]= reserved, =0
227 ****************************************************************************/
228 .macro GET_NODE_ID_CORE_ID
232 GET_NODE_ID_CORE_ID_F10
233 GET_NODE_ID_CORE_ID_F12
234 GET_NODE_ID_CORE_ID_F14
235 GET_NODE_ID_CORE_ID_F15
237 * Check for unrecognized Family
239 cmp $-1, %si # Has family (node/core) already been discovered?
240 jnz node_core_exit # Br if yes
242 mov $((1 << FLAG_UNKNOWN_FAMILY)+(1 << FLAG_IS_PRIMARY)), %esi # No, Set error code, Only let BSP continue
244 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
246 bt $APIC_BSC, %eax # Is this the BSC?
247 jc node_core_exit # Br if yes
253 /****************************************************************************
255 ##***************************************************************************
256 #---------------------------------------------------
258 # AMD_ENABLE_STACK_FAMILY_HOOK_F10 Macro - Stackless
260 # Set any family specific controls needed to enable the use of
261 # cache as general storage before main memory is available.
264 # ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
268 # Family 10h requirements (BKDG section 2.3.3):
270 # * MSRC001_0015[INVDWBINVD]=0
271 # * MSRC001_1021[DIS_IND]=1
272 # * MSRC001_1021[DIS_SPEC_TLB_RLD]=1
273 # * MSRC001_1022[DIS_SPEC_TLB_RLD]=1
274 # * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=1
275 # * MSRC001_1022[DIS_HW_PF]=1
276 # * MSRC001_102A[IcDisSpecTlbWr]=1
277 # * MSRC001_102A[ClLinesToNbDis]=1
278 # * No INVD or WBINVD, no exceptions, page faults or interrupts
279 ****************************************************************************/
280 .macro AMD_ENABLE_STACK_FAMILY_HOOK_F10
281 LOCAL fam10_enable_stack_hook_exit
283 AMD_CPUID $CPUID_MODEL
284 shr $20, %eax # AL = cpu extended family
285 cmp $0x01, %al # Is this family 10h?
286 jnz fam10_enable_stack_hook_exit # Br if no
288 mov $DC_CFG, %ecx # MSR:C001_1022
290 bts $DC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative DTLB reloads bit
291 bts $DIS_CLR_WBTOL2_SMC_HIT, %eax # Turn on Disable the self modifying code check buffer bit
292 bts $DIS_HW_PF, %eax # Turn on Disable hardware prefetches bit
295 dec %cx # MSR:C001_1021
297 bts $IC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative TLB reloads bit
298 bts $DIS_IND, %eax # Turn on Disable indirect branch predictor
301 mov $BU_CFG2, %ecx # MSR C001_102A
303 bts $F10_CL_LINES_TO_NB_DIS, %eax # Allow BIOS ROM to be cached in the IC
304 bts $(IC_DIS_SPEC_TLB_WR-32), %edx #Disable speculative writes to the ITLB
307 mov $HWCR, %ecx # MSR C001_0015
309 bt $FLAG_STACK_REENTRY, %esi # Check if stack has already been set
310 jc fam10_skipClearingBit4
311 btr $INVD_WBINVD, %eax # disable INVD -> WBINVD conversion
314 fam10_skipClearingBit4:
315 mov %esi, %eax # load core#
316 or %al, %al # If (BSP)
317 jne fam10_enable_stack_hook_exit
318 mov $PERF_COUNTER3, %ecx # Select performance counter three
319 # to count number of CAR evictions
320 xor %eax, %eax # Initialize the lower part of the counter to zero
321 xor %edx, %edx # Initializa the upper part of the counter to zero
323 mov $PERF_CONTROL3, %ecx # Select the event control three
324 _RDMSR # Get the current setting
325 and $PERF_CONTROL3_RESERVE_L, %eax # Preserve the reserved bits
326 or $CONFIG_EVENT_L, %eax # Set the lower part of event register to
327 # select CAR Corruption occurred by any cores
328 and $PERF_CONTROL3_RESERVE_H, %dx # Preserve the reserved bits
329 or $CONFIG_EVENT_H, %dx # Set the upper part of event register
331 bts $EVENT_ENABLE, %eax # Enable it
334 fam10_enable_stack_hook_exit:
337 /****************************************************************************
339 * AMD_DISABLE_STACK_FAMILY_HOOK_F10 Macro - Stackless
341 * Return any family specific controls to their 'standard'
342 * settings for using cache with main memory.
345 * ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
349 * Family 10h requirements:
351 * * MSRC001_0015[INVD_WBINVD]=1
352 * * MSRC001_1021[DIS_IND]=0
353 * * MSRC001_1021[DIS_SPEC_TLB_RLD]=0
354 * * MSRC001_1022[DIS_SPEC_TLB_RLD]=0
355 * * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=0
356 * * MSRC001_1022[DIS_HW_PF]=0
357 * * MSRC001_102A[IcDisSpecTlbWr]=0
358 * * MSRC001_102A[ClLinesToNbDis]=0
359 *****************************************************************************/
361 .macro AMD_DISABLE_STACK_FAMILY_HOOK_F10
362 LOCAL fam10_disable_stack_hook_exit
364 AMD_CPUID $CPUID_MODEL
365 shr $20, %eax # AL = cpu extended family
366 cmp $0x01, %al # Is this family 10h?
367 jnz fam10_disable_stack_hook_exit # Br if no
369 mov $DC_CFG, %ecx # MSR:C001_1022
371 btr $DC_DIS_SPEC_TLB_RLD, %eax # Enable speculative TLB reloads
372 btr $DIS_CLR_WBTOL2_SMC_HIT, %eax # Allow self modifying code check buffer
373 btr $DIS_HW_PF, %eax # Allow hardware prefetches
376 dec %cx # MSR:C001_1021
378 btr $DIS_IND, %eax # Turn on indirect branch predictor
379 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative TLB reloads
382 mov $BU_CFG2, %ecx # MSR:C001_102A
385 * BTS error if SBIOS `allows WP code to be cached', but copying
386 * ramstage/payloads from ROM to RAM will be very slow if disable it here.
388 * TODO: disable `allows WP code to be cached' after the ROM to RAM copying.
390 // btr $F10_CL_LINES_TO_NB_DIS, %eax # Return L3 to normal mode
391 btr $(IC_DIS_SPEC_TLB_WR-32), %edx #Re-enable speculative writes to the ITLB
394 #--------------------------------------------------------------------------
395 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
396 #--------------------------------------------------------------------------
398 mov $HWCR, %ecx # MSR:0000_0015
400 mov %ax, %bx # Save INVD -> WBINVD bit
401 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion for the invd instruction.
403 wbinvd # Clear the cache tag RAMs
404 mov %bx, %ax # Restore INVD -> WBINVD bit
407 #--------------------------------------------------------------------------
408 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
409 #--------------------------------------------------------------------------
411 mov $PERF_CONTROL3, %ecx # Select the event control three
412 _RDMSR # Retrieve the current value
413 btc $EVENT_ENABLE, %eax # Is event enable, complement it as well
414 jnc fam10_disable_stack_hook_exit # No
415 cmp $CONFIG_EVENT_L, %ax # Is the lower part of event set to capture the CAR Corruption
416 jne fam10_disable_stack_hook_exit # No
417 cmp $CONFIG_EVENT_H, %dl # Is the upper part of event set to capture the CAR Corruption
418 jne fam10_disable_stack_hook_exit # No
419 _WRMSR # Disable the event
421 fam10_disable_stack_hook_exit:
424 /****************************************************************************
426 * GET_NODE_ID_CORE_ID_F10 Macro - Stackless
428 * Read family specific values to determine the node and core
429 * numbers for the core executing this code.
434 * SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
435 *****************************************************************************/
436 .macro GET_NODE_ID_CORE_ID_F10
438 LOCAL node_core_f10_exit
439 LOCAL node_core_f10_AP
441 cmp $-1, %si # Has node/core already been discovered?
442 jnz node_core_f10_exit # Br if yes
444 AMD_CPUID $CPUID_MODEL
445 shr $20, %eax # AL = cpu extended family
446 cmp $0x01, %al # Is this family 10h?
447 jnz node_core_f10_exit # Br if no
449 xor %esi, %esi # Assume BSC, clear flags
450 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
452 bt $APIC_BSC, %eax # Is this the BSC?
453 jnc node_core_f10_AP # Br if no
456 # Enable routing tables on BSP (just in case the HT init code has not yet enabled them)
457 mov $0x8000C06C, %eax # PCI address for D18F0x6C Link Initialization Control Register
462 btr $0, %eax # Set LinkInitializationControl[RouteTblDis] = 0
468 # This is an AP. Routing tables have been enabled by the HT Init process.
469 # Also, the MailBox register was set by the BSP during early init
470 # The Mailbox register content is formatted as follows:
471 # UINT32 Node:4# // The node id of Core's node.
472 # UINT32 Socket:4# // The socket of this Core's node.
473 # UINT32 Module:2# // The internal module number for Core's node.
474 # UINT32 ModuleType:2# // Single Module = 0, Multi-module = 1.
475 # UINT32 :20# // Reserved
477 mov $0x0C0000408, %ecx # Read the family 10h mailbox
478 _RDMSR # MC4_MISC1[63:32]
479 mov %dx, %si # SI = raw mailbox contents (will extract node# from this)
480 shr $24, %ebx # BL = CPUID Fn0000_0001_EBX[LocalApicId]
481 mov %bx, %di # DI = Initial APIC ID (will extract core# from this)
483 AMD_CPUID $AMD_CPUID_APIC #
484 shr $4, %ch # CH = ApicIdSize, #bits in APIC ID that show core#
485 inc %cl # CL = Number of enabled cores in the socket
488 mov $NB_CFG, %ecx # MSR:C001_001F
489 _RDMSR # EDX has InitApicIdCpuIdLo bit
491 mov %bh, %cl # CL = APIC ID size
492 mov $1, %al # Convert APIC ID size to an AND mask
493 shl %cl, %al # AL = 2^APIC ID size
494 dec %al # AL = mask for relative core number
495 xor %ah, %ah # AX = mask for relative core number
496 bt $(INIT_APIC_ID_CPU_ID_LO-32), %edx # InitApicIdCpuIdLo == 1?
497 #.if (!carry?) # Br if yes
499 mov $8, %ch # Calculate core number shift count
500 sub %cl, %ch # CH = core shift count
502 shr %cl, %di # Right justify core number
505 and %ax, %di # DI = socket-relative core number
507 mov %si, %cx # CX = raw mailbox value
508 shr $10, %cx # CL[1:0] = ModuleType or #nodes per socket (0-SCM, 1-MCM)
509 and $3, %cl # Isolate ModuleType
510 xor %bh, %bh # BX = Number of enabled cores in the socket
511 shr %cl, %bx # BX = Number of enabled cores per node
512 xor %dx, %dx # Clear upper word for div
513 mov %di, %ax # AX = socket-relative core number
514 div %bx # DX = node-relative core number
515 movzx %si, %eax # prepare return value, [23:16]=shared Core# (=0, not shared)
516 and $0x000F, %ax # AX = node number
517 shl $8, %ax # [15:8]=node#
518 mov %dl, %al # [7:0]=core# (relative to node)
519 mov %eax, %esi # ESI = return value
521 bts $FLAG_IS_PRIMARY, %esi # all Family 10h cores are primary
526 /*****************************************************************************
528 *****************************************************************************/
529 /*****************************************************************************
531 * AMD_ENABLE_STACK_FAMILY_HOOK_F12 Macro - Stackless
533 * Set any family specific controls needed to enable the use of
534 * cache as general storage before main memory is available.
537 * ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
541 * Family 12h requirements (BKDG section 2.3.3):
542 * The following requirements must be satisfied prior to using the cache as general storage:
543 * * Paging must be disabled.
544 * * MSRC001_0015[INVD_WBINVD]=0
545 * * MSRC001_1020[DIS_SS]=1
546 * * MSRC001_1021[DIS_SPEC_TLB_RLD]=1
547 * * MSRC001_1022[DIS_SPEC_TLB_RLD]=1
548 * * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=1
549 * * MSRC001_1022[DIS_HW_PF]=1
550 * * MSRC001_1029[ClflushSerialize]=1
551 * * No INVD or WBINVD, no exceptions, page faults or interrupts
552 *****************************************************************************/
553 .macro AMD_ENABLE_STACK_FAMILY_HOOK_F12
554 LOCAL fam12_enable_stack_hook_exit
556 AMD_CPUID $CPUID_MODEL
557 shr $20, %eax # AL = cpu extended family
558 cmp $0x03, %al # Is this family 12h?
559 jnz fam12_enable_stack_hook_exit # Br if no
561 mov $DC_CFG, %ecx # MSR:C001_1022
563 bts $DC_DIS_SPEC_TLB_RLD, %eax # Disable speculative DC-TLB reloads
564 bts $DIS_CLR_WBTOL2_SMC_HIT, %eax # Disable self modifying code check buffer
565 bts $DIS_HW_PF, %eax # Disable hardware prefetches
568 dec %cx #IC_CFG # MSR:C001_1021
570 bts $IC_DIS_SPEC_TLB_RLD, %eax # Disable speculative IC-TLB reloads
573 dec %cx #LS_CFG # MSR:C001_1020
575 bts $DIS_SS, %eax # Disabled Streaming store functionality
578 mov $HWCR, %ecx # MSR C001_0015
580 bt $FLAG_STACK_REENTRY , %esi # Check if stack has already been set
581 jc fam12_skipClearingBit4
582 btr $INVD_WBINVD, %eax # disable INVD -> WBINVD conversion
585 fam12_skipClearingBit4:
586 mov $DE_CFG, %ecx # MSR:C001_1029
588 bts $CL_FLUSH_SERIALIZE, %eax # Serialize all CL Flush actions
591 fam12_enable_stack_hook_exit:
594 /*****************************************************************************
596 * AMD_DISABLE_STACK_FAMILY_HOOK_F12 Macro - Stackless
598 * Return any family specific controls to their 'standard'
599 * settings for using cache with main memory.
602 * ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
606 * Family 12h requirements:
608 * * MSRC001_0015[INVD_WBINVD]=1
609 * * MSRC001_1020[DIS_SS]=0
610 * * MSRC001_1021[IC_DIS_SPEC_TLB_RLD]=0
611 * * MSRC001_1022[DC_DIS_SPEC_TLB_RLD]=0
612 * * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=0
613 * * MSRC001_1022[DIS_HW_PF]=0
614 * * MSRC001_1029[ClflushSerialize]=0
615 *****************************************************************************/
616 .macro AMD_DISABLE_STACK_FAMILY_HOOK_F12
617 LOCAL fam12_disable_stack_hook_exit
619 AMD_CPUID $CPUID_MODEL
620 shr $20, %eax # AL = cpu extended family
621 cmp $0x03, %al # Is this family 12h?
622 jnz fam12_disable_stack_hook_exit # Br if no
624 mov $DC_CFG, %ecx # MSR:C001_1022
626 btr $DC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative DC-TLB reloads
627 btr $DIS_CLR_WBTOL2_SMC_HIT, %eax # Enable self modifying code check buffer
628 btr $DIS_HW_PF, %eax # Enable Hardware prefetches
631 dec %cx #IC_CFG # MSR:C001_1021
633 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative IC-TLB reloads
636 dec %cx #LS_CFG # MSR:C001_1020
638 btr $DIS_SS, %eax # Turn on Streaming store functionality
641 mov $DE_CFG, %ecx # MSR:C001_1029
643 btr $CL_FLUSH_SERIALIZE, %eax
646 #--------------------------------------------------------------------------
647 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
648 #--------------------------------------------------------------------------
650 mov $HWCR, %ecx # MSR:0000_0015h
652 mov %ax, %bx # Save INVD -> WBINVD bit
653 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
655 invd # Clear the cache tag RAMs
656 mov %bx, %ax # Restore INVD -> WBINVD bit
659 #--------------------------------------------------------------------------
660 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
661 #--------------------------------------------------------------------------
663 fam12_disable_stack_hook_exit:
666 /*****************************************************************************
668 * GET_NODE_ID_CORE_ID_F12 Macro - Stackless
670 * Read family specific values to determine the node and core
671 * numbers for the core executing this code.
676 * SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
677 *****************************************************************************/
678 .macro GET_NODE_ID_CORE_ID_F12
680 LOCAL node_core_f12_exit
682 cmp $-1, %si # Has node/core already been discovered?
683 jnz node_core_f12_exit # Br if yes
685 AMD_CPUID $CPUID_MODEL
686 shr $20, %eax # AL = cpu extended family
687 cmp $0x03, %al # Is this family 12h?
688 jnz node_core_f12_exit # Br if no
690 shr $24, %ebx # CPUID_0000_0001_EBX[31:24]: initial local APIC physical ID
691 bts $FLAG_IS_PRIMARY, %ebx # all family 12h cores are primary
692 mov %ebx, %esi # ESI = Node#=0, core number
696 /*****************************************************************************
698 *****************************************************************************/
699 /*****************************************************************************
701 * AMD_ENABLE_STACK_FAMILY_HOOK_F14 Macro - Stackless
703 * Set any family specific controls needed to enable the use of
704 * cache as general storage before main memory is available.
707 * ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
711 * Family 14h requirements (BKDG section 2.3.3):
712 * * Paging must be disabled.
713 * * MSRC001_0015[INVD_WBINVD]=0.
714 * * MSRC001_1020[DisStreamSt]=1.
715 * * MSRC001_1021[DIS_SPEC_TLB_RLD]=1. Disable speculative ITLB reloads.
716 * * MSRC001_1022[DIS_HW_PF]=1.
717 * * No INVD or WBINVD, no exceptions, page faults or interrupts
718 *****************************************************************************/
719 .macro AMD_ENABLE_STACK_FAMILY_HOOK_F14
720 LOCAL fam14_enable_stack_hook_exit
722 AMD_CPUID $CPUID_MODEL
723 shr $20, %eax # AL = cpu extended family
724 cmp $0x05, %al # Is this family 14h?
725 jnz fam14_enable_stack_hook_exit # Br if no
727 mov $DC_CFG, %ecx # MSR:C001_1022
729 bts $DIS_HW_PF, %eax # Disable hardware prefetches
732 dec %cx #IC_CFG # MSR:C001_1021
734 bts $IC_DIS_SPEC_TLB_RLD, %eax # Disable speculative TLB reloads
737 dec %cx #LS_CFG # MSR:C001_1020
739 bts $DIS_STREAM_ST, %eax # Disabled Streaming store functionality
742 mov $HWCR, %ecx # MSR C001_0015
744 bt $FLAG_STACK_REENTRY, %esi # Check if stack has already been set
745 jc fam14_skipClearingBit4
746 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
748 fam14_skipClearingBit4: # Keeping this label
750 fam14_enable_stack_hook_exit:
753 /*****************************************************************************
755 * AMD_DISABLE_STACK_FAMILY_HOOK_F14 Macro - Stackless
757 * Return any family specific controls to their 'standard'
758 * settings for using cache with main memory.
761 * ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
765 * Family 14h requirements:
767 * * MSRC001_0015[INVD_WBINVD]=1.
768 * * MSRC001_1020[DisStreamSt]=0.
769 * * MSRC001_1021[DIS_SPEC_TLB_RLD]=0.
770 * * MSRC001_1022[DIS_HW_PF]=0.
771 *****************************************************************************/
772 .macro AMD_DISABLE_STACK_FAMILY_HOOK_F14
773 LOCAL fam14_disable_stack_hook_exit
775 AMD_CPUID $CPUID_MODEL
776 shr $20, %eax # AL = cpu extended family
777 cmp $0x05, %al # Is this family 14h?
778 jnz fam14_disable_stack_hook_exit # Br if no
780 mov $LS_CFG, %ecx # MSR:C001_1020
782 btr $DIS_STREAM_ST, %eax # Turn on Streaming store functionality
785 inc %cx #IC_CFG # MSR:C001_1021
787 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative DC-TLB reloads
790 inc %cx #DC_CFG # MSR:C001_1022
792 btr $DIS_HW_PF, %eax # Turn on hardware prefetches
795 #--------------------------------------------------------------------------
796 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
797 #--------------------------------------------------------------------------
799 mov $HWCR, %ecx # MSR:C001_0015h
801 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
803 invd # Clear the cache tag RAMs
804 bts $INVD_WBINVD, %eax # Turn on Conversion of INVD to WBINVD
807 #--------------------------------------------------------------------------
808 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
809 #--------------------------------------------------------------------------
811 fam14_disable_stack_hook_exit:
814 /*****************************************************************************
816 * GET_NODE_ID_CORE_ID_F14 Macro - Stackless
818 * Read family specific values to determine the node and core
819 * numbers for the core executing this code.
824 * SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
825 *****************************************************************************/
826 .macro GET_NODE_ID_CORE_ID_F14
828 LOCAL node_core_f14_exit
830 cmp $0x-1, %si # Has node/core already been discovered?
831 jnz node_core_f14_exit # Br if yes
833 AMD_CPUID $CPUID_MODEL
834 shr $20, %eax # AL = cpu extended family
835 cmp $0x05, %al # Is this family 14h?
836 jnz node_core_f14_exit # Br if no
838 xor %esi, %esi # Node must be 0
839 bts $FLAG_IS_PRIMARY, %esi # all family 14h cores are primary
840 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
842 bt $APIC_BSC, %eax # Is this the BSC?
843 jc node_core_f14_exit # Br if yes
844 inc %si # Set core to 1
850 /*****************************************************************************
852 *****************************************************************************/
853 /*****************************************************************************
855 * AMD_ENABLE_STACK_FAMILY_HOOK_F15 Macro - Stackless
857 * Set any family specific controls needed to enable the use of
858 * cache as general storage before main memory is available.
861 * ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
865 * Family 15h requirements (BKDG #42301 section 2.3.3):
866 * * Paging must be disabled.
867 * * MSRC001_0015[INVD_WBINVD]=0
868 * * MSRC001_1020[DisSS]=1
869 * * MSRC001_1021[DIS_SPEC_TLB_RLD]=1
870 * * MSRC001_1022[DIS_SPEC_TLB_RLD]=1
871 * * MSRC001_1022[DisHwPf]=1
872 * * No INVD or WBINVD, no exceptions, page faults or interrupts
873 *****************************************************************************/
874 .macro AMD_ENABLE_STACK_FAMILY_HOOK_F15
875 LOCAL fam15_enable_stack_hook_exit
877 AMD_CPUID $CPUID_MODEL
878 shr $20, %eax # AL = cpu extended family
879 cmp $0x06, %al # Is this family 15h?
880 jnz fam15_enable_stack_hook_exit # Br if no
882 bt $FLAG_STACK_REENTRY , %esi # Check if stack has already been set
883 jc fam15_skipClearingBit4
884 mov $HWCR, %ecx # MSR C001_0015
886 btr $INVD_WBINVD, %eax # disable INVD -> WBINVD conversion
889 fam15_skipClearingBit4:
890 mov $LS_CFG, %ecx # MSR:C001_1020
892 bts $DIS_SS, %eax # Turn on Streaming store functionality disabled bit
895 inc %ecx #IC_CFG # MSR:C001_1021
897 bts $IC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative IC-TLB reloads bit
900 inc %ecx #DC_CFG # MSR:C001_1022
902 bts $DC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative DC-TLB reloads bit
903 bts $DIS_HW_PF, %eax # Turn on Disable hardware prefetches bit
906 mov $CU_CFG3, %ecx # MSR:C001_102B
908 btr $(COMBINE_CR0_CD - 32), %edx # Clear CombineCr0Cd bit
911 fam15_enable_stack_hook_exit:
915 /*****************************************************************************
917 * AMD_DISABLE_STACK_FAMILY_HOOK_F15 Macro - Stackless
919 * Return any family specific controls to their 'standard'
920 * settings for using cache with main memory.
923 * ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
927 * Family 15h requirements:
929 * * MSRC001_0015[INVD_WBINVD]=1
930 * * MSRC001_1020[DisSS]=0
931 * * MSRC001_1021[DIS_SPEC_TLB_RLD]=0
932 * * MSRC001_1022[DIS_SPEC_TLB_RLD]=0
933 * * MSRC001_1022[DIS_HW_PF]=0
934 *****************************************************************************/
935 .macro AMD_DISABLE_STACK_FAMILY_HOOK_F15
936 LOCAL fam15_disable_stack_hook_exit
938 AMD_CPUID $CPUID_MODEL
939 mov %eax, %ebx # Save revision info to EBX
940 shr $20, %eax # AL = cpu extended family
941 cmp $0x06, %al # Is this family 15h?
942 jnz fam15_disable_stack_hook_exit # Br if no
944 mov $LS_CFG, %ecx # MSR:C001_1020
945 #.if (ebx != 00600F00h) ; Is this rev A0?
946 cmp $0x00600F00, %ebx
949 btr $DIS_SS, %eax # Turn on Streaming store functionality
952 0: # End workaround for errata 495 and 496
954 inc %ecx #IC_CFG # MSR:C001_1021
956 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative TLB reloads
959 inc %ecx #DC_CFG # MSR:C001_1022
961 btr $DC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative TLB reloads
962 #.if (ebx != 00600F00h) # Is this rev A0?
963 cmp $0x00600F00, %ebx
965 btr $DIS_HW_PF, %eax # Turn on hardware prefetches
966 #.endif # End workaround for erratum 498
969 #--------------------------------------------------------------------------
970 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
971 #--------------------------------------------------------------------------
973 bt $FLAG_IS_PRIMARY, %esi
974 #.if (carry?) # Only clear cache from primary core
976 mov $HWCR, %ecx # MSR:C001_0015h
978 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
980 wbinvd # Clear the cache tag RAMs
981 bts $INVD_WBINVD, %eax # Turn on Conversion of INVD to WBINVD
986 #--------------------------------------------------------------------------
987 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
988 #--------------------------------------------------------------------------
990 mov $CU_CFG3, %ecx # MSR:C001_102B
992 bts $(COMBINE_CR0_CD - 32), %eax # Set CombineCr0Cd bit
995 fam15_disable_stack_hook_exit:
999 /*****************************************************************************
1001 * GET_NODE_ID_CORE_ID_F15 Macro - Stackless
1003 * Read family specific values to determine the node and core
1004 * numbers for the core executing this code.
1009 * SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
1010 *****************************************************************************/
1011 .macro GET_NODE_ID_CORE_ID_F15
1013 LOCAL node_core_f15_exit
1014 LOCAL node_core_f15_AP
1015 LOCAL node_core_f15_shared
1017 cmp $-1, %si # Has node/core already been discovered?
1018 jnz node_core_f15_exit # Br if yes
1020 AMD_CPUID $CPUID_MODEL
1021 shr $20, %eax # AL = cpu extended family
1022 cmp $06, %al # Is this family 15h?
1023 jnz node_core_f15_exit # Br if no
1025 xor %esi, %esi # Assume BSC, clear local flags
1026 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
1028 bt $APIC_BSC, %eax # Is this the BSC?
1029 jnc node_core_f15_AP # Br if no
1032 # Enable routing tables on BSP (just in case the HT init code has not yet enabled them)
1033 mov $0x8000C06C, %eax # PCI address for D18F0x6C Link Initialization Control Register
1038 btr $0, %eax # Set LinkInitializationControl[RouteTblDis] = 0
1040 jmp node_core_f15_shared #
1044 # This is an AP. Routing tables have been enabled by the HT Init process.
1045 # Also, the MailBox register was set by the BSP during early init
1046 # The Mailbox register content is formatted as follows:
1047 # UINT32 Node:4; // The node id of Core's node.
1048 # UINT32 Socket:4; // The socket of this Core's node.
1049 # UINT32 Module:2; // The internal module number for Core's node.
1050 # UINT32 ModuleType:2; // Single Module = 0, Multi-module = 1.
1051 # UINT32 :20; // Reserved
1053 mov $0x0C0000408, %ecx # Read the family 15h mailbox
1054 _RDMSR # MC4_MISC1[63:32]
1055 mov %dx, %si # SI = raw mailbox contents (will extract node# from this)
1056 shr $24, %ebx # BL = CPUID Fn0000_0001_EBX[LocalApicId]
1057 mov %bx, %di # DI = Initial APIC ID (will extract core# from this)
1059 AMD_CPUID $AMD_CPUID_APIC #
1060 shr $4, %ch # CH = ApicIdSize, #bits in APIC ID that show core#
1061 inc %cl # CL = Number of enabled cores in the socket
1065 _RDMSR # EDX has InitApicIdCpuIdLo bit
1067 mov %bh, %cl # CL = APIC ID size
1068 mov $1, %al # Convert APIC ID size to an AND mask
1069 shl %cl, %al # AL = 2^APIC ID size
1070 dec %al # AL = mask for relative core number
1071 xor %ah, %ah # AX = mask for relative core number
1072 bt $(INIT_APIC_ID_CPU_ID_LO-32), %edx # InitApicIdCpuIdLo == 1?
1073 #.if (!carry?) # Br if yes
1075 mov $8, %ch # Calculate core number shift count
1076 sub %cl, %ch # CH = core shift count
1078 shr %cl, %di # Right justify core number
1081 and %ax, %di # DI = socket-relative core number
1083 mov %si, %cx # CX = raw mailbox value
1084 shr $10, %cx # CL[1:0] = ModuleType or #nodes per socket (0-SCM, 1-MCM)
1085 and $3, %cl # Isolate ModuleType
1086 xor %bh, %bh # BX = Number of enabled cores in the socket
1087 shr %cl, %bx # BX = Number of enabled cores per node
1088 xor %dx, %dx # Clear upper word for div
1089 mov %di, %ax # AX = socket-relative core number
1090 div %bx # DX = node-relative core number
1091 movzx %si, %eax # Prepare return value
1092 and $0x000F, %ax # AX = node number
1093 shl $8,%ax # [15:8]=node#
1094 mov %dl, %al # [7:0]=core# (relative to node)
1095 mov %eax, %esi # ESI = node-relative core number
1098 # determine if this core shares MTRRs
1100 node_core_f15_shared:
1101 mov $0x8000C580, %eax # Compute Unit Status
1103 shl $3, %bh # Move node# to PCI Dev# field
1104 add %bh, %ah # Adjust for node number
1108 in %dx, %eax # [3:0]=Enabled# [19:16]=DualCore
1111 mov $0x06, %cx # Use CH as 'first of pair' core#
1115 bt $0, %eax # Is pair enabled?
1118 mov $0x01, %bh # flag core as primary
1119 bt $16, %eax # Is there a 2nd in the pair?
1122 #.break .if (ch == bl) # Does 1st match MyCore#?
1126 xor %bh, %bh # flag core as NOT primary
1127 #.break .if (ch == bl) # Does 2nd match MyCore#?
1131 #.else # No 2nd core
1133 #.break .if (ch == bl) # Does 1st match MyCore#?
1151 #Error - core# didn't match Compute Unit Status content
1152 bts $FLAG_UNKNOWN_FAMILY, %esi
1153 bts $FLAG_IS_PRIMARY, %esi # Set Is_Primary for unknowns
1156 #.if (bh != 0) # Check state of primary for the matched core
1159 bts $FLAG_IS_PRIMARY, %esi # Set shared flag into return value
1167 /*****************************************************************************
1168 * AMD_ENABLE_STACK: Setup a stack
1171 * EBX = Return address (preserved)
1174 * SS:ESP - Our new private stack location
1176 * EAX = AGESA_STATUS
1178 * ECX = Stack size in bytes
1181 * * This routine presently is limited to a max of 64 processor cores
1185 * eax, ecx, edx, edi, esi, ds, es, ss, esp
1189 * Fixed MTRR address allocation to cores:
1190 * The BSP gets 64K of stack, Core0 of each node gets 16K of stack, all other cores get 4K.
1191 * There is a max of 1 BSP, 7 core0s and 56 other cores.
1192 * Although each core has it's own cache storage, they share the address space. Each core must
1193 * be assigned a private and unique address space for its stack. To support legacy systems,
1194 * the stack needs to be within the legacy address space (1st 1Meg). Room must also be reserved
1195 * for the other legacy elements (Interrupt vectors, BIOS ROM, video buffer, etc.)
1197 * 80000h 40000h 00000h
1198 * +----------+----------+----------+----------+----------+----------+----------+----------+
1199 * 64K | | | | | | | | | 64K ea
1200 * ea +----------+----------+----------+----------+----------+----------+----------+----------+
1201 * | MTRR 0000_0250 MTRRfix64K_00000 |
1202 * +----------+----------+----------+----------+----------+----------+----------+----------+
1203 * | 7 , 6 | 5 , 4 | 3 , 2 | 1 , 0 | 0 | | | | <-node
1204 * |7..1,7..1 |7..1,7..1 |7..1,7..1 |7..1,7..1 | 0 | | | | <-core
1205 * +----------+----------+----------+----------+----------+----------+----------+----------+
1207 * C0000h B0000h A0000h 90000h 80000h
1208 * +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1209 *16K | | | | | | | | | | | | | | | | |
1210 * ea +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1211 * | MTRR 0259 MTRRfix16K_A0000 | MTRR 0258 MTRRfix16K_80000 |
1212 * +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1213 * | > Dis|play B|uffer | < | | | | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | | <-node
1214 * | > T| e m |p o r |a r y | B u |f f e |r A |r e a<| 0 | 0 | 0 | 0 | 0 | 0 | 0 | | <-core
1215 * +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1217 * E0000h D0000h C0000h
1218 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1219 * 4K | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 4K ea
1220 * ea +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1221 * | 026B MTRRfix4K_D8000 | 026A MTRRfix4K_D0000 | 0269 MTRRfix4K_C8000 | 0268 MTRRfix4K_C0000 |
1222 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1223 * | | | | | | | | | | | | | | | | | >| V| I| D| E| O| |B |I |O |S | |A |r |e |a<|
1224 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1226 * 100000h F0000h E0000h
1227 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1228 * | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 4K ea
1229 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1230 * | 026F MTRRfix4K_F8000 | 026E MTRRfix4K_F0000 | 026D MTRRfix4K_E8000 | 026C MTRRfix4K_E0000 |
1231 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1232 * | >|MA|IN| B|IO|S |RA|NG|E | | | | | | |< | >|EX|TE|ND|ED| B|IO|S |ZO|NE| | | | | |< |
1233 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1234 *****************************************************************************/
1235 .macro AMD_ENABLE_STACK
1237 # These are local labels. Declared so linker doesn't cause 'redefined label' errors
1240 LOCAL Protected32Mode
1243 # Note that SS:ESP will be default stack. Note that this stack
1244 # routine will not be used after memory has been initialized. Because
1245 # of its limited lifetime, it will not conflict with typical PCI devices.
1246 movd %ebx, %mm0 # Put return address in a safe place
1247 movd %ebp, %mm1 # Save some other user registers
1249 # get node id and core id of current executing core
1250 GET_NODE_ID_CORE_ID # Sets ESI[23:16]=Shared core## SI[15,8]= Node## SI[7,0]= core# (relative to node)
1251 # Note: ESI[31:24] are used for flags: Unrecognized Family, Is_Primary core, Stack already established
1253 # determine if stack is already enabled. We are using the DefType MSR for this determination.
1254 # It is =0 after reset; CAR setup sets it to enable the MTRRs
1256 test $CR0_MASK, %eax # Is cache disabled? (CD & NW bits)
1257 jnz SetupStack # Jump if yes
1258 mov $AMD_MTRR_DEFTYPE, %ecx # MSR:0000_02FF
1260 test $MSR_MASK, %eax # Are the default types enabled? (MTRR_DEF_TYPE_EN + MTRR_DEF_TYPE_FIX_EN)
1261 jz SetupStack # Jump if no
1262 or $FLAG_STACK_REENTRY, %esi # Bit25, indicate stack has already been initialized
1265 # Set node to map the first 16MB to node 0# 0000_0000 to 00FF_FFFF as DRAM
1266 mov %esi, %ebx # Get my Node/Core info
1268 shl $3, %bh # Isolate my node#, match alignment for PCI Dev#
1269 mov $0x8000C144, %eax # D18F1x44:DRAM Base/Limit# N is Base, N+4 is Limit
1271 mov %eax, %ebx # Save PCI address for Base/Limit pair
1276 xor %eax, %eax # Least Significant bit is AD24 so 0 sets mask of 00FF_FFFF (16MB)
1277 out %eax, %dx # DRAM Limit = node0, no interleave
1280 sub $4, %eax # Now point to the Base register
1284 mov $0x00000003, %eax # Set the read and write enable bits
1285 out %eax, %dx # DRAM Base = 0x0000, R/W
1287 AMD_ENABLE_STACK_FAMILY_HOOK
1289 # Init CPU MSRs for our init routines
1290 mov $MTRR_SYS_CFG, %ecx # SYS_CFG
1292 bts $MTRR_FIX_DRAM_MOD_EN, %eax # Turn on modification enable bit
1296 bt $FLAG_STACK_REENTRY, %eax # Is this a 2nd entry?
1297 #.if (!carry?) # On a re-entry, do not clear MTRRs or reset TOM; just reset the stack SS:ESP
1299 bt $FLAG_IS_PRIMARY, %eax # Is this core the primary in a compute unit?
1300 #.if (carry?) # Families using shared groups do not need to clear the MTRRs since that is done at power-on reset
1301 # Note: Relying on MSRs to be cleared to 0's at reset for families w/shared cores
1302 # Clear all variable and Fixed MTRRs for non-shared cores
1304 mov $AMD_MTRR_VARIABLE_BASE0, %ecx
1307 #.while (cl != 10h) # Variable MTRRphysBase[n] and MTRRphysMask[n]
1316 mov $AMD_MTRR_FIX64k_00000, %cx # MSR:0000_0250
1318 mov $AMD_MTRR_FIX16k_80000, %cx # MSR:0000_0258
1320 mov $AMD_MTRR_FIX16k_A0000, %cx # MSR:0000_0259
1322 mov $AMD_MTRR_FIX4k_C0000, %cx # Fixed 4Ks: MTRRfix4K_C0000 to MTRRfix4K_F8000
1332 # Set TOP_MEM (C001_001A) for non-shared cores to 16M. This will be increased at heap init.
1333 # - not strictly needed since the FixedMTRRs take presedence.
1334 mov $(16 * 1024 * 1024), %eax
1335 mov $TOP_MEM, %ecx # MSR:C001_001A
1337 #.endif # End Is_Primary
1338 #.endif # End Stack_ReEntry
1340 # Clear IORRs (C001_0016-19) and TOM2(C001_001D) for all cores
1343 mov $IORR_BASE, %ecx # MSR:C001_0016 - 0019
1353 mov $TOP_MEM2, %ecx # MSR:C001_001D
1356 # setup MTTRs for stacks
1357 # A speculative read can be generated by a speculative fetch mis-aligned in a code zone
1358 # or due to a data zone being interpreted as code. When a speculative read occurs outside a
1359 # controlled region (intentionally used by software), it could cause an unwanted cache eviction.
1360 # To prevent speculative reads from causing an eviction, the unused cache ranges are set
1361 # to UC type. Only the actively used regions (stack, heap) are reflected in the MTRRs.
1362 # Note: some core stack regions will share an MTRR since the control granularity is much
1363 # larger than the allocated stack zone. The allocation algorithm must account for this 'extra'
1364 # space covered by the MTRR when parseling out cache space for the various uses. In some cases
1365 # this could reduce the amount of EXE cache available to a core. see cpuCacheInit.c
1367 # Outcome of this block is that: (Note the MTRR map at the top of the file)
1368 # ebp - start address of stack block
1369 # ebx - [31:16] - MTRR MSR address
1370 # - [15:8] - slot# in MTRR register
1371 # - [7:0] - block size in #4K blocks
1372 # review: ESI[31:24]=Flags; SI[15,8]= Node#; SI[7,0]= core# (relative to node)
1375 mov %si, %ax # Load node, core
1376 #.if (al == 0) # Is a core 0?
1379 #.if (ah == 0) # Is Node 0? (BSP)
1382 # Is BSP, assign a 64K stack
1383 mov $((AMD_MTRR_FIX64k_00000 << 16) + (3 << 8) + (BSP_STACK_SIZE / 0x1000)), %ebx
1384 mov $BSP_STACK_BASE_ADDR, %ebp
1386 #.else # node 1 to 7, core0
1388 # Is a Core0 of secondary node, assign 16K stacks
1389 mov $AMD_MTRR_FIX16k_80000, %bx
1391 mov %ah, %bh # Node# is used as slot#
1392 mov $(CORE0_STACK_SIZE / 0x1000), %bl
1393 mov %ah, %al # Base = (Node# * Size)#
1396 shl $12, %eax # Expand back to full byte count (* 4K)
1397 add $CORE0_STACK_BASE_ADDR, %eax
1401 #.else #core 1 thru core 7
1403 # Is core 1-7 of any node, assign 4K stacks
1404 mov $8, %al # CoreIndex = ( (Node# * 8) ...
1407 add %bl, %al # ... + Core#)#
1409 mov $AMD_MTRR_FIX64k_00000, %bx
1411 mov %al, %bh # Slot# = (CoreIndex / 16) + 4#
1414 mov $(CORE1_STACK_SIZE / 0x1000), %bl
1416 mul %bl # Base = ( (CoreIndex * Size) ...
1418 shl $12, %eax # Expand back to full byte count (* 4K)
1419 add $CORE1_STACK_BASE_ADDR, %eax # ... + Base_Addr)#
1424 # Now set the MTRR. Add this to already existing settings (don't clear any MTRR)
1425 mov $WB_DRAM_TYPE, %edi # Load Cache type in 1st slot
1426 mov %bh, %cl # ShiftCount = ((slot# ...
1427 and $0x03, %cl # ... % 4) ...
1428 shl $0x03, %cl # ... * 8)#
1429 shl %cl, %edi # Cache type is now in correct position
1430 ror $16, %ebx # Get the MTRR address
1432 rol $16, %ebx # Put slot# & size back in BX
1433 _RDMSR # Read-modify-write the MSR
1434 #.if (bh < 4) # Is value in lower or upper half of MSR?
1446 # Enable MTRR defaults as UC type
1447 mov $AMD_MTRR_DEFTYPE, %ecx # MSR:0000_02FF
1448 _RDMSR # Read-modify-write the MSR
1449 bts $MTRR_DEF_TYPE_EN, %eax # MtrrDefTypeEn
1450 bts $MTRR_DEF_TYPE_FIX_EN, %eax # MtrrDefTypeFixEn
1453 # Close the modification window on the Fixed MTRRs
1454 mov $MTRR_SYS_CFG, %ecx # MSR:0C001_0010
1456 bts $MTRR_FIX_DRAM_EN, %eax # MtrrFixDramEn
1457 bts $MTRR_VAR_DRAM_EN, %eax # variable MTRR enable bit
1458 btr $MTRR_FIX_DRAM_MOD_EN, %eax # Turn off modification enable bit
1461 # Enable caching in CR0
1462 mov %cr0, %eax # Enable WT/WB cache
1463 btr $CR0_PG, %eax # Make sure paging is disabled
1464 btr $CR0_CD, %eax # Clear CR0 NW and CD
1468 # Use the Stack Base & size to calculate SS and ESP values
1470 # esi[31:24]=Flags; esi[15,8]= Node#; esi[7,0]= core# (relative to node)
1471 # ebp - start address of stack block
1472 # ebx - [31:16] - MTRR MSR address
1473 # - [15:8] - slot# in MTRR register
1474 # - [7:0] - block size in #4K blocks
1476 mov %ebp, %esp # Initialize the stack pointer
1477 mov %esp, %edi # Copy the stack start to edi
1479 movzx %bx, %ebx # Clear upper ebx, don't need MSR addr anymore
1480 shl $12, %ebx # Make size full byte count (* 4K)
1481 add %ebx, %esp # Set the Stack Pointer as full linear address
1485 # esi[31:24]=Flags; esi[15,8]= Node#; esi[7,0]= core# (relative to node)
1486 # edi - 32b start address of stack block
1487 # ebx - size of stack block
1488 # esp - 32b linear stack pointer
1491 # Determine mode for SS base;
1492 mov %cr0, %ecx # Check for 32-bit protect mode
1494 #.if (!carry?) # PE=0 means real mode
1497 cmp $0x0D000, %cx # Check for CS
1498 jb Protected32Mode # If CS < D000, it is a selector instead of a segment
1499 # alter SS:ESP for 16b Real Mode:
1502 shr $4, %eax # Create a Real Mode segment for ss, ds, es
1507 sub %eax, %edi # Adjust the clearing pointer for Seg:Offset mode
1508 mov %ebx, %esp # Make SP an offset from SS
1512 # Default is to use Protected 32b Mode
1518 # Now that we have set the location and the MTRRs, initialize the cache by
1519 # reading then writing to zero all of the stack area.
1522 # esp - stack pointer
1523 # ebx - size of stack block
1524 # esi[31:24]=Flags; esi[15,8]= Node#; esi[7,0]= core# (relative to node)
1525 # edi - address of start of stack block
1528 ClearTheStack: # Stack base is in SS, stack pointer is in ESP
1529 shr $2, %ebx # ebx = stack block size in dwords
1531 # Check our flags - Don't clear an existing stack
1532 #.if ( !(esi & 0FF000000h)) # Check our flags
1533 test $(1 << FLAG_STACK_REENTRY), %esi
1537 rep lodsl (%esi) # Pre-load the range
1540 mov %edi, %esi # Preserve base for push on stack
1541 rep stosl (%edi) # Clear the range
1542 movl $0x0ABCDDCBA, (%esp) # Put marker in top stack dword
1543 shl $2, %ebx # Put stack size and base
1544 push %ebx # in top of stack
1547 mov %ebx, %ecx # Return size of stack in bytes
1548 xor %eax, %eax # eax = 0 : no error return code
1553 shl $2, %ecx # Return size of stack in bytes
1555 shr $24, %eax # Keep the flags as part of the error report
1556 or $0x40000000, %eax # eax = AGESA_WARNING (Stack has already been set up)
1560 movd %mm0, %ebx # Restore return address
1564 /*****************************************************************************
1565 * AMD_DISABLE_STACK: Destroy the stack inside the cache. This routine
1566 * should only be executed on the BSP
1572 * EAX = AGESA_SUCCESS
1577 * eax, ecx, edx, esp
1578 *****************************************************************************/
1579 .macro AMD_DISABLE_STACK
1581 mov %ebx, %esp # Save return address
1583 # get node/core/flags of current executing core
1584 GET_NODE_ID_CORE_ID # Sets ESI[15,8]= Node#; ESI[7,0]= core# (relative to node)
1586 # Turn on modification enable bit
1587 mov $MTRR_SYS_CFG, %ecx # MSR:C001_0010
1589 bts $MTRR_FIX_DRAM_MOD_EN, %eax # Enable modifications
1592 # Set lower 640K MTRRs for Write-Back memory caching
1593 mov $AMD_MTRR_FIX64k_00000, %ecx
1594 mov $0x1E1E1E1E, %eax
1596 _WRMSR # 0 - 512K = WB Mem
1597 mov $AMD_MTRR_FIX16k_80000, %ecx
1598 _WRMSR # 512K - 640K = WB Mem
1600 # Turn off modification enable bit
1601 mov $MTRR_SYS_CFG, %ecx # MSR:C001_0010
1603 btr $MTRR_FIX_DRAM_MOD_EN, %eax # Disable modification
1606 AMD_DISABLE_STACK_FAMILY_HOOK # Re-Enable 'normal' cache operations