genirq: Add sanity checks for PM options on shared interrupt lines
[deliverable/linux.git] / kernel / irq / pm.c
CommitLineData
0a0c5168
RW
1/*
2 * linux/kernel/irq/pm.c
3 *
4 * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
5 *
6 * This file contains power management functions related to interrupts.
7 */
8
9#include <linux/irq.h>
10#include <linux/module.h>
11#include <linux/interrupt.h>
9bab0b7f 12#include <linux/syscore_ops.h>
0a0c5168
RW
13
14#include "internals.h"
15
cab303be
TG
16/*
17 * Called from __setup_irq() with desc->lock held after @action has
18 * been installed in the action chain.
19 */
20void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action)
21{
22 desc->nr_actions++;
23
24 if (action->flags & IRQF_FORCE_RESUME)
25 desc->force_resume_depth++;
26
27 WARN_ON_ONCE(desc->force_resume_depth &&
28 desc->force_resume_depth != desc->nr_actions);
29
30 if (action->flags & IRQF_NO_SUSPEND)
31 desc->no_suspend_depth++;
32
33 WARN_ON_ONCE(desc->no_suspend_depth &&
34 desc->no_suspend_depth != desc->nr_actions);
35}
36
37/*
38 * Called from __free_irq() with desc->lock held after @action has
39 * been removed from the action chain.
40 */
41void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action)
42{
43 desc->nr_actions--;
44
45 if (action->flags & IRQF_FORCE_RESUME)
46 desc->force_resume_depth--;
47
48 if (action->flags & IRQF_NO_SUSPEND)
49 desc->no_suspend_depth--;
50}
51
8df2e02c
TG
52static void suspend_device_irq(struct irq_desc *desc, int irq)
53{
54 if (!desc->action || (desc->action->flags & IRQF_NO_SUSPEND))
55 return;
56
57 desc->istate |= IRQS_SUSPENDED;
58 __disable_irq(desc, irq);
59}
60
0a0c5168
RW
61/**
62 * suspend_device_irqs - disable all currently enabled interrupt lines
63 *
8df2e02c
TG
64 * During system-wide suspend or hibernation device drivers need to be
65 * prevented from receiving interrupts and this function is provided
66 * for this purpose.
67 *
68 * So we disable all interrupts and mark them IRQS_SUSPENDED except
69 * for those which are unused and those which are marked as not
70 * suspendable via an interrupt request with the flag IRQF_NO_SUSPEND
71 * set.
0a0c5168
RW
72 */
73void suspend_device_irqs(void)
74{
75 struct irq_desc *desc;
76 int irq;
77
78 for_each_irq_desc(irq, desc) {
79 unsigned long flags;
80
239007b8 81 raw_spin_lock_irqsave(&desc->lock, flags);
8df2e02c 82 suspend_device_irq(desc, irq);
239007b8 83 raw_spin_unlock_irqrestore(&desc->lock, flags);
0a0c5168
RW
84 }
85
86 for_each_irq_desc(irq, desc)
c531e836 87 if (desc->istate & IRQS_SUSPENDED)
0a0c5168
RW
88 synchronize_irq(irq);
89}
90EXPORT_SYMBOL_GPL(suspend_device_irqs);
91
8df2e02c
TG
92static void resume_irq(struct irq_desc *desc, int irq)
93{
94 if (desc->istate & IRQS_SUSPENDED)
95 goto resume;
96
97 if (!desc->action)
98 return;
99
100 /* Interrupts marked with that flag are force reenabled */
101 if (!(desc->action->flags & IRQF_FORCE_RESUME))
102 return;
103
104 /* Pretend that it got disabled ! */
105 desc->depth++;
106resume:
107 desc->istate &= ~IRQS_SUSPENDED;
108 __enable_irq(desc, irq);
109}
110
9bab0b7f 111static void resume_irqs(bool want_early)
0a0c5168
RW
112{
113 struct irq_desc *desc;
114 int irq;
115
116 for_each_irq_desc(irq, desc) {
117 unsigned long flags;
9bab0b7f
IC
118 bool is_early = desc->action &&
119 desc->action->flags & IRQF_EARLY_RESUME;
120
ac01810c 121 if (!is_early && want_early)
9bab0b7f 122 continue;
0a0c5168 123
239007b8 124 raw_spin_lock_irqsave(&desc->lock, flags);
8df2e02c 125 resume_irq(desc, irq);
239007b8 126 raw_spin_unlock_irqrestore(&desc->lock, flags);
0a0c5168
RW
127 }
128}
9bab0b7f
IC
129
130/**
131 * irq_pm_syscore_ops - enable interrupt lines early
132 *
133 * Enable all interrupt lines with %IRQF_EARLY_RESUME set.
134 */
135static void irq_pm_syscore_resume(void)
136{
137 resume_irqs(true);
138}
139
140static struct syscore_ops irq_pm_syscore_ops = {
141 .resume = irq_pm_syscore_resume,
142};
143
144static int __init irq_pm_init_ops(void)
145{
146 register_syscore_ops(&irq_pm_syscore_ops);
147 return 0;
148}
149
150device_initcall(irq_pm_init_ops);
151
152/**
153 * resume_device_irqs - enable interrupt lines disabled by suspend_device_irqs()
154 *
155 * Enable all non-%IRQF_EARLY_RESUME interrupt lines previously
156 * disabled by suspend_device_irqs() that have the IRQS_SUSPENDED flag
157 * set as well as those with %IRQF_FORCE_RESUME.
158 */
159void resume_device_irqs(void)
160{
161 resume_irqs(false);
162}
0a0c5168
RW
163EXPORT_SYMBOL_GPL(resume_device_irqs);
164
165/**
166 * check_wakeup_irqs - check if any wake-up interrupts are pending
167 */
168int check_wakeup_irqs(void)
169{
170 struct irq_desc *desc;
171 int irq;
172
d209a699 173 for_each_irq_desc(irq, desc) {
9c6079aa
TG
174 /*
175 * Only interrupts which are marked as wakeup source
176 * and have not been disabled before the suspend check
177 * can abort suspend.
178 */
d209a699 179 if (irqd_is_wakeup_set(&desc->irq_data)) {
9c6079aa 180 if (desc->depth == 1 && desc->istate & IRQS_PENDING)
d209a699
TG
181 return -EBUSY;
182 continue;
183 }
184 /*
185 * Check the non wakeup interrupts whether they need
186 * to be masked before finally going into suspend
187 * state. That's for hardware which has no wakeup
188 * source configuration facility. The chip
189 * implementation indicates that with
190 * IRQCHIP_MASK_ON_SUSPEND.
191 */
192 if (desc->istate & IRQS_SUSPENDED &&
193 irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND)
194 mask_irq(desc);
195 }
0a0c5168
RW
196
197 return 0;
198}
This page took 0.491393 seconds and 5 git commands to generate.