Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / char / xillybus / xillybus_pcie.c
blob9858711e3e79a0e899d5bec8e672e454a487957c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
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.
8 */
10 #include <linux/module.h>
11 #include <linux/pci.h>
12 #include <linux/slab.h>
13 #include "xillybus.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;
39 int rc;
41 endpoint = xillybus_init_endpoint(&pdev->dev);
43 if (!endpoint)
44 return -ENOMEM;
46 pci_set_drvdata(pdev, endpoint);
48 endpoint->owner = THIS_MODULE;
50 rc = pcim_enable_device(pdev);
51 if (rc) {
52 dev_err(endpoint->dev,
53 "pcim_enable_device() failed. Aborting.\n");
54 return rc;
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");
64 return -ENODEV;
67 rc = pcim_iomap_regions(pdev, 0x01, xillyname);
68 if (rc) {
69 dev_err(endpoint->dev,
70 "pcim_iomap_regions() failed. Aborting.\n");
71 return rc;
74 endpoint->registers = pcim_iomap_table(pdev)[0];
76 pci_set_master(pdev);
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");
82 return -ENODEV;
84 rc = devm_request_irq(&pdev->dev, pdev->irq, xillybus_isr, 0,
85 xillyname, endpoint);
86 if (rc) {
87 dev_err(endpoint->dev,
88 "Failed to register MSI handler. Aborting.\n");
89 return -ENODEV;
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;
103 } else {
104 dev_err(endpoint->dev, "Failed to set DMA mask. Aborting.\n");
105 return -ENODEV;
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 = {
121 .name = xillyname,
122 .id_table = xillyids,
123 .probe = xilly_probe,
124 .remove = xilly_remove,
127 module_pci_driver(xillybus_driver);