From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMZzE-0001YD-4R for qemu-devel@nongnu.org; Mon, 01 Apr 2013 04:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMZzC-00037c-VY for qemu-devel@nongnu.org; Mon, 01 Apr 2013 04:21:04 -0400 Received: from mail-da0-x229.google.com ([2607:f8b0:400e:c00::229]:33802) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMZzC-00037W-Pa for qemu-devel@nongnu.org; Mon, 01 Apr 2013 04:21:02 -0400 Received: by mail-da0-f41.google.com with SMTP id w4so983746dam.0 for ; Mon, 01 Apr 2013 01:21:02 -0700 (PDT) From: Liu Ping Fan Date: Mon, 1 Apr 2013 16:20:30 +0800 Message-Id: <1364804434-7980-2-git-send-email-qemulist@gmail.com> In-Reply-To: <1364804434-7980-1-git-send-email-qemulist@gmail.com> References: <1364804434-7980-1-git-send-email-qemulist@gmail.com> Subject: [Qemu-devel] [PATCH 1/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 , Marcelo Tosatti , 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 2322732..4289e62 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -55,6 +55,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, @@ -228,6 +234,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