1 #include <linux/init.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) {
107 /* If we are to set up a region >32M then look at ARR7 immediately */
109 cyrix_get_arr(7, &lbase, &lsize, <ype);
112 /* Else try ARR0-ARR6 first */
114 for (i = 0; i < 7; i++) {
115 cyrix_get_arr(i, &lbase, &lsize, <ype);
116 if ((i == 3) && arr3_protected)
121 /* ARR0-ARR6 isn't free, try ARR7 but its size must be at least 256K */
122 cyrix_get_arr(i, &lbase, &lsize, <ype);
123 if ((lsize == 0) && (size >= 0x40))
132 static void prepare_set(void)
136 /* Save value of CR4 and clear Page Global Enable (bit 7) */
139 write_cr4(cr4 & ~X86_CR4_PGE);
142 /* Disable and flush caches. Note that wbinvd flushes the TLBs as
144 cr0 = read_cr0() | 0x40000000;
149 /* Cyrix ARRs - everything else were excluded at the top */
150 ccr3 = getCx86(CX86_CCR3);
152 /* Cyrix ARRs - everything else were excluded at the top */
153 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);
157 static void post_set(void)
159 /* Flush caches and TLBs */
162 /* Cyrix ARRs - everything else was excluded at the top */
163 setCx86(CX86_CCR3, ccr3);
166 write_cr0(read_cr0() & 0xbfffffff);
168 /* Restore value of CR4 */
173 static void cyrix_set_arr(unsigned int reg, unsigned long base,
174 unsigned long size, mtrr_type type)
176 unsigned char arr, arr_type, arr_size;
178 arr = CX86_ARR_BASE + (reg << 1) + reg; /* avoid multiplication by 3 */
180 /* count down from 32M (ARR0-ARR6) or from 2G (ARR7) */
184 size &= 0x7fff; /* make sure arr_size <= 14 */
185 for (arr_size = 0; size; arr_size++, size >>= 1) ;
189 case MTRR_TYPE_UNCACHABLE:
192 case MTRR_TYPE_WRCOMB:
195 case MTRR_TYPE_WRTHROUGH:
204 case MTRR_TYPE_UNCACHABLE:
207 case MTRR_TYPE_WRCOMB:
210 case MTRR_TYPE_WRTHROUGH:
222 setCx86(arr, ((unsigned char *) &base)[3]);
223 setCx86(arr + 1, ((unsigned char *) &base)[2]);
224 setCx86(arr + 2, (((unsigned char *) &base)[1]) | arr_size);
225 setCx86(CX86_RCR_BASE + reg, arr_type);
236 static arr_state_t arr_state[8] __devinitdata = {
237 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL},
238 {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}, {0UL, 0UL, 0UL}
241 static unsigned char ccr_state[7] __devinitdata = { 0, 0, 0, 0, 0, 0, 0 };
243 static void cyrix_set_all(void)
249 /* the CCRs are not contiguous */
250 for (i = 0; i < 4; i++)
251 setCx86(CX86_CCR0 + i, ccr_state[i]);
253 setCx86(CX86_CCR4 + i, ccr_state[i]);
254 for (i = 0; i < 8; i++)
255 cyrix_set_arr(i, arr_state[i].base,
256 arr_state[i].size, arr_state[i].type);
263 * On Cyrix 6x86(MX) and M II the ARR3 is special: it has connection
264 * with the SMM (System Management Mode) mode. So we need the following:
265 * Check whether SMI_LOCK (CCR3 bit 0) is set
266 * if it is set, write a warning message: ARR3 cannot be changed!
267 * (it cannot be changed until the next processor reset)
268 * if it is reset, then we can change it, set all the needed bits:
269 * - disable access to SMM memory through ARR3 range (CCR1 bit 7 reset)
270 * - disable access to SMM memory (CCR1 bit 2 reset)
271 * - disable SMM mode (CCR1 bit 1 reset)
272 * - disable write protection of ARR3 (CCR6 bit 1 reset)
273 * - (maybe) disable ARR3
274 * Just to be sure, we enable ARR usage by the processor (CCR5 bit 5 set)
279 struct set_mtrr_context ctxt;
280 unsigned char ccr[7];
281 int ccrc[7] = { 0, 0, 0, 0, 0, 0, 0 };
286 /* flush cache and enable MAPEN */
287 set_mtrr_prepare_save(&ctxt);
288 set_mtrr_cache_disable(&ctxt);
290 /* Save all CCRs locally */
291 ccr[0] = getCx86(CX86_CCR0);
292 ccr[1] = getCx86(CX86_CCR1);
293 ccr[2] = getCx86(CX86_CCR2);
295 ccr[4] = getCx86(CX86_CCR4);
296 ccr[5] = getCx86(CX86_CCR5);
297 ccr[6] = getCx86(CX86_CCR6);
303 /* Disable SMM mode (bit 1), access to SMM memory (bit 2) and
304 * access to SMM memory through ARR3 (bit 7).
321 ccrc[6] = 1; /* Disable write protection of ARR3 */
322 setCx86(CX86_CCR6, ccr[6]);
324 /* Disable ARR3. This is safe now that we disabled SMM. */
325 /* cyrix_set_arr_up (3, 0, 0, 0, FALSE); */
327 /* If we changed CCR1 in memory, change it in the processor, too. */
329 setCx86(CX86_CCR1, ccr[1]);
331 /* Enable ARR usage by the processor */
332 if (!(ccr[5] & 0x20)) {
335 setCx86(CX86_CCR5, ccr[5]);
338 for (i = 0; i < 7; i++)
339 ccr_state[i] = ccr[i];
340 for (i = 0; i < 8; i++)
342 &arr_state[i].base, &arr_state[i].size,
346 set_mtrr_done(&ctxt); /* flush cache and disable MAPEN */
349 printk(KERN_INFO "mtrr: ARR usage was not enabled, enabled manually\n");
351 printk(KERN_INFO "mtrr: ARR3 cannot be changed\n");
353 if ( ccrc[1] & 0x80) printk ("mtrr: SMM memory access through ARR3 disabled\n");
354 if ( ccrc[1] & 0x04) printk ("mtrr: SMM memory access disabled\n");
355 if ( ccrc[1] & 0x02) printk ("mtrr: SMM mode disabled\n");
358 printk(KERN_INFO "mtrr: ARR3 was write protected, unprotected\n");
362 static struct mtrr_ops cyrix_mtrr_ops = {
363 .vendor = X86_VENDOR_CYRIX,
364 // .init = cyrix_arr_init,
365 .set_all = cyrix_set_all,
366 .set = cyrix_set_arr,
367 .get = cyrix_get_arr,
368 .get_free_region = cyrix_get_free_region,
369 .validate_add_page = generic_validate_add_page,
370 .have_wrcomb = positive_have_wrcomb,
373 int __init cyrix_init_mtrr(void)
375 set_mtrr_ops(&cyrix_mtrr_ops);
379 //arch_initcall(cyrix_init_mtrr);