From patchwork Thu Jul 28 17:56:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1017432 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6SHvJOR019533 for ; Thu, 28 Jul 2011 17:57:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753866Ab1G1R5P (ORCPT ); Thu, 28 Jul 2011 13:57:15 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:55820 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753658Ab1G1R5N (ORCPT ); Thu, 28 Jul 2011 13:57:13 -0400 Received: by mail-wy0-f174.google.com with SMTP id 8so327734wyg.19 for ; Thu, 28 Jul 2011 10:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=BlRgAjUO7rOg8fNOkuFOSxA5LdZOD3IRadG/u+8+ckY=; b=skxWojOQHl/w93BfySxUs/GfiIZKOwH2MEKnEiHKtSlNsCYL5oyh59IbsNwVJs1LZ/ F4/gsvUBtKLAxRDgBTL94JbxMy4y1EpmG8d3yM3F60gjU+jm7KFLzWzBQZfuoNxQn9K0 Ue9gk5+eb/TA6kU7VgwMQZD0w0lTnDGQZqiCQ= Received: by 10.227.55.20 with SMTP id s20mr426913wbg.15.1311875832790; Thu, 28 Jul 2011 10:57:12 -0700 (PDT) Received: from localhost.localdomain (bzq-79-182-210-47.red.bezeqint.net [79.182.210.47]) by mx.google.com with ESMTPS id fp3sm1051561wbb.13.2011.07.28.10.57.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Jul 2011 10:57:12 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH v2 3/4] kvm tools: Add a void ptr to be passed to mmio callback Date: Thu, 28 Jul 2011 20:56:20 +0300 Message-Id: <1311875781-691-3-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1311875781-691-1-git-send-email-levinsasha928@gmail.com> References: <1311875781-691-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 28 Jul 2011 17:57:19 +0000 (UTC) This makes MMIO callback similar to it's PIO counterpart by passing a void* value provided in the registration to the callback function. This allows to keep context within the MMIO callback function. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/kvm.h | 2 +- tools/kvm/mmio.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index eeb55b6..5f3cbbf 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -64,7 +64,7 @@ void kvm__irq_line(struct kvm *kvm, int irq, int level); bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count); bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write); void kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr); -bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write)); +bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr), void *ptr); bool kvm__deregister_mmio(struct kvm *kvm, u64 phys_addr); void kvm__pause(void); void kvm__continue(void); diff --git a/tools/kvm/mmio.c b/tools/kvm/mmio.c index 64bef37..de7320f 100644 --- a/tools/kvm/mmio.c +++ b/tools/kvm/mmio.c @@ -14,7 +14,8 @@ struct mmio_mapping { struct rb_int_node node; - void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write); + void (*mmio_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr); + void *ptr; }; static struct rb_root mmio_tree = RB_ROOT; @@ -55,7 +56,7 @@ static const char *to_direction(u8 is_write) return "read"; } -bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write)) +bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*mmio_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr), void *ptr) { struct mmio_mapping *mmio; struct kvm_coalesced_mmio_zone zone; @@ -67,7 +68,8 @@ bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void *mmio = (struct mmio_mapping) { .node = RB_INT_INIT(phys_addr, phys_addr + phys_addr_len), - .kvm_mmio_callback_fn = kvm_mmio_callback_fn, + .mmio_fn = mmio_fn, + .ptr = ptr, }; zone = (struct kvm_coalesced_mmio_zone) { @@ -120,7 +122,7 @@ bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_ mmio = mmio_search(&mmio_tree, phys_addr, len); if (mmio) - mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write); + mmio->mmio_fn(phys_addr, data, len, is_write, mmio->ptr); else fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n", to_direction(is_write), phys_addr, len);