blob: 03e8db6cd78c22aabf2d6c5f0a442ed122b64af7 [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
15#define __SIMPLE_DEVICE__
16
Kyösti Mälkkia963acd2019-08-16 20:34:25 +030017#include <arch/romstage.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030019#include <cbmem.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030020#include <cpu/intel/smm_reloc.h>
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030021#include <cpu/x86/mtrr.h>
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030022#include <cpu/x86/smm.h>
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030023#include <program_loading.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030024#include "sandybridge.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 /* Base of TSEG is top of usable DRAM */
Felix Held4902fee2019-12-28 18:09:47 +010029 uintptr_t tom = pci_read_config32(PCI_DEV(0, 0, 0), TSEGMB);
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020030 return tom;
31}
32
Arthur Heymans340e4b82019-10-23 17:25:58 +020033void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020034{
35 return (void *) smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030036}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030037
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030038static uintptr_t northbridge_get_tseg_base(void)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030039{
40 return ALIGN_DOWN(smm_region_start(), 1*MiB);
41}
42
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030043static size_t northbridge_get_tseg_size(void)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030044{
45 return CONFIG_SMM_TSEG_SIZE;
46}
47
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030048void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030049{
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030050 *start = northbridge_get_tseg_base();
51 *size = northbridge_get_tseg_size();
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030052}
53
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030054void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030055{
Kyösti Mälkkib84c8332016-12-01 10:48:43 +020056 uintptr_t top_of_ram;
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030057
Kyösti Mälkkib84c8332016-12-01 10:48:43 +020058 top_of_ram = (uintptr_t)cbmem_top();
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030059 /* Cache 8MiB below the top of ram. On sandybridge systems the top of
Elyes HAOUASef906092020-02-20 19:41:17 +010060 * RAM under 4GiB is the start of the TSEG region. It is required to
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030061 * be 8MiB aligned. Set this area as cacheable so it can be used later
62 * for ramstage before setting up the entire RAM as cacheable. */
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030063 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030064
Elyes HAOUASef906092020-02-20 19:41:17 +010065 /* Cache 8MiB at the top of ram. Top of RAM on sandybridge systems
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030066 * is where the TSEG region resides. However, it is not restricted
67 * to SMM mode until SMM has been relocated. By setting the region
68 * to cacheable it provides faster access when relocating the SMM
69 * handler as well as using the TSEG region for other purposes. */
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030070 postcar_frame_add_mtrr(pcf, top_of_ram, 8*MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030071}