Re: [PATCH v10 24/24] coresight: allow the coresight core driver to be built as a module

2020-08-21 Thread Sai Prakash Ranjan

On 2020-08-21 09:14, Tingwei Zhang wrote:

Enhance coresight developer's efficiency to debug coresight drivers.
- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight by the Makefile
- modules can have only one init/exit, so we add the etm_perf
  register/unregister function calls to the core init/exit
  functions.
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---


Tested-by: Sai Prakash Ranjan 

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a 
member

of Code Aurora Forum, hosted by The Linux Foundation


[PATCH v10 24/24] coresight: allow the coresight core driver to be built as a module

2020-08-20 Thread Tingwei Zhang
Enhance coresight developer's efficiency to debug coresight drivers.
- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight by the Makefile
- modules can have only one init/exit, so we add the etm_perf
  register/unregister function calls to the core init/exit
  functions.
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 ++-
 drivers/hwtracing/coresight/Makefile  |  5 ++-
 .../{coresight.c => coresight-core.c} | 42 ++-
 .../hwtracing/coresight/coresight-etm-perf.c  |  8 +++-
 .../hwtracing/coresight/coresight-etm-perf.h  |  3 ++
 5 files changed, 48 insertions(+), 15 deletions(-)
 rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c} (98%)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index dfe407cde262..c1198245461d 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -3,7 +3,7 @@
 # Coresight configuration
 #
 menuconfig CORESIGHT
-   bool "CoreSight Tracing Support"
+   tristate "CoreSight Tracing Support"
depends on ARM || ARM64
depends on OF || ACPI
select ARM_AMBA
@@ -15,6 +15,9 @@ menuconfig CORESIGHT
  specification and configure the right series of components when a
  trace source gets enabled.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight.
+
 if CORESIGHT
 config CORESIGHT_LINKS_AND_SINKS
tristate "CoreSight Link and Sink drivers"
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index 0359d5a1588f..1b35b55bd420 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -2,8 +2,9 @@
 #
 # Makefile for CoreSight drivers.
 #
-obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
-  coresight-platform.o coresight-sysfs.o
+obj-$(CONFIG_CORESIGHT) += coresight.o
+coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
+   coresight-sysfs.o
 obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
 coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
  coresight-tmc-etr.o
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight.c
rename to drivers/hwtracing/coresight/coresight-core.c
index 668963b4b7d4..bf6edf468963 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1460,16 +1460,6 @@ int coresight_timeout(void __iomem *addr, u32 offset, 
int position, int value)
 }
 EXPORT_SYMBOL_GPL(coresight_timeout);
 
-struct bus_type coresight_bustype = {
-   .name   = "coresight",
-};
-
-static int __init coresight_init(void)
-{
-   return bus_register(&coresight_bustype);
-}
-postcore_initcall(coresight_init);
-
 /*
  * coresight_release_platform_data: Release references to the devices connected
  * to the output port of this device.
@@ -1678,3 +1668,35 @@ char *coresight_alloc_device_name(struct 
coresight_dev_list *dict,
return name;
 }
 EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
+
+struct bus_type coresight_bustype = {
+   .name   = "coresight",
+};
+
+static int __init coresight_init(void)
+{
+   int ret;
+
+   ret = bus_register(&coresight_bustype);
+   if (ret)
+   return ret;
+
+   ret = etm_perf_init();
+   if (ret)
+   bus_unregister(&coresight_bustype);
+
+   return ret;
+}
+
+static void __exit coresight_exit(void)
+{
+   etm_perf_exit();
+   bus_unregister(&coresight_bustype);
+}
+
+module_init(coresight_init);
+module_exit(coresight_exit);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight tracer driver");
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 3728c44e5763..668b3ff11576 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -591,7 +591,7 @@ void etm_perf_del_symlink_sink(struct coresight_device 
*csdev)
csdev->ea = NULL;
 }
 
-static int __init etm_perf_init(void)
+int __init etm_perf_init(void)
 {
int ret;
 
@@ -618,4 +618,8 @@ static int __init etm_perf_init(void)
 
return ret;
 }
-device_initcall(etm_perf_init);
+
+void __exit etm_perf_exit(void)
+{
+   perf_pmu_unregister(&etm_pmu);
+}
diff --git a/drivers