blob: b4a5292a9f65ea8d3787548ef524f188661b7958 [file] [log] [blame]
Duy Truonge833aca2013-02-12 13:35:08 -08001/* Copyright (c) 2008-2012, The Linux Foundation. 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
Vijay Krishnamoorthye80c3462012-08-27 14:07:32 -070036#define KGSL_CMD_FLAGS_INTERNAL_ISSUE 0x00000002
Tarun Karradeeecc02013-01-21 23:42:17 -080037#define KGSL_CMD_FLAGS_EOF 0x00000100
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39/* Command identifiers */
Shubhraprakash Dasd23ff4b2012-04-05 16:55:54 -060040#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
41#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
Carter Cooper728bd152013-05-28 17:00:06 -060042#define KGSL_CMD_INTERNAL_IDENTIFIER 0x2EEDD00D
Shubhraprakash Dasd23ff4b2012-04-05 16:55:54 -060043#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
44#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
Tarun Karradeeecc02013-01-21 23:42:17 -080045#define KGSL_END_OF_FRAME_IDENTIFIER 0x2E0F2E0F
46#define KGSL_NOP_IB_IDENTIFIER 0x20F20F20
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047
48#ifdef CONFIG_MSM_SCM
49#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz)
Lynus Vaz31754cb2012-02-22 18:07:02 +053050#elif defined CONFIG_MSM_SLEEP_STATS_DEVICE
51#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052#else
53#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
54#endif
55
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -060056void adreno_debugfs_init(struct kgsl_device *device);
57
Jordan Crousec6b3a992012-02-04 10:23:51 -070058#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070059
Shubhraprakash Das4624b552012-06-01 14:08:03 -060060#define ADRENO_NUM_CTX_SWITCH_ALLOWED_BEFORE_DRAW 50
61
Jordan Crousea29a2e02012-08-14 09:09:23 -060062/* One cannot wait forever for the core to idle, so set an upper limit to the
63 * amount of time to wait for the core to go idle
64 */
65
66#define ADRENO_IDLE_TIMEOUT (20 * 1000)
67
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068enum adreno_gpurev {
69 ADRENO_REV_UNKNOWN = 0,
70 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053071 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072 ADRENO_REV_A205 = 205,
73 ADRENO_REV_A220 = 220,
74 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053075 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070076 ADRENO_REV_A320 = 320,
liu zhongfd42e622012-05-01 19:18:30 -070077 ADRENO_REV_A330 = 330,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078};
79
Jordan Crousea78c9172011-07-11 13:14:09 -060080struct adreno_gpudev;
81
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082struct adreno_device {
83 struct kgsl_device dev; /* Must be first field in this struct */
84 unsigned int chip_id;
85 enum adreno_gpurev gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -060086 unsigned long gmem_base;
87 unsigned int gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060089 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090 unsigned int *pfp_fw;
91 size_t pfp_fw_size;
Tarun Karra9c070822012-11-27 16:43:51 -070092 unsigned int pfp_fw_version;
Jordan Crouse505df9c2011-07-28 08:37:59 -060093 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094 unsigned int *pm4_fw;
95 size_t pm4_fw_size;
Tarun Karra9c070822012-11-27 16:43:51 -070096 unsigned int pm4_fw_version;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097 struct adreno_ringbuffer ringbuffer;
98 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060099 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +0530100 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700101 unsigned int istore_size;
102 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -0700103 unsigned int instruction_size;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -0600104 unsigned int ib_check_level;
Tarun Karra3335f142012-06-19 14:11:48 -0700105 unsigned int fast_hang_detect;
Tarun Karradeeecc02013-01-21 23:42:17 -0800106 unsigned int ft_policy;
Tarun Karra987e2f72013-02-14 12:12:22 -0800107 unsigned int ft_user_control;
Tarun Karra696f89e2013-01-27 21:31:40 -0800108 unsigned int long_ib_detect;
109 unsigned int long_ib;
110 unsigned int long_ib_ts;
Tarun Karra99678f82013-02-13 13:57:25 -0800111 unsigned int ft_pf_policy;
Tarun Karra9c070822012-11-27 16:43:51 -0700112 unsigned int gpulist_index;
liu zhong7dfa2a32012-04-27 19:11:01 -0700113 struct ocmem_buf *ocmem_hdl;
liu zhong5af32d92012-08-29 14:36:36 -0600114 unsigned int ocmem_base;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700115};
116
Jordan Crousea78c9172011-07-11 13:14:09 -0600117struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700118 /*
119 * These registers are in a different location on A3XX, so define
120 * them in the structure and use them as variables.
121 */
122 unsigned int reg_rbbm_status;
123 unsigned int reg_cp_pfp_ucode_data;
124 unsigned int reg_cp_pfp_ucode_addr;
Shubhraprakash Das4624b552012-06-01 14:08:03 -0600125 /* keeps track of when we need to execute the draw workaround code */
126 int ctx_switches_since_last_draw;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700127
128 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700129 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600130 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
131 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600132 void (*ctxt_draw_workaround)(struct adreno_device *,
133 struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600134 irqreturn_t (*irq_handler)(struct adreno_device *);
135 void (*irq_control)(struct adreno_device *, int);
Jordan Crouseab601992013-03-05 11:18:20 -0700136 unsigned int (*irq_pending)(struct adreno_device *);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700137 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700138 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
139 void (*start)(struct adreno_device *);
140 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600141};
142
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600143/*
Tarun Karrad20d71a2013-01-25 15:38:57 -0800144 * struct adreno_ft_data - Structure that contains all information to
145 * perform gpu fault tolerance
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600146 * @ib1 - IB1 that the GPU was executing when hang happened
147 * @context_id - Context which caused the hang
148 * @global_eop - eoptimestamp at time of hang
149 * @rb_buffer - Buffer that holds the commands from good contexts
150 * @rb_size - Number of valid dwords in rb_buffer
151 * @bad_rb_buffer - Buffer that holds commands from the hanging context
152 * bad_rb_size - Number of valid dwords in bad_rb_buffer
Tarun Karradeeecc02013-01-21 23:42:17 -0800153 * @good_rb_buffer - Buffer that holds commands from good contexts
154 * good_rb_size - Number of valid dwords in good_rb_buffer
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600155 * @last_valid_ctx_id - The last context from which commands were placed in
156 * ringbuffer before the GPU hung
Tarun Karrad20d71a2013-01-25 15:38:57 -0800157 * @step - Current fault tolerance step being executed
158 * @err_code - Fault tolerance error code
Shubhraprakash Das2747cf62012-09-27 23:05:43 -0700159 * @fault - Indicates whether the hang was caused due to a pagefault
Shubhraprakash Das460cc762013-01-16 16:57:46 -0800160 * @start_of_replay_cmds - Offset in ringbuffer from where commands can be
Tarun Karrad20d71a2013-01-25 15:38:57 -0800161 * replayed during fault tolerance
Shubhraprakash Das460cc762013-01-16 16:57:46 -0800162 * @replay_for_snapshot - Offset in ringbuffer where IB's can be saved for
163 * replaying with snapshot
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600164 */
Tarun Karrad20d71a2013-01-25 15:38:57 -0800165struct adreno_ft_data {
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600166 unsigned int ib1;
167 unsigned int context_id;
168 unsigned int global_eop;
169 unsigned int *rb_buffer;
170 unsigned int rb_size;
171 unsigned int *bad_rb_buffer;
172 unsigned int bad_rb_size;
Tarun Karradeeecc02013-01-21 23:42:17 -0800173 unsigned int *good_rb_buffer;
174 unsigned int good_rb_size;
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600175 unsigned int last_valid_ctx_id;
Tarun Karra3164fb02013-02-05 15:38:51 -0800176 unsigned int status;
177 unsigned int ft_policy;
178 unsigned int err_code;
Shubhraprakash Das460cc762013-01-16 16:57:46 -0800179 unsigned int start_of_replay_cmds;
180 unsigned int replay_for_snapshot;
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600181};
182
Tarun Karra59e79542013-04-10 10:25:25 -0700183/* Fault Tolerance policy flags */
184#define KGSL_FT_DISABLE BIT(0)
185#define KGSL_FT_REPLAY BIT(1)
186#define KGSL_FT_SKIPIB BIT(2)
187#define KGSL_FT_SKIPFRAME BIT(3)
188#define KGSL_FT_TEMP_DISABLE BIT(4)
189#define KGSL_FT_DEFAULT_POLICY (KGSL_FT_REPLAY + KGSL_FT_SKIPIB)
190
191/* Pagefault policy flags */
192#define KGSL_FT_PAGEFAULT_INT_ENABLE 0x00000001
193#define KGSL_FT_PAGEFAULT_GPUHALT_ENABLE 0x00000002
194#define KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE 0x00000004
195#define KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT 0x00000008
196#define KGSL_FT_PAGEFAULT_DEFAULT_POLICY (KGSL_FT_PAGEFAULT_INT_ENABLE + \
197 KGSL_FT_PAGEFAULT_GPUHALT_ENABLE)
198
Jordan Crousea78c9172011-07-11 13:14:09 -0600199extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700200extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600201
Jordan Crousef7597bf2012-01-03 08:43:34 -0700202/* A2XX register sets defined in adreno_a2xx.c */
203extern const unsigned int a200_registers[];
204extern const unsigned int a220_registers[];
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700205extern const unsigned int a225_registers[];
Jordan Crousef7597bf2012-01-03 08:43:34 -0700206extern const unsigned int a200_registers_count;
207extern const unsigned int a220_registers_count;
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700208extern const unsigned int a225_registers_count;
Jordan Crousef7597bf2012-01-03 08:43:34 -0700209
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700210/* A3XX register set defined in adreno_a3xx.c */
211extern const unsigned int a3xx_registers[];
212extern const unsigned int a3xx_registers_count;
213
Carter Cooperf294e892012-11-26 10:45:53 -0700214extern const unsigned int a3xx_hlsq_registers[];
215extern const unsigned int a3xx_hlsq_registers_count;
216
Jordan Crouse99839252012-08-14 14:33:42 -0600217extern const unsigned int a330_registers[];
218extern const unsigned int a330_registers_count;
219
Tarun Karra696f89e2013-01-27 21:31:40 -0800220extern unsigned int ft_detect_regs[];
221extern const unsigned int ft_detect_regs_count;
Tarun Karra3335f142012-06-19 14:11:48 -0700222
223
Jordan Crousea29a2e02012-08-14 09:09:23 -0600224int adreno_idle(struct kgsl_device *device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
226 unsigned int *value);
227void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
228 unsigned int value);
229
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600230int adreno_dump(struct kgsl_device *device, int manual);
231
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600232struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700233 unsigned int pt_base,
234 unsigned int gpuaddr,
235 unsigned int size);
236
237uint8_t *adreno_convertaddr(struct kgsl_device *device,
238 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239
Jordan Crouse233b2092012-04-18 09:31:09 -0600240struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
241 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
242
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700243void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
244 int hang);
245
Tarun Karrad20d71a2013-01-25 15:38:57 -0800246int adreno_dump_and_exec_ft(struct kgsl_device *device);
247
248void adreno_dump_rb(struct kgsl_device *device, const void *buf,
249 size_t len, int start, int size);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600250
Tarun Karra696f89e2013-01-27 21:31:40 -0800251unsigned int adreno_ft_detect(struct kgsl_device *device,
Tarun Karra3335f142012-06-19 14:11:48 -0700252 unsigned int *prev_reg_val);
253
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254static inline int adreno_is_a200(struct adreno_device *adreno_dev)
255{
256 return (adreno_dev->gpurev == ADRENO_REV_A200);
257}
258
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530259static inline int adreno_is_a203(struct adreno_device *adreno_dev)
260{
261 return (adreno_dev->gpurev == ADRENO_REV_A203);
262}
263
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264static inline int adreno_is_a205(struct adreno_device *adreno_dev)
265{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530266 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700267}
268
269static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
270{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530271 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272}
273
274static inline int adreno_is_a220(struct adreno_device *adreno_dev)
275{
276 return (adreno_dev->gpurev == ADRENO_REV_A220);
277}
278
279static inline int adreno_is_a225(struct adreno_device *adreno_dev)
280{
281 return (adreno_dev->gpurev == ADRENO_REV_A225);
282}
283
284static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
285{
286 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
287 adreno_dev->gpurev == ADRENO_REV_A225);
288}
289
Jordan Crouse196c45b2011-07-28 08:37:57 -0600290static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
291{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700292 return (adreno_dev->gpurev <= 299);
293}
294
295static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
296{
297 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600298}
299
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600300static inline int adreno_is_a305(struct adreno_device *adreno_dev)
301{
302 return (adreno_dev->gpurev == ADRENO_REV_A305);
303}
304
305static inline int adreno_is_a320(struct adreno_device *adreno_dev)
306{
307 return (adreno_dev->gpurev == ADRENO_REV_A320);
308}
309
Jordan Crousec0978202012-08-29 14:35:51 -0600310static inline int adreno_is_a330(struct adreno_device *adreno_dev)
311{
312 return (adreno_dev->gpurev == ADRENO_REV_A330);
313}
314
Jordan Crousee6b77622012-04-05 16:55:54 -0600315static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
316{
317 return (cmd[0] == cp_nop_packet(1) &&
318 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
319}
320
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700321/**
322 * adreno_encode_istore_size - encode istore size in CP format
323 * @adreno_dev - The 3D device.
324 *
325 * Encode the istore size into the format expected that the
326 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
327 * bits 31:29 - istore size as encoded by this function
328 * bits 27:16 - vertex shader start offset in instructions
329 * bits 11:0 - pixel shader start offset in instructions.
330 */
331static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
332{
333 unsigned int size;
334 /* in a225 the CP microcode multiplies the encoded
335 * value by 3 while decoding.
336 */
337 if (adreno_is_a225(adreno_dev))
338 size = adreno_dev->istore_size/3;
339 else
340 size = adreno_dev->istore_size;
341
342 return (ilog2(size) - 5) << 29;
343}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600344
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600345static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds,
346 unsigned int nop_gpuaddr)
347{
348 /* Adding an indirect buffer ensures that the prefetch stalls until
349 * the commands in indirect buffer have completed. We need to stall
350 * prefetch with a nop indirect buffer when updating pagetables
351 * because it provides stabler synchronization */
352 *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD;
353 *cmds++ = nop_gpuaddr;
354 *cmds++ = 2;
355 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
356 *cmds++ = 0x00000000;
357 return 5;
358}
359
360static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds,
361 unsigned int new_phys_limit,
362 unsigned int nop_gpuaddr)
363{
364 unsigned int *start = cmds;
365
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600366 *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1);
367 *cmds++ = new_phys_limit;
368 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
369 return cmds - start;
370}
371
372static inline int adreno_add_bank_change_cmds(unsigned int *cmds,
373 int cur_ctx_bank,
374 unsigned int nop_gpuaddr)
375{
376 unsigned int *start = cmds;
377
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600378 *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1);
379 *cmds++ = (cur_ctx_bank ? 0 : 0x20);
380 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
381 return cmds - start;
382}
383
384/*
385 * adreno_read_cmds - Add pm4 packets to perform read
386 * @device - Pointer to device structure
387 * @cmds - Pointer to memory where read commands need to be added
388 * @addr - gpu address of the read
389 * @val - The GPU will wait until the data at address addr becomes
390 * equal to value
391 */
392static inline int adreno_add_read_cmds(struct kgsl_device *device,
393 unsigned int *cmds, unsigned int addr,
394 unsigned int val, unsigned int nop_gpuaddr)
395{
396 unsigned int *start = cmds;
397
398 *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5);
399 /* MEM SPACE = memory, FUNCTION = equals */
400 *cmds++ = 0x13;
401 *cmds++ = addr;
402 *cmds++ = val;
403 *cmds++ = 0xFFFFFFFF;
404 *cmds++ = 0xFFFFFFFF;
405 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
406 return cmds - start;
407}
408
Tarun Karra9c070822012-11-27 16:43:51 -0700409/*
410 * adreno_idle_cmds - Add pm4 packets for GPU idle
411 * @adreno_dev - Pointer to device structure
412 * @cmds - Pointer to memory where idle commands need to be added
413 */
414static inline int adreno_add_idle_cmds(struct adreno_device *adreno_dev,
415 unsigned int *cmds)
416{
417 unsigned int *start = cmds;
418
419 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
420 *cmds++ = 0x00000000;
421
422 if ((adreno_dev->gpurev == ADRENO_REV_A305) ||
423 (adreno_dev->gpurev == ADRENO_REV_A320)) {
424 *cmds++ = cp_type3_packet(CP_WAIT_FOR_ME, 1);
425 *cmds++ = 0x00000000;
426 }
427
428 return cmds - start;
429}
430
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700431#endif /*__ADRENO_H */