blob: e071db972938e7024b304b09c09a52fafe4bca07 [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
Ionela Voinescu00903e52015-01-09 13:14:20 +000026/* For each segment of a program loaded this function is called*/
27void arch_program_segment_loaded(uintptr_t start, size_t size);
28
29/* Upon completion of loading a program this function is called */
30void arch_program_loaded(void);
31
Aaron Durbind1b0e872015-03-17 13:17:06 -050032/************************
33 * ROMSTAGE LOADING *
34 ************************/
35
36/* Run romstage from bootblock. */
37void run_romstage(void);
Aaron Durbin04654a22015-03-17 11:43:44 -050038
39/************************
40 * RAMSTAGE LOADING *
41 ************************/
42
Aaron Durbinfcfdff82015-03-20 10:58:41 -050043struct romstage_handoff;
Aaron Durbin04654a22015-03-17 11:43:44 -050044struct cbmem_entry;
45
Aaron Durbinfcfdff82015-03-20 10:58:41 -050046#if defined(__PRE_RAM__)
47#if CONFIG_RELOCATABLE_RAMSTAGE
48/* The cache_loaded_ramstage() and load_cached_ramstage() functions are defined
49 * to be weak so that board and chipset code may override them. Their job is to
50 * cache and load the ramstage for quick S3 resume. By default a copy of the
51 * relocated ramstage is saved using the cbmem infrastructure. These
52 * functions are only valid during romstage. */
53
54/* The implementer of cache_loaded_ramstage() may use the romstage_handoff
55 * structure to store information, but note that the handoff variable can be
56 * NULL. The ramstage cbmem_entry represents the region occupied by the loaded
57 * ramstage. */
58void cache_loaded_ramstage(struct romstage_handoff *handoff,
59 const struct cbmem_entry *ramstage, void *entry_point);
60/* Return NULL on error or entry point on success. The ramstage cbmem_entry is
61 * the region where to load the cached contents to. */
62void * load_cached_ramstage(struct romstage_handoff *handoff,
63 const struct cbmem_entry *ramstage);
64#else /* CONFIG_RELOCATABLE_RAMSTAGE */
65
66static inline void cache_loaded_ramstage(struct romstage_handoff *handoff,
67 const struct cbmem_entry *ramstage, void *entry_point)
68{
69}
70
71static inline void *
72load_cached_ramstage(struct romstage_handoff *handoff,
73 const struct cbmem_entry *ramstage)
74{
75 return NULL;
76}
77
78#endif /* CONFIG_RELOCATABLE_RAMSTAGE */
79#endif /* defined(__PRE_RAM__) */
80
Aaron Durbin04654a22015-03-17 11:43:44 -050081/* Run ramstage from romstage. */
82void run_ramstage(void);
83
84struct ramstage_loader_ops {
85 const char *name;
86 void *(*load)(uint32_t cbmem_id, const char *name,
87 const struct cbmem_entry **cbmem_entry);
88};
89
90/***********************
91 * PAYLOAD LOADING *
92 ***********************/
93
Aaron Durbine58a24b2014-02-24 22:11:45 -060094struct buffer_area {
Aaron Durbinbdf913a2014-02-24 14:56:34 -060095 void *data;
96 size_t size;
97};
98
99struct payload {
100 const char *name;
Aaron Durbine58a24b2014-02-24 22:11:45 -0600101 struct buffer_area backing_store;
102 /* Used when payload wants memory coreboot ramstage is running at. */
103 struct buffer_area bounce;
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600104 void *entry;
105};
106
107/*
108 * Load payload into memory and return pointer to payload structure. Returns
109 * NULL on error.
110 */
111struct payload *payload_load(void);
112
113/* Run the loaded payload. */
114void payload_run(const struct payload *payload);
115
Aaron Durbinc34713d2014-02-25 20:36:56 -0600116/* Mirror the payload to be loaded. */
117void mirror_payload(struct payload *payload);
118
Aaron Durbin7d1996c2014-02-24 22:27:39 -0600119/* architecture specific function to run payload. */
120void arch_payload_run(const struct payload *payload);
121
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600122/* Payload loading operations. */
123struct payload_loader_ops {
124 const char *name;
125 /*
126 * Fill in payload_backing_store structure. Return 0 on success, < 0
127 * on failure.
128 */
129 int (*locate)(struct payload *payload);
130};
131
132/* Defined in src/lib/selfboot.c */
Aaron Durbinceebc052014-02-25 00:21:10 -0600133void *selfload(struct payload *payload);
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600134
Aaron Durbin04654a22015-03-17 11:43:44 -0500135
136#endif /* PROGRAM_LOADING_H */