Skip to content

Commit 17f4803

Browse files
committed
genirq / PM: Add flag for shared NO_SUSPEND interrupt lines
It currently is required that all users of NO_SUSPEND interrupt lines pass the IRQF_NO_SUSPEND flag when requesting the IRQ or the WARN_ON_ONCE() in irq_pm_install_action() will trigger. That is done to warn about situations in which unprepared interrupt handlers may be run unnecessarily for suspended devices and may attempt to access those devices by mistake. However, it may cause drivers that have no technical reasons for using IRQF_NO_SUSPEND to set that flag just because they happen to share the interrupt line with something like a timer. Moreover, the generic handling of wakeup interrupts introduced by commit 9ce7a25 (genirq: Simplify wakeup mechanism) only works for IRQs without any NO_SUSPEND users, so the drivers of wakeup devices needing to use shared NO_SUSPEND interrupt lines for signaling system wakeup generally have to detect wakeup in their interrupt handlers. Thus if they happen to share an interrupt line with a NO_SUSPEND user, they also need to request that their interrupt handlers be run after suspend_device_irqs(). In both cases the reason for using IRQF_NO_SUSPEND is not because the driver in question has a genuine need to run its interrupt handler after suspend_device_irqs(), but because it happens to share the line with some other NO_SUSPEND user. Otherwise, the driver would do without IRQF_NO_SUSPEND just fine. To make it possible to specify that condition explicitly, introduce a new IRQ action handler flag for shared IRQs, IRQF_COND_SUSPEND, that, when set, will indicate to the IRQ core that the interrupt user is generally fine with suspending the IRQ, but it also can tolerate handler invocations after suspend_device_irqs() and, in particular, it is capable of detecting system wakeup and triggering it as appropriate from its interrupt handler. That will allow us to work around a problem with a shared timer interrupt line on at91 platforms. Link: http://marc.info/?l=linux-kernel&m=142252777602084&w=2 Link: http://marc.info/?t=142252775300011&r=1&w=2 Link: https://lkml.org/lkml/2014/12/15/552 Reported-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Mark Rutland <mark.rutland@arm.com>
1 parent 737eb03 commit 17f4803

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎include/linux/interrupt.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
* IRQF_NO_THREAD - Interrupt cannot be threaded
6060
* IRQF_EARLY_RESUME - Resume IRQ early during syscore instead of at device
6161
* resume time.
62+
* IRQF_COND_SUSPEND - If the IRQ is shared with a NO_SUSPEND user, execute this
63+
* interrupt handler after suspending interrupts. For system
64+
* wakeup devices users need to implement wakeup detection in
65+
* their interrupt handlers.
6266
*/
6367
#define IRQF_DISABLED 0x00000020
6468
#define IRQF_SHARED 0x00000080
@@ -72,6 +76,7 @@
7276
#define IRQF_FORCE_RESUME 0x00008000
7377
#define IRQF_NO_THREAD 0x00010000
7478
#define IRQF_EARLY_RESUME 0x00020000
79+
#define IRQF_COND_SUSPEND 0x00040000
7580

7681
#define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
7782

‎include/linux/irqdesc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct irq_desc {
7878
#ifdef CONFIG_PM_SLEEP
7979
unsigned int nr_actions;
8080
unsigned int no_suspend_depth;
81+
unsigned int cond_suspend_depth;
8182
unsigned int force_resume_depth;
8283
#endif
8384
#ifdef CONFIG_PROC_FS

‎kernel/irq/manage.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,13 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler,
14741474
* otherwise we'll have trouble later trying to figure out
14751475
* which interrupt is which (messes up the interrupt freeing
14761476
* logic etc).
1477+
*
1478+
* Also IRQF_COND_SUSPEND only makes sense for shared interrupts and
1479+
* it cannot be set along with IRQF_NO_SUSPEND.
14771480
*/
1478-
if ((irqflags & IRQF_SHARED) && !dev_id)
1481+
if (((irqflags & IRQF_SHARED) && !dev_id) ||
1482+
(!(irqflags & IRQF_SHARED) && (irqflags & IRQF_COND_SUSPEND)) ||
1483+
((irqflags & IRQF_NO_SUSPEND) && (irqflags & IRQF_COND_SUSPEND)))
14791484
return -EINVAL;
14801485

14811486
desc = irq_to_desc(irq);

‎kernel/irq/pm.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action)
4343

4444
if (action->flags & IRQF_NO_SUSPEND)
4545
desc->no_suspend_depth++;
46+
else if (action->flags & IRQF_COND_SUSPEND)
47+
desc->cond_suspend_depth++;
4648

4749
WARN_ON_ONCE(desc->no_suspend_depth &&
48-
desc->no_suspend_depth != desc->nr_actions);
50+
(desc->no_suspend_depth +
51+
desc->cond_suspend_depth) != desc->nr_actions);
4952
}
5053

5154
/*
@@ -61,6 +64,8 @@ void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action)
6164

6265
if (action->flags & IRQF_NO_SUSPEND)
6366
desc->no_suspend_depth--;
67+
else if (action->flags & IRQF_COND_SUSPEND)
68+
desc->cond_suspend_depth--;
6469
}
6570

6671
static bool suspend_device_irq(struct irq_desc *desc, int irq)

0 commit comments

Comments
 (0)