Skip to content

Commit 828f560

Browse files
author
Marc Zyngier
committed
Merge branch irq/stm32-exti-updates into irq/irqchip-next
* irq/stm32-exti-updates: : . : stm32-exti updates courtesy of Antonio Borneo: : : "This series address some code fix for irq-stm32-exti driver and : simplifies the table that remaps the interrupts from exti to gic." : : Also comes with an additional change to irq_chip_request_resources_parent(), : making it possible to omit the callback in hierarchies. : . irqchip/stm32-exti: Simplify irq description table irqchip/stm32-exti: Read event trigger type from event_trg register irqchip/stm32-exti: Tag emr register as undefined for stm32mp15 irqchip/stm32-exti: Prevent illegal read due to unbounded DT value irqchip/stm32-exti: Fix irq_mask/irq_unmask for direct events irqchip/stm32-exti: Fix irq_set_affinity return value genirq: Don't return error on missing optional irq_request_resources() Signed-off-by: Marc Zyngier <maz@kernel.org>
2 parents ee4aae5 + c297493 commit 828f560

File tree

2 files changed

+126
-127
lines changed

2 files changed

+126
-127
lines changed

drivers/irqchip/irq-stm32-exti.c

Lines changed: 124 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,15 @@ struct stm32_exti_bank {
3434
u32 swier_ofst;
3535
u32 rpr_ofst;
3636
u32 fpr_ofst;
37+
u32 trg_ofst;
3738
};
3839

3940
#define UNDEF_REG ~0
4041

41-
struct stm32_desc_irq {
42-
u32 exti;
43-
u32 irq_parent;
44-
struct irq_chip *chip;
45-
};
46-
4742
struct stm32_exti_drv_data {
4843
const struct stm32_exti_bank **exti_banks;
49-
const struct stm32_desc_irq *desc_irqs;
44+
const u8 *desc_irqs;
5045
u32 bank_nr;
51-
u32 irq_nr;
5246
};
5347

5448
struct stm32_exti_chip_data {
@@ -78,6 +72,7 @@ static const struct stm32_exti_bank stm32f4xx_exti_b1 = {
7872
.swier_ofst = 0x10,
7973
.rpr_ofst = 0x14,
8074
.fpr_ofst = UNDEF_REG,
75+
.trg_ofst = UNDEF_REG,
8176
};
8277

8378
static const struct stm32_exti_bank *stm32f4xx_exti_banks[] = {
@@ -97,6 +92,7 @@ static const struct stm32_exti_bank stm32h7xx_exti_b1 = {
9792
.swier_ofst = 0x08,
9893
.rpr_ofst = 0x88,
9994
.fpr_ofst = UNDEF_REG,
95+
.trg_ofst = UNDEF_REG,
10096
};
10197

10298
static const struct stm32_exti_bank stm32h7xx_exti_b2 = {
@@ -107,6 +103,7 @@ static const struct stm32_exti_bank stm32h7xx_exti_b2 = {
107103
.swier_ofst = 0x28,
108104
.rpr_ofst = 0x98,
109105
.fpr_ofst = UNDEF_REG,
106+
.trg_ofst = UNDEF_REG,
110107
};
111108

112109
static const struct stm32_exti_bank stm32h7xx_exti_b3 = {
@@ -117,6 +114,7 @@ static const struct stm32_exti_bank stm32h7xx_exti_b3 = {
117114
.swier_ofst = 0x48,
118115
.rpr_ofst = 0xA8,
119116
.fpr_ofst = UNDEF_REG,
117+
.trg_ofst = UNDEF_REG,
120118
};
121119

122120
static const struct stm32_exti_bank *stm32h7xx_exti_banks[] = {
@@ -132,32 +130,35 @@ static const struct stm32_exti_drv_data stm32h7xx_drv_data = {
132130

133131
static const struct stm32_exti_bank stm32mp1_exti_b1 = {
134132
.imr_ofst = 0x80,
135-
.emr_ofst = 0x84,
133+
.emr_ofst = UNDEF_REG,
136134
.rtsr_ofst = 0x00,
137135
.ftsr_ofst = 0x04,
138136
.swier_ofst = 0x08,
139137
.rpr_ofst = 0x0C,
140138
.fpr_ofst = 0x10,
139+
.trg_ofst = 0x3EC,
141140
};
142141

143142
static const struct stm32_exti_bank stm32mp1_exti_b2 = {
144143
.imr_ofst = 0x90,
145-
.emr_ofst = 0x94,
144+
.emr_ofst = UNDEF_REG,
146145
.rtsr_ofst = 0x20,
147146
.ftsr_ofst = 0x24,
148147
.swier_ofst = 0x28,
149148
.rpr_ofst = 0x2C,
150149
.fpr_ofst = 0x30,
150+
.trg_ofst = 0x3E8,
151151
};
152152

153153
static const struct stm32_exti_bank stm32mp1_exti_b3 = {
154154
.imr_ofst = 0xA0,
155-
.emr_ofst = 0xA4,
155+
.emr_ofst = UNDEF_REG,
156156
.rtsr_ofst = 0x40,
157157
.ftsr_ofst = 0x44,
158158
.swier_ofst = 0x48,
159159
.rpr_ofst = 0x4C,
160160
.fpr_ofst = 0x50,
161+
.trg_ofst = 0x3E4,
161162
};
162163

163164
static const struct stm32_exti_bank *stm32mp1_exti_banks[] = {
@@ -169,126 +170,114 @@ static const struct stm32_exti_bank *stm32mp1_exti_banks[] = {
169170
static struct irq_chip stm32_exti_h_chip;
170171
static struct irq_chip stm32_exti_h_chip_direct;
171172

172-
static const struct stm32_desc_irq stm32mp1_desc_irq[] = {
173-
{ .exti = 0, .irq_parent = 6, .chip = &stm32_exti_h_chip },
174-
{ .exti = 1, .irq_parent = 7, .chip = &stm32_exti_h_chip },
175-
{ .exti = 2, .irq_parent = 8, .chip = &stm32_exti_h_chip },
176-
{ .exti = 3, .irq_parent = 9, .chip = &stm32_exti_h_chip },
177-
{ .exti = 4, .irq_parent = 10, .chip = &stm32_exti_h_chip },
178-
{ .exti = 5, .irq_parent = 23, .chip = &stm32_exti_h_chip },
179-
{ .exti = 6, .irq_parent = 64, .chip = &stm32_exti_h_chip },
180-
{ .exti = 7, .irq_parent = 65, .chip = &stm32_exti_h_chip },
181-
{ .exti = 8, .irq_parent = 66, .chip = &stm32_exti_h_chip },
182-
{ .exti = 9, .irq_parent = 67, .chip = &stm32_exti_h_chip },
183-
{ .exti = 10, .irq_parent = 40, .chip = &stm32_exti_h_chip },
184-
{ .exti = 11, .irq_parent = 42, .chip = &stm32_exti_h_chip },
185-
{ .exti = 12, .irq_parent = 76, .chip = &stm32_exti_h_chip },
186-
{ .exti = 13, .irq_parent = 77, .chip = &stm32_exti_h_chip },
187-
{ .exti = 14, .irq_parent = 121, .chip = &stm32_exti_h_chip },
188-
{ .exti = 15, .irq_parent = 127, .chip = &stm32_exti_h_chip },
189-
{ .exti = 16, .irq_parent = 1, .chip = &stm32_exti_h_chip },
190-
{ .exti = 19, .irq_parent = 3, .chip = &stm32_exti_h_chip_direct },
191-
{ .exti = 21, .irq_parent = 31, .chip = &stm32_exti_h_chip_direct },
192-
{ .exti = 22, .irq_parent = 33, .chip = &stm32_exti_h_chip_direct },
193-
{ .exti = 23, .irq_parent = 72, .chip = &stm32_exti_h_chip_direct },
194-
{ .exti = 24, .irq_parent = 95, .chip = &stm32_exti_h_chip_direct },
195-
{ .exti = 25, .irq_parent = 107, .chip = &stm32_exti_h_chip_direct },
196-
{ .exti = 26, .irq_parent = 37, .chip = &stm32_exti_h_chip_direct },
197-
{ .exti = 27, .irq_parent = 38, .chip = &stm32_exti_h_chip_direct },
198-
{ .exti = 28, .irq_parent = 39, .chip = &stm32_exti_h_chip_direct },
199-
{ .exti = 29, .irq_parent = 71, .chip = &stm32_exti_h_chip_direct },
200-
{ .exti = 30, .irq_parent = 52, .chip = &stm32_exti_h_chip_direct },
201-
{ .exti = 31, .irq_parent = 53, .chip = &stm32_exti_h_chip_direct },
202-
{ .exti = 32, .irq_parent = 82, .chip = &stm32_exti_h_chip_direct },
203-
{ .exti = 33, .irq_parent = 83, .chip = &stm32_exti_h_chip_direct },
204-
{ .exti = 47, .irq_parent = 93, .chip = &stm32_exti_h_chip_direct },
205-
{ .exti = 48, .irq_parent = 138, .chip = &stm32_exti_h_chip_direct },
206-
{ .exti = 50, .irq_parent = 139, .chip = &stm32_exti_h_chip_direct },
207-
{ .exti = 52, .irq_parent = 140, .chip = &stm32_exti_h_chip_direct },
208-
{ .exti = 53, .irq_parent = 141, .chip = &stm32_exti_h_chip_direct },
209-
{ .exti = 54, .irq_parent = 135, .chip = &stm32_exti_h_chip_direct },
210-
{ .exti = 61, .irq_parent = 100, .chip = &stm32_exti_h_chip_direct },
211-
{ .exti = 65, .irq_parent = 144, .chip = &stm32_exti_h_chip },
212-
{ .exti = 68, .irq_parent = 143, .chip = &stm32_exti_h_chip },
213-
{ .exti = 70, .irq_parent = 62, .chip = &stm32_exti_h_chip_direct },
214-
{ .exti = 73, .irq_parent = 129, .chip = &stm32_exti_h_chip },
173+
#define EXTI_INVALID_IRQ U8_MAX
174+
#define STM32MP1_DESC_IRQ_SIZE (ARRAY_SIZE(stm32mp1_exti_banks) * IRQS_PER_BANK)
175+
176+
static const u8 stm32mp1_desc_irq[] = {
177+
/* default value */
178+
[0 ... (STM32MP1_DESC_IRQ_SIZE - 1)] = EXTI_INVALID_IRQ,
179+
180+
[0] = 6,
181+
[1] = 7,
182+
[2] = 8,
183+
[3] = 9,
184+
[4] = 10,
185+
[5] = 23,
186+
[6] = 64,
187+
[7] = 65,
188+
[8] = 66,
189+
[9] = 67,
190+
[10] = 40,
191+
[11] = 42,
192+
[12] = 76,
193+
[13] = 77,
194+
[14] = 121,
195+
[15] = 127,
196+
[16] = 1,
197+
[19] = 3,
198+
[21] = 31,
199+
[22] = 33,
200+
[23] = 72,
201+
[24] = 95,
202+
[25] = 107,
203+
[26] = 37,
204+
[27] = 38,
205+
[28] = 39,
206+
[29] = 71,
207+
[30] = 52,
208+
[31] = 53,
209+
[32] = 82,
210+
[33] = 83,
211+
[47] = 93,
212+
[48] = 138,
213+
[50] = 139,
214+
[52] = 140,
215+
[53] = 141,
216+
[54] = 135,
217+
[61] = 100,
218+
[65] = 144,
219+
[68] = 143,
220+
[70] = 62,
221+
[73] = 129,
215222
};
216223

217-
static const struct stm32_desc_irq stm32mp13_desc_irq[] = {
218-
{ .exti = 0, .irq_parent = 6, .chip = &stm32_exti_h_chip },
219-
{ .exti = 1, .irq_parent = 7, .chip = &stm32_exti_h_chip },
220-
{ .exti = 2, .irq_parent = 8, .chip = &stm32_exti_h_chip },
221-
{ .exti = 3, .irq_parent = 9, .chip = &stm32_exti_h_chip },
222-
{ .exti = 4, .irq_parent = 10, .chip = &stm32_exti_h_chip },
223-
{ .exti = 5, .irq_parent = 24, .chip = &stm32_exti_h_chip },
224-
{ .exti = 6, .irq_parent = 65, .chip = &stm32_exti_h_chip },
225-
{ .exti = 7, .irq_parent = 66, .chip = &stm32_exti_h_chip },
226-
{ .exti = 8, .irq_parent = 67, .chip = &stm32_exti_h_chip },
227-
{ .exti = 9, .irq_parent = 68, .chip = &stm32_exti_h_chip },
228-
{ .exti = 10, .irq_parent = 41, .chip = &stm32_exti_h_chip },
229-
{ .exti = 11, .irq_parent = 43, .chip = &stm32_exti_h_chip },
230-
{ .exti = 12, .irq_parent = 77, .chip = &stm32_exti_h_chip },
231-
{ .exti = 13, .irq_parent = 78, .chip = &stm32_exti_h_chip },
232-
{ .exti = 14, .irq_parent = 106, .chip = &stm32_exti_h_chip },
233-
{ .exti = 15, .irq_parent = 109, .chip = &stm32_exti_h_chip },
234-
{ .exti = 16, .irq_parent = 1, .chip = &stm32_exti_h_chip },
235-
{ .exti = 19, .irq_parent = 3, .chip = &stm32_exti_h_chip_direct },
236-
{ .exti = 21, .irq_parent = 32, .chip = &stm32_exti_h_chip_direct },
237-
{ .exti = 22, .irq_parent = 34, .chip = &stm32_exti_h_chip_direct },
238-
{ .exti = 23, .irq_parent = 73, .chip = &stm32_exti_h_chip_direct },
239-
{ .exti = 24, .irq_parent = 93, .chip = &stm32_exti_h_chip_direct },
240-
{ .exti = 25, .irq_parent = 114, .chip = &stm32_exti_h_chip_direct },
241-
{ .exti = 26, .irq_parent = 38, .chip = &stm32_exti_h_chip_direct },
242-
{ .exti = 27, .irq_parent = 39, .chip = &stm32_exti_h_chip_direct },
243-
{ .exti = 28, .irq_parent = 40, .chip = &stm32_exti_h_chip_direct },
244-
{ .exti = 29, .irq_parent = 72, .chip = &stm32_exti_h_chip_direct },
245-
{ .exti = 30, .irq_parent = 53, .chip = &stm32_exti_h_chip_direct },
246-
{ .exti = 31, .irq_parent = 54, .chip = &stm32_exti_h_chip_direct },
247-
{ .exti = 32, .irq_parent = 83, .chip = &stm32_exti_h_chip_direct },
248-
{ .exti = 33, .irq_parent = 84, .chip = &stm32_exti_h_chip_direct },
249-
{ .exti = 44, .irq_parent = 96, .chip = &stm32_exti_h_chip_direct },
250-
{ .exti = 47, .irq_parent = 92, .chip = &stm32_exti_h_chip_direct },
251-
{ .exti = 48, .irq_parent = 116, .chip = &stm32_exti_h_chip_direct },
252-
{ .exti = 50, .irq_parent = 117, .chip = &stm32_exti_h_chip_direct },
253-
{ .exti = 52, .irq_parent = 118, .chip = &stm32_exti_h_chip_direct },
254-
{ .exti = 53, .irq_parent = 119, .chip = &stm32_exti_h_chip_direct },
255-
{ .exti = 68, .irq_parent = 63, .chip = &stm32_exti_h_chip_direct },
256-
{ .exti = 70, .irq_parent = 98, .chip = &stm32_exti_h_chip_direct },
224+
static const u8 stm32mp13_desc_irq[] = {
225+
/* default value */
226+
[0 ... (STM32MP1_DESC_IRQ_SIZE - 1)] = EXTI_INVALID_IRQ,
227+
228+
[0] = 6,
229+
[1] = 7,
230+
[2] = 8,
231+
[3] = 9,
232+
[4] = 10,
233+
[5] = 24,
234+
[6] = 65,
235+
[7] = 66,
236+
[8] = 67,
237+
[9] = 68,
238+
[10] = 41,
239+
[11] = 43,
240+
[12] = 77,
241+
[13] = 78,
242+
[14] = 106,
243+
[15] = 109,
244+
[16] = 1,
245+
[19] = 3,
246+
[21] = 32,
247+
[22] = 34,
248+
[23] = 73,
249+
[24] = 93,
250+
[25] = 114,
251+
[26] = 38,
252+
[27] = 39,
253+
[28] = 40,
254+
[29] = 72,
255+
[30] = 53,
256+
[31] = 54,
257+
[32] = 83,
258+
[33] = 84,
259+
[44] = 96,
260+
[47] = 92,
261+
[48] = 116,
262+
[50] = 117,
263+
[52] = 118,
264+
[53] = 119,
265+
[68] = 63,
266+
[70] = 98,
257267
};
258268

259269
static const struct stm32_exti_drv_data stm32mp1_drv_data = {
260270
.exti_banks = stm32mp1_exti_banks,
261271
.bank_nr = ARRAY_SIZE(stm32mp1_exti_banks),
262272
.desc_irqs = stm32mp1_desc_irq,
263-
.irq_nr = ARRAY_SIZE(stm32mp1_desc_irq),
264273
};
265274

266275
static const struct stm32_exti_drv_data stm32mp13_drv_data = {
267276
.exti_banks = stm32mp1_exti_banks,
268277
.bank_nr = ARRAY_SIZE(stm32mp1_exti_banks),
269278
.desc_irqs = stm32mp13_desc_irq,
270-
.irq_nr = ARRAY_SIZE(stm32mp13_desc_irq),
271279
};
272280

273-
static const struct
274-
stm32_desc_irq *stm32_exti_get_desc(const struct stm32_exti_drv_data *drv_data,
275-
irq_hw_number_t hwirq)
276-
{
277-
const struct stm32_desc_irq *desc = NULL;
278-
int i;
279-
280-
if (!drv_data->desc_irqs)
281-
return NULL;
282-
283-
for (i = 0; i < drv_data->irq_nr; i++) {
284-
desc = &drv_data->desc_irqs[i];
285-
if (desc->exti == hwirq)
286-
break;
287-
}
288-
289-
return desc;
290-
}
291-
292281
static unsigned long stm32_exti_pending(struct irq_chip_generic *gc)
293282
{
294283
struct stm32_exti_chip_data *chip_data = gc->private;
@@ -614,7 +603,7 @@ static int stm32_exti_h_set_affinity(struct irq_data *d,
614603
if (d->parent_data->chip)
615604
return irq_chip_set_affinity_parent(d, dest, force);
616605

617-
return -EINVAL;
606+
return IRQ_SET_MASK_OK_DONE;
618607
}
619608

620609
static int __maybe_unused stm32_exti_h_suspend(void)
@@ -691,8 +680,8 @@ static struct irq_chip stm32_exti_h_chip_direct = {
691680
.name = "stm32-exti-h-direct",
692681
.irq_eoi = irq_chip_eoi_parent,
693682
.irq_ack = irq_chip_ack_parent,
694-
.irq_mask = irq_chip_mask_parent,
695-
.irq_unmask = irq_chip_unmask_parent,
683+
.irq_mask = stm32_exti_h_mask,
684+
.irq_unmask = stm32_exti_h_unmask,
696685
.irq_retrigger = irq_chip_retrigger_hierarchy,
697686
.irq_set_type = irq_chip_set_type_parent,
698687
.irq_set_wake = stm32_exti_h_set_wake,
@@ -706,28 +695,36 @@ static int stm32_exti_h_domain_alloc(struct irq_domain *dm,
706695
{
707696
struct stm32_exti_host_data *host_data = dm->host_data;
708697
struct stm32_exti_chip_data *chip_data;
709-
const struct stm32_desc_irq *desc;
698+
u8 desc_irq;
710699
struct irq_fwspec *fwspec = data;
711700
struct irq_fwspec p_fwspec;
712701
irq_hw_number_t hwirq;
713702
int bank;
703+
u32 event_trg;
704+
struct irq_chip *chip;
714705

715706
hwirq = fwspec->param[0];
707+
if (hwirq >= host_data->drv_data->bank_nr * IRQS_PER_BANK)
708+
return -EINVAL;
709+
716710
bank = hwirq / IRQS_PER_BANK;
717711
chip_data = &host_data->chips_data[bank];
718712

713+
event_trg = readl_relaxed(host_data->base + chip_data->reg_bank->trg_ofst);
714+
chip = (event_trg & BIT(hwirq % IRQS_PER_BANK)) ?
715+
&stm32_exti_h_chip : &stm32_exti_h_chip_direct;
716+
717+
irq_domain_set_hwirq_and_chip(dm, virq, hwirq, chip, chip_data);
719718

720-
desc = stm32_exti_get_desc(host_data->drv_data, hwirq);
721-
if (!desc)
719+
if (!host_data->drv_data || !host_data->drv_data->desc_irqs)
722720
return -EINVAL;
723721

724-
irq_domain_set_hwirq_and_chip(dm, virq, hwirq, desc->chip,
725-
chip_data);
726-
if (desc->irq_parent) {
722+
desc_irq = host_data->drv_data->desc_irqs[hwirq];
723+
if (desc_irq != EXTI_INVALID_IRQ) {
727724
p_fwspec.fwnode = dm->parent->fwnode;
728725
p_fwspec.param_count = 3;
729726
p_fwspec.param[0] = GIC_SPI;
730-
p_fwspec.param[1] = desc->irq_parent;
727+
p_fwspec.param[1] = desc_irq;
731728
p_fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
732729

733730
return irq_domain_alloc_irqs_parent(dm, virq, 1, &p_fwspec);
@@ -792,7 +789,8 @@ stm32_exti_chip_data *stm32_exti_chip_init(struct stm32_exti_host_data *h_data,
792789
* clear registers to avoid residue
793790
*/
794791
writel_relaxed(0, base + stm32_bank->imr_ofst);
795-
writel_relaxed(0, base + stm32_bank->emr_ofst);
792+
if (stm32_bank->emr_ofst != UNDEF_REG)
793+
writel_relaxed(0, base + stm32_bank->emr_ofst);
796794

797795
pr_info("%pOF: bank%d\n", node, bank_idx);
798796

kernel/irq/chip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,8 @@ int irq_chip_request_resources_parent(struct irq_data *data)
15161516
if (data->chip->irq_request_resources)
15171517
return data->chip->irq_request_resources(data);
15181518

1519-
return -ENOSYS;
1519+
/* no error on missing optional irq_chip::irq_request_resources */
1520+
return 0;
15201521
}
15211522
EXPORT_SYMBOL_GPL(irq_chip_request_resources_parent);
15221523

0 commit comments

Comments
 (0)