mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] efistub: LoongArch: Reimplement kernel_entry_address()
@ 2023-03-07 10:57 Youling Tang
  2023-03-08 20:50 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Youling Tang @ 2023-03-07 10:57 UTC (permalink / raw)
  To: Huacai Chen, Ard Biesheuvel
  Cc: Xuerui Wang, linux-efi, loongarch, linux-kernel, loongson-kernel

When EFI_KIMG_PREFERRED_ADDRESS is not equal to PHYS_LINK_KADDR, we
should not jump to the link address but the actual load address, so
fix the processing of kernel_entry_address().

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
- EFI_KIMG_PREFERRED_ADDRESS = PHYS_LINK_KADDR:
/ # cat /proc/iomem 
00000000-0fffffff : System RAM
  00000000-001fffff : Reserved
  00200000-0113ffff : Kernel code
  01140000-01a0e5ff : Kernel data
  01a0e600-01b0b337 : Kernel bss

- EFI_KIMG_PREFERRED_ADDRESS = PHYS_LINK_KADDR + 0x4000000 (Enable CONFIG_RELOCATABLE):
 # cat /proc/iomem 
00000000-0fffffff : System RAM
  00000000-041fffff : Reserved
  04200000-0513ffff : Kernel code
  05140000-05a0e5ff : Kernel data
  05a0e600-05b0b337 : Kernel bss

 arch/loongarch/include/asm/efi.h              |  2 --
 drivers/firmware/efi/libstub/loongarch-stub.c |  7 -------
 drivers/firmware/efi/libstub/loongarch.c      | 14 ++++++++++++--
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/loongarch/include/asm/efi.h b/arch/loongarch/include/asm/efi.h
index 091897d40b03..eddc8e79b3fa 100644
--- a/arch/loongarch/include/asm/efi.h
+++ b/arch/loongarch/include/asm/efi.h
@@ -32,6 +32,4 @@ static inline unsigned long efi_get_kimg_min_align(void)
 
 #define EFI_KIMG_PREFERRED_ADDRESS	PHYSADDR(VMLINUX_LOAD_ADDRESS)
 
-unsigned long kernel_entry_address(void);
-
 #endif /* _ASM_LOONGARCH_EFI_H */
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index eee7ed43cdfb..71d178f87274 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -44,10 +44,3 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
 
 	return status;
 }
-
-unsigned long kernel_entry_address(void)
-{
-	unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
-
-	return (unsigned long)&kernel_entry - base + VMLINUX_LOAD_ADDRESS;
-}
diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
index 807cba2693fc..79fa16a765ce 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -37,9 +37,19 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
 	return EFI_SUCCESS;
 }
 
-unsigned long __weak kernel_entry_address(void)
+/*
+ * Get the offset of EFI_KIMG_PREFERRED_ADDRESS relative to the physical
+ * link address.
+ */
+static long get_kernel_offset(void)
+{
+	return EFI_KIMG_PREFERRED_ADDRESS - PHYS_LINK_KADDR;
+}
+
+unsigned long kernel_entry_address(void)
 {
-	return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
+	return *(unsigned long *)(EFI_KIMG_PREFERRED_ADDRESS + 8) +
+		get_kernel_offset();
 }
 
 efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
-- 
2.37.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-08 20:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 10:57 [PATCH] efistub: LoongArch: Reimplement kernel_entry_address() Youling Tang
2023-03-08 20:50 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®