blob: 04dc3d654d8b714b136ec24dd7ee45fcef9cc31d [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
36#define KGSL_CMD_FLAGS_NOT_KERNEL_CMD 0x00000004
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38/* Command identifiers */
Shubhraprakash Dasd23ff4b2012-04-05 16:55:54 -060039#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
40#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
41#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
42#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070043
44#ifdef CONFIG_MSM_SCM
45#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz)
Lynus Vaz31754cb2012-02-22 18:07:02 +053046#elif defined CONFIG_MSM_SLEEP_STATS_DEVICE
47#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048#else
49#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
50#endif
51
Jordan Crousec6b3a992012-02-04 10:23:51 -070052#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070053
Shubhraprakash Das4624b552012-06-01 14:08:03 -060054#define ADRENO_NUM_CTX_SWITCH_ALLOWED_BEFORE_DRAW 50
55
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056enum adreno_gpurev {
57 ADRENO_REV_UNKNOWN = 0,
58 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053059 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060 ADRENO_REV_A205 = 205,
61 ADRENO_REV_A220 = 220,
62 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053063 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070064 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065};
66
Jordan Crousea78c9172011-07-11 13:14:09 -060067struct adreno_gpudev;
68
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069struct adreno_device {
70 struct kgsl_device dev; /* Must be first field in this struct */
71 unsigned int chip_id;
72 enum adreno_gpurev gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -060073 unsigned long gmem_base;
74 unsigned int gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060076 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077 unsigned int *pfp_fw;
78 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060079 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080 unsigned int *pm4_fw;
81 size_t pm4_fw_size;
82 struct adreno_ringbuffer ringbuffer;
83 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060084 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053085 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070086 unsigned int istore_size;
87 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070088 unsigned int instruction_size;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -060089 unsigned int ib_check_level;
Tarun Karra3335f142012-06-19 14:11:48 -070090 unsigned int fast_hang_detect;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091};
92
Jordan Crousea78c9172011-07-11 13:14:09 -060093struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070094 /*
95 * These registers are in a different location on A3XX, so define
96 * them in the structure and use them as variables.
97 */
98 unsigned int reg_rbbm_status;
99 unsigned int reg_cp_pfp_ucode_data;
100 unsigned int reg_cp_pfp_ucode_addr;
Shubhraprakash Das4624b552012-06-01 14:08:03 -0600101 /* keeps track of when we need to execute the draw workaround code */
102 int ctx_switches_since_last_draw;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700103
104 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700105 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600106 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
107 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600108 void (*ctxt_draw_workaround)(struct adreno_device *,
109 struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600110 irqreturn_t (*irq_handler)(struct adreno_device *);
111 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700112 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700113 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
114 void (*start)(struct adreno_device *);
115 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600116};
117
118extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700119extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600120
Jordan Crousef7597bf2012-01-03 08:43:34 -0700121/* A2XX register sets defined in adreno_a2xx.c */
122extern const unsigned int a200_registers[];
123extern const unsigned int a220_registers[];
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700124extern const unsigned int a225_registers[];
Jordan Crousef7597bf2012-01-03 08:43:34 -0700125extern const unsigned int a200_registers_count;
126extern const unsigned int a220_registers_count;
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700127extern const unsigned int a225_registers_count;
Jordan Crousef7597bf2012-01-03 08:43:34 -0700128
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700129/* A3XX register set defined in adreno_a3xx.c */
130extern const unsigned int a3xx_registers[];
131extern const unsigned int a3xx_registers_count;
132
Tarun Karra3335f142012-06-19 14:11:48 -0700133extern unsigned int hang_detect_regs[];
134extern const unsigned int hang_detect_regs_count;
135
136
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137int adreno_idle(struct kgsl_device *device, unsigned int timeout);
138void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
139 unsigned int *value);
140void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
141 unsigned int value);
142
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600143struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700144 unsigned int pt_base,
145 unsigned int gpuaddr,
146 unsigned int size);
147
148uint8_t *adreno_convertaddr(struct kgsl_device *device,
149 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150
Jordan Crouse233b2092012-04-18 09:31:09 -0600151struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
152 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
153
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700154void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
155 int hang);
156
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600157int adreno_dump_and_recover(struct kgsl_device *device);
158
Tarun Karra3335f142012-06-19 14:11:48 -0700159unsigned int adreno_hang_detect(struct kgsl_device *device,
160 unsigned int *prev_reg_val);
161
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162static inline int adreno_is_a200(struct adreno_device *adreno_dev)
163{
164 return (adreno_dev->gpurev == ADRENO_REV_A200);
165}
166
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530167static inline int adreno_is_a203(struct adreno_device *adreno_dev)
168{
169 return (adreno_dev->gpurev == ADRENO_REV_A203);
170}
171
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172static inline int adreno_is_a205(struct adreno_device *adreno_dev)
173{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530174 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175}
176
177static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
178{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530179 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180}
181
182static inline int adreno_is_a220(struct adreno_device *adreno_dev)
183{
184 return (adreno_dev->gpurev == ADRENO_REV_A220);
185}
186
187static inline int adreno_is_a225(struct adreno_device *adreno_dev)
188{
189 return (adreno_dev->gpurev == ADRENO_REV_A225);
190}
191
192static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
193{
194 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
195 adreno_dev->gpurev == ADRENO_REV_A225);
196}
197
Jordan Crouse196c45b2011-07-28 08:37:57 -0600198static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
199{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700200 return (adreno_dev->gpurev <= 299);
201}
202
203static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
204{
205 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600206}
207
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600208static inline int adreno_is_a305(struct adreno_device *adreno_dev)
209{
210 return (adreno_dev->gpurev == ADRENO_REV_A305);
211}
212
213static inline int adreno_is_a320(struct adreno_device *adreno_dev)
214{
215 return (adreno_dev->gpurev == ADRENO_REV_A320);
216}
217
Jordan Crousee6b77622012-04-05 16:55:54 -0600218static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
219{
220 return (cmd[0] == cp_nop_packet(1) &&
221 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
222}
223
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700224/**
225 * adreno_encode_istore_size - encode istore size in CP format
226 * @adreno_dev - The 3D device.
227 *
228 * Encode the istore size into the format expected that the
229 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
230 * bits 31:29 - istore size as encoded by this function
231 * bits 27:16 - vertex shader start offset in instructions
232 * bits 11:0 - pixel shader start offset in instructions.
233 */
234static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
235{
236 unsigned int size;
237 /* in a225 the CP microcode multiplies the encoded
238 * value by 3 while decoding.
239 */
240 if (adreno_is_a225(adreno_dev))
241 size = adreno_dev->istore_size/3;
242 else
243 size = adreno_dev->istore_size;
244
245 return (ilog2(size) - 5) << 29;
246}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600247
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600248static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds,
249 unsigned int nop_gpuaddr)
250{
251 /* Adding an indirect buffer ensures that the prefetch stalls until
252 * the commands in indirect buffer have completed. We need to stall
253 * prefetch with a nop indirect buffer when updating pagetables
254 * because it provides stabler synchronization */
255 *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD;
256 *cmds++ = nop_gpuaddr;
257 *cmds++ = 2;
258 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
259 *cmds++ = 0x00000000;
260 return 5;
261}
262
263static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds,
264 unsigned int new_phys_limit,
265 unsigned int nop_gpuaddr)
266{
267 unsigned int *start = cmds;
268
Sunil Josephcf21e442012-07-10 15:23:13 +0530269 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600270 *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1);
271 *cmds++ = new_phys_limit;
272 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
273 return cmds - start;
274}
275
276static inline int adreno_add_bank_change_cmds(unsigned int *cmds,
277 int cur_ctx_bank,
278 unsigned int nop_gpuaddr)
279{
280 unsigned int *start = cmds;
281
Sunil Josephcf21e442012-07-10 15:23:13 +0530282 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600283 *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1);
284 *cmds++ = (cur_ctx_bank ? 0 : 0x20);
285 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
286 return cmds - start;
287}
288
289/*
290 * adreno_read_cmds - Add pm4 packets to perform read
291 * @device - Pointer to device structure
292 * @cmds - Pointer to memory where read commands need to be added
293 * @addr - gpu address of the read
294 * @val - The GPU will wait until the data at address addr becomes
295 * equal to value
296 */
297static inline int adreno_add_read_cmds(struct kgsl_device *device,
298 unsigned int *cmds, unsigned int addr,
299 unsigned int val, unsigned int nop_gpuaddr)
300{
301 unsigned int *start = cmds;
302
303 *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5);
304 /* MEM SPACE = memory, FUNCTION = equals */
305 *cmds++ = 0x13;
306 *cmds++ = addr;
307 *cmds++ = val;
308 *cmds++ = 0xFFFFFFFF;
309 *cmds++ = 0xFFFFFFFF;
310 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
311 return cmds - start;
312}
313
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700314#endif /*__ADRENO_H */