From patchwork Thu May 26 06:42:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 819682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4Q6gsVS024664 for ; Thu, 26 May 2011 06:42:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754443Ab1EZGmr (ORCPT ); Thu, 26 May 2011 02:42:47 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:62368 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753770Ab1EZGmq (ORCPT ); Thu, 26 May 2011 02:42:46 -0400 Received: by wya21 with SMTP id 21so249400wya.19 for ; Wed, 25 May 2011 23:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=4lokQFLbH36vwRcj0mU9MzikAmA46dUypdmHp1vgK38=; b=uF8M2jpyy/se+1DsK8+XSDzYSeZ3ihv/MvOCRLI3VUrM7g6v7XAuPBLXqqRXJbt56P dwr79rB3bMbnQFR0g4H7tgtGeHKq41b4fBCnmMlkoKsaZo9EXMofKoJkSf0yIi/kZyTe ItM+7MKzalW9hmwHVrW5NiO+rDpi+3Dysyvlg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=pIJwPt5jIO86ZORQmhohwpPi9tttBqiGH77fhayp0RVO4Q1ijSUD2t0+NhPe+1dZLu QgZ65FkNo5X0kbKNDJ8esn/LLO4miBQJ9/+0SzbT7yYhUgN0hD8YHutDPAunRI0s2poK +IYo1j0LzILV7pEr3yYvpdhLYRQ+Rnm+xCCT0= Received: by 10.216.65.18 with SMTP id e18mr5538331wed.23.1306392165325; Wed, 25 May 2011 23:42:45 -0700 (PDT) Received: from localhost.localdomain ([109.66.201.145]) by mx.google.com with ESMTPS id d19sm243507wbh.8.2011.05.25.23.42.43 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 May 2011 23:42:44 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: john@jfloren.net, kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH v2 1/8] kvm tools: Add optional parameter used in ioport callbacks Date: Thu, 26 May 2011 09:42:08 +0300 Message-Id: <1306392135-16993-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 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, 26 May 2011 06:42:54 +0000 (UTC) Allow specifying an optional parameter when registering an ioport range. The callback functions provided by the registering module will be called with the same parameter. This may be used to keep context during callbacks on IO operations. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/ioport.h | 3 ++ tools/kvm/ioport.c | 54 +++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h index 8253938..2a8d74d 100644 --- a/tools/kvm/include/kvm/ioport.h +++ b/tools/kvm/include/kvm/ioport.h @@ -25,11 +25,14 @@ struct kvm; struct ioport_operations { bool (*io_in)(struct kvm *kvm, u16 port, void *data, int size, u32 count); bool (*io_out)(struct kvm *kvm, u16 port, void *data, int size, u32 count); + bool (*io_in_param)(struct kvm *kvm, u16 port, void *data, int size, u32 count, void *param); + bool (*io_out_param)(struct kvm *kvm, u16 port, void *data, int size, u32 count, void *param); }; void ioport__setup_legacy(void); void ioport__register(u16 port, struct ioport_operations *ops, int count); +void ioport__register_param(u16 port, struct ioport_operations *ops, int count, void *param); static inline u8 ioport__read8(u8 *data) { diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c index 1f13960..159d089 100644 --- a/tools/kvm/ioport.c +++ b/tools/kvm/ioport.c @@ -18,6 +18,7 @@ struct ioport_entry { struct rb_int_node node; struct ioport_operations *ops; + void *param; }; static struct rb_root ioport_tree = RB_ROOT; @@ -89,6 +90,29 @@ void ioport__register(u16 port, struct ioport_operations *ops, int count) ioport_insert(&ioport_tree, entry); } +void ioport__register_param(u16 port, struct ioport_operations *ops, int count, void *param) +{ + struct ioport_entry *entry; + + entry = ioport_search(&ioport_tree, port); + if (entry) { + pr_warning("ioport re-registered: %x", port); + rb_int_erase(&ioport_tree, &entry->node); + } + + entry = malloc(sizeof(*entry)); + if (entry == NULL) + die("Failed allocating new ioport entry"); + + *entry = (struct ioport_entry) { + .node = RB_INT_INIT(port, port + count), + .ops = ops, + .param = param, + }; + + ioport_insert(&ioport_tree, entry); +} + static const char *to_direction(int direction) { if (direction == KVM_EXIT_IO_IN) @@ -105,30 +129,32 @@ static void ioport_error(u16 port, void *data, int direction, int size, u32 coun bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count) { struct ioport_operations *ops; - bool ret; + bool ret = false; struct ioport_entry *entry; + void *param; entry = ioport_search(&ioport_tree, port); if (!entry) goto error; - ops = entry->ops; + ops = entry->ops; + param = entry->param; if (direction == KVM_EXIT_IO_IN) { - if (!ops->io_in) - goto error; - - ret = ops->io_in(kvm, port, data, size, count); - if (!ret) - goto error; + if (!param && ops->io_in) + ret = ops->io_in(kvm, port, data, size, count); + if (param && ops->io_in_param) + ret = ops->io_in_param(kvm, port, data, size, count, param); } else { - if (!ops->io_out) - goto error; - - ret = ops->io_out(kvm, port, data, size, count); - if (!ret) - goto error; + if (!param && ops->io_out) + ret = ops->io_out(kvm, port, data, size, count); + if (param && ops->io_out_param) + ret = ops->io_out_param(kvm, port, data, size, count, param); } + + if (!ret) + goto error; + return true; error: if (ioport_debug)