+// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2014 Google, Inc.
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#define IOTRACE_IMPL
-#include <common.h>
+#include <mapmem.h>
+#include <time.h>
+#include <asm/global_data.h>
#include <asm/io.h>
+#include <linux/bug.h>
+#include <u-boot/crc.h>
DECLARE_GLOBAL_DATA_PTR;
-/* Support up to the machine word length for now */
-typedef ulong iovalue_t;
-
-enum iotrace_flags {
- IOT_8 = 0,
- IOT_16,
- IOT_32,
-
- IOT_READ = 0 << 3,
- IOT_WRITE = 1 << 3,
-};
-
-/**
- * struct iotrace_record - Holds a single I/O trace record
- *
- * @flags: I/O access type
- * @addr: Address of access
- * @value: Value written or read
- */
-struct iotrace_record {
- enum iotrace_flags flags;
- phys_addr_t addr;
- iovalue_t value;
-};
-
/**
* struct iotrace - current trace status and checksum
*
* @start: Start address of iotrace buffer
- * @size: Size of iotrace buffer in bytes
+ * @size: Actual size of iotrace buffer in bytes
+ * @needed_size: Needed of iotrace buffer in bytes
* @offset: Current write offset into iotrace buffer
+ * @region_start: Address of IO region to trace
+ * @region_size: Size of region to trace. if 0 will trace all address space
* @crc32: Current value of CRC chceksum of trace records
* @enabled: true if enabled, false if disabled
*/
static struct iotrace {
ulong start;
ulong size;
+ ulong needed_size;
ulong offset;
+ ulong region_start;
+ ulong region_size;
u32 crc32;
bool enabled;
} iotrace;
if (!(gd->flags & GD_FLG_RELOC) || !iotrace.enabled)
return;
+ if (iotrace.region_size)
+ if ((ulong)ptr < iotrace.region_start ||
+ (ulong)ptr > iotrace.region_start + iotrace.region_size)
+ return;
+
/* 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));
+ } else {
+ WARN_ONCE(1, "WARNING: iotrace buffer exhausted, please check needed length using \"iotrace stats\"\n");
+ iotrace.needed_size += sizeof(struct iotrace_record);
+ return;
}
+ rec->timestamp = timer_get_us();
rec->flags = flags;
rec->addr = map_to_sysmem(ptr);
rec->value = value;
iotrace.crc32 = crc32(iotrace.crc32, (unsigned char *)rec,
sizeof(*rec));
+ iotrace.needed_size += sizeof(struct iotrace_record);
iotrace.offset += sizeof(struct iotrace_record);
}
return v;
}
-void iotrace_writel(ulong value, const void *ptr)
+void iotrace_writel(ulong value, void *ptr)
{
add_record(IOT_32 | IOT_WRITE, ptr, value);
writel(value, ptr);
return v;
}
-void iotrace_writew(ulong value, const void *ptr)
+void iotrace_writew(ulong value, void *ptr)
{
add_record(IOT_16 | IOT_WRITE, ptr, value);
writew(value, ptr);
return v;
}
-void iotrace_writeb(ulong value, const void *ptr)
+void iotrace_writeb(ulong value, void *ptr)
{
add_record(IOT_8 | IOT_WRITE, ptr, value);
writeb(value, ptr);
return iotrace.crc32;
}
+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;
+}
+
void iotrace_set_enabled(int enable)
{
iotrace.enabled = enable;
iotrace.crc32 = 0;
}
-void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count)
+void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count)
{
*start = iotrace.start;
*size = iotrace.size;
+ *needed_size = iotrace.needed_size;
*offset = iotrace.offset;
*count = iotrace.offset / sizeof(struct iotrace_record);
}