Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 3 | #ifndef RMODULE_H |
| 4 | #define RMODULE_H |
| 5 | |
| 6 | #include <stdint.h> |
Aaron Durbin | e8c866a | 2013-02-08 17:05:36 -0600 | [diff] [blame] | 7 | #include <stddef.h> |
Aaron Durbin | 3eb8eb7 | 2014-03-10 16:13:58 -0500 | [diff] [blame] | 8 | #include <string.h> |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 9 | #include <commonlib/rmodule-defs.h> |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 10 | |
| 11 | enum { |
| 12 | RMODULE_TYPE_SMM, |
Aaron Durbin | 9be4c47 | 2013-01-12 00:41:44 -0600 | [diff] [blame] | 13 | RMODULE_TYPE_SIPI_VECTOR, |
Aaron Durbin | f7c6d48 | 2013-02-06 15:47:31 -0600 | [diff] [blame] | 14 | RMODULE_TYPE_STAGE, |
Aaron Durbin | c065089 | 2013-03-01 17:10:28 -0600 | [diff] [blame] | 15 | RMODULE_TYPE_VBOOT, |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | struct rmodule; |
| 19 | |
| 20 | /* Public API for loading rmdoules. */ |
| 21 | int rmodule_parse(void *ptr, struct rmodule *m); |
| 22 | void *rmodule_parameters(const struct rmodule *m); |
| 23 | void *rmodule_entry(const struct rmodule *m); |
| 24 | int rmodule_entry_offset(const struct rmodule *m); |
| 25 | int rmodule_memory_size(const struct rmodule *m); |
| 26 | int rmodule_load(void *loc, struct rmodule *m); |
| 27 | int rmodule_load_alignment(const struct rmodule *m); |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 28 | /* rmodule_calc_region() calculates the region size, offset to place an |
| 29 | * rmodule in memory, and load address offset based off of a region allocator |
| 30 | * with an alignment of region_alignment. This function helps place an rmodule |
Elyes HAOUAS | 918535a | 2016-07-28 21:25:21 +0200 | [diff] [blame] | 31 | * in the same location in RAM it will run from. The offset to place the |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 32 | * rmodule into the region allocated of size region_size is returned. The |
| 33 | * load_offset is the address to load and relocate the rmodule. |
| 34 | * region_alignment must be a power of 2. */ |
| 35 | int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size, |
Lee Leahy | 708fc27 | 2017-03-07 12:18:53 -0800 | [diff] [blame] | 36 | size_t *region_size, int *load_offset); |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 37 | |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 38 | /* Support for loading rmodule stages. This API is only available when |
| 39 | * using dynamic cbmem because it uses the dynamic cbmem API to obtain |
| 40 | * the backing store region for the stage. */ |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 41 | struct prog; |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 42 | |
| 43 | struct rmod_stage_load { |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 44 | uint32_t cbmem_id; |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 45 | struct prog *prog; |
Aaron Durbin | 94271b4 | 2016-03-17 23:13:34 -0500 | [diff] [blame] | 46 | void *params; |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /* Both of the following functions return 0 on success, -1 on error. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 50 | int rmodule_stage_load(struct rmod_stage_load *rsl); |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 51 | |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 52 | struct rmodule { |
| 53 | void *location; |
| 54 | struct rmodule_header *header; |
| 55 | const void *payload; |
| 56 | int payload_size; |
| 57 | void *relocations; |
| 58 | }; |
| 59 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 60 | #if CONFIG(RELOCATABLE_MODULES) |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 61 | /* Rmodules have an entry point of named _start. */ |
Aaron Durbin | 3eb8eb7 | 2014-03-10 16:13:58 -0500 | [diff] [blame] | 62 | #define RMODULE_ENTRY(entry_) \ |
Lee Leahy | 746d4af | 2017-03-07 15:31:49 -0800 | [diff] [blame] | 63 | void _start(void *) __attribute__((alias(STRINGIFY(entry_)))) |
Aaron Durbin | 3eb8eb7 | 2014-03-10 16:13:58 -0500 | [diff] [blame] | 64 | #else |
| 65 | #define RMODULE_ENTRY(entry_) |
| 66 | #endif |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 67 | |
| 68 | #endif /* RMODULE_H */ |