blob: fafe8384b45833a153583ccb19a88a13043147dd [file] [log] [blame]
Aaron Durbine6af4be2015-09-24 12:26:31 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 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.
Aaron Durbine6af4be2015-09-24 12:26:31 -050014 */
15
Kyösti Mälkkia963acd2019-08-16 20:34:25 +030016#include <arch/romstage.h>
Arthur Heymans8a1b94c2019-05-25 09:47:01 +020017#include <arch/symbols.h>
Kyösti Mälkki8f23b5d2019-06-30 21:00:07 +030018#include <cbmem.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050019#include <console/console.h>
Elyes HAOUAS2195f7a2019-06-21 07:20:12 +020020#include <commonlib/helpers.h>
Arthur Heymans56e2d7d2019-05-23 15:07:49 +020021#include <cpu/intel/romstage.h>
Nico Huberd67edca2018-11-13 19:28:07 +010022#include <cpu/x86/mtrr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030023#include <cpu/x86/smm.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050024#include <fsp/car.h>
Aaron Durbin909c5122015-09-29 17:41:30 -050025#include <fsp/util.h>
Aaron Durbin6d720f32015-12-08 17:00:23 -060026#include <program_loading.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050027
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030028void fill_postcar_frame(struct postcar_frame *pcf)
Aaron Durbin909c5122015-09-29 17:41:30 -050029{
Kyösti Mälkki8f23b5d2019-06-30 21:00:07 +030030 uintptr_t top_of_ram;
Arthur Heymansbe291e82019-01-06 07:35:11 +010031
Kyösti Mälkki8f23b5d2019-06-30 21:00:07 +030032 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
33 * above top of the ram. This satisfies MTRR alignment requirement
34 * with different TSEG size configurations. */
35 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030036 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 16*MiB, MTRR_TYPE_WRBACK);
Arthur Heymansbe291e82019-01-06 07:35:11 +010037
Aaron Durbin909c5122015-09-29 17:41:30 -050038}
39
Arthur Heymans59b65422019-05-23 15:24:30 +020040/* This is the romstage entry called from cpu/intel/car/romstage.c */
Kyösti Mälkki157b1892019-08-16 14:02:25 +030041void mainboard_romstage_entry(void)
Aaron Durbin909c5122015-09-29 17:41:30 -050042{
43 /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram
44 * is still enabled. We can directly access work buffer here. */
Aaron Durbin7e7a4df2015-12-08 14:34:35 -060045 struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin");
Aaron Durbin909c5122015-09-29 17:41:30 -050046
Jacob Garberf7f90f72019-05-28 15:37:37 -060047 if (prog_locate(&fsp))
48 die_with_post_code(POST_INVALID_CBFS, "Unable to locate fsp.bin");
49
50 /* This leaks a mapping which this code assumes is benign as
51 * the flash is memory mapped CPU's address space. */
52 FSP_INFO_HEADER *fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp)));
Aaron Durbin909c5122015-09-29 17:41:30 -050053
John Zhaod3a73282019-05-31 09:58:49 -070054 if (!fih)
55 die("Invalid FSP header\n");
56
Arthur Heymansbe291e82019-01-06 07:35:11 +010057 cache_as_ram_stage_main(fih);
Aaron Durbine6af4be2015-09-24 12:26:31 -050058}