Skip to contentSkip to conversation

irq-type-flags.patch

PATCH Andrew Morton 7 participants 14 messages Nov 9, 2005 – Nov 10, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Is everyone OK with this?

From: Russell King <[email protected]>

Some ARM platforms have the ability to program the interrupt controller to detect various interrupt edges and/or levels. For some platforms, this is critical to setup correctly, particularly those which the setting is dependent on the device.

Currently, ARM drivers do (eg) the following:

	err = request_irq(irq, ...);

	set_irq_type(irq, IRQT_RISING);

However, if the interrupt has previously been programmed to be level sensitive (for whatever reason) then this will cause an interrupt storm.

Hence, if we combine set_irq_type() with request_irq(), we can then safely set the type prior to unmasking the interrupt. The unfortunate problem is that in order to support this, these flags need to be visible outside of the ARM architecture - drivers such as smc91x need these flags and they're cross-architecture.

Finally, the SA_TRIGGER_* flag passed to request_irq() should reflect the property that the device would like. The IRQ controller code should do its best to select the most appropriate supported mode.

---

 arch/arm/kernel/irq.c  |   16 ++++++++++++++--
 include/linux/signal.h |    8 ++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
arch/arm/kernel/irq.c renamed from arch/arm/kernel/irq.c~irq-type-flags +14 -2
diff -puN arch/arm/kernel/irq.c~irq-type-flags arch/arm/kernel/irq.c
@@ -681,10 +681,16 @@ int setup_irq(unsigned int irq, struct i
 	 */
 	desc = irq_desc + irq;
 	spin_lock_irqsave(&irq_controller_lock, flags);
+#define SA_TRIGGER	(SA_TRIGGER_HIGH|SA_TRIGGER_LOW|\
+			 SA_TRIGGER_RISING|SA_TRIGGER_FALLING)
 	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) {
 			spin_unlock_irqrestore(&irq_controller_lock, flags);
 			return -EBUSY;
 		}
@@ -704,6 +710,12 @@ int setup_irq(unsigned int irq, struct i
 		desc->running = 0;
 		desc->pending = 0;
 		desc->disable_depth = 1;
+
+		if (new->flags & SA_TRIGGER) {
+			unsigned int type = new->flags & SA_TRIGGER;
+			desc->chip->set_type(irq, type);
+		}
+
 		if (!desc->noautoenable) {
 			desc->disable_depth = 0;
 			desc->chip->unmask(irq);
include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +8 -0
diff -puN include/linux/signal.h~irq-type-flags include/linux/signal.h
@@ -18,6 +18,14 @@
 #define SA_PROBE		SA_ONESHOT
 #define SA_SAMPLE_RANDOM	SA_RESTART
 #define SA_SHIRQ		0x04000000
+/*
+ * As above, these correspond to the __IRQT defines in asm-arm/irq.h
+ * to select the interrupt line behaviour.
+ */
+#define SA_TRIGGER_HIGH		0x00000008
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001
 
 /*
  * Real Time signals may be queued.

_

#1 lore raw
Quoted 9 lines · Andrew Morton

Is everyone OK with this?
From: Russell King <[email protected]>
Some ARM platforms have the ability to program the interrupt controller to detect various interrupt edges and/or levels. For some platforms, this is critical to setup correctly, particularly those which the setting is dependent on the device.
Currently, ARM drivers do (eg) the following:

	err = request_irq(irq, ...);
	set_irq_type(irq, IRQT_RISING);
Quoted 10 lines

However, if the interrupt has previously been programmed to be level sensitive (for whatever reason) then this will cause an interrupt storm. Hence, if we combine set_irq_type() with request_irq(), we can then safely set the type prior to unmasking the interrupt. The unfortunate problem is that in order to support this, these flags need to be visible outside of the ARM architecture - drivers such as smc91x need these flags and they're cross-architecture.
Finally, the SA_TRIGGER_* flag passed to request_irq() should reflect the property that the device would like. The IRQ controller code should do its best to select the most appropriate supported mode.

This seems innocuous enough to me. I anticipate that this will have no impact on sparc32.

-- wli

#2 lore raw
In reply to Andrew Morton

arch/arm/kernel/irq.c int setup_irq(unsigned int irq, struct i · line 716

Quoted 1 line · Andrew Morton
arch/arm/kernel/irq.c renamed from arch/arm/kernel/irq.c~irq-type-flags +1 -0
+			desc->chip->set_type(irq, type);

How's the error handled if the PIC can't handle the requested type?

It seems like it ought to be wrong that the driver is setting this. It ought to be a property of the arch or the bus.

David

#3 lore raw
Quoted 8 lines · David Howells

arch/arm/kernel/irq.c int setup_irq(unsigned int irq, struct i · line 716

Quoted 1 line · Andrew Morton
arch/arm/kernel/irq.c renamed from arch/arm/kernel/irq.c~irq-type-flags +1 -0
+			desc->chip->set_type(irq, type);

How's the error handled if the PIC can't handle the requested type?

It seems like it ought to be wrong that the driver is setting this. It ought to be a property of the arch or the bus.

No it should not. Neither the arch not the bus dictates what the device manufacturer decides to do with their interrupt output.

It most definitely is a property of the device/driver and not a higher level.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#7 lore raw
In reply to Andrew Morton
Quoted 2 lines · Andrew Morton

Is everyone OK with this?

Looks fine to me, especially if it gets that set_irq_type() stuff out of some of the drivers.

Quoted 40 lines

diff -puN arch/arm/kernel/irq.c~irq-type-flags arch/arm/kernel/irq.c

arch/arm/kernel/irq.c renamed from arch/arm/kernel/irq.c~irq-type-flags +8 -2
@@ -681,10 +681,16 @@ int setup_irq(unsigned int irq, struct i
 	 */
 	desc = irq_desc + irq;
 	spin_lock_irqsave(&irq_controller_lock, flags);
+#define SA_TRIGGER	(SA_TRIGGER_HIGH|SA_TRIGGER_LOW|\
+			 SA_TRIGGER_RISING|SA_TRIGGER_FALLING)
 	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) {
 			spin_unlock_irqrestore(&irq_controller_lock, flags);
 			return -EBUSY;
 		}

diff -puN include/linux/signal.h~irq-type-flags include/linux/signal.h

include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +8 -0
@@ -18,6 +18,14 @@
 #define SA_PROBE		SA_ONESHOT
 #define SA_SAMPLE_RANDOM	SA_RESTART
 #define SA_SHIRQ		0x04000000
+/*
+ * As above, these correspond to the __IRQT defines in asm-arm/irq.h
+ * to select the interrupt line behaviour.
+ */
+#define SA_TRIGGER_HIGH		0x00000008
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001
 
 /*
  * Real Time signals may be queued.
Quoted 1 line

_

It probably makes sense to move SA_TRIGGER here as well, as it's going to be a pretty common mask. Otherwise everyone that plans to make use of this will likely end up duplicating it.

#8 lore raw
Quoted 6 lines · Paul Mundt

include/linux/signal.h line 28

Quoted 3 lines
include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +3 -0
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001

It probably makes sense to move SA_TRIGGER here as well, as it's going to be a pretty common mask. Otherwise everyone that plans to make use of this will likely end up duplicating it.

Are there any other architectures that plan to make use of this?

#9 lore raw
Quoted 9 lines · Matthew Wilcox
Quoted 6 lines · Paul Mundt

include/linux/signal.h line 28

Quoted 3 lines
include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +3 -0
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001

It probably makes sense to move SA_TRIGGER here as well, as it's going to be a pretty common mask. Otherwise everyone that plans to make use of this will likely end up duplicating it.

Are there any other architectures that plan to make use of this?

SH will at least to some extent. There's some older SH-3's that could benefit from this (we currently have some ugly hacks in place to handle the edge cases for some of these legacy devices on these systems, but it's pretty broken at the moment). The newer cores don't have a lot of use for this though.

#10 lore raw
In reply to Matthew Wilcox
Quoted 9 lines · Matthew Wilcox
Quoted 6 lines · Paul Mundt

include/linux/signal.h line 28

Quoted 3 lines
include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +3 -0
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001

It probably makes sense to move SA_TRIGGER here as well, as it's going to be a pretty common mask. Otherwise everyone that plans to make use of this will likely end up duplicating it.

Are there any other architectures that plan to make use of this?

Just to be clear - the primary reason I'm putting these in a shared file is that we don't want to add #ifdefs to drivers (which is what would be necessary if it was placed in asm-arm.)

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#4 lore raw
In reply to Russell King
Quoted 2 lines · Russell King

Neither the arch not the bus dictates what the device manufacturer decides to do with their interrupt output.

On the other hand, the device manufacturer does not decree what the arch and supporting chipset will *accept*. There's no guarantee that all trigger types will be supported. For instance on my ASB2305 board, I've got an on-chip PIC that will accept any of the four trigger types, but the PCI bus interrupt line attached to one of the external interrupt pins will *only* accept low-level triggered. In such a case, the bus *must* override anything set by one of the devices.

David

#11 lore raw
In reply to Russell King
Quoted 9 lines · Russell King
Quoted 8 lines · Matthew Wilcox
Quoted 6 lines · Paul Mundt

include/linux/signal.h line 28

Quoted 3 lines
include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +3 -0
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001

It probably makes sense to move SA_TRIGGER here as well, as it's going to be a pretty common mask. Otherwise everyone that plans to make use of this will likely end up duplicating it.

Quoted 5 lines
Quoted 1 line

Are there any other architectures that plan to make use of this?

Just to be clear - the primary reason I'm putting these in a shared file is that we don't want to add #ifdefs to drivers (which is what would be necessary if it was placed in asm-arm.)

Certainly. The question is whether it makes sense to put the SA_TRIGGER define (being the | of all these) in arch files or in the common files. And it sounds like since SH also needs to use this, that should also go in adjacent to the SA_TRIGGER_* defines.

#5 lore raw
In reply to David Howells
Quoted 7 lines · David Howells
Quoted 2 lines · Russell King

Neither the arch not the bus dictates what the device manufacturer decides to do with their interrupt output.

On the other hand, the device manufacturer does not decree what the arch and supporting chipset will *accept*.

David, you have completely the wrong idea about this. The driver does not decree anything. The driver is telling the IRQ subsystem what type of interrupt the chip produces.

If an _architecture_ wants to indirect that through something, all well and good - it can, but that's up to the architectures request_irq() internals.

Quoted 6 lines

There's no guarantee that all trigger types
will be supported. For instance on my ASB2305 board, I've got an on-chip PIC that will accept any of the four trigger types, but the PCI bus interrupt line attached to one of the external interrupt pins will *only* accept low-level triggered. In such a case, the bus *must* override anything set by one of the devices.

We have this scenario on ARM today - for years - and it isn't a problem there. So why is it such a massive problem here?

I think the root of this issue is that you're thinking that the driver uses this to dictate to the interrupt controller what it wants the controller to program itself for. It's more a case that the driver is saying "my device produces this kind of interrupt, please configure the input appropriately."

Maybe the real issue here is that we should have dev_request_irq which takes a struct device? That's another, separate, orthogonal interface extension which those who require it can work on.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#12 lore raw
In reply to Matthew Wilcox
Quoted 12 lines · Matthew Wilcox
Quoted 11 lines · Russell King
Quoted 9 lines · Matthew Wilcox
Quoted 6 lines · Paul Mundt

include/linux/signal.h line 28

Quoted 3 lines
include/linux/signal.h renamed from include/linux/signal.h~irq-type-flags +3 -0
+#define SA_TRIGGER_LOW		0x00000004
+#define SA_TRIGGER_RISING	0x00000002
+#define SA_TRIGGER_FALLING	0x00000001

It probably makes sense to move SA_TRIGGER here as well, as it's going to be a pretty common mask. Otherwise everyone that plans to make use of this will likely end up duplicating it.

Are there any other architectures that plan to make use of this?

Quoted 8 lines
Quoted 3 lines

Just to be clear - the primary reason I'm putting these in a shared file is that we don't want to add #ifdefs to drivers (which is what would be necessary if it was placed in asm-arm.)

Certainly. The question is whether it makes sense to put the SA_TRIGGER define (being the | of all these) in arch files or in the common files. And it sounds like since SH also needs to use this, that should also go in adjacent to the SA_TRIGGER_* defines.

I'm fine with moving it there. Shall I do a new patch?

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#6 lore raw
In reply to Russell King
Quoted 5 lines · Russell King

I think the root of this issue is that you're thinking that the driver uses this to dictate to the interrupt controller what it wants the controller to program itself for. It's more a case that the driver is saying "my device produces this kind of interrupt, please configure the input appropriately."

Okay.

Still, I'd like to see some handling for a mismatch - the case in which the driver says "my device can produce X" but X isn't available with that PIC/bus combination. Or maybe provide a way (if there isn't one already) for the driver to query the available trigger types. Some devices I've come across have configurable interrupt generators.

David

#13 lore raw
In reply to Andrew Morton
Quoted 2 lines · Andrew Morton

Is everyone OK with this?

These flags will be nops on x86 and many other architectures. Could be confusing to driver writers. Can this please be made clear in comments?

-Andi

Quoted 1 line