soc/intel/alderlake: Add ADL-P 4+4 with 28W TDP
[coreboot.git] / src / drivers / amd / agesa / s3_mtrr.c
blob51e8a4d27bb77074a3a5fdf9a6ec7322bc0a0cfd
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdint.h>
4 #include <cbmem.h>
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 <string.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[] = {
14 MTRR_FIX_64K_00000,
15 MTRR_FIX_16K_80000,
16 MTRR_FIX_16K_A0000,
17 MTRR_FIX_4K_C0000,
18 MTRR_FIX_4K_C8000,
19 MTRR_FIX_4K_D0000,
20 MTRR_FIX_4K_D8000,
21 MTRR_FIX_4K_E0000,
22 MTRR_FIX_4K_E8000,
23 MTRR_FIX_4K_F0000,
24 MTRR_FIX_4K_F8000,
25 MTRR_PHYS_BASE(0),
26 MTRR_PHYS_MASK(0),
27 MTRR_PHYS_BASE(1),
28 MTRR_PHYS_MASK(1),
29 MTRR_PHYS_BASE(2),
30 MTRR_PHYS_MASK(2),
31 MTRR_PHYS_BASE(3),
32 MTRR_PHYS_MASK(3),
33 MTRR_PHYS_BASE(4),
34 MTRR_PHYS_MASK(4),
35 MTRR_PHYS_BASE(5),
36 MTRR_PHYS_MASK(5),
37 MTRR_PHYS_BASE(6),
38 MTRR_PHYS_MASK(6),
39 MTRR_PHYS_BASE(7),
40 MTRR_PHYS_MASK(7),
41 SYSCFG_MSR,
42 TOP_MEM,
43 TOP_MEM2,
46 void backup_mtrr(void)
48 msr_t syscfg_msr;
49 msr_t *mtrr_save = (msr_t *)cbmem_add(CBMEM_ID_AGESA_MTRR,
50 sizeof(msr_t) * ARRAY_SIZE(msr_backup));
51 if (!mtrr_save)
52 return;
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)
70 msr_t syscfg_msr;
71 msr_t *mtrr_save = (msr_t *)cbmem_find(CBMEM_ID_AGESA_MTRR);
73 if (!mtrr_save)
74 return;
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);