Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4382510img; Tue, 26 Mar 2019 08:21:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFL/7H2plYEuobDbQ/9BxK1td++A3f9StMesjeN003l5/4NRtnCwscu1Bb/vuG1cdHobp6 X-Received: by 2002:a17:902:778a:: with SMTP id o10mr222252pll.135.1553613704426; Tue, 26 Mar 2019 08:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553613704; cv=none; d=google.com; s=arc-20160816; b=aQw/mKZn+35+CJvE+YVuJz6RQ1P8xNLBjjielEgZb99QzhHkNelz9rXh7YX0fEFe3X FB0e3w1sp82G4sVs0f636sZAshZdnHm5KoqNBTHKeqf679FM+LRwpyI0vizzMC2JFef7 RHg9naZYAeeBHtfFlYhmoPbz8MJmbu7K5vBKzLwq874XRue2eDDV7XRuYWkLS5f++s7G oFBPwx6yc5k/Kvygygp2SUIfhCnGYkV7KDunJ9HNNRScphBGojWDAEbBC8KjuMq7Ro/A BfWu+ziFxT54NNdqnawc92JhCrFRHfzZ104CSk1MCn/e/TCnNwU0/fteDBfeHGvJmmL0 cWBg== 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=ZrKl+4d26/6/aqPNOL9Ca1OWqZeQbseVdh2anbOz3lk=; b=b21cDhdxQDL1HpJQJu3Rlp2vg8PglQ/L2/8P1gseZBBdCrgC+J0BW5kKbEDFCr+zD1 c2Gz/vqeAQcmamSOLVu+QkSQgbWW5AEP+zGHma7mDRfeGuzAlcSHxnJYY/qwGDQcsreM boHGStUJcEuSGo7IUdAnFzAuZSefocCagzpqi/GiPSVdh82o4RyD6mhTQUSKAqiUShUp kOINsJWjTqHTQTokcNeKmddMeVLGOA80+vbljtVM08A7rN2m73/h3p895sci/3Otwjqq IJWle64ZooIoCcibag7UnXfVtVyh17g58fQgNen67umFjlYvOCSFlePBawcj82fV6hF9 5pFQ== 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 59si17357670plc.84.2019.03.26.08.21.28; Tue, 26 Mar 2019 08:21:44 -0700 (PDT) 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 S1732076AbfCZPUX (ORCPT + 99 others); Tue, 26 Mar 2019 11:20:23 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5192 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731905AbfCZPUV (ORCPT ); Tue, 26 Mar 2019 11:20:21 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A3D92681E52B8C57E67E; Tue, 26 Mar 2019 23:20:17 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Tue, 26 Mar 2019 23:20:07 +0800 From: Shameer Kolothum To: , CC: , , , , , , , , , , , , , Subject: [PATCH v7 3/4] perf/smmuv3: Add MSI irq support Date: Tue, 26 Mar 2019 15:17:52 +0000 Message-ID: <20190326151753.19384-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190326151753.19384-1-shameerali.kolothum.thodi@huawei.com> References: <20190326151753.19384-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain 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 Reviewed-by: Robin Murphy --- drivers/perf/arm_smmuv3_pmu.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c index c0924e5..7803e9e 100644 --- a/drivers/perf/arm_smmuv3_pmu.c +++ b/drivers/perf/arm_smmuv3_pmu.c @@ -67,6 +67,7 @@ #define SMMU_PMCG_OVSSET0 0xCC0 #define SMMU_PMCG_CFGR 0xE00 #define SMMU_PMCG_CFGR_SID_FILTER_TYPE BIT(23) +#define SMMU_PMCG_CFGR_MSI BIT(21) #define SMMU_PMCG_CFGR_RELOC_CTRS BIT(20) #define SMMU_PMCG_CFGR_SIZE GENMASK(13, 8) #define SMMU_PMCG_CFGR_NCTR GENMASK(5, 0) @@ -77,6 +78,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_PMCG_DEFAULT_FILTER_SPAN 1 #define SMMU_PMCG_DEFAULT_FILTER_SID GENMASK(31, 0) @@ -584,11 +591,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, -- 2.7.4