Martin Roth | 239b5df | 2022-07-26 22:18:26 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Eric Biederman | c84c190 | 2004-10-14 20:13:01 +0000 | [diff] [blame] | 3 | #ifndef CPU_AMD_MTRR_H |
| 4 | #define CPU_AMD_MTRR_H |
| 5 | |
Elyes HAOUAS | d35c7fe | 2018-10-30 07:07:00 +0100 | [diff] [blame] | 6 | #define MTRR_IORR0_BASE 0xC0010016 |
| 7 | #define MTRR_IORR0_MASK 0xC0010017 |
| 8 | #define MTRR_IORR1_BASE 0xC0010018 |
| 9 | #define MTRR_IORR1_MASK 0xC0010019 |
Eric Biederman | c84c190 | 2004-10-14 20:13:01 +0000 | [diff] [blame] | 10 | |
| 11 | #define MTRR_READ_MEM (1 << 4) |
| 12 | #define MTRR_WRITE_MEM (1 << 3) |
| 13 | |
| 14 | #define SYSCFG_MSR 0xC0010010 |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 15 | #define SYSCFG_MSR_TOM2WB (1 << 22) |
Eric Biederman | c84c190 | 2004-10-14 20:13:01 +0000 | [diff] [blame] | 16 | #define SYSCFG_MSR_TOM2En (1 << 21) |
| 17 | #define SYSCFG_MSR_MtrrVarDramEn (1 << 20) |
| 18 | #define SYSCFG_MSR_MtrrFixDramModEn (1 << 19) |
| 19 | #define SYSCFG_MSR_MtrrFixDramEn (1 << 18) |
| 20 | #define SYSCFG_MSR_UcLockEn (1 << 17) |
| 21 | #define SYSCFG_MSR_ChxToDirtyDis (1 << 16) |
| 22 | #define SYSCFG_MSR_ClVicBlkEn (1 << 11) |
| 23 | #define SYSCFG_MSR_SetDirtyEnO (1 << 10) |
| 24 | #define SYSCFG_MSR_SetDirtyEnS (1 << 9) |
| 25 | #define SYSCFG_MSR_SetDirtyEnE (1 << 8) |
| 26 | #define SYSCFG_MSR_SysVicLimitMask ((1 << 8) - (1 << 5)) |
| 27 | #define SYSCFG_MSR_SysAckLimitMask ((1 << 5) - (1 << 0)) |
| 28 | |
Warren Turkal | 4ffde94 | 2010-10-12 06:13:40 +0000 | [diff] [blame] | 29 | #define IORRBase_MSR(reg) (0xC0010016 + 2 * (reg)) |
| 30 | #define IORRMask_MSR(reg) (0xC0010016 + 2 * (reg) + 1) |
| 31 | |
Kyösti Mälkki | 0127c6c | 2015-03-05 14:35:04 +0200 | [diff] [blame] | 32 | #if defined(__ASSEMBLER__) |
| 33 | #define TOP_MEM 0xC001001A |
| 34 | #define TOP_MEM2 0xC001001D |
| 35 | #else |
| 36 | #define TOP_MEM 0xC001001Aul |
| 37 | #define TOP_MEM2 0xC001001Dul |
efdesign98 | 78834b7 | 2011-08-04 16:18:16 -0600 | [diff] [blame] | 38 | #endif |
Eric Biederman | c84c190 | 2004-10-14 20:13:01 +0000 | [diff] [blame] | 39 | |
Arthur Heymans | 1cb9cd5 | 2019-11-28 16:05:08 +0100 | [diff] [blame] | 40 | #if !defined(__ASSEMBLER__) |
Kyösti Mälkki | 4607cac | 2016-12-06 14:14:19 +0200 | [diff] [blame] | 41 | |
| 42 | #include <cpu/x86/msr.h> |
Elyes HAOUAS | 5817c56 | 2020-07-12 09:03:22 +0200 | [diff] [blame] | 43 | #include <stdint.h> |
Kyösti Mälkki | 4607cac | 2016-12-06 14:14:19 +0200 | [diff] [blame] | 44 | |
Kyösti Mälkki | 17bb225 | 2017-04-19 19:55:54 +0300 | [diff] [blame] | 45 | struct device; |
| 46 | void add_uma_resource_below_tolm(struct device *nb, int idx); |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 47 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 48 | static __always_inline msr_t rdmsr_amd(unsigned int index) |
Kyösti Mälkki | 190011e | 2013-03-25 12:48:49 +0200 | [diff] [blame] | 49 | { |
| 50 | msr_t result; |
| 51 | __asm__ __volatile__ ( |
| 52 | "rdmsr" |
| 53 | : "=a" (result.lo), "=d" (result.hi) |
| 54 | : "c"(index), "D"(0x9c5a203a) |
| 55 | ); |
| 56 | return result; |
| 57 | } |
| 58 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 59 | static __always_inline void wrmsr_amd(unsigned int index, msr_t msr) |
Kyösti Mälkki | 190011e | 2013-03-25 12:48:49 +0200 | [diff] [blame] | 60 | { |
| 61 | __asm__ __volatile__ ( |
| 62 | "wrmsr" |
| 63 | : /* No outputs */ |
| 64 | : "c" (index), "a" (msr.lo), "d" (msr.hi), "D" (0x9c5a203a) |
| 65 | ); |
| 66 | } |
| 67 | |
Felix Held | fb532c7 | 2023-04-20 12:57:11 +0200 | [diff] [blame] | 68 | static inline uint32_t get_top_of_mem_below_4gb(void) |
Arthur Heymans | c435038 | 2021-10-28 12:35:39 +0200 | [diff] [blame] | 69 | { |
| 70 | return rdmsr(TOP_MEM).lo; |
| 71 | } |
| 72 | |
Felix Held | 27af3e6 | 2023-04-22 05:59:52 +0200 | [diff] [blame^] | 73 | static inline uint64_t get_top_of_mem_above_4gb(void) |
Arthur Heymans | c435038 | 2021-10-28 12:35:39 +0200 | [diff] [blame] | 74 | { |
| 75 | msr_t msr = rdmsr(TOP_MEM2); |
| 76 | return (uint64_t)msr.hi << 32 | msr.lo; |
| 77 | } |
Stefan Reinauer | 35b6bbb | 2010-03-28 21:26:54 +0000 | [diff] [blame] | 78 | #endif |
Eric Biederman | c84c190 | 2004-10-14 20:13:01 +0000 | [diff] [blame] | 79 | |
| 80 | #endif /* CPU_AMD_MTRR_H */ |