state.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <linux/init.h>
  2. #include <linux/io.h>
  3. #include <linux/mm.h>
  4. #include <asm/processor-cyrix.h>
  5. #include <asm/processor-flags.h>
  6. #include <asm/mtrr.h>
  7. #include <asm/msr.h>
  8. #include "mtrr.h"
  9. /* Put the processor into a state where MTRRs can be safely set */
  10. void set_mtrr_prepare_save(struct set_mtrr_context *ctxt)
  11. {
  12. unsigned int cr0;
  13. /* Disable interrupts locally */
  14. local_irq_save(ctxt->flags);
  15. if (use_intel() || is_cpu(CYRIX)) {
  16. /* Save value of CR4 and clear Page Global Enable (bit 7) */
  17. if (cpu_has_pge) {
  18. ctxt->cr4val = read_cr4();
  19. write_cr4(ctxt->cr4val & ~X86_CR4_PGE);
  20. }
  21. /*
  22. * Disable and flush caches. Note that wbinvd flushes the TLBs
  23. * as a side-effect
  24. */
  25. cr0 = read_cr0() | X86_CR0_CD;
  26. wbinvd();
  27. write_cr0(cr0);
  28. wbinvd();
  29. if (use_intel()) {
  30. /* Save MTRR state */
  31. rdmsr(MSR_MTRRdefType, ctxt->deftype_lo, ctxt->deftype_hi);
  32. } else {
  33. /*
  34. * Cyrix ARRs -
  35. * everything else were excluded at the top
  36. */
  37. ctxt->ccr3 = getCx86(CX86_CCR3);
  38. }
  39. }
  40. }
  41. void set_mtrr_cache_disable(struct set_mtrr_context *ctxt)
  42. {
  43. if (use_intel()) {
  44. /* Disable MTRRs, and set the default type to uncached */
  45. mtrr_wrmsr(MSR_MTRRdefType, ctxt->deftype_lo & 0xf300UL,
  46. ctxt->deftype_hi);
  47. } else {
  48. if (is_cpu(CYRIX)) {
  49. /* Cyrix ARRs - everything else were excluded at the top */
  50. setCx86(CX86_CCR3, (ctxt->ccr3 & 0x0f) | 0x10);
  51. }
  52. }
  53. }
  54. /* Restore the processor after a set_mtrr_prepare */
  55. void set_mtrr_done(struct set_mtrr_context *ctxt)
  56. {
  57. if (use_intel() || is_cpu(CYRIX)) {
  58. /* Flush caches and TLBs */
  59. wbinvd();
  60. /* Restore MTRRdefType */
  61. if (use_intel()) {
  62. /* Intel (P6) standard MTRRs */
  63. mtrr_wrmsr(MSR_MTRRdefType, ctxt->deftype_lo,
  64. ctxt->deftype_hi);
  65. } else {
  66. /*
  67. * Cyrix ARRs -
  68. * everything else was excluded at the top
  69. */
  70. setCx86(CX86_CCR3, ctxt->ccr3);
  71. }
  72. /* Enable caches */
  73. write_cr0(read_cr0() & 0xbfffffff);
  74. /* Restore value of CR4 */
  75. if (cpu_has_pge)
  76. write_cr4(ctxt->cr4val);
  77. }
  78. /* Re-enable interrupts locally (if enabled previously) */
  79. local_irq_restore(ctxt->flags);
  80. }