From: Imre Kaloz <kaloz@kernel.org>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] MIPS: sgi-ip32: Fence PIO reads on CRIME 1.1
Date: Wed, 21 Oct 2026 21:24:18 +0200 [thread overview]
Message-ID: <20261021192418.7246-5-kaloz@kernel.org> (raw)
In-Reply-To: <20261021192418.7246-1-kaloz@kernel.org>
On CRIME 1.1, a MACE or PCI read within about 2us of a read of some PCI
registers (aic7880 HCNTRL, INTSTAT, ERROR) can return that read's data.
Under audio and SCSI DMA, repeating aic7xxx's ahc_pause(), register
read, ahc_unpause() hangs the machine; fenced, it runs clean, as
measured on an O2 with a CRIME 1.1. The next read can be an interrupt
handler's, so the fence follows the trigger.
Add a read hook to the MIPS accessors that, on CRIME 1.1, follows each
MMIO and port read by 5us with interrupts off. Other platforms compile
it out.
Signed-off-by: Imre Kaloz <kaloz@kernel.org>
---
arch/mips/include/asm/io.h | 11 +++++++
.../include/asm/mach-generic/read-fence.h | 20 +++++++++++++
arch/mips/include/asm/mach-ip32/read-fence.h | 29 +++++++++++++++++++
arch/mips/sgi-ip32/crime.c | 12 ++++++++
4 files changed, 72 insertions(+)
create mode 100644 arch/mips/include/asm/mach-generic/read-fence.h
create mode 100644 arch/mips/include/asm/mach-ip32/read-fence.h
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index 980187a83053..a5c49d319546 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -26,6 +26,7 @@
#include <asm/pgtable-bits.h>
#include <asm/string.h>
#include <mangle-port.h>
+#include <read-fence.h>
/*
* Raw operations are never swapped in software. OTOH values that raw
@@ -222,6 +223,8 @@ static inline void pfx##write##bwlq(type val, \
static inline type pfx##read##bwlq(const volatile void __iomem *mem) \
{ \
volatile type *__mem; \
+ unsigned long __rflags; \
+ bool __fence; \
type __val; \
\
__mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \
@@ -229,6 +232,7 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \
if (barrier) \
iobarrier_rw(); \
\
+ __fence = plat_read_fence_begin(&__rflags); \
if (sizeof(type) != sizeof(u64) || sizeof(u64) == sizeof(long)) \
__val = *__mem; \
else if (cpu_has_64bits) { \
@@ -251,6 +255,8 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \
__val = 0; \
BUG(); \
} \
+ if (__fence) \
+ plat_read_fence_end(__rflags); \
\
/* prevent prefetching of coherent DMA data prematurely */ \
if (!relax) \
@@ -283,6 +289,8 @@ static inline void pfx##out##bwlq(type val, unsigned long port) \
static inline type pfx##in##bwlq(unsigned long port) \
{ \
volatile type *__addr; \
+ unsigned long __rflags; \
+ bool __fence; \
type __val; \
\
__addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \
@@ -292,7 +300,10 @@ static inline type pfx##in##bwlq(unsigned long port) \
if (barrier) \
iobarrier_rw(); \
\
+ __fence = plat_read_fence_begin(&__rflags); \
__val = *__addr; \
+ if (__fence) \
+ plat_read_fence_end(__rflags); \
\
/* prevent prefetching of coherent DMA data prematurely */ \
if (!relax) \
diff --git a/arch/mips/include/asm/mach-generic/read-fence.h b/arch/mips/include/asm/mach-generic/read-fence.h
new file mode 100644
index 000000000000..0147ed88bc01
--- /dev/null
+++ b/arch/mips/include/asm/mach-generic/read-fence.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_MACH_GENERIC_READ_FENCE_H
+#define __ASM_MACH_GENERIC_READ_FENCE_H
+
+#include <linux/types.h>
+
+/*
+ * Called around every MMIO and port read; plat_read_fence_end() runs only
+ * when plat_read_fence_begin() returned true.
+ */
+static inline bool plat_read_fence_begin(unsigned long *flags)
+{
+ return false;
+}
+
+static inline void plat_read_fence_end(unsigned long flags)
+{
+}
+
+#endif /* __ASM_MACH_GENERIC_READ_FENCE_H */
diff --git a/arch/mips/include/asm/mach-ip32/read-fence.h b/arch/mips/include/asm/mach-ip32/read-fence.h
new file mode 100644
index 000000000000..7e3105af4c6f
--- /dev/null
+++ b/arch/mips/include/asm/mach-ip32/read-fence.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_MACH_IP32_READ_FENCE_H
+#define __ASM_MACH_IP32_READ_FENCE_H
+
+#include <linux/irqflags.h>
+#include <linux/types.h>
+
+extern bool crime_read_fence;
+void crime_read_fence_end(unsigned long flags);
+
+/*
+ * CRIME 1.1 can return a PCI read's data again to the next MACE or PCI
+ * read issued within about 2us, so each read is followed by 5us with
+ * interrupts off.
+ */
+static inline bool plat_read_fence_begin(unsigned long *flags)
+{
+ if (!crime_read_fence)
+ return false;
+ local_irq_save(*flags);
+ return true;
+}
+
+static inline void plat_read_fence_end(unsigned long flags)
+{
+ crime_read_fence_end(flags);
+}
+
+#endif /* __ASM_MACH_IP32_READ_FENCE_H */
diff --git a/arch/mips/sgi-ip32/crime.c b/arch/mips/sgi-ip32/crime.c
index a24424437c6b..0b94150fbec1 100644
--- a/arch/mips/sgi-ip32/crime.c
+++ b/arch/mips/sgi-ip32/crime.c
@@ -7,6 +7,7 @@
* Copyright (C) 2005 Ilya A. Volynets <ilya@total-knowledge.com>
*/
#include <linux/types.h>
+#include <linux/delay.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
@@ -25,6 +26,16 @@ struct sgi_mace __iomem *mace;
EXPORT_SYMBOL_GPL(mace);
+bool crime_read_fence __read_mostly;
+EXPORT_SYMBOL(crime_read_fence);
+
+void crime_read_fence_end(unsigned long flags)
+{
+ udelay(5);
+ local_irq_restore(flags);
+}
+EXPORT_SYMBOL(crime_read_fence_end);
+
void __init crime_init(void)
{
static const char * const revs[] = { "1.1", "1.3", "1.4" };
@@ -41,6 +52,7 @@ void __init crime_init(void)
switch (id & CRIME_ID_IDBITS) {
case CRIME_ID_IDVALUE:
rev = revs[min_t(u64, id >> 32, ARRAY_SIZE(revs) - 1)];
+ crime_read_fence = !(id >> 32);
break;
case CRIME_ID_IDVALUE_B:
rev = "1.5";
--
2.47.3
prev parent reply other threads:[~2026-10-21 19:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 19:24 [PATCH 0/4] MIPS: sgi-ip32: CRIME 1.1 and MACE PCI fixes Imre Kaloz
2026-10-21 19:24 ` [PATCH 1/4] MIPS: sgi-ip32: Mask MACE PCI interrupts in CRIME only Imre Kaloz
2026-10-21 19:24 ` [PATCH 2/4] MIPS: sgi-ip32: Leave MACE PCI control alone in config accesses Imre Kaloz
2026-10-21 19:24 ` [PATCH 3/4] MIPS: sgi-ip32: Report the real CRIME revision Imre Kaloz
2026-10-21 19:24 ` Imre Kaloz [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=20261021192418.7246-5-kaloz@kernel.org \
--to=kaloz@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@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
all inboxes | Powered by JetHome®