From df72a843aaff4211ffb98d66ff486947fda7bfca Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Fri, 2 May 2014 16:58:33 -0500 Subject: [PATCH 01/26] Introduce range.h RH-Author: Max Reitz Message-id: <1399049936-13496-2-git-send-email-mreitz@redhat.com> Patchwork-id: 58647 O-Subject: [RHEL-6.6 qemu-kvm PATCH v3 01/24] Introduce range.h Bugzilla: 1004420 RH-Acked-by: Laszlo Ersek RH-Acked-by: Kevin Wolf RH-Acked-by: Stefan Hajnoczi From: Blue Swirl BZ: 1004420 Extract range functions from pci.h. These will be used by later patches by non-PCI devices. Adjust current users. Signed-off-by: Blue Swirl (cherry picked from commit bf1b00712375bea65f2254dea8281fa646eebbd5) Conflicts: hw/acpi_piix4.c hw/msix.c hw/pci.c hw/vhost.c hw/dataplane/hostmem.c hw/device-assignment.c hw/acpi_piix4.c does not exist downstream. In contrast, hw/dataplan/hostmem.c and hw/device-assignment.c have to include range.h (which was not part of the upstream patch). The other conflicts are contextual. Signed-off-by: Max Reitz --- hw/dataplane/hostmem.c | 2 +- hw/device-assignment.c | 2 +- hw/msix.c | 1 + hw/pci.c | 1 + hw/pci.h | 29 ----------------------------- hw/piix_pci.c | 1 + hw/vhost.c | 3 +-- range.h | 29 +++++++++++++++++++++++++++++ 8 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 range.h Signed-off-by: Jeff E. Nelson --- hw/dataplane/hostmem.c | 2 +- hw/device-assignment.c | 2 +- hw/msix.c | 1 + hw/pci.c | 1 + hw/pci.h | 29 ----------------------------- hw/piix_pci.c | 1 + hw/vhost.c | 3 +-- range.h | 29 +++++++++++++++++++++++++++++ 8 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 range.h diff --git a/hw/dataplane/hostmem.c b/hw/dataplane/hostmem.c index 844db97..ad073fc 100644 --- a/hw/dataplane/hostmem.c +++ b/hw/dataplane/hostmem.c @@ -12,9 +12,9 @@ */ #include -#include "hw/pci.h" /* for range_*() helper functions */ #include "hw/vhost.h" #include "hostmem.h" +#include "range.h" /** * Map guest physical address to host pointer diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 3519d2a..e9fa3e0 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -38,7 +38,7 @@ #include "device-assignment.h" #include "loader.h" #include "monitor.h" -/* #include "range.h" */ +#include "range.h" #include #include "sysemu.h" diff --git a/hw/msix.c b/hw/msix.c index 2586de8..363a3e2 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -14,6 +14,7 @@ #include "hw.h" #include "msix.h" #include "pci.h" +#include "range.h" #define QEMU_KVM_NO_CPU #include "qemu-kvm.h" diff --git a/hw/pci.c b/hw/pci.c index e68b4ef..45c5974 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -30,6 +30,7 @@ #include "qemu-kvm.h" #include "hw/pc.h" #include "device-assignment.h" +#include "range.h" //#define DEBUG_PCI #ifdef DEBUG_PCI diff --git a/hw/pci.h b/hw/pci.h index 8be7d98..fe5a2da 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -383,33 +383,4 @@ static inline uint32_t pci_config_size(PCIDevice *d) return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : PCI_CONFIG_SPACE_SIZE; } -/* These are not pci specific. Should move into a separate header. - * Only pci.c uses them, so keep them here for now. - */ - -/* Get last byte of a range from offset + length. - * Undefined for ranges that wrap around 0. */ -static inline uint64_t range_get_last(uint64_t offset, uint64_t len) -{ - return offset + len - 1; -} - -/* Check whether a given range covers a given byte. */ -static inline int range_covers_byte(uint64_t offset, uint64_t len, - uint64_t byte) -{ - return offset <= byte && byte <= range_get_last(offset, len); -} - -/* Check whether 2 given ranges overlap. - * Undefined if ranges that wrap around 0. */ -static inline int ranges_overlap(uint64_t first1, uint64_t len1, - uint64_t first2, uint64_t len2) -{ - uint64_t last1 = range_get_last(first1, len1); - uint64_t last2 = range_get_last(first2, len2); - - return !(last2 < first1 || last1 < first2); -} - #endif diff --git a/hw/piix_pci.c b/hw/piix_pci.c index 9660f37..afe4092 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -28,6 +28,7 @@ #include "pci_host.h" #include "isa.h" #include "sysbus.h" +#include "range.h" #include "qemu-kvm.h" diff --git a/hw/vhost.c b/hw/vhost.c index 6e1b492..a342852 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -15,8 +15,7 @@ #include #include "vhost.h" #include "hw/hw.h" -/* For range_get_last */ -#include "pci.h" +#include "range.h" static void vhost_dev_sync_region(struct vhost_dev *dev, uint64_t mfirst, uint64_t mlast, diff --git a/range.h b/range.h new file mode 100644 index 0000000..3502372 --- /dev/null +++ b/range.h @@ -0,0 +1,29 @@ +#ifndef QEMU_RANGE_H +#define QEMU_RANGE_H + +/* Get last byte of a range from offset + length. + * Undefined for ranges that wrap around 0. */ +static inline uint64_t range_get_last(uint64_t offset, uint64_t len) +{ + return offset + len - 1; +} + +/* Check whether a given range covers a given byte. */ +static inline int range_covers_byte(uint64_t offset, uint64_t len, + uint64_t byte) +{ + return offset <= byte && byte <= range_get_last(offset, len); +} + +/* Check whether 2 given ranges overlap. + * Undefined if ranges that wrap around 0. */ +static inline int ranges_overlap(uint64_t first1, uint64_t len1, + uint64_t first2, uint64_t len2) +{ + uint64_t last1 = range_get_last(first1, len1); + uint64_t last2 = range_get_last(first2, len2); + + return !(last2 < first1 || last1 < first2); +} + +#endif -- 1.7.1