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>
10 #include <northbridge/amd/agesa/agesa_helper.h>
12 /* TODO: Do we want MTRR_DEF_TYPE_MSR too? */
13 static const uint32_t msr_backup
[] = {
46 void backup_mtrr(void)
49 msr_t
*mtrr_save
= (msr_t
*)cbmem_add(CBMEM_ID_AGESA_MTRR
,
50 sizeof(msr_t
) * ARRAY_SIZE(msr_backup
));
54 /* Enable access to AMD RdDram and WrDram extension bits */
55 syscfg_msr
= rdmsr(SYSCFG_MSR
);
56 syscfg_msr
.lo
|= SYSCFG_MSR_MtrrFixDramModEn
;
57 wrmsr(SYSCFG_MSR
, syscfg_msr
);
59 for (int i
= 0; i
< ARRAY_SIZE(msr_backup
); i
++)
60 *mtrr_save
++ = rdmsr(msr_backup
[i
]);
62 /* Disable access to AMD RdDram and WrDram extension bits */
63 syscfg_msr
= rdmsr(SYSCFG_MSR
);
64 syscfg_msr
.lo
&= ~SYSCFG_MSR_MtrrFixDramModEn
;
65 wrmsr(SYSCFG_MSR
, syscfg_msr
);
68 void restore_mtrr(void)
71 msr_t
*mtrr_save
= (msr_t
*)cbmem_find(CBMEM_ID_AGESA_MTRR
);
76 /* Enable access to AMD RdDram and WrDram extension bits */
77 syscfg_msr
= rdmsr(SYSCFG_MSR
);
78 syscfg_msr
.lo
|= SYSCFG_MSR_MtrrFixDramModEn
;
79 wrmsr(SYSCFG_MSR
, syscfg_msr
);
81 for (int i
= 0; i
< ARRAY_SIZE(msr_backup
); i
++)
82 wrmsr(msr_backup
[i
], *mtrr_save
++);
84 /* Disable access to AMD RdDram and WrDram extension bits */
85 syscfg_msr
= rdmsr(SYSCFG_MSR
);
86 syscfg_msr
.lo
&= ~SYSCFG_MSR_MtrrFixDramModEn
;
87 wrmsr(SYSCFG_MSR
, syscfg_msr
);