]> Git Repo - J-u-boot.git/blame - arch/x86/include/asm/mtrr.h
x86: mp: Add iterators for CPUs
[J-u-boot.git] / arch / x86 / include / asm / mtrr.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
70a09c6c
SG
2/*
3 * Copyright (c) 2014 Google, Inc
4 *
5 * From Coreboot file of the same name
70a09c6c
SG
6 */
7
8#ifndef _ASM_MTRR_H
9#define _ASM_MTRR_H
10
aff2523f
SG
11/* MTRR region types */
12#define MTRR_TYPE_UNCACHEABLE 0
13#define MTRR_TYPE_WRCOMB 1
14#define MTRR_TYPE_WRTHROUGH 4
15#define MTRR_TYPE_WRPROT 5
16#define MTRR_TYPE_WRBACK 6
17
18#define MTRR_TYPE_COUNT 7
19
20#define MTRR_CAP_MSR 0x0fe
21#define MTRR_DEF_TYPE_MSR 0x2ff
22
43dd22f5
BM
23#define MTRR_CAP_SMRR (1 << 11)
24#define MTRR_CAP_WC (1 << 10)
25#define MTRR_CAP_FIX (1 << 8)
26#define MTRR_CAP_VCNT_MASK 0xff
27
ebe002cd 28#define MTRR_DEF_TYPE_MASK 0xff
aff2523f
SG
29#define MTRR_DEF_TYPE_EN (1 << 11)
30#define MTRR_DEF_TYPE_FIX_EN (1 << 10)
31
32#define MTRR_PHYS_BASE_MSR(reg) (0x200 + 2 * (reg))
33#define MTRR_PHYS_MASK_MSR(reg) (0x200 + 2 * (reg) + 1)
34
35#define MTRR_PHYS_MASK_VALID (1 << 11)
36
37#define MTRR_BASE_TYPE_MASK 0x7
38
39/* Number of MTRRs supported */
40#define MTRR_COUNT 8
70a09c6c 41
45b5a378
SG
42#define NUM_FIXED_MTRRS 11
43#define RANGES_PER_FIXED_MTRR 8
44#define NUM_FIXED_RANGES (NUM_FIXED_MTRRS * RANGES_PER_FIXED_MTRR)
45
43dd22f5
BM
46#define MTRR_FIX_64K_00000_MSR 0x250
47#define MTRR_FIX_16K_80000_MSR 0x258
48#define MTRR_FIX_16K_A0000_MSR 0x259
49#define MTRR_FIX_4K_C0000_MSR 0x268
50#define MTRR_FIX_4K_C8000_MSR 0x269
51#define MTRR_FIX_4K_D0000_MSR 0x26a
52#define MTRR_FIX_4K_D8000_MSR 0x26b
53#define MTRR_FIX_4K_E0000_MSR 0x26c
54#define MTRR_FIX_4K_E8000_MSR 0x26d
55#define MTRR_FIX_4K_F0000_MSR 0x26e
56#define MTRR_FIX_4K_F8000_MSR 0x26f
1a06d2a3 57
8ba25eec
BM
58#define MTRR_FIX_TYPE(t) ((t << 24) | (t << 16) | (t << 8) | t)
59
f09f1ecb 60#if !defined(__ASSEMBLY__)
70a09c6c 61
aff2523f
SG
62/**
63 * Information about the previous MTRR state, set up by mtrr_open()
64 *
65 * @deftype: Previous value of MTRR_DEF_TYPE_MSR
66 * @enable_cache: true if cache was enabled
70a09c6c 67 */
aff2523f
SG
68struct mtrr_state {
69 uint64_t deftype;
70 bool enable_cache;
71};
72
73/**
74 * mtrr_open() - Prepare to adjust MTRRs
75 *
76 * Use mtrr_open() passing in a structure - this function will init it. Then
77 * when done, pass the same structure to mtrr_close() to re-enable MTRRs and
78 * possibly the cache.
79 *
80 * @state: Empty structure to pass in to hold settings
590cee83 81 * @do_caches: true to disable caches before opening
aff2523f 82 */
590cee83 83void mtrr_open(struct mtrr_state *state, bool do_caches);
aff2523f
SG
84
85/**
86 * mtrr_open() - Clean up after adjusting MTRRs, and enable them
87 *
88 * This uses the structure containing information returned from mtrr_open().
89 *
90 * @state: Structure from mtrr_open()
590cee83 91 * @state: true to restore cache state to that before mtrr_open()
aff2523f 92 */
590cee83 93void mtrr_close(struct mtrr_state *state, bool do_caches);
aff2523f
SG
94
95/**
96 * mtrr_add_request() - Add a new MTRR request
97 *
98 * This adds a request for a memory region to be set up in a particular way.
99 *
100 * @type: Requested type (MTRR_TYPE_)
101 * @start: Start address
102 * @size: Size
3b621cca
BM
103 *
104 * @return: 0 on success, non-zero on failure
aff2523f
SG
105 */
106int mtrr_add_request(int type, uint64_t start, uint64_t size);
107
108/**
109 * mtrr_commit() - set up the MTRR registers based on current requests
110 *
111 * This sets up MTRRs for the available DRAM and the requests received so far.
112 * It must be called with caches disabled.
113 *
114 * @do_caches: true if caches are currently on
3b621cca
BM
115 *
116 * @return: 0 on success, non-zero on failure
70a09c6c 117 */
aff2523f 118int mtrr_commit(bool do_caches);
70a09c6c 119
add3f4c9
SG
120/**
121 * mtrr_set_next_var() - set up a variable MTRR
122 *
123 * This finds the first free variable MTRR and sets to the given area
124 *
125 * @type: Requested type (MTRR_TYPE_)
126 * @start: Start address
127 * @size: Size
128 * @return 0 on success, -ENOSPC if there are no more MTRRs
129 */
130int mtrr_set_next_var(uint type, uint64_t base, uint64_t size);
131
70a09c6c
SG
132#endif
133
70a09c6c
SG
134#if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
135# error "CONFIG_XIP_ROM_SIZE is not a power of 2"
136#endif
137
138#if ((CONFIG_CACHE_ROM_SIZE & (CONFIG_CACHE_ROM_SIZE - 1)) != 0)
139# error "CONFIG_CACHE_ROM_SIZE is not a power of 2"
140#endif
141
142#define CACHE_ROM_BASE (((1 << 20) - (CONFIG_CACHE_ROM_SIZE >> 12)) << 12)
143
70a09c6c 144#endif
This page took 0.33223 seconds and 4 git commands to generate.