Skip to contentSkip to conversation

generic hardirq type setting

PATCH In review Paul Mundt 1 participant 2 messages Jan 19, 2006

Subsystems (3)
lore
Share & tools
lore

Paul Mundt

author
#0 lore raw

PATCH 1/1 generic hardirq type setting

Now that Russell's SA_TRIGGER_* changes went in, I've been updating some of the SH code to support it. ARM supports a ->set_type() through its struct irqchip so doesn't have to deal with this, but this requires a bit more work for architectures that are using generic hardirqs.

I've added a ->set_type() to struct hw_interrupt_type to deal with this, which seems like the least invasive solution. dhowells made a note about handling and returning errors for invalid type configurations when Russell's initial patch was posted, so I've implemented this as well.

Any comments?

---

 arch/sh/kernel/cpu/irq/pint.c |   19 +++++++++++++++++++
 include/linux/irq.h           |    1 +
 kernel/irq/manage.c           |   19 +++++++++++++++++--
 3 files changed, 37 insertions(+), 2 deletions(-)
arch/sh/kernel/cpu/irq/pint.c +19 -0
index 95d6024..ca4bb94 100644
@@ -37,9 +37,28 @@ static unsigned int startup_pint_irq(uns
 	return 0; /* never anything pending */
 }
 
+static int set_type_pint_irq(unsigned int irq, unsigned int type)
+{
+	unsigned int val;
+
+	/* Only level detection is possible */
+	if (unlikely(!(type & (SA_TRIGGER_HIGH | SA_TRIGGER_LOW))))
+		return -EINVAL;
+
+	val = ctrl_inw(INTC_ICR2);
+	if (type & SA_TRIGGER_HIGH)
+		val |= (1 << (irq - PINT_IRQ_BASE));
+	else
+		val &= ~(1 << (irq - PINT_IRQ_BASE));
+	ctrl_outw(val, INTC_ICR2);
+
+	return 0;
+}
+
 static struct hw_interrupt_type pint_irq_type = {
 	.typename = "PINT-IRQ",
 	.startup = startup_pint_irq,
+	.set_type = set_type_pint_irq,
 	.shutdown = shutdown_pint_irq,
 	.enable = enable_pint_irq,
 	.disable = disable_pint_irq,
include/linux/irq.h +1 -0
index 6c5d4c8..904cffa 100644
@@ -53,6 +53,7 @@ struct hw_interrupt_type {
 	void (*ack)(unsigned int irq);
 	void (*end)(unsigned int irq);
 	void (*set_affinity)(unsigned int irq, cpumask_t dest);
+	int (*set_type)(unsigned int irq, unsigned int type);
 	/* Currently used only by UML, might disappear one day.*/
 #ifdef CONFIG_IRQ_RELEASE_METHOD
 	void (*release)(unsigned int irq, void *dev_id);
kernel/irq/manage.c +17 -2
index 97d5559..4ec7c9a 100644
@@ -203,8 +203,12 @@ int setup_irq(unsigned int irq, struct i
 	spin_lock_irqsave(&desc->lock,flags);
 	p = &desc->action;
 	if ((old = *p) != NULL) {
-		/* Can't share interrupts unless both agree to */
-		if (!(old->flags & new->flags & SA_SHIRQ)) {
+		/*
+		 * Can't share interrupts unless both agree to and are
+		 * the same type.
+		 */
+		if (!(old->flags & new->flags & SA_SHIRQ) ||
+		    (~old->flags & new->flags & SA_TRIGGER_MASK)) {
 			spin_unlock_irqrestore(&desc->lock,flags);
 			return -EBUSY;
 		}
@@ -220,6 +224,17 @@ int setup_irq(unsigned int irq, struct i
 	*p = new;
 
 	if (!shared) {
+		if (desc->handler->set_type) {
+			unsigned int type = new->flags & SA_TRIGGER_MASK;
+			int ret;
+
+			ret = desc->handler->set_type(irq, type);
+			if (unlikely(ret != 0)) {
+				spin_unlock_irqrestore(&desc->lock, flags);
+				return ret;
+			}
+		}
+
 		desc->depth = 0;
 		desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT |
 				  IRQ_WAITING | IRQ_INPROGRESS);
author
#1 lore raw
Quoted 10 lines · Paul Mundt

Now that Russell's SA_TRIGGER_* changes went in, I've been updating some of the SH code to support it. ARM supports a ->set_type() through its struct irqchip so doesn't have to deal with this, but this requires a bit more work for architectures that are using generic hardirqs.

I've added a ->set_type() to struct hw_interrupt_type to deal with this, which seems like the least invasive solution. dhowells made a note about handling and returning errors for invalid type configurations when Russell's initial patch was posted, so I've implemented this as well.

And here's the right patch without the misplaced ).. Sorry for the noise.

---

 arch/sh/kernel/cpu/irq/pint.c |   19 +++++++++++++++++++
 include/linux/irq.h           |    1 +
 kernel/irq/manage.c           |   19 +++++++++++++++++--
 3 files changed, 37 insertions(+), 2 deletions(-)
arch/sh/kernel/cpu/irq/pint.c +19 -0
index 95d6024..ca4bb94 100644
@@ -37,9 +37,28 @@ static unsigned int startup_pint_irq(uns
 	return 0; /* never anything pending */
 }
 
+static int set_type_pint_irq(unsigned int irq, unsigned int type)
+{
+	unsigned int val;
+
+	/* Only level detection is possible */
+	if (unlikely(!(type & (SA_TRIGGER_HIGH | SA_TRIGGER_LOW))))
+		return -EINVAL;
+
+	val = ctrl_inw(INTC_ICR2);
+	if (type & SA_TRIGGER_HIGH)
+		val |= (1 << (irq - PINT_IRQ_BASE));
+	else
+		val &= ~(1 << (irq - PINT_IRQ_BASE));
+	ctrl_outw(val, INTC_ICR2);
+
+	return 0;
+}
+
 static struct hw_interrupt_type pint_irq_type = {
 	.typename = "PINT-IRQ",
 	.startup = startup_pint_irq,
+	.set_type = set_type_pint_irq,
 	.shutdown = shutdown_pint_irq,
 	.enable = enable_pint_irq,
 	.disable = disable_pint_irq,
include/linux/irq.h +1 -0
index 6c5d4c8..904cffa 100644
@@ -53,6 +53,7 @@ struct hw_interrupt_type {
 	void (*ack)(unsigned int irq);
 	void (*end)(unsigned int irq);
 	void (*set_affinity)(unsigned int irq, cpumask_t dest);
+	int (*set_type)(unsigned int irq, unsigned int type);
 	/* Currently used only by UML, might disappear one day.*/
 #ifdef CONFIG_IRQ_RELEASE_METHOD
 	void (*release)(unsigned int irq, void *dev_id);
kernel/irq/manage.c +17 -2
index 97d5559..4ec7c9a 100644
@@ -203,8 +203,12 @@ int setup_irq(unsigned int irq, struct i
 	spin_lock_irqsave(&desc->lock,flags);
 	p = &desc->action;
 	if ((old = *p) != NULL) {
-		/* Can't share interrupts unless both agree to */
-		if (!(old->flags & new->flags & SA_SHIRQ)) {
+		/*
+		 * Can't share interrupts unless both agree to and are
+		 * the same type.
+		 */
+		if (!(old->flags & new->flags & SA_SHIRQ) ||
+		    (~old->flags & new->flags) & SA_TRIGGER_MASK) {
 			spin_unlock_irqrestore(&desc->lock,flags);
 			return -EBUSY;
 		}
@@ -220,6 +224,17 @@ int setup_irq(unsigned int irq, struct i
 	*p = new;
 
 	if (!shared) {
+		if (desc->handler->set_type) {
+			unsigned int type = new->flags & SA_TRIGGER_MASK;
+			int ret;
+
+			ret = desc->handler->set_type(irq, type);
+			if (unlikely(ret != 0)) {
+				spin_unlock_irqrestore(&desc->lock, flags);
+				return ret;
+			}
+		}
+
 		desc->depth = 0;
 		desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT |
 				  IRQ_WAITING | IRQ_INPROGRESS);