Received: from eggs.gnu.org ([208.118.235.92]:43004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZKrK-0000GG-UM for qemu-devel@nongnu.org; Mon, 06 May 2013 08:49:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZKrG-0007qV-7B for qemu-devel@nongnu.org; Mon, 06 May 2013 08:49:38 -0400 Received: from mail-vc0-f170.google.com ([209.85.220.170]:61122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZKrG-0007qP-35 for qemu-devel@nongnu.org; Mon, 06 May 2013 08:49:34 -0400 Received: by mail-vc0-f170.google.com with SMTP id gf12so3012927vcb.15 for ; Mon, 06 May 2013 05:49:33 -0700 (PDT) From: Liu Ping Fan Date: Mon, 6 May 2013 20:48:58 +0800 Message-Id: <1367844540-9024-4-git-send-email-qemulist@gmail.com> In-Reply-To: <1367844540-9024-1-git-send-email-qemulist@gmail.com> References: <1367844540-9024-1-git-send-email-qemulist@gmail.com> Subject: [Qemu-devel] [PATCH v3 3/5] memory: add ref/unref interface for MemroyRegionOps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Anthony Liguori , Jan Kiszka , Vasilis Liaskovitis , Stefan Hajnoczi , Paolo Bonzini From: Liu Ping Fan This pair of interface are optinal, except for those device which is used outside the biglock's protection for hot unplug. Currently, HostMem used by virtio-blk dataplane is outside biglock, so the RAM device should implement this. Signed-off-by: Liu Ping Fan --- include/exec/memory.h | 10 ++++++++++ memory.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9e88320..7e38fc1 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -54,6 +54,12 @@ struct MemoryRegionIORange { * Memory region callbacks */ struct MemoryRegionOps { + + /* ref/unref pair is optional; ref. + * inc refcnt of object who store MemoryRegion + */ + void (*ref)(void); + void (*unref)(void); /* Read from the memory region. @addr is relative to @mr; @size is * in bytes. */ uint64_t (*read)(void *opaque, @@ -223,6 +229,10 @@ struct MemoryListener { QTAILQ_ENTRY(MemoryListener) link; }; +/**/ +bool memory_region_ref(MemoryRegion *mr); +bool memory_region_unref(MemoryRegion *mr); + /** * memory_region_init: Initialize a memory region * diff --git a/memory.c b/memory.c index 75ca281..c29998d 100644 --- a/memory.c +++ b/memory.c @@ -786,6 +786,24 @@ static bool memory_region_wrong_endianness(MemoryRegion *mr) #endif } +bool memory_region_ref(MemoryRegion *mr) +{ + if (mr->ops && mr->ops->ref) { + mr->ops->ref(); + return true; + } + return false; +} + +bool memory_region_unref(MemoryRegion *mr) +{ + if (mr->ops && mr->ops->unref) { + mr->ops->unref(); + return true; + } + return false; +} + void memory_region_init(MemoryRegion *mr, const char *name, uint64_t size) -- 1.7.4.4