centaur.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include <linux/init.h>
  2. #include <linux/mm.h>
  3. #include <asm/mtrr.h>
  4. #include <asm/msr.h>
  5. #include "mtrr.h"
  6. static struct {
  7. unsigned long high;
  8. unsigned long low;
  9. } centaur_mcr[8];
  10. static u8 centaur_mcr_reserved;
  11. static u8 centaur_mcr_type; /* 0 for winchip, 1 for winchip2 */
  12. /*
  13. * Report boot time MCR setups
  14. */
  15. static int
  16. centaur_get_free_region(unsigned long base, unsigned long size)
  17. /* [SUMMARY] Get a free MTRR.
  18. <base> The starting (base) address of the region.
  19. <size> The size (in bytes) of the region.
  20. [RETURNS] The index of the region on success, else -1 on error.
  21. */
  22. {
  23. int i, max;
  24. mtrr_type ltype;
  25. unsigned long lbase;
  26. unsigned int lsize;
  27. max = num_var_ranges;
  28. for (i = 0; i < max; ++i) {
  29. if (centaur_mcr_reserved & (1 << i))
  30. continue;
  31. mtrr_if->get(i, &lbase, &lsize, &ltype);
  32. if (lsize == 0)
  33. return i;
  34. }
  35. return -ENOSPC;
  36. }
  37. void
  38. mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
  39. {
  40. centaur_mcr[mcr].low = lo;
  41. centaur_mcr[mcr].high = hi;
  42. }
  43. static void
  44. centaur_get_mcr(unsigned int reg, unsigned long *base,
  45. unsigned int *size, mtrr_type * type)
  46. {
  47. *base = centaur_mcr[reg].high >> PAGE_SHIFT;
  48. *size = -(centaur_mcr[reg].low & 0xfffff000) >> PAGE_SHIFT;
  49. *type = MTRR_TYPE_WRCOMB; /* If it is there, it is write-combining */
  50. if (centaur_mcr_type == 1 && ((centaur_mcr[reg].low & 31) & 2))
  51. *type = MTRR_TYPE_UNCACHABLE;
  52. if (centaur_mcr_type == 1 && (centaur_mcr[reg].low & 31) == 25)
  53. *type = MTRR_TYPE_WRBACK;
  54. if (centaur_mcr_type == 0 && (centaur_mcr[reg].low & 31) == 31)
  55. *type = MTRR_TYPE_WRBACK;
  56. }
  57. static void centaur_set_mcr(unsigned int reg, unsigned long base,
  58. unsigned long size, mtrr_type type)
  59. {
  60. unsigned long low, high;
  61. if (size == 0) {
  62. /* Disable */
  63. high = low = 0;
  64. } else {
  65. high = base << PAGE_SHIFT;
  66. if (centaur_mcr_type == 0)
  67. low = -size << PAGE_SHIFT | 0x1f; /* only support write-combining... */
  68. else {
  69. if (type == MTRR_TYPE_UNCACHABLE)
  70. low = -size << PAGE_SHIFT | 0x02; /* NC */
  71. else
  72. low = -size << PAGE_SHIFT | 0x09; /* WWO,WC */
  73. }
  74. }
  75. centaur_mcr[reg].high = high;
  76. centaur_mcr[reg].low = low;
  77. wrmsr(MSR_IDT_MCR0 + reg, low, high);
  78. }
  79. #if 0
  80. /*
  81. * Initialise the later (saner) Winchip MCR variant. In this version
  82. * the BIOS can pass us the registers it has used (but not their values)
  83. * and the control register is read/write
  84. */
  85. static void __init
  86. centaur_mcr1_init(void)
  87. {
  88. unsigned i;
  89. u32 lo, hi;
  90. /* Unfortunately, MCR's are read-only, so there is no way to
  91. * find out what the bios might have done.
  92. */
  93. rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
  94. if (((lo >> 17) & 7) == 1) { /* Type 1 Winchip2 MCR */
  95. lo &= ~0x1C0; /* clear key */
  96. lo |= 0x040; /* set key to 1 */
  97. wrmsr(MSR_IDT_MCR_CTRL, lo, hi); /* unlock MCR */
  98. }
  99. centaur_mcr_type = 1;
  100. /*
  101. * Clear any unconfigured MCR's.
  102. */
  103. for (i = 0; i < 8; ++i) {
  104. if (centaur_mcr[i].high == 0 && centaur_mcr[i].low == 0) {
  105. if (!(lo & (1 << (9 + i))))
  106. wrmsr(MSR_IDT_MCR0 + i, 0, 0);
  107. else
  108. /*
  109. * If the BIOS set up an MCR we cannot see it
  110. * but we don't wish to obliterate it
  111. */
  112. centaur_mcr_reserved |= (1 << i);
  113. }
  114. }
  115. /*
  116. * Throw the main write-combining switch...
  117. * However if OOSTORE is enabled then people have already done far
  118. * cleverer things and we should behave.
  119. */
  120. lo |= 15; /* Write combine enables */
  121. wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
  122. }
  123. /*
  124. * Initialise the original winchip with read only MCR registers
  125. * no used bitmask for the BIOS to pass on and write only control
  126. */
  127. static void __init
  128. centaur_mcr0_init(void)
  129. {
  130. unsigned i;
  131. /* Unfortunately, MCR's are read-only, so there is no way to
  132. * find out what the bios might have done.
  133. */
  134. /* Clear any unconfigured MCR's.
  135. * This way we are sure that the centaur_mcr array contains the actual
  136. * values. The disadvantage is that any BIOS tweaks are thus undone.
  137. *
  138. */
  139. for (i = 0; i < 8; ++i) {
  140. if (centaur_mcr[i].high == 0 && centaur_mcr[i].low == 0)
  141. wrmsr(MSR_IDT_MCR0 + i, 0, 0);
  142. }
  143. wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0); /* Write only */
  144. }
  145. /*
  146. * Initialise Winchip series MCR registers
  147. */
  148. static void __init
  149. centaur_mcr_init(void)
  150. {
  151. struct set_mtrr_context ctxt;
  152. set_mtrr_prepare_save(&ctxt);
  153. set_mtrr_cache_disable(&ctxt);
  154. if (boot_cpu_data.x86_model == 4)
  155. centaur_mcr0_init();
  156. else if (boot_cpu_data.x86_model == 8 || boot_cpu_data.x86_model == 9)
  157. centaur_mcr1_init();
  158. set_mtrr_done(&ctxt);
  159. }
  160. #endif
  161. static int centaur_validate_add_page(unsigned long base,
  162. unsigned long size, unsigned int type)
  163. {
  164. /*
  165. * FIXME: Winchip2 supports uncached
  166. */
  167. if (type != MTRR_TYPE_WRCOMB &&
  168. (centaur_mcr_type == 0 || type != MTRR_TYPE_UNCACHABLE)) {
  169. printk(KERN_WARNING
  170. "mtrr: only write-combining%s supported\n",
  171. centaur_mcr_type ? " and uncacheable are"
  172. : " is");
  173. return -EINVAL;
  174. }
  175. return 0;
  176. }
  177. static struct mtrr_ops centaur_mtrr_ops = {
  178. .vendor = X86_VENDOR_CENTAUR,
  179. // .init = centaur_mcr_init,
  180. .set = centaur_set_mcr,
  181. .get = centaur_get_mcr,
  182. .get_free_region = centaur_get_free_region,
  183. .validate_add_page = centaur_validate_add_page,
  184. .have_wrcomb = positive_have_wrcomb,
  185. };
  186. int __init centaur_init_mtrr(void)
  187. {
  188. set_mtrr_ops(&centaur_mtrr_ops);
  189. return 0;
  190. }
  191. //arch_initcall(centaur_init_mtrr);