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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 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> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 25 | #include <region.h> |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 26 | |
Aaron Durbin | 6e76fff | 2015-03-20 09:42:05 -0500 | [diff] [blame] | 27 | enum { |
| 28 | /* Last segment of program. Can be used to take different actions for |
| 29 | * cache maintenance of a program load. */ |
| 30 | SEG_FINAL = 1 << 0, |
| 31 | }; |
Ionela Voinescu | 00903e5 | 2015-01-09 13:14:20 +0000 | [diff] [blame] | 32 | |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 33 | /* 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] | 34 | * set on the last segment loaded. */ |
| 35 | void arch_segment_loaded(uintptr_t start, size_t size, int flags); |
Ionela Voinescu | 00903e5 | 2015-01-09 13:14:20 +0000 | [diff] [blame] | 36 | |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 37 | struct buffer_area { |
| 38 | void *data; |
| 39 | size_t size; |
| 40 | }; |
| 41 | |
| 42 | enum prog_type { |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 43 | PROG_VERSTAGE, |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 44 | PROG_ROMSTAGE, |
| 45 | PROG_RAMSTAGE, |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 46 | PROG_REFCODE, |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 47 | PROG_PAYLOAD, |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 48 | PROG_BL31, |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /* Representation of a program. */ |
| 52 | struct prog { |
| 53 | enum prog_type type; |
| 54 | const char *name; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 55 | /* Source of program content to load. */ |
| 56 | struct region_device rdev; |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 57 | /* The area can mean different things depending on what type the |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 58 | * program is. A stage after being loaded reflects the memory occupied |
| 59 | * by the program, Since payloads are multi-segment one can't express |
| 60 | * the memory layout with one range. Instead this field is updated |
| 61 | * to reflect the bounce buffer used. */ |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 62 | struct buffer_area area; |
| 63 | /* Entry to program with optional argument. It's up to the architecture |
| 64 | * to decide if argument is passed. */ |
| 65 | void (*entry)(void *); |
| 66 | void *arg; |
| 67 | }; |
| 68 | |
| 69 | static inline size_t prog_size(const struct prog *prog) |
| 70 | { |
| 71 | return prog->area.size; |
| 72 | } |
| 73 | |
| 74 | static inline void *prog_start(const struct prog *prog) |
| 75 | { |
| 76 | return prog->area.data; |
| 77 | } |
| 78 | |
| 79 | static inline void *prog_entry(const struct prog *prog) |
| 80 | { |
| 81 | return prog->entry; |
| 82 | } |
| 83 | |
| 84 | static inline void *prog_entry_arg(const struct prog *prog) |
| 85 | { |
| 86 | return prog->arg; |
| 87 | } |
| 88 | |
| 89 | static inline void prog_set_area(struct prog *prog, void *start, size_t size) |
| 90 | { |
| 91 | prog->area.data = start; |
| 92 | prog->area.size = size; |
| 93 | } |
| 94 | |
| 95 | static inline void prog_set_entry(struct prog *prog, void *e, void *arg) |
| 96 | { |
| 97 | prog->entry = e; |
| 98 | prog->arg = arg; |
| 99 | } |
| 100 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 101 | /* Locate the identified program to run. Return 0 on success. < 0 on error. */ |
| 102 | int prog_locate(struct prog *prog); |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 103 | /* Run the program described by prog. */ |
| 104 | void prog_run(struct prog *prog); |
| 105 | /* Per architecture implementation running a program. */ |
| 106 | void arch_prog_run(struct prog *prog); |
| 107 | /* Platform (SoC/chipset) specific overrides for running a program. This is |
| 108 | * called prior to calling the arch_prog_run. Thus, if there is anything |
| 109 | * special that needs to be done by the platform similar to the architecture |
| 110 | * code it needs to that as well. */ |
| 111 | void platform_prog_run(struct prog *prog); |
| 112 | |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame] | 113 | struct prog_loader_ops { |
| 114 | const char *name; |
Aaron Durbin | 5e8286b | 2015-04-28 15:59:12 -0500 | [diff] [blame] | 115 | /* Determine if the loader is the active one. If so returns 1 else 0 |
| 116 | * or < 0 on error. */ |
| 117 | int (*is_loader_active)(struct prog *prog); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 118 | /* Returns < 0 on error or 0 on success. This function locates |
| 119 | * the rdev representing the file data associated with the passed in |
| 120 | * prog. */ |
| 121 | int (*locate)(struct prog *prog); |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
Aaron Durbin | d1b0e87 | 2015-03-17 13:17:06 -0500 | [diff] [blame] | 124 | /************************ |
| 125 | * ROMSTAGE LOADING * |
| 126 | ************************/ |
| 127 | |
| 128 | /* Run romstage from bootblock. */ |
| 129 | void run_romstage(void); |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 130 | |
| 131 | /************************ |
| 132 | * RAMSTAGE LOADING * |
| 133 | ************************/ |
| 134 | |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame] | 135 | /* Run ramstage from romstage. */ |
| 136 | void run_ramstage(void); |
| 137 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 138 | /* Called when the stage cache couldn't load ramstage on resume. */ |
| 139 | void ramstage_cache_invalid(void); |
Aaron Durbin | fcfdff8 | 2015-03-20 10:58:41 -0500 | [diff] [blame] | 140 | |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 141 | /*********************** |
| 142 | * PAYLOAD LOADING * |
| 143 | ***********************/ |
| 144 | |
Aaron Durbin | ebf2ed4 | 2015-03-20 10:20:15 -0500 | [diff] [blame] | 145 | /* Load payload into memory in preparation to run. */ |
| 146 | void payload_load(void); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 147 | |
| 148 | /* Run the loaded payload. */ |
Aaron Durbin | ebf2ed4 | 2015-03-20 10:20:15 -0500 | [diff] [blame] | 149 | void payload_run(void); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 150 | |
Aaron Durbin | c34713d | 2014-02-25 20:36:56 -0600 | [diff] [blame] | 151 | /* Mirror the payload to be loaded. */ |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame] | 152 | void mirror_payload(struct prog *payload); |
Aaron Durbin | bdf913a | 2014-02-24 14:56:34 -0600 | [diff] [blame] | 153 | |
| 154 | /* Defined in src/lib/selfboot.c */ |
Aaron Durbin | ce9efe0 | 2015-03-20 16:37:12 -0500 | [diff] [blame] | 155 | void *selfload(struct prog *payload); |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 156 | |
| 157 | #endif /* PROGRAM_LOADING_H */ |