]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - common/iotrace.c
2 * Copyright (c) 2014 Google, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
12 DECLARE_GLOBAL_DATA_PTR
;
14 /* Support up to the machine word length for now */
15 typedef ulong iovalue_t
;
27 * struct iotrace_record - Holds a single I/O trace record
29 * @flags: I/O access type
30 * @addr: Address of access
31 * @value: Value written or read
33 struct iotrace_record
{
34 enum iotrace_flags flags
;
40 * struct iotrace - current trace status and checksum
42 * @start: Start address of iotrace buffer
43 * @size: Size of iotrace buffer in bytes
44 * @offset: Current write offset into iotrace buffer
45 * @crc32: Current value of CRC chceksum of trace records
46 * @enabled: true if enabled, false if disabled
48 static struct iotrace
{
56 static void add_record(int flags
, const void *ptr
, ulong value
)
58 struct iotrace_record srec
, *rec
= &srec
;
61 * We don't support iotrace before relocation. Since the trace buffer
62 * is set up by a command, it can't be enabled at present. To change
63 * this we would need to set the iotrace buffer at build-time. See
64 * lib/trace.c for how this might be done if you are interested.
66 if (!(gd
->flags
& GD_FLG_RELOC
) || !iotrace
.enabled
)
69 /* Store it if there is room */
70 if (iotrace
.offset
+ sizeof(*rec
) < iotrace
.size
) {
71 rec
= (struct iotrace_record
*)map_sysmem(
72 iotrace
.start
+ iotrace
.offset
,
77 rec
->addr
= map_to_sysmem(ptr
);
80 /* Update our checksum */
81 iotrace
.crc32
= crc32(iotrace
.crc32
, (unsigned char *)rec
,
84 iotrace
.offset
+= sizeof(struct iotrace_record
);
87 u32
iotrace_readl(const void *ptr
)
92 add_record(IOT_32
| IOT_READ
, ptr
, v
);
97 void iotrace_writel(ulong value
, const void *ptr
)
99 add_record(IOT_32
| IOT_WRITE
, ptr
, value
);
103 u16
iotrace_readw(const void *ptr
)
108 add_record(IOT_16
| IOT_READ
, ptr
, v
);
113 void iotrace_writew(ulong value
, const void *ptr
)
115 add_record(IOT_16
| IOT_WRITE
, ptr
, value
);
119 u8
iotrace_readb(const void *ptr
)
124 add_record(IOT_8
| IOT_READ
, ptr
, v
);
129 void iotrace_writeb(ulong value
, const void *ptr
)
131 add_record(IOT_8
| IOT_WRITE
, ptr
, value
);
135 void iotrace_reset_checksum(void)
140 u32
iotrace_get_checksum(void)
142 return iotrace
.crc32
;
145 void iotrace_set_enabled(int enable
)
147 iotrace
.enabled
= enable
;
150 int iotrace_get_enabled(void)
152 return iotrace
.enabled
;
155 void iotrace_set_buffer(ulong start
, ulong size
)
157 iotrace
.start
= start
;
163 void iotrace_get_buffer(ulong
*start
, ulong
*size
, ulong
*offset
, ulong
*count
)
165 *start
= iotrace
.start
;
166 *size
= iotrace
.size
;
167 *offset
= iotrace
.offset
;
168 *count
= iotrace
.offset
/ sizeof(struct iotrace_record
);