From patchwork Mon Sep 30 15:28:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 2966221 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E08399F88A for ; Mon, 30 Sep 2013 15:29:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A8641201C8 for ; Mon, 30 Sep 2013 15:29:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F12ED2027D for ; Mon, 30 Sep 2013 15:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756009Ab3I3P3W (ORCPT ); Mon, 30 Sep 2013 11:29:22 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:60187 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756097Ab3I3P3U (ORCPT ); Mon, 30 Sep 2013 11:29:20 -0400 Received: by mail-wg0-f53.google.com with SMTP id x12so5366444wgg.20 for ; Mon, 30 Sep 2013 08:29:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F/qVDfxs+RNZyNGS0HNTop9LuayNoCR7wgweRGbzefo=; b=VSzw0m3U7oZ4DtN24nI3AZkGBhF87gxIGgO1oN6uhjDZ9MzyH4afK2KTEbo2JoyMRq ad+EzBD5DAIj2jKGJPOMDnduyvtjpe5noZOJaK2g90k/BgPnMB/gNMJ8XzTjaYxtrYRx OKeKhfXn4aGLFV8h/m3l8k2rFFvC3aO5cfCmx0/Gv6XeITjE9VH1CKMIemNYqfcjqc/V XdcMFbsw8jfo36zIWDBkE5+hnO1sfsMJSWd04q0CP+i47NTZGfgCq7aOrFXv0HssaGkr +pAKe4pitXjSUer+/8ST1L8QKA2sT6FbZjt5Ayg5V9S1lfuZ6LLzx3y+CCUUZ6or16GG O8lg== X-Gm-Message-State: ALoCoQn6mHU8VgZtTTTbYgJkdgxL7RzAqmVg/koRQsYjVGI0JXnyG6P+YAF/I7XTggR7tBPYpf9e X-Received: by 10.195.13.45 with SMTP id ev13mr17974456wjd.20.1380554958988; Mon, 30 Sep 2013 08:29:18 -0700 (PDT) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id ey4sm2015579wic.11.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Sep 2013 08:29:18 -0700 (PDT) From: Antonios Motakis To: kvmarm@lists.cs.columbia.edu, alex.williamson@redhat.com Cc: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, kvm@vger.kernel.org, agraf@suse.de, B08248@freescale.com, tech@virtualopensystems.com, Antonios Motakis Subject: [PATCH 3/7] Return info for device and its memory regions and interrupts Date: Mon, 30 Sep 2013 17:28:39 +0200 Message-Id: <1380554923-17818-4-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380554923-17818-1-git-send-email-a.motakis@virtualopensystems.com> References: <1380554923-17818-1-git-send-email-a.motakis@virtualopensystems.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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_platform.c | 60 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/vfio_platform.c b/drivers/vfio/vfio_platform.c index b9686b0..a0abcfa 100644 --- a/drivers/vfio/vfio_platform.c +++ b/drivers/vfio/vfio_platform.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_platform_ioctl(void *device_data, unsigned int cmd, unsigned long arg) { struct vfio_platform_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_platform_ioctl(void *device_data, return -EINVAL; info.flags = VFIO_DEVICE_FLAGS_PLATFORM; - 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)