diff --git a/litepcie/software/kernel/main.c b/litepcie/software/kernel/main.c index ab7df6e..ca4b9e8 100644 --- a/litepcie/software/kernel/main.c +++ b/litepcie/software/kernel/main.c @@ -137,8 +137,13 @@ static void litepcie_enable_interrupt(struct litepcie_device *s, int irq_num) { uint32_t v; + /* Read the current interrupt enable register value */ v = litepcie_readl(s, CSR_PCIE_MSI_ENABLE_ADDR); + + /* Set the bit corresponding to the given interrupt number */ v |= (1 << irq_num); + + /* Write the updated value back to the register */ litepcie_writel(s, CSR_PCIE_MSI_ENABLE_ADDR, v); } @@ -146,8 +151,13 @@ static void litepcie_disable_interrupt(struct litepcie_device *s, int irq_num) { uint32_t v; + /* Read the current interrupt enable register value */ v = litepcie_readl(s, CSR_PCIE_MSI_ENABLE_ADDR); + + /* Clear the bit corresponding to the given interrupt number */ v &= ~(1 << irq_num); + + /* Write the updated value back to the register */ litepcie_writel(s, CSR_PCIE_MSI_ENABLE_ADDR, v); } @@ -1000,6 +1010,7 @@ static int litepcie_pci_probe(struct pci_dev *dev, const struct pci_device_id *i dev_info(&dev->dev, "\e[1m[Probing device]\e[0m\n"); + /* Allocate memory for the LitePCIe device structure */ litepcie_dev = devm_kzalloc(&dev->dev, sizeof(struct litepcie_device), GFP_KERNEL); if (!litepcie_dev) { ret = -ENOMEM; @@ -1010,6 +1021,7 @@ static int litepcie_pci_probe(struct pci_dev *dev, const struct pci_device_id *i litepcie_dev->dev = dev; spin_lock_init(&litepcie_dev->lock); + /* Enable the PCI device */ ret = pcim_enable_device(dev); if (ret != 0) { dev_err(&dev->dev, "Cannot enable device\n"); @@ -1018,19 +1030,20 @@ static int litepcie_pci_probe(struct pci_dev *dev, const struct pci_device_id *i ret = -EIO; - /* Check device version */ + /* Check the device version */ pci_read_config_byte(dev, PCI_REVISION_ID, &rev_id); if (rev_id != 0) { dev_err(&dev->dev, "Unsupported device version %d\n", rev_id); goto fail1; } - /* Check bar0 config */ + /* Check the BAR0 configuration */ if (!(pci_resource_flags(dev, 0) & IORESOURCE_MEM)) { dev_err(&dev->dev, "Invalid BAR0 configuration\n"); goto fail1; } + /* Request and map BAR0 */ if (pcim_iomap_regions(dev, BIT(0), LITEPCIE_NAME) < 0) { dev_err(&dev->dev, "Could not request regions\n"); goto fail1; @@ -1048,9 +1061,9 @@ static int litepcie_pci_probe(struct pci_dev *dev, const struct pci_device_id *i msleep(10); #endif - /* Show identifier */ + /* Read and display the FPGA identifier */ for (i = 0; i < 256; i++) - fpga_identifier[i] = litepcie_readl(litepcie_dev, CSR_IDENTIFIER_MEM_BASE + i*4); + fpga_identifier[i] = litepcie_readl(litepcie_dev, CSR_IDENTIFIER_MEM_BASE + i * 4); dev_info(&dev->dev, "Version %s\n", fpga_identifier); pci_set_master(dev); @@ -1062,7 +1075,7 @@ static int litepcie_pci_probe(struct pci_dev *dev, const struct pci_device_id *i if (ret) { dev_err(&dev->dev, "Failed to set DMA mask\n"); goto fail1; - }; + } /* MSI-X */ @@ -1089,6 +1102,7 @@ static int litepcie_pci_probe(struct pci_dev *dev, const struct pci_device_id *i for (i = 0; i < irqs; i++) { int irq = pci_irq_vector(dev, i); + /* Request IRQ */ ret = request_irq(irq, litepcie_interrupt, 0, LITEPCIE_NAME, litepcie_dev); if (ret < 0) { dev_err(&dev->dev, " Failed to allocate IRQ %d\n", dev->irq); @@ -1290,6 +1304,7 @@ static const struct pci_device_id litepcie_pci_ids[] = { }; MODULE_DEVICE_TABLE(pci, litepcie_pci_ids); +/* PCI driver structure */ static struct pci_driver litepcie_pci_driver = { .name = LITEPCIE_NAME, .id_table = litepcie_pci_ids, @@ -1297,7 +1312,7 @@ static struct pci_driver litepcie_pci_driver = { .remove = litepcie_pci_remove, }; - +/* Module initialization function */ static int __init litepcie_module_init(void) { int ret; @@ -1337,6 +1352,7 @@ static int __init litepcie_module_init(void) return ret; } +/* Module exit function */ static void __exit litepcie_module_exit(void) { pci_unregister_driver(&litepcie_pci_driver); @@ -1344,7 +1360,6 @@ static void __exit litepcie_module_exit(void) class_destroy(litepcie_class); } - module_init(litepcie_module_init); module_exit(litepcie_module_exit);