blob: fd7576c969c98fc4fdeffd5fdefdd8d7947acf42 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03003
Angel Pons1db5bc72020-01-15 00:49:03 +01004/* Use simple device model for this file even in ramstage */
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03005#define __SIMPLE_DEVICE__
6
Kyösti Mälkkia963acd2019-08-16 20:34:25 +03007#include <arch/romstage.h>
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +03008#include <commonlib/helpers.h>
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +03009#include <cpu/x86/mtrr.h>
Kyösti Mälkki540151f2019-08-15 11:20:18 +030010#include <cpu/x86/smm.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030012#include <cbmem.h>
13#include "haswell.h"
14
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020015static uintptr_t smm_region_start(void)
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030016{
17 /*
18 * Base of TSEG is top of usable DRAM below 4GiB. The register has
Martin Roth128c1042016-11-18 09:29:03 -070019 * 1 MiB alignment.
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030020 */
Angel Pons1db5bc72020-01-15 00:49:03 +010021 uintptr_t tom = pci_read_config32(HOST_BRIDGE, TSEG);
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020022 return tom & ~((1 << 20) - 1);
23}
24
Arthur Heymans340e4b82019-10-23 17:25:58 +020025void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020026{
27 return (void *)smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030028}
Kyösti Mälkki825646e2019-08-02 06:14:50 +030029
Kyösti Mälkki540151f2019-08-15 11:20:18 +030030void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki825646e2019-08-02 06:14:50 +030031{
Kyösti Mälkki540151f2019-08-15 11:20:18 +030032 *start = smm_region_start();
33 *size = CONFIG_SMM_TSEG_SIZE;
Kyösti Mälkki825646e2019-08-02 06:14:50 +030034}
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030035
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030036void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030037{
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030038 uintptr_t top_of_ram;
39
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030040 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
41 * above top of the ram. This satisfies MTRR alignment requirement
42 * with different TSEG size configurations.
43 */
Angel Pons1db5bc72020-01-15 00:49:03 +010044 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8 * MiB);
45 postcar_frame_add_mtrr(pcf, top_of_ram - 8 * MiB, 16 * MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030046}