18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * local MTRR defines. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/types.h> 78c2ecf20Sopenharmony_ci#include <linux/stddef.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define MTRR_CHANGE_MASK_FIXED 0x01 108c2ecf20Sopenharmony_ci#define MTRR_CHANGE_MASK_VARIABLE 0x02 118c2ecf20Sopenharmony_ci#define MTRR_CHANGE_MASK_DEFTYPE 0x04 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciextern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES]; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct mtrr_ops { 168c2ecf20Sopenharmony_ci u32 vendor; 178c2ecf20Sopenharmony_ci u32 use_intel_if; 188c2ecf20Sopenharmony_ci void (*set)(unsigned int reg, unsigned long base, 198c2ecf20Sopenharmony_ci unsigned long size, mtrr_type type); 208c2ecf20Sopenharmony_ci void (*set_all)(void); 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci void (*get)(unsigned int reg, unsigned long *base, 238c2ecf20Sopenharmony_ci unsigned long *size, mtrr_type *type); 248c2ecf20Sopenharmony_ci int (*get_free_region)(unsigned long base, unsigned long size, 258c2ecf20Sopenharmony_ci int replace_reg); 268c2ecf20Sopenharmony_ci int (*validate_add_page)(unsigned long base, unsigned long size, 278c2ecf20Sopenharmony_ci unsigned int type); 288c2ecf20Sopenharmony_ci int (*have_wrcomb)(void); 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciextern int generic_get_free_region(unsigned long base, unsigned long size, 328c2ecf20Sopenharmony_ci int replace_reg); 338c2ecf20Sopenharmony_ciextern int generic_validate_add_page(unsigned long base, unsigned long size, 348c2ecf20Sopenharmony_ci unsigned int type); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciextern const struct mtrr_ops generic_mtrr_ops; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciextern int positive_have_wrcomb(void); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* library functions for processor-specific routines */ 418c2ecf20Sopenharmony_cistruct set_mtrr_context { 428c2ecf20Sopenharmony_ci unsigned long flags; 438c2ecf20Sopenharmony_ci unsigned long cr4val; 448c2ecf20Sopenharmony_ci u32 deftype_lo; 458c2ecf20Sopenharmony_ci u32 deftype_hi; 468c2ecf20Sopenharmony_ci u32 ccr3; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_civoid set_mtrr_done(struct set_mtrr_context *ctxt); 508c2ecf20Sopenharmony_civoid set_mtrr_cache_disable(struct set_mtrr_context *ctxt); 518c2ecf20Sopenharmony_civoid set_mtrr_prepare_save(struct set_mtrr_context *ctxt); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_civoid fill_mtrr_var_range(unsigned int index, 548c2ecf20Sopenharmony_ci u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi); 558c2ecf20Sopenharmony_cibool get_mtrr_state(void); 568c2ecf20Sopenharmony_civoid mtrr_bp_pat_init(void); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciextern void __init set_mtrr_ops(const struct mtrr_ops *ops); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciextern u64 size_or_mask, size_and_mask; 618c2ecf20Sopenharmony_ciextern const struct mtrr_ops *mtrr_if; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd) 648c2ecf20Sopenharmony_ci#define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciextern unsigned int num_var_ranges; 678c2ecf20Sopenharmony_ciextern u64 mtrr_tom2; 688c2ecf20Sopenharmony_ciextern struct mtrr_state_type mtrr_state; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_civoid mtrr_state_warn(void); 718c2ecf20Sopenharmony_ciconst char *mtrr_attrib_to_str(int x); 728c2ecf20Sopenharmony_civoid mtrr_wrmsr(unsigned, unsigned, unsigned); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* CPU specific mtrr init functions */ 758c2ecf20Sopenharmony_ciint amd_init_mtrr(void); 768c2ecf20Sopenharmony_ciint cyrix_init_mtrr(void); 778c2ecf20Sopenharmony_ciint centaur_init_mtrr(void); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciextern int changed_by_mtrr_cleanup; 808c2ecf20Sopenharmony_ciextern int mtrr_cleanup(unsigned address_bits); 81