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