blob: b7e0e5767dedae6b8ba2cfad5908542e181f2f17 [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 */
33#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0xDEADBEEF
34#define KGSL_CMD_IDENTIFIER 0xFEEDFACE
35
36#ifdef CONFIG_MSM_SCM
37#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz)
38#else
39#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
40#endif
41
Jordan Crousec6b3a992012-02-04 10:23:51 -070042#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070043
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044enum adreno_gpurev {
45 ADRENO_REV_UNKNOWN = 0,
46 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053047 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048 ADRENO_REV_A205 = 205,
49 ADRENO_REV_A220 = 220,
50 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053051 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070052 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053};
54
Jordan Crousea78c9172011-07-11 13:14:09 -060055struct adreno_gpudev;
56
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057struct adreno_device {
58 struct kgsl_device dev; /* Must be first field in this struct */
59 unsigned int chip_id;
60 enum adreno_gpurev gpurev;
61 struct kgsl_memregion gmemspace;
62 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060063 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064 unsigned int *pfp_fw;
65 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060066 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067 unsigned int *pm4_fw;
68 size_t pm4_fw_size;
69 struct adreno_ringbuffer ringbuffer;
70 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060071 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053072 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070073 unsigned int istore_size;
74 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070075 unsigned int instruction_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076};
77
Jordan Crousea78c9172011-07-11 13:14:09 -060078struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070079 /*
80 * These registers are in a different location on A3XX, so define
81 * them in the structure and use them as variables.
82 */
83 unsigned int reg_rbbm_status;
84 unsigned int reg_cp_pfp_ucode_data;
85 unsigned int reg_cp_pfp_ucode_addr;
86
87 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070088 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060089 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
90 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
91 irqreturn_t (*irq_handler)(struct adreno_device *);
92 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -070093 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070094 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
95 void (*start)(struct adreno_device *);
96 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -060097};
98
99extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700100extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600101
Jordan Crousef7597bf2012-01-03 08:43:34 -0700102/* A2XX register sets defined in adreno_a2xx.c */
103extern const unsigned int a200_registers[];
104extern const unsigned int a220_registers[];
105extern const unsigned int a200_registers_count;
106extern const unsigned int a220_registers_count;
107
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700108/* A3XX register set defined in adreno_a3xx.c */
109extern const unsigned int a3xx_registers[];
110extern const unsigned int a3xx_registers_count;
111
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700112int adreno_idle(struct kgsl_device *device, unsigned int timeout);
113void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
114 unsigned int *value);
115void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
116 unsigned int value);
117
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700118const struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
119 unsigned int pt_base,
120 unsigned int gpuaddr,
121 unsigned int size);
122
123uint8_t *adreno_convertaddr(struct kgsl_device *device,
124 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700126void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
127 int hang);
128
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129static inline int adreno_is_a200(struct adreno_device *adreno_dev)
130{
131 return (adreno_dev->gpurev == ADRENO_REV_A200);
132}
133
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530134static inline int adreno_is_a203(struct adreno_device *adreno_dev)
135{
136 return (adreno_dev->gpurev == ADRENO_REV_A203);
137}
138
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139static inline int adreno_is_a205(struct adreno_device *adreno_dev)
140{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530141 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142}
143
144static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
145{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530146 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147}
148
149static inline int adreno_is_a220(struct adreno_device *adreno_dev)
150{
151 return (adreno_dev->gpurev == ADRENO_REV_A220);
152}
153
154static inline int adreno_is_a225(struct adreno_device *adreno_dev)
155{
156 return (adreno_dev->gpurev == ADRENO_REV_A225);
157}
158
159static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
160{
161 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
162 adreno_dev->gpurev == ADRENO_REV_A225);
163}
164
Jordan Crouse196c45b2011-07-28 08:37:57 -0600165static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
166{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700167 return (adreno_dev->gpurev <= 299);
168}
169
170static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
171{
172 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600173}
174
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700175/**
176 * adreno_encode_istore_size - encode istore size in CP format
177 * @adreno_dev - The 3D device.
178 *
179 * Encode the istore size into the format expected that the
180 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
181 * bits 31:29 - istore size as encoded by this function
182 * bits 27:16 - vertex shader start offset in instructions
183 * bits 11:0 - pixel shader start offset in instructions.
184 */
185static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
186{
187 unsigned int size;
188 /* in a225 the CP microcode multiplies the encoded
189 * value by 3 while decoding.
190 */
191 if (adreno_is_a225(adreno_dev))
192 size = adreno_dev->istore_size/3;
193 else
194 size = adreno_dev->istore_size;
195
196 return (ilog2(size) - 5) << 29;
197}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600198
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700199#endif /*__ADRENO_H */