1
2
3
4
5
6
7
8#include <config.h>
9#include <asm/msr-index.h>
10#include <asm/mtrr.h>
11#include <asm/post.h>
12#include <asm/processor.h>
13#include <asm/processor-flags.h>
14
15#define KiB 1024
16
17#define IS_POWER_OF_2(x) (!((x) & ((x) - 1)))
18
19.global car_init
20car_init:
21 post_code(POST_CAR_START)
22
23
24
25
26
27
28check_for_clean_reset:
29 mov $MTRR_DEF_TYPE_MSR, %ecx
30 rdmsr
31 and $(MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN), %eax
32 cmp $0, %eax
33 jz no_reset
34
35 movw $IO_PORT_RESET, %dx
36 movb $(SYS_RST | RST_CPU), %al
37 outb %al, %dx
38
39no_reset:
40 post_code(POST_CAR_SIPI)
41
42
43 mov $fixed_mtrr_list_size, %ebx
44 xor %eax, %eax
45 xor %edx, %edx
46
47clear_fixed_mtrr:
48 add $-2, %ebx
49 movzwl fixed_mtrr_list(%ebx), %ecx
50 wrmsr
51 jnz clear_fixed_mtrr
52
53 post_code(POST_CAR_MTRR)
54
55
56 mov $MTRR_CAP_MSR, %ecx
57 rdmsr
58 movzb %al, %ebx
59 mov $MTRR_PHYS_BASE_MSR(0), %ecx
60 xor %eax, %eax
61 xor %edx, %edx
62
63clear_var_mtrr:
64 wrmsr
65 inc %ecx
66 wrmsr
67 inc %ecx
68 dec %ebx
69 jnz clear_var_mtrr
70
71 post_code(POST_CAR_UNCACHEABLE)
72
73
74 mov $MTRR_DEF_TYPE_MSR, %ecx
75 rdmsr
76
77 and $~(MTRR_DEF_TYPE_MASK | MTRR_DEF_TYPE_EN | \
78 MTRR_DEF_TYPE_FIX_EN), %eax
79 wrmsr
80
81
82
83
84
85
86
87
88
89
90
91 movl $0x80000008, %eax
92 cpuid
93 sub $32, %al
94 movzx %al, %eax
95 xorl %esi, %esi
96 bts %eax, %esi
97 dec %esi
98
99 post_code(POST_CAR_BASE_ADDRESS)
100
101
102
103 mov $MTRR_PHYS_BASE_MSR(0), %ecx
104 mov $CONFIG_DCACHE_RAM_BASE, %eax
105 or $MTRR_TYPE_WRBACK, %eax
106 xor %edx,%edx
107 wrmsr
108
109
110 mov $MTRR_PHYS_MASK(0), %ecx
111 mov $CONFIG_DCACHE_RAM_SIZE, %eax
112 dec %eax
113 not %eax
114 or $MTRR_PHYS_MASK_VALID, %eax
115 movl %esi, %edx
116 wrmsr
117
118
119 mov $MTRR_PHYS_BASE_MSR(0), %ecx
120 mov $CONFIG_DCACHE_RAM_BASE, %eax
121 or $MTRR_TYPE_WRBACK, %eax
122 xor %edx,%edx
123 wrmsr
124
125 mov $MTRR_PHYS_MASK_MSR(0), %ecx
126 mov $(512 * KiB), %eax
127 dec %eax
128 not %eax
129 or $MTRR_PHYS_MASK_VALID, %eax
130 movl %esi, %edx
131 wrmsr
132
133 mov $MTRR_PHYS_BASE_MSR(1), %ecx
134 mov $(CONFIG_DCACHE_RAM_BASE + 512 * KiB), %eax
135 or $MTRR_TYPE_WRBACK, %eax
136 xor %edx,%edx
137 wrmsr
138
139 mov $MTRR_PHYS_MASK_MSR(1), %ecx
140 mov $(256 * KiB), %eax
141 dec %eax
142 not %eax
143 or $MTRR_PHYS_MASK_VALID, %eax
144 movl %esi, %edx
145 wrmsr
146#else
147
148#endif
149 post_code(POST_CAR_FILL)
150
151
152 mov $MTRR_DEF_TYPE_MSR, %ecx
153 rdmsr
154 or $MTRR_DEF_TYPE_EN, %eax
155 wrmsr
156
157
158 mov %cr0, %eax
159 and $~(X86_CR0_CD | X86_CR0_NW), %eax
160 invd
161 mov %eax, %cr0
162
163
164 jmp car_nem
165
166 jmp car_cqos
167
168 jmp car_nem_enhanced
169#else
170
171#endif
172 jmp car_init_ret
173
174fixed_mtrr_list:
175 .word MTRR_FIX_64K_00000_MSR
176 .word MTRR_FIX_16K_80000_MSR
177 .word MTRR_FIX_16K_A0000_MSR
178 .word MTRR_FIX_4K_C0000_MSR
179 .word MTRR_FIX_4K_C8000_MSR
180 .word MTRR_FIX_4K_D0000_MSR
181 .word MTRR_FIX_4K_D8000_MSR
182 .word MTRR_FIX_4K_E0000_MSR
183 .word MTRR_FIX_4K_E8000_MSR
184 .word MTRR_FIX_4K_F0000_MSR
185 .word MTRR_FIX_4K_F8000_MSR
186fixed_mtrr_list_size = . - fixed_mtrr_list
187
188
189.global car_nem
190car_nem:
191
192 mov $MSR_EVICT_CTL, %ecx
193 rdmsr
194 or $0x1, %eax
195 wrmsr
196
197 post_code(0x26)
198
199
200 movl $CONFIG_DCACHE_RAM_BASE, %edi
201 movl $CONFIG_DCACHE_RAM_SIZE, %ecx
202 shr $0x02, %ecx
203 xor %eax, %eax
204 cld
205 rep stosl
206
207 post_code(0x27)
208
209
210 mov $MSR_EVICT_CTL, %ecx
211 rdmsr
212 or $0x2, %eax
213 wrmsr
214
215 post_code(0x28)
216
217 jmp car_init_ret
218
219
220.global car_cqos
221car_cqos:
222
223
224
225
226 mov $0x10, %eax
227 mov $0x2, %ecx
228 cpuid
229 and $0x1f, %eax
230 add $1, %al
231
232 mov $1, %ebx
233 mov %al, %cl
234 shl %cl, %ebx
235 sub $1, %ebx
236
237
238 movd %ebx, %mm3
239
240
241
242
243
244 mov $MSR_PREFETCH_CTL, %ecx
245 rdmsr
246 or $(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
247 wrmsr
248
249
250
251
252
253
254
255#endif
256
257
258 xor %edx, %edx
259 mov $CONFIG_DCACHE_RAM_SIZE, %eax
260 mov $CONFIG_CACHE_QOS_SIZE_PER_BIT, %ecx
261 div %ecx
262 mov %eax, %ecx
263 mov $1, %ebx
264 shl %cl, %ebx
265 sub $1, %ebx
266
267
268 mov $MSR_L2_QOS_MASK(0), %ecx
269 rdmsr
270 mov %ebx, %eax
271 wrmsr
272
273
274 mov $MSR_IA32_PQR_ASSOC, %ecx
275 rdmsr
276 and $~MSR_IA32_PQR_ASSOC_MASK, %edx
277 wrmsr
278
279
280 mov $MSR_L2_QOS_MASK(1), %ecx
281 rdmsr
282
283 mov %ebx, %eax
284 xor $~0, %eax
285
286
287
288
289
290 movd %mm3, %ebx
291 and %ebx, %eax
292 wrmsr
293
294 post_code(0x26)
295
296
297 movl $CONFIG_DCACHE_RAM_BASE, %edi
298 movl $CONFIG_DCACHE_RAM_SIZE, %ecx
299 shr $0x02, %ecx
300 xor %eax, %eax
301 cld
302 rep stosl
303
304 post_code(0x27)
305
306
307 mov $MSR_IA32_PQR_ASSOC, %ecx
308 rdmsr
309 and $~MSR_IA32_PQR_ASSOC_MASK, %edx
310 or $1, %edx
311 wrmsr
312
313
314 mov $MSR_PREFETCH_CTL, %ecx
315 rdmsr
316 and $~(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
317 wrmsr
318
319 post_code(0x28)
320
321 jmp car_init_ret
322
323
324.global car_nem_enhanced
325car_nem_enhanced:
326
327 mov $MSR_EVICT_CTL, %ecx
328 rdmsr
329 or $0x1, %eax
330 wrmsr
331 post_code(0x26)
332
333
334 xorl %edi, %edi
335find_llc_subleaf:
336 movl %edi, %ecx
337 movl $0x04, %eax
338 cpuid
339 inc %edi
340 and $0xe0, %al
341 cmp $0x60, %al
342 jnz find_llc_subleaf
343
344
345
346
347
348 shr $22, %ebx
349 inc %ebx
350
351 mov %bl, %cl
352
353
354
355
356
357
358
359
360
361
362
363
364 movl $0x01, %eax
365
366
367
368
369
370
371
372
373
374
375
376 shl %cl, %eax
377 subl $0x02, %eax
378 movl $MSR_IA32_L3_MASK_1, %ecx
379 xorl %edx, %edx
380 wrmsr
381
382
383
384
385
386
387 mov $MSR_IA32_L3_MASK_2, %ecx
388 mov $0x01, %eax
389 xorl %edx, %edx
390 wrmsr
391
392
393
394
395
396
397
398
399
400 movl $MSR_IA32_PQR_ASSOC, %ecx
401 movl $0x02, %eax
402 xorl %edx, %edx
403 wrmsr
404
405 movl $CONFIG_DCACHE_RAM_BASE, %edi
406 movl $CONFIG_DCACHE_RAM_SIZE, %ecx
407 shr $0x02, %ecx
408 xor %eax, %eax
409 cld
410 rep stosl
411
412
413
414
415
416 movl $MSR_IA32_PQR_ASSOC, %ecx
417 movl $0x01, %eax
418 xorl %edx, %edx
419 wrmsr
420
421 post_code(0x27)
422
423
424
425
426
427 movl $MSR_EVICT_CTL, %ecx
428 rdmsr
429 orl $0x02, %eax
430 wrmsr
431
432 post_code(0x28)
433
434 jmp car_init_ret
435#endif
436
437
438_dt_ucode_base_size:
439
440.globl ucode_base
441ucode_base:
442 .long 0
443.globl ucode_size
444ucode_size:
445 .long 0
446 .long CONFIG_SYS_MONITOR_BASE
447 .long CONFIG_SYS_MONITOR_LEN
448#endif
449