mb/starlabs/{lite_adl,byte_adl}: Don't select MAINBOARD_HAS_TPM2
[coreboot2.git] / src / soc / intel / apollolake / mmap_boot.c
blob6e0800cd653c25b52654b74bc0686900bd356e82
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <boot_device.h>
4 #include <commonlib/region.h>
5 #include <console/console.h>
6 #include <fmap.h>
7 #include <intelblocks/fast_spi.h>
8 #include <spi_flash.h>
11 * BIOS region on the flash is mapped right below 4GiB in the address
12 * space. However, 256KiB right below 4GiB is decoded by read-only SRAM and not
13 * boot media.
15 * +-----------+ 0
16 * | |
17 * | |
18 * | |
19 * | |
20 * | |
21 * | |
22 * | |
23 * | |
24 * +--------+ | |
25 * | IFD | | |
26 * bios_start +---> +--------+------------------> +-----------+ 4GiB - bios_size
27 * ^ | | ^ | |
28 * | | | | | |
29 * | | | bios_mapped_size | BIOS |
30 * | | BIOS | | | |
31 * bios_size | | | | |
32 * | | | v | |
33 * | | +------------------> +-----------+ 4GiB - 256KiB
34 * | | | | Read only |
35 * v | | | SRAM |
36 * bios_end +---> +--------+ +-----------+ 4GiB
37 * | Device |
38 * | ext |
39 * +--------+
43 static size_t bios_size;
45 static struct region_device shadow_dev;
46 static struct xlate_region_device real_dev;
47 static struct xlate_window real_dev_window;
49 static void bios_mmap_init(void)
51 size_t size, start, bios_mapped_size;
52 uintptr_t base;
54 size = bios_size;
56 /* If bios_size is initialized, then bail out. */
57 if (size != 0)
58 return;
59 start = fast_spi_get_bios_region(&size);
61 /* BIOS region is mapped right below 4G. */
62 base = 4ULL * GiB - size;
65 * The 256 KiB right below 4G are decoded by readonly SRAM,
66 * not boot media.
68 bios_mapped_size = size - 256 * KiB;
70 rdev_chain_mem(&shadow_dev, (void *)base, bios_mapped_size);
72 xlate_window_init(&real_dev_window, &shadow_dev, start, bios_mapped_size);
73 xlate_region_device_ro_init(&real_dev, 1, &real_dev_window, CONFIG_ROM_SIZE);
75 bios_size = size;
77 /* Check that the CBFS lies within the memory mapped area. It's too
78 easy to forget the SRAM mapping when crafting an FMAP file. */
79 struct region cbfs_region;
80 if (!fmap_locate_area("COREBOOT", &cbfs_region) &&
81 !region_is_subregion(&real_dev_window.sub_region, &cbfs_region))
82 printk(BIOS_CRIT,
83 "ERROR: CBFS @ %zx size %zx exceeds mem-mapped area @ %zx size %zx\n",
84 region_offset(&cbfs_region), region_sz(&cbfs_region),
85 start, bios_mapped_size);
88 const struct region_device *boot_device_ro(void)
90 bios_mmap_init();
92 return &real_dev.rdev;
95 uint32_t spi_flash_get_mmap_windows(struct flash_mmap_window *table)
97 bios_mmap_init();
99 table->flash_base = region_offset(&real_dev_window.sub_region);
100 table->host_base = (uintptr_t)rdev_mmap_full(&shadow_dev);
101 table->size = region_sz(&real_dev_window.sub_region);
103 return 1;