All of lore.kernel.org
 help / color / mirror / Atom feed
From: Youling Tang <tangyouling@loongson.cn>
To: Huacai Chen <chenhuacai@loongson.cn>, Ard Biesheuvel <ardb@kernel.org>
Cc: Xuerui Wang <kernel@xen0n.name>,
	linux-efi@vger.kernel.org, loongarch@lists.linux.dev,
	linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn
Subject: [PATCH] efistub: LoongArch: Reimplement kernel_entry_address()
Date: Tue,  7 Mar 2023 18:57:33 +0800	[thread overview]
Message-ID: <1678186653-27659-1-git-send-email-tangyouling@loongson.cn> (raw)

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


             reply	other threads:[~2023-03-07 10:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 10:57 Youling Tang [this message]
2023-03-08 20:50 ` [PATCH] efistub: LoongArch: Reimplement kernel_entry_address() kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1678186653-27659-1-git-send-email-tangyouling@loongson.cn \
    --to=tangyouling@loongson.cn \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=kernel@xen0n.name \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=loongson-kernel@lists.loongnix.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.