remove trailing whitespace
[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 /* The following functions require the always_inline due to AMD
78  * function STOP_CAR_AND_CPU that disables cache as
79  * ram, the cache as ram stack can no longer be used. Called
80  * functions must be inlined to avoid stack usage. Also, the
81  * compiler must keep local variables register based and not
82  * allocated them from the stack. With gcc 4.5.0, some functions
83  * declared as inline are not being inlined. This patch forces
84  * these functions to always be inlined by adding the qualifier
85  * __attribute__((always_inline)) to their declaration.
86  */
87 static inline __attribute__((always_inline)) void enable_cache(void)
88 {
89         unsigned long cr0;
90         cr0 = read_cr0();
91         cr0 &= 0x9fffffff;
92         write_cr0(cr0);
93 }
94
95 static inline __attribute__((always_inline)) void disable_cache(void)
96 {
97         /* Disable and write back the cache */
98         unsigned long cr0;
99         cr0 = read_cr0();
100         cr0 |= 0x40000000;
101         wbinvd();
102         write_cr0(cr0);
103         wbinvd();
104 }
105
106 #if !defined(__PRE_RAM__)
107 void x86_enable_cache(void);
108 #endif
109
110 #endif /* CPU_X86_CACHE */