coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mmap_boot.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
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>
9 
10 /*
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.
14  *
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  * +--------+
40  *
41  */
42 
43 static size_t bios_size;
44 
45 static struct region_device shadow_dev;
46 static struct xlate_region_device real_dev;
47 static struct xlate_window real_dev_window;
48 
49 static void bios_mmap_init(void)
50 {
51  size_t size, start, bios_mapped_size;
53 
54  size = bios_size;
55 
56  /* If bios_size is initialized, then bail out. */
57  if (size != 0)
58  return;
59  start = fast_spi_get_bios_region(&size);
60 
61  /* BIOS region is mapped right below 4G. */
62  base = 4ULL * GiB - size;
63 
64  /*
65  * The 256 KiB right below 4G are decoded by readonly SRAM,
66  * not boot media.
67  */
68  bios_mapped_size = size - 256 * KiB;
69 
70  rdev_chain_mem(&shadow_dev, (void *)base, bios_mapped_size);
71 
72  xlate_window_init(&real_dev_window, &shadow_dev, start, bios_mapped_size);
74 
75  bios_size = size;
76 
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) &&
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);
86 }
87 
88 const struct region_device *boot_device_ro(void)
89 {
91 
92  return &real_dev.rdev;
93 }
94 
96 {
98 
102 
103  return 1;
104 }
uint32_t spi_flash_get_mmap_windows(struct flash_mmap_window *table)
Definition: mmap_boot.c:18
const struct region_device * boot_device_ro(void)
Definition: mmap_boot.c:13
#define KiB
Definition: helpers.h:75
#define GiB
Definition: helpers.h:77
#define printk(level,...)
Definition: stdlib.h:16
size_t fast_spi_get_bios_region(size_t *bios_size)
Definition: fast_spi.c:232
int fmap_locate_area(const char *name, struct region *r)
Definition: fmap.c:164
#define BIOS_CRIT
BIOS_CRIT - Recovery unlikely.
Definition: loglevel.h:56
static size_t region_sz(const struct region *r)
Definition: region.h:110
int region_is_subregion(const struct region *p, const struct region *c)
Definition: region.c:7
int rdev_chain_mem(struct region_device *child, const void *base, size_t size)
Definition: region.c:293
void xlate_window_init(struct xlate_window *window, const struct region_device *access_dev, size_t sub_region_offset, size_t sub_region_size)
Definition: region.c:216
static void * rdev_mmap_full(const struct region_device *rd)
Definition: region.h:148
void xlate_region_device_ro_init(struct xlate_region_device *xdev, size_t window_count, const struct xlate_window *window_arr, size_t parent_size)
Definition: region.c:200
static size_t region_offset(const struct region *r)
Definition: region.h:105
uintptr_t base
Definition: uart.c:17
static struct region_device shadow_dev
Definition: mmap_boot.c:45
static struct xlate_region_device real_dev
Definition: mmap_boot.c:46
static struct xlate_window real_dev_window
Definition: mmap_boot.c:47
static void bios_mmap_init(void)
Definition: mmap_boot.c:49
static size_t bios_size
Definition: mmap_boot.c:43
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
Definition: region.h:76
struct region_device rdev
Definition: region.h:255
struct region sub_region
Definition: region.h:249