From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=40449 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PB4z8-0000dj-46 for qemu-devel@nongnu.org; Wed, 27 Oct 2010 08:21:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PB4xC-0002Gj-GF for qemu-devel@nongnu.org; Wed, 27 Oct 2010 08:19:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PB4xC-0002Ga-8d for qemu-devel@nongnu.org; Wed, 27 Oct 2010 08:18:06 -0400 Date: Wed, 27 Oct 2010 16:17:37 +0200 From: "Michael S. Tsirkin" Message-ID: <20101027141737.GA3713@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] msi: simplify range checks List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: yamahata@valinux.co.jp, qemu-devel@nongnu.org config write handlers should be idempotent. So no need for complex range checks: a simple one checking that we are touching the relevant capability will do. Signed-off-by: Michael S. Tsirkin --- How does the below look? hw/msi.c | 46 +++++++++++++++++++++------------------------- 1 files changed, 21 insertions(+), 25 deletions(-) diff --git a/hw/msi.c b/hw/msi.c index a949d82..016e7a4 100644 --- a/hw/msi.c +++ b/hw/msi.c @@ -257,34 +257,29 @@ void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len) uint32_t pending; int i; -#ifdef MSI_DEBUG - if (ranges_overlap(addr, len, dev->msi_cap, msi_cap_sizeof(flags))) { - MSI_DEV_PRINTF(dev, "addr 0x%"PRIx32" val 0x%"PRIx32" len %d\n", - addr, val, len); - MSI_DEV_PRINTF(dev, "ctrl: 0x%"PRIx16" address: 0x%"PRIx32, - flags, - pci_get_long(dev->config + msi_address_lo_off(dev))); - if (msi64bit) { - fprintf(stderr, " addrss-hi: 0x%"PRIx32, - pci_get_long(dev->config + msi_address_hi_off(dev))); - } - fprintf(stderr, " data: 0x%"PRIx16, - pci_get_word(dev->config + msi_data_off(dev, msi64bit))); - if (flags & PCI_MSI_FLAGS_MASKBIT) { - fprintf(stderr, " mask 0x%"PRIx32" pending 0x%"PRIx32, - pci_get_long(dev->config + msi_mask_off(dev, msi64bit)), - pci_get_long(dev->config + msi_pending_off(dev, msi64bit))); - } - fprintf(stderr, "\n"); + if (!ranges_overlap(addr, len, dev->msi_cap, msi_cap_sizeof(flags))) { + return; } -#endif - /* Are we modified? */ - if (!(ranges_overlap(addr, len, msi_flags_off(dev), 2) || - (msi_per_vector_mask && - ranges_overlap(addr, len, msi_mask_off(dev, msi64bit), 4)))) { - return; +#ifdef MSI_DEBUG + MSI_DEV_PRINTF(dev, "addr 0x%"PRIx32" val 0x%"PRIx32" len %d\n", + addr, val, len); + MSI_DEV_PRINTF(dev, "ctrl: 0x%"PRIx16" address: 0x%"PRIx32, + flags, + pci_get_long(dev->config + msi_address_lo_off(dev))); + if (msi64bit) { + fprintf(stderr, " addrss-hi: 0x%"PRIx32, + pci_get_long(dev->config + msi_address_hi_off(dev))); } + fprintf(stderr, " data: 0x%"PRIx16, + pci_get_word(dev->config + msi_data_off(dev, msi64bit))); + if (flags & PCI_MSI_FLAGS_MASKBIT) { + fprintf(stderr, " mask 0x%"PRIx32" pending 0x%"PRIx32, + pci_get_long(dev->config + msi_mask_off(dev, msi64bit)), + pci_get_long(dev->config + msi_pending_off(dev, msi64bit))); + } + fprintf(stderr, "\n"); +#endif if (!(flags & PCI_MSI_FLAGS_ENABLE)) { return; -- 1.7.3.2.91.g446ac