Skip to content

Commit 01db473

Browse files
SiFiveHollandakpm00
authored andcommitted
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>
1 parent 372f662 commit 01db473

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ config PPC
137137
select ARCH_HAS_GCOV_PROFILE_ALL
138138
select ARCH_HAS_HUGEPD if HUGETLB_PAGE
139139
select ARCH_HAS_KCOV
140+
select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC_FPU
140141
select ARCH_HAS_MEMBARRIER_CALLBACKS
141142
select ARCH_HAS_MEMBARRIER_SYNC_CORE
142143
select ARCH_HAS_MEMREMAP_COMPAT_ALIGN if PPC_64S_HASH_MMU

arch/powerpc/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ CFLAGS-$(CONFIG_PPC32) += $(call cc-option, $(MULTIPLEWORD))
149149

150150
CFLAGS-$(CONFIG_PPC32) += $(call cc-option,-mno-readonly-in-sdata)
151151

152+
CC_FLAGS_FPU := $(call cc-option,-mhard-float)
153+
CC_FLAGS_NO_FPU := $(call cc-option,-msoft-float)
154+
152155
ifdef CONFIG_FUNCTION_TRACER
153156
ifdef CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY
154157
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
@@ -170,7 +173,7 @@ asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
170173

171174
KBUILD_CPPFLAGS += -I $(srctree)/arch/powerpc $(asinstr)
172175
KBUILD_AFLAGS += $(AFLAGS-y)
173-
KBUILD_CFLAGS += $(call cc-option,-msoft-float)
176+
KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU)
174177
KBUILD_CFLAGS += $(CFLAGS-y)
175178
CPP = $(CC) -E $(KBUILD_CFLAGS)
176179

arch/powerpc/include/asm/fpu.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 */

0 commit comments

Comments
 (0)