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