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 <cpu/intel/smm_reloc.h>
9 #include <cpu/x86/mtrr.h>
10 #include <cpu/x86/smm.h>
11 #include <device/pci_ops.h>
12 #include <program_loading.h>
17 #define HOST_BRIDGE PCI_DEV(0, 0, 0)
19 static uintptr_t top_of_low_ram(void)
23 /* This is at 128 MiB boundary. */
24 tolm
= pci_read_config16(HOST_BRIDGE
, TOLM
) >> 11;
29 size_t northbridge_get_tseg_size(void)
31 const uint8_t esmramc
= pci_read_config8(HOST_BRIDGE
, ESMRAMC
);
33 if (!(esmramc
& T_EN
))
36 switch ((esmramc
& TSEG_SZ_MASK
) >> 1) {
49 uintptr_t northbridge_get_tseg_base(void)
51 uintptr_t tolm
= top_of_low_ram();
53 /* subtract TSEG size */
54 tolm
-= northbridge_get_tseg_size();
58 void smm_region(uintptr_t *start
, size_t *size
)
60 *start
= northbridge_get_tseg_base();
61 *size
= northbridge_get_tseg_size();
64 uintptr_t cbmem_top_chipset(void)
66 return northbridge_get_tseg_base();
72 pci_write_config8(HOST_BRIDGE
, SMRAMC
, D_OPEN
| G_SMRAME
| C_BASE_SEG
);
78 pci_write_config8(HOST_BRIDGE
, SMRAMC
, G_SMRAME
| C_BASE_SEG
);
84 * LOCK the SMM memory window and enable normal SMM.
85 * After running this function, only a full reset can
86 * make the SMM registers writable again.
88 printk(BIOS_DEBUG
, "Locking SMM.\n");
90 pci_write_config8(HOST_BRIDGE
, SMRAMC
, D_LCK
| G_SMRAME
| C_BASE_SEG
);
93 void fill_postcar_frame(struct postcar_frame
*pcf
)
96 * Choose to NOT set ROM as WP cacheable here.
97 * Timestamps indicate the CPU this northbridge code is
98 * connected to, performs better for memcpy() and un-lzma
99 * operations when source is left as UC.
102 pcf
->skip_common_mtrr
= 1;
104 /* Cache RAM as WB from 0 -> TOLM. */
105 postcar_frame_add_mtrr(pcf
, top_of_low_ram(), CACHE_TMP_RAMTOP
, MTRR_TYPE_WRBACK
);