1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2018-2022 ARM Limited. All rights reserved. 5 * 6 * This program is free software and is provided to you under the terms of the 7 * GNU General Public License version 2 as published by the Free Software 8 * Foundation, and any use by you of this program is subject to the terms 9 * of such GNU license. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, you can access it online at 18 * http://www.gnu.org/licenses/gpl-2.0.html. 19 * 20 */ 21 22 #ifndef _KBASE_CSF_TRACE_BUFFER_H_ 23 #define _KBASE_CSF_TRACE_BUFFER_H_ 24 25 #include <linux/types.h> 26 27 #define CSF_FIRMWARE_TRACE_ENABLE_INIT_MASK_MAX (4) 28 #define FIRMWARE_LOG_BUF_NAME "fwlog" 29 30 /* Forward declarations */ 31 struct firmware_trace_buffer; 32 struct kbase_device; 33 34 /** 35 * kbase_csf_firmware_trace_buffers_init - Initialize trace buffers 36 * 37 * @kbdev: Device pointer 38 * 39 * Allocate resources for trace buffers. In particular: 40 * - One memory page of GPU-readable, CPU-writable memory is used for 41 * the Extract variables of all trace buffers. 42 * - One memory page of GPU-writable, CPU-readable memory is used for 43 * the Insert variables of all trace buffers. 44 * - A data buffer of GPU-writable, CPU-readable memory is allocated 45 * for each trace buffer. 46 * 47 * After that, firmware addresses are written with pointers to the 48 * insert, extract and data buffer variables. The size and the trace 49 * enable bits are not dereferenced by the GPU and shall be written 50 * in the firmware addresses directly. 51 * 52 * This function relies on the assumption that the list of 53 * firmware_trace_buffer elements in the device has already been 54 * populated with data from the firmware image parsing. 55 * 56 * Return: 0 if success, or an error code on failure. 57 */ 58 int kbase_csf_firmware_trace_buffers_init(struct kbase_device *kbdev); 59 60 /** 61 * kbase_csf_firmware_trace_buffers_term - Terminate trace buffers 62 * 63 * @kbdev: Device pointer 64 */ 65 void kbase_csf_firmware_trace_buffers_term(struct kbase_device *kbdev); 66 67 /** 68 * kbase_csf_firmware_parse_trace_buffer_entry - Process a "trace buffer" section 69 * 70 * @kbdev: Kbase device structure 71 * @entry: Pointer to the section 72 * @size: Size (in bytes) of the section 73 * @updatable: Indicates whether config items can be updated with FIRMWARE_CONFIG_UPDATE 74 * 75 * Read a "trace buffer" section adding metadata for the related trace buffer 76 * to the kbase_device:csf.firmware_trace_buffers list. 77 * 78 * Unexpected trace buffers will not be parsed and, as a consequence, 79 * will not be initialized. 80 * 81 * Return: 0 if successful, negative error code on failure. 82 */ 83 int kbase_csf_firmware_parse_trace_buffer_entry(struct kbase_device *kbdev, 84 const u32 *entry, 85 unsigned int size, 86 bool updatable); 87 88 /** 89 * kbase_csf_firmware_reload_trace_buffers_data - Reload trace buffers data for firmware reboot 90 * 91 * @kbdev: Device pointer 92 * 93 * Helper function used when rebooting the firmware to reload the initial setup 94 * for all the trace buffers which have been previously parsed and initialized. 95 * 96 * Almost all of the operations done in the initialization process are 97 * replicated, with the difference that they might be done in a different order 98 * and that the variables of a given trace buffer may be mapped to different 99 * offsets within the same existing mappings. 100 * 101 * In other words, the re-initialization done by this function will be 102 * equivalent but not necessarily identical to the original initialization. 103 */ 104 void kbase_csf_firmware_reload_trace_buffers_data(struct kbase_device *kbdev); 105 106 /** 107 * kbase_csf_firmware_get_trace_buffer - Get a trace buffer 108 * 109 * @kbdev: Device pointer 110 * @name: Name of the trace buffer to find 111 * 112 * Return: handle to a trace buffer, given the name, or NULL if a trace buffer 113 * with that name couldn't be found. 114 */ 115 struct firmware_trace_buffer *kbase_csf_firmware_get_trace_buffer( 116 struct kbase_device *kbdev, const char *name); 117 118 /** 119 * kbase_csf_firmware_trace_buffer_get_trace_enable_bits_count - Get number of trace enable bits for a trace buffer 120 * 121 * @trace_buffer: Trace buffer handle 122 * 123 * Return: Number of trace enable bits in a trace buffer. 124 */ 125 unsigned int kbase_csf_firmware_trace_buffer_get_trace_enable_bits_count( 126 const struct firmware_trace_buffer *trace_buffer); 127 128 /** 129 * kbase_csf_firmware_trace_buffer_update_trace_enable_bit - Update a trace enable bit 130 * 131 * @trace_buffer: Trace buffer handle 132 * @bit: Bit to update 133 * @value: New value for the given bit 134 * 135 * Update the value of a given trace enable bit. 136 * 137 * Return: 0 if successful, negative error code on failure. 138 */ 139 int kbase_csf_firmware_trace_buffer_update_trace_enable_bit( 140 struct firmware_trace_buffer *trace_buffer, unsigned int bit, 141 bool value); 142 143 /** 144 * kbase_csf_firmware_trace_buffer_is_empty - Empty trace buffer predicate 145 * 146 * @trace_buffer: Trace buffer handle 147 * 148 * Return: True if the trace buffer is empty, or false otherwise. 149 */ 150 bool kbase_csf_firmware_trace_buffer_is_empty( 151 const struct firmware_trace_buffer *trace_buffer); 152 153 /** 154 * kbase_csf_firmware_trace_buffer_read_data - Read data from a trace buffer 155 * 156 * @trace_buffer: Trace buffer handle 157 * @data: Pointer to a client-allocated where data shall be written. 158 * @num_bytes: Maximum number of bytes to read from the trace buffer. 159 * 160 * Read available data from a trace buffer. The client provides a data buffer 161 * of a given size and the maximum number of bytes to read. 162 * 163 * Return: Number of bytes read from the trace buffer. 164 */ 165 unsigned int kbase_csf_firmware_trace_buffer_read_data( 166 struct firmware_trace_buffer *trace_buffer, u8 *data, unsigned int num_bytes); 167 168 /** 169 * kbase_csf_firmware_trace_buffer_get_active_mask64 - Get trace buffer active mask 170 * 171 * @tb: Trace buffer handle 172 * 173 * Return: Trace buffer active mask. 174 */ 175 u64 kbase_csf_firmware_trace_buffer_get_active_mask64(struct firmware_trace_buffer *tb); 176 177 /** 178 * kbase_csf_firmware_trace_buffer_set_active_mask64 - Set trace buffer active mask 179 * 180 * @tb: Trace buffer handle 181 * @mask: New active mask 182 * 183 * Return: 0 if successful, negative error code on failure. 184 */ 185 int kbase_csf_firmware_trace_buffer_set_active_mask64(struct firmware_trace_buffer *tb, u64 mask); 186 187 #endif /* _KBASE_CSF_TRACE_BUFFER_H_ */ 188