arch/x86/kernel/cpu/mtrr/generic.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/mtrr/generic.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/mtrr/generic.c- Extension
.c- Size
- 28782 bytes
- Lines
- 1080
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/init.hlinux/io.hlinux/mm.hlinux/cc_platform.hlinux/string_choices.hasm/processor-flags.hasm/cacheinfo.hasm/cpufeature.hasm/cpu_device_id.hasm/hypervisor.hasm/mshyperv.hasm/tlbflush.hasm/mtrr.hasm/msr.hasm/memtype.hmtrr.h
Detected Declarations
struct fixed_range_blockstruct cache_mapfunction mtrr_param_setupfunction k8_check_syscfg_dram_mod_enfunction get_mtrr_sizefunction get_var_mtrr_statefunction get_effective_typefunction rm_map_entry_atfunction add_map_entry_atfunction clr_map_range_atfunction add_map_entryfunction map_add_varfunction generic_rebuild_mapfunction get_cache_map_sizefunction mtrr_build_mapfunction mtrr_copy_mapfunction meansfunction type_mergefunction MTRR_TYPE_function get_mtrr_var_rangefunction fill_mtrr_var_rangefunction get_fixed_rangesfunction mtrr_save_fixed_rangesfunction print_fixed_lastfunction update_fixed_lastfunction print_fixedfunction print_mtrr_statefunction get_mtrr_statefunction mtrr_state_warnfunction mtrr_wrmsrfunction set_fixed_rangefunction generic_get_free_regionfunction generic_get_mtrrfunction set_fixed_rangesfunction set_mtrr_var_rangesfunction set_mtrr_statefunction mtrr_disablefunction mtrr_enablefunction mtrr_generic_set_statefunction generic_set_mtrrfunction generic_validate_add_pagefunction generic_have_wrcombfunction positive_have_wrcomb
Annotated Snippet
struct fixed_range_block {
int base_msr; /* start address of an MTRR block */
int ranges; /* number of MTRRs in this block */
};
static struct fixed_range_block fixed_range_blocks[] = {
{ MSR_MTRRfix64K_00000, 1 }, /* one 64k MTRR */
{ MSR_MTRRfix16K_80000, 2 }, /* two 16k MTRRs */
{ MSR_MTRRfix4K_C0000, 8 }, /* eight 4k MTRRs */
{}
};
struct cache_map {
u64 start;
u64 end;
u64 flags;
u64 type:8;
u64 fixed:1;
};
bool mtrr_debug;
static int __init mtrr_param_setup(char *str)
{
int rc = 0;
if (!str)
return -EINVAL;
if (!strcmp(str, "debug"))
mtrr_debug = true;
else
rc = -EINVAL;
return rc;
}
early_param("mtrr", mtrr_param_setup);
/*
* CACHE_MAP_MAX is the maximum number of memory ranges in cache_map, where
* no 2 adjacent ranges have the same cache mode (those would be merged).
* The number is based on the worst case:
* - no two adjacent fixed MTRRs share the same cache mode
* - one variable MTRR is spanning a huge area with mode WB
* - 255 variable MTRRs with mode UC all overlap with the WB MTRR, creating 2
* additional ranges each (result like "ababababa...aba" with a = WB, b = UC),
* accounting for MTRR_MAX_VAR_RANGES * 2 - 1 range entries
* - a TOP_MEM2 area (even with overlapping an UC MTRR can't add 2 range entries
* to the possible maximum, as it always starts at 4GB, thus it can't be in
* the middle of that MTRR, unless that MTRR starts at 0, which would remove
* the initial "a" from the "abababa" pattern above)
* The map won't contain ranges with no matching MTRR (those fall back to the
* default cache mode).
*/
#define CACHE_MAP_MAX (MTRR_NUM_FIXED_RANGES + MTRR_MAX_VAR_RANGES * 2)
static struct cache_map init_cache_map[CACHE_MAP_MAX] __initdata;
static struct cache_map *cache_map __refdata = init_cache_map;
static unsigned int cache_map_size = CACHE_MAP_MAX;
static unsigned int cache_map_n;
static unsigned int cache_map_fixed;
static unsigned long smp_changes_mask;
static int mtrr_state_set;
u64 mtrr_tom2;
struct mtrr_state_type mtrr_state;
/* Reserved bits in the high portion of the MTRRphysBaseN MSR. */
u32 phys_hi_rsvd;
/*
* BIOS is expected to clear MtrrFixDramModEn bit, see for example
* "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD
* Opteron Processors" (26094 Rev. 3.30 February 2006), section
* "13.2.1.2 SYSCFG Register": "The MtrrFixDramModEn bit should be set
* to 1 during BIOS initialization of the fixed MTRRs, then cleared to
* 0 for operation."
*/
static inline void k8_check_syscfg_dram_mod_en(void)
{
u32 lo, hi;
if (!((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
(boot_cpu_data.x86 >= 0x0f)))
return;
if (cc_platform_has(CC_ATTR_HOST_SEV_SNP))
return;
rdmsr(MSR_AMD64_SYSCFG, lo, hi);
Annotation
- Immediate include surface: `linux/export.h`, `linux/init.h`, `linux/io.h`, `linux/mm.h`, `linux/cc_platform.h`, `linux/string_choices.h`, `asm/processor-flags.h`, `asm/cacheinfo.h`.
- Detected declarations: `struct fixed_range_block`, `struct cache_map`, `function mtrr_param_setup`, `function k8_check_syscfg_dram_mod_en`, `function get_mtrr_size`, `function get_var_mtrr_state`, `function get_effective_type`, `function rm_map_entry_at`, `function add_map_entry_at`, `function clr_map_range_at`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.