Skip to contentSkip to conversation

LoongArch: Fix build errors

PATCH In review Guenter Roeck 2 participants 5 messages Jul 1, 2022 – Jul 2, 2022 LoongArch

lore
Share & tools
lore
#0 lore raw

cover LoongArch: Fix build errors

A number of build errors is seen when trying to build loongarch:allnoconfig or loongarch:tinyconfig. This patch series tries to fix the observed errors.

----------------------------------------------------------------
Guenter Roeck (3):
LoongArch: page.h: Add missing include file
LoongArch: Do not include file from toolchain
LoongArch: Always select EFI

 arch/loongarch/Kconfig                 |  6 ++----
 arch/loongarch/include/asm/loongarch.h | 23 +++++++++++------------
 arch/loongarch/include/asm/page.h      |  1 +
 3 files changed, 14 insertions(+), 16 deletions(-)
#1 lore raw

PATCH 1/3 LoongArch: page.h: Add missing include file

Building loongarch:tinyconfig fails with the following error.

./arch/loongarch/include/asm/page.h: In function 'pfn_valid':
./arch/loongarch/include/asm/page.h:42:32: error: 'PHYS_OFFSET' undeclared

Add the missing include file.

Fixes 09cfefb7fa70 ("LoongArch: Add memory management")
---
 arch/loongarch/include/asm/page.h | 1 +
 1 file changed, 1 insertion(+)
arch/loongarch/include/asm/page.h +1 -0
index 3dba4986f6c9..8cee37f832aa 100644
@@ -5,6 +5,7 @@
 #ifndef _ASM_PAGE_H
 #define _ASM_PAGE_H
 
+#include <asm/addrspace.h>
 #include <linux/const.h>
 
 /*
Signature · 1 line
2.35.1
#2 lore raw

RFC PATCH 2/3 LoongArch: Do not include file from toolchain

In reply to Guenter Roeck

Building loongarch:allnoconfig with a self-compiled toolchain fails with the following error.

./arch/loongarch/include/asm/loongarch.h:13:10: fatal error:
larchintrin.h: No such file or directory

loongarch.h includes a file from the toolchain which is not neccessarily available. Drop the include, and call the builtin functions directly.

Fixes f2ac457a6138 ("LoongArch: Add CPU definition headers")

---
RFC: If the builtins are compiler or compiler version specific,
a separate include file may be needed. Either case, the kernel should not include files from the toolchain.

 arch/loongarch/include/asm/loongarch.h | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
arch/loongarch/include/asm/loongarch.h +11 -12
index 3ba4f7e87cd2..df57f88b2fc5 100644
@@ -10,7 +10,6 @@
 #include <linux/types.h>
 
 #ifndef __ASSEMBLY__
-#include <larchintrin.h>
 
 /*
  * parse_r var, r - Helper assembler macro for parsing register names.
@@ -58,7 +57,7 @@ __asm__(".macro	parse_r var r\n\t"
 /* CPUCFG */
 static inline u32 read_cpucfg(u32 reg)
 {
-	return __cpucfg(reg);
+	return __builtin_loongarch_cpucfg(reg);
 }
 
 #endif /* !__ASSEMBLY__ */
@@ -229,53 +228,53 @@ static inline u32 read_cpucfg(u32 reg)
 /* CSR */
 static __always_inline u32 csr_read32(u32 reg)
 {
-	return __csrrd_w(reg);
+	return __builtin_loongarch_csrrd_d(reg);
 }
 
 static __always_inline u64 csr_read64(u32 reg)
 {
-	return __csrrd_d(reg);
+	return __builtin_loongarch_csrrd_d(reg);
 }
 
 static __always_inline void csr_write32(u32 val, u32 reg)
 {
-	__csrwr_w(val, reg);
+	__builtin_loongarch_csrwr_w(val, reg);
 }
 
 static __always_inline void csr_write64(u64 val, u32 reg)
 {
-	__csrwr_d(val, reg);
+	__builtin_loongarch_csrwr_d(val, reg);
 }
 
 static __always_inline u32 csr_xchg32(u32 val, u32 mask, u32 reg)
 {
-	return __csrxchg_w(val, mask, reg);
+	return __builtin_loongarch_csrxchg_w(val, mask, reg);
 }
 
 static __always_inline u64 csr_xchg64(u64 val, u64 mask, u32 reg)
 {
-	return __csrxchg_d(val, mask, reg);
+	return __builtin_loongarch_csrxchg_d(val, mask, reg);
 }
 
 /* IOCSR */
 static __always_inline u32 iocsr_read32(u32 reg)
 {
-	return __iocsrrd_w(reg);
+	return __builtin_loongarch_iocsrrd_w(reg);
 }
 
 static __always_inline u64 iocsr_read64(u32 reg)
 {
-	return __iocsrrd_d(reg);
+	return __builtin_loongarch_iocsrrd_d(reg);
 }
 
 static __always_inline void iocsr_write32(u32 val, u32 reg)
 {
-	__iocsrwr_w(val, reg);
+	__builtin_loongarch_iocsrwr_w(val, reg);
 }
 
 static __always_inline void iocsr_write64(u64 val, u32 reg)
 {
-	__iocsrwr_d(val, reg);
+	__builtin_loongarch_iocsrwr_d(val, reg);
 }
 
 #endif /* !__ASSEMBLY__ */
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/3 LoongArch: Always select EFI

In reply to Guenter Roeck

Building loongarch:allnoconfig or loongarch:tinyconfig fails with the following error.

loongarch64-linux-gnu-ld: arch/loongarch/kernel/env.o: in function `init_environ':
env.c:(.init.text+0xe4): undefined reference to `efi'
loongarch64-linux-gnu-ld: env.c:(.init.text+0xe8): undefined reference to `efi'
loongarch64-linux-gnu-ld: env.c:(.init.text+0xe8): undefined reference to `efi'
loongarch64-linux-gnu-ld: env.c:(.init.text+0x108): undefined reference to `efi_get_fdt_params'
loongarch64-linux-gnu-ld: env.c:(.init.text+0x11c): undefined reference to `efi_memmap_init_early'
loongarch64-linux-gnu-ld: arch/loongarch/kernel/setup.o: in function `platform_init':
setup.c:(.init.text+0x228): undefined reference to `efi_init'
loongarch64-linux-gnu-ld: setup.c:(.init.text+0x250): undefined reference to `efi_runtime_init'
loongarch64-linux-gnu-ld: arch/loongarch/kernel/mem.o: in function `memblock_init':
mem.c:(.init.text+0x24): undefined reference to `efi'
loongarch64-linux-gnu-ld: mem.c:(.init.text+0x28): undefined reference to `efi'
loongarch64-linux-gnu-ld: mem.c:(.init.text+0x28): undefined reference to `efi'

Since it is mandatory, auto-select EFI support to fix the error. Drop the EFI Kconfig help message since it is not needed.

Fixes fa96b57c1490 ("LoongArch: Add build infrastructure")
---
 arch/loongarch/Kconfig | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/loongarch/Kconfig +2 -4
index 1920d52653b4..4ed8d0916be7 100644
@@ -50,6 +50,7 @@ config LOONGARCH
 	select ARCH_WANTS_NO_INSTR
 	select BUILDTIME_TABLE_SORT
 	select COMMON_CLK
+	select EFI
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CMOS_UPDATE
 	select GENERIC_CPU_AUTOPROBE
@@ -296,13 +297,10 @@ config DMI
 	  DMI to identify machine quirks.
 
 config EFI
-	bool "EFI runtime service support"
+	bool
 	select UCS2_STRING
 	select EFI_PARAMS_FROM_FDT
 	select EFI_RUNTIME_WRAPPERS
-	help
-	  This enables the kernel to use EFI runtime services that are
-	  available (such as the EFI variable services).
 
 config SMP
 	bool "Multi-Processing support"
Signature · 1 line
2.35.1
maintainer
#4 lore raw
In reply to Guenter Roeck

Hi, Guenter,

Quoted 4 lines · Guenter Roeck

A number of build errors is seen when trying to build loongarch:allnoconfig or loongarch:tinyconfig. This patch series tries to fix the observed errors.

Thank you very much for your patches. From my point of view, the first patch is good, but we usually include <linux/xxx> before <asm/yyy>; the second patch is not so good, and I think the correct way is modify the cflags for vdso [1]; and the third patch can be dropped at this time, until our kernel is bootable.

[1] https://lore.kernel.org/loongarch/[email protected]/T/#u

Huacai

Quoted 11 lines

----------------------------------------------------------------
Guenter Roeck (3):
LoongArch: page.h: Add missing include file
LoongArch: Do not include file from toolchain
LoongArch: Always select EFI

 arch/loongarch/Kconfig                 |  6 ++----
 arch/loongarch/include/asm/loongarch.h | 23 +++++++++++------------
 arch/loongarch/include/asm/page.h      |  1 +
 3 files changed, 14 insertions(+), 16 deletions(-)