1 // SPDX-License-Identifier: GPL-2.0-only
3 * Host side test driver to test endpoint functionality
5 * Copyright (C) 2017 Texas Instruments
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
9 #include <linux/crc32.h>
10 #include <linux/delay.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/miscdevice.h>
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/random.h>
19 #include <linux/slab.h>
20 #include <linux/uaccess.h>
21 #include <linux/pci.h>
22 #include <linux/pci_ids.h>
24 #include <linux/pci_regs.h>
26 #include <uapi/linux/pcitest.h>
28 #define DRV_MODULE_NAME "pci-endpoint-test"
30 #define IRQ_TYPE_UNDEFINED -1
31 #define IRQ_TYPE_LEGACY 0
32 #define IRQ_TYPE_MSI 1
33 #define IRQ_TYPE_MSIX 2
35 #define PCI_ENDPOINT_TEST_MAGIC 0x0
37 #define PCI_ENDPOINT_TEST_COMMAND 0x4
38 #define COMMAND_RAISE_LEGACY_IRQ BIT(0)
39 #define COMMAND_RAISE_MSI_IRQ BIT(1)
40 #define COMMAND_RAISE_MSIX_IRQ BIT(2)
41 #define COMMAND_READ BIT(3)
42 #define COMMAND_WRITE BIT(4)
43 #define COMMAND_COPY BIT(5)
45 #define PCI_ENDPOINT_TEST_STATUS 0x8
46 #define STATUS_READ_SUCCESS BIT(0)
47 #define STATUS_READ_FAIL BIT(1)
48 #define STATUS_WRITE_SUCCESS BIT(2)
49 #define STATUS_WRITE_FAIL BIT(3)
50 #define STATUS_COPY_SUCCESS BIT(4)
51 #define STATUS_COPY_FAIL BIT(5)
52 #define STATUS_IRQ_RAISED BIT(6)
53 #define STATUS_SRC_ADDR_INVALID BIT(7)
54 #define STATUS_DST_ADDR_INVALID BIT(8)
56 #define PCI_ENDPOINT_TEST_STATUS 0x8
57 #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c
58 #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10
60 #define PCI_ENDPOINT_TEST_LOWER_DST_ADDR 0x14
61 #define PCI_ENDPOINT_TEST_UPPER_DST_ADDR 0x18
63 #define PCI_ENDPOINT_TEST_SIZE 0x1c
64 #define PCI_ENDPOINT_TEST_CHECKSUM 0x20
66 #define PCI_ENDPOINT_TEST_IRQ_TYPE 0x24
67 #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28
69 #define PCI_ENDPOINT_TEST_FLAGS 0x2c
70 #define FLAG_USE_DMA BIT(0)
72 #define PCI_DEVICE_ID_TI_AM654 0xb00c
74 #define is_am654_pci_dev(pdev) \
75 ((pdev)->device == PCI_DEVICE_ID_TI_AM654)
77 static DEFINE_IDA(pci_endpoint_test_ida);
79 #define to_endpoint_test(priv) container_of((priv), struct pci_endpoint_test, \
83 module_param(no_msi, bool, 0444);
84 MODULE_PARM_DESC(no_msi, "Disable MSI interrupt in pci_endpoint_test");
86 static int irq_type = IRQ_TYPE_MSI;
87 module_param(irq_type, int, 0444);
88 MODULE_PARM_DESC(irq_type, "IRQ mode selection in pci_endpoint_test (0 - Legacy, 1 - MSI, 2 - MSI-X)");
99 struct pci_endpoint_test {
100 struct pci_dev *pdev;
102 void __iomem *bar[PCI_STD_NUM_BARS];
103 struct completion irq_raised;
106 /* mutex to protect the ioctls */
108 struct miscdevice miscdev;
109 enum pci_barno test_reg_bar;
113 struct pci_endpoint_test_data {
114 enum pci_barno test_reg_bar;
119 static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test,
122 return readl(test->base + offset);
125 static inline void pci_endpoint_test_writel(struct pci_endpoint_test *test,
126 u32 offset, u32 value)
128 writel(value, test->base + offset);
131 static inline u32 pci_endpoint_test_bar_readl(struct pci_endpoint_test *test,
134 return readl(test->bar[bar] + offset);
137 static inline void pci_endpoint_test_bar_writel(struct pci_endpoint_test *test,
138 int bar, u32 offset, u32 value)
140 writel(value, test->bar[bar] + offset);
143 static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id)
145 struct pci_endpoint_test *test = dev_id;
148 reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
149 if (reg & STATUS_IRQ_RAISED) {
150 test->last_irq = irq;
151 complete(&test->irq_raised);
152 reg &= ~STATUS_IRQ_RAISED;
154 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS,
160 static void pci_endpoint_test_free_irq_vectors(struct pci_endpoint_test *test)
162 struct pci_dev *pdev = test->pdev;
164 pci_free_irq_vectors(pdev);
167 static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test,
171 struct pci_dev *pdev = test->pdev;
172 struct device *dev = &pdev->dev;
176 case IRQ_TYPE_LEGACY:
177 irq = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY);
179 dev_err(dev, "Failed to get Legacy interrupt\n");
182 irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI);
184 dev_err(dev, "Failed to get MSI interrupts\n");
187 irq = pci_alloc_irq_vectors(pdev, 1, 2048, PCI_IRQ_MSIX);
189 dev_err(dev, "Failed to get MSI-X interrupts\n");
192 dev_err(dev, "Invalid IRQ type selected\n");
199 test->num_irqs = irq;
204 static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test)
207 struct pci_dev *pdev = test->pdev;
208 struct device *dev = &pdev->dev;
210 for (i = 0; i < test->num_irqs; i++)
211 devm_free_irq(dev, pci_irq_vector(pdev, i), test);
216 static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test)
220 struct pci_dev *pdev = test->pdev;
221 struct device *dev = &pdev->dev;
223 for (i = 0; i < test->num_irqs; i++) {
224 err = devm_request_irq(dev, pci_irq_vector(pdev, i),
225 pci_endpoint_test_irqhandler,
226 IRQF_SHARED, DRV_MODULE_NAME, test);
235 case IRQ_TYPE_LEGACY:
236 dev_err(dev, "Failed to request IRQ %d for Legacy\n",
237 pci_irq_vector(pdev, i));
240 dev_err(dev, "Failed to request IRQ %d for MSI %d\n",
241 pci_irq_vector(pdev, i),
245 dev_err(dev, "Failed to request IRQ %d for MSI-X %d\n",
246 pci_irq_vector(pdev, i),
254 static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
255 enum pci_barno barno)
260 struct pci_dev *pdev = test->pdev;
262 if (!test->bar[barno])
265 size = pci_resource_len(pdev, barno);
267 if (barno == test->test_reg_bar)
270 for (j = 0; j < size; j += 4)
271 pci_endpoint_test_bar_writel(test, barno, j, 0xA0A0A0A0);
273 for (j = 0; j < size; j += 4) {
274 val = pci_endpoint_test_bar_readl(test, barno, j);
275 if (val != 0xA0A0A0A0)
282 static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test)
286 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
288 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 0);
289 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
290 COMMAND_RAISE_LEGACY_IRQ);
291 val = wait_for_completion_timeout(&test->irq_raised,
292 msecs_to_jiffies(1000));
299 static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
300 u16 msi_num, bool msix)
303 struct pci_dev *pdev = test->pdev;
305 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
306 msix == false ? IRQ_TYPE_MSI :
308 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, msi_num);
309 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
310 msix == false ? COMMAND_RAISE_MSI_IRQ :
311 COMMAND_RAISE_MSIX_IRQ);
312 val = wait_for_completion_timeout(&test->irq_raised,
313 msecs_to_jiffies(1000));
317 if (pci_irq_vector(pdev, msi_num - 1) == test->last_irq)
323 static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
326 struct pci_endpoint_test_xfer_param param;
333 dma_addr_t src_phys_addr;
334 dma_addr_t dst_phys_addr;
335 struct pci_dev *pdev = test->pdev;
336 struct device *dev = &pdev->dev;
338 dma_addr_t orig_src_phys_addr;
340 dma_addr_t orig_dst_phys_addr;
342 size_t alignment = test->alignment;
347 err = copy_from_user(¶m, (void __user *)arg, sizeof(param));
349 dev_err(dev, "Failed to get transfer param\n");
354 if (size > SIZE_MAX - alignment)
357 use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
359 flags |= FLAG_USE_DMA;
361 if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) {
362 dev_err(dev, "Invalid IRQ type option\n");
366 orig_src_addr = kzalloc(size + alignment, GFP_KERNEL);
367 if (!orig_src_addr) {
368 dev_err(dev, "Failed to allocate source buffer\n");
373 get_random_bytes(orig_src_addr, size + alignment);
374 orig_src_phys_addr = dma_map_single(dev, orig_src_addr,
375 size + alignment, DMA_TO_DEVICE);
376 if (dma_mapping_error(dev, orig_src_phys_addr)) {
377 dev_err(dev, "failed to map source buffer address\n");
379 goto err_src_phys_addr;
382 if (alignment && !IS_ALIGNED(orig_src_phys_addr, alignment)) {
383 src_phys_addr = PTR_ALIGN(orig_src_phys_addr, alignment);
384 offset = src_phys_addr - orig_src_phys_addr;
385 src_addr = orig_src_addr + offset;
387 src_phys_addr = orig_src_phys_addr;
388 src_addr = orig_src_addr;
391 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR,
392 lower_32_bits(src_phys_addr));
394 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR,
395 upper_32_bits(src_phys_addr));
397 src_crc32 = crc32_le(~0, src_addr, size);
399 orig_dst_addr = kzalloc(size + alignment, GFP_KERNEL);
400 if (!orig_dst_addr) {
401 dev_err(dev, "Failed to allocate destination address\n");
406 orig_dst_phys_addr = dma_map_single(dev, orig_dst_addr,
407 size + alignment, DMA_FROM_DEVICE);
408 if (dma_mapping_error(dev, orig_dst_phys_addr)) {
409 dev_err(dev, "failed to map destination buffer address\n");
411 goto err_dst_phys_addr;
414 if (alignment && !IS_ALIGNED(orig_dst_phys_addr, alignment)) {
415 dst_phys_addr = PTR_ALIGN(orig_dst_phys_addr, alignment);
416 offset = dst_phys_addr - orig_dst_phys_addr;
417 dst_addr = orig_dst_addr + offset;
419 dst_phys_addr = orig_dst_phys_addr;
420 dst_addr = orig_dst_addr;
423 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR,
424 lower_32_bits(dst_phys_addr));
425 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR,
426 upper_32_bits(dst_phys_addr));
428 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE,
431 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags);
432 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type);
433 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1);
434 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
437 wait_for_completion(&test->irq_raised);
439 dma_unmap_single(dev, orig_dst_phys_addr, size + alignment,
442 dst_crc32 = crc32_le(~0, dst_addr, size);
443 if (dst_crc32 == src_crc32)
447 kfree(orig_dst_addr);
450 dma_unmap_single(dev, orig_src_phys_addr, size + alignment,
454 kfree(orig_src_addr);
460 static bool pci_endpoint_test_write(struct pci_endpoint_test *test,
463 struct pci_endpoint_test_xfer_param param;
469 dma_addr_t phys_addr;
470 struct pci_dev *pdev = test->pdev;
471 struct device *dev = &pdev->dev;
473 dma_addr_t orig_phys_addr;
475 size_t alignment = test->alignment;
480 err = copy_from_user(¶m, (void __user *)arg, sizeof(param));
482 dev_err(dev, "Failed to get transfer param\n");
487 if (size > SIZE_MAX - alignment)
490 use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
492 flags |= FLAG_USE_DMA;
494 if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) {
495 dev_err(dev, "Invalid IRQ type option\n");
499 orig_addr = kzalloc(size + alignment, GFP_KERNEL);
501 dev_err(dev, "Failed to allocate address\n");
506 get_random_bytes(orig_addr, size + alignment);
508 orig_phys_addr = dma_map_single(dev, orig_addr, size + alignment,
510 if (dma_mapping_error(dev, orig_phys_addr)) {
511 dev_err(dev, "failed to map source buffer address\n");
516 if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) {
517 phys_addr = PTR_ALIGN(orig_phys_addr, alignment);
518 offset = phys_addr - orig_phys_addr;
519 addr = orig_addr + offset;
521 phys_addr = orig_phys_addr;
525 crc32 = crc32_le(~0, addr, size);
526 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_CHECKSUM,
529 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR,
530 lower_32_bits(phys_addr));
531 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR,
532 upper_32_bits(phys_addr));
534 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size);
536 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags);
537 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type);
538 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1);
539 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
542 wait_for_completion(&test->irq_raised);
544 reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
545 if (reg & STATUS_READ_SUCCESS)
548 dma_unmap_single(dev, orig_phys_addr, size + alignment,
558 static bool pci_endpoint_test_read(struct pci_endpoint_test *test,
561 struct pci_endpoint_test_xfer_param param;
567 dma_addr_t phys_addr;
568 struct pci_dev *pdev = test->pdev;
569 struct device *dev = &pdev->dev;
571 dma_addr_t orig_phys_addr;
573 size_t alignment = test->alignment;
577 err = copy_from_user(¶m, (void __user *)arg, sizeof(param));
579 dev_err(dev, "Failed to get transfer param\n");
584 if (size > SIZE_MAX - alignment)
587 use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
589 flags |= FLAG_USE_DMA;
591 if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) {
592 dev_err(dev, "Invalid IRQ type option\n");
596 orig_addr = kzalloc(size + alignment, GFP_KERNEL);
598 dev_err(dev, "Failed to allocate destination address\n");
603 orig_phys_addr = dma_map_single(dev, orig_addr, size + alignment,
605 if (dma_mapping_error(dev, orig_phys_addr)) {
606 dev_err(dev, "failed to map source buffer address\n");
611 if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) {
612 phys_addr = PTR_ALIGN(orig_phys_addr, alignment);
613 offset = phys_addr - orig_phys_addr;
614 addr = orig_addr + offset;
616 phys_addr = orig_phys_addr;
620 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR,
621 lower_32_bits(phys_addr));
622 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR,
623 upper_32_bits(phys_addr));
625 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size);
627 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags);
628 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type);
629 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1);
630 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
633 wait_for_completion(&test->irq_raised);
635 dma_unmap_single(dev, orig_phys_addr, size + alignment,
638 crc32 = crc32_le(~0, addr, size);
639 if (crc32 == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM))
648 static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test,
651 struct pci_dev *pdev = test->pdev;
652 struct device *dev = &pdev->dev;
654 if (req_irq_type < IRQ_TYPE_LEGACY || req_irq_type > IRQ_TYPE_MSIX) {
655 dev_err(dev, "Invalid IRQ type option\n");
659 if (irq_type == req_irq_type)
662 pci_endpoint_test_release_irq(test);
663 pci_endpoint_test_free_irq_vectors(test);
665 if (!pci_endpoint_test_alloc_irq_vectors(test, req_irq_type))
668 if (!pci_endpoint_test_request_irq(test))
671 irq_type = req_irq_type;
675 pci_endpoint_test_free_irq_vectors(test);
676 irq_type = IRQ_TYPE_UNDEFINED;
680 static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
685 struct pci_endpoint_test *test = to_endpoint_test(file->private_data);
686 struct pci_dev *pdev = test->pdev;
688 mutex_lock(&test->mutex);
692 if (bar < 0 || bar > 5)
694 if (is_am654_pci_dev(pdev) && bar == BAR_0)
696 ret = pci_endpoint_test_bar(test, bar);
698 case PCITEST_LEGACY_IRQ:
699 ret = pci_endpoint_test_legacy_irq(test);
703 ret = pci_endpoint_test_msi_irq(test, arg, cmd == PCITEST_MSIX);
706 ret = pci_endpoint_test_write(test, arg);
709 ret = pci_endpoint_test_read(test, arg);
712 ret = pci_endpoint_test_copy(test, arg);
714 case PCITEST_SET_IRQTYPE:
715 ret = pci_endpoint_test_set_irq(test, arg);
717 case PCITEST_GET_IRQTYPE:
723 mutex_unlock(&test->mutex);
727 static const struct file_operations pci_endpoint_test_fops = {
728 .owner = THIS_MODULE,
729 .unlocked_ioctl = pci_endpoint_test_ioctl,
732 static int pci_endpoint_test_probe(struct pci_dev *pdev,
733 const struct pci_device_id *ent)
740 struct device *dev = &pdev->dev;
741 struct pci_endpoint_test *test;
742 struct pci_endpoint_test_data *data;
743 enum pci_barno test_reg_bar = BAR_0;
744 struct miscdevice *misc_device;
746 if (pci_is_bridge(pdev))
749 test = devm_kzalloc(dev, sizeof(*test), GFP_KERNEL);
753 test->test_reg_bar = 0;
758 irq_type = IRQ_TYPE_LEGACY;
760 data = (struct pci_endpoint_test_data *)ent->driver_data;
762 test_reg_bar = data->test_reg_bar;
763 test->test_reg_bar = test_reg_bar;
764 test->alignment = data->alignment;
765 irq_type = data->irq_type;
768 init_completion(&test->irq_raised);
769 mutex_init(&test->mutex);
771 if ((dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)) != 0) &&
772 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
773 dev_err(dev, "Cannot set DMA mask\n");
777 err = pci_enable_device(pdev);
779 dev_err(dev, "Cannot enable PCI device\n");
783 err = pci_request_regions(pdev, DRV_MODULE_NAME);
785 dev_err(dev, "Cannot obtain PCI resources\n");
786 goto err_disable_pdev;
789 pci_set_master(pdev);
791 if (!pci_endpoint_test_alloc_irq_vectors(test, irq_type))
792 goto err_disable_irq;
794 if (!pci_endpoint_test_request_irq(test))
795 goto err_disable_irq;
797 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
798 if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
799 base = pci_ioremap_bar(pdev, bar);
801 dev_err(dev, "Failed to read BAR%d\n", bar);
802 WARN_ON(bar == test_reg_bar);
804 test->bar[bar] = base;
808 test->base = test->bar[test_reg_bar];
811 dev_err(dev, "Cannot perform PCI test without BAR%d\n",
816 pci_set_drvdata(pdev, test);
818 id = ida_simple_get(&pci_endpoint_test_ida, 0, 0, GFP_KERNEL);
821 dev_err(dev, "Unable to get id\n");
825 snprintf(name, sizeof(name), DRV_MODULE_NAME ".%d", id);
826 misc_device = &test->miscdev;
827 misc_device->minor = MISC_DYNAMIC_MINOR;
828 misc_device->name = kstrdup(name, GFP_KERNEL);
829 if (!misc_device->name) {
833 misc_device->fops = &pci_endpoint_test_fops,
835 err = misc_register(misc_device);
837 dev_err(dev, "Failed to register device\n");
844 kfree(misc_device->name);
847 ida_simple_remove(&pci_endpoint_test_ida, id);
850 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
852 pci_iounmap(pdev, test->bar[bar]);
854 pci_endpoint_test_release_irq(test);
857 pci_endpoint_test_free_irq_vectors(test);
858 pci_release_regions(pdev);
861 pci_disable_device(pdev);
866 static void pci_endpoint_test_remove(struct pci_dev *pdev)
870 struct pci_endpoint_test *test = pci_get_drvdata(pdev);
871 struct miscdevice *misc_device = &test->miscdev;
873 if (sscanf(misc_device->name, DRV_MODULE_NAME ".%d", &id) != 1)
878 misc_deregister(&test->miscdev);
879 kfree(misc_device->name);
880 ida_simple_remove(&pci_endpoint_test_ida, id);
881 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
883 pci_iounmap(pdev, test->bar[bar]);
886 pci_endpoint_test_release_irq(test);
887 pci_endpoint_test_free_irq_vectors(test);
889 pci_release_regions(pdev);
890 pci_disable_device(pdev);
893 static const struct pci_endpoint_test_data default_data = {
894 .test_reg_bar = BAR_0,
896 .irq_type = IRQ_TYPE_MSI,
899 static const struct pci_endpoint_test_data am654_data = {
900 .test_reg_bar = BAR_2,
902 .irq_type = IRQ_TYPE_MSI,
905 static const struct pci_device_id pci_endpoint_test_tbl[] = {
906 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x),
907 .driver_data = (kernel_ulong_t)&default_data,
909 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x),
910 .driver_data = (kernel_ulong_t)&default_data,
912 { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x81c0) },
913 { PCI_DEVICE_DATA(SYNOPSYS, EDDA, NULL) },
914 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_AM654),
915 .driver_data = (kernel_ulong_t)&am654_data
919 MODULE_DEVICE_TABLE(pci, pci_endpoint_test_tbl);
921 static struct pci_driver pci_endpoint_test_driver = {
922 .name = DRV_MODULE_NAME,
923 .id_table = pci_endpoint_test_tbl,
924 .probe = pci_endpoint_test_probe,
925 .remove = pci_endpoint_test_remove,
927 module_pci_driver(pci_endpoint_test_driver);
929 MODULE_DESCRIPTION("PCI ENDPOINT TEST HOST DRIVER");
930 MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
931 MODULE_LICENSE("GPL v2");