Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc. |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __IOTRACE_H |
| 7 | #define __IOTRACE_H |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | |
Ramon Fried | d03cc69 | 2018-06-08 20:53:25 +0300 | [diff] [blame] | 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 | |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 51 | #define writel(val, addr) iotrace_writel(val, (void *)(addr)) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 52 | |
| 53 | #undef readw |
| 54 | #define readw(addr) iotrace_readw((const void *)(addr)) |
| 55 | |
| 56 | #undef writew |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 57 | #define writew(val, addr) iotrace_writew(val, (void *)(addr)) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 58 | |
| 59 | #undef readb |
Simon Glass | 66823e1 | 2016-05-01 11:35:53 -0600 | [diff] [blame] | 60 | #define readb(addr) iotrace_readb((const void *)(uintptr_t)addr) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 61 | |
| 62 | #undef writeb |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 63 | #define writeb(val, addr) iotrace_writeb(val, (void *)(uintptr_t)addr) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 64 | |
| 65 | #endif |
| 66 | |
| 67 | /* Tracing functions which mirror their io.h counterparts */ |
| 68 | u32 iotrace_readl(const void *ptr); |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 69 | void iotrace_writel(ulong value, void *ptr); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 70 | u16 iotrace_readw(const void *ptr); |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 71 | void iotrace_writew(ulong value, void *ptr); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 72 | u8 iotrace_readb(const void *ptr); |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 73 | void iotrace_writeb(ulong value, void *ptr); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 83 | * Return: currect checksum value |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 84 | */ |
| 85 | u32 iotrace_get_checksum(void); |
| 86 | |
| 87 | /** |
Ramon Fried | d01a417 | 2018-05-30 23:09:58 +0300 | [diff] [blame] | 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 | |
| 111 | /** |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 124 | * Return: true if enabled, false if disabled |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 |
Ramon Fried | 75aa898 | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 147 | * @size: Returns actual size of buffer in bytes |
| 148 | * @needed_size: Returns needed size of buffer in bytes |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 | */ |
Ramon Fried | 75aa898 | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 153 | void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 154 | |
| 155 | #endif /* __IOTRACE_H */ |