]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
aa53233a SG |
2 | /* |
3 | * Copyright (c) 2014 Google, Inc. | |
aa53233a SG |
4 | */ |
5 | ||
6 | #ifndef __IOTRACE_H | |
7 | #define __IOTRACE_H | |
8 | ||
7e9be3ea | 9 | //#include <common.h> |
aa53233a SG |
10 | #include <linux/types.h> |
11 | ||
7e9be3ea RF |
12 | /* Support up to the machine word length for now */ |
13 | typedef ulong iovalue_t; | |
14 | ||
15 | enum iotrace_flags { | |
16 | IOT_8 = 0, | |
17 | IOT_16, | |
18 | IOT_32, | |
19 | ||
20 | IOT_READ = 0 << 3, | |
21 | IOT_WRITE = 1 << 3, | |
22 | }; | |
23 | ||
24 | /** | |
25 | * struct iotrace_record - Holds a single I/O trace record | |
26 | * | |
27 | * @flags: I/O access type | |
28 | * @timestamp: Timestamp of access | |
29 | * @addr: Address of access | |
30 | * @value: Value written or read | |
31 | */ | |
32 | struct iotrace_record { | |
33 | enum iotrace_flags flags; | |
34 | u64 timestamp; | |
35 | phys_addr_t addr; | |
36 | iovalue_t value; | |
37 | }; | |
38 | ||
aa53233a SG |
39 | /* |
40 | * This file is designed to be included in arch/<arch>/include/asm/io.h. | |
41 | * It redirects all IO access through a tracing/checksumming feature for | |
42 | * testing purposes. | |
43 | */ | |
44 | ||
45 | #if defined(CONFIG_IO_TRACE) && !defined(IOTRACE_IMPL) && \ | |
46 | !defined(CONFIG_SPL_BUILD) | |
47 | ||
48 | #undef readl | |
49 | #define readl(addr) iotrace_readl((const void *)(addr)) | |
50 | ||
51 | #undef writel | |
52 | #define writel(val, addr) iotrace_writel(val, (const void *)(addr)) | |
53 | ||
54 | #undef readw | |
55 | #define readw(addr) iotrace_readw((const void *)(addr)) | |
56 | ||
57 | #undef writew | |
58 | #define writew(val, addr) iotrace_writew(val, (const void *)(addr)) | |
59 | ||
60 | #undef readb | |
709e98b7 | 61 | #define readb(addr) iotrace_readb((const void *)(uintptr_t)addr) |
aa53233a SG |
62 | |
63 | #undef writeb | |
709e98b7 SG |
64 | #define writeb(val, addr) \ |
65 | iotrace_writeb(val, (const void *)(uintptr_t)addr) | |
aa53233a SG |
66 | |
67 | #endif | |
68 | ||
69 | /* Tracing functions which mirror their io.h counterparts */ | |
70 | u32 iotrace_readl(const void *ptr); | |
71 | void iotrace_writel(ulong value, const void *ptr); | |
72 | u16 iotrace_readw(const void *ptr); | |
73 | void iotrace_writew(ulong value, const void *ptr); | |
74 | u8 iotrace_readb(const void *ptr); | |
75 | void iotrace_writeb(ulong value, const void *ptr); | |
76 | ||
77 | /** | |
78 | * iotrace_reset_checksum() - Reset the iotrace checksum | |
79 | */ | |
80 | void iotrace_reset_checksum(void); | |
81 | ||
82 | /** | |
83 | * iotrace_get_checksum() - Get the current checksum value | |
84 | * | |
85 | * @return currect checksum value | |
86 | */ | |
87 | u32 iotrace_get_checksum(void); | |
88 | ||
a74440b2 RF |
89 | /** |
90 | * iotrace_set_region() - Set whether iotrace is limited to a specific | |
91 | * io region. | |
92 | * | |
93 | * Defines the address and size of the limited region. | |
94 | * | |
95 | * @start: address of the beginning of the region | |
96 | * @size: size of the region in bytes. | |
97 | */ | |
98 | void iotrace_set_region(ulong start, ulong size); | |
99 | ||
100 | /** | |
101 | * iotrace_reset_region() - Reset the region limit | |
102 | */ | |
103 | void iotrace_reset_region(void); | |
104 | ||
105 | /** | |
106 | * iotrace_get_region() - Get region information | |
107 | * | |
108 | * @start: Returns start address of region | |
109 | * @size: Returns size of region in bytes | |
110 | */ | |
111 | void iotrace_get_region(ulong *start, ulong *size); | |
112 | ||
aa53233a SG |
113 | /** |
114 | * iotrace_set_enabled() - Set whether iotracing is enabled or not | |
115 | * | |
116 | * This controls whether the checksum is updated and a trace record added | |
117 | * for each I/O access. | |
118 | * | |
119 | * @enable: true to enable iotracing, false to disable | |
120 | */ | |
121 | void iotrace_set_enabled(int enable); | |
122 | ||
123 | /** | |
124 | * iotrace_get_enabled() - Get whether iotracing is enabled or not | |
125 | * | |
126 | * @return true if enabled, false if disabled | |
127 | */ | |
128 | int iotrace_get_enabled(void); | |
129 | ||
130 | /** | |
131 | * iotrace_set_buffer() - Set position and size of iotrace buffer | |
132 | * | |
133 | * Defines where the iotrace buffer goes, and resets the output pointer to | |
134 | * the start of the buffer. | |
135 | * | |
136 | * The buffer can be 0 size in which case the checksum is updated but no | |
137 | * trace records are writen. If the buffer is exhausted, the offset will | |
138 | * continue to increase but not new data will be written. | |
139 | * | |
140 | * @start: Start address of buffer | |
141 | * @size: Size of buffer in bytes | |
142 | */ | |
143 | void iotrace_set_buffer(ulong start, ulong size); | |
144 | ||
145 | /** | |
146 | * iotrace_get_buffer() - Get buffer information | |
147 | * | |
148 | * @start: Returns start address of buffer | |
e0212dfa RF |
149 | * @size: Returns actual size of buffer in bytes |
150 | * @needed_size: Returns needed size of buffer in bytes | |
aa53233a SG |
151 | * @offset: Returns the byte offset where the next output trace record will |
152 | * @count: Returns the number of trace records recorded | |
153 | * be written (or would be if the buffer was large enough) | |
154 | */ | |
e0212dfa | 155 | void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count); |
aa53233a SG |
156 | |
157 | #endif /* __IOTRACE_H */ |