From patchwork Tue Mar 7 10:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 660142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4875DC678D4 for ; Tue, 7 Mar 2023 10:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231272AbjCGK6K (ORCPT ); Tue, 7 Mar 2023 05:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231246AbjCGK5h (ORCPT ); Tue, 7 Mar 2023 05:57:37 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80DC757D2C; Tue, 7 Mar 2023 02:57:35 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Dx_5eeGAdkF1MJAA--.12142S3; Tue, 07 Mar 2023 18:57:34 +0800 (CST) Received: from bogon.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxtOWdGAdk1vFNAA--.36843S2; Tue, 07 Mar 2023 18:57:33 +0800 (CST) From: Youling Tang To: Huacai Chen , Ard Biesheuvel Cc: Xuerui Wang , 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 Message-Id: <1678186653-27659-1-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8BxtOWdGAdk1vFNA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E87Iv6xkF7I0E14v26r1j6r 4UYxBIdaVFxhVjvjDU0xZFpf9x07jYSoJUUUUU= Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org 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 --- - 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,