1 /* SPDX-License-Identifier: GPL-2.0-only */
3 // Use simple device model for this file even in ramstage
4 #define __SIMPLE_DEVICE__
6 #include <arch/romstage.h>
8 #include <console/console.h>
9 #include <cpu/x86/mtrr.h>
10 #include <cpu/x86/smm.h>
11 #include <device/pci_ops.h>
16 /* Decodes TSEG region size to bytes. */
17 u32
decode_tseg_size(const u8 esmramc
)
21 switch ((esmramc
>> 1) & 3) {
30 die("Bad TSEG setting.\n");
34 static uintptr_t northbridge_get_tseg_base(void)
38 if (pci_read_config8(HOST_BRIDGE
, DEVEN
) & (DEVEN_D2F0
| DEVEN_D2F1
))
39 /* IGD enabled, get top of Memory from BSM register */
40 tom
= pci_read_config32(IGD_DEV
, BSM
);
42 tom
= (pci_read_config8(HOST_BRIDGE
, TOLUD
) & 0xf8) << 24;
44 /* subtract TSEG size */
45 tom
-= decode_tseg_size(pci_read_config8(HOST_BRIDGE
, ESMRAMC
));
49 static size_t northbridge_get_tseg_size(void)
51 const u8 esmramc
= pci_read_config8(HOST_BRIDGE
, ESMRAMC
);
52 return decode_tseg_size(esmramc
);
56 * Depending of UMA and TSEG configuration, TSEG might start at any
57 * 1 MiB alignment. As this may cause very greedy MTRR setup, push
58 * CBMEM top downwards to 4 MiB boundary.
60 uintptr_t cbmem_top_chipset(void)
62 return ALIGN_DOWN(northbridge_get_tseg_base(), 4*MiB
);
65 /* Decodes used Graphics Mode Select (GMS) to kilobytes. */
66 u32
decode_igd_memory_size(const u32 gms
)
68 static const u16 ggc2uma
[] = { 0, 1, 4, 8, 16, 32, 48, 64 };
70 if (gms
>= ARRAY_SIZE(ggc2uma
))
71 die("Bad Graphics Mode Select (GMS) setting.\n");
73 return ggc2uma
[gms
] << 10;
76 void smm_region(uintptr_t *start
, size_t *size
)
78 *start
= northbridge_get_tseg_base();
79 *size
= northbridge_get_tseg_size();
82 void fill_postcar_frame(struct postcar_frame
*pcf
)
84 /* Cache 8 MiB region below the top of RAM and 2 MiB above top of
85 * RAM to cover both cbmem as the TSEG region.
87 const uintptr_t top_of_ram
= cbmem_top();
88 postcar_frame_add_mtrr(pcf
, top_of_ram
- 8*MiB
, 8*MiB
, MTRR_TYPE_WRBACK
);
89 postcar_frame_add_mtrr(pcf
, northbridge_get_tseg_base(),
90 northbridge_get_tseg_size(), MTRR_TYPE_WRBACK
);