[PATCH] misc: edu: add MSI-X interrupt generation aswell

Neil Armstrong posted 1 patch 2 years, 8 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210812113230.2462428-1-narmstrong@baylibre.com
Maintainers: Jiri Slaby <jslaby@suse.cz>
hw/misc/edu.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
[PATCH] misc: edu: add MSI-X interrupt generation aswell
Posted by Neil Armstrong 2 years, 8 months ago
Add MSI-X aswell since either MSI or MSI-X are optional and
MSI can still be used without any issues.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 hw/misc/edu.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/misc/edu.c b/hw/misc/edu.c
index e935c418d4..5d0643e1bd 100644
--- a/hw/misc/edu.c
+++ b/hw/misc/edu.c
@@ -27,6 +27,7 @@
 #include "hw/pci/pci.h"
 #include "hw/hw.h"
 #include "hw/pci/msi.h"
+#include "hw/pci/msix.h"
 #include "qemu/timer.h"
 #include "qom/object.h"
 #include "qemu/main-loop.h" /* iothread mutex */
@@ -77,6 +78,11 @@ struct EduState {
     uint64_t dma_mask;
 };
 
+static bool edu_msix_enabled(EduState *edu)
+{
+    return msix_enabled(&edu->pdev);
+}
+
 static bool edu_msi_enabled(EduState *edu)
 {
     return msi_enabled(&edu->pdev);
@@ -86,7 +92,9 @@ static void edu_raise_irq(EduState *edu, uint32_t val)
 {
     edu->irq_status |= val;
     if (edu->irq_status) {
-        if (edu_msi_enabled(edu)) {
+        if (edu_msix_enabled(edu)) {
+            msix_notify(&edu->pdev, 0);
+        } else if (edu_msi_enabled(edu)) {
             msi_notify(&edu->pdev, 0);
         } else {
             pci_set_irq(&edu->pdev, 1);
@@ -369,6 +377,10 @@ static void pci_edu_realize(PCIDevice *pdev, Error **errp)
     if (msi_init(pdev, 0, 1, true, false, errp)) {
         return;
     }
+    if (msix_init_exclusive_bar(pdev, 1, 1, errp)) {
+        return;
+    }
+    msix_vector_use(pdev, 0);
 
     timer_init_ms(&edu->dma_timer, QEMU_CLOCK_VIRTUAL, edu_dma_timer, edu);
 
@@ -397,6 +409,7 @@ static void pci_edu_uninit(PCIDevice *pdev)
 
     timer_del(&edu->dma_timer);
     msi_uninit(pdev);
+    msix_uninit_exclusive_bar(pdev);
 }
 
 static void edu_instance_init(Object *obj)
-- 
2.25.1