blob: 488531269cda585de9f8b0b324ce4412f82d85c5 [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;
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -060080 unsigned int ib_check_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081};
82
Jordan Crousea78c9172011-07-11 13:14:09 -060083struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070084 /*
85 * These registers are in a different location on A3XX, so define
86 * them in the structure and use them as variables.
87 */
88 unsigned int reg_rbbm_status;
89 unsigned int reg_cp_pfp_ucode_data;
90 unsigned int reg_cp_pfp_ucode_addr;
91
92 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070093 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060094 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
95 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
96 irqreturn_t (*irq_handler)(struct adreno_device *);
97 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -070098 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070099 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
100 void (*start)(struct adreno_device *);
101 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -0600102};
103
104extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700105extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600106
Jordan Crousef7597bf2012-01-03 08:43:34 -0700107/* A2XX register sets defined in adreno_a2xx.c */
108extern const unsigned int a200_registers[];
109extern const unsigned int a220_registers[];
110extern const unsigned int a200_registers_count;
111extern const unsigned int a220_registers_count;
112
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700113/* A3XX register set defined in adreno_a3xx.c */
114extern const unsigned int a3xx_registers[];
115extern const unsigned int a3xx_registers_count;
116
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117int adreno_idle(struct kgsl_device *device, unsigned int timeout);
118void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
119 unsigned int *value);
120void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
121 unsigned int value);
122
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -0600123struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700124 unsigned int pt_base,
125 unsigned int gpuaddr,
126 unsigned int size);
127
128uint8_t *adreno_convertaddr(struct kgsl_device *device,
129 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700131void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
132 int hang);
133
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134static inline int adreno_is_a200(struct adreno_device *adreno_dev)
135{
136 return (adreno_dev->gpurev == ADRENO_REV_A200);
137}
138
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530139static inline int adreno_is_a203(struct adreno_device *adreno_dev)
140{
141 return (adreno_dev->gpurev == ADRENO_REV_A203);
142}
143
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144static inline int adreno_is_a205(struct adreno_device *adreno_dev)
145{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530146 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147}
148
149static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
150{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530151 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152}
153
154static inline int adreno_is_a220(struct adreno_device *adreno_dev)
155{
156 return (adreno_dev->gpurev == ADRENO_REV_A220);
157}
158
159static inline int adreno_is_a225(struct adreno_device *adreno_dev)
160{
161 return (adreno_dev->gpurev == ADRENO_REV_A225);
162}
163
164static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
165{
166 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
167 adreno_dev->gpurev == ADRENO_REV_A225);
168}
169
Jordan Crouse196c45b2011-07-28 08:37:57 -0600170static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
171{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700172 return (adreno_dev->gpurev <= 299);
173}
174
175static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
176{
177 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600178}
179
Jordan Crousee6b77622012-04-05 16:55:54 -0600180static inline int adreno_rb_ctxtswitch(unsigned int *cmd)
181{
182 return (cmd[0] == cp_nop_packet(1) &&
183 cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER);
184}
185
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700186/**
187 * adreno_encode_istore_size - encode istore size in CP format
188 * @adreno_dev - The 3D device.
189 *
190 * Encode the istore size into the format expected that the
191 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
192 * bits 31:29 - istore size as encoded by this function
193 * bits 27:16 - vertex shader start offset in instructions
194 * bits 11:0 - pixel shader start offset in instructions.
195 */
196static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
197{
198 unsigned int size;
199 /* in a225 the CP microcode multiplies the encoded
200 * value by 3 while decoding.
201 */
202 if (adreno_is_a225(adreno_dev))
203 size = adreno_dev->istore_size/3;
204 else
205 size = adreno_dev->istore_size;
206
207 return (ilog2(size) - 5) << 29;
208}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600209
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700210#endif /*__ADRENO_H */