loading: move ramstage cache function declarations
[coreboot.git] / src / include / program_loading.h
blobe071db972938e7024b304b09c09a52fafe4bca07
1 /*
2 * This file is part of the coreboot project.
4 * Copyright 2015 Google Inc.
5 * Copyright (C) 2014 Imagination Technologies
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.
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.
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
20 #ifndef PROGRAM_LOADING_H
21 #define PROGRAM_LOADING_H
23 #include <stdint.h>
24 #include <stddef.h>
26 /* For each segment of a program loaded this function is called*/
27 void arch_program_segment_loaded(uintptr_t start, size_t size);
29 /* Upon completion of loading a program this function is called */
30 void arch_program_loaded(void);
32 /************************
33 * ROMSTAGE LOADING *
34 ************************/
36 /* Run romstage from bootblock. */
37 void run_romstage(void);
39 /************************
40 * RAMSTAGE LOADING *
41 ************************/
43 struct romstage_handoff;
44 struct cbmem_entry;
46 #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. */
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. */
58 void 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. */
62 void * load_cached_ramstage(struct romstage_handoff *handoff,
63 const struct cbmem_entry *ramstage);
64 #else /* CONFIG_RELOCATABLE_RAMSTAGE */
66 static inline void cache_loaded_ramstage(struct romstage_handoff *handoff,
67 const struct cbmem_entry *ramstage, void *entry_point)
71 static inline void *
72 load_cached_ramstage(struct romstage_handoff *handoff,
73 const struct cbmem_entry *ramstage)
75 return NULL;
78 #endif /* CONFIG_RELOCATABLE_RAMSTAGE */
79 #endif /* defined(__PRE_RAM__) */
81 /* Run ramstage from romstage. */
82 void run_ramstage(void);
84 struct ramstage_loader_ops {
85 const char *name;
86 void *(*load)(uint32_t cbmem_id, const char *name,
87 const struct cbmem_entry **cbmem_entry);
90 /***********************
91 * PAYLOAD LOADING *
92 ***********************/
94 struct buffer_area {
95 void *data;
96 size_t size;
99 struct payload {
100 const char *name;
101 struct buffer_area backing_store;
102 /* Used when payload wants memory coreboot ramstage is running at. */
103 struct buffer_area bounce;
104 void *entry;
108 * Load payload into memory and return pointer to payload structure. Returns
109 * NULL on error.
111 struct payload *payload_load(void);
113 /* Run the loaded payload. */
114 void payload_run(const struct payload *payload);
116 /* Mirror the payload to be loaded. */
117 void mirror_payload(struct payload *payload);
119 /* architecture specific function to run payload. */
120 void arch_payload_run(const struct payload *payload);
122 /* Payload loading operations. */
123 struct payload_loader_ops {
124 const char *name;
126 * Fill in payload_backing_store structure. Return 0 on success, < 0
127 * on failure.
129 int (*locate)(struct payload *payload);
132 /* Defined in src/lib/selfboot.c */
133 void *selfload(struct payload *payload);
136 #endif /* PROGRAM_LOADING_H */