Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 88889
b: refs/heads/master
c: 2e5d9c8
h: refs/heads/master
i:
  88887: f07d626
v: v3
  • Loading branch information
venkatesh.pallipadi@intel.com authored and Ingo Molnar committed Apr 17, 2008
1 parent 9bdd59e commit 072278e
Show file tree
Hide file tree
Showing 11 changed files with 569 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d27554d874c7eeb14c8bfecdc39c3a8618cd8d32
refs/heads/master: 2e5d9c857d4e6c9e7b7d8c8c86a68a7842d213d6
15 changes: 15 additions & 0 deletions trunk/arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,21 @@ config MTRR

See <file:Documentation/mtrr.txt> for more information.

config X86_PAT
def_bool y
prompt "x86 PAT support"
depends on MTRR && NONPROMISC_DEVMEM
help
Use PAT attributes to setup page level cache control.
---help---
PATs are the modern equivalents of MTRRs and are much more
flexible than MTRRs.

Say N here if you see bootup problems (boot crash, boot hang,
spontaneous reboots) or a non-working Xorg.

If unsure, say Y.

config EFI
def_bool n
prompt "EFI runtime service support"
Expand Down
120 changes: 120 additions & 0 deletions trunk/arch/x86/kernel/cpu/mtrr/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <asm/cpufeature.h>
#include <asm/processor-flags.h>
#include <asm/tlbflush.h>
#include <asm/pat.h>
#include "mtrr.h"

struct mtrr_state {
Expand All @@ -35,13 +36,114 @@ static struct fixed_range_block fixed_range_blocks[] = {

static unsigned long smp_changes_mask;
static struct mtrr_state mtrr_state = {};
static int mtrr_state_set;

#undef MODULE_PARAM_PREFIX
#define MODULE_PARAM_PREFIX "mtrr."

static int mtrr_show;
module_param_named(show, mtrr_show, bool, 0);

/*
* Returns the effective MTRR type for the region
* Error returns:
* - 0xFE - when the range is "not entirely covered" by _any_ var range MTRR
* - 0xFF - when MTRR is not enabled
*/
u8 mtrr_type_lookup(u64 start, u64 end)
{
int i;
u64 base, mask;
u8 prev_match, curr_match;

if (!mtrr_state_set)
return 0xFF;

if (!mtrr_state.enabled)
return 0xFF;

/* Make end inclusive end, instead of exclusive */
end--;

/* Look in fixed ranges. Just return the type as per start */
if (mtrr_state.have_fixed && (start < 0x100000)) {
int idx;

if (start < 0x80000) {
idx = 0;
idx += (start >> 16);
return mtrr_state.fixed_ranges[idx];
} else if (start < 0xC0000) {
idx = 1 * 8;
idx += ((start - 0x80000) >> 14);
return mtrr_state.fixed_ranges[idx];
} else if (start < 0x1000000) {
idx = 3 * 8;
idx += ((start - 0xC0000) >> 12);
return mtrr_state.fixed_ranges[idx];
}
}

/*
* Look in variable ranges
* Look of multiple ranges matching this address and pick type
* as per MTRR precedence
*/
if (!mtrr_state.enabled & 2) {
return mtrr_state.def_type;
}

prev_match = 0xFF;
for (i = 0; i < num_var_ranges; ++i) {
unsigned short start_state, end_state;

if (!(mtrr_state.var_ranges[i].mask_lo & (1 << 11)))
continue;

base = (((u64)mtrr_state.var_ranges[i].base_hi) << 32) +
(mtrr_state.var_ranges[i].base_lo & PAGE_MASK);
mask = (((u64)mtrr_state.var_ranges[i].mask_hi) << 32) +
(mtrr_state.var_ranges[i].mask_lo & PAGE_MASK);

start_state = ((start & mask) == (base & mask));
end_state = ((end & mask) == (base & mask));
if (start_state != end_state)
return 0xFE;

if ((start & mask) != (base & mask)) {
continue;
}

curr_match = mtrr_state.var_ranges[i].base_lo & 0xff;
if (prev_match == 0xFF) {
prev_match = curr_match;
continue;
}

if (prev_match == MTRR_TYPE_UNCACHABLE ||
curr_match == MTRR_TYPE_UNCACHABLE) {
return MTRR_TYPE_UNCACHABLE;
}

if ((prev_match == MTRR_TYPE_WRBACK &&
curr_match == MTRR_TYPE_WRTHROUGH) ||
(prev_match == MTRR_TYPE_WRTHROUGH &&
curr_match == MTRR_TYPE_WRBACK)) {
prev_match = MTRR_TYPE_WRTHROUGH;
curr_match = MTRR_TYPE_WRTHROUGH;
}

if (prev_match != curr_match) {
return MTRR_TYPE_UNCACHABLE;
}
}

if (prev_match != 0xFF)
return prev_match;

return mtrr_state.def_type;
}

/* Get the MSR pair relating to a var range */
static void
get_mtrr_var_range(unsigned int index, struct mtrr_var_range *vr)
Expand Down Expand Up @@ -79,12 +181,16 @@ static void print_fixed(unsigned base, unsigned step, const mtrr_type*types)
base, base + step - 1, mtrr_attrib_to_str(*types));
}

static void prepare_set(void);
static void post_set(void);

/* Grab all of the MTRR state for this CPU into *state */
void __init get_mtrr_state(void)
{
unsigned int i;
struct mtrr_var_range *vrs;
unsigned lo, dummy;
unsigned long flags;

vrs = mtrr_state.var_ranges;

Expand Down Expand Up @@ -131,6 +237,17 @@ void __init get_mtrr_state(void)
printk(KERN_INFO "MTRR %u disabled\n", i);
}
}
mtrr_state_set = 1;

/* PAT setup for BP. We need to go through sync steps here */
local_irq_save(flags);
prepare_set();

pat_init();

post_set();
local_irq_restore(flags);

}

/* Some BIOS's are fucked and don't set all MTRRs the same! */
Expand Down Expand Up @@ -397,6 +514,9 @@ static void generic_set_all(void)
/* Actually set the state */
mask = set_mtrr_state();

/* also set PAT */
pat_init();

post_set();
local_irq_restore(flags);

Expand Down
3 changes: 2 additions & 1 deletion trunk/arch/x86/mm/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
obj-y := init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o
obj-y := init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \
pat.o

obj-$(CONFIG_X86_32) += pgtable_32.o

Expand Down
4 changes: 2 additions & 2 deletions trunk/arch/x86/mm/pageattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,14 @@ static inline int change_page_attr_clear(unsigned long addr, int numpages,
int set_memory_uc(unsigned long addr, int numpages)
{
return change_page_attr_set(addr, numpages,
__pgprot(_PAGE_PCD));
__pgprot(_PAGE_CACHE_UC));
}
EXPORT_SYMBOL(set_memory_uc);

int set_memory_wb(unsigned long addr, int numpages)
{
return change_page_attr_clear(addr, numpages,
__pgprot(_PAGE_PCD | _PAGE_PWT));
__pgprot(_PAGE_CACHE_MASK));
}
EXPORT_SYMBOL(set_memory_wb);

Expand Down
Loading

0 comments on commit 072278e

Please sign in to comment.