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 | |
Ramon Fried | d03cc69 | 2018-06-08 20:53:25 +0300 | [diff] [blame] | 9 | //#include <common.h> |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | |
Ramon Fried | d03cc69 | 2018-06-08 20:53:25 +0300 | [diff] [blame] | 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 | |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 52 | #define writel(val, addr) iotrace_writel(val, (void *)(addr)) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 53 | |
| 54 | #undef readw |
| 55 | #define readw(addr) iotrace_readw((const void *)(addr)) |
| 56 | |
| 57 | #undef writew |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 58 | #define writew(val, addr) iotrace_writew(val, (void *)(addr)) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 59 | |
| 60 | #undef readb |
Simon Glass | 66823e1 | 2016-05-01 11:35:53 -0600 | [diff] [blame] | 61 | #define readb(addr) iotrace_readb((const void *)(uintptr_t)addr) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 62 | |
| 63 | #undef writeb |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 64 | #define writeb(val, addr) iotrace_writeb(val, (void *)(uintptr_t)addr) |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 65 | |
| 66 | #endif |
| 67 | |
| 68 | /* Tracing functions which mirror their io.h counterparts */ |
| 69 | u32 iotrace_readl(const void *ptr); |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 70 | void iotrace_writel(ulong value, void *ptr); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 71 | u16 iotrace_readw(const void *ptr); |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 72 | void iotrace_writew(ulong value, void *ptr); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 73 | u8 iotrace_readb(const void *ptr); |
Simon Glass | 815d170 | 2019-09-25 08:56:57 -0600 | [diff] [blame] | 74 | void iotrace_writeb(ulong value, void *ptr); |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * iotrace_reset_checksum() - Reset the iotrace checksum |
| 78 | */ |
| 79 | void iotrace_reset_checksum(void); |
| 80 | |
| 81 | /** |
| 82 | * iotrace_get_checksum() - Get the current checksum value |
| 83 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 84 | * Return: currect checksum value |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 85 | */ |
| 86 | u32 iotrace_get_checksum(void); |
| 87 | |
| 88 | /** |
Ramon Fried | d01a417 | 2018-05-30 23:09:58 +0300 | [diff] [blame] | 89 | * iotrace_set_region() - Set whether iotrace is limited to a specific |
| 90 | * io region. |
| 91 | * |
| 92 | * Defines the address and size of the limited region. |
| 93 | * |
| 94 | * @start: address of the beginning of the region |
| 95 | * @size: size of the region in bytes. |
| 96 | */ |
| 97 | void iotrace_set_region(ulong start, ulong size); |
| 98 | |
| 99 | /** |
| 100 | * iotrace_reset_region() - Reset the region limit |
| 101 | */ |
| 102 | void iotrace_reset_region(void); |
| 103 | |
| 104 | /** |
| 105 | * iotrace_get_region() - Get region information |
| 106 | * |
| 107 | * @start: Returns start address of region |
| 108 | * @size: Returns size of region in bytes |
| 109 | */ |
| 110 | void iotrace_get_region(ulong *start, ulong *size); |
| 111 | |
| 112 | /** |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 113 | * iotrace_set_enabled() - Set whether iotracing is enabled or not |
| 114 | * |
| 115 | * This controls whether the checksum is updated and a trace record added |
| 116 | * for each I/O access. |
| 117 | * |
| 118 | * @enable: true to enable iotracing, false to disable |
| 119 | */ |
| 120 | void iotrace_set_enabled(int enable); |
| 121 | |
| 122 | /** |
| 123 | * iotrace_get_enabled() - Get whether iotracing is enabled or not |
| 124 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 125 | * Return: true if enabled, false if disabled |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 126 | */ |
| 127 | int iotrace_get_enabled(void); |
| 128 | |
| 129 | /** |
| 130 | * iotrace_set_buffer() - Set position and size of iotrace buffer |
| 131 | * |
| 132 | * Defines where the iotrace buffer goes, and resets the output pointer to |
| 133 | * the start of the buffer. |
| 134 | * |
| 135 | * The buffer can be 0 size in which case the checksum is updated but no |
| 136 | * trace records are writen. If the buffer is exhausted, the offset will |
| 137 | * continue to increase but not new data will be written. |
| 138 | * |
| 139 | * @start: Start address of buffer |
| 140 | * @size: Size of buffer in bytes |
| 141 | */ |
| 142 | void iotrace_set_buffer(ulong start, ulong size); |
| 143 | |
| 144 | /** |
| 145 | * iotrace_get_buffer() - Get buffer information |
| 146 | * |
| 147 | * @start: Returns start address of buffer |
Ramon Fried | 75aa898 | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 148 | * @size: Returns actual size of buffer in bytes |
| 149 | * @needed_size: Returns needed size of buffer in bytes |
Simon Glass | 4dc47ca | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 150 | * @offset: Returns the byte offset where the next output trace record will |
| 151 | * @count: Returns the number of trace records recorded |
| 152 | * be written (or would be if the buffer was large enough) |
| 153 | */ |
Ramon Fried | 75aa898 | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 154 | 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] | 155 | |
| 156 | #endif /* __IOTRACE_H */ |