blob: b1eb770f90e6b99c22b9d669746c7055386c99c7 [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älkkia963acd2019-08-16 20:34:25 +030019#include <arch/romstage.h>
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030020#include <console/console.h>
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +030021#include <commonlib/helpers.h>
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030022#include <cpu/x86/mtrr.h>
Kyösti Mälkki540151f2019-08-15 11:20:18 +030023#include <cpu/x86/smm.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020024#include <device/pci_ops.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030025#include <cbmem.h>
26#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
Kyösti Mälkki540151f2019-08-15 11:20:18 +030043void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki825646e2019-08-02 06:14:50 +030044{
Kyösti Mälkki540151f2019-08-15 11:20:18 +030045 *start = smm_region_start();
46 *size = CONFIG_SMM_TSEG_SIZE;
Kyösti Mälkki825646e2019-08-02 06:14:50 +030047}
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030048
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030049void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030050{
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030051 uintptr_t top_of_ram;
52
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030053 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
54 * above top of the ram. This satisfies MTRR alignment requirement
55 * with different TSEG size configurations.
56 */
57 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030058 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 16*MiB,
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030059 MTRR_TYPE_WRBACK);
Kyösti Mälkkie2e1f122019-08-09 09:34:23 +030060}