1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * Copyright (c) 2014 Google, Inc. 4 */ 5 6#ifndef __IOTRACE_H 7#define __IOTRACE_H 8 9#include <linux/types.h> 10 11/* 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 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 51#define writel(val, addr) iotrace_writel(val, (void *)(addr)) 52 53#undef readw 54#define readw(addr) iotrace_readw((const void *)(addr)) 55 56#undef writew 57#define writew(val, addr) iotrace_writew(val, (void *)(addr)) 58 59#undef readb 60#define readb(addr) iotrace_readb((const void *)(uintptr_t)addr) 61 62#undef writeb 63#define writeb(val, addr) iotrace_writeb(val, (void *)(uintptr_t)addr) 64 65#endif 66 67/* Tracing functions which mirror their io.h counterparts */ 68u32 iotrace_readl(const void *ptr); 69void iotrace_writel(ulong value, void *ptr); 70u16 iotrace_readw(const void *ptr); 71void iotrace_writew(ulong value, void *ptr); 72u8 iotrace_readb(const void *ptr); 73void iotrace_writeb(ulong value, void *ptr); 74 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 * 83 * Return: currect checksum value 84 */ 85u32 iotrace_get_checksum(void); 86 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 */ 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/** 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 */ 119void iotrace_set_enabled(int enable); 120 121/** 122 * iotrace_get_enabled() - Get whether iotracing is enabled or not 123 * 124 * Return: true if enabled, false if disabled 125 */ 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 147 * @size: Returns actual size of buffer in bytes 148 * @needed_size: Returns needed size of buffer in bytes 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 */ 153void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count); 154 155#endif /* __IOTRACE_H */ 156