1 #include <linux/init.h>
5 #include <asm/processor-cyrix.h>
6 #include <asm/processor-flags.h>
13 cyrix_get_arr(unsigned int reg
, unsigned long *base
,
14 unsigned long *size
, mtrr_type
* type
)
16 unsigned char arr
, ccr3
, rcr
, shift
;
19 arr
= CX86_ARR_BASE
+ (reg
<< 1) + reg
; /* avoid multiplication by 3 */
21 local_irq_save(flags
);
23 ccr3
= getCx86(CX86_CCR3
);
24 setCx86(CX86_CCR3
, (ccr3
& 0x0f) | 0x10); /* enable MAPEN */
25 ((unsigned char *)base
)[3] = getCx86(arr
);
26 ((unsigned char *)base
)[2] = getCx86(arr
+ 1);
27 ((unsigned char *)base
)[1] = getCx86(arr
+ 2);
28 rcr
= getCx86(CX86_RCR_BASE
+ reg
);
29 setCx86(CX86_CCR3
, ccr3
); /* disable MAPEN */
31 local_irq_restore(flags
);
33 shift
= ((unsigned char *) base
)[1] & 0x0f;
37 * Power of two, at least 4K on ARR0-ARR6, 256K on ARR7
38 * Note: shift==0xf means 4G, this is unsupported.
41 *size
= (reg
< 7 ? 0x1UL
: 0x40UL
) << (shift
- 1);
45 /* Bit 0 is Cache Enable on ARR7, Cache Disable on ARR0-ARR6 */
49 *type
= MTRR_TYPE_UNCACHABLE
;
52 *type
= MTRR_TYPE_WRBACK
;
55 *type
= MTRR_TYPE_WRCOMB
;
59 *type
= MTRR_TYPE_WRTHROUGH
;
65 *type
= MTRR_TYPE_UNCACHABLE
;
68 *type
= MTRR_TYPE_WRCOMB
;
71 *type
= MTRR_TYPE_WRBACK
;
75 *type
= MTRR_TYPE_WRTHROUGH
;
82 * cyrix_get_free_region - get a free ARR.
84 * @base: the starting (base) address of the region.
85 * @size: the size (in bytes) of the region.
87 * Returns: the index of the region on success, else -1 on error.
90 cyrix_get_free_region(unsigned long base
, unsigned long size
, int replace_reg
)
92 unsigned long lbase
, lsize
;
96 switch (replace_reg
) {
110 /* If we are to set up a region >32M then look at ARR7 immediately */
112 cyrix_get_arr(7, &lbase
, &lsize
, <ype
);
115 /* Else try ARR0-ARR6 first */
117 for (i
= 0; i
< 7; i
++) {
118 cyrix_get_arr(i
, &lbase
, &lsize
, <ype
);
123 * ARR0-ARR6 isn't free
124 * try ARR7 but its size must be at least 256K
126 cyrix_get_arr(i
, &lbase
, &lsize
, <ype
);
127 if ((lsize
== 0) && (size
>= 0x40))
133 static u32 cr4
, ccr3
;
135 static void prepare_set(void)
139 /* Save value of CR4 and clear Page Global Enable (bit 7) */
142 write_cr4(cr4
& ~X86_CR4_PGE
);
146 * Disable and flush caches.
147 * Note that wbinvd flushes the TLBs as a side-effect
149 cr0
= read_cr0() | X86_CR0_CD
;
154 /* Cyrix ARRs - everything else was excluded at the top */
155 ccr3
= getCx86(CX86_CCR3
);
157 /* Cyrix ARRs - everything else was excluded at the top */
158 setCx86(CX86_CCR3
, (ccr3
& 0x0f) | 0x10);
161 static void post_set(void)
163 /* Flush caches and TLBs */
166 /* Cyrix ARRs - everything else was excluded at the top */
167 setCx86(CX86_CCR3
, ccr3
);
170 write_cr0(read_cr0() & 0xbfffffff);
172 /* Restore value of CR4 */
177 static void cyrix_set_arr(unsigned int reg
, unsigned long base
,
178 unsigned long size
, mtrr_type type
)
180 unsigned char arr
, arr_type
, arr_size
;
182 arr
= CX86_ARR_BASE
+ (reg
<< 1) + reg
; /* avoid multiplication by 3 */
184 /* count down from 32M (ARR0-ARR6) or from 2G (ARR7) */
188 size
&= 0x7fff; /* make sure arr_size <= 14 */
189 for (arr_size
= 0; size
; arr_size
++, size
>>= 1)
194 case MTRR_TYPE_UNCACHABLE
:
197 case MTRR_TYPE_WRCOMB
:
200 case MTRR_TYPE_WRTHROUGH
:
209 case MTRR_TYPE_UNCACHABLE
:
212 case MTRR_TYPE_WRCOMB
:
215 case MTRR_TYPE_WRTHROUGH
:
227 setCx86(arr
+ 0, ((unsigned char *)&base
)[3]);
228 setCx86(arr
+ 1, ((unsigned char *)&base
)[2]);
229 setCx86(arr
+ 2, (((unsigned char *)&base
)[1]) | arr_size
);
230 setCx86(CX86_RCR_BASE
+ reg
, arr_type
);
241 static arr_state_t arr_state
[8] = {
242 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL},
243 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}
246 static unsigned char ccr_state
[7] = { 0, 0, 0, 0, 0, 0, 0 };
248 static void cyrix_set_all(void)
254 /* the CCRs are not contiguous */
255 for (i
= 0; i
< 4; i
++)
256 setCx86(CX86_CCR0
+ i
, ccr_state
[i
]);
258 setCx86(CX86_CCR4
+ i
, ccr_state
[i
]);
260 for (i
= 0; i
< 8; i
++) {
261 cyrix_set_arr(i
, arr_state
[i
].base
,
262 arr_state
[i
].size
, arr_state
[i
].type
);
268 static struct mtrr_ops cyrix_mtrr_ops
= {
269 .vendor
= X86_VENDOR_CYRIX
,
270 .set_all
= cyrix_set_all
,
271 .set
= cyrix_set_arr
,
272 .get
= cyrix_get_arr
,
273 .get_free_region
= cyrix_get_free_region
,
274 .validate_add_page
= generic_validate_add_page
,
275 .have_wrcomb
= positive_have_wrcomb
,
278 int __init
cyrix_init_mtrr(void)
280 set_mtrr_ops(&cyrix_mtrr_ops
);