blob: 38047c74ddc548ab3e3773e6ffc0b1f1643cf56a [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
53 * store of the payload_segments and data. */
54 struct buffer_area area;
55 /* Entry to program with optional argument. It's up to the architecture
56 * to decide if argument is passed. */
57 void (*entry)(void *);
58 void *arg;
59};
60
61static inline size_t prog_size(const struct prog *prog)
62{
63 return prog->area.size;
64}
65
66static inline void *prog_start(const struct prog *prog)
67{
68 return prog->area.data;
69}
70
71static inline void *prog_entry(const struct prog *prog)
72{
73 return prog->entry;
74}
75
76static inline void *prog_entry_arg(const struct prog *prog)
77{
78 return prog->arg;
79}
80
81static inline void prog_set_area(struct prog *prog, void *start, size_t size)
82{
83 prog->area.data = start;
84 prog->area.size = size;
85}
86
87static inline void prog_set_entry(struct prog *prog, void *e, void *arg)
88{
89 prog->entry = e;
90 prog->arg = arg;
91}
92
Aaron Durbind1b0e872015-03-17 13:17:06 -050093/************************
94 * ROMSTAGE LOADING *
95 ************************/
96
97/* Run romstage from bootblock. */
98void run_romstage(void);
Aaron Durbin04654a22015-03-17 11:43:44 -050099
100/************************
101 * RAMSTAGE LOADING *
102 ************************/
103
Aaron Durbinfcfdff82015-03-20 10:58:41 -0500104struct romstage_handoff;
Aaron Durbin3948e532015-03-20 13:00:20 -0500105#if IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)
106/* Cache the loaded ramstage described by prog. */
107void cache_loaded_ramstage(struct romstage_handoff *, struct prog *p);
108/* Load ramstage from cache filling in struct prog. */
109void load_cached_ramstage(struct romstage_handoff *h, struct prog *p);
110#else
111static inline void cache_loaded_ramstage(struct romstage_handoff *h,
112 struct prog *p) {}
113static inline void load_cached_ramstage(struct romstage_handoff *h,
114 struct prog *p) {}
115#endif
Aaron Durbinfcfdff82015-03-20 10:58:41 -0500116
Aaron Durbin04654a22015-03-17 11:43:44 -0500117/* Run ramstage from romstage. */
118void run_ramstage(void);
119
120struct ramstage_loader_ops {
121 const char *name;
Aaron Durbin3948e532015-03-20 13:00:20 -0500122 /* Returns 0 on succes. < 0 on error. */
123 int (*load)(struct prog *ramstage);
Aaron Durbin04654a22015-03-17 11:43:44 -0500124};
125
126/***********************
127 * PAYLOAD LOADING *
128 ***********************/
129
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600130struct payload {
Aaron Durbin3948e532015-03-20 13:00:20 -0500131 struct prog prog;
Aaron Durbine58a24b2014-02-24 22:11:45 -0600132 /* Used when payload wants memory coreboot ramstage is running at. */
133 struct buffer_area bounce;
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600134};
135
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500136/* Load payload into memory in preparation to run. */
137void payload_load(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600138
139/* Run the loaded payload. */
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500140void payload_run(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600141
Aaron Durbinc34713d2014-02-25 20:36:56 -0600142/* Mirror the payload to be loaded. */
143void mirror_payload(struct payload *payload);
144
Aaron Durbin7d1996c2014-02-24 22:27:39 -0600145/* architecture specific function to run payload. */
146void arch_payload_run(const struct payload *payload);
147
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600148/* Payload loading operations. */
149struct payload_loader_ops {
150 const char *name;
151 /*
152 * Fill in payload_backing_store structure. Return 0 on success, < 0
153 * on failure.
154 */
155 int (*locate)(struct payload *payload);
156};
157
158/* Defined in src/lib/selfboot.c */
Aaron Durbinceebc052014-02-25 00:21:10 -0600159void *selfload(struct payload *payload);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600160
Aaron Durbin04654a22015-03-17 11:43:44 -0500161
162#endif /* PROGRAM_LOADING_H */