- Moved hlt() to it's own header.
[coreboot.git] / src / cpu / k8 / earlymtrr.inc
1 #include <cpu/k8/mtrr.h>
2
3
4         /* Save off the BIST value */
5         movl    %eax, %ebp
6
7 /* The fixed and variable MTRRs are powered-up with random values, clear them to
8  * MTRR_TYPE_UNCACHEABLE for safty reason 
9  */
10
11 earlymtrr_start:
12         xorl    %eax, %eax                      # clear %eax and %edx
13         xorl    %edx, %edx                      #
14         movl    $fixed_mtrr_msr, %esi
15
16 clear_fixed_var_mtrr:
17         lodsl   (%esi), %eax
18         testl   %eax, %eax
19         jz      clear_fixed_var_mtrr_out
20
21         movl    %eax, %ecx
22         xorl    %eax, %eax
23         wrmsr
24
25         jmp     clear_fixed_var_mtrr
26 clear_fixed_var_mtrr_out:
27
28 /* enable memory access for 0 - 1MB using top_mem */
29         movl    $TOP_MEM, %ecx
30         xorl    %edx, %edx
31         movl    $(((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK) , %eax
32         wrmsr
33
34 set_var_mtrr:
35         /* enable caching for 0 - 1MB using variable mtrr */
36         movl    $0x200, %ecx
37         rdmsr
38         andl    $0xfffffff0, %edx
39         orl     $0x00000000, %edx
40         andl    $0x00000f00, %eax
41         orl     $(0x00000000 | MTRR_TYPE_WRBACK), %eax
42         wrmsr
43
44         movl    $0x201, %ecx
45         rdmsr
46         andl    $0xfffffff0, %edx
47         orl     $0x0000000f, %edx
48         andl    $0x000007ff, %eax
49         orl     $((~((CONFIG_LB_MEM_TOPK << 10) - 1)) | 0x800), %eax
50         wrmsr
51
52 #if defined(XIP_ROM_SIZE) && defined(XIP_ROM_BASE)
53         /* enable write base caching so we can do execute in place
54          * on the flash rom.
55          */
56         movl    $0x202, %ecx
57         xorl    %edx, %edx
58         movl    $(XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
59         wrmsr   
60
61         movl    $0x203, %ecx
62         movl    $0x0000000f, %edx
63         movl    $(~(XIP_ROM_SIZE - 1) | 0x800), %eax
64         wrmsr
65 #endif /* XIP_ROM_SIZE && XIP_ROM_BASE */
66
67 enable_mtrr:    
68         /* Set the default memory type and enable fixed and variable MTRRs */
69         movl    $MTRRdefType_MSR, %ecx
70         xorl    %edx, %edx
71         /* Enable Variable MTRRs */
72         movl    $0x00000800, %eax
73         wrmsr
74
75         /* Enable the MTRRs in SYSCFG */
76         movl    $SYSCFG_MSR, %ecx
77         rdmsr
78         orl     $(SYSCFG_MSR_MtrrVarDramEn), %eax
79         wrmsr
80
81         /* enable cache */
82         movl    %cr0, %eax
83         andl    $0x9fffffff,%eax
84         movl    %eax, %cr0
85
86         jmp     earlymtrr_end
87
88 fixed_mtrr_msr: 
89         .long   0x250, 0x258, 0x259
90         .long   0x268, 0x269, 0x26A
91         .long   0x26B, 0x26C, 0x26D
92         .long   0x26E, 0x26F
93 var_mtrr_msr:
94         .long   0x200, 0x201, 0x202, 0x203
95         .long   0x204, 0x205, 0x206, 0x207
96         .long   0x208, 0x209, 0x20A, 0x20B
97         .long   0x20C, 0x20D, 0x20E, 0x20F
98 var_iorr_msr:
99         .long   0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019
100 mem_top:
101         .long   0xC001001A, 0xC001001D
102         .long   0x000 /* NULL, end of table */
103 earlymtrr_end:
104         /* Restore the BIST value */
105         movl    %ebp, %eax