blob: ec036c9d7cd66ba6dd55c4cedbc69f1b33b6d4ee [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älkki2c3fd492016-07-22 22:52:14 +030019#include <arch/cpu.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 <console/console.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030023#include <cpu/intel/romstage.h>
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030024#include <cpu/x86/mtrr.h>
25#include <program_loading.h>
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030026#include <stage_cache.h>
Arthur Heymans97c7c6b2018-05-15 16:45:21 +020027#include <cpu/intel/smm/gen1/smi.h>
Kyösti Mälkki191d2212014-06-15 12:06:12 +030028#include "nehalem.h"
29
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020030static uintptr_t smm_region_start(void)
Kyösti Mälkki191d2212014-06-15 12:06:12 +030031{
32 /* Base of TSEG is top of usable DRAM */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020033 uintptr_t tom = pci_read_config32(PCI_DEV(0,0,0), TSEG);
34 return tom;
35}
36
Arthur Heymans97c7c6b2018-05-15 16:45:21 +020037u32 northbridge_get_tseg_base(void)
38{
Arthur Heymans23fbd052019-05-28 17:38:17 +020039 return (u32)smm_region_start();
Arthur Heymans97c7c6b2018-05-15 16:45:21 +020040}
41
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030042u32 northbridge_get_tseg_size(void)
43{
44 return CONFIG_SMM_TSEG_SIZE;
45}
46
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020047void *cbmem_top(void)
48{
49 return (void *) smm_region_start();
Kyösti Mälkki191d2212014-06-15 12:06:12 +030050}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030051
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030052void stage_cache_external_region(void **base, size_t *size)
53{
54 /* The stage cache lives at the end of TSEG region.
55 * The top of RAM is defined to be the TSEG base address. */
56 *size = CONFIG_SMM_RESERVED_SIZE;
57 *base = (void *)((uintptr_t)northbridge_get_tseg_base() +
58 northbridge_get_tseg_size() - CONFIG_SMM_RESERVED_SIZE);
59}
60
Arthur Heymans02b13fd2018-06-03 12:26:58 +020061/* platform_enter_postcar() determines the stack to use after
62 * cache-as-ram is torn down as well as the MTRR settings to use,
63 * and continues execution in postcar stage. */
64void platform_enter_postcar(void)
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030065{
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030066 struct postcar_frame pcf;
67 uintptr_t top_of_ram;
68
Kyösti Mälkki6e2d0c12019-06-28 10:08:51 +030069 if (postcar_frame_init(&pcf, 0))
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030070 die("Unable to initialize postcar frame.\n");
71
72 /* Cache the ROM as WP just below 4GiB. */
Nico Huber089b9082018-05-27 14:37:32 +020073 postcar_frame_add_romcache(&pcf, MTRR_TYPE_WRPROT);
Kyösti Mälkki2c3fd492016-07-22 22:52:14 +030074
75 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
76 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
77
78 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
79 * above top of the ram. This satisfies MTRR alignment requirement
80 * with different TSEG size configurations.
81 */
82 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
83 postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 8*MiB, MTRR_TYPE_WRBACK);
84 postcar_frame_add_mtrr(&pcf, top_of_ram, 8*MiB, MTRR_TYPE_WRBACK);
85
Arthur Heymans02b13fd2018-06-03 12:26:58 +020086 run_postcar_phase(&pcf);
87
88 /* We do not return here. */
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030089}