Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp681189ybh; Wed, 22 Jul 2020 10:24:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGg41E9FmjU9UCdfdwQ2sULG19vTPkLKLxx6xqntByJX1J6PztGcefctVtPmDg2pFlT5RL X-Received: by 2002:a05:6402:c06:: with SMTP id co6mr529571edb.142.1595438648371; Wed, 22 Jul 2020 10:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595438648; cv=none; d=google.com; s=arc-20160816; b=Y3wIk1v7kk4ymcxI3zxwMjP2W5FcpxBmfdNbuXM53IznPVeoSQetycbK9mTVXIUynu HqgCXGxL256sY7lCPzj29zfIMVgvZ2id2i5/3IDo9KCRkWVfXzNWJznfFwOA1EagCEWV Wy5KGFKe0t2i8QGvRMDUrYvpXmOB6GJ4UwbcOnseDZlXlSfdlNCIMUM6tNq0MYSglvJ7 2py37shcyFVDybecZcwR4BO0+Xz6TC9unYUJreI5ab05Y5aDtpslmNy+3m6SC/AkOYsb KVfxsixpNnu2mvQwlOWZkSkulACUxE+GV8P62ohWurWfzCruit45RvBB4huiUTgVU059 17Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eXQVZTVd0Ugci8UhECR1jtdBewVU0v6s/kJtw8eCaz8=; b=j67ocBEa7gzb2Z8mAdiBH1c/KOew8CkP/zBWfi11r4+1If7ndxKRu/7q1/wWKMUX3e 0zbqep4Vx/b1BCqxDFDKon5Dv9/9kszZFOlN0r+SM5WoNYU937gEIh3eb1W0BrkwvC57 GLBDBb2l/lClNW1Y/J7ipAdIjlr9b4hMo+i9t+QmxKm2xyVeu2KZWorBtcdLUnUhP4Aw jDfDZ1AyZjp72c8juH3Nt5QoMWC1sVPeT3Z+Y6LyDPwHxovS0FuVzCy7Dl+RySycn/gb Zgj8gEd2IcWAsa7QjIWR6cva9pYYDGqL2K7lS3MUm5Aib3aczq9MJd+qVLu98QRr2TOi yOLQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb4si418918ejb.173.2020.07.22.10.23.45; Wed, 22 Jul 2020 10:24:08 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732203AbgGVRVU (ORCPT + 99 others); Wed, 22 Jul 2020 13:21:20 -0400 Received: from foss.arm.com ([217.140.110.172]:60046 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729000AbgGVRVJ (ORCPT ); Wed, 22 Jul 2020 13:21:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 069361478; Wed, 22 Jul 2020 10:21:09 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 222703F66F; Wed, 22 Jul 2020 10:21:08 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, mike.leach@linaro.org, mathieu.poirier@linaro.org, coresight@lists.linaro.org, Suzuki K Poulose Subject: [RFC PATCH 12/14] coresight: etm4x: Refactor probing routine Date: Wed, 22 Jul 2020 18:20:38 +0100 Message-Id: <20200722172040.1299289-13-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200722172040.1299289-1-suzuki.poulose@arm.com> References: <20200722172040.1299289-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CoreSight ETM with system register access may not have a memory mapped i/o access. Refactor the ETM specific probing into a common routine to allow reusing the code for such ETMs. Cc: Mathieu Poirier Cc: Mike Leach Signed-off-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etm4x.c | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 831206f7f306..e91af23ac419 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -1541,27 +1541,43 @@ static bool etm4_cpu_supports_sysreg(int cpu) return sys_reg_support; } -static int etm4_probe(struct amba_device *adev, const struct amba_id *id) +static int etm4_probe_common(struct device *dev, void __iomem *base) { int ret, cpu; bool sys_reg = false; - void __iomem *base; - struct device *dev = &adev->dev; struct coresight_platform_data *pdata = NULL; struct etmv4_drvdata *drvdata; - struct resource *res = &adev->res; struct coresight_desc desc = { 0 }; + cpu = coresight_get_cpu(dev); + if (cpu < 0) + return cpu; + cpu = coresight_get_cpu(dev); if (cpu < 0 || !cpu_online(cpu)) return -EPROBE_DEFER; sys_reg = etm4_cpu_supports_sysreg(cpu); + if (sys_reg) { + desc.access = (struct csdev_access){ + .no_iomem = true, + .read = etm4x_sysreg_read, + .write = etm4x_sysreg_write, + }; + } else if (base) { + desc.access.base = base; + } else { + dev_crit(dev, "etm4x: Unable to detect access\n"); + return -ENODEV; + } + + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); if (!drvdata) return -ENOMEM; + drvdata->base = base; drvdata->cpu = cpu; dev_set_drvdata(dev, drvdata); @@ -1579,22 +1595,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) if (fwnode_property_present(dev_fwnode(dev), "qcom,skip-power-up")) drvdata->skip_power_up = true; - if (sys_reg) { - desc.access = (struct csdev_access){ - .no_iomem = true, - .read = etm4x_sysreg_read, - .write = etm4x_sysreg_write, - }; - } else { - /* Validity for the resource is already checked by the AMBA core */ - base = devm_ioremap_resource(dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); - - drvdata->base = base; - desc.access.base = base; - } - spin_lock_init(&drvdata->spinlock); desc.name = devm_kasprintf(dev, GFP_KERNEL, "etm%d", drvdata->cpu); @@ -1630,7 +1630,7 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) ret = PTR_ERR(pdata); goto err_arch_supported; } - adev->dev.platform_data = pdata; + dev->platform_data = pdata; desc.type = CORESIGHT_DEV_TYPE_SOURCE; desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC; @@ -1650,7 +1650,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) goto err_arch_supported; } - pm_runtime_put(&adev->dev); dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n", drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf); if (sys_reg) @@ -1669,6 +1668,25 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) return ret; } +static int etm4_probe_amba(struct amba_device *adev, const struct amba_id *id) +{ + void __iomem *base; + struct device *dev = &adev->dev; + struct resource *res = &adev->res; + int ret; + + /* Validity for the resource is already checked by the AMBA core */ + base = devm_ioremap_resource(dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + + ret = etm4_probe_common(dev, base); + if (!ret) + pm_runtime_put(&adev->dev); + + return ret; +} + static struct amba_cs_uci_id uci_id_etm4[] = { { /* ETMv4 UCI data */ @@ -1700,7 +1718,7 @@ static struct amba_driver etm4x_driver = { .name = "coresight-etm4x", .suppress_bind_attrs = true, }, - .probe = etm4_probe, + .probe = etm4_probe_amba, .id_table = etm4_ids, }; builtin_amba_driver(etm4x_driver); -- 2.24.1