Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
| 4 | * |
| 5 | * From Coreboot file of the same name |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _ASM_MTRR_H |
| 9 | #define _ASM_MTRR_H |
| 10 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 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 |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 17 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 18 | #define MTRR_TYPE_COUNT 7 |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 19 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 20 | #define MTRR_CAP_MSR 0x0fe |
| 21 | #define MTRR_DEF_TYPE_MSR 0x2ff |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 22 | |
Bin Meng | c45a93b | 2015-07-06 16:31:30 +0800 | [diff] [blame] | 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 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 28 | #define MTRR_DEF_TYPE_EN (1 << 11) |
| 29 | #define MTRR_DEF_TYPE_FIX_EN (1 << 10) |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 30 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 31 | #define MTRR_PHYS_BASE_MSR(reg) (0x200 + 2 * (reg)) |
| 32 | #define MTRR_PHYS_MASK_MSR(reg) (0x200 + 2 * (reg) + 1) |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 33 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 34 | #define MTRR_PHYS_MASK_VALID (1 << 11) |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 35 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 36 | #define MTRR_BASE_TYPE_MASK 0x7 |
| 37 | |
| 38 | /* Number of MTRRs supported */ |
| 39 | #define MTRR_COUNT 8 |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 40 | |
Simon Glass | a9a4426 | 2015-04-29 22:25:59 -0600 | [diff] [blame] | 41 | #define NUM_FIXED_MTRRS 11 |
| 42 | #define RANGES_PER_FIXED_MTRR 8 |
| 43 | #define NUM_FIXED_RANGES (NUM_FIXED_MTRRS * RANGES_PER_FIXED_MTRR) |
| 44 | |
Bin Meng | c45a93b | 2015-07-06 16:31:30 +0800 | [diff] [blame] | 45 | #define MTRR_FIX_64K_00000_MSR 0x250 |
| 46 | #define MTRR_FIX_16K_80000_MSR 0x258 |
| 47 | #define MTRR_FIX_16K_A0000_MSR 0x259 |
| 48 | #define MTRR_FIX_4K_C0000_MSR 0x268 |
| 49 | #define MTRR_FIX_4K_C8000_MSR 0x269 |
| 50 | #define MTRR_FIX_4K_D0000_MSR 0x26a |
| 51 | #define MTRR_FIX_4K_D8000_MSR 0x26b |
| 52 | #define MTRR_FIX_4K_E0000_MSR 0x26c |
| 53 | #define MTRR_FIX_4K_E8000_MSR 0x26d |
| 54 | #define MTRR_FIX_4K_F0000_MSR 0x26e |
| 55 | #define MTRR_FIX_4K_F8000_MSR 0x26f |
Simon Glass | 71ca938 | 2015-04-28 20:25:13 -0600 | [diff] [blame] | 56 | |
Bin Meng | 268ca83 | 2015-07-15 16:23:38 +0800 | [diff] [blame] | 57 | #define MTRR_FIX_TYPE(t) ((t << 24) | (t << 16) | (t << 8) | t) |
| 58 | |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 59 | #if !defined(__ASSEMBLER__) |
| 60 | |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Information about the previous MTRR state, set up by mtrr_open() |
| 63 | * |
| 64 | * @deftype: Previous value of MTRR_DEF_TYPE_MSR |
| 65 | * @enable_cache: true if cache was enabled |
| 66 | */ |
| 67 | struct mtrr_state { |
| 68 | uint64_t deftype; |
| 69 | bool enable_cache; |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * mtrr_open() - Prepare to adjust MTRRs |
| 74 | * |
| 75 | * Use mtrr_open() passing in a structure - this function will init it. Then |
| 76 | * when done, pass the same structure to mtrr_close() to re-enable MTRRs and |
| 77 | * possibly the cache. |
| 78 | * |
| 79 | * @state: Empty structure to pass in to hold settings |
| 80 | */ |
| 81 | void mtrr_open(struct mtrr_state *state); |
| 82 | |
| 83 | /** |
| 84 | * mtrr_open() - Clean up after adjusting MTRRs, and enable them |
| 85 | * |
| 86 | * This uses the structure containing information returned from mtrr_open(). |
| 87 | * |
| 88 | * @state: Structure from mtrr_open() |
| 89 | */ |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 90 | void mtrr_close(struct mtrr_state *state); |
| 91 | |
| 92 | /** |
| 93 | * mtrr_add_request() - Add a new MTRR request |
| 94 | * |
| 95 | * This adds a request for a memory region to be set up in a particular way. |
| 96 | * |
| 97 | * @type: Requested type (MTRR_TYPE_) |
| 98 | * @start: Start address |
| 99 | * @size: Size |
Bin Meng | 80d2976 | 2015-01-22 11:29:41 +0800 | [diff] [blame] | 100 | * |
| 101 | * @return: 0 on success, non-zero on failure |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 102 | */ |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 103 | int mtrr_add_request(int type, uint64_t start, uint64_t size); |
| 104 | |
| 105 | /** |
| 106 | * mtrr_commit() - set up the MTRR registers based on current requests |
| 107 | * |
| 108 | * This sets up MTRRs for the available DRAM and the requests received so far. |
| 109 | * It must be called with caches disabled. |
| 110 | * |
| 111 | * @do_caches: true if caches are currently on |
Bin Meng | 80d2976 | 2015-01-22 11:29:41 +0800 | [diff] [blame] | 112 | * |
| 113 | * @return: 0 on success, non-zero on failure |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 114 | */ |
Simon Glass | 7bf5b9e | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 115 | int mtrr_commit(bool do_caches); |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 116 | |
| 117 | #endif |
| 118 | |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 119 | #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0) |
| 120 | # error "CONFIG_XIP_ROM_SIZE is not a power of 2" |
| 121 | #endif |
| 122 | |
| 123 | #if ((CONFIG_CACHE_ROM_SIZE & (CONFIG_CACHE_ROM_SIZE - 1)) != 0) |
| 124 | # error "CONFIG_CACHE_ROM_SIZE is not a power of 2" |
| 125 | #endif |
| 126 | |
| 127 | #define CACHE_ROM_BASE (((1 << 20) - (CONFIG_CACHE_ROM_SIZE >> 12)) << 12) |
| 128 | |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 129 | #endif |