1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/misc/xillybus_pcie.c
5 * Copyright 2011 Xillybus Ltd, http://xillybus.com
7 * Driver for the Xillybus FPGA/host framework using PCI Express.
10 #include <linux/module.h>
11 #include <linux/pci.h>
12 #include <linux/slab.h>
15 MODULE_DESCRIPTION("Xillybus driver for PCIe");
16 MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
17 MODULE_ALIAS("xillybus_pcie");
18 MODULE_LICENSE("GPL v2");
20 #define PCI_DEVICE_ID_XILLYBUS 0xebeb
22 #define PCI_VENDOR_ID_ACTEL 0x11aa
23 #define PCI_VENDOR_ID_LATTICE 0x1204
25 static const char xillyname
[] = "xillybus_pcie";
27 static const struct pci_device_id xillyids
[] = {
28 {PCI_DEVICE(PCI_VENDOR_ID_XILINX
, PCI_DEVICE_ID_XILLYBUS
)},
29 {PCI_DEVICE(PCI_VENDOR_ID_ALTERA
, PCI_DEVICE_ID_XILLYBUS
)},
30 {PCI_DEVICE(PCI_VENDOR_ID_ACTEL
, PCI_DEVICE_ID_XILLYBUS
)},
31 {PCI_DEVICE(PCI_VENDOR_ID_LATTICE
, PCI_DEVICE_ID_XILLYBUS
)},
32 { /* End: all zeroes */ }
35 static int xilly_probe(struct pci_dev
*pdev
,
36 const struct pci_device_id
*ent
)
38 struct xilly_endpoint
*endpoint
;
41 endpoint
= xillybus_init_endpoint(&pdev
->dev
);
46 pci_set_drvdata(pdev
, endpoint
);
48 endpoint
->owner
= THIS_MODULE
;
50 rc
= pcim_enable_device(pdev
);
52 dev_err(endpoint
->dev
,
53 "pcim_enable_device() failed. Aborting.\n");
57 /* L0s has caused packet drops. No power saving, thank you. */
59 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
);
61 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
62 dev_err(endpoint
->dev
,
63 "Incorrect BAR configuration. Aborting.\n");
67 rc
= pcim_iomap_regions(pdev
, 0x01, xillyname
);
69 dev_err(endpoint
->dev
,
70 "pcim_iomap_regions() failed. Aborting.\n");
74 endpoint
->registers
= pcim_iomap_table(pdev
)[0];
78 /* Set up a single MSI interrupt */
79 if (pci_enable_msi(pdev
)) {
80 dev_err(endpoint
->dev
,
81 "Failed to enable MSI interrupts. Aborting.\n");
84 rc
= devm_request_irq(&pdev
->dev
, pdev
->irq
, xillybus_isr
, 0,
87 dev_err(endpoint
->dev
,
88 "Failed to register MSI handler. Aborting.\n");
93 * Some (old and buggy?) hardware drops 64-bit addressed PCIe packets,
94 * even when the PCIe driver claims that a 64-bit mask is OK. On the
95 * other hand, on some architectures, 64-bit addressing is mandatory.
96 * So go for the 64-bit mask only when failing is the other option.
99 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32))) {
100 endpoint
->dma_using_dac
= 0;
101 } else if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
102 endpoint
->dma_using_dac
= 1;
104 dev_err(endpoint
->dev
, "Failed to set DMA mask. Aborting.\n");
108 return xillybus_endpoint_discovery(endpoint
);
111 static void xilly_remove(struct pci_dev
*pdev
)
113 struct xilly_endpoint
*endpoint
= pci_get_drvdata(pdev
);
115 xillybus_endpoint_remove(endpoint
);
118 MODULE_DEVICE_TABLE(pci
, xillyids
);
120 static struct pci_driver xillybus_driver
= {
122 .id_table
= xillyids
,
123 .probe
= xilly_probe
,
124 .remove
= xilly_remove
,
127 module_pci_driver(xillybus_driver
);