blob: 3d5fe31694aabbf85fe729eda6d89dd41aaec79e [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Aaron Durbinad935522012-12-24 14:28:37 -06003#ifndef RMODULE_H
4#define RMODULE_H
5
6#include <stdint.h>
Aaron Durbine8c866a2013-02-08 17:05:36 -06007#include <stddef.h>
Aaron Durbin3eb8eb72014-03-10 16:13:58 -05008#include <string.h>
Aaron Durbindc9f5cd2015-09-08 13:34:43 -05009#include <commonlib/rmodule-defs.h>
Aaron Durbinad935522012-12-24 14:28:37 -060010
11enum {
12 RMODULE_TYPE_SMM,
Aaron Durbin9be4c472013-01-12 00:41:44 -060013 RMODULE_TYPE_SIPI_VECTOR,
Aaron Durbinf7c6d482013-02-06 15:47:31 -060014 RMODULE_TYPE_STAGE,
Aaron Durbinc0650892013-03-01 17:10:28 -060015 RMODULE_TYPE_VBOOT,
Aaron Durbinad935522012-12-24 14:28:37 -060016};
17
18struct rmodule;
19
20/* Public API for loading rmdoules. */
21int rmodule_parse(void *ptr, struct rmodule *m);
22void *rmodule_parameters(const struct rmodule *m);
23void *rmodule_entry(const struct rmodule *m);
24int rmodule_entry_offset(const struct rmodule *m);
25int rmodule_memory_size(const struct rmodule *m);
26int rmodule_load(void *loc, struct rmodule *m);
27int rmodule_load_alignment(const struct rmodule *m);
Aaron Durbindd4a6d22013-02-27 22:50:12 -060028/* 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 HAOUAS918535a2016-07-28 21:25:21 +020031 * in the same location in RAM it will run from. The offset to place the
Aaron Durbindd4a6d22013-02-27 22:50:12 -060032 * 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. */
35int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
Lee Leahy708fc272017-03-07 12:18:53 -080036 size_t *region_size, int *load_offset);
Aaron Durbinad935522012-12-24 14:28:37 -060037
Aaron Durbinf545abf2013-10-24 10:14:06 -050038/* 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 Durbin460703b2015-03-27 21:17:22 -050041struct prog;
Aaron Durbinf545abf2013-10-24 10:14:06 -050042
43struct rmod_stage_load {
Aaron Durbinf545abf2013-10-24 10:14:06 -050044 uint32_t cbmem_id;
Aaron Durbin460703b2015-03-27 21:17:22 -050045 struct prog *prog;
Aaron Durbin94271b42016-03-17 23:13:34 -050046 void *params;
Aaron Durbinf545abf2013-10-24 10:14:06 -050047};
48
49/* Both of the following functions return 0 on success, -1 on error. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050050int rmodule_stage_load(struct rmod_stage_load *rsl);
Aaron Durbinad935522012-12-24 14:28:37 -060051
Aaron Durbinad935522012-12-24 14:28:37 -060052struct rmodule {
53 void *location;
54 struct rmodule_header *header;
55 const void *payload;
56 int payload_size;
57 void *relocations;
58};
59
Julius Wernercd49cce2019-03-05 16:53:33 -080060#if CONFIG(RELOCATABLE_MODULES)
Aaron Durbindde76292015-09-05 12:59:26 -050061/* Rmodules have an entry point of named _start. */
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050062#define RMODULE_ENTRY(entry_) \
Lee Leahy746d4af2017-03-07 15:31:49 -080063 void _start(void *) __attribute__((alias(STRINGIFY(entry_))))
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050064#else
65#define RMODULE_ENTRY(entry_)
66#endif
Aaron Durbinad935522012-12-24 14:28:37 -060067
68#endif /* RMODULE_H */