From patchwork Fri Dec 8 05:54:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13484861 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2391C10F09 for ; Fri, 8 Dec 2023 05:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B6gq8bj1QTWhtx8WZIBv59H5DPVvWgD/m72qD4EOPSw=; b=pcBA9sUWiNOOel U5df6y8E8PaDvSdm8JaeVUSoxmpnp2niTQL7RyS9Qsj71QZEA+zJLE4dvmw4gRYJEeoCDBEAuphzy Dx4DYUEaZ9a7DZaO8uVJPOzBLFRSIC5wcwCpvnkkJC+7iIgIF4thxbr9StptvtK4S63kWSBOn65CU nuWyRyw4CYaIt0YDTxir6HT+a5OrmBMoVf9OvGBsG4IS11OT2Y87FnWv5Nge16FYN0LyH4tpwVxA4 MowGlZ8HI8fVyPDbFFLrasCifnX9es/dHh2M/iVjXY8cAB4/rD6Kvu5K+VQWnpgqpjxY/mROe0It0 kKYbjQkkJMQBArvDGNTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBTpk-00EnrR-03; Fri, 08 Dec 2023 05:55:32 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBTpQ-00EnVJ-0Z for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2023 05:55:16 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d1e1edb10bso15914465ad.1 for ; Thu, 07 Dec 2023 21:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702014911; x=1702619711; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+YzUuPYE3yay4aPXmYR/ZrTN/zes857jj0i/rwk/8vA=; b=lvQRBf1m4SlTAV5W3l5dZxaIt+LuC/kMu70XtARHO4hjOezNCyqOm3NcUDJW5kKXss 9EEDuDX2tH68IXPFjsPQF4NVHBJmnNBmpnrtVeON7WVsKadTzvK+IjYuKFFySxbd96hW 2N67IPfe9Jb5ZOZieowlJDPXy3uCw8/EdCtlrH7GlDmkZxOrbWsUos01dWkaRNeJRdSR C1oz2nBtd1I60ieOtqIgMw2rL7DrgkJiKgsyZedb+TzWLw9N9bv847Iqpaeb1w9auI0E W/vOML2gpZ8A6P3VUD7sr3OQTE7588sx67xaCDegLUd8MujFsS64pY3WM1ERcX3uH6gf cBzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702014911; x=1702619711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+YzUuPYE3yay4aPXmYR/ZrTN/zes857jj0i/rwk/8vA=; b=t4nx9kuJySxmxRP0Iq7zZ/Z7zlwRco8/YoH+wY56ZFAuhVjUZC8SJBcrt4Qs9GYHl5 6ZGRqvJUR7f4F0lgzFCS6EzbtZ443qdI/2yUU1Rakxm1aVGYDsISmmSsNkixsl2oh20i kTorf6khpIxRV0V6QkNWcifDpBYrYp62mJx6BzBstH2xBpEpwidtihFEWww9fzCuhew4 8D7LRCcOQk9NNTB5Ywtxj5E5Bxor6SU0uUOjToZ5mdcFq/JDEiP0CZiGxM8kFIxaAOw/ h8FVMYHX+jt/4kOk4FI5D8nYsi7qK90BsndW6WfUTruQiyGmIuD0OwvSz9fvrOzkTv2X +d3w== X-Gm-Message-State: AOJu0YwZOBIcrL9miZYiw95ZlsJW59DiObAwSKIldrj+f8KXA6vsp6iB BP/PR2IoYd/IOVkHzSxRziT8k/ApHBzsylOHCwri44qn5KdVgThuUdW2xJ/ZsmqGrl3rW28K8Cp IYAsD1+NI/Ljk0p7nLIaZtAY7vQ4wA5TzdwsPUaGEKaS0T4lz82/tSaVIWrhcD8ggwK2vNIIwxl nMGYYrpkZkOikCGFPLc/XmGSUrEg== X-Google-Smtp-Source: AGHT+IGkpKPNTZyORkUclzuJiqEGnd764SXTk1kHONQX0GukAsvi/MYXEyo8qWiBUacvBaveWOlV4w== X-Received: by 2002:a17:902:7e82:b0:1d0:b9f4:800f with SMTP id z2-20020a1709027e8200b001d0b9f4800fmr3698333pla.109.1702014911528; Thu, 07 Dec 2023 21:55:11 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id s22-20020a170902989600b001ce5b859a59sm786250plp.305.2023.12.07.21.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 21:55:11 -0800 (PST) From: Samuel Holland To: linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-riscv@lists.infradead.org, Christoph Hellwig Cc: linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arch@vger.kernel.org, Samuel Holland Subject: [RFC PATCH 07/12] powerpc: Implement ARCH_HAS_KERNEL_FPU_SUPPORT Date: Thu, 7 Dec 2023 21:54:37 -0800 Message-ID: <20231208055501.2916202-8-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231208055501.2916202-1-samuel.holland@sifive.com> References: <20231208055501.2916202-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_215512_261721_AB98167C X-CRM114-Status: GOOD ( 14.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Signed-off-by: Samuel Holland Reviewed-by: Christoph Hellwig --- arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 5 ++++- arch/powerpc/include/asm/fpu.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/fpu.h diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 6f105ee4f3cf..e96cb5b7c571 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -137,6 +137,7 @@ config PPC select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HUGEPD if HUGETLB_PAGE select ARCH_HAS_KCOV + select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKS select ARCH_HAS_MEMBARRIER_SYNC_CORE select ARCH_HAS_MEMREMAP_COMPAT_ALIGN if PPC_64S_HASH_MMU diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index f19dbaa1d541..2d5f21baf6ff 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -142,6 +142,9 @@ CFLAGS-$(CONFIG_PPC32) += $(call cc-option, $(MULTIPLEWORD)) CFLAGS-$(CONFIG_PPC32) += $(call cc-option,-mno-readonly-in-sdata) +CC_FLAGS_FPU := $(call cc-option,-mhard-float) +CC_FLAGS_NO_FPU += $(call cc-option,-msoft-float) + ifdef CONFIG_FUNCTION_TRACER ifdef CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY @@ -163,7 +166,7 @@ asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1) KBUILD_CPPFLAGS += -I $(srctree)/arch/$(ARCH) $(asinstr) KBUILD_AFLAGS += $(AFLAGS-y) -KBUILD_CFLAGS += $(call cc-option,-msoft-float) +KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU) KBUILD_CFLAGS += $(CFLAGS-y) CPP = $(CC) -E $(KBUILD_CFLAGS) diff --git a/arch/powerpc/include/asm/fpu.h b/arch/powerpc/include/asm/fpu.h new file mode 100644 index 000000000000..ca584e4bc40f --- /dev/null +++ b/arch/powerpc/include/asm/fpu.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 SiFive + */ + +#ifndef _ASM_POWERPC_FPU_H +#define _ASM_POWERPC_FPU_H + +#include + +#include +#include + +#define kernel_fpu_available() (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) + +static inline void kernel_fpu_begin(void) +{ + preempt_disable(); + enable_kernel_fp(); +} + +static inline void kernel_fpu_end(void) +{ + disable_kernel_fp(); + preempt_enable(); +} + +#endif /* ! _ASM_POWERPC_FPU_H */