blob: d1d784d73ba8452a6b98d5c898fc8b68001a45c1 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google, Inc.
Lee Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
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,
Lee Leahy32471722015-04-20 15:20:28 -070012 * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgi25509ee2015-03-26 15:17:45 +010018 * Foundation, Inc.
Lee Leahy77ff0b12015-05-05 15:07:29 -070019 */
20
21#include <arch/io.h>
22#include <cbmem.h>
Lee Leahy32471722015-04-20 15:20:28 -070023#include <console/console.h>
24#include <soc/intel/common/memmap.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070025#include <soc/iosf.h>
26#include <soc/smm.h>
27
Lee Leahy32471722015-04-20 15:20:28 -070028static size_t smm_region_size(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070029{
Lee Leahy32471722015-04-20 15:20:28 -070030 u32 smm_size;
31 smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF;
32 smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF;
33 smm_size = (smm_size + 1) << 20;
34 return smm_size;
35}
36
37void smm_region(void **start, size_t *size)
38{
39 *start = (void *)((iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20);
40 *size = smm_region_size();
41}
42
43size_t mmap_region_granluarity(void)
44{
45 /* Align to TSEG size when SMM is in use, and 8MiB by default */
46 return IS_ENABLED(CONFIG_HAVE_SMI_HANDLER) ? smm_region_size()
47 : 8 << 20;
Lee Leahy77ff0b12015-05-05 15:07:29 -070048}
49
50void *cbmem_top(void)
51{
Lee Leahy32471722015-04-20 15:20:28 -070052 char *smm_base;
53 size_t smm_size;
54
55 /*
56 * +-------------------------+ Top of RAM (aligned)
57 * | System Management Mode |
58 * | code and data | Length: CONFIG_TSEG_SIZE
59 * | (TSEG) |
60 * +-------------------------+ SMM base (aligned)
61 * | |
62 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
63 * | |
64 * +-------------------------+ top_of_ram (aligned)
65 * | |
66 * | CBMEM Root |
67 * | |
68 * +-------------------------+
69 * | |
70 * | FSP Reserved Memory |
71 * | |
72 * +-------------------------+
73 * | |
74 * | Various CBMEM Entries |
75 * | |
76 * +-------------------------+ top_of_stack (8 byte aligned)
77 * | |
78 * | stack (CBMEM Entry) |
79 * | |
80 * +-------------------------+
81 */
82
83 smm_region((void **)&smm_base, &smm_size);
Aaron Durbinbbbfbf22015-07-13 16:55:28 -050084 return (void *)smm_base;
Lee Leahy77ff0b12015-05-05 15:07:29 -070085}