Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3634653pxk; Tue, 29 Sep 2020 02:05:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOS+UijXdHezYP8dCjpZ9oVj3XQQy9gyVCbwEUxs2KZJaoTRXet48suePgTPneMEcENoiF X-Received: by 2002:aa7:c3d4:: with SMTP id l20mr2134272edr.263.1601370344549; Tue, 29 Sep 2020 02:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601370344; cv=none; d=google.com; s=arc-20160816; b=ZP6yM1hiQaUmQd4LQhGHRiXwBYiisRUG57IAMTWYHVwOOjLyoprXw47z6cDpRdgZ5W ZNEkspgSzCsZVXcfSVZbRB6rkWlb4iQOA+YH7QMfckTwze0exT3VxEa25FaCjzisrvw2 hxHARXkkw7ACOinHKki2WXVeUP2VAy5eBMpZn4uDvItTd8G83OUzrYI5iKSbAWp7OZLc eWgfWzA37E3SipfJ3mTuKb27e9Zjgi7uD5yZc+VbVMXXySgIV0Vd7ciuAzXbP0fQaJ2c NnpQnciodScMWltWKpr7YeyjoOL6ShACeuuOKXOZ8EtqA2BrcTvCpdYHP8YP3v0EDqsa uL5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=4+Gb0iyPYJxfWHuBoJVnh8WDom5OHmnreyU2IfwUKMk=; b=c0jrR8uLYgNqSgQKew/8pXCY09p0L1LXsW8YBhfUBTxEuz8njL4nJRwnBgxVJuu/Ck G84hb07oYjkpr5t5hBCR57UZOtviCUHgslVFqWkSTwz8C4D8tWYvCBQXjACIPUMoWSAU EqE5nLONIzycp+KQE9Sl99tnVXNif1v2Smk/H2tHiNK6Im/3OkWK8r5keTGmmAkYctEA 3T6ytsTOS1GLlMXkurKsl8BsobYs0Q/nwui22aAeIGFtFQQQ4jLvSlWeBsfBvFIs+FKY xEiFGoz5Zh5RSwuVKBL6fusOIs4v7WMAWT98qHoDXLbou7qRd0nk850GzOj852EWs6Sc oJqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si2324522ejb.651.2020.09.29.02.05.22; Tue, 29 Sep 2020 02:05:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbgI2JEM (ORCPT + 99 others); Tue, 29 Sep 2020 05:04:12 -0400 Received: from inva020.nxp.com ([92.121.34.13]:47906 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727758AbgI2JEB (ORCPT ); Tue, 29 Sep 2020 05:04:01 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 153021A124B; Tue, 29 Sep 2020 11:03:59 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 0708E1A1249; Tue, 29 Sep 2020 11:03:59 +0200 (CEST) Received: from fsr-ub1864-111.ea.freescale.net (fsr-ub1864-111.ea.freescale.net [10.171.82.141]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id A83E02032C; Tue, 29 Sep 2020 11:03:58 +0200 (CEST) From: Diana Craciun To: alex.williamson@redhat.com, kvm@vger.kernel.org Cc: bharatb.linux@gmail.com, linux-kernel@vger.kernel.org, eric.auger@redhat.com, Diana Craciun , Bharat Bhushan Subject: [PATCH v5 07/10] vfio/fsl-mc: Add irq infrastructure for fsl-mc devices Date: Tue, 29 Sep 2020 12:03:36 +0300 Message-Id: <20200929090339.17659-8-diana.craciun@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200929090339.17659-1-diana.craciun@oss.nxp.com> References: <20200929090339.17659-1-diana.craciun@oss.nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the skeleton for interrupt support for fsl-mc devices. The interrupts are not yet functional, the functionality will be added by subsequent patches. Signed-off-by: Bharat Bhushan Signed-off-by: Diana Craciun --- drivers/vfio/fsl-mc/Makefile | 2 +- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 52 ++++++++++++++++++++++- drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 34 +++++++++++++++ drivers/vfio/fsl-mc/vfio_fsl_mc_private.h | 6 +++ 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c diff --git a/drivers/vfio/fsl-mc/Makefile b/drivers/vfio/fsl-mc/Makefile index 0c6e5d2ddaae..cad6dbf0b735 100644 --- a/drivers/vfio/fsl-mc/Makefile +++ b/drivers/vfio/fsl-mc/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) -vfio-fsl-mc-y := vfio_fsl_mc.o +vfio-fsl-mc-y := vfio_fsl_mc.o vfio_fsl_mc_intr.o obj-$(CONFIG_VFIO_FSL_MC) += vfio-fsl-mc.o diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index 548fb4d80f3f..2919e2d0041b 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c @@ -217,11 +217,55 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd, } case VFIO_DEVICE_GET_IRQ_INFO: { - return -ENOTTY; + struct vfio_irq_info info; + + minsz = offsetofend(struct vfio_irq_info, count); + if (copy_from_user(&info, (void __user *)arg, minsz)) + return -EFAULT; + + if (info.argsz < minsz) + return -EINVAL; + + if (info.index >= mc_dev->obj_desc.irq_count) + return -EINVAL; + + info.flags = VFIO_IRQ_INFO_EVENTFD; + info.count = 1; + + return copy_to_user((void __user *)arg, &info, minsz); } case VFIO_DEVICE_SET_IRQS: { - return -ENOTTY; + struct vfio_irq_set hdr; + u8 *data = NULL; + int ret = 0; + size_t data_size = 0; + + minsz = offsetofend(struct vfio_irq_set, count); + + if (copy_from_user(&hdr, (void __user *)arg, minsz)) + return -EFAULT; + + ret = vfio_set_irqs_validate_and_prepare(&hdr, mc_dev->obj_desc.irq_count, + mc_dev->obj_desc.irq_count, &data_size); + if (ret) + return ret; + + if (data_size) { + data = memdup_user((void __user *)(arg + minsz), + data_size); + if (IS_ERR(data)) + return PTR_ERR(data); + } + + mutex_lock(&vdev->igate); + ret = vfio_fsl_mc_set_irqs_ioctl(vdev, hdr.flags, + hdr.index, hdr.start, + hdr.count, data); + mutex_unlock(&vdev->igate); + kfree(data); + + return ret; } case VFIO_DEVICE_RESET: { @@ -422,6 +466,8 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) if (ret) goto out_reflck; + mutex_init(&vdev->igate); + return 0; out_reflck: @@ -442,6 +488,8 @@ static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev) if (!vdev) return -EINVAL; + mutex_destroy(&vdev->igate); + vfio_fsl_mc_reflck_put(vdev->reflck); if (is_fsl_mc_bus_dprc(mc_dev)) { diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c new file mode 100644 index 000000000000..5232f208e361 --- /dev/null +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) +/* + * Copyright 2013-2016 Freescale Semiconductor Inc. + * Copyright 2019 NXP + */ + +#include +#include +#include +#include +#include + +#include "linux/fsl/mc.h" +#include "vfio_fsl_mc_private.h" + +static int vfio_fsl_mc_set_irq_trigger(struct vfio_fsl_mc_device *vdev, + unsigned int index, unsigned int start, + unsigned int count, u32 flags, + void *data) +{ + return -EINVAL; +} + +int vfio_fsl_mc_set_irqs_ioctl(struct vfio_fsl_mc_device *vdev, + u32 flags, unsigned int index, + unsigned int start, unsigned int count, + void *data) +{ + if (flags & VFIO_IRQ_SET_ACTION_TRIGGER) + return vfio_fsl_mc_set_irq_trigger(vdev, index, start, + count, flags, data); + else + return -EINVAL; +} diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h b/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h index d47ef6215429..2c3f625a3240 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h @@ -33,6 +33,12 @@ struct vfio_fsl_mc_device { int refcnt; struct vfio_fsl_mc_region *regions; struct vfio_fsl_mc_reflck *reflck; + struct mutex igate; }; +extern int vfio_fsl_mc_set_irqs_ioctl(struct vfio_fsl_mc_device *vdev, + u32 flags, unsigned int index, + unsigned int start, unsigned int count, + void *data); + #endif /* VFIO_FSL_MC_PRIVATE_H */ -- 2.17.1