blob: 4fdc8a1b665ac785955df2bf87a2f26ae033fe7b [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
50#define KGSL_SNAPSHOT_SECTION_END 0xFFFF
51
52/* OS sub-section header */
53#define KGSL_SNAPSHOT_OS_LINUX 0x0001
54
55/* Linux OS specific information */
56
57#define SNAPSHOT_STATE_HUNG 0
58#define SNAPSHOT_STATE_RUNNING 1
59
60struct kgsl_snapshot_linux {
61 int osid; /* subsection OS identifier */
62 int state; /* 1 if the thread is running, 0 for hung */
63 __u32 seconds; /* Unix timestamp for the snapshot */
64 __u32 power_flags; /* Current power flags */
65 __u32 power_level; /* Current power level */
66 __u32 power_interval_timeout; /* Power interval timeout */
67 __u32 grpclk; /* Current GP clock value */
68 __u32 busclk; /* Current busclk value */
69 __u32 ptbase; /* Current ptbase */
70 __u32 pid; /* PID of the process that owns the PT */
71 __u32 current_context; /* ID of the current context */
72 __u32 ctxtcount; /* Number of contexts appended to section */
73 unsigned char release[32]; /* kernel release */
74 unsigned char version[32]; /* kernel version */
75 unsigned char comm[16]; /* Name of the process that owns the PT */
76} __packed;
77
78/*
79 * This structure contains a record of an active context.
80 * These are appended one after another in the OS section below
81 * the header above
82 */
83
84struct kgsl_snapshot_linux_context {
85 __u32 id; /* The context ID */
86 __u32 timestamp_queued; /* The last queued timestamp */
87 __u32 timestamp_retired; /* The last timestamp retired by HW */
88};
89
90/* Ringbuffer sub-section header */
91struct kgsl_snapshot_rb {
92 int start; /* dword at the start of the dump */
93 int end; /* dword at the end of the dump */
94 int rbsize; /* Size (in dwords) of the ringbuffer */
95 int wptr; /* Current index of the CPU write pointer */
96 int rptr; /* Current index of the GPU read pointer */
97 int count; /* Number of dwords in the dump */
98} __packed;
99
100/* Indirect buffer sub-section header */
101struct kgsl_snapshot_ib {
102 __u32 gpuaddr; /* GPU address of the the IB */
103 __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
104 int size; /* Size of the IB */
105} __packed;
106
107/* Register sub-section header */
108struct kgsl_snapshot_regs {
109 __u32 count; /* Number of register pairs in the section */
110} __packed;
111
112/* Indexed register sub-section header */
113struct kgsl_snapshot_indexed_regs {
114 __u32 index_reg; /* Offset of the index register for this section */
115 __u32 data_reg; /* Offset of the data register for this section */
116 int start; /* Starting index */
117 int count; /* Number of dwords in the data */
118} __packed;
119
120/* Istore sub-section header */
121struct kgsl_snapshot_istore {
122 int count; /* Number of instructions in the istore */
123} __packed;
124
125/* Debug data sub-section header */
126
127#define SNAPSHOT_DEBUG_SX 1
128#define SNAPSHOT_DEBUG_CP 2
129#define SNAPSHOT_DEBUG_SQ 3
130#define SNAPSHOT_DEBUG_SQTHREAD 4
131#define SNAPSHOT_DEBUG_MIU 5
132
133struct kgsl_snapshot_debug {
134 int type; /* Type identifier for the attached tata */
135 int size; /* Size of the section in bytes */
136} __packed;
137
138#ifdef __KERNEL__
139
140/* Allocate 512K for each device snapshot */
141#define KGSL_SNAPSHOT_MEMSIZE (512 * 1024)
142
143struct kgsl_device;
144/*
145 * A helper macro to print out "not enough memory functions" - this
146 * makes it easy to standardize the messages as well as cut down on
147 * the number of strings in the binary
148 */
149
150#define SNAPSHOT_ERR_NOMEM(_d, _s) \
151 KGSL_DRV_ERR((_d), \
152 "snapshot: not enough snapshot memory for section %s\n", (_s))
153
154/*
155 * kgsl_snapshot_add_section - Add a new section to the GPU snapshot
156 * @device - the KGSL device being snapshotted
157 * @id - the section id
158 * @snapshot - pointer to the memory for the snapshot
159 * @remain - pointer to the number of bytes left in the snapshot region
160 * @func - Function pointer to fill the section
161 * @priv - Priv pointer to pass to the function
162 *
163 * Set up a KGSL snapshot header by filling the memory with the callback
164 * function and adding the standard section header
165 */
166
167static inline void *kgsl_snapshot_add_section(struct kgsl_device *device,
168 u16 id, void *snapshot, int *remain,
169 int (*func)(struct kgsl_device *, void *, int, void *), void *priv)
170{
171 struct kgsl_snapshot_section_header *header = snapshot;
172 void *data = snapshot + sizeof(*header);
173 int ret = 0;
174
175 /*
176 * Sanity check to make sure there is enough for the header. The
177 * callback will check to make sure there is enough for the rest
178 * of the data. If there isn't enough room then don't advance the
179 * pointer.
180 */
181
182 if (*remain < sizeof(*header))
183 return snapshot;
184
185 /* It is legal to have no function (i.e. - make an empty section) */
186
187 if (func) {
188 ret = func(device, data, *remain, priv);
189
190 /*
191 * If there wasn't enough room for the data then don't bother
192 * setting up the header.
193 */
194
195 if (ret == 0)
196 return snapshot;
197 }
198
199 header->magic = SNAPSHOT_SECTION_MAGIC;
200 header->id = id;
201 header->size = ret + sizeof(*header);
202
203 /* Decrement the room left in the snapshot region */
204 *remain -= header->size;
205 /* Advance the pointer to the end of the next function */
206 return snapshot + header->size;
207}
208
209/* A common helper function to dump a range of registers. This will be used in
210 * the GPU specific devices like this:
211 *
212 * struct kgsl_snapshot_registers priv;
213 * priv.regs = registers_array;;
214 * priv.count = num_registers;
215 *
216 * kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS, snapshot,
217 * remain, kgsl_snapshot_dump_regs, &priv).
218 *
219 * Pass in an array of register range pairs in the form of:
220 * start reg, stop reg
221 * All the registers between start and stop inclusive will be dumped
222 */
223
224struct kgsl_snapshot_registers {
225 unsigned int *regs; /* Pointer to the array of register ranges */
226 int count; /* Number of entries in the array */
227};
228
229int kgsl_snapshot_dump_regs(struct kgsl_device *device, void *snapshot,
230 int remain, void *priv);
231
232/*
233 * A common helper function to dump a set of indexed registers. Use it
234 * like this:
235 *
236 * struct kgsl_snapshot_indexed_registers priv;
237 * priv.index = REG_INDEX;
238 * priv.data = REG_DATA;
239 * priv.count = num_registers
240 *
241 * kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_INDEXED_REGS,
242 * snapshot, remain, kgsl_snapshot_dump_indexed_regs, &priv).
243 *
244 * The callback function will write an index from 0 to priv.count to
245 * the index register and read the data from the data register.
246 */
247
248struct kgsl_snapshot_indexed_registers {
249 unsigned int index; /* Offset of the index register */
250 unsigned int data; /* Offset of the data register */
251 unsigned int start; /* Index to start with */
252 unsigned int count; /* Number of values to read from the pair */
253};
254
255int kgsl_snapshot_dump_indexed_regs(struct kgsl_device *device,
256 void *snapshot, int remain, void *priv);
257
258#endif
259#endif