blob: 981bd7b557317a48545d7a3251cc0222fb984fd2 [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
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Aaron Durbinbdf913a2014-02-24 14:56:34 -060019 */
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 {
Aaron Durbin17200ad2015-05-01 16:48:54 -050042 PROG_VERSTAGE,
Aaron Durbin3948e532015-03-20 13:00:20 -050043 PROG_ROMSTAGE,
44 PROG_RAMSTAGE,
45 PROG_PAYLOAD,
46};
47
48/* Representation of a program. */
49struct prog {
50 enum prog_type type;
51 const char *name;
52 /* The area can mean different things depending on what type the
53 * program is. e.g. a payload prog uses this field for the backing
Aaron Durbince9efe02015-03-20 16:37:12 -050054 * store of the payload_segments and data. After loading the segments
55 * area is updated to reflect the bounce buffer used. */
Aaron Durbin3948e532015-03-20 13:00:20 -050056 struct buffer_area area;
57 /* Entry to program with optional argument. It's up to the architecture
58 * to decide if argument is passed. */
59 void (*entry)(void *);
60 void *arg;
61};
62
63static inline size_t prog_size(const struct prog *prog)
64{
65 return prog->area.size;
66}
67
68static inline void *prog_start(const struct prog *prog)
69{
70 return prog->area.data;
71}
72
73static inline void *prog_entry(const struct prog *prog)
74{
75 return prog->entry;
76}
77
78static inline void *prog_entry_arg(const struct prog *prog)
79{
80 return prog->arg;
81}
82
83static inline void prog_set_area(struct prog *prog, void *start, size_t size)
84{
85 prog->area.data = start;
86 prog->area.size = size;
87}
88
89static inline void prog_set_entry(struct prog *prog, void *e, void *arg)
90{
91 prog->entry = e;
92 prog->arg = arg;
93}
94
Aaron Durbinb3847e62015-03-20 15:55:08 -050095/* Run the program described by prog. */
96void prog_run(struct prog *prog);
97/* Per architecture implementation running a program. */
98void arch_prog_run(struct prog *prog);
99/* Platform (SoC/chipset) specific overrides for running a program. This is
100 * called prior to calling the arch_prog_run. Thus, if there is anything
101 * special that needs to be done by the platform similar to the architecture
102 * code it needs to that as well. */
103void platform_prog_run(struct prog *prog);
104
Aaron Durbince9efe02015-03-20 16:37:12 -0500105struct prog_loader_ops {
106 const char *name;
Aaron Durbin5e8286b2015-04-28 15:59:12 -0500107 /* Determine if the loader is the active one. If so returns 1 else 0
108 * or < 0 on error. */
109 int (*is_loader_active)(struct prog *prog);
Aaron Durbince9efe02015-03-20 16:37:12 -0500110 /* Returns < 0 on error or 0 on success. This function needs to do
111 * different things depending on the prog type. See definition
112 * of struct prog above. */
113 int (*prepare)(struct prog *prog);
114};
115
Aaron Durbind1b0e872015-03-17 13:17:06 -0500116/************************
117 * ROMSTAGE LOADING *
118 ************************/
119
120/* Run romstage from bootblock. */
121void run_romstage(void);
Aaron Durbin04654a22015-03-17 11:43:44 -0500122
123/************************
124 * RAMSTAGE LOADING *
125 ************************/
126
Aaron Durbince9efe02015-03-20 16:37:12 -0500127/* Run ramstage from romstage. */
128void run_ramstage(void);
129
Aaron Durbinbd74a4b2015-03-06 23:17:33 -0600130/* Called when the stage cache couldn't load ramstage on resume. */
131void ramstage_cache_invalid(void);
Aaron Durbinfcfdff82015-03-20 10:58:41 -0500132
Aaron Durbin04654a22015-03-17 11:43:44 -0500133/***********************
134 * PAYLOAD LOADING *
135 ***********************/
136
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500137/* Load payload into memory in preparation to run. */
138void payload_load(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600139
140/* Run the loaded payload. */
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500141void payload_run(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600142
Aaron Durbinc34713d2014-02-25 20:36:56 -0600143/* Mirror the payload to be loaded. */
Aaron Durbince9efe02015-03-20 16:37:12 -0500144void mirror_payload(struct prog *payload);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600145
146/* Defined in src/lib/selfboot.c */
Aaron Durbince9efe02015-03-20 16:37:12 -0500147void *selfload(struct prog *payload);
Aaron Durbin04654a22015-03-17 11:43:44 -0500148
149#endif /* PROGRAM_LOADING_H */