2 * PCIe host controller driver for Xilinx AXI PCIe Bridge
4 * Copyright (c) 2012 - 2014 Xilinx, Inc.
6 * Based on the Tegra PCIe driver
8 * Bits taken from Synopsys Designware Host controller driver and
9 * ARM PCI Host generic driver.
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
19 #include <linux/irqdomain.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/msi.h>
23 #include <linux/of_address.h>
24 #include <linux/of_pci.h>
25 #include <linux/of_platform.h>
26 #include <linux/of_irq.h>
27 #include <linux/pci.h>
28 #include <linux/platform_device.h>
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
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_IDR_ALL_MASK 0xFFFFFFFF
65 /* Root Port Error FIFO Read Register definitions */
66 #define XILINX_PCIE_RPEFR_ERR_VALID BIT(18)
67 #define XILINX_PCIE_RPEFR_REQ_ID GENMASK(15, 0)
68 #define XILINX_PCIE_RPEFR_ALL_MASK 0xFFFFFFFF
70 /* Root Port Interrupt FIFO Read Register 1 definitions */
71 #define XILINX_PCIE_RPIFR1_INTR_VALID BIT(31)
72 #define XILINX_PCIE_RPIFR1_MSI_INTR BIT(30)
73 #define XILINX_PCIE_RPIFR1_INTR_MASK GENMASK(28, 27)
74 #define XILINX_PCIE_RPIFR1_ALL_MASK 0xFFFFFFFF
75 #define XILINX_PCIE_RPIFR1_INTR_SHIFT 27
77 /* Bridge Info Register definitions */
78 #define XILINX_PCIE_BIR_ECAM_SZ_MASK GENMASK(18, 16)
79 #define XILINX_PCIE_BIR_ECAM_SZ_SHIFT 16
81 /* Root Port Interrupt FIFO Read Register 2 definitions */
82 #define XILINX_PCIE_RPIFR2_MSG_DATA GENMASK(15, 0)
84 /* Root Port Status/control Register definitions */
85 #define XILINX_PCIE_REG_RPSC_BEN BIT(0)
87 /* Phy Status/Control Register definitions */
88 #define XILINX_PCIE_REG_PSCR_LNKUP BIT(11)
90 /* ECAM definitions */
91 #define ECAM_BUS_NUM_SHIFT 20
92 #define ECAM_DEV_NUM_SHIFT 12
94 /* Number of MSI IRQs */
95 #define XILINX_NUM_MSI_IRQS 128
97 /* Number of Memory Resources */
98 #define XILINX_MAX_NUM_RESOURCES 3
101 * struct xilinx_pcie_port - PCIe port information
102 * @reg_base: IO Mapped Register Base
103 * @irq: Interrupt number
104 * @msi_pages: MSI pages
105 * @root_busno: Root Bus number
106 * @dev: Device pointer
107 * @irq_domain: IRQ domain pointer
108 * @bus_range: Bus range
109 * @resources: Bus Resources
111 struct xilinx_pcie_port {
112 void __iomem *reg_base;
114 unsigned long msi_pages;
117 struct irq_domain *irq_domain;
118 struct resource bus_range;
119 struct list_head resources;
122 static DECLARE_BITMAP(msi_irq_in_use, XILINX_NUM_MSI_IRQS);
124 static inline struct xilinx_pcie_port *sys_to_pcie(struct pci_sys_data *sys)
126 return sys->private_data;
129 static inline u32 pcie_read(struct xilinx_pcie_port *port, u32 reg)
131 return readl(port->reg_base + reg);
134 static inline void pcie_write(struct xilinx_pcie_port *port, u32 val, u32 reg)
136 writel(val, port->reg_base + reg);
139 static inline bool xilinx_pcie_link_is_up(struct xilinx_pcie_port *port)
141 return (pcie_read(port, XILINX_PCIE_REG_PSCR) &
142 XILINX_PCIE_REG_PSCR_LNKUP) ? 1 : 0;
146 * xilinx_pcie_clear_err_interrupts - Clear Error Interrupts
147 * @port: PCIe port information
149 static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie_port *port)
151 unsigned long val = pcie_read(port, XILINX_PCIE_REG_RPEFR);
153 if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
154 dev_dbg(port->dev, "Requester ID %lu\n",
155 val & XILINX_PCIE_RPEFR_REQ_ID);
156 pcie_write(port, XILINX_PCIE_RPEFR_ALL_MASK,
157 XILINX_PCIE_REG_RPEFR);
162 * xilinx_pcie_valid_device - Check if a valid device is present on bus
163 * @bus: PCI Bus structure
164 * @devfn: device/function
166 * Return: 'true' on success and 'false' if invalid device is found
168 static bool xilinx_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
170 struct xilinx_pcie_port *port = sys_to_pcie(bus->sysdata);
172 /* Check if link is up when trying to access downstream ports */
173 if (bus->number != port->root_busno)
174 if (!xilinx_pcie_link_is_up(port))
177 /* Only one device down on each root port */
178 if (bus->number == port->root_busno && devfn > 0)
182 * Do not read more than one device on the bus directly attached
185 if (bus->primary == port->root_busno && devfn > 0)
192 * xilinx_pcie_map_bus - Get configuration base
193 * @bus: PCI Bus structure
194 * @devfn: Device/function
195 * @where: Offset from base
197 * Return: Base address of the configuration space needed to be
200 static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
201 unsigned int devfn, int where)
203 struct xilinx_pcie_port *port = sys_to_pcie(bus->sysdata);
206 if (!xilinx_pcie_valid_device(bus, devfn))
209 relbus = (bus->number << ECAM_BUS_NUM_SHIFT) |
210 (devfn << ECAM_DEV_NUM_SHIFT);
212 return port->reg_base + relbus + where;
215 /* PCIe operations */
216 static struct pci_ops xilinx_pcie_ops = {
217 .map_bus = xilinx_pcie_map_bus,
218 .read = pci_generic_config_read,
219 .write = pci_generic_config_write,
225 * xilinx_pcie_destroy_msi - Free MSI number
226 * @irq: IRQ to be freed
228 static void xilinx_pcie_destroy_msi(unsigned int irq)
230 struct irq_desc *desc;
231 struct msi_desc *msi;
232 struct xilinx_pcie_port *port;
234 desc = irq_to_desc(irq);
235 msi = irq_desc_get_msi_desc(desc);
236 port = sys_to_pcie(msi->dev->bus->sysdata);
238 if (!test_bit(irq, msi_irq_in_use))
239 dev_err(port->dev, "Trying to free unused MSI#%d\n", irq);
241 clear_bit(irq, msi_irq_in_use);
245 * xilinx_pcie_assign_msi - Allocate MSI number
246 * @port: PCIe port structure
248 * Return: A valid IRQ on success and error value on failure.
250 static int xilinx_pcie_assign_msi(struct xilinx_pcie_port *port)
254 pos = find_first_zero_bit(msi_irq_in_use, XILINX_NUM_MSI_IRQS);
255 if (pos < XILINX_NUM_MSI_IRQS)
256 set_bit(pos, msi_irq_in_use);
264 * xilinx_msi_teardown_irq - Destroy the MSI
265 * @chip: MSI Chip descriptor
266 * @irq: MSI IRQ to destroy
268 static void xilinx_msi_teardown_irq(struct msi_controller *chip,
271 xilinx_pcie_destroy_msi(irq);
275 * xilinx_pcie_msi_setup_irq - Setup MSI request
276 * @chip: MSI chip pointer
277 * @pdev: PCIe device pointer
278 * @desc: MSI descriptor pointer
280 * Return: '0' on success and error value on failure
282 static int xilinx_pcie_msi_setup_irq(struct msi_controller *chip,
283 struct pci_dev *pdev,
284 struct msi_desc *desc)
286 struct xilinx_pcie_port *port = sys_to_pcie(pdev->bus->sysdata);
290 phys_addr_t msg_addr;
292 hwirq = xilinx_pcie_assign_msi(port);
296 irq = irq_create_mapping(port->irq_domain, hwirq);
300 irq_set_msi_desc(irq, desc);
302 msg_addr = virt_to_phys((void *)port->msi_pages);
305 msg.address_lo = msg_addr;
308 pci_write_msi_msg(irq, &msg);
313 /* MSI Chip Descriptor */
314 static struct msi_controller xilinx_pcie_msi_chip = {
315 .setup_irq = xilinx_pcie_msi_setup_irq,
316 .teardown_irq = xilinx_msi_teardown_irq,
319 /* HW Interrupt Chip Descriptor */
320 static struct irq_chip xilinx_msi_irq_chip = {
321 .name = "Xilinx PCIe MSI",
322 .irq_enable = pci_msi_unmask_irq,
323 .irq_disable = pci_msi_mask_irq,
324 .irq_mask = pci_msi_mask_irq,
325 .irq_unmask = pci_msi_unmask_irq,
329 * xilinx_pcie_msi_map - Set the handler for the MSI and mark IRQ as valid
330 * @domain: IRQ domain
331 * @irq: Virtual IRQ number
332 * @hwirq: HW interrupt number
334 * Return: Always returns 0.
336 static int xilinx_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
337 irq_hw_number_t hwirq)
339 irq_set_chip_and_handler(irq, &xilinx_msi_irq_chip, handle_simple_irq);
340 irq_set_chip_data(irq, domain->host_data);
341 set_irq_flags(irq, IRQF_VALID);
346 /* IRQ Domain operations */
347 static const struct irq_domain_ops msi_domain_ops = {
348 .map = xilinx_pcie_msi_map,
352 * xilinx_pcie_enable_msi - Enable MSI support
353 * @port: PCIe port information
355 static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
357 phys_addr_t msg_addr;
359 port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
360 msg_addr = virt_to_phys((void *)port->msi_pages);
361 pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
362 pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
368 * xilinx_pcie_intx_map - Set the handler for the INTx and mark IRQ as valid
369 * @domain: IRQ domain
370 * @irq: Virtual IRQ number
371 * @hwirq: HW interrupt number
373 * Return: Always returns 0.
375 static int xilinx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
376 irq_hw_number_t hwirq)
378 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
379 irq_set_chip_data(irq, domain->host_data);
380 set_irq_flags(irq, IRQF_VALID);
385 /* INTx IRQ Domain operations */
386 static const struct irq_domain_ops intx_domain_ops = {
387 .map = xilinx_pcie_intx_map,
390 /* PCIe HW Functions */
393 * xilinx_pcie_intr_handler - Interrupt Service Handler
395 * @data: PCIe port information
397 * Return: IRQ_HANDLED on success and IRQ_NONE on failure
399 static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
401 struct xilinx_pcie_port *port = (struct xilinx_pcie_port *)data;
402 u32 val, mask, status, msi_data;
404 /* Read interrupt decode and mask registers */
405 val = pcie_read(port, XILINX_PCIE_REG_IDR);
406 mask = pcie_read(port, XILINX_PCIE_REG_IMR);
412 if (status & XILINX_PCIE_INTR_LINK_DOWN)
413 dev_warn(port->dev, "Link Down\n");
415 if (status & XILINX_PCIE_INTR_ECRC_ERR)
416 dev_warn(port->dev, "ECRC failed\n");
418 if (status & XILINX_PCIE_INTR_STR_ERR)
419 dev_warn(port->dev, "Streaming error\n");
421 if (status & XILINX_PCIE_INTR_HOT_RESET)
422 dev_info(port->dev, "Hot reset\n");
424 if (status & XILINX_PCIE_INTR_CFG_TIMEOUT)
425 dev_warn(port->dev, "ECAM access timeout\n");
427 if (status & XILINX_PCIE_INTR_CORRECTABLE) {
428 dev_warn(port->dev, "Correctable error message\n");
429 xilinx_pcie_clear_err_interrupts(port);
432 if (status & XILINX_PCIE_INTR_NONFATAL) {
433 dev_warn(port->dev, "Non fatal error message\n");
434 xilinx_pcie_clear_err_interrupts(port);
437 if (status & XILINX_PCIE_INTR_FATAL) {
438 dev_warn(port->dev, "Fatal error message\n");
439 xilinx_pcie_clear_err_interrupts(port);
442 if (status & XILINX_PCIE_INTR_INTX) {
443 /* INTx interrupt received */
444 val = pcie_read(port, XILINX_PCIE_REG_RPIFR1);
446 /* Check whether interrupt valid */
447 if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
448 dev_warn(port->dev, "RP Intr FIFO1 read error\n");
452 if (!(val & XILINX_PCIE_RPIFR1_MSI_INTR)) {
453 /* Clear interrupt FIFO register 1 */
454 pcie_write(port, XILINX_PCIE_RPIFR1_ALL_MASK,
455 XILINX_PCIE_REG_RPIFR1);
457 /* Handle INTx Interrupt */
458 val = ((val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
459 XILINX_PCIE_RPIFR1_INTR_SHIFT) + 1;
460 generic_handle_irq(irq_find_mapping(port->irq_domain,
465 if (status & XILINX_PCIE_INTR_MSI) {
467 val = pcie_read(port, XILINX_PCIE_REG_RPIFR1);
469 if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
470 dev_warn(port->dev, "RP Intr FIFO1 read error\n");
474 if (val & XILINX_PCIE_RPIFR1_MSI_INTR) {
475 msi_data = pcie_read(port, XILINX_PCIE_REG_RPIFR2) &
476 XILINX_PCIE_RPIFR2_MSG_DATA;
478 /* Clear interrupt FIFO register 1 */
479 pcie_write(port, XILINX_PCIE_RPIFR1_ALL_MASK,
480 XILINX_PCIE_REG_RPIFR1);
482 if (IS_ENABLED(CONFIG_PCI_MSI)) {
483 /* Handle MSI Interrupt */
484 generic_handle_irq(msi_data);
489 if (status & XILINX_PCIE_INTR_SLV_UNSUPP)
490 dev_warn(port->dev, "Slave unsupported request\n");
492 if (status & XILINX_PCIE_INTR_SLV_UNEXP)
493 dev_warn(port->dev, "Slave unexpected completion\n");
495 if (status & XILINX_PCIE_INTR_SLV_COMPL)
496 dev_warn(port->dev, "Slave completion timeout\n");
498 if (status & XILINX_PCIE_INTR_SLV_ERRP)
499 dev_warn(port->dev, "Slave Error Poison\n");
501 if (status & XILINX_PCIE_INTR_SLV_CMPABT)
502 dev_warn(port->dev, "Slave Completer Abort\n");
504 if (status & XILINX_PCIE_INTR_SLV_ILLBUR)
505 dev_warn(port->dev, "Slave Illegal Burst\n");
507 if (status & XILINX_PCIE_INTR_MST_DECERR)
508 dev_warn(port->dev, "Master decode error\n");
510 if (status & XILINX_PCIE_INTR_MST_SLVERR)
511 dev_warn(port->dev, "Master slave error\n");
513 if (status & XILINX_PCIE_INTR_MST_ERRP)
514 dev_warn(port->dev, "Master error poison\n");
516 /* Clear the Interrupt Decode register */
517 pcie_write(port, status, XILINX_PCIE_REG_IDR);
523 * xilinx_pcie_free_irq_domain - Free IRQ domain
524 * @port: PCIe port information
526 static void xilinx_pcie_free_irq_domain(struct xilinx_pcie_port *port)
531 /* Free IRQ Domain */
532 if (IS_ENABLED(CONFIG_PCI_MSI)) {
534 free_pages(port->msi_pages, 0);
536 num_irqs = XILINX_NUM_MSI_IRQS;
542 for (i = 0; i < num_irqs; i++) {
543 irq = irq_find_mapping(port->irq_domain, i);
545 irq_dispose_mapping(irq);
548 irq_domain_remove(port->irq_domain);
552 * xilinx_pcie_init_irq_domain - Initialize IRQ domain
553 * @port: PCIe port information
555 * Return: '0' on success and error value on failure
557 static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
559 struct device *dev = port->dev;
560 struct device_node *node = dev->of_node;
561 struct device_node *pcie_intc_node;
564 pcie_intc_node = of_get_next_child(node, NULL);
565 if (!pcie_intc_node) {
566 dev_err(dev, "No PCIe Intc node found\n");
567 return PTR_ERR(pcie_intc_node);
570 port->irq_domain = irq_domain_add_linear(pcie_intc_node, 4,
573 if (!port->irq_domain) {
574 dev_err(dev, "Failed to get a INTx IRQ domain\n");
575 return PTR_ERR(port->irq_domain);
579 if (IS_ENABLED(CONFIG_PCI_MSI)) {
580 port->irq_domain = irq_domain_add_linear(node,
583 &xilinx_pcie_msi_chip);
584 if (!port->irq_domain) {
585 dev_err(dev, "Failed to get a MSI IRQ domain\n");
586 return PTR_ERR(port->irq_domain);
589 xilinx_pcie_enable_msi(port);
596 * xilinx_pcie_init_port - Initialize hardware
597 * @port: PCIe port information
599 static void xilinx_pcie_init_port(struct xilinx_pcie_port *port)
601 if (xilinx_pcie_link_is_up(port))
602 dev_info(port->dev, "PCIe Link is UP\n");
604 dev_info(port->dev, "PCIe Link is DOWN\n");
606 /* Disable all interrupts */
607 pcie_write(port, ~XILINX_PCIE_IDR_ALL_MASK,
608 XILINX_PCIE_REG_IMR);
610 /* Clear pending interrupts */
611 pcie_write(port, pcie_read(port, XILINX_PCIE_REG_IDR) &
612 XILINX_PCIE_IMR_ALL_MASK,
613 XILINX_PCIE_REG_IDR);
615 /* Enable all interrupts */
616 pcie_write(port, XILINX_PCIE_IMR_ALL_MASK, XILINX_PCIE_REG_IMR);
618 /* Enable the Bridge enable bit */
619 pcie_write(port, pcie_read(port, XILINX_PCIE_REG_RPSC) |
620 XILINX_PCIE_REG_RPSC_BEN,
621 XILINX_PCIE_REG_RPSC);
625 * xilinx_pcie_setup - Setup memory resources
627 * @sys: Per controller structure
629 * Return: '1' on success and error value on failure
631 static int xilinx_pcie_setup(int nr, struct pci_sys_data *sys)
633 struct xilinx_pcie_port *port = sys_to_pcie(sys);
635 list_splice_init(&port->resources, &sys->resources);
641 * xilinx_pcie_scan_bus - Scan PCIe bus for devices
643 * @sys: Per controller structure
645 * Return: Valid Bus pointer on success and NULL on failure
647 static struct pci_bus *xilinx_pcie_scan_bus(int nr, struct pci_sys_data *sys)
649 struct xilinx_pcie_port *port = sys_to_pcie(sys);
652 port->root_busno = sys->busnr;
653 bus = pci_scan_root_bus(port->dev, sys->busnr, &xilinx_pcie_ops,
654 sys, &sys->resources);
660 * xilinx_pcie_parse_and_add_res - Add resources by parsing ranges
661 * @port: PCIe port information
663 * Return: '0' on success and error value on failure
665 static int xilinx_pcie_parse_and_add_res(struct xilinx_pcie_port *port)
667 struct device *dev = port->dev;
668 struct device_node *node = dev->of_node;
669 struct resource *mem;
670 resource_size_t offset;
671 struct of_pci_range_parser parser;
672 struct of_pci_range range;
673 struct resource_entry *win;
674 int err = 0, mem_resno = 0;
677 if (of_pci_range_parser_init(&parser, node)) {
678 dev_err(dev, "missing \"ranges\" property\n");
682 /* Parse the ranges and add the resources found to the list */
683 for_each_of_pci_range(&parser, &range) {
685 if (mem_resno >= XILINX_MAX_NUM_RESOURCES) {
686 dev_err(dev, "Maximum memory resources exceeded\n");
690 mem = devm_kmalloc(dev, sizeof(*mem), GFP_KERNEL);
696 of_pci_range_to_resource(&range, node, mem);
698 switch (mem->flags & IORESOURCE_TYPE_BITS) {
700 offset = range.cpu_addr - range.pci_addr;
709 dev_warn(dev, "Invalid resource found %pR\n", mem);
713 err = request_resource(&iomem_resource, mem);
717 pci_add_resource_offset(&port->resources, mem, offset);
720 /* Get the bus range */
721 if (of_pci_parse_bus_range(node, &port->bus_range)) {
722 u32 val = pcie_read(port, XILINX_PCIE_REG_BIR);
725 last = (val & XILINX_PCIE_BIR_ECAM_SZ_MASK) >>
726 XILINX_PCIE_BIR_ECAM_SZ_SHIFT;
728 port->bus_range = (struct resource) {
732 .flags = IORESOURCE_BUS,
736 /* Register bus resource */
737 pci_add_resource(&port->resources, &port->bus_range);
742 release_child_resources(&iomem_resource);
743 resource_list_for_each_entry(win, &port->resources)
744 devm_kfree(dev, win->res);
745 pci_free_resource_list(&port->resources);
751 * xilinx_pcie_parse_dt - Parse Device tree
752 * @port: PCIe port information
754 * Return: '0' on success and error value on failure
756 static int xilinx_pcie_parse_dt(struct xilinx_pcie_port *port)
758 struct device *dev = port->dev;
759 struct device_node *node = dev->of_node;
760 struct resource regs;
764 type = of_get_property(node, "device_type", NULL);
765 if (!type || strcmp(type, "pci")) {
766 dev_err(dev, "invalid \"device_type\" %s\n", type);
770 err = of_address_to_resource(node, 0, ®s);
772 dev_err(dev, "missing \"reg\" property\n");
776 port->reg_base = devm_ioremap_resource(dev, ®s);
777 if (IS_ERR(port->reg_base))
778 return PTR_ERR(port->reg_base);
780 port->irq = irq_of_parse_and_map(node, 0);
781 err = devm_request_irq(dev, port->irq, xilinx_pcie_intr_handler,
782 IRQF_SHARED, "xilinx-pcie", port);
784 dev_err(dev, "unable to request irq %d\n", port->irq);
792 * xilinx_pcie_probe - Probe function
793 * @pdev: Platform device pointer
795 * Return: '0' on success and error value on failure
797 static int xilinx_pcie_probe(struct platform_device *pdev)
799 struct xilinx_pcie_port *port;
801 struct device *dev = &pdev->dev;
807 port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
813 err = xilinx_pcie_parse_dt(port);
815 dev_err(dev, "Parsing DT failed\n");
819 xilinx_pcie_init_port(port);
821 err = xilinx_pcie_init_irq_domain(port);
823 dev_err(dev, "Failed creating IRQ Domain\n");
828 * Parse PCI ranges, configuration bus range and
829 * request their resources
831 INIT_LIST_HEAD(&port->resources);
832 err = xilinx_pcie_parse_and_add_res(port);
834 dev_err(dev, "Failed adding resources\n");
838 platform_set_drvdata(pdev, port);
840 /* Register the device */
841 memset(&hw, 0, sizeof(hw));
842 hw = (struct hw_pci) {
844 .private_data = (void **)&port,
845 .setup = xilinx_pcie_setup,
846 .map_irq = of_irq_parse_and_map_pci,
847 .scan = xilinx_pcie_scan_bus,
848 .ops = &xilinx_pcie_ops,
851 #ifdef CONFIG_PCI_MSI
852 xilinx_pcie_msi_chip.dev = port->dev;
853 hw.msi_ctrl = &xilinx_pcie_msi_chip;
855 pci_common_init_dev(dev, &hw);
861 * xilinx_pcie_remove - Remove function
862 * @pdev: Platform device pointer
866 static int xilinx_pcie_remove(struct platform_device *pdev)
868 struct xilinx_pcie_port *port = platform_get_drvdata(pdev);
870 xilinx_pcie_free_irq_domain(port);
875 static struct of_device_id xilinx_pcie_of_match[] = {
876 { .compatible = "xlnx,axi-pcie-host-1.00.a", },
880 static struct platform_driver xilinx_pcie_driver = {
882 .name = "xilinx-pcie",
883 .of_match_table = xilinx_pcie_of_match,
884 .suppress_bind_attrs = true,
886 .probe = xilinx_pcie_probe,
887 .remove = xilinx_pcie_remove,
889 module_platform_driver(xilinx_pcie_driver);
891 MODULE_AUTHOR("Xilinx Inc");
892 MODULE_DESCRIPTION("Xilinx AXI PCIe driver");
893 MODULE_LICENSE("GPL v2");