cosmetic comment changes.
[coreboot.git] / src / include / cpu / x86 / cache.h
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2004 Eric W. Biederman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #ifndef CPU_X86_CACHE
21 #define CPU_X86_CACHE
22
23 /*
24  * Need two versions because ROMCC chokes on certain clobbers:
25  * cache.h:29.71: cache.h:60.24: earlymtrr.c:117.23: romstage.c:144.33: 
26  * 0x1559920 asm        Internal compiler error: lhs 1 regcm == 0
27  */
28
29 #if defined(__GNUC__)
30
31 /* The memory clobber prevents the GCC from reordering the read/write order
32  * of CR0
33  */
34 static inline unsigned long read_cr0(void)
35 {
36         unsigned long cr0;
37         asm volatile ("movl %%cr0, %0" : "=r" (cr0) :: "memory");
38         return cr0;
39 }
40
41 static inline void write_cr0(unsigned long cr0)
42 {
43         asm volatile ("movl %0, %%cr0" : : "r" (cr0) : "memory");
44 }
45
46 static inline void wbinvd(void)
47 {
48         asm volatile ("wbinvd" ::: "memory");
49 }
50
51 #else
52
53 static inline unsigned long read_cr0(void)
54 {
55         unsigned long cr0;
56         asm volatile ("movl %%cr0, %0" : "=r" (cr0));
57         return cr0;
58 }
59
60 static inline void write_cr0(unsigned long cr0)
61 {
62         asm volatile ("movl %0, %%cr0" : : "r" (cr0));
63 }
64
65 static inline void wbinvd(void)
66 {
67         asm volatile ("wbinvd");
68 }
69
70 #endif
71
72 static inline void invd(void)
73 {
74         asm volatile("invd" ::: "memory");
75 }
76
77 static inline void enable_cache(void)
78 {
79         unsigned long cr0;
80         cr0 = read_cr0();
81         cr0 &= 0x9fffffff;
82         write_cr0(cr0);
83 }
84
85 static inline void disable_cache(void)
86 {
87         /* Disable and write back the cache */
88         unsigned long cr0;
89         cr0 = read_cr0();
90         cr0 |= 0x40000000;
91         wbinvd();
92         write_cr0(cr0);
93         wbinvd();
94 }
95
96 #if !defined(__PRE_RAM__)
97 void x86_enable_cache(void);
98 #endif
99
100 #endif /* CPU_X86_CACHE */