xref: /linux/drivers/pci/controller/pcie-xilinx.c (revision 0bd0a41a5120f78685a132834865b0a631b9026a)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * PCIe host controller driver for Xilinx AXI PCIe Bridge
4  *
5  * Copyright (c) 2012 - 2014 Xilinx, Inc.
6  *
7  * Based on the Tegra PCIe driver
8  *
9  * Bits taken from Synopsys DesignWare Host controller driver and
10  * ARM PCI Host generic driver.
11  */
12 
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/irqchip/irq-msi-lib.h>
16 #include <linux/irqdomain.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/msi.h>
20 #include <linux/of_address.h>
21 #include <linux/of_pci.h>
22 #include <linux/of_platform.h>
23 #include <linux/of_irq.h>
24 #include <linux/pci.h>
25 #include <linux/pci-ecam.h>
26 #include <linux/platform_device.h>
27 
28 #include "../pci.h"
29 
30 /* Register definitions */
31 #define XILINX_PCIE_REG_BIR		0x00000130
32 #define XILINX_PCIE_REG_IDR		0x00000138
33 #define XILINX_PCIE_REG_IMR		0x0000013c
34 #define XILINX_PCIE_REG_PSCR		0x00000144
35 #define XILINX_PCIE_REG_RPSC		0x00000148
36 #define XILINX_PCIE_REG_MSIBASE1	0x0000014c
37 #define XILINX_PCIE_REG_MSIBASE2	0x00000150
38 #define XILINX_PCIE_REG_RPEFR		0x00000154
39 #define XILINX_PCIE_REG_RPIFR1		0x00000158
40 #define XILINX_PCIE_REG_RPIFR2		0x0000015c
41 
42 /* Interrupt registers definitions */
43 #define XILINX_PCIE_INTR_LINK_DOWN	BIT(0)
44 #define XILINX_PCIE_INTR_ECRC_ERR	BIT(1)
45 #define XILINX_PCIE_INTR_STR_ERR	BIT(2)
46 #define XILINX_PCIE_INTR_HOT_RESET	BIT(3)
47 #define XILINX_PCIE_INTR_CFG_TIMEOUT	BIT(8)
48 #define XILINX_PCIE_INTR_CORRECTABLE	BIT(9)
49 #define XILINX_PCIE_INTR_NONFATAL	BIT(10)
50 #define XILINX_PCIE_INTR_FATAL		BIT(11)
51 #define XILINX_PCIE_INTR_INTX		BIT(16)
52 #define XILINX_PCIE_INTR_MSI		BIT(17)
53 #define XILINX_PCIE_INTR_SLV_UNSUPP	BIT(20)
54 #define XILINX_PCIE_INTR_SLV_UNEXP	BIT(21)
55 #define XILINX_PCIE_INTR_SLV_COMPL	BIT(22)
56 #define XILINX_PCIE_INTR_SLV_ERRP	BIT(23)
57 #define XILINX_PCIE_INTR_SLV_CMPABT	BIT(24)
58 #define XILINX_PCIE_INTR_SLV_ILLBUR	BIT(25)
59 #define XILINX_PCIE_INTR_MST_DECERR	BIT(26)
60 #define XILINX_PCIE_INTR_MST_SLVERR	BIT(27)
61 #define XILINX_PCIE_INTR_MST_ERRP	BIT(28)
62 #define XILINX_PCIE_IMR_ALL_MASK	0x1FF30FED
63 #define XILINX_PCIE_IMR_ENABLE_MASK	0x1FF30F0D
64 #define XILINX_PCIE_IDR_ALL_MASK	0xFFFFFFFF
65 
66 /* Root Port Error FIFO Read Register definitions */
67 #define XILINX_PCIE_RPEFR_ERR_VALID	BIT(18)
68 #define XILINX_PCIE_RPEFR_REQ_ID	GENMASK(15, 0)
69 #define XILINX_PCIE_RPEFR_ALL_MASK	0xFFFFFFFF
70 
71 /* Root Port Interrupt FIFO Read Register 1 definitions */
72 #define XILINX_PCIE_RPIFR1_INTR_VALID	BIT(31)
73 #define XILINX_PCIE_RPIFR1_MSI_INTR	BIT(30)
74 #define XILINX_PCIE_RPIFR1_INTR_MASK	GENMASK(28, 27)
75 #define XILINX_PCIE_RPIFR1_ALL_MASK	0xFFFFFFFF
76 #define XILINX_PCIE_RPIFR1_INTR_SHIFT	27
77 
78 /* Bridge Info Register definitions */
79 #define XILINX_PCIE_BIR_ECAM_SZ_MASK	GENMASK(18, 16)
80 #define XILINX_PCIE_BIR_ECAM_SZ_SHIFT	16
81 
82 /* Root Port Interrupt FIFO Read Register 2 definitions */
83 #define XILINX_PCIE_RPIFR2_MSG_DATA	GENMASK(15, 0)
84 
85 /* Root Port Status/control Register definitions */
86 #define XILINX_PCIE_REG_RPSC_BEN	BIT(0)
87 
88 /* Phy Status/Control Register definitions */
89 #define XILINX_PCIE_REG_PSCR_LNKUP	BIT(11)
90 
91 /* Number of MSI IRQs */
92 #define XILINX_NUM_MSI_IRQS		128
93 
94 /**
95  * struct xilinx_pcie - PCIe port information
96  * @dev: Device pointer
97  * @reg_base: IO Mapped Register Base
98  * @msi_map: Bitmap of allocated MSIs
99  * @map_lock: Mutex protecting the MSI allocation
100  * @msi_domain: MSI IRQ domain pointer
101  * @leg_domain: Legacy IRQ domain pointer
102  * @resources: Bus Resources
103  */
104 struct xilinx_pcie {
105 	struct device *dev;
106 	void __iomem *reg_base;
107 	unsigned long msi_map[BITS_TO_LONGS(XILINX_NUM_MSI_IRQS)];
108 	struct mutex map_lock;
109 	struct irq_domain *msi_domain;
110 	struct irq_domain *leg_domain;
111 	struct list_head resources;
112 };
113 
pcie_read(struct xilinx_pcie * pcie,u32 reg)114 static inline u32 pcie_read(struct xilinx_pcie *pcie, u32 reg)
115 {
116 	return readl(pcie->reg_base + reg);
117 }
118 
pcie_write(struct xilinx_pcie * pcie,u32 val,u32 reg)119 static inline void pcie_write(struct xilinx_pcie *pcie, u32 val, u32 reg)
120 {
121 	writel(val, pcie->reg_base + reg);
122 }
123 
xilinx_pcie_link_up(struct xilinx_pcie * pcie)124 static inline bool xilinx_pcie_link_up(struct xilinx_pcie *pcie)
125 {
126 	return (pcie_read(pcie, XILINX_PCIE_REG_PSCR) &
127 		XILINX_PCIE_REG_PSCR_LNKUP) ? 1 : 0;
128 }
129 
130 /**
131  * xilinx_pcie_clear_err_interrupts - Clear Error Interrupts
132  * @pcie: PCIe port information
133  */
xilinx_pcie_clear_err_interrupts(struct xilinx_pcie * pcie)134 static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie *pcie)
135 {
136 	struct device *dev = pcie->dev;
137 	unsigned long val = pcie_read(pcie, XILINX_PCIE_REG_RPEFR);
138 
139 	if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
140 		dev_dbg(dev, "Requester ID %lu\n",
141 			val & XILINX_PCIE_RPEFR_REQ_ID);
142 		pcie_write(pcie, XILINX_PCIE_RPEFR_ALL_MASK,
143 			   XILINX_PCIE_REG_RPEFR);
144 	}
145 }
146 
147 /**
148  * xilinx_pcie_valid_device - Check if a valid device is present on bus
149  * @bus: PCI Bus structure
150  * @devfn: device/function
151  *
152  * Return: 'true' on success and 'false' if invalid device is found
153  */
xilinx_pcie_valid_device(struct pci_bus * bus,unsigned int devfn)154 static bool xilinx_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
155 {
156 	struct xilinx_pcie *pcie = bus->sysdata;
157 
158 	/* Check if link is up when trying to access downstream pcie ports */
159 	if (!pci_is_root_bus(bus)) {
160 		if (!xilinx_pcie_link_up(pcie))
161 			return false;
162 	} else if (devfn > 0) {
163 		/* Only one device down on each root port */
164 		return false;
165 	}
166 	return true;
167 }
168 
169 /**
170  * xilinx_pcie_map_bus - Get configuration base
171  * @bus: PCI Bus structure
172  * @devfn: Device/function
173  * @where: Offset from base
174  *
175  * Return: Base address of the configuration space needed to be
176  *	   accessed.
177  */
xilinx_pcie_map_bus(struct pci_bus * bus,unsigned int devfn,int where)178 static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
179 					 unsigned int devfn, int where)
180 {
181 	struct xilinx_pcie *pcie = bus->sysdata;
182 
183 	if (!xilinx_pcie_valid_device(bus, devfn))
184 		return NULL;
185 
186 	return pcie->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where);
187 }
188 
189 /* PCIe operations */
190 static struct pci_ops xilinx_pcie_ops = {
191 	.map_bus = xilinx_pcie_map_bus,
192 	.read	= pci_generic_config_read,
193 	.write	= pci_generic_config_write,
194 };
195 
196 /* MSI functions */
197 
xilinx_msi_top_irq_ack(struct irq_data * d)198 static void xilinx_msi_top_irq_ack(struct irq_data *d)
199 {
200 	/*
201 	 * xilinx_pcie_intr_handler() will have performed the Ack.
202 	 * Eventually, this should be fixed and the Ack be moved in
203 	 * the respective callbacks for INTx and MSI.
204 	 */
205 }
206 
xilinx_compose_msi_msg(struct irq_data * data,struct msi_msg * msg)207 static void xilinx_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
208 {
209 	struct xilinx_pcie *pcie = irq_data_get_irq_chip_data(data);
210 	phys_addr_t pa = ALIGN_DOWN(virt_to_phys(pcie), SZ_4K);
211 
212 	msg->address_lo = lower_32_bits(pa);
213 	msg->address_hi = upper_32_bits(pa);
214 	msg->data = data->hwirq;
215 }
216 
217 static struct irq_chip xilinx_msi_bottom_chip = {
218 	.name			= "Xilinx MSI",
219 	.irq_compose_msi_msg	= xilinx_compose_msi_msg,
220 };
221 
xilinx_msi_domain_alloc(struct irq_domain * domain,unsigned int virq,unsigned int nr_irqs,void * args)222 static int xilinx_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
223 				  unsigned int nr_irqs, void *args)
224 {
225 	struct xilinx_pcie *pcie = domain->host_data;
226 	int hwirq, i;
227 
228 	mutex_lock(&pcie->map_lock);
229 
230 	hwirq = bitmap_find_free_region(pcie->msi_map, XILINX_NUM_MSI_IRQS, order_base_2(nr_irqs));
231 
232 	mutex_unlock(&pcie->map_lock);
233 
234 	if (hwirq < 0)
235 		return -ENOSPC;
236 
237 	for (i = 0; i < nr_irqs; i++)
238 		irq_domain_set_info(domain, virq + i, hwirq + i,
239 				    &xilinx_msi_bottom_chip, domain->host_data,
240 				    handle_edge_irq, NULL, NULL);
241 
242 	return 0;
243 }
244 
xilinx_msi_domain_free(struct irq_domain * domain,unsigned int virq,unsigned int nr_irqs)245 static void xilinx_msi_domain_free(struct irq_domain *domain, unsigned int virq,
246 				  unsigned int nr_irqs)
247 {
248 	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
249 	struct xilinx_pcie *pcie = domain->host_data;
250 
251 	mutex_lock(&pcie->map_lock);
252 
253 	bitmap_release_region(pcie->msi_map, d->hwirq, order_base_2(nr_irqs));
254 
255 	mutex_unlock(&pcie->map_lock);
256 }
257 
258 static const struct irq_domain_ops xilinx_msi_domain_ops = {
259 	.alloc	= xilinx_msi_domain_alloc,
260 	.free	= xilinx_msi_domain_free,
261 };
262 
xilinx_init_dev_msi_info(struct device * dev,struct irq_domain * domain,struct irq_domain * real_parent,struct msi_domain_info * info)263 static bool xilinx_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
264 				     struct irq_domain *real_parent, struct msi_domain_info *info)
265 {
266 	struct irq_chip *chip = info->chip;
267 
268 	if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info))
269 		return false;
270 
271 	chip->irq_ack = xilinx_msi_top_irq_ack;
272 	return true;
273 }
274 
275 #define XILINX_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS	| \
276 				   MSI_FLAG_USE_DEF_CHIP_OPS	| \
277 				   MSI_FLAG_NO_AFFINITY)
278 
279 static const struct msi_parent_ops xilinx_msi_parent_ops = {
280 	.required_flags		= XILINX_MSI_FLAGS_REQUIRED,
281 	.supported_flags	= MSI_GENERIC_FLAGS_MASK,
282 	.bus_select_token	= DOMAIN_BUS_PCI_MSI,
283 	.prefix			= "xilinx-",
284 	.init_dev_msi_info	= xilinx_init_dev_msi_info,
285 };
286 
xilinx_allocate_msi_domains(struct xilinx_pcie * pcie)287 static int xilinx_allocate_msi_domains(struct xilinx_pcie *pcie)
288 {
289 	struct irq_domain_info info = {
290 		.fwnode		= dev_fwnode(pcie->dev),
291 		.ops		= &xilinx_msi_domain_ops,
292 		.host_data	= pcie,
293 		.size		= XILINX_NUM_MSI_IRQS,
294 	};
295 
296 	pcie->msi_domain = msi_create_parent_irq_domain(&info, &xilinx_msi_parent_ops);
297 	if (!pcie->msi_domain) {
298 		dev_err(pcie->dev, "failed to create MSI domain\n");
299 		return -ENOMEM;
300 	}
301 
302 	return 0;
303 }
304 
xilinx_free_msi_domains(struct xilinx_pcie * pcie)305 static void xilinx_free_msi_domains(struct xilinx_pcie *pcie)
306 {
307 	irq_domain_remove(pcie->msi_domain);
308 }
309 
310 /* INTx Functions */
311 
312 /**
313  * xilinx_pcie_intx_map - Set the handler for the INTx and mark IRQ as valid
314  * @domain: IRQ domain
315  * @irq: Virtual IRQ number
316  * @hwirq: HW interrupt number
317  *
318  * Return: Always returns 0.
319  */
xilinx_pcie_intx_map(struct irq_domain * domain,unsigned int irq,irq_hw_number_t hwirq)320 static int xilinx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
321 				irq_hw_number_t hwirq)
322 {
323 	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
324 	irq_set_chip_data(irq, domain->host_data);
325 
326 	return 0;
327 }
328 
329 /* INTx IRQ Domain operations */
330 static const struct irq_domain_ops intx_domain_ops = {
331 	.map = xilinx_pcie_intx_map,
332 	.xlate = pci_irqd_intx_xlate,
333 };
334 
335 /* PCIe HW Functions */
336 
337 /**
338  * xilinx_pcie_intr_handler - Interrupt Service Handler
339  * @irq: IRQ number
340  * @data: PCIe port information
341  *
342  * Return: IRQ_HANDLED on success and IRQ_NONE on failure
343  */
xilinx_pcie_intr_handler(int irq,void * data)344 static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
345 {
346 	struct xilinx_pcie *pcie = (struct xilinx_pcie *)data;
347 	struct device *dev = pcie->dev;
348 	u32 val, mask, status;
349 
350 	/* Read interrupt decode and mask registers */
351 	val = pcie_read(pcie, XILINX_PCIE_REG_IDR);
352 	mask = pcie_read(pcie, XILINX_PCIE_REG_IMR);
353 
354 	status = val & mask;
355 	if (!status)
356 		return IRQ_NONE;
357 
358 	if (status & XILINX_PCIE_INTR_LINK_DOWN)
359 		dev_warn(dev, "Link Down\n");
360 
361 	if (status & XILINX_PCIE_INTR_ECRC_ERR)
362 		dev_warn(dev, "ECRC failed\n");
363 
364 	if (status & XILINX_PCIE_INTR_STR_ERR)
365 		dev_warn(dev, "Streaming error\n");
366 
367 	if (status & XILINX_PCIE_INTR_HOT_RESET)
368 		dev_info(dev, "Hot reset\n");
369 
370 	if (status & XILINX_PCIE_INTR_CFG_TIMEOUT)
371 		dev_warn(dev, "ECAM access timeout\n");
372 
373 	if (status & XILINX_PCIE_INTR_CORRECTABLE) {
374 		dev_warn(dev, "Correctable error message\n");
375 		xilinx_pcie_clear_err_interrupts(pcie);
376 	}
377 
378 	if (status & XILINX_PCIE_INTR_NONFATAL) {
379 		dev_warn(dev, "Non fatal error message\n");
380 		xilinx_pcie_clear_err_interrupts(pcie);
381 	}
382 
383 	if (status & XILINX_PCIE_INTR_FATAL) {
384 		dev_warn(dev, "Fatal error message\n");
385 		xilinx_pcie_clear_err_interrupts(pcie);
386 	}
387 
388 	if (status & (XILINX_PCIE_INTR_INTX | XILINX_PCIE_INTR_MSI)) {
389 		struct irq_domain *domain;
390 
391 		val = pcie_read(pcie, XILINX_PCIE_REG_RPIFR1);
392 
393 		/* Check whether interrupt valid */
394 		if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
395 			dev_warn(dev, "RP Intr FIFO1 read error\n");
396 			goto error;
397 		}
398 
399 		/* Decode the IRQ number */
400 		if (val & XILINX_PCIE_RPIFR1_MSI_INTR) {
401 			val = pcie_read(pcie, XILINX_PCIE_REG_RPIFR2) &
402 				XILINX_PCIE_RPIFR2_MSG_DATA;
403 			domain = pcie->msi_domain->parent;
404 		} else {
405 			val = (val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
406 				XILINX_PCIE_RPIFR1_INTR_SHIFT;
407 			domain = pcie->leg_domain;
408 		}
409 
410 		/* Clear interrupt FIFO register 1 */
411 		pcie_write(pcie, XILINX_PCIE_RPIFR1_ALL_MASK,
412 			   XILINX_PCIE_REG_RPIFR1);
413 
414 		generic_handle_domain_irq(domain, val);
415 	}
416 
417 	if (status & XILINX_PCIE_INTR_SLV_UNSUPP)
418 		dev_warn(dev, "Slave unsupported request\n");
419 
420 	if (status & XILINX_PCIE_INTR_SLV_UNEXP)
421 		dev_warn(dev, "Slave unexpected completion\n");
422 
423 	if (status & XILINX_PCIE_INTR_SLV_COMPL)
424 		dev_warn(dev, "Slave completion timeout\n");
425 
426 	if (status & XILINX_PCIE_INTR_SLV_ERRP)
427 		dev_warn(dev, "Slave Error Poison\n");
428 
429 	if (status & XILINX_PCIE_INTR_SLV_CMPABT)
430 		dev_warn(dev, "Slave Completer Abort\n");
431 
432 	if (status & XILINX_PCIE_INTR_SLV_ILLBUR)
433 		dev_warn(dev, "Slave Illegal Burst\n");
434 
435 	if (status & XILINX_PCIE_INTR_MST_DECERR)
436 		dev_warn(dev, "Master decode error\n");
437 
438 	if (status & XILINX_PCIE_INTR_MST_SLVERR)
439 		dev_warn(dev, "Master slave error\n");
440 
441 	if (status & XILINX_PCIE_INTR_MST_ERRP)
442 		dev_warn(dev, "Master error poison\n");
443 
444 error:
445 	/* Clear the Interrupt Decode register */
446 	pcie_write(pcie, status, XILINX_PCIE_REG_IDR);
447 
448 	return IRQ_HANDLED;
449 }
450 
451 /**
452  * xilinx_pcie_init_irq_domain - Initialize IRQ domain
453  * @pcie: PCIe port information
454  *
455  * Return: '0' on success and error value on failure
456  */
xilinx_pcie_init_irq_domain(struct xilinx_pcie * pcie)457 static int xilinx_pcie_init_irq_domain(struct xilinx_pcie *pcie)
458 {
459 	struct device *dev = pcie->dev;
460 	struct device_node *pcie_intc_node;
461 	int ret;
462 
463 	/* Setup INTx */
464 	pcie_intc_node = of_get_next_child(dev->of_node, NULL);
465 	if (!pcie_intc_node) {
466 		dev_err(dev, "No PCIe Intc node found\n");
467 		return -ENODEV;
468 	}
469 
470 	pcie->leg_domain = irq_domain_create_linear(of_fwnode_handle(pcie_intc_node), PCI_NUM_INTX,
471 						    &intx_domain_ops, pcie);
472 	of_node_put(pcie_intc_node);
473 	if (!pcie->leg_domain) {
474 		dev_err(dev, "Failed to get a INTx IRQ domain\n");
475 		return -ENODEV;
476 	}
477 
478 	/* Setup MSI */
479 	if (IS_ENABLED(CONFIG_PCI_MSI)) {
480 		phys_addr_t pa = ALIGN_DOWN(virt_to_phys(pcie), SZ_4K);
481 
482 		ret = xilinx_allocate_msi_domains(pcie);
483 		if (ret)
484 			return ret;
485 
486 		pcie_write(pcie, upper_32_bits(pa), XILINX_PCIE_REG_MSIBASE1);
487 		pcie_write(pcie, lower_32_bits(pa), XILINX_PCIE_REG_MSIBASE2);
488 	}
489 
490 	return 0;
491 }
492 
493 /**
494  * xilinx_pcie_init_port - Initialize hardware
495  * @pcie: PCIe port information
496  */
xilinx_pcie_init_port(struct xilinx_pcie * pcie)497 static void xilinx_pcie_init_port(struct xilinx_pcie *pcie)
498 {
499 	struct device *dev = pcie->dev;
500 
501 	if (xilinx_pcie_link_up(pcie))
502 		dev_info(dev, "PCIe Link is UP\n");
503 	else
504 		dev_info(dev, "PCIe Link is DOWN\n");
505 
506 	/* Disable all interrupts */
507 	pcie_write(pcie, ~XILINX_PCIE_IDR_ALL_MASK,
508 		   XILINX_PCIE_REG_IMR);
509 
510 	/* Clear pending interrupts */
511 	pcie_write(pcie, pcie_read(pcie, XILINX_PCIE_REG_IDR) &
512 			 XILINX_PCIE_IMR_ALL_MASK,
513 		   XILINX_PCIE_REG_IDR);
514 
515 	/* Enable all interrupts we handle */
516 	pcie_write(pcie, XILINX_PCIE_IMR_ENABLE_MASK, XILINX_PCIE_REG_IMR);
517 
518 	/* Enable the Bridge enable bit */
519 	pcie_write(pcie, pcie_read(pcie, XILINX_PCIE_REG_RPSC) |
520 			 XILINX_PCIE_REG_RPSC_BEN,
521 		   XILINX_PCIE_REG_RPSC);
522 }
523 
524 /**
525  * xilinx_pcie_parse_dt - Parse Device tree
526  * @pcie: PCIe port information
527  *
528  * Return: '0' on success and error value on failure
529  */
xilinx_pcie_parse_dt(struct xilinx_pcie * pcie)530 static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
531 {
532 	struct device *dev = pcie->dev;
533 	struct device_node *node = dev->of_node;
534 	struct resource regs;
535 	unsigned int irq;
536 	int err;
537 
538 	err = of_address_to_resource(node, 0, &regs);
539 	if (err) {
540 		dev_err(dev, "missing \"reg\" property\n");
541 		return err;
542 	}
543 
544 	pcie->reg_base = devm_pci_remap_cfg_resource(dev, &regs);
545 	if (IS_ERR(pcie->reg_base))
546 		return PTR_ERR(pcie->reg_base);
547 
548 	irq = irq_of_parse_and_map(node, 0);
549 	err = devm_request_irq(dev, irq, xilinx_pcie_intr_handler,
550 			       IRQF_SHARED | IRQF_NO_THREAD,
551 			       "xilinx-pcie", pcie);
552 	if (err) {
553 		dev_err(dev, "unable to request irq %d\n", irq);
554 		return err;
555 	}
556 
557 	return 0;
558 }
559 
560 /**
561  * xilinx_pcie_probe - Probe function
562  * @pdev: Platform device pointer
563  *
564  * Return: '0' on success and error value on failure
565  */
xilinx_pcie_probe(struct platform_device * pdev)566 static int xilinx_pcie_probe(struct platform_device *pdev)
567 {
568 	struct device *dev = &pdev->dev;
569 	struct xilinx_pcie *pcie;
570 	struct pci_host_bridge *bridge;
571 	int err;
572 
573 	if (!dev->of_node)
574 		return -ENODEV;
575 
576 	bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
577 	if (!bridge)
578 		return -ENODEV;
579 
580 	pcie = pci_host_bridge_priv(bridge);
581 	mutex_init(&pcie->map_lock);
582 	pcie->dev = dev;
583 
584 	err = xilinx_pcie_parse_dt(pcie);
585 	if (err) {
586 		dev_err(dev, "Parsing DT failed\n");
587 		return err;
588 	}
589 
590 	xilinx_pcie_init_port(pcie);
591 
592 	err = xilinx_pcie_init_irq_domain(pcie);
593 	if (err) {
594 		dev_err(dev, "Failed creating IRQ Domain\n");
595 		return err;
596 	}
597 
598 	bridge->sysdata = pcie;
599 	bridge->ops = &xilinx_pcie_ops;
600 
601 	err = pci_host_probe(bridge);
602 	if (err)
603 		xilinx_free_msi_domains(pcie);
604 
605 	return err;
606 }
607 
608 static const struct of_device_id xilinx_pcie_of_match[] = {
609 	{ .compatible = "xlnx,axi-pcie-host-1.00.a", },
610 	{}
611 };
612 
613 static struct platform_driver xilinx_pcie_driver = {
614 	.driver = {
615 		.name = "xilinx-pcie",
616 		.of_match_table = xilinx_pcie_of_match,
617 		.suppress_bind_attrs = true,
618 	},
619 	.probe = xilinx_pcie_probe,
620 };
621 builtin_platform_driver(xilinx_pcie_driver);
622