[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/23] pci: add helper functions for pci config writ
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH 18/23] pci: add helper functions for pci config write function. |
Date: |
Mon, 5 Oct 2009 19:06:58 +0900 |
add helper functions for pci config write function to check
if its configuration space is changed.
Those function will be used later and generic enough for specific
pci device to use.
Signed-off-by: Isaku Yamahata <address@hidden>
---
hw/pci.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/hw/pci.h b/hw/pci.h
index 1f402d2..0ea08b7 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -393,6 +393,65 @@ static inline uint32_t pcie_config_size(PCIDevice *d)
return pci_is_pcie(d)? PCIE_CONFIG_SPACE_SIZE: PCI_CONFIG_SPACE_SIZE;
}
+struct pci_config_update {
+ PCIDevice *d;
+ uint32_t addr;
+ uint32_t val;
+ int len;
+
+ uint8_t orig[4];
+};
+
+static inline void pci_write_config_init(struct pci_config_update *update,
+ PCIDevice *d,
+ uint32_t addr, uint32_t val, int len)
+{
+ assert(len == 1 || len == 2 || len == 4);
+
+ update->d = d;
+ update->addr = addr;
+ update->val = val;
+ update->len = len;
+ memcpy(update->orig, &d->config[addr], len);
+}
+
+static inline void pci_write_config_update(struct pci_config_update *update)
+{
+ PCIDevice *d = update->d;
+ uint32_t addr = update->addr;
+ uint32_t val = update->val;
+ uint32_t config_size = pcie_config_size(d);
+ int i;
+
+ for(i = 0; i < update->len && addr < config_size; val >>= 8, ++i, ++addr) {
+ uint8_t wmask = d->wmask[addr];
+ d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask);
+ }
+}
+
+static inline int pci_config_changed(const struct pci_config_update *update,
+ uint32_t base, uint32_t end)
+{
+ uint32_t low = MAX(update->addr, base);
+ uint32_t high = MIN(update->addr + update->len, end);
+
+ /* Check if [addr, addr + len) intersects [base, end).
+ The intersection is [low, high), so see if it's empty or not */
+ if (low >= high)
+ return 0;
+
+ return memcmp(update->orig + (low - update->addr),
+ update->d->config + low,
+ high - low);
+}
+
+/* for convinience not to type symbol constant twice */
+static inline int pci_config_changed_with_size(
+ const struct pci_config_update *update, uint32_t base, uint32_t size)
+{
+ return pci_config_changed(update, base, base + size);
+}
+
/* lsi53c895a.c */
#define LSI_MAX_DEVS 7
--
1.6.0.2
- [Qemu-devel] Re: [PATCH 22/23] pci: initialize wmask according to pci header type., (continued)
- [Qemu-devel] [PATCH 06/23] pci: define a constant to represent a unmapped bar and use it., Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 08/23] pci: use helper functions to access pci config space., Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 07/23] pci: helper functions to access PCIDevice::config, Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 21/23] pci/brdige: qdevfy and initialize secondary bus and subordinate bus., Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 23/23] pci/monitor: print out bridge's filtering values and so on., Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 04/23] pci: use the symbolic constant, PCI_ROM_ADDRESS_ENABLE instead of 1., Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 18/23] pci: add helper functions for pci config write function.,
Isaku Yamahata <=
- [Qemu-devel] [PATCH 09/23] pci: introduce pcibus_t to represent pci bus address/size instead of uint32_t, Isaku Yamahata, 2009/10/05
- [Qemu-devel] [PATCH 19/23] pci: use helper function in pci_default_write_config(), Isaku Yamahata, 2009/10/05
- [Qemu-devel] Re: [PATCH v4 00/23] pci: various pci clean up and pci express support., Michael S. Tsirkin, 2009/10/05
- [Qemu-devel] [PATCH 16/23] pci: pcie host and mmcfg support., Isaku Yamahata, 2009/10/05
- [Qemu-devel] Re: [PATCH 16/23] pci: pcie host and mmcfg support., Michael S. Tsirkin, 2009/10/05