blob: 04ab735f4620fbefd96b77b44f676275307c2a97 [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +01002
3#include <arch/romstage.h>
4#include <cbmem.h>
Elyes Haouas8ed58352022-10-22 22:17:28 +02005#include <commonlib/bsd/helpers.h>
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +01006#include <console/console.h>
7#include <cpu/x86/mtrr.h>
8#include <cpu/x86/smm.h>
Subrata Banik30a01142023-03-22 00:35:42 +05309#include <intelbasecode/ramtop.h>
Srinidhi N Kaushik4eb489f2020-11-25 02:21:57 -080010#include <intelblocks/fast_spi.h>
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010011#include <intelblocks/systemagent.h>
Angel Pons3dea2b62020-10-01 22:50:12 +020012#include <types.h>
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010013
Michael Niewöhnere75a64f2019-10-19 15:17:06 +020014/*
15 * Expected Host Memory Map (we don't know 100% and not all regions are present on all SoCs):
16 *
17 * +---------------------------+ TOUUD
18 * | |
19 * +---------------------------+ TOM (if mem > 4GB)
20 * | CSME UMA (if mem > 4 GiB) |
21 * +---------------------------+ TOUUD
22 * | |
23 * +---------------------------+ 4GiB
24 * | PCI Address Space |
25 * +---------------------------+ TOM (if mem < 4GB)
26 * | CSME UMA (if mem < 4 GiB) |
27 * +---------------------------+ TOLUD (also maps into MC address space)
28 * | iGD / DSM |
29 * +---------------------------+ BDSM
30 * | GTT / GSM |
31 * +---------------------------+ TOLM
32 * | TSEG |
33 * +---------------------------+ TSEGMB
34 * | DMA Protected Region |
35 * +---------------------------+ DPR
36 * | PRM (C6DRAM/SGX) |
37 * +---------------------------+ PRMRR
38 * | Probeless Trace |
39 * +---------------------------+ ME Stolen
40 * | PTT |
41 * +---------------------------+ TOLUM / top_of_ram / cbmem_top
42 * | CBMEM Root |
43 * +---------------------------+
44 * | FSP Reserved Memory |
45 * +---------------------------+
46 * | various CBMEM entries |
47 * +---------------------------+ top_of_stack (8 byte aligned)
48 * | stack (CBMEM entry) |
49 * +---------------------------+ FSP TOLUM
50 * | |
51 * +---------------------------+ 0
52 */
53
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010054void smm_region(uintptr_t *start, size_t *size)
55{
56 *start = sa_get_tseg_base();
57 *size = sa_get_tseg_size();
58}
59
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010060void fill_postcar_frame(struct postcar_frame *pcf)
61{
Angel Pons3dea2b62020-10-01 22:50:12 +020062 /* FSP does not seem to bother w.r.t. alignment when asked to place cbmem_top() */
63 uintptr_t top_of_ram = ALIGN_UP((uintptr_t)cbmem_top(), 8 * MiB);
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010064
65 /*
66 * We need to make sure ramstage will be run cached. At this
67 * point exact location of ramstage in cbmem is not known.
Angel Pons3dea2b62020-10-01 22:50:12 +020068 * Instruct postcar to cache 16 megs below cbmem top which is
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010069 * a safe bet to cover ramstage.
70 */
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010071 printk(BIOS_DEBUG, "top_of_ram = 0x%lx\n", top_of_ram);
Angel Pons3dea2b62020-10-01 22:50:12 +020072
Subrata Banik725dd392023-02-24 20:10:00 +000073 /*
Subrata Banik30a01142023-03-22 00:35:42 +053074 * Store the top_of_ram (ramtop) into the CMOS if SOC_INTEL_COMMON_BASECODE_RAMTOP
Subrata Banik725dd392023-02-24 20:10:00 +000075 * config is enabled.
76 */
Arthur Heymansa2bc2542021-05-29 08:10:49 +020077 if (ENV_CREATES_CBMEM && CONFIG(SOC_INTEL_COMMON_BASECODE_RAMTOP))
Subrata Banik30a01142023-03-22 00:35:42 +053078 update_ramtop(top_of_ram);
Subrata Banik725dd392023-02-24 20:10:00 +000079
Angel Pons3dea2b62020-10-01 22:50:12 +020080 postcar_frame_add_mtrr(pcf, top_of_ram - 16 * MiB, 16 * MiB, MTRR_TYPE_WRBACK);
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010081
82 /* Cache the TSEG region */
83 postcar_enable_tseg_cache(pcf);
Srinidhi N Kaushik4eb489f2020-11-25 02:21:57 -080084
85 /* Cache the extended BIOS region if it is supported */
86 fast_spi_cache_ext_bios_postcar(pcf);
Michael Niewöhnere0ad1fa2019-10-28 18:55:14 +010087}