Re: Set DBGCLAIM when self-host debug is enabled

2021-01-07 Thread Tingwei Zhang
On Wed, Jan 06, 2021 at 08:23:56PM +0800, Mark Rutland wrote:
> On Wed, Jan 06, 2021 at 06:29:53PM +0800, ting...@codeaurora.org wrote:
> > Hi Will and Mark,
> 
> Hi Tingwei,
> 
> > In recent implementation of save/restore ARM debug registers in
> > EL2/EL3, we found it's necessary to know whether self-host debug is
> > enabled so EL2/EL3 can avoid saving/restoring debug registers but no
> > one is using debug.
> 
> In what situation are you considering? I assume you mean idle sequences
> using CPU_SUSPEND?
> 
> Generally our expectation for CPU_SUSPEND is:
> 
> * Where StateType==0, the debug state is preserved with all other
>   PE state.
> 
> * Where StateType==1 and the PE returns "warm" without having entered a
>   powerdown state, the debug state is preserved along with all other PE
>   state.
> 
> * Where StateType==1, and the PE returns "cold" after having entered a
>   powerdown state (i.e. we return via the entry point address), the
>   debug state is not preserved.
> 
> ... and I'm missing where you could avoid saving the state. What
> situation(s) did you have in mind?
> 
In StateType==1 case, EL2/EL3 can save debug registers before PE suspend
and restore them after PE resume. If EL2/EL3 doesn't know whether external
debugger or self-host debugger is using debug registers, it can save and
restore bindly everytime. However, if EL2/EL3 can get the information from
DBGCLAIM, it can only save/restore debug registers when debug is ongoing
which means DGBCLAIM[0] is set by external debugger or DGBCLAIM[1] is set
by self-host debugger.

> > In ARM PSCI, it has one option to set DBGCLAIM[1] to 1 to indicate
> > that debug is in use by a self-host debugger. Do you think it's
> > resonable to add this to Kernel?
> > 
> > For example, can we set DBGCLAIM[1] to 1 in enable_debug_monitors()
> > and clear it in disable_debug_monitors().
> 
> I was under the impression that this was solely for the benefit of an
> external debugger, and should have no functional impact on the PSCI
> implementation from the kernel's PoV, so as above I think we need a
> better description of the case you're trying to address.

If self-host debugger like gdb/kgdb is used for debug, Kernel can set
DBGCLAIM[1] to inform EL2/EL3.

Thanks,
Tingwei
> 
> Thanks,
> Mark.


Re: [PATCH v4 20/25] coresight: etm4x: Detect system instructions support

2020-11-24 Thread Tingwei Zhang
On Tue, Nov 24, 2020 at 07:38:55PM +0800, Suzuki K Poulose wrote:
> On 11/24/20 12:41 AM, Tingwei Zhang wrote:
> >On Mon, Nov 23, 2020 at 05:39:43PM +0800, Suzuki K Poulose wrote:
> >>On 11/23/20 7:58 AM, Tingwei Zhang wrote:
> >>>Hi Suzuki,
> >>>
> >>>On Fri, Nov 20, 2020 at 12:45:42AM +0800, Suzuki K Poulose wrote:
> >>>>ETM v4.4 onwards adds support for system instruction access
> >>>>to the ETM. Detect the support on an ETM and switch to using the
> >>>>mode when available.
> >>>>
> >>>>Cc: Mike Leach 
> >>>>Reviewed-by: Mathieu Poirier 
> >>>>Signed-off-by: Suzuki K Poulose 
> >>>>---
> >>>>  .../coresight/coresight-etm4x-core.c  | 39
> >>>>+++
> >>>>  1 file changed, 39 insertions(+)
> >>>>
> >>>>diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>>>b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>>>index 7ac0a185c146..5cbea9c27f58 100644
> >>>>--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>>>+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>>>@@ -684,6 +684,37 @@ static const struct coresight_ops etm4_cs_ops = {
> >>>>  .source_ops = _source_ops,
> >>>>  };
> >>>>
> >>>>+static inline bool cpu_supports_sysreg_trace(void)
> >>>>+{
> >>>>+ u64 dfr0 = read_sysreg_s(SYS_ID_AA64DFR0_EL1);
> >>>>+
> >>>>+ return ((dfr0 >> ID_AA64DFR0_TRACEVER_SHIFT) & 0xfUL) > 0;
> >>>>+}
> >>>>+
> >>>>+static bool etm4_init_sysreg_access(struct etmv4_drvdata *drvdata,
> >>>>+ struct csdev_access *csa)
> >>>>+{
> >>>>+ u32 devarch;
> >>>>+
> >>>>+ if (!cpu_supports_sysreg_trace())
> >>>>+ return false;
> >>>>+
> >>>>+ /*
> >>>>+  * ETMs implementing sysreg access must implement TRCDEVARCH.
> >>>>+  */
> >>>>+ devarch = read_etm4x_sysreg_const_offset(TRCDEVARCH);
> >>>>+ if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH)
> >>>
> >>>Is this driver suppose to work on ETM 5.0/ETE trace unit before ETE
> >>>driver
> >>>is ready?
> >>
> >>No, it is not supposed to work on an ETE without the ETE support. That
> >>check
> >>ensures that we only detect ETMv4x for now. The ETE driver support adds
> >>the
> >>ETE_ARCH as one of the supported ETMs. If you hack around it might still
> >>probe,
> >>but things could go terribly wrong if we access registers that are not
> >>available
> >>on ETE.
> >>
> >>Btw, are you able to test this series on an ETMv4.4+ system ?
> >>
> >I'm trying to test this series on an ETE. Look like it's not correct.
> >I'll apply ETE patch on top of this and test.
> >
> 
> Yes please ! Much appreciated. Do you have a TRBE as well ? Or are you
> using a legacy CoreSight topology ?
> 
I have TRBE as well.

> Kind regards
> Suzuki
> ___
> CoreSight mailing list
> coresi...@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/coresight


Re: [PATCH v4 20/25] coresight: etm4x: Detect system instructions support

2020-11-23 Thread Tingwei Zhang
On Mon, Nov 23, 2020 at 05:39:43PM +0800, Suzuki K Poulose wrote:
> On 11/23/20 7:58 AM, Tingwei Zhang wrote:
> >Hi Suzuki,
> >
> >On Fri, Nov 20, 2020 at 12:45:42AM +0800, Suzuki K Poulose wrote:
> >>ETM v4.4 onwards adds support for system instruction access
> >>to the ETM. Detect the support on an ETM and switch to using the
> >>mode when available.
> >>
> >>Cc: Mike Leach 
> >>Reviewed-by: Mathieu Poirier 
> >>Signed-off-by: Suzuki K Poulose 
> >>---
> >>  .../coresight/coresight-etm4x-core.c  | 39 +++
> >>  1 file changed, 39 insertions(+)
> >>
> >>diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>index 7ac0a185c146..5cbea9c27f58 100644
> >>--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>@@ -684,6 +684,37 @@ static const struct coresight_ops etm4_cs_ops = {
> >>.source_ops = _source_ops,
> >>  };
> >>
> >>+static inline bool cpu_supports_sysreg_trace(void)
> >>+{
> >>+   u64 dfr0 = read_sysreg_s(SYS_ID_AA64DFR0_EL1);
> >>+
> >>+   return ((dfr0 >> ID_AA64DFR0_TRACEVER_SHIFT) & 0xfUL) > 0;
> >>+}
> >>+
> >>+static bool etm4_init_sysreg_access(struct etmv4_drvdata *drvdata,
> >>+   struct csdev_access *csa)
> >>+{
> >>+   u32 devarch;
> >>+
> >>+   if (!cpu_supports_sysreg_trace())
> >>+   return false;
> >>+
> >>+   /*
> >>+* ETMs implementing sysreg access must implement TRCDEVARCH.
> >>+*/
> >>+   devarch = read_etm4x_sysreg_const_offset(TRCDEVARCH);
> >>+   if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH)
> >
> >Is this driver suppose to work on ETM 5.0/ETE trace unit before ETE driver
> >is ready?
> 
> No, it is not supposed to work on an ETE without the ETE support. That check
> ensures that we only detect ETMv4x for now. The ETE driver support adds the
> ETE_ARCH as one of the supported ETMs. If you hack around it might still
> probe,
> but things could go terribly wrong if we access registers that are not
> available
> on ETE.
> 
> Btw, are you able to test this series on an ETMv4.4+ system ?
> 
I'm trying to test this series on an ETE. Look like it's not correct.
I'll apply ETE patch on top of this and test.

> Kind regards
> Suzuki
> ___
> CoreSight mailing list
> coresi...@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/coresight


Re: [PATCH v4 20/25] coresight: etm4x: Detect system instructions support

2020-11-22 Thread Tingwei Zhang
Hi Suzuki,

On Fri, Nov 20, 2020 at 12:45:42AM +0800, Suzuki K Poulose wrote:
> ETM v4.4 onwards adds support for system instruction access
> to the ETM. Detect the support on an ETM and switch to using the
> mode when available.
> 
> Cc: Mike Leach 
> Reviewed-by: Mathieu Poirier 
> Signed-off-by: Suzuki K Poulose 
> ---
>  .../coresight/coresight-etm4x-core.c  | 39 +++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c 
> b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> index 7ac0a185c146..5cbea9c27f58 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -684,6 +684,37 @@ static const struct coresight_ops etm4_cs_ops = {
>   .source_ops = _source_ops,
>  };
> 
> +static inline bool cpu_supports_sysreg_trace(void)
> +{
> + u64 dfr0 = read_sysreg_s(SYS_ID_AA64DFR0_EL1);
> +
> + return ((dfr0 >> ID_AA64DFR0_TRACEVER_SHIFT) & 0xfUL) > 0;
> +}
> +
> +static bool etm4_init_sysreg_access(struct etmv4_drvdata *drvdata,
> + struct csdev_access *csa)
> +{
> + u32 devarch;
> +
> + if (!cpu_supports_sysreg_trace())
> + return false;
> +
> + /*
> +  * ETMs implementing sysreg access must implement TRCDEVARCH.
> +  */
> + devarch = read_etm4x_sysreg_const_offset(TRCDEVARCH);
> + if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH)

Is this driver suppose to work on ETM 5.0/ETE trace unit before ETE driver
is ready?

Thanks,
Tingwei

> + return false;
> + *csa = (struct csdev_access) {
> + .io_mem = false,
> + .read   = etm4x_sysreg_read,
> + .write  = etm4x_sysreg_write,
> + };
> +
> + drvdata->arch = etm_devarch_to_arch(devarch);
> + return true;
> +}
> +
>  static bool etm4_init_iomem_access(struct etmv4_drvdata *drvdata,
>  struct csdev_access *csa)
>  {
> @@ -714,9 +745,17 @@ static bool etm4_init_iomem_access(struct etmv4_drvdata 
> *drvdata,
>  static bool etm4_init_csdev_access(struct etmv4_drvdata *drvdata,
>  struct csdev_access *csa)
>  {
> + /*
> +  * Always choose the memory mapped io, if there is
> +  * a memory map to prevent sysreg access on broken
> +  * systems.
> +  */
>   if (drvdata->base)
>   return etm4_init_iomem_access(drvdata, csa);
> 
> + if (etm4_init_sysreg_access(drvdata, csa))
> + return true;
> +
>   return false;
>  }
> 
> -- 
> 2.24.1
> 
> ___
> CoreSight mailing list
> coresi...@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/coresight


Re: [RFC 07/11] coresight: sink: Add TRBE driver

2020-11-13 Thread Tingwei Zhang
Hi Anshuman,

On Tue, Nov 10, 2020 at 08:45:05PM +0800, Anshuman Khandual wrote:
> Trace Buffer Extension (TRBE) implements a trace buffer per CPU which is
> accessible via the system registers. The TRBE supports different addressing
> modes including CPU virtual address and buffer modes including the circular
> buffer mode. The TRBE buffer is addressed by a base pointer (TRBBASER_EL1),
> an write pointer (TRBPTR_EL1) and a limit pointer (TRBLIMITR_EL1). But the
> access to the trace buffer could be prohibited by a higher exception level
> (EL3 or EL2), indicated by TRBIDR_EL1.P. The TRBE can also generate a CPU
> private interrupt (PPI) on address translation errors and when the buffer
> is full. Overall implementation here is inspired from the Arm SPE driver.
> 
> Signed-off-by: Anshuman Khandual 
> ---
>  Documentation/trace/coresight/coresight-trbe.rst |  36 ++
>  arch/arm64/include/asm/sysreg.h  |   2 +
>  drivers/hwtracing/coresight/Kconfig  |  11 +
>  drivers/hwtracing/coresight/Makefile |   1 +
>  drivers/hwtracing/coresight/coresight-trbe.c | 766 
> +++
>  drivers/hwtracing/coresight/coresight-trbe.h | 525 
>  6 files changed, 1341 insertions(+)
>  create mode 100644 Documentation/trace/coresight/coresight-trbe.rst
>  create mode 100644 drivers/hwtracing/coresight/coresight-trbe.c
>  create mode 100644 drivers/hwtracing/coresight/coresight-trbe.h
> 
> diff --git a/Documentation/trace/coresight/coresight-trbe.rst 
> b/Documentation/trace/coresight/coresight-trbe.rst
> new file mode 100644
> index 000..4320a8b
> --- /dev/null
> +++ b/Documentation/trace/coresight/coresight-trbe.rst
> @@ -0,0 +1,36 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +==
> +Trace Buffer Extension (TRBE).
> +==
> +
> +:Author:   Anshuman Khandual 
> +:Date: November 2020
> +
> +Hardware Description
> +
> +
> +Trace Buffer Extension (TRBE) is a percpu hardware which captures in system
> +memory, CPU traces generated from a corresponding percpu tracing unit. This
> +gets plugged in as a coresight sink device because the corresponding trace
> +genarators (ETE), are plugged in as source device.
> +
> +Sysfs files and directories
> +---
> +
> +The TRBE devices appear on the existing coresight bus alongside the other
> +coresight devices::
> +
> + >$ ls /sys/bus/coresight/devices
> + trbe0  trbe1  trbe2 trbe3
> +
> +The ``trbe`` named TRBEs are associated with a CPU.::
> +
> + >$ ls /sys/bus/coresight/devices/trbe0/
> + irq align dbm
> +
> +*Key file items are:-*
> +   * ``irq``: TRBE maintenance interrupt number
> +   * ``align``: TRBE write pointer alignment
> +   * ``dbm``: TRBE updates memory with access and dirty flags
> +
> diff --git a/arch/arm64/include/asm/sysreg.h 
> b/arch/arm64/include/asm/sysreg.h
> index 14cb156..61136f6 100644
> --- a/arch/arm64/include/asm/sysreg.h
> +++ b/arch/arm64/include/asm/sysreg.h
> @@ -97,6 +97,7 @@
>  #define SET_PSTATE_UAO(x)__emit_inst(0xd500401f | PSTATE_UAO | 
> ((!!x) << 
> PSTATE_Imm_shift))
>  #define SET_PSTATE_SSBS(x)   __emit_inst(0xd500401f | PSTATE_SSBS | 
> ((!!x) 
> << PSTATE_Imm_shift))
>  #define SET_PSTATE_TCO(x)__emit_inst(0xd500401f | PSTATE_TCO | 
> ((!!x) << 
> PSTATE_Imm_shift))
> +#define TSB_CSYNC__emit_inst(0xd503225f)
> 
>  #define __SYS_BARRIER_INSN(CRm, op2, Rt) \
>   __emit_inst(0xd500 | sys_insn(0, 3, 3, (CRm), (op2)) | ((Rt) & 
> 0x1f))
> @@ -865,6 +866,7 @@
>  #define ID_AA64MMFR2_CNP_SHIFT   0
> 
>  /* id_aa64dfr0 */
> +#define ID_AA64DFR0_TRBE_SHIFT   44
>  #define ID_AA64DFR0_TRACE_FILT_SHIFT 40
>  #define ID_AA64DFR0_DOUBLELOCK_SHIFT 36
>  #define ID_AA64DFR0_PMSVER_SHIFT 32
> diff --git a/drivers/hwtracing/coresight/Kconfig 
> b/drivers/hwtracing/coresight/Kconfig
> index c119824..0f5e101 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -156,6 +156,17 @@ config CORESIGHT_CTI
> To compile this driver as a module, choose M here: the
> module will be called coresight-cti.
> 
> +config CORESIGHT_TRBE
> + bool "Trace Buffer Extension (TRBE) driver"

Can you consider to support TRBE as loadable module since all coresight
drivers support loadable module now.

Thanks
Tingwei

> + depends on ARM64
> + help
> +   This driver provides support for percpu Trace Buffer Extension (TRBE).
> +   TRBE always needs to be used along with it's corresponding percpu ETE
> +   component. ETE generates trace data which is then captured with TRBE.
> +   Unlike traditional sink devices, TRBE is a CPU feature accessible via
> +   system registers. But it's explicit dependency with trace unit (ETE)
> +   requires it to be plugged in as a coresight sink device.
> +
>  config 

Re: [RFC 06/11] coresight: ete: Detect ETE as one of the supported ETMs

2020-11-13 Thread Tingwei Zhang
Hi Anshuman,

On Tue, Nov 10, 2020 at 08:45:04PM +0800, Anshuman Khandual wrote:
> From: Suzuki K Poulose 
> 
> Add ETE as one of the supported device types we support
> with ETM4x driver. The devices are named following the
> existing convention as ete.
> 
> ETE mandates that the trace resource status register is programmed
> before the tracing is turned on. For the moment simply write to
> it indicating TraceActive.
> 
> Signed-off-by: Suzuki K Poulose 
> Signed-off-by: Anshuman Khandual 
> ---
>  .../devicetree/bindings/arm/coresight.txt  |  3 ++
>  drivers/hwtracing/coresight/coresight-etm4x-core.c | 55 
> +-
>  drivers/hwtracing/coresight/coresight-etm4x.h  |  7 +++
>  3 files changed, 52 insertions(+), 13 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/arm/coresight.txt 
> b/Documentation/devicetree/bindings/arm/coresight.txt
> index bff96a5..784cc1b 100644
> --- a/Documentation/devicetree/bindings/arm/coresight.txt
> +++ b/Documentation/devicetree/bindings/arm/coresight.txt
> @@ -40,6 +40,9 @@ its hardware characteristcs.
>   - Embedded Trace Macrocell with system register access only.
>   "arm,coresight-etm-sysreg";
> 
> + - Embedded Trace Extensions.
> + "arm,ete"
> +
>   - Coresight programmable Replicator :
>   "arm,coresight-dynamic-replicator", "arm,primecell";
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c 
> b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> index 15b6e94..0fea349 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -331,6 +331,13 @@ static int etm4_enable_hw(struct etmv4_drvdata 
> *drvdata)
>   etm4x_relaxed_write32(csa, trcpdcr | TRCPDCR_PU, TRCPDCR);
>   }
> 
> + /*
> +  * ETE mandates that the TRCRSR is written to before
> +  * enabling it.
> +  */
> + if (drvdata->arch >= ETM_ARCH_ETE)
> + etm4x_relaxed_write32(csa, TRCRSR_TA, TRCRSR);
> +
>   /* Enable the trace unit */
>   etm4x_relaxed_write32(csa, 1, TRCPRGCTLR);
> 
> @@ -763,13 +770,24 @@ static bool etm_init_sysreg_access(struct 
> etmv4_drvdata *drvdata,
>* ETMs implementing sysreg access must implement TRCDEVARCH.
>*/
>   devarch = read_etm4x_sysreg_const_offset(TRCDEVARCH);
> - if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH)
> + switch (devarch & ETM_DEVARCH_ID_MASK) {
> + case ETM_DEVARCH_ETMv4x_ARCH:
> + *csa = (struct csdev_access) {
> + .io_mem = false,
> + .read   = etm4x_sysreg_read,
> + .write  = etm4x_sysreg_write,
> + };
> + break;
> + case ETM_DEVARCH_ETE_ARCH:
> + *csa = (struct csdev_access) {
> + .io_mem = false,
> + .read   = ete_sysreg_read,
> + .write  = ete_sysreg_write,
> + };
> + break;
> + default:
>   return false;
> - *csa = (struct csdev_access) {
> - .io_mem = false,
> - .read   = etm4x_sysreg_read,
> - .write  = etm4x_sysreg_write,
> - };
> + }
> 
>   drvdata->arch = etm_devarch_to_arch(devarch);
>   return true;
> @@ -1698,6 +1716,8 @@ static int etm4_probe(struct device *dev, void __iomem 
> *base)
>   struct etmv4_drvdata *drvdata;
>   struct coresight_desc desc = { 0 };
>   struct etm_init_arg init_arg = { 0 };
> + u8 major, minor;
> + char *type_name;
> 
>   drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
>   if (!drvdata)
> @@ -1724,10 +1744,6 @@ static int etm4_probe(struct device *dev, void 
> __iomem *base)
>   if (drvdata->cpu < 0)
>   return drvdata->cpu;
> 
> - desc.name = devm_kasprintf(dev, GFP_KERNEL, "etm%d", drvdata->cpu);
> - if (!desc.name)
> - return -ENOMEM;
> -
>   init_arg.drvdata = drvdata;
>   init_arg.csa = 
> 
> @@ -1742,6 +1758,19 @@ static int etm4_probe(struct device *dev, void 
> __iomem *base)
>   if (!desc.access.io_mem ||
>   fwnode_property_present(dev_fwnode(dev), "qcom,skip-power-up"))
>   drvdata->skip_power_up = true;
> + major = ETM_ARCH_MAJOR_VERSION(drvdata->arch);
> + minor = ETM_ARCH_MINOR_VERSION(drvdata->arch);
> + if (drvdata->arch >= ETM_ARCH_ETE) {
> + type_name = "ete";
> + major -= 4;
> + } else {
> + type_name = "etm";
> + }
> +
When trace unit supports ETE, could it be still compatible with ETMv4.4?
Can use selectively use it as ETM instead of ETE?

Thanks,
Tingwei

> + desc.name = devm_kasprintf(dev, GFP_KERNEL,
> +"%s%d", type_name, drvdata->cpu);
> + if (!desc.name)
> + return -ENOMEM;
> 
>   

Re: [RFC 00/11] arm64: coresight: Enable ETE and TRBE

2020-11-13 Thread Tingwei Zhang
Hi Anshuman,

On Tue, Nov 10, 2020 at 08:44:58PM +0800, Anshuman Khandual wrote:
> This series enables future IP trace features Embedded Trace Extension (ETE)
> and Trace Buffer Extension (TRBE). This series depends on the ETM system
> register instruction support series [0] and the v8.4 Self hosted tracing
> support series (Jonathan Zhou) [1]. The tree is available here [2] for
> quick access.
> 
> ETE is the PE (CPU) trace unit for CPUs, implementing future architecture
> extensions. ETE overlaps with the ETMv4 architecture, with additions to
> support the newer architecture features and some restrictions on the
> supported features w.r.t ETMv4. The ETE support is added by extending the
> ETMv4 driver to recognise the ETE and handle the features as exposed by the
> TRCIDRx registers. ETE only supports system instructions access from the
> host CPU. The ETE could be integrated with a TRBE (see below), or with the
> legacy CoreSight trace bus (e.g, ETRs). Thus the ETE follows same firmware
> description as the ETMs and requires a node per instance.
> 
> Trace Buffer Extensions (TRBE) implements a per CPU trace buffer, which is
> accessible via the system registers and can be combined with the ETE to
> provide a 1x1 configuration of source & sink. TRBE is being represented
> here as a CoreSight sink. Primary reason is that the ETE source could work
> with other traditional CoreSight sink devices. As TRBE captures the trace
> data which is produced by ETE, it cannot work alone.
> 
> TRBE representation here have some distinct deviations from a traditional
> CoreSight sink device. Coresight path between ETE and TRBE are not built
> during boot looking at respective DT or ACPI entries. Instead TRBE gets
> checked on each available CPU, when found gets connected with respective
> ETE source device on the same CPU, after altering its outward connections.
> ETE TRBE path connection lasts only till the CPU is online. But ETE-TRBE
> coupling/decoupling method implemented here is not optimal and would be
> reworked later on.

Only perf mode is supported in TRBE in current path. Will you consider
support sysfs mode as well in following patch sets?

Thanks,
Tingwei

> 
> Unlike traditional sinks, TRBE can generate interrupts to signal including
> many other things, buffer got filled. The interrupt is a PPI and should be
> communicated from the platform. DT or ACPI entry representing TRBE should
> have the PPI number for a given platform. During perf session, the TRBE IRQ
> handler should capture trace for perf auxiliary buffer before restarting it
> back. System registers being used here to configure ETE and TRBE could be
> referred in the link below.
> 
> https://developer.arm.com/docs/ddi0601/g/aarch64-system-registers.
> 
> This adds another change where CoreSight sink device needs to be disabled
> before capturing the trace data for perf in order to avoid race condition
> with another simultaneous TRBE IRQ handling. This might cause problem with
> traditional sink devices which can be operated in both sysfs and perf mode.
> This needs to be addressed correctly. One option would be to move the
> update_buffer callback into the respective sink devices. e.g, disable().
> 
> This series is primarily looking from some early feed back both on proposed
> design and its implementation. It acknowledges, that it might be incomplete
> and will have scopes for improvement.
> 
> Things todo:
> - Improve ETE-TRBE coupling and decoupling method
> - Improve TRBE IRQ handling for all possible corner cases
> - Implement sysfs based trace sessions
> 
> [0] 
> https://lore.kernel.org/linux-arm-kernel/20201028220945.3826358-1-suzuki.poul...@arm.com/
> [1] 
> https://lore.kernel.org/linux-arm-kernel/1600396210-54196-1-git-send-email-jonathan.zhou...@huawei.com/
> [2] 
> https://gitlab.arm.com/linux-arm/linux-skp/-/tree/coresight/etm/v8.4-self-hosted
> 
> Anshuman Khandual (6):
>   arm64: Add TRBE definitions
>   coresight: sink: Add TRBE driver
>   coresight: etm-perf: Truncate the perf record if handle has no space
>   coresight: etm-perf: Disable the path before capturing the trace data
>   coresgith: etm-perf: Connect TRBE sink with ETE source
>   dts: bindings: Document device tree binding for Arm TRBE
> 
> Suzuki K Poulose (5):
>   coresight: etm-perf: Allow an event to use different sinks
>   coresight: Do not scan for graph if none is present
>   coresight: etm4x: Add support for PE OS lock
>   coresight: ete: Add support for sysreg support
>   coresight: ete: Detect ETE as one of the supported ETMs
> 
>  .../devicetree/bindings/arm/coresight.txt  |   3 +
>  Documentation/devicetree/bindings/arm/trbe.txt |  20 +
>  Documentation/trace/coresight/coresight-trbe.rst   |  36 +
>  arch/arm64/include/asm/sysreg.h|  51 ++
>  drivers/hwtracing/coresight/Kconfig|  11 +
>  drivers/hwtracing/coresight/Makefile   |   1 +
>  drivers/hwtracing/coresight/coresight-etm-perf.c   |  85 

[PATCH v4 3/6] tracing: add trace_export support for event trace

2020-09-25 Thread Tingwei Zhang
Only function traces can be exported to other destinations currently.
This patch exports event trace as well. Move trace export related
function to the beginning of file so other trace can call
trace_process_export() to export.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
Reviewed-by: Alexander Shishkin 
---
 include/linux/trace.h |   1 +
 kernel/trace/trace.c  | 259 ++
 2 files changed, 135 insertions(+), 125 deletions(-)

diff --git a/include/linux/trace.h b/include/linux/trace.h
index c115a5d2269f..86033d214972 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -5,6 +5,7 @@
 #ifdef CONFIG_TRACING
 
 #define TRACE_EXPORT_FUNCTION  BIT(0)
+#define TRACE_EXPORT_EVENT BIT(1)
 
 /*
  * The trace export - an export of Ftrace output. The trace_export
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 3ca121ad8728..a40ee413123c 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -251,6 +251,138 @@ unsigned long long ns2usecs(u64 nsec)
return nsec;
 }
 
+static void
+trace_process_export(struct trace_export *export,
+  struct ring_buffer_event *event, int flag)
+{
+   struct trace_entry *entry;
+   unsigned int size = 0;
+
+   if (export->flags & flag) {
+   entry = ring_buffer_event_data(event);
+   size = ring_buffer_event_length(event);
+   export->write(export, entry, size);
+   }
+}
+
+static DEFINE_MUTEX(ftrace_export_lock);
+
+static struct trace_export __rcu *ftrace_exports_list __read_mostly;
+
+static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
+static DEFINE_STATIC_KEY_FALSE(trace_event_exports_enabled);
+
+static inline void ftrace_exports_enable(struct trace_export *export)
+{
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_inc(_function_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_EVENT)
+   static_branch_inc(_event_exports_enabled);
+}
+
+static inline void ftrace_exports_disable(struct trace_export *export)
+{
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_dec(_function_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_EVENT)
+   static_branch_dec(_event_exports_enabled);
+}
+
+static void ftrace_exports(struct ring_buffer_event *event, int flag)
+{
+   struct trace_export *export;
+
+   preempt_disable_notrace();
+
+   export = rcu_dereference_raw_check(ftrace_exports_list);
+   while (export) {
+   trace_process_export(export, event, flag);
+   export = rcu_dereference_raw_check(export->next);
+   }
+
+   preempt_enable_notrace();
+}
+
+static inline void
+add_trace_export(struct trace_export **list, struct trace_export *export)
+{
+   rcu_assign_pointer(export->next, *list);
+   /*
+* We are entering export into the list but another
+* CPU might be walking that list. We need to make sure
+* the export->next pointer is valid before another CPU sees
+* the export pointer included into the list.
+*/
+   rcu_assign_pointer(*list, export);
+}
+
+static inline int
+rm_trace_export(struct trace_export **list, struct trace_export *export)
+{
+   struct trace_export **p;
+
+   for (p = list; *p != NULL; p = &(*p)->next)
+   if (*p == export)
+   break;
+
+   if (*p != export)
+   return -1;
+
+   rcu_assign_pointer(*p, (*p)->next);
+
+   return 0;
+}
+
+static inline void
+add_ftrace_export(struct trace_export **list, struct trace_export *export)
+{
+   ftrace_exports_enable(export);
+
+   add_trace_export(list, export);
+}
+
+static inline int
+rm_ftrace_export(struct trace_export **list, struct trace_export *export)
+{
+   int ret;
+
+   ret = rm_trace_export(list, export);
+   ftrace_exports_disable(export);
+
+   return ret;
+}
+
+int register_ftrace_export(struct trace_export *export)
+{
+   if (WARN_ON_ONCE(!export->write))
+   return -1;
+
+   mutex_lock(_export_lock);
+
+   add_ftrace_export(_exports_list, export);
+
+   mutex_unlock(_export_lock);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(register_ftrace_export);
+
+int unregister_ftrace_export(struct trace_export *export)
+{
+   int ret;
+
+   mutex_lock(_export_lock);
+
+   ret = rm_ftrace_export(_exports_list, export);
+
+   mutex_unlock(_export_lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(unregister_ftrace_export);
+
 /* trace_flags holds trace_options default values */
 #define TRACE_DEFAULT_FLAGS\
(FUNCTION_DEFAULT_FLAGS |   \
@@ -2699,6 +2831,8 @@ void trace_event_buffer_commit(struct trace_event_buffer 
*fbuffer)
if (static_key_f

[PATCH v4 1/6] stm class: ftrace: change dependency to TRACING

2020-09-25 Thread Tingwei Zhang
We will support copying event trace to STM. Change
STM_SOURCE_FTRACE to depend on TRACING since we will
support multiple tracers.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
Reviewed-by: Alexander Shishkin 
---
 drivers/hwtracing/stm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/stm/Kconfig b/drivers/hwtracing/stm/Kconfig
index d0e92a8a045c..aad594fe79cc 100644
--- a/drivers/hwtracing/stm/Kconfig
+++ b/drivers/hwtracing/stm/Kconfig
@@ -71,7 +71,7 @@ config STM_SOURCE_HEARTBEAT
 
 config STM_SOURCE_FTRACE
tristate "Copy the output from kernel Ftrace to STM engine"
-   depends on FUNCTION_TRACER
+   depends on TRACING
help
  This option can be used to copy the output from kernel Ftrace
  to STM engine. Enabling this option will introduce a slight
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v4 5/6] stm class: ftrace: enable supported trace export flag

2020-09-25 Thread Tingwei Zhang
Set flags for trace_export. Export function trace, event trace
and trace marker to stm.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
Reviewed-by: Alexander Shishkin 
---
 drivers/hwtracing/stm/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwtracing/stm/ftrace.c b/drivers/hwtracing/stm/ftrace.c
index ce868e095410..c694a6e692d1 100644
--- a/drivers/hwtracing/stm/ftrace.c
+++ b/drivers/hwtracing/stm/ftrace.c
@@ -46,6 +46,8 @@ static int stm_ftrace_link(struct stm_source_data *data)
struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
 
sf->ftrace.write = stm_ftrace_write;
+   sf->ftrace.flags = TRACE_EXPORT_FUNCTION | TRACE_EXPORT_EVENT
+   | TRACE_EXPORT_MARKER;
 
return register_ftrace_export(>ftrace);
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v4 6/6] stm class: ftrace: use different channel accroding to CPU

2020-09-25 Thread Tingwei Zhang
To avoid mixup of packets from differnt ftrace packets simultaneously,
use different channel for packets from different CPU.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 drivers/hwtracing/stm/ftrace.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/stm/ftrace.c b/drivers/hwtracing/stm/ftrace.c
index c694a6e692d1..3bb606dfa634 100644
--- a/drivers/hwtracing/stm/ftrace.c
+++ b/drivers/hwtracing/stm/ftrace.c
@@ -37,8 +37,10 @@ static void notrace
 stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int 
len)
 {
struct stm_ftrace *stm = container_of(export, struct stm_ftrace, 
ftrace);
+   /* This is called from trace system with preemption disabled */
+   unsigned int cpu = smp_processor_id();
 
-   stm_source_write(>data, STM_FTRACE_CHAN, buf, len);
+   stm_source_write(>data, STM_FTRACE_CHAN + cpu, buf, len);
 }
 
 static int stm_ftrace_link(struct stm_source_data *data)
@@ -63,6 +65,7 @@ static int __init stm_ftrace_init(void)
 {
int ret;
 
+   stm_ftrace.data.nr_chans = roundup_pow_of_two(num_possible_cpus());
ret = stm_source_register_device(NULL, _ftrace.data);
if (ret)
pr_err("Failed to register stm_source - ftrace.\n");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v4 0/6] tracing: export event trace and trace_marker

2020-09-25 Thread Tingwei Zhang
Ftrace has ability to export trace packets to other destination.
Currently, only function trace can be exported. This series extends the
support to event trace and trace_maker. STM is one possible destination to
export ftrace. Use separate channel for each CPU to avoid mixing up packets
from different CPUs together.

Change from v3:
Round up number of channels to power of 2. (Alex)

Change from v2:
Change flag definition to BIT(). (Steven)
Add comment in stm_ftrace_write() to clarify it's safe to use 
smp_processor_id() here since preempt is disabled. (Steven) 

Change from v1:
All changes are suggested by Steven Rostedt.
User separate flag to control function trace, event trace and trace mark.
Allocate channels according to num_possible_cpu() dynamically.
Move ftrace_exports routines up so all ftrace can use them.

Tingwei Zhang (6):
  stm class: ftrace: change dependency to TRACING
  tracing: add flag to control different traces
  tracing: add trace_export support for event trace
  tracing: add trace_export support for trace_marker
  stm class: ftrace: enable supported trace export flag
  stm class: ftrace: use different channel accroding to CPU

 drivers/hwtracing/stm/Kconfig  |   2 +-
 drivers/hwtracing/stm/ftrace.c |   7 +-
 include/linux/trace.h  |   7 +
 kernel/trace/trace.c   | 270 ++---
 4 files changed, 159 insertions(+), 127 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v4 2/6] tracing: add flag to control different traces

2020-09-25 Thread Tingwei Zhang
More traces like event trace or trace marker will be supported.
Add flag for difference traces, so that they can be controlled
separately. Move current function trace to it's own flag
instead of global ftrace enable flag.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
Reviewed-by: Alexander Shishkin 
---
 include/linux/trace.h |  5 +
 kernel/trace/trace.c  | 36 +++-
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/include/linux/trace.h b/include/linux/trace.h
index 36d255d66f88..c115a5d2269f 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -3,6 +3,9 @@
 #define _LINUX_TRACE_H
 
 #ifdef CONFIG_TRACING
+
+#define TRACE_EXPORT_FUNCTION  BIT(0)
+
 /*
  * The trace export - an export of Ftrace output. The trace_export
  * can process traces and export them to a registered destination as
@@ -15,10 +18,12 @@
  * next- pointer to the next trace_export
  * write   - copy traces which have been delt with ->commit() to
  *   the destination
+ * flags   - which ftrace to be exported
  */
 struct trace_export {
struct trace_export __rcu   *next;
void (*write)(struct trace_export *, const void *, unsigned int);
+   int flags;
 };
 
 int register_ftrace_export(struct trace_export *export);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f40d850ebabc..3ca121ad8728 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2744,33 +2744,37 @@ trace_buffer_unlock_commit_nostack(struct trace_buffer 
*buffer,
 
 static void
 trace_process_export(struct trace_export *export,
-  struct ring_buffer_event *event)
+  struct ring_buffer_event *event, int flag)
 {
struct trace_entry *entry;
unsigned int size = 0;
 
-   entry = ring_buffer_event_data(event);
-   size = ring_buffer_event_length(event);
-   export->write(export, entry, size);
+   if (export->flags & flag) {
+   entry = ring_buffer_event_data(event);
+   size = ring_buffer_event_length(event);
+   export->write(export, entry, size);
+   }
 }
 
 static DEFINE_MUTEX(ftrace_export_lock);
 
 static struct trace_export __rcu *ftrace_exports_list __read_mostly;
 
-static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);
+static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
 
-static inline void ftrace_exports_enable(void)
+static inline void ftrace_exports_enable(struct trace_export *export)
 {
-   static_branch_enable(_exports_enabled);
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_inc(_function_exports_enabled);
 }
 
-static inline void ftrace_exports_disable(void)
+static inline void ftrace_exports_disable(struct trace_export *export)
 {
-   static_branch_disable(_exports_enabled);
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_dec(_function_exports_enabled);
 }
 
-static void ftrace_exports(struct ring_buffer_event *event)
+static void ftrace_exports(struct ring_buffer_event *event, int flag)
 {
struct trace_export *export;
 
@@ -2778,7 +2782,7 @@ static void ftrace_exports(struct ring_buffer_event 
*event)
 
export = rcu_dereference_raw_check(ftrace_exports_list);
while (export) {
-   trace_process_export(export, event);
+   trace_process_export(export, event, flag);
export = rcu_dereference_raw_check(export->next);
}
 
@@ -2818,8 +2822,7 @@ rm_trace_export(struct trace_export **list, struct 
trace_export *export)
 static inline void
 add_ftrace_export(struct trace_export **list, struct trace_export *export)
 {
-   if (*list == NULL)
-   ftrace_exports_enable();
+   ftrace_exports_enable(export);
 
add_trace_export(list, export);
 }
@@ -2830,8 +2833,7 @@ rm_ftrace_export(struct trace_export **list, struct 
trace_export *export)
int ret;
 
ret = rm_trace_export(list, export);
-   if (*list == NULL)
-   ftrace_exports_disable();
+   ftrace_exports_disable(export);
 
return ret;
 }
@@ -2884,8 +2886,8 @@ trace_function(struct trace_array *tr,
entry->parent_ip= parent_ip;
 
if (!call_filter_check_discard(call, entry, buffer, event)) {
-   if (static_branch_unlikely(_exports_enabled))
-   ftrace_exports(event);
+   if (static_branch_unlikely(_function_exports_enabled))
+   ftrace_exports(event, TRACE_EXPORT_FUNCTION);
__buffer_unlock_commit(buffer, event);
}
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v4 4/6] tracing: add trace_export support for trace_marker

2020-09-25 Thread Tingwei Zhang
Add the support to route trace_marker buffer to other destination
via trace_export.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
Reviewed-by: Alexander Shishkin 
---
 include/linux/trace.h | 1 +
 kernel/trace/trace.c  | 9 +
 2 files changed, 10 insertions(+)

diff --git a/include/linux/trace.h b/include/linux/trace.h
index 86033d214972..886a4ffd9d45 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -6,6 +6,7 @@
 
 #define TRACE_EXPORT_FUNCTION  BIT(0)
 #define TRACE_EXPORT_EVENT BIT(1)
+#define TRACE_EXPORT_MARKERBIT(2)
 
 /*
  * The trace export - an export of Ftrace output. The trace_export
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a40ee413123c..6048fba2f590 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -271,6 +271,7 @@ static struct trace_export __rcu *ftrace_exports_list 
__read_mostly;
 
 static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
 static DEFINE_STATIC_KEY_FALSE(trace_event_exports_enabled);
+static DEFINE_STATIC_KEY_FALSE(trace_marker_exports_enabled);
 
 static inline void ftrace_exports_enable(struct trace_export *export)
 {
@@ -279,6 +280,9 @@ static inline void ftrace_exports_enable(struct 
trace_export *export)
 
if (export->flags & TRACE_EXPORT_EVENT)
static_branch_inc(_event_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_MARKER)
+   static_branch_inc(_marker_exports_enabled);
 }
 
 static inline void ftrace_exports_disable(struct trace_export *export)
@@ -288,6 +292,9 @@ static inline void ftrace_exports_disable(struct 
trace_export *export)
 
if (export->flags & TRACE_EXPORT_EVENT)
static_branch_dec(_event_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_MARKER)
+   static_branch_dec(_marker_exports_enabled);
 }
 
 static void ftrace_exports(struct ring_buffer_event *event, int flag)
@@ -6687,6 +6694,8 @@ tracing_mark_write(struct file *filp, const char __user 
*ubuf,
} else
entry->buf[cnt] = '\0';
 
+   if (static_branch_unlikely(_marker_exports_enabled))
+   ftrace_exports(event, TRACE_EXPORT_MARKER);
__buffer_unlock_commit(buffer, event);
 
if (tt)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH v3 6/6] stm class: ftrace: use different channel accroding to CPU

2020-09-22 Thread Tingwei Zhang
On Fri, Sep 18, 2020 at 08:45:52PM +0800, Alexander Shishkin wrote:
> Tingwei Zhang  writes:
> 
> > @@ -63,6 +65,7 @@ static int __init stm_ftrace_init(void)
> >  {
> > int ret;
> >  
> > +   stm_ftrace.data.nr_chans = num_possible_cpus();
> 
> Not a problem with this patch necesarily, but this made me realize that
> .nr_chans may be larger than:
> 
>  (1) what the policy permits,
>  (2) what the stm device can handle.
> 
> While (1) the user can fix in the policy, they won't be able to fix (2),
> in which case they won't be able to use stm_ftrace at all. I'm thinking
> if a link-time callback would be good enough.
>

Hi Alex,

I'm not sure if I understand this correct. If the nr_chans requested by
stm_ftrace is larger than policy permits or stm device can handle,
stm_assign_first_policy() returns with error so stm_source_link_add()
will fail. User would notice that when link happens.  There's not much
we can do if resource is not enough.
 
> Another thing is that .nr_chans needs to be a power of 2 at the moment.
> 
I'll change to below.
stm_ftrace.data.nr_chans = roundup_pow_of_two(num_possible_cpus());
> Regards,
> --
> Alex
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


Re: [PATCH v11 09/24] coresight: etm3x: allow etm3x to be built as a module

2020-09-22 Thread Tingwei Zhang
On Wed, Sep 23, 2020 at 05:42:08AM +0800, Mathieu Poirier wrote:
> On Tue, Sep 15, 2020 at 12:09:18PM -0600, Mathieu Poirier wrote:
> > On Tue, Sep 15, 2020 at 06:41:01PM +0800, Tingwei Zhang wrote:
> > > From: Kim Phillips 
> > > 
> > > 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
> > > - delay advertising the per-cpu etmdrvdata
> > > - protect etmdrvdata[] by modifying it on relevant CPU
> > > 
> > > Cc: Mathieu Poirier 
> > > Cc: Leo Yan 
> > > Cc: Alexander Shishkin 
> > > Cc: Randy Dunlap 
> > > Cc: Suzuki K Poulose 
> > > Cc: Greg Kroah-Hartman 
> > > Cc: Russell King 
> > > Signed-off-by: Kim Phillips 
> > > Signed-off-by: Tingwei Zhang 
> > > Reviewed-by: Mike Leach 
> > > ---
> > >  drivers/hwtracing/coresight/Kconfig   |   5 +-
> > >  drivers/hwtracing/coresight/Makefile  |   5 +-
> > >  ...resight-etm3x.c => coresight-etm3x-core.c} | 148
> ++
> > >  3 files changed, 122 insertions(+), 36 deletions(-)
> > >  rename drivers/hwtracing/coresight/{coresight-etm3x.c =>
> coresight-etm3x-core.c} (90%)
> > >
> 
> I got tired of waiting for a V12 and Mike has based his work on complex
> configuration on your patchset.  So I did the corrections and applied
> this set to my tree.  With a little luck Greg won't mind the late
> submission and
> things will work out fine. 
> 
> You owe me a beer.  If Greg accepts my pull request, you owe him one too.
> 
> Mathieu
>  

Really appreciated it, Mathieu.  I definitely owe you and Greg one.

I was waiting for other comments.

Thanks
Tingwei

> > > 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 19497d1d92bf..86b4648844b4 100644
> > > --- a/drivers/hwtracing/coresight/Makefile
> > > +++ b/drivers/hwtracing/coresight/Makefile
> > > @@ -11,8 +11,9 @@ 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 \
> > > - coresight-etm3x-sysfs.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_STM) += coresight-stm.o
> > > diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c
> b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > > similarity index 90%
> > > rename from drivers/hwtracing/coresight/coresight-etm3x.c
> > > rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> > 

[PATCH v11 10/24] coresight: etm4x: allow etm4x to be built as a module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

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
- delay advertising the per-cpu etmdrvdata
- protect etmdrvdata[] by modifying it on relevant CPU

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Suggested-by: Suzuki K Poulose 
Reviewed-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 drivers/hwtracing/coresight/Makefile  |  4 +-
 ...resight-etm4x.c => coresight-etm4x-core.c} | 84 ++-
 3 files changed, 69 insertions(+), 24 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm4x.c => 
coresight-etm4x-core.c} (96%)

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 86b4648844b4..3f2b057443fb 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -14,8 +14,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 96%
rename from drivers/hwtracing/coresight/coresight-etm4x.c
rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
index b29ad4f7fac2..33eb2b1508c6 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -1441,7 +1441,7 @@ static int __init etm4_pm_setup(void)
return ret;
 }
 
-static void __init etm4_pm_clear(void)
+static void etm4_pm_clear(void)
 {
cpu_pm_unregister_notifier(_cpu_pm_nb);
cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
@@ -1498,25 +1498,20 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
if (!desc.name)
return -ENOMEM;
 
-   etmdrvdata[drvdata->cpu] = drvdata;
-
if (smp_call_function_single(drvdata->cpu,
etm4_init_arch_data,  drvdata, 1))
dev_err(dev, "ETM arch init failed\n");
 
-   if (etm4_arch_supported(drvdata->arch) == false) {
-   ret = -EINVAL;
-   goto err_arch_supported;
-   }
+   if (etm4_arch_supported(drvdata->arch) == false)
+   return -EINVAL;
 
etm4_init_trace_id(drvdata);
etm4_set_default(>config);
 
pdata = coresight_get_platform_data(dev);
-   if (IS_ERR(pdata)) {
-   ret = PTR_ERR(pdata);
-   goto err_arch_supported;
-   }
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+
adev->dev.platform_data = pdata;
 
desc.type = CORESIGHT_DEV_TYPE_SOURCE;
@@ -1526,17 +1521,17 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
desc.dev = dev;
desc.groups = coresight_etmv4_groups;
drvdata->csdev = coresight_register();
-   if (IS_ERR(drvdata->csdev)) {
-   

[PATCH v11 12/24] coresight: tpiu: allow tpiu to be built as a module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig  |  5 -
 drivers/hwtracing/coresight/coresight-tpiu.c | 20 +++-
 2 files changed, 23 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..566c57e03596 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(>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,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 17/24] coresight: cti: Fix remove sysfs link error

2020-09-15 Thread Tingwei Zhang
From: Mike Leach 

CTI code to remove sysfs link to other devices on shutdown, incorrectly
tries to remove a single ended link when these are all double ended. This
implementation leaves elements in the link info structure undefined which
results in a crash in recent tests for driver module unload.

This patch corrects the link removal code.

Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other coresight 
devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 5003d1f59af0..abc8b32e79b3 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -494,12 +494,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata 
*drvdata,
return !link_err;
 }
 
-static void cti_remove_sysfs_link(struct cti_trig_con *tc)
+static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
+ struct cti_trig_con *tc)
 {
struct coresight_sysfs_link link_info;
 
+   link_info.orig = drvdata->csdev;
link_info.orig_name = tc->con_dev_name;
link_info.target = tc->con_dev;
+   link_info.target_name = dev_name(>csdev->dev);
coresight_remove_sysfs_link(_info);
 }
 
@@ -589,7 +592,7 @@ static void cti_remove_assoc_from_csdev(struct 
coresight_device *csdev)
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
if (tc->con_dev == csdev->ect_dev) {
-   cti_remove_sysfs_link(tc);
+   cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
}
@@ -641,7 +644,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata 
*drvdata)
if (tc->con_dev) {
coresight_set_assoc_ectdev_mutex(tc->con_dev,
 NULL);
-   cti_remove_sysfs_link(tc);
+   cti_remove_sysfs_link(drvdata, tc);
tc->con_dev = NULL;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 21/24] coresight: cti: allow cti to be built as a module

2020-09-15 Thread Tingwei Zhang
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
- move cti_remove_conn_xrefs to cti_remove since all sysfs links
  have gone when system calls device_release.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 -
 drivers/hwtracing/coresight/Makefile  |  6 +++---
 .../{coresight-cti.c => coresight-cti-core.c} | 20 ++-
 .../hwtracing/coresight/coresight-platform.c  |  1 +
 drivers/hwtracing/coresight/coresight.c   |  1 +
 5 files changed, 28 insertions(+), 5 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 3dbd49a060dd..27034bd4d3c7 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -19,6 +19,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 \
-   coresight-cti-sysfs.o
+obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
+coresight-cti-y := coresight-cti-core.ocoresight-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 38e785d913b0..d28eae93e55c 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -822,7 +822,6 @@ static void cti_device_release(struct device *dev)
struct cti_drvdata *ect_item, *ect_tmp;
 
mutex_lock(_mutex);
-   cti_remove_conn_xrefs(drvdata);
cti_pm_release(drvdata);
 
/* remove from the list */
@@ -837,6 +836,18 @@ 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(>dev);
+
+   mutex_lock(_mutex);
+   cti_remove_conn_xrefs(drvdata);
+   mutex_unlock(_mutex);
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
 
 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -957,6 +968,8 @@ static const struct amba_id cti_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, cti_ids);
+
 static struct amba_driver cti_driver = {
.drv = {
.name   = "coresight-cti",
@@ -964,6 +977,7 @@ static struct amba_driver cti_driver = {
.suppress_bind_attrs = true,
},
.probe  = cti_probe,
+   .remove = cti_remove,
.id_table   = cti_ids,
 };
 
@@ -986,3 +1000,7 @@ static void __exit cti_exit(void)
 
 module_init(cti_init);
 module_exit(cti_exit);
+
+MODULE_AUTHOR("Mike Leach ");
+MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwtracing/coresight/coresight-platform.c 
b/drivers/hwtracing/coresight/coresight-platform.c
index 227e234a2470..3629b7885aca 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -75,6 +75,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
}
return c

[PATCH v11 16/24] coresight: cti: add function to register cti associate ops

2020-09-15 Thread Tingwei Zhang
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 
Tested-by: Mike Leach 
Reported-by: kernel test robot 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c  | 36 +---
 drivers/hwtracing/coresight/coresight-priv.h | 14 
 drivers/hwtracing/coresight/coresight.c  | 21 ++--
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 47f3c9abae30..5003d1f59af0 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -539,7 +539,7 @@ cti_match_fixup_csdev(struct cti_device *ctidev, const char 
*node_name,
  * This will set the association if CTI declared before the CS device.
  * (called from coresight_register() with coresight_mutex locked).
  */
-void cti_add_assoc_to_csdev(struct coresight_device *csdev)
+static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
 {
struct cti_drvdata *ect_item;
struct cti_device *ctidev;
@@ -572,13 +572,12 @@ void cti_add_assoc_to_csdev(struct coresight_device 
*csdev)
 cti_add_done:
mutex_unlock(_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
 
 /*
  * Removing the associated devices is easier.
  * A CTI will not have a value for csdev->ect_dev.
  */
-void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
+static void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 {
struct cti_drvdata *ctidrv;
struct cti_trig_con *tc;
@@ -599,7 +598,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device 
*csdev)
}
mutex_unlock(_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
@@ -956,4 +963,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(_driver);
+   if (ret)
+   pr_info("Error registering cti driver\n");
+   coresight_set_cti_ops(_assoc_ops);
+   return ret;
+}
+
+static void __exit cti_exit(void)
+{
+   coresight_remove_cti_ops();
+   amba_driver_unregister(_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 d638c7d48815..65a29293b6cb 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -173,15 +173,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 4faa4aa3964d..4f4485b17458 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -56,6 +56,20 @@ static struct list_head *stm_path;
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 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;
@@ -1232,7 +1246,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 &am

[PATCH v11 19/24] coresight: cti: don't disable ect device if it's not enabled

2020-09-15 Thread Tingwei Zhang
If associated ect device is not enabled at first place, disable
routine should not be called. Add ect_enabled flag to check whether
ect device is enabled. Fix the issue in below case.  Ect device is
not available when associated coresight device enabled and the
association is established after coresight device is enabled.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight.c | 11 ---
 include/linux/coresight.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index b8b0a20e93c9..711beb92166a 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -244,13 +244,18 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 
if (!ect_csdev)
return 0;
+   if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
+   return 0;
 
if (enable) {
-   if (ect_ops(ect_csdev)->enable)
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (!ect_ret)
+   csdev->ect_enabled = true;
} else {
-   if (ect_ops(ect_csdev)->disable)
+   if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   csdev->ect_enabled = false;
+   }
}
 
/* output warning if ECT enable is preventing trace operation */
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 3bb738f9a326..7d3c87e5b97c 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -208,6 +208,7 @@ struct coresight_device {
/* sysfs links between components */
int nr_links;
bool has_conns_grp;
+   bool ect_enabled; /* true only if associated ect device is enabled */
 };
 
 /*
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 23/24] coresight: catu: allow catu drivers to be built as modules

2020-09-15 Thread Tingwei Zhang
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 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 47696a7d24a7..99430f6cf5a5 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -567,11 +567,21 @@ 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(>dev);
+
+   coresight_unregister(drvdata->csdev);
+   return 0;
+}
+
 static struct amba_id catu_ids[] = {
CS_AMBA_ID(0x000bb9ee),
{},
 };
 
+MODULE_DEVICE_TABLE(amba, catu_ids);
+
 static struct amba_driver catu_driver = {
.drv = {
.name   = "coresight-catu",
@@ -579,6 +589,7 @@ static struct amba_driver catu_driver = {
.suppress_bind_attrs= true,
},
.probe  = catu_probe,
+   .remove = catu_remove,
.id_table   = catu_ids,
 };
 
@@ -601,3 +612,7 @@ static void __exit catu_exit(void)
 
 module_init(catu_init);
 module_exit(catu_exit);
+
+MODULE_AUTHOR("Suzuki K Poulose ");
+MODULE_DESCRIPTION("Arm CoreSight Address Translation Unit (CATU) Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 20/24] coresight: cti: increase reference count when enabling cti

2020-09-15 Thread Tingwei Zhang
CTI device is enabled when associated coresight device is enabled.
Increase the module and device reference count for CTI device
when it's enabled. This can prevent CTI device be removed or
module be unloaded when CTI device is enabled by an active trace
session.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 711beb92166a..546c97045afe 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -241,19 +241,30 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 {
int ect_ret = 0;
struct coresight_device *ect_csdev = csdev->ect_dev;
+   struct module *mod;
 
if (!ect_csdev)
return 0;
if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
return 0;
 
+   mod = ect_csdev->dev.parent->driver->owner;
if (enable) {
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
-   if (!ect_ret)
-   csdev->ect_enabled = true;
+   if (try_module_get(mod)) {
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (ect_ret) {
+   module_put(mod);
+   } else {
+   get_device(ect_csdev->dev.parent);
+   csdev->ect_enabled = true;
+   }
+   } else
+   ect_ret = -ENODEV;
} else {
if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   put_device(ect_csdev->dev.parent);
+   module_put(mod);
csdev->ect_enabled = false;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 22/24] coresight: tmc-etr: add function to register catu ops

2020-09-15 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

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 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 1801804a7762..47696a7d24a7 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,
@@ -582,4 +582,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(_driver);
+   if (ret)
+   pr_info("Error registering catu driver\n");
+   tmc_etr_set_catu_ops(_catu_buf_ops);
+   return ret;
+}
+
+static void __exit catu_exit(void)
+{
+   tmc_etr_remove_catu_ops();
+   amba_driver_unregister(_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 ad991a37e2d2..714f9e867e5f 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] = _flat_buf_ops,
[ETR_MODE_ETR_SG] = _sg_buf_ops,
-   [ETR_MODE_CATU] = IS_ENABLED(CONFIG_CORESIGHT_CATU)
-   ? _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 6e8d2dc33d17..b91ec7dde7bc 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -326,4 +326,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
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 14/24] coresight: allow funnel driver to be built as module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-funnel as module, for ease of development.

- combine static and dynamic funnel init into single
  module_init/exit call
- add funnel_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reported-by: kernel test robot 
Tested-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
Reviewed-by: Suzuki K Poulose 
---
 .../hwtracing/coresight/coresight-funnel.c| 65 ++-
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-funnel.c 
b/drivers/hwtracing/coresight/coresight-funnel.c
index 900690a9f7f0..af40814ce560 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,29 +328,41 @@ static int static_funnel_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_funnel_remove(struct platform_device *pdev)
+{
+   funnel_remove(>dev);
+   pm_runtime_disable(>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,
+   .remove  = static_funnel_remove,
.driver = {
.name   = "coresight-static-funnel",
+   .owner  = THIS_MODULE,
.of_match_table = static_funnel_match,
.acpi_match_table = ACPI_PTR(static_funnel_ids),
.pm = _dev_pm_ops,
.suppress_bind_attrs = true,
},
 };
-builtin_platform_driver(static_funnel_driver);
 
 static int dynamic_funnel_probe(struct amba_device *adev,
const struct amba_id *id)
@@ -349,6 +370,11 @@ static int dynamic_funnel_probe(struct amba_device *adev,
return funnel_probe(>dev, >res);
 }
 
+static int __exit dynamic_funnel_remove(struct amba_device *adev)
+{
+   return funnel_remove(>dev);
+}
+
 static const struct amba_id dynamic_funnel_ids[] = {
{
.id = 0x000bb908,
@@ -362,6 +388,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",
@@ -370,6 +398,39 @@ static struct amba_driver dynamic_funnel_driver = {
.suppress_bind_attrs = true,
},
.probe  = dynamic_funnel_probe,
+   .remove = dynamic_funnel_remove,
.id_table   = dynamic_funnel_ids,
 };
-builtin_amba_driver(dynamic_funnel_driver);
+
+static int __init funnel_init(void)
+{
+   int ret;
+
+   ret = platform_driver_register(_funnel_driver);
+   if (ret) {
+   pr_info("Error registering platform driver\n");
+   return ret;
+   }
+
+   ret = amba_driver_register(_funnel_driver);
+   if (ret) {
+   pr_info("Error registering amba driver\n");
+   platform_driver_unregister(_funnel_driver);
+   }
+
+   return ret;
+}
+
+static void __exit funnel_exit(void)
+{
+   platform_driver_unregister(_funnel_driver);
+   amba_driver_unregister(_funnel_driver);
+}
+
+module_init(funnel_init);
+module_exit(funnel_exit);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Funnel Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



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

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

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

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index dfe407cde262..c1198245461d 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -3,7 +3,7 @@
 # Coresight configuration
 #
 menuconfig CORESIGHT
-   bool "CoreSight Tracing Support"
+   tristate "CoreSight Tracing Support"
depends on ARM || ARM64
depends on OF || ACPI
select ARM_AMBA
@@ -15,6 +15,9 @@ menuconfig CORESIGHT
  specification and configure the right series of components when a
  trace source gets enabled.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight.
+
 if CORESIGHT
 config CORESIGHT_LINKS_AND_SINKS
tristate "CoreSight Link and Sink drivers"
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index 27034bd4d3c7..f20e357758d1 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -2,8 +2,9 @@
 #
 # Makefile for CoreSight drivers.
 #
-obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
-  coresight-platform.o coresight-sysfs.o
+obj-$(CONFIG_CORESIGHT) += coresight.o
+coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
+   coresight-sysfs.o
 obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
 coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
  coresight-tmc-etr.o
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight.c
rename to drivers/hwtracing/coresight/coresight-core.c
index 5aebdbe293f2..6994c1309b2b 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1452,16 +1452,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(_bustype);
-}
-postcore_initcall(coresight_init);
-
 /*
  * coresight_release_platform_data: Release references to the devices connected
  * to the output port of this device.
@@ -1670,3 +1660,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(_bustype);
+   if (ret)
+   return ret;
+
+   ret = etm_perf_init();
+   if (ret)
+   bus_unregister(_bustype);
+
+   return ret;
+}
+
+static void __exit coresight_exit(void)
+{
+   etm_perf_exit();
+   bus_unregister(_bustype);
+}
+
+module_init(coresight_init);
+module_exit(coresight_exit);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight tracer driver");
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 47894a0dcf5e..c2c9b127d074 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -599,7 +599,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;
 
@@ -626,4 +626,8 @@ static int __init etm_perf_init(void)
 
return ret;
 }
-device_initcall(etm_perf_init);
+
+void __exit etm_perf_exit(void)
+{
+   pe

[PATCH v11 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure

2020-09-15 Thread Tingwei Zhang
When coresight_build_path() fails on all the cpus, etm_setup_aux
calls etm_free_aux() to free allocated event_data.
WARN_ON(cpumask_empty(mask) will be triggered since cpu mask is empty.
Check event_data->snk_config is not NULL first to avoid this
warning.

Fixes: f5200aa9831f38 ("coresight: perf: Refactor function free_event_data()")
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 644805e0a9ec..47894a0dcf5e 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -126,10 +126,10 @@ static void free_sink_buffer(struct etm_event_data 
*event_data)
cpumask_t *mask = _data->mask;
struct coresight_device *sink;
 
-   if (WARN_ON(cpumask_empty(mask)))
+   if (!event_data->snk_config)
return;
 
-   if (!event_data->snk_config)
+   if (WARN_ON(cpumask_empty(mask)))
return;
 
cpu = cpumask_first(mask);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 07/24] coresight: stm: allow to build coresight-stm as a module

2020-09-15 Thread Tingwei Zhang
- 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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig |  5 -
 drivers/hwtracing/coresight/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 2ba819a47cf6..b0ad912651a9 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -951,6 +951,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(>dev);
+
+   coresight_unregister(drvdata->csdev);
+
+   stm_unregister_device(>stm);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int stm_runtime_suspend(struct device *dev)
 {
@@ -983,6 +994,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",
@@ -991,7 +1004,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 ");
+MODULE_DESCRIPTION("Arm CoreSight System Trace Macrocell driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 18/24] coresight: cti: Fix bug clearing sysfs links on callback

2020-09-15 Thread Tingwei Zhang
From: Mike Leach 

During module unload, a coresight driver module will call back into
the CTI driver to remove any links between the two devices.

The current code has 2 issues:-
1) in the CTI driver the matching code is matching to the wrong device
so misses all the links.
2) The callback is called too late in the unload process resulting in a
crash.

This fixes both the issues.

Fixes: 177af8285b59 ("coresight: cti: Enable CTI associated with devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
Acked-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c | 2 +-
 drivers/hwtracing/coresight/coresight.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index abc8b32e79b3..38e785d913b0 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -591,7 +591,7 @@ static void cti_remove_assoc_from_csdev(struct 
coresight_device *csdev)
ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
-   if (tc->con_dev == csdev->ect_dev) {
+   if (tc->con_dev == csdev) {
cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 4f4485b17458..b8b0a20e93c9 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1246,8 +1246,6 @@ static void coresight_device_release(struct device *dev)
 {
struct coresight_device *csdev = to_coresight_device(dev);
 
-   if (cti_assoc_ops && cti_assoc_ops->remove)
-   cti_assoc_ops->remove(csdev);
fwnode_handle_put(csdev->dev.fwnode);
kfree(csdev->refcnt);
kfree(csdev);
@@ -1582,6 +1580,8 @@ void coresight_unregister(struct coresight_device *csdev)
 {
etm_perf_del_symlink_sink(csdev);
/* Remove references of that device in the topology */
+   if (cti_assoc_ops && cti_assoc_ops->remove)
+   cti_assoc_ops->remove(csdev);
coresight_remove_conns(csdev);
coresight_clear_default_sink(csdev);
coresight_release_platform_data(csdev, csdev->pdata);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 11/24] coresight: etb: allow etb to be built as a module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +++-
 drivers/hwtracing/coresight/coresight-etb10.c | 26 ++-
 2 files changed, 29 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 04ee9cda988d..248cc82c838e 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -801,6 +801,21 @@ 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(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int etb_runtime_suspend(struct device *dev)
 {
@@ -835,6 +850,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 +861,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Embedded Trace Buffer driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 15/24] coresight: allow replicator driver to be built as module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-replicator as modules, for ease of development.

- Kconfig becomes a tristate, to allow =m
- combine static and dynamic replicator init into single
  module_init/exit call
- add replicator_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 .../coresight/coresight-replicator.c  | 65 ++-
 2 files changed, 67 insertions(+), 3 deletions(-)

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-replicator.c 
b/drivers/hwtracing/coresight/coresight-replicator.c
index 78acf29c49ca..62afdde0e5ea 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -291,6 +291,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;
@@ -310,6 +318,13 @@ static int static_replicator_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_replicator_remove(struct platform_device *pdev)
+{
+   replicator_remove(>dev);
+   pm_runtime_disable(>dev);
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int replicator_runtime_suspend(struct device *dev)
 {
@@ -343,24 +358,29 @@ static const struct of_device_id 
static_replicator_match[] = {
{}
 };
 
+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 = _dev_pm_ops,
.suppress_bind_attrs = true,
},
 };
-builtin_platform_driver(static_replicator_driver);
 
 static int dynamic_replicator_probe(struct amba_device *adev,
const struct amba_id *id)
@@ -368,19 +388,60 @@ static int dynamic_replicator_probe(struct amba_device 
*adev,
return replicator_probe(>dev, >res);
 }
 
+static int __exit dynamic_replicator_remove(struct amba_device *adev)
+{
+   return replicator_remove(>dev);
+}
+
 static const struct amba_id dynamic_replicator_ids[] = {
CS_AMBA_ID(0x000bb909),
CS_AMBA_ID(0x000bb9ec), /* Coresight SoC-600 */
{},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
+
 static struct amba_driver dynamic_replicator_driver = {
.drv = {
.name   = "coresight-dynamic-replicator",
.pm = _dev_pm_ops,
+   .owner  = THIS_MODULE,
.suppress_bind_attrs = true,
},
.probe  = dynamic_replicator_probe,
+   .remove = dynamic_replicator_remove,
.id_table   = dynamic_replicator_ids,
 };
-builtin_amba_driver(dynamic_replicator_driver);
+
+static int __init replicator_init(void)
+{
+   int ret;

[PATCH v11 09/24] coresight: etm3x: allow etm3x to be built as a module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

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
- delay advertising the per-cpu etmdrvdata
- protect etmdrvdata[] by modifying it on relevant CPU

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |   5 +-
 drivers/hwtracing/coresight/Makefile  |   5 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} | 148 ++
 3 files changed, 122 insertions(+), 36 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm3x.c => 
coresight-etm3x-core.c} (90%)

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 19497d1d92bf..86b4648844b4 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -11,8 +11,9 @@ 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 
\
-   coresight-etm3x-sysfs.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_STM) += coresight-stm.o
diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c 
b/drivers/hwtracing/coresight/coresight-etm3x-core.c
similarity index 90%
rename from drivers/hwtracing/coresight/coresight-etm3x.c
rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
index bf22dcfd3327..56eba0b5c71f 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
@@ -782,6 +782,42 @@ static void etm_init_trace_id(struct etm_drvdata *drvdata)
drvdata->traceid = coresight_get_trace_id(drvdata->cpu);
 }
 
+static int __init etm_hp_setup(void)
+{
+   int ret;
+
+   ret = 
cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
+"arm/coresight:starting",
+etm_starting_cpu, etm_dying_cpu);
+
+   if (ret)
+   return ret;
+
+   ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
+  "arm/coresight:online",
+  etm_online_cpu, NULL);
+
+   /* HP dyn state ID returned in ret on success */
+   if (ret > 0) {
+   hp_online = ret;
+   return 0;
+   }
+
+   /* failed dyn state - remove others */
+   cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+
+   return ret;
+}
+
+static void etm_hp_clear(void)
+{
+   cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+   if (hp_online) {
+   cpuhp_remove_state_nocalls(hp_online);
+   hp_online = 0;
+   }
+}
+
 static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 {
int ret;
@@ -824,38 +860,23 @@ static int etm_probe(struct amba_device *adev, const 
struct amba_id *id)
return -ENOMEM;
 
cpus_read_lock();
-   etmdrvdata[drvdata->cpu] = drvdata;
 
if (smp_call_function_single(drvdata->cp

[PATCH v11 04/24] coresight: add coresight prefix to barrier_pkt

2020-09-15 Thread Tingwei Zhang
Add coresight prefix to make it specific. It will be a export symbol.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etb10.c   | 2 +-
 drivers/hwtracing/coresight/coresight-priv.h| 7 +++
 drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +-
 drivers/hwtracing/coresight/coresight.c | 2 +-
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index 03e3f2590191..04ee9cda988d 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 28695e26e5c6..d638c7d48815 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,9 @@ 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 6375504ba8b0..44402d413ebb 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 bb4f9e0a5438..ae40bb0539fd 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -53,7 +53,7 @@ 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] = {0x7fff, 0x7fff, 0x7fff, 0x7fff};
+const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 
 static int coresight_id_match(struct device *dev, void *data)
 {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 06/24] coresight: add try_get_module() in coresight_grab_device()

2020-09-15 Thread Tingwei Zhang
When coresight device is in an active session, driver module of
that device should not be removed. Use try_get_module() in
coresight_grab_device() to prevent module to be unloaded.
Use get_device()/put_device() to protect device data
in the middle of active session.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Suggested-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight.c | 60 ++---
 1 file changed, 53 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index d1aea3a1e7b6..4faa4aa3964d 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -629,13 +629,45 @@ struct coresight_device *coresight_get_sink_by_id(u32 id)
return dev ? to_coresight_device(dev) : NULL;
 }
 
+/**
+ * coresight_get_ref- Helper function to increase reference count to module
+ * and device.
+ * Return true in successful case and power up the device.
+ * Return false when failed to get reference of module.
+ */
+static inline bool coresight_get_ref(struct coresight_device *csdev)
+{
+   struct device *dev = csdev->dev.parent;
+
+   /* Make sure the driver can't be removed */
+   if (!try_module_get(dev->driver->owner))
+   return false;
+   /* Make sure the device can't go away */
+   get_device(dev);
+   pm_runtime_get_sync(dev);
+   return true;
+}
+
+/**
+ * coresight_put_ref- Helper function to decrease reference count to module
+ * and device. Power off the device.
+ */
+static inline void coresight_put_ref(struct coresight_device *csdev)
+{
+   struct device *dev = csdev->dev.parent;
+
+   pm_runtime_put(dev);
+   put_device(dev);
+   module_put(dev->driver->owner);
+}
+
 /*
  * coresight_grab_device - Power up this device and any of the helper
  * devices connected to it for trace operation. Since the helper devices
  * don't appear on the trace path, they should be handled along with the
  * the master device.
  */
-static void coresight_grab_device(struct coresight_device *csdev)
+static int coresight_grab_device(struct coresight_device *csdev)
 {
int i;
 
@@ -644,9 +676,20 @@ static void coresight_grab_device(struct coresight_device 
*csdev)
 
child  = csdev->pdata->conns[i].child_dev;
if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-   pm_runtime_get_sync(child->dev.parent);
+   if (!coresight_get_ref(child))
+   goto err;
+   }
+   if (coresight_get_ref(csdev))
+   return 0;
+err:
+   for (i--; i >= 0; i--) {
+   struct coresight_device *child;
+
+   child  = csdev->pdata->conns[i].child_dev;
+   if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
+   coresight_put_ref(child);
}
-   pm_runtime_get_sync(csdev->dev.parent);
+   return -ENODEV;
 }
 
 /*
@@ -657,13 +700,13 @@ static void coresight_drop_device(struct coresight_device 
*csdev)
 {
int i;
 
-   pm_runtime_put(csdev->dev.parent);
+   coresight_put_ref(csdev);
for (i = 0; i < csdev->pdata->nr_outport; i++) {
struct coresight_device *child;
 
child  = csdev->pdata->conns[i].child_dev;
if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-   pm_runtime_put(child->dev.parent);
+   coresight_put_ref(child);
}
 }
 
@@ -682,7 +725,7 @@ static int _coresight_build_path(struct coresight_device 
*csdev,
 struct coresight_device *sink,
 struct list_head *path)
 {
-   int i;
+   int i, ret;
bool found = false;
struct coresight_node *node;
 
@@ -712,11 +755,14 @@ static int _coresight_build_path(struct coresight_device 
*csdev,
 * is tell the PM runtime core we need this element and add a node
 * for it.
 */
+   ret = coresight_grab_device(csdev);
+   if (ret)
+   return ret;
+
node = kzalloc(sizeof(struct coresight_node), GFP_KERNEL);
if (!node)
return -ENOMEM;
 
-   coresight_grab_device(csdev);
node->csdev = csdev;
list_add(>link, path);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 13/24] coresight: tmc: allow tmc to be built as a module

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  6 -
 drivers/hwtracing/coresight/Makefile  |  6 ++---
 .../{coresight-tmc.c => coresight-tmc-core.c} | 25 ++-
 3 files changed, 32 insertions(+), 5 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} 
(95%)

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 3f2b057443fb..3dbd49a060dd 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -4,9 +4,9 @@
 #
 obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
   coresight-platform.o coresight-sysfs.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 95%
rename from drivers/hwtracing/coresight/coresight-tmc.c
rename to drivers/hwtracing/coresight/coresight-tmc-core.c
index 9ca3aaafcfbc..5653e0945c74 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -559,6 +559,21 @@ static void tmc_shutdown(struct amba_device *adev)
spin_unlock_irqrestore(>spinlock, flags);
 }
 
+static int __exit tmc_remove(struct amba_device *adev)
+{
+   struct tmc_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 static const struct amba_id tmc_ids[] = {
CS_AMBA_ID(0x000bb961),
/* Coresight SoC 600 TMC-ETR/ETS */
@@ -570,6 +585,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",
@@ -578,6 +595,12 @@ static struct amba_driver tmc_driver = {
},
.probe  = tmc_probe,
.shutdown   = tmc_shutdown,
+   .remove = tmc_remove,
.id_table   = tmc_ids,
 };
-builtin_amba_driver(tmc_driver);
+
+module_amba_driver(tmc_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 05/24] coresight: export global symbols

2020-09-15 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

Export symbols used among coresight modules.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 1 +
 drivers/hwtracing/coresight/coresight-sysfs.c| 2 ++
 drivers/hwtracing/coresight/coresight-tmc-etr.c  | 6 ++
 drivers/hwtracing/coresight/coresight.c  | 8 
 4 files changed, 17 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index b4e5758b6c12..644805e0a9ec 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -525,6 +525,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-sysfs.c 
b/drivers/hwtracing/coresight/coresight-sysfs.c
index 82afeaf2ccc4..34d2a2d31d00 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -102,6 +102,7 @@ int coresight_add_sysfs_link(struct coresight_sysfs_link 
*info)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(coresight_add_sysfs_link);
 
 void coresight_remove_sysfs_link(struct coresight_sysfs_link *info)
 {
@@ -122,6 +123,7 @@ void coresight_remove_sysfs_link(struct 
coresight_sysfs_link *info)
info->orig->nr_links--;
info->target->nr_links--;
 }
+EXPORT_SYMBOL_GPL(coresight_remove_sysfs_link);
 
 /*
  * coresight_make_links: Make a link for a connection from a @orig
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c 
b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index b29c2db94d96..ad991a37e2d2 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 ae40bb0539fd..d1aea3a1e7b6 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -54,6 +54,7 @@ static struct list_head *stm_path;
  * it needs to look for another sync sequence.
  */
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
+EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
 
 static int coresight_id_match(struct device *dev, void *data)
 {
@@ -179,6 +180,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)
 {
@@ -190,6 +192,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.
@@ -208,6 +211,7 @@ void coresight_disclaim_device_unlocked(void __iomem *base)
 */
WARN_ON_ONCE(1);
 }
+EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);
 
 void coresig

[PATCH v11 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules

2020-09-15 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 5fe773c4d6cc..28695e26e5c6 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -166,7 +166,7 @@ int coresight_make_links(struct coresight_device *orig,
 void coresight_remove_links(struct coresight_device *orig,
struct coresight_connection *conn);
 
-#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 58fffdecdbfd..3bb738f9a326 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -324,7 +324,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);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE

2020-09-15 Thread Tingwei Zhang
Define a MODULE_DEVICE_TABLE for cpu_debug so module can
be auto loaded on boot.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 7e642fb3ed15..e1d232411d8d 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",
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 01/24] coresight: cpu_debug: add module name in Kconfig

2020-09-15 Thread Tingwei Zhang
Provide name of cpu_debug module in Kconfig help section.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v11 00/24] coresight: allow to build coresight as modules

2020-09-15 Thread Tingwei Zhang
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

Change from v10:
Rebase to latest coresight-next
Protect etmdrvdata[] by modifying it on relevant CPU for ETM3. (Mathieu and 
Suzuki)
 -It's not tested.
Refine the alignment in coresight makefile. (Mathieu)
Add reason for cti_remove_conn_xrefs change. (Mathieu)
Set owner for static funnel driver. (Suzuki)

Change from v9:
Fix warning reported by kernel test robot 
Rebase to coresight-next

Change from v8:
Protect etmdrvdata[] by modifying it on relevant CPU  (Mathieu and Suzuki)
Grab the device before allocating memory for the node (Mathieu)
Add author of coresight core driver (Mathieu)

Change from v7:
Depends on below change for ETM hotplug (Sai)
https://lore.kernel.org/linux-arm-kernel/20200729051310.18436-1-saiprakash.ran...@codeaurora.org/
Add mutex lock to protect etmdrvdata[] (Suzuki)
Add helper function coresight_get_ref() (Suzuki)
Reorg replicator and funnel change. Use two patches to support these
two drivers. (Suzuki)
Add fix tag to "coresight: etm: perf: Fix warning caused by etm_setup_aux
failure" (Suzuki)
Update author of "coresight: cti: Fix bug clearing sysfs links on callback"

Change from v6:
Correct module description for CATU (Mike)
Check ect_ret equals 0 and set ect_enabled flag (Mike)
Add Tested-by and Reviewed-by from Mike

Change from v5:
Add below CTI clean up change from Mike into series
 -https://lists.linaro.org/pipermail/coresight/2020-July/004349.html
Increase module reference count when enabling CTI device (Mike)

Change from v4:
Fix error handling in coresight_grab_devicei() (Greg)
Add coresight: cti: Fix remove sysfs link error from Mike
 -https://lists.linaro.org/pipermail/coresight/2020-July/004275.html
Move cti_remove_conn_xrefs() into cti_remove() (Mike)
Align patch subject to coresight: :  (Mike)

Change from v3:
Rebase to coresight-next (Mike and Mathieu)
Reorder try_get_module() (Suzuki)
Clean up etmdrvdata[] in device remote path (Mike)
Move cti_remove_conn_xrefs to cti_remove (Mike)

Change from v2:
Rebase to 5.8-rc5. Export coresight_add_sysfs_link and
coresight_remove_sysfs_link
Fix one cut and paste error on MODULE_DESCRIPTION of CTI

Change from v1:
Use try_module_get() to avoid module to be unloaded when device is used
in active trace session. (Mathieu P)

Change from above two series.
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 (8):
  coresight: use IS_ENABLED for CONFIGs that may be modules
  coresight: etm3x: allow etm3x to be built as a module
  coresight: etm4x: allow etm4x to be built as a module
  coresight: etb: allow etb to be built as a module
  coresight: tpiu: allow tpiu to be built as a module
  coresight: tmc: allow tmc to be built as a module
  coresight: allow funnel driver to be built as module
  coresight: allow replicator driver to be built as module

Mian Yousaf Kaukab (2):
  coresight: export global symbols
  coresight: tmc-etr: add function to register catu ops

Mike Leach (2):
  coresight: cti: Fix remove sysfs link error
  coresight: cti: Fix bug clearing sysfs links on callback

Tingwei Zhang (12):
  coresight: cpu_debug: add module name in Kconfig
  coresight: cpu_debug: define MODULE_DEVICE_TABLE
  coresight: add coresight prefix to barrier_pkt
  coresight: add try_get_module() in coresight_grab_device()
  coresight: stm: allow to build coresight-stm as a module
  coresight: etm: perf: Fix warning caused by etm_setup_aux failure
  coresight: cti: add function to register cti associate ops
  coresight: cti: don't disable ect device if it's not enabled
  coresight: cti: increase reference count when enabling cti
  coresight: cti: allow cti to be built as a module
  coresight: catu: allow catu drivers to be built as modules
  coresight: allow the coresight core driver to be built as a module

 drivers/hwtracing/coresight/Kconfig   |  54 --
 drivers/hwtracing/coresight/Makefile  |  26 +--
 drivers/hwtracing/coresight/coresight-catu.c  |  37 -
 drivers/hwtracing/coresight/coresight-catu.h  |   2 -
 .../{coresight.c => coresight-core.c} | 154 +++---
 .../hwtracing/coresight/coresight-cpu-debug.c |   2 +
 .../{coresight-cti.c => coresight-cti-core.c} |  67 ++--
 drivers/hwtracing/coresight/coresight-etb10.c |  28 +++-
 .../hwtracing/coresight/coresight-etm-perf.c  |  13 +-
 .../hwtracing/coresight/coresight-etm-perf.h  |   5 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} | 148 +
 ...resight-etm4x.c => coresight-etm4x-core.c} |  84 ++

Re: [PATCH v3 0/6] tracing: export event trace and trace_marker

2020-09-14 Thread Tingwei Zhang
Hi Alexander, Maxime, Aleandre,

May I know your comments for this patch set?

Thanks,
Tingwei

On Thu, Sep 03, 2020 at 08:17:00AM +0800, Tingwei Zhang wrote:
> Ftrace has ability to export trace packets to other destination.
> Currently, only function trace can be exported. This series extends the
> support to event trace and trace_maker. STM is one possible destination to
> export ftrace. Use separate channel for each CPU to avoid mixing up
> packets
> from different CPUs together.
> 
> Change from v2:
> Change flag definition to BIT(). (Steven)
> Add comment in stm_ftrace_write() to clarify it's safe to use 
> smp_processor_id() here since preempt is disabled. (Steven) 
> 
> Change from v1:
> All changes are suggested by Steven Rostedt.
> User separate flag to control function trace, event trace and trace mark.
> Allocate channels according to num_possible_cpu() dynamically.
> Move ftrace_exports routines up so all ftrace can use them.
> 
> Tingwei Zhang (6):
>   stm class: ftrace: change dependency to TRACING
>   tracing: add flag to control different traces
>   tracing: add trace_export support for event trace
>   tracing: add trace_export support for trace_marker
>   stm class: ftrace: enable supported trace export flag
>   stm class: ftrace: use different channel accroding to CPU
> 
>  drivers/hwtracing/stm/Kconfig  |   2 +-
>  drivers/hwtracing/stm/ftrace.c |   7 +-
>  include/linux/trace.h  |   7 +
>  kernel/trace/trace.c   | 270 ++---
>  4 files changed, 159 insertions(+), 127 deletions(-)
> 
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 


Re: [PATCH v3 0/6] tracing: export event trace and trace_marker

2020-09-14 Thread Tingwei Zhang
On Tue, Sep 15, 2020 at 06:43:09AM +0800, Steven Rostedt wrote:
> On Wed, 2 Sep 2020 07:28:39 +0800
> Tingwei Zhang  wrote:
> 
> > Hi Alexander,
> > 
> > May I know your comments for this patch set?
> 
> I ran your patch set against get_maintainers.pl and it came up with this:
> 
> Alexander Shishkin  (maintainer:SYSTEM
> TRACE MODULE CLASS)
> Maxime Coquelin  (maintainer:ARM/STM32
> ARCHITECTURE)
> Alexandre Torgue  (maintainer:ARM/STM32
> ARCHITECTURE)
> Steven Rostedt  (maintainer:TRACING)
> Ingo Molnar  (maintainer:TRACING)
> linux-st...@st-md-mailman.stormreply.com (moderated list:ARM/STM32
> ARCHITECTURE)
> linux-arm-ker...@lists.infradead.org (moderated list:ARM/STM32
> ARCHITECTURE)
> linux-kernel@vger.kernel.org (open list)
> 
> I would use that to know who to send to.
> 
> You have Alexander, myself, Ingo and LKML, but you should add the others
> in
> that list for this series, and then it may get noticed. Please use
> get_maintainers.pl for future patches if you don't know who to send them
> to.
> 
> -- Steve
> 
Thanks a lot for the detail instructions, Steve.  I noticed that after
senting previous mail to Alexander.

I sent the patchset to maintainers and mail list as you mentioned in
https://patchwork.kernel.org/cover/11752107/.

Thanks,
Tingwei

> > 
> > Thanks,
> > Tingwei
> > 
> > On Thu, Aug 13, 2020 at 09:45:46AM +0800, Tingwei Zhang wrote:
> > > Ftrace has ability to export trace packets to other destination.
> > > Currently, only function trace can be exported. This series extends
> the
> > > support to event trace and trace_maker. STM is one possible
> destination to
> > > export ftrace. Use separate channel for each CPU to avoid mixing up
> > > packets
> > > from different CPUs together.
> > > 
> > > Change from v2:
> > > Change flag definition to BIT(). (Steven)
> > > Add comment in stm_ftrace_write() to clarify it's safe to use 
> > > smp_processor_id() here since preempt is disabled. (Steven) 
> > > 
> > > Change from v1:
> > > All changes are suggested by Steven Rostedt.
> > > User separate flag to control function trace, event trace and trace
> mark.
> > > Allocate channels according to num_possible_cpu() dynamically.
> > > Move ftrace_exports routines up so all ftrace can use them.
> > > 
> > > Tingwei Zhang (6):
> > >   stm class: ftrace: change dependency to TRACING
> > >   tracing: add flag to control different traces
> > >   tracing: add trace_export support for event trace
> > >   tracing: add trace_export support for trace_marker
> > >   stm class: ftrace: enable supported trace export flag
> > >   stm class: ftrace: use different channel accroding to CPU
> > > 
> > >  drivers/hwtracing/stm/Kconfig  |   2 +-
> > >  drivers/hwtracing/stm/ftrace.c |   7 +-
> > >  include/linux/trace.h  |   7 +
> > >  kernel/trace/trace.c   | 270
> ++---
> > >  4 files changed, 159 insertions(+), 127 deletions(-)
> > > 
> > > -- 
> > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > > a Linux Foundation Collaborative Project
> > >   
> 


Re: [PATCH v10 09/24] coresight: etm3x: allow etm3x to be built as a module

2020-09-13 Thread Tingwei Zhang
On Sun, Sep 13, 2020 at 09:17:05PM +0800, Suzuki K Poulose wrote:
> On 08/21/2020 04:44 AM, Tingwei Zhang wrote:
> >From: Kim Phillips 
> >
> >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 
> >Cc: Leo Yan 
> >Cc: Alexander Shishkin 
> >Cc: Randy Dunlap 
> >Cc: Suzuki K Poulose 
> >Cc: Greg Kroah-Hartman 
> >Cc: Russell King 
> >Signed-off-by: Kim Phillips 
> >Signed-off-by: Tingwei Zhang 
> >Reviewed-by: Mike Leach 
> 
> 
> >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 bf22dcfd3327..ba9c86497acb 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(>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;
> >+}
> >+
> 
> Don't we need to fix the races like we did for ETMv4 ?
> 
> Suzuki
> 
Yes, we need that.  Unfortunately, I don't have ETMv3 devie to verify the
change.  Mathieu has been very kind to offer his help to take care of
ETMv3.

Thanks,
Tingwei
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


Re: [PATCH v10 14/24] coresight: allow funnel driver to be built as module

2020-09-13 Thread Tingwei Zhang
On Sun, Sep 13, 2020 at 09:24:52PM +0800, Suzuki K Poulose wrote:
> On 08/21/2020 04:44 AM, Tingwei Zhang wrote:
> >From: Kim Phillips 
> >
> >Allow to build coresight-funnel as module, for ease of development.
> >
> >- combine static and dynamic funnel init into single
> >   module_init/exit call
> >- add funnel_remove functions, for module unload
> >- add a MODULE_DEVICE_TABLE for autoloading on boot
> >
> >Cc: Mathieu Poirier 
> >Cc: Leo Yan 
> >Cc: Alexander Shishkin 
> >Cc: Randy Dunlap 
> >Cc: Suzuki K Poulose 
> >Cc: Greg Kroah-Hartman 
> >Cc: Russell King 
> >Co-developed-by: Mian Yousaf Kaukab 
> >Signed-off-by: Mian Yousaf Kaukab 
> >Signed-off-by: Kim Phillips 
> >Signed-off-by: Tingwei Zhang 
> >Reported-by: kernel test robot 
> >Tested-by: Mike Leach 
> >Reviewed-by: Mathieu Poirier 
> >---
> >  .../hwtracing/coresight/coresight-funnel.c| 64 ++-
> >  1 file changed, 62 insertions(+), 2 deletions(-)
> >
> >diff --git a/drivers/hwtracing/coresight/coresight-funnel.c
> b/drivers/hwtracing/coresight/coresight-funnel.c
> >index 900690a9f7f0..07bc20391fac 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,32 @@ static int static_funnel_probe(struct
> platform_device *pdev)
> > return ret;
> >  }
> >+static int __exit static_funnel_remove(struct platform_device *pdev)
> >+{
> >+funnel_remove(>dev);
> >+pm_runtime_disable(>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,
> >+.remove  = static_funnel_remove,
> > .driver = {
> > .name   = "coresight-static-funnel",
> > .of_match_table = static_funnel_match,
> 
> Sorry missed this. Please set the owner field here. With that :
> 
> Reviewed-by: Suzuki K Poulose 
>
Thanks, Suzuki. I'll add owner in v11.

Thanks,
Tingwei 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


Re: [PATCH v10 21/24] coresight: cti: allow cti to be built as a module

2020-09-10 Thread Tingwei Zhang
On Fri, Sep 11, 2020 at 07:03:03AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 21, 2020 at 11:44:42AM +0800, Tingwei Zhang wrote:
> > 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
> > - move cti_remove_conn_xrefs to cti_remove
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > 
> > Signed-off-by: Tingwei Zhang 
> > Tested-by: Mike Leach 
> > Reviewed-by Mike Leach 
> > ---
> >  drivers/hwtracing/coresight/Kconfig   |  5 -
> >  drivers/hwtracing/coresight/Makefile  |  4 ++--
> >  .../{coresight-cti.c => coresight-cti-core.c} | 20 ++-
> >  .../hwtracing/coresight/coresight-platform.c  |  1 +
> >  drivers/hwtracing/coresight/coresight.c   |  1 +
> >  5 files changed, 27 insertions(+), 4 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 f2a568b969c4..0359d5a1588f 100644
> > --- a/drivers/hwtracing/coresight/Makefile
> > +++ b/drivers/hwtracing/coresight/Makefile
> > @@ -19,6 +19,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.ocoresight-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 ec286d617b73..d6d5419ec21c 100644
> > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > +++ b/drivers/hwtracing/coresight/coresight-cti-core.c
> > @@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
> > struct cti_drvdata *ect_item, *ect_tmp;
> >  
> > mutex_lock(_mutex);
> > -   cti_remove_conn_xrefs(drvdata);
> > cti_pm_release(drvdata);
> >  
> > /* remove from the list */
> > @@ -853,6 +852,18 @@ 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(>dev);
> > +
> > +   mutex_lock(_mutex);
> > +   cti_remove_conn_xrefs(drvdata);
> > +   mutex_unlock(_mutex);
> > +
> > +   coresight_unregister(drvdata->csdev);
> > +
> > +   return 0;
> 
> Once again my recommendations from V8 were not followed.
>

Sorry for missing your comment. I'll add reason for above change
in commit message in V11.

Thanks,
Tingwei
 
> > +}
> >  
> >  static int cti_probe(struct amba_device *adev, const struct amba_id
> *id)
> >  {
> > @@ -973,6 +984,8

Re: [PATCH v10 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure

2020-09-10 Thread Tingwei Zhang
On Fri, Sep 11, 2020 at 06:28:40AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 21, 2020 at 11:44:29AM +0800, Tingwei Zhang wrote:
> > When coresight_build_path() fails on all the cpus, etm_setup_aux
> > calls etm_free_aux() to free allocated event_data.
> > WARN_ON(cpumask_empty(mask) will be triggered since cpu mask is empty.
> > Check event_data->snk_config is not NULL first to avoid this
> > warning.
> > 
> > Signed-off-by: Tingwei Zhang 
> > Reviewed-by: Mike Leach 
> > Reviewed-by: Suzuki K Poulose 
> > Reviewed-by: Mathieu Poirier 
> 
> What happend to the Fixed tag that was in V8?  This is casting doubts on
> the
> reset of this set.  
> 
Hi Mathieu,

Sorry about the mess here. I pushed the change to Android mainline and missed
fix tag when making V10.

To make sure there's no other missing, I compared all V8 and V10 patches and
rechecked all comments on V8.

Two issues were found.
1. Reviewed-by from you on [patch 5/24] should not be added.
2. MODULE_LICENSE("GPL v2") was missed in V10.

I'll fix all issues on V11.

Shall I send V11 when it's ready or wait for your comments on other patches?

Thanks,
Tingwei

> > ---
> >  drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c
> b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > index dcb0592418ae..3728c44e5763 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > @@ -126,10 +126,10 @@ static void free_sink_buffer(struct etm_event_data
> *event_data)
> > cpumask_t *mask = _data->mask;
> > struct coresight_device *sink;
> >  
> > -   if (WARN_ON(cpumask_empty(mask)))
> > +   if (!event_data->snk_config)
> > return;
> >  
> > -   if (!event_data->snk_config)
> > +   if (WARN_ON(cpumask_empty(mask)))
> > return;
> >  
> > cpu = cpumask_first(mask);
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 


Re: [PATCH v10 04/24] coresight: add coresight prefix to barrier_pkt

2020-09-10 Thread Tingwei Zhang
On Fri, Sep 11, 2020 at 06:19:18AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 21, 2020 at 11:44:25AM +0800, Tingwei Zhang wrote:
> > Add coresight prefix to make it specific. It will be a export symbol.
> > 
> > Signed-off-by: Mian Yousaf Kaukab 
> > Signed-off-by: Tingwei Zhang 
> > Reviewed-by: Suzuki K Poulose 
> > Reviewed-by: Mathieu Poirier 
> > ---
> >  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 | 2 +-
> >  4 files changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-etb10.c
> b/drivers/hwtracing/coresight/coresight-etb10.c
> > index 03e3f2590191..04ee9cda988d 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 d801a2755432..dcb8aeb6af62 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);
> 
> Didn't I comment on this before?
> 
Sorry for missing below comment from you, Mathieu.
Indentation problem.

I'll fix it in v11.

Thanks,
Tingwei

> >  }
> >  
> > -
> >  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 6375504ba8b0..44402d413ebb 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 e9c90f2de34a..d515088cc47d 100644
> > --- a/drivers/hwtracing/coresight/coresight.c
> > +++ b/drivers/hwtracing/coresight/coresight.c
> > @@ -53,7 +53,7 @@ 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] = {0x7fff, 0x7fff, 0x7fff,
> 0x7fff};
> > +const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff,
> 0x7fff, 0x7fff};
> >  
> >  static int coresight_id_match(struct device *dev, void *data)
> >  {
> > -- 
> > 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-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


Re: [PATCH v9 00/24] coresight: allow to build coresight as modules

2020-09-09 Thread Tingwei Zhang
On Thu, Sep 10, 2020 at 04:45:52AM +0800, ts...@codeaurora.org wrote:
> On 2020-09-09 09:15, Mathieu Poirier wrote:
> >On Wed, Sep 09, 2020 at 02:54:33AM +, Tingwei Zhang wrote:
> >>On Wed, Sep 09, 2020 at 01:53:51AM +0800, Mathieu Poirier wrote:
> >>> Hi Tingwei,
> >>>
> >>> Apologies for the untimely response to this set, I am hoping to get
> to
> >>> it in the next two weeks.
> >>>
> >>
> >>It's fine, Mathieu. Please let me know your comments once you have time.
> >>I'm targeting to get these set merged in 5.10 Kernel.
> >
> >From the above it is not clear if you want this set to be _in_ the 5.10
> >cycle
> >or added to my list _during_ the 5.10 cycle, which would make it part of
> >the
> >5.11 cycle.  In any case the latter seems more realistic.
> 
> Tingwei can correct me here, but we prefer to have patches to be part of the
> 5.10 release. It means they should get merged in Linus's tree in the next
> merge window.

Yes.  The target is to merge this series into Linus's tree in 5.10 Kernel.

Thanks,
Tingwei

> 
> ---Trilok Soni


Re: [PATCH v9 00/24] coresight: allow to build coresight as modules

2020-09-08 Thread Tingwei Zhang
On Wed, Sep 09, 2020 at 01:53:51AM +0800, Mathieu Poirier wrote:
> Hi Tingwei,
> 
> Apologies for the untimely response to this set, I am hoping to get to
> it in the next two weeks.
>

It's fine, Mathieu. Please let me know your comments once you have time.
I'm targeting to get these set merged in 5.10 Kernel.
 
> Thanks,
> Mathieu
> 
> On Wed, 19 Aug 2020 at 23:47, Tingwei Zhang 
> wrote:
> >
> > 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
> >
> > Change from v8:
> > Protect etmdrvdata[] by modifying it on relevant CPU  (Mathieu and
> Suzuki)
> > Grab the device before allocating memory for the node (Mathieu)
> > Add author of coresight core driver (Mathieu)
> >
> > Change from v7:
> > Depends on below change for ETM hotplug (Sai)
> >
> https://lore.kernel.org/linux-arm-kernel/20200729051310.18436-1-saiprakash
> .ran...@codeaurora.org/
> > Add mutex lock to protect etmdrvdata[] (Suzuki)
> > Add helper function coresight_get_ref() (Suzuki)
> > Reorg replicator and funnel change. Use two patches to support these
> > two drivers. (Suzuki)
> > Add fix tag to "coresight: etm: perf: Fix warning caused by
> etm_setup_aux
> > failure" (Suzuki)
> > Update author of "coresight: cti: Fix bug clearing sysfs links on
> callback"
> >
> > Change from v6:
> > Correct module description for CATU (Mike)
> > Check ect_ret equals 0 and set ect_enabled flag (Mike)
> > Add Tested-by and Reviewed-by from Mike
> >
> > Change from v5:
> > Add below CTI clean up change from Mike into series
> >  -https://lists.linaro.org/pipermail/coresight/2020-July/004349.html
> > Increase module reference count when enabling CTI device (Mike)
> >
> > Change from v4:
> > Fix error handling in coresight_grab_devicei() (Greg)
> > Add coresight: cti: Fix remove sysfs link error from Mike
> >  -https://lists.linaro.org/pipermail/coresight/2020-July/004275.html
> > Move cti_remove_conn_xrefs() into cti_remove() (Mike)
> > Align patch subject to coresight: :  (Mike)
> >
> > Change from v3:
> > Rebase to coresight-next (Mike and Mathieu)
> > Reorder try_get_module() (Suzuki)
> > Clean up etmdrvdata[] in device remote path (Mike)
> > Move cti_remove_conn_xrefs to cti_remove (Mike)
> >
> > Change from v2:
> > Rebase to 5.8-rc5. Export coresight_add_sysfs_link and
> > coresight_remove_sysfs_link
> > Fix one cut and paste error on MODULE_DESCRIPTION of CTI
> >
> > Change from v1:
> > Use try_module_get() to avoid module to be unloaded when device is used
> > in active trace session. (Mathieu P)
> >
> > Change from above two series.
> > 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 (8):
> >   coresight: use IS_ENABLED for CONFIGs that may be modules
> >   coresight: etm3x: allow etm3x to be built as a module
> >   coresight: etm4x: allow etm4x to be built as a module
> >   coresight: etb: allow etb to be built as a module
> >   coresight: tpiu: allow tpiu to be built as a module
> >   coresight: tmc: allow tmc to be built as a module
> >   coresight: allow funnel driver to be built as module
> >   coresight: allow replicator driver to be built as module
> >
> > Mian Yousaf Kaukab (2):
> >   coresight: export global symbols
> >   coresight: tmc-etr: add function to register catu ops
> >
> > Mike Leach (2):
> >   coresight: cti: Fix remove sysfs link error
> >   coresight: cti: Fix bug clearing sysfs links on callback
> >
> > Tingwei Zhang (12):
> >   coresight: cpu_debug: add module name in Kconfig
> >   coresight: cpu_debug: define MODULE_DEVICE_TABLE
> >   coresight: add coresight prefix to barrier_pkt
> >   coresight: add try_get_module() in coresight_grab_device()
> >   coresight: stm: allow to build coresight-stm as a module
> >   coresight: etm: perf: Fix warning caused by etm_setup_aux failure
> >   coresight: cti: add function to register cti associate ops
> >   coresight: cti: don't disable ect device if it's not enabled
&g

[PATCH v3 0/6] tracing: export event trace and trace_marker

2020-09-02 Thread Tingwei Zhang
Ftrace has ability to export trace packets to other destination.
Currently, only function trace can be exported. This series extends the
support to event trace and trace_maker. STM is one possible destination to
export ftrace. Use separate channel for each CPU to avoid mixing up packets
from different CPUs together.

Change from v2:
Change flag definition to BIT(). (Steven)
Add comment in stm_ftrace_write() to clarify it's safe to use 
smp_processor_id() here since preempt is disabled. (Steven) 

Change from v1:
All changes are suggested by Steven Rostedt.
User separate flag to control function trace, event trace and trace mark.
Allocate channels according to num_possible_cpu() dynamically.
Move ftrace_exports routines up so all ftrace can use them.

Tingwei Zhang (6):
  stm class: ftrace: change dependency to TRACING
  tracing: add flag to control different traces
  tracing: add trace_export support for event trace
  tracing: add trace_export support for trace_marker
  stm class: ftrace: enable supported trace export flag
  stm class: ftrace: use different channel accroding to CPU

 drivers/hwtracing/stm/Kconfig  |   2 +-
 drivers/hwtracing/stm/ftrace.c |   7 +-
 include/linux/trace.h  |   7 +
 kernel/trace/trace.c   | 270 ++---
 4 files changed, 159 insertions(+), 127 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v3 6/6] stm class: ftrace: use different channel accroding to CPU

2020-09-02 Thread Tingwei Zhang
To avoid mixup of packets from differnt ftrace packets simultaneously,
use different channel for packets from different CPU.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 drivers/hwtracing/stm/ftrace.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/stm/ftrace.c b/drivers/hwtracing/stm/ftrace.c
index c694a6e692d1..ebf29489919c 100644
--- a/drivers/hwtracing/stm/ftrace.c
+++ b/drivers/hwtracing/stm/ftrace.c
@@ -37,8 +37,10 @@ static void notrace
 stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int 
len)
 {
struct stm_ftrace *stm = container_of(export, struct stm_ftrace, 
ftrace);
+   /* This is called from trace system with preemption disabled */
+   unsigned int cpu = smp_processor_id();
 
-   stm_source_write(>data, STM_FTRACE_CHAN, buf, len);
+   stm_source_write(>data, STM_FTRACE_CHAN + cpu, buf, len);
 }
 
 static int stm_ftrace_link(struct stm_source_data *data)
@@ -63,6 +65,7 @@ static int __init stm_ftrace_init(void)
 {
int ret;
 
+   stm_ftrace.data.nr_chans = num_possible_cpus();
ret = stm_source_register_device(NULL, _ftrace.data);
if (ret)
pr_err("Failed to register stm_source - ftrace.\n");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v3 2/6] tracing: add flag to control different traces

2020-09-02 Thread Tingwei Zhang
More traces like event trace or trace marker will be supported.
Add flag for difference traces, so that they can be controlled
separately. Move current function trace to it's own flag
instead of global ftrace enable flag.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 include/linux/trace.h |  5 +
 kernel/trace/trace.c  | 36 +++-
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/include/linux/trace.h b/include/linux/trace.h
index 7fd86d3c691f..bc93063dda39 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -3,6 +3,9 @@
 #define _LINUX_TRACE_H
 
 #ifdef CONFIG_TRACING
+
+#define TRACE_EXPORT_FUNCTION  BIT(0)
+
 /*
  * The trace export - an export of Ftrace output. The trace_export
  * can process traces and export them to a registered destination as
@@ -15,10 +18,12 @@
  * next- pointer to the next trace_export
  * write   - copy traces which have been delt with ->commit() to
  *   the destination
+ * flags   - which ftrace to be exported
  */
 struct trace_export {
struct trace_export __rcu   *next;
void (*write)(struct trace_export *, const void *, unsigned int);
+   int flags;
 };
 
 int register_ftrace_export(struct trace_export *export);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index bb62269724d5..8f1e66831e9e 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2747,33 +2747,37 @@ trace_buffer_unlock_commit_nostack(struct trace_buffer 
*buffer,
 
 static void
 trace_process_export(struct trace_export *export,
-  struct ring_buffer_event *event)
+  struct ring_buffer_event *event, int flag)
 {
struct trace_entry *entry;
unsigned int size = 0;
 
-   entry = ring_buffer_event_data(event);
-   size = ring_buffer_event_length(event);
-   export->write(export, entry, size);
+   if (export->flags & flag) {
+   entry = ring_buffer_event_data(event);
+   size = ring_buffer_event_length(event);
+   export->write(export, entry, size);
+   }
 }
 
 static DEFINE_MUTEX(ftrace_export_lock);
 
 static struct trace_export __rcu *ftrace_exports_list __read_mostly;
 
-static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);
+static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
 
-static inline void ftrace_exports_enable(void)
+static inline void ftrace_exports_enable(struct trace_export *export)
 {
-   static_branch_enable(_exports_enabled);
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_inc(_function_exports_enabled);
 }
 
-static inline void ftrace_exports_disable(void)
+static inline void ftrace_exports_disable(struct trace_export *export)
 {
-   static_branch_disable(_exports_enabled);
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_dec(_function_exports_enabled);
 }
 
-static void ftrace_exports(struct ring_buffer_event *event)
+static void ftrace_exports(struct ring_buffer_event *event, int flag)
 {
struct trace_export *export;
 
@@ -2781,7 +2785,7 @@ static void ftrace_exports(struct ring_buffer_event 
*event)
 
export = rcu_dereference_raw_check(ftrace_exports_list);
while (export) {
-   trace_process_export(export, event);
+   trace_process_export(export, event, flag);
export = rcu_dereference_raw_check(export->next);
}
 
@@ -2821,8 +2825,7 @@ rm_trace_export(struct trace_export **list, struct 
trace_export *export)
 static inline void
 add_ftrace_export(struct trace_export **list, struct trace_export *export)
 {
-   if (*list == NULL)
-   ftrace_exports_enable();
+   ftrace_exports_enable(export);
 
add_trace_export(list, export);
 }
@@ -2833,8 +2836,7 @@ rm_ftrace_export(struct trace_export **list, struct 
trace_export *export)
int ret;
 
ret = rm_trace_export(list, export);
-   if (*list == NULL)
-   ftrace_exports_disable();
+   ftrace_exports_disable(export);
 
return ret;
 }
@@ -2887,8 +2889,8 @@ trace_function(struct trace_array *tr,
entry->parent_ip= parent_ip;
 
if (!call_filter_check_discard(call, entry, buffer, event)) {
-   if (static_branch_unlikely(_exports_enabled))
-   ftrace_exports(event);
+   if (static_branch_unlikely(_function_exports_enabled))
+   ftrace_exports(event, TRACE_EXPORT_FUNCTION);
__buffer_unlock_commit(buffer, event);
}
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v3 5/6] stm class: ftrace: enable supported trace export flag

2020-09-02 Thread Tingwei Zhang
Set flags for trace_export. Export function trace, event trace
and trace marker to stm.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 drivers/hwtracing/stm/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwtracing/stm/ftrace.c b/drivers/hwtracing/stm/ftrace.c
index ce868e095410..c694a6e692d1 100644
--- a/drivers/hwtracing/stm/ftrace.c
+++ b/drivers/hwtracing/stm/ftrace.c
@@ -46,6 +46,8 @@ static int stm_ftrace_link(struct stm_source_data *data)
struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
 
sf->ftrace.write = stm_ftrace_write;
+   sf->ftrace.flags = TRACE_EXPORT_FUNCTION | TRACE_EXPORT_EVENT
+   | TRACE_EXPORT_MARKER;
 
return register_ftrace_export(>ftrace);
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v3 1/6] stm class: ftrace: change dependency to TRACING

2020-09-02 Thread Tingwei Zhang
We will support copying event trace to STM. Change
STM_SOURCE_FTRACE to depend on TRACING since we will
support multiple tracers.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 drivers/hwtracing/stm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/stm/Kconfig b/drivers/hwtracing/stm/Kconfig
index d0e92a8a045c..aad594fe79cc 100644
--- a/drivers/hwtracing/stm/Kconfig
+++ b/drivers/hwtracing/stm/Kconfig
@@ -71,7 +71,7 @@ config STM_SOURCE_HEARTBEAT
 
 config STM_SOURCE_FTRACE
tristate "Copy the output from kernel Ftrace to STM engine"
-   depends on FUNCTION_TRACER
+   depends on TRACING
help
  This option can be used to copy the output from kernel Ftrace
  to STM engine. Enabling this option will introduce a slight
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v3 4/6] tracing: add trace_export support for trace_marker

2020-09-02 Thread Tingwei Zhang
Add the support to route trace_marker buffer to other destination
via trace_export.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 include/linux/trace.h | 1 +
 kernel/trace/trace.c  | 9 +
 2 files changed, 10 insertions(+)

diff --git a/include/linux/trace.h b/include/linux/trace.h
index 5a01eeffb254..80b7df68bc0f 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -6,6 +6,7 @@
 
 #define TRACE_EXPORT_FUNCTION  BIT(0)
 #define TRACE_EXPORT_EVENT BIT(1)
+#define TRACE_EXPORT_MARKERBIT(2)
 
 /*
  * The trace export - an export of Ftrace output. The trace_export
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2f9302a8b322..67993abda394 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -271,6 +271,7 @@ static struct trace_export __rcu *ftrace_exports_list 
__read_mostly;
 
 static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
 static DEFINE_STATIC_KEY_FALSE(trace_event_exports_enabled);
+static DEFINE_STATIC_KEY_FALSE(trace_marker_exports_enabled);
 
 static inline void ftrace_exports_enable(struct trace_export *export)
 {
@@ -279,6 +280,9 @@ static inline void ftrace_exports_enable(struct 
trace_export *export)
 
if (export->flags & TRACE_EXPORT_EVENT)
static_branch_inc(_event_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_MARKER)
+   static_branch_inc(_marker_exports_enabled);
 }
 
 static inline void ftrace_exports_disable(struct trace_export *export)
@@ -288,6 +292,9 @@ static inline void ftrace_exports_disable(struct 
trace_export *export)
 
if (export->flags & TRACE_EXPORT_EVENT)
static_branch_dec(_event_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_MARKER)
+   static_branch_dec(_marker_exports_enabled);
 }
 
 static void ftrace_exports(struct ring_buffer_event *event, int flag)
@@ -6648,6 +6655,8 @@ tracing_mark_write(struct file *filp, const char __user 
*ubuf,
} else
entry->buf[cnt] = '\0';
 
+   if (static_branch_unlikely(_marker_exports_enabled))
+   ftrace_exports(event, TRACE_EXPORT_MARKER);
__buffer_unlock_commit(buffer, event);
 
if (tt)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v3 3/6] tracing: add trace_export support for event trace

2020-09-02 Thread Tingwei Zhang
Only function traces can be exported to other destinations currently.
This patch exports event trace as well. Move trace export related
function to the beginning of file so other trace can call
trace_process_export() to export.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Steven Rostedt (VMware) 
---
 include/linux/trace.h |   1 +
 kernel/trace/trace.c  | 259 ++
 2 files changed, 135 insertions(+), 125 deletions(-)

diff --git a/include/linux/trace.h b/include/linux/trace.h
index bc93063dda39..5a01eeffb254 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -5,6 +5,7 @@
 #ifdef CONFIG_TRACING
 
 #define TRACE_EXPORT_FUNCTION  BIT(0)
+#define TRACE_EXPORT_EVENT BIT(1)
 
 /*
  * The trace export - an export of Ftrace output. The trace_export
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8f1e66831e9e..2f9302a8b322 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -251,6 +251,138 @@ unsigned long long ns2usecs(u64 nsec)
return nsec;
 }
 
+static void
+trace_process_export(struct trace_export *export,
+  struct ring_buffer_event *event, int flag)
+{
+   struct trace_entry *entry;
+   unsigned int size = 0;
+
+   if (export->flags & flag) {
+   entry = ring_buffer_event_data(event);
+   size = ring_buffer_event_length(event);
+   export->write(export, entry, size);
+   }
+}
+
+static DEFINE_MUTEX(ftrace_export_lock);
+
+static struct trace_export __rcu *ftrace_exports_list __read_mostly;
+
+static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
+static DEFINE_STATIC_KEY_FALSE(trace_event_exports_enabled);
+
+static inline void ftrace_exports_enable(struct trace_export *export)
+{
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_inc(_function_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_EVENT)
+   static_branch_inc(_event_exports_enabled);
+}
+
+static inline void ftrace_exports_disable(struct trace_export *export)
+{
+   if (export->flags & TRACE_EXPORT_FUNCTION)
+   static_branch_dec(_function_exports_enabled);
+
+   if (export->flags & TRACE_EXPORT_EVENT)
+   static_branch_dec(_event_exports_enabled);
+}
+
+static void ftrace_exports(struct ring_buffer_event *event, int flag)
+{
+   struct trace_export *export;
+
+   preempt_disable_notrace();
+
+   export = rcu_dereference_raw_check(ftrace_exports_list);
+   while (export) {
+   trace_process_export(export, event, flag);
+   export = rcu_dereference_raw_check(export->next);
+   }
+
+   preempt_enable_notrace();
+}
+
+static inline void
+add_trace_export(struct trace_export **list, struct trace_export *export)
+{
+   rcu_assign_pointer(export->next, *list);
+   /*
+* We are entering export into the list but another
+* CPU might be walking that list. We need to make sure
+* the export->next pointer is valid before another CPU sees
+* the export pointer included into the list.
+*/
+   rcu_assign_pointer(*list, export);
+}
+
+static inline int
+rm_trace_export(struct trace_export **list, struct trace_export *export)
+{
+   struct trace_export **p;
+
+   for (p = list; *p != NULL; p = &(*p)->next)
+   if (*p == export)
+   break;
+
+   if (*p != export)
+   return -1;
+
+   rcu_assign_pointer(*p, (*p)->next);
+
+   return 0;
+}
+
+static inline void
+add_ftrace_export(struct trace_export **list, struct trace_export *export)
+{
+   ftrace_exports_enable(export);
+
+   add_trace_export(list, export);
+}
+
+static inline int
+rm_ftrace_export(struct trace_export **list, struct trace_export *export)
+{
+   int ret;
+
+   ret = rm_trace_export(list, export);
+   ftrace_exports_disable(export);
+
+   return ret;
+}
+
+int register_ftrace_export(struct trace_export *export)
+{
+   if (WARN_ON_ONCE(!export->write))
+   return -1;
+
+   mutex_lock(_export_lock);
+
+   add_ftrace_export(_exports_list, export);
+
+   mutex_unlock(_export_lock);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(register_ftrace_export);
+
+int unregister_ftrace_export(struct trace_export *export)
+{
+   int ret;
+
+   mutex_lock(_export_lock);
+
+   ret = rm_ftrace_export(_exports_list, export);
+
+   mutex_unlock(_export_lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(unregister_ftrace_export);
+
 /* trace_flags holds trace_options default values */
 #define TRACE_DEFAULT_FLAGS\
(FUNCTION_DEFAULT_FLAGS |   \
@@ -2702,6 +2834,8 @@ void trace_event_buffer_commit(struct trace_event_buffer 
*fbuffer)
if (static_key_false(_printk_key.key))

Re: [PATCH v3 0/6] tracing: export event trace and trace_marker

2020-09-01 Thread Tingwei Zhang
Hi Alexander,

May I know your comments for this patch set?

Thanks,
Tingwei

On Thu, Aug 13, 2020 at 09:45:46AM +0800, Tingwei Zhang wrote:
> Ftrace has ability to export trace packets to other destination.
> Currently, only function trace can be exported. This series extends the
> support to event trace and trace_maker. STM is one possible destination to
> export ftrace. Use separate channel for each CPU to avoid mixing up
> packets
> from different CPUs together.
> 
> Change from v2:
> Change flag definition to BIT(). (Steven)
> Add comment in stm_ftrace_write() to clarify it's safe to use 
> smp_processor_id() here since preempt is disabled. (Steven) 
> 
> Change from v1:
> All changes are suggested by Steven Rostedt.
> User separate flag to control function trace, event trace and trace mark.
> Allocate channels according to num_possible_cpu() dynamically.
> Move ftrace_exports routines up so all ftrace can use them.
> 
> Tingwei Zhang (6):
>   stm class: ftrace: change dependency to TRACING
>   tracing: add flag to control different traces
>   tracing: add trace_export support for event trace
>   tracing: add trace_export support for trace_marker
>   stm class: ftrace: enable supported trace export flag
>   stm class: ftrace: use different channel accroding to CPU
> 
>  drivers/hwtracing/stm/Kconfig  |   2 +-
>  drivers/hwtracing/stm/ftrace.c |   7 +-
>  include/linux/trace.h  |   7 +
>  kernel/trace/trace.c   | 270 ++---
>  4 files changed, 159 insertions(+), 127 deletions(-)
> 
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 


Re: [PATCH v3 0/6] tracing: export event trace and trace_marker

2020-09-01 Thread Tingwei Zhang
On Wed, Sep 02, 2020 at 01:05:49AM +0800, Mathieu Poirier wrote:
> On Tue, Sep 01, 2020 at 02:37:40PM +0800, Tingwei Zhang wrote:
> > Hi Mathieu,
> > 
> > May I know your comments for this patch set?
> 
> I do not maintain any of these files.
> 
Sorry for my wrong assumption.

> > 
> > Thanks,
> > Tingwei
> > 
> > On Thu, Aug 13, 2020 at 09:45:46AM +0800, Tingwei Zhang wrote:
> > > Ftrace has ability to export trace packets to other destination.
> > > Currently, only function trace can be exported. This series extends
> the
> > > support to event trace and trace_maker. STM is one possible
> destination to
> > > export ftrace. Use separate channel for each CPU to avoid mixing up
> > > packets
> > > from different CPUs together.
> > > 
> > > Change from v2:
> > > Change flag definition to BIT(). (Steven)
> > > Add comment in stm_ftrace_write() to clarify it's safe to use 
> > > smp_processor_id() here since preempt is disabled. (Steven) 
> > > 
> > > Change from v1:
> > > All changes are suggested by Steven Rostedt.
> > > User separate flag to control function trace, event trace and trace
> mark.
> > > Allocate channels according to num_possible_cpu() dynamically.
> > > Move ftrace_exports routines up so all ftrace can use them.
> > > 
> > > Tingwei Zhang (6):
> > >   stm class: ftrace: change dependency to TRACING
> > >   tracing: add flag to control different traces
> > >   tracing: add trace_export support for event trace
> > >   tracing: add trace_export support for trace_marker
> > >   stm class: ftrace: enable supported trace export flag
> > >   stm class: ftrace: use different channel accroding to CPU
> > > 
> > >  drivers/hwtracing/stm/Kconfig  |   2 +-
> > >  drivers/hwtracing/stm/ftrace.c |   7 +-
> > >  include/linux/trace.h  |   7 +
> > >  kernel/trace/trace.c   | 270
> ++---
> > >  4 files changed, 159 insertions(+), 127 deletions(-)
> > > 
> > > -- 
> > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > > a Linux Foundation Collaborative Project
> > > 


Re: [PATCH v3 0/6] tracing: export event trace and trace_marker

2020-09-01 Thread Tingwei Zhang
Hi Mathieu,

May I know your comments for this patch set?

Thanks,
Tingwei

On Thu, Aug 13, 2020 at 09:45:46AM +0800, Tingwei Zhang wrote:
> Ftrace has ability to export trace packets to other destination.
> Currently, only function trace can be exported. This series extends the
> support to event trace and trace_maker. STM is one possible destination to
> export ftrace. Use separate channel for each CPU to avoid mixing up
> packets
> from different CPUs together.
> 
> Change from v2:
> Change flag definition to BIT(). (Steven)
> Add comment in stm_ftrace_write() to clarify it's safe to use 
> smp_processor_id() here since preempt is disabled. (Steven) 
> 
> Change from v1:
> All changes are suggested by Steven Rostedt.
> User separate flag to control function trace, event trace and trace mark.
> Allocate channels according to num_possible_cpu() dynamically.
> Move ftrace_exports routines up so all ftrace can use them.
> 
> Tingwei Zhang (6):
>   stm class: ftrace: change dependency to TRACING
>   tracing: add flag to control different traces
>   tracing: add trace_export support for event trace
>   tracing: add trace_export support for trace_marker
>   stm class: ftrace: enable supported trace export flag
>   stm class: ftrace: use different channel accroding to CPU
> 
>  drivers/hwtracing/stm/Kconfig  |   2 +-
>  drivers/hwtracing/stm/ftrace.c |   7 +-
>  include/linux/trace.h  |   7 +
>  kernel/trace/trace.c   | 270 ++---
>  4 files changed, 159 insertions(+), 127 deletions(-)
> 
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 


Re: [PATCH] coresight: cti: write regsiters directly in cti_enable_hw()

2020-09-01 Thread Tingwei Zhang
On Tue, Sep 01, 2020 at 04:28:19AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 28, 2020 at 11:18:18AM +0800, Tingwei Zhang wrote:
> > On Fri, Aug 28, 2020 at 02:12:53AM +0800, Mathieu Poirier wrote:
> > > Hi Tingwei,
> > > 
> > > On Tue, Aug 18, 2020 at 07:10:57PM +0800, Tingwei Zhang wrote:
> > > > Deadlock as below is triggered by one CPU holds drvdata->spinlock
> > > > and calls cti_enable_hw(). Smp_call_function_single() is called
> > > > in cti_enable_hw() and tries to let another CPU write CTI registers.
> > > > That CPU is trying to get drvdata->spinlock in cti_cpu_pm_notify()
> > > > and doesn't response to IPI from smp_call_function_single().
> > > > 
> > > > [  988.335937] CPU: 6 PID: 10258 Comm: sh Tainted: GWL
> > > > 5.8.0-rc6-mainline-16783-gc38daa79b26b-dirty #1
> > > > [  988.346364] Hardware name: Thundercomm Dragonboard 845c (DT)
> > > > [  988.352073] pstate: 2045 (nzCv daif +PAN -UAO BTYPE=--)
> > > > [  988.357689] pc : smp_call_function_single+0x158/0x1b8
> > > > [  988.362782] lr : smp_call_function_single+0x124/0x1b8
> > > > ...
> > > > [  988.451638] Call trace:
> > > > [  988.454119]  smp_call_function_single+0x158/0x1b8
> > > > [  988.458866]  cti_enable+0xb4/0xf8 [coresight_cti]
> > > > [  988.463618]  coresight_control_assoc_ectdev+0x6c/0x128
> [coresight]
> > > > [  988.469855]  coresight_enable+0x1f0/0x364 [coresight]
> > > > [  988.474957]  enable_source_store+0x5c/0x9c [coresight]
> > > > [  988.480140]  dev_attr_store+0x14/0x28
> > > > [  988.483839]  sysfs_kf_write+0x38/0x4c
> > > > [  988.487532]  kernfs_fop_write+0x1c0/0x2b0
> > > > [  988.491585]  vfs_write+0xfc/0x300
> > > > [  988.494931]  ksys_write+0x78/0xe0
> > > > [  988.498283]  __arm64_sys_write+0x18/0x20
> > > > [  988.502240]  el0_svc_common+0x98/0x160
> > > > [  988.506024]  do_el0_svc+0x78/0x80
> > > > [  988.509377]  el0_sync_handler+0xd4/0x270
> > > > [  988.513337]  el0_sync+0x164/0x180
> > > > 
> > > 
> > > Was this the full log or you did cut some of it?
> > > 
> > 
> > I cut some CPU registers' value since it's too long and not relevant.
> > The Call trace is full.
> > 
> > > > This change write CTI registers directly in cti_enable_hw().
> > > > Config->hw_powered has been checked to be true with spinlock holded.
> > > > CTI is powered and can be programmed until spinlock is released.
> > > > 
> > > 
> > > From your explanation above it seems that cti_enable_hw() was called
> from,
> > > say
> > > CPUy, to enable the CTI associated to CPUx.  CTIx's drvdata->spinlock
> was
> > > taken
> > > and smp_call_function_single() called right after.  That woke up CPUx
> and
> > > cti_cpu_pm_notify() was executed on CPUx in interrupt context, trying
> to
> > > take
> > > CTIx's drvdata->spinlock.  That hung CPUx and the kernel got angry.
> Is my
> > > assessment correct?
> > > 
> > 
> > Most of them is correct. The only difference is CPUx is power on when
> > cti_enable_hw() is called.  Otherwise it will goto cti_state_unchanged:
> > and won't call cti_enable_hw_smp_call(). cti_cpu_pm_notify() is called
> > when CPUx tries to suspend instead of resume.
> > 
> > > If so I don't think the fix suggested in this patch will work.  The
> same
> > > condition will happen whenever cti_enable_hw() is called on a CPU to
> > > enable a
> > > CTI that belongs to another CPU and that cti_cpu_pm_notify() is called
> on
> > > latter
> > > CPU at the same time.
> > > 
> > 
> > I'm not sure I understand this correctly.  Let me clarify it a little
> bit.
> > It's a deadlock since cti_enable_hw() holds the spinlock and calls
> > cti_enable_hw_smp_call() from CPUx to enable CTI associated to CPUy. It
> > waits for cti_enable_hw_smp_call() to return. IPI is sent to CPUy while
> > CPUy is in cti_cpu_pm_notify() and waits for spinlock. In this patch,
> > I remove cti_enable_hw_smp_call() and write CTI CPU directly on CPUx.
> > It won't wait for CPUy and release spinlock after program registers of
> > CTI. After cti_enable_hw() releases spinlock, cti_cpu_pm_notify() will
> > continue to run. Since spinlock is held and config->hw_powered is true,
> > we don't need to worry about CPUy power down when we program CTI on
> CPUx.

[PATCH v2] coresight: cti: write regsiters directly in cti_enable_hw()

2020-09-01 Thread Tingwei Zhang
Deadlock as below is triggered by one CPU holds drvdata->spinlock
and calls cti_enable_hw(). Smp_call_function_single() is called
in cti_enable_hw() and tries to let another CPU write CTI registers.
That CPU is trying to get drvdata->spinlock in cti_cpu_pm_notify()
and doesn't response to IPI from smp_call_function_single().

[  988.335937] CPU: 6 PID: 10258 Comm: sh Tainted: GWL
5.8.0-rc6-mainline-16783-gc38daa79b26b-dirty #1
[  988.346364] Hardware name: Thundercomm Dragonboard 845c (DT)
[  988.352073] pstate: 2045 (nzCv daif +PAN -UAO BTYPE=--)
[  988.357689] pc : smp_call_function_single+0x158/0x1b8
[  988.362782] lr : smp_call_function_single+0x124/0x1b8
...
[  988.451638] Call trace:
[  988.454119]  smp_call_function_single+0x158/0x1b8
[  988.458866]  cti_enable+0xb4/0xf8 [coresight_cti]
[  988.463618]  coresight_control_assoc_ectdev+0x6c/0x128 [coresight]
[  988.469855]  coresight_enable+0x1f0/0x364 [coresight]
[  988.474957]  enable_source_store+0x5c/0x9c [coresight]
[  988.480140]  dev_attr_store+0x14/0x28
[  988.483839]  sysfs_kf_write+0x38/0x4c
[  988.487532]  kernfs_fop_write+0x1c0/0x2b0
[  988.491585]  vfs_write+0xfc/0x300
[  988.494931]  ksys_write+0x78/0xe0
[  988.498283]  __arm64_sys_write+0x18/0x20
[  988.502240]  el0_svc_common+0x98/0x160
[  988.506024]  do_el0_svc+0x78/0x80
[  988.509377]  el0_sync_handler+0xd4/0x270
[  988.513337]  el0_sync+0x164/0x180

This change write CTI registers directly in cti_enable_hw().
Config->hw_powered has been checked to be true with spinlock holded.
CTI is powered and can be programmed until spinlock is released.

Fixes: 6a0953ce7de9 ("coresight: cti: Add CPU idle pm notifer to CTI devices")
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight-cti.c | 24 +
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index c4e9cc7034ab..d04181c12a7f 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -86,22 +86,16 @@ void cti_write_all_hw_regs(struct cti_drvdata *drvdata)
CS_LOCK(drvdata->base);
 }
 
-static void cti_enable_hw_smp_call(void *info)
-{
-   struct cti_drvdata *drvdata = info;
-
-   cti_write_all_hw_regs(drvdata);
-}
-
 /* write regs to hardware and enable */
 static int cti_enable_hw(struct cti_drvdata *drvdata)
 {
struct cti_config *config = >config;
struct device *dev = >csdev->dev;
int rc = 0;
+   unsigned long flags;
 
pm_runtime_get_sync(dev->parent);
-   spin_lock(>spinlock);
+   spin_lock_irqsave(>spinlock, flags);
 
/* no need to do anything if enabled or unpowered*/
if (config->hw_enabled || !config->hw_powered)
@@ -112,19 +106,11 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
if (rc)
goto cti_err_not_enabled;
 
-   if (drvdata->ctidev.cpu >= 0) {
-   rc = smp_call_function_single(drvdata->ctidev.cpu,
- cti_enable_hw_smp_call,
- drvdata, 1);
-   if (rc)
-   goto cti_err_not_enabled;
-   } else {
-   cti_write_all_hw_regs(drvdata);
-   }
+   cti_write_all_hw_regs(drvdata);
 
config->hw_enabled = true;
atomic_inc(>config.enable_req_count);
-   spin_unlock(>spinlock);
+   spin_unlock_irqrestore(>spinlock, flags);
return rc;
 
 cti_state_unchanged:
@@ -132,7 +118,7 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
 
/* cannot enable due to error */
 cti_err_not_enabled:
-   spin_unlock(>spinlock);
+   spin_unlock_irqrestore(>spinlock, flags);
pm_runtime_put(dev->parent);
return rc;
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH] coresight: cti: write regsiters directly in cti_enable_hw()

2020-08-27 Thread Tingwei Zhang
On Fri, Aug 28, 2020 at 02:12:53AM +0800, Mathieu Poirier wrote:
> Hi Tingwei,
> 
> On Tue, Aug 18, 2020 at 07:10:57PM +0800, Tingwei Zhang wrote:
> > Deadlock as below is triggered by one CPU holds drvdata->spinlock
> > and calls cti_enable_hw(). Smp_call_function_single() is called
> > in cti_enable_hw() and tries to let another CPU write CTI registers.
> > That CPU is trying to get drvdata->spinlock in cti_cpu_pm_notify()
> > and doesn't response to IPI from smp_call_function_single().
> > 
> > [  988.335937] CPU: 6 PID: 10258 Comm: sh Tainted: GWL
> > 5.8.0-rc6-mainline-16783-gc38daa79b26b-dirty #1
> > [  988.346364] Hardware name: Thundercomm Dragonboard 845c (DT)
> > [  988.352073] pstate: 2045 (nzCv daif +PAN -UAO BTYPE=--)
> > [  988.357689] pc : smp_call_function_single+0x158/0x1b8
> > [  988.362782] lr : smp_call_function_single+0x124/0x1b8
> > ...
> > [  988.451638] Call trace:
> > [  988.454119]  smp_call_function_single+0x158/0x1b8
> > [  988.458866]  cti_enable+0xb4/0xf8 [coresight_cti]
> > [  988.463618]  coresight_control_assoc_ectdev+0x6c/0x128 [coresight]
> > [  988.469855]  coresight_enable+0x1f0/0x364 [coresight]
> > [  988.474957]  enable_source_store+0x5c/0x9c [coresight]
> > [  988.480140]  dev_attr_store+0x14/0x28
> > [  988.483839]  sysfs_kf_write+0x38/0x4c
> > [  988.487532]  kernfs_fop_write+0x1c0/0x2b0
> > [  988.491585]  vfs_write+0xfc/0x300
> > [  988.494931]  ksys_write+0x78/0xe0
> > [  988.498283]  __arm64_sys_write+0x18/0x20
> > [  988.502240]  el0_svc_common+0x98/0x160
> > [  988.506024]  do_el0_svc+0x78/0x80
> > [  988.509377]  el0_sync_handler+0xd4/0x270
> > [  988.513337]  el0_sync+0x164/0x180
> > 
> 
> Was this the full log or you did cut some of it?
> 

I cut some CPU registers' value since it's too long and not relevant.
The Call trace is full.

> > This change write CTI registers directly in cti_enable_hw().
> > Config->hw_powered has been checked to be true with spinlock holded.
> > CTI is powered and can be programmed until spinlock is released.
> > 
> 
> From your explanation above it seems that cti_enable_hw() was called from,
> say
> CPUy, to enable the CTI associated to CPUx.  CTIx's drvdata->spinlock was
> taken
> and smp_call_function_single() called right after.  That woke up CPUx and
> cti_cpu_pm_notify() was executed on CPUx in interrupt context, trying to
> take
> CTIx's drvdata->spinlock.  That hung CPUx and the kernel got angry.  Is my
> assessment correct?
> 

Most of them is correct. The only difference is CPUx is power on when
cti_enable_hw() is called.  Otherwise it will goto cti_state_unchanged:
and won't call cti_enable_hw_smp_call(). cti_cpu_pm_notify() is called
when CPUx tries to suspend instead of resume.

> If so I don't think the fix suggested in this patch will work.  The same
> condition will happen whenever cti_enable_hw() is called on a CPU to
> enable a
> CTI that belongs to another CPU and that cti_cpu_pm_notify() is called on
> latter
> CPU at the same time.
> 

I'm not sure I understand this correctly.  Let me clarify it a little bit.
It's a deadlock since cti_enable_hw() holds the spinlock and calls
cti_enable_hw_smp_call() from CPUx to enable CTI associated to CPUy. It
waits for cti_enable_hw_smp_call() to return. IPI is sent to CPUy while
CPUy is in cti_cpu_pm_notify() and waits for spinlock. In this patch,
I remove cti_enable_hw_smp_call() and write CTI CPU directly on CPUx.
It won't wait for CPUy and release spinlock after program registers of
CTI. After cti_enable_hw() releases spinlock, cti_cpu_pm_notify() will
continue to run. Since spinlock is held and config->hw_powered is true,
we don't need to worry about CPUy power down when we program CTI on CPUx.

> I think a better solution is to grab the lock in cti_enable_hw() and check
> the
> value of ->ctidev.cpu.  If not a global CPU, i.e >= 0, then release the
> lock and
> call smp_call_function_single().  In cti_enable_hw_smp_call() take the
> lock
> again and move forward from there. 
> 

After cti_enable_hw() releases the lock, it's possible that CPU is offline
by user, cti_enable_hw_smp_call() will fail in this case.



> I have applied the other two patches in this set so no need to send them
> again.
>
Thanks,
Tingwei 
> Thanks,
> Mathieu
> 
> > Fixes: 6a0953ce7de9 ("coresight: cti: Add CPU idle pm notifer to CTI
> devices")
> > Signed-off-by: Tingwei Zhang 
> > ---
> >  drivers/hwtracing/coresight/coresight-cti.c | 17 +
> >  1 file changed, 1 insertion(+), 16 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-cti.c
&g

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

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

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

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

[PATCH v10 22/24] coresight: tmc-etr: add function to register catu ops

2020-08-20 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

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 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 1801804a7762..47696a7d24a7 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,
@@ -582,4 +582,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(_driver);
+   if (ret)
+   pr_info("Error registering catu driver\n");
+   tmc_etr_set_catu_ops(_catu_buf_ops);
+   return ret;
+}
+
+static void __exit catu_exit(void)
+{
+   tmc_etr_remove_catu_ops();
+   amba_driver_unregister(_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 ad991a37e2d2..714f9e867e5f 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] = _flat_buf_ops,
[ETR_MODE_ETR_SG] = _sg_buf_ops,
-   [ETR_MODE_CATU] = IS_ENABLED(CONFIG_CORESIGHT_CATU)
-   ? _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 6e8d2dc33d17..b91ec7dde7bc 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -326,4 +326,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
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 23/24] coresight: catu: allow catu drivers to be built as modules

2020-08-20 Thread Tingwei Zhang
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 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 47696a7d24a7..99430f6cf5a5 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -567,11 +567,21 @@ 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(>dev);
+
+   coresight_unregister(drvdata->csdev);
+   return 0;
+}
+
 static struct amba_id catu_ids[] = {
CS_AMBA_ID(0x000bb9ee),
{},
 };
 
+MODULE_DEVICE_TABLE(amba, catu_ids);
+
 static struct amba_driver catu_driver = {
.drv = {
.name   = "coresight-catu",
@@ -579,6 +589,7 @@ static struct amba_driver catu_driver = {
.suppress_bind_attrs= true,
},
.probe  = catu_probe,
+   .remove = catu_remove,
.id_table   = catu_ids,
 };
 
@@ -601,3 +612,7 @@ static void __exit catu_exit(void)
 
 module_init(catu_init);
 module_exit(catu_exit);
+
+MODULE_AUTHOR("Suzuki K Poulose ");
+MODULE_DESCRIPTION("Arm CoreSight Address Translation Unit (CATU) Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 19/24] coresight: cti: don't disable ect device if it's not enabled

2020-08-20 Thread Tingwei Zhang
If associated ect device is not enabled at first place, disable
routine should not be called. Add ect_enabled flag to check whether
ect device is enabled. Fix the issue in below case.  Ect device is
not available when associated coresight device enabled and the
association is established after coresight device is enabled.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight.c | 11 ---
 include/linux/coresight.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 6c09be15d60c..d354fd57474e 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -244,13 +244,18 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 
if (!ect_csdev)
return 0;
+   if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
+   return 0;
 
if (enable) {
-   if (ect_ops(ect_csdev)->enable)
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (!ect_ret)
+   csdev->ect_enabled = true;
} else {
-   if (ect_ops(ect_csdev)->disable)
+   if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   csdev->ect_enabled = false;
+   }
}
 
/* output warning if ECT enable is preventing trace operation */
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 3bb738f9a326..7d3c87e5b97c 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -208,6 +208,7 @@ struct coresight_device {
/* sysfs links between components */
int nr_links;
bool has_conns_grp;
+   bool ect_enabled; /* true only if associated ect device is enabled */
 };
 
 /*
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 21/24] coresight: cti: allow cti to be built as a module

2020-08-20 Thread Tingwei Zhang
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
- move cti_remove_conn_xrefs to cti_remove
- add a MODULE_DEVICE_TABLE for autoloading on boot

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 -
 drivers/hwtracing/coresight/Makefile  |  4 ++--
 .../{coresight-cti.c => coresight-cti-core.c} | 20 ++-
 .../hwtracing/coresight/coresight-platform.c  |  1 +
 drivers/hwtracing/coresight/coresight.c   |  1 +
 5 files changed, 27 insertions(+), 4 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 f2a568b969c4..0359d5a1588f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -19,6 +19,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.ocoresight-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 ec286d617b73..d6d5419ec21c 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
struct cti_drvdata *ect_item, *ect_tmp;
 
mutex_lock(_mutex);
-   cti_remove_conn_xrefs(drvdata);
cti_pm_release(drvdata);
 
/* remove from the list */
@@ -853,6 +852,18 @@ 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(>dev);
+
+   mutex_lock(_mutex);
+   cti_remove_conn_xrefs(drvdata);
+   mutex_unlock(_mutex);
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
 
 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -973,6 +984,8 @@ static const struct amba_id cti_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, cti_ids);
+
 static struct amba_driver cti_driver = {
.drv = {
.name   = "coresight-cti",
@@ -980,6 +993,7 @@ static struct amba_driver cti_driver = {
.suppress_bind_attrs = true,
},
.probe  = cti_probe,
+   .remove = cti_remove,
.id_table   = cti_ids,
 };
 
@@ -1002,3 +1016,7 @@ static void __exit cti_exit(void)
 
 module_init(cti_init);
 module_exit(cti_exit);
+
+MODULE_AUTHOR("Mike Leach ");
+MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwtracing/coresight/coresight-platform.c 
b/drivers/hwtracing/coresight/coresight-platform.c
index 227e234a2470..3629b7885aca 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -75,6 +75,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_cores

[PATCH v10 20/24] coresight: cti: increase reference count when enabling cti

2020-08-20 Thread Tingwei Zhang
CTI device is enabled when associated coresight device is enabled.
Increase the module and device reference count for CTI device
when it's enabled. This can prevent CTI device be removed or
module be unloaded when CTI device is enabled by an active trace
session.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index d354fd57474e..6c9f6930b8b8 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -241,19 +241,30 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 {
int ect_ret = 0;
struct coresight_device *ect_csdev = csdev->ect_dev;
+   struct module *mod;
 
if (!ect_csdev)
return 0;
if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
return 0;
 
+   mod = ect_csdev->dev.parent->driver->owner;
if (enable) {
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
-   if (!ect_ret)
-   csdev->ect_enabled = true;
+   if (try_module_get(mod)) {
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (ect_ret) {
+   module_put(mod);
+   } else {
+   get_device(ect_csdev->dev.parent);
+   csdev->ect_enabled = true;
+   }
+   } else
+   ect_ret = -ENODEV;
} else {
if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   put_device(ect_csdev->dev.parent);
+   module_put(mod);
csdev->ect_enabled = false;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 18/24] coresight: cti: Fix bug clearing sysfs links on callback

2020-08-20 Thread Tingwei Zhang
From: Mike Leach 

During module unload, a coresight driver module will call back into
the CTI driver to remove any links between the two devices.

The current code has 2 issues:-
1) in the CTI driver the matching code is matching to the wrong device
so misses all the links.
2) The callback is called too late in the unload process resulting in a
crash.

This fixes both the issues.

Fixes: 177af8285b59 ("coresight: cti: Enable CTI associated with devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
Acked-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight-cti.c | 2 +-
 drivers/hwtracing/coresight/coresight.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 73304374a155..ec286d617b73 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -608,7 +608,7 @@ static void cti_remove_assoc_from_csdev(struct 
coresight_device *csdev)
ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
-   if (tc->con_dev == csdev->ect_dev) {
+   if (tc->con_dev == csdev) {
cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index c2174fed263b..6c09be15d60c 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1254,8 +1254,6 @@ static void coresight_device_release(struct device *dev)
 {
struct coresight_device *csdev = to_coresight_device(dev);
 
-   if (cti_assoc_ops && cti_assoc_ops->remove)
-   cti_assoc_ops->remove(csdev);
fwnode_handle_put(csdev->dev.fwnode);
kfree(csdev->refcnt);
kfree(csdev);
@@ -1590,6 +1588,8 @@ void coresight_unregister(struct coresight_device *csdev)
 {
etm_perf_del_symlink_sink(csdev);
/* Remove references of that device in the topology */
+   if (cti_assoc_ops && cti_assoc_ops->remove)
+   cti_assoc_ops->remove(csdev);
coresight_remove_conns(csdev);
coresight_clear_default_sink(csdev);
coresight_release_platform_data(csdev, csdev->pdata);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 14/24] coresight: allow funnel driver to be built as module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-funnel as module, for ease of development.

- combine static and dynamic funnel init into single
  module_init/exit call
- add funnel_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reported-by: kernel test robot 
Tested-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 .../hwtracing/coresight/coresight-funnel.c| 64 ++-
 1 file changed, 62 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-funnel.c 
b/drivers/hwtracing/coresight/coresight-funnel.c
index 900690a9f7f0..07bc20391fac 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,32 @@ static int static_funnel_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_funnel_remove(struct platform_device *pdev)
+{
+   funnel_remove(>dev);
+   pm_runtime_disable(>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,
+   .remove  = static_funnel_remove,
.driver = {
.name   = "coresight-static-funnel",
.of_match_table = static_funnel_match,
@@ -341,7 +362,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)
@@ -349,6 +369,11 @@ static int dynamic_funnel_probe(struct amba_device *adev,
return funnel_probe(>dev, >res);
 }
 
+static int __exit dynamic_funnel_remove(struct amba_device *adev)
+{
+   return funnel_remove(>dev);
+}
+
 static const struct amba_id dynamic_funnel_ids[] = {
{
.id = 0x000bb908,
@@ -362,6 +387,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",
@@ -370,6 +397,39 @@ static struct amba_driver dynamic_funnel_driver = {
.suppress_bind_attrs = true,
},
.probe  = dynamic_funnel_probe,
+   .remove = dynamic_funnel_remove,
.id_table   = dynamic_funnel_ids,
 };
-builtin_amba_driver(dynamic_funnel_driver);
+
+static int __init funnel_init(void)
+{
+   int ret;
+
+   ret = platform_driver_register(_funnel_driver);
+   if (ret) {
+   pr_info("Error registering platform driver\n");
+   return ret;
+   }
+
+   ret = amba_driver_register(_funnel_driver);
+   if (ret) {
+   pr_info("Error registering amba driver\n");
+   platform_driver_unregister(_funnel_driver);
+   }
+
+   return ret;
+}
+
+static void __exit funnel_exit(void)
+{
+   platform_driver_unregister(_funnel_driver);
+   amba_driver_unregister(_funnel_driver);
+}
+
+module_init(funnel_init);
+module_exit(funnel_exit);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Funnel Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 17/24] coresight: cti: Fix remove sysfs link error

2020-08-20 Thread Tingwei Zhang
From: Mike Leach 

CTI code to remove sysfs link to other devices on shutdown, incorrectly
tries to remove a single ended link when these are all double ended. This
implementation leaves elements in the link info structure undefined which
results in a crash in recent tests for driver module unload.

This patch corrects the link removal code.

Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other coresight 
devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index b031c9dbe026..73304374a155 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata 
*drvdata,
return !link_err;
 }
 
-static void cti_remove_sysfs_link(struct cti_trig_con *tc)
+static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
+ struct cti_trig_con *tc)
 {
struct coresight_sysfs_link link_info;
 
+   link_info.orig = drvdata->csdev;
link_info.orig_name = tc->con_dev_name;
link_info.target = tc->con_dev;
+   link_info.target_name = dev_name(>csdev->dev);
coresight_remove_sysfs_link(_info);
 }
 
@@ -606,7 +609,7 @@ static void cti_remove_assoc_from_csdev(struct 
coresight_device *csdev)
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
if (tc->con_dev == csdev->ect_dev) {
-   cti_remove_sysfs_link(tc);
+   cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
}
@@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata 
*drvdata)
if (tc->con_dev) {
coresight_set_assoc_ectdev_mutex(tc->con_dev,
 NULL);
-   cti_remove_sysfs_link(tc);
+   cti_remove_sysfs_link(drvdata, tc);
tc->con_dev = NULL;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 15/24] coresight: allow replicator driver to be built as module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-replicator as modules, for ease of development.

- Kconfig becomes a tristate, to allow =m
- combine static and dynamic replicator init into single
  module_init/exit call
- add replicator_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 .../coresight/coresight-replicator.c  | 65 ++-
 2 files changed, 67 insertions(+), 3 deletions(-)

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-replicator.c 
b/drivers/hwtracing/coresight/coresight-replicator.c
index 78acf29c49ca..62afdde0e5ea 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -291,6 +291,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;
@@ -310,6 +318,13 @@ static int static_replicator_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_replicator_remove(struct platform_device *pdev)
+{
+   replicator_remove(>dev);
+   pm_runtime_disable(>dev);
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int replicator_runtime_suspend(struct device *dev)
 {
@@ -343,24 +358,29 @@ static const struct of_device_id 
static_replicator_match[] = {
{}
 };
 
+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 = _dev_pm_ops,
.suppress_bind_attrs = true,
},
 };
-builtin_platform_driver(static_replicator_driver);
 
 static int dynamic_replicator_probe(struct amba_device *adev,
const struct amba_id *id)
@@ -368,19 +388,60 @@ static int dynamic_replicator_probe(struct amba_device 
*adev,
return replicator_probe(>dev, >res);
 }
 
+static int __exit dynamic_replicator_remove(struct amba_device *adev)
+{
+   return replicator_remove(>dev);
+}
+
 static const struct amba_id dynamic_replicator_ids[] = {
CS_AMBA_ID(0x000bb909),
CS_AMBA_ID(0x000bb9ec), /* Coresight SoC-600 */
{},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
+
 static struct amba_driver dynamic_replicator_driver = {
.drv = {
.name   = "coresight-dynamic-replicator",
.pm = _dev_pm_ops,
+   .owner  = THIS_MODULE,
.suppress_bind_attrs = true,
},
.probe  = dynamic_replicator_probe,
+   .remove = dynamic_replicator_remove,
.id_table   = dynamic_replicator_ids,
 };
-builtin_amba_driver(dynamic_replicator_driver);
+
+static int __init replicator_init(void)
+{
+   int ret;
+
+   ret = platform_driver_r

[PATCH v10 13/24] coresight: tmc: allow tmc to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  6 -
 drivers/hwtracing/coresight/Makefile  |  6 ++---
 .../{coresight-tmc.c => coresight-tmc-core.c} | 25 ++-
 3 files changed, 32 insertions(+), 5 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} 
(95%)

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 271dc255454f..f2a568b969c4 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -4,9 +4,9 @@
 #
 obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
   coresight-platform.o coresight-sysfs.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 95%
rename from drivers/hwtracing/coresight/coresight-tmc.c
rename to drivers/hwtracing/coresight/coresight-tmc-core.c
index 7040d583bed9..c268fafb3f32 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -561,6 +561,21 @@ static void tmc_shutdown(struct amba_device *adev)
spin_unlock_irqrestore(>spinlock, flags);
 }
 
+static int __exit tmc_remove(struct amba_device *adev)
+{
+   struct tmc_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 static const struct amba_id tmc_ids[] = {
CS_AMBA_ID(0x000bb961),
/* Coresight SoC 600 TMC-ETR/ETS */
@@ -572,6 +587,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",
@@ -580,6 +597,12 @@ static struct amba_driver tmc_driver = {
},
.probe  = tmc_probe,
.shutdown   = tmc_shutdown,
+   .remove = tmc_remove,
.id_table   = tmc_ids,
 };
-builtin_amba_driver(tmc_driver);
+
+module_amba_driver(tmc_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 16/24] coresight: cti: add function to register cti associate ops

2020-08-20 Thread Tingwei Zhang
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 
Tested-by: Mike Leach 
Reported-by: kernel test robot 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c  | 36 +---
 drivers/hwtracing/coresight/coresight-priv.h | 14 
 drivers/hwtracing/coresight/coresight.c  | 21 ++--
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 3ccc703dc940..b031c9dbe026 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -556,7 +556,7 @@ cti_match_fixup_csdev(struct cti_device *ctidev, const char 
*node_name,
  * This will set the association if CTI declared before the CS device.
  * (called from coresight_register() with coresight_mutex locked).
  */
-void cti_add_assoc_to_csdev(struct coresight_device *csdev)
+static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
 {
struct cti_drvdata *ect_item;
struct cti_device *ctidev;
@@ -589,13 +589,12 @@ void cti_add_assoc_to_csdev(struct coresight_device 
*csdev)
 cti_add_done:
mutex_unlock(_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
 
 /*
  * Removing the associated devices is easier.
  * A CTI will not have a value for csdev->ect_dev.
  */
-void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
+static void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 {
struct cti_drvdata *ctidrv;
struct cti_trig_con *tc;
@@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device 
*csdev)
}
mutex_unlock(_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
@@ -972,4 +979,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(_driver);
+   if (ret)
+   pr_info("Error registering cti driver\n");
+   coresight_set_cti_ops(_assoc_ops);
+   return ret;
+}
+
+static void __exit cti_exit(void)
+{
+   coresight_remove_cti_ops();
+   amba_driver_unregister(_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 dcb8aeb6af62..6cde6cf42554 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -173,15 +173,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 b040d4421f84..c2174fed263b 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -56,6 +56,20 @@ static struct list_head *stm_path;
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 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;
@@ -1240,7 +1254,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 &am

[PATCH v10 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure

2020-08-20 Thread Tingwei Zhang
When coresight_build_path() fails on all the cpus, etm_setup_aux
calls etm_free_aux() to free allocated event_data.
WARN_ON(cpumask_empty(mask) will be triggered since cpu mask is empty.
Check event_data->snk_config is not NULL first to avoid this
warning.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index dcb0592418ae..3728c44e5763 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -126,10 +126,10 @@ static void free_sink_buffer(struct etm_event_data 
*event_data)
cpumask_t *mask = _data->mask;
struct coresight_device *sink;
 
-   if (WARN_ON(cpumask_empty(mask)))
+   if (!event_data->snk_config)
return;
 
-   if (!event_data->snk_config)
+   if (WARN_ON(cpumask_empty(mask)))
return;
 
cpu = cpumask_first(mask);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 12/24] coresight: tpiu: allow tpiu to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig  |  5 -
 drivers/hwtracing/coresight/coresight-tpiu.c | 20 +++-
 2 files changed, 23 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..566c57e03596 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(>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,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 f2dc625ea585..d801a2755432 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -165,7 +165,7 @@ int coresight_make_links(struct coresight_device *orig,
 void coresight_remove_links(struct coresight_device *orig,
struct coresight_connection *conn);
 
-#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 58fffdecdbfd..3bb738f9a326 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -324,7 +324,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);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 04/24] coresight: add coresight prefix to barrier_pkt

2020-08-20 Thread Tingwei Zhang
Add coresight prefix to make it specific. It will be a export symbol.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index 03e3f2590191..04ee9cda988d 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 d801a2755432..dcb8aeb6af62 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 6375504ba8b0..44402d413ebb 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 e9c90f2de34a..d515088cc47d 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -53,7 +53,7 @@ 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] = {0x7fff, 0x7fff, 0x7fff, 0x7fff};
+const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 
 static int coresight_id_match(struct device *dev, void *data)
 {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 05/24] coresight: export global symbols

2020-08-20 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

Export symbols used among coresight modules.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 1 +
 drivers/hwtracing/coresight/coresight-sysfs.c| 2 ++
 drivers/hwtracing/coresight/coresight-tmc-etr.c  | 6 ++
 drivers/hwtracing/coresight/coresight.c  | 8 
 4 files changed, 17 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 1a3169e69bb1..dcb0592418ae 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -517,6 +517,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-sysfs.c 
b/drivers/hwtracing/coresight/coresight-sysfs.c
index 82afeaf2ccc4..34d2a2d31d00 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -102,6 +102,7 @@ int coresight_add_sysfs_link(struct coresight_sysfs_link 
*info)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(coresight_add_sysfs_link);
 
 void coresight_remove_sysfs_link(struct coresight_sysfs_link *info)
 {
@@ -122,6 +123,7 @@ void coresight_remove_sysfs_link(struct 
coresight_sysfs_link *info)
info->orig->nr_links--;
info->target->nr_links--;
 }
+EXPORT_SYMBOL_GPL(coresight_remove_sysfs_link);
 
 /*
  * coresight_make_links: Make a link for a connection from a @orig
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c 
b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index b29c2db94d96..ad991a37e2d2 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 d515088cc47d..cd17aea6b50d 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -54,6 +54,7 @@ static struct list_head *stm_path;
  * it needs to look for another sync sequence.
  */
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
+EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
 
 static int coresight_id_match(struct device *dev, void *data)
 {
@@ -179,6 +180,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)
 {
@@ -190,6 +192,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.
@@ -208,6 +211,7 @@ void coresight_disclaim_device_unlocked(void __iomem *base)
 */
WARN_ON_ONCE(1);
 }
+EXPORT_SYMBOL_GPL(coresight_disclaim_device_

[PATCH v10 09/24] coresight: etm3x: allow etm3x to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +++-
 drivers/hwtracing/coresight/Makefile  |  3 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} | 28 ++-
 3 files changed, 33 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 19497d1d92bf..d619cfd0abd8 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -11,7 +11,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 bf22dcfd3327..ba9c86497acb 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(>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,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 10/24] coresight: etm4x: allow etm4x to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

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
- delay advertising the per-cpu etmdrvdata
- protect etmdrvdata[] by modifying it on relevant CPU

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Suggested-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 drivers/hwtracing/coresight/Makefile  |  4 +-
 ...resight-etm4x.c => coresight-etm4x-core.c} | 84 ++-
 3 files changed, 69 insertions(+), 24 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm4x.c => 
coresight-etm4x-core.c} (96%)

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 d619cfd0abd8..271dc255454f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -14,8 +14,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 96%
rename from drivers/hwtracing/coresight/coresight-etm4x.c
rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
index 8b0634ebef77..56aed38cd0fa 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -1430,7 +1430,7 @@ static int __init etm4_pm_setup(void)
return ret;
 }
 
-static void __init etm4_pm_clear(void)
+static void etm4_pm_clear(void)
 {
cpu_pm_unregister_notifier(_cpu_pm_nb);
cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
@@ -1487,25 +1487,20 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
if (!desc.name)
return -ENOMEM;
 
-   etmdrvdata[drvdata->cpu] = drvdata;
-
if (smp_call_function_single(drvdata->cpu,
etm4_init_arch_data,  drvdata, 1))
dev_err(dev, "ETM arch init failed\n");
 
-   if (etm4_arch_supported(drvdata->arch) == false) {
-   ret = -EINVAL;
-   goto err_arch_supported;
-   }
+   if (etm4_arch_supported(drvdata->arch) == false)
+   return -EINVAL;
 
etm4_init_trace_id(drvdata);
etm4_set_default(>config);
 
pdata = coresight_get_platform_data(dev);
-   if (IS_ERR(pdata)) {
-   ret = PTR_ERR(pdata);
-   goto err_arch_supported;
-   }
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+
adev->dev.platform_data = pdata;
 
desc.type = CORESIGHT_DEV_TYPE_SOURCE;
@@ -1515,17 +1510,17 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
desc.dev = dev;
desc.groups = coresight_etmv4_groups;
drvdata->csdev = coresight_register();
-   if (IS_ERR(drvdata->csdev)) {
-   ret = PTR_ERR(drvdata->csde

[PATCH v10 11/24] coresight: etb: allow etb to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +++-
 drivers/hwtracing/coresight/coresight-etb10.c | 26 ++-
 2 files changed, 29 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 04ee9cda988d..248cc82c838e 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -801,6 +801,21 @@ 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(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int etb_runtime_suspend(struct device *dev)
 {
@@ -835,6 +850,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 +861,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Embedded Trace Buffer driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 06/24] coresight: add try_get_module() in coresight_grab_device()

2020-08-20 Thread Tingwei Zhang
When coresight device is in an active session, driver module of
that device should not be removed. Use try_get_module() in
coresight_grab_device() to prevent module to be unloaded.
Use get_device()/put_device() to protect device data
in the middle of active session.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Suggested-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight.c | 60 ++---
 1 file changed, 53 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index cd17aea6b50d..b040d4421f84 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -633,13 +633,45 @@ struct coresight_device *coresight_get_sink_by_id(u32 id)
return dev ? to_coresight_device(dev) : NULL;
 }
 
+/**
+ * coresight_get_ref- Helper function to increase reference count to module
+ * and device.
+ * Return true in successful case and power up the device.
+ * Return false when failed to get reference of module.
+ */
+static inline bool coresight_get_ref(struct coresight_device *csdev)
+{
+   struct device *dev = csdev->dev.parent;
+
+   /* Make sure the driver can't be removed */
+   if (!try_module_get(dev->driver->owner))
+   return false;
+   /* Make sure the device can't go away */
+   get_device(dev);
+   pm_runtime_get_sync(dev);
+   return true;
+}
+
+/**
+ * coresight_put_ref- Helper function to decrease reference count to module
+ * and device. Power off the device.
+ */
+static inline void coresight_put_ref(struct coresight_device *csdev)
+{
+   struct device *dev = csdev->dev.parent;
+
+   pm_runtime_put(dev);
+   put_device(dev);
+   module_put(dev->driver->owner);
+}
+
 /*
  * coresight_grab_device - Power up this device and any of the helper
  * devices connected to it for trace operation. Since the helper devices
  * don't appear on the trace path, they should be handled along with the
  * the master device.
  */
-static void coresight_grab_device(struct coresight_device *csdev)
+static int coresight_grab_device(struct coresight_device *csdev)
 {
int i;
 
@@ -648,9 +680,20 @@ static void coresight_grab_device(struct coresight_device 
*csdev)
 
child  = csdev->pdata->conns[i].child_dev;
if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-   pm_runtime_get_sync(child->dev.parent);
+   if (!coresight_get_ref(child))
+   goto err;
+   }
+   if (coresight_get_ref(csdev))
+   return 0;
+err:
+   for (i--; i >= 0; i--) {
+   struct coresight_device *child;
+
+   child  = csdev->pdata->conns[i].child_dev;
+   if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
+   coresight_put_ref(child);
}
-   pm_runtime_get_sync(csdev->dev.parent);
+   return -ENODEV;
 }
 
 /*
@@ -661,13 +704,13 @@ static void coresight_drop_device(struct coresight_device 
*csdev)
 {
int i;
 
-   pm_runtime_put(csdev->dev.parent);
+   coresight_put_ref(csdev);
for (i = 0; i < csdev->pdata->nr_outport; i++) {
struct coresight_device *child;
 
child  = csdev->pdata->conns[i].child_dev;
if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-   pm_runtime_put(child->dev.parent);
+   coresight_put_ref(child);
}
 }
 
@@ -686,7 +729,7 @@ static int _coresight_build_path(struct coresight_device 
*csdev,
 struct coresight_device *sink,
 struct list_head *path)
 {
-   int i;
+   int i, ret;
bool found = false;
struct coresight_node *node;
 
@@ -716,11 +759,14 @@ static int _coresight_build_path(struct coresight_device 
*csdev,
 * is tell the PM runtime core we need this element and add a node
 * for it.
 */
+   ret = coresight_grab_device(csdev);
+   if (ret)
+   return ret;
+
node = kzalloc(sizeof(struct coresight_node), GFP_KERNEL);
if (!node)
return -ENOMEM;
 
-   coresight_grab_device(csdev);
node->csdev = csdev;
list_add(>link, path);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 07/24] coresight: stm: allow to build coresight-stm as a module

2020-08-20 Thread Tingwei Zhang
- 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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig |  5 -
 drivers/hwtracing/coresight/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 2ba819a47cf6..b0ad912651a9 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -951,6 +951,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(>dev);
+
+   coresight_unregister(drvdata->csdev);
+
+   stm_unregister_device(>stm);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int stm_runtime_suspend(struct device *dev)
 {
@@ -983,6 +994,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",
@@ -991,7 +1004,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 ");
+MODULE_DESCRIPTION("Arm CoreSight System Trace Macrocell driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE

2020-08-20 Thread Tingwei Zhang
Define a MODULE_DEVICE_TABLE for cpu_debug so module can
be auto loaded on boot.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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",
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 00/24] coresight: allow to build coresight as modules

2020-08-20 Thread Tingwei Zhang
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

Change from v9:
Fix warning reported by kernel test robot 
Rebase to coresight-next

Change from v8:
Protect etmdrvdata[] by modifying it on relevant CPU  (Mathieu and Suzuki)
Grab the device before allocating memory for the node (Mathieu)
Add author of coresight core driver (Mathieu)

Change from v7:
Depends on below change for ETM hotplug (Sai)
https://lore.kernel.org/linux-arm-kernel/20200729051310.18436-1-saiprakash.ran...@codeaurora.org/
Add mutex lock to protect etmdrvdata[] (Suzuki)
Add helper function coresight_get_ref() (Suzuki)
Reorg replicator and funnel change. Use two patches to support these
two drivers. (Suzuki)
Add fix tag to "coresight: etm: perf: Fix warning caused by etm_setup_aux
failure" (Suzuki)
Update author of "coresight: cti: Fix bug clearing sysfs links on callback"

Change from v6:
Correct module description for CATU (Mike)
Check ect_ret equals 0 and set ect_enabled flag (Mike)
Add Tested-by and Reviewed-by from Mike

Change from v5:
Add below CTI clean up change from Mike into series
 -https://lists.linaro.org/pipermail/coresight/2020-July/004349.html
Increase module reference count when enabling CTI device (Mike)

Change from v4:
Fix error handling in coresight_grab_devicei() (Greg)
Add coresight: cti: Fix remove sysfs link error from Mike
 -https://lists.linaro.org/pipermail/coresight/2020-July/004275.html
Move cti_remove_conn_xrefs() into cti_remove() (Mike)
Align patch subject to coresight: :  (Mike)

Change from v3:
Rebase to coresight-next (Mike and Mathieu)
Reorder try_get_module() (Suzuki)
Clean up etmdrvdata[] in device remote path (Mike)
Move cti_remove_conn_xrefs to cti_remove (Mike)

Change from v2:
Rebase to 5.8-rc5. Export coresight_add_sysfs_link and
coresight_remove_sysfs_link
Fix one cut and paste error on MODULE_DESCRIPTION of CTI

Change from v1:
Use try_module_get() to avoid module to be unloaded when device is used
in active trace session. (Mathieu P)

Change from above two series.
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 (8):
  coresight: use IS_ENABLED for CONFIGs that may be modules
  coresight: etm3x: allow etm3x to be built as a module
  coresight: etm4x: allow etm4x to be built as a module
  coresight: etb: allow etb to be built as a module
  coresight: tpiu: allow tpiu to be built as a module
  coresight: tmc: allow tmc to be built as a module
  coresight: allow funnel driver to be built as module
  coresight: allow replicator driver to be built as module

Mian Yousaf Kaukab (2):
  coresight: export global symbols
  coresight: tmc-etr: add function to register catu ops

Mike Leach (2):
  coresight: cti: Fix remove sysfs link error
  coresight: cti: Fix bug clearing sysfs links on callback

Tingwei Zhang (12):
  coresight: cpu_debug: add module name in Kconfig
  coresight: cpu_debug: define MODULE_DEVICE_TABLE
  coresight: add coresight prefix to barrier_pkt
  coresight: add try_get_module() in coresight_grab_device()
  coresight: stm: allow to build coresight-stm as a module
  coresight: etm: perf: Fix warning caused by etm_setup_aux failure
  coresight: cti: add function to register cti associate ops
  coresight: cti: don't disable ect device if it's not enabled
  coresight: cti: increase reference count when enabling cti
  coresight: cti: allow cti to be built as a module
  coresight: catu: allow catu drivers to be built as modules
  coresight: allow the coresight core driver to be built as a module

 drivers/hwtracing/coresight/Kconfig   |  54 --
 drivers/hwtracing/coresight/Makefile  |  22 +--
 drivers/hwtracing/coresight/coresight-catu.c  |  37 -
 drivers/hwtracing/coresight/coresight-catu.h  |   2 -
 .../{coresight.c => coresight-core.c} | 154 +++---
 .../hwtracing/coresight/coresight-cpu-debug.c |   2 +
 .../{coresight-cti.c => coresight-cti-core.c} |  67 ++--
 drivers/hwtracing/coresight/coresight-etb10.c |  28 +++-
 .../hwtracing/coresight/coresight-etm-perf.c  |  13 +-
 .../hwtracing/coresight/coresight-etm-perf.h  |   5 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} |  28 +++-
 ...resight-etm4x.c => coresight-etm4x-core.c} |  84 +++---
 .../hwtracing/coresight/coresight-funnel.c|  64 +++-
 .../hwtracing/coresight/coresight-platform.c  |   1 +
 drivers/hwtracing/coresight/coresight-priv.h  |  24 ++-
 .../coresight/coresight-replicator.c  |  65 +++-
 drivers/hwtracing/coresight/coresight-stm.c   |  20 ++-
 drivers/hwtracing/cores

[PATCH v10 01/24] coresight: cpu_debug: add module name in Kconfig

2020-08-20 Thread Tingwei Zhang
Provide name of cpu_debug module in Kconfig help section.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 11/24] coresight: etb: allow etb to be built as a module

2020-08-19 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +++-
 drivers/hwtracing/coresight/coresight-etb10.c | 26 ++-
 2 files changed, 29 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 04ee9cda988d..248cc82c838e 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -801,6 +801,21 @@ 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(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int etb_runtime_suspend(struct device *dev)
 {
@@ -835,6 +850,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 +861,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Embedded Trace Buffer driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



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

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

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

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

[PATCH v9 23/24] coresight: catu: allow catu drivers to be built as modules

2020-08-19 Thread Tingwei Zhang
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 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 47696a7d24a7..99430f6cf5a5 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -567,11 +567,21 @@ 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(>dev);
+
+   coresight_unregister(drvdata->csdev);
+   return 0;
+}
+
 static struct amba_id catu_ids[] = {
CS_AMBA_ID(0x000bb9ee),
{},
 };
 
+MODULE_DEVICE_TABLE(amba, catu_ids);
+
 static struct amba_driver catu_driver = {
.drv = {
.name   = "coresight-catu",
@@ -579,6 +589,7 @@ static struct amba_driver catu_driver = {
.suppress_bind_attrs= true,
},
.probe  = catu_probe,
+   .remove = catu_remove,
.id_table   = catu_ids,
 };
 
@@ -601,3 +612,7 @@ static void __exit catu_exit(void)
 
 module_init(catu_init);
 module_exit(catu_exit);
+
+MODULE_AUTHOR("Suzuki K Poulose ");
+MODULE_DESCRIPTION("Arm CoreSight Address Translation Unit (CATU) Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 20/24] coresight: cti: increase reference count when enabling cti

2020-08-19 Thread Tingwei Zhang
CTI device is enabled when associated coresight device is enabled.
Increase the module and device reference count for CTI device
when it's enabled. This can prevent CTI device be removed or
module be unloaded when CTI device is enabled by an active trace
session.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index d354fd57474e..6c9f6930b8b8 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -241,19 +241,30 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 {
int ect_ret = 0;
struct coresight_device *ect_csdev = csdev->ect_dev;
+   struct module *mod;
 
if (!ect_csdev)
return 0;
if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
return 0;
 
+   mod = ect_csdev->dev.parent->driver->owner;
if (enable) {
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
-   if (!ect_ret)
-   csdev->ect_enabled = true;
+   if (try_module_get(mod)) {
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (ect_ret) {
+   module_put(mod);
+   } else {
+   get_device(ect_csdev->dev.parent);
+   csdev->ect_enabled = true;
+   }
+   } else
+   ect_ret = -ENODEV;
} else {
if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   put_device(ect_csdev->dev.parent);
+   module_put(mod);
csdev->ect_enabled = false;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 16/24] coresight: cti: add function to register cti associate ops

2020-08-19 Thread Tingwei Zhang
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 
Tested-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c  | 32 ++--
 drivers/hwtracing/coresight/coresight-priv.h | 14 -
 drivers/hwtracing/coresight/coresight.c  | 21 +++--
 3 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 3ccc703dc940..1f470c47ba70 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -589,7 +589,6 @@ void cti_add_assoc_to_csdev(struct coresight_device *csdev)
 cti_add_done:
mutex_unlock(_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
 
 /*
  * Removing the associated devices is easier.
@@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device 
*csdev)
}
mutex_unlock(_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
@@ -972,4 +979,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(_driver);
+   if (ret)
+   pr_info("Error registering cti driver\n");
+   coresight_set_cti_ops(_assoc_ops);
+   return ret;
+}
+
+static void __exit cti_exit(void)
+{
+   coresight_remove_cti_ops();
+   amba_driver_unregister(_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 dcb8aeb6af62..6cde6cf42554 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -173,15 +173,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 b040d4421f84..c2174fed263b 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -56,6 +56,20 @@ static struct list_head *stm_path;
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 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;
@@ -1240,7 +1254,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);
@@ -1551,8 +1566,8 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
ret = coresight_fixup_device_conns(csdev);
if (!ret)
ret = coresight_fixup_orphan_conns(csdev);
-   if (!ret)
-   cti_add_assoc_to_csdev(csdev);
+   if (!ret && cti_assoc_ops && cti_assoc_ops->add)
+   cti_assoc_ops->add(csdev);
 
mutex_unlock(_mutex);
if (ret) {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 22/24] coresight: tmc-etr: add function to register catu ops

2020-08-19 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

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 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 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 1801804a7762..47696a7d24a7 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,
@@ -582,4 +582,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(_driver);
+   if (ret)
+   pr_info("Error registering catu driver\n");
+   tmc_etr_set_catu_ops(_catu_buf_ops);
+   return ret;
+}
+
+static void __exit catu_exit(void)
+{
+   tmc_etr_remove_catu_ops();
+   amba_driver_unregister(_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 ad991a37e2d2..714f9e867e5f 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] = _flat_buf_ops,
[ETR_MODE_ETR_SG] = _sg_buf_ops,
-   [ETR_MODE_CATU] = IS_ENABLED(CONFIG_CORESIGHT_CATU)
-   ? _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 6e8d2dc33d17..b91ec7dde7bc 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -326,4 +326,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
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 21/24] coresight: cti: allow cti to be built as a module

2020-08-19 Thread Tingwei Zhang
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
- move cti_remove_conn_xrefs to cti_remove
- add a MODULE_DEVICE_TABLE for autoloading on boot

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 -
 drivers/hwtracing/coresight/Makefile  |  4 ++--
 .../{coresight-cti.c => coresight-cti-core.c} | 20 ++-
 .../hwtracing/coresight/coresight-platform.c  |  1 +
 drivers/hwtracing/coresight/coresight.c   |  1 +
 5 files changed, 27 insertions(+), 4 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 f2a568b969c4..0359d5a1588f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -19,6 +19,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.ocoresight-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 6bb06c5715db..1d8d7cb41937 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
struct cti_drvdata *ect_item, *ect_tmp;
 
mutex_lock(_mutex);
-   cti_remove_conn_xrefs(drvdata);
cti_pm_release(drvdata);
 
/* remove from the list */
@@ -853,6 +852,18 @@ 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(>dev);
+
+   mutex_lock(_mutex);
+   cti_remove_conn_xrefs(drvdata);
+   mutex_unlock(_mutex);
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
 
 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -973,6 +984,8 @@ static const struct amba_id cti_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, cti_ids);
+
 static struct amba_driver cti_driver = {
.drv = {
.name   = "coresight-cti",
@@ -980,6 +993,7 @@ static struct amba_driver cti_driver = {
.suppress_bind_attrs = true,
},
.probe  = cti_probe,
+   .remove = cti_remove,
.id_table   = cti_ids,
 };
 
@@ -1002,3 +1016,7 @@ static void __exit cti_exit(void)
 
 module_init(cti_init);
 module_exit(cti_exit);
+
+MODULE_AUTHOR("Mike Leach ");
+MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwtracing/coresight/coresight-platform.c 
b/drivers/hwtracing/coresight/coresight-platform.c
index bfd44231d7ad..635d55c1d580 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -75,6 +75,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_cores

[PATCH v9 12/24] coresight: tpiu: allow tpiu to be built as a module

2020-08-19 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig  |  5 -
 drivers/hwtracing/coresight/coresight-tpiu.c | 20 +++-
 2 files changed, 23 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..566c57e03596 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(>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,13 @@ 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 ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 15/24] coresight: allow replicator driver to be built as module

2020-08-19 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-replicator as modules, for ease of development.

- Kconfig becomes a tristate, to allow =m
- combine static and dynamic replicator init into single
  module_init/exit call
- add replicator_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 .../coresight/coresight-replicator.c  | 65 ++-
 2 files changed, 67 insertions(+), 3 deletions(-)

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-replicator.c 
b/drivers/hwtracing/coresight/coresight-replicator.c
index 78acf29c49ca..62afdde0e5ea 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -291,6 +291,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;
@@ -310,6 +318,13 @@ static int static_replicator_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_replicator_remove(struct platform_device *pdev)
+{
+   replicator_remove(>dev);
+   pm_runtime_disable(>dev);
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int replicator_runtime_suspend(struct device *dev)
 {
@@ -343,24 +358,29 @@ static const struct of_device_id 
static_replicator_match[] = {
{}
 };
 
+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 = _dev_pm_ops,
.suppress_bind_attrs = true,
},
 };
-builtin_platform_driver(static_replicator_driver);
 
 static int dynamic_replicator_probe(struct amba_device *adev,
const struct amba_id *id)
@@ -368,19 +388,60 @@ static int dynamic_replicator_probe(struct amba_device 
*adev,
return replicator_probe(>dev, >res);
 }
 
+static int __exit dynamic_replicator_remove(struct amba_device *adev)
+{
+   return replicator_remove(>dev);
+}
+
 static const struct amba_id dynamic_replicator_ids[] = {
CS_AMBA_ID(0x000bb909),
CS_AMBA_ID(0x000bb9ec), /* Coresight SoC-600 */
{},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
+
 static struct amba_driver dynamic_replicator_driver = {
.drv = {
.name   = "coresight-dynamic-replicator",
.pm = _dev_pm_ops,
+   .owner  = THIS_MODULE,
.suppress_bind_attrs = true,
},
.probe  = dynamic_replicator_probe,
+   .remove = dynamic_replicator_remove,
.id_table   = dynamic_replicator_ids,
 };
-builtin_amba_driver(dynamic_replicator_driver);
+
+static int __init replicator_init(void)
+{
+   int ret;
+
+   ret = platform_driver_r

[PATCH v9 19/24] coresight: cti: don't disable ect device if it's not enabled

2020-08-19 Thread Tingwei Zhang
If associated ect device is not enabled at first place, disable
routine should not be called. Add ect_enabled flag to check whether
ect device is enabled. Fix the issue in below case.  Ect device is
not available when associated coresight device enabled and the
association is established after coresight device is enabled.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight.c | 11 ---
 include/linux/coresight.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 6c09be15d60c..d354fd57474e 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -244,13 +244,18 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 
if (!ect_csdev)
return 0;
+   if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
+   return 0;
 
if (enable) {
-   if (ect_ops(ect_csdev)->enable)
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (!ect_ret)
+   csdev->ect_enabled = true;
} else {
-   if (ect_ops(ect_csdev)->disable)
+   if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   csdev->ect_enabled = false;
+   }
}
 
/* output warning if ECT enable is preventing trace operation */
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 3bb738f9a326..7d3c87e5b97c 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -208,6 +208,7 @@ struct coresight_device {
/* sysfs links between components */
int nr_links;
bool has_conns_grp;
+   bool ect_enabled; /* true only if associated ect device is enabled */
 };
 
 /*
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 18/24] coresight: cti: Fix bug clearing sysfs links on callback

2020-08-19 Thread Tingwei Zhang
From: Mike Leach 

During module unload, a coresight driver module will call back into
the CTI driver to remove any links between the two devices.

The current code has 2 issues:-
1) in the CTI driver the matching code is matching to the wrong device
so misses all the links.
2) The callback is called too late in the unload process resulting in a
crash.

This fixes both the issues.

Fixes: 177af8285b59 ("coresight: cti: Enable CTI associated with devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
Acked-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight-cti.c | 2 +-
 drivers/hwtracing/coresight/coresight.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 1c34db7d1b1b..6bb06c5715db 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -608,7 +608,7 @@ void cti_remove_assoc_from_csdev(struct coresight_device 
*csdev)
ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
-   if (tc->con_dev == csdev->ect_dev) {
+   if (tc->con_dev == csdev) {
cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index c2174fed263b..6c09be15d60c 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1254,8 +1254,6 @@ static void coresight_device_release(struct device *dev)
 {
struct coresight_device *csdev = to_coresight_device(dev);
 
-   if (cti_assoc_ops && cti_assoc_ops->remove)
-   cti_assoc_ops->remove(csdev);
fwnode_handle_put(csdev->dev.fwnode);
kfree(csdev->refcnt);
kfree(csdev);
@@ -1590,6 +1588,8 @@ void coresight_unregister(struct coresight_device *csdev)
 {
etm_perf_del_symlink_sink(csdev);
/* Remove references of that device in the topology */
+   if (cti_assoc_ops && cti_assoc_ops->remove)
+   cti_assoc_ops->remove(csdev);
coresight_remove_conns(csdev);
coresight_clear_default_sink(csdev);
coresight_release_platform_data(csdev, csdev->pdata);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v9 13/24] coresight: tmc: allow tmc to be built as a module

2020-08-19 Thread Tingwei Zhang
From: Kim Phillips 

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 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  6 -
 drivers/hwtracing/coresight/Makefile  |  6 ++---
 .../{coresight-tmc.c => coresight-tmc-core.c} | 25 ++-
 3 files changed, 32 insertions(+), 5 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} 
(95%)

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 271dc255454f..f2a568b969c4 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -4,9 +4,9 @@
 #
 obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
   coresight-platform.o coresight-sysfs.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 95%
rename from drivers/hwtracing/coresight/coresight-tmc.c
rename to drivers/hwtracing/coresight/coresight-tmc-core.c
index 7040d583bed9..c268fafb3f32 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -561,6 +561,21 @@ static void tmc_shutdown(struct amba_device *adev)
spin_unlock_irqrestore(>spinlock, flags);
 }
 
+static int __exit tmc_remove(struct amba_device *adev)
+{
+   struct tmc_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 static const struct amba_id tmc_ids[] = {
CS_AMBA_ID(0x000bb961),
/* Coresight SoC 600 TMC-ETR/ETS */
@@ -572,6 +587,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",
@@ -580,6 +597,12 @@ static struct amba_driver tmc_driver = {
},
.probe  = tmc_probe,
.shutdown   = tmc_shutdown,
+   .remove = tmc_remove,
.id_table   = tmc_ids,
 };
-builtin_amba_driver(tmc_driver);
+
+module_amba_driver(tmc_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



  1   2   >