blob: 14d569b5bb33c053e161b129796ecff11e5af4e6 [file] [log] [blame]
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03001/*
2 * This file is part of the coreboot project.
3 *
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030013 */
14
Angel Pons1db5bc72020-01-15 00:49:03 +010015/* Use simple device model for this file even in ramstage */
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030016#define __SIMPLE_DEVICE__
17
Kyösti Mälkkia963acd2019-08-16 20:34:25 +030018#include <arch/romstage.h>
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +030019#include <commonlib/helpers.h>
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030020#include <cpu/x86/mtrr.h>
Kyösti Mälkki540151f2019-08-15 11:20:18 +030021#include <cpu/x86/smm.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030023#include <cbmem.h>
24#include "haswell.h"
25
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020026static uintptr_t smm_region_start(void)
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030027{
28 /*
29 * Base of TSEG is top of usable DRAM below 4GiB. The register has
Martin Roth128c1042016-11-18 09:29:03 -070030 * 1 MiB alignment.
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030031 */
Angel Pons1db5bc72020-01-15 00:49:03 +010032 uintptr_t tom = pci_read_config32(HOST_BRIDGE, TSEG);
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020033 return tom & ~((1 << 20) - 1);
34}
35
Arthur Heymans340e4b82019-10-23 17:25:58 +020036void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020037{
38 return (void *)smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030039}
Kyösti Mälkki825646e2019-08-02 06:14:50 +030040
Kyösti Mälkki540151f2019-08-15 11:20:18 +030041void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki825646e2019-08-02 06:14:50 +030042{
Kyösti Mälkki540151f2019-08-15 11:20:18 +030043 *start = smm_region_start();
44 *size = CONFIG_SMM_TSEG_SIZE;
Kyösti Mälkki825646e2019-08-02 06:14:50 +030045}
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030046
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030047void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030048{
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030049 uintptr_t top_of_ram;
50
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030051 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
52 * above top of the ram. This satisfies MTRR alignment requirement
53 * with different TSEG size configurations.
54 */
Angel Pons1db5bc72020-01-15 00:49:03 +010055 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8 * MiB);
56 postcar_frame_add_mtrr(pcf, top_of_ram - 8 * MiB, 16 * MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030057}