Path: blob/master/arch/x86/kernel/cpu/mtrr/generic.c
10775 views
/*1* This only handles 32bit MTRR on 32bit hosts. This is strictly wrong2* because MTRRs can span up to 40 bits (36bits on most modern x86)3*/4#define DEBUG56#include <linux/module.h>7#include <linux/init.h>8#include <linux/io.h>9#include <linux/mm.h>1011#include <asm/processor-flags.h>12#include <asm/cpufeature.h>13#include <asm/tlbflush.h>14#include <asm/system.h>15#include <asm/mtrr.h>16#include <asm/msr.h>17#include <asm/pat.h>1819#include "mtrr.h"2021struct fixed_range_block {22int base_msr; /* start address of an MTRR block */23int ranges; /* number of MTRRs in this block */24};2526static struct fixed_range_block fixed_range_blocks[] = {27{ MSR_MTRRfix64K_00000, 1 }, /* one 64k MTRR */28{ MSR_MTRRfix16K_80000, 2 }, /* two 16k MTRRs */29{ MSR_MTRRfix4K_C0000, 8 }, /* eight 4k MTRRs */30{}31};3233static unsigned long smp_changes_mask;34static int mtrr_state_set;35u64 mtrr_tom2;3637struct mtrr_state_type mtrr_state;38EXPORT_SYMBOL_GPL(mtrr_state);3940/*41* BIOS is expected to clear MtrrFixDramModEn bit, see for example42* "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD43* Opteron Processors" (26094 Rev. 3.30 February 2006), section44* "13.2.1.2 SYSCFG Register": "The MtrrFixDramModEn bit should be set45* to 1 during BIOS initalization of the fixed MTRRs, then cleared to46* 0 for operation."47*/48static inline void k8_check_syscfg_dram_mod_en(void)49{50u32 lo, hi;5152if (!((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&53(boot_cpu_data.x86 >= 0x0f)))54return;5556rdmsr(MSR_K8_SYSCFG, lo, hi);57if (lo & K8_MTRRFIXRANGE_DRAM_MODIFY) {58printk(KERN_ERR FW_WARN "MTRR: CPU %u: SYSCFG[MtrrFixDramModEn]"59" not cleared by BIOS, clearing this bit\n",60smp_processor_id());61lo &= ~K8_MTRRFIXRANGE_DRAM_MODIFY;62mtrr_wrmsr(MSR_K8_SYSCFG, lo, hi);63}64}6566/* Get the size of contiguous MTRR range */67static u64 get_mtrr_size(u64 mask)68{69u64 size;7071mask >>= PAGE_SHIFT;72mask |= size_or_mask;73size = -mask;74size <<= PAGE_SHIFT;75return size;76}7778/*79* Check and return the effective type for MTRR-MTRR type overlap.80* Returns 1 if the effective type is UNCACHEABLE, else returns 081*/82static int check_type_overlap(u8 *prev, u8 *curr)83{84if (*prev == MTRR_TYPE_UNCACHABLE || *curr == MTRR_TYPE_UNCACHABLE) {85*prev = MTRR_TYPE_UNCACHABLE;86*curr = MTRR_TYPE_UNCACHABLE;87return 1;88}8990if ((*prev == MTRR_TYPE_WRBACK && *curr == MTRR_TYPE_WRTHROUGH) ||91(*prev == MTRR_TYPE_WRTHROUGH && *curr == MTRR_TYPE_WRBACK)) {92*prev = MTRR_TYPE_WRTHROUGH;93*curr = MTRR_TYPE_WRTHROUGH;94}9596if (*prev != *curr) {97*prev = MTRR_TYPE_UNCACHABLE;98*curr = MTRR_TYPE_UNCACHABLE;99return 1;100}101102return 0;103}104105/*106* Error/Semi-error returns:107* 0xFF - when MTRR is not enabled108* *repeat == 1 implies [start:end] spanned across MTRR range and type returned109* corresponds only to [start:*partial_end].110* Caller has to lookup again for [*partial_end:end].111*/112static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)113{114int i;115u64 base, mask;116u8 prev_match, curr_match;117118*repeat = 0;119if (!mtrr_state_set)120return 0xFF;121122if (!mtrr_state.enabled)123return 0xFF;124125/* Make end inclusive end, instead of exclusive */126end--;127128/* Look in fixed ranges. Just return the type as per start */129if (mtrr_state.have_fixed && (start < 0x100000)) {130int idx;131132if (start < 0x80000) {133idx = 0;134idx += (start >> 16);135return mtrr_state.fixed_ranges[idx];136} else if (start < 0xC0000) {137idx = 1 * 8;138idx += ((start - 0x80000) >> 14);139return mtrr_state.fixed_ranges[idx];140} else if (start < 0x1000000) {141idx = 3 * 8;142idx += ((start - 0xC0000) >> 12);143return mtrr_state.fixed_ranges[idx];144}145}146147/*148* Look in variable ranges149* Look of multiple ranges matching this address and pick type150* as per MTRR precedence151*/152if (!(mtrr_state.enabled & 2))153return mtrr_state.def_type;154155prev_match = 0xFF;156for (i = 0; i < num_var_ranges; ++i) {157unsigned short start_state, end_state;158159if (!(mtrr_state.var_ranges[i].mask_lo & (1 << 11)))160continue;161162base = (((u64)mtrr_state.var_ranges[i].base_hi) << 32) +163(mtrr_state.var_ranges[i].base_lo & PAGE_MASK);164mask = (((u64)mtrr_state.var_ranges[i].mask_hi) << 32) +165(mtrr_state.var_ranges[i].mask_lo & PAGE_MASK);166167start_state = ((start & mask) == (base & mask));168end_state = ((end & mask) == (base & mask));169170if (start_state != end_state) {171/*172* We have start:end spanning across an MTRR.173* We split the region into174* either175* (start:mtrr_end) (mtrr_end:end)176* or177* (start:mtrr_start) (mtrr_start:end)178* depending on kind of overlap.179* Return the type for first region and a pointer to180* the start of second region so that caller will181* lookup again on the second region.182* Note: This way we handle multiple overlaps as well.183*/184if (start_state)185*partial_end = base + get_mtrr_size(mask);186else187*partial_end = base;188189if (unlikely(*partial_end <= start)) {190WARN_ON(1);191*partial_end = start + PAGE_SIZE;192}193194end = *partial_end - 1; /* end is inclusive */195*repeat = 1;196}197198if ((start & mask) != (base & mask))199continue;200201curr_match = mtrr_state.var_ranges[i].base_lo & 0xff;202if (prev_match == 0xFF) {203prev_match = curr_match;204continue;205}206207if (check_type_overlap(&prev_match, &curr_match))208return curr_match;209}210211if (mtrr_tom2) {212if (start >= (1ULL<<32) && (end < mtrr_tom2))213return MTRR_TYPE_WRBACK;214}215216if (prev_match != 0xFF)217return prev_match;218219return mtrr_state.def_type;220}221222/*223* Returns the effective MTRR type for the region224* Error return:225* 0xFF - when MTRR is not enabled226*/227u8 mtrr_type_lookup(u64 start, u64 end)228{229u8 type, prev_type;230int repeat;231u64 partial_end;232233type = __mtrr_type_lookup(start, end, &partial_end, &repeat);234235/*236* Common path is with repeat = 0.237* However, we can have cases where [start:end] spans across some238* MTRR range. Do repeated lookups for that case here.239*/240while (repeat) {241prev_type = type;242start = partial_end;243type = __mtrr_type_lookup(start, end, &partial_end, &repeat);244245if (check_type_overlap(&prev_type, &type))246return type;247}248249return type;250}251252/* Get the MSR pair relating to a var range */253static void254get_mtrr_var_range(unsigned int index, struct mtrr_var_range *vr)255{256rdmsr(MTRRphysBase_MSR(index), vr->base_lo, vr->base_hi);257rdmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi);258}259260/* Fill the MSR pair relating to a var range */261void fill_mtrr_var_range(unsigned int index,262u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi)263{264struct mtrr_var_range *vr;265266vr = mtrr_state.var_ranges;267268vr[index].base_lo = base_lo;269vr[index].base_hi = base_hi;270vr[index].mask_lo = mask_lo;271vr[index].mask_hi = mask_hi;272}273274static void get_fixed_ranges(mtrr_type *frs)275{276unsigned int *p = (unsigned int *)frs;277int i;278279k8_check_syscfg_dram_mod_en();280281rdmsr(MSR_MTRRfix64K_00000, p[0], p[1]);282283for (i = 0; i < 2; i++)284rdmsr(MSR_MTRRfix16K_80000 + i, p[2 + i * 2], p[3 + i * 2]);285for (i = 0; i < 8; i++)286rdmsr(MSR_MTRRfix4K_C0000 + i, p[6 + i * 2], p[7 + i * 2]);287}288289void mtrr_save_fixed_ranges(void *info)290{291if (cpu_has_mtrr)292get_fixed_ranges(mtrr_state.fixed_ranges);293}294295static unsigned __initdata last_fixed_start;296static unsigned __initdata last_fixed_end;297static mtrr_type __initdata last_fixed_type;298299static void __init print_fixed_last(void)300{301if (!last_fixed_end)302return;303304pr_debug(" %05X-%05X %s\n", last_fixed_start,305last_fixed_end - 1, mtrr_attrib_to_str(last_fixed_type));306307last_fixed_end = 0;308}309310static void __init update_fixed_last(unsigned base, unsigned end,311mtrr_type type)312{313last_fixed_start = base;314last_fixed_end = end;315last_fixed_type = type;316}317318static void __init319print_fixed(unsigned base, unsigned step, const mtrr_type *types)320{321unsigned i;322323for (i = 0; i < 8; ++i, ++types, base += step) {324if (last_fixed_end == 0) {325update_fixed_last(base, base + step, *types);326continue;327}328if (last_fixed_end == base && last_fixed_type == *types) {329last_fixed_end = base + step;330continue;331}332/* new segments: gap or different type */333print_fixed_last();334update_fixed_last(base, base + step, *types);335}336}337338static void prepare_set(void);339static void post_set(void);340341static void __init print_mtrr_state(void)342{343unsigned int i;344int high_width;345346pr_debug("MTRR default type: %s\n",347mtrr_attrib_to_str(mtrr_state.def_type));348if (mtrr_state.have_fixed) {349pr_debug("MTRR fixed ranges %sabled:\n",350mtrr_state.enabled & 1 ? "en" : "dis");351print_fixed(0x00000, 0x10000, mtrr_state.fixed_ranges + 0);352for (i = 0; i < 2; ++i)353print_fixed(0x80000 + i * 0x20000, 0x04000,354mtrr_state.fixed_ranges + (i + 1) * 8);355for (i = 0; i < 8; ++i)356print_fixed(0xC0000 + i * 0x08000, 0x01000,357mtrr_state.fixed_ranges + (i + 3) * 8);358359/* tail */360print_fixed_last();361}362pr_debug("MTRR variable ranges %sabled:\n",363mtrr_state.enabled & 2 ? "en" : "dis");364if (size_or_mask & 0xffffffffUL)365high_width = ffs(size_or_mask & 0xffffffffUL) - 1;366else367high_width = ffs(size_or_mask>>32) + 32 - 1;368high_width = (high_width - (32 - PAGE_SHIFT) + 3) / 4;369370for (i = 0; i < num_var_ranges; ++i) {371if (mtrr_state.var_ranges[i].mask_lo & (1 << 11))372pr_debug(" %u base %0*X%05X000 mask %0*X%05X000 %s\n",373i,374high_width,375mtrr_state.var_ranges[i].base_hi,376mtrr_state.var_ranges[i].base_lo >> 12,377high_width,378mtrr_state.var_ranges[i].mask_hi,379mtrr_state.var_ranges[i].mask_lo >> 12,380mtrr_attrib_to_str(mtrr_state.var_ranges[i].base_lo & 0xff));381else382pr_debug(" %u disabled\n", i);383}384if (mtrr_tom2)385pr_debug("TOM2: %016llx aka %lldM\n", mtrr_tom2, mtrr_tom2>>20);386}387388/* Grab all of the MTRR state for this CPU into *state */389void __init get_mtrr_state(void)390{391struct mtrr_var_range *vrs;392unsigned long flags;393unsigned lo, dummy;394unsigned int i;395396vrs = mtrr_state.var_ranges;397398rdmsr(MSR_MTRRcap, lo, dummy);399mtrr_state.have_fixed = (lo >> 8) & 1;400401for (i = 0; i < num_var_ranges; i++)402get_mtrr_var_range(i, &vrs[i]);403if (mtrr_state.have_fixed)404get_fixed_ranges(mtrr_state.fixed_ranges);405406rdmsr(MSR_MTRRdefType, lo, dummy);407mtrr_state.def_type = (lo & 0xff);408mtrr_state.enabled = (lo & 0xc00) >> 10;409410if (amd_special_default_mtrr()) {411unsigned low, high;412413/* TOP_MEM2 */414rdmsr(MSR_K8_TOP_MEM2, low, high);415mtrr_tom2 = high;416mtrr_tom2 <<= 32;417mtrr_tom2 |= low;418mtrr_tom2 &= 0xffffff800000ULL;419}420421print_mtrr_state();422423mtrr_state_set = 1;424425/* PAT setup for BP. We need to go through sync steps here */426local_irq_save(flags);427prepare_set();428429pat_init();430431post_set();432local_irq_restore(flags);433}434435/* Some BIOS's are messed up and don't set all MTRRs the same! */436void __init mtrr_state_warn(void)437{438unsigned long mask = smp_changes_mask;439440if (!mask)441return;442if (mask & MTRR_CHANGE_MASK_FIXED)443pr_warning("mtrr: your CPUs had inconsistent fixed MTRR settings\n");444if (mask & MTRR_CHANGE_MASK_VARIABLE)445pr_warning("mtrr: your CPUs had inconsistent variable MTRR settings\n");446if (mask & MTRR_CHANGE_MASK_DEFTYPE)447pr_warning("mtrr: your CPUs had inconsistent MTRRdefType settings\n");448449printk(KERN_INFO "mtrr: probably your BIOS does not setup all CPUs.\n");450printk(KERN_INFO "mtrr: corrected configuration.\n");451}452453/*454* Doesn't attempt to pass an error out to MTRR users455* because it's quite complicated in some cases and probably not456* worth it because the best error handling is to ignore it.457*/458void mtrr_wrmsr(unsigned msr, unsigned a, unsigned b)459{460if (wrmsr_safe(msr, a, b) < 0) {461printk(KERN_ERR462"MTRR: CPU %u: Writing MSR %x to %x:%x failed\n",463smp_processor_id(), msr, a, b);464}465}466467/**468* set_fixed_range - checks & updates a fixed-range MTRR if it469* differs from the value it should have470* @msr: MSR address of the MTTR which should be checked and updated471* @changed: pointer which indicates whether the MTRR needed to be changed472* @msrwords: pointer to the MSR values which the MSR should have473*/474static void set_fixed_range(int msr, bool *changed, unsigned int *msrwords)475{476unsigned lo, hi;477478rdmsr(msr, lo, hi);479480if (lo != msrwords[0] || hi != msrwords[1]) {481mtrr_wrmsr(msr, msrwords[0], msrwords[1]);482*changed = true;483}484}485486/**487* generic_get_free_region - Get a free MTRR.488* @base: The starting (base) address of the region.489* @size: The size (in bytes) of the region.490* @replace_reg: mtrr index to be replaced; set to invalid value if none.491*492* Returns: The index of the region on success, else negative on error.493*/494int495generic_get_free_region(unsigned long base, unsigned long size, int replace_reg)496{497unsigned long lbase, lsize;498mtrr_type ltype;499int i, max;500501max = num_var_ranges;502if (replace_reg >= 0 && replace_reg < max)503return replace_reg;504505for (i = 0; i < max; ++i) {506mtrr_if->get(i, &lbase, &lsize, <ype);507if (lsize == 0)508return i;509}510511return -ENOSPC;512}513514static void generic_get_mtrr(unsigned int reg, unsigned long *base,515unsigned long *size, mtrr_type *type)516{517unsigned int mask_lo, mask_hi, base_lo, base_hi;518unsigned int tmp, hi;519520/*521* get_mtrr doesn't need to update mtrr_state, also it could be called522* from any cpu, so try to print it out directly.523*/524get_cpu();525526rdmsr(MTRRphysMask_MSR(reg), mask_lo, mask_hi);527528if ((mask_lo & 0x800) == 0) {529/* Invalid (i.e. free) range */530*base = 0;531*size = 0;532*type = 0;533goto out_put_cpu;534}535536rdmsr(MTRRphysBase_MSR(reg), base_lo, base_hi);537538/* Work out the shifted address mask: */539tmp = mask_hi << (32 - PAGE_SHIFT) | mask_lo >> PAGE_SHIFT;540mask_lo = size_or_mask | tmp;541542/* Expand tmp with high bits to all 1s: */543hi = fls(tmp);544if (hi > 0) {545tmp |= ~((1<<(hi - 1)) - 1);546547if (tmp != mask_lo) {548printk(KERN_WARNING "mtrr: your BIOS has configured an incorrect mask, fixing it.\n");549mask_lo = tmp;550}551}552553/*554* This works correctly if size is a power of two, i.e. a555* contiguous range:556*/557*size = -mask_lo;558*base = base_hi << (32 - PAGE_SHIFT) | base_lo >> PAGE_SHIFT;559*type = base_lo & 0xff;560561out_put_cpu:562put_cpu();563}564565/**566* set_fixed_ranges - checks & updates the fixed-range MTRRs if they567* differ from the saved set568* @frs: pointer to fixed-range MTRR values, saved by get_fixed_ranges()569*/570static int set_fixed_ranges(mtrr_type *frs)571{572unsigned long long *saved = (unsigned long long *)frs;573bool changed = false;574int block = -1, range;575576k8_check_syscfg_dram_mod_en();577578while (fixed_range_blocks[++block].ranges) {579for (range = 0; range < fixed_range_blocks[block].ranges; range++)580set_fixed_range(fixed_range_blocks[block].base_msr + range,581&changed, (unsigned int *)saved++);582}583584return changed;585}586587/*588* Set the MSR pair relating to a var range.589* Returns true if changes are made.590*/591static bool set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)592{593unsigned int lo, hi;594bool changed = false;595596rdmsr(MTRRphysBase_MSR(index), lo, hi);597if ((vr->base_lo & 0xfffff0ffUL) != (lo & 0xfffff0ffUL)598|| (vr->base_hi & (size_and_mask >> (32 - PAGE_SHIFT))) !=599(hi & (size_and_mask >> (32 - PAGE_SHIFT)))) {600601mtrr_wrmsr(MTRRphysBase_MSR(index), vr->base_lo, vr->base_hi);602changed = true;603}604605rdmsr(MTRRphysMask_MSR(index), lo, hi);606607if ((vr->mask_lo & 0xfffff800UL) != (lo & 0xfffff800UL)608|| (vr->mask_hi & (size_and_mask >> (32 - PAGE_SHIFT))) !=609(hi & (size_and_mask >> (32 - PAGE_SHIFT)))) {610mtrr_wrmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi);611changed = true;612}613return changed;614}615616static u32 deftype_lo, deftype_hi;617618/**619* set_mtrr_state - Set the MTRR state for this CPU.620*621* NOTE: The CPU must already be in a safe state for MTRR changes.622* RETURNS: 0 if no changes made, else a mask indicating what was changed.623*/624static unsigned long set_mtrr_state(void)625{626unsigned long change_mask = 0;627unsigned int i;628629for (i = 0; i < num_var_ranges; i++) {630if (set_mtrr_var_ranges(i, &mtrr_state.var_ranges[i]))631change_mask |= MTRR_CHANGE_MASK_VARIABLE;632}633634if (mtrr_state.have_fixed && set_fixed_ranges(mtrr_state.fixed_ranges))635change_mask |= MTRR_CHANGE_MASK_FIXED;636637/*638* Set_mtrr_restore restores the old value of MTRRdefType,639* so to set it we fiddle with the saved value:640*/641if ((deftype_lo & 0xff) != mtrr_state.def_type642|| ((deftype_lo & 0xc00) >> 10) != mtrr_state.enabled) {643644deftype_lo = (deftype_lo & ~0xcff) | mtrr_state.def_type |645(mtrr_state.enabled << 10);646change_mask |= MTRR_CHANGE_MASK_DEFTYPE;647}648649return change_mask;650}651652653static unsigned long cr4;654static DEFINE_RAW_SPINLOCK(set_atomicity_lock);655656/*657* Since we are disabling the cache don't allow any interrupts,658* they would run extremely slow and would only increase the pain.659*660* The caller must ensure that local interrupts are disabled and661* are reenabled after post_set() has been called.662*/663static void prepare_set(void) __acquires(set_atomicity_lock)664{665unsigned long cr0;666667/*668* Note that this is not ideal669* since the cache is only flushed/disabled for this CPU while the670* MTRRs are changed, but changing this requires more invasive671* changes to the way the kernel boots672*/673674raw_spin_lock(&set_atomicity_lock);675676/* Enter the no-fill (CD=1, NW=0) cache mode and flush caches. */677cr0 = read_cr0() | X86_CR0_CD;678write_cr0(cr0);679wbinvd();680681/* Save value of CR4 and clear Page Global Enable (bit 7) */682if (cpu_has_pge) {683cr4 = read_cr4();684write_cr4(cr4 & ~X86_CR4_PGE);685}686687/* Flush all TLBs via a mov %cr3, %reg; mov %reg, %cr3 */688__flush_tlb();689690/* Save MTRR state */691rdmsr(MSR_MTRRdefType, deftype_lo, deftype_hi);692693/* Disable MTRRs, and set the default type to uncached */694mtrr_wrmsr(MSR_MTRRdefType, deftype_lo & ~0xcff, deftype_hi);695}696697static void post_set(void) __releases(set_atomicity_lock)698{699/* Flush TLBs (no need to flush caches - they are disabled) */700__flush_tlb();701702/* Intel (P6) standard MTRRs */703mtrr_wrmsr(MSR_MTRRdefType, deftype_lo, deftype_hi);704705/* Enable caches */706write_cr0(read_cr0() & 0xbfffffff);707708/* Restore value of CR4 */709if (cpu_has_pge)710write_cr4(cr4);711raw_spin_unlock(&set_atomicity_lock);712}713714static void generic_set_all(void)715{716unsigned long mask, count;717unsigned long flags;718719local_irq_save(flags);720prepare_set();721722/* Actually set the state */723mask = set_mtrr_state();724725/* also set PAT */726pat_init();727728post_set();729local_irq_restore(flags);730731/* Use the atomic bitops to update the global mask */732for (count = 0; count < sizeof mask * 8; ++count) {733if (mask & 0x01)734set_bit(count, &smp_changes_mask);735mask >>= 1;736}737738}739740/**741* generic_set_mtrr - set variable MTRR register on the local CPU.742*743* @reg: The register to set.744* @base: The base address of the region.745* @size: The size of the region. If this is 0 the region is disabled.746* @type: The type of the region.747*748* Returns nothing.749*/750static void generic_set_mtrr(unsigned int reg, unsigned long base,751unsigned long size, mtrr_type type)752{753unsigned long flags;754struct mtrr_var_range *vr;755756vr = &mtrr_state.var_ranges[reg];757758local_irq_save(flags);759prepare_set();760761if (size == 0) {762/*763* The invalid bit is kept in the mask, so we simply764* clear the relevant mask register to disable a range.765*/766mtrr_wrmsr(MTRRphysMask_MSR(reg), 0, 0);767memset(vr, 0, sizeof(struct mtrr_var_range));768} else {769vr->base_lo = base << PAGE_SHIFT | type;770vr->base_hi = (base & size_and_mask) >> (32 - PAGE_SHIFT);771vr->mask_lo = -size << PAGE_SHIFT | 0x800;772vr->mask_hi = (-size & size_and_mask) >> (32 - PAGE_SHIFT);773774mtrr_wrmsr(MTRRphysBase_MSR(reg), vr->base_lo, vr->base_hi);775mtrr_wrmsr(MTRRphysMask_MSR(reg), vr->mask_lo, vr->mask_hi);776}777778post_set();779local_irq_restore(flags);780}781782int generic_validate_add_page(unsigned long base, unsigned long size,783unsigned int type)784{785unsigned long lbase, last;786787/*788* For Intel PPro stepping <= 7789* must be 4 MiB aligned and not touch 0x70000000 -> 0x7003FFFF790*/791if (is_cpu(INTEL) && boot_cpu_data.x86 == 6 &&792boot_cpu_data.x86_model == 1 &&793boot_cpu_data.x86_mask <= 7) {794if (base & ((1 << (22 - PAGE_SHIFT)) - 1)) {795pr_warning("mtrr: base(0x%lx000) is not 4 MiB aligned\n", base);796return -EINVAL;797}798if (!(base + size < 0x70000 || base > 0x7003F) &&799(type == MTRR_TYPE_WRCOMB800|| type == MTRR_TYPE_WRBACK)) {801pr_warning("mtrr: writable mtrr between 0x70000000 and 0x7003FFFF may hang the CPU.\n");802return -EINVAL;803}804}805806/*807* Check upper bits of base and last are equal and lower bits are 0808* for base and 1 for last809*/810last = base + size - 1;811for (lbase = base; !(lbase & 1) && (last & 1);812lbase = lbase >> 1, last = last >> 1)813;814if (lbase != last) {815pr_warning("mtrr: base(0x%lx000) is not aligned on a size(0x%lx000) boundary\n", base, size);816return -EINVAL;817}818return 0;819}820821static int generic_have_wrcomb(void)822{823unsigned long config, dummy;824rdmsr(MSR_MTRRcap, config, dummy);825return config & (1 << 10);826}827828int positive_have_wrcomb(void)829{830return 1;831}832833/*834* Generic structure...835*/836const struct mtrr_ops generic_mtrr_ops = {837.use_intel_if = 1,838.set_all = generic_set_all,839.get = generic_get_mtrr,840.get_free_region = generic_get_free_region,841.set = generic_set_mtrr,842.validate_add_page = generic_validate_add_page,843.have_wrcomb = generic_have_wrcomb,844};845846847