blob: 07ccb85141551476f096d0e932f73913b661d0b9 [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;
65 struct kgsl_memregion gmemspace;
66 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060067 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068 unsigned int *pfp_fw;
69 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060070 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071 unsigned int *pm4_fw;
72 size_t pm4_fw_size;
73 struct adreno_ringbuffer ringbuffer;
74 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060075 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053076 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070077 unsigned int istore_size;
78 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070079 unsigned int instruction_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080};
81
Jordan Crousea78c9172011-07-11 13:14:09 -060082struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070083 /*
84 * These registers are in a different location on A3XX, so define
85 * them in the structure and use them as variables.
86 */
87 unsigned int reg_rbbm_status;
88 unsigned int reg_cp_pfp_ucode_data;
89 unsigned int reg_cp_pfp_ucode_addr;
90
91 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070092 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060093 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
94 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
95 irqreturn_t (*irq_handler)(struct adreno_device *);
96 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -070097 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070098 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
99 void (*start)(struct adreno_device *);
100 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600101};
102
103extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700104extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600105
Jordan Crousef7597bf2012-01-03 08:43:34 -0700106/* A2XX register sets defined in adreno_a2xx.c */
107extern const unsigned int a200_registers[];
108extern const unsigned int a220_registers[];
109extern const unsigned int a200_registers_count;
110extern const unsigned int a220_registers_count;
111
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700112/* A3XX register set defined in adreno_a3xx.c */
113extern const unsigned int a3xx_registers[];
114extern const unsigned int a3xx_registers_count;
115
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116int adreno_idle(struct kgsl_device *device, unsigned int timeout);
117void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
118 unsigned int *value);
119void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
120 unsigned int value);
121
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700122const struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
123 unsigned int pt_base,
124 unsigned int gpuaddr,
125 unsigned int size);
126
127uint8_t *adreno_convertaddr(struct kgsl_device *device,
128 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700130void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
131 int hang);
132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133static inline int adreno_is_a200(struct adreno_device *adreno_dev)
134{
135 return (adreno_dev->gpurev == ADRENO_REV_A200);
136}
137
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530138static inline int adreno_is_a203(struct adreno_device *adreno_dev)
139{
140 return (adreno_dev->gpurev == ADRENO_REV_A203);
141}
142
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143static inline int adreno_is_a205(struct adreno_device *adreno_dev)
144{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530145 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146}
147
148static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
149{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530150 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151}
152
153static inline int adreno_is_a220(struct adreno_device *adreno_dev)
154{
155 return (adreno_dev->gpurev == ADRENO_REV_A220);
156}
157
158static inline int adreno_is_a225(struct adreno_device *adreno_dev)
159{
160 return (adreno_dev->gpurev == ADRENO_REV_A225);
161}
162
163static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
164{
165 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
166 adreno_dev->gpurev == ADRENO_REV_A225);
167}
168
Jordan Crouse196c45b2011-07-28 08:37:57 -0600169static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
170{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700171 return (adreno_dev->gpurev <= 299);
172}
173
174static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
175{
176 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600177}
178
Jordan Crousee6b77622012-04-05 16:55:54 -0600179static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
180{
181 return (cmd[0] == cp_nop_packet(1) &&
182 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
183}
184
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700185/**
186 * adreno_encode_istore_size - encode istore size in CP format
187 * @adreno_dev - The 3D device.
188 *
189 * Encode the istore size into the format expected that the
190 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
191 * bits 31:29 - istore size as encoded by this function
192 * bits 27:16 - vertex shader start offset in instructions
193 * bits 11:0 - pixel shader start offset in instructions.
194 */
195static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
196{
197 unsigned int size;
198 /* in a225 the CP microcode multiplies the encoded
199 * value by 3 while decoding.
200 */
201 if (adreno_is_a225(adreno_dev))
202 size = adreno_dev->istore_size/3;
203 else
204 size = adreno_dev->istore_size;
205
206 return (ilog2(size) - 5) << 29;
207}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600208
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700209#endif /*__ADRENO_H */