blob: 269988777f06470e9967b709b0b67e078ceaca91 [file] [log] [blame]
Aaron Durbinbdf913a2014-02-24 14:56:34 -06001/*
2 * This file is part of the coreboot project.
3 *
Aaron Durbin04654a22015-03-17 11:43:44 -05004 * Copyright 2015 Google Inc.
Ionela Voinescu00903e52015-01-09 13:14:20 +00005 * Copyright (C) 2014 Imagination Technologies
Aaron Durbinbdf913a2014-02-24 14:56:34 -06006 *
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 Durbin04654a22015-03-17 11:43:44 -050020#ifndef PROGRAM_LOADING_H
21#define PROGRAM_LOADING_H
Aaron Durbinbdf913a2014-02-24 14:56:34 -060022
23#include <stdint.h>
24#include <stddef.h>
25
Aaron Durbin6e76fff2015-03-20 09:42:05 -050026enum {
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 Voinescu00903e52015-01-09 13:14:20 +000031
Aaron Durbin3948e532015-03-20 13:00:20 -050032/* Called for each segment of a program loaded. The SEG_FINAL flag will be
Aaron Durbin6e76fff2015-03-20 09:42:05 -050033 * set on the last segment loaded. */
34void arch_segment_loaded(uintptr_t start, size_t size, int flags);
Ionela Voinescu00903e52015-01-09 13:14:20 +000035
Aaron Durbin3948e532015-03-20 13:00:20 -050036struct buffer_area {
37 void *data;
38 size_t size;
39};
40
41enum prog_type {
42 PROG_ROMSTAGE,
43 PROG_RAMSTAGE,
44 PROG_PAYLOAD,
45};
46
47/* Representation of a program. */
48struct 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 Durbince9efe02015-03-20 16:37:12 -050053 * store of the payload_segments and data. After loading the segments
54 * area is updated to reflect the bounce buffer used. */
Aaron Durbin3948e532015-03-20 13:00:20 -050055 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
62static inline size_t prog_size(const struct prog *prog)
63{
64 return prog->area.size;
65}
66
67static inline void *prog_start(const struct prog *prog)
68{
69 return prog->area.data;
70}
71
72static inline void *prog_entry(const struct prog *prog)
73{
74 return prog->entry;
75}
76
77static inline void *prog_entry_arg(const struct prog *prog)
78{
79 return prog->arg;
80}
81
82static 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
88static inline void prog_set_entry(struct prog *prog, void *e, void *arg)
89{
90 prog->entry = e;
91 prog->arg = arg;
92}
93
Aaron Durbinb3847e62015-03-20 15:55:08 -050094/* Run the program described by prog. */
95void prog_run(struct prog *prog);
96/* Per architecture implementation running a program. */
97void 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. */
102void platform_prog_run(struct prog *prog);
103
Aaron Durbince9efe02015-03-20 16:37:12 -0500104struct 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 Durbind1b0e872015-03-17 13:17:06 -0500112/************************
113 * ROMSTAGE LOADING *
114 ************************/
115
116/* Run romstage from bootblock. */
117void run_romstage(void);
Aaron Durbin04654a22015-03-17 11:43:44 -0500118
119/************************
120 * RAMSTAGE LOADING *
121 ************************/
122
Aaron Durbince9efe02015-03-20 16:37:12 -0500123/* Run ramstage from romstage. */
124void run_ramstage(void);
125
Aaron Durbinfcfdff82015-03-20 10:58:41 -0500126struct romstage_handoff;
Aaron Durbin3948e532015-03-20 13:00:20 -0500127#if IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)
128/* Cache the loaded ramstage described by prog. */
129void cache_loaded_ramstage(struct romstage_handoff *, struct prog *p);
130/* Load ramstage from cache filling in struct prog. */
131void load_cached_ramstage(struct romstage_handoff *h, struct prog *p);
132#else
133static inline void cache_loaded_ramstage(struct romstage_handoff *h,
134 struct prog *p) {}
135static inline void load_cached_ramstage(struct romstage_handoff *h,
136 struct prog *p) {}
137#endif
Aaron Durbinfcfdff82015-03-20 10:58:41 -0500138
Aaron Durbin04654a22015-03-17 11:43:44 -0500139/***********************
140 * PAYLOAD LOADING *
141 ***********************/
142
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500143/* Load payload into memory in preparation to run. */
144void payload_load(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600145
146/* Run the loaded payload. */
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500147void payload_run(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600148
Aaron Durbinc34713d2014-02-25 20:36:56 -0600149/* Mirror the payload to be loaded. */
Aaron Durbince9efe02015-03-20 16:37:12 -0500150void mirror_payload(struct prog *payload);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600151
152/* Defined in src/lib/selfboot.c */
Aaron Durbince9efe02015-03-20 16:37:12 -0500153void *selfload(struct prog *payload);
Aaron Durbin04654a22015-03-17 11:43:44 -0500154
155#endif /* PROGRAM_LOADING_H */