blob: d9f6160dfcf71ce16bb51372e5a753a851da90d9 [file] [log] [blame]
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 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,
Aaron Durbin2c4aab32015-03-06 23:26:06 -060011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050014 */
15
Kyösti Mälkki81100bf2019-08-16 10:37:15 +030016#include <arch/romstage.h>
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050017#include <cbmem.h>
Kyösti Mälkki81100bf2019-08-16 10:37:15 +030018#include <cpu/x86/mtrr.h>
Kyösti Mälkki568a42a2019-08-14 06:48:28 +030019#include <cpu/x86/smm.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070020#include <soc/iosf.h>
Aaron Durbin7837be62013-10-21 22:32:00 -050021
Kyösti Mälkki568a42a2019-08-14 06:48:28 +030022static uintptr_t smm_region_start(void)
Aaron Durbin7837be62013-10-21 22:32:00 -050023{
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020024 return (iosf_bunit_read(BUNIT_SMRRL) << 20);
Aaron Durbin7837be62013-10-21 22:32:00 -050025}
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050026
Kyösti Mälkki568a42a2019-08-14 06:48:28 +030027static size_t smm_region_size(void)
28{
29 return CONFIG_SMM_TSEG_SIZE;
30}
31
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020032void *cbmem_top(void)
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050033{
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020034 return (void *) smm_region_start();
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050035}
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030036
Kyösti Mälkki568a42a2019-08-14 06:48:28 +030037void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030038{
Kyösti Mälkki568a42a2019-08-14 06:48:28 +030039 *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20;
40 *size = smm_region_size();
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030041}
Kyösti Mälkki81100bf2019-08-16 10:37:15 +030042
43void fill_postcar_frame(struct postcar_frame *pcf)
44{
45 uintptr_t top_of_ram;
46
47 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
48 * above top of the ram. This satisfies MTRR alignment requirement
49 * with different TSEG size configurations.
50 */
51 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
52 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 16*MiB,
53 MTRR_TYPE_WRBACK);
54}