blob: 6fe1628bc0b8e8771361d04526ff70659cb2fbc6 [file] [log] [blame]
Eric Biedermanc84c1902004-10-14 20:13:01 +00001#ifndef CPU_AMD_MTRR_H
2#define CPU_AMD_MTRR_H
3
Elyes HAOUASd35c7fe2018-10-30 07:07:00 +01004#define MTRR_IORR0_BASE 0xC0010016
5#define MTRR_IORR0_MASK 0xC0010017
6#define MTRR_IORR1_BASE 0xC0010018
7#define MTRR_IORR1_MASK 0xC0010019
Eric Biedermanc84c1902004-10-14 20:13:01 +00008
9#define MTRR_READ_MEM (1 << 4)
10#define MTRR_WRITE_MEM (1 << 3)
11
12#define SYSCFG_MSR 0xC0010010
Scott Duplichanf3cce2f2010-11-13 19:07:59 +000013#define SYSCFG_MSR_TOM2WB (1 << 22)
Eric Biedermanc84c1902004-10-14 20:13:01 +000014#define SYSCFG_MSR_TOM2En (1 << 21)
15#define SYSCFG_MSR_MtrrVarDramEn (1 << 20)
16#define SYSCFG_MSR_MtrrFixDramModEn (1 << 19)
17#define SYSCFG_MSR_MtrrFixDramEn (1 << 18)
18#define SYSCFG_MSR_UcLockEn (1 << 17)
19#define SYSCFG_MSR_ChxToDirtyDis (1 << 16)
20#define SYSCFG_MSR_ClVicBlkEn (1 << 11)
21#define SYSCFG_MSR_SetDirtyEnO (1 << 10)
22#define SYSCFG_MSR_SetDirtyEnS (1 << 9)
23#define SYSCFG_MSR_SetDirtyEnE (1 << 8)
24#define SYSCFG_MSR_SysVicLimitMask ((1 << 8) - (1 << 5))
25#define SYSCFG_MSR_SysAckLimitMask ((1 << 5) - (1 << 0))
26
Warren Turkal4ffde942010-10-12 06:13:40 +000027#define IORRBase_MSR(reg) (0xC0010016 + 2 * (reg))
28#define IORRMask_MSR(reg) (0xC0010016 + 2 * (reg) + 1)
29
Kyösti Mälkki0127c6c2015-03-05 14:35:04 +020030#if defined(__ASSEMBLER__)
31#define TOP_MEM 0xC001001A
32#define TOP_MEM2 0xC001001D
33#else
34#define TOP_MEM 0xC001001Aul
35#define TOP_MEM2 0xC001001Dul
efdesign9878834b72011-08-04 16:18:16 -060036#endif
Eric Biedermanc84c1902004-10-14 20:13:01 +000037
38#define TOP_MEM_MASK 0x007fffff
39#define TOP_MEM_MASK_KB (TOP_MEM_MASK >> 10)
40
Arthur Heymans1cb9cd52019-11-28 16:05:08 +010041#if !defined(__ASSEMBLER__)
Kyösti Mälkki4607cac2016-12-06 14:14:19 +020042
43#include <cpu/x86/msr.h>
Elyes HAOUAS5817c562020-07-12 09:03:22 +020044#include <stdint.h>
Kyösti Mälkki4607cac2016-12-06 14:14:19 +020045
Kyösti Mälkki17bb2252017-04-19 19:55:54 +030046struct device;
47void add_uma_resource_below_tolm(struct device *nb, int idx);
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030048
Aaron Durbin75a62e72018-09-13 02:10:45 -060049static __always_inline msr_t rdmsr_amd(unsigned int index)
Kyösti Mälkki190011e2013-03-25 12:48:49 +020050{
51 msr_t result;
52 __asm__ __volatile__ (
53 "rdmsr"
54 : "=a" (result.lo), "=d" (result.hi)
55 : "c"(index), "D"(0x9c5a203a)
56 );
57 return result;
58}
59
Aaron Durbin75a62e72018-09-13 02:10:45 -060060static __always_inline void wrmsr_amd(unsigned int index, msr_t msr)
Kyösti Mälkki190011e2013-03-25 12:48:49 +020061{
62 __asm__ __volatile__ (
63 "wrmsr"
64 : /* No outputs */
65 : "c" (index), "a" (msr.lo), "d" (msr.hi), "D" (0x9c5a203a)
66 );
67}
68
Arthur Heymansc4350382021-10-28 12:35:39 +020069static inline uint64_t amd_topmem(void)
70{
71 return rdmsr(TOP_MEM).lo;
72}
73
74static inline uint64_t amd_topmem2(void)
75{
76 msr_t msr = rdmsr(TOP_MEM2);
77 return (uint64_t)msr.hi << 32 | msr.lo;
78}
Stefan Reinauer35b6bbb2010-03-28 21:26:54 +000079#endif
Eric Biedermanc84c1902004-10-14 20:13:01 +000080
81#endif /* CPU_AMD_MTRR_H */