blob: 14b66a0fc7aa16da030924ceeb048c4c1bb29291 [file] [log] [blame]
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030014 */
15
16// Use simple device model for this file even in ramstage
17#define __SIMPLE_DEVICE__
18
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030019#include <arch/cpu.h>
20#include <console/console.h>
21#include <cpu/x86/mtrr.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>
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030024#include <cpu/intel/romstage.h>
Kyösti Mälkki825646e2019-08-02 06:14:50 +030025#include <stage_cache.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030026#include "haswell.h"
27
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020028static uintptr_t smm_region_start(void)
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030029{
30 /*
31 * Base of TSEG is top of usable DRAM below 4GiB. The register has
Martin Roth128c1042016-11-18 09:29:03 -070032 * 1 MiB alignment.
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030033 */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020034 uintptr_t tom = pci_read_config32(PCI_DEV(0,0,0), TSEG);
35 return tom & ~((1 << 20) - 1);
36}
37
38void *cbmem_top(void)
39{
40 return (void *)smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030041}
Kyösti Mälkki825646e2019-08-02 06:14:50 +030042
43/* Region of SMM space is reserved for multipurpose use. It falls below
44 * the IED region and above the SMM handler. */
45#define RESERVED_SMM_OFFSET \
46 (CONFIG_SMM_TSEG_SIZE - CONFIG_IED_REGION_SIZE - CONFIG_SMM_RESERVED_SIZE)
47
48void stage_cache_external_region(void **base, size_t *size)
49{
50 /* The ramstage cache lives in the TSEG region at RESERVED_SMM_OFFSET.
51 * The top of RAM is defined to be the TSEG base address. */
52 *size = CONFIG_SMM_RESERVED_SIZE;
53 *base = (void *)((uint32_t)cbmem_top() + RESERVED_SMM_OFFSET);
54}
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030055
56/* platform_enter_postcar() determines the stack to use after
57 * cache-as-ram is torn down as well as the MTRR settings to use,
58 * and continues execution in postcar stage. */
59void platform_enter_postcar(void)
60{
61 struct postcar_frame pcf;
62 uintptr_t top_of_ram;
63
64 if (postcar_frame_init(&pcf, 0))
65 die("Unable to initialize postcar frame.\n");
66 /* Cache the ROM as WP just below 4GiB. */
67 postcar_frame_add_romcache(&pcf, MTRR_TYPE_WRPROT);
68
69 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
70 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
71
72 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
73 * above top of the ram. This satisfies MTRR alignment requirement
74 * with different TSEG size configurations.
75 */
76 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
77 postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 16*MiB,
78 MTRR_TYPE_WRBACK);
79
80 run_postcar_phase(&pcf);
81}