lightnvm: NVM should depend on HAS_DMA
[deliverable/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/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>
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_IDR_ALL_MASK 0xFFFFFFFF
64
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
69
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
76
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
80
81 /* Root Port Interrupt FIFO Read Register 2 definitions */
82 #define XILINX_PCIE_RPIFR2_MSG_DATA GENMASK(15, 0)
83
84 /* Root Port Status/control Register definitions */
85 #define XILINX_PCIE_REG_RPSC_BEN BIT(0)
86
87 /* Phy Status/Control Register definitions */
88 #define XILINX_PCIE_REG_PSCR_LNKUP BIT(11)
89
90 /* ECAM definitions */
91 #define ECAM_BUS_NUM_SHIFT 20
92 #define ECAM_DEV_NUM_SHIFT 12
93
94 /* Number of MSI IRQs */
95 #define XILINX_NUM_MSI_IRQS 128
96
97 /**
98 * struct xilinx_pcie_port - PCIe port information
99 * @reg_base: IO Mapped Register Base
100 * @irq: Interrupt number
101 * @msi_pages: MSI pages
102 * @root_busno: Root Bus number
103 * @dev: Device pointer
104 * @irq_domain: IRQ domain pointer
105 * @resources: Bus Resources
106 */
107 struct xilinx_pcie_port {
108 void __iomem *reg_base;
109 u32 irq;
110 unsigned long msi_pages;
111 u8 root_busno;
112 struct device *dev;
113 struct irq_domain *irq_domain;
114 struct list_head resources;
115 };
116
117 static DECLARE_BITMAP(msi_irq_in_use, XILINX_NUM_MSI_IRQS);
118
119 static inline u32 pcie_read(struct xilinx_pcie_port *port, u32 reg)
120 {
121 return readl(port->reg_base + reg);
122 }
123
124 static inline void pcie_write(struct xilinx_pcie_port *port, u32 val, u32 reg)
125 {
126 writel(val, port->reg_base + reg);
127 }
128
129 static inline bool xilinx_pcie_link_is_up(struct xilinx_pcie_port *port)
130 {
131 return (pcie_read(port, XILINX_PCIE_REG_PSCR) &
132 XILINX_PCIE_REG_PSCR_LNKUP) ? 1 : 0;
133 }
134
135 /**
136 * xilinx_pcie_clear_err_interrupts - Clear Error Interrupts
137 * @port: PCIe port information
138 */
139 static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie_port *port)
140 {
141 unsigned long val = pcie_read(port, XILINX_PCIE_REG_RPEFR);
142
143 if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
144 dev_dbg(port->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_is_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 /*
172 * Do not read more than one device on the bus directly attached
173 * to RC.
174 */
175 if (bus->primary == port->root_busno && devfn > 0)
176 return false;
177
178 return true;
179 }
180
181 /**
182 * xilinx_pcie_map_bus - Get configuration base
183 * @bus: PCI Bus structure
184 * @devfn: Device/function
185 * @where: Offset from base
186 *
187 * Return: Base address of the configuration space needed to be
188 * accessed.
189 */
190 static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
191 unsigned int devfn, int where)
192 {
193 struct xilinx_pcie_port *port = bus->sysdata;
194 int relbus;
195
196 if (!xilinx_pcie_valid_device(bus, devfn))
197 return NULL;
198
199 relbus = (bus->number << ECAM_BUS_NUM_SHIFT) |
200 (devfn << ECAM_DEV_NUM_SHIFT);
201
202 return port->reg_base + relbus + where;
203 }
204
205 /* PCIe operations */
206 static struct pci_ops xilinx_pcie_ops = {
207 .map_bus = xilinx_pcie_map_bus,
208 .read = pci_generic_config_read,
209 .write = pci_generic_config_write,
210 };
211
212 /* MSI functions */
213
214 /**
215 * xilinx_pcie_destroy_msi - Free MSI number
216 * @irq: IRQ to be freed
217 */
218 static void xilinx_pcie_destroy_msi(unsigned int irq)
219 {
220 struct msi_desc *msi;
221 struct xilinx_pcie_port *port;
222
223 if (!test_bit(irq, msi_irq_in_use)) {
224 msi = irq_get_msi_desc(irq);
225 port = msi_desc_to_pci_sysdata(msi);
226 dev_err(port->dev, "Trying to free unused MSI#%d\n", irq);
227 } else {
228 clear_bit(irq, msi_irq_in_use);
229 }
230 }
231
232 /**
233 * xilinx_pcie_assign_msi - Allocate MSI number
234 * @port: PCIe port structure
235 *
236 * Return: A valid IRQ on success and error value on failure.
237 */
238 static int xilinx_pcie_assign_msi(struct xilinx_pcie_port *port)
239 {
240 int pos;
241
242 pos = find_first_zero_bit(msi_irq_in_use, XILINX_NUM_MSI_IRQS);
243 if (pos < XILINX_NUM_MSI_IRQS)
244 set_bit(pos, msi_irq_in_use);
245 else
246 return -ENOSPC;
247
248 return pos;
249 }
250
251 /**
252 * xilinx_msi_teardown_irq - Destroy the MSI
253 * @chip: MSI Chip descriptor
254 * @irq: MSI IRQ to destroy
255 */
256 static void xilinx_msi_teardown_irq(struct msi_controller *chip,
257 unsigned int irq)
258 {
259 xilinx_pcie_destroy_msi(irq);
260 }
261
262 /**
263 * xilinx_pcie_msi_setup_irq - Setup MSI request
264 * @chip: MSI chip pointer
265 * @pdev: PCIe device pointer
266 * @desc: MSI descriptor pointer
267 *
268 * Return: '0' on success and error value on failure
269 */
270 static int xilinx_pcie_msi_setup_irq(struct msi_controller *chip,
271 struct pci_dev *pdev,
272 struct msi_desc *desc)
273 {
274 struct xilinx_pcie_port *port = pdev->bus->sysdata;
275 unsigned int irq;
276 int hwirq;
277 struct msi_msg msg;
278 phys_addr_t msg_addr;
279
280 hwirq = xilinx_pcie_assign_msi(port);
281 if (hwirq < 0)
282 return hwirq;
283
284 irq = irq_create_mapping(port->irq_domain, hwirq);
285 if (!irq)
286 return -EINVAL;
287
288 irq_set_msi_desc(irq, desc);
289
290 msg_addr = virt_to_phys((void *)port->msi_pages);
291
292 msg.address_hi = 0;
293 msg.address_lo = msg_addr;
294 msg.data = irq;
295
296 pci_write_msi_msg(irq, &msg);
297
298 return 0;
299 }
300
301 /* MSI Chip Descriptor */
302 static struct msi_controller xilinx_pcie_msi_chip = {
303 .setup_irq = xilinx_pcie_msi_setup_irq,
304 .teardown_irq = xilinx_msi_teardown_irq,
305 };
306
307 /* HW Interrupt Chip Descriptor */
308 static struct irq_chip xilinx_msi_irq_chip = {
309 .name = "Xilinx PCIe MSI",
310 .irq_enable = pci_msi_unmask_irq,
311 .irq_disable = pci_msi_mask_irq,
312 .irq_mask = pci_msi_mask_irq,
313 .irq_unmask = pci_msi_unmask_irq,
314 };
315
316 /**
317 * xilinx_pcie_msi_map - Set the handler for the MSI and mark IRQ as valid
318 * @domain: IRQ domain
319 * @irq: Virtual IRQ number
320 * @hwirq: HW interrupt number
321 *
322 * Return: Always returns 0.
323 */
324 static int xilinx_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
325 irq_hw_number_t hwirq)
326 {
327 irq_set_chip_and_handler(irq, &xilinx_msi_irq_chip, handle_simple_irq);
328 irq_set_chip_data(irq, domain->host_data);
329
330 return 0;
331 }
332
333 /* IRQ Domain operations */
334 static const struct irq_domain_ops msi_domain_ops = {
335 .map = xilinx_pcie_msi_map,
336 };
337
338 /**
339 * xilinx_pcie_enable_msi - Enable MSI support
340 * @port: PCIe port information
341 */
342 static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
343 {
344 phys_addr_t msg_addr;
345
346 port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
347 msg_addr = virt_to_phys((void *)port->msi_pages);
348 pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
349 pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
350 }
351
352 /* INTx Functions */
353
354 /**
355 * xilinx_pcie_intx_map - Set the handler for the INTx and mark IRQ as valid
356 * @domain: IRQ domain
357 * @irq: Virtual IRQ number
358 * @hwirq: HW interrupt number
359 *
360 * Return: Always returns 0.
361 */
362 static int xilinx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
363 irq_hw_number_t hwirq)
364 {
365 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
366 irq_set_chip_data(irq, domain->host_data);
367
368 return 0;
369 }
370
371 /* INTx IRQ Domain operations */
372 static const struct irq_domain_ops intx_domain_ops = {
373 .map = xilinx_pcie_intx_map,
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 u32 val, mask, status, msi_data;
389
390 /* Read interrupt decode and mask registers */
391 val = pcie_read(port, XILINX_PCIE_REG_IDR);
392 mask = pcie_read(port, XILINX_PCIE_REG_IMR);
393
394 status = val & mask;
395 if (!status)
396 return IRQ_NONE;
397
398 if (status & XILINX_PCIE_INTR_LINK_DOWN)
399 dev_warn(port->dev, "Link Down\n");
400
401 if (status & XILINX_PCIE_INTR_ECRC_ERR)
402 dev_warn(port->dev, "ECRC failed\n");
403
404 if (status & XILINX_PCIE_INTR_STR_ERR)
405 dev_warn(port->dev, "Streaming error\n");
406
407 if (status & XILINX_PCIE_INTR_HOT_RESET)
408 dev_info(port->dev, "Hot reset\n");
409
410 if (status & XILINX_PCIE_INTR_CFG_TIMEOUT)
411 dev_warn(port->dev, "ECAM access timeout\n");
412
413 if (status & XILINX_PCIE_INTR_CORRECTABLE) {
414 dev_warn(port->dev, "Correctable error message\n");
415 xilinx_pcie_clear_err_interrupts(port);
416 }
417
418 if (status & XILINX_PCIE_INTR_NONFATAL) {
419 dev_warn(port->dev, "Non fatal error message\n");
420 xilinx_pcie_clear_err_interrupts(port);
421 }
422
423 if (status & XILINX_PCIE_INTR_FATAL) {
424 dev_warn(port->dev, "Fatal error message\n");
425 xilinx_pcie_clear_err_interrupts(port);
426 }
427
428 if (status & XILINX_PCIE_INTR_INTX) {
429 /* INTx interrupt received */
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(port->dev, "RP Intr FIFO1 read error\n");
435 return IRQ_HANDLED;
436 }
437
438 if (!(val & XILINX_PCIE_RPIFR1_MSI_INTR)) {
439 /* Clear interrupt FIFO register 1 */
440 pcie_write(port, XILINX_PCIE_RPIFR1_ALL_MASK,
441 XILINX_PCIE_REG_RPIFR1);
442
443 /* Handle INTx Interrupt */
444 val = ((val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
445 XILINX_PCIE_RPIFR1_INTR_SHIFT) + 1;
446 generic_handle_irq(irq_find_mapping(port->irq_domain,
447 val));
448 }
449 }
450
451 if (status & XILINX_PCIE_INTR_MSI) {
452 /* MSI Interrupt */
453 val = pcie_read(port, XILINX_PCIE_REG_RPIFR1);
454
455 if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
456 dev_warn(port->dev, "RP Intr FIFO1 read error\n");
457 return IRQ_HANDLED;
458 }
459
460 if (val & XILINX_PCIE_RPIFR1_MSI_INTR) {
461 msi_data = pcie_read(port, XILINX_PCIE_REG_RPIFR2) &
462 XILINX_PCIE_RPIFR2_MSG_DATA;
463
464 /* Clear interrupt FIFO register 1 */
465 pcie_write(port, XILINX_PCIE_RPIFR1_ALL_MASK,
466 XILINX_PCIE_REG_RPIFR1);
467
468 if (IS_ENABLED(CONFIG_PCI_MSI)) {
469 /* Handle MSI Interrupt */
470 generic_handle_irq(msi_data);
471 }
472 }
473 }
474
475 if (status & XILINX_PCIE_INTR_SLV_UNSUPP)
476 dev_warn(port->dev, "Slave unsupported request\n");
477
478 if (status & XILINX_PCIE_INTR_SLV_UNEXP)
479 dev_warn(port->dev, "Slave unexpected completion\n");
480
481 if (status & XILINX_PCIE_INTR_SLV_COMPL)
482 dev_warn(port->dev, "Slave completion timeout\n");
483
484 if (status & XILINX_PCIE_INTR_SLV_ERRP)
485 dev_warn(port->dev, "Slave Error Poison\n");
486
487 if (status & XILINX_PCIE_INTR_SLV_CMPABT)
488 dev_warn(port->dev, "Slave Completer Abort\n");
489
490 if (status & XILINX_PCIE_INTR_SLV_ILLBUR)
491 dev_warn(port->dev, "Slave Illegal Burst\n");
492
493 if (status & XILINX_PCIE_INTR_MST_DECERR)
494 dev_warn(port->dev, "Master decode error\n");
495
496 if (status & XILINX_PCIE_INTR_MST_SLVERR)
497 dev_warn(port->dev, "Master slave error\n");
498
499 if (status & XILINX_PCIE_INTR_MST_ERRP)
500 dev_warn(port->dev, "Master error poison\n");
501
502 /* Clear the Interrupt Decode register */
503 pcie_write(port, status, XILINX_PCIE_REG_IDR);
504
505 return IRQ_HANDLED;
506 }
507
508 /**
509 * xilinx_pcie_free_irq_domain - Free IRQ domain
510 * @port: PCIe port information
511 */
512 static void xilinx_pcie_free_irq_domain(struct xilinx_pcie_port *port)
513 {
514 int i;
515 u32 irq, num_irqs;
516
517 /* Free IRQ Domain */
518 if (IS_ENABLED(CONFIG_PCI_MSI)) {
519
520 free_pages(port->msi_pages, 0);
521
522 num_irqs = XILINX_NUM_MSI_IRQS;
523 } else {
524 /* INTx */
525 num_irqs = 4;
526 }
527
528 for (i = 0; i < num_irqs; i++) {
529 irq = irq_find_mapping(port->irq_domain, i);
530 if (irq > 0)
531 irq_dispose_mapping(irq);
532 }
533
534 irq_domain_remove(port->irq_domain);
535 }
536
537 /**
538 * xilinx_pcie_init_irq_domain - Initialize IRQ domain
539 * @port: PCIe port information
540 *
541 * Return: '0' on success and error value on failure
542 */
543 static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
544 {
545 struct device *dev = port->dev;
546 struct device_node *node = dev->of_node;
547 struct device_node *pcie_intc_node;
548
549 /* Setup INTx */
550 pcie_intc_node = of_get_next_child(node, NULL);
551 if (!pcie_intc_node) {
552 dev_err(dev, "No PCIe Intc node found\n");
553 return -ENODEV;
554 }
555
556 port->irq_domain = irq_domain_add_linear(pcie_intc_node, 4,
557 &intx_domain_ops,
558 port);
559 if (!port->irq_domain) {
560 dev_err(dev, "Failed to get a INTx IRQ domain\n");
561 return -ENODEV;
562 }
563
564 /* Setup MSI */
565 if (IS_ENABLED(CONFIG_PCI_MSI)) {
566 port->irq_domain = irq_domain_add_linear(node,
567 XILINX_NUM_MSI_IRQS,
568 &msi_domain_ops,
569 &xilinx_pcie_msi_chip);
570 if (!port->irq_domain) {
571 dev_err(dev, "Failed to get a MSI IRQ domain\n");
572 return -ENODEV;
573 }
574
575 xilinx_pcie_enable_msi(port);
576 }
577
578 return 0;
579 }
580
581 /**
582 * xilinx_pcie_init_port - Initialize hardware
583 * @port: PCIe port information
584 */
585 static void xilinx_pcie_init_port(struct xilinx_pcie_port *port)
586 {
587 if (xilinx_pcie_link_is_up(port))
588 dev_info(port->dev, "PCIe Link is UP\n");
589 else
590 dev_info(port->dev, "PCIe Link is DOWN\n");
591
592 /* Disable all interrupts */
593 pcie_write(port, ~XILINX_PCIE_IDR_ALL_MASK,
594 XILINX_PCIE_REG_IMR);
595
596 /* Clear pending interrupts */
597 pcie_write(port, pcie_read(port, XILINX_PCIE_REG_IDR) &
598 XILINX_PCIE_IMR_ALL_MASK,
599 XILINX_PCIE_REG_IDR);
600
601 /* Enable all interrupts */
602 pcie_write(port, XILINX_PCIE_IMR_ALL_MASK, XILINX_PCIE_REG_IMR);
603
604 /* Enable the Bridge enable bit */
605 pcie_write(port, pcie_read(port, XILINX_PCIE_REG_RPSC) |
606 XILINX_PCIE_REG_RPSC_BEN,
607 XILINX_PCIE_REG_RPSC);
608 }
609
610 /**
611 * xilinx_pcie_parse_dt - Parse Device tree
612 * @port: PCIe port information
613 *
614 * Return: '0' on success and error value on failure
615 */
616 static int xilinx_pcie_parse_dt(struct xilinx_pcie_port *port)
617 {
618 struct device *dev = port->dev;
619 struct device_node *node = dev->of_node;
620 struct resource regs;
621 const char *type;
622 int err;
623
624 type = of_get_property(node, "device_type", NULL);
625 if (!type || strcmp(type, "pci")) {
626 dev_err(dev, "invalid \"device_type\" %s\n", type);
627 return -EINVAL;
628 }
629
630 err = of_address_to_resource(node, 0, &regs);
631 if (err) {
632 dev_err(dev, "missing \"reg\" property\n");
633 return err;
634 }
635
636 port->reg_base = devm_ioremap_resource(dev, &regs);
637 if (IS_ERR(port->reg_base))
638 return PTR_ERR(port->reg_base);
639
640 port->irq = irq_of_parse_and_map(node, 0);
641 err = devm_request_irq(dev, port->irq, xilinx_pcie_intr_handler,
642 IRQF_SHARED | IRQF_NO_THREAD,
643 "xilinx-pcie", port);
644 if (err) {
645 dev_err(dev, "unable to request irq %d\n", port->irq);
646 return err;
647 }
648
649 return 0;
650 }
651
652 /**
653 * xilinx_pcie_probe - Probe function
654 * @pdev: Platform device pointer
655 *
656 * Return: '0' on success and error value on failure
657 */
658 static int xilinx_pcie_probe(struct platform_device *pdev)
659 {
660 struct xilinx_pcie_port *port;
661 struct device *dev = &pdev->dev;
662 struct pci_bus *bus;
663 int err;
664 resource_size_t iobase = 0;
665 LIST_HEAD(res);
666
667 if (!dev->of_node)
668 return -ENODEV;
669
670 port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
671 if (!port)
672 return -ENOMEM;
673
674 port->dev = dev;
675
676 err = xilinx_pcie_parse_dt(port);
677 if (err) {
678 dev_err(dev, "Parsing DT failed\n");
679 return err;
680 }
681
682 xilinx_pcie_init_port(port);
683
684 err = xilinx_pcie_init_irq_domain(port);
685 if (err) {
686 dev_err(dev, "Failed creating IRQ Domain\n");
687 return err;
688 }
689
690 err = of_pci_get_host_bridge_resources(dev->of_node, 0, 0xff, &res,
691 &iobase);
692 if (err) {
693 dev_err(dev, "Getting bridge resources failed\n");
694 return err;
695 }
696
697 err = devm_request_pci_bus_resources(dev, &res);
698 if (err)
699 goto error;
700
701 bus = pci_create_root_bus(&pdev->dev, 0,
702 &xilinx_pcie_ops, port, &res);
703 if (!bus) {
704 err = -ENOMEM;
705 goto error;
706 }
707
708 #ifdef CONFIG_PCI_MSI
709 xilinx_pcie_msi_chip.dev = port->dev;
710 bus->msi = &xilinx_pcie_msi_chip;
711 #endif
712 pci_scan_child_bus(bus);
713 pci_assign_unassigned_bus_resources(bus);
714 #ifndef CONFIG_MICROBLAZE
715 pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
716 #endif
717 pci_bus_add_devices(bus);
718 platform_set_drvdata(pdev, port);
719
720 return 0;
721
722 error:
723 pci_free_resource_list(&res);
724 return err;
725 }
726
727 /**
728 * xilinx_pcie_remove - Remove function
729 * @pdev: Platform device pointer
730 *
731 * Return: '0' always
732 */
733 static int xilinx_pcie_remove(struct platform_device *pdev)
734 {
735 struct xilinx_pcie_port *port = platform_get_drvdata(pdev);
736
737 xilinx_pcie_free_irq_domain(port);
738
739 return 0;
740 }
741
742 static struct of_device_id xilinx_pcie_of_match[] = {
743 { .compatible = "xlnx,axi-pcie-host-1.00.a", },
744 {}
745 };
746
747 static struct platform_driver xilinx_pcie_driver = {
748 .driver = {
749 .name = "xilinx-pcie",
750 .of_match_table = xilinx_pcie_of_match,
751 .suppress_bind_attrs = true,
752 },
753 .probe = xilinx_pcie_probe,
754 .remove = xilinx_pcie_remove,
755 };
756 module_platform_driver(xilinx_pcie_driver);
757
758 MODULE_AUTHOR("Xilinx Inc");
759 MODULE_DESCRIPTION("Xilinx AXI PCIe driver");
760 MODULE_LICENSE("GPL v2");
This page took 0.059804 seconds and 5 git commands to generate.