Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 4 | * Copyright 2015 Google Inc. |
Ionela Voinescu | 00903e5 | 2015-01-09 13:14:20 +0000 | [diff] [blame] | 5 | * Copyright (C) 2014 Imagination Technologies |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 20 | #ifndef PROGRAM_LOADING_H |
| 21 | #define PROGRAM_LOADING_H |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 22 | |
| 23 | #include <stdint.h> |
| 24 | #include <stddef.h> |
| 25 | |
Aaron Durbin | 6e76fff | 2015-03-20 09:42:05 -0500 | [diff] [blame] | 26 | enum { |
| 27 | /* Last segment of program. Can be used to take different actions for |
| 28 | * cache maintenance of a program load. */ |
| 29 | SEG_FINAL = 1 << 0, |
| 30 | }; |
Ionela Voinescu | 00903e5 | 2015-01-09 13:14:20 +0000 | [diff] [blame] | 31 | |
Aaron Durbin | 6e76fff | 2015-03-20 09:42:05 -0500 | [diff] [blame] | 32 | /* Called for each segment of a program loaded. The PROG_FLAG_FINAL will be |
| 33 | * set on the last segment loaded. */ |
| 34 | void arch_segment_loaded(uintptr_t start, size_t size, int flags); |
Ionela Voinescu | 00903e5 | 2015-01-09 13:14:20 +0000 | [diff] [blame] | 35 | |
Aaron Durbin | d1b0e87 | 2015-03-17 13:17:06 -0500 | [diff] [blame] | 36 | /************************ |
| 37 | * ROMSTAGE LOADING * |
| 38 | ************************/ |
| 39 | |
| 40 | /* Run romstage from bootblock. */ |
| 41 | void run_romstage(void); |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 42 | |
| 43 | /************************ |
| 44 | * RAMSTAGE LOADING * |
| 45 | ************************/ |
| 46 | |
Aaron Durbin | fcfdff8 | 2015-03-20 10:58:41 -0500 | [diff] [blame] | 47 | struct romstage_handoff; |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 48 | struct cbmem_entry; |
| 49 | |
Aaron Durbin | fcfdff8 | 2015-03-20 10:58:41 -0500 | [diff] [blame] | 50 | #if defined(__PRE_RAM__) |
| 51 | #if CONFIG_RELOCATABLE_RAMSTAGE |
| 52 | /* The cache_loaded_ramstage() and load_cached_ramstage() functions are defined |
| 53 | * to be weak so that board and chipset code may override them. Their job is to |
| 54 | * cache and load the ramstage for quick S3 resume. By default a copy of the |
| 55 | * relocated ramstage is saved using the cbmem infrastructure. These |
| 56 | * functions are only valid during romstage. */ |
| 57 | |
| 58 | /* The implementer of cache_loaded_ramstage() may use the romstage_handoff |
| 59 | * structure to store information, but note that the handoff variable can be |
| 60 | * NULL. The ramstage cbmem_entry represents the region occupied by the loaded |
| 61 | * ramstage. */ |
| 62 | void cache_loaded_ramstage(struct romstage_handoff *handoff, |
| 63 | const struct cbmem_entry *ramstage, void *entry_point); |
| 64 | /* Return NULL on error or entry point on success. The ramstage cbmem_entry is |
| 65 | * the region where to load the cached contents to. */ |
| 66 | void * load_cached_ramstage(struct romstage_handoff *handoff, |
| 67 | const struct cbmem_entry *ramstage); |
| 68 | #else /* CONFIG_RELOCATABLE_RAMSTAGE */ |
| 69 | |
| 70 | static inline void cache_loaded_ramstage(struct romstage_handoff *handoff, |
| 71 | const struct cbmem_entry *ramstage, void *entry_point) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | static inline void * |
| 76 | load_cached_ramstage(struct romstage_handoff *handoff, |
| 77 | const struct cbmem_entry *ramstage) |
| 78 | { |
| 79 | return NULL; |
| 80 | } |
| 81 | |
| 82 | #endif /* CONFIG_RELOCATABLE_RAMSTAGE */ |
| 83 | #endif /* defined(__PRE_RAM__) */ |
| 84 | |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 85 | /* Run ramstage from romstage. */ |
| 86 | void run_ramstage(void); |
| 87 | |
| 88 | struct ramstage_loader_ops { |
| 89 | const char *name; |
| 90 | void *(*load)(uint32_t cbmem_id, const char *name, |
| 91 | const struct cbmem_entry **cbmem_entry); |
| 92 | }; |
| 93 | |
| 94 | /*********************** |
| 95 | * PAYLOAD LOADING * |
| 96 | ***********************/ |
| 97 | |
Aaron Durbin | e58a24b | 2014-02-24 22:11:45 -0600 | [diff] [blame] | 98 | struct buffer_area { |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 99 | void *data; |
| 100 | size_t size; |
| 101 | }; |
| 102 | |
| 103 | struct payload { |
| 104 | const char *name; |
Aaron Durbin | e58a24b | 2014-02-24 22:11:45 -0600 | [diff] [blame] | 105 | struct buffer_area backing_store; |
| 106 | /* Used when payload wants memory coreboot ramstage is running at. */ |
| 107 | struct buffer_area bounce; |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 108 | void *entry; |
| 109 | }; |
| 110 | |
Aaron Durbin | ebf2ed4 | 2015-03-20 10:20:15 -0500 | [diff] [blame] | 111 | /* Load payload into memory in preparation to run. */ |
| 112 | void payload_load(void); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 113 | |
| 114 | /* Run the loaded payload. */ |
Aaron Durbin | ebf2ed4 | 2015-03-20 10:20:15 -0500 | [diff] [blame] | 115 | void payload_run(void); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 116 | |
Aaron Durbin | c34713d | 2014-02-25 20:36:56 -0600 | [diff] [blame] | 117 | /* Mirror the payload to be loaded. */ |
| 118 | void mirror_payload(struct payload *payload); |
| 119 | |
Aaron Durbin | 7d1996c | 2014-02-24 22:27:39 -0600 | [diff] [blame] | 120 | /* architecture specific function to run payload. */ |
| 121 | void arch_payload_run(const struct payload *payload); |
| 122 | |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 123 | /* Payload loading operations. */ |
| 124 | struct payload_loader_ops { |
| 125 | const char *name; |
| 126 | /* |
| 127 | * Fill in payload_backing_store structure. Return 0 on success, < 0 |
| 128 | * on failure. |
| 129 | */ |
| 130 | int (*locate)(struct payload *payload); |
| 131 | }; |
| 132 | |
| 133 | /* Defined in src/lib/selfboot.c */ |
Aaron Durbin | ceebc05 | 2014-02-25 00:21:10 -0600 | [diff] [blame] | 134 | void *selfload(struct payload *payload); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 135 | |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 136 | |
| 137 | #endif /* PROGRAM_LOADING_H */ |