blob: bd3f4787a0d194495bcc4e9b124029f02bb790b7 [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
Arthur Heymans8a1b94c2019-05-25 09:47:01 +020016#include <arch/symbols.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050017#include <console/console.h>
Elyes HAOUAS2195f7a2019-06-21 07:20:12 +020018#include <commonlib/helpers.h>
Arthur Heymans56e2d7d2019-05-23 15:07:49 +020019#include <cpu/intel/romstage.h>
Nico Huberd67edca2018-11-13 19:28:07 +010020#include <cpu/x86/mtrr.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050021#include <fsp/car.h>
Aaron Durbin909c5122015-09-29 17:41:30 -050022#include <fsp/util.h>
Arthur Heymansbe291e82019-01-06 07:35:11 +010023#include <fsp/memmap.h>
Aaron Durbin6d720f32015-12-08 17:00:23 -060024#include <program_loading.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050025#include <timestamp.h>
26
Arthur Heymansbe291e82019-01-06 07:35:11 +010027#define ROMSTAGE_RAM_STACK_SIZE 0x5000
Aaron Durbin909c5122015-09-29 17:41:30 -050028
Arthur Heymansbe291e82019-01-06 07:35:11 +010029/* platform_enter_postcar() determines the stack to use after
30 * cache-as-ram is torn down as well as the MTRR settings to use,
31 * and continues execution in postcar stage. */
Arthur Heymans56e2d7d2019-05-23 15:07:49 +020032void platform_enter_postcar(void)
Aaron Durbin909c5122015-09-29 17:41:30 -050033{
Arthur Heymansbe291e82019-01-06 07:35:11 +010034 struct postcar_frame pcf;
35 size_t alignment;
36 uint32_t aligned_ram;
37
38 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
39 die("Unable to initialize postcar frame.\n");
40 /* Cache the ROM as WP just below 4GiB. */
41 postcar_frame_add_mtrr(&pcf, CACHE_ROM_BASE, CACHE_ROM_SIZE,
42 MTRR_TYPE_WRPROT);
43
44 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
45 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
46
47 /*
48 * +-------------------------+ Top of RAM (aligned)
49 * | System Management Mode |
50 * | code and data | Length: CONFIG_TSEG_SIZE
51 * | (TSEG) |
52 * +-------------------------+ SMM base (aligned)
53 * | |
54 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
55 * | |
56 * +-------------------------+ top_of_ram (aligned)
57 * | |
58 * | CBMEM Root |
59 * | |
60 * +-------------------------+
61 * | |
62 * | FSP Reserved Memory |
63 * | |
64 * +-------------------------+
65 * | |
66 * | Various CBMEM Entries |
67 * | |
68 * +-------------------------+ top_of_stack (8 byte aligned)
69 * | |
70 * | stack (CBMEM Entry) |
71 * | |
72 * +-------------------------+
73 */
74
75 alignment = mmap_region_granularity();
76 aligned_ram = ALIGN_DOWN(romstage_ram_stack_bottom(), alignment);
77 postcar_frame_add_mtrr(&pcf, aligned_ram, alignment, MTRR_TYPE_WRBACK);
78
79 if (CONFIG(HAVE_SMI_HANDLER)) {
80 void *smm_base;
81 size_t smm_size;
82
83 /*
84 * Cache the TSEG region at the top of ram. This region is not
85 * restricted to SMM mode until SMM has been relocated. By
86 * setting the region to cacheable it provides faster access
87 * when relocating the SMM handler as well as using the TSEG
88 * region for other purposes.
89 */
90 smm_region(&smm_base, &smm_size);
91 postcar_frame_add_mtrr(&pcf, (uintptr_t)smm_base, alignment,
92 MTRR_TYPE_WRBACK);
93 }
94
95 run_postcar_phase(&pcf);
Aaron Durbin909c5122015-09-29 17:41:30 -050096}
97
Arthur Heymans59b65422019-05-23 15:24:30 +020098/* This is the romstage entry called from cpu/intel/car/romstage.c */
Arthur Heymans56e2d7d2019-05-23 15:07:49 +020099void mainboard_romstage_entry(unsigned long bist)
Aaron Durbin909c5122015-09-29 17:41:30 -0500100{
101 /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram
102 * is still enabled. We can directly access work buffer here. */
Aaron Durbin7e7a4df2015-12-08 14:34:35 -0600103 struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin");
Aaron Durbin909c5122015-09-29 17:41:30 -0500104
Jacob Garberf7f90f72019-05-28 15:37:37 -0600105 if (prog_locate(&fsp))
106 die_with_post_code(POST_INVALID_CBFS, "Unable to locate fsp.bin");
107
108 /* This leaks a mapping which this code assumes is benign as
109 * the flash is memory mapped CPU's address space. */
110 FSP_INFO_HEADER *fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp)));
Aaron Durbin909c5122015-09-29 17:41:30 -0500111
John Zhaod3a73282019-05-31 09:58:49 -0700112 if (!fih)
113 die("Invalid FSP header\n");
114
Arthur Heymansbe291e82019-01-06 07:35:11 +0100115 cache_as_ram_stage_main(fih);
Aaron Durbine6af4be2015-09-24 12:26:31 -0500116}