mtrr.h 7.1 KB
Newer Older
T
Thomas Gleixner 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*  Generic MTRR (Memory Type Range Register) ioctls.

    Copyright (C) 1997-1999  Richard Gooch

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    Richard Gooch may be reached by email at  rgooch@atnf.csiro.au
    The postal address is:
      Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
*/
H
H. Peter Anvin 已提交
23 24
#ifndef _ASM_X86_MTRR_H
#define _ASM_X86_MTRR_H
T
Thomas Gleixner 已提交
25

26
#include <linux/types.h>
T
Thomas Gleixner 已提交
27 28 29 30 31 32 33 34 35 36 37
#include <linux/ioctl.h>
#include <linux/errno.h>

#define	MTRR_IOCTL_BASE	'M'

/* Warning: this structure has a different order from i386
   on x86-64. The 32bit emulation code takes care of that.
   But you need to use this for 64bit, otherwise your X server
   will break. */

#ifdef __i386__
38 39 40 41 42 43
struct mtrr_sentry {
    unsigned long base;    /*  Base address     */
    unsigned int size;    /*  Size of region   */
    unsigned int type;     /*  Type of region   */
};

44
struct mtrr_gentry {
T
Thomas Gleixner 已提交
45 46 47 48 49 50 51 52
    unsigned int regnum;   /*  Register number  */
    unsigned long base;    /*  Base address     */
    unsigned int size;    /*  Size of region   */
    unsigned int type;     /*  Type of region   */
};

#else /* __i386__ */

53 54 55 56 57 58
struct mtrr_sentry {
	__u64 base;		/*  Base address     */
	__u32 size;		/*  Size of region   */
	__u32 type;		/*  Type of region   */
};

59
struct mtrr_gentry {
60 61 62 63 64
	__u64 base;		/*  Base address     */
	__u32 size;		/*  Size of region   */
	__u32 regnum;		/*  Register number  */
	__u32 type;		/*  Type of region   */
	__u32 _pad;		/*  Unused	     */
T
Thomas Gleixner 已提交
65
};
66

T
Thomas Gleixner 已提交
67 68
#endif /* !__i386__ */

S
Sheng Yang 已提交
69
struct mtrr_var_range {
70 71 72 73
	__u32 base_lo;
	__u32 base_hi;
	__u32 mask_lo;
	__u32 mask_hi;
S
Sheng Yang 已提交
74 75 76 77
};

/* In the Intel processor's MTRR interface, the MTRR type is always held in
   an 8 bit field: */
78
typedef __u8 mtrr_type;
S
Sheng Yang 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

#define MTRR_NUM_FIXED_RANGES 88
#define MTRR_MAX_VAR_RANGES 256

struct mtrr_state_type {
	struct mtrr_var_range var_ranges[MTRR_MAX_VAR_RANGES];
	mtrr_type fixed_ranges[MTRR_NUM_FIXED_RANGES];
	unsigned char enabled;
	unsigned char have_fixed;
	mtrr_type def_type;
};

#define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
#define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)

T
Thomas Gleixner 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/*  These are the various ioctls  */
#define MTRRIOC_ADD_ENTRY        _IOW(MTRR_IOCTL_BASE,  0, struct mtrr_sentry)
#define MTRRIOC_SET_ENTRY        _IOW(MTRR_IOCTL_BASE,  1, struct mtrr_sentry)
#define MTRRIOC_DEL_ENTRY        _IOW(MTRR_IOCTL_BASE,  2, struct mtrr_sentry)
#define MTRRIOC_GET_ENTRY        _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry)
#define MTRRIOC_KILL_ENTRY       _IOW(MTRR_IOCTL_BASE,  4, struct mtrr_sentry)
#define MTRRIOC_ADD_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  5, struct mtrr_sentry)
#define MTRRIOC_SET_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  6, struct mtrr_sentry)
#define MTRRIOC_DEL_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  7, struct mtrr_sentry)
#define MTRRIOC_GET_PAGE_ENTRY   _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry)
#define MTRRIOC_KILL_PAGE_ENTRY  _IOW(MTRR_IOCTL_BASE,  9, struct mtrr_sentry)

/*  These are the region types  */
#define MTRR_TYPE_UNCACHABLE 0
#define MTRR_TYPE_WRCOMB     1
/*#define MTRR_TYPE_         2*/
/*#define MTRR_TYPE_         3*/
#define MTRR_TYPE_WRTHROUGH  4
#define MTRR_TYPE_WRPROT     5
#define MTRR_TYPE_WRBACK     6
#define MTRR_NUM_TYPES       7

116
#ifdef __KERNEL__
T
Thomas Gleixner 已提交
117 118 119

/*  The following functions are for use by other drivers  */
# ifdef CONFIG_MTRR
I
Ingo Molnar 已提交
120
extern u8 mtrr_type_lookup(u64 addr, u64 end);
T
Thomas Gleixner 已提交
121 122
extern void mtrr_save_fixed_ranges(void *);
extern void mtrr_save_state(void);
123 124 125 126 127 128
extern int mtrr_add(unsigned long base, unsigned long size,
		    unsigned int type, bool increment);
extern int mtrr_add_page(unsigned long base, unsigned long size,
			 unsigned int type, bool increment);
extern int mtrr_del(int reg, unsigned long base, unsigned long size);
extern int mtrr_del_page(int reg, unsigned long base, unsigned long size);
T
Thomas Gleixner 已提交
129 130 131
extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
extern void mtrr_ap_init(void);
extern void mtrr_bp_init(void);
132 133 134
extern void set_mtrr_aps_delayed_init(void);
extern void mtrr_aps_init(void);
extern void mtrr_bp_restore(void);
135
extern int mtrr_trim_uncached_memory(unsigned long end_pfn);
136
extern int amd_special_default_mtrr(void);
T
Thomas Gleixner 已提交
137
#  else
I
Ingo Molnar 已提交
138 139 140 141 142 143 144
static inline u8 mtrr_type_lookup(u64 addr, u64 end)
{
	/*
	 * Return no-MTRRs:
	 */
	return 0xff;
}
T
Thomas Gleixner 已提交
145 146
#define mtrr_save_fixed_ranges(arg) do {} while (0)
#define mtrr_save_state() do {} while (0)
147 148
static inline int mtrr_add(unsigned long base, unsigned long size,
			   unsigned int type, bool increment)
T
Thomas Gleixner 已提交
149 150 151
{
    return -ENODEV;
}
152
static inline int mtrr_add_page(unsigned long base, unsigned long size,
153
				unsigned int type, bool increment)
T
Thomas Gleixner 已提交
154 155 156
{
    return -ENODEV;
}
157
static inline int mtrr_del(int reg, unsigned long base, unsigned long size)
T
Thomas Gleixner 已提交
158 159 160
{
    return -ENODEV;
}
161
static inline int mtrr_del_page(int reg, unsigned long base, unsigned long size)
T
Thomas Gleixner 已提交
162 163 164
{
    return -ENODEV;
}
165 166 167 168
static inline int mtrr_trim_uncached_memory(unsigned long end_pfn)
{
	return 0;
}
169 170 171
static inline void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
{
}
T
Thomas Gleixner 已提交
172 173 174

#define mtrr_ap_init() do {} while (0)
#define mtrr_bp_init() do {} while (0)
175 176 177
#define set_mtrr_aps_delayed_init() do {} while (0)
#define mtrr_aps_init() do {} while (0)
#define mtrr_bp_restore() do {} while (0)
T
Thomas Gleixner 已提交
178 179 180 181 182
#  endif

#ifdef CONFIG_COMPAT
#include <linux/compat.h>

183
struct mtrr_sentry32 {
T
Thomas Gleixner 已提交
184 185 186 187 188
    compat_ulong_t base;    /*  Base address     */
    compat_uint_t size;    /*  Size of region   */
    compat_uint_t type;     /*  Type of region   */
};

189
struct mtrr_gentry32 {
T
Thomas Gleixner 已提交
190 191 192 193 194 195 196 197
    compat_ulong_t regnum;   /*  Register number  */
    compat_uint_t base;    /*  Base address     */
    compat_uint_t size;    /*  Size of region   */
    compat_uint_t type;     /*  Type of region   */
};

#define MTRR_IOCTL_BASE 'M'

198 199 200 201 202 203 204 205 206 207 208
#define MTRRIOC32_ADD_ENTRY      _IOW(MTRR_IOCTL_BASE,  0, struct mtrr_sentry32)
#define MTRRIOC32_SET_ENTRY      _IOW(MTRR_IOCTL_BASE,  1, struct mtrr_sentry32)
#define MTRRIOC32_DEL_ENTRY      _IOW(MTRR_IOCTL_BASE,  2, struct mtrr_sentry32)
#define MTRRIOC32_GET_ENTRY      _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry32)
#define MTRRIOC32_KILL_ENTRY     _IOW(MTRR_IOCTL_BASE,  4, struct mtrr_sentry32)
#define MTRRIOC32_ADD_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE,  5, struct mtrr_sentry32)
#define MTRRIOC32_SET_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE,  6, struct mtrr_sentry32)
#define MTRRIOC32_DEL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE,  7, struct mtrr_sentry32)
#define MTRRIOC32_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry32)
#define MTRRIOC32_KILL_PAGE_ENTRY		\
				 _IOW(MTRR_IOCTL_BASE,  9, struct mtrr_sentry32)
T
Thomas Gleixner 已提交
209 210 211 212
#endif /* CONFIG_COMPAT */

#endif /* __KERNEL__ */

H
H. Peter Anvin 已提交
213
#endif /* _ASM_X86_MTRR_H */