|
15 | 15 | #define QEMU_VENDOR_ID 0x1234
|
16 | 16 |
|
17 | 17 | static struct pci_device_id id_table[] = {
|
18 |
| - { PCI_DEVICE(QEMU_VENDOR_ID, EDU_DEVICE_ID), }, |
19 |
| - { 0, } |
| 18 | + { PCI_DEVICE(QEMU_VENDOR_ID, EDU_DEVICE_ID), }, |
| 19 | + { 0, } |
20 | 20 | };
|
21 | 21 | MODULE_DEVICE_TABLE(pci, id_table);
|
22 | 22 | static int major;
|
23 | 23 | static struct pci_dev *pdev;
|
24 | 24 | static void __iomem *mmio;
|
25 | 25 | static struct file_operations fops = {
|
26 |
| - .owner = THIS_MODULE, |
| 26 | + .owner = THIS_MODULE, |
27 | 27 | };
|
28 | 28 |
|
29 | 29 | static irqreturn_t irq_handler(int irq, void *dev)
|
30 | 30 | {
|
31 |
| - pr_info("irq_handler irq = %d dev = %d\n", irq, *(int *)dev); |
32 |
| - iowrite32(0, mmio + 4); |
33 |
| - return IRQ_HANDLED; |
| 31 | + pr_info("irq_handler irq = %d dev = %d\n", irq, *(int *)dev); |
| 32 | + iowrite32(0, mmio + 4); |
| 33 | + return IRQ_HANDLED; |
34 | 34 | }
|
35 | 35 |
|
36 | 36 | static int probe(struct pci_dev *dev, const struct pci_device_id *id)
|
37 | 37 | {
|
38 |
| - pr_info("probe\n"); |
39 |
| - major = register_chrdev(0, CDEV_NAME, &fops); |
40 |
| - pdev = dev; |
41 |
| - if (pci_enable_device(dev) < 0) { |
42 |
| - dev_err(&(pdev->dev), "pci_enable_device\n"); |
43 |
| - goto error; |
44 |
| - } |
45 |
| - if (pci_request_region(dev, BAR, "myregion0")) { |
46 |
| - dev_err(&(pdev->dev), "pci_request_region\n"); |
47 |
| - goto error; |
48 |
| - } |
49 |
| - mmio = pci_iomap(pdev, BAR, pci_resource_len(pdev, BAR)); |
50 |
| - pr_info("dev->irq = %u\n", dev->irq); |
51 |
| - if (request_irq(dev->irq, irq_handler, IRQF_SHARED, "pci_irq_handler0", &major) < 0) { |
52 |
| - dev_err(&(dev->dev), "request_irq\n"); |
53 |
| - goto error; |
54 |
| - } |
55 |
| - iowrite32(0x12345678, mmio); |
56 |
| - return 0; |
| 38 | + pr_info("probe\n"); |
| 39 | + major = register_chrdev(0, CDEV_NAME, &fops); |
| 40 | + pdev = dev; |
| 41 | + if (pci_enable_device(dev) < 0) { |
| 42 | + dev_err(&(pdev->dev), "pci_enable_device\n"); |
| 43 | + goto error; |
| 44 | + } |
| 45 | + if (pci_request_region(dev, BAR, "myregion0")) { |
| 46 | + dev_err(&(pdev->dev), "pci_request_region\n"); |
| 47 | + goto error; |
| 48 | + } |
| 49 | + mmio = pci_iomap(pdev, BAR, pci_resource_len(pdev, BAR)); |
| 50 | + pr_info("dev->irq = %u\n", dev->irq); |
| 51 | + if (request_irq(dev->irq, irq_handler, IRQF_SHARED, "pci_irq_handler0", &major) < 0) { |
| 52 | + dev_err(&(dev->dev), "request_irq\n"); |
| 53 | + goto error; |
| 54 | + } |
| 55 | + iowrite32(0x12345678, mmio); |
| 56 | + return 0; |
57 | 57 | error:
|
58 |
| - return 1; |
| 58 | + return 1; |
59 | 59 | }
|
60 | 60 |
|
61 | 61 | static void remove(struct pci_dev *dev)
|
62 | 62 | {
|
63 |
| - pr_info("remove\n"); |
64 |
| - free_irq(dev->irq, &major); |
65 |
| - pci_release_region(dev, BAR); |
66 |
| - unregister_chrdev(major, CDEV_NAME); |
| 63 | + pr_info("remove\n"); |
| 64 | + free_irq(dev->irq, &major); |
| 65 | + pci_release_region(dev, BAR); |
| 66 | + unregister_chrdev(major, CDEV_NAME); |
67 | 67 | }
|
68 | 68 |
|
69 | 69 | static struct pci_driver pci_driver = {
|
70 |
| - .name = CDEV_NAME, |
71 |
| - .id_table = id_table, |
72 |
| - .probe = probe, |
73 |
| - .remove = remove, |
| 70 | + .name = CDEV_NAME, |
| 71 | + .id_table = id_table, |
| 72 | + .probe = probe, |
| 73 | + .remove = remove, |
74 | 74 | };
|
75 | 75 |
|
76 | 76 | static int myinit(void)
|
77 | 77 | {
|
78 |
| - if (pci_register_driver(&pci_driver) < 0) { |
79 |
| - return 1; |
80 |
| - } |
81 |
| - return 0; |
| 78 | + if (pci_register_driver(&pci_driver) < 0) { |
| 79 | + return 1; |
| 80 | + } |
| 81 | + return 0; |
82 | 82 | }
|
83 | 83 |
|
84 | 84 | static void myexit(void)
|
85 | 85 | {
|
86 |
| - pci_unregister_driver(&pci_driver); |
| 86 | + pci_unregister_driver(&pci_driver); |
87 | 87 | }
|
88 | 88 |
|
89 | 89 | module_init(myinit);
|
|
0 commit comments