xref: /aosp_15_r20/external/coreboot/src/include/rmodule.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef RMODULE_H
3 #define RMODULE_H
4 
5 #include <stdint.h>
6 #include <stddef.h>
7 #include <commonlib/rmodule-defs.h>
8 
9 enum {
10 	RMODULE_TYPE_SMM,
11 	RMODULE_TYPE_SIPI_VECTOR,
12 	RMODULE_TYPE_STAGE,
13 	RMODULE_TYPE_VBOOT,
14 };
15 
16 struct rmodule;
17 
18 /* Public API for loading rmodules. */
19 int rmodule_parse(void *ptr, struct rmodule *m);
20 void *rmodule_parameters(const struct rmodule *m);
21 void *rmodule_entry(const struct rmodule *m);
22 int rmodule_entry_offset(const struct rmodule *m);
23 int rmodule_memory_size(const struct rmodule *m);
24 int rmodule_load(void *loc, struct rmodule *m);
25 int rmodule_load_alignment(const struct rmodule *m);
26 /* rmodule_calc_region() calculates the region size, offset to place an
27  * rmodule in memory, and load address offset based off of a region allocator
28  * with an alignment of region_alignment. This function helps place an rmodule
29  * in the same location in RAM it will run from. The offset to place the
30  * rmodule into the region allocated of size region_size is returned. The
31  * load_offset is the address to load and relocate the rmodule.
32  * region_alignment must be a power of 2. */
33 int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
34 			size_t *region_size, int *load_offset);
35 
36 /* Support for loading rmodule stages. This API is only available when
37  * using dynamic cbmem because it uses the dynamic cbmem API to obtain
38  * the backing store region for the stage. */
39 struct prog;
40 
41 struct rmod_stage_load {
42 	uint32_t cbmem_id;
43 	struct prog *prog;
44 	void *params;
45 };
46 
47 /* Both of the following functions return 0 on success, -1 on error. */
48 int rmodule_stage_load(struct rmod_stage_load *rsl);
49 
50 struct rmodule {
51 	void *location;
52 	struct rmodule_header *header;
53 	const void *payload;
54 	int payload_size;
55 	void *relocations;
56 };
57 
58 #if CONFIG(RELOCATABLE_MODULES)
59 /* Rmodules have an entry point of named _start. */
60 #define RMODULE_ENTRY(entry_) \
61 	void _start(void *) __attribute__((alias(STRINGIFY(entry_))))
62 #else
63 #define RMODULE_ENTRY(entry_)
64 #endif
65 
66 #endif /* RMODULE_H */
67