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 6526f2371acbf55813ac412cf521c0d8c8c2a793
Author: lipengfei28 <[email protected]>
AuthorDate: Thu Jan 16 21:27:29 2025 +0800

    drivers/pci:write legacy num to config space when enable legacy irq
    
    write legacy num to config sapce when enable legacy irq
    
    Signed-off-by: lipengfei28 <[email protected]>
---
 drivers/pci/pci.c          | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/pci_ep_test.c  | 10 +++++++++-
 drivers/pci/pci_qemu_edu.c |  2 ++
 include/nuttx/pci/pci.h    | 27 +++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 694ce7f372d..e84420cd1a9 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -2035,6 +2035,52 @@ int pci_connect_irq(FAR struct pci_device_s *dev, FAR 
int *irq, int num)
     }
 }
 
+/****************************************************************************
+ * Name: pci_enable_irq
+ *
+ * Description:
+ *   Enable legacy irq if available.
+ *
+ * Input Parameters:
+ *   dev - PCI device
+ *   irq - allocated vectors
+ *
+ ****************************************************************************/
+
+void pci_enable_irq(FAR struct pci_device_s *dev, int irq)
+{
+  uint16_t command;
+  uint8_t line;
+
+  pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &line);
+  pci_read_config_word(dev, PCI_COMMAND, &command);
+  command &= ~PCI_COMMAND_INTX_DISABLE;
+  pci_write_config_word(dev, PCI_COMMAND, command);
+  if (line == 0)
+    {
+      pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
+    }
+}
+
+/****************************************************************************
+ * Name: pci_disable_irq
+ *
+ * Description:
+ *   Disable legacy irq.
+ *
+ * Input Parameters:
+ *   dev - PCI device
+ *
+ ****************************************************************************/
+
+void pci_disable_irq(FAR struct pci_device_s *dev)
+{
+  uint16_t command;
+  pci_read_config_word(dev, PCI_COMMAND, &command);
+  command |= PCI_COMMAND_INTX_DISABLE;
+  pci_write_config_word(dev, PCI_COMMAND, command);
+}
+
 /****************************************************************************
  * Name: pci_register_driver
  *
diff --git a/drivers/pci/pci_ep_test.c b/drivers/pci/pci_ep_test.c
index 7cff95e4336..0b36e4a8ba8 100644
--- a/drivers/pci/pci_ep_test.c
+++ b/drivers/pci/pci_ep_test.c
@@ -542,10 +542,14 @@ static bool pci_ep_test_free_irq(FAR struct pci_ep_test_s 
*test)
 {
   up_disable_irq(test->irq);
   irq_detach(test->irq);
-  if (test->irq_type != PCI_EP_TEST_IRQ_TYPE_LEGACY)
+  if (test->irq_type >= PCI_EP_TEST_IRQ_TYPE_MSI)
     {
       pci_release_irq(test->pdev, &test->irq, 1);
     }
+  else if (test->irq_type == PCI_EP_TEST_IRQ_TYPE_LEGACY)
+    {
+      pci_disable_irq(dev);
+    }
 
   return true;
 }
@@ -625,6 +629,10 @@ static int pci_ep_test_alloc_irq(FAR struct pci_ep_test_s 
*test,
           return ret;
         }
     }
+  else if (irq_type == PCI_EP_TEST_IRQ_TYPE_LEGACY)
+    {
+      pci_enable_irq(dev, test->irq);
+    }
 
   ret = irq_attach(test->irq, pci_ep_test_handler, test);
   if (ret >= 0)
diff --git a/drivers/pci/pci_qemu_edu.c b/drivers/pci/pci_qemu_edu.c
index 4ef96b34ff7..5d826cbc047 100644
--- a/drivers/pci/pci_qemu_edu.c
+++ b/drivers/pci/pci_qemu_edu.c
@@ -450,10 +450,12 @@ static int pci_qemu_edu_probe(FAR struct pci_device_s 
*dev)
 
   irq_attach(irq, pci_qemu_edu_interrupt, &priv);
   up_enable_irq(irq);
+  pci_enable_irq(dev, irq);
 
   pci_qemu_edu_test_intx(&priv);
   pci_qemu_edu_test_dma(&priv);
 
+  pci_disable_irq(dev);
   up_disable_irq(irq);
   irq_detach(irq);
 
diff --git a/include/nuttx/pci/pci.h b/include/nuttx/pci/pci.h
index 58de9fa8130..d4f2610e83c 100644
--- a/include/nuttx/pci/pci.h
+++ b/include/nuttx/pci/pci.h
@@ -834,6 +834,33 @@ void pci_release_irq(FAR struct pci_device_s *dev, FAR int 
*irq, int num);
 
 int pci_connect_irq(FAR struct pci_device_s *dev, FAR int *irq, int num);
 
+/****************************************************************************
+ * Name: pci_enable_irq
+ *
+ * Description:
+ *   Enable legacy irq if available.
+ *
+ * Input Parameters:
+ *   dev - PCI device
+ *   irq - allocated vectors
+ *
+ ****************************************************************************/
+
+void pci_enable_irq(FAR struct pci_device_s *dev, int irq);
+
+/****************************************************************************
+ * Name: pci_disable_irq
+ *
+ * Description:
+ *   Disable legacy irq.
+ *
+ * Input Parameters:
+ *   dev - PCI device
+ *
+ ****************************************************************************/
+
+void pci_disable_irq(FAR struct pci_device_s *dev);
+
 /****************************************************************************
  * Name: pci_register_driver
  *

Reply via email to