Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Jiaxun Yang <jiaxun.yang@flygoat.com>,
	stable@vger.kernel.org
Subject: [PATCH fixes 4/4] MIPS: Use toolchain MT ASE support whenever possible
Date: Sun, 16 Jun 2024 14:25:05 +0100	[thread overview]
Message-ID: <20240616-mips-mt-fixes-v1-4-83913e0e60fc@flygoat.com> (raw)
In-Reply-To: <20240616-mips-mt-fixes-v1-0-83913e0e60fc@flygoat.com>

Probe toolchain support to MT ASE and use it in code whenever
possible.

Fix build on MIPS downstream toolchain that is not really happy
with our .insn usage.

Cc: stable@vger.kernel.org
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 arch/mips/Makefile                 |  2 +
 arch/mips/include/asm/asmmacro.h   | 75 ++++++++++++++++++++++++++++++++++++--
 arch/mips/include/asm/mipsmtregs.h | 40 ++++++++++++++++++++
 3 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 80aecba24892..e3d1c5a0e8e9 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -257,6 +257,8 @@ toolchain-dsp				:= $(call cc-option-yn,$(mips-cflags) -Wa$(comma)-mdsp)
 cflags-$(toolchain-dsp)			+= -DTOOLCHAIN_SUPPORTS_DSP
 toolchain-ginv				:= $(call cc-option-yn,$(mips-cflags) -Wa$(comma)-mginv)
 cflags-$(toolchain-ginv)		+= -DTOOLCHAIN_SUPPORTS_GINV
+toolchain-mt				:= $(call cc-option-yn,$(mips-cflags) -Wa$(comma)-mt)
+cflags-$(toolchain-mt)			+= -DTOOLCHAIN_SUPPORTS_MT
 
 #
 # Firmware support
diff --git a/arch/mips/include/asm/asmmacro.h b/arch/mips/include/asm/asmmacro.h
index 6eadd59f53e9..b60fa51e5fbb 100644
--- a/arch/mips/include/asm/asmmacro.h
+++ b/arch/mips/include/asm/asmmacro.h
@@ -318,9 +318,77 @@
 	.endm
 #endif /* !CONFIG_CPU_MIPSR2 && !CONFIG_CPU_MIPSR5 && !CONFIG_CPU_MIPSR6 */
 
-/*
- * Temporary until all gas have MT ASE support
- */
+#ifdef TOOLCHAIN_SUPPORTS_MT
+	.macro	_dmt	reg = $0
+	.set	push
+	.set	mt
+	dmt	\reg
+	.set	pop
+	.endm
+
+	.macro	_emt	reg = $0
+	.set	push
+	.set	mt
+	emt	\reg
+	.set	pop
+	.endm
+
+	.macro	_dvpe	reg = $0
+	.set	push
+	.set	mt
+	dvpe	\reg
+	.set	pop
+	.endm
+
+	.macro	_evpe	reg = $0
+	.set	push
+	.set	mt
+	evpe	\reg
+	.set	pop
+	.endm
+
+	.macro	_mftr	rs, rt, u, sel, h = 0
+	.set	push
+	.set	mt
+	mftr	\rs, \rt, \u, \sel, \h
+	.set	pop
+	.endm
+
+	.macro	_mttr	rt, rs, u, sel, h = 0
+	.set	push
+	.set	mt
+	mttr	\rt, \rs, \u, \sel, \h
+	.set	pop
+	.endm
+
+	.macro	_mftc0	rs, rt, sel = 0
+	.set	push
+	.set	mt
+	mftc0	\rs, \rt, \sel
+	.set	pop
+	.endm
+
+	.macro	_mttc0	rt, rs, sel = 0
+	.set	push
+	.set	mt
+	mttc0	\rt, \rs, \sel
+	.set	pop
+	.endm
+
+	.macro	_mftgpr	rs, rt
+	.set	push
+	.set	mt
+	mftgpr	\rs, \rt
+	.set	pop
+	.endm
+
+	.macro	_mttgpr	rs, rt
+	.set	push
+	.set	mt
+	mttgpr	\rs, \rt
+	.set	pop
+	.endm
+#else
 	.macro	_dmt	reg = $0
 	parse_r		__reg, \reg
 	insn_if_mips	0x41600bc1 | (__reg << 16)
@@ -374,6 +442,7 @@
 	.macro	_mttgpr	rs, rt
 	_mttr		\rt, \rs, 1, 0, 0
 	.endm
+#endif
 
 #ifdef TOOLCHAIN_SUPPORTS_MSA
 	.macro	_cfcmsa	rd, cs
diff --git a/arch/mips/include/asm/mipsmtregs.h b/arch/mips/include/asm/mipsmtregs.h
index b1ee3c48e84b..93b8aa807b82 100644
--- a/arch/mips/include/asm/mipsmtregs.h
+++ b/arch/mips/include/asm/mipsmtregs.h
@@ -189,11 +189,16 @@ static inline unsigned core_nvpes(void)
 	return ((conf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
 }
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_DVPE							\
 	_ASM_MACRO_1R(dvpe, rt,						\
 			_ASM_INSN_IF_MIPS(0x41600001 | __rt << 16)	\
 			_ASM_INSN32_IF_MM(0x0000157C | __rt << 21))
 #define _ASM_UNSET_DVPE ".purgem dvpe\n\t"
+#else
+#define _ASM_SET_DVPE ".set\tmt\n\t"
+#define _ASM_UNSET_DVPE
+#endif
 
 static inline unsigned int dvpe(void)
 {
@@ -214,11 +219,16 @@ static inline unsigned int dvpe(void)
 	return res;
 }
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_EVPE							\
 	_ASM_MACRO_1R(evpe, rt,					\
 			_ASM_INSN_IF_MIPS(0x41600021 | __rt << 16)	\
 			_ASM_INSN32_IF_MM(0x0000357C | __rt << 21))
 #define _ASM_UNSET_EVPE ".purgem evpe\n\t"
+#else
+#define _ASM_SET_EVPE ".set\tmt\n\t"
+#define _ASM_UNSET_EVPE
+#endif
 
 static inline void __raw_evpe(void)
 {
@@ -243,11 +253,16 @@ static inline void evpe(int previous)
 		__raw_evpe();
 }
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_DMT							\
 	_ASM_MACRO_1R(dmt, rt,						\
 			_ASM_INSN_IF_MIPS(0x41600bc1 | __rt << 16)	\
 			_ASM_INSN32_IF_MM(0x0000057C | __rt << 21))
 #define _ASM_UNSET_DMT ".purgem dmt\n\t"
+#else
+#define _ASM_SET_DMT ".set\tmt\n\t"
+#define _ASM_UNSET_DMT
+#endif
 
 static inline unsigned int dmt(void)
 {
@@ -268,11 +283,16 @@ static inline unsigned int dmt(void)
 	return res;
 }
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_EMT							\
 	_ASM_MACRO_1R(emt, rt,						\
 			_ASM_INSN_IF_MIPS(0x41600be1 | __rt << 16)	\
 			_ASM_INSN32_IF_MM(0x0000257C | __rt << 21))
 #define _ASM_UNSET_EMT ".purgem emt\n\t"
+#else
+#define _ASM_SET_EMT ".set\tmt\n\t"
+#define _ASM_UNSET_EMT
+#endif
 
 static inline void __raw_emt(void)
 {
@@ -306,6 +326,7 @@ static inline void ehb(void)
 	"	.set	pop				\n");
 }
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_MFTC0							\
 	_ASM_MACRO_2R_1S(mftc0, rs, rt, sel,				\
 			_ASM_INSN_IF_MIPS(0x41000000 | __rt << 16 |	\
@@ -313,6 +334,10 @@ static inline void ehb(void)
 			_ASM_INSN32_IF_MM(0x0000000E | __rt << 21 |	\
 				__rs << 16 | \\sel << 4))
 #define _ASM_UNSET_MFTC0 ".purgem mftc0\n\t"
+#else
+#define _ASM_SET_MFTC0 ".set\tmt\n\t"
+#define _ASM_UNSET_MFTC0
+#endif
 
 #define mftc0(rt, sel)							\
 ({									\
@@ -330,6 +355,7 @@ static inline void ehb(void)
 	__res;								\
 })
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_MFTGPR							\
 	_ASM_MACRO_2R(mftgpr, rs, rt,					\
 			_ASM_INSN_IF_MIPS(0x41000020 | __rt << 16 |	\
@@ -337,6 +363,10 @@ static inline void ehb(void)
 			_ASM_INSN32_IF_MM(0x0000040E | __rt << 21 |	\
 				__rs << 16))
 #define _ASM_UNSET_MFTGPR ".purgem mftgpr\n\t"
+#else
+#define _ASM_SET_MFTGPR ".set\tmt\n\t"
+#define _ASM_UNSET_MFTGPR
+#endif
 
 #define mftgpr(rt)							\
 ({									\
@@ -365,6 +395,7 @@ static inline void ehb(void)
 	__res;								\
 })
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_MTTGPR							\
 	_ASM_MACRO_2R(mttgpr, rt, rs,					\
 			_ASM_INSN_IF_MIPS(0x41800020 | __rt << 16 |	\
@@ -372,6 +403,10 @@ static inline void ehb(void)
 			_ASM_INSN32_IF_MM(0x00000406 | __rt << 21 |	\
 				__rs << 16))
 #define _ASM_UNSET_MTTGPR ".purgem mttgpr\n\t"
+#else
+#define _ASM_SET_MTTGPR ".set\tmt\n\t"
+#define _ASM_UNSET_MTTGPR
+#endif
 
 #define mttgpr(rs, v)							\
 do {									\
@@ -385,6 +420,7 @@ do {									\
 	: : "r" (v));							\
 } while (0)
 
+#ifndef TOOLCHAIN_SUPPORTS_MT
 #define _ASM_SET_MTTC0							\
 	_ASM_MACRO_2R_1S(mttc0, rt, rs, sel,				\
 			_ASM_INSN_IF_MIPS(0x41800000 | __rt << 16 |	\
@@ -392,6 +428,10 @@ do {									\
 			_ASM_INSN32_IF_MM(0x0000040E | __rt << 21 |	\
 				__rs << 16 | \\sel << 4))
 #define _ASM_UNSET_MTTC0 ".purgem mttc0\n\t"
+#else
+#define _ASM_SET_MTTC0 ".set\tmt\n\t"
+#define _ASM_UNSET_MTTC0
+#endif
 
 #define mttc0(rs, sel, v)							\
 ({									\

-- 
2.43.0


      parent reply	other threads:[~2024-06-16 13:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-16 13:25 [PATCH fixes 0/4] MIPS: MT ASE fixes Jiaxun Yang
2024-06-16 13:25 ` [PATCH fixes 1/4] MIPS: mipsmtregs: Fix target register for MFTC0 Jiaxun Yang
2024-06-19 11:32   ` Jiaxun Yang
2024-06-19 11:37     ` Jiaxun Yang
2024-06-20 14:43       ` Thomas Bogendoerfer
2024-06-21  8:25   ` Thomas Bogendoerfer
2024-06-16 13:25 ` [PATCH fixes 2/4] MIPS: asmmacro: Fix MT ASE macros Jiaxun Yang
2024-06-16 13:25 ` [PATCH fixes 3/4] MIPS: cps-vec: Replace MT instructions with macros Jiaxun Yang
2024-06-27  9:00   ` Thomas Bogendoerfer
2024-06-27 11:14     ` Jiaxun Yang
2024-06-27 19:51       ` Maciej W. Rozycki
2024-06-28  0:36         ` Jiaxun Yang
2024-06-16 13:25 ` Jiaxun Yang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240616-mips-mt-fixes-v1-4-83913e0e60fc@flygoat.com \
    --to=jiaxun.yang@flygoat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox