GNU Linux-libre 4.9.309-gnu1
[releases.git] / kernel / irq / migration.c
1
2 #include <linux/irq.h>
3 #include <linux/interrupt.h>
4
5 #include "internals.h"
6
7 void irq_move_masked_irq(struct irq_data *idata)
8 {
9         struct irq_desc *desc = irq_data_to_desc(idata);
10         struct irq_data *data = &desc->irq_data;
11         struct irq_chip *chip = data->chip;
12
13         if (likely(!irqd_is_setaffinity_pending(data)))
14                 return;
15
16         irqd_clr_move_pending(data);
17
18         /*
19          * Paranoia: cpu-local interrupts shouldn't be calling in here anyway.
20          */
21         if (irqd_is_per_cpu(data)) {
22                 WARN_ON(1);
23                 return;
24         }
25
26         if (unlikely(cpumask_empty(desc->pending_mask)))
27                 return;
28
29         if (!chip->irq_set_affinity)
30                 return;
31
32         assert_raw_spin_locked(&desc->lock);
33
34         /*
35          * If there was a valid mask to work with, please
36          * do the disable, re-program, enable sequence.
37          * This is *not* particularly important for level triggered
38          * but in a edge trigger case, we might be setting rte
39          * when an active trigger is coming in. This could
40          * cause some ioapics to mal-function.
41          * Being paranoid i guess!
42          *
43          * For correct operation this depends on the caller
44          * masking the irqs.
45          */
46         if (cpumask_any_and(desc->pending_mask, cpu_online_mask) < nr_cpu_ids) {
47                 int ret;
48
49                 ret = irq_do_set_affinity(data, desc->pending_mask, false);
50                 /*
51                  * If the there is a cleanup pending in the underlying
52                  * vector management, reschedule the move for the next
53                  * interrupt. Leave desc->pending_mask intact.
54                  */
55                 if (ret == -EBUSY) {
56                         irqd_set_move_pending(data);
57                         return;
58                 }
59         }
60         cpumask_clear(desc->pending_mask);
61 }
62
63 void irq_move_irq(struct irq_data *idata)
64 {
65         bool masked;
66
67         /*
68          * Get top level irq_data when CONFIG_IRQ_DOMAIN_HIERARCHY is enabled,
69          * and it should be optimized away when CONFIG_IRQ_DOMAIN_HIERARCHY is
70          * disabled. So we avoid an "#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY" here.
71          */
72         idata = irq_desc_get_irq_data(irq_data_to_desc(idata));
73
74         if (likely(!irqd_is_setaffinity_pending(idata)))
75                 return;
76
77         if (unlikely(irqd_irq_disabled(idata)))
78                 return;
79
80         /*
81          * Be careful vs. already masked interrupts. If this is a
82          * threaded interrupt with ONESHOT set, we can end up with an
83          * interrupt storm.
84          */
85         masked = irqd_irq_masked(idata);
86         if (!masked)
87                 idata->chip->irq_mask(idata);
88         irq_move_masked_irq(idata);
89         if (!masked)
90                 idata->chip->irq_unmask(idata);
91 }