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 | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 32 | /* Called for each segment of a program loaded. The SEG_FINAL flag will be |
Aaron Durbin | 6e76fff | 2015-03-20 09:42:05 -0500 | [diff] [blame] | 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 | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 36 | struct buffer_area { |
| 37 | void *data; |
| 38 | size_t size; |
| 39 | }; |
| 40 | |
| 41 | enum prog_type { |
| 42 | PROG_ROMSTAGE, |
| 43 | PROG_RAMSTAGE, |
| 44 | PROG_PAYLOAD, |
| 45 | }; |
| 46 | |
| 47 | /* Representation of a program. */ |
| 48 | struct prog { |
| 49 | enum prog_type type; |
| 50 | const char *name; |
| 51 | /* The area can mean different things depending on what type the |
| 52 | * program is. e.g. a payload prog uses this field for the backing |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame^] | 53 | * store of the payload_segments and data. After loading the segments |
| 54 | * area is updated to reflect the bounce buffer used. */ |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 55 | struct buffer_area area; |
| 56 | /* Entry to program with optional argument. It's up to the architecture |
| 57 | * to decide if argument is passed. */ |
| 58 | void (*entry)(void *); |
| 59 | void *arg; |
| 60 | }; |
| 61 | |
| 62 | static inline size_t prog_size(const struct prog *prog) |
| 63 | { |
| 64 | return prog->area.size; |
| 65 | } |
| 66 | |
| 67 | static inline void *prog_start(const struct prog *prog) |
| 68 | { |
| 69 | return prog->area.data; |
| 70 | } |
| 71 | |
| 72 | static inline void *prog_entry(const struct prog *prog) |
| 73 | { |
| 74 | return prog->entry; |
| 75 | } |
| 76 | |
| 77 | static inline void *prog_entry_arg(const struct prog *prog) |
| 78 | { |
| 79 | return prog->arg; |
| 80 | } |
| 81 | |
| 82 | static inline void prog_set_area(struct prog *prog, void *start, size_t size) |
| 83 | { |
| 84 | prog->area.data = start; |
| 85 | prog->area.size = size; |
| 86 | } |
| 87 | |
| 88 | static inline void prog_set_entry(struct prog *prog, void *e, void *arg) |
| 89 | { |
| 90 | prog->entry = e; |
| 91 | prog->arg = arg; |
| 92 | } |
| 93 | |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 94 | /* Run the program described by prog. */ |
| 95 | void prog_run(struct prog *prog); |
| 96 | /* Per architecture implementation running a program. */ |
| 97 | void arch_prog_run(struct prog *prog); |
| 98 | /* Platform (SoC/chipset) specific overrides for running a program. This is |
| 99 | * called prior to calling the arch_prog_run. Thus, if there is anything |
| 100 | * special that needs to be done by the platform similar to the architecture |
| 101 | * code it needs to that as well. */ |
| 102 | void platform_prog_run(struct prog *prog); |
| 103 | |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame^] | 104 | struct prog_loader_ops { |
| 105 | const char *name; |
| 106 | /* Returns < 0 on error or 0 on success. This function needs to do |
| 107 | * different things depending on the prog type. See definition |
| 108 | * of struct prog above. */ |
| 109 | int (*prepare)(struct prog *prog); |
| 110 | }; |
| 111 | |
Aaron Durbin | d1b0e87 | 2015-03-17 13:17:06 -0500 | [diff] [blame] | 112 | /************************ |
| 113 | * ROMSTAGE LOADING * |
| 114 | ************************/ |
| 115 | |
| 116 | /* Run romstage from bootblock. */ |
| 117 | void run_romstage(void); |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 118 | |
| 119 | /************************ |
| 120 | * RAMSTAGE LOADING * |
| 121 | ************************/ |
| 122 | |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame^] | 123 | /* Run ramstage from romstage. */ |
| 124 | void run_ramstage(void); |
| 125 | |
Aaron Durbin | fcfdff8 | 2015-03-20 10:58:41 -0500 | [diff] [blame] | 126 | struct romstage_handoff; |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 127 | #if IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE) |
| 128 | /* Cache the loaded ramstage described by prog. */ |
| 129 | void cache_loaded_ramstage(struct romstage_handoff *, struct prog *p); |
| 130 | /* Load ramstage from cache filling in struct prog. */ |
| 131 | void load_cached_ramstage(struct romstage_handoff *h, struct prog *p); |
| 132 | #else |
| 133 | static inline void cache_loaded_ramstage(struct romstage_handoff *h, |
| 134 | struct prog *p) {} |
| 135 | static inline void load_cached_ramstage(struct romstage_handoff *h, |
| 136 | struct prog *p) {} |
| 137 | #endif |
Aaron Durbin | fcfdff8 | 2015-03-20 10:58:41 -0500 | [diff] [blame] | 138 | |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 139 | /*********************** |
| 140 | * PAYLOAD LOADING * |
| 141 | ***********************/ |
| 142 | |
Aaron Durbin | ebf2ed4 | 2015-03-20 10:20:15 -0500 | [diff] [blame] | 143 | /* Load payload into memory in preparation to run. */ |
| 144 | void payload_load(void); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 145 | |
| 146 | /* Run the loaded payload. */ |
Aaron Durbin | ebf2ed4 | 2015-03-20 10:20:15 -0500 | [diff] [blame] | 147 | void payload_run(void); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 148 | |
Aaron Durbin | c34713d | 2014-02-25 20:36:56 -0600 | [diff] [blame] | 149 | /* Mirror the payload to be loaded. */ |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame^] | 150 | void mirror_payload(struct prog *payload); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 151 | |
| 152 | /* Defined in src/lib/selfboot.c */ |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame^] | 153 | void *selfload(struct prog *payload); |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 154 | |
| 155 | #endif /* PROGRAM_LOADING_H */ |