xref: /openbmc/u-boot/arch/x86/include/asm/mtrr.h (revision 1a06d2a3)
170a09c6cSSimon Glass /*
270a09c6cSSimon Glass  * Copyright (c) 2014 Google, Inc
370a09c6cSSimon Glass  *
470a09c6cSSimon Glass  * From Coreboot file of the same name
570a09c6cSSimon Glass  *
670a09c6cSSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
770a09c6cSSimon Glass  */
870a09c6cSSimon Glass 
970a09c6cSSimon Glass #ifndef _ASM_MTRR_H
1070a09c6cSSimon Glass #define _ASM_MTRR_H
1170a09c6cSSimon Glass 
12aff2523fSSimon Glass /* MTRR region types */
1370a09c6cSSimon Glass #define MTRR_TYPE_UNCACHEABLE	0
1470a09c6cSSimon Glass #define MTRR_TYPE_WRCOMB	1
1570a09c6cSSimon Glass #define MTRR_TYPE_WRTHROUGH	4
1670a09c6cSSimon Glass #define MTRR_TYPE_WRPROT	5
1770a09c6cSSimon Glass #define MTRR_TYPE_WRBACK	6
1870a09c6cSSimon Glass 
19aff2523fSSimon Glass #define MTRR_TYPE_COUNT		7
2070a09c6cSSimon Glass 
21aff2523fSSimon Glass #define MTRR_CAP_MSR		0x0fe
22aff2523fSSimon Glass #define MTRR_DEF_TYPE_MSR	0x2ff
2370a09c6cSSimon Glass 
24aff2523fSSimon Glass #define MTRR_DEF_TYPE_EN	(1 << 11)
25aff2523fSSimon Glass #define MTRR_DEF_TYPE_FIX_EN	(1 << 10)
2670a09c6cSSimon Glass 
27aff2523fSSimon Glass #define MTRR_PHYS_BASE_MSR(reg)	(0x200 + 2 * (reg))
28aff2523fSSimon Glass #define MTRR_PHYS_MASK_MSR(reg)	(0x200 + 2 * (reg) + 1)
2970a09c6cSSimon Glass 
30aff2523fSSimon Glass #define MTRR_PHYS_MASK_VALID	(1 << 11)
3170a09c6cSSimon Glass 
32aff2523fSSimon Glass #define MTRR_BASE_TYPE_MASK	0x7
33aff2523fSSimon Glass 
34aff2523fSSimon Glass /* Number of MTRRs supported */
35aff2523fSSimon Glass #define MTRR_COUNT		8
3670a09c6cSSimon Glass 
37*1a06d2a3SSimon Glass #define NUM_FIXED_RANGES 88
38*1a06d2a3SSimon Glass #define RANGES_PER_FIXED_MTRR 8
39*1a06d2a3SSimon Glass #define MTRR_FIX_64K_00000_MSR 0x250
40*1a06d2a3SSimon Glass #define MTRR_FIX_16K_80000_MSR 0x258
41*1a06d2a3SSimon Glass #define MTRR_FIX_16K_A0000_MSR 0x259
42*1a06d2a3SSimon Glass #define MTRR_FIX_4K_C0000_MSR 0x268
43*1a06d2a3SSimon Glass #define MTRR_FIX_4K_C8000_MSR 0x269
44*1a06d2a3SSimon Glass #define MTRR_FIX_4K_D0000_MSR 0x26a
45*1a06d2a3SSimon Glass #define MTRR_FIX_4K_D8000_MSR 0x26b
46*1a06d2a3SSimon Glass #define MTRR_FIX_4K_E0000_MSR 0x26c
47*1a06d2a3SSimon Glass #define MTRR_FIX_4K_E8000_MSR 0x26d
48*1a06d2a3SSimon Glass #define MTRR_FIX_4K_F0000_MSR 0x26e
49*1a06d2a3SSimon Glass #define MTRR_FIX_4K_F8000_MSR 0x26f
50*1a06d2a3SSimon Glass 
5170a09c6cSSimon Glass #if !defined(__ASSEMBLER__)
5270a09c6cSSimon Glass 
53aff2523fSSimon Glass /**
54aff2523fSSimon Glass  * Information about the previous MTRR state, set up by mtrr_open()
55aff2523fSSimon Glass  *
56aff2523fSSimon Glass  * @deftype:		Previous value of MTRR_DEF_TYPE_MSR
57aff2523fSSimon Glass  * @enable_cache:	true if cache was enabled
5870a09c6cSSimon Glass  */
59aff2523fSSimon Glass struct mtrr_state {
60aff2523fSSimon Glass 	uint64_t deftype;
61aff2523fSSimon Glass 	bool enable_cache;
62aff2523fSSimon Glass };
63aff2523fSSimon Glass 
64aff2523fSSimon Glass /**
65aff2523fSSimon Glass  * mtrr_open() - Prepare to adjust MTRRs
66aff2523fSSimon Glass  *
67aff2523fSSimon Glass  * Use mtrr_open() passing in a structure - this function will init it. Then
68aff2523fSSimon Glass  * when done, pass the same structure to mtrr_close() to re-enable MTRRs and
69aff2523fSSimon Glass  * possibly the cache.
70aff2523fSSimon Glass  *
71aff2523fSSimon Glass  * @state:	Empty structure to pass in to hold settings
7270a09c6cSSimon Glass  */
73aff2523fSSimon Glass void mtrr_open(struct mtrr_state *state);
74aff2523fSSimon Glass 
75aff2523fSSimon Glass /**
76aff2523fSSimon Glass  * mtrr_open() - Clean up after adjusting MTRRs, and enable them
77aff2523fSSimon Glass  *
78aff2523fSSimon Glass  * This uses the structure containing information returned from mtrr_open().
79aff2523fSSimon Glass  *
80aff2523fSSimon Glass  * @state:	Structure from mtrr_open()
81aff2523fSSimon Glass  */
82aff2523fSSimon Glass void mtrr_close(struct mtrr_state *state);
83aff2523fSSimon Glass 
84aff2523fSSimon Glass /**
85aff2523fSSimon Glass  * mtrr_add_request() - Add a new MTRR request
86aff2523fSSimon Glass  *
87aff2523fSSimon Glass  * This adds a request for a memory region to be set up in a particular way.
88aff2523fSSimon Glass  *
89aff2523fSSimon Glass  * @type:	Requested type (MTRR_TYPE_)
90aff2523fSSimon Glass  * @start:	Start address
91aff2523fSSimon Glass  * @size:	Size
923b621ccaSBin Meng  *
933b621ccaSBin Meng  * @return:	0 on success, non-zero on failure
94aff2523fSSimon Glass  */
95aff2523fSSimon Glass int mtrr_add_request(int type, uint64_t start, uint64_t size);
96aff2523fSSimon Glass 
97aff2523fSSimon Glass /**
98aff2523fSSimon Glass  * mtrr_commit() - set up the MTRR registers based on current requests
99aff2523fSSimon Glass  *
100aff2523fSSimon Glass  * This sets up MTRRs for the available DRAM and the requests received so far.
101aff2523fSSimon Glass  * It must be called with caches disabled.
102aff2523fSSimon Glass  *
103aff2523fSSimon Glass  * @do_caches:	true if caches are currently on
1043b621ccaSBin Meng  *
1053b621ccaSBin Meng  * @return:	0 on success, non-zero on failure
106aff2523fSSimon Glass  */
107aff2523fSSimon Glass int mtrr_commit(bool do_caches);
10870a09c6cSSimon Glass 
10970a09c6cSSimon Glass #endif
11070a09c6cSSimon Glass 
11170a09c6cSSimon Glass #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
11270a09c6cSSimon Glass # error "CONFIG_XIP_ROM_SIZE is not a power of 2"
11370a09c6cSSimon Glass #endif
11470a09c6cSSimon Glass 
11570a09c6cSSimon Glass #if ((CONFIG_CACHE_ROM_SIZE & (CONFIG_CACHE_ROM_SIZE - 1)) != 0)
11670a09c6cSSimon Glass # error "CONFIG_CACHE_ROM_SIZE is not a power of 2"
11770a09c6cSSimon Glass #endif
11870a09c6cSSimon Glass 
11970a09c6cSSimon Glass #define CACHE_ROM_BASE	(((1 << 20) - (CONFIG_CACHE_ROM_SIZE >> 12)) << 12)
12070a09c6cSSimon Glass 
12170a09c6cSSimon Glass #endif
122