blob: 2eeb63d69b0b7d2b83c2bde527b81e1885c21be1 [file] [log] [blame]
Jordan Crouse156cfbc2012-01-24 09:32:04 -07001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
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#define SNAPSHOT_MAGIC 0x504D0001
22
23/* GPU ID scheme:
24 * [16:31] - core identifer (0x0002 for 2D or 0x0003 for 3D)
25 * [00:16] - GPU specific identifier
26 */
27
28struct kgsl_snapshot_header {
29 __u32 magic; /* Magic identifier */
30 __u32 gpuid; /* GPU ID - see above */
31} __packed;
32
33/* Section header */
34#define SNAPSHOT_SECTION_MAGIC 0xABCD
35
36struct kgsl_snapshot_section_header {
37 __u16 magic; /* Magic identifier */
38 __u16 id; /* Type of section */
39 __u32 size; /* Size of the section including this header */
40} __packed;
41
42/* Section identifiers */
43#define KGSL_SNAPSHOT_SECTION_OS 0x0101
44#define KGSL_SNAPSHOT_SECTION_REGS 0x0201
45#define KGSL_SNAPSHOT_SECTION_RB 0x0301
46#define KGSL_SNAPSHOT_SECTION_IB 0x0401
47#define KGSL_SNAPSHOT_SECTION_INDEXED_REGS 0x0501
48#define KGSL_SNAPSHOT_SECTION_ISTORE 0x0801
49#define KGSL_SNAPSHOT_SECTION_DEBUG 0x0901
Jordan Crouse0c2761a2012-02-01 22:11:12 -070050#define KGSL_SNAPSHOT_SECTION_DEBUGBUS 0x0A01
Jordan Crouse9610b6b2012-03-16 14:53:42 -060051#define KGSL_SNAPSHOT_SECTION_GPU_OBJECT 0x0B01
52
Jordan Crouse156cfbc2012-01-24 09:32:04 -070053#define KGSL_SNAPSHOT_SECTION_END 0xFFFF
54
55/* OS sub-section header */
56#define KGSL_SNAPSHOT_OS_LINUX 0x0001
57
58/* Linux OS specific information */
59
60#define SNAPSHOT_STATE_HUNG 0
61#define SNAPSHOT_STATE_RUNNING 1
62
63struct kgsl_snapshot_linux {
64 int osid; /* subsection OS identifier */
65 int state; /* 1 if the thread is running, 0 for hung */
66 __u32 seconds; /* Unix timestamp for the snapshot */
67 __u32 power_flags; /* Current power flags */
68 __u32 power_level; /* Current power level */
69 __u32 power_interval_timeout; /* Power interval timeout */
70 __u32 grpclk; /* Current GP clock value */
71 __u32 busclk; /* Current busclk value */
72 __u32 ptbase; /* Current ptbase */
73 __u32 pid; /* PID of the process that owns the PT */
74 __u32 current_context; /* ID of the current context */
75 __u32 ctxtcount; /* Number of contexts appended to section */
76 unsigned char release[32]; /* kernel release */
77 unsigned char version[32]; /* kernel version */
78 unsigned char comm[16]; /* Name of the process that owns the PT */
79} __packed;
80
81/*
82 * This structure contains a record of an active context.
83 * These are appended one after another in the OS section below
84 * the header above
85 */
86
87struct kgsl_snapshot_linux_context {
88 __u32 id; /* The context ID */
89 __u32 timestamp_queued; /* The last queued timestamp */
90 __u32 timestamp_retired; /* The last timestamp retired by HW */
91};
92
93/* Ringbuffer sub-section header */
94struct kgsl_snapshot_rb {
95 int start; /* dword at the start of the dump */
96 int end; /* dword at the end of the dump */
97 int rbsize; /* Size (in dwords) of the ringbuffer */
98 int wptr; /* Current index of the CPU write pointer */
99 int rptr; /* Current index of the GPU read pointer */
100 int count; /* Number of dwords in the dump */
101} __packed;
102
103/* Indirect buffer sub-section header */
104struct kgsl_snapshot_ib {
105 __u32 gpuaddr; /* GPU address of the the IB */
106 __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
107 int size; /* Size of the IB */
108} __packed;
109
110/* Register sub-section header */
111struct kgsl_snapshot_regs {
112 __u32 count; /* Number of register pairs in the section */
113} __packed;
114
115/* Indexed register sub-section header */
116struct kgsl_snapshot_indexed_regs {
117 __u32 index_reg; /* Offset of the index register for this section */
118 __u32 data_reg; /* Offset of the data register for this section */
119 int start; /* Starting index */
120 int count; /* Number of dwords in the data */
121} __packed;
122
123/* Istore sub-section header */
124struct kgsl_snapshot_istore {
125 int count; /* Number of instructions in the istore */
126} __packed;
127
128/* Debug data sub-section header */
129
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700130/* A2XX debug sections */
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700131#define SNAPSHOT_DEBUG_SX 1
132#define SNAPSHOT_DEBUG_CP 2
133#define SNAPSHOT_DEBUG_SQ 3
134#define SNAPSHOT_DEBUG_SQTHREAD 4
135#define SNAPSHOT_DEBUG_MIU 5
136
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700137/* A3XX debug sections */
138#define SNAPSHOT_DEBUG_VPC_MEMORY 6
139#define SNAPSHOT_DEBUG_CP_MEQ 7
140#define SNAPSHOT_DEBUG_CP_PM4_RAM 8
141#define SNAPSHOT_DEBUG_CP_PFP_RAM 9
142#define SNAPSHOT_DEBUG_CP_ROQ 10
143
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700144struct kgsl_snapshot_debug {
145 int type; /* Type identifier for the attached tata */
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700146 int size; /* Size of the section in dwords */
147} __packed;
148
149struct kgsl_snapshot_debugbus {
150 int id; /* Debug bus ID */
151 int count; /* Number of dwords in the dump */
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700152} __packed;
153
Jordan Crouseea2c6382012-03-16 14:53:42 -0600154#define SNAPSHOT_GPU_OBJECT_SHADER 1
155
Jordan Crouse9610b6b2012-03-16 14:53:42 -0600156struct kgsl_snapshot_gpu_object {
157 int type; /* Type of GPU object */
158 __u32 gpuaddr; /* GPU address of the the object */
159 __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
160 int size; /* Size of the object (in dwords) */
161};
162
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700163#ifdef __KERNEL__
164
165/* Allocate 512K for each device snapshot */
166#define KGSL_SNAPSHOT_MEMSIZE (512 * 1024)
167
168struct kgsl_device;
169/*
170 * A helper macro to print out "not enough memory functions" - this
171 * makes it easy to standardize the messages as well as cut down on
172 * the number of strings in the binary
173 */
174
175#define SNAPSHOT_ERR_NOMEM(_d, _s) \
176 KGSL_DRV_ERR((_d), \
177 "snapshot: not enough snapshot memory for section %s\n", (_s))
178
179/*
180 * kgsl_snapshot_add_section - Add a new section to the GPU snapshot
181 * @device - the KGSL device being snapshotted
182 * @id - the section id
183 * @snapshot - pointer to the memory for the snapshot
184 * @remain - pointer to the number of bytes left in the snapshot region
185 * @func - Function pointer to fill the section
186 * @priv - Priv pointer to pass to the function
187 *
188 * Set up a KGSL snapshot header by filling the memory with the callback
189 * function and adding the standard section header
190 */
191
192static inline void *kgsl_snapshot_add_section(struct kgsl_device *device,
193 u16 id, void *snapshot, int *remain,
194 int (*func)(struct kgsl_device *, void *, int, void *), void *priv)
195{
196 struct kgsl_snapshot_section_header *header = snapshot;
197 void *data = snapshot + sizeof(*header);
198 int ret = 0;
199
200 /*
201 * Sanity check to make sure there is enough for the header. The
202 * callback will check to make sure there is enough for the rest
203 * of the data. If there isn't enough room then don't advance the
204 * pointer.
205 */
206
207 if (*remain < sizeof(*header))
208 return snapshot;
209
210 /* It is legal to have no function (i.e. - make an empty section) */
211
212 if (func) {
213 ret = func(device, data, *remain, priv);
214
215 /*
216 * If there wasn't enough room for the data then don't bother
217 * setting up the header.
218 */
219
220 if (ret == 0)
221 return snapshot;
222 }
223
224 header->magic = SNAPSHOT_SECTION_MAGIC;
225 header->id = id;
226 header->size = ret + sizeof(*header);
227
228 /* Decrement the room left in the snapshot region */
229 *remain -= header->size;
230 /* Advance the pointer to the end of the next function */
231 return snapshot + header->size;
232}
233
234/* A common helper function to dump a range of registers. This will be used in
235 * the GPU specific devices like this:
236 *
237 * struct kgsl_snapshot_registers priv;
238 * priv.regs = registers_array;;
239 * priv.count = num_registers;
240 *
241 * kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS, snapshot,
242 * remain, kgsl_snapshot_dump_regs, &priv).
243 *
244 * Pass in an array of register range pairs in the form of:
245 * start reg, stop reg
246 * All the registers between start and stop inclusive will be dumped
247 */
248
249struct kgsl_snapshot_registers {
250 unsigned int *regs; /* Pointer to the array of register ranges */
251 int count; /* Number of entries in the array */
252};
253
254int kgsl_snapshot_dump_regs(struct kgsl_device *device, void *snapshot,
255 int remain, void *priv);
256
257/*
258 * A common helper function to dump a set of indexed registers. Use it
259 * like this:
260 *
261 * struct kgsl_snapshot_indexed_registers priv;
262 * priv.index = REG_INDEX;
263 * priv.data = REG_DATA;
264 * priv.count = num_registers
265 *
266 * kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_INDEXED_REGS,
267 * snapshot, remain, kgsl_snapshot_dump_indexed_regs, &priv).
268 *
269 * The callback function will write an index from 0 to priv.count to
270 * the index register and read the data from the data register.
271 */
272
273struct kgsl_snapshot_indexed_registers {
274 unsigned int index; /* Offset of the index register */
275 unsigned int data; /* Offset of the data register */
276 unsigned int start; /* Index to start with */
277 unsigned int count; /* Number of values to read from the pair */
278};
279
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700280/* Helper function to snapshot a section of indexed registers */
281
282void *kgsl_snapshot_indexed_registers(struct kgsl_device *device,
283 void *snapshot, int *remain, unsigned int index,
284 unsigned int data, unsigned int start, unsigned int count);
285
Jordan Crouse9610b6b2012-03-16 14:53:42 -0600286/* Freeze a GPU buffer so it can be dumped in the snapshot */
287int kgsl_snapshot_get_object(struct kgsl_device *device, unsigned int ptbase,
288 unsigned int gpuaddr, unsigned int size, unsigned int type);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700289
290#endif
291#endif