xref: /aosp_15_r20/external/coreboot/src/arch/riscv/opensbi.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /* OpenSBI wants to make its own definitions for some of our compiler.h macros. */
4 #undef __packed
5 #undef __noreturn
6 #undef __aligned
7 
8 #include <sbi/fw_dynamic.h>
9 #include <arch/boot.h>
10 /* DO NOT INCLUDE COREBOOT HEADERS HERE */
11 
run_opensbi(const int hart_id,const void * fdt,const void * opensbi,const void * payload,const int payload_mode)12 void run_opensbi(const int hart_id,
13 		 const void *fdt,
14 		 const void *opensbi,
15 		 const void *payload,
16 		 const int payload_mode)
17 {
18 	struct fw_dynamic_info info = {
19 		.magic = FW_DYNAMIC_INFO_MAGIC_VALUE,
20 		.version = FW_DYNAMIC_INFO_VERSION_MAX,
21 		.next_mode = payload_mode,
22 		.next_addr = (uintptr_t)payload,
23 		.options = 0,
24 		.boot_hart = CONFIG_OPENSBI_FW_DYNAMIC_BOOT_HART,
25 	};
26 
27 	csr_write(mepc, opensbi);
28 	asm volatile (
29 			"mv	a0, %0\n\t"
30 			"mv	a1, %1\n\t"
31 			"mv	a2, %2\n\t"
32 			"mret" :
33 			: "r"(hart_id), "r"(fdt), "r"(&info)
34 			: "a0", "a1", "a2");
35 }
36