Skip to contentSkip to conversation

coresight: Move remaining AMBA ACPI devices into platform driver

PATCH Superseded Anshuman Khandual 3 participants 25 messages Jan 23, 2024 – Feb 22, 2024

Subsystems (5)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover coresight: Move remaining AMBA ACPI devices into platform driver

This moves remaining AMBA ACPI devices into respective platform drivers for enabling ACPI based power management support. This series applies on kernel v6.8-rc1 release. This series has been built, and boot tested on a DT based coresight platform. Although this still requires some more testing on ACPI based coresight platforms.

https://git.gitlab.arm.com/linux-arm/linux-anshuman.git (amba_other_acpi_migration_v4)

Cc Lorenzo Pieralisi <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Mike Leach <[email protected]>
Cc James Clark <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>

Changes in V4:

- Fixed PM imbalance in etm4_probe() error path with pm_runtime_disable()
- Restored back the pm_runtime_disable() on platform probe error paths in replicator, funnel, catu, tpiu, tmc and stm devices
- Dropped dev_caps argument from __tmc_probe()
- Changed xxxx_platform_remove() for platform_driver->remove_new() callback

Changes in V3:

https://lore.kernel.org/all/[email protected]/

- Split coresight_init_driver/remove_driver() helpers into a separate patch
- Added 'drvdata->pclk' comments in replicator, funnel, tpiu, tmc, and stm devices
- Updated funnel, and replicator drivers to use these new helpers
- Check for drvdata instead of drvdata->pclk in suspend and resume paths in catu, tmc and debug devices
- Added patch to extract device name from AMBA pid based table lookup for stm
- Added patch to extract device properties from AMBA pid based table look for tmc
- Dropped pm_runtime_put() from common __probe() functions
- Handled pm_runtime_put() in AMBA driver in success path
- Handled pm_runtime_put() in platform driver in both success and error paths

Changes in V2:

https://lore.kernel.org/all/[email protected]/

- Dropped redundant devm_ioremap_resource() hunk from tmc_platform_probe()
- Defined coresight_[init|remove]_driver() for both AMBA/platform drivers
- Changed catu, tmc, tpiu, stm and debug coresight drivers to use the new helpers avoiding build issues arising from module_amba_driver(), and module_platform_driver() being on the same file

Changes in V1:

https://lore.kernel.org/all/[email protected]/

- Replaced all IS_ERR() instances with IS_ERR_OR_NULL() as per Suzuki

Changes in RFC:

https://lore.kernel.org/all/[email protected]/

Anshuman Khandual (11):
coresight: etm4x: Fix unbalanced pm_runtime_enable()
coresight: stm: Extract device name from AMBA pid based table lookup
coresight: tmc: Extract device properties from AMBA pid based table lookup
coresight: Add helpers registering/removing both AMBA and platform drivers
coresight: replicator: Move ACPI support from AMBA driver to platform driver
coresight: funnel: Move ACPI support from AMBA driver to platform driver
coresight: catu: Move ACPI support from AMBA driver to platform driver
coresight: tpiu: Move ACPI support from AMBA driver to platform driver
coresight: tmc: Move ACPI support from AMBA driver to platform driver
coresight: stm: Move ACPI support from AMBA driver to platform driver
coresight: debug: Move ACPI support from AMBA driver to platform driver

 drivers/acpi/arm64/amba.c                     |   8 -
 drivers/hwtracing/coresight/coresight-catu.c  | 142 +++++++++++++---
 drivers/hwtracing/coresight/coresight-catu.h  |   1 +
 drivers/hwtracing/coresight/coresight-core.c  |  29 ++++
 .../hwtracing/coresight/coresight-cpu-debug.c | 141 ++++++++++++++--
 .../coresight/coresight-etm4x-core.c          |   3 +
 .../hwtracing/coresight/coresight-funnel.c    |  86 +++++-----
 drivers/hwtracing/coresight/coresight-priv.h  |  10 ++
 .../coresight/coresight-replicator.c          |  81 ++++-----
 drivers/hwtracing/coresight/coresight-stm.c   | 117 +++++++++++--
 .../hwtracing/coresight/coresight-tmc-core.c  | 158 +++++++++++++++---
 drivers/hwtracing/coresight/coresight-tmc.h   |   2 +
 drivers/hwtracing/coresight/coresight-tpiu.c  | 102 +++++++++--
 include/linux/coresight.h                     |   7 +
 14 files changed, 726 insertions(+), 161 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/11 coresight: etm4x: Fix unbalanced pm_runtime_enable()

There is an unbalanced pm_runtime_enable() in etm4_probe_platform_dev() when etm4_probe() fails. This problem can be observed via the coresight etm4 module's (load -> unload -> load) sequence when etm4_probe() fails in etm4_probe_platform_dev().

[   63.379943] coresight-etm4x 7040000.etm: Unbalanced pm_runtime_enable!
[   63.393630] coresight-etm4x 7140000.etm: Unbalanced pm_runtime_enable!
[   63.407455] coresight-etm4x 7240000.etm: Unbalanced pm_runtime_enable!
[   63.420983] coresight-etm4x 7340000.etm: Unbalanced pm_runtime_enable!
[   63.420999] coresight-etm4x 7440000.etm: Unbalanced pm_runtime_enable!
[   63.441209] coresight-etm4x 7540000.etm: Unbalanced pm_runtime_enable!
[   63.454689] coresight-etm4x 7640000.etm: Unbalanced pm_runtime_enable!
[   63.474982] coresight-etm4x 7740000.etm: Unbalanced pm_runtime_enable!

This fixes the above problem - with an explicit pm_runtime_disable() call when etm4_probe() fails during etm4_probe_platform_dev().

Cc Lorenzo Pieralisi <[email protected]>
Cc Hanjun Guo <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Mike Leach <[email protected]>
Cc James Clark <[email protected]>
Cc Leo Yan <[email protected]>

---
Changes in V4:

- New patch in the series

 drivers/hwtracing/coresight/coresight-etm4x-core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -0
index ce1995a2827f..7c693b45ac05 100644
@@ -2217,6 +2217,9 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
 	ret = etm4_probe(&pdev->dev);
 
 	pm_runtime_put(&pdev->dev);
+	if (ret)
+		pm_runtime_disable(&pdev->dev);
+
 	return ret;
 }
 
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH V4 01/11] coresight: etm4x: Fix unbalanced pm_runtime_enable()

Quoted 14 lines · Anshuman Khandual

There is an unbalanced pm_runtime_enable() in etm4_probe_platform_dev() when etm4_probe() fails. This problem can be observed via the coresight etm4 module's (load -> unload -> load) sequence when etm4_probe() fails in etm4_probe_platform_dev().

[   63.379943] coresight-etm4x 7040000.etm: Unbalanced pm_runtime_enable!
[   63.393630] coresight-etm4x 7140000.etm: Unbalanced pm_runtime_enable!
[   63.407455] coresight-etm4x 7240000.etm: Unbalanced pm_runtime_enable!
[   63.420983] coresight-etm4x 7340000.etm: Unbalanced pm_runtime_enable!
[   63.420999] coresight-etm4x 7440000.etm: Unbalanced pm_runtime_enable!
[   63.441209] coresight-etm4x 7540000.etm: Unbalanced pm_runtime_enable!
[   63.454689] coresight-etm4x 7640000.etm: Unbalanced pm_runtime_enable!
[   63.474982] coresight-etm4x 7740000.etm: Unbalanced pm_runtime_enable!
Quoted 2 lines

This fixes the above problem - with an explicit pm_runtime_disable() call when etm4_probe() fails during etm4_probe_platform_dev().

Fixes 5214b563588e ("coresight: etm4x: Add support for sysreg only devices"
Quoted 28 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Hanjun Guo <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Mike Leach <[email protected]>
Cc James Clark <[email protected]>
Cc Leo Yan <[email protected]>

---
Changes in V4:

- New patch in the series

  drivers/hwtracing/coresight/coresight-etm4x-core.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
index ce1995a2827f..7c693b45ac05 100644

drivers/hwtracing/coresight/coresight-etm4x-core.c static int etm4_probe_platform_dev(struct platform_device *pdev) · line 2225

Quoted 9 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -0
@@ -2217,6 +2217,9 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
  	ret = etm4_probe(&pdev->dev);
 
  	pm_runtime_put(&pdev->dev);
+	if (ret)
+		pm_runtime_disable(&pdev->dev);
+
  	return ret;
  }
 

Looks good to me. I have glanced through the other platform device driver code in coresight subsystem and they all seem to be safe, except for Ultrasoc-smb, which doesn't do any power managment. It may be, because it is only supported on an ACPI system.

Suzuki

#3 lore raw

Re: [PATCH V4 01/11] coresight: etm4x: Fix unbalanced pm_runtime_enable()

Quoted 15 lines · Suzuki K Poulose
Quoted 14 lines · Anshuman Khandual

There is an unbalanced pm_runtime_enable() in etm4_probe_platform_dev() when etm4_probe() fails. This problem can be observed via the coresight etm4 module's (load -> unload -> load) sequence when etm4_probe() fails in etm4_probe_platform_dev().

[   63.379943] coresight-etm4x 7040000.etm: Unbalanced pm_runtime_enable! [   63.393630] coresight-etm4x 7140000.etm: Unbalanced pm_runtime_enable! [   63.407455] coresight-etm4x 7240000.etm: Unbalanced pm_runtime_enable! [   63.420983] coresight-etm4x 7340000.etm: Unbalanced pm_runtime_enable! [   63.420999] coresight-etm4x 7440000.etm: Unbalanced pm_runtime_enable! [   63.441209] coresight-etm4x 7540000.etm: Unbalanced pm_runtime_enable! [   63.454689] coresight-etm4x 7640000.etm: Unbalanced pm_runtime_enable! [   63.474982] coresight-etm4x 7740000.etm: Unbalanced pm_runtime_enable!

Quoted 4 lines
Quoted 2 lines

This fixes the above problem - with an explicit pm_runtime_disable() call when etm4_probe() fails during etm4_probe_platform_dev().

Fixes 5214b563588e ("coresight: etm4x: Add support for sysreg only devices"

Sure, will add this 'Fixes' tag here.

Quoted 24 lines
Quoted 24 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Hanjun Guo <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Mike Leach <[email protected]>
Cc James Clark <[email protected]>
Cc Leo Yan <[email protected]>

---
Changes in V4:

- New patch in the series

  drivers/hwtracing/coresight/coresight-etm4x-core.c | 3 +++

  1 file changed, 3 insertions(+)
Quoted 16 lines
Quoted 12 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -0
index ce1995a2827f..7c693b45ac05 100644
@@ -2217,6 +2217,9 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
       ret = etm4_probe(&pdev->dev);
         pm_runtime_put(&pdev->dev);
+    if (ret)
+        pm_runtime_disable(&pdev->dev);
+
       return ret;
   }
Quoted 1 line

Looks good to me. I have glanced through the other platform device driver code in coresight subsystem and they all seem to be safe, except for Ultrasoc-smb, which doesn't do any power managment. It may be, because it is only supported on an ACPI system.

Understood.

#4 lore raw

PATCH v4 2/11 coresight: stm: Extract device name from AMBA pid based table lookup

In reply to Anshuman Khandual

Instead of using AMBA private data field, extract the device name from AMBA pid based table lookup using new coresight_get_uci_data_from_amba() helper.

---
 drivers/hwtracing/coresight/coresight-priv.h | 10 ++++++++++
 drivers/hwtracing/coresight/coresight-stm.c  | 14 +++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-priv.h +10 -0
index 767076e07970..68cbb036cec8 100644
@@ -221,6 +221,16 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
 	return uci_id->data;
 }
 
+static inline void *coresight_get_uci_data_from_amba(const struct amba_id *table, u32 pid)
+{
+	while (table->mask) {
+		if ((table->id & table->mask) == pid)
+			return coresight_get_uci_data(table);
+		table++;
+	};
+	return NULL;
+}
+
 void coresight_release_platform_data(struct coresight_device *csdev,
 				     struct device *dev,
 				     struct coresight_platform_data *pdata);
drivers/hwtracing/coresight/coresight-stm.c +13 -1
index a1c27c901ad1..9cdca4f86cab 100644
@@ -804,6 +804,18 @@ static void stm_init_generic_data(struct stm_drvdata *drvdata,
 	drvdata->stm.set_options = stm_generic_set_options;
 }
 
+#define STM_AMBA_MASK 0xfffff
+
+static const struct amba_id stm_ids[];
+
+static char *stm_csdev_name(struct coresight_device *csdev)
+{
+	u32 stm_pid = coresight_get_pid(&csdev->access) & STM_AMBA_MASK;
+	void *uci_data = coresight_get_uci_data_from_amba(stm_ids, stm_pid);
+
+	return uci_data ? (char *)uci_data : "STM";
+}
+
 static int stm_probe(struct amba_device *adev, const struct amba_id *id)
 {
 	int ret, trace_id;
@@ -900,7 +912,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
 	pm_runtime_put(&adev->dev);
 
 	dev_info(&drvdata->csdev->dev, "%s initialized\n",
-		 (char *)coresight_get_uci_data(id));
+		 stm_csdev_name(drvdata->csdev));
 	return 0;
 
 cs_unregister:
Signature · 1 line
2.25.1
maintainer
#5 lore raw

Re: [PATCH V4 02/11] coresight: stm: Extract device name from AMBA pid based table lookup

Quoted 21 lines · Anshuman Khandual

Instead of using AMBA private data field, extract the device name from AMBA pid based table lookup using new coresight_get_uci_data_from_amba() helper.

---
  drivers/hwtracing/coresight/coresight-priv.h | 10 ++++++++++
  drivers/hwtracing/coresight/coresight-stm.c  | 14 +++++++++++++-
  2 files changed, 23 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-priv.h +0 -0
index 767076e07970..68cbb036cec8 100644

drivers/hwtracing/coresight/coresight-priv.h static inline void *coresight_get_uci_data(const struct amba_id *id) · line 227

Quoted 7 lines
drivers/hwtracing/coresight/coresight-priv.h +4 -0
@@ -221,6 +221,16 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
  	return uci_id->data;
  }
 
+static inline void *coresight_get_uci_data_from_amba(const struct amba_id *table, u32 pid)
+{
+	while (table->mask) {
+		if ((table->id & table->mask) == pid)

Why are we masking table->id ? table->id is a static value that the driver wants to check for "variants" of a given device. The table->mask is there to filter out the "irrelevant" bits of the PID that we read from the device. So this should instead be:

		if ((table->mask & pid) == table->id)
Quoted 14 lines
drivers/hwtracing/coresight/coresight-priv.h +6 -0
+			return coresight_get_uci_data(table);
+		table++;
+	};
+	return NULL;
+}
+
  void coresight_release_platform_data(struct coresight_device *csdev,
  				     struct device *dev,
  				     struct coresight_platform_data *pdata);
drivers/hwtracing/coresight/coresight-stm.c +0 -0
index a1c27c901ad1..9cdca4f86cab 100644

drivers/hwtracing/coresight/coresight-stm.c static void stm_init_generic_data(struct stm_drvdata *drvdata, · line 813

Quoted 10 lines
drivers/hwtracing/coresight/coresight-stm.c +7 -0
@@ -804,6 +804,18 @@ static void stm_init_generic_data(struct stm_drvdata *drvdata,
  	drvdata->stm.set_options = stm_generic_set_options;
  }
 
+#define STM_AMBA_MASK 0xfffff
+
+static const struct amba_id stm_ids[];
+
+static char *stm_csdev_name(struct coresight_device *csdev)
+{
+	u32 stm_pid = coresight_get_pid(&csdev->access) & STM_AMBA_MASK;

Similar to above:

Why do we apply a "custom" mask to the PID and later check the PID with that of the table->pid.

The way it is supposed work is :

	(table->mask & dev_pid) == table->pid

the table->mask is there for a reason: i.e., to get the relevant bits from the device_pid and compare it against "the" expected value (table->pid).

Suzuki

Quoted 17 lines
drivers/hwtracing/coresight/coresight-stm.c +6 -1
+	void *uci_data = coresight_get_uci_data_from_amba(stm_ids, stm_pid);
+
+	return uci_data ? (char *)uci_data : "STM";
+}
+
  static int stm_probe(struct amba_device *adev, const struct amba_id *id)
  {
  	int ret, trace_id;
@@ -900,7 +912,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
  	pm_runtime_put(&adev->dev);
 
  	dev_info(&drvdata->csdev->dev, "%s initialized\n",
-		 (char *)coresight_get_uci_data(id));
+		 stm_csdev_name(drvdata->csdev));
  	return 0;
 
  cs_unregister:
#6 lore raw

Re: [PATCH V4 02/11] coresight: stm: Extract device name from AMBA pid based table lookup

Quoted 34 lines · Suzuki K Poulose
Quoted 21 lines · Anshuman Khandual

Instead of using AMBA private data field, extract the device name from AMBA pid based table lookup using new coresight_get_uci_data_from_amba() helper.

---
  drivers/hwtracing/coresight/coresight-priv.h | 10 ++++++++++ drivers/hwtracing/coresight/coresight-stm.c  | 14 +++++++++++++-

  2 files changed, 23 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-priv.h +0 -0
index 767076e07970..68cbb036cec8 100644

drivers/hwtracing/coresight/coresight-priv.h static inline void *coresight_get_uci_data(const struct amba_id *id) · line 226

Quoted 6 lines
drivers/hwtracing/coresight/coresight-priv.h +3 -0
@@ -221,6 +221,16 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
       return uci_id->data;
   }
   +static inline void *coresight_get_uci_data_from_amba(const struct amba_id *table, u32 pid)
+{
+    while (table->mask) {
+        if ((table->id & table->mask) == pid)

Why are we masking table->id ? table->id is a static value that the driver wants to check for "variants" of a given device. The table->mask is there to filter out the "irrelevant" bits of the PID that we read from the device. So this should instead be:

Quoted 1 line

        if ((table->mask & pid) == table->id)

Sure, will this change as suggested.

Quoted 27 lines
Quoted 18 lines
drivers/hwtracing/coresight/coresight-priv.h +6 -0
+            return coresight_get_uci_data(table);
+        table++;
+    };
+    return NULL;
+}
+
   void coresight_release_platform_data(struct coresight_device *csdev,
                        struct device *dev,
                        struct coresight_platform_data *pdata);
drivers/hwtracing/coresight/coresight-stm.c +0 -0
index a1c27c901ad1..9cdca4f86cab 100644
@@ -804,6 +804,18 @@ static void stm_init_generic_data(struct stm_drvdata *drvdata,
       drvdata->stm.set_options = stm_generic_set_options;
   }

  +#define STM_AMBA_MASK 0xfffff

drivers/hwtracing/coresight/coresight-stm.c static void stm_init_generic_data(struct stm_drvdata *drvdata, · line 813

Quoted 6 lines
drivers/hwtracing/coresight/coresight-stm.c +6 -0
+
+static const struct amba_id stm_ids[];
+
+static char *stm_csdev_name(struct coresight_device *csdev)
+{
+    u32 stm_pid = coresight_get_pid(&csdev->access) & STM_AMBA_MASK;

Similar to above:

Quoted 8 lines

Why do we apply a "custom" mask to the PID and later check the PID with that of the table->pid.

The way it is supposed work is :

    (table->mask & dev_pid) == table->pid

the table->mask is there for a reason: i.e., to get the relevant bits from the device_pid and compare it against "the" expected value (table->pid).

Understood, will change the helper as follows

static inline void *coresight_get_uci_data_from_amba(const struct amba_id *table, u32 pid)

{
        while (table->mask) {
                if ((pid & table->mask) == table->id)
                        return coresight_get_uci_data(table);
                table++;
        };
        return NULL;
}

and also drop both the custom masks STM_AMBA_MASK and TMC_AMBA_MASK.

#7 lore raw

PATCH v4 3/11 coresight: tmc: Extract device properties from AMBA pid based table lookup

In reply to Anshuman Khandual

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.

---
 .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +13 -6
index 7ec5365e2b64..e71db3099a29 100644
@@ -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;
Signature · 1 line
2.25.1
maintainer
#8 lore raw

Re: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup

Quoted 58 lines · Anshuman Khandual

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.

---
  .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------
  1 file changed, 13 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -6
index 7ec5365e2b64..e71db3099a29 100644
@@ -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;

drivers/hwtracing/coresight/coresight-tmc-core.c static int tmc_probe(struct amba_device *adev, const struct amba_id *id) · line 548

Quoted 6 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
@@ -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

Quoted 3 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
  	drvdata->miscdev.name = desc.name;
  	drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
  	drvdata->miscdev.fops = &tmc_fops;
#9 lore raw

Re: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup

Quoted 56 lines · Suzuki K Poulose
Quoted 55 lines · Anshuman Khandual

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.

---
  .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------

  1 file changed, 13 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 7ec5365e2b64..e71db3099a29 100644
@@ -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

drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
+
+static const struct amba_id tmc_ids[];
+

  /* Detect and initialise the capabilities of a TMC ETR */

drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
-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;

drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
@@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
           goto out;
Quoted 8 lines

drivers/hwtracing/coresight/coresight-tmc-core.c static int tmc_probe(struct amba_device *adev, const struct amba_id *id) · line 547

Quoted 4 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +2 -0
       }
   +    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.

drivers/hwtracing/coresight/coresight-tmc-core.c +6 -1
@@ -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;
maintainer
#10 lore raw

Re: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup

Quoted 76 lines · Anshuman Khandual
Quoted 56 lines · Suzuki K Poulose
Quoted 55 lines · Anshuman Khandual

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.

---
   .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------
   1 file changed, 13 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +8 -6
index 7ec5365e2b64..e71db3099a29 100644
@@ -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;
Quoted 8 lines

drivers/hwtracing/coresight/coresight-tmc-core.c static int tmc_probe(struct amba_device *adev, const struct amba_id *id) · line 547

Quoted 4 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +2 -0
       }
   +    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.

drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
@@ -538,8 +538,13 @@ static int __tmc_probe(struct device *dev, struct resource *res)
                 goto out;

drivers/hwtracing/coresight/coresight-tmc-core.c static int __tmc_probe(struct device *dev, struct resource *res) · line 547

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +6 -1
         }
 
-       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

Quoted 3 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
         drvdata->miscdev.name = desc.name;
         drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
#11 lore raw

Re: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup

Quoted 73 lines · Suzuki K Poulose
Quoted 72 lines · Anshuman Khandual
Quoted 56 lines · Suzuki K Poulose
Quoted 55 lines · Anshuman Khandual

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.

---
   .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------

   1 file changed, 13 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 7ec5365e2b64..e71db3099a29 100644
@@ -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

drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
+
+static const struct amba_id tmc_ids[];
+

   /* Detect and initialise the capabilities of a TMC ETR */

drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
-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;

drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
@@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
            goto out;
Quoted 8 lines

drivers/hwtracing/coresight/coresight-tmc-core.c static int tmc_probe(struct amba_device *adev, const struct amba_id *id) · line 547

Quoted 4 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +2 -0
        }
    +    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.

Quoted 15 lines

drivers/hwtracing/coresight/coresight-tmc-core.c static int __tmc_probe(struct device *dev, struct resource *res) · line 547

Quoted 13 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +6 -0
@@ -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.

drivers/hwtracing/coresight/coresight-tmc-core.c +12 -4
@@ -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);
maintainer
#12 lore raw

Re: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup

Quoted 128 lines · Anshuman Khandual
Quoted 73 lines · Suzuki K Poulose
Quoted 72 lines · Anshuman Khandual
Quoted 56 lines · Suzuki K Poulose
Quoted 55 lines · Anshuman Khandual

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.

---
    .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------
    1 file changed, 13 insertions(+), 6 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +8 -6
index 7ec5365e2b64..e71db3099a29 100644
@@ -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;
Quoted 8 lines

drivers/hwtracing/coresight/coresight-tmc-core.c static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) · line 374

Quoted 4 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +2 -0
        }
    +    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.

Quoted 15 lines

drivers/hwtracing/coresight/coresight-tmc-core.c static int __tmc_probe(struct device *dev, struct resource *res) · line 547

Quoted 13 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +6 -0
@@ -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.

drivers/hwtracing/coresight/coresight-tmc-core.c +11 -2
@@ -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);
 

drivers/hwtracing/coresight/coresight-tmc-core.c static int tmc_probe(struct amba_device *adev, const struct amba_id *id) · line 512

Quoted 9 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +1 -2
@@ -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

#13 lore raw

PATCH v4 4/11 coresight: Add helpers registering/removing both AMBA and platform drivers

In reply to Anshuman Khandual

This adds two different helpers i.e coresight_init_driver()/remove_driver() enabling coresight devices to register or remove AMBA and platform drivers.

---
 drivers/hwtracing/coresight/coresight-core.c | 29 ++++++++++++++++++++
 include/linux/coresight.h                    |  7 +++++
 2 files changed, 36 insertions(+)
drivers/hwtracing/coresight/coresight-core.c +29 -0
index d7f0e231feb9..4e897cc5da81 100644
@@ -1836,6 +1836,35 @@ static void __exit coresight_exit(void)
 module_init(coresight_init);
 module_exit(coresight_exit);
 
+int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
+			  struct platform_driver *pdev_drv)
+{
+	int ret;
+
+	ret = amba_driver_register(amba_drv);
+	if (ret) {
+		pr_err("%s: error registering AMBA driver\n", drv);
+		return ret;
+	}
+
+	ret = platform_driver_register(pdev_drv);
+	if (!ret)
+		return 0;
+
+	pr_err("%s: error registering platform driver\n", drv);
+	amba_driver_unregister(amba_drv);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(coresight_init_driver);
+
+void coresight_remove_driver(struct amba_driver *amba_drv,
+			     struct platform_driver *pdev_drv)
+{
+	amba_driver_unregister(amba_drv);
+	platform_driver_unregister(pdev_drv);
+}
+EXPORT_SYMBOL_GPL(coresight_remove_driver);
+
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Pratik Patel <[email protected]>");
 MODULE_AUTHOR("Mathieu Poirier <[email protected]>");
include/linux/coresight.h +7 -0
index a4cb7dd6ca23..7e1646d4863c 100644
@@ -12,6 +12,8 @@
 #include <linux/io.h>
 #include <linux/perf_event.h>
 #include <linux/sched.h>
+#include <linux/amba/bus.h>
+#include <linux/platform_device.h>
 
 /* Peripheral id registers (0xFD0-0xFEC) */
 #define CORESIGHT_PERIPHIDR4	0xfd0
@@ -598,6 +600,11 @@ void coresight_relaxed_write64(struct coresight_device *csdev,
 			       u64 val, u32 offset);
 void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset);
 
+int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
+			  struct platform_driver *pdev_drv);
+
+void coresight_remove_driver(struct amba_driver *amba_drv,
+			     struct platform_driver *pdev_drv);
 #else
 static inline struct coresight_device *
 coresight_register(struct coresight_desc *desc) { return NULL; }
Signature · 1 line
2.25.1
#14 lore raw

PATCH v4 5/11 coresight: replicator: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the dynamic replicator device in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for repliacator devices on ACPI based systems.

The driver would try to enable the APB clock if available. Also, rename the code to reflect the fact that it now handles both static and dynamic replicators.

---
Changes in V4:

- Added pm_runtime_disable() in replicator_platform_probe()
- Changed replicator_platform_remove() for platform_driver->remove_new()

 drivers/acpi/arm64/amba.c                     |  1 -
 .../coresight/coresight-replicator.c          | 81 ++++++++++---------
 2 files changed, 43 insertions(+), 39 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index 171b5c2c7edd..270f4e3819a2 100644
@@ -27,7 +27,6 @@ static const struct acpi_device_id amba_id_list[] = {
 	{"ARMHC503", 0}, /* ARM CoreSight Debug */
 	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
 	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
-	{"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
 	{"ARMHC9CA", 0}, /* ARM CoreSight CATU */
 	{"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
 	{"", 0},
drivers/hwtracing/coresight/coresight-replicator.c +43 -38

174 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#15 lore raw

Re: [PATCH V4 05/11] coresight: replicator: Move ACPI support from AMBA driver to platform driver

Hi Anshuman

Quoted 8 lines · Anshuman Khandual

Add support for the dynamic replicator device in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for repliacator devices on ACPI based systems.

The driver would try to enable the APB clock if available. Also, rename the code to reflect the fact that it now handles both static and dynamic replicators.

Quoted 12 lines

I think the patch is doing three different things:

1) Use new helper to register/remove AMBA/Platform drivers
2) Refactor replicator_probe() to make sure it can be reused for platform/amba driver, by moving the pm_runtime_put() to the callers.
3) Actually moving the ACPI driver to Platform driver

While (1) and (3) are obvious, (2) gave me hard time to review this patch, without proper description. If you don't mind, are you able to split the patch and add proper description of the 3 changes mentioned above.

Kind regards
Suzuki

Quoted 210 lines

---
Changes in V4:

- Added pm_runtime_disable() in replicator_platform_probe()
- Changed replicator_platform_remove() for platform_driver->remove_new()

  drivers/acpi/arm64/amba.c                     |  1 -
  .../coresight/coresight-replicator.c          | 81 ++++++++++---------
  2 files changed, 43 insertions(+), 39 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index 171b5c2c7edd..270f4e3819a2 100644
@@ -27,7 +27,6 @@ static const struct acpi_device_id amba_id_list[] = {
  	{"ARMHC503", 0}, /* ARM CoreSight Debug */
  	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
  	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
-	{"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
  	{"ARMHC9CA", 0}, /* ARM CoreSight CATU */
  	{"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
  	{"", 0},
drivers/hwtracing/coresight/coresight-replicator.c +43 -38
index 91d93060dda5..9b5f52725f43 100644
@@ -31,6 +31,7 @@ DEFINE_CORESIGHT_DEVLIST(replicator_devs, "replicator");
   * @base:	memory mapped base address for this component. Also indicates
   *		whether this one is programmable or not.
   * @atclk:	optional clock for the core parts of the replicator.
+ * @pclk:	APB clock if present, otherwise NULL
   * @csdev:	component vitals needed by the framework
   * @spinlock:	serialize enable/disable operations.
   * @check_idfilter_val: check if the context is lost upon clock removal.
@@ -38,6 +39,7 @@ DEFINE_CORESIGHT_DEVLIST(replicator_devs, "replicator");
  struct replicator_drvdata {
  	void __iomem		*base;
  	struct clk		*atclk;
+	struct clk		*pclk;
  	struct coresight_device	*csdev;
  	spinlock_t		spinlock;
  	bool			check_idfilter_val;
@@ -243,6 +245,10 @@ static int replicator_probe(struct device *dev, struct resource *res)
  			return ret;
  	}
 
+	drvdata->pclk = coresight_get_enable_apb_pclk(dev);
+	if (IS_ERR(drvdata->pclk))
+		return -ENODEV;
+
  	/*
  	 * Map the device base for dynamic-replicator, which has been
  	 * validated by AMBA core
@@ -285,7 +291,6 @@ static int replicator_probe(struct device *dev, struct resource *res)
  	}
 
  	replicator_reset(drvdata);
-	pm_runtime_put(dev);
 
  out_disable_clk:
  	if (ret && !IS_ERR_OR_NULL(drvdata->atclk))
@@ -301,29 +306,33 @@ static int replicator_remove(struct device *dev)
  	return 0;
  }
 
-static int static_replicator_probe(struct platform_device *pdev)
+static int replicator_platform_probe(struct platform_device *pdev)
  {
+	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	int ret;
 
  	pm_runtime_get_noresume(&pdev->dev);
  	pm_runtime_set_active(&pdev->dev);
  	pm_runtime_enable(&pdev->dev);
 
-	/* Static replicators do not have programming base */
-	ret = replicator_probe(&pdev->dev, NULL);
-
-	if (ret) {
-		pm_runtime_put_noidle(&pdev->dev);
+	ret = replicator_probe(&pdev->dev, res);
+	pm_runtime_put(&pdev->dev);
+	if (ret)
  		pm_runtime_disable(&pdev->dev);
-	}
 
  	return ret;
  }
 
-static void static_replicator_remove(struct platform_device *pdev)
+static void replicator_platform_remove(struct platform_device *pdev)
  {
-	replicator_remove(&pdev->dev);
+	struct replicator_drvdata *drvdata = dev_get_drvdata(&pdev->dev);
+
+	if (drvdata)
+		replicator_remove(&pdev->dev);
+
  	pm_runtime_disable(&pdev->dev);
+	if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk))
+		clk_put(drvdata->pclk);
  }
 
  #ifdef CONFIG_PM
@@ -334,6 +343,8 @@ static int replicator_runtime_suspend(struct device *dev)
  	if (drvdata && !IS_ERR(drvdata->atclk))
  		clk_disable_unprepare(drvdata->atclk);
 
+	if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk))
+		clk_disable_unprepare(drvdata->pclk);
  	return 0;
  }
 
@@ -344,6 +355,8 @@ static int replicator_runtime_resume(struct device *dev)
  	if (drvdata && !IS_ERR(drvdata->atclk))
  		clk_prepare_enable(drvdata->atclk);
 
+	if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk))
+		clk_prepare_enable(drvdata->pclk);
  	return 0;
  }
  #endif
@@ -353,31 +366,32 @@ static const struct dev_pm_ops replicator_dev_pm_ops = {
  			   replicator_runtime_resume, NULL)
  };
 
-static const struct of_device_id static_replicator_match[] = {
+static const struct of_device_id replicator_match[] = {
  	{.compatible = "arm,coresight-replicator"},
  	{.compatible = "arm,coresight-static-replicator"},
  	{}
  };
 
-MODULE_DEVICE_TABLE(of, static_replicator_match);
+MODULE_DEVICE_TABLE(of, replicator_match);
 
  #ifdef CONFIG_ACPI
-static const struct acpi_device_id static_replicator_acpi_ids[] = {
+static const struct acpi_device_id replicator_acpi_ids[] = {
  	{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
+	{"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
  	{}
  };
 
-MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);
+MODULE_DEVICE_TABLE(acpi, replicator_acpi_ids);
  #endif
 
-static struct platform_driver static_replicator_driver = {
-	.probe          = static_replicator_probe,
-	.remove_new     = static_replicator_remove,
+static struct platform_driver replicator_driver = {
+	.probe          = replicator_platform_probe,
+	.remove_new     = replicator_platform_remove,
  	.driver         = {
-		.name   = "coresight-static-replicator",
+		.name   = "coresight-replicator",
  		/* THIS_MODULE is taken care of by platform_driver_register() */
-		.of_match_table = of_match_ptr(static_replicator_match),
-		.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
+		.of_match_table = of_match_ptr(replicator_match),
+		.acpi_match_table = ACPI_PTR(replicator_acpi_ids),
  		.pm	= &replicator_dev_pm_ops,
  		.suppress_bind_attrs = true,
  	},
@@ -386,7 +400,13 @@ static struct platform_driver static_replicator_driver = {
  static int dynamic_replicator_probe(struct amba_device *adev,
  				    const struct amba_id *id)
  {
-	return replicator_probe(&adev->dev, &adev->res);
+	int ret;
+
+	ret = replicator_probe(&adev->dev, &adev->res);
+	if (!ret)
+		pm_runtime_put(&adev->dev);
+
+	return ret;
  }
 
  static void dynamic_replicator_remove(struct amba_device *adev)
@@ -416,27 +436,12 @@ static struct amba_driver dynamic_replicator_driver = {
 
  static int __init replicator_init(void)
  {
-	int ret;
-
-	ret = platform_driver_register(&static_replicator_driver);
-	if (ret) {
-		pr_info("Error registering platform driver\n");
-		return ret;
-	}
-
-	ret = amba_driver_register(&dynamic_replicator_driver);
-	if (ret) {
-		pr_info("Error registering amba driver\n");
-		platform_driver_unregister(&static_replicator_driver);
-	}
-
-	return ret;
+	return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver);
  }
 
  static void __exit replicator_exit(void)
  {
-	platform_driver_unregister(&static_replicator_driver);
-	amba_driver_unregister(&dynamic_replicator_driver);
+	coresight_remove_driver(&dynamic_replicator_driver, &replicator_driver);
  }
 
  module_init(replicator_init);
maintainer
#16 lore raw

Re: [PATCH V4 05/11] coresight: replicator: Move ACPI support from AMBA driver to platform driver

Quoted 26 lines · Suzuki K Poulose

Hi Anshuman

Quoted 8 lines · Anshuman Khandual

Add support for the dynamic replicator device in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for repliacator devices on ACPI based systems.

The driver would try to enable the APB clock if available. Also, rename the code to reflect the fact that it now handles both static and dynamic replicators.

Quoted 12 lines

I think the patch is doing three different things:

Quoted 9 lines

1) Use new helper to register/remove AMBA/Platform drivers
2) Refactor replicator_probe() to make sure it can be reused for platform/amba driver, by moving the pm_runtime_put() to the callers.
3) Actually moving the ACPI driver to Platform driver

While (1) and (3) are obvious, (2) gave me hard time to review this patch, without proper description. If you don't mind, are you able to split the patch and add proper description of the 3 changes mentioned above.

You could even move (1) for all the existing drivers into a single patch
or even fold it with the patch that introduces the helpers. That way it
is cleaner and easier to review. And (2) & (3) could be in the same patch for each driver, but please add something in the description for (2).

Suzuki

Quoted 206 lines

Kind regards
Suzuki

Quoted 201 lines

---
Changes in V4:

- Added pm_runtime_disable() in replicator_platform_probe()
- Changed replicator_platform_remove() for platform_driver->remove_new()

  drivers/acpi/arm64/amba.c                     |  1 - .../coresight/coresight-replicator.c          | 81 ++++++++++---------

  2 files changed, 43 insertions(+), 39 deletions(-)
drivers/acpi/arm64/amba.c +0 -0
index 171b5c2c7edd..270f4e3819a2 100644
@@ -27,7 +27,6 @@ static const struct acpi_device_id amba_id_list[] = {

      {"ARMHC503", 0}, /* ARM CoreSight Debug */ {"ARMHC979", 0}, /* ARM CoreSight TPIU */
      {"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */ -    {"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */ {"ARMHC9CA", 0}, /* ARM CoreSight CATU */
      {"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */ {"", 0},

drivers/hwtracing/coresight/coresight-replicator.c +1 -0
index 91d93060dda5..9b5f52725f43 100644
@@ -31,6 +31,7 @@ DEFINE_CORESIGHT_DEVLIST(replicator_devs, 
 "replicator");
    * @base:    memory mapped base address for this component. Also indicates
    *        whether this one is programmable or not.
    * @atclk:    optional clock for the core parts of the replicator.
+ * @pclk:    APB clock if present, otherwise NULL
    * @csdev:    component vitals needed by the framework
    * @spinlock:    serialize enable/disable operations.

   * @check_idfilter_val: check if the context is lost upon clock removal.

drivers/hwtracing/coresight/coresight-replicator.c +1 -0
@@ -38,6 +39,7 @@ DEFINE_CORESIGHT_DEVLIST(replicator_devs, 
 "replicator");
   struct replicator_drvdata {
       void __iomem        *base;
       struct clk        *atclk;
+    struct clk        *pclk;
       struct coresight_device    *csdev;
       spinlock_t        spinlock;

      bool            check_idfilter_val;

drivers/hwtracing/coresight/coresight-replicator.c +4 -1
@@ -243,6 +245,10 @@ static int replicator_probe(struct device *dev, 
 struct resource *res)
               return ret;
       }
+    drvdata->pclk = coresight_get_enable_apb_pclk(dev);
+    if (IS_ERR(drvdata->pclk))
+        return -ENODEV;
+
       /*
        * Map the device base for dynamic-replicator, which has been
        * validated by AMBA core
@@ -285,7 +291,6 @@ static int replicator_probe(struct device *dev, 
 struct resource *res)
       }
       replicator_reset(drvdata);
-    pm_runtime_put(dev);

  out_disable_clk:
      if (ret && !IS_ERR_OR_NULL(drvdata->atclk))

drivers/hwtracing/coresight/coresight-replicator.c +20 -12
@@ -301,29 +306,33 @@ static int replicator_remove(struct device *dev)
       return 0;
   }
-static int static_replicator_probe(struct platform_device *pdev)
+static int replicator_platform_probe(struct platform_device *pdev)
   {
+    struct resource *res = platform_get_resource(pdev, 
 IORESOURCE_MEM, 0);
       int ret;
       pm_runtime_get_noresume(&pdev->dev);
       pm_runtime_set_active(&pdev->dev);
       pm_runtime_enable(&pdev->dev);
-    /* Static replicators do not have programming base */
-    ret = replicator_probe(&pdev->dev, NULL);
-
-    if (ret) {
-        pm_runtime_put_noidle(&pdev->dev);
+    ret = replicator_probe(&pdev->dev, res);
+    pm_runtime_put(&pdev->dev);
+    if (ret)
           pm_runtime_disable(&pdev->dev);
-    }
       return ret;
   }
-static void static_replicator_remove(struct platform_device *pdev)
+static void replicator_platform_remove(struct platform_device *pdev)
   {
-    replicator_remove(&pdev->dev);
+    struct replicator_drvdata *drvdata = dev_get_drvdata(&pdev->dev);
+
+    if (drvdata)
+        replicator_remove(&pdev->dev);
+
       pm_runtime_disable(&pdev->dev);
+    if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk))
+        clk_put(drvdata->pclk);
   }
   #ifdef CONFIG_PM
@@ -334,6 +343,8 @@ static int replicator_runtime_suspend(struct 
 device *dev)
       if (drvdata && !IS_ERR(drvdata->atclk))
           clk_disable_unprepare(drvdata->atclk);
+    if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk))
+        clk_disable_unprepare(drvdata->pclk);
       return 0;
   }
@@ -344,6 +355,8 @@ static int replicator_runtime_resume(struct device 
 *dev)
       if (drvdata && !IS_ERR(drvdata->atclk))
           clk_prepare_enable(drvdata->atclk);
+    if (drvdata && !IS_ERR_OR_NULL(drvdata->pclk))
+        clk_prepare_enable(drvdata->pclk);
       return 0;
   }
   #endif
@@ -353,31 +366,32 @@ static const struct dev_pm_ops 
 replicator_dev_pm_ops = {
                  replicator_runtime_resume, NULL)
   };
-static const struct of_device_id static_replicator_match[] = {
+static const struct of_device_id replicator_match[] = {
       {.compatible = "arm,coresight-replicator"},
       {.compatible = "arm,coresight-static-replicator"},
       {}
   };
-MODULE_DEVICE_TABLE(of, static_replicator_match);
+MODULE_DEVICE_TABLE(of, replicator_match);
   #ifdef CONFIG_ACPI
-static const struct acpi_device_id static_replicator_acpi_ids[] = {
+static const struct acpi_device_id replicator_acpi_ids[] = {

      {"ARMHC985", 0}, /* ARM CoreSight Static Replicator */ +    {"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */ {}
  };

drivers/hwtracing/coresight/coresight-replicator.c +1 -1
-MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);
+MODULE_DEVICE_TABLE(acpi, replicator_acpi_ids);

  #endif

drivers/hwtracing/coresight/coresight-replicator.c +3 -3
-static struct platform_driver static_replicator_driver = {
-    .probe          = static_replicator_probe,
-    .remove_new     = static_replicator_remove,
+static struct platform_driver replicator_driver = {
+    .probe          = replicator_platform_probe,
+    .remove_new     = replicator_platform_remove,

      .driver         = {
-        .name   = "coresight-static-replicator",
+        .name   = "coresight-replicator",
          /* THIS_MODULE is taken care of by platform_driver_register() */ -        .of_match_table = of_match_ptr(static_replicator_match), -        .acpi_match_table = ACPI_PTR(static_replicator_acpi_ids), +        .of_match_table = of_match_ptr(replicator_match),
+        .acpi_match_table = ACPI_PTR(replicator_acpi_ids), .pm    = &replicator_dev_pm_ops, .suppress_bind_attrs = true,
      },

drivers/hwtracing/coresight/coresight-replicator.c +9 -18
@@ -386,7 +400,13 @@ static struct platform_driver 
 static_replicator_driver = {
   static int dynamic_replicator_probe(struct amba_device *adev,
                       const struct amba_id *id)
   {
-    return replicator_probe(&adev->dev, &adev->res);
+    int ret;
+
+    ret = replicator_probe(&adev->dev, &adev->res);
+    if (!ret)
+        pm_runtime_put(&adev->dev);
+
+    return ret;
   }
   static void dynamic_replicator_remove(struct amba_device *adev)
@@ -416,27 +436,12 @@ static struct amba_driver 
 dynamic_replicator_driver = {
   static int __init replicator_init(void)
   {
-    int ret;
-
-    ret = platform_driver_register(&static_replicator_driver);
-    if (ret) {
-        pr_info("Error registering platform driver\n");
-        return ret;
-    }
-
-    ret = amba_driver_register(&dynamic_replicator_driver);
-    if (ret) {
-        pr_info("Error registering amba driver\n");
-        platform_driver_unregister(&static_replicator_driver);
-    }
-
-    return ret;
+    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver);
   }
   static void __exit replicator_exit(void)
   {
-    platform_driver_unregister(&static_replicator_driver);
-    amba_driver_unregister(&dynamic_replicator_driver);
+    coresight_remove_driver(&dynamic_replicator_driver, 
 &replicator_driver);
   }
   module_init(replicator_init);
#17 lore raw

Re: [PATCH V4 05/11] coresight: replicator: Move ACPI support from AMBA driver to platform driver

Quoted 31 lines · Suzuki K Poulose
Quoted 30 lines · Suzuki K Poulose

Hi Anshuman

Quoted 8 lines · Anshuman Khandual

Add support for the dynamic replicator device in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for repliacator devices on ACPI based systems.

The driver would try to enable the APB clock if available. Also, rename the code to reflect the fact that it now handles both static and dynamic replicators.

Quoted 12 lines

I think the patch is doing three different things:

1) Use new helper to register/remove AMBA/Platform drivers
2) Refactor replicator_probe() to make sure it can be reused for platform/amba driver, by moving the pm_runtime_put() to the callers.
3) Actually moving the ACPI driver to Platform driver

Quoted 8 lines
Quoted 5 lines

While (1) and (3) are obvious, (2) gave me hard time to review this patch, without proper description. If you don't mind, are you able to split the patch and add proper description of the 3 changes mentioned above.

You could even move (1) for all the existing drivers into a single patch or even fold it with the patch that introduces the helpers. That way it

There are only two existing coresight devices with both AMBA and platform drivers available i.e replicator and funnel. Such devices could use these new helpers right from the beginning. As you mentioned earlier such changes might be folded back into the patch adding the helpers.

But coresight devices such as catu, tpiu, tmc, stm and debug don't have platform drivers to begin with. Hence the helpers could only be used in their respective patches adding platform drivers.

Quoted 1 line

is cleaner and easier to review. And (2) & (3) could be in the same patch for each driver, but please add something in the description for (2).

Please find the updated commit message here, does this look okay ?

coresight: replicator: Move ACPI support from AMBA driver to platform driver

Add support for the dynamic replicator device in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for replicator devices on ACPI based systems.

The driver would try to enable the APB clock if available. Also, rename the code to reflect the fact that it now handles both static and dynamic replicators. But first this refactors replicator_probe() making sure it can be used both for platform and AMBA drivers, by moving the pm_runtime_put() to the callers.

#18 lore raw

PATCH v4 6/11 coresight: funnel: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the dynamic funnel device in the platform driver, which can then be used on ACPI based platforms. This change would allow runtime power management for ACPI based systems.

The driver would try to enable the APB clock if available. Also, rename the code to reflect the fact that it now handles both static and dynamic funnels.

---
Changes in V4:

- Added pm_runtime_disable() in funnel_platform_probe()
- Changed funnel_platform_remove() for platform_driver->remove_new()

 drivers/acpi/arm64/amba.c                     |  1 -
 .../hwtracing/coresight/coresight-funnel.c    | 86 ++++++++++---------
 2 files changed, 46 insertions(+), 41 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index 270f4e3819a2..afb6afb66967 100644
@@ -28,7 +28,6 @@ static const struct acpi_device_id amba_id_list[] = {
 	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
 	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
 	{"ARMHC9CA", 0}, /* ARM CoreSight CATU */
-	{"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
 	{"", 0},
 };
 
drivers/hwtracing/coresight/coresight-funnel.c +46 -40

172 lines not on this page · raw message

Signature · 1 line
2.25.1
#19 lore raw

PATCH v4 7/11 coresight: catu: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the catu devices in a new platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for ACPI based systems. The driver would try to enable the APB clock if available.

---
Changes in V4:

- Added pm_runtime_disable() in catu_platform_probe()

 drivers/acpi/arm64/amba.c                    |   1 -
 drivers/hwtracing/coresight/coresight-catu.c | 142 ++++++++++++++++---
 drivers/hwtracing/coresight/coresight-catu.h |   1 +
 3 files changed, 124 insertions(+), 20 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index afb6afb66967..587061b0fd2f 100644
@@ -27,7 +27,6 @@ static const struct acpi_device_id amba_id_list[] = {
 	{"ARMHC503", 0}, /* ARM CoreSight Debug */
 	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
 	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
-	{"ARMHC9CA", 0}, /* ARM CoreSight CATU */
 	{"", 0},
 };
 
drivers/hwtracing/coresight/coresight-catu.c +123 -19

196 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-catu.h +1 -0
index 442e034bbfba..141feac1c14b 100644
@@ -61,6 +61,7 @@
 #define CATU_IRQEN_OFF		0x0
 
 struct catu_drvdata {
+	struct clk *pclk;
 	void __iomem *base;
 	struct coresight_device *csdev;
 	int irq;
Signature · 1 line
2.25.1
#20 lore raw

PATCH v4 8/11 coresight: tpiu: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the tpiu device in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for ACPI based systems. The driver would try to enable the APB clock if available.

---
Changes in V4:

- Added pm_runtime_disable() in tpiu_platform_probe()

 drivers/acpi/arm64/amba.c                    |   1 -
 drivers/hwtracing/coresight/coresight-tpiu.c | 102 +++++++++++++++++--
 2 files changed, 92 insertions(+), 11 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index 587061b0fd2f..6d24a8f7914b 100644
@@ -25,7 +25,6 @@ static const struct acpi_device_id amba_id_list[] = {
 	{"ARMHC501", 0}, /* ARM CoreSight ETR */
 	{"ARMHC502", 0}, /* ARM CoreSight STM */
 	{"ARMHC503", 0}, /* ARM CoreSight Debug */
-	{"ARMHC979", 0}, /* ARM CoreSight TPIU */
 	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
 	{"", 0},
 };
drivers/hwtracing/coresight/coresight-tpiu.c +92 -10

175 lines not on this page · raw message

Signature · 1 line
2.25.1
#21 lore raw

PATCH v4 9/11 coresight: tmc: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the tmc devices in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for ACPI based systems. The driver would try to enable the APB clock if available.

---
Changes in V4:

- Dropped dev_caps argument from __tmc_probe()
- Added pm_runtime_disable() in tmc_platform_probe()

 drivers/acpi/arm64/amba.c                     |   2 -
 .../hwtracing/coresight/coresight-tmc-core.c  | 139 ++++++++++++++++--
 drivers/hwtracing/coresight/coresight-tmc.h   |   2 +
 3 files changed, 126 insertions(+), 17 deletions(-)
drivers/acpi/arm64/amba.c +0 -2
index 6d24a8f7914b..d3c1defa7bc8 100644
@@ -22,10 +22,8 @@
 static const struct acpi_device_id amba_id_list[] = {
 	{"ARMH0061", 0}, /* PL061 GPIO Device */
 	{"ARMH0330", 0}, /* ARM DMA Controller DMA-330 */
-	{"ARMHC501", 0}, /* ARM CoreSight ETR */
 	{"ARMHC502", 0}, /* ARM CoreSight STM */
 	{"ARMHC503", 0}, /* ARM CoreSight Debug */
-	{"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
 	{"", 0},
 };
 
drivers/hwtracing/coresight/coresight-tmc-core.c +124 -15

195 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc.h +2 -0
index 8dcb426ac3e7..cb5a0920c203 100644
@@ -166,6 +166,7 @@ struct etr_buf {
 
 /**
  * struct tmc_drvdata - specifics associated to an TMC component
+ * @pclk:	APB clock if present, otherwise NULL
  * @base:	memory mapped base address for this component.
  * @csdev:	component vitals needed by the framework.
  * @miscdev:	specifics to handle "/dev/xyz.tmc" entry.
@@ -190,6 +191,7 @@ struct etr_buf {
  * @perf_buf:	PERF buffer for ETR.
  */
 struct tmc_drvdata {
+	struct clk		*pclk;
 	void __iomem		*base;
 	struct coresight_device	*csdev;
 	struct miscdevice	miscdev;
Signature · 1 line
2.25.1
#22 lore raw

PATCH v4 10/11 coresight: stm: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the stm devices in the platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for ACPI based systems. The driver would try to enable the APB clock if available.

---
Changes in V4:

- Added pm_runtime_disable() in stm_platform_probe()

 drivers/acpi/arm64/amba.c                   |   1 -
 drivers/hwtracing/coresight/coresight-stm.c | 103 ++++++++++++++++++--
 2 files changed, 93 insertions(+), 11 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index d3c1defa7bc8..bec0976541da 100644
@@ -22,7 +22,6 @@
 static const struct acpi_device_id amba_id_list[] = {
 	{"ARMH0061", 0}, /* PL061 GPIO Device */
 	{"ARMH0330", 0}, /* ARM DMA Controller DMA-330 */
-	{"ARMHC502", 0}, /* ARM CoreSight STM */
 	{"ARMHC503", 0}, /* ARM CoreSight Debug */
 	{"", 0},
 };
drivers/hwtracing/coresight/coresight-stm.c +93 -10

186 lines not on this page · raw message

Signature · 1 line
2.25.1
#23 lore raw

PATCH v4 11/11 coresight: debug: Move ACPI support from AMBA driver to platform driver

In reply to Anshuman Khandual

Add support for the cpu debug devices in a new platform driver, which can then be used on ACPI based platforms. This change would now allow runtime power management for ACPI based systems. The driver would try to enable the APB clock if available.

---
 drivers/acpi/arm64/amba.c                     |   1 -
 .../hwtracing/coresight/coresight-cpu-debug.c | 141 ++++++++++++++++--
 2 files changed, 127 insertions(+), 15 deletions(-)
drivers/acpi/arm64/amba.c +0 -1
index bec0976541da..e1f0bbb8f393 100644
@@ -22,7 +22,6 @@
 static const struct acpi_device_id amba_id_list[] = {
 	{"ARMH0061", 0}, /* PL061 GPIO Device */
 	{"ARMH0330", 0}, /* ARM DMA Controller DMA-330 */
-	{"ARMHC503", 0}, /* ARM CoreSight Debug */
 	{"", 0},
 };
 
drivers/hwtracing/coresight/coresight-cpu-debug.c +127 -14

188 lines not on this page · raw message

Signature · 1 line
2.25.1
Reviewed-by on the v4 series
#24 lore raw
In reply to Anshuman Khandual
Quoted 8 lines · Anshuman Khandual

This moves remaining AMBA ACPI devices into respective platform drivers for enabling ACPI based power management support. This series applies on kernel v6.8-rc1 release. This series has been built, and boot tested on a DT based coresight platform. Although this still requires some more testing on ACPI based coresight platforms.

https://git.gitlab.arm.com/linux-arm/linux-anshuman.git (amba_other_acpi_migration_v4)

Quoted 13 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Mike Leach <[email protected]>
Cc James Clark <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Quoted 72 lines

Changes in V4:

- Fixed PM imbalance in etm4_probe() error path with pm_runtime_disable()
- Restored back the pm_runtime_disable() on platform probe error paths in replicator, funnel, catu, tpiu, tmc and stm devices
- Dropped dev_caps argument from __tmc_probe()
- Changed xxxx_platform_remove() for platform_driver->remove_new() callback

Changes in V3:

https://lore.kernel.org/all/[email protected]/

- Split coresight_init_driver/remove_driver() helpers into a separate patch
- Added 'drvdata->pclk' comments in replicator, funnel, tpiu, tmc, and stm devices
- Updated funnel, and replicator drivers to use these new helpers
- Check for drvdata instead of drvdata->pclk in suspend and resume paths in catu, tmc and debug devices
- Added patch to extract device name from AMBA pid based table lookup for stm
- Added patch to extract device properties from AMBA pid based table look for tmc
- Dropped pm_runtime_put() from common __probe() functions
- Handled pm_runtime_put() in AMBA driver in success path
- Handled pm_runtime_put() in platform driver in both success and error paths

Changes in V2:

https://lore.kernel.org/all/[email protected]/

- Dropped redundant devm_ioremap_resource() hunk from tmc_platform_probe()
- Defined coresight_[init|remove]_driver() for both AMBA/platform drivers
- Changed catu, tmc, tpiu, stm and debug coresight drivers to use the new helpers avoiding build issues arising from module_amba_driver(), and module_platform_driver() being on the same file

Changes in V1:

https://lore.kernel.org/all/[email protected]/

- Replaced all IS_ERR() instances with IS_ERR_OR_NULL() as per Suzuki

Changes in RFC:

https://lore.kernel.org/all/[email protected]/

Anshuman Khandual (11):
coresight: etm4x: Fix unbalanced pm_runtime_enable()
coresight: stm: Extract device name from AMBA pid based table lookup
coresight: tmc: Extract device properties from AMBA pid based table lookup
coresight: Add helpers registering/removing both AMBA and platform drivers
coresight: replicator: Move ACPI support from AMBA driver to platform driver
coresight: funnel: Move ACPI support from AMBA driver to platform driver
coresight: catu: Move ACPI support from AMBA driver to platform driver
coresight: tpiu: Move ACPI support from AMBA driver to platform driver
coresight: tmc: Move ACPI support from AMBA driver to platform driver
coresight: stm: Move ACPI support from AMBA driver to platform driver
coresight: debug: Move ACPI support from AMBA driver to platform driver

 drivers/acpi/arm64/amba.c                     |   8 -
 drivers/hwtracing/coresight/coresight-catu.c  | 142 +++++++++++++---
 drivers/hwtracing/coresight/coresight-catu.h  |   1 +
 drivers/hwtracing/coresight/coresight-core.c  |  29 ++++
 .../hwtracing/coresight/coresight-cpu-debug.c | 141 ++++++++++++++--
 .../coresight/coresight-etm4x-core.c          |   3 +
 .../hwtracing/coresight/coresight-funnel.c    |  86 +++++-----
 drivers/hwtracing/coresight/coresight-priv.h  |  10 ++
 .../coresight/coresight-replicator.c          |  81 ++++-----
 drivers/hwtracing/coresight/coresight-stm.c   | 117 +++++++++++--
 .../hwtracing/coresight/coresight-tmc-core.c  | 158 +++++++++++++++---
 drivers/hwtracing/coresight/coresight-tmc.h   |   2 +
 drivers/hwtracing/coresight/coresight-tpiu.c  | 102 +++++++++--
 include/linux/coresight.h                     |   7 +
 14 files changed, 726 insertions(+), 161 deletions(-)