blob: d229cf816a433bdfe087239eef22df3d509c4cbc [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#ifndef RMODULE_H
20#define RMODULE_H
21
22#include <stdint.h>
Aaron Durbine8c866a2013-02-08 17:05:36 -060023#include <stddef.h>
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050024#include <string.h>
Aaron Durbin4e6ad1b2014-03-10 09:53:34 -050025#include <rmodule-defs.h>
Aaron Durbinad935522012-12-24 14:28:37 -060026
27enum {
28 RMODULE_TYPE_SMM,
Aaron Durbin9be4c472013-01-12 00:41:44 -060029 RMODULE_TYPE_SIPI_VECTOR,
Aaron Durbinf7c6d482013-02-06 15:47:31 -060030 RMODULE_TYPE_STAGE,
Aaron Durbinc0650892013-03-01 17:10:28 -060031 RMODULE_TYPE_VBOOT,
Aaron Durbinad935522012-12-24 14:28:37 -060032};
33
34struct rmodule;
35
36/* Public API for loading rmdoules. */
37int rmodule_parse(void *ptr, struct rmodule *m);
38void *rmodule_parameters(const struct rmodule *m);
39void *rmodule_entry(const struct rmodule *m);
40int rmodule_entry_offset(const struct rmodule *m);
41int rmodule_memory_size(const struct rmodule *m);
42int rmodule_load(void *loc, struct rmodule *m);
43int rmodule_load_alignment(const struct rmodule *m);
Aaron Durbindd4a6d22013-02-27 22:50:12 -060044/* rmodule_calc_region() calculates the region size, offset to place an
45 * rmodule in memory, and load address offset based off of a region allocator
46 * with an alignment of region_alignment. This function helps place an rmodule
47 * in the same location in ram it will run from. The offset to place the
48 * rmodule into the region allocated of size region_size is returned. The
49 * load_offset is the address to load and relocate the rmodule.
50 * region_alignment must be a power of 2. */
51int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
52 size_t *region_size, int *load_offset);
Aaron Durbinad935522012-12-24 14:28:37 -060053
Aaron Durbinf545abf2013-10-24 10:14:06 -050054/* Support for loading rmodule stages. This API is only available when
55 * using dynamic cbmem because it uses the dynamic cbmem API to obtain
56 * the backing store region for the stage. */
57#if CONFIG_DYNAMIC_CBMEM
58struct cbfs_stage;
59struct cbmem_entry;
60
61struct rmod_stage_load {
62 /* Inputs */
63 uint32_t cbmem_id;
64 const char *name;
65 /* Outputs */
66 const struct cbmem_entry *cbmem_entry;
67 void *entry;
68};
69
70/* Both of the following functions return 0 on success, -1 on error. */
71int rmodule_stage_load(struct rmod_stage_load *rsl, struct cbfs_stage *stage);
72int rmodule_stage_load_from_cbfs(struct rmod_stage_load *rsl);
73#endif
Aaron Durbinad935522012-12-24 14:28:37 -060074
Aaron Durbinad935522012-12-24 14:28:37 -060075struct rmodule {
76 void *location;
77 struct rmodule_header *header;
78 const void *payload;
79 int payload_size;
80 void *relocations;
81};
82
Aaron Durbin3eb8eb72014-03-10 16:13:58 -050083#if IS_ENABLED(CONFIG_RELOCATABLE_MODULES)
84/* Rmodules have an entry point of named __rmodule_entry. */
85#define RMODULE_ENTRY(entry_) \
86 void __rmodule_entry(void *) __attribute__((alias (STRINGIFY(entry_))))
87#else
88#define RMODULE_ENTRY(entry_)
89#endif
Aaron Durbinad935522012-12-24 14:28:37 -060090
91#endif /* RMODULE_H */