coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
bootmem.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef BOOTMEM_H
4 #define BOOTMEM_H
5 
6 #include <boot/coreboot_tables.h>
7 #include <memrange.h>
8 #include <types.h>
9 
10 /**
11  * Bootmem types match to LB_MEM tags, except for the following:
12  * BM_MEM_RAMSTAGE : Memory where any kind of boot firmware resides and that
13  * should not be touched by bootmem (by example: stack,
14  * TTB, program, ...).
15  * BM_MEM_PAYLOAD : Memory where any kind of payload resides and that should
16  * not be touched by bootmem.
17  * Start at 0x10000 to make sure that the caller doesn't provide LB_MEM tags.
18  */
20  BM_MEM_INVALID = 0, /* Invalid type (used in optional arguments). */
21 
22  BM_MEM_FIRST = 0x10000, /* First entry in this list */
23  BM_MEM_RAM, /* Memory anyone can use */
24  BM_MEM_RESERVED, /* Don't use this memory region */
25  BM_MEM_ACPI, /* ACPI Tables */
26  BM_MEM_NVS, /* ACPI NVS Memory */
27  BM_MEM_UNUSABLE, /* Unusable address space */
28  BM_MEM_VENDOR_RSVD, /* Vendor Reserved */
29  BM_MEM_OPENSBI, /* Risc-V OpenSBI */
30  BM_MEM_BL31, /* Arm64 BL31 executable */
31  BM_MEM_TABLE, /* Ram configuration tables are kept in */
32  /* Tags below this point are ignored for the OS table. */
36  BM_MEM_LAST, /* Last entry in this list */
37 };
38 
39 /**
40  * Write memory coreboot table. Current resource map is serialized into
41  * memtable (LB_MEM_* types). bootmem library is unusable until this function
42  * is called first in the write tables path before payload is loaded.
43  *
44  * Bootmem types match to LB_MEM tags, except for the following:
45  * BM_MEM_RAMSTAGE : Translates to LB_MEM_RAM.
46  * BM_MEM_PAYLOAD : Translates to LB_MEM_RAM.
47  * BM_MEM_BL31 : Translates to LB_MEM_RESERVED.
48  */
49 void bootmem_write_memory_table(struct lb_memory *mem);
50 
51 /* Architecture hook to add bootmem areas the architecture controls when
52  * bootmem_write_memory_table() is called. */
53 void bootmem_arch_add_ranges(void);
54 
55 /* Platform hook to add bootmem areas the platform / board controls. */
57 
58 /* Add a range of a given type to the bootmem address space. */
59 void bootmem_add_range(uint64_t start, uint64_t size,
60  const enum bootmem_type tag);
61 
62 /* Print current range map of boot memory. */
63 void bootmem_dump_ranges(void);
64 
65 typedef bool (*range_action_t)(const struct range_entry *r, void *arg);
66 
67 /**
68  * Walk memory tables from OS point of view and call the provided function,
69  * for every region. The caller has to return false to break out of the loop any
70  * time, or return true to continue.
71  *
72  * @param action The function to call for each memory range.
73  * @param arg Pointer passed to function @action. Set to NULL if unused.
74  * @return true if the function 'action' returned false.
75  */
76 bool bootmem_walk_os_mem(range_action_t action, void *arg);
77 
78 /**
79  * Walk memory tables and call the provided function, for every region.
80  * The caller has to return false to break out of the loop any time, or
81  * return true to continue.
82  *
83  * @param action The function to call for each memory range.
84  * @param arg Pointer passed to function @action. Set to NULL if unused.
85  * @return true if the function 'action' returned false.
86  */
87 bool bootmem_walk(range_action_t action, void *arg);
88 
89 /* Returns 1 if the requested memory range is all tagged as type dest_type.
90  * Otherwise returns 0.
91  */
93  enum bootmem_type dest_type);
94 
95 /* Allocate a temporary buffer from the unused RAM areas. */
96 void *bootmem_allocate_buffer(size_t size);
97 
98 #endif /* BOOTMEM_H */
void * bootmem_allocate_buffer(size_t size)
Definition: bootmem.c:216
void bootmem_dump_ranges(void)
Definition: bootmem.c:155
bool(* range_action_t)(const struct range_entry *r, void *arg)
Definition: bootmem.h:65
bool bootmem_walk_os_mem(range_action_t action, void *arg)
Walk memory tables from OS point of view and call the provided function, for every region.
Definition: bootmem.c:169
void bootmem_platform_add_ranges(void)
Definition: bootmem.c:27
bootmem_type
Bootmem types match to LB_MEM tags, except for the following: BM_MEM_RAMSTAGE : Memory where any kind...
Definition: bootmem.h:19
@ BM_MEM_LAST
Definition: bootmem.h:36
@ BM_MEM_RAM
Definition: bootmem.h:23
@ BM_MEM_OS_CUTOFF
Definition: bootmem.h:33
@ BM_MEM_ACPI
Definition: bootmem.h:25
@ BM_MEM_VENDOR_RSVD
Definition: bootmem.h:28
@ BM_MEM_UNUSABLE
Definition: bootmem.h:27
@ BM_MEM_BL31
Definition: bootmem.h:30
@ BM_MEM_TABLE
Definition: bootmem.h:31
@ BM_MEM_RAMSTAGE
Definition: bootmem.h:34
@ BM_MEM_FIRST
Definition: bootmem.h:22
@ BM_MEM_OPENSBI
Definition: bootmem.h:29
@ BM_MEM_PAYLOAD
Definition: bootmem.h:35
@ BM_MEM_INVALID
Definition: bootmem.h:20
@ BM_MEM_RESERVED
Definition: bootmem.h:24
@ BM_MEM_NVS
Definition: bootmem.h:26
void bootmem_arch_add_ranges(void)
Definition: tables.c:12
void bootmem_add_range(uint64_t start, uint64_t size, const enum bootmem_type tag)
Definition: bootmem.c:88
void bootmem_write_memory_table(struct lb_memory *mem)
Write memory coreboot table.
Definition: bootmem.c:102
int bootmem_region_targets_type(uint64_t start, uint64_t size, enum bootmem_type dest_type)
Definition: bootmem.c:197
bool bootmem_walk(range_action_t action, void *arg)
Walk memory tables and call the provided function, for every region.
Definition: bootmem.c:183
struct bootblock_arg arg
Definition: decompressor.c:22
_Bool bool
Definition: stdbool.h:6
unsigned long long uint64_t
Definition: stdint.h:17
Definition: memrange.h:24