2 * Copyright (c) 2014 Google, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
13 DECLARE_GLOBAL_DATA_PTR;
15 /* Support up to the machine word length for now */
16 typedef ulong iovalue_t;
28 * struct iotrace_record - Holds a single I/O trace record
30 * @flags: I/O access type
31 * @addr: Address of access
32 * @value: Value written or read
34 struct iotrace_record {
35 enum iotrace_flags flags;
41 * struct iotrace - current trace status and checksum
43 * @start: Start address of iotrace buffer
44 * @size: Size of iotrace buffer in bytes
45 * @offset: Current write offset into iotrace buffer
46 * @crc32: Current value of CRC chceksum of trace records
47 * @enabled: true if enabled, false if disabled
49 static struct iotrace {
57 static void add_record(int flags, const void *ptr, ulong value)
59 struct iotrace_record srec, *rec = &srec;
62 * We don't support iotrace before relocation. Since the trace buffer
63 * is set up by a command, it can't be enabled at present. To change
64 * this we would need to set the iotrace buffer at build-time. See
65 * lib/trace.c for how this might be done if you are interested.
67 if (!(gd->flags & GD_FLG_RELOC) || !iotrace.enabled)
70 /* Store it if there is room */
71 if (iotrace.offset + sizeof(*rec) < iotrace.size) {
72 rec = (struct iotrace_record *)map_sysmem(
73 iotrace.start + iotrace.offset,
78 rec->addr = map_to_sysmem(ptr);
81 /* Update our checksum */
82 iotrace.crc32 = crc32(iotrace.crc32, (unsigned char *)rec,
85 iotrace.offset += sizeof(struct iotrace_record);
88 u32 iotrace_readl(const void *ptr)
93 add_record(IOT_32 | IOT_READ, ptr, v);
98 void iotrace_writel(ulong value, const void *ptr)
100 add_record(IOT_32 | IOT_WRITE, ptr, value);
104 u16 iotrace_readw(const void *ptr)
109 add_record(IOT_16 | IOT_READ, ptr, v);
114 void iotrace_writew(ulong value, const void *ptr)
116 add_record(IOT_16 | IOT_WRITE, ptr, value);
120 u8 iotrace_readb(const void *ptr)
125 add_record(IOT_8 | IOT_READ, ptr, v);
130 void iotrace_writeb(ulong value, const void *ptr)
132 add_record(IOT_8 | IOT_WRITE, ptr, value);
136 void iotrace_reset_checksum(void)
141 u32 iotrace_get_checksum(void)
143 return iotrace.crc32;
146 void iotrace_set_enabled(int enable)
148 iotrace.enabled = enable;
151 int iotrace_get_enabled(void)
153 return iotrace.enabled;
156 void iotrace_set_buffer(ulong start, ulong size)
158 iotrace.start = start;
164 void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count)
166 *start = iotrace.start;
167 *size = iotrace.size;
168 *offset = iotrace.offset;
169 *count = iotrace.offset / sizeof(struct iotrace_record);