2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2009-07-04 10:24:16 +08:00
|
|
|
* local MTRR defines.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2008-01-30 20:30:31 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/stddef.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define MTRR_CHANGE_MASK_FIXED 0x01
|
|
|
|
#define MTRR_CHANGE_MASK_VARIABLE 0x02
|
|
|
|
#define MTRR_CHANGE_MASK_DEFTYPE 0x04
|
|
|
|
|
2008-10-09 16:01:52 +08:00
|
|
|
extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
|
x86, 32-bit: trim memory not covered by wb mtrrs
On some machines, buggy BIOSes don't properly setup WB MTRRs to cover all
available RAM, meaning the last few megs (or even gigs) of memory will be
marked uncached. Since Linux tends to allocate from high memory addresses
first, this causes the machine to be unusably slow as soon as the kernel
starts really using memory (i.e. right around init time).
This patch works around the problem by scanning the MTRRs at boot and
figuring out whether the current end_pfn value (setup by early e820 code)
goes beyond the highest WB MTRR range, and if so, trimming it to match. A
fairly obnoxious KERN_WARNING is printed too, letting the user know that
not all of their memory is available due to a likely BIOS bug.
Something similar could be done on i386 if needed, but the boot ordering
would be slightly different, since the MTRR code on i386 depends on the
boot_cpu_data structure being setup.
This patch fixes a bug in the last patch that caused the code to run on
non-Intel machines (AMD machines apparently don't need it and it's untested
on other non-Intel machines, so best keep it off).
Further enhancements and fixes from:
Yinghai Lu <Yinghai.Lu@Sun.COM>
Andi Kleen <ak@suse.de>
Signed-off-by: Jesse Barnes <jesse.barnes@intel.com>
Tested-by: Justin Piszcz <jpiszcz@lucidpixels.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Yinghai Lu <yhlu.kernel@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-01-30 20:33:18 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct mtrr_ops {
|
|
|
|
u32 vendor;
|
|
|
|
u32 use_intel_if;
|
|
|
|
void (*set)(unsigned int reg, unsigned long base,
|
|
|
|
unsigned long size, mtrr_type type);
|
|
|
|
void (*set_all)(void);
|
|
|
|
|
|
|
|
void (*get)(unsigned int reg, unsigned long *base,
|
2009-07-04 10:24:16 +08:00
|
|
|
unsigned long *size, mtrr_type *type);
|
[PATCH] i386: fix MTRR code
Until not so long ago, there were system log messages pointing to
inconsistent MTRR setup of the video frame buffer caused by the way vesafb
and X worked. While vesafb was fixed meanwhile, I believe fixing it there
only hides a shortcoming in the MTRR code itself, in that that code is not
symmetric with respect to the ordering of attempts to set up two (or more)
regions where one contains the other. In the current shape, it permits
only setting up sub-regions of pre-exisiting ones. The patch below makes
this symmetric.
While working on that I noticed a few more inconsistencies in that code,
namely
- use of 'unsigned int' for sizes in many, but not all places (the patch
is converting this to use 'unsigned long' everywhere, which specifically
might be necessary for x86-64 once a processor supporting more than 44
physical address bits would become available)
- the code to correct inconsistent settings during secondary processor
startup tried (if necessary) to correct, among other things, the value
in IA32_MTRR_DEF_TYPE, however the newly computed value would never get
used (i.e. stored in the respective MSR)
- the generic range validation code checked that the end of the
to-be-added range would be above 1MB; the value checked should have been
the start of the range
- when contained regions are detected, previously this was allowed only
when the old region was uncacheable; this can be symmetric (i.e. the new
region can also be uncacheable) and even further as per Intel's
documentation write-trough and write-back for either region is also
compatible with the respective opposite in the other
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andi Kleen <ak@suse.de>
2006-12-07 09:14:09 +08:00
|
|
|
int (*get_free_region)(unsigned long base, unsigned long size,
|
|
|
|
int replace_reg);
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*validate_add_page)(unsigned long base, unsigned long size,
|
|
|
|
unsigned int type);
|
|
|
|
int (*have_wrcomb)(void);
|
|
|
|
};
|
|
|
|
|
[PATCH] i386: fix MTRR code
Until not so long ago, there were system log messages pointing to
inconsistent MTRR setup of the video frame buffer caused by the way vesafb
and X worked. While vesafb was fixed meanwhile, I believe fixing it there
only hides a shortcoming in the MTRR code itself, in that that code is not
symmetric with respect to the ordering of attempts to set up two (or more)
regions where one contains the other. In the current shape, it permits
only setting up sub-regions of pre-exisiting ones. The patch below makes
this symmetric.
While working on that I noticed a few more inconsistencies in that code,
namely
- use of 'unsigned int' for sizes in many, but not all places (the patch
is converting this to use 'unsigned long' everywhere, which specifically
might be necessary for x86-64 once a processor supporting more than 44
physical address bits would become available)
- the code to correct inconsistent settings during secondary processor
startup tried (if necessary) to correct, among other things, the value
in IA32_MTRR_DEF_TYPE, however the newly computed value would never get
used (i.e. stored in the respective MSR)
- the generic range validation code checked that the end of the
to-be-added range would be above 1MB; the value checked should have been
the start of the range
- when contained regions are detected, previously this was allowed only
when the old region was uncacheable; this can be symmetric (i.e. the new
region can also be uncacheable) and even further as per Intel's
documentation write-trough and write-back for either region is also
compatible with the respective opposite in the other
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andi Kleen <ak@suse.de>
2006-12-07 09:14:09 +08:00
|
|
|
extern int generic_get_free_region(unsigned long base, unsigned long size,
|
|
|
|
int replace_reg);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern int generic_validate_add_page(unsigned long base, unsigned long size,
|
|
|
|
unsigned int type);
|
|
|
|
|
|
|
|
extern struct mtrr_ops generic_mtrr_ops;
|
|
|
|
|
|
|
|
extern int positive_have_wrcomb(void);
|
|
|
|
|
|
|
|
/* library functions for processor-specific routines */
|
|
|
|
struct set_mtrr_context {
|
2009-07-04 10:24:16 +08:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long cr4val;
|
|
|
|
u32 deftype_lo;
|
|
|
|
u32 deftype_hi;
|
|
|
|
u32 ccr3;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void set_mtrr_done(struct set_mtrr_context *ctxt);
|
|
|
|
void set_mtrr_cache_disable(struct set_mtrr_context *ctxt);
|
|
|
|
void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);
|
|
|
|
|
2008-04-29 18:52:33 +08:00
|
|
|
void fill_mtrr_var_range(unsigned int index,
|
|
|
|
u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
|
2005-04-17 06:20:36 +08:00
|
|
|
void get_mtrr_state(void);
|
|
|
|
|
2009-07-04 10:24:16 +08:00
|
|
|
extern void set_mtrr_ops(struct mtrr_ops *ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-13 20:26:23 +08:00
|
|
|
extern u64 size_or_mask, size_and_mask;
|
2009-07-04 10:24:16 +08:00
|
|
|
extern struct mtrr_ops *mtrr_if;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
|
|
|
|
#define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
|
|
|
|
|
|
|
|
extern unsigned int num_var_ranges;
|
2008-04-29 18:52:33 +08:00
|
|
|
extern u64 mtrr_tom2;
|
2009-03-17 07:33:59 +08:00
|
|
|
extern struct mtrr_state_type mtrr_state;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void mtrr_state_warn(void);
|
[PATCH] i386: fix MTRR code
Until not so long ago, there were system log messages pointing to
inconsistent MTRR setup of the video frame buffer caused by the way vesafb
and X worked. While vesafb was fixed meanwhile, I believe fixing it there
only hides a shortcoming in the MTRR code itself, in that that code is not
symmetric with respect to the ordering of attempts to set up two (or more)
regions where one contains the other. In the current shape, it permits
only setting up sub-regions of pre-exisiting ones. The patch below makes
this symmetric.
While working on that I noticed a few more inconsistencies in that code,
namely
- use of 'unsigned int' for sizes in many, but not all places (the patch
is converting this to use 'unsigned long' everywhere, which specifically
might be necessary for x86-64 once a processor supporting more than 44
physical address bits would become available)
- the code to correct inconsistent settings during secondary processor
startup tried (if necessary) to correct, among other things, the value
in IA32_MTRR_DEF_TYPE, however the newly computed value would never get
used (i.e. stored in the respective MSR)
- the generic range validation code checked that the end of the
to-be-added range would be above 1MB; the value checked should have been
the start of the range
- when contained regions are detected, previously this was allowed only
when the old region was uncacheable; this can be symmetric (i.e. the new
region can also be uncacheable) and even further as per Intel's
documentation write-trough and write-back for either region is also
compatible with the respective opposite in the other
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andi Kleen <ak@suse.de>
2006-12-07 09:14:09 +08:00
|
|
|
const char *mtrr_attrib_to_str(int x);
|
2005-04-17 06:20:36 +08:00
|
|
|
void mtrr_wrmsr(unsigned, unsigned, unsigned);
|
|
|
|
|
2008-02-04 23:48:05 +08:00
|
|
|
/* CPU specific mtrr init functions */
|
|
|
|
int amd_init_mtrr(void);
|
|
|
|
int cyrix_init_mtrr(void);
|
|
|
|
int centaur_init_mtrr(void);
|
2009-03-12 11:07:39 +08:00
|
|
|
|
|
|
|
extern int changed_by_mtrr_cleanup;
|
|
|
|
extern int mtrr_cleanup(unsigned address_bits);
|