mtrr.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Generic MTRR (Memory Type Range Register) ioctls.
  2. Copyright (C) 1997-1999 Richard Gooch
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not, write to the Free
  13. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. Richard Gooch may be reached by email at rgooch@atnf.csiro.au
  15. The postal address is:
  16. Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
  17. */
  18. #ifndef _ASM_X86_MTRR_H
  19. #define _ASM_X86_MTRR_H
  20. #include <linux/types.h>
  21. #include <linux/ioctl.h>
  22. #include <linux/errno.h>
  23. #define MTRR_IOCTL_BASE 'M'
  24. /* Warning: this structure has a different order from i386
  25. on x86-64. The 32bit emulation code takes care of that.
  26. But you need to use this for 64bit, otherwise your X server
  27. will break. */
  28. #ifdef __i386__
  29. struct mtrr_sentry {
  30. unsigned long base; /* Base address */
  31. unsigned int size; /* Size of region */
  32. unsigned int type; /* Type of region */
  33. };
  34. struct mtrr_gentry {
  35. unsigned int regnum; /* Register number */
  36. unsigned long base; /* Base address */
  37. unsigned int size; /* Size of region */
  38. unsigned int type; /* Type of region */
  39. };
  40. #else /* __i386__ */
  41. struct mtrr_sentry {
  42. __u64 base; /* Base address */
  43. __u32 size; /* Size of region */
  44. __u32 type; /* Type of region */
  45. };
  46. struct mtrr_gentry {
  47. __u64 base; /* Base address */
  48. __u32 size; /* Size of region */
  49. __u32 regnum; /* Register number */
  50. __u32 type; /* Type of region */
  51. __u32 _pad; /* Unused */
  52. };
  53. #endif /* !__i386__ */
  54. struct mtrr_var_range {
  55. __u32 base_lo;
  56. __u32 base_hi;
  57. __u32 mask_lo;
  58. __u32 mask_hi;
  59. };
  60. /* In the Intel processor's MTRR interface, the MTRR type is always held in
  61. an 8 bit field: */
  62. typedef __u8 mtrr_type;
  63. #define MTRR_NUM_FIXED_RANGES 88
  64. #define MTRR_MAX_VAR_RANGES 256
  65. struct mtrr_state_type {
  66. struct mtrr_var_range var_ranges[MTRR_MAX_VAR_RANGES];
  67. mtrr_type fixed_ranges[MTRR_NUM_FIXED_RANGES];
  68. unsigned char enabled;
  69. unsigned char have_fixed;
  70. mtrr_type def_type;
  71. };
  72. #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
  73. #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
  74. /* These are the various ioctls */
  75. #define MTRRIOC_ADD_ENTRY _IOW(MTRR_IOCTL_BASE, 0, struct mtrr_sentry)
  76. #define MTRRIOC_SET_ENTRY _IOW(MTRR_IOCTL_BASE, 1, struct mtrr_sentry)
  77. #define MTRRIOC_DEL_ENTRY _IOW(MTRR_IOCTL_BASE, 2, struct mtrr_sentry)
  78. #define MTRRIOC_GET_ENTRY _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry)
  79. #define MTRRIOC_KILL_ENTRY _IOW(MTRR_IOCTL_BASE, 4, struct mtrr_sentry)
  80. #define MTRRIOC_ADD_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 5, struct mtrr_sentry)
  81. #define MTRRIOC_SET_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 6, struct mtrr_sentry)
  82. #define MTRRIOC_DEL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 7, struct mtrr_sentry)
  83. #define MTRRIOC_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry)
  84. #define MTRRIOC_KILL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry)
  85. /* These are the region types */
  86. #define MTRR_TYPE_UNCACHABLE 0
  87. #define MTRR_TYPE_WRCOMB 1
  88. /*#define MTRR_TYPE_ 2*/
  89. /*#define MTRR_TYPE_ 3*/
  90. #define MTRR_TYPE_WRTHROUGH 4
  91. #define MTRR_TYPE_WRPROT 5
  92. #define MTRR_TYPE_WRBACK 6
  93. #define MTRR_NUM_TYPES 7
  94. #ifdef __KERNEL__
  95. /* The following functions are for use by other drivers */
  96. # ifdef CONFIG_MTRR
  97. extern u8 mtrr_type_lookup(u64 addr, u64 end);
  98. extern void mtrr_save_fixed_ranges(void *);
  99. extern void mtrr_save_state(void);
  100. extern int mtrr_add(unsigned long base, unsigned long size,
  101. unsigned int type, bool increment);
  102. extern int mtrr_add_page(unsigned long base, unsigned long size,
  103. unsigned int type, bool increment);
  104. extern int mtrr_del(int reg, unsigned long base, unsigned long size);
  105. extern int mtrr_del_page(int reg, unsigned long base, unsigned long size);
  106. extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
  107. extern void mtrr_ap_init(void);
  108. extern void mtrr_bp_init(void);
  109. extern void set_mtrr_aps_delayed_init(void);
  110. extern void mtrr_aps_init(void);
  111. extern void mtrr_bp_restore(void);
  112. extern int mtrr_trim_uncached_memory(unsigned long end_pfn);
  113. extern int amd_special_default_mtrr(void);
  114. # else
  115. static inline u8 mtrr_type_lookup(u64 addr, u64 end)
  116. {
  117. /*
  118. * Return no-MTRRs:
  119. */
  120. return 0xff;
  121. }
  122. #define mtrr_save_fixed_ranges(arg) do {} while (0)
  123. #define mtrr_save_state() do {} while (0)
  124. static inline int mtrr_add(unsigned long base, unsigned long size,
  125. unsigned int type, bool increment)
  126. {
  127. return -ENODEV;
  128. }
  129. static inline int mtrr_add_page(unsigned long base, unsigned long size,
  130. unsigned int type, bool increment)
  131. {
  132. return -ENODEV;
  133. }
  134. static inline int mtrr_del(int reg, unsigned long base, unsigned long size)
  135. {
  136. return -ENODEV;
  137. }
  138. static inline int mtrr_del_page(int reg, unsigned long base, unsigned long size)
  139. {
  140. return -ENODEV;
  141. }
  142. static inline int mtrr_trim_uncached_memory(unsigned long end_pfn)
  143. {
  144. return 0;
  145. }
  146. static inline void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
  147. {
  148. }
  149. #define mtrr_ap_init() do {} while (0)
  150. #define mtrr_bp_init() do {} while (0)
  151. #define set_mtrr_aps_delayed_init() do {} while (0)
  152. #define mtrr_aps_init() do {} while (0)
  153. #define mtrr_bp_restore() do {} while (0)
  154. # endif
  155. #ifdef CONFIG_COMPAT
  156. #include <linux/compat.h>
  157. struct mtrr_sentry32 {
  158. compat_ulong_t base; /* Base address */
  159. compat_uint_t size; /* Size of region */
  160. compat_uint_t type; /* Type of region */
  161. };
  162. struct mtrr_gentry32 {
  163. compat_ulong_t regnum; /* Register number */
  164. compat_uint_t base; /* Base address */
  165. compat_uint_t size; /* Size of region */
  166. compat_uint_t type; /* Type of region */
  167. };
  168. #define MTRR_IOCTL_BASE 'M'
  169. #define MTRRIOC32_ADD_ENTRY _IOW(MTRR_IOCTL_BASE, 0, struct mtrr_sentry32)
  170. #define MTRRIOC32_SET_ENTRY _IOW(MTRR_IOCTL_BASE, 1, struct mtrr_sentry32)
  171. #define MTRRIOC32_DEL_ENTRY _IOW(MTRR_IOCTL_BASE, 2, struct mtrr_sentry32)
  172. #define MTRRIOC32_GET_ENTRY _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry32)
  173. #define MTRRIOC32_KILL_ENTRY _IOW(MTRR_IOCTL_BASE, 4, struct mtrr_sentry32)
  174. #define MTRRIOC32_ADD_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 5, struct mtrr_sentry32)
  175. #define MTRRIOC32_SET_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 6, struct mtrr_sentry32)
  176. #define MTRRIOC32_DEL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 7, struct mtrr_sentry32)
  177. #define MTRRIOC32_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry32)
  178. #define MTRRIOC32_KILL_PAGE_ENTRY \
  179. _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry32)
  180. #endif /* CONFIG_COMPAT */
  181. #endif /* __KERNEL__ */
  182. #endif /* _ASM_X86_MTRR_H */