You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/13 01:42:17 UTC

(nuttx) 03/03: drivers/pci_qemu_edu: add MSI test

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4a147fc86b2c5f4f0880b658aa50680e8d82c0f7
Author: p-szafonimateusz <p-...@xiaomi.com>
AuthorDate: Wed Mar 20 08:20:19 2024 +0100

    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-...@xiaomi.com>
---
 drivers/pci/pci_qemu_edu.c | 41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pci_qemu_edu.c b/drivers/pci/pci_qemu_edu.c
index 37b1627052..94bddd56cc 100644
--- a/drivers/pci/pci_qemu_edu.c
+++ b/drivers/pci/pci_qemu_edu.c
@@ -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;