Following patch reworks car_disable into C. Tested, works here. I compared
[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 /* the memory clobber prevents the GCC from reordering the read/write order
24    of CR0 */
25
26 static inline unsigned long read_cr0(void)
27 {
28         unsigned long cr0;
29         asm volatile ("movl %%cr0, %0" : "=r" (cr0) :: "memory");
30         return cr0;
31 }
32
33 static inline void write_cr0(unsigned long cr0)
34 {
35         asm volatile ("movl %0, %%cr0" : : "r" (cr0) : "memory");
36 }
37
38 static inline void invd(void)
39 {
40         asm volatile("invd" ::: "memory");
41 }
42
43 static inline void wbinvd(void)
44 {
45         asm volatile ("wbinvd" ::: "memory");
46 }
47
48 static inline void enable_cache(void)
49 {
50         unsigned long cr0;
51         cr0 = read_cr0();
52         cr0 &= 0x9fffffff;
53         write_cr0(cr0);
54 }
55
56 static inline void disable_cache(void)
57 {
58         /* Disable and write back the cache */
59         unsigned long cr0;
60         cr0 = read_cr0();
61         cr0 |= 0x40000000;
62         wbinvd();
63         write_cr0(cr0);
64         wbinvd();
65 }
66
67 #if !defined(__PRE_RAM__)
68 void x86_enable_cache(void);
69 #endif
70
71 #endif /* CPU_X86_CACHE */