coresight: etm4x: save/restore ETMv4 context across CPU low power states
v5 cover coresight: etm4x: save/restore ETMv4 context across CPU low power states
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Let's mitigate against this by conditionally saving and restoring the trace unit state when the CPU enters low power states.
This patchset introduces a firmware property named 'arm,coresight-loses-context-with-cpu' - when this is present the hardware state will be conditionally saved and restored.
A module parameter 'pm_save_enable' is also introduced which can be configured to override the firmware property. This parameter also provides a means to save/restore state when external agents are used.
The hardware state is only ever saved and restored when a coresight session is present.
The last patch should be considered as an RFC as further consideration is required relating to where the pm_save_enable parameter lives and to determine if the external agent support should be a pm_save_enable option or a new kernel option.
Changes since v4:
- Rename fwnode property to "arm,coresight-loses-context-with-cpu" as this doesn't imply a software policy
- Update the device tree binding document to indicate that this property isn't specific to ETMs - also provide a longer description more generic description with an example of why it might be used
- Set the module parameter at probe based on the value determined by firmware. The user can still override the firmware via the kernel command line, this has the effect of hiding the PARAM_PM_SAVE_FIRMWARE option from the user - though we still internally use it to allow us to determine if the user has set the parameter.
- Remove unnecessary call to smp_processor_id
- Move etm4_needs_save_restore helper to coresight.c and rename
- Rebased onto coresight/next a04d8683f577 ("...ity of etm4_os_unlock comment")
- Drop Reviewed-By from Suzuki on "coresight: etm4x: save/restore st..." patch as content changed too much
- Add module option to that keeps clocks/power enabled at probe and saves state when external or self-hosted is in use.
Changes since v3:
- Only save/restore when self-hosted is being used and detect this without relying on the coresight registers (which may not be available)
- Only allocate memory for etmv4_save_state at probe time when configuration indicates it may be used
- Set pm_save_enable param to 0444 such that it is static after boot
- Save/restore TRCPDCR
- Add missing comments to struct etm4_drvdata documentation
- Rebased onto coresight/next (8f1f9857)
Changes since v2:
- Move the PM notifier block from drvdata to file static
- Add section names to document references
- Add additional information to commit messages
- Remove trcdvcvr and trcdvcmr from saved state and add a comment to describe why
- Ensure TRCPDCR_PU is set after restore and add a comment to explain why we bother toggling TRCPDCR_PU on save/restore
- Reword the pm_save_enable options and add comments
- Miscellaneous style changes
- Move device tree binding documentation to its own patch
Changes since v1:
- Rebased onto coresight/next
- Correcly pass bit number rather than BIT macro to coresight_timeout
- Abort saving state if a timeout occurs
- Fix completely broken pm_notify handling and unregister handler on error
- Use state_needs_restore to ensure state is restored only once
- Add module parameter description to existing boot_enable parameter and use module_param instead of module_param_named
- Add firmware bindings for coresight-needs-save-restore
- Rename 'disable_pm_save' to 'pm_save_enable' which allows for disabled, enabled or firmware
- Update comment on etm4_os_lock, it incorrectly indicated that the code unlocks the trace registers
- Add comments to explain use of OS lock during save/restore
- Fix incorrect error description whilst waiting for PM stable
- Add WARN_ON_ONCE when cpu isn't as expected during save/restore
- Various updates to commit messages
Andrew Murray (3):
coresight: etm4x: save/restore state across CPU low power states
dt-bindings: arm: coresight: Add support for
coresight-loses-context-with-cpu
coresight: etm4x: save/restore state for external agents
.../devicetree/bindings/arm/coresight.txt | 9 + drivers/hwtracing/coresight/coresight-etm4x.c | 339 +++++++++++++++++- drivers/hwtracing/coresight/coresight-etm4x.h | 64 ++++ drivers/hwtracing/coresight/coresight.c | 8 +- include/linux/coresight.h | 13 + 5 files changed, 431 insertions(+), 2 deletions(-)
Signature · 7 lines
2.21.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 1/3 coresight: etm4x: save/restore state across CPU low power states
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Let's mitigate against this by conditionally saving and restoring the trace unit state when the CPU enters low power states.
This patchset introduces a firmware property named 'arm,coresight-loses-context-with-cpu' - when this is present the hardware state will be conditionally saved and restored.
A module parameter 'pm_save_enable' is also introduced which can be configured to override the firmware property. This can be set to never allow save/restore or to conditionally allow it (only for self-hosted). The default value is determined by firmware.
We avoid saving the hardware state when self-hosted coresight isn't in use to reduce PM latency - we can't determine this by reading the claim tags (TRCCLAIMCLR) as these are 'trace' registers which need power and clocking, something we can't easily provide in the PM context. Therefore we rely on the existing drvdata->mode internal state that is set when self-hosted coresight is used (and powered).
--- drivers/hwtracing/coresight/coresight-etm4x.c | 318 ++++++++++++++++++ drivers/hwtracing/coresight/coresight-etm4x.h | 64 ++++ drivers/hwtracing/coresight/coresight.c | 6 + include/linux/coresight.h | 6 + 4 files changed, 394 insertions(+)
drivers/hwtracing/coresight/coresight-etm4x.c +318 -0
@@ -18,6 +18,7 @@#include <linux/stat.h> #include <linux/clk.h> #include <linux/cpu.h> +#include <linux/cpu_pm.h> #include <linux/coresight.h> #include <linux/coresight-pmu.h> #include <linux/pm_wakeup.h>
@@ -26,6 +27,7 @@#include <linux/uaccess.h> #include <linux/perf_event.h> #include <linux/pm_runtime.h> +#include <linux/property.h> #include <asm/sections.h> #include <asm/local.h> #include <asm/virt.h>
@@ -37,6 +39,15 @@ static int boot_enable;module_param (boot_enable, int,0444 );MODULE_PARM_DESC (boot_enable,"Enable tracing on boot" ); +#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ +#define PARAM_PM_SAVE_NEVER 1/* never save any state */ +#define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ + +static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ; +module_param (pm_save_enable, int,0444 ); +MODULE_PARM_DESC (pm_save_enable, +"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +/* The number of ETMv4 currently registered */ static int etm4_count;static struct etmv4_drvdata *etmdrvdata[NR_CPUS ];
@@ -54,6 +65,14 @@ static void etm4_os_unlock(struct etmv4_drvdata *drvdata)isb (); } +static void etm4_os_lock (struct etmv4_drvdata *drvdata) +{ +/* Writing 0x1 to TRCOSLAR locks the trace registers */ +writel_relaxed (0x1 , drvdata->base +TRCOSLAR ); + drvdata->os_unlock = false; +isb (); +} +static bool etm4_arch_supported (u8 arch) {/* Mask out the minor version number */
@@ -1085,6 +1104,288 @@ static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) drvdata->trcid =coresight_get_trace_id (drvdata->cpu); } +#ifdef CONFIG_CPU_PM +static int etm4_cpu_save (struct etmv4_drvdata *drvdata) +{ +int i, ret =0 ; +struct etmv4_save_state *state; +struct device *etm_dev = &drvdata->csdev->dev; + +/* +* As recommended by 3.4.1 ("The procedure when powering down the PE") +* of ARM IHI 0064D +*/ +dsb (sy); +isb (); + +CS_UNLOCK (drvdata->base); + +/* Lock the OS lock to disable trace and external debugger access */ +etm4_os_lock (drvdata); + +/* wait for TRCSTATR.PMSTABLE to go up */ +if (coresight_timeout (drvdata->base,TRCSTATR , +TRCSTATR_PMSTABLE_BIT ,1 )) { +dev_err (etm_dev, +"timeout while waiting for PM Stable Status\n" ); +etm4_os_unlock (drvdata); + ret = -EBUSY ; + goto out; + } + + state = drvdata->save_state; + + state->trcprgctlr =readl (drvdata->base +TRCPRGCTLR ); + state->trcprocselr =readl (drvdata->base +TRCPROCSELR ); + state->trcconfigr =readl (drvdata->base +TRCCONFIGR ); + state->trcauxctlr =readl (drvdata->base +TRCAUXCTLR ); + state->trceventctl0r =readl (drvdata->base +TRCEVENTCTL0R ); + state->trceventctl1r =readl (drvdata->base +TRCEVENTCTL1R ); + state->trcstallctlr =readl (drvdata->base +TRCSTALLCTLR ); + state->trctsctlr =readl (drvdata->base +TRCTSCTLR ); + state->trcsyncpr =readl (drvdata->base +TRCSYNCPR ); + state->trcccctlr =readl (drvdata->base +TRCCCCTLR ); + state->trcbbctlr =readl (drvdata->base +TRCBBCTLR ); + state->trctraceidr =readl (drvdata->base +TRCTRACEIDR ); + state->trcqctlr =readl (drvdata->base +TRCQCTLR ); + + state->trcvictlr =readl (drvdata->base +TRCVICTLR ); + state->trcviiectlr =readl (drvdata->base +TRCVIIECTLR ); + state->trcvissctlr =readl (drvdata->base +TRCVISSCTLR ); + state->trcvipcssctlr =readl (drvdata->base +TRCVIPCSSCTLR ); + state->trcvdctlr =readl (drvdata->base +TRCVDCTLR ); + state->trcvdsacctlr =readl (drvdata->base +TRCVDSACCTLR ); + state->trcvdarcctlr =readl (drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) + state->trcseqevr[i] =readl (drvdata->base +TRCSEQEVRn (i)); + + state->trcseqrstevr =readl (drvdata->base +TRCSEQRSTEVR ); + state->trcseqstr =readl (drvdata->base +TRCSEQSTR ); + state->trcextinselr =readl (drvdata->base +TRCEXTINSELR ); + +for (i =0 ; i < drvdata->nr_cntr; i++) { + state->trccntrldvr[i] =readl (drvdata->base +TRCCNTRLDVRn (i)); + state->trccntctlr[i] =readl (drvdata->base +TRCCNTCTLRn (i)); + state->trccntvr[i] =readl (drvdata->base +TRCCNTVRn (i)); + } + +for (i =0 ; i < drvdata->nr_resource *2 ; i++) + state->trcrsctlr[i] =readl (drvdata->base +TRCRSCTLRn (i)); + +for (i =0 ; i < drvdata->nr_ss_cmp; i++) { + state->trcssccr[i] =readl (drvdata->base +TRCSSCCRn (i)); + state->trcsscsr[i] =readl (drvdata->base +TRCSSCSRn (i)); + state->trcsspcicr[i] =readl (drvdata->base +TRCSSPCICRn (i)); + } + +for (i =0 ; i < drvdata->nr_addr_cmp *2 ; i++) { + state->trcacvr[i] =readl (drvdata->base +TRCACVRn (i)); + state->trcacatr[i] =readl (drvdata->base +TRCACATRn (i)); + } + +/* +* Data trace stream is architecturally prohibited for A profile cores +* so we don't save (or later restore) trcdvcvr and trcdvcmr - As per +* section 1.3.4 ("Possible functional configurations of an ETMv4 trace +* unit") of ARM IHI 0064D. +*/ + +for (i =0 ; i < drvdata->numcidc; i++) + state->trccidcvr[i] =readl (drvdata->base +TRCCIDCVRn (i)); + +for (i =0 ; i < drvdata->numvmidc; i++) + state->trcvmidcvr[i] =readl (drvdata->base +TRCVMIDCVRn (i)); + + state->trccidcctlr0 =readl (drvdata->base +TRCCIDCCTLR0 ); + state->trccidcctlr1 =readl (drvdata->base +TRCCIDCCTLR1 ); + + state->trcvmidcctlr0 =readl (drvdata->base +TRCVMIDCCTLR0 ); + state->trcvmidcctlr0 =readl (drvdata->base +TRCVMIDCCTLR1 ); + + state->trcclaimset =readl (drvdata->base +TRCCLAIMCLR ); + + state->trcpdcr =readl (drvdata->base +TRCPDCR ); + +/* wait for TRCSTATR.IDLE to go up */ +if (coresight_timeout (drvdata->base,TRCSTATR ,TRCSTATR_IDLE_BIT ,1 )) { +dev_err (etm_dev, +"timeout while waiting for Idle Trace Status\n" ); +etm4_os_unlock (drvdata); + ret = -EBUSY ; + goto out; + } + + drvdata->state_needs_restore = true; + +/* +* Power can be removed from the trace unit now. We do this to +* potentially save power on systems that respect the TRCPDCR_PU +* despite requesting software to save/restore state. +*/ +writel_relaxed ((state->trcpdcr & ~TRCPDCR_PU ), + drvdata->base +TRCPDCR ); + +out: +CS_LOCK (drvdata->base); +return ret; +} + +static void etm4_cpu_restore (struct etmv4_drvdata *drvdata) +{ +int i; +struct etmv4_save_state *state = drvdata->save_state; + +CS_UNLOCK (drvdata->base); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcprgctlr, drvdata->base +TRCPRGCTLR ); +writel_relaxed (state->trcprocselr, drvdata->base +TRCPROCSELR ); +writel_relaxed (state->trcconfigr, drvdata->base +TRCCONFIGR ); +writel_relaxed (state->trcauxctlr, drvdata->base +TRCAUXCTLR ); +writel_relaxed (state->trceventctl0r, drvdata->base +TRCEVENTCTL0R ); +writel_relaxed (state->trceventctl1r, drvdata->base +TRCEVENTCTL1R ); +writel_relaxed (state->trcstallctlr, drvdata->base +TRCSTALLCTLR ); +writel_relaxed (state->trctsctlr, drvdata->base +TRCTSCTLR ); +writel_relaxed (state->trcsyncpr, drvdata->base +TRCSYNCPR ); +writel_relaxed (state->trcccctlr, drvdata->base +TRCCCCTLR ); +writel_relaxed (state->trcbbctlr, drvdata->base +TRCBBCTLR ); +writel_relaxed (state->trctraceidr, drvdata->base +TRCTRACEIDR ); +writel_relaxed (state->trcqctlr, drvdata->base +TRCQCTLR ); + +writel_relaxed (state->trcvictlr, drvdata->base +TRCVICTLR ); +writel_relaxed (state->trcviiectlr, drvdata->base +TRCVIIECTLR ); +writel_relaxed (state->trcvissctlr, drvdata->base +TRCVISSCTLR ); +writel_relaxed (state->trcvipcssctlr, drvdata->base +TRCVIPCSSCTLR ); +writel_relaxed (state->trcvdctlr, drvdata->base +TRCVDCTLR ); +writel_relaxed (state->trcvdsacctlr, drvdata->base +TRCVDSACCTLR ); +writel_relaxed (state->trcvdarcctlr, drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) +writel_relaxed (state->trcseqevr[i], + drvdata->base +TRCSEQEVRn (i)); + +writel_relaxed (state->trcseqrstevr, drvdata->base +TRCSEQRSTEVR ); +writel_relaxed (state->trcseqstr, drvdata->base +TRCSEQSTR ); +writel_relaxed (state->trcextinselr, drvdata->base +TRCEXTINSELR ); + +for (i =0 ; i < drvdata->nr_cntr; i++) { +writel_relaxed (state->trccntrldvr[i], + drvdata->base +TRCCNTRLDVRn (i)); +writel_relaxed (state->trccntctlr[i], + drvdata->base +TRCCNTCTLRn (i)); +writel_relaxed (state->trccntvr[i], + drvdata->base +TRCCNTVRn (i)); + } + +for (i =0 ; i < drvdata->nr_resource *2 ; i++) +writel_relaxed (state->trcrsctlr[i], + drvdata->base +TRCRSCTLRn (i)); + +for (i =0 ; i < drvdata->nr_ss_cmp; i++) { +writel_relaxed (state->trcssccr[i], + drvdata->base +TRCSSCCRn (i)); +writel_relaxed (state->trcsscsr[i], + drvdata->base +TRCSSCSRn (i)); +writel_relaxed (state->trcsspcicr[i], + drvdata->base +TRCSSPCICRn (i)); + } + +for (i =0 ; i < drvdata->nr_addr_cmp *2 ; i++) { +writel_relaxed (state->trcacvr[i], + drvdata->base +TRCACVRn (i)); +writel_relaxed (state->trcacatr[i], + drvdata->base +TRCACATRn (i)); + } + +for (i =0 ; i < drvdata->numcidc; i++) +writel_relaxed (state->trccidcvr[i], + drvdata->base +TRCCIDCVRn (i)); + +for (i =0 ; i < drvdata->numvmidc; i++) +writel_relaxed (state->trcvmidcvr[i], + drvdata->base +TRCVMIDCVRn (i)); + +writel_relaxed (state->trccidcctlr0, drvdata->base +TRCCIDCCTLR0 ); +writel_relaxed (state->trccidcctlr1, drvdata->base +TRCCIDCCTLR1 ); + +writel_relaxed (state->trcvmidcctlr0, drvdata->base +TRCVMIDCCTLR0 ); +writel_relaxed (state->trcvmidcctlr0, drvdata->base +TRCVMIDCCTLR1 ); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcpdcr, drvdata->base +TRCPDCR ); + + drvdata->state_needs_restore = false; + +/* +* As recommended by section 4.3.7 ("Synchronization when using the +* memory-mapped interface") of ARM IHI 0064D +*/ +dsb (sy); +isb (); + +/* Unlock the OS lock to re-enable trace and external debug access */ +etm4_os_unlock (drvdata); +CS_LOCK (drvdata->base); +} + +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd, +void *v) +{ +struct etmv4_drvdata *drvdata; +unsigned int cpu =smp_processor_id (); + +if (!etmdrvdata[cpu]) +return 0 ; + + drvdata = etmdrvdata[cpu]; + +if (!drvdata->save_state) +return NOTIFY_OK ; + +if (WARN_ON_ONCE (drvdata->cpu != cpu)) +return NOTIFY_BAD ; + +switch (cmd) { +case CPU_PM_ENTER : +/* save the state if self-hosted coresight is in use */ +if (local_read (&drvdata->mode)) +if (etm4_cpu_save (drvdata)) +return NOTIFY_BAD ; +break ; +case CPU_PM_EXIT : +case CPU_PM_ENTER_FAILED : +/* trcclaimset is set when there is state to restore */ +if (drvdata->state_needs_restore) +etm4_cpu_restore (drvdata); +break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +static struct notifier_block etm4_cpu_pm_nb = { + .notifier_call = etm4_cpu_pm_notify, +}; + +static int etm4_cpu_pm_register (void ) +{ +return cpu_pm_register_notifier (&etm4_cpu_pm_nb); +} + +static void etm4_cpu_pm_unregister (void ) +{ +cpu_pm_unregister_notifier (&etm4_cpu_pm_nb); +} +#else +static int etm4_cpu_pm_register (void ) {return 0 ; } +static void etm4_cpu_pm_unregister (void ) { } +#endif +static int etm4_probe (struct amba_device *adev,const struct amba_id *id) {int ret;
@@ -1101,6 +1402,17 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)dev_set_drvdata (dev, drvdata); +if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) + pm_save_enable =coresight_loses_context_with_cpu (dev) ? +PARAM_PM_SAVE_SELF_HOSTED :PARAM_PM_SAVE_NEVER ; + +if (pm_save_enable !=PARAM_PM_SAVE_NEVER ) { + drvdata->save_state =devm_kmalloc (dev, +sizeof (struct etmv4_save_state ),GFP_KERNEL ); +if (!drvdata->save_state) +return -ENOMEM ; + } +/* Validity for the resource is already checked by the AMBA core */ base =devm_ioremap_resource (dev, res);if (IS_ERR (base))
@@ -1135,6 +1447,10 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)if (ret <0 ) goto err_arch_supported; hp_online = ret; + + ret =etm4_cpu_pm_register (); +if (ret) + goto err_arch_supported; }cpus_read_unlock ();
@@ -1185,6 +1501,8 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) err_arch_supported:if (--etm4_count ==0 ) { +etm4_cpu_pm_unregister (); +cpuhp_remove_state_nocalls (CPUHP_AP_ARM_CORESIGHT_STARTING );if (hp_online)cpuhp_remove_state_nocalls (hp_online);
drivers/hwtracing/coresight/coresight-etm4x.h +64 -0
88 lines not on this page · raw message
drivers/hwtracing/coresight/coresight.c +6 -0
@@ -1308,6 +1308,12 @@ static inline int coresight_search_device_idx(struct coresight_dev_list *dict,return -ENOENT ; } +bool coresight_loses_context_with_cpu (struct device *dev) +{ +return fwnode_property_present (dev_fwnode (dev), +"arm,coresight-loses-context-with-cpu" ); +} +/* * coresight_alloc_device_name - Get an index for a given device in the * device index list specific to a driver. An index is allocated for a
include/linux/coresight.h +6 -0
@@ -285,6 +285,8 @@ extern void coresight_disclaim_device(void __iomem *base);extern void coresight_disclaim_device_unlocked (void __iomem *base);extern char *coresight_alloc_device_name (struct coresight_dev_list *devs,struct device *dev); + +extern bool coresight_loses_context_with_cpu (struct device *dev);#else static inline struct coresight_device *coresight_register (struct coresight_desc *desc) {return NULL ; }
@@ -307,6 +309,10 @@ static inline int coresight_claim_device(void __iomem *base)static inline void coresight_disclaim_device (void __iomem *base) {}static inline void coresight_disclaim_device_unlocked (void __iomem *base) {} +static inline bool coresight_loses_context_with_cpu (struct device *dev) +{ +return false; +}#endif extern int coresight_get_cpu (struct device *dev);
Signature · 7 lines
2.21.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 1/3] coresight: etm4x: save/restore state across CPU low power states
Hi Andrew,
Quoted 96 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Let's mitigate against this by conditionally saving and restoring the trace unit state when the CPU enters low power states.
This patchset introduces a firmware property named 'arm,coresight-loses-context-with-cpu' - when this is present the hardware state will be conditionally saved and restored.
A module parameter '
pm_save_enable' is also introduced which can be configured to override the firmware property. This can be set to never allow save/restore or to conditionally allow it (only for self-hosted). The default value is determined by firmware.We avoid saving the hardware state when self-hosted coresight isn't in use to reduce PM latency - we can't determine this by reading the claim tags (TRCCLAIMCLR) as these are 'trace' registers which need power and clocking, something we can't easily provide in the PM context. Therefore we rely on the existing
drvdata->modeinternal state that is set when self-hosted coresight is used (and powered).Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 318 ++++++++++++++++++ drivers/hwtracing/coresight/coresight-etm4x.h | 64 ++++ drivers/hwtracing/coresight/coresight.c | 6 + include/linux/coresight.h | 6 + 4 files changed, 394 insertions(+)drivers/hwtracing/coresight/coresight-etm4x.c +31
-0@@ -18,6 +18,7 @@#include <linux/stat.h> #include <linux/clk.h> #include <linux/cpu.h> +#include <linux/cpu_pm.h> #include <linux/coresight.h> #include <linux/coresight-pmu.h> #include <linux/pm_wakeup.h> @@ -26,6 +27,7 @@#include <linux/uaccess.h> #include <linux/perf_event.h> #include <linux/pm_runtime.h> +#include <linux/property.h> #include <asm/sections.h> #include <asm/local.h> #include <asm/virt.h> @@ -37,6 +39,15 @@ static int boot_enable;module_param (boot_enable, int,0444 );MODULE_PARM_DESC (boot_enable,"Enable tracing on boot" ); +#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ +#define PARAM_PM_SAVE_NEVER 1/* never save any state */ +#define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ + +static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ; +module_param (pm_save_enable, int,0444 ); +MODULE_PARM_DESC (pm_save_enable, +"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +/* The number of ETMv4 currently registered */ static int etm4_count;static struct etmv4_drvdata *etmdrvdata[NR_CPUS ];@@ -54,6 +65,14 @@ static void etm4_os_unlock(struct etmv4_drvdata *drvdata)isb (); } +static void etm4_os_lock (struct etmv4_drvdata *drvdata) +{ +/* Writing 0x1 to TRCOSLAR locks the trace registers */ +writel_relaxed (0x1 , drvdata->base +TRCOSLAR ); + drvdata->os_unlock = false; +isb (); +} +static bool etm4_arch_supported (u8 arch) {/* Mask out the minor version number */ @@ -1085,6 +1104,288 @@ static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) drvdata->trcid =coresight_get_trace_id (drvdata->cpu); } +#ifdef CONFIG_CPU_PM +static int etm4_cpu_save (struct etmv4_drvdata *drvdata) +{ +int i, ret =0 ; +struct etmv4_save_state *state; +struct device *etm_dev = &drvdata->csdev->dev; + +/* +* As recommended by 3.4.1 ("The procedure when powering down the PE") +* of ARM IHI 0064D +*/ +dsb (sy);
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1128
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +10
-0+isb (); + +CS_UNLOCK (drvdata->base); + +/* Lock the OS lock to disable trace and external debugger access */ +etm4_os_lock (drvdata); + +/* wait for TRCSTATR.PMSTABLE to go up */ +if (coresight_timeout (drvdata->base,TRCSTATR , +TRCSTATR_PMSTABLE_BIT ,1 )) {
Indentation problems
Quoted 220 lines
drivers/hwtracing/coresight/coresight-etm4x.c +220
-0+dev_err (etm_dev, +"timeout while waiting for PM Stable Status\n" ); +etm4_os_unlock (drvdata); + ret = -EBUSY ; + goto out; + } + + state = drvdata->save_state; + + state->trcprgctlr =readl (drvdata->base +TRCPRGCTLR ); + state->trcprocselr =readl (drvdata->base +TRCPROCSELR ); + state->trcconfigr =readl (drvdata->base +TRCCONFIGR ); + state->trcauxctlr =readl (drvdata->base +TRCAUXCTLR ); + state->trceventctl0r =readl (drvdata->base +TRCEVENTCTL0R ); + state->trceventctl1r =readl (drvdata->base +TRCEVENTCTL1R ); + state->trcstallctlr =readl (drvdata->base +TRCSTALLCTLR ); + state->trctsctlr =readl (drvdata->base +TRCTSCTLR ); + state->trcsyncpr =readl (drvdata->base +TRCSYNCPR ); + state->trcccctlr =readl (drvdata->base +TRCCCCTLR ); + state->trcbbctlr =readl (drvdata->base +TRCBBCTLR ); + state->trctraceidr =readl (drvdata->base +TRCTRACEIDR ); + state->trcqctlr =readl (drvdata->base +TRCQCTLR ); + + state->trcvictlr =readl (drvdata->base +TRCVICTLR ); + state->trcviiectlr =readl (drvdata->base +TRCVIIECTLR ); + state->trcvissctlr =readl (drvdata->base +TRCVISSCTLR ); + state->trcvipcssctlr =readl (drvdata->base +TRCVIPCSSCTLR ); + state->trcvdctlr =readl (drvdata->base +TRCVDCTLR ); + state->trcvdsacctlr =readl (drvdata->base +TRCVDSACCTLR ); + state->trcvdarcctlr =readl (drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) + state->trcseqevr[i] =readl (drvdata->base +TRCSEQEVRn (i)); + + state->trcseqrstevr =readl (drvdata->base +TRCSEQRSTEVR ); + state->trcseqstr =readl (drvdata->base +TRCSEQSTR ); + state->trcextinselr =readl (drvdata->base +TRCEXTINSELR ); + +for (i =0 ; i < drvdata->nr_cntr; i++) { + state->trccntrldvr[i] =readl (drvdata->base +TRCCNTRLDVRn (i)); + state->trccntctlr[i] =readl (drvdata->base +TRCCNTCTLRn (i)); + state->trccntvr[i] =readl (drvdata->base +TRCCNTVRn (i)); + } + +for (i =0 ; i < drvdata->nr_resource *2 ; i++) + state->trcrsctlr[i] =readl (drvdata->base +TRCRSCTLRn (i)); + +for (i =0 ; i < drvdata->nr_ss_cmp; i++) { + state->trcssccr[i] =readl (drvdata->base +TRCSSCCRn (i)); + state->trcsscsr[i] =readl (drvdata->base +TRCSSCSRn (i)); + state->trcsspcicr[i] =readl (drvdata->base +TRCSSPCICRn (i)); + } + +for (i =0 ; i < drvdata->nr_addr_cmp *2 ; i++) { + state->trcacvr[i] =readl (drvdata->base +TRCACVRn (i)); + state->trcacatr[i] =readl (drvdata->base +TRCACATRn (i)); + } + +/* +* Data trace stream is architecturally prohibited for A profile cores +* so we don't save (or later restore) trcdvcvr and trcdvcmr - As per +* section 1.3.4 ("Possible functional configurations of an ETMv4 trace +* unit") of ARM IHI 0064D. +*/ + +for (i =0 ; i < drvdata->numcidc; i++) + state->trccidcvr[i] =readl (drvdata->base +TRCCIDCVRn (i)); + +for (i =0 ; i < drvdata->numvmidc; i++) + state->trcvmidcvr[i] =readl (drvdata->base +TRCVMIDCVRn (i)); + + state->trccidcctlr0 =readl (drvdata->base +TRCCIDCCTLR0 ); + state->trccidcctlr1 =readl (drvdata->base +TRCCIDCCTLR1 ); + + state->trcvmidcctlr0 =readl (drvdata->base +TRCVMIDCCTLR0 ); + state->trcvmidcctlr0 =readl (drvdata->base +TRCVMIDCCTLR1 ); + + state->trcclaimset =readl (drvdata->base +TRCCLAIMCLR ); + + state->trcpdcr =readl (drvdata->base +TRCPDCR ); + +/* wait for TRCSTATR.IDLE to go up */ +if (coresight_timeout (drvdata->base,TRCSTATR ,TRCSTATR_IDLE_BIT ,1 )) { +dev_err (etm_dev, +"timeout while waiting for Idle Trace Status\n" ); +etm4_os_unlock (drvdata); + ret = -EBUSY ; + goto out; + } + + drvdata->state_needs_restore = true; + +/* +* Power can be removed from the trace unit now. We do this to +* potentially save power on systems that respect the TRCPDCR_PU +* despite requesting software to save/restore state. +*/ +writel_relaxed ((state->trcpdcr & ~TRCPDCR_PU ), + drvdata->base +TRCPDCR ); + +out: +CS_LOCK (drvdata->base); +return ret; +} + +static void etm4_cpu_restore (struct etmv4_drvdata *drvdata) +{ +int i; +struct etmv4_save_state *state = drvdata->save_state; + +CS_UNLOCK (drvdata->base); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcprgctlr, drvdata->base +TRCPRGCTLR ); +writel_relaxed (state->trcprocselr, drvdata->base +TRCPROCSELR ); +writel_relaxed (state->trcconfigr, drvdata->base +TRCCONFIGR ); +writel_relaxed (state->trcauxctlr, drvdata->base +TRCAUXCTLR ); +writel_relaxed (state->trceventctl0r, drvdata->base +TRCEVENTCTL0R ); +writel_relaxed (state->trceventctl1r, drvdata->base +TRCEVENTCTL1R ); +writel_relaxed (state->trcstallctlr, drvdata->base +TRCSTALLCTLR ); +writel_relaxed (state->trctsctlr, drvdata->base +TRCTSCTLR ); +writel_relaxed (state->trcsyncpr, drvdata->base +TRCSYNCPR ); +writel_relaxed (state->trcccctlr, drvdata->base +TRCCCCTLR ); +writel_relaxed (state->trcbbctlr, drvdata->base +TRCBBCTLR ); +writel_relaxed (state->trctraceidr, drvdata->base +TRCTRACEIDR ); +writel_relaxed (state->trcqctlr, drvdata->base +TRCQCTLR ); + +writel_relaxed (state->trcvictlr, drvdata->base +TRCVICTLR ); +writel_relaxed (state->trcviiectlr, drvdata->base +TRCVIIECTLR ); +writel_relaxed (state->trcvissctlr, drvdata->base +TRCVISSCTLR ); +writel_relaxed (state->trcvipcssctlr, drvdata->base +TRCVIPCSSCTLR ); +writel_relaxed (state->trcvdctlr, drvdata->base +TRCVDCTLR ); +writel_relaxed (state->trcvdsacctlr, drvdata->base +TRCVDSACCTLR ); +writel_relaxed (state->trcvdarcctlr, drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) +writel_relaxed (state->trcseqevr[i], + drvdata->base +TRCSEQEVRn (i)); + +writel_relaxed (state->trcseqrstevr, drvdata->base +TRCSEQRSTEVR ); +writel_relaxed (state->trcseqstr, drvdata->base +TRCSEQSTR ); +writel_relaxed (state->trcextinselr, drvdata->base +TRCEXTINSELR ); + +for (i =0 ; i < drvdata->nr_cntr; i++) { +writel_relaxed (state->trccntrldvr[i], + drvdata->base +TRCCNTRLDVRn (i)); +writel_relaxed (state->trccntctlr[i], + drvdata->base +TRCCNTCTLRn (i)); +writel_relaxed (state->trccntvr[i], + drvdata->base +TRCCNTVRn (i)); + } + +for (i =0 ; i < drvdata->nr_resource *2 ; i++) +writel_relaxed (state->trcrsctlr[i], + drvdata->base +TRCRSCTLRn (i)); + +for (i =0 ; i < drvdata->nr_ss_cmp; i++) { +writel_relaxed (state->trcssccr[i], + drvdata->base +TRCSSCCRn (i)); +writel_relaxed (state->trcsscsr[i], + drvdata->base +TRCSSCSRn (i)); +writel_relaxed (state->trcsspcicr[i], + drvdata->base +TRCSSPCICRn (i)); + } + +for (i =0 ; i < drvdata->nr_addr_cmp *2 ; i++) { +writel_relaxed (state->trcacvr[i], + drvdata->base +TRCACVRn (i)); +writel_relaxed (state->trcacatr[i], + drvdata->base +TRCACATRn (i)); + } + +for (i =0 ; i < drvdata->numcidc; i++) +writel_relaxed (state->trccidcvr[i], + drvdata->base +TRCCIDCVRn (i)); + +for (i =0 ; i < drvdata->numvmidc; i++) +writel_relaxed (state->trcvmidcvr[i], + drvdata->base +TRCVMIDCVRn (i)); + +writel_relaxed (state->trccidcctlr0, drvdata->base +TRCCIDCCTLR0 ); +writel_relaxed (state->trccidcctlr1, drvdata->base +TRCCIDCCTLR1 ); + +writel_relaxed (state->trcvmidcctlr0, drvdata->base +TRCVMIDCCTLR0 ); +writel_relaxed (state->trcvmidcctlr0, drvdata->base +TRCVMIDCCTLR1 ); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcpdcr, drvdata->base +TRCPDCR ); + + drvdata->state_needs_restore = false; + +/* +* As recommended by section 4.3.7 ("Synchronization when using the +* memory-mapped interface") of ARM IHI 0064D +*/ +dsb (sy); +isb (); + +/* Unlock the OS lock to re-enable trace and external debug access */ +etm4_os_unlock (drvdata); +CS_LOCK (drvdata->base); +} + +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd, +void *v) +{ +struct etmv4_drvdata *drvdata; +unsigned int cpu =smp_processor_id (); + +if (!etmdrvdata[cpu]) +return 0 ; + + drvdata = etmdrvdata[cpu]; + +if (!drvdata->save_state) +return NOTIFY_OK ; + +if (WARN_ON_ONCE (drvdata->cpu != cpu))
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1358
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +10
-0+return NOTIFY_BAD ; + +switch (cmd) { +case CPU_PM_ENTER : +/* save the state if self-hosted coresight is in use */ +if (local_read (&drvdata->mode)) +if (etm4_cpu_save (drvdata)) +return NOTIFY_BAD ; +break ; +case CPU_PM_EXIT :
Implicit fallthroughs are coming to an end. Please add a
/* fallthrough */
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1360
Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm4x.c +2
-0+case CPU_PM_ENTER_FAILED : +/* trcclaimset is set when there is state to restore */
As far as I can tell the above comment doesn't apply anymore.
Quoted 209 lines
drivers/hwtracing/coresight/coresight-etm4x.c +45
-0+if (drvdata->state_needs_restore) +etm4_cpu_restore (drvdata); +break ; +default : + return NOTIFY_DONE; + } + +return NOTIFY_OK ; +} + +static struct notifier_block etm4_cpu_pm_nb = { + .notifier_call = etm4_cpu_pm_notify, +}; + +static int etm4_cpu_pm_register (void ) +{ +return cpu_pm_register_notifier (&etm4_cpu_pm_nb); +} + +static void etm4_cpu_pm_unregister (void ) +{ +cpu_pm_unregister_notifier (&etm4_cpu_pm_nb); +} +#else +static int etm4_cpu_pm_register (void ) {return 0 ; } +static void etm4_cpu_pm_unregister (void ) { } +#endif +static int etm4_probe (struct amba_device *adev,const struct amba_id *id) {int ret;@@ -1101,6 +1402,17 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)dev_set_drvdata (dev, drvdata); +if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) + pm_save_enable =coresight_loses_context_with_cpu (dev) ? +PARAM_PM_SAVE_SELF_HOSTED :PARAM_PM_SAVE_NEVER ; + +if (pm_save_enable !=PARAM_PM_SAVE_NEVER ) { + drvdata->save_state =devm_kmalloc (dev, +sizeof (struct etmv4_save_state ),GFP_KERNEL ); +if (!drvdata->save_state) +return -ENOMEM ; + } +/* Validity for the resource is already checked by the AMBA core */ base =devm_ioremap_resource (dev, res);if (IS_ERR (base))@@ -1135,6 +1447,10 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)if (ret <0 ) goto err_arch_supported; hp_online = ret; + + ret =etm4_cpu_pm_register (); +if (ret) + goto err_arch_supported; }cpus_read_unlock ();@@ -1185,6 +1501,8 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) err_arch_supported:if (--etm4_count ==0 ) { +etm4_cpu_pm_unregister (); +cpuhp_remove_state_nocalls (CPUHP_AP_ARM_CORESIGHT_STARTING );if (hp_online)cpuhp_remove_state_nocalls (hp_online);drivers/hwtracing/coresight/coresight-etm4x.h +64
-0@@ -175,6 +175,7 @@ ETM_MODE_EXCL_USER)#define TRCSTATR_IDLE_BIT 0 +#define TRCSTATR_PMSTABLE_BIT 1#define ETM_DEFAULT_ADDR_COMP 0/* PowerDown Control Register bits */ @@ -281,6 +282,65 @@ struct etmv4_config {u32 ext_inp; }; +/** +* struct etm4_save_state - state to be preserved when ETM is without power +*/ +struct etmv4_save_state { +u32 trcprgctlr; +u32 trcprocselr; +u32 trcconfigr; +u32 trcauxctlr; +u32 trceventctl0r; +u32 trceventctl1r; +u32 trcstallctlr; +u32 trctsctlr; +u32 trcsyncpr; +u32 trcccctlr; +u32 trcbbctlr; +u32 trctraceidr; +u32 trcqctlr; + +u32 trcvictlr; +u32 trcviiectlr; +u32 trcvissctlr; +u32 trcvipcssctlr; +u32 trcvdctlr; +u32 trcvdsacctlr; +u32 trcvdarcctlr; + +u32 trcseqevr[ETM_MAX_SEQ_STATES ]; +u32 trcseqrstevr; +u32 trcseqstr; +u32 trcextinselr; +u32 trccntrldvr[ETMv4_MAX_CNTR]; +u32 trccntctlr[ETMv4_MAX_CNTR]; +u32 trccntvr[ETMv4_MAX_CNTR]; + +u32 trcrsctlr[ETM_MAX_RES_SEL *2 ]; + +u32 trcssccr[ETM_MAX_SS_CMP ]; +u32 trcsscsr[ETM_MAX_SS_CMP ]; +u32 trcsspcicr[ETM_MAX_SS_CMP ]; + +u64 trcacvr[ETM_MAX_SINGLE_ADDR_CMP ]; +u64 trcacatr[ETM_MAX_SINGLE_ADDR_CMP ]; +u64 trccidcvr[ETMv4_MAX_CTXID_CMP]; +u32 trcvmidcvr[ETM_MAX_VMID_CMP ]; +u32 trccidcctlr0; +u32 trccidcctlr1; +u32 trcvmidcctlr0; +u32 trcvmidcctlr1; + +u32 trcclaimset; + +u32 cntr_val[ETMv4_MAX_CNTR]; +u32 seq_state; +u32 vinst_ctrl; +u32 ss_status[ETM_MAX_SS_CMP ]; + +u32 trcpdcr; +}; +/** * struct etm4_drvdata - specifics associated to an ETM component * @base: Memory mapped base address for this component. @@ -336,6 +396,8 @@ struct etmv4_config {* @atbtrig: If the implementation can support ATB triggers * @lpoverride: If the implementation can support low-power state over. * @config: structure holding configuration parameters. +* @save_state: State to be preserved across power loss +* @state_needs_restore: True when there is context to restore after PM exit */ struct etmv4_drvdata {void __iomem *base;@@ -381,6 +443,8 @@ struct etmv4_drvdata {bool atbtrig;bool lpoverride;struct etmv4_config config; +struct etmv4_save_state *save_state; +bool state_needs_restore; };/* Address comparator access types */ drivers/hwtracing/coresight/coresight.c +6
-0@@ -1308,6 +1308,12 @@ static inline int coresight_search_device_idx(struct coresight_dev_list *dict,return -ENOENT ; } +bool coresight_loses_context_with_cpu (struct device *dev) +{ +return fwnode_property_present (dev_fwnode (dev), +"arm,coresight-loses-context-with-cpu" ); +} +/* * coresight_alloc_device_name - Get an index for a given device in the * device index list specific to a driver. An index is allocated for a include/linux/coresight.h +6
-0@@ -285,6 +285,8 @@ extern void coresight_disclaim_device(void __iomem *base);extern void coresight_disclaim_device_unlocked (void __iomem *base);extern char *coresight_alloc_device_name (struct coresight_dev_list *devs,struct device *dev); + +extern bool coresight_loses_context_with_cpu (struct device *dev);#else static inline struct coresight_device *coresight_register (struct coresight_desc *desc) {return NULL ; }@@ -307,6 +309,10 @@ static inline int coresight_claim_device(void __iomem *base)static inline void coresight_disclaim_device (void __iomem *base) {}static inline void coresight_disclaim_device_unlocked (void __iomem *base) {} +static inline bool coresight_loses_context_with_cpu (struct device *dev) +{ +return false; +}#endif extern int coresight_get_cpu (struct device *dev);Signature · 1 line
2.21.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 1/3] coresight: etm4x: save/restore state across CPU low power states
Quoted 103 lines · Mathieu Poirier
Hi Andrew,
Quoted 100 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Let's mitigate against this by conditionally saving and restoring the trace unit state when the CPU enters low power states.
This patchset introduces a firmware property named 'arm,coresight-loses-context-with-cpu' - when this is present the hardware state will be conditionally saved and restored.
A module parameter '
pm_save_enable' is also introduced which can be configured to override the firmware property. This can be set to never allow save/restore or to conditionally allow it (only for self-hosted). The default value is determined by firmware.We avoid saving the hardware state when self-hosted coresight isn't in use to reduce PM latency - we can't determine this by reading the claim tags (TRCCLAIMCLR) as these are 'trace' registers which need power and clocking, something we can't easily provide in the PM context. Therefore we rely on the existing
drvdata->modeinternal state that is set when self-hosted coresight is used (and powered).Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 318 ++++++++++++++++++ drivers/hwtracing/coresight/coresight-etm4x.h | 64 ++++ drivers/hwtracing/coresight/coresight.c | 6 + include/linux/coresight.h | 6 + 4 files changed, 394 insertions(+)drivers/hwtracing/coresight/coresight-etm4x.c +35
-0@@ -18,6 +18,7 @@#include <linux/stat.h> #include <linux/clk.h> #include <linux/cpu.h> +#include <linux/cpu_pm.h> #include <linux/coresight.h> #include <linux/coresight-pmu.h> #include <linux/pm_wakeup.h> @@ -26,6 +27,7 @@#include <linux/uaccess.h> #include <linux/perf_event.h> #include <linux/pm_runtime.h> +#include <linux/property.h> #include <asm/sections.h> #include <asm/local.h> #include <asm/virt.h> @@ -37,6 +39,15 @@ static int boot_enable;module_param (boot_enable, int,0444 );MODULE_PARM_DESC (boot_enable,"Enable tracing on boot" ); +#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ +#define PARAM_PM_SAVE_NEVER 1/* never save any state */ +#define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ + +static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ; +module_param (pm_save_enable, int,0444 ); +MODULE_PARM_DESC (pm_save_enable, +"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +/* The number of ETMv4 currently registered */ static int etm4_count;static struct etmv4_drvdata *etmdrvdata[NR_CPUS ];@@ -54,6 +65,14 @@ static void etm4_os_unlock(struct etmv4_drvdata *drvdata)isb (); } +static void etm4_os_lock (struct etmv4_drvdata *drvdata) +{ +/* Writing 0x1 to TRCOSLAR locks the trace registers */ +writel_relaxed (0x1 , drvdata->base +TRCOSLAR ); + drvdata->os_unlock = false; +isb (); +} +static bool etm4_arch_supported (u8 arch) {/* Mask out the minor version number */ @@ -1085,6 +1104,288 @@ static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) drvdata->trcid =coresight_get_trace_id (drvdata->cpu); } +#ifdef CONFIG_CPU_PM +static int etm4_cpu_save (struct etmv4_drvdata *drvdata) +{ +int i, ret =0 ; +struct etmv4_save_state *state; +struct device *etm_dev = &drvdata->csdev->dev; + +/* +* As recommended by 3.4.1 ("The procedure when powering down the PE") +* of ARM IHI 0064D +*/ +dsb (sy); +isb (); + +CS_UNLOCK (drvdata->base); +
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1128
Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm4x.c +6
-0+/* Lock the OS lock to disable trace and external debugger access */ +etm4_os_lock (drvdata); + +/* wait for TRCSTATR.PMSTABLE to go up */ +if (coresight_timeout (drvdata->base,TRCSTATR , +TRCSTATR_PMSTABLE_BIT ,1 )) {Indentation problems
Thanks, I'll also improve the indentation of etm4_cpu_restore.
Quoted 233 lines
Quoted 221 lines
drivers/hwtracing/coresight/coresight-etm4x.c +220
-0+dev_err (etm_dev, +"timeout while waiting for PM Stable Status\n" ); +etm4_os_unlock (drvdata); + ret = -EBUSY ; + goto out; + } + + state = drvdata->save_state; + + state->trcprgctlr =readl (drvdata->base +TRCPRGCTLR ); + state->trcprocselr =readl (drvdata->base +TRCPROCSELR ); + state->trcconfigr =readl (drvdata->base +TRCCONFIGR ); + state->trcauxctlr =readl (drvdata->base +TRCAUXCTLR ); + state->trceventctl0r =readl (drvdata->base +TRCEVENTCTL0R ); + state->trceventctl1r =readl (drvdata->base +TRCEVENTCTL1R ); + state->trcstallctlr =readl (drvdata->base +TRCSTALLCTLR ); + state->trctsctlr =readl (drvdata->base +TRCTSCTLR ); + state->trcsyncpr =readl (drvdata->base +TRCSYNCPR ); + state->trcccctlr =readl (drvdata->base +TRCCCCTLR ); + state->trcbbctlr =readl (drvdata->base +TRCBBCTLR ); + state->trctraceidr =readl (drvdata->base +TRCTRACEIDR ); + state->trcqctlr =readl (drvdata->base +TRCQCTLR ); + + state->trcvictlr =readl (drvdata->base +TRCVICTLR ); + state->trcviiectlr =readl (drvdata->base +TRCVIIECTLR ); + state->trcvissctlr =readl (drvdata->base +TRCVISSCTLR ); + state->trcvipcssctlr =readl (drvdata->base +TRCVIPCSSCTLR ); + state->trcvdctlr =readl (drvdata->base +TRCVDCTLR ); + state->trcvdsacctlr =readl (drvdata->base +TRCVDSACCTLR ); + state->trcvdarcctlr =readl (drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) + state->trcseqevr[i] =readl (drvdata->base +TRCSEQEVRn (i)); + + state->trcseqrstevr =readl (drvdata->base +TRCSEQRSTEVR ); + state->trcseqstr =readl (drvdata->base +TRCSEQSTR ); + state->trcextinselr =readl (drvdata->base +TRCEXTINSELR ); + +for (i =0 ; i < drvdata->nr_cntr; i++) { + state->trccntrldvr[i] =readl (drvdata->base +TRCCNTRLDVRn (i)); + state->trccntctlr[i] =readl (drvdata->base +TRCCNTCTLRn (i)); + state->trccntvr[i] =readl (drvdata->base +TRCCNTVRn (i)); + } + +for (i =0 ; i < drvdata->nr_resource *2 ; i++) + state->trcrsctlr[i] =readl (drvdata->base +TRCRSCTLRn (i)); + +for (i =0 ; i < drvdata->nr_ss_cmp; i++) { + state->trcssccr[i] =readl (drvdata->base +TRCSSCCRn (i)); + state->trcsscsr[i] =readl (drvdata->base +TRCSSCSRn (i)); + state->trcsspcicr[i] =readl (drvdata->base +TRCSSPCICRn (i)); + } + +for (i =0 ; i < drvdata->nr_addr_cmp *2 ; i++) { + state->trcacvr[i] =readl (drvdata->base +TRCACVRn (i)); + state->trcacatr[i] =readl (drvdata->base +TRCACATRn (i)); + } + +/* +* Data trace stream is architecturally prohibited for A profile cores +* so we don't save (or later restore) trcdvcvr and trcdvcmr - As per +* section 1.3.4 ("Possible functional configurations of an ETMv4 trace +* unit") of ARM IHI 0064D. +*/ + +for (i =0 ; i < drvdata->numcidc; i++) + state->trccidcvr[i] =readl (drvdata->base +TRCCIDCVRn (i)); + +for (i =0 ; i < drvdata->numvmidc; i++) + state->trcvmidcvr[i] =readl (drvdata->base +TRCVMIDCVRn (i)); + + state->trccidcctlr0 =readl (drvdata->base +TRCCIDCCTLR0 ); + state->trccidcctlr1 =readl (drvdata->base +TRCCIDCCTLR1 ); + + state->trcvmidcctlr0 =readl (drvdata->base +TRCVMIDCCTLR0 ); + state->trcvmidcctlr0 =readl (drvdata->base +TRCVMIDCCTLR1 ); + + state->trcclaimset =readl (drvdata->base +TRCCLAIMCLR ); + + state->trcpdcr =readl (drvdata->base +TRCPDCR ); + +/* wait for TRCSTATR.IDLE to go up */ +if (coresight_timeout (drvdata->base,TRCSTATR ,TRCSTATR_IDLE_BIT ,1 )) { +dev_err (etm_dev, +"timeout while waiting for Idle Trace Status\n" ); +etm4_os_unlock (drvdata); + ret = -EBUSY ; + goto out; + } + + drvdata->state_needs_restore = true; + +/* +* Power can be removed from the trace unit now. We do this to +* potentially save power on systems that respect the TRCPDCR_PU +* despite requesting software to save/restore state. +*/ +writel_relaxed ((state->trcpdcr & ~TRCPDCR_PU ), + drvdata->base +TRCPDCR ); + +out: +CS_LOCK (drvdata->base); +return ret; +} + +static void etm4_cpu_restore (struct etmv4_drvdata *drvdata) +{ +int i; +struct etmv4_save_state *state = drvdata->save_state; + +CS_UNLOCK (drvdata->base); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcprgctlr, drvdata->base +TRCPRGCTLR ); +writel_relaxed (state->trcprocselr, drvdata->base +TRCPROCSELR ); +writel_relaxed (state->trcconfigr, drvdata->base +TRCCONFIGR ); +writel_relaxed (state->trcauxctlr, drvdata->base +TRCAUXCTLR ); +writel_relaxed (state->trceventctl0r, drvdata->base +TRCEVENTCTL0R ); +writel_relaxed (state->trceventctl1r, drvdata->base +TRCEVENTCTL1R ); +writel_relaxed (state->trcstallctlr, drvdata->base +TRCSTALLCTLR ); +writel_relaxed (state->trctsctlr, drvdata->base +TRCTSCTLR ); +writel_relaxed (state->trcsyncpr, drvdata->base +TRCSYNCPR ); +writel_relaxed (state->trcccctlr, drvdata->base +TRCCCCTLR ); +writel_relaxed (state->trcbbctlr, drvdata->base +TRCBBCTLR ); +writel_relaxed (state->trctraceidr, drvdata->base +TRCTRACEIDR ); +writel_relaxed (state->trcqctlr, drvdata->base +TRCQCTLR ); + +writel_relaxed (state->trcvictlr, drvdata->base +TRCVICTLR ); +writel_relaxed (state->trcviiectlr, drvdata->base +TRCVIIECTLR ); +writel_relaxed (state->trcvissctlr, drvdata->base +TRCVISSCTLR ); +writel_relaxed (state->trcvipcssctlr, drvdata->base +TRCVIPCSSCTLR ); +writel_relaxed (state->trcvdctlr, drvdata->base +TRCVDCTLR ); +writel_relaxed (state->trcvdsacctlr, drvdata->base +TRCVDSACCTLR ); +writel_relaxed (state->trcvdarcctlr, drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) +writel_relaxed (state->trcseqevr[i], + drvdata->base +TRCSEQEVRn (i)); + +writel_relaxed (state->trcseqrstevr, drvdata->base +TRCSEQRSTEVR ); +writel_relaxed (state->trcseqstr, drvdata->base +TRCSEQSTR ); +writel_relaxed (state->trcextinselr, drvdata->base +TRCEXTINSELR ); + +for (i =0 ; i < drvdata->nr_cntr; i++) { +writel_relaxed (state->trccntrldvr[i], + drvdata->base +TRCCNTRLDVRn (i)); +writel_relaxed (state->trccntctlr[i], + drvdata->base +TRCCNTCTLRn (i)); +writel_relaxed (state->trccntvr[i], + drvdata->base +TRCCNTVRn (i)); + } + +for (i =0 ; i < drvdata->nr_resource *2 ; i++) +writel_relaxed (state->trcrsctlr[i], + drvdata->base +TRCRSCTLRn (i)); + +for (i =0 ; i < drvdata->nr_ss_cmp; i++) { +writel_relaxed (state->trcssccr[i], + drvdata->base +TRCSSCCRn (i)); +writel_relaxed (state->trcsscsr[i], + drvdata->base +TRCSSCSRn (i)); +writel_relaxed (state->trcsspcicr[i], + drvdata->base +TRCSSPCICRn (i)); + } + +for (i =0 ; i < drvdata->nr_addr_cmp *2 ; i++) { +writel_relaxed (state->trcacvr[i], + drvdata->base +TRCACVRn (i)); +writel_relaxed (state->trcacatr[i], + drvdata->base +TRCACATRn (i)); + } + +for (i =0 ; i < drvdata->numcidc; i++) +writel_relaxed (state->trccidcvr[i], + drvdata->base +TRCCIDCVRn (i)); + +for (i =0 ; i < drvdata->numvmidc; i++) +writel_relaxed (state->trcvmidcvr[i], + drvdata->base +TRCVMIDCVRn (i)); + +writel_relaxed (state->trccidcctlr0, drvdata->base +TRCCIDCCTLR0 ); +writel_relaxed (state->trccidcctlr1, drvdata->base +TRCCIDCCTLR1 ); + +writel_relaxed (state->trcvmidcctlr0, drvdata->base +TRCVMIDCCTLR0 ); +writel_relaxed (state->trcvmidcctlr0, drvdata->base +TRCVMIDCCTLR1 ); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcpdcr, drvdata->base +TRCPDCR ); + + drvdata->state_needs_restore = false; + +/* +* As recommended by section 4.3.7 ("Synchronization when using the +* memory-mapped interface") of ARM IHI 0064D +*/ +dsb (sy); +isb (); + +/* Unlock the OS lock to re-enable trace and external debug access */ +etm4_os_unlock (drvdata); +CS_LOCK (drvdata->base); +} + +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd, +void *v) +{ +struct etmv4_drvdata *drvdata; +unsigned int cpu =smp_processor_id (); + +if (!etmdrvdata[cpu]) +return 0 ; + + drvdata = etmdrvdata[cpu]; + +if (!drvdata->save_state) +return NOTIFY_OK ; + +if (WARN_ON_ONCE (drvdata->cpu != cpu))drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1358
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +10
-0+return NOTIFY_BAD ; + +switch (cmd) { +case CPU_PM_ENTER : +/* save the state if self-hosted coresight is in use */ +if (local_read (&drvdata->mode)) +if (etm4_cpu_save (drvdata)) +return NOTIFY_BAD ; +break ; +case CPU_PM_EXIT :Implicit fallthroughs are coming to an end. Please add a
Quoted 6 lines
/* fallthrough */drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1360
Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm4x.c +2
-0+case CPU_PM_ENTER_FAILED : +/* trcclaimset is set when there is state to restore */ As far as I can tell the above comment doesn't apply anymore.
I'll update it.
Thanks,
Andrew Murray
Quoted 206 lines
Quoted 206 lines
drivers/hwtracing/coresight/coresight-etm4x.c +45
-0+if (drvdata->state_needs_restore) +etm4_cpu_restore (drvdata); +break ; +default : + return NOTIFY_DONE; + } + +return NOTIFY_OK ; +} + +static struct notifier_block etm4_cpu_pm_nb = { + .notifier_call = etm4_cpu_pm_notify, +}; + +static int etm4_cpu_pm_register (void ) +{ +return cpu_pm_register_notifier (&etm4_cpu_pm_nb); +} + +static void etm4_cpu_pm_unregister (void ) +{ +cpu_pm_unregister_notifier (&etm4_cpu_pm_nb); +} +#else +static int etm4_cpu_pm_register (void ) {return 0 ; } +static void etm4_cpu_pm_unregister (void ) { } +#endif +static int etm4_probe (struct amba_device *adev,const struct amba_id *id) {int ret;@@ -1101,6 +1402,17 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)dev_set_drvdata (dev, drvdata); +if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) + pm_save_enable =coresight_loses_context_with_cpu (dev) ? +PARAM_PM_SAVE_SELF_HOSTED :PARAM_PM_SAVE_NEVER ; + +if (pm_save_enable !=PARAM_PM_SAVE_NEVER ) { + drvdata->save_state =devm_kmalloc (dev, +sizeof (struct etmv4_save_state ),GFP_KERNEL ); +if (!drvdata->save_state) +return -ENOMEM ; + } +/* Validity for the resource is already checked by the AMBA core */ base =devm_ioremap_resource (dev, res);if (IS_ERR (base))@@ -1135,6 +1447,10 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)if (ret <0 ) goto err_arch_supported; hp_online = ret; + + ret =etm4_cpu_pm_register (); +if (ret) + goto err_arch_supported; }cpus_read_unlock ();@@ -1185,6 +1501,8 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) err_arch_supported:if (--etm4_count ==0 ) { +etm4_cpu_pm_unregister (); +cpuhp_remove_state_nocalls (CPUHP_AP_ARM_CORESIGHT_STARTING );if (hp_online)cpuhp_remove_state_nocalls (hp_online);drivers/hwtracing/coresight/coresight-etm4x.h +64
-0@@ -175,6 +175,7 @@ ETM_MODE_EXCL_USER)#define TRCSTATR_IDLE_BIT 0 +#define TRCSTATR_PMSTABLE_BIT 1#define ETM_DEFAULT_ADDR_COMP 0/* PowerDown Control Register bits */ @@ -281,6 +282,65 @@ struct etmv4_config {u32 ext_inp; }; +/** +* struct etm4_save_state - state to be preserved when ETM is without power +*/ +struct etmv4_save_state { +u32 trcprgctlr; +u32 trcprocselr; +u32 trcconfigr; +u32 trcauxctlr; +u32 trceventctl0r; +u32 trceventctl1r; +u32 trcstallctlr; +u32 trctsctlr; +u32 trcsyncpr; +u32 trcccctlr; +u32 trcbbctlr; +u32 trctraceidr; +u32 trcqctlr; + +u32 trcvictlr; +u32 trcviiectlr; +u32 trcvissctlr; +u32 trcvipcssctlr; +u32 trcvdctlr; +u32 trcvdsacctlr; +u32 trcvdarcctlr; + +u32 trcseqevr[ETM_MAX_SEQ_STATES ]; +u32 trcseqrstevr; +u32 trcseqstr; +u32 trcextinselr; +u32 trccntrldvr[ETMv4_MAX_CNTR]; +u32 trccntctlr[ETMv4_MAX_CNTR]; +u32 trccntvr[ETMv4_MAX_CNTR]; + +u32 trcrsctlr[ETM_MAX_RES_SEL *2 ]; + +u32 trcssccr[ETM_MAX_SS_CMP ]; +u32 trcsscsr[ETM_MAX_SS_CMP ]; +u32 trcsspcicr[ETM_MAX_SS_CMP ]; + +u64 trcacvr[ETM_MAX_SINGLE_ADDR_CMP ]; +u64 trcacatr[ETM_MAX_SINGLE_ADDR_CMP ]; +u64 trccidcvr[ETMv4_MAX_CTXID_CMP]; +u32 trcvmidcvr[ETM_MAX_VMID_CMP ]; +u32 trccidcctlr0; +u32 trccidcctlr1; +u32 trcvmidcctlr0; +u32 trcvmidcctlr1; + +u32 trcclaimset; + +u32 cntr_val[ETMv4_MAX_CNTR]; +u32 seq_state; +u32 vinst_ctrl; +u32 ss_status[ETM_MAX_SS_CMP ]; + +u32 trcpdcr; +}; +/** * struct etm4_drvdata - specifics associated to an ETM component * @base: Memory mapped base address for this component. @@ -336,6 +396,8 @@ struct etmv4_config {* @atbtrig: If the implementation can support ATB triggers * @lpoverride: If the implementation can support low-power state over. * @config: structure holding configuration parameters. +* @save_state: State to be preserved across power loss +* @state_needs_restore: True when there is context to restore after PM exit */ struct etmv4_drvdata {void __iomem *base;@@ -381,6 +443,8 @@ struct etmv4_drvdata {bool atbtrig;bool lpoverride;struct etmv4_config config; +struct etmv4_save_state *save_state; +bool state_needs_restore; };/* Address comparator access types */ drivers/hwtracing/coresight/coresight.c +6
-0@@ -1308,6 +1308,12 @@ static inline int coresight_search_device_idx(struct coresight_dev_list *dict,return -ENOENT ; } +bool coresight_loses_context_with_cpu (struct device *dev) +{ +return fwnode_property_present (dev_fwnode (dev), +"arm,coresight-loses-context-with-cpu" ); +} +/* * coresight_alloc_device_name - Get an index for a given device in the * device index list specific to a driver. An index is allocated for a include/linux/coresight.h +6
-0@@ -285,6 +285,8 @@ extern void coresight_disclaim_device(void __iomem *base);extern void coresight_disclaim_device_unlocked (void __iomem *base);extern char *coresight_alloc_device_name (struct coresight_dev_list *devs,struct device *dev); + +extern bool coresight_loses_context_with_cpu (struct device *dev);#else static inline struct coresight_device *coresight_register (struct coresight_desc *desc) {return NULL ; }@@ -307,6 +309,10 @@ static inline int coresight_claim_device(void __iomem *base)static inline void coresight_disclaim_device (void __iomem *base) {}static inline void coresight_disclaim_device_unlocked (void __iomem *base) {} +static inline bool coresight_loses_context_with_cpu (struct device *dev) +{ +return false; +}#endif
Quoted 4 lines
Quoted 4 lines
include/linux/coresight.h +0
-0extern int coresight_get_cpu (struct device *dev);Signature · 1 line
2.21.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 1/3] coresight: etm4x: save/restore state across CPU low power states
In reply to Andrew MurrayHi Andrew,
Quoted 14 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Let's mitigate against this by conditionally saving and restoring the trace unit state when the CPU enters low power states.
This patchset introduces a firmware property named 'arm,coresight-loses-context-with-cpu' - when this is present the hardware state will be conditionally saved and restored.
A module parameter '
pm_save_enable' is also introduced which can be configured to override the firmware property. This can be set to never allow save/restore or to conditionally allow it (only for self-hosted). The default value is determined by firmware.
Quoted 6 lines
We avoid saving the hardware state when self-hosted coresight isn't in use to reduce PM latency - we can't determine this by reading the claim tags (TRCCLAIMCLR) as these are 'trace' registers which need power and clocking, something we can't easily provide in the PM context. Therefore we rely on the existing
drvdata->modeinternal state that is set when self-hosted coresight is used (and powered).
The patch looks good to me. Some very minor comments below.
Quoted 35 lines
Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 318 ++++++++++++++++++ drivers/hwtracing/coresight/coresight-etm4x.h | 64 ++++ drivers/hwtracing/coresight/coresight.c | 6 + include/linux/coresight.h | 6 + 4 files changed, 394 insertions(+)drivers/hwtracing/coresight/coresight-etm4x.c +24
-0+static void etm4_cpu_restore (struct etmv4_drvdata *drvdata) +{ +int i; +struct etmv4_save_state *state = drvdata->save_state; + +CS_UNLOCK (drvdata->base); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcprgctlr, drvdata->base +TRCPRGCTLR ); +writel_relaxed (state->trcprocselr, drvdata->base +TRCPROCSELR ); +writel_relaxed (state->trcconfigr, drvdata->base +TRCCONFIGR ); +writel_relaxed (state->trcauxctlr, drvdata->base +TRCAUXCTLR ); +writel_relaxed (state->trceventctl0r, drvdata->base +TRCEVENTCTL0R ); +writel_relaxed (state->trceventctl1r, drvdata->base +TRCEVENTCTL1R ); +writel_relaxed (state->trcstallctlr, drvdata->base +TRCSTALLCTLR ); +writel_relaxed (state->trctsctlr, drvdata->base +TRCTSCTLR ); +writel_relaxed (state->trcsyncpr, drvdata->base +TRCSYNCPR ); +writel_relaxed (state->trcccctlr, drvdata->base +TRCCCCTLR ); +writel_relaxed (state->trcbbctlr, drvdata->base +TRCBBCTLR ); +writel_relaxed (state->trctraceidr, drvdata->base +TRCTRACEIDR ); +writel_relaxed (state->trcqctlr, drvdata->base +TRCQCTLR ); + +writel_relaxed (state->trcvictlr, drvdata->base +TRCVICTLR );
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1267
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +10
-0+writel_relaxed (state->trcviiectlr, drvdata->base +TRCVIIECTLR ); +writel_relaxed (state->trcvissctlr, drvdata->base +TRCVISSCTLR ); +writel_relaxed (state->trcvipcssctlr, drvdata->base +TRCVIPCSSCTLR ); +writel_relaxed (state->trcvdctlr, drvdata->base +TRCVDCTLR ); +writel_relaxed (state->trcvdsacctlr, drvdata->base +TRCVDSACCTLR ); +writel_relaxed (state->trcvdarcctlr, drvdata->base +TRCVDARCCTLR ); + +for (i =0 ; i < drvdata->nrseqstate; i++) +writel_relaxed (state->trcseqevr[i], + drvdata->base +TRCSEQEVRn (i));
minor nit: alignment issues here and below for the multi-line write_relaxed() invocations.
...
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1341
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c +8
-0+static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd, +void *v) +{ +struct etmv4_drvdata *drvdata; +unsigned int cpu =smp_processor_id (); + +if (!etmdrvdata[cpu]) +return 0 ;
Please could we be consistent with the return value. i.e, use something in line with NOTIFY_*. NOTIFY_OK ?
With the above fixed:
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 1/3] coresight: etm4x: save/restore state across CPU low power states
Quoted 67 lines · Suzuki K Poulose
Hi Andrew,
Quoted 14 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Let's mitigate against this by conditionally saving and restoring the trace unit state when the CPU enters low power states.
This patchset introduces a firmware property named 'arm,coresight-loses-context-with-cpu' - when this is present the hardware state will be conditionally saved and restored.
A module parameter '
pm_save_enable' is also introduced which can be configured to override the firmware property. This can be set to never allow save/restore or to conditionally allow it (only for self-hosted). The default value is determined by firmware.Quoted 6 lines
We avoid saving the hardware state when self-hosted coresight isn't in use to reduce PM latency - we can't determine this by reading the claim tags (TRCCLAIMCLR) as these are 'trace' registers which need power and clocking, something we can't easily provide in the PM context. Therefore we rely on the existing
drvdata->modeinternal state that is set when self-hosted coresight is used (and powered).The patch looks good to me. Some very minor comments below.
Quoted 41 lines
Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 318 ++++++++++++++++++ drivers/hwtracing/coresight/coresight-etm4x.h | 64 ++++ drivers/hwtracing/coresight/coresight.c | 6 + include/linux/coresight.h | 6 + 4 files changed, 394 insertions(+)drivers/hwtracing/coresight/coresight-etm4x.c +30
-0+static void etm4_cpu_restore (struct etmv4_drvdata *drvdata) +{ +int i; +struct etmv4_save_state *state = drvdata->save_state; + +CS_UNLOCK (drvdata->base); + +writel_relaxed (state->trcclaimset, drvdata->base +TRCCLAIMSET ); + +writel_relaxed (state->trcprgctlr, drvdata->base +TRCPRGCTLR ); +writel_relaxed (state->trcprocselr, drvdata->base +TRCPROCSELR ); +writel_relaxed (state->trcconfigr, drvdata->base +TRCCONFIGR ); +writel_relaxed (state->trcauxctlr, drvdata->base +TRCAUXCTLR ); +writel_relaxed (state->trceventctl0r, drvdata->base +TRCEVENTCTL0R ); +writel_relaxed (state->trceventctl1r, drvdata->base +TRCEVENTCTL1R ); +writel_relaxed (state->trcstallctlr, drvdata->base +TRCSTALLCTLR ); +writel_relaxed (state->trctsctlr, drvdata->base +TRCTSCTLR ); +writel_relaxed (state->trcsyncpr, drvdata->base +TRCSYNCPR ); +writel_relaxed (state->trcccctlr, drvdata->base +TRCCCCTLR ); +writel_relaxed (state->trcbbctlr, drvdata->base +TRCBBCTLR ); +writel_relaxed (state->trctraceidr, drvdata->base +TRCTRACEIDR ); +writel_relaxed (state->trcqctlr, drvdata->base +TRCQCTLR ); + +writel_relaxed (state->trcvictlr, drvdata->base +TRCVICTLR ); +writel_relaxed (state->trcviiectlr, drvdata->base +TRCVIIECTLR ); +writel_relaxed (state->trcvissctlr, drvdata->base +TRCVISSCTLR ); +writel_relaxed (state->trcvipcssctlr, drvdata->base +TRCVIPCSSCTLR ); +writel_relaxed (state->trcvdctlr, drvdata->base +TRCVDCTLR ); +writel_relaxed (state->trcvdsacctlr, drvdata->base +TRCVDSACCTLR ); +writel_relaxed (state->trcvdarcctlr, drvdata->base +TRCVDARCCTLR );
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1267
Quoted 4 lines
drivers/hwtracing/coresight/coresight-etm4x.c +4
-0+ +for (i =0 ; i < drvdata->nrseqstate; i++) +writel_relaxed (state->trcseqevr[i], + drvdata->base +TRCSEQEVRn (i));minor nit: alignment issues here and below for the multi-line
write_relaxed()invocations.
...
OK.
Quoted 14 lines
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) · line 1341
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +8
-0+static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd, +void *v) +{ +struct etmv4_drvdata *drvdata; +unsigned int cpu =smp_processor_id (); + +if (!etmdrvdata[cpu]) +return 0 ;Please could we be consistent with the return value. i.e, use something in line with NOTIFY_*.
NOTIFY_OK?
Yes I think NOTIFY_OK is the correct thing to do here.
Quoted 3 lines
With the above fixed:
Reviewed-by Suzuki K Poulose <[email protected]>
Thanks for the review,
Andrew Murray
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 2/3 dt-bindings: arm: coresight: Add support for coresight-loses-context-with-cpu
In reply to Andrew MurraySome coresight components, because of choices made during hardware integration, require their state to be saved and restored across CPU low power states.
The software has no reliable method of detecting when save/restore is required thus let's add a binding to inform the kernel.
--- Documentation/devicetree/bindings/arm/coresight.txt | 9 +++++++++ 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/arm/coresight.txt +9 -0
@@ -87,6 +87,15 @@ its hardware characteristcs. * port or ports: see "Graph bindings for Coresight" below. +* Optional properties for all components: + + * arm,coresight-loses-context-with-cpu : boolean. Indicates that the + hardware will lose register context on CPU power down (e.g. CPUIdle). + An example of where this may be needed are systems which contain a + coresight component and CPU in the same power domain. When the CPU + powers down the coresight component also powers down and loses its + context. This property is currently only used for the ETM 4.x driver. + * Optional properties for ETM/PTMs: * arm,cp14: must be present if the system accesses ETM/PTM management
Signature · 7 lines
2.21.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 2/3] dt-bindings: arm: coresight: Add support for coresight-loses-context-with-cpu
Quoted 19 lines · Andrew Murray
Some coresight components, because of choices made during hardware integration, require their state to be saved and restored across CPU low power states.
The software has no reliable method of detecting when save/restore is required thus let's add a binding to inform the kernel.
Signed-off-by Andrew Murray <[email protected]>--- Documentation/devicetree/bindings/arm/coresight.txt | 9 +++++++++ 1 file changed, 9 insertions(+)Documentation/devicetree/bindings/arm/coresight.txt +0
-0@@ -87,6 +87,15 @@ its hardware characteristcs. * port or ports: see "Graph bindings for Coresight" below.
Documentation/devicetree/bindings/arm/coresight.txt its hardware characteristcs. · line 98
Quoted 10 lines
Documentation/devicetree/bindings/arm/coresight.txt +9
-0+* Optional properties for all components: + + * arm,coresight-loses-context-with-cpu : boolean. Indicates that the + hardware will lose register context on CPU power down (e.g. CPUIdle). + An example of where this may be needed are systems which contain a + coresight component and CPU in the same power domain. When the CPU + powers down the coresight component also powers down and loses its + context. This property is currently only used for the ETM 4.x driver. +
When you resend this set make sure to include the device tree mailing list as instructed by get_maintainer.pl. Since this set did not CC the DT list, none of the maintainers over there will look at your patches.
Quoted 6 lines
Documentation/devicetree/bindings/arm/coresight.txt +0
-0* Optional properties for ETM/PTMs: * arm,cp14: must be present if the system accesses ETM/PTM managementSignature · 1 line
2.21.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 2/3] dt-bindings: arm: coresight: Add support for coresight-loses-context-with-cpu
Quoted 33 lines · Mathieu Poirier
Quoted 19 lines · Andrew Murray
Some coresight components, because of choices made during hardware integration, require their state to be saved and restored across CPU low power states.
The software has no reliable method of detecting when save/restore is required thus let's add a binding to inform the kernel.
Signed-off-by Andrew Murray <[email protected]>--- Documentation/devicetree/bindings/arm/coresight.txt | 9 +++++++++ 1 file changed, 9 insertions(+)Documentation/devicetree/bindings/arm/coresight.txt +0
-0@@ -87,6 +87,15 @@ its hardware characteristcs. * port or ports: see "Graph bindings for Coresight" below.Documentation/devicetree/bindings/arm/coresight.txt its hardware characteristcs. · line 98
Quoted 10 lines
Documentation/devicetree/bindings/arm/coresight.txt +9
-0+* Optional properties for all components: + + * arm,coresight-loses-context-with-cpu : boolean. Indicates that the + hardware will lose register context on CPU power down (e.g. CPUIdle). + An example of where this may be needed are systems which contain a + coresight component and CPU in the same power domain. When the CPU + powers down the coresight component also powers down and loses its + context. This property is currently only used for the ETM 4.x driver. +Reviewed-by Mathieu Poirier <[email protected]>
Quoted 4 lines
When you resend this set make sure to include the device tree mailing list as instructed by get_maintainer.pl. Since this set did not CC the DT list, none of the maintainers over there will look at your patches.
Sure I'll do that.
Thanks,
Andrew Murray
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/arm/coresight.txt +0
-0* Optional properties for ETM/PTMs: * arm,cp14: must be present if the system accesses ETM/PTM managementSignature · 1 line
2.21.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 2/3] dt-bindings: arm: coresight: Add support for coresight-loses-context-with-cpu
In reply to Andrew MurrayQuoted 23 lines · Andrew Murray
Some coresight components, because of choices made during hardware integration, require their state to be saved and restored across CPU low power states.
The software has no reliable method of detecting when save/restore is required thus let's add a binding to inform the kernel.
Signed-off-by Andrew Murray <[email protected]>--- Documentation/devicetree/bindings/arm/coresight.txt | 9 +++++++++ 1 file changed, 9 insertions(+)Documentation/devicetree/bindings/arm/coresight.txt +2
-0@@ -87,6 +87,15 @@ its hardware characteristcs. * port or ports: see "Graph bindings for Coresight" below. +* Optional properties for all components: +
Documentation/devicetree/bindings/arm/coresight.txt its hardware characteristcs. · line 101
Quoted 10 lines
Documentation/devicetree/bindings/arm/coresight.txt +7
-0+ * arm,coresight-loses-context-with-cpu : boolean. Indicates that the + hardware will lose register context on CPU power down (e.g. CPUIdle). + An example of where this may be needed are systems which contain a + coresight component and CPU in the same power domain. When the CPU + powers down the coresight component also powers down and loses its + context. This property is currently only used for the ETM 4.x driver. + * Optional properties for ETM/PTMs: * arm,cp14: must be present if the system accesses ETM/PTM management
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 3/3 coresight: etm4x: save/restore state for external agents
In reply to Andrew MurraySome hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Much like self-hosted debug, we should also save/restore the trace unit state when it is in use by external agents.
We wish to avoid saving the hardware state when coresight isn't in use to reduce PM latency - However as external trace/debug is designed to be unintrusive to the CPU, the only way of determining that an external agent is present is to read the claim tags (TRCCLAIMCLR). Unfortunately this register needs power and clocking - something it won't have when coresight isn't in use. We also don't want to temporarily enable it due to the latency and PM context.
Let's compromise by adding a module parameter that will keep the trace unit powered and clocked, thus allowing us to only save/restore state when external trace (or self-hosted) is in use. Though please note that this doesn't allow for tracing from boot on hardware that needs save/restore as the CPU may idle prior to the ETMv4 driver starting and adding PM hooks to save/restore.
--- drivers/hwtracing/coresight/coresight-etm4x.c | 27 ++++++++++++++++--- drivers/hwtracing/coresight/coresight.c | 2 +- include/linux/coresight.h | 7 +++++ 3 files changed, 31 insertions(+), 5 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x.c +23 -4
@@ -42,11 +42,12 @@ MODULE_PARM_DESC(boot_enable, "Enable tracing on boot");#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ #define PARAM_PM_SAVE_NEVER 1/* never save any state */ #define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ +#define PARAM_PM_SAVE_EXTERNAL 3/* save all state (keeps power on) */ static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ;module_param (pm_save_enable, int,0444 );MODULE_PARM_DESC (pm_save_enable, -"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +"Save/restore state on power down: 1 = never, 2 = self-hosted, 3 = self-hosted/external" );/* The number of ETMv4 currently registered */ static int etm4_count;
@@ -1331,6 +1332,22 @@ static void etm4_cpu_restore(struct etmv4_drvdata *drvdata)CS_LOCK (drvdata->base); } +static bool etm4_coresight_in_use (struct etmv4_drvdata *drvdata) +{ +/* Self-hosted session in progress? */ +if (local_read (&drvdata->mode)) +return true; + +/* External agents can be detected through claim tags however we +* only read these tags if the trace unit is powered. +*/ +if (drvdata->csdev &&pm_runtime_active (drvdata->csdev->dev.parent)) +if (coresight_is_claimed_any (drvdata->base)) +return true; + +return false; +} +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd,void *v) {
@@ -1350,8 +1367,8 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,switch (cmd) {case CPU_PM_ENTER : -/* save the state if self-hosted coresight is in use */ -if (local_read (&drvdata->mode)) +/* Save the state if coresight is in use */ +if (etm4_coresight_in_use (drvdata))if (etm4_cpu_save (drvdata))return NOTIFY_BAD ;break ;
@@ -1488,7 +1505,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) goto err_arch_supported; } -pm_runtime_put (&adev->dev); +if (pm_save_enable !=PARAM_PM_SAVE_EXTERNAL ) +pm_runtime_put (&adev->dev); +dev_info (&drvdata->csdev->dev,"CPU%d: ETM v%d.%d initialized\n" , drvdata->cpu, drvdata->arch >>4 , drvdata->arch &0xf );
drivers/hwtracing/coresight/coresight.c +1 -1
@@ -140,7 +140,7 @@ static inline bool coresight_is_claimed_self_hosted(void __iomem *base)return coresight_read_claim_tags (base) ==CORESIGHT_CLAIM_SELF_HOSTED ; } -static inline bool coresight_is_claimed_any (void __iomem *base) +bool coresight_is_claimed_any (void __iomem *base) {return coresight_read_claim_tags (base) !=0 ; }
include/linux/coresight.h +7 -0
@@ -286,6 +286,8 @@ extern void coresight_disclaim_device_unlocked(void __iomem *base);extern char *coresight_alloc_device_name (struct coresight_dev_list *devs,struct device *dev); +extern bool coresight_is_claimed_any (void __iomem *base); +extern bool coresight_loses_context_with_cpu (struct device *dev);#else static inline struct coresight_device *
@@ -309,6 +311,11 @@ static inline int coresight_claim_device(void __iomem *base)static inline void coresight_disclaim_device (void __iomem *base) {}static inline void coresight_disclaim_device_unlocked (void __iomem *base) {} +static inline bool coresight_is_claimed_any (void __iomem *base) +{ +return false; +} +static inline bool coresight_loses_context_with_cpu (struct device *dev) {return false;
Signature · 7 lines
2.21.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 3/3] coresight: etm4x: save/restore state for external agents
Quoted 46 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Much like self-hosted debug, we should also save/restore the trace unit state when it is in use by external agents.
We wish to avoid saving the hardware state when coresight isn't in use to reduce PM latency - However as external trace/debug is designed to be unintrusive to the CPU, the only way of determining that an external agent is present is to read the claim tags (TRCCLAIMCLR). Unfortunately this register needs power and clocking - something it won't have when coresight isn't in use. We also don't want to temporarily enable it due to the latency and PM context.
Let's compromise by adding a module parameter that will keep the trace unit powered and clocked, thus allowing us to only save/restore state when external trace (or self-hosted) is in use. Though please note that this doesn't allow for tracing from boot on hardware that needs save/restore as the CPU may idle prior to the ETMv4 driver starting and adding PM hooks to save/restore.
Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 27 ++++++++++++++++--- drivers/hwtracing/coresight/coresight.c | 2 +- include/linux/coresight.h | 7 +++++ 3 files changed, 31 insertions(+), 5 deletions(-)drivers/hwtracing/coresight/coresight-etm4x.c +2
-1@@ -42,11 +42,12 @@ MODULE_PARM_DESC(boot_enable, "Enable tracing on boot");#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ #define PARAM_PM_SAVE_NEVER 1/* never save any state */ #define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ +#define PARAM_PM_SAVE_EXTERNAL 3/* save all state (keeps power on) */ static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ;module_param (pm_save_enable, int,0444 );MODULE_PARM_DESC (pm_save_enable, -"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +"Save/restore state on power down: 1 = never, 2 = self-hosted, 3 = self-hosted/external" );/* The number of ETMv4 currently registered */ static int etm4_count;@@ -1331,6 +1332,22 @@ static void etm4_cpu_restore(struct etmv4_drvdata *drvdata)CS_LOCK (drvdata->base); }
drivers/hwtracing/coresight/coresight-etm4x.c static void etm4_cpu_restore(struct etmv4_drvdata *drvdata) · line 1343
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +9
-0+static bool etm4_coresight_in_use (struct etmv4_drvdata *drvdata) +{ +/* Self-hosted session in progress? */ +if (local_read (&drvdata->mode)) +return true; + +/* External agents can be detected through claim tags however we +* only read these tags if the trace unit is powered. +*/
Multi-line comment format error
Quoted 73 lines
drivers/hwtracing/coresight/coresight-etm4x.c +12
-3+if (drvdata->csdev &&pm_runtime_active (drvdata->csdev->dev.parent)) +if (coresight_is_claimed_any (drvdata->base)) +return true; + +return false; +} +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd,void *v) {@@ -1350,8 +1367,8 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,switch (cmd) {case CPU_PM_ENTER : -/* save the state if self-hosted coresight is in use */ -if (local_read (&drvdata->mode)) +/* Save the state if coresight is in use */ +if (etm4_coresight_in_use (drvdata))if (etm4_cpu_save (drvdata))return NOTIFY_BAD ;break ;@@ -1488,7 +1505,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) goto err_arch_supported; } -pm_runtime_put (&adev->dev); +if (pm_save_enable !=PARAM_PM_SAVE_EXTERNAL ) +pm_runtime_put (&adev->dev); +dev_info (&drvdata->csdev->dev,"CPU%d: ETM v%d.%d initialized\n" , drvdata->cpu, drvdata->arch >>4 , drvdata->arch &0xf );drivers/hwtracing/coresight/coresight.c +1
-1@@ -140,7 +140,7 @@ static inline bool coresight_is_claimed_self_hosted(void __iomem *base)return coresight_read_claim_tags (base) ==CORESIGHT_CLAIM_SELF_HOSTED ; } -static inline bool coresight_is_claimed_any (void __iomem *base) +bool coresight_is_claimed_any (void __iomem *base) {return coresight_read_claim_tags (base) !=0 ; }include/linux/coresight.h +7
-0@@ -286,6 +286,8 @@ extern void coresight_disclaim_device_unlocked(void __iomem *base);extern char *coresight_alloc_device_name (struct coresight_dev_list *devs,struct device *dev); +extern bool coresight_is_claimed_any (void __iomem *base); +extern bool coresight_loses_context_with_cpu (struct device *dev);#else static inline struct coresight_device *@@ -309,6 +311,11 @@ static inline int coresight_claim_device(void __iomem *base)static inline void coresight_disclaim_device (void __iomem *base) {}static inline void coresight_disclaim_device_unlocked (void __iomem *base) {} +static inline bool coresight_is_claimed_any (void __iomem *base) +{ +return false; +} +static inline bool coresight_loses_context_with_cpu (struct device *dev) {return false;Signature · 1 line
2.21.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Suzuki K Poulose
maintainerRe: [PATCH v5 3/3] coresight: etm4x: save/restore state for external agents
In reply to Andrew MurrayHi Andrew
Quoted 12 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Much like self-hosted debug, we should also save/restore the trace unit state when it is in use by external agents.
We wish to avoid saving the hardware state when coresight isn't in use to reduce PM latency - However as external trace/debug is designed to be unintrusive to the CPU, the only way of determining that an external agent is present is to read the claim tags (TRCCLAIMCLR). Unfortunately this register needs power and clocking - something it won't have when coresight isn't in use. We also don't want to temporarily enable it due to the latency and PM context.
Quoted 6 lines
Let's compromise by adding a module parameter that will keep the trace unit powered and clocked, thus allowing us to only save/restore state when external trace (or self-hosted) is in use. Though please note that this doesn't allow for tracing from boot on hardware that needs save/restore as the CPU may idle prior to the ETMv4 driver starting and adding PM hooks to save/restore.
This looks fine to me. Some minor comments below.
Quoted 12 lines
Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 27 ++++++++++++++++--- drivers/hwtracing/coresight/coresight.c | 2 +- include/linux/coresight.h | 7 +++++ 3 files changed, 31 insertions(+), 5 deletions(-)drivers/hwtracing/coresight/coresight-etm4x.c +0
-0
drivers/hwtracing/coresight/coresight-etm4x.c MODULE_PARM_DESC(boot_enable, "Enable tracing on boot"); · line 45
Quoted 4 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1
-0@@ -42,11 +42,12 @@ MODULE_PARM_DESC(boot_enable, "Enable tracing on boot");#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ #define PARAM_PM_SAVE_NEVER 1/* never save any state */ #define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ +#define PARAM_PM_SAVE_EXTERNAL 3/* save all state (keeps power on) */
Should we say PARAM_PM_SAVE_ALWAYS instead ?
drivers/hwtracing/coresight/coresight-etm4x.c MODULE_PARM_DESC(boot_enable, "Enable tracing on boot"); · line 50
Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1
-1static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ;module_param (pm_save_enable, int,0444 );MODULE_PARM_DESC (pm_save_enable, -"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +"Save/restore state on power down: 1 = never, 2 = self-hosted, 3 = self-hosted/external" );
similarly here and also mention that the power/clocks are not dropped in that case ? I see the comment above, but please could we make it more explicit ?
Quoted 38 lines
drivers/hwtracing/coresight/coresight-etm4x.c +18
-2/* The number of ETMv4 currently registered */ static int etm4_count;@@ -1331,6 +1332,22 @@ static void etm4_cpu_restore(struct etmv4_drvdata *drvdata)CS_LOCK (drvdata->base); } +static bool etm4_coresight_in_use (struct etmv4_drvdata *drvdata) +{ +/* Self-hosted session in progress? */ +if (local_read (&drvdata->mode)) +return true; + +/* External agents can be detected through claim tags however we +* only read these tags if the trace unit is powered. +*/ +if (drvdata->csdev &&pm_runtime_active (drvdata->csdev->dev.parent)) +if (coresight_is_claimed_any (drvdata->base)) +return true; + +return false; +} +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd,void *v) {@@ -1350,8 +1367,8 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,switch (cmd) {case CPU_PM_ENTER : -/* save the state if self-hosted coresight is in use */ -if (local_read (&drvdata->mode)) +/* Save the state if coresight is in use */ +if (etm4_coresight_in_use (drvdata))if (etm4_cpu_save (drvdata))return NOTIFY_BAD ;break ;
drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_probe(struct amba_device *adev, const struct amba_id *id) · line 1510
Quoted 7 lines
drivers/hwtracing/coresight/coresight-etm4x.c +3
-1@@ -1488,7 +1505,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) goto err_arch_supported; } -pm_runtime_put (&adev->dev); +if (pm_save_enable !=PARAM_PM_SAVE_EXTERNAL ) +pm_runtime_put (&adev->dev); +
It may be a good idea to explain why we don't drop the power here in a comment to help people reading the code. You could paste what is in the commit description in here to avoid another lookup.
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0
-0dev_info (&drvdata->csdev->dev,"CPU%d: ETM v%d.%d initialized\n" , drvdata->cpu, drvdata->arch >>4 , drvdata->arch &0xf );drivers/hwtracing/coresight/coresight.c +0
-0
drivers/hwtracing/coresight/coresight.c static inline bool coresight_is_claimed_self_hosted(void __iomem *base) · line 146
Quoted 8 lines
drivers/hwtracing/coresight/coresight.c +1
-1@@ -140,7 +140,7 @@ static inline bool coresight_is_claimed_self_hosted(void __iomem *base)return coresight_read_claim_tags (base) ==CORESIGHT_CLAIM_SELF_HOSTED ; } -static inline bool coresight_is_claimed_any (void __iomem *base) +bool coresight_is_claimed_any (void __iomem *base) {return coresight_read_claim_tags (base) !=0 ; }
minor nit: We may retain this as static inline and move this to the header file.
Kind regards
Suzuki
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 3/3] coresight: etm4x: save/restore state for external agents
Quoted 31 lines · Suzuki K Poulose
Hi Andrew
Quoted 12 lines · Andrew Murray
Some hardware will ignore bit TRCPDCR.PU which is used to signal to hardware that power should not be removed from the trace unit. Much like self-hosted debug, we should also save/restore the trace unit state when it is in use by external agents.
We wish to avoid saving the hardware state when coresight isn't in use to reduce PM latency - However as external trace/debug is designed to be unintrusive to the CPU, the only way of determining that an external agent is present is to read the claim tags (TRCCLAIMCLR). Unfortunately this register needs power and clocking - something it won't have when coresight isn't in use. We also don't want to temporarily enable it due to the latency and PM context.
Quoted 6 lines
Let's compromise by adding a module parameter that will keep the trace unit powered and clocked, thus allowing us to only save/restore state when external trace (or self-hosted) is in use. Though please note that this doesn't allow for tracing from boot on hardware that needs save/restore as the CPU may idle prior to the ETMv4 driver starting and adding PM hooks to save/restore.
This looks fine to me. Some minor comments below.
Quoted 7 lines
Signed-off-by Andrew Murray <[email protected]>--- drivers/hwtracing/coresight/coresight-etm4x.c | 27 ++++++++++++++++--- drivers/hwtracing/coresight/coresight.c | 2 +- include/linux/coresight.h | 7 +++++ 3 files changed, 31 insertions(+), 5 deletions(-)
Quoted 12 lines
drivers/hwtracing/coresight/coresight-etm4x.c MODULE_PARM_DESC(boot_enable, "Enable tracing on boot"); · line 45
Quoted 9 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1
-0@@ -42,11 +42,12 @@ MODULE_PARM_DESC(boot_enable, "Enable tracing on boot");#define PARAM_PM_SAVE_FIRMWARE 0/* save self-hosted state as per firmware */ #define PARAM_PM_SAVE_NEVER 1/* never save any state */ #define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ +#define PARAM_PM_SAVE_EXTERNAL 3/* save all state (keeps power on) */ Should we say
PARAM_PM_SAVE_ALWAYSinstead ?
Yes I think this is OK.
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c MODULE_PARM_DESC(boot_enable, "Enable tracing on boot"); · line 50
Quoted 5 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1
-1static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ;module_param (pm_save_enable, int,0444 );MODULE_PARM_DESC (pm_save_enable, -"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +"Save/restore state on power down: 1 = never, 2 = self-hosted, 3 = self-hosted/external" );similarly here and also mention that the power/clocks are not dropped in that case ? I see the comment above, but please could we make it more explicit ?
I'll change it to ... 3 = self-hosted/external (keeps power on)");
Quoted 38 lines
Quoted 38 lines
drivers/hwtracing/coresight/coresight-etm4x.c +18
-2/* The number of ETMv4 currently registered */ static int etm4_count;@@ -1331,6 +1332,22 @@ static void etm4_cpu_restore(struct etmv4_drvdata *drvdata)CS_LOCK (drvdata->base); } +static bool etm4_coresight_in_use (struct etmv4_drvdata *drvdata) +{ +/* Self-hosted session in progress? */ +if (local_read (&drvdata->mode)) +return true; + +/* External agents can be detected through claim tags however we +* only read these tags if the trace unit is powered. +*/ +if (drvdata->csdev &&pm_runtime_active (drvdata->csdev->dev.parent)) +if (coresight_is_claimed_any (drvdata->base)) +return true; + +return false; +} +static int etm4_cpu_pm_notify (struct notifier_block *nb,unsigned long cmd,void *v) {@@ -1350,8 +1367,8 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,switch (cmd) {case CPU_PM_ENTER : -/* save the state if self-hosted coresight is in use */ -if (local_read (&drvdata->mode)) +/* Save the state if coresight is in use */ +if (etm4_coresight_in_use (drvdata))if (etm4_cpu_save (drvdata))return NOTIFY_BAD ;break ;@@ -1488,7 +1505,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) goto err_arch_supported; }
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_probe(struct amba_device *adev, const struct amba_id *id) · line 1510
Quoted 4 lines
drivers/hwtracing/coresight/coresight-etm4x.c +3
-1-pm_runtime_put (&adev->dev); +if (pm_save_enable !=PARAM_PM_SAVE_EXTERNAL ) +pm_runtime_put (&adev->dev); +It may be a good idea to explain why we don't drop the power here in a comment to help people reading the code. You could paste what is in the commit description in here to avoid another lookup.
Good idea. I'll modify it slightly however.
Quoted 17 lines
Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0
-0dev_info (&drvdata->csdev->dev,"CPU%d: ETM v%d.%d initialized\n" , drvdata->cpu, drvdata->arch >>4 , drvdata->arch &0xf );drivers/hwtracing/coresight/coresight.c +0
-0drivers/hwtracing/coresight/coresight.c static inline bool coresight_is_claimed_self_hosted(void __iomem *base) · line 145
Quoted 7 lines
drivers/hwtracing/coresight/coresight.c +1
-1@@ -140,7 +140,7 @@ static inline bool coresight_is_claimed_self_hosted(void __iomem *base)return coresight_read_claim_tags (base) ==CORESIGHT_CLAIM_SELF_HOSTED ; } -static inline bool coresight_is_claimed_any (void __iomem *base) +bool coresight_is_claimed_any (void __iomem *base) {return coresight_read_claim_tags (base) !=0 ; }minor nit: We may retain this as static inline and move this to the header file.
OK.
Thanks,
Andrew Murray
Quoted 3 lines
Kind regards
Suzuki
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel