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