1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <program_loading.h>
6 #include <arch/encoding.h>
7 #include <arch/smp/smp.h>
10 #include <console/console.h>
12 struct arch_prog_run_args
{
18 * A pointer to the Flattened Device Tree passed to coreboot by the boot ROM.
19 * Presumably this FDT is also in ROM.
21 * This pointer is only used in ramstage!
24 static void do_arch_prog_run(struct arch_prog_run_args
*args
)
26 int hart_id
= HLS()->hart_id
;
27 struct prog
*prog
= args
->prog
;
28 void *fdt
= HLS()->fdt
;
30 if (prog_cbfs_type(prog
) == CBFS_TYPE_FIT_PAYLOAD
)
31 fdt
= prog_entry_arg(prog
);
33 if (ENV_RAMSTAGE
&& prog_type(prog
) == PROG_PAYLOAD
) {
34 if (CONFIG(RISCV_OPENSBI
)) {
35 // tell OpenSBI to switch to Supervisor mode before jumping to payload
36 run_payload_opensbi(prog
, fdt
, args
->opensbi
, RISCV_PAYLOAD_MODE_S
);
38 run_payload(prog
, fdt
, RISCV_PAYLOAD_MODE_S
);
41 void (*doit
)(int hart_id
, void *fdt
, void *arg
) = prog_entry(prog
);
42 doit(hart_id
, fdt
, prog_entry_arg(prog
));
45 die("Failed to run stage");
48 void arch_prog_run(struct prog
*prog
)
50 struct arch_prog_run_args args
= {};
54 /* In case of OpenSBI we have to load it before resuming all HARTs */
55 if (ENV_RAMSTAGE
&& CONFIG(RISCV_OPENSBI
)) {
56 struct prog sbi
= PROG_INIT(PROG_OPENSBI
, CONFIG_CBFS_PREFIX
"/opensbi");
58 if (!selfload_check(&sbi
, BM_MEM_OPENSBI
))
59 die("OpenSBI load failed");
64 smp_resume((void (*)(void *))do_arch_prog_run
, &args
);