From patchwork Mon Mar 28 13:35:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 8679431 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 035ED9F30C for ; Mon, 28 Mar 2016 13:46:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EF91B2021B for ; Mon, 28 Mar 2016 13:46:38 +0000 (UTC) Received: from bombadil.infradead.org (unknown [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC177201E4 for ; Mon, 28 Mar 2016 13:46:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1akXLR-000816-9n; Mon, 28 Mar 2016 13:36:37 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1akXLB-0007vP-8r for linux-arm-kernel@lists.infradead.org; Mon, 28 Mar 2016 13:36:23 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id B038060871; Mon, 28 Mar 2016 13:36:04 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A2D9161506; Mon, 28 Mar 2016 13:36:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RDNS_NONE,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1DB3A60386; Mon, 28 Mar 2016 13:36:02 +0000 (UTC) From: Sinan Kaya To: kvm@vger.kernel.org, timur@codeaurora.org, cov@codeaurora.org, jcm@redhat.com, eric.auger@linaro.org Subject: [PATCH V3 3/3] vfio, platform: add QTI HIDMA reset driver Date: Mon, 28 Mar 2016 09:35:24 -0400 Message-Id: <1459172124-6730-4-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1459172124-6730-1-git-send-email-okaya@codeaurora.org> References: <1459172124-6730-1-git-send-email-okaya@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160328_063621_401978_D3125EE0 X-CRM114-Status: GOOD ( 22.28 ) X-Spam-Score: -2.9 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, Baptiste Reynal , Arnd Bergmann , vikrams@codeaurora.org, marc.zyngier@arm.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Sinan Kaya , vinod.koul@intel.com, Alex Williamson , linux-arm-kernel@lists.infradead.org, agross@codeaurora.org, shankerd@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In situations where the userspace driver is stopped abnormally and the VFIO platform device is released, the assigned HW device currently is left running. As a consequence the HW device might continue issuing IRQs and performing DMA accesses. This patch is implementing a reset driver for HIDMA platform driver. This gets called by the VFIO platform reset interface. Reviewed-by: Eric Auger Signed-off-by: Sinan Kaya --- drivers/vfio/platform/reset/Kconfig | 9 ++ drivers/vfio/platform/reset/Makefile | 2 + .../vfio/platform/reset/vfio_platform_qcomhidma.c | 101 +++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 drivers/vfio/platform/reset/vfio_platform_qcomhidma.c diff --git a/drivers/vfio/platform/reset/Kconfig b/drivers/vfio/platform/reset/Kconfig index 70cccc5..d02b3b5 100644 --- a/drivers/vfio/platform/reset/Kconfig +++ b/drivers/vfio/platform/reset/Kconfig @@ -13,3 +13,12 @@ config VFIO_PLATFORM_AMDXGBE_RESET Enables the VFIO platform driver to handle reset for AMD XGBE If you don't know what to do here, say N. + +config VFIO_PLATFORM_QCOMHIDMA_RESET + tristate "VFIO support for Qualcomm Technologies HIDMA reset" + depends on VFIO_PLATFORM + help + Enables the VFIO platform driver to handle reset for Qualcomm Technologies + HIDMA Channel. + + If you don't know what to do here, say N. diff --git a/drivers/vfio/platform/reset/Makefile b/drivers/vfio/platform/reset/Makefile index 93f4e23..ec7748a 100644 --- a/drivers/vfio/platform/reset/Makefile +++ b/drivers/vfio/platform/reset/Makefile @@ -1,7 +1,9 @@ vfio-platform-calxedaxgmac-y := vfio_platform_calxedaxgmac.o vfio-platform-amdxgbe-y := vfio_platform_amdxgbe.o +vfio-platform-qcomhidma-y := vfio_platform_qcomhidma.o ccflags-y += -Idrivers/vfio/platform obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) += vfio-platform-calxedaxgmac.o +obj-$(CONFIG_VFIO_PLATFORM_QCOMHIDMA_RESET) += vfio-platform-qcomhidma.o obj-$(CONFIG_VFIO_PLATFORM_AMDXGBE_RESET) += vfio-platform-amdxgbe.o diff --git a/drivers/vfio/platform/reset/vfio_platform_qcomhidma.c b/drivers/vfio/platform/reset/vfio_platform_qcomhidma.c new file mode 100644 index 0000000..ef3491b --- /dev/null +++ b/drivers/vfio/platform/reset/vfio_platform_qcomhidma.c @@ -0,0 +1,101 @@ +/* + * Qualcomm Technologies HIDMA VFIO Reset Driver + * + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include + +#include "vfio_platform_private.h" + +#define TRCA_CTRLSTS_OFFSET 0x000 +#define EVCA_CTRLSTS_OFFSET 0x000 + +#define CH_CONTROL_MASK GENMASK(7, 0) +#define CH_STATE_MASK GENMASK(7, 0) +#define CH_STATE_BIT_POS 0x8 + +#define HIDMA_CH_STATE(val) \ + ((val >> CH_STATE_BIT_POS) & CH_STATE_MASK) + +#define EVCA_IRQ_EN_OFFSET 0x110 + +#define CH_RESET 9 +#define CH_DISABLED 0 + +int vfio_platform_qcomhidma_reset(struct vfio_platform_device *vdev) +{ + struct vfio_platform_region *trreg; + struct vfio_platform_region *evreg; + u32 val; + int ret; + + if (vdev->num_regions != 2) + return -ENODEV; + + trreg = &vdev->regions[0]; + if (!trreg->ioaddr) { + trreg->ioaddr = + ioremap_nocache(trreg->addr, trreg->size); + if (!trreg->ioaddr) + return -ENOMEM; + } + + evreg = &vdev->regions[1]; + if (!evreg->ioaddr) { + evreg->ioaddr = + ioremap_nocache(evreg->addr, evreg->size); + if (!evreg->ioaddr) + return -ENOMEM; + } + + /* disable IRQ */ + writel(0, evreg->ioaddr + EVCA_IRQ_EN_OFFSET); + + /* reset both transfer and event channels */ + val = readl(trreg->ioaddr + TRCA_CTRLSTS_OFFSET); + val &= ~(CH_CONTROL_MASK << 16); + val |= CH_RESET << 16; + writel(val, trreg->ioaddr + TRCA_CTRLSTS_OFFSET); + + ret = readl_poll_timeout(trreg->ioaddr + TRCA_CTRLSTS_OFFSET, val, + HIDMA_CH_STATE(val) == CH_DISABLED, 1000, + 10000); + if (ret) + return ret; + + val = readl(evreg->ioaddr + EVCA_CTRLSTS_OFFSET); + val &= ~(CH_CONTROL_MASK << 16); + val |= CH_RESET << 16; + writel(val, evreg->ioaddr + EVCA_CTRLSTS_OFFSET); + + ret = readl_poll_timeout(evreg->ioaddr + EVCA_CTRLSTS_OFFSET, val, + HIDMA_CH_STATE(val) == CH_DISABLED, 1000, + 10000); + if (ret) + return ret; + + pr_info("HIDMA channel reset\n"); + return 0; +} +module_vfio_reset_handler("qcom,hidma-1.0", "QCOM8061", + vfio_platform_qcomhidma_reset); +MODULE_ALIAS_VFIO_PLATFORM_RESET("qcom,hidma-1.0"); +MODULE_ALIAS_VFIO_PLATFORM_RESET("QCOM8061"); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Reset support for Qualcomm Technologies HIDMA device");