blob: b923049eda80bb3cabdca0fb51c55ce2ae98e0fc [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"
liu zhong7dfa2a32012-04-27 19:11:01 -070020#include <mach/ocmem.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021
22#define DEVICE_3D_NAME "kgsl-3d"
23#define DEVICE_3D0_NAME "kgsl-3d0"
24
25#define ADRENO_DEVICE(device) \
26 KGSL_CONTAINER_OF(device, struct adreno_device, dev)
27
Jordan Crouse4815e9f2012-07-09 15:36:37 -060028#define ADRENO_CHIPID_CORE(_id) (((_id) >> 24) & 0xFF)
29#define ADRENO_CHIPID_MAJOR(_id) (((_id) >> 16) & 0xFF)
30#define ADRENO_CHIPID_MINOR(_id) (((_id) >> 8) & 0xFF)
31#define ADRENO_CHIPID_PATCH(_id) ((_id) & 0xFF)
32
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033/* Flags to control command packet settings */
Jordan Crousee0ea7622012-01-24 09:32:04 -070034#define KGSL_CMD_FLAGS_NONE 0x00000000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#define KGSL_CMD_FLAGS_PMODE 0x00000001
Carter Cooper7ffaba62012-05-24 13:59:53 -060036#define KGSL_CMD_FLAGS_DUMMY_INTR_CMD 0x00000002
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
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -060052void adreno_debugfs_init(struct kgsl_device *device);
53
Jordan Crousec6b3a992012-02-04 10:23:51 -070054#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070055
Shubhraprakash Das4624b552012-06-01 14:08:03 -060056#define ADRENO_NUM_CTX_SWITCH_ALLOWED_BEFORE_DRAW 50
57
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058enum adreno_gpurev {
59 ADRENO_REV_UNKNOWN = 0,
60 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053061 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062 ADRENO_REV_A205 = 205,
63 ADRENO_REV_A220 = 220,
64 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053065 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070066 ADRENO_REV_A320 = 320,
liu zhongfd42e622012-05-01 19:18:30 -070067 ADRENO_REV_A330 = 330,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068};
69
Jordan Crousea78c9172011-07-11 13:14:09 -060070struct adreno_gpudev;
71
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072struct adreno_device {
73 struct kgsl_device dev; /* Must be first field in this struct */
74 unsigned int chip_id;
75 enum adreno_gpurev gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -060076 unsigned long gmem_base;
77 unsigned int gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060079 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080 unsigned int *pfp_fw;
81 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060082 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070083 unsigned int *pm4_fw;
84 size_t pm4_fw_size;
85 struct adreno_ringbuffer ringbuffer;
86 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060087 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053088 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070089 unsigned int istore_size;
90 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070091 unsigned int instruction_size;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -060092 unsigned int ib_check_level;
Tarun Karra3335f142012-06-19 14:11:48 -070093 unsigned int fast_hang_detect;
liu zhong7dfa2a32012-04-27 19:11:01 -070094 struct ocmem_buf *ocmem_hdl;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095};
96
Jordan Crousea78c9172011-07-11 13:14:09 -060097struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070098 /*
99 * These registers are in a different location on A3XX, so define
100 * them in the structure and use them as variables.
101 */
102 unsigned int reg_rbbm_status;
103 unsigned int reg_cp_pfp_ucode_data;
104 unsigned int reg_cp_pfp_ucode_addr;
Shubhraprakash Das4624b552012-06-01 14:08:03 -0600105 /* keeps track of when we need to execute the draw workaround code */
106 int ctx_switches_since_last_draw;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700107
108 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700109 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600110 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
111 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600112 void (*ctxt_draw_workaround)(struct adreno_device *,
113 struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600114 irqreturn_t (*irq_handler)(struct adreno_device *);
115 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700116 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700117 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
118 void (*start)(struct adreno_device *);
119 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600120};
121
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600122/*
123 * struct adreno_recovery_data - Structure that contains all information to
124 * perform gpu recovery from hangs
125 * @ib1 - IB1 that the GPU was executing when hang happened
126 * @context_id - Context which caused the hang
127 * @global_eop - eoptimestamp at time of hang
128 * @rb_buffer - Buffer that holds the commands from good contexts
129 * @rb_size - Number of valid dwords in rb_buffer
130 * @bad_rb_buffer - Buffer that holds commands from the hanging context
131 * bad_rb_size - Number of valid dwords in bad_rb_buffer
132 * @last_valid_ctx_id - The last context from which commands were placed in
133 * ringbuffer before the GPU hung
134 */
135struct adreno_recovery_data {
136 unsigned int ib1;
137 unsigned int context_id;
138 unsigned int global_eop;
139 unsigned int *rb_buffer;
140 unsigned int rb_size;
141 unsigned int *bad_rb_buffer;
142 unsigned int bad_rb_size;
143 unsigned int last_valid_ctx_id;
144};
145
Jordan Crousea78c9172011-07-11 13:14:09 -0600146extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700147extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600148
Jordan Crousef7597bf2012-01-03 08:43:34 -0700149/* A2XX register sets defined in adreno_a2xx.c */
150extern const unsigned int a200_registers[];
151extern const unsigned int a220_registers[];
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700152extern const unsigned int a225_registers[];
Jordan Crousef7597bf2012-01-03 08:43:34 -0700153extern const unsigned int a200_registers_count;
154extern const unsigned int a220_registers_count;
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700155extern const unsigned int a225_registers_count;
Jordan Crousef7597bf2012-01-03 08:43:34 -0700156
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700157/* A3XX register set defined in adreno_a3xx.c */
158extern const unsigned int a3xx_registers[];
159extern const unsigned int a3xx_registers_count;
160
Tarun Karra3335f142012-06-19 14:11:48 -0700161extern unsigned int hang_detect_regs[];
162extern const unsigned int hang_detect_regs_count;
163
164
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165int adreno_idle(struct kgsl_device *device, unsigned int timeout);
166void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
167 unsigned int *value);
168void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
169 unsigned int value);
170
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600171int adreno_dump(struct kgsl_device *device, int manual);
172
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600173struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700174 unsigned int pt_base,
175 unsigned int gpuaddr,
176 unsigned int size);
177
178uint8_t *adreno_convertaddr(struct kgsl_device *device,
179 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180
Jordan Crouse233b2092012-04-18 09:31:09 -0600181struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
182 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
183
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700184void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
185 int hang);
186
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600187int adreno_dump_and_recover(struct kgsl_device *device);
188
Tarun Karra3335f142012-06-19 14:11:48 -0700189unsigned int adreno_hang_detect(struct kgsl_device *device,
190 unsigned int *prev_reg_val);
191
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192static inline int adreno_is_a200(struct adreno_device *adreno_dev)
193{
194 return (adreno_dev->gpurev == ADRENO_REV_A200);
195}
196
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530197static inline int adreno_is_a203(struct adreno_device *adreno_dev)
198{
199 return (adreno_dev->gpurev == ADRENO_REV_A203);
200}
201
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202static inline int adreno_is_a205(struct adreno_device *adreno_dev)
203{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530204 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205}
206
207static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
208{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530209 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700210}
211
212static inline int adreno_is_a220(struct adreno_device *adreno_dev)
213{
214 return (adreno_dev->gpurev == ADRENO_REV_A220);
215}
216
217static inline int adreno_is_a225(struct adreno_device *adreno_dev)
218{
219 return (adreno_dev->gpurev == ADRENO_REV_A225);
220}
221
222static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
223{
224 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
225 adreno_dev->gpurev == ADRENO_REV_A225);
226}
227
Jordan Crouse196c45b2011-07-28 08:37:57 -0600228static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
229{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700230 return (adreno_dev->gpurev <= 299);
231}
232
233static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
234{
235 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600236}
237
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600238static inline int adreno_is_a305(struct adreno_device *adreno_dev)
239{
240 return (adreno_dev->gpurev == ADRENO_REV_A305);
241}
242
243static inline int adreno_is_a320(struct adreno_device *adreno_dev)
244{
245 return (adreno_dev->gpurev == ADRENO_REV_A320);
246}
247
Jordan Crousee6b77622012-04-05 16:55:54 -0600248static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
249{
250 return (cmd[0] == cp_nop_packet(1) &&
251 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
252}
253
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700254/**
255 * adreno_encode_istore_size - encode istore size in CP format
256 * @adreno_dev - The 3D device.
257 *
258 * Encode the istore size into the format expected that the
259 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
260 * bits 31:29 - istore size as encoded by this function
261 * bits 27:16 - vertex shader start offset in instructions
262 * bits 11:0 - pixel shader start offset in instructions.
263 */
264static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
265{
266 unsigned int size;
267 /* in a225 the CP microcode multiplies the encoded
268 * value by 3 while decoding.
269 */
270 if (adreno_is_a225(adreno_dev))
271 size = adreno_dev->istore_size/3;
272 else
273 size = adreno_dev->istore_size;
274
275 return (ilog2(size) - 5) << 29;
276}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600277
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600278static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds,
279 unsigned int nop_gpuaddr)
280{
281 /* Adding an indirect buffer ensures that the prefetch stalls until
282 * the commands in indirect buffer have completed. We need to stall
283 * prefetch with a nop indirect buffer when updating pagetables
284 * because it provides stabler synchronization */
285 *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD;
286 *cmds++ = nop_gpuaddr;
287 *cmds++ = 2;
288 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
289 *cmds++ = 0x00000000;
290 return 5;
291}
292
293static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds,
294 unsigned int new_phys_limit,
295 unsigned int nop_gpuaddr)
296{
297 unsigned int *start = cmds;
298
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600299 *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1);
300 *cmds++ = new_phys_limit;
301 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
302 return cmds - start;
303}
304
305static inline int adreno_add_bank_change_cmds(unsigned int *cmds,
306 int cur_ctx_bank,
307 unsigned int nop_gpuaddr)
308{
309 unsigned int *start = cmds;
310
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600311 *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1);
312 *cmds++ = (cur_ctx_bank ? 0 : 0x20);
313 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
314 return cmds - start;
315}
316
317/*
318 * adreno_read_cmds - Add pm4 packets to perform read
319 * @device - Pointer to device structure
320 * @cmds - Pointer to memory where read commands need to be added
321 * @addr - gpu address of the read
322 * @val - The GPU will wait until the data at address addr becomes
323 * equal to value
324 */
325static inline int adreno_add_read_cmds(struct kgsl_device *device,
326 unsigned int *cmds, unsigned int addr,
327 unsigned int val, unsigned int nop_gpuaddr)
328{
329 unsigned int *start = cmds;
330
331 *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5);
332 /* MEM SPACE = memory, FUNCTION = equals */
333 *cmds++ = 0x13;
334 *cmds++ = addr;
335 *cmds++ = val;
336 *cmds++ = 0xFFFFFFFF;
337 *cmds++ = 0xFFFFFFFF;
338 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
339 return cmds - start;
340}
341
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700342#endif /*__ADRENO_H */