Skip to content

Commit

Permalink
software/kernel/main: Add a few comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Oct 2, 2024
1 parent aa67c65 commit c724869
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions litepcie/software/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,27 @@ 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);
}

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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -1290,14 +1304,15 @@ 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,
.probe = litepcie_pci_probe,
.remove = litepcie_pci_remove,
};


/* Module initialization function */
static int __init litepcie_module_init(void)
{
int ret;
Expand Down Expand Up @@ -1337,14 +1352,14 @@ 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);
unregister_chrdev_region(litepcie_dev_t, LITEPCIE_MINOR_COUNT);
class_destroy(litepcie_class);
}


module_init(litepcie_module_init);
module_exit(litepcie_module_exit);

Expand Down

0 comments on commit c724869

Please sign in to comment.