From patchwork Fri Aug 23 19:41:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 269532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E9B462C009C for ; Sat, 24 Aug 2013 05:42:03 +1000 (EST) Received: from localhost ([::1]:38414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCxFC-00089U-5O for incoming@patchwork.ozlabs.org; Fri, 23 Aug 2013 15:42:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCxEb-0007wo-Qf for qemu-devel@nongnu.org; Fri, 23 Aug 2013 15:41:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCxEV-0005hV-RW for qemu-devel@nongnu.org; Fri, 23 Aug 2013 15:41:25 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:64756) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCxEV-0005hJ-IJ for qemu-devel@nongnu.org; Fri, 23 Aug 2013 15:41:19 -0400 Received: by mail-pa0-f41.google.com with SMTP id bj1so1065683pad.0 for ; Fri, 23 Aug 2013 12:41:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eIieAKz44gH22LSDwhVe6/3uDXnZduouPeVLg2W482Y=; b=evaM6KpbaXW8wlfPbBBt+VlzI9g3o+pRtlRt8vowPZPl7I2FGRabVlVqwXv1mu+yNg PPLp01xtP7PXE6b/pj4G1V+7lhZ27SDk166HE38NvSQs39zxpsfTuCsfm42XSJ3LIsRo rhU4rg4FLKuF/7pjkxeOJxJKCSQWr2fKPEVmHWS2zi6pfzzfb6umZgt0lfWJrLVRIewt WtlCHZNZ2MEvYdGIeRIYLzAT3MqfShrSsGLiNh5O51JwJnTaZU9zkLKBbNfpD899w+wT /kd67NL4tpm+PPKoET09alGv663j1/ZJenjDAfXtwxZoHUS5Quxnq33RG7UMYVLM/Y3T +RRQ== X-Gm-Message-State: ALoCoQnEuyj/yiRiX7AEXTr/MdGvfr/zwp7i0/Iww5Wb5xNUEZerv3+38H1ApRrb5XlG+Qs9mi50 X-Received: by 10.66.139.8 with SMTP id qu8mr653441pab.94.1377286878769; Fri, 23 Aug 2013 12:41:18 -0700 (PDT) Received: from localhost.localdomain (c-67-169-183-77.hsd1.ca.comcast.net. [67.169.183.77]) by mx.google.com with ESMTPSA id ib9sm1446453pbc.43.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 12:41:17 -0700 (PDT) From: Christoffer Dall To: qemu-devel@nongnu.org Date: Fri, 23 Aug 2013 12:41:01 -0700 Message-Id: <1377286862-5879-4-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1377286862-5879-1-git-send-email-christoffer.dall@linaro.org> References: <1377286862-5879-1-git-send-email-christoffer.dall@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.41 Cc: linaro-kernel@lists.linaro.org, kvmarm@lists.cs.columbia.edu, Christoffer Dall , patches@linaro.org Subject: [Qemu-devel] [PATCH 3/4] kvm: Common device control API functions 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 Introduces two simple functions: int kvm_device_ioctl(int fd, int type, ...); int kvm_create_device(KVMState *s, uint64_t type, bool test); These functions wrap the basic ioctl-based interactions with KVM in a way similar to other KVM ioctl wrappers. Signed-off-by: Christoffer Dall --- include/sysemu/kvm.h | 5 +++++ kvm-all.c | 39 +++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 3 files changed, 45 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 1e5847e..84ca5ef 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -190,6 +190,11 @@ int kvm_vm_ioctl(KVMState *s, int type, ...); int kvm_vcpu_ioctl(CPUState *cpu, int type, ...); +int kvm_device_ioctl(int fd, int type, ...); + +int kvm_create_device(KVMState *s, uint64_t type, bool test); + + /* Arch specific hooks */ extern const KVMCapabilityInfo kvm_arch_required_capabilities[]; diff --git a/kvm-all.c b/kvm-all.c index fe64f3b..957b961 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1770,6 +1770,24 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...) return ret; } +int kvm_device_ioctl(int fd, int type, ...) +{ + int ret; + void *arg; + va_list ap; + + va_start(ap, type); + arg = va_arg(ap, void *); + va_end(ap); + + trace_kvm_device_ioctl(fd, type, arg); + ret = ioctl(fd, type, arg); + if (ret == -1) { + ret = -errno; + } + return ret; +} + int kvm_has_sync_mmu(void) { return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU); @@ -2064,3 +2082,24 @@ int kvm_on_sigbus(int code, void *addr) { return kvm_arch_on_sigbus(code, addr); } + +int kvm_create_device(KVMState *s, uint64_t type, bool test) +{ + int ret; + struct kvm_create_device create_dev; + + create_dev.type = type; + create_dev.fd = -1; + create_dev.flags = (test) ? KVM_CREATE_DEVICE_TEST : 0; + + if (!kvm_check_extension(s, KVM_CAP_DEVICE_CTRL)) { + return -1; + } + + ret = kvm_vm_ioctl(s, KVM_CREATE_DEVICE, &create_dev); + if (ret) { + return ret; + } + + return (test) ? 0 : create_dev.fd; +} diff --git a/trace-events b/trace-events index 3856b5c..5372c6e 100644 --- a/trace-events +++ b/trace-events @@ -1163,6 +1163,7 @@ migrate_set_state(int new_state) "new state %d" kvm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type %d, arg %p" +kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type %d, arg %p" kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d" # memory.c