From patchwork Fri Nov 30 15:47:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 152564 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3813328ljp; Fri, 30 Nov 2018 07:49:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZvsJXmqcGvoxttLOC/3693QSzgPgcC2QhEv3oFTMY+bcAZY6tgxfZpsOmiy3hxXpEiUQT X-Received: by 2002:a63:2a4a:: with SMTP id q71mr5222615pgq.374.1543592978124; Fri, 30 Nov 2018 07:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543592978; cv=none; d=google.com; s=arc-20160816; b=qiwYsppe4y3DFOlrrluHZlUZaiku2WyKXc20FheUETXX7KbaKr9Yzr2yHodisxaI5I eZhwdJpiI7h6dEQ7nmn6JH3fIXxxwuNKJK45jxXnhlqiX/I9Ty5ZOGP1afBIGd2lKurX pDmCy9ZQ9gVT/peRCtNrDRwJTXZqMh9HdM4E6TIagYfaKAa9uQ6myCvvojwsFL0DcSca sRSk+JXNAD1m00mj5baibCMdviqAHWY6aXzf6qPBz/MOF4DXgpBOwY7N5+KuS2sC1VOZ 1Xf8f5YZmF/nlzcXs6SA5bixSt0hxabgV078m1JYlMKelaXe1uQ01FHrJfK8eJzavzdN upjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=EtEWZ9xp0OPfi5WMzVDxU+wec9GUDcNj8E6EmV3uTss=; b=n1tuLpGEr681HZIJ127ZJeu04thBcueIdwzbYStz8u0zyF3vFPQizEkwJxHxjKnNm0 UXsD4U9iUZWwrZl/oL1D/EYtOQ+PusqpAvlQs+ClvR2eSy+bFgdb8Mrtrmyivwh4IGOL EMNE6NvisFFChdCTO1R6TW/sZvTi+7pdx2v0QwYtSsuyQ52EjwbMJ36cfMfb8QZfQ3Mj r/xQ3zGouXUgNHyrooz+SgfPUOfANg1ESKt2N/Mpl/GwQfvINwULYKoIDW9vu/iQ7UT5 4gI/Alcf0w1hrgE9BOczJ6dh3qWCUfAGIGQy+nwMrHpfv//3xZfE6NSXnDXwozhZc96A ANMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si5680967pld.239.2018.11.30.07.49.37; Fri, 30 Nov 2018 07:49:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727517AbeLAC7V (ORCPT + 32 others); Fri, 30 Nov 2018 21:59:21 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:48820 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727158AbeLAC7V (ORCPT ); Fri, 30 Nov 2018 21:59:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0A3DFE2878776; Fri, 30 Nov 2018 23:49:30 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.408.0; Fri, 30 Nov 2018 23:49:24 +0800 From: Shameer Kolothum To: , CC: , , , , , , , , , , , , Subject: [PATCH v5 3/4] perf/smmuv3: Add MSI irq support Date: Fri, 30 Nov 2018 15:47:50 +0000 Message-ID: <20181130154751.28580-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20181130154751.28580-1-shameerali.kolothum.thodi@huawei.com> References: <20181130154751.28580-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds support for MSI-based counter overflow interrupt. Signed-off-by: Shameer Kolothum --- drivers/perf/arm_smmuv3_pmu.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) -- 2.7.4 Reviewed-by: Robin Murphy diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c index fb9dcd8..71d10a0 100644 --- a/drivers/perf/arm_smmuv3_pmu.c +++ b/drivers/perf/arm_smmuv3_pmu.c @@ -68,6 +68,7 @@ #define SMMU_PMCG_OVSSET0 0xCC0 #define SMMU_PMCG_CFGR 0xE00 #define SMMU_PMCG_CFGR_RELOC_CTRS BIT(20) +#define SMMU_PMCG_CFGR_MSI BIT(21) #define SMMU_PMCG_CFGR_SID_FILTER_TYPE BIT(23) #define SMMU_PMCG_CFGR_SIZE_MASK GENMASK(13, 8) #define SMMU_PMCG_CFGR_NCTR_MASK GENMASK(5, 0) @@ -78,6 +79,12 @@ #define SMMU_PMCG_IRQ_CTRL 0xE50 #define SMMU_PMCG_IRQ_CTRL_IRQEN BIT(0) #define SMMU_PMCG_IRQ_CFG0 0xE58 +#define SMMU_PMCG_IRQ_CFG1 0xE60 +#define SMMU_PMCG_IRQ_CFG2 0xE64 + +/* MSI config fields */ +#define MSI_CFG0_ADDR_MASK GENMASK_ULL(51, 2) +#define MSI_CFG2_MEMATTR_DEVICE_nGnRE 0x1 #define SMMU_DEFAULT_FILTER_SPAN 1 #define SMMU_DEFAULT_FILTER_STREAM_ID GENMASK(31, 0) @@ -587,11 +594,62 @@ static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data) return IRQ_HANDLED; } +static void smmu_pmu_free_msis(void *data) +{ + struct device *dev = data; + + platform_msi_domain_free_irqs(dev); +} + +static void smmu_pmu_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + phys_addr_t doorbell; + struct device *dev = msi_desc_to_dev(desc); + struct smmu_pmu *pmu = dev_get_drvdata(dev); + + doorbell = (((u64)msg->address_hi) << 32) | msg->address_lo; + doorbell &= MSI_CFG0_ADDR_MASK; + + writeq_relaxed(doorbell, pmu->reg_base + SMMU_PMCG_IRQ_CFG0); + writel_relaxed(msg->data, pmu->reg_base + SMMU_PMCG_IRQ_CFG1); + writel_relaxed(MSI_CFG2_MEMATTR_DEVICE_nGnRE, + pmu->reg_base + SMMU_PMCG_IRQ_CFG2); +} + +static void smmu_pmu_setup_msi(struct smmu_pmu *pmu) +{ + struct msi_desc *desc; + struct device *dev = pmu->dev; + int ret; + + /* Clear MSI address reg */ + writeq_relaxed(0, pmu->reg_base + SMMU_PMCG_IRQ_CFG0); + + /* MSI supported or not */ + if (!(readl(pmu->reg_base + SMMU_PMCG_CFGR) & SMMU_PMCG_CFGR_MSI)) + return; + + ret = platform_msi_domain_alloc_irqs(dev, 1, smmu_pmu_write_msi_msg); + if (ret) { + dev_warn(dev, "failed to allocate MSIs\n"); + return; + } + + desc = first_msi_entry(dev); + if (desc) + pmu->irq = desc->irq; + + /* Add callback to free MSIs on teardown */ + devm_add_action(dev, smmu_pmu_free_msis, dev); +} + static int smmu_pmu_setup_irq(struct smmu_pmu *pmu) { unsigned long flags = IRQF_NOBALANCING | IRQF_SHARED | IRQF_NO_THREAD; int irq, ret = -ENXIO; + smmu_pmu_setup_msi(pmu); + irq = pmu->irq; if (irq) ret = devm_request_irq(pmu->dev, irq, smmu_pmu_handle_irq,