From patchwork Fri May 3 02:45:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 241140 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 C2C472C009A for ; Fri, 3 May 2013 12:47:51 +1000 (EST) Received: from localhost ([::1]:59931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UY62I-0003IL-0Z for incoming@patchwork.ozlabs.org; Thu, 02 May 2013 22:47:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UY60U-0000v2-6u for qemu-devel@nongnu.org; Thu, 02 May 2013 22:45:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UY60T-0002MD-Ce for qemu-devel@nongnu.org; Thu, 02 May 2013 22:45:58 -0400 Received: from mail-qa0-x22b.google.com ([2607:f8b0:400d:c00::22b]:58883) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UY60T-0002M5-6I for qemu-devel@nongnu.org; Thu, 02 May 2013 22:45:57 -0400 Received: by mail-qa0-f43.google.com with SMTP id bs12so142676qab.2 for ; Thu, 02 May 2013 19:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=SpDw2YuWX7CVSRrPvwTv0Ht7rF0QPIQnAsaAH4cQ1xk=; b=K8BnpC1Ag1gI48F2TH0A2y2X+fZdpJZ7Zao4jHK2FhwIT+/UlXirzPGrGB5cEywOI4 e+o/gocUhs87wjGuOi2+RfM54WTLCaDYskKq/R5G0uI9mBRhRM7czEiNb1q5NWiN/cOp s/hjSklyQTlBWw51omwvE8mVxkBGdFIw5+hd9AsGwCb/aBgbcRPQHiNq+6b+vuw7QWGC jqwo+b6dRVRnKxIw0KYLakHpEb1W6EJKgIGhLiEg0QAfv2o2K7/sPV3APKfejJ2yZotU Z4/ZEFSYfr4q6AomfHK9tgcVVq/B7MPo3tTXZeuivIYHafvCMTGObT/EaGbDE9wiFMYV z5tQ== X-Received: by 10.224.80.4 with SMTP id r4mr10628341qak.95.1367549156738; Thu, 02 May 2013 19:45:56 -0700 (PDT) Received: from localhost ([111.192.242.37]) by mx.google.com with ESMTPSA id en8sm14443612qeb.0.2013.05.02.19.45.52 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 02 May 2013 19:45:56 -0700 (PDT) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Fri, 3 May 2013 10:45:19 +0800 Message-Id: <1367549122-2948-4-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1367549122-2948-1-git-send-email-qemulist@gmail.com> References: <1367549122-2948-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::22b Cc: Peter Maydell , Anthony Liguori , Jan Kiszka , Vasilis Liaskovitis , Stefan Hajnoczi , Paolo Bonzini Subject: [Qemu-devel] [PATCH v2 3/6] memory: add ref/unref interface for MemroyRegionOps 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 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 2761668..edeb480 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)