提交 2d2ee8de 编写于 作者: P Paul Jimenez 提交者: Ingo Molnar

x86: mtrr use type bool [RESEND AGAIN]

This is a janitorish patch to 1) remove private TRUE/FALSE #def's in
favor of using the standard enum from linux/stddef.h and 2) switch the
variables holding those values to type 'bool' (from linux/types.h)
since it both seems more appropriate and allows for potentially better
optimization.

As a truly minor aside, I removed a couple of comments documenting
a 'do_safe' parameter that seems to no longer exist.
Signed-off-by: NPaul Jimenez <pj@place.org>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 3e759396
...@@ -53,8 +53,6 @@ static void amd_set_mtrr(unsigned int reg, unsigned long base, ...@@ -53,8 +53,6 @@ static void amd_set_mtrr(unsigned int reg, unsigned long base,
<base> The base address of the region. <base> The base address of the region.
<size> The size of the region. If this is 0 the region is disabled. <size> The size of the region. If this is 0 the region is disabled.
<type> The type of the region. <type> The type of the region.
<do_safe> If TRUE, do the change safely. If FALSE, safety measures should
be done externally.
[RETURNS] Nothing. [RETURNS] Nothing.
*/ */
{ {
......
...@@ -188,7 +188,7 @@ static inline void k8_enable_fixed_iorrs(void) ...@@ -188,7 +188,7 @@ static inline void k8_enable_fixed_iorrs(void)
* \param changed pointer which indicates whether the MTRR needed to be changed * \param changed pointer which indicates whether the MTRR needed to be changed
* \param msrwords pointer to the MSR values which the MSR should have * \param msrwords pointer to the MSR values which the MSR should have
*/ */
static void set_fixed_range(int msr, int * changed, unsigned int * msrwords) static void set_fixed_range(int msr, bool *changed, unsigned int *msrwords)
{ {
unsigned lo, hi; unsigned lo, hi;
...@@ -200,7 +200,7 @@ static void set_fixed_range(int msr, int * changed, unsigned int * msrwords) ...@@ -200,7 +200,7 @@ static void set_fixed_range(int msr, int * changed, unsigned int * msrwords)
((msrwords[0] | msrwords[1]) & K8_MTRR_RDMEM_WRMEM_MASK)) ((msrwords[0] | msrwords[1]) & K8_MTRR_RDMEM_WRMEM_MASK))
k8_enable_fixed_iorrs(); k8_enable_fixed_iorrs();
mtrr_wrmsr(msr, msrwords[0], msrwords[1]); mtrr_wrmsr(msr, msrwords[0], msrwords[1]);
*changed = TRUE; *changed = true;
} }
} }
...@@ -260,7 +260,7 @@ static void generic_get_mtrr(unsigned int reg, unsigned long *base, ...@@ -260,7 +260,7 @@ static void generic_get_mtrr(unsigned int reg, unsigned long *base,
static int set_fixed_ranges(mtrr_type * frs) static int set_fixed_ranges(mtrr_type * frs)
{ {
unsigned long long *saved = (unsigned long long *) frs; unsigned long long *saved = (unsigned long long *) frs;
int changed = FALSE; bool changed = false;
int block=-1, range; int block=-1, range;
while (fixed_range_blocks[++block].ranges) while (fixed_range_blocks[++block].ranges)
...@@ -273,17 +273,17 @@ static int set_fixed_ranges(mtrr_type * frs) ...@@ -273,17 +273,17 @@ static int set_fixed_ranges(mtrr_type * frs)
/* Set the MSR pair relating to a var range. Returns TRUE if /* Set the MSR pair relating to a var range. Returns TRUE if
changes are made */ changes are made */
static int set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr) static bool set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
{ {
unsigned int lo, hi; unsigned int lo, hi;
int changed = FALSE; bool changed = false;
rdmsr(MTRRphysBase_MSR(index), lo, hi); rdmsr(MTRRphysBase_MSR(index), lo, hi);
if ((vr->base_lo & 0xfffff0ffUL) != (lo & 0xfffff0ffUL) if ((vr->base_lo & 0xfffff0ffUL) != (lo & 0xfffff0ffUL)
|| (vr->base_hi & (size_and_mask >> (32 - PAGE_SHIFT))) != || (vr->base_hi & (size_and_mask >> (32 - PAGE_SHIFT))) !=
(hi & (size_and_mask >> (32 - PAGE_SHIFT)))) { (hi & (size_and_mask >> (32 - PAGE_SHIFT)))) {
mtrr_wrmsr(MTRRphysBase_MSR(index), vr->base_lo, vr->base_hi); mtrr_wrmsr(MTRRphysBase_MSR(index), vr->base_lo, vr->base_hi);
changed = TRUE; changed = true;
} }
rdmsr(MTRRphysMask_MSR(index), lo, hi); rdmsr(MTRRphysMask_MSR(index), lo, hi);
...@@ -292,7 +292,7 @@ static int set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr) ...@@ -292,7 +292,7 @@ static int set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
|| (vr->mask_hi & (size_and_mask >> (32 - PAGE_SHIFT))) != || (vr->mask_hi & (size_and_mask >> (32 - PAGE_SHIFT))) !=
(hi & (size_and_mask >> (32 - PAGE_SHIFT)))) { (hi & (size_and_mask >> (32 - PAGE_SHIFT)))) {
mtrr_wrmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi); mtrr_wrmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi);
changed = TRUE; changed = true;
} }
return changed; return changed;
} }
...@@ -417,8 +417,6 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base, ...@@ -417,8 +417,6 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base,
<base> The base address of the region. <base> The base address of the region.
<size> The size of the region. If this is 0 the region is disabled. <size> The size of the region. If this is 0 the region is disabled.
<type> The type of the region. <type> The type of the region.
<do_safe> If TRUE, do the change safely. If FALSE, safety measures should
be done externally.
[RETURNS] Nothing. [RETURNS] Nothing.
*/ */
{ {
......
...@@ -37,7 +37,7 @@ const char *mtrr_attrib_to_str(int x) ...@@ -37,7 +37,7 @@ const char *mtrr_attrib_to_str(int x)
static int static int
mtrr_file_add(unsigned long base, unsigned long size, mtrr_file_add(unsigned long base, unsigned long size,
unsigned int type, char increment, struct file *file, int page) unsigned int type, bool increment, struct file *file, int page)
{ {
int reg, max; int reg, max;
unsigned int *fcount = FILE_FCOUNT(file); unsigned int *fcount = FILE_FCOUNT(file);
...@@ -55,7 +55,7 @@ mtrr_file_add(unsigned long base, unsigned long size, ...@@ -55,7 +55,7 @@ mtrr_file_add(unsigned long base, unsigned long size,
base >>= PAGE_SHIFT; base >>= PAGE_SHIFT;
size >>= PAGE_SHIFT; size >>= PAGE_SHIFT;
} }
reg = mtrr_add_page(base, size, type, 1); reg = mtrr_add_page(base, size, type, true);
if (reg >= 0) if (reg >= 0)
++fcount[reg]; ++fcount[reg];
return reg; return reg;
...@@ -141,7 +141,7 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) ...@@ -141,7 +141,7 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
size >>= PAGE_SHIFT; size >>= PAGE_SHIFT;
err = err =
mtrr_add_page((unsigned long) base, (unsigned long) size, i, mtrr_add_page((unsigned long) base, (unsigned long) size, i,
1); true);
if (err < 0) if (err < 0)
return err; return err;
return len; return len;
...@@ -217,7 +217,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -217,7 +217,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
err = err =
mtrr_file_add(sentry.base, sentry.size, sentry.type, 1, mtrr_file_add(sentry.base, sentry.size, sentry.type, true,
file, 0); file, 0);
break; break;
case MTRRIOC_SET_ENTRY: case MTRRIOC_SET_ENTRY:
...@@ -226,7 +226,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -226,7 +226,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#endif #endif
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
err = mtrr_add(sentry.base, sentry.size, sentry.type, 0); err = mtrr_add(sentry.base, sentry.size, sentry.type, false);
break; break;
case MTRRIOC_DEL_ENTRY: case MTRRIOC_DEL_ENTRY:
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
...@@ -270,7 +270,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -270,7 +270,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
err = err =
mtrr_file_add(sentry.base, sentry.size, sentry.type, 1, mtrr_file_add(sentry.base, sentry.size, sentry.type, true,
file, 1); file, 1);
break; break;
case MTRRIOC_SET_PAGE_ENTRY: case MTRRIOC_SET_PAGE_ENTRY:
...@@ -279,7 +279,8 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -279,7 +279,8 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#endif #endif
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
err = mtrr_add_page(sentry.base, sentry.size, sentry.type, 0); err =
mtrr_add_page(sentry.base, sentry.size, sentry.type, false);
break; break;
case MTRRIOC_DEL_PAGE_ENTRY: case MTRRIOC_DEL_PAGE_ENTRY:
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
......
...@@ -311,7 +311,7 @@ static void set_mtrr(unsigned int reg, unsigned long base, ...@@ -311,7 +311,7 @@ static void set_mtrr(unsigned int reg, unsigned long base,
*/ */
int mtrr_add_page(unsigned long base, unsigned long size, int mtrr_add_page(unsigned long base, unsigned long size,
unsigned int type, char increment) unsigned int type, bool increment)
{ {
int i, replace, error; int i, replace, error;
mtrr_type ltype; mtrr_type ltype;
...@@ -394,7 +394,9 @@ int mtrr_add_page(unsigned long base, unsigned long size, ...@@ -394,7 +394,9 @@ int mtrr_add_page(unsigned long base, unsigned long size,
if (likely(replace < 0)) if (likely(replace < 0))
usage_table[i] = 1; usage_table[i] = 1;
else { else {
usage_table[i] = usage_table[replace] + !!increment; usage_table[i] = usage_table[replace];
if (increment)
usage_table[i]++;
if (unlikely(replace != i)) { if (unlikely(replace != i)) {
set_mtrr(replace, 0, 0, 0); set_mtrr(replace, 0, 0, 0);
usage_table[replace] = 0; usage_table[replace] = 0;
...@@ -460,7 +462,7 @@ static int mtrr_check(unsigned long base, unsigned long size) ...@@ -460,7 +462,7 @@ static int mtrr_check(unsigned long base, unsigned long size)
int int
mtrr_add(unsigned long base, unsigned long size, unsigned int type, mtrr_add(unsigned long base, unsigned long size, unsigned int type,
char increment) bool increment)
{ {
if (mtrr_check(base, size)) if (mtrr_check(base, size))
return -EINVAL; return -EINVAL;
......
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
* local mtrr defines. * local mtrr defines.
*/ */
#ifndef TRUE #include <linux/types.h>
#define TRUE 1 #include <linux/stddef.h>
#define FALSE 0
#endif
#define MTRRcap_MSR 0x0fe #define MTRRcap_MSR 0x0fe
#define MTRRdefType_MSR 0x2ff #define MTRRdefType_MSR 0x2ff
......
...@@ -89,9 +89,9 @@ struct mtrr_gentry ...@@ -89,9 +89,9 @@ struct mtrr_gentry
extern void mtrr_save_fixed_ranges(void *); extern void mtrr_save_fixed_ranges(void *);
extern void mtrr_save_state(void); extern void mtrr_save_state(void);
extern int mtrr_add (unsigned long base, unsigned long size, extern int mtrr_add (unsigned long base, unsigned long size,
unsigned int type, char increment); unsigned int type, bool increment);
extern int mtrr_add_page (unsigned long base, unsigned long size, extern int mtrr_add_page (unsigned long base, unsigned long size,
unsigned int type, char increment); unsigned int type, bool increment);
extern int mtrr_del (int reg, unsigned long base, unsigned long size); 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); extern int mtrr_del_page (int reg, unsigned long base, unsigned long size);
extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi); extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
...@@ -101,12 +101,12 @@ extern void mtrr_bp_init(void); ...@@ -101,12 +101,12 @@ extern void mtrr_bp_init(void);
#define mtrr_save_fixed_ranges(arg) do {} while (0) #define mtrr_save_fixed_ranges(arg) do {} while (0)
#define mtrr_save_state() do {} while (0) #define mtrr_save_state() do {} while (0)
static __inline__ int mtrr_add (unsigned long base, unsigned long size, static __inline__ int mtrr_add (unsigned long base, unsigned long size,
unsigned int type, char increment) unsigned int type, bool increment)
{ {
return -ENODEV; return -ENODEV;
} }
static __inline__ int mtrr_add_page (unsigned long base, unsigned long size, static __inline__ int mtrr_add_page (unsigned long base, unsigned long size,
unsigned int type, char increment) unsigned int type, bool increment)
{ {
return -ENODEV; return -ENODEV;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册