Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 1 | /* |
| 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 Durbin | e8c866a | 2013-02-08 17:05:36 -0600 | [diff] [blame] | 23 | #include <stddef.h> |
Aaron Durbin | 4e6ad1b | 2014-03-10 09:53:34 -0500 | [diff] [blame] | 24 | #include <rmodule-defs.h> |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 25 | |
| 26 | enum { |
| 27 | RMODULE_TYPE_SMM, |
Aaron Durbin | 9be4c47 | 2013-01-12 00:41:44 -0600 | [diff] [blame] | 28 | RMODULE_TYPE_SIPI_VECTOR, |
Aaron Durbin | f7c6d48 | 2013-02-06 15:47:31 -0600 | [diff] [blame] | 29 | RMODULE_TYPE_STAGE, |
Aaron Durbin | c065089 | 2013-03-01 17:10:28 -0600 | [diff] [blame] | 30 | RMODULE_TYPE_VBOOT, |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | struct rmodule; |
| 34 | |
| 35 | /* Public API for loading rmdoules. */ |
| 36 | int rmodule_parse(void *ptr, struct rmodule *m); |
| 37 | void *rmodule_parameters(const struct rmodule *m); |
| 38 | void *rmodule_entry(const struct rmodule *m); |
| 39 | int rmodule_entry_offset(const struct rmodule *m); |
| 40 | int rmodule_memory_size(const struct rmodule *m); |
| 41 | int rmodule_load(void *loc, struct rmodule *m); |
| 42 | int rmodule_load_alignment(const struct rmodule *m); |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 43 | /* 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. */ |
| 50 | int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size, |
| 51 | size_t *region_size, int *load_offset); |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 52 | |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 53 | #define DEFINE_RMODULE_HEADER(name_, entry_, type_) \ |
| 54 | struct rmodule_header name_ \ |
| 55 | __attribute__ ((section (".module_header"))) = \ |
| 56 | RMODULE_HEADER(entry_, type_) |
| 57 | |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 58 | /* 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 |
| 62 | struct cbfs_stage; |
| 63 | struct cbmem_entry; |
| 64 | |
| 65 | struct 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. */ |
| 75 | int rmodule_stage_load(struct rmod_stage_load *rsl, struct cbfs_stage *stage); |
| 76 | int rmodule_stage_load_from_cbfs(struct rmod_stage_load *rsl); |
| 77 | #endif |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 78 | |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 79 | struct 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. */ |
| 89 | extern char _relocations_begin_offset[]; |
| 90 | extern char _relocations_end_offset[]; |
| 91 | extern char _payload_end_offset[]; |
| 92 | extern char _payload_begin_offset[]; |
Aaron Durbin | f7c6d48 | 2013-02-06 15:47:31 -0600 | [diff] [blame] | 93 | extern char _bss[]; |
| 94 | extern char _ebss[]; |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 95 | extern char _module_program_size[]; |
| 96 | extern char _module_link_start_addr[]; |
| 97 | extern char _module_params_begin[]; |
| 98 | extern char _module_params_end[]; |
| 99 | |
| 100 | #endif /* RMODULE_H */ |