From patchwork Mon Aug 5 13:17:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 2838684 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E65B7BF535 for ; Mon, 5 Aug 2013 13:19:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BEA8F201A4 for ; Mon, 5 Aug 2013 13:19:46 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C2112013A for ; Mon, 5 Aug 2013 13:19:45 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6Kgn-0003Lp-Rf; Mon, 05 Aug 2013 13:19:10 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6Kgd-0002lT-8n; Mon, 05 Aug 2013 13:18:59 +0000 Received: from mail-wg0-f41.google.com ([74.125.82.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6KgG-0002fu-Kr for linux-arm-kernel@lists.infradead.org; Mon, 05 Aug 2013 13:18:41 +0000 Received: by mail-wg0-f41.google.com with SMTP id l18so1306603wgh.2 for ; Mon, 05 Aug 2013 06:18:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=cChDU8cY6jqdPbQ3U4+5UrXtXoN/OgZxBhwfAUM2Cvc=; b=PEvGvzNMl+LvHw0zPktmqm5zVhIU9TbrEYmyWApUX2/tKSbEGsMvVtNIoUjs/HO8C6 kaONFEVaVOBpgGcXDheqdR8QmzrC47o8mRF8MyFsmFBe0x1Bt4aSbtOwuvLyMaI0w84K qvoCD8LJv6AA7XRckseaHSCYLLjRBMBokknS3knCN570ojTlEAPMxu0r4vSnp9QyIkPX uUDWCFMLzwkxe5Ovaz+e71Sr3fZxbQPXiaf7IYpyEwhyIakyVNgcfLiV2NWTfaP7qMY2 C6LJV+9k/bKBt415sACufsX5MUo/4PyPSA4IHh1Xeko3kxm1OekuN+6DukD2W5JVqUV4 i+/A== X-Received: by 10.194.243.101 with SMTP id wx5mr13137906wjc.49.1375708693146; Mon, 05 Aug 2013 06:18:13 -0700 (PDT) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id lp4sm18736449wic.2.2013.08.05.06.18.10 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 06:18:12 -0700 (PDT) From: Antonios Motakis To: linux-arm-kernel@lists.infradead.org, alex.williamson@redhat.com Subject: [PATCH 3/3] Return info for device and its memory regions and interrupts Date: Mon, 5 Aug 2013 15:17:12 +0200 Message-Id: <1375708632-26356-4-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1375708632-26356-1-git-send-email-a.motakis@virtualopensystems.com> References: <1375708632-26356-1-git-send-email-a.motakis@virtualopensystems.com> X-Gm-Message-State: ALoCoQl+dSRe+1XLVn6STKpOuSRyivQdlY+OXPMYuUyuCQYaxz42ps+t2IgjNOKvzG8oXVi0VMg2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130805_091836_962401_B6EDD27A X-CRM114-Status: GOOD ( 14.87 ) X-Spam-Score: -2.6 (--) Cc: linux-samsung-soc@vger.kernel.org, kvm@vger.kernel.org, agraf@suse.de, B08248@freescale.com, iommu@lists.linux-foundation.org, Antonios Motakis , kvmarm@lists.cs.columbia.edu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 A VFIO userspace driver will start by opening the VFIO device that corresponds to an IOMMU group, and will use the ioctl interface to get the basic device info, such as number of memory regions and interrupts, and their properties. This patch implements the IOCTLs: - VFIO_DEVICE_GET_INFO - VFIO_DEVICE_GET_REGION_INFO - VFIO_DEVICE_GET_IRQ_INFO Signed-off-by: Antonios Motakis --- drivers/vfio/vfio_dt.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/vfio_dt.c b/drivers/vfio/vfio_dt.c index ad4d31d..817c552 100644 --- a/drivers/vfio/vfio_dt.c +++ b/drivers/vfio/vfio_dt.c @@ -28,6 +28,10 @@ #include #include #include +#include +#include +#include +#include #define DRIVER_VERSION "0.1" #define DRIVER_AUTHOR "Antonios Motakis " @@ -54,10 +58,13 @@ static long vfio_dt_ioctl(void *device_data, unsigned int cmd, unsigned long arg) { struct vfio_dt_device *vdev = device_data; + struct device_node *of_node = vdev->pdev->dev.of_node; unsigned long minsz; if (cmd == VFIO_DEVICE_GET_INFO) { struct vfio_device_info info; + struct resource res; + int cnt = 0; minsz = offsetofend(struct vfio_device_info, num_irqs); @@ -68,18 +75,57 @@ static long vfio_dt_ioctl(void *device_data, return -EINVAL; info.flags = VFIO_DEVICE_FLAGS_DT; - info.num_regions = 0; - info.num_irqs = 0; + + while (!of_address_to_resource(of_node, cnt, &res)) + cnt++; + + info.num_regions = cnt; + + info.num_irqs = of_irq_count(of_node); return copy_to_user((void __user *)arg, &info, minsz); - } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) - return -EINVAL; + } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) { + struct vfio_region_info info; + struct resource res; - else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) - return -EINVAL; + minsz = offsetofend(struct vfio_region_info, offset); + + if (copy_from_user(&info, (void __user *)arg, minsz)) + return -EFAULT; + + if (info.argsz < minsz) + return -EINVAL; + + if(of_address_to_resource(of_node, info.index, &res)) + return -EINVAL; + + info.offset = res.start; /* map phys addr with offset */ + info.size = resource_size(&res); + info.flags = 0; + + return copy_to_user((void __user *)arg, &info, minsz); + + } else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) { + struct vfio_irq_info info; + struct resource res; + + minsz = offsetofend(struct vfio_irq_info, count); + + if (copy_from_user(&info, (void __user *)arg, minsz)) + return -EFAULT; + + if (info.argsz < minsz) + return -EINVAL; + + of_irq_to_resource(of_node, info.index, &res); + + info.flags = 0; + info.count = 1; + + return copy_to_user((void __user *)arg, &info, minsz); - else if (cmd == VFIO_DEVICE_SET_IRQS) + } else if (cmd == VFIO_DEVICE_SET_IRQS) return -EINVAL; else if (cmd == VFIO_DEVICE_RESET)