Module Name:    src
Committed By:   jmcneill
Date:           Thu Mar 13 18:41:34 UTC 2025

Modified Files:
        src/sys/arch/evbppc/wii: pic_pi.c

Log Message:
wii: Revert pic_pi.c r1.2 and r1.3.

The simplification of pic_pi.c in r1.2 introduced a performance regression
with sdhc. Revert to the original implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbppc/wii/pic_pi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbppc/wii/pic_pi.c
diff -u src/sys/arch/evbppc/wii/pic_pi.c:1.3 src/sys/arch/evbppc/wii/pic_pi.c:1.4
--- src/sys/arch/evbppc/wii/pic_pi.c:1.3	Sun Feb 16 12:45:25 2025
+++ src/sys/arch/evbppc/wii/pic_pi.c	Thu Mar 13 18:41:34 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: pic_pi.c,v 1.3 2025/02/16 12:45:25 jmcneill Exp $ */
+/* $NetBSD: pic_pi.c,v 1.4 2025/03/13 18:41:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2024 Jared McNeill <jmcne...@invisible.ca>
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pic_pi.c,v 1.3 2025/02/16 12:45:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_pi.c,v 1.4 2025/03/13 18:41:34 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/intr.h>
@@ -45,6 +45,9 @@ __KERNEL_RCSID(0, "$NetBSD: pic_pi.c,v 1
 #include <arch/powerpc/pic/picvar.h>
 #include <machine/wii.h>
 
+static uint32_t pic_irqmask;
+static uint32_t pic_actmask;
+
 void pi_init_intr(void);
 
 #define WR4(reg, val)	out32(reg, val)
@@ -53,29 +56,32 @@ void pi_init_intr(void);
 static void
 pi_enable_irq(struct pic_ops *pic, int irq, int type)
 {
-	WR4(PI_INTMR, RD4(PI_INTMR) | __BIT(irq));
+	pic_irqmask |= __BIT(irq);
+	WR4(PI_INTMR, pic_irqmask & ~pic_actmask);
 }
 
 static void
 pi_disable_irq(struct pic_ops *pic, int irq)
 {
-	WR4(PI_INTMR, RD4(PI_INTMR) & ~__BIT(irq));
+	pic_irqmask &= ~__BIT(irq);
+	WR4(PI_INTMR, pic_irqmask & ~pic_actmask);
 }
 
 static int
 pi_get_irq(struct pic_ops *pic, int mode)
 {
-	static uint32_t pend;
+	uint32_t raw, pend;
 	int irq;
 
-	if (mode == PIC_GET_IRQ) {
-		pend = RD4(PI_INTSR) & RD4(PI_INTMR);
-	}
+	raw = RD4(PI_INTSR);
+	pend = raw & pic_irqmask;
 	if (pend == 0) {
 		return 255;
 	}
 	irq = ffs32(pend) - 1;
-	pend &= ~__BIT(irq);
+
+	pic_actmask |= __BIT(irq);
+	WR4(PI_INTMR, pic_irqmask & ~pic_actmask);
 
 	return irq;
 }
@@ -83,6 +89,8 @@ pi_get_irq(struct pic_ops *pic, int mode
 static void
 pi_ack_irq(struct pic_ops *pic, int irq)
 {
+	pic_actmask &= ~__BIT(irq);
+	WR4(PI_INTMR, pic_irqmask & ~pic_actmask);
 	WR4(PI_INTSR, __BIT(irq));
 }
 
@@ -101,6 +109,9 @@ static struct pic_ops pic = {
 void
 pi_init_intr(void)
 {
+	pic_irqmask = 0;
+	pic_actmask = 0;
+
 	/* Mask and clear all interrupts. */
 	WR4(PI_INTMR, 0);
 	WR4(PI_INTSR, ~0U);

Reply via email to