All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: kvm@vger.kernel.org
Subject: [PATCH 19/20] msix: add mask/unmask notifiers
Date: Thu, 4 Feb 2010 17:29:12 +0200	[thread overview]
Message-ID: <20100204152912.GT8461@redhat.com> (raw)
In-Reply-To: <cover.1265297173.git.mst@redhat.com>

Support per-vector callbacks for msix mask/unmask.
Will be used for vhost net.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/msix.c |   36 +++++++++++++++++++++++++++++++++++-
 hw/msix.h |    1 +
 hw/pci.h  |    6 ++++++
 3 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index 87f125b..31a61c6 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -318,6 +318,13 @@ static void msix_mmio_writel(void *opaque, target_phys_addr_t addr,
     if (kvm_enabled() && kvm_irqchip_in_kernel()) {
         kvm_msix_update(dev, vector, was_masked, msix_is_masked(dev, vector));
     }
+    if (was_masked != msix_is_masked(dev, vector) &&
+        dev->msix_mask_notifier && dev->msix_mask_notifier_opaque[vector]) {
+        int r = dev->msix_mask_notifier(dev, vector,
+					dev->msix_mask_notifier_opaque[vector],
+					msix_is_masked(dev, vector));
+        assert(r >= 0);
+    }
     msix_handle_mask_update(dev, vector);
 }
 
@@ -356,10 +363,18 @@ void msix_mmio_map(PCIDevice *d, int region_num,
 
 static void msix_mask_all(struct PCIDevice *dev, unsigned nentries)
 {
-    int vector;
+    int vector, r;
     for (vector = 0; vector < nentries; ++vector) {
         unsigned offset = vector * MSIX_ENTRY_SIZE + MSIX_VECTOR_CTRL;
+        int was_masked = msix_is_masked(dev, vector);
         dev->msix_table_page[offset] |= MSIX_VECTOR_MASK;
+        if (was_masked != msix_is_masked(dev, vector) &&
+            dev->msix_mask_notifier && dev->msix_mask_notifier_opaque[vector]) {
+            r = dev->msix_mask_notifier(dev, vector,
+                                        dev->msix_mask_notifier_opaque[vector],
+                                        msix_is_masked(dev, vector));
+            assert(r >= 0);
+        }
     }
 }
 
@@ -382,6 +397,9 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
                                             sizeof *dev->msix_irq_entries);
     }
 #endif
+    dev->msix_mask_notifier_opaque =
+        qemu_mallocz(nentries * sizeof *dev->msix_mask_notifier_opaque);
+    dev->msix_mask_notifier = NULL;
     dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                         sizeof *dev->msix_entry_used);
 
@@ -444,6 +462,8 @@ int msix_uninit(PCIDevice *dev)
     dev->msix_entry_used = NULL;
     qemu_free(dev->msix_irq_entries);
     dev->msix_irq_entries = NULL;
+    qemu_free(dev->msix_mask_notifier_opaque);
+    dev->msix_mask_notifier_opaque = NULL;
     dev->cap_present &= ~QEMU_PCI_CAP_MSIX;
     return 0;
 }
@@ -587,3 +607,17 @@ void msix_unuse_all_vectors(PCIDevice *dev)
         return;
     msix_free_irq_entries(dev);
 }
+
+int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque)
+{
+    int r = 0;
+    if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
+        return 0;
+
+    if (dev->msix_mask_notifier)
+        r = dev->msix_mask_notifier(dev, vector, opaque,
+                                    msix_is_masked(dev, vector));
+    if (r >= 0)
+        dev->msix_mask_notifier_opaque[vector] = opaque;
+    return r;
+}
diff --git a/hw/msix.h b/hw/msix.h
index a9f7993..f167231 100644
--- a/hw/msix.h
+++ b/hw/msix.h
@@ -33,4 +33,5 @@ void msix_reset(PCIDevice *dev);
 
 extern int msix_supported;
 
+int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque);
 #endif
diff --git a/hw/pci.h b/hw/pci.h
index c9e9d56..a4a0fe9 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -137,6 +137,9 @@ enum {
 #define PCI_CAPABILITY_CONFIG_MSI_LENGTH 0x10
 #define PCI_CAPABILITY_CONFIG_MSIX_LENGTH 0x10
 
+typedef int (*msix_mask_notifier_func)(PCIDevice *, unsigned vector,
+				       void *opaque, int masked);
+
 struct PCIDevice {
     DeviceState qdev;
     /* PCI config space */
@@ -202,6 +205,9 @@ struct PCIDevice {
 
     struct kvm_irq_routing_entry *msix_irq_entries;
 
+    void **msix_mask_notifier_opaque;
+    msix_mask_notifier_func msix_mask_notifier;
+
     /* Device capability configuration space */
     struct {
         int supported;
-- 
1.6.6.144.g5c3af


  parent reply	other threads:[~2010-02-04 15:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1265297173.git.mst@redhat.com>
2010-02-04 15:27 ` [PATCH 01/20] exec: memory notifiers Michael S. Tsirkin
2010-02-04 15:27 ` [PATCH 02/20] kvm: move kvm_set_phys_mem around Michael S. Tsirkin
2010-02-04 15:27 ` [PATCH 03/20] kvm: move kvm to use memory notifiers Michael S. Tsirkin
2010-02-04 15:27 ` [PATCH 04/20] qemu-kvm: fixup after merging " Michael S. Tsirkin
2010-02-04 15:27 ` [PATCH 05/20] kvm: add API to set ioeventfd Michael S. Tsirkin
2010-02-04 15:27 ` [PATCH 06/20] notifier: event notifier implementation Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 07/20] virtio: add notifier support Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 08/20] virtio: add APIs for queue fields Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 09/20] virtio: add status change callback Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 10/20] virtio: move typedef to qemu-common Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 11/20] virtio-pci: fill in notifier support Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 12/20] tap: add interface to get device fd Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 13/20] vhost: vhost net support Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 14/20] tap: add vhost/vhostfd options Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 15/20] tap: add API to retrieve vhost net header Michael S. Tsirkin
2010-02-04 15:28 ` [PATCH 16/20] virtio-net: vhost net support Michael S. Tsirkin
2010-02-04 15:29 ` [PATCH 17/20] qemu-kvm: add vhost.h header Michael S. Tsirkin
2010-02-04 15:29 ` [PATCH 18/20] kvm: irqfd support Michael S. Tsirkin
2010-02-04 15:29 ` Michael S. Tsirkin [this message]
2010-02-04 15:29 ` [PATCH 20/20] virtio-pci: " Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100204152912.GT8461@redhat.com \
    --to=mst@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.