pci: use range helper functions.
authorIsaku Yamahata <yamahata@valinux.co.jp>
Fri, 30 Oct 2009 12:21:20 +0000 (21:21 +0900)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 9 Nov 2009 14:43:10 +0000 (08:43 -0600)
clean up pci_default_write_config() by the range helper functions.

Suggested by Michael S. Tsirkin <mst@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/pci.c

index 67133b661d6f78707b31c38bcc82d40bb8fdc176..d9fd564b49e69e05a89b3e98469d700d88d28347 100644 (file)
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -699,19 +699,15 @@ uint32_t pci_default_read_config(PCIDevice *d,
 
 void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
 {
-    uint8_t orig[PCI_CONFIG_SPACE_SIZE];
     int i;
     uint32_t config_size = pci_config_size(d);
 
-    /* not efficient, but simple */
-    memcpy(orig, d->config, PCI_CONFIG_SPACE_SIZE);
     for(i = 0; i < l && addr < config_size; val >>= 8, ++i, ++addr) {
         uint8_t wmask = d->wmask[addr];
         d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask);
     }
-    if (memcmp(orig + PCI_BASE_ADDRESS_0, d->config + PCI_BASE_ADDRESS_0, 24)
-        || ((orig[PCI_COMMAND] ^ d->config[PCI_COMMAND])
-            & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
+    if (ranges_overlap(addr, l, PCI_BASE_ADDRESS_0, 24) ||
+        range_covers_byte(addr, l, PCI_COMMAND))
         pci_update_mappings(d);
 }