Patchwork [19/23] pci: use helper function in pci_default_write_config()

login
register
mail settings
Submitter Isaku Yamahata
Date Oct. 5, 2009, 10:06 a.m.
Message ID <1254737223-16129-20-git-send-email-yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/34982/
State Superseded
Headers show

Comments

Isaku Yamahata - Oct. 5, 2009, 10:06 a.m.
use helper function in pci_default_write_config() to
check whether the configuration space is changed.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |   23 +++++++++--------------
 hw/pci.h |    1 +
 2 files changed, 10 insertions(+), 14 deletions(-)

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 65afbd2..b8d2f8f 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -681,21 +681,16 @@  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 = pcie_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) ||
-         memcmp(orig + PCI_ROM_ADDRESS, d->config + PCI_ROM_ADDRESS, 4))
-        || ((orig[PCI_COMMAND] ^ d->config[PCI_COMMAND])
-            & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
+    struct pci_config_update update;
+
+    pci_write_config_init(&update, d, addr, val, l);
+    pci_write_config_update(&update);
+    if (pci_config_changed(&update,
+                           PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_5 + 4) ||
+        pci_config_changed_with_size(&update, PCI_ROM_ADDRESS, 4) ||
+        pci_config_changed_with_size(&update, PCI_COMMAND, 1)) {
         pci_update_mappings(d);
+    }
 }
 
 static void pci_data_write_common(PCIDevice *pci_dev,
diff --git a/hw/pci.h b/hw/pci.h
index 0ea08b7..37c2c23 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -118,6 +118,7 @@  typedef struct PCIIORegion {
 #define  PCI_HEADER_TYPE_CARDBUS	2
 #define  PCI_HEADER_TYPE_MULTI_FUNCTION 0x80
 #define PCI_BASE_ADDRESS_0	0x10	/* 32 bits */
+#define PCI_BASE_ADDRESS_5	0x24	/* 32 bits */
 #define PCI_PRIMARY_BUS		0x18	/* Primary bus number */
 #define PCI_SECONDARY_BUS	0x19	/* Secondary bus number */
 #define PCI_SEC_STATUS		0x1e	/* Secondary status register, only bit 14 used */