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 #ifndef PROGRAM_LOADING_H
17 #define PROGRAM_LOADING_H
24 /* Last segment of program. Can be used to take different actions for
25 * cache maintenance of a program load. */
29 /* Called for each segment of a program loaded. The SEG_FINAL flag will be
30 * set on the last segment loaded. */
31 void arch_segment_loaded(uintptr_t start
, size_t size
, int flags
);
33 /* Representation of a program. */
35 /* The region_device within the asset is the source of program content
36 * to load. After loading program it represents the memory region of
37 * the stages and payload. For architectures that use a bounce buffer
38 * then it would represent the bounce buffer. */
40 /* Entry to program with optional argument. It's up to the architecture
41 * to decide if argument is passed. */
42 void (*entry
)(void *);
46 #define PROG_INIT(type_, name_) \
48 .asset = ASSET_INIT(type_, name_), \
51 static inline const char *prog_name(const struct prog
*prog
)
53 return asset_name(&prog
->asset
);
56 static inline enum asset_type
prog_type(const struct prog
*prog
)
58 return asset_type(&prog
->asset
);
61 static inline struct region_device
*prog_rdev(struct prog
*prog
)
63 return asset_rdev(&prog
->asset
);
66 /* Only valid for loaded programs. */
67 static inline size_t prog_size(const struct prog
*prog
)
69 return asset_size(&prog
->asset
);
72 /* Only valid for loaded programs. */
73 static inline void *prog_start(const struct prog
*prog
)
75 return asset_mmap(&prog
->asset
);
78 static inline void *prog_entry(const struct prog
*prog
)
83 static inline void *prog_entry_arg(const struct prog
*prog
)
88 /* region_device representing the 32-bit flat address space. */
89 extern const struct mem_region_device addrspace_32bit
;
91 static inline void prog_memory_init(struct prog
*prog
, uintptr_t ptr
,
94 rdev_chain(&prog
->asset
.rdev
, &addrspace_32bit
.rdev
, ptr
, size
);
97 static inline void prog_set_area(struct prog
*prog
, void *start
, size_t size
)
99 prog_memory_init(prog
, (uintptr_t)start
, size
);
102 static inline void prog_set_entry(struct prog
*prog
, void *e
, void *arg
)
108 /* Locate the identified program to run. Return 0 on success. < 0 on error. */
109 static inline int prog_locate(struct prog
*prog
)
111 return asset_locate(&prog
->asset
);
114 /* Run the program described by prog. */
115 void prog_run(struct prog
*prog
);
116 /* Per architecture implementation running a program. */
117 void arch_prog_run(struct prog
*prog
);
118 /* Platform (SoC/chipset) specific overrides for running a program. This is
119 * called prior to calling the arch_prog_run. Thus, if there is anything
120 * special that needs to be done by the platform similar to the architecture
121 * code it needs to that as well. */
122 void platform_prog_run(struct prog
*prog
);
124 struct prog_loader_ops
{
126 /* Determine if the loader is the active one. If so returns 1 else 0
127 * or < 0 on error. */
128 int (*is_loader_active
)(struct prog
*prog
);
129 /* Returns < 0 on error or 0 on success. This function locates
130 * the rdev representing the file data associated with the passed in
132 int (*locate
)(struct prog
*prog
);
135 /************************
137 ************************/
139 /* Run romstage from bootblock. */
140 void run_romstage(void);
142 /************************
144 ************************/
146 /* Run ramstage from romstage. */
147 void run_ramstage(void);
149 /* Called when the stage cache couldn't load ramstage on resume. */
150 void ramstage_cache_invalid(void);
152 /***********************
154 ***********************/
156 /* Load payload into memory in preparation to run. */
157 void payload_load(void);
159 /* Run the loaded payload. */
160 void payload_run(void);
162 /* Mirror the payload to be loaded. */
163 void mirror_payload(struct prog
*payload
);
165 /* Defined in src/lib/selfboot.c */
166 void *selfload(struct prog
*payload
);
168 #endif /* PROGRAM_LOADING_H */