Generic IRQs: proper edge/level via irq_chip->set_type hook
I'm trying to cleanup/remove the use of handle_simple_irq in the OMAP GPIO IRQ handling.
Currently, the OMAP GPIO demux handler uses handle_simple_irq for all the GPIOs whether they are edge or level. The result is duplicated logic with handle_[edge|level]_irq as well as things not working correctly for threaded interrupts with the -rt patch.
Currently, upon init, the handlers for all GPIO IRQs are initialized to handle_simple_irq. This is fine, since before the interrupts are registered via request_irq or setup_irq, we don't know if they are edge or level.
When request_irq or setup_irq are called, the type of interrupt (edge or level) is known and the 'set_type' hook of the irq_chip is called to set the triggering accordingly. It seems to me this is also the appropriate place to change the handler from handle_simple_irq to handle_[edge|level]_irq via a call to set_irq_handler().
The problem is that when the 'set_type' hook is called the irq_desc->lock is held by setup_irq(), so a call to set_irq_handler() dies with a recursive lock.
The hack below allows me to get the above idea working, but I'm looking for better suggestions on how to rework the locking here so that the handler might be changed from within the irq_chip's set_type handler.
Any ideas?
Kevin
kernel/irq/manage.c +4 -2
@@ -369,10 +369,12 @@ int setup_irq(unsigned int irq, struct irqaction *new)/* Setup the type (level, edge polarity) if configured: */ if (new->flags &IRQF_TRIGGER_MASK ) { -if (desc->chip && desc->chip->set_type) +if (desc->chip && desc->chip->set_type) { +spin_unlock (&desc->lock); desc->chip->set_type (irq, new->flags &IRQF_TRIGGER_MASK ); -else +spin_lock (&desc->lock); + }else /* * IRQF_TRIGGER_* but the PIC does not support * multiple flow-types?
Quoted 6 lines · Kevin Hilman
The hack below allows me to get the above idea working, but I'm looking for better suggestions on how to rework the locking here so that the handler might be changed from within the irq_chip's
set_typehandler.Any ideas?
As I'm sure you know, this problem can show up on most platforms. It's not limited to OMAP; more generic solutions are needed.
One solution would have the irq_chip.set_type() method just call
/* caller has locked the irq_desc and both params are valid */
static inline void __set_irq_handler_unlocked(int irq, irq_flow_handler_t handler)
{
irq_desc[irq].handler = handler;
}Another solution, limited to chained handlers, is to have the chaining handler call the right handler (edge or level) directly instead of calling generic_handle_irq():
if (desc->status & IRQ_LEVEL) handle_level_irq(irq, desc); else handle_edge_irq(irq, desc);
Of course that requires set_type() to maintain that status flag, which currently isn't handled by the genirq core. Equivalently it might mask against (IRQ_TYPE_LEVEL_HIGH|IRQ_TYPE_LEVEL_LOW), which again isn't handled by the genirq core but is handled by the GPIO logic in the OMAP tree.
- Dave
Quoted 10 lines · David Brownell
Quoted 6 lines · Kevin Hilman
The hack below allows me to get the above idea working, but I'm looking for better suggestions on how to rework the locking here so that the handler might be changed from within the irq_chip's
set_typehandler.Any ideas?
As I'm sure you know, this problem can show up on most platforms. It's not limited to OMAP; more generic solutions are needed.
Agreed.
Quoted 7 lines
One solution would have the
irq_chip.set_type()method just call/* caller has locked the
irq_descand both params are valid */
static inline void__set_irq_handler_unlocked(int irq, irq_flow_handler_t handler){ irq_desc[irq].handler = handler; }
I like this. For starters, I'll submit an RFC patcheset to the OMAP list which adds this and then fixes up the OMAP GPIO handlers to use it, as well as a couple other fixes/cleanups for OMAP.
Quoted 11 lines
Another solution, limited to chained handlers, is to have the chaining handler call the right handler (edge or level) directly instead of calling
generic_handle_irq():if (desc->status & IRQ_LEVEL) handle_level_irq(irq, desc); else handle_edge_irq(irq, desc);Of course that requires
set_type()to maintain that status flag, which currently isn't handled by the genirq core.
This is what I'm currently doing, but I was hoping for something a bit more generic that other platforms could use too.
Quoted 6 lines
Equivalently it might mask against (IRQ_TYPE_LEVEL_HIGH|IRQ_TYPE_LEVEL_LOW), which again isn't handled by the genirq core but is handled by the GPIO logic in the OMAP tree.
- Dave