From patchwork Fri Mar 18 03:27:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 8616001 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 583B7C0553 for ; Fri, 18 Mar 2016 03:28:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB7B420392 for ; Fri, 18 Mar 2016 03:28:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C6C6A2038F for ; Fri, 18 Mar 2016 03:28:21 +0000 (UTC) Received: from localhost ([::1]:41277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agl5J-0006Nm-3Y for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 23:28:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agl53-0006Fk-4H for qemu-devel@nongnu.org; Thu, 17 Mar 2016 23:28:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agl52-0000wR-BR for qemu-devel@nongnu.org; Thu, 17 Mar 2016 23:28:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41235) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agl4y-0000vD-5D; Thu, 17 Mar 2016 23:28:00 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id CD30A141D; Fri, 18 Mar 2016 03:27:59 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-7-63.pek2.redhat.com [10.72.7.63]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2I3Rce5023061; Thu, 17 Mar 2016 23:27:56 -0400 From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 18 Mar 2016 11:27:33 +0800 Message-Id: <1458271654-23706-5-git-send-email-peterx@redhat.com> In-Reply-To: <1458271654-23706-1-git-send-email-peterx@redhat.com> References: <1458271654-23706-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: wei@redhat.com, peter.maydell@linaro.org, drjones@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, peterx@redhat.com, abologna@redhat.com, qemu-arm@nongnu.org Subject: [Qemu-devel] [PATCH v5 4/5] kvm: add kvm_support_device() helper function 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This can be used when probing whether KVM support specific device. Here, a raw vmfd is used. Signed-off-by: Peter Xu --- include/sysemu/kvm.h | 9 +++++++++ kvm-all.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 6695fa7..8738fa1 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -306,6 +306,15 @@ void kvm_device_access(int fd, int group, uint64_t attr, */ int kvm_create_device(KVMState *s, uint64_t type, bool test); +/** + * kvm_support_device - probe whether KVM support specific device + * + * @vmfd: The fd handler for VM + * @type: type of device + * + * @return: true if supported, otherwise false. + */ +bool kvm_support_device(int vmfd, uint64_t type); /* Arch specific hooks */ diff --git a/kvm-all.c b/kvm-all.c index 44c0464..77deccc 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -2339,6 +2339,21 @@ int kvm_create_device(KVMState *s, uint64_t type, bool test) return test ? 0 : create_dev.fd; } +bool kvm_support_device(int vmfd, uint64_t type) +{ + struct kvm_create_device create_dev = { + .type = type, + .fd = -1, + .flags = KVM_CREATE_DEVICE_TEST, + }; + + if (ioctl(vmfd, KVM_CHECK_EXTENSION, KVM_CAP_DEVICE_CTRL) <= 0) { + return false; + } + + return (ioctl(vmfd, KVM_CREATE_DEVICE, &create_dev) >= 0); +} + int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source) { struct kvm_one_reg reg;