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 | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 57 | struct prog; |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 58 | |
| 59 | struct rmod_stage_load { |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 60 | uint32_t cbmem_id; |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 61 | struct prog *prog; |
Aaron Durbin | f545abf | 2013-10-24 10:14:06 -0500 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* Both of the following functions return 0 on success, -1 on error. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame^] | 65 | int rmodule_stage_load(struct rmod_stage_load *rsl); |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 66 | |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 67 | struct rmodule { |
| 68 | void *location; |
| 69 | struct rmodule_header *header; |
| 70 | const void *payload; |
| 71 | int payload_size; |
| 72 | void *relocations; |
| 73 | }; |
| 74 | |
Aaron Durbin | 3eb8eb7 | 2014-03-10 16:13:58 -0500 | [diff] [blame] | 75 | #if IS_ENABLED(CONFIG_RELOCATABLE_MODULES) |
| 76 | /* Rmodules have an entry point of named __rmodule_entry. */ |
| 77 | #define RMODULE_ENTRY(entry_) \ |
| 78 | void __rmodule_entry(void *) __attribute__((alias (STRINGIFY(entry_)))) |
| 79 | #else |
| 80 | #define RMODULE_ENTRY(entry_) |
| 81 | #endif |
Aaron Durbin | ad93552 | 2012-12-24 14:28:37 -0600 | [diff] [blame] | 82 | |
| 83 | #endif /* RMODULE_H */ |