blob: 95378a159b9058b81ef9871571cd5f436f40d9ea [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"
19
20#define DEVICE_3D_NAME "kgsl-3d"
21#define DEVICE_3D0_NAME "kgsl-3d0"
22
23#define ADRENO_DEVICE(device) \
24 KGSL_CONTAINER_OF(device, struct adreno_device, dev)
25
26/* Flags to control command packet settings */
Jordan Crousee0ea7622012-01-24 09:32:04 -070027#define KGSL_CMD_FLAGS_NONE 0x00000000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#define KGSL_CMD_FLAGS_PMODE 0x00000001
29#define KGSL_CMD_FLAGS_NO_TS_CMP 0x00000002
30#define KGSL_CMD_FLAGS_NOT_KERNEL_CMD 0x00000004
31
32/* Command identifiers */
Shubhraprakash Dasd23ff4b2012-04-05 16:55:54 -060033#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
34#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
35#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
36#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38#ifdef CONFIG_MSM_SCM
39#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz)
Lynus Vaz31754cb2012-02-22 18:07:02 +053040#elif defined CONFIG_MSM_SLEEP_STATS_DEVICE
41#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042#else
43#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
44#endif
45
Jordan Crousec6b3a992012-02-04 10:23:51 -070046#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070047
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048enum adreno_gpurev {
49 ADRENO_REV_UNKNOWN = 0,
50 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053051 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052 ADRENO_REV_A205 = 205,
53 ADRENO_REV_A220 = 220,
54 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053055 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070056 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057};
58
Jordan Crousea78c9172011-07-11 13:14:09 -060059struct adreno_gpudev;
60
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061struct adreno_device {
62 struct kgsl_device dev; /* Must be first field in this struct */
63 unsigned int chip_id;
64 enum adreno_gpurev gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -060065 unsigned long gmem_base;
66 unsigned int gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060068 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069 unsigned int *pfp_fw;
70 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060071 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072 unsigned int *pm4_fw;
73 size_t pm4_fw_size;
74 struct adreno_ringbuffer ringbuffer;
75 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060076 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053077 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070078 unsigned int istore_size;
79 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070080 unsigned int instruction_size;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -060081 unsigned int ib_check_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082};
83
Jordan Crousea78c9172011-07-11 13:14:09 -060084struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070085 /*
86 * These registers are in a different location on A3XX, so define
87 * them in the structure and use them as variables.
88 */
89 unsigned int reg_rbbm_status;
90 unsigned int reg_cp_pfp_ucode_data;
91 unsigned int reg_cp_pfp_ucode_addr;
92
93 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070094 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060095 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
96 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
97 irqreturn_t (*irq_handler)(struct adreno_device *);
98 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -070099 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700100 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
101 void (*start)(struct adreno_device *);
102 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600103};
104
105extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700106extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600107
Jordan Crousef7597bf2012-01-03 08:43:34 -0700108/* A2XX register sets defined in adreno_a2xx.c */
109extern const unsigned int a200_registers[];
110extern const unsigned int a220_registers[];
111extern const unsigned int a200_registers_count;
112extern const unsigned int a220_registers_count;
113
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700114/* A3XX register set defined in adreno_a3xx.c */
115extern const unsigned int a3xx_registers[];
116extern const unsigned int a3xx_registers_count;
117
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118int adreno_idle(struct kgsl_device *device, unsigned int timeout);
119void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
120 unsigned int *value);
121void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
122 unsigned int value);
123
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600124struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700125 unsigned int pt_base,
126 unsigned int gpuaddr,
127 unsigned int size);
128
129uint8_t *adreno_convertaddr(struct kgsl_device *device,
130 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131
Jordan Crouse233b2092012-04-18 09:31:09 -0600132struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
133 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
134
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700135void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
136 int hang);
137
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138static inline int adreno_is_a200(struct adreno_device *adreno_dev)
139{
140 return (adreno_dev->gpurev == ADRENO_REV_A200);
141}
142
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530143static inline int adreno_is_a203(struct adreno_device *adreno_dev)
144{
145 return (adreno_dev->gpurev == ADRENO_REV_A203);
146}
147
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148static inline int adreno_is_a205(struct adreno_device *adreno_dev)
149{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530150 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151}
152
153static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
154{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530155 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700156}
157
158static inline int adreno_is_a220(struct adreno_device *adreno_dev)
159{
160 return (adreno_dev->gpurev == ADRENO_REV_A220);
161}
162
163static inline int adreno_is_a225(struct adreno_device *adreno_dev)
164{
165 return (adreno_dev->gpurev == ADRENO_REV_A225);
166}
167
168static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
169{
170 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
171 adreno_dev->gpurev == ADRENO_REV_A225);
172}
173
Jordan Crouse196c45b2011-07-28 08:37:57 -0600174static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
175{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700176 return (adreno_dev->gpurev <= 299);
177}
178
179static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
180{
181 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600182}
183
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600184static inline int adreno_is_a305(struct adreno_device *adreno_dev)
185{
186 return (adreno_dev->gpurev == ADRENO_REV_A305);
187}
188
189static inline int adreno_is_a320(struct adreno_device *adreno_dev)
190{
191 return (adreno_dev->gpurev == ADRENO_REV_A320);
192}
193
Jordan Crousee6b77622012-04-05 16:55:54 -0600194static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
195{
196 return (cmd[0] == cp_nop_packet(1) &&
197 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
198}
199
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700200/**
201 * adreno_encode_istore_size - encode istore size in CP format
202 * @adreno_dev - The 3D device.
203 *
204 * Encode the istore size into the format expected that the
205 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
206 * bits 31:29 - istore size as encoded by this function
207 * bits 27:16 - vertex shader start offset in instructions
208 * bits 11:0 - pixel shader start offset in instructions.
209 */
210static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
211{
212 unsigned int size;
213 /* in a225 the CP microcode multiplies the encoded
214 * value by 3 while decoding.
215 */
216 if (adreno_is_a225(adreno_dev))
217 size = adreno_dev->istore_size/3;
218 else
219 size = adreno_dev->istore_size;
220
221 return (ilog2(size) - 5) << 29;
222}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600223
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224#endif /*__ADRENO_H */