From 6f1bd7583f13c7173991428d8ffe9cca7bb02291 Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Mon, 26 Apr 2021 12:21:58 +0100 Subject: [PATCH] ANDROID: coresight: Update ETE/TRBE to v6 merged upstream Mark the buffer as truncated in irq + minor cleanups picked along the way. Bug: 174685394 Signed-off-by: Qais Yousef Change-Id: I36111a14ef066b579a28c39e265f3d601a82e18a --- drivers/hwtracing/coresight/coresight-core.c | 2 +- .../hwtracing/coresight/coresight-etm4x-core.c | 4 ++-- drivers/hwtracing/coresight/coresight-trbe.c | 18 +++++++++++++----- drivers/hwtracing/coresight/coresight-trbe.h | 3 +-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index c4c9f41c0622..1504eb09f8e5 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -23,7 +23,7 @@ #include "coresight-priv.h" static DEFINE_MUTEX(coresight_mutex); -DEFINE_PER_CPU(struct coresight_device *, csdev_sink); +static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); /** * struct coresight_node - elements of a path, from source to sink diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 90827077d2f9..6fee02bf7b71 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -115,7 +115,7 @@ void etm4x_sysreg_write(u64 val, u32 offset, bool _relaxed, bool _64bit) } } -u64 ete_sysreg_read(u32 offset, bool _relaxed, bool _64bit) +static u64 ete_sysreg_read(u32 offset, bool _relaxed, bool _64bit) { u64 res = 0; @@ -132,7 +132,7 @@ u64 ete_sysreg_read(u32 offset, bool _relaxed, bool _64bit) return res; } -void ete_sysreg_write(u64 val, u32 offset, bool _relaxed, bool _64bit) +static void ete_sysreg_write(u64 val, u32 offset, bool _relaxed, bool _64bit) { if (!_relaxed) __iowmb(); /* Imitate the !relaxed I/O helpers */ diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c index a7484abda325..176868496879 100644 --- a/drivers/hwtracing/coresight/coresight-trbe.c +++ b/drivers/hwtracing/coresight/coresight-trbe.c @@ -5,6 +5,8 @@ * device (ETE) thus generating required trace data. Trace can be enabled * via the perf framework. * + * The AUX buffer handling is inspired from Arm SPE PMU driver. + * * Copyright (C) 2020 ARM Ltd. * * Author: Anshuman Khandual @@ -515,7 +517,7 @@ static void *arm_trbe_alloc_buffer(struct coresight_device *csdev, if (!buf->trbe_base) { kfree(pglist); kfree(buf); - return ERR_PTR(buf->trbe_base); + return ERR_PTR(-ENOMEM); } buf->trbe_limit = buf->trbe_base + nr_pages * PAGE_SIZE; buf->trbe_write = buf->trbe_base; @@ -614,9 +616,10 @@ static unsigned long arm_trbe_update_buffer(struct coresight_device *csdev, /* * Otherwise, the buffer is full and the write pointer * has reached base. Adjust this back to the Limit pointer - * for correct size. + * for correct size. Also, mark the buffer truncated. */ write = get_trbe_limit_pointer(); + perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED); } offset = write - base; @@ -703,7 +706,12 @@ static void trbe_handle_overflow(struct perf_output_handle *handle) if (buf->snapshot) handle->head += size; - perf_aux_output_flag(handle, PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW); + /* + * Mark the buffer as truncated, as we have stopped the trace + * collection upon the WRAP event, without stopping the source. + */ + perf_aux_output_flag(handle, PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW | + PERF_AUX_FLAG_TRUNCATED); perf_aux_output_end(handle, size); event_data = perf_aux_output_begin(handle, event); if (!event_data) { @@ -863,7 +871,7 @@ static void arm_trbe_register_coresight_cpu(struct trbe_drvdata *drvdata, int cp dev = &cpudata->drvdata->pdev->dev; desc.name = devm_kasprintf(dev, GFP_KERNEL, "trbe%d", cpu); - if (IS_ERR(desc.name)) + if (!desc.name) goto cpu_clear; desc.type = CORESIGHT_DEV_TYPE_SINK; @@ -1038,7 +1046,7 @@ static int arm_trbe_probe_irq(struct platform_device *pdev, if (irq_get_percpu_devid_partition(drvdata->irq, &drvdata->supported_cpus)) return -EINVAL; - drvdata->handle = alloc_percpu(typeof(*drvdata->handle)); + drvdata->handle = alloc_percpu(struct perf_output_handle *); if (!drvdata->handle) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-trbe.h b/drivers/hwtracing/coresight/coresight-trbe.h index 499b846ccfee..abf3e36082f0 100644 --- a/drivers/hwtracing/coresight/coresight-trbe.h +++ b/drivers/hwtracing/coresight/coresight-trbe.h @@ -128,8 +128,7 @@ static inline void set_trbe_write_pointer(unsigned long addr) static inline unsigned long get_trbe_limit_pointer(void) { u64 trblimitr = read_sysreg_s(SYS_TRBLIMITR_EL1); - unsigned long limit = (trblimitr >> TRBLIMITR_LIMIT_SHIFT) & TRBLIMITR_LIMIT_MASK; - unsigned long addr = limit << TRBLIMITR_LIMIT_SHIFT; + unsigned long addr = trblimitr & (TRBLIMITR_LIMIT_MASK << TRBLIMITR_LIMIT_SHIFT); WARN_ON(!IS_ALIGNED(addr, PAGE_SIZE)); return addr;