2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-06-12 05:29:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Google, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IOTRACE_IMPL
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2014-06-12 05:29:41 +00:00
|
|
|
#include <asm/io.h>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2014-06-12 05:29:41 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct iotrace - current trace status and checksum
|
|
|
|
*
|
|
|
|
* @start: Start address of iotrace buffer
|
2018-06-08 17:53:27 +00:00
|
|
|
* @size: Actual size of iotrace buffer in bytes
|
|
|
|
* @needed_size: Needed of iotrace buffer in bytes
|
2014-06-12 05:29:41 +00:00
|
|
|
* @offset: Current write offset into iotrace buffer
|
2018-05-30 20:09:58 +00:00
|
|
|
* @region_start: Address of IO region to trace
|
|
|
|
* @region_size: Size of region to trace. if 0 will trace all address space
|
2014-06-12 05:29:41 +00:00
|
|
|
* @crc32: Current value of CRC chceksum of trace records
|
|
|
|
* @enabled: true if enabled, false if disabled
|
|
|
|
*/
|
|
|
|
static struct iotrace {
|
|
|
|
ulong start;
|
|
|
|
ulong size;
|
2018-06-08 17:53:27 +00:00
|
|
|
ulong needed_size;
|
2014-06-12 05:29:41 +00:00
|
|
|
ulong offset;
|
2018-05-30 20:09:58 +00:00
|
|
|
ulong region_start;
|
|
|
|
ulong region_size;
|
2014-06-12 05:29:41 +00:00
|
|
|
u32 crc32;
|
|
|
|
bool enabled;
|
|
|
|
} iotrace;
|
|
|
|
|
|
|
|
static void add_record(int flags, const void *ptr, ulong value)
|
|
|
|
{
|
|
|
|
struct iotrace_record srec, *rec = &srec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't support iotrace before relocation. Since the trace buffer
|
|
|
|
* is set up by a command, it can't be enabled at present. To change
|
|
|
|
* this we would need to set the iotrace buffer at build-time. See
|
|
|
|
* lib/trace.c for how this might be done if you are interested.
|
|
|
|
*/
|
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !iotrace.enabled)
|
|
|
|
return;
|
|
|
|
|
2018-05-30 20:09:58 +00:00
|
|
|
if (iotrace.region_size)
|
|
|
|
if ((ulong)ptr < iotrace.region_start ||
|
|
|
|
(ulong)ptr > iotrace.region_start + iotrace.region_size)
|
|
|
|
return;
|
|
|
|
|
2014-06-12 05:29:41 +00:00
|
|
|
/* Store it if there is room */
|
|
|
|
if (iotrace.offset + sizeof(*rec) < iotrace.size) {
|
|
|
|
rec = (struct iotrace_record *)map_sysmem(
|
|
|
|
iotrace.start + iotrace.offset,
|
|
|
|
sizeof(value));
|
2018-06-08 17:53:27 +00:00
|
|
|
} else {
|
|
|
|
WARN_ONCE(1, "WARNING: iotrace buffer exhausted, please check needed length using \"iotrace stats\"\n");
|
|
|
|
iotrace.needed_size += sizeof(struct iotrace_record);
|
|
|
|
return;
|
2014-06-12 05:29:41 +00:00
|
|
|
}
|
2018-06-08 17:53:27 +00:00
|
|
|
|
2018-05-30 20:09:59 +00:00
|
|
|
rec->timestamp = timer_get_us();
|
2014-06-12 05:29:41 +00:00
|
|
|
rec->flags = flags;
|
|
|
|
rec->addr = map_to_sysmem(ptr);
|
|
|
|
rec->value = value;
|
|
|
|
|
|
|
|
/* Update our checksum */
|
|
|
|
iotrace.crc32 = crc32(iotrace.crc32, (unsigned char *)rec,
|
|
|
|
sizeof(*rec));
|
|
|
|
|
2018-06-08 17:53:27 +00:00
|
|
|
iotrace.needed_size += sizeof(struct iotrace_record);
|
2014-06-12 05:29:41 +00:00
|
|
|
iotrace.offset += sizeof(struct iotrace_record);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 iotrace_readl(const void *ptr)
|
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
v = readl(ptr);
|
|
|
|
add_record(IOT_32 | IOT_READ, ptr, v);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2019-09-25 14:56:57 +00:00
|
|
|
void iotrace_writel(ulong value, void *ptr)
|
2014-06-12 05:29:41 +00:00
|
|
|
{
|
|
|
|
add_record(IOT_32 | IOT_WRITE, ptr, value);
|
|
|
|
writel(value, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 iotrace_readw(const void *ptr)
|
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
v = readw(ptr);
|
|
|
|
add_record(IOT_16 | IOT_READ, ptr, v);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2019-09-25 14:56:57 +00:00
|
|
|
void iotrace_writew(ulong value, void *ptr)
|
2014-06-12 05:29:41 +00:00
|
|
|
{
|
|
|
|
add_record(IOT_16 | IOT_WRITE, ptr, value);
|
|
|
|
writew(value, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 iotrace_readb(const void *ptr)
|
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
v = readb(ptr);
|
|
|
|
add_record(IOT_8 | IOT_READ, ptr, v);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2019-09-25 14:56:57 +00:00
|
|
|
void iotrace_writeb(ulong value, void *ptr)
|
2014-06-12 05:29:41 +00:00
|
|
|
{
|
|
|
|
add_record(IOT_8 | IOT_WRITE, ptr, value);
|
|
|
|
writeb(value, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void iotrace_reset_checksum(void)
|
|
|
|
{
|
|
|
|
iotrace.crc32 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 iotrace_get_checksum(void)
|
|
|
|
{
|
|
|
|
return iotrace.crc32;
|
|
|
|
}
|
|
|
|
|
2018-05-30 20:09:58 +00:00
|
|
|
void iotrace_set_region(ulong start, ulong size)
|
|
|
|
{
|
|
|
|
iotrace.region_start = start;
|
|
|
|
iotrace.region_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iotrace_reset_region(void)
|
|
|
|
{
|
|
|
|
iotrace.region_start = 0;
|
|
|
|
iotrace.region_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iotrace_get_region(ulong *start, ulong *size)
|
|
|
|
{
|
|
|
|
*start = iotrace.region_start;
|
|
|
|
*size = iotrace.region_size;
|
|
|
|
}
|
|
|
|
|
2014-06-12 05:29:41 +00:00
|
|
|
void iotrace_set_enabled(int enable)
|
|
|
|
{
|
|
|
|
iotrace.enabled = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iotrace_get_enabled(void)
|
|
|
|
{
|
|
|
|
return iotrace.enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iotrace_set_buffer(ulong start, ulong size)
|
|
|
|
{
|
|
|
|
iotrace.start = start;
|
|
|
|
iotrace.size = size;
|
|
|
|
iotrace.offset = 0;
|
|
|
|
iotrace.crc32 = 0;
|
|
|
|
}
|
|
|
|
|
2018-06-08 17:53:27 +00:00
|
|
|
void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count)
|
2014-06-12 05:29:41 +00:00
|
|
|
{
|
|
|
|
*start = iotrace.start;
|
|
|
|
*size = iotrace.size;
|
2018-06-08 17:53:27 +00:00
|
|
|
*needed_size = iotrace.needed_size;
|
2014-06-12 05:29:41 +00:00
|
|
|
*offset = iotrace.offset;
|
|
|
|
*count = iotrace.offset / sizeof(struct iotrace_record);
|
|
|
|
}
|