blob: 57f48595b2e13efbea61b49380ffdc585bdd26b0 [file] [log] [blame]
Jordan Crousef7597bf2012-01-03 08:43:34 -07001/* Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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#ifndef __ADRENO_H
14#define __ADRENO_H
15
16#include "kgsl_device.h"
17#include "adreno_drawctxt.h"
18#include "adreno_ringbuffer.h"
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -060019#include "kgsl_iommu.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070020
21#define DEVICE_3D_NAME "kgsl-3d"
22#define DEVICE_3D0_NAME "kgsl-3d0"
23
24#define ADRENO_DEVICE(device) \
25 KGSL_CONTAINER_OF(device, struct adreno_device, dev)
26
Jordan Crouse4815e9f2012-07-09 15:36:37 -060027#define ADRENO_CHIPID_CORE(_id) (((_id) >> 24) & 0xFF)
28#define ADRENO_CHIPID_MAJOR(_id) (((_id) >> 16) & 0xFF)
29#define ADRENO_CHIPID_MINOR(_id) (((_id) >> 8) & 0xFF)
30#define ADRENO_CHIPID_PATCH(_id) ((_id) & 0xFF)
31
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032/* Flags to control command packet settings */
Jordan Crousee0ea7622012-01-24 09:32:04 -070033#define KGSL_CMD_FLAGS_NONE 0x00000000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034#define KGSL_CMD_FLAGS_PMODE 0x00000001
Zhoulu Luo552905e2012-06-21 15:21:52 -070035#define KGSL_CMD_FLAGS_NO_TS_CMP 0x00000002
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036
37/* Command identifiers */
Shubhraprakash Dasd23ff4b2012-04-05 16:55:54 -060038#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
39#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
40#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
41#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#ifdef CONFIG_MSM_SCM
44#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz)
Lynus Vaz31754cb2012-02-22 18:07:02 +053045#elif defined CONFIG_MSM_SLEEP_STATS_DEVICE
46#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047#else
48#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
49#endif
50
Jordan Crousec6b3a992012-02-04 10:23:51 -070051#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070052
Shubhraprakash Das4624b552012-06-01 14:08:03 -060053#define ADRENO_NUM_CTX_SWITCH_ALLOWED_BEFORE_DRAW 50
54
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055enum adreno_gpurev {
56 ADRENO_REV_UNKNOWN = 0,
57 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053058 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059 ADRENO_REV_A205 = 205,
60 ADRENO_REV_A220 = 220,
61 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053062 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070063 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064};
65
Jordan Crousea78c9172011-07-11 13:14:09 -060066struct adreno_gpudev;
67
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068struct adreno_device {
69 struct kgsl_device dev; /* Must be first field in this struct */
70 unsigned int chip_id;
71 enum adreno_gpurev gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -060072 unsigned long gmem_base;
73 unsigned int gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060075 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076 unsigned int *pfp_fw;
77 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060078 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070079 unsigned int *pm4_fw;
80 size_t pm4_fw_size;
81 struct adreno_ringbuffer ringbuffer;
82 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060083 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053084 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070085 unsigned int istore_size;
86 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070087 unsigned int instruction_size;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -060088 unsigned int ib_check_level;
Tarun Karra3335f142012-06-19 14:11:48 -070089 unsigned int fast_hang_detect;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090};
91
Jordan Crousea78c9172011-07-11 13:14:09 -060092struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070093 /*
94 * These registers are in a different location on A3XX, so define
95 * them in the structure and use them as variables.
96 */
97 unsigned int reg_rbbm_status;
98 unsigned int reg_cp_pfp_ucode_data;
99 unsigned int reg_cp_pfp_ucode_addr;
Shubhraprakash Das4624b552012-06-01 14:08:03 -0600100 /* keeps track of when we need to execute the draw workaround code */
101 int ctx_switches_since_last_draw;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700102
103 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700104 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600105 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
106 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600107 void (*ctxt_draw_workaround)(struct adreno_device *,
108 struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600109 irqreturn_t (*irq_handler)(struct adreno_device *);
110 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700111 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700112 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
113 void (*start)(struct adreno_device *);
114 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600115};
116
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600117/*
118 * struct adreno_recovery_data - Structure that contains all information to
119 * perform gpu recovery from hangs
120 * @ib1 - IB1 that the GPU was executing when hang happened
121 * @context_id - Context which caused the hang
122 * @global_eop - eoptimestamp at time of hang
123 * @rb_buffer - Buffer that holds the commands from good contexts
124 * @rb_size - Number of valid dwords in rb_buffer
125 * @bad_rb_buffer - Buffer that holds commands from the hanging context
126 * bad_rb_size - Number of valid dwords in bad_rb_buffer
127 * @last_valid_ctx_id - The last context from which commands were placed in
128 * ringbuffer before the GPU hung
129 */
130struct adreno_recovery_data {
131 unsigned int ib1;
132 unsigned int context_id;
133 unsigned int global_eop;
134 unsigned int *rb_buffer;
135 unsigned int rb_size;
136 unsigned int *bad_rb_buffer;
137 unsigned int bad_rb_size;
138 unsigned int last_valid_ctx_id;
139};
140
Jordan Crousea78c9172011-07-11 13:14:09 -0600141extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700142extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600143
Jordan Crousef7597bf2012-01-03 08:43:34 -0700144/* A2XX register sets defined in adreno_a2xx.c */
145extern const unsigned int a200_registers[];
146extern const unsigned int a220_registers[];
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700147extern const unsigned int a225_registers[];
Jordan Crousef7597bf2012-01-03 08:43:34 -0700148extern const unsigned int a200_registers_count;
149extern const unsigned int a220_registers_count;
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700150extern const unsigned int a225_registers_count;
Jordan Crousef7597bf2012-01-03 08:43:34 -0700151
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700152/* A3XX register set defined in adreno_a3xx.c */
153extern const unsigned int a3xx_registers[];
154extern const unsigned int a3xx_registers_count;
155
Tarun Karra3335f142012-06-19 14:11:48 -0700156extern unsigned int hang_detect_regs[];
157extern const unsigned int hang_detect_regs_count;
158
159
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160int adreno_idle(struct kgsl_device *device, unsigned int timeout);
161void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
162 unsigned int *value);
163void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
164 unsigned int value);
165
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600166struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700167 unsigned int pt_base,
168 unsigned int gpuaddr,
169 unsigned int size);
170
171uint8_t *adreno_convertaddr(struct kgsl_device *device,
172 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173
Jordan Crouse233b2092012-04-18 09:31:09 -0600174struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
175 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
176
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700177void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
178 int hang);
179
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600180int adreno_dump_and_recover(struct kgsl_device *device);
181
Tarun Karra3335f142012-06-19 14:11:48 -0700182unsigned int adreno_hang_detect(struct kgsl_device *device,
183 unsigned int *prev_reg_val);
184
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185static inline int adreno_is_a200(struct adreno_device *adreno_dev)
186{
187 return (adreno_dev->gpurev == ADRENO_REV_A200);
188}
189
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530190static inline int adreno_is_a203(struct adreno_device *adreno_dev)
191{
192 return (adreno_dev->gpurev == ADRENO_REV_A203);
193}
194
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195static inline int adreno_is_a205(struct adreno_device *adreno_dev)
196{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530197 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198}
199
200static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
201{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530202 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203}
204
205static inline int adreno_is_a220(struct adreno_device *adreno_dev)
206{
207 return (adreno_dev->gpurev == ADRENO_REV_A220);
208}
209
210static inline int adreno_is_a225(struct adreno_device *adreno_dev)
211{
212 return (adreno_dev->gpurev == ADRENO_REV_A225);
213}
214
215static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
216{
217 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
218 adreno_dev->gpurev == ADRENO_REV_A225);
219}
220
Jordan Crouse196c45b2011-07-28 08:37:57 -0600221static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
222{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700223 return (adreno_dev->gpurev <= 299);
224}
225
226static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
227{
228 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600229}
230
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600231static inline int adreno_is_a305(struct adreno_device *adreno_dev)
232{
233 return (adreno_dev->gpurev == ADRENO_REV_A305);
234}
235
236static inline int adreno_is_a320(struct adreno_device *adreno_dev)
237{
238 return (adreno_dev->gpurev == ADRENO_REV_A320);
239}
240
Jordan Crousee6b77622012-04-05 16:55:54 -0600241static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
242{
243 return (cmd[0] == cp_nop_packet(1) &&
244 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
245}
246
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700247/**
248 * adreno_encode_istore_size - encode istore size in CP format
249 * @adreno_dev - The 3D device.
250 *
251 * Encode the istore size into the format expected that the
252 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
253 * bits 31:29 - istore size as encoded by this function
254 * bits 27:16 - vertex shader start offset in instructions
255 * bits 11:0 - pixel shader start offset in instructions.
256 */
257static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
258{
259 unsigned int size;
260 /* in a225 the CP microcode multiplies the encoded
261 * value by 3 while decoding.
262 */
263 if (adreno_is_a225(adreno_dev))
264 size = adreno_dev->istore_size/3;
265 else
266 size = adreno_dev->istore_size;
267
268 return (ilog2(size) - 5) << 29;
269}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600270
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600271static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds,
272 unsigned int nop_gpuaddr)
273{
274 /* Adding an indirect buffer ensures that the prefetch stalls until
275 * the commands in indirect buffer have completed. We need to stall
276 * prefetch with a nop indirect buffer when updating pagetables
277 * because it provides stabler synchronization */
278 *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD;
279 *cmds++ = nop_gpuaddr;
280 *cmds++ = 2;
281 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
282 *cmds++ = 0x00000000;
283 return 5;
284}
285
286static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds,
287 unsigned int new_phys_limit,
288 unsigned int nop_gpuaddr)
289{
290 unsigned int *start = cmds;
291
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600292 *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1);
293 *cmds++ = new_phys_limit;
294 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
295 return cmds - start;
296}
297
298static inline int adreno_add_bank_change_cmds(unsigned int *cmds,
299 int cur_ctx_bank,
300 unsigned int nop_gpuaddr)
301{
302 unsigned int *start = cmds;
303
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600304 *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1);
305 *cmds++ = (cur_ctx_bank ? 0 : 0x20);
306 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
307 return cmds - start;
308}
309
310/*
311 * adreno_read_cmds - Add pm4 packets to perform read
312 * @device - Pointer to device structure
313 * @cmds - Pointer to memory where read commands need to be added
314 * @addr - gpu address of the read
315 * @val - The GPU will wait until the data at address addr becomes
316 * equal to value
317 */
318static inline int adreno_add_read_cmds(struct kgsl_device *device,
319 unsigned int *cmds, unsigned int addr,
320 unsigned int val, unsigned int nop_gpuaddr)
321{
322 unsigned int *start = cmds;
323
324 *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5);
325 /* MEM SPACE = memory, FUNCTION = equals */
326 *cmds++ = 0x13;
327 *cmds++ = addr;
328 *cmds++ = val;
329 *cmds++ = 0xFFFFFFFF;
330 *cmds++ = 0xFFFFFFFF;
331 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
332 return cmds - start;
333}
334
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700335#endif /*__ADRENO_H */