Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: implement ARCH_HAS_KERNEL_FPU_SUPPORT

PowerPC provides an equivalent to the common kernel-mode FPU API, but in a
different header and using different function names. The PowerPC API also
requires a non-preemptible context. Add a wrapper header, and export the
CFLAGS adjustments.

Link: https://lkml.kernel.org/r/20240329072441.591471-9-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Samuel Holland and committed by
Andrew Morton
01db473e 372f6623

+33 -1
+1
arch/powerpc/Kconfig
··· 137 137 select ARCH_HAS_GCOV_PROFILE_ALL 138 138 select ARCH_HAS_HUGEPD if HUGETLB_PAGE 139 139 select ARCH_HAS_KCOV 140 + select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC_FPU 140 141 select ARCH_HAS_MEMBARRIER_CALLBACKS 141 142 select ARCH_HAS_MEMBARRIER_SYNC_CORE 142 143 select ARCH_HAS_MEMREMAP_COMPAT_ALIGN if PPC_64S_HASH_MMU
+4 -1
arch/powerpc/Makefile
··· 149 149 150 150 CFLAGS-$(CONFIG_PPC32) += $(call cc-option,-mno-readonly-in-sdata) 151 151 152 + CC_FLAGS_FPU := $(call cc-option,-mhard-float) 153 + CC_FLAGS_NO_FPU := $(call cc-option,-msoft-float) 154 + 152 155 ifdef CONFIG_FUNCTION_TRACER 153 156 ifdef CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY 154 157 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY ··· 173 170 174 171 KBUILD_CPPFLAGS += -I $(srctree)/arch/powerpc $(asinstr) 175 172 KBUILD_AFLAGS += $(AFLAGS-y) 176 - KBUILD_CFLAGS += $(call cc-option,-msoft-float) 173 + KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU) 177 174 KBUILD_CFLAGS += $(CFLAGS-y) 178 175 CPP = $(CC) -E $(KBUILD_CFLAGS) 179 176
+28
arch/powerpc/include/asm/fpu.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2023 SiFive 4 + */ 5 + 6 + #ifndef _ASM_POWERPC_FPU_H 7 + #define _ASM_POWERPC_FPU_H 8 + 9 + #include <linux/preempt.h> 10 + 11 + #include <asm/cpu_has_feature.h> 12 + #include <asm/switch_to.h> 13 + 14 + #define kernel_fpu_available() (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) 15 + 16 + static inline void kernel_fpu_begin(void) 17 + { 18 + preempt_disable(); 19 + enable_kernel_fp(); 20 + } 21 + 22 + static inline void kernel_fpu_end(void) 23 + { 24 + disable_kernel_fp(); 25 + preempt_enable(); 26 + } 27 + 28 + #endif /* ! _ASM_POWERPC_FPU_H */