blob: 1efb117343ab0481c7040c9d35c2a046db154325 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass4dc47ca2014-06-11 23:29:41 -06002/*
3 * Copyright (c) 2014 Google, Inc.
Simon Glass4dc47ca2014-06-11 23:29:41 -06004 */
5
6#ifndef __IOTRACE_H
7#define __IOTRACE_H
8
9#include <linux/types.h>
10
11/*
12 * This file is designed to be included in arch/<arch>/include/asm/io.h.
13 * It redirects all IO access through a tracing/checksumming feature for
14 * testing purposes.
15 */
16
17#if defined(CONFIG_IO_TRACE) && !defined(IOTRACE_IMPL) && \
18 !defined(CONFIG_SPL_BUILD)
19
20#undef readl
21#define readl(addr) iotrace_readl((const void *)(addr))
22
23#undef writel
24#define writel(val, addr) iotrace_writel(val, (const void *)(addr))
25
26#undef readw
27#define readw(addr) iotrace_readw((const void *)(addr))
28
29#undef writew
30#define writew(val, addr) iotrace_writew(val, (const void *)(addr))
31
32#undef readb
Simon Glass66823e12016-05-01 11:35:53 -060033#define readb(addr) iotrace_readb((const void *)(uintptr_t)addr)
Simon Glass4dc47ca2014-06-11 23:29:41 -060034
35#undef writeb
Simon Glass66823e12016-05-01 11:35:53 -060036#define writeb(val, addr) \
37 iotrace_writeb(val, (const void *)(uintptr_t)addr)
Simon Glass4dc47ca2014-06-11 23:29:41 -060038
39#endif
40
41/* Tracing functions which mirror their io.h counterparts */
42u32 iotrace_readl(const void *ptr);
43void iotrace_writel(ulong value, const void *ptr);
44u16 iotrace_readw(const void *ptr);
45void iotrace_writew(ulong value, const void *ptr);
46u8 iotrace_readb(const void *ptr);
47void iotrace_writeb(ulong value, const void *ptr);
48
49/**
50 * iotrace_reset_checksum() - Reset the iotrace checksum
51 */
52void iotrace_reset_checksum(void);
53
54/**
55 * iotrace_get_checksum() - Get the current checksum value
56 *
57 * @return currect checksum value
58 */
59u32 iotrace_get_checksum(void);
60
61/**
Ramon Friedd01a4172018-05-30 23:09:58 +030062 * iotrace_set_region() - Set whether iotrace is limited to a specific
63 * io region.
64 *
65 * Defines the address and size of the limited region.
66 *
67 * @start: address of the beginning of the region
68 * @size: size of the region in bytes.
69 */
70void iotrace_set_region(ulong start, ulong size);
71
72/**
73 * iotrace_reset_region() - Reset the region limit
74 */
75void iotrace_reset_region(void);
76
77/**
78 * iotrace_get_region() - Get region information
79 *
80 * @start: Returns start address of region
81 * @size: Returns size of region in bytes
82 */
83void iotrace_get_region(ulong *start, ulong *size);
84
85/**
Simon Glass4dc47ca2014-06-11 23:29:41 -060086 * iotrace_set_enabled() - Set whether iotracing is enabled or not
87 *
88 * This controls whether the checksum is updated and a trace record added
89 * for each I/O access.
90 *
91 * @enable: true to enable iotracing, false to disable
92 */
93void iotrace_set_enabled(int enable);
94
95/**
96 * iotrace_get_enabled() - Get whether iotracing is enabled or not
97 *
98 * @return true if enabled, false if disabled
99 */
100int iotrace_get_enabled(void);
101
102/**
103 * iotrace_set_buffer() - Set position and size of iotrace buffer
104 *
105 * Defines where the iotrace buffer goes, and resets the output pointer to
106 * the start of the buffer.
107 *
108 * The buffer can be 0 size in which case the checksum is updated but no
109 * trace records are writen. If the buffer is exhausted, the offset will
110 * continue to increase but not new data will be written.
111 *
112 * @start: Start address of buffer
113 * @size: Size of buffer in bytes
114 */
115void iotrace_set_buffer(ulong start, ulong size);
116
117/**
118 * iotrace_get_buffer() - Get buffer information
119 *
120 * @start: Returns start address of buffer
121 * @size: Returns size of buffer in bytes
122 * @offset: Returns the byte offset where the next output trace record will
123 * @count: Returns the number of trace records recorded
124 * be written (or would be if the buffer was large enough)
125 */
126void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count);
127
128#endif /* __IOTRACE_H */