1 #include <linux/init.h>
11 cyrix_get_arr(unsigned int reg, unsigned long *base,
12 unsigned int *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)
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.
92 /* If we are to set up a region >32M then look at ARR7 immediately */
94 cyrix_get_arr(7, &lbase, &lsize, <ype);
97 /* Else try ARR0-ARR6 first */
99 for (i = 0; i < 7; i++) {
100 cyrix_get_arr(i, &lbase, &lsize, <ype);
101 if ((i == 3) && arr3_protected)
106 /* ARR0-ARR6 isn't free, try ARR7 but its size must be at least 256K */
107 cyrix_get_arr(i, &lbase, &lsize, <ype);
108 if ((lsize == 0) && (size >= 0x40))
117 static void prepare_set(void)
121 /* Save value of CR4 and clear Page Global Enable (bit 7) */
124 write_cr4(cr4 & (unsigned char) ~(1 << 7));
127 /* Disable and flush caches. Note that wbinvd flushes the TLBs as
129 cr0 = read_cr0() | 0x40000000;
134 /* Cyrix ARRs - everything else were excluded at the top */
135 ccr3 = getCx86(CX86_CCR3);
137 /* Cyrix ARRs - everything else were excluded at the top */
138 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);
142 static void post_set(void)
144 /* Flush caches and TLBs */
147 /* Cyrix ARRs - everything else was excluded at the top */
148 setCx86(CX86_CCR3, ccr3);
151 write_cr0(read_cr0() & 0xbfffffff);
153 /* Restore value of CR4 */
158 static void cyrix_set_arr(unsigned int reg, unsigned long base,
159 unsigned long size, mtrr_type type)
161 unsigned char arr, arr_type, arr_size;
163 arr = CX86_ARR_BASE + (reg << 1) + reg; /* avoid multiplication by 3 */
165 /* count down from 32M (ARR0-ARR6) or from 2G (ARR7) */
169 size &= 0x7fff; /* make sure arr_size <= 14 */
170 for (arr_size = 0; size; arr_size++, size >>= 1) ;
174 case MTRR_TYPE_UNCACHABLE:
177 case MTRR_TYPE_WRCOMB:
180 case MTRR_TYPE_WRTHROUGH:
189 case MTRR_TYPE_UNCACHABLE:
192 case MTRR_TYPE_WRCOMB:
195 case MTRR_TYPE_WRTHROUGH:
207 setCx86(arr, ((unsigned char *) &base)[3]);
208 setCx86(arr + 1, ((unsigned char *) &base)[2]);
209 setCx86(arr + 2, (((unsigned char *) &base)[1]) | arr_size);
210 setCx86(CX86_RCR_BASE + reg, arr_type);
221 static arr_state_t arr_state[8] __devinitdata = {
222 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL},
223 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}
226 static unsigned char ccr_state[7] __devinitdata = { 0, 0, 0, 0, 0, 0, 0 };
228 static void cyrix_set_all(void)
234 /* the CCRs are not contiguous */
235 for (i = 0; i < 4; i++)
236 setCx86(CX86_CCR0 + i, ccr_state[i]);
238 setCx86(CX86_CCR4 + i, ccr_state[i]);
239 for (i = 0; i < 8; i++)
240 cyrix_set_arr(i, arr_state[i].base,
241 arr_state[i].size, arr_state[i].type);
248 * On Cyrix 6x86(MX) and M II the ARR3 is special: it has connection
249 * with the SMM (System Management Mode) mode. So we need the following:
250 * Check whether SMI_LOCK (CCR3 bit 0) is set
251 * if it is set, write a warning message: ARR3 cannot be changed!
252 * (it cannot be changed until the next processor reset)
253 * if it is reset, then we can change it, set all the needed bits:
254 * - disable access to SMM memory through ARR3 range (CCR1 bit 7 reset)
255 * - disable access to SMM memory (CCR1 bit 2 reset)
256 * - disable SMM mode (CCR1 bit 1 reset)
257 * - disable write protection of ARR3 (CCR6 bit 1 reset)
258 * - (maybe) disable ARR3
259 * Just to be sure, we enable ARR usage by the processor (CCR5 bit 5 set)
264 struct set_mtrr_context ctxt;
265 unsigned char ccr[7];
266 int ccrc[7] = { 0, 0, 0, 0, 0, 0, 0 };
271 /* flush cache and enable MAPEN */
272 set_mtrr_prepare_save(&ctxt);
273 set_mtrr_cache_disable(&ctxt);
275 /* Save all CCRs locally */
276 ccr[0] = getCx86(CX86_CCR0);
277 ccr[1] = getCx86(CX86_CCR1);
278 ccr[2] = getCx86(CX86_CCR2);
280 ccr[4] = getCx86(CX86_CCR4);
281 ccr[5] = getCx86(CX86_CCR5);
282 ccr[6] = getCx86(CX86_CCR6);
288 /* Disable SMM mode (bit 1), access to SMM memory (bit 2) and
289 * access to SMM memory through ARR3 (bit 7).
306 ccrc[6] = 1; /* Disable write protection of ARR3 */
307 setCx86(CX86_CCR6, ccr[6]);
309 /* Disable ARR3. This is safe now that we disabled SMM. */
310 /* cyrix_set_arr_up (3, 0, 0, 0, FALSE); */
312 /* If we changed CCR1 in memory, change it in the processor, too. */
314 setCx86(CX86_CCR1, ccr[1]);
316 /* Enable ARR usage by the processor */
317 if (!(ccr[5] & 0x20)) {
320 setCx86(CX86_CCR5, ccr[5]);
323 for (i = 0; i < 7; i++)
324 ccr_state[i] = ccr[i];
325 for (i = 0; i < 8; i++)
327 &arr_state[i].base, &arr_state[i].size,
331 set_mtrr_done(&ctxt); /* flush cache and disable MAPEN */
334 printk(KERN_INFO "mtrr: ARR usage was not enabled, enabled manually\n");
336 printk(KERN_INFO "mtrr: ARR3 cannot be changed\n");
338 if ( ccrc[1] & 0x80) printk ("mtrr: SMM memory access through ARR3 disabled\n");
339 if ( ccrc[1] & 0x04) printk ("mtrr: SMM memory access disabled\n");
340 if ( ccrc[1] & 0x02) printk ("mtrr: SMM mode disabled\n");
343 printk(KERN_INFO "mtrr: ARR3 was write protected, unprotected\n");
347 static struct mtrr_ops cyrix_mtrr_ops = {
348 .vendor = X86_VENDOR_CYRIX,
349 // .init = cyrix_arr_init,
350 .set_all = cyrix_set_all,
351 .set = cyrix_set_arr,
352 .get = cyrix_get_arr,
353 .get_free_region = cyrix_get_free_region,
354 .validate_add_page = generic_validate_add_page,
355 .have_wrcomb = positive_have_wrcomb,
358 int __init cyrix_init_mtrr(void)
360 set_mtrr_ops(&cyrix_mtrr_ops);
364 //arch_initcall(cyrix_init_mtrr);