1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
;/*++
; This file contains an 'Intel Peripheral Driver' and uniquely
; identified as "Intel Reference Module" and is
; licensed for Intel CPUs and chipsets under the terms of your
; license agreement with Intel or your vendor. This file may
; be modified by the user, subject to additional terms of the
; license agreement
;--*/
;
;/*++
;
; Copyright (c) 1999 - 2011 Intel Corporation. All rights reserved
; This software and associated documentation (if any) is furnished
; under a license and may only be used or copied in accordance
; with the terms of the license. Except as permitted by such
; license, no part of this software or documentation may be
; reproduced, stored in a retrieval system, or transmitted in any
; form or by any means without the express written consent of
; Intel Corporation.
;
;
; Module Name:
;
; TxtDxeAp.asm
;
; Abstract:
;
; This file contains DXE AP initialization code.
;
;--*/
.xlist
include txt.inc
include mmx64.inc
.list
_TEXT SEGMENT
EXTERN mAcmBase:QWORD
EXTERN mMcuAddr:QWORD
EXTERN mApMtrrTab:QWORD
EXTERN mApIdt:QWORD
EXTERN mApCr4:QWORD
EXTERN mApSavedIa32ThermInterruptMSR:QWORD
EXTERN mApSavedApicThermalValue:DWORD
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure: DoApInit
;
; Input: AcmBase - Base address of LT BIOS ACM
; McuAddr - Address of MCU patch in flash
;
; Output: None
;
; Registers: All are preserved
;
; Description: Initiatialize AP before GETSEC as per TXT BWG
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
DoApInit PROC FRAME
START_FRAME
MAKE_LOCAL ACM_SIZE_TO_CACHE:QWORD
MAKE_LOCAL ACM_BASE_TO_CACHE:QWORD
MAKE_LOCAL NEXT_MTRR_INDEX:QWORD
MAKE_LOCAL NEXT_MTRR_SIZE:QWORD
; jmp $
END_FRAME
pushf
cli
PUSHA_64
;
; Check uCode was loaded or not
;
mov rcx, MCU_REV_MSR
xor rax, rax
xor rdx, rdx
wrmsr
mov rax, 1
cpuid
mov rcx, MCU_REV_MSR
rdmsr
or rdx, rdx
jnz uCode_loaded
;
; Load uCode update
;
mov rax, 1
cpuid
mov rax, mMcuAddr
lea rax, [rax + SIZEOF MCU] ; RAX -> MCU data (after header)
xor rdx, rdx
mov rcx, MCU_LOAD_MSR ; Trigger to load MCU
wrmsr ; Load MCU
mov rax, 1
cpuid
uCode_loaded:
;-----------------------------------------------------------------------------
;
; Section: Initial RLPs cache requirements
;
; Description: Ensure CR0.CD and CR0.NW are cleared
;
;-----------------------------------------------------------------------------
;
; Clear CR0.CD and CR0.NW
;
mov rax, cr0
and rax, NOT (CR0_CD_MASK + CR0_NW_MASK)
mov cr0, rax
;-----------------------------------------------------------------------------
;
; Section: Clean all MCi_STATUS MSR registers
;
; Description: MCA registers are cleaned
;
;-----------------------------------------------------------------------------
mov rcx, MCG_CAP
rdmsr
movzx rbx, al ; ebx = MCR bank count
xor rax, rax ; Write 0 into all MCi_STATUS registers
xor rdx, rdx
mov rcx, MC0_STATUS
McaErrorCleanLoopStart:
wrmsr
dec rbx
jz @F
add rcx, 4 ; ecx = number of MSRs per bank
jmp McaErrorCleanLoopStart
@@:
mov rcx,IA32_APIC_BASE
rdmsr
and rax,BIT11+BIT10
cmp rax,BIT11+BIT10
jne x2ApicDisabled
mov rcx,EFI_MSR_EXT_XAPIC_LVT_THERM
rdmsr
and eax, NOT (B_INTERRUPT_MASK + B_DELIVERY_MODE + B_VECTOR)
or eax, (B_INTERRUPT_MASK + V_MODE_SMI)
wrmsr
jmp @f
x2ApicDisabled:
; mask thermal LVT
mov rcx, IA32_APIC_BASE
rdmsr ; Get APIC Base
and rax, BASE_ADDR_MASK ; Just need the address
mov edx, [rax+LOCAL_APIC_THERMAL_DEF]
and edx, NOT (B_INTERRUPT_MASK + B_DELIVERY_MODE + B_VECTOR)
or edx, (B_INTERRUPT_MASK + V_MODE_SMI)
mov DWORD PTR [rax+LOCAL_APIC_THERMAL_DEF], edx ;disable DTS SMIs
@@:
POPA_64
popf
leave
ret 0
DoApInit ENDP
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure: ApSaveConfig
;
; Input: None
;
; Output: None
;
; Registers: All are preserved
;
; Description: Saves AP configuration
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
ApSaveConfig PROC FRAME
START_FRAME
END_FRAME
pushf
cli
PUSHA_64
mov rcx, IA32_MTRR_CAP
rdmsr
and rax, 0FFh
shl rax, 1
mov rcx, rax
lea rbx, mApMtrrTab
SaveNextMtrr:
add rcx, IA32_MTRR_PHYSBASE0 - 1
rdmsr
mov QWORD PTR [rbx+0], rax
mov QWORD PTR [rbx+8], rdx
sub rcx, IA32_MTRR_PHYSBASE0 - 1
add rbx, 10h
loop SaveNextMtrr
mov rcx, IA32_MTRR_DEF_TYPE
rdmsr
mov QWORD PTR [rbx+0], rax
mov QWORD PTR [rbx+8], rdx
lea rbx, mApIdt
sidt [rbx]
lea rbx, mApCr4
mov rax, cr4
mov QWORD PTR [rbx], rax
mov rcx,IA32_APIC_BASE
rdmsr
and rax,BIT11+BIT10
cmp rax,BIT11+BIT10
jne x2ApicDisabled
mov rcx,EFI_MSR_EXT_XAPIC_LVT_THERM
rdmsr
lea rbx, mApSavedApicThermalValue
mov DWORD PTR [rbx], eax ; read and save thermal LVT
jmp @f
x2ApicDisabled:
mov rcx, IA32_APIC_BASE
rdmsr ; Get APIC Base
and rax, BASE_ADDR_MASK ; Just need the address
lea rbx, mApSavedApicThermalValue
mov edx, DWORD PTR [rax+LOCAL_APIC_THERMAL_DEF]
mov DWORD PTR [rbx], edx ; read and save thermal LVT
@@:
mov rcx, EFI_MSR_IA32_THERM_INTERRUPT
rdmsr ;
lea rbx, mApSavedIa32ThermInterruptMSR
mov QWORD PTR [rbx+0], rax
mov QWORD PTR [rbx+8], rdx
;disable THERMAL INT
and rax, NOT (BIT0+BIT1+BIT2+BIT4+BIT15+BIT23)
wrmsr
wbinvd
POPA_64
popf
leave
ret 0
ApSaveConfig ENDP
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure: ApRestoreConfig
;
; Input: None
;
; Output: None
;
; Registers: All are preserved
;
; Description: Saves AP configuration
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
ApRestoreConfig PROC FRAME
START_FRAME
END_FRAME
pushf
cli
PUSHA_64
;
; Disable cache
;
mov rax, cr0 ; set CR0:CD and CR0:NE, clear CR0:NW
or rax, CR0_CD_MASK OR CR0_NE_MASK
and rax, NOT CR0_NW_MASK
mov cr0, rax
wbinvd
mov rcx, IA32_MTRR_CAP
rdmsr
and rax, 0FFh
shl rax, 1
mov rcx, rax
lea rbx, mApMtrrTab
RestoreNextMtrr:
add rcx, IA32_MTRR_PHYSBASE0 - 1
mov rax, QWORD PTR [rbx+0]
mov rdx, QWORD PTR [rbx+8]
wrmsr
sub rcx, IA32_MTRR_PHYSBASE0 - 1
add rbx, 10h
loop RestoreNextMtrr
mov rax, QWORD PTR [rbx+0]
mov rdx, QWORD PTR [rbx+8]
mov rcx, IA32_MTRR_DEF_TYPE
wrmsr
lea rbx, mApIdt
lidt FWORD PTR [rbx]
lea rbx, mApCr4
mov rax, QWORD PTR [rbx]
mov cr4, rax
mov rcx, EFI_MSR_IA32_THERM_INTERRUPT
lea rbx, mApSavedIa32ThermInterruptMSR
mov rax, QWORD PTR [rbx+0]
mov rdx, QWORD PTR [rbx+8]
wrmsr
mov rcx,IA32_APIC_BASE
rdmsr
and rax,BIT11+BIT10
cmp rax,BIT11+BIT10
jne x2ApicDisabled
mov rcx,EFI_MSR_EXT_XAPIC_LVT_THERM
lea rbx, mApSavedApicThermalValue
mov eax,DWORD PTR [rbx] ;restore thermal LVT
xor rdx,rdx
wrmsr
jmp @f
x2ApicDisabled:
mov rcx, IA32_APIC_BASE
rdmsr ; Get APIC Base
and rax, BASE_ADDR_MASK ; Just need the address
lea rbx, mApSavedApicThermalValue
mov edx, DWORD PTR [rbx]
mov DWORD PTR [rax+LOCAL_APIC_THERMAL_DEF], edx ; restore thermal LVT
@@:
;
; Enable cache
;
mov rax, cr0
and rax, NOT CR0_CD_MASK
mov cr0, rax
POPA_64
popf
leave
ret 0
ApRestoreConfig ENDP
_TEXT ENDS
END
|