blob: 2147ab09197ec507524f5317e2b598639c708096 [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 Durbin4e6ad1b2014-03-10 09:53:34 -050024#include <rmodule-defs.h>
Aaron Durbinad935522012-12-24 14:28:37 -060025
26enum {
27 RMODULE_TYPE_SMM,
Aaron Durbin9be4c472013-01-12 00:41:44 -060028 RMODULE_TYPE_SIPI_VECTOR,
Aaron Durbinf7c6d482013-02-06 15:47:31 -060029 RMODULE_TYPE_STAGE,
Aaron Durbinc0650892013-03-01 17:10:28 -060030 RMODULE_TYPE_VBOOT,
Aaron Durbinad935522012-12-24 14:28:37 -060031};
32
33struct rmodule;
34
35/* Public API for loading rmdoules. */
36int rmodule_parse(void *ptr, struct rmodule *m);
37void *rmodule_parameters(const struct rmodule *m);
38void *rmodule_entry(const struct rmodule *m);
39int rmodule_entry_offset(const struct rmodule *m);
40int rmodule_memory_size(const struct rmodule *m);
41int rmodule_load(void *loc, struct rmodule *m);
42int rmodule_load_alignment(const struct rmodule *m);
Aaron Durbindd4a6d22013-02-27 22:50:12 -060043/* rmodule_calc_region() calculates the region size, offset to place an
44 * rmodule in memory, and load address offset based off of a region allocator
45 * with an alignment of region_alignment. This function helps place an rmodule
46 * in the same location in ram it will run from. The offset to place the
47 * rmodule into the region allocated of size region_size is returned. The
48 * load_offset is the address to load and relocate the rmodule.
49 * region_alignment must be a power of 2. */
50int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
51 size_t *region_size, int *load_offset);
Aaron Durbinad935522012-12-24 14:28:37 -060052
Aaron Durbinad935522012-12-24 14:28:37 -060053#define DEFINE_RMODULE_HEADER(name_, entry_, type_) \
54 struct rmodule_header name_ \
55 __attribute__ ((section (".module_header"))) = \
56 RMODULE_HEADER(entry_, type_)
57
Aaron Durbinf545abf2013-10-24 10:14:06 -050058/* Support for loading rmodule stages. This API is only available when
59 * using dynamic cbmem because it uses the dynamic cbmem API to obtain
60 * the backing store region for the stage. */
61#if CONFIG_DYNAMIC_CBMEM
62struct cbfs_stage;
63struct cbmem_entry;
64
65struct rmod_stage_load {
66 /* Inputs */
67 uint32_t cbmem_id;
68 const char *name;
69 /* Outputs */
70 const struct cbmem_entry *cbmem_entry;
71 void *entry;
72};
73
74/* Both of the following functions return 0 on success, -1 on error. */
75int rmodule_stage_load(struct rmod_stage_load *rsl, struct cbfs_stage *stage);
76int rmodule_stage_load_from_cbfs(struct rmod_stage_load *rsl);
77#endif
Aaron Durbinad935522012-12-24 14:28:37 -060078
Aaron Durbinad935522012-12-24 14:28:37 -060079struct rmodule {
80 void *location;
81 struct rmodule_header *header;
82 const void *payload;
83 int payload_size;
84 void *relocations;
85};
86
87/* These are the symbols assumed that every module contains. The linker script
88 * provides these symbols. */
89extern char _relocations_begin_offset[];
90extern char _relocations_end_offset[];
91extern char _payload_end_offset[];
92extern char _payload_begin_offset[];
Aaron Durbinf7c6d482013-02-06 15:47:31 -060093extern char _bss[];
94extern char _ebss[];
Aaron Durbinad935522012-12-24 14:28:37 -060095extern char _module_program_size[];
96extern char _module_link_start_addr[];
97extern char _module_params_begin[];
98extern char _module_params_end[];
99
100#endif /* RMODULE_H */