1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Western Digital Corporation or its affiliates.
7 #include <linux/libfdt.h>
10 #include <linux/unaligned.h>
14 typedef void __noreturn (*jump_kernel_func
)(unsigned long, unsigned long);
16 static unsigned long hartid
;
18 static int get_boot_hartid_from_fdt(void)
24 fdt
= get_efi_config_table(DEVICE_TREE_GUID
);
28 chosen_node
= fdt_path_offset(fdt
, "/chosen");
32 prop
= fdt_getprop((void *)fdt
, chosen_node
, "boot-hartid", &len
);
36 if (len
== sizeof(u32
))
37 hartid
= (unsigned long) fdt32_to_cpu(*(fdt32_t
*)prop
);
38 else if (len
== sizeof(u64
))
39 hartid
= (unsigned long) fdt64_to_cpu(__get_unaligned_t(fdt64_t
, prop
));
46 static efi_status_t
get_boot_hartid_from_efi(void)
48 efi_guid_t boot_protocol_guid
= RISCV_EFI_BOOT_PROTOCOL_GUID
;
49 struct riscv_efi_boot_protocol
*boot_protocol
;
52 status
= efi_bs_call(locate_protocol
, &boot_protocol_guid
, NULL
,
53 (void **)&boot_protocol
);
54 if (status
!= EFI_SUCCESS
)
56 return efi_call_proto(boot_protocol
, get_boot_hartid
, &hartid
);
59 efi_status_t
check_platform_features(void)
64 status
= get_boot_hartid_from_efi();
65 if (status
!= EFI_SUCCESS
) {
66 ret
= get_boot_hartid_from_fdt();
68 efi_err("Failed to get boot hartid!\n");
69 return EFI_UNSUPPORTED
;
75 unsigned long __weak
stext_offset(void)
78 * This fallback definition is used by the EFI zboot stub, which loads
79 * the entire image so it can branch via the image header at offset #0.
84 void __noreturn
efi_enter_kernel(unsigned long entrypoint
, unsigned long fdt
,
85 unsigned long fdt_size
)
87 unsigned long kernel_entry
= entrypoint
+ stext_offset();
88 jump_kernel_func jump_kernel
= (jump_kernel_func
)kernel_entry
;
91 * Jump to real kernel here with following constraints.
92 * 1. MMU should be disabled.
93 * 2. a0 should contain hartid
94 * 3. a1 should DT address
96 csr_write(CSR_SATP
, 0);
97 jump_kernel(hartid
, fdt
);