Hareesh Gundu | 9c6b1fa | 2017-01-06 15:37:09 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef _KGSL_SNAPSHOT_H_ |
| 15 | #define _KGSL_SNAPSHOT_H_ |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | |
| 19 | /* Snapshot header */ |
| 20 | |
| 21 | /* High word is static, low word is snapshot version ID */ |
| 22 | #define SNAPSHOT_MAGIC 0x504D0002 |
| 23 | |
| 24 | /* GPU ID scheme: |
| 25 | * [16:31] - core identifer (0x0002 for 2D or 0x0003 for 3D) |
| 26 | * [00:16] - GPU specific identifier |
| 27 | */ |
| 28 | |
| 29 | struct kgsl_snapshot_header { |
| 30 | __u32 magic; /* Magic identifier */ |
| 31 | __u32 gpuid; /* GPU ID - see above */ |
| 32 | /* Added in snapshot version 2 */ |
| 33 | __u32 chipid; /* Chip ID from the GPU */ |
| 34 | } __packed; |
| 35 | |
| 36 | /* Section header */ |
| 37 | #define SNAPSHOT_SECTION_MAGIC 0xABCD |
| 38 | |
| 39 | struct kgsl_snapshot_section_header { |
| 40 | __u16 magic; /* Magic identifier */ |
| 41 | __u16 id; /* Type of section */ |
| 42 | __u32 size; /* Size of the section including this header */ |
| 43 | } __packed; |
| 44 | |
| 45 | /* Section identifiers */ |
| 46 | #define KGSL_SNAPSHOT_SECTION_OS 0x0101 |
| 47 | #define KGSL_SNAPSHOT_SECTION_REGS 0x0201 |
| 48 | #define KGSL_SNAPSHOT_SECTION_RB 0x0301 |
| 49 | #define KGSL_SNAPSHOT_SECTION_RB_V2 0x0302 |
| 50 | #define KGSL_SNAPSHOT_SECTION_IB 0x0401 |
| 51 | #define KGSL_SNAPSHOT_SECTION_IB_V2 0x0402 |
| 52 | #define KGSL_SNAPSHOT_SECTION_INDEXED_REGS 0x0501 |
| 53 | #define KGSL_SNAPSHOT_SECTION_ISTORE 0x0801 |
| 54 | #define KGSL_SNAPSHOT_SECTION_DEBUG 0x0901 |
| 55 | #define KGSL_SNAPSHOT_SECTION_DEBUGBUS 0x0A01 |
| 56 | #define KGSL_SNAPSHOT_SECTION_GPU_OBJECT 0x0B01 |
| 57 | #define KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2 0x0B02 |
| 58 | #define KGSL_SNAPSHOT_SECTION_MEMLIST 0x0E01 |
| 59 | #define KGSL_SNAPSHOT_SECTION_MEMLIST_V2 0x0E02 |
| 60 | #define KGSL_SNAPSHOT_SECTION_SHADER 0x1201 |
Shrenuj Bansal | 4166540 | 2016-12-16 15:25:54 -0800 | [diff] [blame^] | 61 | #define KGSL_SNAPSHOT_SECTION_MVC 0x1501 |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 62 | |
| 63 | #define KGSL_SNAPSHOT_SECTION_END 0xFFFF |
| 64 | |
| 65 | /* OS sub-section header */ |
| 66 | #define KGSL_SNAPSHOT_OS_LINUX 0x0001 |
| 67 | #define KGSL_SNAPSHOT_OS_LINUX_V3 0x00000202 |
| 68 | |
| 69 | /* Linux OS specific information */ |
| 70 | struct kgsl_snapshot_linux { |
| 71 | int osid; /* subsection OS identifier */ |
| 72 | int state; /* 1 if the thread is running, 0 for hung */ |
| 73 | __u32 seconds; /* Unix timestamp for the snapshot */ |
| 74 | __u32 power_flags; /* Current power flags */ |
| 75 | __u32 power_level; /* Current power level */ |
| 76 | __u32 power_interval_timeout; /* Power interval timeout */ |
| 77 | __u32 grpclk; /* Current GP clock value */ |
| 78 | __u32 busclk; /* Current busclk value */ |
| 79 | __u32 ptbase; /* Current ptbase */ |
| 80 | __u32 pid; /* PID of the process that owns the PT */ |
| 81 | __u32 current_context; /* ID of the current context */ |
| 82 | __u32 ctxtcount; /* Number of contexts appended to section */ |
| 83 | unsigned char release[32]; /* kernel release */ |
| 84 | unsigned char version[32]; /* kernel version */ |
| 85 | unsigned char comm[16]; /* Name of the process that owns the PT */ |
| 86 | } __packed; |
| 87 | |
| 88 | struct kgsl_snapshot_linux_v2 { |
| 89 | int osid; /* subsection OS identifier */ |
| 90 | __u32 seconds; /* Unix timestamp for the snapshot */ |
| 91 | __u32 power_flags; /* Current power flags */ |
| 92 | __u32 power_level; /* Current power level */ |
| 93 | __u32 power_interval_timeout; /* Power interval timeout */ |
| 94 | __u32 grpclk; /* Current GP clock value */ |
| 95 | __u32 busclk; /* Current busclk value */ |
| 96 | __u64 ptbase; /* Current ptbase */ |
| 97 | __u32 pid; /* PID of the process that owns the PT */ |
| 98 | __u32 current_context; /* ID of the current context */ |
| 99 | __u32 ctxtcount; /* Number of contexts appended to section */ |
| 100 | unsigned char release[32]; /* kernel release */ |
| 101 | unsigned char version[32]; /* kernel version */ |
| 102 | unsigned char comm[16]; /* Name of the process that owns the PT */ |
| 103 | } __packed; |
| 104 | |
| 105 | /* |
| 106 | * This structure contains a record of an active context. |
| 107 | * These are appended one after another in the OS section below |
| 108 | * the header above |
| 109 | */ |
| 110 | |
| 111 | struct kgsl_snapshot_linux_context { |
| 112 | __u32 id; /* The context ID */ |
| 113 | __u32 timestamp_queued; /* The last queued timestamp */ |
| 114 | __u32 timestamp_retired; /* The last timestamp retired by HW */ |
| 115 | }; |
| 116 | |
| 117 | struct kgsl_snapshot_linux_context_v2 { |
| 118 | __u32 id; /* The context ID */ |
| 119 | __u32 timestamp_queued; /* The last queued timestamp */ |
| 120 | __u32 timestamp_consumed; /* The last timestamp consumed by HW */ |
| 121 | __u32 timestamp_retired; /* The last timestamp retired by HW */ |
| 122 | }; |
| 123 | /* Ringbuffer sub-section header */ |
| 124 | struct kgsl_snapshot_rb { |
| 125 | int start; /* dword at the start of the dump */ |
| 126 | int end; /* dword at the end of the dump */ |
| 127 | int rbsize; /* Size (in dwords) of the ringbuffer */ |
| 128 | int wptr; /* Current index of the CPU write pointer */ |
| 129 | int rptr; /* Current index of the GPU read pointer */ |
| 130 | int count; /* Number of dwords in the dump */ |
| 131 | __u32 timestamp_queued; /* The last queued timestamp */ |
| 132 | __u32 timestamp_retired; /* The last timestamp retired by HW */ |
| 133 | } __packed; |
| 134 | |
| 135 | struct kgsl_snapshot_rb_v2 { |
| 136 | int start; /* dword at the start of the dump */ |
| 137 | int end; /* dword at the end of the dump */ |
| 138 | int rbsize; /* Size (in dwords) of the ringbuffer */ |
| 139 | int wptr; /* Current index of the CPU write pointer */ |
| 140 | int rptr; /* Current index of the GPU read pointer */ |
| 141 | int count; /* Number of dwords in the dump */ |
| 142 | __u32 timestamp_queued; /* The last queued timestamp */ |
| 143 | __u32 timestamp_retired; /* The last timestamp retired by HW */ |
| 144 | __u64 gpuaddr; /* The GPU address of the ringbuffer */ |
| 145 | __u32 id; /* Ringbuffer identifier */ |
| 146 | } __packed; |
| 147 | |
| 148 | |
| 149 | /* Replay or Memory list section, both sections have same header */ |
| 150 | struct kgsl_snapshot_replay_mem_list { |
| 151 | /* |
| 152 | * Number of IBs to replay for replay section or |
| 153 | * number of memory list entries for mem list section |
| 154 | */ |
| 155 | int num_entries; |
| 156 | /* Pagetable base to which the replay IBs or memory entries belong */ |
| 157 | __u32 ptbase; |
| 158 | } __packed; |
| 159 | |
| 160 | /* Replay or Memory list section, both sections have same header */ |
| 161 | struct kgsl_snapshot_mem_list_v2 { |
| 162 | /* |
| 163 | * Number of IBs to replay for replay section or |
| 164 | * number of memory list entries for mem list section |
| 165 | */ |
| 166 | int num_entries; |
| 167 | /* Pagetable base to which the replay IBs or memory entries belong */ |
| 168 | __u64 ptbase; |
| 169 | } __packed; |
| 170 | |
| 171 | |
| 172 | /* Indirect buffer sub-section header */ |
| 173 | struct kgsl_snapshot_ib { |
| 174 | __u32 gpuaddr; /* GPU address of the the IB */ |
| 175 | __u32 ptbase; /* Base for the pagetable the GPU address is valid in */ |
| 176 | int size; /* Size of the IB */ |
| 177 | } __packed; |
| 178 | |
| 179 | /* Indirect buffer sub-section header (v2) */ |
| 180 | struct kgsl_snapshot_ib_v2 { |
| 181 | __u64 gpuaddr; /* GPU address of the the IB */ |
| 182 | __u64 ptbase; /* Base for the pagetable the GPU address is valid in */ |
| 183 | __u64 size; /* Size of the IB */ |
| 184 | } __packed; |
| 185 | |
| 186 | |
| 187 | /* Register sub-section header */ |
| 188 | struct kgsl_snapshot_regs { |
| 189 | __u32 count; /* Number of register pairs in the section */ |
| 190 | } __packed; |
| 191 | |
| 192 | /* Indexed register sub-section header */ |
| 193 | struct kgsl_snapshot_indexed_regs { |
| 194 | __u32 index_reg; /* Offset of the index register for this section */ |
| 195 | __u32 data_reg; /* Offset of the data register for this section */ |
| 196 | int start; /* Starting index */ |
| 197 | int count; /* Number of dwords in the data */ |
| 198 | } __packed; |
| 199 | |
Shrenuj Bansal | 4166540 | 2016-12-16 15:25:54 -0800 | [diff] [blame^] | 200 | /* MVC register sub-section header */ |
| 201 | struct kgsl_snapshot_mvc_regs { |
| 202 | int ctxt_id; |
| 203 | int cluster_id; |
| 204 | } __packed; |
| 205 | |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 206 | /* Istore sub-section header */ |
| 207 | struct kgsl_snapshot_istore { |
| 208 | int count; /* Number of instructions in the istore */ |
| 209 | } __packed; |
| 210 | |
| 211 | /* Debug data sub-section header */ |
| 212 | |
| 213 | /* A2XX debug sections */ |
| 214 | #define SNAPSHOT_DEBUG_SX 1 |
| 215 | #define SNAPSHOT_DEBUG_CP 2 |
| 216 | #define SNAPSHOT_DEBUG_SQ 3 |
| 217 | #define SNAPSHOT_DEBUG_SQTHREAD 4 |
| 218 | #define SNAPSHOT_DEBUG_MIU 5 |
| 219 | |
| 220 | /* A3XX debug sections */ |
| 221 | #define SNAPSHOT_DEBUG_VPC_MEMORY 6 |
| 222 | #define SNAPSHOT_DEBUG_CP_MEQ 7 |
| 223 | #define SNAPSHOT_DEBUG_CP_PM4_RAM 8 |
| 224 | #define SNAPSHOT_DEBUG_CP_PFP_RAM 9 |
| 225 | #define SNAPSHOT_DEBUG_CP_ROQ 10 |
| 226 | #define SNAPSHOT_DEBUG_SHADER_MEMORY 11 |
| 227 | #define SNAPSHOT_DEBUG_CP_MERCIU 12 |
| 228 | |
| 229 | struct kgsl_snapshot_debug { |
| 230 | int type; /* Type identifier for the attached tata */ |
| 231 | int size; /* Size of the section in dwords */ |
| 232 | } __packed; |
| 233 | |
| 234 | struct kgsl_snapshot_debugbus { |
| 235 | int id; /* Debug bus ID */ |
| 236 | int count; /* Number of dwords in the dump */ |
| 237 | } __packed; |
| 238 | |
| 239 | struct kgsl_snapshot_shader { |
| 240 | int type; /* SP/TP statetype */ |
| 241 | int index; /* SP/TP index */ |
| 242 | int size; /* Number of dwords in the dump */ |
| 243 | } __packed; |
| 244 | |
| 245 | #define SNAPSHOT_GPU_OBJECT_SHADER 1 |
| 246 | #define SNAPSHOT_GPU_OBJECT_IB 2 |
| 247 | #define SNAPSHOT_GPU_OBJECT_GENERIC 3 |
| 248 | #define SNAPSHOT_GPU_OBJECT_DRAW 4 |
| 249 | #define SNAPSHOT_GPU_OBJECT_GLOBAL 5 |
| 250 | |
| 251 | struct kgsl_snapshot_gpu_object { |
| 252 | int type; /* Type of GPU object */ |
| 253 | __u32 gpuaddr; /* GPU address of the the object */ |
| 254 | __u32 ptbase; /* Base for the pagetable the GPU address is valid in */ |
| 255 | int size; /* Size of the object (in dwords) */ |
| 256 | }; |
| 257 | |
| 258 | struct kgsl_snapshot_gpu_object_v2 { |
| 259 | int type; /* Type of GPU object */ |
| 260 | __u64 gpuaddr; /* GPU address of the the object */ |
| 261 | __u64 ptbase; /* Base for the pagetable the GPU address is valid in */ |
| 262 | __u64 size; /* Size of the object (in dwords) */ |
| 263 | } __packed; |
| 264 | |
Hareesh Gundu | 9c6b1fa | 2017-01-06 15:37:09 +0530 | [diff] [blame] | 265 | void kgsl_snapshot_push_object(struct kgsl_process_private *process, |
| 266 | uint64_t gpuaddr, uint64_t dwords); |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 267 | #endif |