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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame^] | 17 | * Foundation, Inc. |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 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 | 3eb8eb7 | 2014-03-10 16:13:58 -0500 | [diff] [blame] | 24 | #include <string.h> |
Aaron Durbin | 4e6ad1b | 2014-03-10 09:53:34 -0500 | [diff] [blame] | 25 | #include <rmodule-defs.h> |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 26 | |
| 27 | enum { |
| 28 | RMODULE_TYPE_SMM, |
Aaron Durbin | 9be4c47 | 2013-01-12 00:41:44 -0600 | [diff] [blame] | 29 | RMODULE_TYPE_SIPI_VECTOR, |
Aaron Durbin | f7c6d48 | 2013-02-06 15:47:31 -0600 | [diff] [blame] | 30 | RMODULE_TYPE_STAGE, |
Aaron Durbin | c065089 | 2013-03-01 17:10:28 -0600 | [diff] [blame] | 31 | RMODULE_TYPE_VBOOT, |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct rmodule; |
| 35 | |
| 36 | /* Public API for loading rmdoules. */ |
| 37 | int rmodule_parse(void *ptr, struct rmodule *m); |
| 38 | void *rmodule_parameters(const struct rmodule *m); |
| 39 | void *rmodule_entry(const struct rmodule *m); |
| 40 | int rmodule_entry_offset(const struct rmodule *m); |
| 41 | int rmodule_memory_size(const struct rmodule *m); |
| 42 | int rmodule_load(void *loc, struct rmodule *m); |
| 43 | int rmodule_load_alignment(const struct rmodule *m); |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 44 | /* 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. */ |
| 51 | int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size, |
| 52 | size_t *region_size, int *load_offset); |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 53 | |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 54 | /* 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. */ |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 57 | struct cbfs_stage; |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 58 | struct prog; |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 59 | |
| 60 | struct rmod_stage_load { |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 61 | uint32_t cbmem_id; |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 62 | struct prog *prog; |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /* Both of the following functions return 0 on success, -1 on error. */ |
| 66 | int rmodule_stage_load(struct rmod_stage_load *rsl, struct cbfs_stage *stage); |
| 67 | int rmodule_stage_load_from_cbfs(struct rmod_stage_load *rsl); |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 68 | |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 69 | struct rmodule { |
| 70 | void *location; |
| 71 | struct rmodule_header *header; |
| 72 | const void *payload; |
| 73 | int payload_size; |
| 74 | void *relocations; |
| 75 | }; |
| 76 | |
Aaron Durbin | 3eb8eb7 | 2014-03-10 16:13:58 -0500 | [diff] [blame] | 77 | #if IS_ENABLED(CONFIG_RELOCATABLE_MODULES) |
| 78 | /* Rmodules have an entry point of named __rmodule_entry. */ |
| 79 | #define RMODULE_ENTRY(entry_) \ |
| 80 | void __rmodule_entry(void *) __attribute__((alias (STRINGIFY(entry_)))) |
| 81 | #else |
| 82 | #define RMODULE_ENTRY(entry_) |
| 83 | #endif |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 84 | |
| 85 | #endif /* RMODULE_H */ |