Skip to content

Commit a7fc89f

Browse files
author
Linus Walleij
committed
gpio: thunderx: Switch to GPIOLIB_IRQCHIP
Use the new infrastructure for hierarchical irqchips in gpiolib. The major part of the rewrite was dues to the fact that the driver was passing around a per-irq pointer to struct thunderx_line * data container, and the central handlers will assume struct gpio_chip * to be passed to we need to use the hwirq as index to look up the struct thunderx_line * for each IRQ. The pushing and pop:ing of the irqdomain was confusing because I've never seen this before, but I tried to replicate it as best I could. I have no chance to test or debug this so I need help. Cc: David Daney <david.daney@cavium.com> Cc: Thierry Reding <treding@nvidia.com> Cc: Brian Masney <masneyb@onstation.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20190808123242.5359-4-linus.walleij@linaro.org
1 parent 821c76c commit a7fc89f

2 files changed

Lines changed: 57 additions & 107 deletions

File tree

‎drivers/gpio/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ config GPIO_THUNDERX
539539
tristate "Cavium ThunderX/OCTEON-TX GPIO"
540540
depends on ARCH_THUNDER || (64BIT && COMPILE_TEST)
541541
depends on PCI_MSI
542+
select GPIOLIB_IRQCHIP
542543
select IRQ_DOMAIN_HIERARCHY
543544
select IRQ_FASTEOI_HIERARCHY_HANDLERS
544545
help

‎drivers/gpio/gpio-thunderx.c‎

Lines changed: 56 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ struct thunderx_line {
5353
struct thunderx_gpio {
5454
struct gpio_chip chip;
5555
u8 __iomem *register_base;
56-
struct irq_domain *irqd;
5756
struct msix_entry *msix_entries; /* per line MSI-X */
5857
struct thunderx_line *line_entries; /* per line irq info */
5958
raw_spinlock_t lock;
@@ -283,54 +282,60 @@ static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
283282
}
284283
}
285284

286-
static void thunderx_gpio_irq_ack(struct irq_data *data)
285+
static void thunderx_gpio_irq_ack(struct irq_data *d)
287286
{
288-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
287+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
288+
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
289289

290290
writeq(GPIO_INTR_INTR,
291-
txline->txgpio->register_base + intr_reg(txline->line));
291+
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
292292
}
293293

294-
static void thunderx_gpio_irq_mask(struct irq_data *data)
294+
static void thunderx_gpio_irq_mask(struct irq_data *d)
295295
{
296-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
296+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
297+
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
297298

298299
writeq(GPIO_INTR_ENA_W1C,
299-
txline->txgpio->register_base + intr_reg(txline->line));
300+
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
300301
}
301302

302-
static void thunderx_gpio_irq_mask_ack(struct irq_data *data)
303+
static void thunderx_gpio_irq_mask_ack(struct irq_data *d)
303304
{
304-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
305+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
306+
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
305307

306308
writeq(GPIO_INTR_ENA_W1C | GPIO_INTR_INTR,
307-
txline->txgpio->register_base + intr_reg(txline->line));
309+
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
308310
}
309311

310-
static void thunderx_gpio_irq_unmask(struct irq_data *data)
312+
static void thunderx_gpio_irq_unmask(struct irq_data *d)
311313
{
312-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
314+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
315+
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
313316

314317
writeq(GPIO_INTR_ENA_W1S,
315-
txline->txgpio->register_base + intr_reg(txline->line));
318+
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
316319
}
317320

318-
static int thunderx_gpio_irq_set_type(struct irq_data *data,
321+
static int thunderx_gpio_irq_set_type(struct irq_data *d,
319322
unsigned int flow_type)
320323
{
321-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
322-
struct thunderx_gpio *txgpio = txline->txgpio;
324+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
325+
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
326+
struct thunderx_line *txline =
327+
&txgpio->line_entries[irqd_to_hwirq(d)];
323328
u64 bit_cfg;
324329

325-
irqd_set_trigger_type(data, flow_type);
330+
irqd_set_trigger_type(d, flow_type);
326331

327332
bit_cfg = txline->fil_bits | GPIO_BIT_CFG_INT_EN;
328333

329334
if (flow_type & IRQ_TYPE_EDGE_BOTH) {
330-
irq_set_handler_locked(data, handle_fasteoi_ack_irq);
335+
irq_set_handler_locked(d, handle_fasteoi_ack_irq);
331336
bit_cfg |= GPIO_BIT_CFG_INT_TYPE;
332337
} else {
333-
irq_set_handler_locked(data, handle_fasteoi_mask_irq);
338+
irq_set_handler_locked(d, handle_fasteoi_mask_irq);
334339
}
335340

336341
raw_spin_lock(&txgpio->lock);
@@ -359,33 +364,6 @@ static void thunderx_gpio_irq_disable(struct irq_data *data)
359364
irq_chip_disable_parent(data);
360365
}
361366

362-
static int thunderx_gpio_irq_request_resources(struct irq_data *data)
363-
{
364-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
365-
struct thunderx_gpio *txgpio = txline->txgpio;
366-
int r;
367-
368-
r = gpiochip_lock_as_irq(&txgpio->chip, txline->line);
369-
if (r)
370-
return r;
371-
372-
r = irq_chip_request_resources_parent(data);
373-
if (r)
374-
gpiochip_unlock_as_irq(&txgpio->chip, txline->line);
375-
376-
return r;
377-
}
378-
379-
static void thunderx_gpio_irq_release_resources(struct irq_data *data)
380-
{
381-
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
382-
struct thunderx_gpio *txgpio = txline->txgpio;
383-
384-
irq_chip_release_resources_parent(data);
385-
386-
gpiochip_unlock_as_irq(&txgpio->chip, txline->line);
387-
}
388-
389367
/*
390368
* Interrupts are chained from underlying MSI-X vectors. We have
391369
* these irq_chip functions to be able to handle level triggering
@@ -402,48 +380,22 @@ static struct irq_chip thunderx_gpio_irq_chip = {
402380
.irq_unmask = thunderx_gpio_irq_unmask,
403381
.irq_eoi = irq_chip_eoi_parent,
404382
.irq_set_affinity = irq_chip_set_affinity_parent,
405-
.irq_request_resources = thunderx_gpio_irq_request_resources,
406-
.irq_release_resources = thunderx_gpio_irq_release_resources,
407383
.irq_set_type = thunderx_gpio_irq_set_type,
408384

409385
.flags = IRQCHIP_SET_TYPE_MASKED
410386
};
411387

412-
static int thunderx_gpio_irq_translate(struct irq_domain *d,
413-
struct irq_fwspec *fwspec,
414-
irq_hw_number_t *hwirq,
415-
unsigned int *type)
388+
static int thunderx_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
389+
unsigned int child,
390+
unsigned int child_type,
391+
unsigned int *parent,
392+
unsigned int *parent_type)
416393
{
417-
struct thunderx_gpio *txgpio = d->host_data;
418-
419-
if (WARN_ON(fwspec->param_count < 2))
420-
return -EINVAL;
421-
if (fwspec->param[0] >= txgpio->chip.ngpio)
422-
return -EINVAL;
423-
*hwirq = fwspec->param[0];
424-
*type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
425-
return 0;
426-
}
427-
428-
static int thunderx_gpio_irq_alloc(struct irq_domain *d, unsigned int virq,
429-
unsigned int nr_irqs, void *arg)
430-
{
431-
struct thunderx_line *txline = arg;
394+
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
432395

433-
return irq_domain_set_hwirq_and_chip(d, virq, txline->line,
434-
&thunderx_gpio_irq_chip, txline);
435-
}
436-
437-
static const struct irq_domain_ops thunderx_gpio_irqd_ops = {
438-
.alloc = thunderx_gpio_irq_alloc,
439-
.translate = thunderx_gpio_irq_translate
440-
};
441-
442-
static int thunderx_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
443-
{
444-
struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
445-
446-
return irq_find_mapping(txgpio->irqd, offset);
396+
*parent = txgpio->base_msi + (2 * child);
397+
*parent_type = IRQ_TYPE_LEVEL_HIGH;
398+
return 0;
447399
}
448400

449401
static int thunderx_gpio_probe(struct pci_dev *pdev,
@@ -453,6 +405,7 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
453405
struct device *dev = &pdev->dev;
454406
struct thunderx_gpio *txgpio;
455407
struct gpio_chip *chip;
408+
struct gpio_irq_chip *girq;
456409
int ngpio, i;
457410
int err = 0;
458411

@@ -497,8 +450,8 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
497450
}
498451

499452
txgpio->msix_entries = devm_kcalloc(dev,
500-
ngpio, sizeof(struct msix_entry),
501-
GFP_KERNEL);
453+
ngpio, sizeof(struct msix_entry),
454+
GFP_KERNEL);
502455
if (!txgpio->msix_entries) {
503456
err = -ENOMEM;
504457
goto out;
@@ -539,27 +492,6 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
539492
if (err < 0)
540493
goto out;
541494

542-
/*
543-
* Push GPIO specific irqdomain on hierarchy created as a side
544-
* effect of the pci_enable_msix()
545-
*/
546-
txgpio->irqd = irq_domain_create_hierarchy(irq_get_irq_data(txgpio->msix_entries[0].vector)->domain,
547-
0, 0, of_node_to_fwnode(dev->of_node),
548-
&thunderx_gpio_irqd_ops, txgpio);
549-
if (!txgpio->irqd) {
550-
err = -ENOMEM;
551-
goto out;
552-
}
553-
554-
/* Push on irq_data and the domain for each line. */
555-
for (i = 0; i < ngpio; i++) {
556-
err = irq_domain_push_irq(txgpio->irqd,
557-
txgpio->msix_entries[i].vector,
558-
&txgpio->line_entries[i]);
559-
if (err < 0)
560-
dev_err(dev, "irq_domain_push_irq: %d\n", err);
561-
}
562-
563495
chip->label = KBUILD_MODNAME;
564496
chip->parent = dev;
565497
chip->owner = THIS_MODULE;
@@ -574,11 +506,28 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
574506
chip->set = thunderx_gpio_set;
575507
chip->set_multiple = thunderx_gpio_set_multiple;
576508
chip->set_config = thunderx_gpio_set_config;
577-
chip->to_irq = thunderx_gpio_to_irq;
509+
girq = &chip->irq;
510+
girq->chip = &thunderx_gpio_irq_chip;
511+
girq->fwnode = of_node_to_fwnode(dev->of_node);
512+
girq->parent_domain =
513+
irq_get_irq_data(txgpio->msix_entries[0].vector)->domain;
514+
girq->child_to_parent_hwirq = thunderx_gpio_child_to_parent_hwirq;
515+
girq->handler = handle_bad_irq;
516+
girq->default_type = IRQ_TYPE_NONE;
517+
578518
err = devm_gpiochip_add_data(dev, chip, txgpio);
579519
if (err)
580520
goto out;
581521

522+
/* Push on irq_data and the domain for each line. */
523+
for (i = 0; i < ngpio; i++) {
524+
err = irq_domain_push_irq(chip->irq.domain,
525+
txgpio->msix_entries[i].vector,
526+
chip);
527+
if (err < 0)
528+
dev_err(dev, "irq_domain_push_irq: %d\n", err);
529+
}
530+
582531
dev_info(dev, "ThunderX GPIO: %d lines with base %d.\n",
583532
ngpio, chip->base);
584533
return 0;
@@ -593,10 +542,10 @@ static void thunderx_gpio_remove(struct pci_dev *pdev)
593542
struct thunderx_gpio *txgpio = pci_get_drvdata(pdev);
594543

595544
for (i = 0; i < txgpio->chip.ngpio; i++)
596-
irq_domain_pop_irq(txgpio->irqd,
545+
irq_domain_pop_irq(txgpio->chip.irq.domain,
597546
txgpio->msix_entries[i].vector);
598547

599-
irq_domain_remove(txgpio->irqd);
548+
irq_domain_remove(txgpio->chip.irq.domain);
600549

601550
pci_set_drvdata(pdev, NULL);
602551
}

0 commit comments

Comments
 (0)