From patchwork Mon May 13 20:01:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 243513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1A9AA2C007E for ; Tue, 14 May 2013 06:01:53 +1000 (EST) Received: from localhost ([::1]:45591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UbywR-0004w9-B3 for incoming@patchwork.ozlabs.org; Mon, 13 May 2013 16:01:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ubyvr-0004lN-RK for qemu-devel@nongnu.org; Mon, 13 May 2013 16:01:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ubyvp-0008Bg-1g for qemu-devel@nongnu.org; Mon, 13 May 2013 16:01:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ubyvo-0008BV-RB for qemu-devel@nongnu.org; Mon, 13 May 2013 16:01:12 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4DK1BjK022759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 13 May 2013 16:01:11 -0400 Received: from redhat.com (vpn-202-66.tlv.redhat.com [10.35.202.66]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r4DK18gh012762; Mon, 13 May 2013 16:01:09 -0400 Date: Mon, 13 May 2013 23:01:11 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Anthony Liguori , lersek@redhat.com, seabios@seabios.org Message-ID: <87af80d75efe782e9edb47f214e0521f50a9cf56.1368474222.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 08/13] range: add Range structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sometimes we need to pass ranges around, add a handy structure for this purpose. Signed-off-by: Michael S. Tsirkin --- include/qemu/range.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/qemu/range.h b/include/qemu/range.h index 3502372..4bcd346 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -1,6 +1,28 @@ #ifndef QEMU_RANGE_H #define QEMU_RANGE_H +#include + +/* + * Operations on 64 address ranges. + * Notes: + * - ranges must not wrap around 0, but can include the last byte ~0x0LL. + * - this can not represent a full 0 to ~0x0LL range. + */ + +/* A structure representing a range of addresses. */ +struct Range { + uint64_t begin; /* First byte of the range, or 0 if empty. */ + uint64_t end; /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */ +}; +typedef struct Range Range; + +/* verify that range is not empty and does not overlap */ +static inline bool range_valid(struct Range *range) +{ + return range->begin + 1 <= range->end; +} + /* 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)