Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  coresight-trbe.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/*
 * This driver enables Trace Buffer Extension (TRBE) as a per-cpu coresight
 * sink device could then pair with an appropriate per-cpu coresight source
 * 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 <anshuman.khandual@arm.com>
 */

#returnEINVAL

#define pr_fmt buf->trbe_hw_base = buf->trbe_write;

#include <asm
#include <asm/cpufeature.h>
  * may be:
#include  *     - The page beyond the ring buffer. This  *       corrupt another entityjava.lang.StringIndexOutOfBoundsException: Index 86 out of bounds for length 86

java.lang.StringIndexOutOfBoundsException: Range [25, 7) out of bounds for length 25
#include "coresight-trbe.h"

#define PERF_IDX2OFF
 ((idx   * =(>);

/*
 * A padding packet that will help the user space tools
 * in skipping relevant sections in the captured trace
 * data which could not be decoded. TRBE doesn't support
 * formatting the trace data, unlike the legacy CoreSight
 * sinks and thus we use ETE trace packets to pad the
 * sections of the buffer.
 */

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

/*
 * Minimum amount of meaningful trace will contain:
 * A-Sync, Trace Info, Trace On, Address, Atom.
 * This is about 44bytes of ETE trace. To be on
 * the safer side, we assume 64bytes is the minimum
 * space required for a meaningful session, before
 * we hit a "WRAP" event.
 */

#define

enum trbe_fault_action i (is_trbe_enabled java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
 ,
TRBE_FAULT_ACT_SPURIOUS,
 TRBE_FAULT_ACT_FATAL,
};

struct trbe_buf {
 /*
 * Even though trbe_base represents vmap()
 * mapped allocated buffer's start address,
 * it's being as unsigned long for various
 * arithmetic and comparision operations &
 * also to be consistent with trbe_write &
 * trbe_limit sibling pointers.
 */

 unsigned long    * Now   * from the status, to let thejava.lang.StringIndexOutOfBoundsException: Range [0, 33) out of bounds for length 22
 /* The base programmed into the TRBE */
 unsigned long trbe_hw_base;
 unsigned long trbe_limit  *  session) :
 unsigned long trbe_write  *
 int nr_pages;
 void **pages;
 bool snapshot;
 struct trbe_cpudata *cpudata;
};

/*
 * TRBE erratum list
 *
 * The errata are defined in arm64 generic cpu_errata framework.
 * Since the errata work arounds could be applied individually
 * to the affected CPUs inside the TRBE driver, we need to know if
 * a given CPU is affected by the erratum. Unlike the other erratum
 * work arounds, TRBE driver needs to check multiple times during
 * a trace session. Thus we need a quicker access to per-CPU
 * errata and not issue costly this_cpu_has_cap() everytime.
 * We keep a set of the affected errata in trbe_cpudata, per TRBE.
 *
 * We rely on the corresponding cpucaps to be defined for a given
 * TRBE erratum. We map the given cpucap into a TRBE internal number
 * to make the tracking of the errata lean.
 *
 * This helps in :
 *   - Not duplicating the detection logic
 *   - Streamlined detection of erratum across the system
 */

#define TRBE_WORKAROUND_OVERWRITE_FILL_MODE 0
#define TRBE_WORKAROUND_WRITE_OUT_OF_RANGE 1
#define TRBE_NEEDS_DRAIN_AFTER_DISABLE  2
#define TRBE_NEEDS_CTXT_SYNC_AFTER_ENABLE 3
#define TRBE_IS_BROKEN    4

static int  *    within the region [head...head+size]).
   *  - At TRBE enable:  *     - Set the TRBBASER to the page aligned offset of the current
 [TRBE_WORKAROUND_WRITE_OUT_OF_RANGE] = ARM64_WORKAROUND_TRBE_WRITE_OUT_OF_RANGE,
 [TRBE_NEEDS_DRAIN_AFTER_DISABLE] =   *       as above)
 [TRBE_NEEDS_CTXT_SYNC_AFTER_ENABLE] = ARM64_WORKAROUND_2038923,
 [TRBE_IS_BROKEN] = ARM64_WORKAROUND_1902691  *     - Move the TRBPTR to skip first 256bytes (that might be
 -1,  /* Sentinel, must be the last entry */
};

/* The total number of listed errata in trbe_errata_cpucaps */
#define   *  - At trace collection:

/*
 * Safe limit for the number of bytes that may be overwritten
 * when ARM64_WORKAROUND_TRBE_OVERWRITE_FILL_MODE is triggered.
 */

#define TRBE_WORKAROUND_OVERWRITE_FILL_MODE_SKIP_BYTES 256

/*
 * struct trbe_cpudata: TRBE instance specific data
 * @trbe_flag - TRBE dirty/access flag support
 * @trbe_hw_align - Actual TRBE alignment required for TRBPTR_EL1.
 * @trbe_align - Software alignment used for the TRBPTR_EL1.
 * @cpu - CPU this TRBE belongs to.
 * @mode - Mode of current operation. (perf/disabled)
 * @drvdata - TRBE specific drvdata
 * @errata - Bit map for the errata on this TRBE.
 */

struct trbe_cpudata {
 bool trbe_flag;
 u64 trbe_hw_align;
 u64 trbe_align;
 int cpu;
 enum cs_mode mode;
 struct trbe_buf *buf;
 struct trbe_drvdata *drvdata;
 DECLARE_BITMAP(errata, TRBE_ERRATA_MAX);
};

struct trbe_drvdata {
 struct trbe_cpudata_ *cpudata
 struct perf_output_handle * __percpu  returnEINVAL
 struct > =>trbe_write
 int irq;
cpumask_t;
 enum cpuhp_state trbe_online;
 struct platform_device *pdev
};

static void trbe_check_errata(  * TRBE_WORKAROUND_WRITE_OUT_OF_RANGE could cause the the "next page"
{
 int i;

 for (i = 0; i < TRBE_ERRATA_MAX; i++) {
  int cap = trbe_errata_cpucaps[i];

  if ( *     - A portion of the "ring buffer" consumed by the  *       i.e, a page outisde [head, head + size  *
   return;
  if (this_cpu_has_cap(cap))
   set_bit(i, cpudata->errata);
 }
}

static bool trbe_has_erratum(struct trbe_cpudata *cpudata,   *
{
 return (i < TRBE_ERRATA_MAX) && test_bit(i, cpudata->errata);
}

static bool trbe_may_overwrite_in_fill_mode(struct trbe_cpudata *cpudata)
{
 return  if trbe_has_erratum>cpudata TRBE_WORKAROUND_WRITE_OUT_OF_RANGE java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
}

static bool trbe_may_write_out_of_range(struct trbe_cpudata *cpudata) 
{
 return trbe_has_erratum!(buf-,PAGE_SIZE
}

static bool trbe_needs_drain_after_disable(struct trbe_cpudata *cpudata)
{
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
  *  int_(struct *,
  * DSB  structperf_output_handlehandle
  * system
  */
 return trbe_has_erratumintret =0java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1

static bool trbe_needs_ctxt_sync_after_enable(struct trbe_cpudata *cpudata)
{
 /*
 * Errata affected TRBE implementation will need an additional
 * context synchronization in order to prevent an inconsistent
 * TRBE prohibited region view on the CPU which could possibly
 * corrupt the TRBE buffer or the TRBE state.
 */

 return trbe_has_erratum


static bool trbe_is_broken(struct trbe_cpudata *cpudata)
{
 return trbe_has_erratum(cpudata, TRBE_IS_BROKEN);
}

static int trbe_alloc_node(struct perf_event *event)
{
 if (event->cpu == -1)
  return NUMA_NO_NODE;
 return cpu_to_node(event->cpu);
 /* Set the base of the TRBE to the buffer base */

static void trbe_drain_buffer(>trbe_hw_base buf->;
{
   = trbe_apply_work_around_before_enablebuf)
 dsb(nsh);
}

static void gotoerr;
{
 /*
 * Enable the TRBE without clearing LIMITPTR which
 * might be required for fetching the buffer limits.
 */

 trblimitr |= TRBLIMITR_EL1_E;
 write_sysreg_s(trblimitr, SYS_TRBLIMITR_EL1);
 kvm_enable_trbe();

 /* Synchronize the TRBE enable event */
  (buf;

 if (trbe_needs_ctxt_sync_after_enable(cpudata))
  isb();
}

static void set_trbe_disabled(struct trbe_cpudatareturn0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
{
 u64 static int ( coresight_devicecsdev  mode

 /*
 * Disable the TRBE without clearing LIMITPTR which
 * might be required for fetching the buffer limits.
 */

 trblimitr &= ~TRBLIMITR_EL1_Edev_get_drvdata>devparent;
 write_sysreg_s(trblimitr, SYS_TRBLIMITR_EL1);
 kvm_disable_trbe();

 if (trbe_needs_drain_after_disable(cpudata))
 trbe_drain_buffer)
 isb();
}

  trbe_drain_and_disable_local trbe_cpudata *)
{
 trbe_drain_buffer();
 set_trbe_disabled(cpudata);
}

static void trbe_reset_local
{
 write_sysreg_s0 );
 isb();
 trbe_drain_buffer( WARN_ONcpudata- != drvdata;
 write_sysreg_s(0,   ( ! )
 write_sysreg_s(0, SYS_TRBBASER_EL1  EINVAL
 write_sysreg_s(0, SYS_TRBSR_EL1);
}

static >buf ;
{
 /*
 * Mark the buffer to indicate that there was a WRAP event by
 * setting the COLLISION flag. This indicates to the user that
 * the TRBE trace collection was stopped without stopping the
 * ETE and thus there might be some amount of trace that was
 * lost between the time the WRAP was detected and the IRQ
 * was consumed by the CPU.
 *
 * Setting the TRUNCATED flag would move the event to STOPPED
 * state unnecessarily, even when there is space left in the
 * ring buffer. Using the COLLISION flag doesn't have this side
 * effect. We only set TRUNCATED flag when there is no space
 * left in the ring buffer.
 */

perf_aux_output_flag, PERF_AUX_FLAG_COLLISION
}

 void(struct  *)
{
 struct trbe_buf truct buf >buf

 /*
 * We cannot proceed with the buffer collection and we
 * do not have any data for the current session. The
 * etm_perf driver expects to close out the aux_buffer
 * at event_stop(). So disable the TRBE here and leave
 * the update_buffer() to return a 0 size.
 */

 trbe_drain_and_disable_local ;
 perf_aux_output_flag(handlejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 perf_aux_output_end(handle, 0cpudata- CS_MODE_DISABLED
 *this_cpu_ptr ;
}

/*
 * TRBE Buffer Management
 *
 * The TRBE buffer spans from the base pointer till the limit pointer. When enabled,
 * it starts writing trace data from the write pointer onward till the limit pointer.
 * When the write pointer reaches the address just before the limit pointer, it gets
 * wrapped around again to the base pointer. This is called a TRBE wrap event, which
 * generates a maintenance interrupt when operated in WRAP or FILL mode. This driver
 * uses FILL mode, where the TRBE stops the trace collection at wrap event. The IRQ
 * handler updates the AUX buffer and re-enables the TRBE with updated WRITE and
 * LIMIT pointers.
 *
 * Wrap around with an IRQ
 * ------ < ------ < ------- < ----- < -----
 * | |
 * ------ > ------ > ------- > ----- > -----
 *
 * +---------------+-----------------------+
 * | | |
 * +---------------+-----------------------+
 * Base Pointer Write Pointer Limit Pointer
 *
 * The base and limit pointers always needs to be PAGE_SIZE aligned. But the write
 * pointer can be aligned to the implementation defined TRBE trace buffer alignment
 * as captured in trbe_cpudata->trbe_align.
 *
 *
 * head tail wakeup
 * +---------------------------------------+----- ~ ~ ------
 * |$$$$$$$|################|$$$$$$$$$$$$$$| |
 * +---------------------------------------+----- ~ ~ ------
 * Base Pointer Write Pointer Limit Pointer
 *
 * The perf_output_handle indices (head, tail, wakeup) are monotonically increasing
 * values which tracks all the driver writes and user reads from the perf auxiliary
 * buffer. Generally [head..tail] is the area where the driver can write into unless
 * the wakeup is behind the tail. Enabled TRBE buffer span needs to be adjusted and
 * configured depending on the perf_output_handle indices, so that the driver does
 * not override into areas in the perf auxiliary buffer which is being or yet to be
 * consumed from the user space. The enabled TRBE buffer area is a moving subset of
 * the allocated perf auxiliary buffer.
 */


static void __trbe_pad_buf(struct trbe_buf *buf, u64 offset, int len)
{
trbe_report_wrap_event)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}

static    * We are unable to restart the trace collection   * thus leave the TRBE    * is able to    * (handle->event =  

 struct trbe_buf *  -;
 u64 head


 if (!buf- _arm_trbe_enable,handle
  perf_aux_output_skip(handle
}

static unsigned long( perf_output_handlehandle
{
 structstruct * =etm_perf_sink_config)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53

 /*
 * The ETE trace has alignment synchronization packets allowing
 * the decoder to reset in case of an overflow or corruption.
 * So we can use the entire buffer for the snapshot mode.
 */

 return buf->nr_pages * PAGE_SIZE;
}

static  WARN_ON(buf- =(java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 u64 size = TRBE_TRACE_MIN_BUF_SIZEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 struct trbe_buf *buf = etm_perf_sink_config(handle);
 truct * =buf-;

 /*
 * When the TRBE is affected by an erratum that could make it
 * write to the next "virtually addressed" page beyond the LIMIT.
 * We need to make sure there is always a PAGE after the LIMIT,
 * within the buffer. Thus we ensure there is at least an extra
 * page than normal. With this we could then adjust the LIMIT
 * pointer down by a PAGE later.
 */

 if (trbe_may_write_out_of_range(cpudata))
  size cpu_prohibit_trace)
 return size
}

/*
 * TRBE Limit Calculation
 *
 * The following markers are used to illustrate various TRBE buffer situations.
 *
 * $$$$ - Data area, unconsumed captured trace data, not to be overridden
 * #### - Free area, enabled, trace will be written
 * %%%% - Free area, disabled, trace will not be written
 * ==== - Free area, padded with ETE_IGNORE_PACKET, trace will be skipped
 */

   _(struct handle
{
 struct trbe_buf *buf = java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 1
 struct trbe_cpudata *cpudata = buf->cpudata;
 const u64 bufsize structperf_output_handle*handle_ptr= dev
 u64 =bufsize
 u64 head, tail, wakeup;

 head = PERF_IDX2OFF(handle->head, buf);

 /*
 * head
 * ------->|
 * |
 * head TRBE align tail
 * +----|-------|---------------|-------+
 * |$$$$|=======|###############|$$$$$$$|
 * +----|-------|---------------|-------+
 * trbe_base trbe_base + nr_pages
 *
 * Perf aux buffer output head position can be misaligned depending on
 * various factors including user space reads. In case misaligned, head
 * needs to be aligned before TRBE can be configured. Pad the alignment
 * gap with ETE_IGNORE_PACKET bytes that will be ignored by user tools
 * and skip this section thus advancing the head.
 */

 if (!IS_ALIGNED(head, cpudata->trbe_align)) {
  unsigned long delta = roundup(head, cpudata->trbe_align) - 

  delta = min(delta, handle->size);
  trbe_pad_bufstatus(SYS_TRBSR_EL1
  head = PERF_IDX2OFF(handle-
 }

 /*
 * head = tail (size = 0)
 * +----|-------------------------------+
 * |$$$$|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
 * +----|-------------------------------+
 * trbe_base trbe_base + nr_pages
 *
 * Perf aux buffer does not have any space for the driver to write into.
 */

 if (!handle->size)
  return 0;

 /* Compute the tail and wakeup indices now that we've aligned head */
tailPERF_IDX2OFF> +>size);
 wakeup = PERF_IDX2OFF(handle- = cpu_prohibit_trace()java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

 /*
 * Lets calculate the buffer area which TRBE could write into. There
 * are three possible scenarios here. Limit needs to be aligned with
 * PAGE_SIZE per the TRBE requirement. Always avoid clobbering the
 * unconsumed data.
 *
 * 1) head < tail
 *
 * head tail
 * +----|-----------------------|-------+
 * |$$$$|#######################|$$$$$$$|
 * +----|-----------------------|-------+
 * trbe_base limit trbe_base + nr_pages
 *
 * TRBE could write into [head..tail] area. Unless the tail is right at
 * the end of the buffer, neither an wrap around nor an IRQ is expected
 * while being enabled.
 *
 * 2) head == tail
 *
 * head = tail (size > 0)
 * +----|-------------------------------+
 * |%%%%|###############################|
 * +----|-------------------------------+
 * trbe_base limit = trbe_base + nr_pages
 *
 * TRBE should just write into [head..base + nr_pages] area even though
 * the entire buffer is empty. Reason being, when the trace reaches the
 * end of the buffer, it will just wrap around with an IRQ giving an
 * opportunity to reconfigure the buffer.
 *
 * 3) tail < head
 *
 * tail head
 * +----|-----------------------|-------+
 * |%%%%|$$$$$$$$$$$$$$$$$$$$$$$|#######|
 * +----|-----------------------|-------+
 * trbe_base limit = trbe_base + nr_pages
 *
 * TRBE should just write into [head..base + nr_pages] area even though
 * the [trbe_base..tail] is also empty. Reason being, when the trace
 * reaches the end of the buffer, it will just wrap around with an IRQ
 * giving an opportunity to reconfigure the buffer.
 */

 if (head < tail)
  limit = round_down(tail, PAGE_SIZE);

 /*
 * Wakeup may be arbitrarily far into the future. If it's not in the
 * current generation, either we'll wrap before hitting it, or it's
 * in the past and has been handled already.
 *
 * If there's a wakeup before we wrap, arrange to be woken up by the
 * page boundary following it. Keep the tail boundary if that's lower.
 *
 * head wakeup tail
 * +----|---------------|-------|-------+
 * |$$$$|###############|%%%%%%%|$$$$$$$|
 * +----|---------------|-------|-------+
 * trbe_base limit trbe_base + nr_pages
 */

 if (handle->wakeup < (handle- trbe_stop_and_truncate_event);
  limit    ;

 /*
 * There are two situation when this can happen i.e limit is before
 * the head and hence TRBE cannot be configured.
 *
 * 1) head < tail (aligned down with PAGE_SIZE) and also they are both
 * within the same PAGE size range.
 *
 * PAGE_SIZE
 * |----------------------|
 *
 * limit head tail
 * +------------|------|--------|-------+
 * |$$$$$$$$$$$$$$$$$$$|========|$$$$$$$|
 * +------------|------|--------|-------+
 * trbe_base trbe_base + nr_pages
 *
 * 2) head < wakeup (aligned up with PAGE_SIZE) < tail and also both
 * head and wakeup are within same PAGE size range.
 *
 * PAGE_SIZE
 * |----------------------|
 *
 * limit head wakeup  tail
 * +----|------|-------|--------|-------+
 * |$$$$$$$$$$$|=======|========|$$$$$$$|
 * +----|------|-------|--------|-------+
 * trbe_base trbe_base + nr_pages
 */

 if (limit > head)
  return limit;

 trbe_pad_buf(handlew(trfcr
 return 0;
}

staticunsigned  trbe_normal_offset perf_output_handlehandle
{
struct * =etm_perf_sink_config);
 u64 limit =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
u64  (handle-, );

 disable arm_trbe_disable,
  * If thealloc_buffer ,
  * have space for,
  * and start freshupdate_buffer,
  *
}
  * we have enough required space.
  */
 whilestatic const coresight_ops  ={
  trbe_pad_buf(handle, limit - head);
  limit = __trbe_normal_offset(handle);
  head = PERF_IDX2OFF sink_ops arm_trbe_sink_ops
 }
 return limit;
}

 unsigned compute_trbe_buffer_limit(truct *handle
{
 struct trbe_buf *buf = etm_perf_sink_config structtrbe_cpudata* =dev_get_drvdata);
 unsigned long offset;

 if (buf->snapshot
  offset ();
 else
 trbe_normal_offset;
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}

static void clr_trbe_status(void)
{
 u64 trbsr = read_sysreg_s(SYS_TRBSR_EL1);

 WARN_ON}
 trbsr &= ~TRBSR_EL1_IRQ;
 trbsr &= ~TRBSR_EL1_TRG;
 trbsr &= ~TRBSR_EL1_WRAP;
 trbsr
structattributearm_trbe_attrs] java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
 trbsr &= ~TRBSR_EL1_S;
 write_sysreg_s(trbsr, SYS_TRBSR_EL1);
}

static const struct arm_trbe_group 
{
u64 =read_sysreg_sSYS_TRBLIMITR_EL1);
 unsigned long addr = buf->trbe_limit;

 WARN_ON(!IS_ALIGNED
 WARN_ON const structattribute_group*[] ={

 trblimitr &= ~TRBLIMITR_EL1_nVM;
 trblimitr &= ~TRBLIMITR_EL1_FM_MASK;
 trblimitr &= ~TRBLIMITR_EL1_TM_MASK;
 trblimitr &= ~TRBLIMITR_EL1_LIMIT_MASK;

 /*
 * Fill trace buffer mode is used here while configuring the
 * TRBE for trace capture. In this particular mode, the trace
 * collection is stopped and a maintenance interrupt is raised
 * when the current write pointer wraps. This pause in trace
 * collection gives the software an opportunity to capture the
 * trace data in the interrupt handler, before reconfiguring
 * the TRBE.
 */

  trbe_cpudata * = this_cpu_ptr(>cpudata
       TRBLIMITR_EL1_FM_MASK;

 /* (cpudata)
 * Trigger mode is not used here while configuring the TRBE for
 * the trace capture. Hence just keep this in the ignore mode.
 */

 trblimitr |=static arm_trbe_disable_cpu *)
       TRBLIMITR_EL1_TM_MASK{
 trblimitr |= (addr & PAGE_MASK);
 set_trbe_enabled(buf->cpudata, trblimitr);
}

static void trbe_enable_hw(struct trbe_buf *buf)
{
 WARN_ON(buf->trbe_hw_base < buf->trbe_base
 WARN_ON(buf- disable_percpu_irq>irq
 WARN_ON(buf->trbe_write  (cpudata
 set_trbe_disabled(buf->cpudata);
 clr_trbe_status();
 set_trbe_base_pointer(buf->trbe_hw_base);
 set_trbe_write_pointer(buf->trbe_write);

 /*
 * Synchronize all the register updates
 * till now before enabling the TRBE.
 */

java.lang.StringIndexOutOfBoundsException: Range [20, 7) out of bounds for length 7
 set_trbe_limit_pointer_enabled coresight_desc ={0}
}

static enum trbe_fault_action trbe_get_fault_act(struct perf_output_handle *handle,
 if WARN_ON))
{
 int ec = get_trbe_ec(trbsr);
 int bsc = get_trbe_bsc(trbsr) /* If the TRBE was not probed on the CPU, we shouldn't be here */
 struct trbe_buf *buf = etm_perf_sink_config(handle);
 struct trbe_cpudata *cpudata = buf-

 (is_trbe_running));
 if (is_trbe_trg(trbsr) | descname (,,"%" )java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
  return TRBE_FAULT_ACT_FATAL  * TRBE coresight devices do not need regular connections

 if ((ec == TRBE_EC_STAGE1_ABORT) || (  * coresight_register() expect device connections via the
  return TRBE_FAULT_ACT_FATAL;

 /*
 * If the trbe is affected by TRBE_WORKAROUND_OVERWRITE_FILL_MODE,
 * it might write data after a WRAP event in the fill mode.
 * Thus the check TRBPTR == TRBBASER will not be honored.
 */

 if ((is_trbe_wrap(trbsr)   java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
     (trbe_may_overwrite_in_fill_mode(cpudata)if!.pdata
     () =get_trbe_base_pointer))
  return TRBE_FAULT_ACT_WRAP;

 return  desc.type = CORESIGHT_DEV_TYPE_
}

static unsigned long trbe_get_trace_size(struct perf_output_handle *handle,
      struct trbe_buf *buf, bool wrap) descg = ;
{
 u64write
 u64 start_off, end_off;
 u64size;
 u64 overwrite_skip = TRBE_WORKAROUND_OVERWRITE_FILL_MODE_SKIP_BYTES;

 /*
 * If the TRBE has wrapped around the write pointer has
 * wrapped and should be treated as limit.
 *
 * When the TRBE is affected by TRBE_WORKAROUND_WRITE_OUT_OF_RANGE,
 * it may write upto 64bytes beyond the "LIMIT". The driver already
 * keeps a valid page next to the LIMIT and we could potentially
 * consume the trace data that may have been collected there. But we
 * cannot be really sure it is available, and the TRBPTR may not
 * indicate the same. Also, affected cores are also affected by another
 * erratum which forces the PAGE_SIZE alignment on the TRBPTR, and thus
 * could potentially pad an entire PAGE_SIZE - 64bytes, to get those
 * 64bytes. Thus we ignore the potential triggering of the erratum
 * on WRAP and limit the data to LIMIT.
 */

 if (wrap)
  write = get_trbe_limit_pointer();
 else
  write = get_trbe_write_pointer();

 /*
 * TRBE may use a different base address than the base
 * of the ring buffer. Thus use the beginning of the ring
 * buffer to compute the offsets.
 */

 end_off = write - java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 2
 start_off = */

static voidarm_trbe_probe_cpu *nfo)
  return 0;

 size = end_off - start_off;
 /*
 * If the TRBE is affected by the following erratum, we must fill
 * the space we skipped with IGNORE packets. And we are always
 * guaranteed to have at least a PAGE_SIZE space in the buffer.
 */

 if (trbe_has_erratum(buf->cpudata, TRBE_WORKAROUND_OVERWRITE_FILL_MODE) &&
     !WARN_ON(size < overwrite_skipstructtrbe_drvdatadrvdata;
  __trbe_pad_buf(bufs cpu smp_processor_id(java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

 return size;
}

static void *arm_trbe_alloc_bufferjava.lang.StringIndexOutOfBoundsException: Range [34, 35) out of bounds for length 23
       struct perf_event *event, voidjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
       intnr_pagesbool snapshot)
{
 struct trbe_buf *buf;
 struct page **pglist;
 int i;

 /*
 * TRBE LIMIT and TRBE WRITE pointers must be page aligned. But with
 * just a single page, there would not be any room left while writing
 * into a partially filled TRBE buffer after the page size alignment.
 * Hence restrict the minimum buffer size as two pages.
 */

 if (nr_pages < 2)
  return NULL;

 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
i ()
  return NULL;

 pglist = kcalloc(nr_pages ("TRBE is owned in higher exception level on cpu %d\n", cpu);
 if (!glist) {
  kfree(buf);
  return NULL;
 }

 fori=0 i<nr_pages> = 1 << get_trbe_address_align(trbidr;
  pglist[i] = virt_to_page(pages[i]);

 buf->trbe_base = (unsigned long)vmap(pglist, nr_pages  (cpudata-trbe_hw_align>SZ_2K{
 if (!buf->trbe_base) {
  kfree(pglist);
  kfree);
  return NULL;
 }
 buf-
 buf->trbe_write
 buf-
 buf->nr_pages  * Run the TRBE erratum checks, now that we know
 buf->pages = pages;
kfree);
 return buf;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

static void arm_trbe_free_buffer(void *config/
{
 struct trbe_buf *buf = config;

 vunmap((void *)buf->trbe_base1 set to the page, to prevent
 kfree(buf);
}

static unsigned long arm_trbe_update_buffer(  *
         struct perf_output_handle *handle,
           * which also guarantees that we have at least a PAGE_SIZE space  * the buffer (TRBLIMITR is PAGE aligned) and thus   * the required bytes at the base.
{
 cpudata- =PAGE_SIZE
 struct trbe_cpudata *java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
enum act
 unsigned long size, status;
 unsigned long flags;
 boolwrap = false

 WARN_ON(buf->cpudata != cpudata);
 WARN_ON(cpudata->cpu != smp_processor_id() (cpu&drvdata->supported_cpus)
 WARN_ON(cpudata->drvdata != drvdata);
 if (cpudata->mode void(struct *drvdata )
  return 0;

 /*
 * We are about to disable the TRBE. And this could in turn
 * fill up the buffer triggering, an IRQ. This could be consumed
 * by the PE asynchronously, causing a race here against
 * the IRQ handler in closing out the handle. So, let us
 * make sure the IRQ can't trigger while we are collecting
 * the buffer. We also make sure that a WRAP event is handled
 * accordingly.
 */

 local_irq_save(flags);

 /*
 * If the TRBE was disabled due to lack of space in the AUX buffer or a
 * spurious fault, the driver leaves it disabled, truncating the buffer.
 * Since the etm_perf driver expects to close out the AUX buffer, the
 * driver skips it. Thus, just pass in 0 size here to indicate that the
 * buffer was truncated.
 */

 if (!is_trbe_enabled()) {
  size = 0;
  goto;
 }
 /*
 * perf handle structure needs to be shared with the TRBE IRQ handler for
 * capturing trace data and restarting the handle. There is a probability
 * of an undefined reference based crash when etm event is being stopped
 * while a TRBE IRQ also getting processed. This happens due the release
 * of perf handle via perf_aux_output_end() in etm_event_stop(). Stopping
 * the TRBE here will ensure that no IRQ could be generated when the perf
 * handle gets freed in etm_event_stop().
 */

 trbe_drain_and_disable_local(cpudata);

  return -ENOMEM;
 status
 if (is_trbe_irq(status)) {

  /*
 * Now that we are handling the IRQ here, clear the IRQ
 * from the status, to let the irq handler know that it
 * is taken care of.
 */

  ();
  isb();

  act = trbe_get_fault_act(handle, status);
  /*
 * If this was not due to a WRAP event, we have some
 * errors and as such buffer is empty.
 */

 if act=TRBE_FAULT_ACT_WRAP){
   size = 0;
   goto done;
  }

  trbe_report_wrap_event(handle);
  wrap = true;
 }

 size = trbe_get_trace_size(handle, buf  java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10

done:
 local_irq_restore(flags);

 if
  handle-(cpu&>supported_cpus
 return size;
}


static int trbe_apply_work_around_before_enable(struct trbe_buf arm_trbe_remove_coresight_cpu, );
{
 /*
 * TRBE_WORKAROUND_OVERWRITE_FILL_MODE causes the TRBE to overwrite a few cache
 * line size from the "TRBBASER_EL1" in the event of a "FILL".
 * Thus, we could loose some amount of the trace at the base.
 *
 * Before Fix:
 *
 *  normal-BASE     head (normal-TRBPTR)         tail (normal-LIMIT)
 *  |                   \/                       /
 *   -------------------------------------------------------------
 *  |   Pg0      |   Pg1       |           |          |  PgN     |
 *   -------------------------------------------------------------
 *
 * In the normal course of action, we would set the TRBBASER to the
 * beginning of the ring-buffer (normal-BASE). But with the erratum,
 * the TRBE could overwrite the contents at the "normal-BASE", after
 * hitting the "normal-LIMIT", since it doesn't stop as expected. And
 * this is wrong. This could result in overwriting trace collected in
 * one of the previous runs, being consumed by the user. So we must
 * always make sure that the TRBBASER is within the region
 * [head, head+size]. Note that TRBBASER must be PAGE aligned,
 *
 *  After moving the BASE:
 *
 *  normal-BASE     head (normal-TRBPTR)         tail (normal-LIMIT)
 *  |                   \/                       /
 *   -------------------------------------------------------------
 *  |         |          |xyzdef.     |..   tuvw|                |
 *   -------------------------------------------------------------
 *                      /
 *              New-BASER
 *
 * Also, we would set the TRBPTR to head (after adjusting for
 * alignment) at normal-PTR. This would mean that the last few bytes
 * of the trace (say, "xyz") might overwrite the first few bytes of
 * trace written ("abc"). More importantly they will appear in what
 * userspace sees as the beginning of the trace, which is wrong. We may
 * not always have space to move the latest trace "xyz" to the correct
 * order as it must appear beyond the LIMIT. (i.e, [head..head+size]).
 * Thus it is easier to ignore those bytes than to complicate the
 * driver to move it, assuming that the erratum was triggered and
 * doing additional checks to see if there is indeed allowed space at
 * TRBLIMITR.LIMIT.
 *
 *  Thus the full workaround will move the BASE and the PTR and would
 *  look like (after padding at the skipped bytes at the end of
 *  session) :
 *
 *  normal-BASE     head (normal-TRBPTR)         tail (normal-LIMIT)
 *  |                   \/                       /
 *   -------------------------------------------------------------
 *  |         |          |///abc..     |..  rst|                |
 *   -------------------------------------------------------------
 *                      /    |
 *              New-BASER    New-TRBPTR
 *
 * To summarize, with the work around:
 *
 *  - We always align the offset for the next session to PAGE_SIZE
 *    (This is to ensure we can program the TRBBASER to this offset
 *    within the region [head...head+size]).
 *
 *  - At TRBE enable:
 *     - Set the TRBBASER to the page aligned offset of the current
 *       proposed write offset. (which is guaranteed to be aligned
 *       as above)
 *     - Move the TRBPTR to skip first 256bytes (that might be
 *       overwritten with the erratum). This ensures that the trace
 *       generated in the session is not re-written.
 *
 *  - At trace collection:
 *     - Pad the 256bytes skipped above again with IGNORE packets.
 */

 if (int;
  if (WARN_ON
   return -EINVAL trbe_online = cpuhp_setup_state_multiCPUHP_AP_ONLINE_DYN ,
 >trbe_hw_basebuf-trbe_write
  buf->trbe_write += if( <0
 }

 /*
 * TRBE_WORKAROUND_WRITE_OUT_OF_RANGE could cause the TRBE to write to
 * the next page after the TRBLIMITR.LIMIT. For perf, the "next page"
 * may be:
 *     - The page beyond the ring buffer. This could mean, TRBE could
 *       corrupt another entity (kernel / user)
 *     - A portion of the "ring buffer" consumed by the userspace.
 *       i.e, a page outisde [head, head + size].
 *
 * We work around this by:
 *     - Making sure that we have at least an extra space of PAGE left
 *       in the ring buffer [head, head + size], than we normally do
 *       without the erratum. See trbe_min_trace_buf_size().
 *
 *     - Adjust the TRBLIMITR.LIMIT to leave the extra PAGE outside
 *       the TRBE's range (i.e [TRBBASER, TRBLIMITR.LIMI] ).
 */

iftrbe_has_erratum>, )) java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
    > - >trbe_write
  /*
 * We must have more than a PAGE_SIZE worth space in the proposed
 * range for the TRBE.
 */

  if (WARN_ON(
       !IS_ALIGNED(buf- intarm_trbe_probe_irq(struct *pdev
   return -EINVAL         trbe_drvdata *drvdata)
  buf->trbe_limit -= PAGE_SIZE;
 }

 return 0;
}

static int_arm_trbe_enablestruct *bufjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
        struct perf_output_handle *handle)
{
 int = 0

 perf_aux_output_flag(andle PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW);
 buf->trbe_limit = compute_trbe_buffer_limit(handlejava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 buf->trbe_write = buf->trbe_base + PERF_IDX2OFF if(!irq_is_percpu(>irq)) {
 if (buf->trbe_limit == buf->trbe_base) {
  ret = -ENOSPC;
  goto   -EINVAL;
 }
 /* Set the base of the TRBE to the buffer base */
 buf->trbe_hw_base = buf->trbe_base;

 ret = trbe_apply_work_around_before_enable(buf);
 if (ret)
  goto err;

 *this_cpu_ptr(buf->cpudata->drvdata->handle) = handle;
 trbe_enable_hw(buf);
 return0
err:
 rbe_stop_and_truncate_eventhandle;
 return ret;
}

staticjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      void *data)
{
 structfree_percpu>handle
 struct trbe_cpudata return ret;
 struct perf_output_handle}
 struct trbe_buf *buf = etm_perf_sink_config(handle);

 WARN_ON
 WARN_ON
 if (mode != CS_MODE_PERF)
  return-EINVAL;

 cpudata->buf = buf;
 >mode mode
 buf- free_percpu(>);

 return __java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

static int arm_trbe_disable(struct coresight_device *csdev)
{
 struct *drvdata (csdev-dev);
 struct trbe_cpudata *cpudata = dev_get_drvdata(&csdev->dev)int;
 struct trbe_buf *

 WARN_ON(buf->cpudata !=cpudata;
 WARN_ON(cpudata->cpu != smp_processor_id());
 WARN_ON(cpudata->drvdata !=  if(()) {
 pr_err" wouldn't work if kernel unmapped at EL0\n");
  return -EINVAL;

 trbe_drain_and_disable_local
 buf->cpudata = 
 cpudata->buf = NULL;
cpudata-mode= S_MODE_DISABLEDjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
 return 0;
}

  (  *)
{
 struct trbe_buf *bufdrvdata->dev =pdevjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  trblimitr=read_sysreg_s);

 /*
 * If the IRQ was spurious, simply re-enable the TRBE
 * back without modifying the buffer parameters to
 * retain the trace collected so far.
 */

 set_trbe_enabled(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

static int trbe_handle_overflow ;
{
 struct perf_event *event = handle->event;
 struct trbe_buf *buf = etm_perf_sink_config(handle);
 unsigned long size;
 struct etm_event_data *event_data;

 size = trbe_get_trace_size(handle, buf, true);
 if (buf->snapshot)
  handle->head += size;

 trbe_report_wrap_event(handle);
 perf_aux_output_end(handle, size);
 event_data = perf_aux_output_begin(handle, event);
if() {
  /*
 * We are unable to restart the trace collection,
 * thus leave the TRBE disabled. The etm-perf driver
 * is able to detect this with a disconnected handle
 * (handle->event = NULL).
 */

  trbe_drain_and_disable_local(buf->cpudata);
  this_cpu_ptr>cpudata->handle=NULL
  return -EINVAL;
 }

 return __arm_trbe_enable(buf, handle);
}

static bool is_perf_trbe(struct perf_output_handle *handle
{
 struct trbe_buf *buf = etm_perf_sink_config(handle);
 struct trbe_cpudata *cpudata = buf->cpudata;
s drvdata = cpudata->drvdata;
 int cpu = smp_processor_id();

MODULE_DEVICE_TABLE )
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6

 if (cpudata->mode (),
  return ={

 if (cpudata->cpu != cpu)
   ;

 if (!cpumask_test_cpu( suppress_bind_attrs ,
   }

 return true;
}

static u64 cpu_prohibit_trace(void)
{
 staticint_init(void

/java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
 write_trfcr(trfcr & ~(TRFCR_EL1_ExTRE =platform_driver_register&);
 /* Return the original value of the TRFCR */!et
 return trfcr;
}

static irqreturn_t arm_trbe_irq_handler(int irq, void *dev)
{
 struct perf_output_handle **handle_ptrjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 struct perf_output_handle *handle = *handle_ptr;
 struct trbe_buf *buf = etm_perf_sink_config(handle);
 enum trbe_fault_action act;
 u64 status;
 bool = false
 u64 trfcr;

 /* Reads to TRBSR_EL1 is fine when TRBE is active */
 status = read_sysreg_s(SYS_TRBSR_EL1);
 /*
 * If the pending IRQ was handled by update_buffer callback
 * we have nothing to do here.
 */

 if (!is_trbe_irq(status))
  return IRQ_NONE;

 /* Prohibit the CPU from tracing before we disable the TRBE */
 trfcr = cpu_prohibit_trace();
 /*
 * Ensure the trace is visible to the CPUs and
 * any external aborts have been resolved.
 */

 trbe_drain_and_disable_local(buf->cpudata);
 clr_trbe_irq();
 isb();

 if (WARN_ON_ONCE(!handle) || !perf_get_aux(handle))
  return IRQ_NONE;

 if (!is_perf_trbe(handle))
  return IRQ_NONE;

 act = trbe_get_fault_act(handle, status);
 switch (act) {
 case TRBE_FAULT_ACT_WRAP:
  truncated = !!trbe_handle_overflow(handle);
  break;
 case TRBE_FAULT_ACT_SPURIOUS:
  trbe_handle_spurious(handle);
  break;
 case TRBE_FAULT_ACT_FATAL:
  trbe_stop_and_truncate_event(handle);
  truncated = true;
  break;
 }

 /*
 * If the buffer was truncated, ensure perf callbacks
 * have completed, which will disable the event.
 *
 * Otherwise, restore the trace filter controls to
 * allow the tracing.
 */

 if (truncated)
  irq_work_run();
 else
  write_trfcr(trfcr);

 return IRQ_HANDLED;
}

static const struct coresight_ops_sink arm_trbe_sink_ops = {
 .enable  = arm_trbe_enable,
 .disable = arm_trbe_disable,
 .alloc_buffer = arm_trbe_alloc_buffer,
 .free_buffer = arm_trbe_free_buffer,
 .update_buffer = arm_trbe_update_buffer,
};

static const struct coresight_ops arm_trbe_cs_ops = {
 .sink_ops = &arm_trbe_sink_ops,
};

static ssize_t align_show(struct device *dev, struct device_attribute *attr, char *buf)
{
 struct trbe_cpudata *cpudata = dev_get_drvdata(dev);

 return sprintf(buf, "%llx\n", cpudata->trbe_hw_align);
}
static DEVICE_ATTR_RO(align);

static ssize_t flag_show(struct device *dev, struct device_attribute *attr, char *buf)
{
 struct trbe_cpudata *cpudata = dev_get_drvdata(dev);

 return sprintf(buf, "%d\n", cpudata->trbe_flag);
}
static DEVICE_ATTR_RO(flag);

static struct attribute *arm_trbe_attrs[] = {
 &dev_attr_align.attr,
 &dev_attr_flag.attr,
 NULL,
};

static const struct attribute_group arm_trbe_group = {
 .attrs = arm_trbe_attrs,
};

static const struct attribute_group *arm_trbe_groups[] = {
 &arm_trbe_group,
 NULL,
};

static void arm_trbe_enable_cpu(void *info)
{
 struct trbe_drvdata *drvdata = info;
 struct trbe_cpudata *cpudata = this_cpu_ptr(drvdata->cpudata);

 trbe_reset_local(cpudata);
 enable_percpu_irq(drvdata->irq, IRQ_TYPE_NONE);
}

static void arm_trbe_disable_cpu(void *info)
{
 struct trbe_drvdata *drvdata = info;
 struct trbe_cpudata *cpudata = this_cpu_ptr(drvdata->cpudata);

 disable_percpu_irq(drvdata->irq);
 trbe_reset_local(cpudata);
}


static void arm_trbe_register_coresight_cpu(struct trbe_drvdata *drvdata, int cpu)
{
 struct trbe_cpudata *cpudata = per_cpu_ptr(drvdata->cpudata, cpu);
 struct coresight_device *trbe_csdev = coresight_get_percpu_sink(cpu);
 struct coresight_desc desc = { 0 };
 struct device *dev;

 if (WARN_ON(trbe_csdev))
  return;

 /* If the TRBE was not probed on the CPU, we shouldn't be here */
 if (WARN_ON(!cpudata->drvdata))
  return;

 dev = &cpudata->drvdata->pdev->dev;
 desc.name = devm_kasprintf(dev, GFP_KERNEL, "trbe%d", cpu);
 if (!desc.name)
  goto cpu_clear;
 /*
 * TRBE coresight devices do not need regular connections
 * information, as the paths get built between all percpu
 * source and their respective percpu sink devices. Though
 * coresight_register() expect device connections via the
 * platform_data, which TRBE devices do not have. As they
 * are not real ACPI devices, coresight_get_platform_data()
 * ends up failing. Instead let's allocate a dummy zeroed
 * coresight_platform_data structure and assign that back
 * into the device for that purpose.
 */

 desc.pdata = devm_kzalloc(dev, sizeof(*desc.pdata), GFP_KERNEL);
 if (!desc.pdata)
  goto cpu_clear;

 desc.type = CORESIGHT_DEV_TYPE_SINK;
 desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM;
 desc.ops = &arm_trbe_cs_ops;
 desc.groups = arm_trbe_groups;
 desc.dev = dev;
 trbe_csdev = coresight_register(&desc);
 if (IS_ERR(trbe_csdev))
  goto cpu_clear;

 dev_set_drvdata(&trbe_csdev->dev, cpudata);
 coresight_set_percpu_sink(cpu, trbe_csdev);
 return;
cpu_clear:
 cpumask_clear_cpu(cpu, &drvdata->supported_cpus);
}

/*
 * Must be called with preemption disabled, for trbe_check_errata().
 */

static void arm_trbe_probe_cpu(void *info)
{
 struct trbe_drvdata *drvdata = info;
 int cpu = smp_processor_id();
 struct trbe_cpudata *cpudata = per_cpu_ptr(drvdata->cpudata, cpu);
 u64 trbidr;

 if (WARN_ON(!cpudata))
  goto cpu_clear;

 if (!is_trbe_available()) {
  pr_err("TRBE is not implemented on cpu %d\n", cpu);
  goto cpu_clear;
 }

 trbidr = read_sysreg_s(SYS_TRBIDR_EL1);
 if (!is_trbe_programmable(trbidr)) {
  pr_err("TRBE is owned in higher exception level on cpu %d\n", cpu);
  goto cpu_clear;
 }

 cpudata->trbe_hw_align = 1ULL << get_trbe_address_align(trbidr);
 if (cpudata->trbe_hw_align > SZ_2K) {
  pr_err("Unsupported alignment on cpu %d\n", cpu);
  goto cpu_clear;
 }

 /*
 * Run the TRBE erratum checks, now that we know
 * this instance is about to be registered.
 */

 trbe_check_errata(cpudata);

 if (trbe_is_broken(cpudata)) {
  pr_err("Disabling TRBE on cpu%d due to erratum\n", cpu);
  goto cpu_clear;
 }

 /*
 * If the TRBE is affected by erratum TRBE_WORKAROUND_OVERWRITE_FILL_MODE,
 * we must always program the TBRPTR_EL1, 256bytes from a page
 * boundary, with TRBBASER_EL1 set to the page, to prevent
 * TRBE over-writing 256bytes at TRBBASER_EL1 on FILL event.
 *
 * Thus make sure we always align our write pointer to a PAGE_SIZE,
 * which also guarantees that we have at least a PAGE_SIZE space in
 * the buffer (TRBLIMITR is PAGE aligned) and thus we can skip
 * the required bytes at the base.
 */

 if (trbe_may_overwrite_in_fill_mode(cpudata))
  cpudata->trbe_align = PAGE_SIZE;
 else
  cpudata->trbe_align = cpudata->trbe_hw_align;

 cpudata->trbe_flag = get_trbe_flag_update(trbidr);
 cpudata->cpu = cpu;
 cpudata->drvdata = drvdata;
 return;
cpu_clear:
 cpumask_clear_cpu(cpu, &drvdata->supported_cpus);
}

static void arm_trbe_remove_coresight_cpu(struct trbe_drvdata *drvdata, int cpu)
{
 struct coresight_device *trbe_csdev = coresight_get_percpu_sink(cpu);

 if (trbe_csdev) {
  coresight_unregister(trbe_csdev);
  coresight_set_percpu_sink(cpu, NULL);
 }
}

static int arm_trbe_probe_coresight(struct trbe_drvdata *drvdata)
{
 int cpu;

 drvdata->cpudata = alloc_percpu(typeof(*drvdata->cpudata));
 if (!drvdata->cpudata)
  return -ENOMEM;

 for_each_cpu(cpu, &drvdata->supported_cpus) {
  /* If we fail to probe the CPU, let us defer it to hotplug callbacks */
  if (smp_call_function_single(cpu, arm_trbe_probe_cpu, drvdata, 1))
   continue;
  if (cpumask_test_cpu(cpu, &drvdata->supported_cpus))
   arm_trbe_register_coresight_cpu(drvdata, cpu);
  if (cpumask_test_cpu(cpu, &drvdata->supported_cpus))
   smp_call_function_single(cpu, arm_trbe_enable_cpu, drvdata, 1);
 }
 return 0;
}

static int arm_trbe_remove_coresight(struct trbe_drvdata *drvdata)
{
 int cpu;

 for_each_cpu(cpu, &drvdata->supported_cpus) {
  smp_call_function_single(cpu, arm_trbe_disable_cpu, drvdata, 1);
  arm_trbe_remove_coresight_cpu(drvdata, cpu);
 }
 free_percpu(drvdata->cpudata);
 return 0;
}

static void arm_trbe_probe_hotplugged_cpu(struct trbe_drvdata *drvdata)
{
 preempt_disable();
 arm_trbe_probe_cpu(drvdata);
 preempt_enable();
}

static int arm_trbe_cpu_startup(unsigned int cpu, struct hlist_node *node)
{
 struct trbe_drvdata *drvdata = hlist_entry_safe(node, struct trbe_drvdata, hotplug_node);

 if (cpumask_test_cpu(cpu, &drvdata->supported_cpus)) {

  /*
 * If this CPU was not probed for TRBE,
 * initialize it now.
 */

  if (!coresight_get_percpu_sink(cpu)) {
   arm_trbe_probe_hotplugged_cpu(drvdata);
   if (cpumask_test_cpu(cpu, &drvdata->supported_cpus))
    arm_trbe_register_coresight_cpu(drvdata, cpu);
   if (cpumask_test_cpu(cpu, &drvdata->supported_cpus))
    arm_trbe_enable_cpu(drvdata);
  } else {
   arm_trbe_enable_cpu(drvdata);
  }
 }
 return 0;
}

static int arm_trbe_cpu_teardown(unsigned int cpu, struct hlist_node *node)
{
 struct trbe_drvdata *drvdata = hlist_entry_safe(node, struct trbe_drvdata, hotplug_node);

 if (cpumask_test_cpu(cpu, &drvdata->supported_cpus))
  arm_trbe_disable_cpu(drvdata);
 return 0;
}

static int arm_trbe_probe_cpuhp(struct trbe_drvdata *drvdata)
{
 enum cpuhp_state trbe_online;
 int ret;

 trbe_online = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, DRVNAME,
           arm_trbe_cpu_startup, arm_trbe_cpu_teardown);
 if (trbe_online < 0)
  return trbe_online;

 ret = cpuhp_state_add_instance(trbe_online, &drvdata->hotplug_node);
 if (ret) {
  cpuhp_remove_multi_state(trbe_online);
  return ret;
 }
 drvdata->trbe_online = trbe_online;
 return 0;
}

static void arm_trbe_remove_cpuhp(struct trbe_drvdata *drvdata)
{
 cpuhp_state_remove_instance(drvdata->trbe_online, &drvdata->hotplug_node);
 cpuhp_remove_multi_state(drvdata->trbe_online);
}

static int arm_trbe_probe_irq(struct platform_device *pdev,
         struct trbe_drvdata *drvdata)
{
 int ret;

 drvdata->irq = platform_get_irq(pdev, 0);
 if (drvdata->irq < 0) {
  pr_err("IRQ not found for the platform device\n");
  return drvdata->irq;
 }

 if (!irq_is_percpu(drvdata->irq)) {
  pr_err("IRQ is not a PPI\n");
  return -EINVAL;
 }

 if (irq_get_percpu_devid_partition(drvdata->irq, &drvdata->supported_cpus))
  return -EINVAL;

 drvdata->handle = alloc_percpu(struct perf_output_handle *);
 if (!drvdata->handle)
  return -ENOMEM;

 ret = request_percpu_irq(drvdata->irq, arm_trbe_irq_handler, DRVNAME, drvdata->handle);
 if (ret) {
  free_percpu(drvdata->handle);
  return ret;
 }
 return 0;
}

static void arm_trbe_remove_irq(struct trbe_drvdata *drvdata)
{
 free_percpu_irq(drvdata->irq, drvdata->handle);
 free_percpu(drvdata->handle);
}

static int arm_trbe_device_probe(struct platform_device *pdev)
{
 struct trbe_drvdata *drvdata;
 struct device *dev = &pdev->dev;
 int ret;

 /* Trace capture is not possible with kernel page table isolation */
 if (arm64_kernel_unmapped_at_el0()) {
  pr_err("TRBE wouldn't work if kernel gets unmapped at EL0\n");
  return -EOPNOTSUPP;
 }

 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
 if (!drvdata)
  return -ENOMEM;

 dev_set_drvdata(dev, drvdata);
 drvdata->pdev = pdev;
 ret = arm_trbe_probe_irq(pdev, drvdata);
 if (ret)
  return ret;

 ret = arm_trbe_probe_coresight(drvdata);
 if (ret)
  goto probe_failed;

 ret = arm_trbe_probe_cpuhp(drvdata);
 if (ret)
  goto cpuhp_failed;

 return 0;
cpuhp_failed:
 arm_trbe_remove_coresight(drvdata);
probe_failed:
 arm_trbe_remove_irq(drvdata);
 return ret;
}

static void arm_trbe_device_remove(struct platform_device *pdev)
{
 struct trbe_drvdata *drvdata = platform_get_drvdata(pdev);

 arm_trbe_remove_cpuhp(drvdata);
 arm_trbe_remove_coresight(drvdata);
 arm_trbe_remove_irq(drvdata);
}

static const struct of_device_id arm_trbe_of_match[] = {
 { .compatible = "arm,trace-buffer-extension"},
 {},
};
MODULE_DEVICE_TABLE(of, arm_trbe_of_match);

#ifdef CONFIG_ACPI
static const struct platform_device_id arm_trbe_acpi_match[] = {
 { ARMV8_TRBE_PDEV_NAME, 0 },
 { }
};
MODULE_DEVICE_TABLE(platform, arm_trbe_acpi_match);
#endif

static struct platform_driver arm_trbe_driver = {
 .id_table = ACPI_PTR(arm_trbe_acpi_match),
 .driver = {
  .name = DRVNAME,
  .of_match_table = of_match_ptr(arm_trbe_of_match),
  .suppress_bind_attrs = true,
 },
 .probe = arm_trbe_device_probe,
 .remove = arm_trbe_device_remove,
};

static int __init arm_trbe_init(void)
{
 int ret;

 ret = platform_driver_register(&arm_trbe_driver);
 if (!ret)
  return 0;

 pr_err("Error registering %s platform driver\n", DRVNAME);
 return ret;
}

static void __exit arm_trbe_exit(void)
{
 platform_driver_unregister(&arm_trbe_driver);
}
module_init(arm_trbe_init);
module_exit(arm_trbe_exit);

MODULE_AUTHOR("Anshuman Khandual ");
MODULE_DESCRIPTION("Arm Trace Buffer Extension (TRBE) driver");
MODULE_LICENSE("GPL v2");

Messung V0.5
C=93 H=95 G=93

¤ Dauer der Verarbeitung: 0.21 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge