drivers/pci_qemu_edu: add MSI test

Add simple MSI test for QEMU PCI EDU device so we can verify if MSI works correctly

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
p-szafonimateusz 2024-03-20 08:20:19 +01:00 committed by Xiang Xiao
parent 0659b333b4
commit 4a147fc86b

View File

@ -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>
@ -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 */
@ -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);
@ -458,6 +456,36 @@ 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);
@ -465,6 +493,11 @@ static int pci_qemu_edu_probe(FAR struct pci_device_s *dev)
/* 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;