blob: b2d61fe93ada134c5cfd97f4b1e27999ac927a34 [file] [log] [blame]
Kyösti Mälkki191d2212014-06-15 12:06:12 +03001/*
2 * This file is part of the coreboot project.
3 *
Patrick Georgi5b2a2d02018-09-26 20:46:04 +02004 * Copyright (C) 2012 Google LLC
Kyösti Mälkki191d2212014-06-15 12:06:12 +03005 * Copyright (C) 2013 Vladimir Serbinenko.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Kyösti Mälkki191d2212014-06-15 12:06:12 +030015 */
16
17#define __SIMPLE_DEVICE__
18
Kyösti Mälkkia963acd2019-08-16 20:34:25 +030019#include <arch/romstage.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Kyösti Mälkki191d2212014-06-15 12:06:12 +030021#include <cbmem.h>
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030022#include <cpu/x86/mtrr.h>
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030023#include <cpu/x86/smm.h>
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030024#include <program_loading.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030025#include <cpu/intel/smm_reloc.h>
Angel Pons95de2312020-02-17 13:08:53 +010026#include "ironlake.h"
Kyösti Mälkki191d2212014-06-15 12:06:12 +030027
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020028static uintptr_t smm_region_start(void)
Kyösti Mälkki191d2212014-06-15 12:06:12 +030029{
30 /* Base of TSEG is top of usable DRAM */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020031 uintptr_t tom = pci_read_config32(PCI_DEV(0,0,0), TSEG);
32 return tom;
33}
34
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030035static uintptr_t northbridge_get_tseg_base(void)
Arthur Heymans97c7c6b2018-05-15 16:45:21 +020036{
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030037 return smm_region_start();
Arthur Heymans97c7c6b2018-05-15 16:45:21 +020038}
39
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030040static size_t northbridge_get_tseg_size(void)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030041{
42 return CONFIG_SMM_TSEG_SIZE;
43}
44
Arthur Heymans340e4b82019-10-23 17:25:58 +020045void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020046{
47 return (void *) smm_region_start();
Kyösti Mälkki191d2212014-06-15 12:06:12 +030048}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030049
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030050void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030051{
Kyösti Mälkkid53fd702019-08-14 06:25:55 +030052 *start = northbridge_get_tseg_base();
53 *size = northbridge_get_tseg_size();
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030054}
55
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030056void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030057{
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030058 uintptr_t top_of_ram;
59
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030060 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
61 * above top of the ram. This satisfies MTRR alignment requirement
62 * with different TSEG size configurations.
63 */
64 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030065 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB, MTRR_TYPE_WRBACK);
66 postcar_frame_add_mtrr(pcf, top_of_ram, 8*MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030067}