blob: 991a3e6f0181af340e7912147cbbe148163c5f71 [file] [log] [blame]
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
16 */
17
18#include <console/console.h>
19#include <cbmem.h>
20
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030021unsigned long __attribute__((weak)) get_top_of_ram(void)
22{
23 printk(BIOS_WARNING, "WARNING: you need to define get_top_of_ram() for your chipset\n");
24 return 0;
25}
26
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030027#if !CONFIG_DYNAMIC_CBMEM
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030028void get_cbmem_table(uint64_t *base, uint64_t *size)
29{
30 uint64_t top_of_ram = get_top_of_ram();
31
32 if (top_of_ram >= HIGH_MEMORY_SIZE) {
33 *base = top_of_ram - HIGH_MEMORY_SIZE;
34 *size = HIGH_MEMORY_SIZE;
35 } else {
36 *base = 0;
37 *size = 0;
38 }
39}
40#endif
41
42#if !CONFIG_DYNAMIC_CBMEM && !defined(__PRE_RAM__)
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030043void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop)
44{
45 /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */
46}
47
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030048/* This is for compatibility with old boards only. Any new chipset and board
49 * must implement get_top_of_ram() for both romstage and ramstage to support
50 * features like CAR_MIGRATION and CBMEM_CONSOLE.
51 */
Kyösti Mälkki2b790f62013-09-03 05:25:57 +030052void set_top_of_ram(uint64_t ramtop)
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030053{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030054 backup_top_of_ram(ramtop);
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +030055 cbmem_late_set_table(ramtop - HIGH_MEMORY_SIZE, HIGH_MEMORY_SIZE);
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030056}
57#endif