xref: /openbmc/linux/arch/x86/kernel/cpu/mtrr/mtrr.h (revision 7effbd18)
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	vendor;
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 u64 size_or_mask, size_and_mask;
55 extern const struct mtrr_ops *mtrr_if;
56 
57 #define is_cpu(vnd)	(mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
58 
59 extern unsigned int num_var_ranges;
60 extern u64 mtrr_tom2;
61 extern struct mtrr_state_type mtrr_state;
62 
63 void mtrr_state_warn(void);
64 const char *mtrr_attrib_to_str(int x);
65 void mtrr_wrmsr(unsigned, unsigned, unsigned);
66 
67 /* CPU specific mtrr_ops vectors. */
68 extern const struct mtrr_ops amd_mtrr_ops;
69 extern const struct mtrr_ops cyrix_mtrr_ops;
70 extern const struct mtrr_ops centaur_mtrr_ops;
71 
72 extern int changed_by_mtrr_cleanup;
73 extern int mtrr_cleanup(unsigned address_bits);
74