coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mtrr.h File Reference
#include <cpu/x86/msr.h>
#include <arch/cpu.h>
#include <stdint.h>
#include <stddef.h>
Include dependency graph for mtrr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  var_mtrr_context
 

Macros

#define MTRR_TYPE_UNCACHEABLE   0
 
#define MTRR_TYPE_WRCOMB   1
 
#define MTRR_TYPE_WRTHROUGH   4
 
#define MTRR_TYPE_WRPROT   5
 
#define MTRR_TYPE_WRBACK   6
 
#define MTRR_NUM_TYPES   7
 
#define MTRR_CAP_MSR   0x0fe
 
#define MTRR_CAP_PRMRR   (1 << 12)
 
#define MTRR_CAP_SMRR   (1 << 11)
 
#define MTRR_CAP_WC   (1 << 10)
 
#define MTRR_CAP_FIX   (1 << 8)
 
#define MTRR_CAP_VCNT   0xff
 
#define MTRR_DEF_TYPE_MSR   0x2ff
 
#define MTRR_DEF_TYPE_MASK   0xff
 
#define MTRR_DEF_TYPE_EN   (1 << 11)
 
#define MTRR_DEF_TYPE_FIX_EN   (1 << 10)
 
#define IA32_SMRR_PHYS_BASE   0x1f2
 
#define IA32_SMRR_PHYS_MASK   0x1f3
 
#define SMRR_PHYS_MASK_LOCK   (1 << 10)
 
#define CORE2_SMRR_PHYS_BASE   0xa0
 
#define CORE2_SMRR_PHYS_MASK   0xa1
 
#define MTRR_PHYS_BASE(reg)   (0x200 + 2 * (reg))
 
#define MTRR_PHYS_MASK(reg)   (MTRR_PHYS_BASE(reg) + 1)
 
#define MTRR_PHYS_MASK_VALID   (1 << 11)
 
#define NUM_FIXED_RANGES   88
 
#define RANGES_PER_FIXED_MTRR   8
 
#define MTRR_FIX_64K_00000   0x250
 
#define MTRR_FIX_16K_80000   0x258
 
#define MTRR_FIX_16K_A0000   0x259
 
#define MTRR_FIX_4K_C0000   0x268
 
#define MTRR_FIX_4K_C8000   0x269
 
#define MTRR_FIX_4K_D0000   0x26a
 
#define MTRR_FIX_4K_D8000   0x26b
 
#define MTRR_FIX_4K_E0000   0x26c
 
#define MTRR_FIX_4K_E8000   0x26d
 
#define MTRR_FIX_4K_F0000   0x26e
 
#define MTRR_FIX_4K_F8000   0x26f
 
#define _POW2_MASK(x)
 
#define _ALIGN_UP_POW2(x)   ((x + _POW2_MASK(x)) & ~_POW2_MASK(x))
 
#define _ALIGN_DOWN_POW2(x)   ((x) & ~_POW2_MASK(x))
 
#define _FROM_4G_TOP(x)   ((0xffffffff - (x)) + 1)
 
#define CACHE_TMP_RAMTOP   (16<<20)
 
#define OPTIMAL_CACHE_ROM_SIZE   _ALIGN_UP_POW2(CONFIG_ROM_SIZE)
 
#define OPTIMAL_CACHE_ROM_BASE   _FROM_4G_TOP(OPTIMAL_CACHE_ROM_SIZE)
 
#define CAR_END   (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)
 
#define CAR_CACHE_ROM_SIZE   OPTIMAL_CACHE_ROM_SIZE
 
#define CACHE_ROM_SIZE   CAR_CACHE_ROM_SIZE
 
#define CACHE_ROM_BASE   _FROM_4G_TOP(CACHE_ROM_SIZE)
 

Functions

void x86_setup_mtrrs (void)
 
void x86_setup_mtrrs_with_detect (void)
 
void x86_setup_mtrrs_with_detect_no_above_4gb (void)
 
void x86_setup_var_mtrrs (unsigned int address_bits, unsigned int above4gb)
 
void enable_fixed_mtrr (void)
 
void fixed_mtrrs_expose_amd_rwdram (void)
 
void fixed_mtrrs_hide_amd_rwdram (void)
 
void x86_setup_fixed_mtrrs (void)
 
void x86_setup_fixed_mtrrs_no_enable (void)
 
void x86_mtrr_check (void)
 
void need_restore_mtrr (void)
 
void mtrr_use_temp_range (uintptr_t begin, size_t size, int type)
 
static int get_var_mtrr_count (void)
 
void set_var_mtrr (unsigned int reg, unsigned int base, unsigned int size, unsigned int type)
 
int get_free_var_mtrr (void)
 
void clear_all_var_mtrr (void)
 
asmlinkage void display_mtrrs (void)
 
static int var_mtrr_context_current_mtrr (const struct var_mtrr_context *ctx)
 
void var_mtrr_context_init (struct var_mtrr_context *ctx, void *arg)
 
int var_mtrr_set_with_cb (struct var_mtrr_context *ctx, uintptr_t addr, size_t size, int type, void(*callback)(const struct var_mtrr_context *ctx, uintptr_t base_addr, size_t size, msr_t base, msr_t mask))
 
int var_mtrr_set (struct var_mtrr_context *ctx, uintptr_t addr, size_t size, int type)
 
asmlinkage voidsoc_set_mtrrs (void *top_of_stack)
 
asmlinkage void soc_enable_mtrrs (void)
 
static unsigned int fms (unsigned int x)
 
static unsigned int fls (unsigned int x)
 

Macro Definition Documentation

◆ _ALIGN_DOWN_POW2

#define _ALIGN_DOWN_POW2 (   x)    ((x) & ~_POW2_MASK(x))

Definition at line 185 of file mtrr.h.

◆ _ALIGN_UP_POW2

#define _ALIGN_UP_POW2 (   x)    ((x + _POW2_MASK(x)) & ~_POW2_MASK(x))

Definition at line 184 of file mtrr.h.

◆ _FROM_4G_TOP

#define _FROM_4G_TOP (   x)    ((0xffffffff - (x)) + 1)

Definition at line 188 of file mtrr.h.

◆ _POW2_MASK

#define _POW2_MASK (   x)
Value:
((x>>1)|(x>>2)|(x>>3)|(x>>4)|(x>>5)| \
(x>>6)|(x>>7)|(x>>8)|((1<<18)-1))
int x
Definition: edid.c:994

Definition at line 182 of file mtrr.h.

◆ CACHE_ROM_BASE

#define CACHE_ROM_BASE   _FROM_4G_TOP(CACHE_ROM_SIZE)

Definition at line 226 of file mtrr.h.

◆ CACHE_ROM_SIZE

#define CACHE_ROM_SIZE   CAR_CACHE_ROM_SIZE

Definition at line 223 of file mtrr.h.

◆ CACHE_TMP_RAMTOP

#define CACHE_TMP_RAMTOP   (16<<20)

Definition at line 194 of file mtrr.h.

◆ CAR_CACHE_ROM_SIZE

#define CAR_CACHE_ROM_SIZE   OPTIMAL_CACHE_ROM_SIZE

Definition at line 212 of file mtrr.h.

◆ CAR_END

#define CAR_END   (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)

Definition at line 208 of file mtrr.h.

◆ CORE2_SMRR_PHYS_BASE

#define CORE2_SMRR_PHYS_BASE   0xa0

Definition at line 36 of file mtrr.h.

◆ CORE2_SMRR_PHYS_MASK

#define CORE2_SMRR_PHYS_MASK   0xa1

Definition at line 37 of file mtrr.h.

◆ IA32_SMRR_PHYS_BASE

#define IA32_SMRR_PHYS_BASE   0x1f2

Definition at line 30 of file mtrr.h.

◆ IA32_SMRR_PHYS_MASK

#define IA32_SMRR_PHYS_MASK   0x1f3

Definition at line 31 of file mtrr.h.

◆ MTRR_CAP_FIX

#define MTRR_CAP_FIX   (1 << 8)

Definition at line 22 of file mtrr.h.

◆ MTRR_CAP_MSR

#define MTRR_CAP_MSR   0x0fe

Definition at line 17 of file mtrr.h.

◆ MTRR_CAP_PRMRR

#define MTRR_CAP_PRMRR   (1 << 12)

Definition at line 19 of file mtrr.h.

◆ MTRR_CAP_SMRR

#define MTRR_CAP_SMRR   (1 << 11)

Definition at line 20 of file mtrr.h.

◆ MTRR_CAP_VCNT

#define MTRR_CAP_VCNT   0xff

Definition at line 23 of file mtrr.h.

◆ MTRR_CAP_WC

#define MTRR_CAP_WC   (1 << 10)

Definition at line 21 of file mtrr.h.

◆ MTRR_DEF_TYPE_EN

#define MTRR_DEF_TYPE_EN   (1 << 11)

Definition at line 27 of file mtrr.h.

◆ MTRR_DEF_TYPE_FIX_EN

#define MTRR_DEF_TYPE_FIX_EN   (1 << 10)

Definition at line 28 of file mtrr.h.

◆ MTRR_DEF_TYPE_MASK

#define MTRR_DEF_TYPE_MASK   0xff

Definition at line 26 of file mtrr.h.

◆ MTRR_DEF_TYPE_MSR

#define MTRR_DEF_TYPE_MSR   0x2ff

Definition at line 25 of file mtrr.h.

◆ MTRR_FIX_16K_80000

#define MTRR_FIX_16K_80000   0x258

Definition at line 46 of file mtrr.h.

◆ MTRR_FIX_16K_A0000

#define MTRR_FIX_16K_A0000   0x259

Definition at line 47 of file mtrr.h.

◆ MTRR_FIX_4K_C0000

#define MTRR_FIX_4K_C0000   0x268

Definition at line 48 of file mtrr.h.

◆ MTRR_FIX_4K_C8000

#define MTRR_FIX_4K_C8000   0x269

Definition at line 49 of file mtrr.h.

◆ MTRR_FIX_4K_D0000

#define MTRR_FIX_4K_D0000   0x26a

Definition at line 50 of file mtrr.h.

◆ MTRR_FIX_4K_D8000

#define MTRR_FIX_4K_D8000   0x26b

Definition at line 51 of file mtrr.h.

◆ MTRR_FIX_4K_E0000

#define MTRR_FIX_4K_E0000   0x26c

Definition at line 52 of file mtrr.h.

◆ MTRR_FIX_4K_E8000

#define MTRR_FIX_4K_E8000   0x26d

Definition at line 53 of file mtrr.h.

◆ MTRR_FIX_4K_F0000

#define MTRR_FIX_4K_F0000   0x26e

Definition at line 54 of file mtrr.h.

◆ MTRR_FIX_4K_F8000

#define MTRR_FIX_4K_F8000   0x26f

Definition at line 55 of file mtrr.h.

◆ MTRR_FIX_64K_00000

#define MTRR_FIX_64K_00000   0x250

Definition at line 45 of file mtrr.h.

◆ MTRR_NUM_TYPES

#define MTRR_NUM_TYPES   7

Definition at line 15 of file mtrr.h.

◆ MTRR_PHYS_BASE

#define MTRR_PHYS_BASE (   reg)    (0x200 + 2 * (reg))

Definition at line 39 of file mtrr.h.

◆ MTRR_PHYS_MASK

#define MTRR_PHYS_MASK (   reg)    (MTRR_PHYS_BASE(reg) + 1)

Definition at line 40 of file mtrr.h.

◆ MTRR_PHYS_MASK_VALID

#define MTRR_PHYS_MASK_VALID   (1 << 11)

Definition at line 41 of file mtrr.h.

◆ MTRR_TYPE_UNCACHEABLE

#define MTRR_TYPE_UNCACHEABLE   0

Definition at line 10 of file mtrr.h.

◆ MTRR_TYPE_WRBACK

#define MTRR_TYPE_WRBACK   6

Definition at line 14 of file mtrr.h.

◆ MTRR_TYPE_WRCOMB

#define MTRR_TYPE_WRCOMB   1

Definition at line 11 of file mtrr.h.

◆ MTRR_TYPE_WRPROT

#define MTRR_TYPE_WRPROT   5

Definition at line 13 of file mtrr.h.

◆ MTRR_TYPE_WRTHROUGH

#define MTRR_TYPE_WRTHROUGH   4

Definition at line 12 of file mtrr.h.

◆ NUM_FIXED_RANGES

#define NUM_FIXED_RANGES   88

Definition at line 43 of file mtrr.h.

◆ OPTIMAL_CACHE_ROM_BASE

#define OPTIMAL_CACHE_ROM_BASE   _FROM_4G_TOP(OPTIMAL_CACHE_ROM_SIZE)

Definition at line 198 of file mtrr.h.

◆ OPTIMAL_CACHE_ROM_SIZE

#define OPTIMAL_CACHE_ROM_SIZE   _ALIGN_UP_POW2(CONFIG_ROM_SIZE)

Definition at line 197 of file mtrr.h.

◆ RANGES_PER_FIXED_MTRR

#define RANGES_PER_FIXED_MTRR   8

Definition at line 44 of file mtrr.h.

◆ SMRR_PHYS_MASK_LOCK

#define SMRR_PHYS_MASK_LOCK   (1 << 10)

Definition at line 32 of file mtrr.h.

Function Documentation

◆ clear_all_var_mtrr()

void clear_all_var_mtrr ( void  )

Definition at line 53 of file mtrrlib.c.

References get_var_mtrr_count(), MTRR_PHYS_BASE, MTRR_PHYS_MASK, and wrmsr().

Referenced by early_cache_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_mtrrs()

asmlinkage void display_mtrrs ( void  )

Definition at line 186 of file debug.c.

References _display_mtrrs(), and CONFIG.

Referenced by bootblock_soc_init(), fsp_debug_after_memory_init(), fsp_debug_after_notify(), fsp_debug_after_silicon_init(), fsp_debug_before_memory_init(), fsp_debug_before_silicon_init(), fsp_notify_dummy(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enable_fixed_mtrr()

void enable_fixed_mtrr ( void  )

Definition at line 54 of file mtrr.c.

References msr_struct::lo, MTRR_DEF_TYPE_EN, MTRR_DEF_TYPE_FIX_EN, MTRR_DEF_TYPE_MSR, rdmsr(), and wrmsr().

Here is the call graph for this function:

◆ fixed_mtrrs_expose_amd_rwdram()

void fixed_mtrrs_expose_amd_rwdram ( void  )

Definition at line 63 of file mtrr.c.

References CONFIG, msr_struct::lo, rdmsr(), SYSCFG_MSR, SYSCFG_MSR_MtrrFixDramModEn, and wrmsr().

Referenced by commit_fixed_mtrrs(), and save_bsp_msrs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fixed_mtrrs_hide_amd_rwdram()

void fixed_mtrrs_hide_amd_rwdram ( void  )

Definition at line 75 of file mtrr.c.

References CONFIG, msr_struct::lo, rdmsr(), SYSCFG_MSR, SYSCFG_MSR_MtrrFixDramModEn, and wrmsr().

Referenced by commit_fixed_mtrrs(), and save_bsp_msrs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fls()

static unsigned int fls ( unsigned int  x)
inlinestatic

Definition at line 168 of file mtrr.h.

References x.

Referenced by fls64(), optimize_var_mtrr_hole(), and var_mtrr_set_with_cb().

Here is the caller graph for this function:

◆ fms()

static unsigned int fms ( unsigned int  x)
inlinestatic

Definition at line 156 of file mtrr.h.

References x.

Referenced by calc_var_mtrrs_with_hole(), enable_pci_mmconf(), fms64(), optimize_var_mtrr_hole(), and var_mtrr_set_with_cb().

Here is the caller graph for this function:

◆ get_free_var_mtrr()

int get_free_var_mtrr ( void  )

Definition at line 11 of file mtrrlib.c.

References get_var_mtrr_count(), msr_struct::lo, MTRR_PHYS_MASK, MTRR_PHYS_MASK_VALID, and rdmsr().

Referenced by fast_spi_enable_cache_range(), and platform_prog_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_var_mtrr_count()

static int get_var_mtrr_count ( void  )
inlinestatic

Definition at line 105 of file mtrr.h.

References msr_struct::lo, MTRR_CAP_MSR, MTRR_CAP_VCNT, and rdmsr().

Referenced by _display_mtrrs(), clear_all_var_mtrr(), detect_var_mtrrs(), get_free_var_mtrr(), intel_txt_prepare_bios_acm(), max_cache_used(), save_bsp_msrs(), set_range_uc(), and var_mtrr_context_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mtrr_use_temp_range()

◆ need_restore_mtrr()

void need_restore_mtrr ( void  )

Definition at line 863 of file mtrr.c.

References put_back_original_solution.

Referenced by mtrr_use_temp_range().

Here is the caller graph for this function:

◆ set_var_mtrr()

void set_var_mtrr ( unsigned int  reg,
unsigned int  base,
unsigned int  size,
unsigned int  type 
)

Definition at line 30 of file mtrrlib.c.

References base, BIOS_ERR, cpu_phys_address_size(), msr_struct::hi, IS_POWER_OF_2, KiB, msr_struct::lo, MTRR_PHYS_BASE, MTRR_PHYS_MASK, MTRR_PHYS_MASK_VALID, printk, type, and wrmsr().

Referenced by amd_initmmio(), fast_spi_enable_cache_range(), platform_prog_run(), and set_early_mtrrs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ soc_enable_mtrrs()

asmlinkage void soc_enable_mtrrs ( void  )

Definition at line 69 of file mtrr.c.

References MTRR_DEF_TYPE_EN, MTRR_DEF_TYPE_MSR, soc_msr_read(), and soc_msr_write().

Here is the call graph for this function:

◆ soc_set_mtrrs()

asmlinkage void* soc_set_mtrrs ( void top_of_stack)

Definition at line 8 of file mtrr.c.

References MTRR_PHYS_BASE, and soc_msr_write().

Here is the call graph for this function:

◆ var_mtrr_context_current_mtrr()

static int var_mtrr_context_current_mtrr ( const struct var_mtrr_context ctx)
inlinestatic

Definition at line 130 of file mtrr.h.

References var_mtrr_context::used_var_mtrrs.

Referenced by set_mtrr().

Here is the caller graph for this function:

◆ var_mtrr_context_init()

void var_mtrr_context_init ( struct var_mtrr_context ctx,
void arg 
)

Definition at line 9 of file earlymtrr.c.

References var_mtrr_context::arg, arg, cpu_phys_address_size(), get_var_mtrr_count(), var_mtrr_context::max_var_mtrrs, var_mtrr_context::upper_mask, and var_mtrr_context::used_var_mtrrs.

Referenced by early_cache_setup(), and postcar_frame_prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ var_mtrr_set()

int var_mtrr_set ( struct var_mtrr_context ctx,
uintptr_t  addr,
size_t  size,
int  type 
)

Definition at line 71 of file earlymtrr.c.

References addr, set_mtrr(), type, and var_mtrr_set_with_cb().

Referenced by early_cache_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ var_mtrr_set_with_cb()

int var_mtrr_set_with_cb ( struct var_mtrr_context ctx,
uintptr_t  addr,
size_t  size,
int  type,
void(*)(const struct var_mtrr_context *ctx, uintptr_t base_addr, size_t size, msr_t base, msr_t mask callback 
)

Definition at line 17 of file earlymtrr.c.

References addr, base, BIOS_ERR, fls(), fms(), mask, var_mtrr_context::max_var_mtrrs, MTRR_PHYS_MASK_VALID, printk, type, var_mtrr_context::upper_mask, and var_mtrr_context::used_var_mtrrs.

Referenced by postcar_frame_add_mtrr(), and var_mtrr_set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ x86_mtrr_check()

void x86_mtrr_check ( void  )

Definition at line 836 of file mtrr.c.

References BIOS_DEBUG, msr_struct::lo, MTRR_DEF_TYPE_EN, MTRR_DEF_TYPE_FIX_EN, MTRR_DEF_TYPE_MSR, post_code, printk, and rdmsr().

Referenced by post_cpus_init(), and pre_mp_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ x86_setup_fixed_mtrrs()

void x86_setup_fixed_mtrrs ( void  )

Definition at line 354 of file mtrr.c.

Referenced by _x86_setup_mtrrs().

Here is the caller graph for this function:

◆ x86_setup_fixed_mtrrs_no_enable()

void x86_setup_fixed_mtrrs_no_enable ( void  )

Definition at line 348 of file mtrr.c.

References calc_fixed_mtrrs(), and commit_fixed_mtrrs().

Here is the call graph for this function:

◆ x86_setup_mtrrs()

void x86_setup_mtrrs ( void  )

Definition at line 815 of file mtrr.c.

References _x86_setup_mtrrs(), MIN_MTRRS, and total_mtrrs.

Here is the call graph for this function:

◆ x86_setup_mtrrs_with_detect()

void x86_setup_mtrrs_with_detect ( void  )

Definition at line 823 of file mtrr.c.

References _x86_setup_mtrrs(), and detect_var_mtrrs().

Referenced by pre_mp_init(), and wrapper_x86_setup_mtrrs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ x86_setup_mtrrs_with_detect_no_above_4gb()

void x86_setup_mtrrs_with_detect_no_above_4gb ( void  )

Definition at line 830 of file mtrr.c.

References _x86_setup_mtrrs(), and detect_var_mtrrs().

Referenced by pre_mp_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ x86_setup_var_mtrrs()

void x86_setup_var_mtrrs ( unsigned int  address_bits,
unsigned int  above4gb 
)

Definition at line 786 of file mtrr.c.

References calc_var_mtrrs(), commit_var_mtrrs(), get_physical_address_space(), var_mtrr_solution::mtrr_default_type, mtrr_global_solution, NULL, and prepare_var_mtrrs().

Referenced by _x86_setup_mtrrs().

Here is the call graph for this function:
Here is the caller graph for this function: