static void tmc_etf_disable_hw(struct tmc_drvdata *drvdata) { CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); tmc_disable_hw(drvdata); CS_LOCK(drvdata->base); }
static void tmc_etf_disable_hw(struct tmc_drvdata *drvdata) { CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); tmc_disable_hw(drvdata); coresight_disclaim_device_unlocked(drvdata->base); CS_LOCK(drvdata->base); }
static void tmc_etb_disable_hw(struct tmc_drvdata *drvdata) { CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); /* * When operating in sysFS mode the content of the buffer needs to be * read before the TMC is disabled. */ if (local_read(&drvdata->mode) == CS_MODE_SYSFS) tmc_etb_dump_hw(drvdata); tmc_disable_hw(drvdata); CS_LOCK(drvdata->base); }
static void tmc_update_etf_buffer(struct coresight_device *csdev, struct perf_output_handle *handle, void *sink_config) { int i, cur; u32 *buf_ptr; u32 read_ptr, write_ptr; u32 status, to_read; unsigned long offset; struct cs_buffers *buf = sink_config; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); if (!buf) return; /* This shouldn't happen */ if (WARN_ON_ONCE(local_read(&drvdata->mode) != CS_MODE_PERF)) return; CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); read_ptr = readl_relaxed(drvdata->base + TMC_RRP); write_ptr = readl_relaxed(drvdata->base + TMC_RWP); /* * Get a hold of the status register and see if a wrap around * has occurred. If so adjust things accordingly. */ status = readl_relaxed(drvdata->base + TMC_STS); if (status & TMC_STS_FULL) { local_inc(&buf->lost); to_read = drvdata->size; } else { to_read = CIRC_CNT(write_ptr, read_ptr, drvdata->size); } /* * The TMC RAM buffer may be bigger than the space available in the * perf ring buffer (handle->size). If so advance the RRP so that we * get the latest trace data. */ if (to_read > handle->size) { u32 mask = 0; /* * The value written to RRP must be byte-address aligned to * the width of the trace memory databus _and_ to a frame * boundary (16 byte), whichever is the biggest. For example, * for 32-bit, 64-bit and 128-bit wide trace memory, the four * LSBs must be 0s. For 256-bit wide trace memory, the five * LSBs must be 0s. */ switch (drvdata->memwidth) { case TMC_MEM_INTF_WIDTH_32BITS: case TMC_MEM_INTF_WIDTH_64BITS: case TMC_MEM_INTF_WIDTH_128BITS: mask = GENMASK(31, 5); break; case TMC_MEM_INTF_WIDTH_256BITS: mask = GENMASK(31, 6); break; } /* * Make sure the new size is aligned in accordance with the * requirement explained above. */ to_read = handle->size & mask; /* Move the RAM read pointer up */ read_ptr = (write_ptr + drvdata->size) - to_read; /* Make sure we are still within our limits */ if (read_ptr > (drvdata->size - 1)) read_ptr -= drvdata->size; /* Tell the HW */ writel_relaxed(read_ptr, drvdata->base + TMC_RRP); local_inc(&buf->lost); } cur = buf->cur; offset = buf->offset; /* for every byte to read */ for (i = 0; i < to_read; i += 4) { buf_ptr = buf->data_pages[cur] + offset; *buf_ptr = readl_relaxed(drvdata->base + TMC_RRD); offset += 4; if (offset >= PAGE_SIZE) { offset = 0; cur++; /* wrap around at the end of the buffer */ cur &= buf->nr_pages - 1; } } /* * In snapshot mode all we have to do is communicate to * perf_aux_output_end() the address of the current head. In full * trace mode the same function expects a size to move rb->aux_head * forward. */ if (buf->snapshot) local_set(&buf->data_size, (cur * PAGE_SIZE) + offset); else local_add(to_read, &buf->data_size); CS_LOCK(drvdata->base); }
static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, struct perf_output_handle *handle, void *sink_config) { bool lost = false; int i, cur; const u32 *barrier; u32 *buf_ptr; u64 read_ptr, write_ptr; u32 status; unsigned long offset, to_read = 0, flags; struct cs_buffers *buf = sink_config; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); if (!buf) return 0; /* This shouldn't happen */ if (WARN_ON_ONCE(drvdata->mode != CS_MODE_PERF)) return 0; spin_lock_irqsave(&drvdata->spinlock, flags); /* Don't do anything if another tracer is using this sink */ if (atomic_read(csdev->refcnt) != 1) goto out; CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); read_ptr = tmc_read_rrp(drvdata); write_ptr = tmc_read_rwp(drvdata); /* * Get a hold of the status register and see if a wrap around * has occurred. If so adjust things accordingly. */ status = readl_relaxed(drvdata->base + TMC_STS); if (status & TMC_STS_FULL) { lost = true; to_read = drvdata->size; } else { to_read = CIRC_CNT(write_ptr, read_ptr, drvdata->size); } /* * The TMC RAM buffer may be bigger than the space available in the * perf ring buffer (handle->size). If so advance the RRP so that we * get the latest trace data. */ if (to_read > handle->size) { u32 mask = 0; /* * The value written to RRP must be byte-address aligned to * the width of the trace memory databus _and_ to a frame * boundary (16 byte), whichever is the biggest. For example, * for 32-bit, 64-bit and 128-bit wide trace memory, the four * LSBs must be 0s. For 256-bit wide trace memory, the five * LSBs must be 0s. */ switch (drvdata->memwidth) { case TMC_MEM_INTF_WIDTH_32BITS: case TMC_MEM_INTF_WIDTH_64BITS: case TMC_MEM_INTF_WIDTH_128BITS: mask = GENMASK(31, 4); break; case TMC_MEM_INTF_WIDTH_256BITS: mask = GENMASK(31, 5); break; } /* * Make sure the new size is aligned in accordance with the * requirement explained above. */ to_read = handle->size & mask; /* Move the RAM read pointer up */ read_ptr = (write_ptr + drvdata->size) - to_read; /* Make sure we are still within our limits */ if (read_ptr > (drvdata->size - 1)) read_ptr -= drvdata->size; /* Tell the HW */ tmc_write_rrp(drvdata, read_ptr); lost = true; } if (lost) perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED); cur = buf->cur; offset = buf->offset; barrier = barrier_pkt; /* for every byte to read */ for (i = 0; i < to_read; i += 4) { buf_ptr = buf->data_pages[cur] + offset; *buf_ptr = readl_relaxed(drvdata->base + TMC_RRD); if (lost && *barrier) { *buf_ptr = *barrier; barrier++; } offset += 4; if (offset >= PAGE_SIZE) { offset = 0; cur++; /* wrap around at the end of the buffer */ cur &= buf->nr_pages - 1; } } /* In snapshot mode we have to update the head */ if (buf->snapshot) { handle->head = (cur * PAGE_SIZE) + offset; to_read = buf->nr_pages << PAGE_SHIFT; } CS_LOCK(drvdata->base); out: spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; }