blob: 9e2e3333fe65d37a2782fd82f98012af50173252 [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#define __SIMPLE_DEVICE__
17
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030018#include <arch/cpu.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030020#include <cbmem.h>
Kyösti Mälkkib84c8332016-12-01 10:48:43 +020021#include <console/console.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030022#include <cpu/intel/romstage.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030023#include <cpu/intel/smm_reloc.h>
Kyösti Mälkkibfca6702016-07-22 22:48:35 +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>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030027#include "sandybridge.h"
28
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020029static uintptr_t smm_region_start(void)
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030030{
31 /* Base of TSEG is top of usable DRAM */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020032 uintptr_t tom = pci_read_config32(PCI_DEV(0,0,0), TSEG);
33 return tom;
34}
35
36void *cbmem_top(void)
37{
38 return (void *) smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030039}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030040
Kyösti Mälkkif6c20682019-08-02 06:14:50 +030041u32 northbridge_get_tseg_base(void)
42{
43 return ALIGN_DOWN(smm_region_start(), 1*MiB);
44}
45
46u32 northbridge_get_tseg_size(void)
47{
48 return CONFIG_SMM_TSEG_SIZE;
49}
50
51void stage_cache_external_region(void **base, size_t *size)
52{
53 /* The stage cache lives at the end of TSEG region.
54 * The top of RAM is defined to be the TSEG base address. */
55 *size = CONFIG_SMM_RESERVED_SIZE;
56 *base = (void *)((uintptr_t)northbridge_get_tseg_base() + northbridge_get_tseg_size()
57 - CONFIG_IED_REGION_SIZE - CONFIG_SMM_RESERVED_SIZE);
58}
59
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030060void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030061{
Kyösti Mälkkib84c8332016-12-01 10:48:43 +020062 uintptr_t top_of_ram;
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030063
Kyösti Mälkkib84c8332016-12-01 10:48:43 +020064 top_of_ram = (uintptr_t)cbmem_top();
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030065 /* Cache 8MiB below the top of ram. On sandybridge systems the top of
66 * ram under 4GiB is the start of the TSEG region. It is required to
67 * be 8MiB aligned. Set this area as cacheable so it can be used later
68 * for ramstage before setting up the entire RAM as cacheable. */
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030069 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkibfca6702016-07-22 22:48:35 +030070
71 /* Cache 8MiB at the top of ram. Top of ram on sandybridge systems
72 * is where the TSEG region resides. However, it is not restricted
73 * to SMM mode until SMM has been relocated. By setting the region
74 * to cacheable it provides faster access when relocating the SMM
75 * handler as well as using the TSEG region for other purposes. */
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030076 postcar_frame_add_mtrr(pcf, top_of_ram, 8*MiB, MTRR_TYPE_WRBACK);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030077}