| .. | .. |
|---|
| 45 | 45 | } |
|---|
| 46 | 46 | |
|---|
| 47 | 47 | /* Tasklet to handle resend: */ |
|---|
| 48 | | -static DECLARE_TASKLET(resend_tasklet, resend_irqs, 0); |
|---|
| 48 | +static DECLARE_TASKLET_OLD(resend_tasklet, resend_irqs); |
|---|
| 49 | 49 | |
|---|
| 50 | +static int irq_sw_resend(struct irq_desc *desc) |
|---|
| 51 | +{ |
|---|
| 52 | + unsigned int irq = irq_desc_get_irq(desc); |
|---|
| 53 | + |
|---|
| 54 | + /* |
|---|
| 55 | + * Validate whether this interrupt can be safely injected from |
|---|
| 56 | + * non interrupt context |
|---|
| 57 | + */ |
|---|
| 58 | + if (handle_enforce_irqctx(&desc->irq_data)) |
|---|
| 59 | + return -EINVAL; |
|---|
| 60 | + |
|---|
| 61 | + /* |
|---|
| 62 | + * If the interrupt is running in the thread context of the parent |
|---|
| 63 | + * irq we need to be careful, because we cannot trigger it |
|---|
| 64 | + * directly. |
|---|
| 65 | + */ |
|---|
| 66 | + if (irq_settings_is_nested_thread(desc)) { |
|---|
| 67 | + /* |
|---|
| 68 | + * If the parent_irq is valid, we retrigger the parent, |
|---|
| 69 | + * otherwise we do nothing. |
|---|
| 70 | + */ |
|---|
| 71 | + if (!desc->parent_irq) |
|---|
| 72 | + return -EINVAL; |
|---|
| 73 | + irq = desc->parent_irq; |
|---|
| 74 | + } |
|---|
| 75 | + |
|---|
| 76 | + /* Set it pending and activate the softirq: */ |
|---|
| 77 | + set_bit(irq, irqs_resend); |
|---|
| 78 | + tasklet_schedule(&resend_tasklet); |
|---|
| 79 | + return 0; |
|---|
| 80 | +} |
|---|
| 81 | + |
|---|
| 82 | +#else |
|---|
| 83 | +static int irq_sw_resend(struct irq_desc *desc) |
|---|
| 84 | +{ |
|---|
| 85 | + return -EINVAL; |
|---|
| 86 | +} |
|---|
| 50 | 87 | #endif |
|---|
| 88 | + |
|---|
| 89 | +static int try_retrigger(struct irq_desc *desc) |
|---|
| 90 | +{ |
|---|
| 91 | + if (desc->irq_data.chip->irq_retrigger) |
|---|
| 92 | + return desc->irq_data.chip->irq_retrigger(&desc->irq_data); |
|---|
| 93 | + |
|---|
| 94 | +#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
|---|
| 95 | + return irq_chip_retrigger_hierarchy(&desc->irq_data); |
|---|
| 96 | +#else |
|---|
| 97 | + return 0; |
|---|
| 98 | +#endif |
|---|
| 99 | +} |
|---|
| 51 | 100 | |
|---|
| 52 | 101 | /* |
|---|
| 53 | 102 | * IRQ resend |
|---|
| 54 | 103 | * |
|---|
| 55 | 104 | * Is called with interrupts disabled and desc->lock held. |
|---|
| 56 | 105 | */ |
|---|
| 57 | | -void check_irq_resend(struct irq_desc *desc) |
|---|
| 106 | +int check_irq_resend(struct irq_desc *desc, bool inject) |
|---|
| 58 | 107 | { |
|---|
| 108 | + int err = 0; |
|---|
| 109 | + |
|---|
| 59 | 110 | /* |
|---|
| 60 | | - * We do not resend level type interrupts. Level type |
|---|
| 61 | | - * interrupts are resent by hardware when they are still |
|---|
| 62 | | - * active. Clear the pending bit so suspend/resume does not |
|---|
| 63 | | - * get confused. |
|---|
| 111 | + * We do not resend level type interrupts. Level type interrupts |
|---|
| 112 | + * are resent by hardware when they are still active. Clear the |
|---|
| 113 | + * pending bit so suspend/resume does not get confused. |
|---|
| 64 | 114 | */ |
|---|
| 65 | 115 | if (irq_settings_is_level(desc)) { |
|---|
| 66 | 116 | desc->istate &= ~IRQS_PENDING; |
|---|
| 67 | | - return; |
|---|
| 117 | + return -EINVAL; |
|---|
| 68 | 118 | } |
|---|
| 119 | + |
|---|
| 69 | 120 | if (desc->istate & IRQS_REPLAY) |
|---|
| 70 | | - return; |
|---|
| 71 | | - if (desc->istate & IRQS_PENDING) { |
|---|
| 72 | | - desc->istate &= ~IRQS_PENDING; |
|---|
| 121 | + return -EBUSY; |
|---|
| 122 | + |
|---|
| 123 | + if (!(desc->istate & IRQS_PENDING) && !inject) |
|---|
| 124 | + return 0; |
|---|
| 125 | + |
|---|
| 126 | + desc->istate &= ~IRQS_PENDING; |
|---|
| 127 | + |
|---|
| 128 | + if (!try_retrigger(desc)) |
|---|
| 129 | + err = irq_sw_resend(desc); |
|---|
| 130 | + |
|---|
| 131 | + /* If the retrigger was successfull, mark it with the REPLAY bit */ |
|---|
| 132 | + if (!err) |
|---|
| 73 | 133 | desc->istate |= IRQS_REPLAY; |
|---|
| 74 | | - |
|---|
| 75 | | - if (!desc->irq_data.chip->irq_retrigger || |
|---|
| 76 | | - !desc->irq_data.chip->irq_retrigger(&desc->irq_data)) { |
|---|
| 77 | | -#ifdef CONFIG_HARDIRQS_SW_RESEND |
|---|
| 78 | | - unsigned int irq = irq_desc_get_irq(desc); |
|---|
| 79 | | - |
|---|
| 80 | | - /* |
|---|
| 81 | | - * If the interrupt is running in the thread |
|---|
| 82 | | - * context of the parent irq we need to be |
|---|
| 83 | | - * careful, because we cannot trigger it |
|---|
| 84 | | - * directly. |
|---|
| 85 | | - */ |
|---|
| 86 | | - if (irq_settings_is_nested_thread(desc)) { |
|---|
| 87 | | - /* |
|---|
| 88 | | - * If the parent_irq is valid, we |
|---|
| 89 | | - * retrigger the parent, otherwise we |
|---|
| 90 | | - * do nothing. |
|---|
| 91 | | - */ |
|---|
| 92 | | - if (!desc->parent_irq) |
|---|
| 93 | | - return; |
|---|
| 94 | | - irq = desc->parent_irq; |
|---|
| 95 | | - } |
|---|
| 96 | | - /* Set it pending and activate the softirq: */ |
|---|
| 97 | | - set_bit(irq, irqs_resend); |
|---|
| 98 | | - tasklet_schedule(&resend_tasklet); |
|---|
| 99 | | -#endif |
|---|
| 100 | | - } |
|---|
| 101 | | - } |
|---|
| 134 | + return err; |
|---|
| 102 | 135 | } |
|---|
| 136 | + |
|---|
| 137 | +#ifdef CONFIG_GENERIC_IRQ_INJECTION |
|---|
| 138 | +/** |
|---|
| 139 | + * irq_inject_interrupt - Inject an interrupt for testing/error injection |
|---|
| 140 | + * @irq: The interrupt number |
|---|
| 141 | + * |
|---|
| 142 | + * This function must only be used for debug and testing purposes! |
|---|
| 143 | + * |
|---|
| 144 | + * Especially on x86 this can cause a premature completion of an interrupt |
|---|
| 145 | + * affinity change causing the interrupt line to become stale. Very |
|---|
| 146 | + * unlikely, but possible. |
|---|
| 147 | + * |
|---|
| 148 | + * The injection can fail for various reasons: |
|---|
| 149 | + * - Interrupt is not activated |
|---|
| 150 | + * - Interrupt is NMI type or currently replaying |
|---|
| 151 | + * - Interrupt is level type |
|---|
| 152 | + * - Interrupt does not support hardware retrigger and software resend is |
|---|
| 153 | + * either not enabled or not possible for the interrupt. |
|---|
| 154 | + */ |
|---|
| 155 | +int irq_inject_interrupt(unsigned int irq) |
|---|
| 156 | +{ |
|---|
| 157 | + struct irq_desc *desc; |
|---|
| 158 | + unsigned long flags; |
|---|
| 159 | + int err; |
|---|
| 160 | + |
|---|
| 161 | + /* Try the state injection hardware interface first */ |
|---|
| 162 | + if (!irq_set_irqchip_state(irq, IRQCHIP_STATE_PENDING, true)) |
|---|
| 163 | + return 0; |
|---|
| 164 | + |
|---|
| 165 | + /* That failed, try via the resend mechanism */ |
|---|
| 166 | + desc = irq_get_desc_buslock(irq, &flags, 0); |
|---|
| 167 | + if (!desc) |
|---|
| 168 | + return -EINVAL; |
|---|
| 169 | + |
|---|
| 170 | + /* |
|---|
| 171 | + * Only try to inject when the interrupt is: |
|---|
| 172 | + * - not NMI type |
|---|
| 173 | + * - activated |
|---|
| 174 | + */ |
|---|
| 175 | + if ((desc->istate & IRQS_NMI) || !irqd_is_activated(&desc->irq_data)) |
|---|
| 176 | + err = -EINVAL; |
|---|
| 177 | + else |
|---|
| 178 | + err = check_irq_resend(desc, true); |
|---|
| 179 | + |
|---|
| 180 | + irq_put_desc_busunlock(desc, flags); |
|---|
| 181 | + return err; |
|---|
| 182 | +} |
|---|
| 183 | +EXPORT_SYMBOL_GPL(irq_inject_interrupt); |
|---|
| 184 | +#endif |
|---|