From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjARc-0000N1-NT for qemu-devel@nongnu.org; Sun, 02 Jun 2013 11:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjARb-0000Os-QV for qemu-devel@nongnu.org; Sun, 02 Jun 2013 11:43:44 -0400 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:39769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjARb-0000Oj-Kj for qemu-devel@nongnu.org; Sun, 02 Jun 2013 11:43:43 -0400 Received: by mail-wi0-f182.google.com with SMTP id c10so1958359wiw.9 for ; Sun, 02 Jun 2013 08:43:42 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Sun, 2 Jun 2013 17:43:19 +0200 Message-Id: <1370187812-13191-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1370187812-13191-1-git-send-email-pbonzini@redhat.com> References: <1370187812-13191-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 02/15] memory: add ref/unref List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Liu Ping Fan , jan.kiszka@siemens.com Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 30 ++++++++++++++++++++++++++++++ memory.c | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 457a53c..71df1e6 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -268,6 +268,36 @@ struct MemoryListener { void memory_region_init(MemoryRegion *mr, const char *name, uint64_t size); + +/** + * memory_region_ref: Add 1 to a memory region's reference count + * + * Whenever memory regions are accessed outside the BQL, they need to be + * preserved against hot-unplug. MemoryRegions actually do not have their + * own reference count; they piggyback on a QOM object, their "owner". + * This function adds a reference to the owner. + * + * All MemoryRegions must have an owner if they can disappear, even if the + * device they belong to operates exclusively under the BQL. This is because + * the region could be returned at any time by memory_region_find, and this + * is usually under guest control. + * + * @mr: the #MemoryRegion + */ +void memory_region_ref(MemoryRegion *mr); + +/** + * memory_region_unref: Remove 1 to a memory region's reference count + * + * Whenever memory regions are accessed outside the BQL, they need to be + * preserved against hot-unplug. MemoryRegions actually do not have their + * own reference count; they piggyback on a QOM object, their "owner". + * This function removes a reference to the owner and possibly destroys it. + * + * @mr: the #MemoryRegion + */ +void memory_region_unref(MemoryRegion *mr); + /** * memory_region_init_io: Initialize an I/O memory region. * diff --git a/memory.c b/memory.c index e855105..28613d6 100644 --- a/memory.c +++ b/memory.c @@ -1113,6 +1113,20 @@ void memory_region_set_owner(MemoryRegion *mr, } } +void memory_region_ref(MemoryRegion *mr) +{ + if (mr && mr->owner) { + object_ref(mr->owner); + } +} + +void memory_region_unref(MemoryRegion *mr) +{ + if (mr && mr->owner) { + object_unref(mr->owner); + } +} + uint64_t memory_region_size(MemoryRegion *mr) { if (int128_eq(mr->size, int128_2_64())) { -- 1.8.1.4