blob: 4ce56a46bcde111a91e9d64181fe93dd4b67e3ce [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
27/* Flags to control command packet settings */
Jordan Crousee0ea7622012-01-24 09:32:04 -070028#define KGSL_CMD_FLAGS_NONE 0x00000000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029#define KGSL_CMD_FLAGS_PMODE 0x00000001
30#define KGSL_CMD_FLAGS_NO_TS_CMP 0x00000002
31#define KGSL_CMD_FLAGS_NOT_KERNEL_CMD 0x00000004
32
33/* Command identifiers */
Shubhraprakash Dasd23ff4b2012-04-05 16:55:54 -060034#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
35#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
36#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
37#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#ifdef CONFIG_MSM_SCM
40#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz)
Lynus Vaz31754cb2012-02-22 18:07:02 +053041#elif defined CONFIG_MSM_SLEEP_STATS_DEVICE
42#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070043#else
44#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
45#endif
46
Jordan Crousec6b3a992012-02-04 10:23:51 -070047#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070048
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049enum adreno_gpurev {
50 ADRENO_REV_UNKNOWN = 0,
51 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053052 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053 ADRENO_REV_A205 = 205,
54 ADRENO_REV_A220 = 220,
55 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053056 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070057 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058};
59
Jordan Crousea78c9172011-07-11 13:14:09 -060060struct adreno_gpudev;
61
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062struct adreno_device {
63 struct kgsl_device dev; /* Must be first field in this struct */
64 unsigned int chip_id;
65 enum adreno_gpurev gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -060066 unsigned long gmem_base;
67 unsigned int gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060069 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070 unsigned int *pfp_fw;
71 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060072 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073 unsigned int *pm4_fw;
74 size_t pm4_fw_size;
75 struct adreno_ringbuffer ringbuffer;
76 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060077 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053078 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070079 unsigned int istore_size;
80 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070081 unsigned int instruction_size;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -060082 unsigned int ib_check_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070083};
84
Jordan Crousea78c9172011-07-11 13:14:09 -060085struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070086 /*
87 * These registers are in a different location on A3XX, so define
88 * them in the structure and use them as variables.
89 */
90 unsigned int reg_rbbm_status;
91 unsigned int reg_cp_pfp_ucode_data;
92 unsigned int reg_cp_pfp_ucode_addr;
93
94 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070095 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060096 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
97 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
98 irqreturn_t (*irq_handler)(struct adreno_device *);
99 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700100 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700101 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
102 void (*start)(struct adreno_device *);
103 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600104};
105
106extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700107extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600108
Jordan Crousef7597bf2012-01-03 08:43:34 -0700109/* A2XX register sets defined in adreno_a2xx.c */
110extern const unsigned int a200_registers[];
111extern const unsigned int a220_registers[];
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700112extern const unsigned int a225_registers[];
Jordan Crousef7597bf2012-01-03 08:43:34 -0700113extern const unsigned int a200_registers_count;
114extern const unsigned int a220_registers_count;
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700115extern const unsigned int a225_registers_count;
Jordan Crousef7597bf2012-01-03 08:43:34 -0700116
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700117/* A3XX register set defined in adreno_a3xx.c */
118extern const unsigned int a3xx_registers[];
119extern const unsigned int a3xx_registers_count;
120
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121int adreno_idle(struct kgsl_device *device, unsigned int timeout);
122void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
123 unsigned int *value);
124void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
125 unsigned int value);
126
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600127struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700128 unsigned int pt_base,
129 unsigned int gpuaddr,
130 unsigned int size);
131
132uint8_t *adreno_convertaddr(struct kgsl_device *device,
133 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134
Jordan Crouse233b2092012-04-18 09:31:09 -0600135struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
136 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
137
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700138void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
139 int hang);
140
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141static inline int adreno_is_a200(struct adreno_device *adreno_dev)
142{
143 return (adreno_dev->gpurev == ADRENO_REV_A200);
144}
145
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530146static inline int adreno_is_a203(struct adreno_device *adreno_dev)
147{
148 return (adreno_dev->gpurev == ADRENO_REV_A203);
149}
150
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151static inline int adreno_is_a205(struct adreno_device *adreno_dev)
152{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530153 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154}
155
156static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
157{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530158 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159}
160
161static inline int adreno_is_a220(struct adreno_device *adreno_dev)
162{
163 return (adreno_dev->gpurev == ADRENO_REV_A220);
164}
165
166static inline int adreno_is_a225(struct adreno_device *adreno_dev)
167{
168 return (adreno_dev->gpurev == ADRENO_REV_A225);
169}
170
171static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
172{
173 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
174 adreno_dev->gpurev == ADRENO_REV_A225);
175}
176
Jordan Crouse196c45b2011-07-28 08:37:57 -0600177static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
178{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700179 return (adreno_dev->gpurev <= 299);
180}
181
182static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
183{
184 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600185}
186
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600187static inline int adreno_is_a305(struct adreno_device *adreno_dev)
188{
189 return (adreno_dev->gpurev == ADRENO_REV_A305);
190}
191
192static inline int adreno_is_a320(struct adreno_device *adreno_dev)
193{
194 return (adreno_dev->gpurev == ADRENO_REV_A320);
195}
196
Jordan Crousee6b77622012-04-05 16:55:54 -0600197static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
198{
199 return (cmd[0] == cp_nop_packet(1) &&
200 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
201}
202
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700203/**
204 * adreno_encode_istore_size - encode istore size in CP format
205 * @adreno_dev - The 3D device.
206 *
207 * Encode the istore size into the format expected that the
208 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
209 * bits 31:29 - istore size as encoded by this function
210 * bits 27:16 - vertex shader start offset in instructions
211 * bits 11:0 - pixel shader start offset in instructions.
212 */
213static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
214{
215 unsigned int size;
216 /* in a225 the CP microcode multiplies the encoded
217 * value by 3 while decoding.
218 */
219 if (adreno_is_a225(adreno_dev))
220 size = adreno_dev->istore_size/3;
221 else
222 size = adreno_dev->istore_size;
223
224 return (ilog2(size) - 5) << 29;
225}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600226
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600227static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds,
228 unsigned int nop_gpuaddr)
229{
230 /* Adding an indirect buffer ensures that the prefetch stalls until
231 * the commands in indirect buffer have completed. We need to stall
232 * prefetch with a nop indirect buffer when updating pagetables
233 * because it provides stabler synchronization */
234 *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD;
235 *cmds++ = nop_gpuaddr;
236 *cmds++ = 2;
237 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
238 *cmds++ = 0x00000000;
239 return 5;
240}
241
242static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds,
243 unsigned int new_phys_limit,
244 unsigned int nop_gpuaddr)
245{
246 unsigned int *start = cmds;
247
248 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
249 *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1);
250 *cmds++ = new_phys_limit;
251 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
252 return cmds - start;
253}
254
255static inline int adreno_add_bank_change_cmds(unsigned int *cmds,
256 int cur_ctx_bank,
257 unsigned int nop_gpuaddr)
258{
259 unsigned int *start = cmds;
260
261 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
262 *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1);
263 *cmds++ = (cur_ctx_bank ? 0 : 0x20);
264 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
265 return cmds - start;
266}
267
268/*
269 * adreno_read_cmds - Add pm4 packets to perform read
270 * @device - Pointer to device structure
271 * @cmds - Pointer to memory where read commands need to be added
272 * @addr - gpu address of the read
273 * @val - The GPU will wait until the data at address addr becomes
274 * equal to value
275 */
276static inline int adreno_add_read_cmds(struct kgsl_device *device,
277 unsigned int *cmds, unsigned int addr,
278 unsigned int val, unsigned int nop_gpuaddr)
279{
280 unsigned int *start = cmds;
281
282 *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5);
283 /* MEM SPACE = memory, FUNCTION = equals */
284 *cmds++ = 0x13;
285 *cmds++ = addr;
286 *cmds++ = val;
287 *cmds++ = 0xFFFFFFFF;
288 *cmds++ = 0xFFFFFFFF;
289 cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr);
290 return cmds - start;
291}
292
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293#endif /*__ADRENO_H */