diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2019-01-11 13:35:48 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2019-01-11 13:35:48 +0000 |
| commit | e53f7796fbe71a5c7c24ffebf04b4aa9a759da36 (patch) | |
| tree | 64cad2b5700d85dcf5bf0f4091ceac2231d1872e /include/qemu/range.h | |
| parent | 291741033f611a4f0bbce3f7c9dead84ce315f96 (diff) | |
| parent | d769f0dfeeaa1554a38fedb16bb20a4b0ecf793c (diff) | |
| download | focaccia-qemu-e53f7796fbe71a5c7c24ffebf04b4aa9a759da36.tar.gz focaccia-qemu-e53f7796fbe71a5c7c24ffebf04b4aa9a759da36.zip | |
Merge remote-tracking branch 'remotes/ehabkost/tags/machine-next-pull-request' into staging
Machine queue, 2019-01-10 * Simplify GlobalProperty array declarations (Eduardo Habkost) * Deprecate cpu-add commands (Kashyap Chamarthy) * range/memory-device cleanups (David Hildenbrand) * Fix -device scsi-hd,help regression (Marc-André Lureau) * Fix crash when -global generates multiple warnings (Eduardo Habkost) # gpg: Signature made Thu 10 Jan 2019 14:28:23 GMT # gpg: using RSA key 2807936F984DC5A6 # gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" # Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF D1AA 2807 936F 984D C5A6 * remotes/ehabkost/tags/machine-next-pull-request: qom: Don't keep error value between object_property_parse() calls qdev: fix -device scsi-hd,help regression machine: Use shorter format for GlobalProperty arrays machine: Eliminate unnecessary stringify() usage spapr: Eliminate SPAPR_PCI_2_7_MMIO_WIN_SIZE macro memory-device: rewrite address assignment using ranges range: add some more functions Mention that QMP 'cpu-add' will be deprecated Update that HMP 'cpu-add' is deprecated in 4.0 qemu-deprecated.texi: Rename the HMP section Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include/qemu/range.h')
| -rw-r--r-- | include/qemu/range.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/include/qemu/range.h b/include/qemu/range.h index 7e75f4e655..ba606c6bc0 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -113,6 +113,68 @@ static inline uint64_t range_upb(Range *range) } /* + * Initialize @range to span the interval [@lob,@lob + @size - 1]. + * @size may be 0. If the range would overflow, returns -ERANGE, otherwise + * 0. + */ +static inline int QEMU_WARN_UNUSED_RESULT range_init(Range *range, uint64_t lob, + uint64_t size) +{ + if (lob + size < lob) { + return -ERANGE; + } + range->lob = lob; + range->upb = lob + size - 1; + range_invariant(range); + return 0; +} + +/* + * Initialize @range to span the interval [@lob,@lob + @size - 1]. + * @size may be 0. Range must not overflow. + */ +static inline void range_init_nofail(Range *range, uint64_t lob, uint64_t size) +{ + range->lob = lob; + range->upb = lob + size - 1; + range_invariant(range); +} + +/* + * Get the size of @range. + */ +static inline uint64_t range_size(const Range *range) +{ + return range->upb - range->lob + 1; +} + +/* + * Check if @range1 overlaps with @range2. If one of the ranges is empty, + * the result is always "false". + */ +static inline bool range_overlaps_range(const Range *range1, + const Range *range2) +{ + if (range_is_empty(range1) || range_is_empty(range2)) { + return false; + } + return !(range2->upb < range1->lob || range1->upb < range2->lob); +} + +/* + * Check if @range1 contains @range2. If one of the ranges is empty, + * the result is always "false". + */ +static inline bool range_contains_range(const Range *range1, + const Range *range2) +{ + if (range_is_empty(range1) || range_is_empty(range2)) { + return false; + } + return range1->lob <= range2->lob && range1->upb >= range2->upb; +} + +/* * Extend @range to the smallest interval that includes @extend_by, too. */ static inline void range_extend(Range *range, Range *extend_by) |