2022-05-31 18:04:11 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/threads.h>
|
|
|
|
|
|
|
|
#include <asm/addrspace.h>
|
|
|
|
#include <asm/asm.h>
|
|
|
|
#include <asm/asmmacro.h>
|
2022-10-12 16:36:19 +08:00
|
|
|
#include <asm/bug.h>
|
2022-05-31 18:04:11 +08:00
|
|
|
#include <asm/regdef.h>
|
|
|
|
#include <asm/loongarch.h>
|
|
|
|
#include <asm/stackframe.h>
|
|
|
|
|
efi/loongarch: Add efistub booting support
This patch adds efistub booting support, which is the standard UEFI boot
protocol for LoongArch to use.
We use generic efistub, which means we can pass boot information (i.e.,
system table, memory map, kernel command line, initrd) via a light FDT
and drop a lot of non-standard code.
We use a flat mapping to map the efi runtime in the kernel's address
space. In efi, VA = PA; in kernel, VA = PA + PAGE_OFFSET. As a result,
flat mapping is not identity mapping, SetVirtualAddressMap() is still
needed for the efi runtime.
Tested-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
[ardb: change fpic to fpie as suggested by Xi Ruoyao]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-08-19 18:20:37 +08:00
|
|
|
#ifdef CONFIG_EFI_STUB
|
|
|
|
|
|
|
|
#include "efi-header.S"
|
|
|
|
|
|
|
|
__HEAD
|
|
|
|
|
|
|
|
_head:
|
|
|
|
.word MZ_MAGIC /* "MZ", MS-DOS header */
|
2022-10-12 16:36:19 +08:00
|
|
|
.org 0x8
|
|
|
|
.dword kernel_entry /* Kernel entry point */
|
|
|
|
.dword _end - _text /* Kernel image effective size */
|
|
|
|
.quad 0 /* Kernel image load offset from start of RAM */
|
|
|
|
.org 0x3c /* 0x20 ~ 0x3b reserved */
|
efi/loongarch: Add efistub booting support
This patch adds efistub booting support, which is the standard UEFI boot
protocol for LoongArch to use.
We use generic efistub, which means we can pass boot information (i.e.,
system table, memory map, kernel command line, initrd) via a light FDT
and drop a lot of non-standard code.
We use a flat mapping to map the efi runtime in the kernel's address
space. In efi, VA = PA; in kernel, VA = PA + PAGE_OFFSET. As a result,
flat mapping is not identity mapping, SetVirtualAddressMap() is still
needed for the efi runtime.
Tested-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
[ardb: change fpic to fpie as suggested by Xi Ruoyao]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-08-19 18:20:37 +08:00
|
|
|
.long pe_header - _head /* Offset to the PE header */
|
|
|
|
|
|
|
|
pe_header:
|
|
|
|
__EFI_PE_HEADER
|
|
|
|
|
|
|
|
SYM_DATA(kernel_asize, .long _end - _text);
|
|
|
|
SYM_DATA(kernel_fsize, .long _edata - _text);
|
|
|
|
SYM_DATA(kernel_offset, .long kernel_offset - _text);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-05-31 18:04:11 +08:00
|
|
|
__REF
|
|
|
|
|
2022-09-26 22:25:29 +08:00
|
|
|
.align 12
|
|
|
|
|
2022-05-31 18:04:11 +08:00
|
|
|
SYM_CODE_START(kernel_entry) # kernel entry point
|
|
|
|
|
|
|
|
/* Config direct window and set PG */
|
|
|
|
li.d t0, CSR_DMW0_INIT # UC, PLV0, 0x8000 xxxx xxxx xxxx
|
|
|
|
csrwr t0, LOONGARCH_CSR_DMWIN0
|
|
|
|
li.d t0, CSR_DMW1_INIT # CA, PLV0, 0x9000 xxxx xxxx xxxx
|
|
|
|
csrwr t0, LOONGARCH_CSR_DMWIN1
|
2022-08-11 20:52:12 +08:00
|
|
|
|
|
|
|
/* We might not get launched at the address the kernel is linked to,
|
|
|
|
so we jump there. */
|
|
|
|
la.abs t0, 0f
|
|
|
|
jr t0
|
|
|
|
0:
|
2022-05-31 18:04:11 +08:00
|
|
|
/* Enable PG */
|
|
|
|
li.w t0, 0xb0 # PLV=0, IE=0, PG=1
|
|
|
|
csrwr t0, LOONGARCH_CSR_CRMD
|
|
|
|
li.w t0, 0x04 # PLV=0, PIE=1, PWE=0
|
|
|
|
csrwr t0, LOONGARCH_CSR_PRMD
|
|
|
|
li.w t0, 0x00 # FPE=0, SXE=0, ASXE=0, BTE=0
|
|
|
|
csrwr t0, LOONGARCH_CSR_EUEN
|
|
|
|
|
2022-10-12 16:36:08 +08:00
|
|
|
la.pcrel t0, __bss_start # clear .bss
|
2022-05-31 18:04:11 +08:00
|
|
|
st.d zero, t0, 0
|
2022-10-12 16:36:08 +08:00
|
|
|
la.pcrel t1, __bss_stop - LONGSIZE
|
2022-05-31 18:04:11 +08:00
|
|
|
1:
|
|
|
|
addi.d t0, t0, LONGSIZE
|
|
|
|
st.d zero, t0, 0
|
|
|
|
bne t0, t1, 1b
|
|
|
|
|
2022-10-12 16:36:08 +08:00
|
|
|
la.pcrel t0, fw_arg0
|
2022-05-31 18:04:11 +08:00
|
|
|
st.d a0, t0, 0 # firmware arguments
|
2022-10-12 16:36:08 +08:00
|
|
|
la.pcrel t0, fw_arg1
|
2022-05-31 18:04:11 +08:00
|
|
|
st.d a1, t0, 0
|
2022-10-12 16:36:08 +08:00
|
|
|
la.pcrel t0, fw_arg2
|
efi/loongarch: libstub: remove dependency on flattened DT
LoongArch does not use FDT or DT natively [yet], and the only reason it
currently uses it is so that it can reuse the existing EFI stub code.
Overloading the DT with data passed between the EFI stub and the core
kernel has been a source of problems: there is the overlap between
information provided by EFI which DT can also provide (initrd base/size,
command line, memory descriptions), requiring us to reason about which
is which and what to prioritize. It has also resulted in ABI leaks,
i.e., internal ABI being promoted to external ABI inadvertently because
the bootloader can set the EFI stub's DT properties as well (e.g.,
"kaslr-seed"). This has become especially problematic with boot
environments that want to pretend that EFI boot is being done (to access
ACPI and SMBIOS tables, for instance) but have no ability to execute the
EFI stub, and so the environment that the EFI stub creates is emulated
[poorly, in some cases].
Another downside of treating DT like this is that the DT binary that the
kernel receives is different from the one created by the firmware, which
is undesirable in the context of secure and measured boot.
Given that LoongArch support in Linux is brand new, we can avoid these
pitfalls, and treat the DT strictly as a hardware description, and use a
separate handover method between the EFI stub and the kernel. Now that
initrd loading and passing the EFI memory map have been refactored into
pure EFI routines that use EFI configuration tables, the only thing we
need to pass directly is the kernel command line (even if we could pass
this via a config table as well, it is used extremely early, so passing
it directly is preferred in this case.)
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
2022-09-16 19:48:53 +02:00
|
|
|
st.d a2, t0, 0
|
2022-05-31 18:04:11 +08:00
|
|
|
|
|
|
|
/* KSave3 used for percpu base, initialized as 0 */
|
|
|
|
csrwr zero, PERCPU_BASE_KS
|
|
|
|
/* GPR21 used for percpu base (runtime), initialized as 0 */
|
2022-07-26 23:57:18 +08:00
|
|
|
move u0, zero
|
2022-05-31 18:04:11 +08:00
|
|
|
|
2022-10-12 16:36:08 +08:00
|
|
|
la.pcrel tp, init_thread_union
|
2022-05-31 18:04:11 +08:00
|
|
|
/* Set the SP after an empty pt_regs. */
|
2022-10-29 16:29:31 +08:00
|
|
|
PTR_LI sp, (_THREAD_SIZE - PT_SIZE)
|
2022-05-31 18:04:11 +08:00
|
|
|
PTR_ADD sp, sp, tp
|
|
|
|
set_saved_sp sp, t0, t1
|
|
|
|
|
|
|
|
bl start_kernel
|
2022-10-12 16:36:19 +08:00
|
|
|
ASM_BUG()
|
2022-05-31 18:04:11 +08:00
|
|
|
|
|
|
|
SYM_CODE_END(kernel_entry)
|
|
|
|
|
2022-05-31 18:04:12 +08:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SMP slave cpus entry point. Board specific code for bootstrap calls this
|
|
|
|
* function after setting up the stack and tp registers.
|
|
|
|
*/
|
|
|
|
SYM_CODE_START(smpboot_entry)
|
|
|
|
li.d t0, CSR_DMW0_INIT # UC, PLV0
|
|
|
|
csrwr t0, LOONGARCH_CSR_DMWIN0
|
|
|
|
li.d t0, CSR_DMW1_INIT # CA, PLV0
|
|
|
|
csrwr t0, LOONGARCH_CSR_DMWIN1
|
2022-08-11 20:52:12 +08:00
|
|
|
|
|
|
|
la.abs t0, 0f
|
|
|
|
jr t0
|
|
|
|
0:
|
|
|
|
/* Enable PG */
|
2022-05-31 18:04:12 +08:00
|
|
|
li.w t0, 0xb0 # PLV=0, IE=0, PG=1
|
|
|
|
csrwr t0, LOONGARCH_CSR_CRMD
|
|
|
|
li.w t0, 0x04 # PLV=0, PIE=1, PWE=0
|
|
|
|
csrwr t0, LOONGARCH_CSR_PRMD
|
|
|
|
li.w t0, 0x00 # FPE=0, SXE=0, ASXE=0, BTE=0
|
|
|
|
csrwr t0, LOONGARCH_CSR_EUEN
|
|
|
|
|
|
|
|
la.abs t0, cpuboot_data
|
|
|
|
ld.d sp, t0, CPU_BOOT_STACK
|
|
|
|
ld.d tp, t0, CPU_BOOT_TINFO
|
|
|
|
|
|
|
|
bl start_secondary
|
2022-10-12 16:36:19 +08:00
|
|
|
ASM_BUG()
|
|
|
|
|
2022-05-31 18:04:12 +08:00
|
|
|
SYM_CODE_END(smpboot_entry)
|
|
|
|
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2022-05-31 18:04:11 +08:00
|
|
|
SYM_ENTRY(kernel_entry_end, SYM_L_GLOBAL, SYM_A_NONE)
|