blob: d5610426cc84ea1cbac0b4e473c345aa6d3f1d35 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassaa532332014-06-11 23:29:41 -06002/*
3 * Copyright (c) 2014 Google, Inc.
Simon Glassaa532332014-06-11 23:29:41 -06004 */
5
6#ifndef __IOTRACE_H
7#define __IOTRACE_H
8
9#include <linux/types.h>
10
Ramon Fried7e9be3e2018-06-08 20:53:25 +030011/* Support up to the machine word length for now */
12typedef ulong iovalue_t;
13
14enum 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 */
31struct iotrace_record {
32 enum iotrace_flags flags;
33 u64 timestamp;
34 phys_addr_t addr;
35 iovalue_t value;
36};
37
Simon Glassaa532332014-06-11 23:29:41 -060038/*
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
Simon Glass9859dc72019-09-25 08:56:57 -060051#define writel(val, addr) iotrace_writel(val, (void *)(addr))
Simon Glassaa532332014-06-11 23:29:41 -060052
53#undef readw
54#define readw(addr) iotrace_readw((const void *)(addr))
55
56#undef writew
Simon Glass9859dc72019-09-25 08:56:57 -060057#define writew(val, addr) iotrace_writew(val, (void *)(addr))
Simon Glassaa532332014-06-11 23:29:41 -060058
59#undef readb
Simon Glass709e98b2016-05-01 11:35:53 -060060#define readb(addr) iotrace_readb((const void *)(uintptr_t)addr)
Simon Glassaa532332014-06-11 23:29:41 -060061
62#undef writeb
Simon Glass9859dc72019-09-25 08:56:57 -060063#define writeb(val, addr) iotrace_writeb(val, (void *)(uintptr_t)addr)
Simon Glassaa532332014-06-11 23:29:41 -060064
65#endif
66
67/* Tracing functions which mirror their io.h counterparts */
68u32 iotrace_readl(const void *ptr);
Simon Glass9859dc72019-09-25 08:56:57 -060069void iotrace_writel(ulong value, void *ptr);
Simon Glassaa532332014-06-11 23:29:41 -060070u16 iotrace_readw(const void *ptr);
Simon Glass9859dc72019-09-25 08:56:57 -060071void iotrace_writew(ulong value, void *ptr);
Simon Glassaa532332014-06-11 23:29:41 -060072u8 iotrace_readb(const void *ptr);
Simon Glass9859dc72019-09-25 08:56:57 -060073void iotrace_writeb(ulong value, void *ptr);
Simon Glassaa532332014-06-11 23:29:41 -060074
75/**
76 * iotrace_reset_checksum() - Reset the iotrace checksum
77 */
78void iotrace_reset_checksum(void);
79
80/**
81 * iotrace_get_checksum() - Get the current checksum value
82 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010083 * Return: currect checksum value
Simon Glassaa532332014-06-11 23:29:41 -060084 */
85u32 iotrace_get_checksum(void);
86
87/**
Ramon Frieda74440b2018-05-30 23:09:58 +030088 * 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 */
96void iotrace_set_region(ulong start, ulong size);
97
98/**
99 * iotrace_reset_region() - Reset the region limit
100 */
101void 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 */
109void iotrace_get_region(ulong *start, ulong *size);
110
111/**
Simon Glassaa532332014-06-11 23:29:41 -0600112 * 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 */
119void iotrace_set_enabled(int enable);
120
121/**
122 * iotrace_get_enabled() - Get whether iotracing is enabled or not
123 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100124 * Return: true if enabled, false if disabled
Simon Glassaa532332014-06-11 23:29:41 -0600125 */
126int 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 */
141void iotrace_set_buffer(ulong start, ulong size);
142
143/**
144 * iotrace_get_buffer() - Get buffer information
145 *
146 * @start: Returns start address of buffer
Ramon Friede0212df2018-06-08 20:53:27 +0300147 * @size: Returns actual size of buffer in bytes
148 * @needed_size: Returns needed size of buffer in bytes
Simon Glassaa532332014-06-11 23:29:41 -0600149 * @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 */
Ramon Friede0212df2018-06-08 20:53:27 +0300153void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count);
Simon Glassaa532332014-06-11 23:29:41 -0600154
155#endif /* __IOTRACE_H */