Skip to content

Commit a564ac3

Browse files
haokexinlinusw
authored andcommitted
Revert "gpio: thunderx: Switch to GPIOLIB_IRQCHIP"
This reverts commit a7fc89f because there are some bugs in this commit, and we don't have a simple way to fix these bugs. So revert this commit to make the thunderx gpio work on the stable kernel at least. We will switch to GPIOLIB_IRQCHIP for thunderx gpio by following patches. Fixes: a7fc89f ("gpio: thunderx: Switch to GPIOLIB_IRQCHIP") Signed-off-by: Kevin Hao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent b3a987b commit a564ac3

File tree

2 files changed

+107
-57
lines changed

2 files changed

+107
-57
lines changed

drivers/gpio/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ config GPIO_THUNDERX
573573
tristate "Cavium ThunderX/OCTEON-TX GPIO"
574574
depends on ARCH_THUNDER || (64BIT && COMPILE_TEST)
575575
depends on PCI_MSI
576-
select GPIOLIB_IRQCHIP
577576
select IRQ_DOMAIN_HIERARCHY
578577
select IRQ_FASTEOI_HIERARCHY_HANDLERS
579578
help

drivers/gpio/gpio-thunderx.c

Lines changed: 107 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct thunderx_line {
5353
struct thunderx_gpio {
5454
struct gpio_chip chip;
5555
u8 __iomem *register_base;
56+
struct irq_domain *irqd;
5657
struct msix_entry *msix_entries; /* per line MSI-X */
5758
struct thunderx_line *line_entries; /* per line irq info */
5859
raw_spinlock_t lock;
@@ -285,60 +286,54 @@ static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
285286
}
286287
}
287288

288-
static void thunderx_gpio_irq_ack(struct irq_data *d)
289+
static void thunderx_gpio_irq_ack(struct irq_data *data)
289290
{
290-
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
291-
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
291+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
292292

293293
writeq(GPIO_INTR_INTR,
294-
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
294+
txline->txgpio->register_base + intr_reg(txline->line));
295295
}
296296

297-
static void thunderx_gpio_irq_mask(struct irq_data *d)
297+
static void thunderx_gpio_irq_mask(struct irq_data *data)
298298
{
299-
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
300-
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
299+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
301300

302301
writeq(GPIO_INTR_ENA_W1C,
303-
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
302+
txline->txgpio->register_base + intr_reg(txline->line));
304303
}
305304

306-
static void thunderx_gpio_irq_mask_ack(struct irq_data *d)
305+
static void thunderx_gpio_irq_mask_ack(struct irq_data *data)
307306
{
308-
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
309-
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
307+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
310308

311309
writeq(GPIO_INTR_ENA_W1C | GPIO_INTR_INTR,
312-
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
310+
txline->txgpio->register_base + intr_reg(txline->line));
313311
}
314312

315-
static void thunderx_gpio_irq_unmask(struct irq_data *d)
313+
static void thunderx_gpio_irq_unmask(struct irq_data *data)
316314
{
317-
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
318-
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
315+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
319316

320317
writeq(GPIO_INTR_ENA_W1S,
321-
txgpio->register_base + intr_reg(irqd_to_hwirq(d)));
318+
txline->txgpio->register_base + intr_reg(txline->line));
322319
}
323320

324-
static int thunderx_gpio_irq_set_type(struct irq_data *d,
321+
static int thunderx_gpio_irq_set_type(struct irq_data *data,
325322
unsigned int flow_type)
326323
{
327-
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
328-
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
329-
struct thunderx_line *txline =
330-
&txgpio->line_entries[irqd_to_hwirq(d)];
324+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
325+
struct thunderx_gpio *txgpio = txline->txgpio;
331326
u64 bit_cfg;
332327

333-
irqd_set_trigger_type(d, flow_type);
328+
irqd_set_trigger_type(data, flow_type);
334329

335330
bit_cfg = txline->fil_bits | GPIO_BIT_CFG_INT_EN;
336331

337332
if (flow_type & IRQ_TYPE_EDGE_BOTH) {
338-
irq_set_handler_locked(d, handle_fasteoi_ack_irq);
333+
irq_set_handler_locked(data, handle_fasteoi_ack_irq);
339334
bit_cfg |= GPIO_BIT_CFG_INT_TYPE;
340335
} else {
341-
irq_set_handler_locked(d, handle_fasteoi_mask_irq);
336+
irq_set_handler_locked(data, handle_fasteoi_mask_irq);
342337
}
343338

344339
raw_spin_lock(&txgpio->lock);
@@ -367,6 +362,33 @@ static void thunderx_gpio_irq_disable(struct irq_data *data)
367362
irq_chip_disable_parent(data);
368363
}
369364

365+
static int thunderx_gpio_irq_request_resources(struct irq_data *data)
366+
{
367+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
368+
struct thunderx_gpio *txgpio = txline->txgpio;
369+
int r;
370+
371+
r = gpiochip_lock_as_irq(&txgpio->chip, txline->line);
372+
if (r)
373+
return r;
374+
375+
r = irq_chip_request_resources_parent(data);
376+
if (r)
377+
gpiochip_unlock_as_irq(&txgpio->chip, txline->line);
378+
379+
return r;
380+
}
381+
382+
static void thunderx_gpio_irq_release_resources(struct irq_data *data)
383+
{
384+
struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
385+
struct thunderx_gpio *txgpio = txline->txgpio;
386+
387+
irq_chip_release_resources_parent(data);
388+
389+
gpiochip_unlock_as_irq(&txgpio->chip, txline->line);
390+
}
391+
370392
/*
371393
* Interrupts are chained from underlying MSI-X vectors. We have
372394
* these irq_chip functions to be able to handle level triggering
@@ -383,32 +405,57 @@ static struct irq_chip thunderx_gpio_irq_chip = {
383405
.irq_unmask = thunderx_gpio_irq_unmask,
384406
.irq_eoi = irq_chip_eoi_parent,
385407
.irq_set_affinity = irq_chip_set_affinity_parent,
408+
.irq_request_resources = thunderx_gpio_irq_request_resources,
409+
.irq_release_resources = thunderx_gpio_irq_release_resources,
386410
.irq_set_type = thunderx_gpio_irq_set_type,
387411

388412
.flags = IRQCHIP_SET_TYPE_MASKED
389413
};
390414

391-
static int thunderx_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
392-
unsigned int child,
393-
unsigned int child_type,
394-
unsigned int *parent,
395-
unsigned int *parent_type)
415+
static int thunderx_gpio_irq_translate(struct irq_domain *d,
416+
struct irq_fwspec *fwspec,
417+
irq_hw_number_t *hwirq,
418+
unsigned int *type)
396419
{
397-
struct thunderx_gpio *txgpio = gpiochip_get_data(gc);
398-
399-
*parent = txgpio->base_msi + (2 * child);
400-
*parent_type = IRQ_TYPE_LEVEL_HIGH;
420+
struct thunderx_gpio *txgpio = d->host_data;
421+
422+
if (WARN_ON(fwspec->param_count < 2))
423+
return -EINVAL;
424+
if (fwspec->param[0] >= txgpio->chip.ngpio)
425+
return -EINVAL;
426+
*hwirq = fwspec->param[0];
427+
*type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
401428
return 0;
402429
}
403430

431+
static int thunderx_gpio_irq_alloc(struct irq_domain *d, unsigned int virq,
432+
unsigned int nr_irqs, void *arg)
433+
{
434+
struct thunderx_line *txline = arg;
435+
436+
return irq_domain_set_hwirq_and_chip(d, virq, txline->line,
437+
&thunderx_gpio_irq_chip, txline);
438+
}
439+
440+
static const struct irq_domain_ops thunderx_gpio_irqd_ops = {
441+
.alloc = thunderx_gpio_irq_alloc,
442+
.translate = thunderx_gpio_irq_translate
443+
};
444+
445+
static int thunderx_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
446+
{
447+
struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
448+
449+
return irq_find_mapping(txgpio->irqd, offset);
450+
}
451+
404452
static int thunderx_gpio_probe(struct pci_dev *pdev,
405453
const struct pci_device_id *id)
406454
{
407455
void __iomem * const *tbl;
408456
struct device *dev = &pdev->dev;
409457
struct thunderx_gpio *txgpio;
410458
struct gpio_chip *chip;
411-
struct gpio_irq_chip *girq;
412459
int ngpio, i;
413460
int err = 0;
414461

@@ -453,8 +500,8 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
453500
}
454501

455502
txgpio->msix_entries = devm_kcalloc(dev,
456-
ngpio, sizeof(struct msix_entry),
457-
GFP_KERNEL);
503+
ngpio, sizeof(struct msix_entry),
504+
GFP_KERNEL);
458505
if (!txgpio->msix_entries) {
459506
err = -ENOMEM;
460507
goto out;
@@ -495,6 +542,27 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
495542
if (err < 0)
496543
goto out;
497544

545+
/*
546+
* Push GPIO specific irqdomain on hierarchy created as a side
547+
* effect of the pci_enable_msix()
548+
*/
549+
txgpio->irqd = irq_domain_create_hierarchy(irq_get_irq_data(txgpio->msix_entries[0].vector)->domain,
550+
0, 0, of_node_to_fwnode(dev->of_node),
551+
&thunderx_gpio_irqd_ops, txgpio);
552+
if (!txgpio->irqd) {
553+
err = -ENOMEM;
554+
goto out;
555+
}
556+
557+
/* Push on irq_data and the domain for each line. */
558+
for (i = 0; i < ngpio; i++) {
559+
err = irq_domain_push_irq(txgpio->irqd,
560+
txgpio->msix_entries[i].vector,
561+
&txgpio->line_entries[i]);
562+
if (err < 0)
563+
dev_err(dev, "irq_domain_push_irq: %d\n", err);
564+
}
565+
498566
chip->label = KBUILD_MODNAME;
499567
chip->parent = dev;
500568
chip->owner = THIS_MODULE;
@@ -509,28 +577,11 @@ static int thunderx_gpio_probe(struct pci_dev *pdev,
509577
chip->set = thunderx_gpio_set;
510578
chip->set_multiple = thunderx_gpio_set_multiple;
511579
chip->set_config = thunderx_gpio_set_config;
512-
girq = &chip->irq;
513-
girq->chip = &thunderx_gpio_irq_chip;
514-
girq->fwnode = of_node_to_fwnode(dev->of_node);
515-
girq->parent_domain =
516-
irq_get_irq_data(txgpio->msix_entries[0].vector)->domain;
517-
girq->child_to_parent_hwirq = thunderx_gpio_child_to_parent_hwirq;
518-
girq->handler = handle_bad_irq;
519-
girq->default_type = IRQ_TYPE_NONE;
520-
580+
chip->to_irq = thunderx_gpio_to_irq;
521581
err = devm_gpiochip_add_data(dev, chip, txgpio);
522582
if (err)
523583
goto out;
524584

525-
/* Push on irq_data and the domain for each line. */
526-
for (i = 0; i < ngpio; i++) {
527-
err = irq_domain_push_irq(chip->irq.domain,
528-
txgpio->msix_entries[i].vector,
529-
chip);
530-
if (err < 0)
531-
dev_err(dev, "irq_domain_push_irq: %d\n", err);
532-
}
533-
534585
dev_info(dev, "ThunderX GPIO: %d lines with base %d.\n",
535586
ngpio, chip->base);
536587
return 0;
@@ -545,10 +596,10 @@ static void thunderx_gpio_remove(struct pci_dev *pdev)
545596
struct thunderx_gpio *txgpio = pci_get_drvdata(pdev);
546597

547598
for (i = 0; i < txgpio->chip.ngpio; i++)
548-
irq_domain_pop_irq(txgpio->chip.irq.domain,
599+
irq_domain_pop_irq(txgpio->irqd,
549600
txgpio->msix_entries[i].vector);
550601

551-
irq_domain_remove(txgpio->chip.irq.domain);
602+
irq_domain_remove(txgpio->irqd);
552603

553604
pci_set_drvdata(pdev, NULL);
554605
}

0 commit comments

Comments
 (0)