1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * local MTRR defines. 4 */ 5 6 #include <linux/types.h> 7 #include <linux/stddef.h> 8 9 #define MTRR_CHANGE_MASK_FIXED 0x01 10 #define MTRR_CHANGE_MASK_VARIABLE 0x02 11 #define MTRR_CHANGE_MASK_DEFTYPE 0x04 12 13 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES]; 14 15 struct mtrr_ops { 16 u32 var_regs; 17 void (*set)(unsigned int reg, unsigned long base, 18 unsigned long size, mtrr_type type); 19 void (*get)(unsigned int reg, unsigned long *base, 20 unsigned long *size, mtrr_type *type); 21 int (*get_free_region)(unsigned long base, unsigned long size, 22 int replace_reg); 23 int (*validate_add_page)(unsigned long base, unsigned long size, 24 unsigned int type); 25 int (*have_wrcomb)(void); 26 }; 27 28 extern int generic_get_free_region(unsigned long base, unsigned long size, 29 int replace_reg); 30 extern int generic_validate_add_page(unsigned long base, unsigned long size, 31 unsigned int type); 32 33 extern const struct mtrr_ops generic_mtrr_ops; 34 35 extern int positive_have_wrcomb(void); 36 37 /* library functions for processor-specific routines */ 38 struct set_mtrr_context { 39 unsigned long flags; 40 unsigned long cr4val; 41 u32 deftype_lo; 42 u32 deftype_hi; 43 u32 ccr3; 44 }; 45 46 void set_mtrr_done(struct set_mtrr_context *ctxt); 47 void set_mtrr_cache_disable(struct set_mtrr_context *ctxt); 48 void set_mtrr_prepare_save(struct set_mtrr_context *ctxt); 49 50 void fill_mtrr_var_range(unsigned int index, 51 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi); 52 bool get_mtrr_state(void); 53 54 extern const struct mtrr_ops *mtrr_if; 55 extern struct mutex mtrr_mutex; 56 57 extern unsigned int num_var_ranges; 58 extern u64 mtrr_tom2; 59 extern struct mtrr_state_type mtrr_state; 60 extern u32 phys_hi_rsvd; 61 62 void mtrr_state_warn(void); 63 const char *mtrr_attrib_to_str(int x); 64 void mtrr_wrmsr(unsigned, unsigned, unsigned); 65 #ifdef CONFIG_X86_32 66 void mtrr_set_if(void); 67 void mtrr_register_syscore(void); 68 #else 69 static inline void mtrr_set_if(void) { } 70 static inline void mtrr_register_syscore(void) { } 71 #endif 72 void mtrr_build_map(void); 73 void mtrr_copy_map(void); 74 75 /* CPU specific mtrr_ops vectors. */ 76 extern const struct mtrr_ops amd_mtrr_ops; 77 extern const struct mtrr_ops cyrix_mtrr_ops; 78 extern const struct mtrr_ops centaur_mtrr_ops; 79 80 extern int changed_by_mtrr_cleanup; 81 extern int mtrr_cleanup(void); 82 83 /* 84 * Must be used by code which uses mtrr_if to call platform-specific 85 * MTRR manipulation functions. 86 */ 87 static inline bool mtrr_enabled(void) 88 { 89 return !!mtrr_if; 90 } 91 void generic_rebuild_map(void); 92