[V4,03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup
Message ID | 20240123054608.1790189-4-anshuman.khandual@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-34735-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp137989dyi; Mon, 22 Jan 2024 21:47:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsrcLA9Thc6b5mLd8fbAerrJBiF1Uu0sa4BdyYTteDbvkgsp4q1+eoCpnA6TvNj/jH9BA0 X-Received: by 2002:a81:4988:0:b0:5ff:505f:4e5b with SMTP id w130-20020a814988000000b005ff505f4e5bmr4903280ywa.75.1705988858483; Mon, 22 Jan 2024 21:47:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705988858; cv=pass; d=google.com; s=arc-20160816; b=jH3QxnW/OlnJGF+AfqE1yv4PsXh8BNeg6c0EGb6Rl+7Mr/Sip2biTUvidzWEQ0oSgY +S9e6zLk8/iEYKT1bXYcQDSejZKtlEKH0/chRtbRt198DL+BZi1+JZ4z17WzoivBqyCL LOdDjxoCyQRWISmmS5A1z7uvRLohFoDKN1wveP0WmlQTOTjJIzJ+AUxBtDmExrLrFdaX i+oYCNwDZK9jsZ0YCd9AzppfhzInypJdBU2qmlLzXlHjjwpNI9Y+2boWNmP97R+CPSiM DNg2ylkZHp8iUNam47c9ObxQGuOgJDMJHQqwEmI0OkzYH6zuTXsF8qAW15s64luBpNHk EoFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Zg58/ZEXIrYAfo6V0pCAywlCfuUpwY4VAc96U80v1q0=; fh=78ZiYAsMqkMiOIWlhjjSgWn2SS9khyeUqw/r/4rUn1M=; b=C9qytrLs6HTSATx5HIMvvTvaXgtnpaJiQwJMQ5xjswpNdRw8zxVWETFZSnbL3opl5I ismlps7SYJ+NtomsT9pbAB1zD30G/m2351+FpWbRVS6q7LigoQrIb0LiI8IErWu+RQva NIoT+RdnUR+vPGjh715R5lB8C3zS6ZCUY5lAxDIVRJgBwe6MYIbcqJtb9eZZnF7Tifej tvthaiPP0PfT6hhtIfBn93zWVaCsAjuUDroiam5CpR0g94vk3wmYvmXdNBCMDdI1pgh1 rF5gxr+O3lxJDqYadPtafh0NhWz2yqvFB7FHEDGsSeyLWJZqq4kgFbrpSXvLzYWJnSJc AVcQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-34735-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34735-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s14-20020a0c8d4e000000b006868b932e4dsi4323462qvb.423.2024.01.22.21.47.38 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 21:47:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34735-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-34735-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34735-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 47A701C2355D for <ouuuleilei@gmail.com>; Tue, 23 Jan 2024 05:47:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E9BDFBFA; Tue, 23 Jan 2024 05:46:47 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CE92C8DD; Tue, 23 Jan 2024 05:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705988805; cv=none; b=pJogscWKjlkmQ6p+yqupNPjPnYwKWqICKUCOF3VBK6BoUCsW+gq2wKV6nRLYom3cuayvqutCSJ/9CZnCthKDIpmyoV/mdKqHhiaRZv4sryTCXBncycf6qsnGmkrZZacIv/9isODjNA+xVviCSkFCXzXFeXdhyVAiywSlljSzN6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705988805; c=relaxed/simple; bh=0mjJxnCmvKiSTYuVDSEK+hlxIecGTkYr/y/sD7YUgkw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hkaX0w53+vhlbX1YotkeMPXRcu+GfS4+Xv84kkQ//BCT/Lr2LLnwlPtpibm1H5jz87l6pfAsHUbzK1b58jGYLK+93a9z+FzlgOihhjQPLfx3V3PICW864bY/3/3V+N7VUGNte0LlKv2XBltH9F0CVmxcwagixo5aryzorfa7wB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 0FCE41FB; Mon, 22 Jan 2024 21:47:29 -0800 (PST) Received: from a077893.arm.com (unknown [10.163.40.228]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5AB8B3F762; Mon, 22 Jan 2024 21:46:39 -0800 (PST) From: Anshuman Khandual <anshuman.khandual@arm.com> To: linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com Cc: Anshuman Khandual <anshuman.khandual@arm.com>, Lorenzo Pieralisi <lpieralisi@kernel.org>, Sudeep Holla <sudeep.holla@arm.com>, Mike Leach <mike.leach@linaro.org>, James Clark <james.clark@arm.com>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup Date: Tue, 23 Jan 2024 11:16:00 +0530 Message-Id: <20240123054608.1790189-4-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240123054608.1790189-1-anshuman.khandual@arm.com> References: <20240123054608.1790189-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788858973632640162 X-GMAIL-MSGID: 1788858973632640162 |
Series |
coresight: Move remaining AMBA ACPI devices into platform driver
|
|
Commit Message
Anshuman Khandual
Jan. 23, 2024, 5:46 a.m. UTC
This extracts device properties from AMBA pid based table lookup. This also
defers tmc_etr_setup_caps() after the coresight device has been initialized
so that PID value can be read.
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: James Clark <james.clark@arm.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
.../hwtracing/coresight/coresight-tmc-core.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
Comments
On 23/01/2024 05:46, Anshuman Khandual wrote: > This extracts device properties from AMBA pid based table lookup. This also > defers tmc_etr_setup_caps() after the coresight device has been initialized > so that PID value can be read. > > Cc: Suzuki K Poulose <suzuki.poulose@arm.com> > Cc: Mike Leach <mike.leach@linaro.org> > Cc: James Clark <james.clark@arm.com> > Cc: coresight@lists.linaro.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> > --- > .../hwtracing/coresight/coresight-tmc-core.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c > index 7ec5365e2b64..e71db3099a29 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc-core.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c > @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) > return (auth & TMC_AUTH_NSID_MASK) == 0x3; > } > > +#define TMC_AMBA_MASK 0xfffff > + > +static const struct amba_id tmc_ids[]; > + > /* Detect and initialise the capabilities of a TMC ETR */ > -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) > +static int tmc_etr_setup_caps(struct device *parent, u32 devid) > { > int rc; > - u32 dma_mask = 0; > + u32 tmc_pid, dma_mask = 0; > struct tmc_drvdata *drvdata = dev_get_drvdata(parent); > + void *dev_caps; > > if (!tmc_etr_has_non_secure_access(drvdata)) > return -EACCES; > > + tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK; > + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); > + > /* Set the unadvertised capabilities */ > tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); > > @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) > desc.type = CORESIGHT_DEV_TYPE_SINK; > desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; > desc.ops = &tmc_etr_cs_ops; > - ret = tmc_etr_setup_caps(dev, devid, > - coresight_get_uci_data(id)); > - if (ret) > - goto out; > idr_init(&drvdata->idr); > mutex_init(&drvdata->idr_mutex); > dev_list = &etr_devs; > @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) > goto out; > } > > + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) > + ret = tmc_etr_setup_caps(dev, devid); > + With this change, we silently accept an ETR that may only have "SECURE" access only and crash later while we try to enable tracing. You could pass in the "access" (which is already in 'desc.access' in the original call site and deal with it ? Suzuki > drvdata->miscdev.name = desc.name; > drvdata->miscdev.minor = MISC_DYNAMIC_MINOR; > drvdata->miscdev.fops = &tmc_fops;
On 2/12/24 17:43, Suzuki K Poulose wrote: > On 23/01/2024 05:46, Anshuman Khandual wrote: >> This extracts device properties from AMBA pid based table lookup. This also >> defers tmc_etr_setup_caps() after the coresight device has been initialized >> so that PID value can be read. >> >> Cc: Suzuki K Poulose <suzuki.poulose@arm.com> >> Cc: Mike Leach <mike.leach@linaro.org> >> Cc: James Clark <james.clark@arm.com> >> Cc: coresight@lists.linaro.org >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >> --- >> .../hwtracing/coresight/coresight-tmc-core.c | 19 +++++++++++++------ >> 1 file changed, 13 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c >> index 7ec5365e2b64..e71db3099a29 100644 >> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c >> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c >> @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) >> return (auth & TMC_AUTH_NSID_MASK) == 0x3; >> } >> +#define TMC_AMBA_MASK 0xfffff >> + >> +static const struct amba_id tmc_ids[]; >> + >> /* Detect and initialise the capabilities of a TMC ETR */ >> -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) >> +static int tmc_etr_setup_caps(struct device *parent, u32 devid) >> { >> int rc; >> - u32 dma_mask = 0; >> + u32 tmc_pid, dma_mask = 0; >> struct tmc_drvdata *drvdata = dev_get_drvdata(parent); >> + void *dev_caps; >> if (!tmc_etr_has_non_secure_access(drvdata)) >> return -EACCES; >> + tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK; >> + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); >> + >> /* Set the unadvertised capabilities */ >> tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); >> @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >> desc.type = CORESIGHT_DEV_TYPE_SINK; >> desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; >> desc.ops = &tmc_etr_cs_ops; >> - ret = tmc_etr_setup_caps(dev, devid, >> - coresight_get_uci_data(id)); >> - if (ret) >> - goto out; >> idr_init(&drvdata->idr); >> mutex_init(&drvdata->idr_mutex); >> dev_list = &etr_devs; >> @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >> goto out; >> } >> + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) >> + ret = tmc_etr_setup_caps(dev, devid); >> + > > With this change, we silently accept an ETR that may only have "SECURE" access only and crash later while we try to enable tracing. You could > pass in the "access" (which is already in 'desc.access' in the original > call site and deal with it ? Just wondering, if something like the following will help ? A failed tmc_etr_setup_caps() because of failed tmc_etr_has_non_secure_access(), will unregister the coresight device before returning. --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -538,8 +538,13 @@ static int __tmc_probe(struct device *dev, struct resource *res) goto out; } - if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { ret = tmc_etr_setup_caps(dev, devid); + if (ret) { + coresight_unregister(drvdata->csdev); + goto out; + } + } drvdata->miscdev.name = desc.name; drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
On 13/02/2024 03:13, Anshuman Khandual wrote: > > > On 2/12/24 17:43, Suzuki K Poulose wrote: >> On 23/01/2024 05:46, Anshuman Khandual wrote: >>> This extracts device properties from AMBA pid based table lookup. This also >>> defers tmc_etr_setup_caps() after the coresight device has been initialized >>> so that PID value can be read. >>> >>> Cc: Suzuki K Poulose <suzuki.poulose@arm.com> >>> Cc: Mike Leach <mike.leach@linaro.org> >>> Cc: James Clark <james.clark@arm.com> >>> Cc: coresight@lists.linaro.org >>> Cc: linux-arm-kernel@lists.infradead.org >>> Cc: linux-kernel@vger.kernel.org >>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>> --- >>> .../hwtracing/coresight/coresight-tmc-core.c | 19 +++++++++++++------ >>> 1 file changed, 13 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c >>> index 7ec5365e2b64..e71db3099a29 100644 >>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c >>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c >>> @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) >>> return (auth & TMC_AUTH_NSID_MASK) == 0x3; >>> } >>> +#define TMC_AMBA_MASK 0xfffff >>> + >>> +static const struct amba_id tmc_ids[]; >>> + >>> /* Detect and initialise the capabilities of a TMC ETR */ >>> -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) >>> +static int tmc_etr_setup_caps(struct device *parent, u32 devid) >>> { >>> int rc; >>> - u32 dma_mask = 0; >>> + u32 tmc_pid, dma_mask = 0; >>> struct tmc_drvdata *drvdata = dev_get_drvdata(parent); >>> + void *dev_caps; >>> if (!tmc_etr_has_non_secure_access(drvdata)) >>> return -EACCES; >>> + tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK; >>> + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); >>> + >>> /* Set the unadvertised capabilities */ >>> tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); >>> @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >>> desc.type = CORESIGHT_DEV_TYPE_SINK; >>> desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; >>> desc.ops = &tmc_etr_cs_ops; >>> - ret = tmc_etr_setup_caps(dev, devid, >>> - coresight_get_uci_data(id)); >>> - if (ret) >>> - goto out; >>> idr_init(&drvdata->idr); >>> mutex_init(&drvdata->idr_mutex); >>> dev_list = &etr_devs; >>> @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >>> goto out; >>> } >>> + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) >>> + ret = tmc_etr_setup_caps(dev, devid); >>> + >> >> With this change, we silently accept an ETR that may only have "SECURE" access only and crash later while we try to enable tracing. You could >> pass in the "access" (which is already in 'desc.access' in the original >> call site and deal with it ? > > Just wondering, if something like the following will help ? A failed tmc_etr_setup_caps() > because of failed tmc_etr_has_non_secure_access(), will unregister the coresight device > before returning. > > --- a/drivers/hwtracing/coresight/coresight-tmc-core.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c > @@ -538,8 +538,13 @@ static int __tmc_probe(struct device *dev, struct resource *res) > goto out; > } > > - if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) > + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { > ret = tmc_etr_setup_caps(dev, devid); > + if (ret) { > + coresight_unregister(drvdata->csdev); > + goto out; > + } > + } Why do we move the tmc_etr_setup_caps() in the first place ? We could retain where that was and pass "desc.access" parameter rather than registering the csdev and then relying csdev->access ? Suzuki > > drvdata->miscdev.name = desc.name; > drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
On 2/13/24 16:02, Suzuki K Poulose wrote: > On 13/02/2024 03:13, Anshuman Khandual wrote: >> >> >> On 2/12/24 17:43, Suzuki K Poulose wrote: >>> On 23/01/2024 05:46, Anshuman Khandual wrote: >>>> This extracts device properties from AMBA pid based table lookup. This also >>>> defers tmc_etr_setup_caps() after the coresight device has been initialized >>>> so that PID value can be read. >>>> >>>> Cc: Suzuki K Poulose <suzuki.poulose@arm.com> >>>> Cc: Mike Leach <mike.leach@linaro.org> >>>> Cc: James Clark <james.clark@arm.com> >>>> Cc: coresight@lists.linaro.org >>>> Cc: linux-arm-kernel@lists.infradead.org >>>> Cc: linux-kernel@vger.kernel.org >>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>>> --- >>>> .../hwtracing/coresight/coresight-tmc-core.c | 19 +++++++++++++------ >>>> 1 file changed, 13 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c >>>> index 7ec5365e2b64..e71db3099a29 100644 >>>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c >>>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c >>>> @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) >>>> return (auth & TMC_AUTH_NSID_MASK) == 0x3; >>>> } >>>> +#define TMC_AMBA_MASK 0xfffff >>>> + >>>> +static const struct amba_id tmc_ids[]; >>>> + >>>> /* Detect and initialise the capabilities of a TMC ETR */ >>>> -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) >>>> +static int tmc_etr_setup_caps(struct device *parent, u32 devid) >>>> { >>>> int rc; >>>> - u32 dma_mask = 0; >>>> + u32 tmc_pid, dma_mask = 0; >>>> struct tmc_drvdata *drvdata = dev_get_drvdata(parent); >>>> + void *dev_caps; >>>> if (!tmc_etr_has_non_secure_access(drvdata)) >>>> return -EACCES; >>>> + tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK; >>>> + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); >>>> + >>>> /* Set the unadvertised capabilities */ >>>> tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); >>>> @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >>>> desc.type = CORESIGHT_DEV_TYPE_SINK; >>>> desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; >>>> desc.ops = &tmc_etr_cs_ops; >>>> - ret = tmc_etr_setup_caps(dev, devid, >>>> - coresight_get_uci_data(id)); >>>> - if (ret) >>>> - goto out; >>>> idr_init(&drvdata->idr); >>>> mutex_init(&drvdata->idr_mutex); >>>> dev_list = &etr_devs; >>>> @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >>>> goto out; >>>> } >>>> + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) >>>> + ret = tmc_etr_setup_caps(dev, devid); >>>> + >>> >>> With this change, we silently accept an ETR that may only have "SECURE" access only and crash later while we try to enable tracing. You could >>> pass in the "access" (which is already in 'desc.access' in the original >>> call site and deal with it ? >> >> Just wondering, if something like the following will help ? A failed tmc_etr_setup_caps() >> because of failed tmc_etr_has_non_secure_access(), will unregister the coresight device >> before returning. >> >> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c >> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c >> @@ -538,8 +538,13 @@ static int __tmc_probe(struct device *dev, struct resource *res) >> goto out; >> } >> - if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) >> + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { >> ret = tmc_etr_setup_caps(dev, devid); >> + if (ret) { >> + coresight_unregister(drvdata->csdev); >> + goto out; >> + } >> + } > > Why do we move the tmc_etr_setup_caps() in the first place ? We could retain where that was and pass "desc.access" parameter rather than registering the csdev and then relying csdev->access ? Agreed, and after implementing the changes suggested above, the entire patch will look something like the following. Please do confirm if this looks good enough. --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -370,16 +370,25 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) return (auth & TMC_AUTH_NSID_MASK) == 0x3; } +#define TMC_AMBA_MASK 0xfffff + +static const struct amba_id tmc_ids[]; + /* Detect and initialise the capabilities of a TMC ETR */ -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) +static int tmc_etr_setup_caps(struct device *parent, u32 devid, + struct csdev_access *access) { int rc; - u32 dma_mask = 0; + u32 tmc_pid, dma_mask = 0; struct tmc_drvdata *drvdata = dev_get_drvdata(parent); + void *dev_caps; if (!tmc_etr_has_non_secure_access(drvdata)) return -EACCES; + tmc_pid = coresight_get_pid(access) & TMC_AMBA_MASK; + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); + /* Set the unadvertised capabilities */ tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); @@ -497,8 +506,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) desc.type = CORESIGHT_DEV_TYPE_SINK; desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; desc.ops = &tmc_etr_cs_ops; - ret = tmc_etr_setup_caps(dev, devid, - coresight_get_uci_data(id)); + ret = tmc_etr_setup_caps(dev, devid, &desc.access); if (ret) goto out; idr_init(&drvdata->idr);
On 14/02/2024 03:35, Anshuman Khandual wrote: > > > On 2/13/24 16:02, Suzuki K Poulose wrote: >> On 13/02/2024 03:13, Anshuman Khandual wrote: >>> >>> >>> On 2/12/24 17:43, Suzuki K Poulose wrote: >>>> On 23/01/2024 05:46, Anshuman Khandual wrote: >>>>> This extracts device properties from AMBA pid based table lookup. This also >>>>> defers tmc_etr_setup_caps() after the coresight device has been initialized >>>>> so that PID value can be read. >>>>> >>>>> Cc: Suzuki K Poulose <suzuki.poulose@arm.com> >>>>> Cc: Mike Leach <mike.leach@linaro.org> >>>>> Cc: James Clark <james.clark@arm.com> >>>>> Cc: coresight@lists.linaro.org >>>>> Cc: linux-arm-kernel@lists.infradead.org >>>>> Cc: linux-kernel@vger.kernel.org >>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>>>> --- >>>>> .../hwtracing/coresight/coresight-tmc-core.c | 19 +++++++++++++------ >>>>> 1 file changed, 13 insertions(+), 6 deletions(-) >>>>> >>>>> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c >>>>> index 7ec5365e2b64..e71db3099a29 100644 >>>>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c >>>>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c >>>>> @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) >>>>> return (auth & TMC_AUTH_NSID_MASK) == 0x3; >>>>> } >>>>> +#define TMC_AMBA_MASK 0xfffff >>>>> + >>>>> +static const struct amba_id tmc_ids[]; >>>>> + >>>>> /* Detect and initialise the capabilities of a TMC ETR */ >>>>> -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) >>>>> +static int tmc_etr_setup_caps(struct device *parent, u32 devid) >>>>> { >>>>> int rc; >>>>> - u32 dma_mask = 0; >>>>> + u32 tmc_pid, dma_mask = 0; >>>>> struct tmc_drvdata *drvdata = dev_get_drvdata(parent); >>>>> + void *dev_caps; >>>>> if (!tmc_etr_has_non_secure_access(drvdata)) >>>>> return -EACCES; >>>>> + tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK; >>>>> + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); >>>>> + >>>>> /* Set the unadvertised capabilities */ >>>>> tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); >>>>> @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >>>>> desc.type = CORESIGHT_DEV_TYPE_SINK; >>>>> desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; >>>>> desc.ops = &tmc_etr_cs_ops; >>>>> - ret = tmc_etr_setup_caps(dev, devid, >>>>> - coresight_get_uci_data(id)); >>>>> - if (ret) >>>>> - goto out; >>>>> idr_init(&drvdata->idr); >>>>> mutex_init(&drvdata->idr_mutex); >>>>> dev_list = &etr_devs; >>>>> @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) >>>>> goto out; >>>>> } >>>>> + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) >>>>> + ret = tmc_etr_setup_caps(dev, devid); >>>>> + >>>> >>>> With this change, we silently accept an ETR that may only have "SECURE" access only and crash later while we try to enable tracing. You could >>>> pass in the "access" (which is already in 'desc.access' in the original >>>> call site and deal with it ? >>> >>> Just wondering, if something like the following will help ? A failed tmc_etr_setup_caps() >>> because of failed tmc_etr_has_non_secure_access(), will unregister the coresight device >>> before returning. >>> >>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c >>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c >>> @@ -538,8 +538,13 @@ static int __tmc_probe(struct device *dev, struct resource *res) >>> goto out; >>> } >>> - if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) >>> + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { >>> ret = tmc_etr_setup_caps(dev, devid); >>> + if (ret) { >>> + coresight_unregister(drvdata->csdev); >>> + goto out; >>> + } >>> + } >> >> Why do we move the tmc_etr_setup_caps() in the first place ? We could retain where that was and pass "desc.access" parameter rather than registering the csdev and then relying csdev->access ? > > Agreed, and after implementing the changes suggested above, the entire patch > will look something like the following. Please do confirm if this looks good > enough. > > --- a/drivers/hwtracing/coresight/coresight-tmc-core.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c > @@ -370,16 +370,25 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) > return (auth & TMC_AUTH_NSID_MASK) == 0x3; > } > > +#define TMC_AMBA_MASK 0xfffff > + > +static const struct amba_id tmc_ids[]; > + > /* Detect and initialise the capabilities of a TMC ETR */ > -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) > +static int tmc_etr_setup_caps(struct device *parent, u32 devid, > + struct csdev_access *access) > { > int rc; > - u32 dma_mask = 0; > + u32 tmc_pid, dma_mask = 0; > struct tmc_drvdata *drvdata = dev_get_drvdata(parent); > + void *dev_caps; > > if (!tmc_etr_has_non_secure_access(drvdata)) > return -EACCES; > > + tmc_pid = coresight_get_pid(access) & TMC_AMBA_MASK; > + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); > + > /* Set the unadvertised capabilities */ > tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); > > @@ -497,8 +506,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) > desc.type = CORESIGHT_DEV_TYPE_SINK; > desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; > desc.ops = &tmc_etr_cs_ops; > - ret = tmc_etr_setup_caps(dev, devid, > - coresight_get_uci_data(id)); > + ret = tmc_etr_setup_caps(dev, devid, &desc.access); > if (ret) > goto out; > idr_init(&drvdata->idr); > That looks much better. Thanks Suzuki
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c index 7ec5365e2b64..e71db3099a29 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) return (auth & TMC_AUTH_NSID_MASK) == 0x3; } +#define TMC_AMBA_MASK 0xfffff + +static const struct amba_id tmc_ids[]; + /* Detect and initialise the capabilities of a TMC ETR */ -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps) +static int tmc_etr_setup_caps(struct device *parent, u32 devid) { int rc; - u32 dma_mask = 0; + u32 tmc_pid, dma_mask = 0; struct tmc_drvdata *drvdata = dev_get_drvdata(parent); + void *dev_caps; if (!tmc_etr_has_non_secure_access(drvdata)) return -EACCES; + tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK; + dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid); + /* Set the unadvertised capabilities */ tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps); @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) desc.type = CORESIGHT_DEV_TYPE_SINK; desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM; desc.ops = &tmc_etr_cs_ops; - ret = tmc_etr_setup_caps(dev, devid, - coresight_get_uci_data(id)); - if (ret) - goto out; idr_init(&drvdata->idr); mutex_init(&drvdata->idr_mutex); dev_list = &etr_devs; @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) goto out; } + if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) + ret = tmc_etr_setup_caps(dev, devid); + drvdata->miscdev.name = desc.name; drvdata->miscdev.minor = MISC_DYNAMIC_MINOR; drvdata->miscdev.fops = &tmc_fops;