[PATCH 4/4] MIPS: sgi-ip32: Fence PIO reads on CRIME 1.1
From: Imre Kaloz
Date: Wed Oct 21 2026 - 15:25:58 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxxxxxxxxxxxx>
*/
#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