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