]> Git Repo - linux.git/blob - drivers/pci/host/pcie-xilinx.c
mm: disable interrupts while initializing deferred pages
[linux.git] / drivers / pci / host / pcie-xilinx.c
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/irqdomain.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/msi.h>
19 #include <linux/of_address.h>
20 #include <linux/of_pci.h>
21 #include <linux/of_platform.h>
22 #include <linux/of_irq.h>
23 #include <linux/pci.h>
24 #include <linux/platform_device.h>
25
26 /* Register definitions */
27 #define XILINX_PCIE_REG_BIR             0x00000130
28 #define XILINX_PCIE_REG_IDR             0x00000138
29 #define XILINX_PCIE_REG_IMR             0x0000013c
30 #define XILINX_PCIE_REG_PSCR            0x00000144
31 #define XILINX_PCIE_REG_RPSC            0x00000148
32 #define XILINX_PCIE_REG_MSIBASE1        0x0000014c
33 #define XILINX_PCIE_REG_MSIBASE2        0x00000150
34 #define XILINX_PCIE_REG_RPEFR           0x00000154
35 #define XILINX_PCIE_REG_RPIFR1          0x00000158
36 #define XILINX_PCIE_REG_RPIFR2          0x0000015c
37
38 /* Interrupt registers definitions */
39 #define XILINX_PCIE_INTR_LINK_DOWN      BIT(0)
40 #define XILINX_PCIE_INTR_ECRC_ERR       BIT(1)
41 #define XILINX_PCIE_INTR_STR_ERR        BIT(2)
42 #define XILINX_PCIE_INTR_HOT_RESET      BIT(3)
43 #define XILINX_PCIE_INTR_CFG_TIMEOUT    BIT(8)
44 #define XILINX_PCIE_INTR_CORRECTABLE    BIT(9)
45 #define XILINX_PCIE_INTR_NONFATAL       BIT(10)
46 #define XILINX_PCIE_INTR_FATAL          BIT(11)
47 #define XILINX_PCIE_INTR_INTX           BIT(16)
48 #define XILINX_PCIE_INTR_MSI            BIT(17)
49 #define XILINX_PCIE_INTR_SLV_UNSUPP     BIT(20)
50 #define XILINX_PCIE_INTR_SLV_UNEXP      BIT(21)
51 #define XILINX_PCIE_INTR_SLV_COMPL      BIT(22)
52 #define XILINX_PCIE_INTR_SLV_ERRP       BIT(23)
53 #define XILINX_PCIE_INTR_SLV_CMPABT     BIT(24)
54 #define XILINX_PCIE_INTR_SLV_ILLBUR     BIT(25)
55 #define XILINX_PCIE_INTR_MST_DECERR     BIT(26)
56 #define XILINX_PCIE_INTR_MST_SLVERR     BIT(27)
57 #define XILINX_PCIE_INTR_MST_ERRP       BIT(28)
58 #define XILINX_PCIE_IMR_ALL_MASK        0x1FF30FED
59 #define XILINX_PCIE_IMR_ENABLE_MASK     0x1FF30F0D
60 #define XILINX_PCIE_IDR_ALL_MASK        0xFFFFFFFF
61
62 /* Root Port Error FIFO Read Register definitions */
63 #define XILINX_PCIE_RPEFR_ERR_VALID     BIT(18)
64 #define XILINX_PCIE_RPEFR_REQ_ID        GENMASK(15, 0)
65 #define XILINX_PCIE_RPEFR_ALL_MASK      0xFFFFFFFF
66
67 /* Root Port Interrupt FIFO Read Register 1 definitions */
68 #define XILINX_PCIE_RPIFR1_INTR_VALID   BIT(31)
69 #define XILINX_PCIE_RPIFR1_MSI_INTR     BIT(30)
70 #define XILINX_PCIE_RPIFR1_INTR_MASK    GENMASK(28, 27)
71 #define XILINX_PCIE_RPIFR1_ALL_MASK     0xFFFFFFFF
72 #define XILINX_PCIE_RPIFR1_INTR_SHIFT   27
73
74 /* Bridge Info Register definitions */
75 #define XILINX_PCIE_BIR_ECAM_SZ_MASK    GENMASK(18, 16)
76 #define XILINX_PCIE_BIR_ECAM_SZ_SHIFT   16
77
78 /* Root Port Interrupt FIFO Read Register 2 definitions */
79 #define XILINX_PCIE_RPIFR2_MSG_DATA     GENMASK(15, 0)
80
81 /* Root Port Status/control Register definitions */
82 #define XILINX_PCIE_REG_RPSC_BEN        BIT(0)
83
84 /* Phy Status/Control Register definitions */
85 #define XILINX_PCIE_REG_PSCR_LNKUP      BIT(11)
86
87 /* ECAM definitions */
88 #define ECAM_BUS_NUM_SHIFT              20
89 #define ECAM_DEV_NUM_SHIFT              12
90
91 /* Number of MSI IRQs */
92 #define XILINX_NUM_MSI_IRQS             128
93
94 /**
95  * struct xilinx_pcie_port - PCIe port information
96  * @reg_base: IO Mapped Register Base
97  * @irq: Interrupt number
98  * @msi_pages: MSI pages
99  * @root_busno: Root Bus number
100  * @dev: Device pointer
101  * @msi_domain: MSI IRQ domain pointer
102  * @leg_domain: Legacy IRQ domain pointer
103  * @resources: Bus Resources
104  */
105 struct xilinx_pcie_port {
106         void __iomem *reg_base;
107         u32 irq;
108         unsigned long msi_pages;
109         u8 root_busno;
110         struct device *dev;
111         struct irq_domain *msi_domain;
112         struct irq_domain *leg_domain;
113         struct list_head resources;
114 };
115
116 static DECLARE_BITMAP(msi_irq_in_use, XILINX_NUM_MSI_IRQS);
117
118 static inline u32 pcie_read(struct xilinx_pcie_port *port, u32 reg)
119 {
120         return readl(port->reg_base + reg);
121 }
122
123 static inline void pcie_write(struct xilinx_pcie_port *port, u32 val, u32 reg)
124 {
125         writel(val, port->reg_base + reg);
126 }
127
128 static inline bool xilinx_pcie_link_up(struct xilinx_pcie_port *port)
129 {
130         return (pcie_read(port, XILINX_PCIE_REG_PSCR) &
131                 XILINX_PCIE_REG_PSCR_LNKUP) ? 1 : 0;
132 }
133
134 /**
135  * xilinx_pcie_clear_err_interrupts - Clear Error Interrupts
136  * @port: PCIe port information
137  */
138 static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie_port *port)
139 {
140         struct device *dev = port->dev;
141         unsigned long val = pcie_read(port, XILINX_PCIE_REG_RPEFR);
142
143         if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
144                 dev_dbg(dev, "Requester ID %lu\n",
145                         val & XILINX_PCIE_RPEFR_REQ_ID);
146                 pcie_write(port, XILINX_PCIE_RPEFR_ALL_MASK,
147                            XILINX_PCIE_REG_RPEFR);
148         }
149 }
150
151 /**
152  * xilinx_pcie_valid_device - Check if a valid device is present on bus
153  * @bus: PCI Bus structure
154  * @devfn: device/function
155  *
156  * Return: 'true' on success and 'false' if invalid device is found
157  */
158 static bool xilinx_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
159 {
160         struct xilinx_pcie_port *port = bus->sysdata;
161
162         /* Check if link is up when trying to access downstream ports */
163         if (bus->number != port->root_busno)
164                 if (!xilinx_pcie_link_up(port))
165                         return false;
166
167         /* Only one device down on each root port */
168         if (bus->number == port->root_busno && devfn > 0)
169                 return false;
170
171         return true;
172 }
173
174 /**
175  * xilinx_pcie_map_bus - Get configuration base
176  * @bus: PCI Bus structure
177  * @devfn: Device/function
178  * @where: Offset from base
179  *
180  * Return: Base address of the configuration space needed to be
181  *         accessed.
182  */
183 static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
184                                          unsigned int devfn, int where)
185 {
186         struct xilinx_pcie_port *port = bus->sysdata;
187         int relbus;
188
189         if (!xilinx_pcie_valid_device(bus, devfn))
190                 return NULL;
191
192         relbus = (bus->number << ECAM_BUS_NUM_SHIFT) |
193                  (devfn << ECAM_DEV_NUM_SHIFT);
194
195         return port->reg_base + relbus + where;
196 }
197
198 /* PCIe operations */
199 static struct pci_ops xilinx_pcie_ops = {
200         .map_bus = xilinx_pcie_map_bus,
201         .read   = pci_generic_config_read,
202         .write  = pci_generic_config_write,
203 };
204
205 /* MSI functions */
206
207 /**
208  * xilinx_pcie_destroy_msi - Free MSI number
209  * @irq: IRQ to be freed
210  */
211 static void xilinx_pcie_destroy_msi(unsigned int irq)
212 {
213         struct msi_desc *msi;
214         struct xilinx_pcie_port *port;
215         struct irq_data *d = irq_get_irq_data(irq);
216         irq_hw_number_t hwirq = irqd_to_hwirq(d);
217
218         if (!test_bit(hwirq, msi_irq_in_use)) {
219                 msi = irq_get_msi_desc(irq);
220                 port = msi_desc_to_pci_sysdata(msi);
221                 dev_err(port->dev, "Trying to free unused MSI#%d\n", irq);
222         } else {
223                 clear_bit(hwirq, msi_irq_in_use);
224         }
225 }
226
227 /**
228  * xilinx_pcie_assign_msi - Allocate MSI number
229  *
230  * Return: A valid IRQ on success and error value on failure.
231  */
232 static int xilinx_pcie_assign_msi(void)
233 {
234         int pos;
235
236         pos = find_first_zero_bit(msi_irq_in_use, XILINX_NUM_MSI_IRQS);
237         if (pos < XILINX_NUM_MSI_IRQS)
238                 set_bit(pos, msi_irq_in_use);
239         else
240                 return -ENOSPC;
241
242         return pos;
243 }
244
245 /**
246  * xilinx_msi_teardown_irq - Destroy the MSI
247  * @chip: MSI Chip descriptor
248  * @irq: MSI IRQ to destroy
249  */
250 static void xilinx_msi_teardown_irq(struct msi_controller *chip,
251                                     unsigned int irq)
252 {
253         xilinx_pcie_destroy_msi(irq);
254         irq_dispose_mapping(irq);
255 }
256
257 /**
258  * xilinx_pcie_msi_setup_irq - Setup MSI request
259  * @chip: MSI chip pointer
260  * @pdev: PCIe device pointer
261  * @desc: MSI descriptor pointer
262  *
263  * Return: '0' on success and error value on failure
264  */
265 static int xilinx_pcie_msi_setup_irq(struct msi_controller *chip,
266                                      struct pci_dev *pdev,
267                                      struct msi_desc *desc)
268 {
269         struct xilinx_pcie_port *port = pdev->bus->sysdata;
270         unsigned int irq;
271         int hwirq;
272         struct msi_msg msg;
273         phys_addr_t msg_addr;
274
275         hwirq = xilinx_pcie_assign_msi();
276         if (hwirq < 0)
277                 return hwirq;
278
279         irq = irq_create_mapping(port->msi_domain, hwirq);
280         if (!irq)
281                 return -EINVAL;
282
283         irq_set_msi_desc(irq, desc);
284
285         msg_addr = virt_to_phys((void *)port->msi_pages);
286
287         msg.address_hi = 0;
288         msg.address_lo = msg_addr;
289         msg.data = irq;
290
291         pci_write_msi_msg(irq, &msg);
292
293         return 0;
294 }
295
296 /* MSI Chip Descriptor */
297 static struct msi_controller xilinx_pcie_msi_chip = {
298         .setup_irq = xilinx_pcie_msi_setup_irq,
299         .teardown_irq = xilinx_msi_teardown_irq,
300 };
301
302 /* HW Interrupt Chip Descriptor */
303 static struct irq_chip xilinx_msi_irq_chip = {
304         .name = "Xilinx PCIe MSI",
305         .irq_enable = pci_msi_unmask_irq,
306         .irq_disable = pci_msi_mask_irq,
307         .irq_mask = pci_msi_mask_irq,
308         .irq_unmask = pci_msi_unmask_irq,
309 };
310
311 /**
312  * xilinx_pcie_msi_map - Set the handler for the MSI and mark IRQ as valid
313  * @domain: IRQ domain
314  * @irq: Virtual IRQ number
315  * @hwirq: HW interrupt number
316  *
317  * Return: Always returns 0.
318  */
319 static int xilinx_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
320                                irq_hw_number_t hwirq)
321 {
322         irq_set_chip_and_handler(irq, &xilinx_msi_irq_chip, handle_simple_irq);
323         irq_set_chip_data(irq, domain->host_data);
324
325         return 0;
326 }
327
328 /* IRQ Domain operations */
329 static const struct irq_domain_ops msi_domain_ops = {
330         .map = xilinx_pcie_msi_map,
331 };
332
333 /**
334  * xilinx_pcie_enable_msi - Enable MSI support
335  * @port: PCIe port information
336  */
337 static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
338 {
339         phys_addr_t msg_addr;
340
341         port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
342         msg_addr = virt_to_phys((void *)port->msi_pages);
343         pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
344         pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
345 }
346
347 /* INTx Functions */
348
349 /**
350  * xilinx_pcie_intx_map - Set the handler for the INTx and mark IRQ as valid
351  * @domain: IRQ domain
352  * @irq: Virtual IRQ number
353  * @hwirq: HW interrupt number
354  *
355  * Return: Always returns 0.
356  */
357 static int xilinx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
358                                 irq_hw_number_t hwirq)
359 {
360         irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
361         irq_set_chip_data(irq, domain->host_data);
362
363         return 0;
364 }
365
366 /* INTx IRQ Domain operations */
367 static const struct irq_domain_ops intx_domain_ops = {
368         .map = xilinx_pcie_intx_map,
369         .xlate = pci_irqd_intx_xlate,
370 };
371
372 /* PCIe HW Functions */
373
374 /**
375  * xilinx_pcie_intr_handler - Interrupt Service Handler
376  * @irq: IRQ number
377  * @data: PCIe port information
378  *
379  * Return: IRQ_HANDLED on success and IRQ_NONE on failure
380  */
381 static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
382 {
383         struct xilinx_pcie_port *port = (struct xilinx_pcie_port *)data;
384         struct device *dev = port->dev;
385         u32 val, mask, status;
386
387         /* Read interrupt decode and mask registers */
388         val = pcie_read(port, XILINX_PCIE_REG_IDR);
389         mask = pcie_read(port, XILINX_PCIE_REG_IMR);
390
391         status = val & mask;
392         if (!status)
393                 return IRQ_NONE;
394
395         if (status & XILINX_PCIE_INTR_LINK_DOWN)
396                 dev_warn(dev, "Link Down\n");
397
398         if (status & XILINX_PCIE_INTR_ECRC_ERR)
399                 dev_warn(dev, "ECRC failed\n");
400
401         if (status & XILINX_PCIE_INTR_STR_ERR)
402                 dev_warn(dev, "Streaming error\n");
403
404         if (status & XILINX_PCIE_INTR_HOT_RESET)
405                 dev_info(dev, "Hot reset\n");
406
407         if (status & XILINX_PCIE_INTR_CFG_TIMEOUT)
408                 dev_warn(dev, "ECAM access timeout\n");
409
410         if (status & XILINX_PCIE_INTR_CORRECTABLE) {
411                 dev_warn(dev, "Correctable error message\n");
412                 xilinx_pcie_clear_err_interrupts(port);
413         }
414
415         if (status & XILINX_PCIE_INTR_NONFATAL) {
416                 dev_warn(dev, "Non fatal error message\n");
417                 xilinx_pcie_clear_err_interrupts(port);
418         }
419
420         if (status & XILINX_PCIE_INTR_FATAL) {
421                 dev_warn(dev, "Fatal error message\n");
422                 xilinx_pcie_clear_err_interrupts(port);
423         }
424
425         if (status & (XILINX_PCIE_INTR_INTX | XILINX_PCIE_INTR_MSI)) {
426                 val = pcie_read(port, XILINX_PCIE_REG_RPIFR1);
427
428                 /* Check whether interrupt valid */
429                 if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
430                         dev_warn(dev, "RP Intr FIFO1 read error\n");
431                         goto error;
432                 }
433
434                 /* Decode the IRQ number */
435                 if (val & XILINX_PCIE_RPIFR1_MSI_INTR) {
436                         val = pcie_read(port, XILINX_PCIE_REG_RPIFR2) &
437                                 XILINX_PCIE_RPIFR2_MSG_DATA;
438                 } else {
439                         val = (val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
440                                 XILINX_PCIE_RPIFR1_INTR_SHIFT;
441                         val = irq_find_mapping(port->leg_domain, val);
442                 }
443
444                 /* Clear interrupt FIFO register 1 */
445                 pcie_write(port, XILINX_PCIE_RPIFR1_ALL_MASK,
446                            XILINX_PCIE_REG_RPIFR1);
447
448                 /* Handle the interrupt */
449                 if (IS_ENABLED(CONFIG_PCI_MSI) ||
450                     !(val & XILINX_PCIE_RPIFR1_MSI_INTR))
451                         generic_handle_irq(val);
452         }
453
454         if (status & XILINX_PCIE_INTR_SLV_UNSUPP)
455                 dev_warn(dev, "Slave unsupported request\n");
456
457         if (status & XILINX_PCIE_INTR_SLV_UNEXP)
458                 dev_warn(dev, "Slave unexpected completion\n");
459
460         if (status & XILINX_PCIE_INTR_SLV_COMPL)
461                 dev_warn(dev, "Slave completion timeout\n");
462
463         if (status & XILINX_PCIE_INTR_SLV_ERRP)
464                 dev_warn(dev, "Slave Error Poison\n");
465
466         if (status & XILINX_PCIE_INTR_SLV_CMPABT)
467                 dev_warn(dev, "Slave Completer Abort\n");
468
469         if (status & XILINX_PCIE_INTR_SLV_ILLBUR)
470                 dev_warn(dev, "Slave Illegal Burst\n");
471
472         if (status & XILINX_PCIE_INTR_MST_DECERR)
473                 dev_warn(dev, "Master decode error\n");
474
475         if (status & XILINX_PCIE_INTR_MST_SLVERR)
476                 dev_warn(dev, "Master slave error\n");
477
478         if (status & XILINX_PCIE_INTR_MST_ERRP)
479                 dev_warn(dev, "Master error poison\n");
480
481 error:
482         /* Clear the Interrupt Decode register */
483         pcie_write(port, status, XILINX_PCIE_REG_IDR);
484
485         return IRQ_HANDLED;
486 }
487
488 /**
489  * xilinx_pcie_init_irq_domain - Initialize IRQ domain
490  * @port: PCIe port information
491  *
492  * Return: '0' on success and error value on failure
493  */
494 static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
495 {
496         struct device *dev = port->dev;
497         struct device_node *node = dev->of_node;
498         struct device_node *pcie_intc_node;
499
500         /* Setup INTx */
501         pcie_intc_node = of_get_next_child(node, NULL);
502         if (!pcie_intc_node) {
503                 dev_err(dev, "No PCIe Intc node found\n");
504                 return -ENODEV;
505         }
506
507         port->leg_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
508                                                  &intx_domain_ops,
509                                                  port);
510         if (!port->leg_domain) {
511                 dev_err(dev, "Failed to get a INTx IRQ domain\n");
512                 return -ENODEV;
513         }
514
515         /* Setup MSI */
516         if (IS_ENABLED(CONFIG_PCI_MSI)) {
517                 port->msi_domain = irq_domain_add_linear(node,
518                                                          XILINX_NUM_MSI_IRQS,
519                                                          &msi_domain_ops,
520                                                          &xilinx_pcie_msi_chip);
521                 if (!port->msi_domain) {
522                         dev_err(dev, "Failed to get a MSI IRQ domain\n");
523                         return -ENODEV;
524                 }
525
526                 xilinx_pcie_enable_msi(port);
527         }
528
529         return 0;
530 }
531
532 /**
533  * xilinx_pcie_init_port - Initialize hardware
534  * @port: PCIe port information
535  */
536 static void xilinx_pcie_init_port(struct xilinx_pcie_port *port)
537 {
538         struct device *dev = port->dev;
539
540         if (xilinx_pcie_link_up(port))
541                 dev_info(dev, "PCIe Link is UP\n");
542         else
543                 dev_info(dev, "PCIe Link is DOWN\n");
544
545         /* Disable all interrupts */
546         pcie_write(port, ~XILINX_PCIE_IDR_ALL_MASK,
547                    XILINX_PCIE_REG_IMR);
548
549         /* Clear pending interrupts */
550         pcie_write(port, pcie_read(port, XILINX_PCIE_REG_IDR) &
551                          XILINX_PCIE_IMR_ALL_MASK,
552                    XILINX_PCIE_REG_IDR);
553
554         /* Enable all interrupts we handle */
555         pcie_write(port, XILINX_PCIE_IMR_ENABLE_MASK, XILINX_PCIE_REG_IMR);
556
557         /* Enable the Bridge enable bit */
558         pcie_write(port, pcie_read(port, XILINX_PCIE_REG_RPSC) |
559                          XILINX_PCIE_REG_RPSC_BEN,
560                    XILINX_PCIE_REG_RPSC);
561 }
562
563 /**
564  * xilinx_pcie_parse_dt - Parse Device tree
565  * @port: PCIe port information
566  *
567  * Return: '0' on success and error value on failure
568  */
569 static int xilinx_pcie_parse_dt(struct xilinx_pcie_port *port)
570 {
571         struct device *dev = port->dev;
572         struct device_node *node = dev->of_node;
573         struct resource regs;
574         const char *type;
575         int err;
576
577         type = of_get_property(node, "device_type", NULL);
578         if (!type || strcmp(type, "pci")) {
579                 dev_err(dev, "invalid \"device_type\" %s\n", type);
580                 return -EINVAL;
581         }
582
583         err = of_address_to_resource(node, 0, &regs);
584         if (err) {
585                 dev_err(dev, "missing \"reg\" property\n");
586                 return err;
587         }
588
589         port->reg_base = devm_pci_remap_cfg_resource(dev, &regs);
590         if (IS_ERR(port->reg_base))
591                 return PTR_ERR(port->reg_base);
592
593         port->irq = irq_of_parse_and_map(node, 0);
594         err = devm_request_irq(dev, port->irq, xilinx_pcie_intr_handler,
595                                IRQF_SHARED | IRQF_NO_THREAD,
596                                "xilinx-pcie", port);
597         if (err) {
598                 dev_err(dev, "unable to request irq %d\n", port->irq);
599                 return err;
600         }
601
602         return 0;
603 }
604
605 /**
606  * xilinx_pcie_probe - Probe function
607  * @pdev: Platform device pointer
608  *
609  * Return: '0' on success and error value on failure
610  */
611 static int xilinx_pcie_probe(struct platform_device *pdev)
612 {
613         struct device *dev = &pdev->dev;
614         struct xilinx_pcie_port *port;
615         struct pci_bus *bus, *child;
616         struct pci_host_bridge *bridge;
617         int err;
618         resource_size_t iobase = 0;
619         LIST_HEAD(res);
620
621         if (!dev->of_node)
622                 return -ENODEV;
623
624         bridge = devm_pci_alloc_host_bridge(dev, sizeof(*port));
625         if (!bridge)
626                 return -ENODEV;
627
628         port = pci_host_bridge_priv(bridge);
629
630         port->dev = dev;
631
632         err = xilinx_pcie_parse_dt(port);
633         if (err) {
634                 dev_err(dev, "Parsing DT failed\n");
635                 return err;
636         }
637
638         xilinx_pcie_init_port(port);
639
640         err = xilinx_pcie_init_irq_domain(port);
641         if (err) {
642                 dev_err(dev, "Failed creating IRQ Domain\n");
643                 return err;
644         }
645
646         err = of_pci_get_host_bridge_resources(dev->of_node, 0, 0xff, &res,
647                                                &iobase);
648         if (err) {
649                 dev_err(dev, "Getting bridge resources failed\n");
650                 return err;
651         }
652
653         err = devm_request_pci_bus_resources(dev, &res);
654         if (err)
655                 goto error;
656
657
658         list_splice_init(&res, &bridge->windows);
659         bridge->dev.parent = dev;
660         bridge->sysdata = port;
661         bridge->busnr = 0;
662         bridge->ops = &xilinx_pcie_ops;
663         bridge->map_irq = of_irq_parse_and_map_pci;
664         bridge->swizzle_irq = pci_common_swizzle;
665
666 #ifdef CONFIG_PCI_MSI
667         xilinx_pcie_msi_chip.dev = dev;
668         bridge->msi = &xilinx_pcie_msi_chip;
669 #endif
670         err = pci_scan_root_bus_bridge(bridge);
671         if (err < 0)
672                 goto error;
673
674         bus = bridge->bus;
675
676         pci_assign_unassigned_bus_resources(bus);
677         list_for_each_entry(child, &bus->children, node)
678                 pcie_bus_configure_settings(child);
679         pci_bus_add_devices(bus);
680         return 0;
681
682 error:
683         pci_free_resource_list(&res);
684         return err;
685 }
686
687 static const struct of_device_id xilinx_pcie_of_match[] = {
688         { .compatible = "xlnx,axi-pcie-host-1.00.a", },
689         {}
690 };
691
692 static struct platform_driver xilinx_pcie_driver = {
693         .driver = {
694                 .name = "xilinx-pcie",
695                 .of_match_table = xilinx_pcie_of_match,
696                 .suppress_bind_attrs = true,
697         },
698         .probe = xilinx_pcie_probe,
699 };
700 builtin_platform_driver(xilinx_pcie_driver);
This page took 0.073835 seconds and 4 git commands to generate.