blob: a7ea20c41e9767addcdc9417232cd929949351fc [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[];
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700111extern const unsigned int a225_registers[];
Jordan Crousef7597bf2012-01-03 08:43:34 -0700112extern const unsigned int a200_registers_count;
113extern const unsigned int a220_registers_count;
Jeremy Gebben6be78d12012-03-07 16:02:47 -0700114extern const unsigned int a225_registers_count;
Jordan Crousef7597bf2012-01-03 08:43:34 -0700115
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700116/* A3XX register set defined in adreno_a3xx.c */
117extern const unsigned int a3xx_registers[];
118extern const unsigned int a3xx_registers_count;
119
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120int adreno_idle(struct kgsl_device *device, unsigned int timeout);
121void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
122 unsigned int *value);
123void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
124 unsigned int value);
125
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600126struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700127 unsigned int pt_base,
128 unsigned int gpuaddr,
129 unsigned int size);
130
131uint8_t *adreno_convertaddr(struct kgsl_device *device,
132 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133
Jordan Crouse233b2092012-04-18 09:31:09 -0600134struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
135 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
136
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700137void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
138 int hang);
139
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140static inline int adreno_is_a200(struct adreno_device *adreno_dev)
141{
142 return (adreno_dev->gpurev == ADRENO_REV_A200);
143}
144
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530145static inline int adreno_is_a203(struct adreno_device *adreno_dev)
146{
147 return (adreno_dev->gpurev == ADRENO_REV_A203);
148}
149
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150static inline int adreno_is_a205(struct adreno_device *adreno_dev)
151{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530152 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700153}
154
155static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
156{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530157 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158}
159
160static inline int adreno_is_a220(struct adreno_device *adreno_dev)
161{
162 return (adreno_dev->gpurev == ADRENO_REV_A220);
163}
164
165static inline int adreno_is_a225(struct adreno_device *adreno_dev)
166{
167 return (adreno_dev->gpurev == ADRENO_REV_A225);
168}
169
170static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
171{
172 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
173 adreno_dev->gpurev == ADRENO_REV_A225);
174}
175
Jordan Crouse196c45b2011-07-28 08:37:57 -0600176static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
177{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700178 return (adreno_dev->gpurev <= 299);
179}
180
181static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
182{
183 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600184}
185
Kevin Matlage48d0e2e2012-04-26 10:52:36 -0600186static inline int adreno_is_a305(struct adreno_device *adreno_dev)
187{
188 return (adreno_dev->gpurev == ADRENO_REV_A305);
189}
190
191static inline int adreno_is_a320(struct adreno_device *adreno_dev)
192{
193 return (adreno_dev->gpurev == ADRENO_REV_A320);
194}
195
Jordan Crousee6b77622012-04-05 16:55:54 -0600196static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
197{
198 return (cmd[0] == cp_nop_packet(1) &&
199 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
200}
201
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700202/**
203 * adreno_encode_istore_size - encode istore size in CP format
204 * @adreno_dev - The 3D device.
205 *
206 * Encode the istore size into the format expected that the
207 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
208 * bits 31:29 - istore size as encoded by this function
209 * bits 27:16 - vertex shader start offset in instructions
210 * bits 11:0 - pixel shader start offset in instructions.
211 */
212static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
213{
214 unsigned int size;
215 /* in a225 the CP microcode multiplies the encoded
216 * value by 3 while decoding.
217 */
218 if (adreno_is_a225(adreno_dev))
219 size = adreno_dev->istore_size/3;
220 else
221 size = adreno_dev->istore_size;
222
223 return (ilog2(size) - 5) << 29;
224}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600225
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700226#endif /*__ADRENO_H */