Allow to build coresight as modules. This gives developers the feasibility to test their code without reboot.
This series is based on below two series.
- "coresight: allow to build components as modules" https://lkml.org/lkml/2018/6/5/989 - "coresight: make drivers modular" https://lkml.org/lkml/2020/1/17/468
This series adds the support to dynamically remove module when the device in that module is enabled and used by some trace path. It disables all trace paths with that device and release the trace path.
Kim Phillips (7): coresight: use IS_ENABLED for CONFIGs that may be modules coresight: allow etm3x to be built as a module coresight: allow etm4x to be built as a module coresight: allow etb to be built as a module coresight: allow tpiu to be built as a module coresight: allow tmc to be built as a module coresight: allow funnel and replicator drivers to be built as modules
Mian Yousaf Kaukab (4): coresight: export global symbols coresight: remove multiple init calls from funnel driver coresight: remove multiple init calls from replicator driver coresight: tmc-etr: add function to register catu ops
Tingwei Zhang (10): coresight: cpu_debug: add module name in Kconfig coresight: cpu_debug: define MODULE_DEVICE_TABLE coresight: add coresight prefix to barrier_pkt Allow to build coresight-stm as a module, for ease of development. coresight: cti: add function to register cti associate ops coresight: allow cti to be built as a module coresight: allow catu drivers to be built as modules coresight: disable trace path with device being removed coresight: allow the coresight core driver to be built as a module coresight: perf: clean up perf event on device unregister path
drivers/hwtracing/coresight/Kconfig | 54 ++++- drivers/hwtracing/coresight/Makefile | 20 +- drivers/hwtracing/coresight/coresight-catu.c | 37 ++- drivers/hwtracing/coresight/coresight-catu.h | 2 - .../{coresight.c => coresight-core.c} | 218 ++++++++++++++++-- .../hwtracing/coresight/coresight-cpu-debug.c | 2 + .../{coresight-cti.c => coresight-cti-core.c} | 46 +++- drivers/hwtracing/coresight/coresight-etb10.c | 22 +- .../hwtracing/coresight/coresight-etm-perf.c | 166 ++++++++++++- .../hwtracing/coresight/coresight-etm-perf.h | 7 +- ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++- ...resight-etm4x.c => coresight-etm4x-core.c} | 31 ++- .../hwtracing/coresight/coresight-funnel.c | 62 ++++- .../hwtracing/coresight/coresight-platform.c | 1 + drivers/hwtracing/coresight/coresight-priv.h | 28 +-- .../coresight/coresight-replicator.c | 63 ++++- drivers/hwtracing/coresight/coresight-stm.c | 20 +- .../{coresight-tmc.c => coresight-tmc-core.c} | 19 +- .../hwtracing/coresight/coresight-tmc-etf.c | 2 +- .../hwtracing/coresight/coresight-tmc-etr.c | 21 +- drivers/hwtracing/coresight/coresight-tmc.h | 3 + drivers/hwtracing/coresight/coresight-tpiu.c | 19 +- include/linux/coresight.h | 2 +- kernel/events/core.c | 1 + 24 files changed, 796 insertions(+), 77 deletions(-) rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c} (87%) rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (95%) rename drivers/hwtracing/coresight/{coresight-etm3x.c => coresight-etm3x-core.c} (97%) rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (98%) rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} (96%)
Provide name of cpu_debug module in Kconfig help section.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 02dbb5ca3bcf..4663fd1bbffc 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -110,6 +110,9 @@ config CORESIGHT_CPU_DEBUG properly, please refer Documentation/trace/coresight/coresight-cpu-debug.rst for detailed description and the example for usage.
+ To compile this driver as a module, choose M here: the + module will be called coresight-cpu-debug. + config CORESIGHT_CTI bool "CoreSight Cross Trigger Interface (CTI) driver" depends on ARM || ARM64
Define a MODULE_DEVICE_TABLE for cpu_debug so module can be auto loaded on boot.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-cpu-debug.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c index 96544b348c27..1d0880b3764a 100644 --- a/drivers/hwtracing/coresight/coresight-cpu-debug.c +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c @@ -665,6 +665,8 @@ static const struct amba_id debug_ids[] = { {}, };
+MODULE_DEVICE_TABLE(amba, debug_ids); + static struct amba_driver debug_driver = { .drv = { .name = "coresight-cpu-debug",
From: Kim Phillips kim.phillips@arm.com
Checking for ifdef CONFIG_x fails if CONFIG_x=m. Use IS_ENABLED that is true for both built-ins and modules, instead. Required when building coresight components as modules.
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-etm-perf.h | 2 +- drivers/hwtracing/coresight/coresight-priv.h | 2 +- include/linux/coresight.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 015213abe00a..05f89723e282 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -57,7 +57,7 @@ struct etm_event_data { struct list_head * __percpu *path; };
-#ifdef CONFIG_CORESIGHT +#if IS_ENABLED(CONFIG_CORESIGHT) int etm_perf_symlink(struct coresight_device *csdev, bool link); int etm_perf_add_symlink_sink(struct coresight_device *csdev); void etm_perf_del_symlink_sink(struct coresight_device *csdev); diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 890f9a5c97c6..a7b4945f7446 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -154,7 +154,7 @@ struct list_head *coresight_build_path(struct coresight_device *csdev, struct coresight_device *sink); void coresight_release_path(struct list_head *path);
-#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X +#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X) extern int etm_readl_cp14(u32 off, unsigned int *val); extern int etm_writel_cp14(u32 off, u32 val); #else diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 193cc9dbf448..82782338d281 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -296,7 +296,7 @@ struct coresight_ops { const struct coresight_ops_ect *ect_ops; };
-#ifdef CONFIG_CORESIGHT +#if IS_ENABLED(CONFIG_CORESIGHT) extern struct coresight_device * coresight_register(struct coresight_desc *desc); extern void coresight_unregister(struct coresight_device *csdev);
Add coresight prefix to make it specific. It will be a export symbol.
Signed-off-by: Mian Yousaf Kaukab ykaukab@suse.de Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-etb10.c | 2 +- drivers/hwtracing/coresight/coresight-priv.h | 8 ++++---- drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +- drivers/hwtracing/coresight/coresight.c | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 3810290e6d07..bbad5c1f67fa 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -525,7 +525,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
cur = buf->cur; offset = buf->offset; - barrier = barrier_pkt; + barrier = coresight_barrier_pkt;
for (i = 0; i < to_read; i += 4) { buf_ptr = buf->data_pages[cur] + offset; diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index a7b4945f7446..335ba2208b61 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -66,8 +66,8 @@ static DEVICE_ATTR_RO(name) #define coresight_simple_reg64(type, name, lo_off, hi_off) \ __coresight_simple_func(type, NULL, name, lo_off, hi_off)
-extern const u32 barrier_pkt[4]; -#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(barrier_pkt)) +extern const u32 coresight_barrier_pkt[4]; +#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(coresight_barrier_pkt))
enum etm_addr_type { ETM_ADDR_TYPE_NONE, @@ -104,10 +104,10 @@ struct cs_buffers { static inline void coresight_insert_barrier_packet(void *buf) { if (buf) - memcpy(buf, barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE); + memcpy(buf, coresight_barrier_pkt, + CORESIGHT_BARRIER_PKT_SIZE); }
- static inline void CS_LOCK(void __iomem *addr) { do { diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index d0cc3985b72a..52b287481b8b 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -519,7 +519,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev,
cur = buf->cur; offset = buf->offset; - barrier = barrier_pkt; + barrier = coresight_barrier_pkt;
/* for every byte to read */ for (i = 0; i < to_read; i += 4) { diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index c71553c09f8e..e057c991df6f 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -53,7 +53,8 @@ static struct list_head *stm_path; * beginning of the data collected in a buffer. That way the decoder knows that * it needs to look for another sync sequence. */ -const u32 barrier_pkt[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; +const u32 coresight_barrier_pkt[4] = { + 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
static int coresight_id_match(struct device *dev, void *data) {
From: Mian Yousaf Kaukab ykaukab@suse.de
Export symbols used among coresight modules.
Signed-off-by: Mian Yousaf Kaukab ykaukab@suse.de Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-etm-perf.c | 1 + drivers/hwtracing/coresight/coresight-tmc-etr.c | 6 ++++++ drivers/hwtracing/coresight/coresight.c | 8 ++++++++ 3 files changed, 15 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 84f1dcb69827..dbca77150a81 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -506,6 +506,7 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link)
return 0; } +EXPORT_SYMBOL_GPL(etm_perf_symlink);
static ssize_t etm_perf_sink_name_show(struct device *dev, struct device_attribute *dattr, diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 625882bc8b08..b86c76ae26b9 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -255,6 +255,7 @@ void tmc_free_sg_table(struct tmc_sg_table *sg_table) tmc_free_table_pages(sg_table); tmc_free_data_pages(sg_table); } +EXPORT_SYMBOL_GPL(tmc_free_sg_table);
/* * Alloc pages for the table. Since this will be used by the device, @@ -340,6 +341,7 @@ struct tmc_sg_table *tmc_alloc_sg_table(struct device *dev,
return sg_table; } +EXPORT_SYMBOL_GPL(tmc_alloc_sg_table);
/* * tmc_sg_table_sync_data_range: Sync the data buffer written @@ -360,6 +362,7 @@ void tmc_sg_table_sync_data_range(struct tmc_sg_table *table, PAGE_SIZE, DMA_FROM_DEVICE); } } +EXPORT_SYMBOL_GPL(tmc_sg_table_sync_data_range);
/* tmc_sg_sync_table: Sync the page table */ void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table) @@ -372,6 +375,7 @@ void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table) dma_sync_single_for_device(real_dev, table_pages->daddrs[i], PAGE_SIZE, DMA_TO_DEVICE); } +EXPORT_SYMBOL_GPL(tmc_sg_table_sync_table);
/* * tmc_sg_table_get_data: Get the buffer pointer for data @offset @@ -401,6 +405,7 @@ ssize_t tmc_sg_table_get_data(struct tmc_sg_table *sg_table, *bufpp = page_address(data_pages->pages[pg_idx]) + pg_offset; return len; } +EXPORT_SYMBOL_GPL(tmc_sg_table_get_data);
#ifdef ETR_SG_DEBUG /* Map a dma address to virtual address */ @@ -766,6 +771,7 @@ tmc_etr_get_catu_device(struct tmc_drvdata *drvdata)
return NULL; } +EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device);
static inline int tmc_etr_enable_catu(struct tmc_drvdata *drvdata, struct etr_buf *etr_buf) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index e057c991df6f..e8c4e10b75b5 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -55,6 +55,7 @@ static struct list_head *stm_path; */ const u32 coresight_barrier_pkt[4] = { 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; +EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
static int coresight_id_match(struct device *dev, void *data) { @@ -180,6 +181,7 @@ int coresight_claim_device_unlocked(void __iomem *base) coresight_clear_claim_tags(base); return -EBUSY; } +EXPORT_SYMBOL_GPL(coresight_claim_device_unlocked);
int coresight_claim_device(void __iomem *base) { @@ -191,6 +193,7 @@ int coresight_claim_device(void __iomem *base)
return rc; } +EXPORT_SYMBOL_GPL(coresight_claim_device);
/* * coresight_disclaim_device_unlocked : Clear the claim tags for the device. @@ -209,6 +212,7 @@ void coresight_disclaim_device_unlocked(void __iomem *base) */ WARN_ON_ONCE(1); } +EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);
void coresight_disclaim_device(void __iomem *base) { @@ -216,6 +220,7 @@ void coresight_disclaim_device(void __iomem *base) coresight_disclaim_device_unlocked(base); CS_LOCK(base); } +EXPORT_SYMBOL_GPL(coresight_disclaim_device);
/* enable or disable an associated CTI device of the supplied CS device */ static int @@ -468,6 +473,7 @@ void coresight_disable_path(struct list_head *path) { coresight_disable_path_from(path, NULL); } +EXPORT_SYMBOL_GPL(coresight_disable_path);
int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data) { @@ -1199,6 +1205,7 @@ int coresight_timeout(void __iomem *addr, u32 offset, int position, int value)
return -EAGAIN; } +EXPORT_SYMBOL_GPL(coresight_timeout);
struct bus_type coresight_bustype = { .name = "coresight", @@ -1355,6 +1362,7 @@ bool coresight_loses_context_with_cpu(struct device *dev) return fwnode_property_present(dev_fwnode(dev), "arm,coresight-loses-context-with-cpu"); } +EXPORT_SYMBOL_GPL(coresight_loses_context_with_cpu);
/* * coresight_alloc_device_name - Get an index for a given device in the
- Kconfig becomes a tristate, to allow =m - add a stm_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++++- drivers/hwtracing/coresight/coresight-stm.c | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 4663fd1bbffc..6433f835fc97 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -86,7 +86,7 @@ config CORESIGHT_SOURCE_ETM4X data tracing may also be available.
config CORESIGHT_STM - bool "CoreSight System Trace Macrocell driver" + tristate "CoreSight System Trace Macrocell driver" depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64 select CORESIGHT_LINKS_AND_SINKS select STM @@ -96,6 +96,9 @@ config CORESIGHT_STM logging useful software events or data coming from various entities in the system, possibly running different OSs
+ To compile this driver as a module, choose M here: the + module will be called coresight-stm. + config CORESIGHT_CPU_DEBUG tristate "CoreSight CPU Debug driver" depends on ARM || ARM64 diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c index b908ca104645..d009e95fb5b8 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -950,6 +950,17 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id) return ret; }
+static int __exit stm_remove(struct amba_device *adev) +{ + struct stm_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + coresight_unregister(drvdata->csdev); + + stm_unregister_device(&drvdata->stm); + + return 0; +} + #ifdef CONFIG_PM static int stm_runtime_suspend(struct device *dev) { @@ -982,6 +993,8 @@ static const struct amba_id stm_ids[] = { { 0, 0}, };
+MODULE_DEVICE_TABLE(amba, stm_ids); + static struct amba_driver stm_driver = { .drv = { .name = "coresight-stm", @@ -990,7 +1003,12 @@ static struct amba_driver stm_driver = { .suppress_bind_attrs = true, }, .probe = stm_probe, + .remove = stm_remove, .id_table = stm_ids, };
-builtin_amba_driver(stm_driver); +module_amba_driver(stm_driver); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_DESCRIPTION("Arm CoreSight System Trace Macrocell driver"); +MODULE_LICENSE("GPL v2");
From: Kim Phillips kim.phillips@arm.com
Allow to build coresight-etm3x as a module, for ease of development.
- Kconfig becomes a tristate, to allow =m - append -core to source file name to allow module to be called coresight-etm3x by the Makefile - add an etm_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 +++- drivers/hwtracing/coresight/Makefile | 3 ++- ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) rename drivers/hwtracing/coresight/{coresight-etm3x.c => coresight-etm3x-core.c} (97%)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 6433f835fc97..8fd9fd139cf3 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10 special enhancement or added features.
config CORESIGHT_SOURCE_ETM3X - bool "CoreSight Embedded Trace Macrocell 3.x driver" + tristate "CoreSight Embedded Trace Macrocell 3.x driver" depends on !ARM64 select CORESIGHT_LINKS_AND_SINKS help @@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X This is primarily useful for instruction level tracing. Depending the ETM version data tracing may also be available.
+ To compile this driver as a module, choose M here: the + module will be called coresight-etm3x. + config CORESIGHT_SOURCE_ETM4X bool "CoreSight Embedded Trace Macrocell 4.x driver" depends on ARM64 diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 0e3e72f0f510..56a3dee21de1 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -10,7 +10,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \ coresight-replicator.o -obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o coresight-etm-cp14.o \ +obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o +coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \ coresight-etm3x-sysfs.o obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \ coresight-etm4x-sysfs.o diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c similarity index 97% rename from drivers/hwtracing/coresight/coresight-etm3x.c rename to drivers/hwtracing/coresight/coresight-etm3x-core.c index e2cb6873c3f2..5f4f7280c829 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) return ret; }
+static int __exit etm_remove(struct amba_device *adev) +{ + struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + etm_perf_symlink(drvdata->csdev, false); + + if (--etm_count == 0) { + cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING); + if (hp_online) + cpuhp_remove_state_nocalls(hp_online); + } + + coresight_unregister(drvdata->csdev); + + return 0; +} + #ifdef CONFIG_PM static int etm_runtime_suspend(struct device *dev) { @@ -937,6 +954,8 @@ static const struct amba_id etm_ids[] = { { 0, 0}, };
+MODULE_DEVICE_TABLE(amba, etm_ids); + static struct amba_driver etm_driver = { .drv = { .name = "coresight-etm3x", @@ -945,6 +964,12 @@ static struct amba_driver etm_driver = { .suppress_bind_attrs = true, }, .probe = etm_probe, + .remove = etm_remove, .id_table = etm_ids, }; -builtin_amba_driver(etm_driver); +module_amba_driver(etm_driver); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_AUTHOR("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace driver"); +MODULE_LICENSE("GPL v2");
From: Kim Phillips kim.phillips@arm.com
Allow to build coresight-etm4x as a module, for ease of development.
- Kconfig becomes a tristate, to allow =m - append -core to source file name to allow module to be called coresight-etm4x by the Makefile - add an etm4_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++- drivers/hwtracing/coresight/Makefile | 4 +-- ...resight-etm4x.c => coresight-etm4x-core.c} | 31 ++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (98%)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 8fd9fd139cf3..d6e107bbd30b 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X module will be called coresight-etm3x.
config CORESIGHT_SOURCE_ETM4X - bool "CoreSight Embedded Trace Macrocell 4.x driver" + tristate "CoreSight Embedded Trace Macrocell 4.x driver" depends on ARM64 select CORESIGHT_LINKS_AND_SINKS select PID_IN_CONTEXTIDR @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X for instruction level tracing. Depending on the implemented version data tracing may also be available.
+ To compile this driver as a module, choose M here: the + module will be called coresight-etm4x. + config CORESIGHT_STM tristate "CoreSight System Trace Macrocell driver" depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64 diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 56a3dee21de1..a00be5f74a34 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -13,8 +13,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \ obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \ coresight-etm3x-sysfs.o -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \ - coresight-etm4x-sysfs.o +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c similarity index 98% rename from drivers/hwtracing/coresight/coresight-etm4x.c rename to drivers/hwtracing/coresight/coresight-etm4x-core.c index a90d757f7043..b5eac5fbbd69 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -1546,6 +1546,26 @@ static struct amba_cs_uci_id uci_id_etm4[] = { } };
+static int __exit etm4_remove(struct amba_device *adev) +{ + struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + etm_perf_symlink(drvdata->csdev, false); + + if (--etm4_count == 0) { + etm4_cpu_pm_unregister(); + + cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING); + if (hp_online) + cpuhp_remove_state_nocalls(hp_online); + } + + coresight_unregister(drvdata->csdev); + + return 0; +} + + static const struct amba_id etm4_ids[] = { CS_AMBA_ID(0x000bb95d), /* Cortex-A53 */ CS_AMBA_ID(0x000bb95e), /* Cortex-A57 */ @@ -1560,12 +1580,21 @@ static const struct amba_id etm4_ids[] = { {}, };
+MODULE_DEVICE_TABLE(amba, etm4_ids); + static struct amba_driver etm4x_driver = { .drv = { .name = "coresight-etm4x", + .owner = THIS_MODULE, .suppress_bind_attrs = true, }, .probe = etm4_probe, + .remove = etm4_remove, .id_table = etm4_ids, }; -builtin_amba_driver(etm4x_driver); +module_amba_driver(etm4x_driver); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_AUTHOR("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver"); +MODULE_LICENSE("GPL v2");
From: Kim Phillips kim.phillips@arm.com
Allow to build coresight-etb10 as a module, for ease of development.
- Kconfig becomes a tristate, to allow =m - add an etb_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++++- drivers/hwtracing/coresight/coresight-etb10.c | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index d6e107bbd30b..996d84a1edb8 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -57,13 +57,16 @@ config CORESIGHT_SINK_TPIU the on-board coresight memory can handle.
config CORESIGHT_SINK_ETBV10 - bool "Coresight ETBv1.0 driver" + tristate "Coresight ETBv1.0 driver" depends on CORESIGHT_LINKS_AND_SINKS help This enables support for the Embedded Trace Buffer version 1.0 driver that complies with the generic implementation of the component without special enhancement or added features.
+ To compile this driver as a module, choose M here: the + module will be called coresight-etb10. + config CORESIGHT_SOURCE_ETM3X tristate "CoreSight Embedded Trace Macrocell 3.x driver" depends on !ARM64 diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index bbad5c1f67fa..babb9d281ef2 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -801,6 +801,16 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id) return ret; }
+static int __exit etb_remove(struct amba_device *adev) +{ + struct etb_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + misc_deregister(&drvdata->miscdev); + coresight_unregister(drvdata->csdev); + + return 0; +} + #ifdef CONFIG_PM static int etb_runtime_suspend(struct device *dev) { @@ -835,6 +845,8 @@ static const struct amba_id etb_ids[] = { { 0, 0}, };
+MODULE_DEVICE_TABLE(amba, etb_ids); + static struct amba_driver etb_driver = { .drv = { .name = "coresight-etb10", @@ -844,6 +856,12 @@ static struct amba_driver etb_driver = {
}, .probe = etb_probe, + .remove = etb_remove, .id_table = etb_ids, }; -builtin_amba_driver(etb_driver); +module_amba_driver(etb_driver); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_AUTHOR("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight Embedded Trace Buffer driver"); +MODULE_LICENSE("GPL v2");
From: Kim Phillips kim.phillips@arm.com
Allow to build coresight-tpiu as a module, for ease of development.
- Kconfig becomes a tristate, to allow =m - add a tpiu_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++++- drivers/hwtracing/coresight/coresight-tpiu.c | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 996d84a1edb8..8fd9887fb03b 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -46,7 +46,7 @@ config CORESIGHT_CATU mode where the address is not translated.
config CORESIGHT_SINK_TPIU - bool "Coresight generic TPIU driver" + tristate "Coresight generic TPIU driver" depends on CORESIGHT_LINKS_AND_SINKS help This enables support for the Trace Port Interface Unit driver, @@ -56,6 +56,9 @@ config CORESIGHT_SINK_TPIU connected to an external host for use case capturing more traces than the on-board coresight memory can handle.
+ To compile this driver as a module, choose M here: the + module will be called coresight-tpiu. + config CORESIGHT_SINK_ETBV10 tristate "Coresight ETBv1.0 driver" depends on CORESIGHT_LINKS_AND_SINKS diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c index f8583e4032a6..e4ddd9801535 100644 --- a/drivers/hwtracing/coresight/coresight-tpiu.c +++ b/drivers/hwtracing/coresight/coresight-tpiu.c @@ -173,6 +173,15 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id) return PTR_ERR(drvdata->csdev); }
+static int __exit tpiu_remove(struct amba_device *adev) +{ + struct tpiu_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + coresight_unregister(drvdata->csdev); + + return 0; +} + #ifdef CONFIG_PM static int tpiu_runtime_suspend(struct device *dev) { @@ -216,6 +225,8 @@ static const struct amba_id tpiu_ids[] = { { 0, 0}, };
+MODULE_DEVICE_TABLE(amba, tpiu_ids); + static struct amba_driver tpiu_driver = { .drv = { .name = "coresight-tpiu", @@ -224,6 +235,12 @@ static struct amba_driver tpiu_driver = { .suppress_bind_attrs = true, }, .probe = tpiu_probe, + .remove = tpiu_remove, .id_table = tpiu_ids, }; -builtin_amba_driver(tpiu_driver); +module_amba_driver(tpiu_driver); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_AUTHOR("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver"); +MODULE_LICENSE("GPL v2");
From: Kim Phillips kim.phillips@arm.com
Allow to build coresight-tmc as a module, for ease of development.
- Kconfig becomes a tristate, to allow =m - append -core to source file name to allow module to be called coresight-tmc by the Makefile - add an tmc_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 6 +++++- drivers/hwtracing/coresight/Makefile | 6 +++--- .../{coresight-tmc.c => coresight-tmc-core.c} | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} (96%)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 8fd9887fb03b..fc48ae086746 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -25,7 +25,8 @@ config CORESIGHT_LINKS_AND_SINKS entity at run time to form a complete trace path.
config CORESIGHT_LINK_AND_SINK_TMC - bool "Coresight generic TMC driver" + tristate "Coresight generic TMC driver" + depends on CORESIGHT_LINKS_AND_SINKS help This enables support for the Trace Memory Controller driver. @@ -34,6 +35,9 @@ config CORESIGHT_LINK_AND_SINK_TMC complies with the generic implementation of the component without special enhancement or added features.
+ To compile this driver as a module, choose M here: the + module will be called coresight-tmc. + config CORESIGHT_CATU bool "Coresight Address Translation Unit (CATU) driver" depends on CORESIGHT_LINK_AND_SINK_TMC diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index a00be5f74a34..8a7d7ddcce24 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -3,9 +3,9 @@ # Makefile for CoreSight drivers. # obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o coresight-platform.o -obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \ - coresight-tmc-etf.o \ - coresight-tmc-etr.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 obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \ diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc-core.c similarity index 96% rename from drivers/hwtracing/coresight/coresight-tmc.c rename to drivers/hwtracing/coresight/coresight-tmc-core.c index 1cf82fa58289..a0b8cc5f63fb 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -538,6 +538,16 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) return ret; }
+static int __exit tmc_remove(struct amba_device *adev) +{ + struct tmc_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + misc_deregister(&drvdata->miscdev); + coresight_unregister(drvdata->csdev); + + return 0; +} + static const struct amba_id tmc_ids[] = { CS_AMBA_ID(0x000bb961), /* Coresight SoC 600 TMC-ETR/ETS */ @@ -549,6 +559,8 @@ static const struct amba_id tmc_ids[] = { { 0, 0}, };
+MODULE_DEVICE_TABLE(amba, tmc_ids); + static struct amba_driver tmc_driver = { .drv = { .name = "coresight-tmc", @@ -556,6 +568,11 @@ static struct amba_driver tmc_driver = { .suppress_bind_attrs = true, }, .probe = tmc_probe, + .remove = tmc_remove, .id_table = tmc_ids, }; -builtin_amba_driver(tmc_driver); +module_amba_driver(tmc_driver); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver"); +MODULE_LICENSE("GPL v2");
From: Mian Yousaf Kaukab ykaukab@suse.de
Dynamic-funnel uses module_amba_driver to register. Whereas static-funnel uses builtin_platform_driver. Combine these init calls into a single module_init/exit pair in preparation to make the driver modular.
Signed-off-by: Mian Yousaf Kaukab ykaukab@suse.de Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- .../hwtracing/coresight/coresight-funnel.c | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c index 900690a9f7f0..594711c757fe 100644 --- a/drivers/hwtracing/coresight/coresight-funnel.c +++ b/drivers/hwtracing/coresight/coresight-funnel.c @@ -341,7 +341,6 @@ static struct platform_driver static_funnel_driver = { .suppress_bind_attrs = true, }, }; -builtin_platform_driver(static_funnel_driver);
static int dynamic_funnel_probe(struct amba_device *adev, const struct amba_id *id) @@ -372,4 +371,32 @@ static struct amba_driver dynamic_funnel_driver = { .probe = dynamic_funnel_probe, .id_table = dynamic_funnel_ids, }; -builtin_amba_driver(dynamic_funnel_driver); + +static int __init funnel_init(void) +{ + int ret; + + ret = platform_driver_register(&static_funnel_driver); + if (ret) { + pr_info("Error registering platform driver\n"); + return ret; + } + + ret = amba_driver_register(&dynamic_funnel_driver); + if (ret) { + pr_info("Error registering amba driver\n"); + platform_driver_unregister(&static_funnel_driver); + } + + return ret; +} + +static void __exit funnel_exit(void) +{ + platform_driver_unregister(&static_funnel_driver); + amba_driver_unregister(&dynamic_funnel_driver); +} + +module_init(funnel_init); +module_exit(funnel_exit); +
From: Mian Yousaf Kaukab ykaukab@suse.de
Dynamic-replicator uses module_amba_driver to register. Whereas static-replicator uses builtin_platform_driver. Combine these init calls into a single module_init/exit pair in preparation to make the driver modular.
Signed-off-by: Mian Yousaf Kaukab ykaukab@suse.de Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- .../coresight/coresight-replicator.c | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c index e7dc1c31d20d..32ee3497d018 100644 --- a/drivers/hwtracing/coresight/coresight-replicator.c +++ b/drivers/hwtracing/coresight/coresight-replicator.c @@ -339,7 +339,6 @@ static struct platform_driver static_replicator_driver = { .suppress_bind_attrs = true, }, }; -builtin_platform_driver(static_replicator_driver);
static int dynamic_replicator_probe(struct amba_device *adev, const struct amba_id *id) @@ -369,4 +368,31 @@ static struct amba_driver dynamic_replicator_driver = { .probe = dynamic_replicator_probe, .id_table = dynamic_replicator_ids, }; -builtin_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; +} + +static void __exit replicator_exit(void) +{ + platform_driver_unregister(&static_replicator_driver); + amba_driver_unregister(&dynamic_replicator_driver); +} + +module_init(replicator_init); +module_exit(replicator_exit);
From: Kim Phillips kim.phillips@arm.com
Allow to build coresight-funnel and coresight-replicator as modules, for ease of development.
- Kconfig becomes a tristate, to allow =m - add funnel_remove and replicator_remove functions, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Cc: Mathieu Poirier mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++- .../hwtracing/coresight/coresight-funnel.c | 31 +++++++++++++++++ .../coresight/coresight-replicator.c | 33 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index fc48ae086746..f31778dd0b5d 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -17,13 +17,16 @@ menuconfig CORESIGHT
if CORESIGHT config CORESIGHT_LINKS_AND_SINKS - bool "CoreSight Link and Sink drivers" + tristate "CoreSight Link and Sink drivers" help This enables support for CoreSight link and sink drivers that are responsible for transporting and collecting the trace data respectively. Link and sinks are dynamically aggregated with a trace entity at run time to form a complete trace path.
+ To compile these drivers as modules, choose M here: the + modules will be called coresight-funnel and coresight-replicator. + config CORESIGHT_LINK_AND_SINK_TMC tristate "Coresight generic TMC driver"
diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c index 594711c757fe..062694ef9879 100644 --- a/drivers/hwtracing/coresight/coresight-funnel.c +++ b/drivers/hwtracing/coresight/coresight-funnel.c @@ -274,6 +274,15 @@ static int funnel_probe(struct device *dev, struct resource *res) return ret; }
+static int __exit funnel_remove(struct device *dev) +{ + struct funnel_drvdata *drvdata = dev_get_drvdata(dev); + + coresight_unregister(drvdata->csdev); + + return 0; +} + #ifdef CONFIG_PM static int funnel_runtime_suspend(struct device *dev) { @@ -319,20 +328,31 @@ static int static_funnel_probe(struct platform_device *pdev) return ret; }
+static int __exit static_funnel_remove(struct platform_device *pdev) +{ + funnel_remove(&pdev->dev); + pm_runtime_disable(&pdev->dev); + return 0; +} + static const struct of_device_id static_funnel_match[] = { {.compatible = "arm,coresight-static-funnel"}, {} };
+MODULE_DEVICE_TABLE(of, static_funnel_match); + #ifdef CONFIG_ACPI static const struct acpi_device_id static_funnel_ids[] = { {"ARMHC9FE", 0}, {}, }; +MODULE_DEVICE_TABLE(acpi, static_funnel_ids); #endif
static struct platform_driver static_funnel_driver = { .probe = static_funnel_probe, + .probe = static_funnel_remove, .driver = { .name = "coresight-static-funnel", .of_match_table = static_funnel_match, @@ -348,6 +368,11 @@ static int dynamic_funnel_probe(struct amba_device *adev, return funnel_probe(&adev->dev, &adev->res); }
+static int __exit dynamic_funnel_remove(struct amba_device *adev) +{ + return funnel_remove(&adev->dev); +} + static const struct amba_id dynamic_funnel_ids[] = { { .id = 0x000bb908, @@ -361,6 +386,8 @@ static const struct amba_id dynamic_funnel_ids[] = { { 0, 0}, };
+MODULE_DEVICE_TABLE(amba, dynamic_funnel_ids); + static struct amba_driver dynamic_funnel_driver = { .drv = { .name = "coresight-dynamic-funnel", @@ -369,6 +396,7 @@ static struct amba_driver dynamic_funnel_driver = { .suppress_bind_attrs = true, }, .probe = dynamic_funnel_probe, + .remove = dynamic_funnel_remove, .id_table = dynamic_funnel_ids, };
@@ -400,3 +428,6 @@ static void __exit funnel_exit(void) module_init(funnel_init); module_exit(funnel_exit);
+MODULE_AUTHOR("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight Funnel Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c index 32ee3497d018..463a99dec778 100644 --- a/drivers/hwtracing/coresight/coresight-replicator.c +++ b/drivers/hwtracing/coresight/coresight-replicator.c @@ -270,6 +270,14 @@ static int replicator_probe(struct device *dev, struct resource *res) return ret; }
+static int __exit replicator_remove(struct device *dev) +{ + struct replicator_drvdata *drvdata = dev_get_drvdata(dev); + + coresight_unregister(drvdata->csdev); + return 0; +} + static int static_replicator_probe(struct platform_device *pdev) { int ret; @@ -289,6 +297,13 @@ static int static_replicator_probe(struct platform_device *pdev) return ret; }
+static int __exit static_replicator_remove(struct platform_device *pdev) +{ + replicator_remove(&pdev->dev); + pm_runtime_disable(&pdev->dev); + return 0; +} + #ifdef CONFIG_PM static int replicator_runtime_suspend(struct device *dev) { @@ -321,18 +336,22 @@ static const struct of_device_id static_replicator_match[] = { {.compatible = "arm,coresight-static-replicator"}, {} }; +MODULE_DEVICE_TABLE(of, static_replicator_match);
#ifdef CONFIG_ACPI static const struct acpi_device_id static_replicator_acpi_ids[] = { {"ARMHC985", 0}, /* ARM CoreSight Static Replicator */ {} }; +MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids); #endif
static struct platform_driver static_replicator_driver = { .probe = static_replicator_probe, + .remove = static_replicator_remove, .driver = { .name = "coresight-static-replicator", + .owner = THIS_MODULE, .of_match_table = of_match_ptr(static_replicator_match), .acpi_match_table = ACPI_PTR(static_replicator_acpi_ids), .pm = &replicator_dev_pm_ops, @@ -346,6 +365,11 @@ static int dynamic_replicator_probe(struct amba_device *adev, return replicator_probe(&adev->dev, &adev->res); }
+static int __exit dynamic_replicator_remove(struct amba_device *adev) +{ + return replicator_remove(&adev->dev); +} + static const struct amba_id dynamic_replicator_ids[] = { { .id = 0x000bb909, @@ -359,13 +383,17 @@ static const struct amba_id dynamic_replicator_ids[] = { { 0, 0 }, };
+MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids); + static struct amba_driver dynamic_replicator_driver = { .drv = { .name = "coresight-dynamic-replicator", .pm = &replicator_dev_pm_ops, + .owner = THIS_MODULE, .suppress_bind_attrs = true, }, .probe = dynamic_replicator_probe, + .remove = dynamic_replicator_remove, .id_table = dynamic_replicator_ids, };
@@ -396,3 +424,8 @@ static void __exit replicator_exit(void)
module_init(replicator_init); module_exit(replicator_exit); + +MODULE_AUTHOR("Pratik Patel pratikp@codeaurora.org"); +MODULE_AUTHOR("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight Replicator Driver"); +MODULE_LICENSE("GPL v2");
Add static cti_assoc_ops to coresight core driver. Let cti driver register the add_assoc and remove_assoc call back. Avoid coresight core driver to depend on cti driver.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-cti.c | 32 ++++++++++++++++++-- drivers/hwtracing/coresight/coresight-priv.h | 14 ++++----- drivers/hwtracing/coresight/coresight.c | 20 ++++++++++-- 3 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c index aa6e0249bd70..2829286daed9 100644 --- a/drivers/hwtracing/coresight/coresight-cti.c +++ b/drivers/hwtracing/coresight/coresight-cti.c @@ -504,7 +504,6 @@ void cti_add_assoc_to_csdev(struct coresight_device *csdev) cti_add_done: mutex_unlock(&ect_mutex); } -EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
/* * Removing the associated devices is easier. @@ -530,7 +529,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev) } mutex_unlock(&ect_mutex); } -EXPORT_SYMBOL_GPL(cti_remove_assoc_from_csdev); + +/* + * Operations to add and remove associated CTI. + * Register to coresight core driver as call back function. + */ +static struct cti_assoc_op cti_assoc_ops = { + .add = cti_add_assoc_to_csdev, + .remove = cti_remove_assoc_from_csdev +};
/* * Update the cross references where the associated device was found @@ -742,4 +749,23 @@ static struct amba_driver cti_driver = { .probe = cti_probe, .id_table = cti_ids, }; -builtin_amba_driver(cti_driver); + +static int __init cti_init(void) +{ + int ret; + + ret = amba_driver_register(&cti_driver); + if (ret) + pr_info("Error registering cti driver\n"); + coresight_set_cti_ops(&cti_assoc_ops); + return ret; +} + +static void __exit cti_exit(void) +{ + coresight_remove_cti_ops(); + amba_driver_unregister(&cti_driver); +} + +module_init(cti_init); +module_exit(cti_exit); diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 335ba2208b61..56d677473be4 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -162,15 +162,13 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; } static inline int etm_writel_cp14(u32 off, u32 val) { return 0; } #endif
-#ifdef CONFIG_CORESIGHT_CTI -extern void cti_add_assoc_to_csdev(struct coresight_device *csdev); -extern void cti_remove_assoc_from_csdev(struct coresight_device *csdev); +struct cti_assoc_op { + void (*add)(struct coresight_device *csdev); + void (*remove)(struct coresight_device *csdev); +};
-#else -static inline void cti_add_assoc_to_csdev(struct coresight_device *csdev) {} -static inline void -cti_remove_assoc_from_csdev(struct coresight_device *csdev) {} -#endif +extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op); +extern void coresight_remove_cti_ops(void);
/* * Macros and inline functions to handle CoreSight UCI data and driver diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index e8c4e10b75b5..bf8c41901016 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -57,6 +57,20 @@ const u32 coresight_barrier_pkt[4] = { 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
+static const struct cti_assoc_op *cti_assoc_ops; + +void coresight_set_cti_ops(const struct cti_assoc_op *cti_op) +{ + cti_assoc_ops = cti_op; +} +EXPORT_SYMBOL_GPL(coresight_set_cti_ops); + +void coresight_remove_cti_ops(void) +{ + cti_assoc_ops = NULL; +} +EXPORT_SYMBOL_GPL(coresight_remove_cti_ops); + static int coresight_id_match(struct device *dev, void *data) { int trace_id, i_trace_id; @@ -1030,7 +1044,8 @@ static void coresight_device_release(struct device *dev) { struct coresight_device *csdev = to_coresight_device(dev);
- cti_remove_assoc_from_csdev(csdev); + if (cti_assoc_ops && cti_assoc_ops->remove) + cti_assoc_ops->remove(csdev); fwnode_handle_put(csdev->dev.fwnode); kfree(csdev->refcnt); kfree(csdev); @@ -1314,7 +1329,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
coresight_fixup_device_conns(csdev); coresight_fixup_orphan_conns(csdev); - cti_add_assoc_to_csdev(csdev); + if (cti_assoc_ops && cti_assoc_ops->add) + cti_assoc_ops->add(csdev);
mutex_unlock(&coresight_mutex);
Allow to build coresight-cti as a module, for ease of development.
- Kconfig becomes a tristate, to allow =m - append -core to source file name to allow module to be called coresight-cti by the Makefile - add an cti_remove function, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++++- drivers/hwtracing/coresight/Makefile | 4 ++-- .../{coresight-cti.c => coresight-cti-core.c} | 14 ++++++++++++++ drivers/hwtracing/coresight/coresight-platform.c | 1 + drivers/hwtracing/coresight/coresight.c | 1 + 5 files changed, 22 insertions(+), 3 deletions(-) rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (98%)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index f31778dd0b5d..b04aae2ceecc 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -136,7 +136,7 @@ config CORESIGHT_CPU_DEBUG module will be called coresight-cpu-debug.
config CORESIGHT_CTI - bool "CoreSight Cross Trigger Interface (CTI) driver" + tristate "CoreSight Cross Trigger Interface (CTI) driver" depends on ARM || ARM64 help This driver provides support for CoreSight CTI and CTM components. @@ -147,6 +147,9 @@ config CORESIGHT_CTI halt compared to disabling sources and sinks normally in driver software.
+ To compile this driver as a module, choose M here: the + module will be called coresight-cti. + config CORESIGHT_CTI_INTEGRATION_REGS bool "Access CTI CoreSight Integration Registers" depends on CORESIGHT_CTI diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 8a7d7ddcce24..c65a153b1e1b 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -18,6 +18,6 @@ coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o -obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o \ - coresight-cti-platform.o \ +obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o +coresight-cti-y := coresight-cti-core.o coresight-cti-platform.o \ coresight-cti-sysfs.o diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti-core.c similarity index 98% rename from drivers/hwtracing/coresight/coresight-cti.c rename to drivers/hwtracing/coresight/coresight-cti-core.c index 2829286daed9..b31839682c9e 100644 --- a/drivers/hwtracing/coresight/coresight-cti.c +++ b/drivers/hwtracing/coresight/coresight-cti-core.c @@ -618,6 +618,14 @@ static void cti_device_release(struct device *dev) if (drvdata->csdev_release) drvdata->csdev_release(dev); } +static int __exit cti_remove(struct amba_device *adev) +{ + struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + coresight_unregister(drvdata->csdev); + + return 0; +}
static int cti_probe(struct amba_device *adev, const struct amba_id *id) { @@ -739,6 +747,7 @@ static const struct amba_id cti_ids[] = { CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */ { 0, 0}, }; +MODULE_DEVICE_TABLE(amba, cti_ids);
static struct amba_driver cti_driver = { .drv = { @@ -747,6 +756,7 @@ static struct amba_driver cti_driver = { .suppress_bind_attrs = true, }, .probe = cti_probe, + .remove = cti_remove, .id_table = cti_ids, };
@@ -769,3 +779,7 @@ static void __exit cti_exit(void)
module_init(cti_init); module_exit(cti_exit); + +MODULE_AUTHOR("Mike Leach mike.leach@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight Funnel Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c index 43418a2126ff..44f24683f089 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c @@ -76,6 +76,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode) } return csdev; } +EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
#ifdef CONFIG_OF static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index bf8c41901016..cf7079f4b99c 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -273,6 +273,7 @@ void coresight_set_assoc_ectdev_mutex(struct coresight_device *csdev, csdev->ect_dev = ect_csdev; mutex_unlock(&coresight_mutex); } +EXPORT_SYMBOL_GPL(coresight_set_assoc_ectdev_mutex);
static int coresight_enable_sink(struct coresight_device *csdev, u32 mode, void *data)
From: Mian Yousaf Kaukab ykaukab@suse.de
Make etr_catu_buf_ops static. Instead of directly accessing it in etr_buf_ops[], add a function to let catu driver register the ops at runtime. Break circular dependency between tmc-etr and catu drivers.
Signed-off-by: Mian Yousaf Kaukab ykaukab@suse.de Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-catu.c | 22 +++++++++++++++++-- drivers/hwtracing/coresight/coresight-catu.h | 2 -- .../hwtracing/coresight/coresight-tmc-etr.c | 15 +++++++++++-- drivers/hwtracing/coresight/coresight-tmc.h | 3 +++ 4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c index 16ebf38a9f66..9d51df7d08f9 100644 --- a/drivers/hwtracing/coresight/coresight-catu.c +++ b/drivers/hwtracing/coresight/coresight-catu.c @@ -358,7 +358,7 @@ static int catu_alloc_etr_buf(struct tmc_drvdata *tmc_drvdata, return 0; }
-const struct etr_buf_operations etr_catu_buf_ops = { +static const struct etr_buf_operations etr_catu_buf_ops = { .alloc = catu_alloc_etr_buf, .free = catu_free_etr_buf, .sync = catu_sync_etr_buf, @@ -585,4 +585,22 @@ static struct amba_driver catu_driver = { .id_table = catu_ids, };
-builtin_amba_driver(catu_driver); +static int __init catu_init(void) +{ + int ret; + + ret = amba_driver_register(&catu_driver); + if (ret) + pr_info("Error registering catu driver\n"); + tmc_etr_set_catu_ops(&etr_catu_buf_ops); + return ret; +} + +static void __exit catu_exit(void) +{ + tmc_etr_remove_catu_ops(); + amba_driver_unregister(&catu_driver); +} + +module_init(catu_init); +module_exit(catu_exit); diff --git a/drivers/hwtracing/coresight/coresight-catu.h b/drivers/hwtracing/coresight/coresight-catu.h index 80ceee3c739c..6160c2d75a56 100644 --- a/drivers/hwtracing/coresight/coresight-catu.h +++ b/drivers/hwtracing/coresight/coresight-catu.h @@ -108,6 +108,4 @@ static inline bool coresight_is_catu_device(struct coresight_device *csdev) return true; }
-extern const struct etr_buf_operations etr_catu_buf_ops; - #endif diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index b86c76ae26b9..8f84f294d0d8 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -794,10 +794,21 @@ static inline void tmc_etr_disable_catu(struct tmc_drvdata *drvdata) static const struct etr_buf_operations *etr_buf_ops[] = { [ETR_MODE_FLAT] = &etr_flat_buf_ops, [ETR_MODE_ETR_SG] = &etr_sg_buf_ops, - [ETR_MODE_CATU] = IS_ENABLED(CONFIG_CORESIGHT_CATU) - ? &etr_catu_buf_ops : NULL, + [ETR_MODE_CATU] = NULL, };
+void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu) +{ + etr_buf_ops[ETR_MODE_CATU] = catu; +} +EXPORT_SYMBOL_GPL(tmc_etr_set_catu_ops); + +void tmc_etr_remove_catu_ops(void) +{ + etr_buf_ops[ETR_MODE_CATU] = NULL; +} +EXPORT_SYMBOL_GPL(tmc_etr_remove_catu_ops); + static inline int tmc_etr_mode_alloc_buf(int mode, struct tmc_drvdata *drvdata, struct etr_buf *etr_buf, int node, diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index 71de978575f3..db431e230a40 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -325,4 +325,7 @@ tmc_sg_table_buf_size(struct tmc_sg_table *sg_table)
struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
+void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu); +void tmc_etr_remove_catu_ops(void); + #endif
Allow to build coresight-catu as modules, for ease of development. - Kconfig becomes a tristate, to allow =m - add catu_remove functions, for module unload - add a MODULE_DEVICE_TABLE for autoloading on boot
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++++- drivers/hwtracing/coresight/coresight-catu.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index b04aae2ceecc..dfe407cde262 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -42,7 +42,7 @@ config CORESIGHT_LINK_AND_SINK_TMC module will be called coresight-tmc.
config CORESIGHT_CATU - bool "Coresight Address Translation Unit (CATU) driver" + tristate "Coresight Address Translation Unit (CATU) driver" depends on CORESIGHT_LINK_AND_SINK_TMC help Enable support for the Coresight Address Translation Unit (CATU). @@ -52,6 +52,9 @@ config CORESIGHT_CATU by looking up the provided table. CATU can also be used in pass-through mode where the address is not translated.
+ To compile this driver as a module, choose M here: the + module will be called coresight-catu. + config CORESIGHT_SINK_TPIU tristate "Coresight generic TPIU driver" depends on CORESIGHT_LINKS_AND_SINKS diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c index 9d51df7d08f9..c0cbe1f79c38 100644 --- a/drivers/hwtracing/coresight/coresight-catu.c +++ b/drivers/hwtracing/coresight/coresight-catu.c @@ -567,6 +567,14 @@ static int catu_probe(struct amba_device *adev, const struct amba_id *id) return ret; }
+static int __exit catu_remove(struct amba_device *adev) +{ + struct catu_drvdata *drvdata = dev_get_drvdata(&adev->dev); + + coresight_unregister(drvdata->csdev); + return 0; +} + static struct amba_id catu_ids[] = { { .id = 0x000bb9ee, @@ -575,6 +583,8 @@ static struct amba_id catu_ids[] = { {}, };
+MODULE_DEVICE_TABLE(amba, catu_ids); + static struct amba_driver catu_driver = { .drv = { .name = "coresight-catu", @@ -582,6 +592,7 @@ static struct amba_driver catu_driver = { .suppress_bind_attrs = true, }, .probe = catu_probe, + .remove = catu_remove, .id_table = catu_ids, };
@@ -604,3 +615,7 @@ static void __exit catu_exit(void)
module_init(catu_init); module_exit(catu_exit); + +MODULE_AUTHOR("Suzuki K Poulose suzuki.poulose@arm.com"); +MODULE_DESCRIPTION("Arm CoreSight Replicator Driver"); +MODULE_LICENSE("GPL v2");
Coresight trace path holds the reference to devices on the path. Disable trace path before really remove coresight device.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight.c | 137 ++++++++++++++++++++++++ 1 file changed, 137 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index cf7079f4b99c..0870316ec4c4 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -490,6 +490,138 @@ void coresight_disable_path(struct list_head *path) } EXPORT_SYMBOL_GPL(coresight_disable_path);
+/* + * coresight_dev_on_path - Check if device is on trace path. + * + * @path - The trace path to check with. + * @csdev - The coresight device to check + * + * Returns true if the device is on trace path. + */ +bool coresight_dev_on_path(struct list_head *path, + struct coresight_device *csdev) +{ + struct coresight_node *nd; + + list_for_each_entry(nd, path, link) { + if (csdev == nd->csdev) + return true; + } + return false; +} + +/* + * coresight_disable_path_with - Disable trace path + * if trace path has concerned device on it. + * + * @path - The trace path to check. + * @csdev - Concerned coresight device + * + * Returns true if the device is on trace path. + */ +static bool coresight_disable_path_with(struct list_head *path, + struct coresight_device *csdev) +{ + struct coresight_node *src_nd; + struct coresight_device *srcdev; + bool ret; + + ret = coresight_dev_on_path(path, csdev); + if (ret) { + src_nd = list_first_entry(path, struct coresight_node, link); + srcdev = src_nd->csdev; + if (source_ops(srcdev)->disable) + source_ops(srcdev)->disable(srcdev, NULL); + srcdev->enable = false; + coresight_disable_path(path); + coresight_release_path(path); + } + + return ret; +} + +/* + * __coresight_disable_with - Check cpu trace path and + * stm trace path. Disable any path with conerned device. + * + * @csdev - Concerned coresight device + * + */ +static void __coresight_disable_with(struct coresight_device *csdev) +{ + int cpu; + struct list_head *path = NULL; + + for_each_possible_cpu(cpu) { + path = per_cpu(tracer_path, cpu); + if (path) { + if (coresight_disable_path_with(path, csdev)) + per_cpu(tracer_path, cpu) = NULL; + } + } + if (stm_path) { + path = stm_path; + if (coresight_disable_path_with(path, csdev)) + stm_path = NULL; + } +} + +static int coresight_disable_match(struct device *dev, void *data) +{ + int i; + struct coresight_device *csdev, *iterator; + struct coresight_connection *conn; + + csdev = data; + iterator = to_coresight_device(dev); + + /* No need to check oneself */ + if (csdev == iterator) + return 0; + + /* + * Circle throuch all the connection of that component. If we find + * a connection whose name matches @csdev, disable path with it. + */ + for (i = 0; i < iterator->pdata->nr_outport; i++) { + conn = &iterator->pdata->conns[i]; + + if (conn->child_dev == NULL) + continue; + + if (csdev->dev.fwnode == conn->child_fwnode) { + __coresight_disable_with(iterator); + + /* No need to continue */ + break; + } + } + + /* + * Returning '0' ensures that all known components on the + * bus will be checked. + */ + return 0; +} + +/** + * coresight_disable_with - disable any path with @csdev. + * @csdev: The device to check. + * + * Search for all the active paths. If @csdev is part of that path, + * disable the whole path. Device with CORESIGHT_DEV_TYPE_HELPER type + * is not part of path. Search for its parent device and disable any + * path with that device. + */ +void coresight_disable_with(struct coresight_device *csdev) +{ + if (csdev->type != CORESIGHT_DEV_TYPE_HELPER) + return __coresight_disable_with(csdev); + if (csdev->pdata->nr_inport) + bus_for_each_dev(&coresight_bustype, NULL, + csdev, coresight_disable_match); +} + int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data) {
@@ -1243,6 +1375,7 @@ void coresight_release_platform_data(struct coresight_platform_data *pdata)
for (i = 0; i < pdata->nr_outport; i++) { if (pdata->conns[i].child_fwnode) { + pdata->conns[i].child_dev = NULL; fwnode_handle_put(pdata->conns[i].child_fwnode); pdata->conns[i].child_fwnode = NULL; } @@ -1349,9 +1482,13 @@ EXPORT_SYMBOL_GPL(coresight_register); void coresight_unregister(struct coresight_device *csdev) { etm_perf_del_symlink_sink(csdev); + + mutex_lock(&coresight_mutex); + coresight_disable_with(csdev); /* Remove references of that device in the topology */ coresight_remove_conns(csdev); coresight_release_platform_data(csdev->pdata); + mutex_unlock(&coresight_mutex); device_unregister(&csdev->dev); } EXPORT_SYMBOL_GPL(coresight_unregister);
Good day Tingwei,
On Wed, Jul 01, 2020 at 03:14:25PM +0800, Tingwei Zhang wrote:
Coresight trace path holds the reference to devices on the path. Disable trace path before really remove coresight device.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org
drivers/hwtracing/coresight/coresight.c | 137 ++++++++++++++++++++++++ 1 file changed, 137 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index cf7079f4b99c..0870316ec4c4 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -490,6 +490,138 @@ void coresight_disable_path(struct list_head *path) } EXPORT_SYMBOL_GPL(coresight_disable_path); +/*
- coresight_dev_on_path - Check if device is on trace path.
- @path - The trace path to check with.
- @csdev - The coresight device to check
- Returns true if the device is on trace path.
- */
+bool coresight_dev_on_path(struct list_head *path,
struct coresight_device *csdev)
+{
- struct coresight_node *nd;
- list_for_each_entry(nd, path, link) {
if (csdev == nd->csdev)
return true;
- }
- return false;
+}
+/*
- coresight_disable_path_with - Disable trace path
- if trace path has concerned device on it.
- @path - The trace path to check.
- @csdev - Concerned coresight device
- Returns true if the device is on trace path.
- */
+static bool coresight_disable_path_with(struct list_head *path,
struct coresight_device *csdev)
+{
- struct coresight_node *src_nd;
- struct coresight_device *srcdev;
- bool ret;
- ret = coresight_dev_on_path(path, csdev);
- if (ret) {
src_nd = list_first_entry(path, struct coresight_node, link);
srcdev = src_nd->csdev;
if (source_ops(srcdev)->disable)
source_ops(srcdev)->disable(srcdev, NULL);
srcdev->enable = false;
coresight_disable_path(path);
coresight_release_path(path);
- }
- return ret;
+}
+/*
- __coresight_disable_with - Check cpu trace path and
- stm trace path. Disable any path with conerned device.
- @csdev - Concerned coresight device
- */
+static void __coresight_disable_with(struct coresight_device *csdev) +{
- int cpu;
- struct list_head *path = NULL;
- for_each_possible_cpu(cpu) {
path = per_cpu(tracer_path, cpu);
if (path) {
if (coresight_disable_path_with(path, csdev))
per_cpu(tracer_path, cpu) = NULL;
}
- }
- if (stm_path) {
path = stm_path;
if (coresight_disable_path_with(path, csdev))
stm_path = NULL;
- }
+}
+static int coresight_disable_match(struct device *dev, void *data) +{
- int i;
- struct coresight_device *csdev, *iterator;
- struct coresight_connection *conn;
- csdev = data;
- iterator = to_coresight_device(dev);
- /* No need to check oneself */
- if (csdev == iterator)
return 0;
- /*
* Circle throuch all the connection of that component. If we find
* a connection whose name matches @csdev, disable path with it.
*/
- for (i = 0; i < iterator->pdata->nr_outport; i++) {
conn = &iterator->pdata->conns[i];
if (conn->child_dev == NULL)
continue;
if (csdev->dev.fwnode == conn->child_fwnode) {
__coresight_disable_with(iterator);
/* No need to continue */
break;
}
- }
- /*
* Returning '0' ensures that all known components on the
* bus will be checked.
*/
- return 0;
+}
+/**
- coresight_disable_with - disable any path with @csdev.
- @csdev: The device to check.
- Search for all the active paths. If @csdev is part of that path,
- disable the whole path. Device with CORESIGHT_DEV_TYPE_HELPER type
- is not part of path. Search for its parent device and disable any
- path with that device.
- */
+void coresight_disable_with(struct coresight_device *csdev) +{
- if (csdev->type != CORESIGHT_DEV_TYPE_HELPER)
return __coresight_disable_with(csdev);
The main problem is indeed to take care of ongoing sessions which, other than the module mechanic, is the bulk of the code added in this set.
I've been thinking about this problem while reviewing an unrelated patchset and the solution I see is to let the driver core work for us. Since there is no implicit relation between modules, all we need is to introduce one using try_module_get() and module_put(). The module for each csdev can be accessed via csdev->dev->parent->driver->module.
From looking at the code if we call try_module_get() in coresight_grab_device()
and module_put() in coresight_drop_device(), the driver core won't let users remove modules for as long as a session is using the driver. That way all you need is the loop below and that is quite simple.
Let me know what you think, Mathieu
- if (csdev->pdata->nr_inport)
bus_for_each_dev(&coresight_bustype, NULL,
csdev, coresight_disable_match);
+}
int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data) { @@ -1243,6 +1375,7 @@ void coresight_release_platform_data(struct coresight_platform_data *pdata) for (i = 0; i < pdata->nr_outport; i++) { if (pdata->conns[i].child_fwnode) {
}pdata->conns[i].child_dev = NULL; fwnode_handle_put(pdata->conns[i].child_fwnode); pdata->conns[i].child_fwnode = NULL;
@@ -1349,9 +1482,13 @@ EXPORT_SYMBOL_GPL(coresight_register); void coresight_unregister(struct coresight_device *csdev) { etm_perf_del_symlink_sink(csdev);
- mutex_lock(&coresight_mutex);
- coresight_disable_with(csdev); /* Remove references of that device in the topology */ coresight_remove_conns(csdev); coresight_release_platform_data(csdev->pdata);
- mutex_unlock(&coresight_mutex); device_unregister(&csdev->dev);
} EXPORT_SYMBOL_GPL(coresight_unregister); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Thanks for reviewing this, Mathieu.
On 2020-07-14 06:11, Mathieu Poirier wrote:
Good day Tingwei,
On Wed, Jul 01, 2020 at 03:14:25PM +0800, Tingwei Zhang wrote:
Coresight trace path holds the reference to devices on the path. Disable trace path before really remove coresight device.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org
drivers/hwtracing/coresight/coresight.c | 137 ++++++++++++++++++++++++ 1 file changed, 137 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight.c
b/drivers/hwtracing/coresight/coresight.c
index cf7079f4b99c..0870316ec4c4 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -490,6 +490,138 @@ void coresight_disable_path(struct list_head
*path)
} EXPORT_SYMBOL_GPL(coresight_disable_path);
+/*
- coresight_dev_on_path - Check if device is on trace path.
- @path - The trace path to check with.
- @csdev - The coresight device to check
- Returns true if the device is on trace path.
- */
+bool coresight_dev_on_path(struct list_head *path,
struct coresight_device *csdev)
+{
- struct coresight_node *nd;
- list_for_each_entry(nd, path, link) {
if (csdev == nd->csdev)
return true;
- }
- return false;
+}
+/*
- coresight_disable_path_with - Disable trace path
- if trace path has concerned device on it.
- @path - The trace path to check.
- @csdev - Concerned coresight device
- Returns true if the device is on trace path.
- */
+static bool coresight_disable_path_with(struct list_head *path,
struct coresight_device *csdev)
+{
- struct coresight_node *src_nd;
- struct coresight_device *srcdev;
- bool ret;
- ret = coresight_dev_on_path(path, csdev);
- if (ret) {
src_nd = list_first_entry(path, struct coresight_node,
link);
srcdev = src_nd->csdev;
if (source_ops(srcdev)->disable)
source_ops(srcdev)->disable(srcdev, NULL);
srcdev->enable = false;
coresight_disable_path(path);
coresight_release_path(path);
- }
- return ret;
+}
+/*
- __coresight_disable_with - Check cpu trace path and
- stm trace path. Disable any path with conerned device.
- @csdev - Concerned coresight device
- */
+static void __coresight_disable_with(struct coresight_device *csdev) +{
- int cpu;
- struct list_head *path = NULL;
- for_each_possible_cpu(cpu) {
path = per_cpu(tracer_path, cpu);
if (path) {
if (coresight_disable_path_with(path, csdev))
per_cpu(tracer_path, cpu) = NULL;
}
- }
- if (stm_path) {
path = stm_path;
if (coresight_disable_path_with(path, csdev))
stm_path = NULL;
- }
+}
+static int coresight_disable_match(struct device *dev, void *data) +{
- int i;
- struct coresight_device *csdev, *iterator;
- struct coresight_connection *conn;
- csdev = data;
- iterator = to_coresight_device(dev);
- /* No need to check oneself */
- if (csdev == iterator)
return 0;
- /*
* Circle throuch all the connection of that component. If we
find
* a connection whose name matches @csdev, disable path with it.
*/
- for (i = 0; i < iterator->pdata->nr_outport; i++) {
conn = &iterator->pdata->conns[i];
if (conn->child_dev == NULL)
continue;
if (csdev->dev.fwnode == conn->child_fwnode) {
__coresight_disable_with(iterator);
/* No need to continue */
break;
}
- }
- /*
* Returning '0' ensures that all known components on the
* bus will be checked.
*/
- return 0;
+}
+/**
- coresight_disable_with - disable any path with @csdev.
- @csdev: The device to check.
- Search for all the active paths. If @csdev is part of that path,
- disable the whole path. Device with CORESIGHT_DEV_TYPE_HELPER type
- is not part of path. Search for its parent device and disable any
- path with that device.
- */
+void coresight_disable_with(struct coresight_device *csdev) +{
- if (csdev->type != CORESIGHT_DEV_TYPE_HELPER)
return __coresight_disable_with(csdev);
The main problem is indeed to take care of ongoing sessions which, other than the module mechanic, is the bulk of the code added in this set.
I've been thinking about this problem while reviewing an unrelated patchset and the solution I see is to let the driver core work for us. Since there is no implicit relation between modules, all we need is to introduce one using try_module_get() and module_put(). The module for each csdev can be accessed via csdev->dev->parent->driver->module.
From looking at the code if we call try_module_get() in coresight_grab_device() and module_put() in coresight_drop_device(), the driver core won't let users remove modules for as long as a session is using the driver. That way all you need is the loop below and that is quite simple.
Let me know what you think, Mathieu
I agree with you, Mathieu. Using try_module_get() and module_put() is a simpler, cleaner and safer way. I'll make the change, verify them and send a new patch set for review.
Tingwei
- if (csdev->pdata->nr_inport)
bus_for_each_dev(&coresight_bustype, NULL,
csdev, coresight_disable_match);
+}
int coresight_enable_path(struct list_head *path, u32 mode, void
*sink_data)
{
@@ -1243,6 +1375,7 @@ void coresight_release_platform_data(struct
coresight_platform_data *pdata)
for (i = 0; i < pdata->nr_outport; i++) { if (pdata->conns[i].child_fwnode) {
}pdata->conns[i].child_dev = NULL; fwnode_handle_put(pdata->conns[i].child_fwnode); pdata->conns[i].child_fwnode = NULL;
@@ -1349,9 +1482,13 @@ EXPORT_SYMBOL_GPL(coresight_register); void coresight_unregister(struct coresight_device *csdev) { etm_perf_del_symlink_sink(csdev);
- mutex_lock(&coresight_mutex);
- coresight_disable_with(csdev); /* Remove references of that device in the topology */ coresight_remove_conns(csdev); coresight_release_platform_data(csdev->pdata);
- mutex_unlock(&coresight_mutex); device_unregister(&csdev->dev);
} EXPORT_SYMBOL_GPL(coresight_unregister); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
Forum,
a Linux Foundation Collaborative Project
linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
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 mathieu.poirier@linaro.org Cc: Leo Yan leo.yan@linaro.org Cc: Alexander Shishkin alexander.shishkin@linux.intel.com Cc: Randy Dunlap rdunlap@infradead.org Cc: Suzuki K Poulose Suzuki.Poulose@arm.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Russell King linux@armlinux.org.uk Signed-off-by: Kim Phillips kim.phillips@arm.com Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/Kconfig | 5 ++- drivers/hwtracing/coresight/Makefile | 3 +- .../{coresight.c => coresight-core.c} | 42 ++++++++++++++----- .../hwtracing/coresight/coresight-etm-perf.c | 8 +++- .../hwtracing/coresight/coresight-etm-perf.h | 3 ++ 5 files changed, 47 insertions(+), 14 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 c65a153b1e1b..3fea4760575a 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -2,7 +2,8 @@ # # Makefile for CoreSight drivers. # -obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o coresight-platform.o +obj-$(CONFIG_CORESIGHT) += coresight.o +coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.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 0870316ec4c4..55ff45a9729e 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1355,16 +1355,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. @@ -1557,3 +1547,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("Mathieu Poirier mathieu.poirier@linaro.org"); +MODULE_DESCRIPTION("Arm CoreSight tracer driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index dbca77150a81..b466162d8254 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -580,7 +580,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;
@@ -607,4 +607,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/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 05f89723e282..3e4f2ad5e193 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -82,4 +82,7 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
#endif /* CONFIG_CORESIGHT */
+int __init etm_perf_init(void); +void __exit etm_perf_exit(void); + #endif
When coresight unreigster is called, check whether this device is used by any perf event. Stop and release that perf event to avoid accessing removed coresight device data later.
Signed-off-by: Tingwei Zhang tingwei@codeaurora.org --- drivers/hwtracing/coresight/coresight-core.c | 7 + .../hwtracing/coresight/coresight-etm-perf.c | 157 +++++++++++++++++- .../hwtracing/coresight/coresight-etm-perf.h | 2 + drivers/hwtracing/coresight/coresight-priv.h | 4 +- kernel/events/core.c | 1 + 5 files changed, 164 insertions(+), 7 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 55ff45a9729e..8261d527c8fb 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1475,9 +1475,16 @@ void coresight_unregister(struct coresight_device *csdev)
mutex_lock(&coresight_mutex); coresight_disable_with(csdev); + /* + * Disable all perf events that have trace path related to csdev. + * Deny any request to create new trace path. + */ + etm_perf_disable_with(csdev); /* Remove references of that device in the topology */ coresight_remove_conns(csdev); coresight_release_platform_data(csdev->pdata); + /* New trace path in perf can be established */ + etm_perf_disable_done(); mutex_unlock(&coresight_mutex); device_unregister(&csdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index b466162d8254..95aeb1ca807c 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -23,9 +23,22 @@
static struct pmu etm_pmu; static bool etm_perf_up; +/* Count for on going tasks which are changing coresight topology */ +static atomic_t *cs_updating_cnt; + +static DEFINE_MUTEX(cs_path_mutex);
static DEFINE_PER_CPU(struct perf_output_handle, ctx_handle); static DEFINE_PER_CPU(struct coresight_device *, csdev_src); +static DEFINE_PER_CPU(bool, csdev_src_removing); + +struct ev_data { + struct etm_event_data *event_data; + struct list_head link; +}; + +/* List for all events */ +static LIST_HEAD(ev_list);
/* ETMv3.5/PTM's ETMCR is 'config' */ PMU_FORMAT_ATTR(cycacc, "config:" __stringify(ETM_OPT_CYCACC)); @@ -64,6 +77,8 @@ static const struct attribute_group *etm_pmu_attr_groups[] = { NULL, };
+static void update_cs_cfg(void *ignored); + static inline struct list_head ** etm_event_cpu_path_ptr(struct etm_event_data *data, int cpu) { @@ -135,15 +150,35 @@ static void free_sink_buffer(struct etm_event_data *event_data) cpu = cpumask_first(mask); sink = coresight_get_sink(etm_event_cpu_path(event_data, cpu)); sink_ops(sink)->free_buffer(event_data->snk_config); + event_data->snk_config = NULL; }
-static void free_event_data(struct work_struct *work) +static void del_event_from_list(struct etm_event_data *event_data, + struct ev_data *del_ev_data) +{ + struct ev_data *ev_data = NULL; + struct ev_data *ev_data_next = NULL; + + if (IS_ERR_OR_NULL(del_ev_data)) { + list_for_each_entry_safe(ev_data, ev_data_next, &ev_list, link) { + if (ev_data->event_data == event_data) { + del_ev_data = ev_data; + break; + } + } + } + if (!(IS_ERR_OR_NULL(del_ev_data))) { + list_del(&del_ev_data->link); + kfree(del_ev_data); + } +} + +static void _free_event_data(struct etm_event_data *event_data, + struct ev_data *ev_data) { int cpu; cpumask_t *mask; - struct etm_event_data *event_data;
- event_data = container_of(work, struct etm_event_data, work); mask = &event_data->mask;
/* Free the sink buffers, if there are any */ @@ -159,6 +194,20 @@ static void free_event_data(struct work_struct *work) }
free_percpu(event_data->path); + del_event_from_list(event_data, ev_data); +} + +static void free_event_data(struct work_struct *work) +{ + struct etm_event_data *event_data; + + event_data = container_of(work, struct etm_event_data, work); + + mutex_lock(&cs_path_mutex); + if (event_data->snk_config) + _free_event_data(event_data, NULL); + mutex_unlock(&cs_path_mutex); + kfree(event_data); }
@@ -212,7 +261,10 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, cpumask_t *mask; struct coresight_device *sink; struct etm_event_data *event_data = NULL; + struct ev_data *ev_data;
+ if (atomic_read(cs_updating_cnt)) + return NULL; event_data = alloc_event_data(cpu); if (!event_data) return NULL; @@ -231,6 +283,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
mask = &event_data->mask;
+ mutex_lock(&cs_path_mutex); /* * Setup the path for each CPU in a trace session. We try to build * trace path for each CPU in the mask. If we don't find an ETM @@ -282,10 +335,19 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, if (!event_data->snk_config) goto err;
+ ev_data = kzalloc(sizeof(struct ev_data), GFP_KERNEL); + if (!ev_data) { + *etm_event_cpu_path_ptr(event_data, cpu) = NULL; + goto err; + } + ev_data->event_data = event_data; + list_add(&ev_data->link, &ev_list); + mutex_unlock(&cs_path_mutex); out: return event_data;
err: + mutex_unlock(&cs_path_mutex); etm_free_aux(event_data); event_data = NULL; goto out; @@ -299,7 +361,7 @@ static void etm_event_start(struct perf_event *event, int flags) struct coresight_device *sink, *csdev = per_cpu(csdev_src, cpu); struct list_head *path;
- if (!csdev) + if (!csdev || atomic_read(cs_updating_cnt)) goto fail;
/* @@ -310,6 +372,9 @@ static void etm_event_start(struct perf_event *event, int flags) if (!event_data) goto fail;
+ if (!event_data->snk_config) + goto fail; + path = etm_event_cpu_path(event_data, cpu); /* We need a sink, no need to continue without one */ sink = coresight_get_sink(path); @@ -391,7 +456,7 @@ static int etm_event_add(struct perf_event *event, int mode) int ret = 0; struct hw_perf_event *hwc = &event->hw;
- if (mode & PERF_EF_START) { + if (mode & PERF_EF_START && !atomic_read(cs_updating_cnt)) { etm_event_start(event, 0); if (hwc->state & PERF_HES_STOPPED) ret = -EINVAL; @@ -499,9 +564,14 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link) if (ret) return ret; per_cpu(csdev_src, cpu) = csdev; + per_cpu(csdev_src_removing, cpu) = false; } else { sysfs_remove_link(&pmu_dev->kobj, entry); - per_cpu(csdev_src, cpu) = NULL; + /* + * Set to NULL later when device is unregistered to avoid + * conflict with ongoing event. + */ + per_cpu(csdev_src_removing, cpu) = true; }
return 0; @@ -580,10 +650,79 @@ void etm_perf_del_symlink_sink(struct coresight_device *csdev) csdev->ea = NULL; }
+static void update_cs_cfg(void *ignored) +{ + /* + * Reschedule running events. + * Events will be stopped and coresight path will be disabled. + * Coresight path won't be enabled again until coresight update + * is done. + */ + perf_pmu_resched(&etm_pmu); +} + +static void update_cs_path(struct coresight_device *csdev) +{ + struct ev_data *ev_data = NULL; + struct ev_data *ev_data_next = NULL; + struct etm_event_data *event_data; + unsigned int cpu; + cpumask_t *mask; + bool ret = false; + + mutex_lock(&cs_path_mutex); + + list_for_each_entry_safe(ev_data, ev_data_next, &ev_list, link) { + event_data = ev_data->event_data; + if (!event_data->snk_config) + continue; + + mask = &event_data->mask; + + for_each_cpu(cpu, mask) { + struct list_head **ppath; + + ppath = etm_event_cpu_path_ptr(event_data, cpu); + if (!(IS_ERR_OR_NULL(*ppath))) { + ret = coresight_dev_on_path(*ppath, csdev); + if (ret) + break; + } + } + + if (ret) + _free_event_data(event_data, ev_data); + } + + mutex_unlock(&cs_path_mutex); + for_each_possible_cpu(cpu) { + if (per_cpu(csdev_src_removing, cpu)) { + per_cpu(csdev_src, cpu) = NULL; + per_cpu(csdev_src_removing, cpu) = false; + } + } +} + +void etm_perf_disable_with(struct coresight_device *csdev) +{ + atomic_inc(cs_updating_cnt); + get_online_cpus(); + on_each_cpu(update_cs_cfg, NULL, 1); + put_online_cpus(); + /* Free events which have trace path related to csdev */ + update_cs_path(csdev); +} + +void etm_perf_disable_done(void) +{ + atomic_dec(cs_updating_cnt); +} + int __init etm_perf_init(void) { int ret;
+ etm_pmu.module = THIS_MODULE; etm_pmu.capabilities = (PERF_PMU_CAP_EXCLUSIVE | PERF_PMU_CAP_ITRACE);
@@ -601,6 +740,11 @@ int __init etm_perf_init(void) etm_pmu.addr_filters_validate = etm_addr_filters_validate; etm_pmu.nr_addr_filters = ETM_ADDR_CMP_MAX;
+ cs_updating_cnt = kcalloc(1, sizeof(*cs_updating_cnt), GFP_KERNEL); + if (!cs_updating_cnt) + return -ENOMEM; + atomic_set(cs_updating_cnt, 0); + ret = perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1); if (ret == 0) etm_perf_up = true; @@ -610,5 +754,6 @@ int __init etm_perf_init(void)
void __exit etm_perf_exit(void) { + kfree(cs_updating_cnt); perf_pmu_unregister(&etm_pmu); } diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 3e4f2ad5e193..221831732cb1 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -61,6 +61,8 @@ struct etm_event_data { int etm_perf_symlink(struct coresight_device *csdev, bool link); int etm_perf_add_symlink_sink(struct coresight_device *csdev); void etm_perf_del_symlink_sink(struct coresight_device *csdev); +void etm_perf_disable_with(struct coresight_device *csdev); +void etm_perf_disable_done(void); static inline void *etm_perf_sink_config(struct perf_output_handle *handle) { struct etm_event_data *data = perf_get_aux(handle); diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 56d677473be4..f91fff8267be 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -151,8 +151,10 @@ struct coresight_device *coresight_get_sink(struct list_head *path); struct coresight_device *coresight_get_enabled_sink(bool reset); struct coresight_device *coresight_get_sink_by_id(u32 id); struct list_head *coresight_build_path(struct coresight_device *csdev, - struct coresight_device *sink); + struct coresight_device *sink); void coresight_release_path(struct list_head *path); +bool coresight_dev_on_path(struct list_head *path, + struct coresight_device *csdev);
#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X) extern int etm_readl_cp14(u32 off, unsigned int *val); diff --git a/kernel/events/core.c b/kernel/events/core.c index e296c5c59c6f..cce7a2b82a4b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2723,6 +2723,7 @@ void perf_pmu_resched(struct pmu *pmu) ctx_resched(cpuctx, task_ctx, EVENT_ALL|EVENT_CPU); perf_ctx_unlock(cpuctx, task_ctx); } +EXPORT_SYMBOL_GPL(perf_pmu_resched);
/* * Cross CPU call to install and enable a performance event