From patchwork Thu Feb 4 15:29:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 77048 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o14FWQIm020109 for ; Thu, 4 Feb 2010 15:32:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932349Ab0BDPcY (ORCPT ); Thu, 4 Feb 2010 10:32:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23784 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932290Ab0BDPcX (ORCPT ); Thu, 4 Feb 2010 10:32:23 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o14FWN9j004984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Feb 2010 10:32:23 -0500 Received: from redhat.com (vpn2-9-138.ams2.redhat.com [10.36.9.138]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o14FWLLS005961 for ; Thu, 4 Feb 2010 10:32:22 -0500 Date: Thu, 4 Feb 2010 17:29:12 +0200 From: "Michael S. Tsirkin" To: kvm@vger.kernel.org Subject: [PATCH 19/20] msix: add mask/unmask notifiers Message-ID: <20100204152912.GT8461@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Feb 2010 15:32:26 +0000 (UTC) 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;