blob: 8da4ec9eeba734f51c1014de1ff4bf66c01c41b5 [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03002
3#define __SIMPLE_DEVICE__
4
Kyösti Mälkkia963acd2019-08-16 20:34:25 +03005#include <arch/romstage.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03007#include <cbmem.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +03008#include <cpu/intel/smm_reloc.h>
Kyösti Mälkkibfca6702016-07-22 22:48:35 +03009#include <cpu/x86/mtrr.h>
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030010#include <cpu/x86/smm.h>
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030011#include <program_loading.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030012#include "sandybridge.h"
13
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020014static uintptr_t smm_region_start(void)
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030015{
16 /* Base of TSEG is top of usable DRAM */
Angel Pons7c49cb82020-03-16 23:17:32 +010017 return pci_read_config32(HOST_BRIDGE, TSEGMB);
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020018}
19
Arthur Heymans340e4b82019-10-23 17:25:58 +020020void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020021{
Angel Pons7c49cb82020-03-16 23:17:32 +010022 return (void *)smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030023}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030024
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030025static uintptr_t northbridge_get_tseg_base(void)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030026{
Angel Pons7c49cb82020-03-16 23:17:32 +010027 return ALIGN_DOWN(smm_region_start(), 1 * MiB);
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030028}
29
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030030static size_t northbridge_get_tseg_size(void)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030031{
32 return CONFIG_SMM_TSEG_SIZE;
33}
34
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030035void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030036{
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030037 *start = northbridge_get_tseg_base();
Angel Pons7c49cb82020-03-16 23:17:32 +010038 *size = northbridge_get_tseg_size();
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030039}
40
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030041void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030042{
Angel Pons7c49cb82020-03-16 23:17:32 +010043 uintptr_t top_of_ram = (uintptr_t)cbmem_top();
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030044
Angel Pons7c49cb82020-03-16 23:17:32 +010045 /*
46 * Cache 8MiB below the top of ram. On sandybridge systems the top of
Elyes HAOUASef906092020-02-20 19:41:17 +010047 * RAM under 4GiB is the start of the TSEG region. It is required to
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030048 * be 8MiB aligned. Set this area as cacheable so it can be used later
Angel Pons7c49cb82020-03-16 23:17:32 +010049 * for ramstage before setting up the entire RAM as cacheable.
50 */
51 postcar_frame_add_mtrr(pcf, top_of_ram - 8 * MiB, 8 * MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030052
Angel Pons7c49cb82020-03-16 23:17:32 +010053 /*
54 * Cache 8MiB at the top of ram. Top of RAM on sandybridge systems
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030055 * is where the TSEG region resides. However, it is not restricted
56 * to SMM mode until SMM has been relocated. By setting the region
57 * to cacheable it provides faster access when relocating the SMM
Angel Pons7c49cb82020-03-16 23:17:32 +010058 * handler as well as using the TSEG region for other purposes.
59 */
60 postcar_frame_add_mtrr(pcf, top_of_ram, 8 * MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030061}