Patrick Georgi | d1e50f9 | 2020-03-04 15:00:05 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 2 | |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 3 | #include <program_loading.h> |
Ronald G. Minnich | f47f5fb | 2015-09-22 15:53:32 -0700 | [diff] [blame] | 4 | #include <vm.h> |
Jonathan Neuschäfer | 042a833 | 2018-02-16 13:36:47 +0100 | [diff] [blame] | 5 | #include <arch/boot.h> |
Ronald G. Minnich | f47f5fb | 2015-09-22 15:53:32 -0700 | [diff] [blame] | 6 | #include <arch/encoding.h> |
Xiang Wang | 26f725e | 2018-10-11 17:42:49 +0800 | [diff] [blame] | 7 | #include <arch/smp/smp.h> |
Xiang Wang | 820dcfc | 2018-07-19 17:35:39 +0800 | [diff] [blame] | 8 | #include <mcall.h> |
Julius Werner | 98eeb96 | 2019-12-11 15:47:42 -0800 | [diff] [blame] | 9 | #include <cbfs.h> |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 10 | #include <console/console.h> |
| 11 | |
| 12 | struct arch_prog_run_args { |
| 13 | struct prog *prog; |
| 14 | struct prog *opensbi; |
| 15 | }; |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 16 | |
Jonathan Neuschäfer | 042a833 | 2018-02-16 13:36:47 +0100 | [diff] [blame] | 17 | /* |
| 18 | * A pointer to the Flattened Device Tree passed to coreboot by the boot ROM. |
| 19 | * Presumably this FDT is also in ROM. |
| 20 | * |
| 21 | * This pointer is only used in ramstage! |
| 22 | */ |
Jonathan Neuschäfer | 042a833 | 2018-02-16 13:36:47 +0100 | [diff] [blame] | 23 | |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 24 | static void do_arch_prog_run(struct arch_prog_run_args *args) |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 25 | { |
Arthur Heymans | 55069d1 | 2019-11-01 21:53:36 +0100 | [diff] [blame] | 26 | int hart_id = HLS()->hart_id; |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 27 | struct prog *prog = args->prog; |
Arthur Heymans | 763eeec | 2019-11-03 12:24:48 +0100 | [diff] [blame] | 28 | void *fdt = HLS()->fdt; |
Xiang Wang | 820dcfc | 2018-07-19 17:35:39 +0800 | [diff] [blame] | 29 | |
Julius Werner | 0057262 | 2022-05-26 20:29:42 -0700 | [diff] [blame^] | 30 | if (prog_cbfs_type(prog) == CBFS_TYPE_FIT_PAYLOAD) |
Arthur Heymans | 763eeec | 2019-11-03 12:24:48 +0100 | [diff] [blame] | 31 | fdt = prog_entry_arg(prog); |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 32 | |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 33 | if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) { |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 34 | if (CONFIG(RISCV_OPENSBI)) |
| 35 | run_payload_opensbi(prog, fdt, args->opensbi, RISCV_PAYLOAD_MODE_S); |
| 36 | else |
| 37 | run_payload(prog, fdt, RISCV_PAYLOAD_MODE_S); |
| 38 | } else { |
Arthur Heymans | 55069d1 | 2019-11-01 21:53:36 +0100 | [diff] [blame] | 39 | void (*doit)(int hart_id, void *fdt, void *arg) = prog_entry(prog); |
| 40 | doit(hart_id, fdt, prog_entry_arg(prog)); |
Ronald G. Minnich | f47f5fb | 2015-09-22 15:53:32 -0700 | [diff] [blame] | 41 | } |
Jonathan Neuschäfer | 455c3c9 | 2016-07-07 20:53:29 +0200 | [diff] [blame] | 42 | |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 43 | die("Failed to run stage"); |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 44 | } |
Xiang Wang | 26f725e | 2018-10-11 17:42:49 +0800 | [diff] [blame] | 45 | |
| 46 | void arch_prog_run(struct prog *prog) |
| 47 | { |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 48 | struct arch_prog_run_args args = {}; |
| 49 | |
| 50 | args.prog = prog; |
| 51 | |
| 52 | /* In case of OpenSBI we have to load it before resuming all HARTs */ |
| 53 | if (ENV_RAMSTAGE && CONFIG(RISCV_OPENSBI)) { |
| 54 | struct prog sbi = PROG_INIT(PROG_OPENSBI, CONFIG_CBFS_PREFIX"/opensbi"); |
| 55 | |
Xiang Wang | a6f9eab | 2019-03-28 12:19:30 +0800 | [diff] [blame] | 56 | if (!selfload_check(&sbi, BM_MEM_OPENSBI)) |
| 57 | die("OpenSBI load failed"); |
| 58 | |
| 59 | args.opensbi = &sbi; |
| 60 | } |
| 61 | |
| 62 | smp_resume((void (*)(void *))do_arch_prog_run, &args); |
Xiang Wang | 26f725e | 2018-10-11 17:42:49 +0800 | [diff] [blame] | 63 | } |