-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: add support for kernel-mode FPU
This is motivated by the amdgpu DRM driver, which needs floating-point code to support recent hardware. That code is not performance-critical, so only provide a minimal non-preemptible implementation for now. Support is limited to riscv64 because riscv32 requires runtime (libgcc) assistance to convert between doubles and 64-bit integers. Link: https://lkml.kernel.org/r/20240329072441.591471-12-samuel.holland@sifive.com Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> 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: Michael Ellerman <mpe@ellerman.id.au> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicolas Schier <nicolas@fjasle.eu> 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>
- Loading branch information
Samuel Holland
authored and
Andrew Morton
committed
May 19, 2024
1 parent
b0b8a15
commit 77acc6b
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright (C) 2023 SiFive | ||
*/ | ||
|
||
#ifndef _ASM_RISCV_FPU_H | ||
#define _ASM_RISCV_FPU_H | ||
|
||
#include <asm/switch_to.h> | ||
|
||
#define kernel_fpu_available() has_fpu() | ||
|
||
void kernel_fpu_begin(void); | ||
void kernel_fpu_end(void); | ||
|
||
#endif /* ! _ASM_RISCV_FPU_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (C) 2023 SiFive | ||
*/ | ||
|
||
#include <linux/export.h> | ||
#include <linux/preempt.h> | ||
|
||
#include <asm/csr.h> | ||
#include <asm/fpu.h> | ||
#include <asm/processor.h> | ||
#include <asm/switch_to.h> | ||
|
||
void kernel_fpu_begin(void) | ||
{ | ||
preempt_disable(); | ||
fstate_save(current, task_pt_regs(current)); | ||
csr_set(CSR_SSTATUS, SR_FS); | ||
} | ||
EXPORT_SYMBOL_GPL(kernel_fpu_begin); | ||
|
||
void kernel_fpu_end(void) | ||
{ | ||
csr_clear(CSR_SSTATUS, SR_FS); | ||
fstate_restore(current, task_pt_regs(current)); | ||
preempt_enable(); | ||
} | ||
EXPORT_SYMBOL_GPL(kernel_fpu_end); |