1 #include <linux/init.h>
6 #include <asm/processor-cyrix.h>
7 #include <asm/processor-flags.h>
11 cyrix_get_arr(unsigned int reg, unsigned long *base,
12 unsigned long *size, mtrr_type * type)
15 unsigned char arr, ccr3, rcr, shift;
17 arr = CX86_ARR_BASE + (reg << 1) + reg; /* avoid multiplication by 3 */
19 /* Save flags and disable interrupts */
20 local_irq_save(flags);
22 ccr3 = getCx86(CX86_CCR3);
23 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
24 ((unsigned char *) base)[3] = getCx86(arr);
25 ((unsigned char *) base)[2] = getCx86(arr + 1);
26 ((unsigned char *) base)[1] = getCx86(arr + 2);
27 rcr = getCx86(CX86_RCR_BASE + reg);
28 setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
30 /* Enable interrupts if it was enabled previously */
31 local_irq_restore(flags);
32 shift = ((unsigned char *) base)[1] & 0x0f;
35 /* Power of two, at least 4K on ARR0-ARR6, 256K on ARR7
36 * Note: shift==0xf means 4G, this is unsupported.
39 *size = (reg < 7 ? 0x1UL : 0x40UL) << (shift - 1);
43 /* Bit 0 is Cache Enable on ARR7, Cache Disable on ARR0-ARR6 */
47 *type = MTRR_TYPE_UNCACHABLE;
50 *type = MTRR_TYPE_WRBACK;
53 *type = MTRR_TYPE_WRCOMB;
57 *type = MTRR_TYPE_WRTHROUGH;
63 *type = MTRR_TYPE_UNCACHABLE;
66 *type = MTRR_TYPE_WRCOMB;
69 *type = MTRR_TYPE_WRBACK;
73 *type = MTRR_TYPE_WRTHROUGH;
80 cyrix_get_free_region(unsigned long base, unsigned long size, int replace_reg)
81 /* [SUMMARY] Get a free ARR.
82 <base> The starting (base) address of the region.
83 <size> The size (in bytes) of the region.
84 [RETURNS] The index of the region on success, else -1 on error.
89 unsigned long lbase, lsize;
91 switch (replace_reg) {
105 /* If we are to set up a region >32M then look at ARR7 immediately */
107 cyrix_get_arr(7, &lbase, &lsize, <ype);
110 /* Else try ARR0-ARR6 first */
112 for (i = 0; i < 7; i++) {
113 cyrix_get_arr(i, &lbase, &lsize, <ype);
117 /* ARR0-ARR6 isn't free, try ARR7 but its size must be at least 256K */
118 cyrix_get_arr(i, &lbase, &lsize, <ype);
119 if ((lsize == 0) && (size >= 0x40))
128 static void prepare_set(void)
132 /* Save value of CR4 and clear Page Global Enable (bit 7) */
135 write_cr4(cr4 & ~X86_CR4_PGE);
138 /* Disable and flush caches. Note that wbinvd flushes the TLBs as
140 cr0 = read_cr0() | X86_CR0_CD;
145 /* Cyrix ARRs - everything else was excluded at the top */
146 ccr3 = getCx86(CX86_CCR3);
148 /* Cyrix ARRs - everything else was excluded at the top */
149 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);
153 static void post_set(void)
155 /* Flush caches and TLBs */
158 /* Cyrix ARRs - everything else was excluded at the top */
159 setCx86(CX86_CCR3, ccr3);
162 write_cr0(read_cr0() & 0xbfffffff);
164 /* Restore value of CR4 */
169 static void cyrix_set_arr(unsigned int reg, unsigned long base,
170 unsigned long size, mtrr_type type)
172 unsigned char arr, arr_type, arr_size;
174 arr = CX86_ARR_BASE + (reg << 1) + reg; /* avoid multiplication by 3 */
176 /* count down from 32M (ARR0-ARR6) or from 2G (ARR7) */
180 size &= 0x7fff; /* make sure arr_size <= 14 */
181 for (arr_size = 0; size; arr_size++, size >>= 1) ;
185 case MTRR_TYPE_UNCACHABLE:
188 case MTRR_TYPE_WRCOMB:
191 case MTRR_TYPE_WRTHROUGH:
200 case MTRR_TYPE_UNCACHABLE:
203 case MTRR_TYPE_WRCOMB:
206 case MTRR_TYPE_WRTHROUGH:
218 setCx86(arr, ((unsigned char *) &base)[3]);
219 setCx86(arr + 1, ((unsigned char *) &base)[2]);
220 setCx86(arr + 2, (((unsigned char *) &base)[1]) | arr_size);
221 setCx86(CX86_RCR_BASE + reg, arr_type);
232 static arr_state_t arr_state[8] = {
233 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL},
234 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}
237 static unsigned char ccr_state[7] = { 0, 0, 0, 0, 0, 0, 0 };
239 static void cyrix_set_all(void)
245 /* the CCRs are not contiguous */
246 for (i = 0; i < 4; i++)
247 setCx86(CX86_CCR0 + i, ccr_state[i]);
249 setCx86(CX86_CCR4 + i, ccr_state[i]);
250 for (i = 0; i < 8; i++)
251 cyrix_set_arr(i, arr_state[i].base,
252 arr_state[i].size, arr_state[i].type);
257 static struct mtrr_ops cyrix_mtrr_ops = {
258 .vendor = X86_VENDOR_CYRIX,
259 // .init = cyrix_arr_init,
260 .set_all = cyrix_set_all,
261 .set = cyrix_set_arr,
262 .get = cyrix_get_arr,
263 .get_free_region = cyrix_get_free_region,
264 .validate_add_page = generic_validate_add_page,
265 .have_wrcomb = positive_have_wrcomb,
268 int __init cyrix_init_mtrr(void)
270 set_mtrr_ops(&cyrix_mtrr_ops);
274 //arch_initcall(cyrix_init_mtrr);