blob: 85ccd3cd465944de85245763a7578d97b44549fa [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 Durbin6e76fff2015-03-20 09:42:05 -050032/* Called for each segment of a program loaded. The PROG_FLAG_FINAL will be
33 * 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 Durbind1b0e872015-03-17 13:17:06 -050036/************************
37 * ROMSTAGE LOADING *
38 ************************/
39
40/* Run romstage from bootblock. */
41void run_romstage(void);
Aaron Durbin04654a22015-03-17 11:43:44 -050042
43/************************
44 * RAMSTAGE LOADING *
45 ************************/
46
Aaron Durbinfcfdff82015-03-20 10:58:41 -050047struct romstage_handoff;
Aaron Durbin04654a22015-03-17 11:43:44 -050048struct cbmem_entry;
49
Aaron Durbinfcfdff82015-03-20 10:58:41 -050050#if defined(__PRE_RAM__)
51#if CONFIG_RELOCATABLE_RAMSTAGE
52/* The cache_loaded_ramstage() and load_cached_ramstage() functions are defined
53 * to be weak so that board and chipset code may override them. Their job is to
54 * cache and load the ramstage for quick S3 resume. By default a copy of the
55 * relocated ramstage is saved using the cbmem infrastructure. These
56 * functions are only valid during romstage. */
57
58/* The implementer of cache_loaded_ramstage() may use the romstage_handoff
59 * structure to store information, but note that the handoff variable can be
60 * NULL. The ramstage cbmem_entry represents the region occupied by the loaded
61 * ramstage. */
62void cache_loaded_ramstage(struct romstage_handoff *handoff,
63 const struct cbmem_entry *ramstage, void *entry_point);
64/* Return NULL on error or entry point on success. The ramstage cbmem_entry is
65 * the region where to load the cached contents to. */
66void * load_cached_ramstage(struct romstage_handoff *handoff,
67 const struct cbmem_entry *ramstage);
68#else /* CONFIG_RELOCATABLE_RAMSTAGE */
69
70static inline void cache_loaded_ramstage(struct romstage_handoff *handoff,
71 const struct cbmem_entry *ramstage, void *entry_point)
72{
73}
74
75static inline void *
76load_cached_ramstage(struct romstage_handoff *handoff,
77 const struct cbmem_entry *ramstage)
78{
79 return NULL;
80}
81
82#endif /* CONFIG_RELOCATABLE_RAMSTAGE */
83#endif /* defined(__PRE_RAM__) */
84
Aaron Durbin04654a22015-03-17 11:43:44 -050085/* Run ramstage from romstage. */
86void run_ramstage(void);
87
88struct ramstage_loader_ops {
89 const char *name;
90 void *(*load)(uint32_t cbmem_id, const char *name,
91 const struct cbmem_entry **cbmem_entry);
92};
93
94/***********************
95 * PAYLOAD LOADING *
96 ***********************/
97
Aaron Durbine58a24b2014-02-24 22:11:45 -060098struct buffer_area {
Aaron Durbinbdf913a2014-02-24 14:56:34 -060099 void *data;
100 size_t size;
101};
102
103struct payload {
104 const char *name;
Aaron Durbine58a24b2014-02-24 22:11:45 -0600105 struct buffer_area backing_store;
106 /* Used when payload wants memory coreboot ramstage is running at. */
107 struct buffer_area bounce;
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600108 void *entry;
109};
110
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500111/* Load payload into memory in preparation to run. */
112void payload_load(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600113
114/* Run the loaded payload. */
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500115void payload_run(void);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600116
Aaron Durbinc34713d2014-02-25 20:36:56 -0600117/* Mirror the payload to be loaded. */
118void mirror_payload(struct payload *payload);
119
Aaron Durbin7d1996c2014-02-24 22:27:39 -0600120/* architecture specific function to run payload. */
121void arch_payload_run(const struct payload *payload);
122
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600123/* Payload loading operations. */
124struct payload_loader_ops {
125 const char *name;
126 /*
127 * Fill in payload_backing_store structure. Return 0 on success, < 0
128 * on failure.
129 */
130 int (*locate)(struct payload *payload);
131};
132
133/* Defined in src/lib/selfboot.c */
Aaron Durbinceebc052014-02-25 00:21:10 -0600134void *selfload(struct payload *payload);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600135
Aaron Durbin04654a22015-03-17 11:43:44 -0500136
137#endif /* PROGRAM_LOADING_H */