1aa53233aSSimon Glass /* 2aa53233aSSimon Glass * Copyright (c) 2014 Google, Inc. 3aa53233aSSimon Glass * 4aa53233aSSimon Glass * SPDX-License-Identifier: GPL-2.0+ 5aa53233aSSimon Glass */ 6aa53233aSSimon Glass 7aa53233aSSimon Glass #ifndef __IOTRACE_H 8aa53233aSSimon Glass #define __IOTRACE_H 9aa53233aSSimon Glass 10aa53233aSSimon Glass #include <linux/types.h> 11aa53233aSSimon Glass 12aa53233aSSimon Glass /* 13aa53233aSSimon Glass * This file is designed to be included in arch/<arch>/include/asm/io.h. 14aa53233aSSimon Glass * It redirects all IO access through a tracing/checksumming feature for 15aa53233aSSimon Glass * testing purposes. 16aa53233aSSimon Glass */ 17aa53233aSSimon Glass 18aa53233aSSimon Glass #if defined(CONFIG_IO_TRACE) && !defined(IOTRACE_IMPL) && \ 19aa53233aSSimon Glass !defined(CONFIG_SPL_BUILD) 20aa53233aSSimon Glass 21aa53233aSSimon Glass #undef readl 22aa53233aSSimon Glass #define readl(addr) iotrace_readl((const void *)(addr)) 23aa53233aSSimon Glass 24aa53233aSSimon Glass #undef writel 25aa53233aSSimon Glass #define writel(val, addr) iotrace_writel(val, (const void *)(addr)) 26aa53233aSSimon Glass 27aa53233aSSimon Glass #undef readw 28aa53233aSSimon Glass #define readw(addr) iotrace_readw((const void *)(addr)) 29aa53233aSSimon Glass 30aa53233aSSimon Glass #undef writew 31aa53233aSSimon Glass #define writew(val, addr) iotrace_writew(val, (const void *)(addr)) 32aa53233aSSimon Glass 33aa53233aSSimon Glass #undef readb 34*709e98b7SSimon Glass #define readb(addr) iotrace_readb((const void *)(uintptr_t)addr) 35aa53233aSSimon Glass 36aa53233aSSimon Glass #undef writeb 37*709e98b7SSimon Glass #define writeb(val, addr) \ 38*709e98b7SSimon Glass iotrace_writeb(val, (const void *)(uintptr_t)addr) 39aa53233aSSimon Glass 40aa53233aSSimon Glass #endif 41aa53233aSSimon Glass 42aa53233aSSimon Glass /* Tracing functions which mirror their io.h counterparts */ 43aa53233aSSimon Glass u32 iotrace_readl(const void *ptr); 44aa53233aSSimon Glass void iotrace_writel(ulong value, const void *ptr); 45aa53233aSSimon Glass u16 iotrace_readw(const void *ptr); 46aa53233aSSimon Glass void iotrace_writew(ulong value, const void *ptr); 47aa53233aSSimon Glass u8 iotrace_readb(const void *ptr); 48aa53233aSSimon Glass void iotrace_writeb(ulong value, const void *ptr); 49aa53233aSSimon Glass 50aa53233aSSimon Glass /** 51aa53233aSSimon Glass * iotrace_reset_checksum() - Reset the iotrace checksum 52aa53233aSSimon Glass */ 53aa53233aSSimon Glass void iotrace_reset_checksum(void); 54aa53233aSSimon Glass 55aa53233aSSimon Glass /** 56aa53233aSSimon Glass * iotrace_get_checksum() - Get the current checksum value 57aa53233aSSimon Glass * 58aa53233aSSimon Glass * @return currect checksum value 59aa53233aSSimon Glass */ 60aa53233aSSimon Glass u32 iotrace_get_checksum(void); 61aa53233aSSimon Glass 62aa53233aSSimon Glass /** 63aa53233aSSimon Glass * iotrace_set_enabled() - Set whether iotracing is enabled or not 64aa53233aSSimon Glass * 65aa53233aSSimon Glass * This controls whether the checksum is updated and a trace record added 66aa53233aSSimon Glass * for each I/O access. 67aa53233aSSimon Glass * 68aa53233aSSimon Glass * @enable: true to enable iotracing, false to disable 69aa53233aSSimon Glass */ 70aa53233aSSimon Glass void iotrace_set_enabled(int enable); 71aa53233aSSimon Glass 72aa53233aSSimon Glass /** 73aa53233aSSimon Glass * iotrace_get_enabled() - Get whether iotracing is enabled or not 74aa53233aSSimon Glass * 75aa53233aSSimon Glass * @return true if enabled, false if disabled 76aa53233aSSimon Glass */ 77aa53233aSSimon Glass int iotrace_get_enabled(void); 78aa53233aSSimon Glass 79aa53233aSSimon Glass /** 80aa53233aSSimon Glass * iotrace_set_buffer() - Set position and size of iotrace buffer 81aa53233aSSimon Glass * 82aa53233aSSimon Glass * Defines where the iotrace buffer goes, and resets the output pointer to 83aa53233aSSimon Glass * the start of the buffer. 84aa53233aSSimon Glass * 85aa53233aSSimon Glass * The buffer can be 0 size in which case the checksum is updated but no 86aa53233aSSimon Glass * trace records are writen. If the buffer is exhausted, the offset will 87aa53233aSSimon Glass * continue to increase but not new data will be written. 88aa53233aSSimon Glass * 89aa53233aSSimon Glass * @start: Start address of buffer 90aa53233aSSimon Glass * @size: Size of buffer in bytes 91aa53233aSSimon Glass */ 92aa53233aSSimon Glass void iotrace_set_buffer(ulong start, ulong size); 93aa53233aSSimon Glass 94aa53233aSSimon Glass /** 95aa53233aSSimon Glass * iotrace_get_buffer() - Get buffer information 96aa53233aSSimon Glass * 97aa53233aSSimon Glass * @start: Returns start address of buffer 98aa53233aSSimon Glass * @size: Returns size of buffer in bytes 99aa53233aSSimon Glass * @offset: Returns the byte offset where the next output trace record will 100aa53233aSSimon Glass * @count: Returns the number of trace records recorded 101aa53233aSSimon Glass * be written (or would be if the buffer was large enough) 102aa53233aSSimon Glass */ 103aa53233aSSimon Glass void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count); 104aa53233aSSimon Glass 105aa53233aSSimon Glass #endif /* __IOTRACE_H */ 106