linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	coresight@lists.linaro.org, mike.leach@linaro.org,
	robert.walker@arm.com, Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Subject: [PATCH 22/25] coresight: Use platform agnostic names
Date: Wed, 20 Mar 2019 18:49:39 +0000	[thread overview]
Message-ID: <1553107783-3340-23-git-send-email-suzuki.poulose@arm.com> (raw)
In-Reply-To: <1553107783-3340-1-git-send-email-suzuki.poulose@arm.com>

So far we have reused the name of the "platform" device for
the CoreSight device. But this is not very intuitive when
we move to ACPI. Also, the ACPI device names have ":" in them
(e.g, ARMHC97C:01), which the perf tool doesn't like very much.
This patch introduces a generic naming scheme, givin more intuitive
names for the devices that appear on the CoreSight bus.
The names follow the pattern "prefix" followed by "index" (e.g, etm5).
We maintain a list of allocated devices per "prefix" to make sure
we don't allocate a new name when it is reprobed (e.g, due to
unsatisifed device dependencies). So, we maintain the list
of "fwnodes" of the parent devices to allocate a consistent name.
All devices except the ETMs get an index allocated in the order
of probing. ETMs get an index based on the CPU they are attached to.

TMC devices are named using "tmc_etf", "tmc_etb", and "tmc_etr"
prefixes depending on the configuration of the device.

The replicators are not classified as dynamic/static anymore.
One could easily figure that out by checking the presence of
"mgmt" registers under sysfs.

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-catu.c       |  7 +++
 drivers/hwtracing/coresight/coresight-etb10.c      |  6 +++
 drivers/hwtracing/coresight/coresight-etm3x.c      |  5 ++
 drivers/hwtracing/coresight/coresight-etm4x.c      |  4 ++
 drivers/hwtracing/coresight/coresight-funnel.c     |  6 +++
 drivers/hwtracing/coresight/coresight-replicator.c |  7 +++
 drivers/hwtracing/coresight/coresight-stm.c        |  6 +++
 drivers/hwtracing/coresight/coresight-tmc.c        | 14 ++++++
 drivers/hwtracing/coresight/coresight-tpiu.c       |  6 +++
 drivers/hwtracing/coresight/coresight.c            | 58 ++++++++++++++++++++++
 include/linux/coresight.h                          | 25 +++++++++-
 11 files changed, 143 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
index 4595c67..6492bce 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -28,6 +28,8 @@
 #define catu_dbg(x, ...) do {} while (0)
 #endif
 
+DEFINE_CORESIGHT_DEVLIST(catu_devs, "catu");
+
 struct catu_etr_buf {
 	struct tmc_sg_table *catu_table;
 	dma_addr_t sladdr;
@@ -510,6 +512,11 @@ static int catu_probe(struct amba_device *adev, const struct amba_id *id)
 		ret = PTR_ERR(pdata);
 		goto out;
 	}
+
+	pdata->name = coresight_alloc_device_name(&catu_devs, dev);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	dev->platform_data = pdata;
 
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c
index e4175849..42b525c 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -62,6 +62,8 @@
 #define ETB_FFSR_BIT		1
 #define ETB_FRAME_SIZE_WORDS	4
 
+DEFINE_CORESIGHT_DEVLIST(etb10_devs, "etb10_");
+
 /**
  * struct etb_drvdata - specifics associated to an ETB component
  * @base:	memory mapped base address for this component.
@@ -692,6 +694,10 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
 	pdata = coresight_get_platform_data(dev);
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
+	pdata->name = coresight_alloc_device_name(&etb10_devs, dev);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	adev->dev.platform_data = pdata;
 
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c
index b101464..35ed953 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x.c
@@ -797,6 +797,11 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
 
+	pdata->name  = devm_kasprintf(dev, GFP_KERNEL,
+				      "etm%d", pdata->cpu);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	adev->dev.platform_data = pdata;
 	drvdata->use_cp14 = fwnode_property_read_bool(dev->fwnode, "arm,cp14");
 	dev_set_drvdata(dev, drvdata);
diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c
index bfc23ab..55fcb78 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x.c
@@ -982,6 +982,10 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	pdata = coresight_get_platform_data(dev);
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
+	pdata->name = devm_kasprintf(dev, GFP_KERNEL, "etm%d", pdata->cpu);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	adev->dev.platform_data = pdata;
 
 	dev_set_drvdata(dev, drvdata);
diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c
index 2590744..96b6773 100644
--- a/drivers/hwtracing/coresight/coresight-funnel.c
+++ b/drivers/hwtracing/coresight/coresight-funnel.c
@@ -27,6 +27,8 @@
 #define FUNNEL_HOLDTIME		(0x7 << FUNNEL_HOLDTIME_SHFT)
 #define FUNNEL_ENSx_MASK	0xff
 
+DEFINE_CORESIGHT_DEVLIST(funnel_devs, "funnel");
+
 /**
  * struct funnel_drvdata - specifics associated to a funnel component
  * @base:	memory mapped base address for this component.
@@ -189,6 +191,10 @@ static int funnel_probe(struct amba_device *adev, const struct amba_id *id)
 	pdata = coresight_get_platform_data(dev);
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
+	pdata->name = coresight_alloc_device_name(&funnel_devs, dev);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	adev->dev.platform_data = pdata;
 
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c
index 7eb3bf7..7b937c0 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -22,6 +22,8 @@
 #define REPLICATOR_IDFILTER0		0x000
 #define REPLICATOR_IDFILTER1		0x004
 
+DEFINE_CORESIGHT_DEVLIST(replicator_devs, "replicator");
+
 /**
  * struct replicator_drvdata - specifics associated to a replicator component
  * @base:	memory mapped base address for this component. Also indicates
@@ -184,6 +186,11 @@ static int replicator_probe(struct device *dev, struct resource *res)
 		return PTR_ERR(pdata);
 	dev->platform_data = pdata;
 
+	pdata->name = coresight_alloc_device_name(&replicator_devs, dev);
+
+	if (!pdata->name)
+		return -ENOMEM;
+
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
 	if (!drvdata)
 		return -ENOMEM;
diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
index 6514586..d94ae22 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -107,6 +107,8 @@ struct channel_space {
 	unsigned long		*guaranteed;
 };
 
+DEFINE_CORESIGHT_DEVLIST(stm_devs, "stm");
+
 /**
  * struct stm_drvdata - specifics associated to an STM component
  * @base:		memory mapped base address for this component.
@@ -813,6 +815,10 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
 	pdata = coresight_get_platform_data(dev);
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
+	pdata->name = coresight_alloc_device_name(&stm_devs, dev);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	adev->dev.platform_data = pdata;
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
 	if (!drvdata)
diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c
index 147ab17..030303d 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc.c
@@ -25,6 +25,10 @@
 #include "coresight-priv.h"
 #include "coresight-tmc.h"
 
+DEFINE_CORESIGHT_DEVLIST(etb_devs, "tmc_etb");
+DEFINE_CORESIGHT_DEVLIST(etf_devs, "tmc_etf");
+DEFINE_CORESIGHT_DEVLIST(etr_devs, "tmc_etr");
+
 void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata)
 {
 	/* Ensure formatter, unformatter and hardware fifo are empty */
@@ -394,6 +398,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
 	struct tmc_drvdata *drvdata;
 	struct resource *res = &adev->res;
 	struct coresight_desc desc = { 0 };
+	struct coresight_dev_list *dev_list = NULL;
 
 	pdata = coresight_get_platform_data(dev);
 	if (IS_ERR(pdata)) {
@@ -440,6 +445,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_BUFFER;
 		desc.ops = &tmc_etb_cs_ops;
+		dev_list = &etb_devs;
 		break;
 	case TMC_CONFIG_TYPE_ETR:
 		desc.type = CORESIGHT_DEV_TYPE_SINK;
@@ -449,11 +455,13 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
 					 coresight_get_uci_data(id));
 		if (ret)
 			goto out;
+		dev_list = &etr_devs;
 		break;
 	case TMC_CONFIG_TYPE_ETF:
 		desc.type = CORESIGHT_DEV_TYPE_LINKSINK;
 		desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_FIFO;
 		desc.ops = &tmc_etf_cs_ops;
+		dev_list = &etf_devs;
 		break;
 	default:
 		pr_err("%s: Unsupported TMC config\n", pdata->name);
@@ -461,6 +469,12 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
 		goto out;
 	}
 
+	pdata->name = coresight_alloc_device_name(dev_list, dev);
+	if (!pdata->name) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	drvdata->csdev = coresight_register(&desc);
 	if (IS_ERR(drvdata->csdev)) {
 		ret = PTR_ERR(drvdata->csdev);
diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c
index 18a749a..f5cc457 100644
--- a/drivers/hwtracing/coresight/coresight-tpiu.c
+++ b/drivers/hwtracing/coresight/coresight-tpiu.c
@@ -46,6 +46,8 @@
 #define FFCR_FON_MAN		BIT(6)
 #define FFCR_STOP_FI		BIT(12)
 
+DEFINE_CORESIGHT_DEVLIST(tpiu_devs, "tpiu");
+
 /**
  * @base:	memory mapped base address for this component.
  * @dev:	the coresight device entity associated to this component.
@@ -124,6 +126,10 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
 	pdata = coresight_get_platform_data(dev);
 	if (IS_ERR(pdata))
 		return PTR_ERR(pdata);
+	pdata->name = coresight_alloc_device_name(&tpiu_devs, dev);
+	if (!pdata->name)
+		return -ENOMEM;
+
 	adev->dev.platform_data = pdata;
 
 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 9cdedab..ca40c55 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1253,3 +1253,61 @@ void coresight_unregister(struct coresight_device *csdev)
 	device_unregister(&csdev->dev);
 }
 EXPORT_SYMBOL_GPL(coresight_unregister);
+
+
+/*
+ * coresight_search_device_idx - Search the fwnode handle of a device
+ * in the given dev_idx list. Must be called with the coresight_mutex held.
+ *
+ * Returns the index of the entry, when found. Otherwise, -ENOENT.
+ */
+static inline int coresight_search_device_idx(struct coresight_dev_list *dict,
+					      struct fwnode_handle *fwnode)
+{
+	int i;
+
+	for (i = 0; i < dict->nr_idx; i++)
+		if (dict->fwnode_list[i] == fwnode)
+			return i;
+	return -ENOENT;
+}
+
+/*
+ * coresight_alloc_device_name - Get an index for a given device in the
+ * device index list specific to a driver. An index is allocated for a
+ * device and is tracked with the fwnode_handle to prevent allocating
+ * duplicate indices for the same device (e.g, if we defer probing of
+ * a device due to dependencies), in case the index is requested again.
+ */
+char *coresight_alloc_device_name(struct coresight_dev_list *dict,
+				  struct device *dev)
+{
+	int idx;
+	char *name = NULL;
+	struct fwnode_handle **list;
+
+	mutex_lock(&coresight_mutex);
+
+	idx = coresight_search_device_idx(dict, dev_fwnode(dev));
+	if (idx < 0) {
+		/* Make space for the new entry */
+		idx = dict->nr_idx;
+		list = krealloc(dict->fwnode_list,
+				(idx + 1) * sizeof(*dict->fwnode_list),
+				GFP_KERNEL);
+		if (ZERO_OR_NULL_PTR(list)) {
+			idx = -ENOMEM;
+			goto done;
+		}
+
+		list[idx] = dev_fwnode(dev);
+		dict->fwnode_list = list;
+		dict->nr_idx = idx + 1;
+	}
+
+	name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", dict->pfx, idx);
+done:
+	mutex_unlock(&coresight_mutex);
+	return name;
+}
+EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 76c31b2..9d933bb 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -174,6 +174,28 @@ struct coresight_device {
 	struct dev_ext_attribute *ea;
 };
 
+/*
+ * coresight_dev_list - Mapping for devices to "name" index for device
+ * names.
+ *
+ * @nr_idx:		Number of entries already allocated.
+ * @pfx:		Prefix pattern for device name.
+ * @fwnode_list:	Array of fwnode_handles associated with each allocated
+ *			index, upto nr_idx entries.
+ */
+struct coresight_dev_list {
+	int			nr_idx;
+	const char		*pfx;
+	struct fwnode_handle	**fwnode_list;
+};
+
+#define DEFINE_CORESIGHT_DEVLIST(var, dev_pfx)				\
+static struct coresight_dev_list (var) = {				\
+						.pfx = dev_pfx,		\
+						.nr_idx = 0,		\
+						.fwnode_list = NULL,	\
+}
+
 #define to_coresight_device(d) container_of(d, struct coresight_device, dev)
 
 #define source_ops(csdev)	csdev->ops->source_ops
@@ -266,7 +288,8 @@ extern int coresight_claim_device_unlocked(void __iomem *base);
 
 extern void coresight_disclaim_device(void __iomem *base);
 extern void coresight_disclaim_device_unlocked(void __iomem *base);
-
+extern char *coresight_alloc_device_name(struct coresight_dev_list *devs,
+					 struct device *dev);
 #else
 static inline struct coresight_device *
 coresight_register(struct coresight_desc *desc) { return NULL; }
-- 
2.7.4


  parent reply	other threads:[~2019-03-20 18:51 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 18:49 [PATCH 00/25] coresight: Support for ACPI bindings Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 01/25] coresight: tmc: Report DMA setup failures Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 02/25] coresight: dynamic-replicator: Clean up error handling Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 03/25] coresight: replicator: Prepare for merging with dynamic-replicator Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 04/25] coresight: dynamic-replicator: Prepare for merging with static replicator Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 05/25] coresight: Merge the static and dynamic replicator drivers Suzuki K Poulose
2019-03-27 15:27   ` Mathieu Poirier
2019-03-27 17:33     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 06/25] coresight: funnel: Clean up device book keeping Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 07/25] coresight: replicator: Cleanup device tracking Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 08/25] coresight: tmc: Clean up device specific data Suzuki K Poulose
2019-03-26 21:53   ` Mathieu Poirier
2019-03-27 11:45     ` Suzuki K Poulose
2019-03-27 14:42     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 09/25] coresight: catu: Cleanup " Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 10/25] coresight: tpiu: Clean up " Suzuki K Poulose
2019-03-26 21:54   ` Mathieu Poirier
2019-03-27 11:52     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 11/25] coresight: stm: Cleanup " Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 12/25] coresight: etm: Clean up " Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 13/25] coresight: etb10: " Suzuki K Poulose
2019-03-27 21:39   ` Mathieu Poirier
2019-03-28 11:09     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 14/25] coresight: Rename of_coresight to coresight-platform Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 15/25] coresight: etm3x: Rearrange cp14 access detection Suzuki K Poulose
2019-03-27 22:05   ` Mathieu Poirier
2019-03-28 11:03     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 16/25] coresight: stm: Rearrange probing the stimulus area Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 17/25] coresight: tmc-etr: Rearrange probing default buffer size Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 18/25] coresight: Introduce generic platform data helper Suzuki K Poulose
2019-03-27 22:57   ` Mathieu Poirier
2019-03-28 10:59     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 19/25] coresight: Make device to CPU mapping generic Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 20/25] coresight: platform: Use fwnode handle for device search Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 21/25] coresight: Use fwnode handle instead of device names Suzuki K Poulose
2019-03-28 17:42   ` Mathieu Poirier
2019-03-28 18:42     ` Suzuki K Poulose
2019-03-20 18:49 ` Suzuki K Poulose [this message]
2019-03-28 19:43   ` [PATCH 22/25] coresight: Use platform agnostic names Mathieu Poirier
2019-03-20 18:49 ` [PATCH 23/25] coresight: stm: ACPI support for parsing stimulus base Suzuki K Poulose
2019-03-28 20:41   ` Mathieu Poirier
2019-04-04 11:27     ` Suzuki K Poulose
2019-03-20 18:49 ` [PATCH 24/25] coresight: Support for ACPI bindings Suzuki K Poulose
2019-03-29 19:09   ` Mathieu Poirier
2019-03-20 18:49 ` [PATCH 25/25] coresight: acpi: Support for components Suzuki K Poulose
2019-03-20 18:49 ` [TEST PATCH 26/25] edk2-platform: juno: Update ACPI CoreSight Bindings Suzuki K Poulose
2019-03-22 10:13 ` [PATCH 00/25] coresight: Support for ACPI bindings Suzuki K Poulose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1553107783-3340-23-git-send-email-suzuki.poulose@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=coresight@lists.linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=robert.walker@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).