dfcd84f47542f8c2e6041f34301ea3e89108d15e
[openwrt/staging/blocktrron.git] /
1 From db305233136f5aa2444a8287a279384e8458c458 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Thu, 1 Apr 2021 20:12:48 +0200
4 Subject: [PATCH] PCI: aardvark: Use separate INTA interrupt for emulated root
5 bridge
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Emulated root bridge currently provides only one Legacy INTA interrupt
11 which is used for reporting PCIe PME and ERR events and handled by kernel
12 PCIe PME and AER drivers.
13
14 Aardvark HW reports these PME and ERR events separately, so there is no
15 need to mix real INTA interrupt and emulated INTA interrupt for PCIe PME
16 and AER drivers.
17
18 Register a new advk-RP (as in Root Port) irq chip and a new irq domain
19 for emulated root bridge and use this new separate irq domain for
20 providing INTA interrupt from emulated root bridge for PME and ERR events.
21
22 The real INTA interrupt from real devices is now separate.
23
24 A custom map_irq callback function on PCI host bridge structure is used to
25 allocate IRQ mapping for emulated root bridge from new irq domain. Original
26 callback of_irq_parse_and_map_pci() is used for all other devices as before.
27
28 Signed-off-by: Pali Rohár <pali@kernel.org>
29 Signed-off-by: Marek Behún <kabel@kernel.org>
30 ---
31 drivers/pci/controller/pci-aardvark.c | 69 ++++++++++++++++++++++++++-
32 1 file changed, 67 insertions(+), 2 deletions(-)
33
34 --- a/drivers/pci/controller/pci-aardvark.c
35 +++ b/drivers/pci/controller/pci-aardvark.c
36 @@ -273,6 +273,7 @@ struct advk_pcie {
37 } wins[OB_WIN_COUNT];
38 u8 wins_count;
39 int irq;
40 + struct irq_domain *rp_irq_domain;
41 struct irq_domain *irq_domain;
42 struct irq_chip irq_chip;
43 raw_spinlock_t irq_lock;
44 @@ -1436,6 +1437,44 @@ static void advk_pcie_remove_irq_domain(
45 irq_domain_remove(pcie->irq_domain);
46 }
47
48 +static struct irq_chip advk_rp_irq_chip = {
49 + .name = "advk-RP",
50 +};
51 +
52 +static int advk_pcie_rp_irq_map(struct irq_domain *h,
53 + unsigned int virq, irq_hw_number_t hwirq)
54 +{
55 + struct advk_pcie *pcie = h->host_data;
56 +
57 + irq_set_chip_and_handler(virq, &advk_rp_irq_chip, handle_simple_irq);
58 + irq_set_chip_data(virq, pcie);
59 +
60 + return 0;
61 +}
62 +
63 +static const struct irq_domain_ops advk_pcie_rp_irq_domain_ops = {
64 + .map = advk_pcie_rp_irq_map,
65 + .xlate = irq_domain_xlate_onecell,
66 +};
67 +
68 +static int advk_pcie_init_rp_irq_domain(struct advk_pcie *pcie)
69 +{
70 + pcie->rp_irq_domain = irq_domain_add_linear(NULL, 1,
71 + &advk_pcie_rp_irq_domain_ops,
72 + pcie);
73 + if (!pcie->rp_irq_domain) {
74 + dev_err(&pcie->pdev->dev, "Failed to add Root Port IRQ domain\n");
75 + return -ENOMEM;
76 + }
77 +
78 + return 0;
79 +}
80 +
81 +static void advk_pcie_remove_rp_irq_domain(struct advk_pcie *pcie)
82 +{
83 + irq_domain_remove(pcie->rp_irq_domain);
84 +}
85 +
86 static void advk_pcie_handle_pme(struct advk_pcie *pcie)
87 {
88 u32 requester = advk_readl(pcie, PCIE_MSG_LOG_REG) >> 16;
89 @@ -1458,7 +1497,7 @@ static void advk_pcie_handle_pme(struct
90 if (!(le16_to_cpu(pcie->bridge.pcie_conf.rootctl) & PCI_EXP_RTCTL_PMEIE))
91 return;
92
93 - virq = irq_find_mapping(pcie->irq_domain, 0);
94 + virq = irq_find_mapping(pcie->rp_irq_domain, 0);
95 if (generic_handle_irq(virq) == -EINVAL)
96 dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
97 }
98 @@ -1515,7 +1554,7 @@ static void advk_pcie_handle_int(struct
99 * Aardvark HW returns zero for PCI_ERR_ROOT_AER_IRQ, so use
100 * PCIe interrupt 0
101 */
102 - virq = irq_find_mapping(pcie->irq_domain, 0);
103 + virq = irq_find_mapping(pcie->rp_irq_domain, 0);
104 if (generic_handle_irq(virq) == -EINVAL)
105 dev_err_ratelimited(&pcie->pdev->dev, "unhandled ERR IRQ\n");
106 }
107 @@ -1560,6 +1599,21 @@ static void advk_pcie_irq_handler(struct
108 chained_irq_exit(chip, desc);
109 }
110
111 +static int advk_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
112 +{
113 + struct advk_pcie *pcie = dev->bus->sysdata;
114 +
115 + /*
116 + * Emulated root bridge has its own emulated irq chip and irq domain.
117 + * Argument pin is the INTx pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) and
118 + * hwirq for irq_create_mapping() is indexed from zero.
119 + */
120 + if (pci_is_root_bus(dev->bus))
121 + return irq_create_mapping(pcie->rp_irq_domain, pin - 1);
122 + else
123 + return of_irq_parse_and_map_pci(dev, slot, pin);
124 +}
125 +
126 static void __maybe_unused advk_pcie_disable_phy(struct advk_pcie *pcie)
127 {
128 phy_power_off(pcie->phy);
129 @@ -1761,14 +1815,24 @@ static int advk_pcie_probe(struct platfo
130 return ret;
131 }
132
133 + ret = advk_pcie_init_rp_irq_domain(pcie);
134 + if (ret) {
135 + dev_err(dev, "Failed to initialize irq\n");
136 + advk_pcie_remove_msi_irq_domain(pcie);
137 + advk_pcie_remove_irq_domain(pcie);
138 + return ret;
139 + }
140 +
141 irq_set_chained_handler_and_data(pcie->irq, advk_pcie_irq_handler, pcie);
142
143 bridge->sysdata = pcie;
144 bridge->ops = &advk_pcie_ops;
145 + bridge->map_irq = advk_pcie_map_irq;
146
147 ret = pci_host_probe(bridge);
148 if (ret < 0) {
149 irq_set_chained_handler_and_data(pcie->irq, NULL, NULL);
150 + advk_pcie_remove_rp_irq_domain(pcie);
151 advk_pcie_remove_msi_irq_domain(pcie);
152 advk_pcie_remove_irq_domain(pcie);
153 return ret;
154 @@ -1820,6 +1884,7 @@ static int advk_pcie_remove(struct platf
155 irq_set_chained_handler_and_data(pcie->irq, NULL, NULL);
156
157 /* Remove IRQ domains */
158 + advk_pcie_remove_rp_irq_domain(pcie);
159 advk_pcie_remove_msi_irq_domain(pcie);
160 advk_pcie_remove_irq_domain(pcie);
161