From patchwork Fri May 16 01:52:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 349397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 371AD140096 for ; Fri, 16 May 2014 11:55:43 +1000 (EST) Received: from localhost ([::1]:32947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wl7N7-0005BZ-01 for incoming@patchwork.ozlabs.org; Thu, 15 May 2014 21:55:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wl7Me-0004QU-KR for qemu-devel@nongnu.org; Thu, 15 May 2014 21:55:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wl7MY-0006ub-DY for qemu-devel@nongnu.org; Thu, 15 May 2014 21:55:12 -0400 Received: from mail-qg0-f51.google.com ([209.85.192.51]:55625) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wl7MY-0006tm-A4 for qemu-devel@nongnu.org; Thu, 15 May 2014 21:55:06 -0400 Received: by mail-qg0-f51.google.com with SMTP id q107so3160088qgd.24 for ; Thu, 15 May 2014 18:55:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4GrhooVsskR7mX3TszG6p311VBdQpXkG6DzYjqBP64U=; b=lLhAH6+a65bp9bV4ER7GfO2uNwZvaF5ugrggJcfdvT8es/UsDNOTPO5ZGUkqtKoYr0 CsTCvgzvisCIwJMebQ8w1Jg8FNEHFmgc9QYClxzxvzgldBK4+i7DRytxjEH99/CDsApH LvWAYaqULEdFpBkcjmDRlAqwhTw5p+5vfhA0xSFKCjTocWTcTbyH/qa0kTbXd9VoHNfF RQeQN8u9HJaGxtLZBhhJFDX8mIYB61Xix3xD6yiwkF0Nk5gsiBN5pW+AuF8E44kGl43c YFjT33i827iIVoT5iIj/R7oa7CwdKTiCdie0ZFzrt0UZFB7K1uUHKMXSbBY/82763m1b KaJg== X-Gm-Message-State: ALoCoQnXN5zL8iQivJgyTOkv7oIJguFHlzxdx8iZf4/jkfd+YFrmVQKxtu66CXQPZMqT7holyonB X-Received: by 10.224.66.74 with SMTP id m10mr18848099qai.14.1400205305906; Thu, 15 May 2014 18:55:05 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPSA id 74sm4276626qgf.32.2014.05.15.18.55.04 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 15 May 2014 18:55:05 -0700 (PDT) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Thu, 15 May 2014 18:52:49 -0700 Message-Id: X-Mailer: git-send-email 1.9.3.1.ga73a6ad In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.51 Cc: edgar.iglesias@xilinx.com, pbonzini@redhat.com, afaerber@suse.de, peter.maydell@linaro.org Subject: [Qemu-devel] [RFC v1 05/25] memory: MemoryRegion: Add contained flag 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 Rather than use the .parent == NULL check to determine if a memory region is contained, add a purpose specific boolean flag. This allows for .parent to be easily converted to a link property while preserving all the semantics of the legacy API. Signed-off-by: Peter Crosthwaite --- include/exec/memory.h | 1 + memory.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 371c066..2bb074f 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -142,6 +142,7 @@ struct MemoryRegion { void *opaque; struct Object *owner; MemoryRegion *parent; + bool contained; Int128 size; hwaddr addr; void (*destructor)(MemoryRegion *mr); diff --git a/memory.c b/memory.c index 3c32d5a..a37fdd2 100644 --- a/memory.c +++ b/memory.c @@ -1451,6 +1451,7 @@ static void do_memory_region_add_subregion_common(MemoryRegion *subregion) QTAILQ_INSERT_TAIL(&mr->subregions, subregion, subregions_link); done: memory_region_update_pending |= mr->enabled && subregion->enabled; + subregion->contained = true; memory_region_transaction_commit(); } @@ -1487,8 +1488,8 @@ void memory_region_del_subregion(MemoryRegion *mr, MemoryRegion *subregion) { memory_region_transaction_begin(); - assert(subregion->parent == mr); - subregion->parent = NULL; + assert(subregion->parent == mr && subregion->contained); + subregion->contained = false; QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link); memory_region_unref(subregion); memory_region_update_pending |= mr->enabled && subregion->enabled; @@ -1510,7 +1511,7 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr) { MemoryRegion *parent = mr->parent; - if (addr == mr->addr || !parent) { + if (addr == mr->addr || !mr->contained) { mr->addr = addr; return; } @@ -1518,7 +1519,7 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr) memory_region_transaction_begin(); memory_region_ref(mr); memory_region_del_subregion(parent, mr); - memory_region_add_subregion_common(parent, addr, mr); + do_memory_region_add_subregion_common(mr); memory_region_unref(mr); memory_region_transaction_commit(); }