blob: a2612d1110a1b6ad22f6ec2f30d899527978ed84 [file] [log] [blame]
Aaron Durbinad935522012-12-24 14:28:37 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 ChromeOS Authors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbinad935522012-12-24 14:28:37 -060014 */
15#ifndef RMODULE_H
16#define RMODULE_H
17
18#include <stdint.h>
Aaron Durbine8c866a2013-02-08 17:05:36 -060019#include <stddef.h>
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050020#include <string.h>
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050021#include <commonlib/rmodule-defs.h>
Aaron Durbinad935522012-12-24 14:28:37 -060022
23enum {
24 RMODULE_TYPE_SMM,
Aaron Durbin9be4c472013-01-12 00:41:44 -060025 RMODULE_TYPE_SIPI_VECTOR,
Aaron Durbinf7c6d482013-02-06 15:47:31 -060026 RMODULE_TYPE_STAGE,
Aaron Durbinc0650892013-03-01 17:10:28 -060027 RMODULE_TYPE_VBOOT,
Aaron Durbinad935522012-12-24 14:28:37 -060028};
29
30struct rmodule;
31
32/* Public API for loading rmdoules. */
33int rmodule_parse(void *ptr, struct rmodule *m);
34void *rmodule_parameters(const struct rmodule *m);
35void *rmodule_entry(const struct rmodule *m);
36int rmodule_entry_offset(const struct rmodule *m);
37int rmodule_memory_size(const struct rmodule *m);
38int rmodule_load(void *loc, struct rmodule *m);
39int rmodule_load_alignment(const struct rmodule *m);
Aaron Durbindd4a6d22013-02-27 22:50:12 -060040/* rmodule_calc_region() calculates the region size, offset to place an
41 * rmodule in memory, and load address offset based off of a region allocator
42 * with an alignment of region_alignment. This function helps place an rmodule
43 * in the same location in ram it will run from. The offset to place the
44 * rmodule into the region allocated of size region_size is returned. The
45 * load_offset is the address to load and relocate the rmodule.
46 * region_alignment must be a power of 2. */
47int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
48 size_t *region_size, int *load_offset);
Aaron Durbinad935522012-12-24 14:28:37 -060049
Aaron Durbinf545abf2013-10-24 10:14:06 -050050/* Support for loading rmodule stages. This API is only available when
51 * using dynamic cbmem because it uses the dynamic cbmem API to obtain
52 * the backing store region for the stage. */
Aaron Durbin460703b2015-03-27 21:17:22 -050053struct prog;
Aaron Durbinf545abf2013-10-24 10:14:06 -050054
55struct rmod_stage_load {
Aaron Durbinf545abf2013-10-24 10:14:06 -050056 uint32_t cbmem_id;
Aaron Durbin460703b2015-03-27 21:17:22 -050057 struct prog *prog;
Aaron Durbinf545abf2013-10-24 10:14:06 -050058};
59
60/* Both of the following functions return 0 on success, -1 on error. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050061int rmodule_stage_load(struct rmod_stage_load *rsl);
Aaron Durbinad935522012-12-24 14:28:37 -060062
Aaron Durbinad935522012-12-24 14:28:37 -060063struct rmodule {
64 void *location;
65 struct rmodule_header *header;
66 const void *payload;
67 int payload_size;
68 void *relocations;
69};
70
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050071#if IS_ENABLED(CONFIG_RELOCATABLE_MODULES)
Aaron Durbindde76292015-09-05 12:59:26 -050072/* Rmodules have an entry point of named _start. */
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050073#define RMODULE_ENTRY(entry_) \
Aaron Durbindde76292015-09-05 12:59:26 -050074 void _start(void *) __attribute__((alias (STRINGIFY(entry_))))
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050075#else
76#define RMODULE_ENTRY(entry_)
77#endif
Aaron Durbinad935522012-12-24 14:28:37 -060078
79#endif /* RMODULE_H */