1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <cpu/x86/msr.h>
6 #include <cpu/x86/mtrr.h>
7 #include <cpu/amd/mtrr.h>
8 #include <cpu/x86/cache.h>
9 #include <northbridge/amd/agesa/agesa_helper.h>
11 /* TODO: Do we want MTRR_DEF_TYPE_MSR too? */
12 static const uint32_t msr_backup
[] = {
45 void backup_mtrr(void)
48 msr_t
*mtrr_save
= (msr_t
*)cbmem_add(CBMEM_ID_AGESA_MTRR
,
49 sizeof(msr_t
) * ARRAY_SIZE(msr_backup
));
53 /* Enable access to AMD RdDram and WrDram extension bits */
54 syscfg_msr
= rdmsr(SYSCFG_MSR
);
55 syscfg_msr
.lo
|= SYSCFG_MSR_MtrrFixDramModEn
;
56 wrmsr(SYSCFG_MSR
, syscfg_msr
);
58 for (int i
= 0; i
< ARRAY_SIZE(msr_backup
); i
++)
59 *mtrr_save
++ = rdmsr(msr_backup
[i
]);
61 /* Disable access to AMD RdDram and WrDram extension bits */
62 syscfg_msr
= rdmsr(SYSCFG_MSR
);
63 syscfg_msr
.lo
&= ~SYSCFG_MSR_MtrrFixDramModEn
;
64 wrmsr(SYSCFG_MSR
, syscfg_msr
);
67 void restore_mtrr(void)
70 msr_t
*mtrr_save
= (msr_t
*)cbmem_find(CBMEM_ID_AGESA_MTRR
);
75 /* Enable access to AMD RdDram and WrDram extension bits */
76 syscfg_msr
= rdmsr(SYSCFG_MSR
);
77 syscfg_msr
.lo
|= SYSCFG_MSR_MtrrFixDramModEn
;
78 wrmsr(SYSCFG_MSR
, syscfg_msr
);
80 for (int i
= 0; i
< ARRAY_SIZE(msr_backup
); i
++)
81 wrmsr(msr_backup
[i
], *mtrr_save
++);
83 /* Disable access to AMD RdDram and WrDram extension bits */
84 syscfg_msr
= rdmsr(SYSCFG_MSR
);
85 syscfg_msr
.lo
&= ~SYSCFG_MSR_MtrrFixDramModEn
;
86 wrmsr(SYSCFG_MSR
, syscfg_msr
);