Skip to content

Commit

Permalink
drivers/pci_qemu_edu: add MSI test
Browse files Browse the repository at this point in the history
Add simple MSI test for QEMU PCI EDU device so we can verify if MSI works correctly

Signed-off-by: p-szafonimateusz <[email protected]>
  • Loading branch information
szafonimateusz-mi authored and xiaoxiang781216 committed Sep 13, 2024
1 parent 0659b33 commit 4a147fc
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions drivers/pci/pci_qemu_edu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <debug.h>
#include <errno.h>

#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/kmalloc.h>
#include <nuttx/pci/pci.h>
Expand Down Expand Up @@ -398,7 +397,7 @@ static int pci_qemu_edu_probe(FAR struct pci_device_s *dev)
{
struct pci_qemu_edu_priv_s priv;
unsigned int flags;
uint8_t irq;
int irq = 0;
int ret;

/* Enable EDU device */
Expand Down Expand Up @@ -443,8 +442,7 @@ static int pci_qemu_edu_probe(FAR struct pci_device_s *dev)

/* Run IRQ Tests */

pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
irq = IRQ0 + irq;
irq = pci_get_irq(dev);
pciinfo("IRQ TEST: Attaching IRQ %u to %p\n", irq, pci_qemu_edu_interrupt);

irq_attach(irq, pci_qemu_edu_interrupt, &priv);
Expand All @@ -458,13 +456,48 @@ static int pci_qemu_edu_probe(FAR struct pci_device_s *dev)

/* Run MSI Tests */

pciinfo("MSI TEST\n");

irq = 0;
ret = pci_alloc_irq(dev, &irq, 1);
if (ret != 1)
{
pcierr("Failed to allocate MSI %d\n", ret);
goto err;
}

pciinfo("MSI TEST: Attaching MSI %u to %p\n",
irq, pci_qemu_edu_interrupt);

ret = pci_connect_irq(dev, &irq, 1);
if (ret != OK)
{
pcierr("Failed to connect MSI %d\n", ret);
goto err;
}

irq_attach(irq, pci_qemu_edu_interrupt, &priv);
up_enable_irq(irq);

pci_qemu_edu_test_intx(&priv);
pci_qemu_edu_test_dma(&priv);

up_disable_irq(irq);
irq_detach(irq);
pci_release_irq(dev, &irq, 1);

/* Uninitialize the driver */

nxsem_destroy(&priv.isr_done);

/* TODO: add pci unmap api */

err:
if (irq != 0)
{
pci_release_irq(dev, &irq, 1);
}

pci_clear_master(dev);
pci_disable_device(dev);
return ret;
Expand Down

0 comments on commit 4a147fc

Please sign in to comment.