blob: 74f36c31c975d47303c9d86e1e485df3b8697ed4 [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,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070051 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052};
53
Jordan Crousea78c9172011-07-11 13:14:09 -060054struct adreno_gpudev;
55
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056struct adreno_device {
57 struct kgsl_device dev; /* Must be first field in this struct */
58 unsigned int chip_id;
59 enum adreno_gpurev gpurev;
60 struct kgsl_memregion gmemspace;
61 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060062 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070063 unsigned int *pfp_fw;
64 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060065 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 unsigned int *pm4_fw;
67 size_t pm4_fw_size;
68 struct adreno_ringbuffer ringbuffer;
69 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060070 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053071 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070072 unsigned int istore_size;
73 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070074 unsigned int instruction_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075};
76
Jordan Crousea78c9172011-07-11 13:14:09 -060077struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070078 /*
79 * These registers are in a different location on A3XX, so define
80 * them in the structure and use them as variables.
81 */
82 unsigned int reg_rbbm_status;
83 unsigned int reg_cp_pfp_ucode_data;
84 unsigned int reg_cp_pfp_ucode_addr;
85
86 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070087 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060088 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
89 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
90 irqreturn_t (*irq_handler)(struct adreno_device *);
91 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -070092 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070093 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
94 void (*start)(struct adreno_device *);
95 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -060096};
97
98extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070099extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600100
Jordan Crousef7597bf2012-01-03 08:43:34 -0700101/* A2XX register sets defined in adreno_a2xx.c */
102extern const unsigned int a200_registers[];
103extern const unsigned int a220_registers[];
104extern const unsigned int a200_registers_count;
105extern const unsigned int a220_registers_count;
106
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700107/* A3XX register set defined in adreno_a3xx.c */
108extern const unsigned int a3xx_registers[];
109extern const unsigned int a3xx_registers_count;
110
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700111int adreno_idle(struct kgsl_device *device, unsigned int timeout);
112void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
113 unsigned int *value);
114void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
115 unsigned int value);
116
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700117const struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
118 unsigned int pt_base,
119 unsigned int gpuaddr,
120 unsigned int size);
121
122uint8_t *adreno_convertaddr(struct kgsl_device *device,
123 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700124
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700125void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
126 int hang);
127
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128static inline int adreno_is_a200(struct adreno_device *adreno_dev)
129{
130 return (adreno_dev->gpurev == ADRENO_REV_A200);
131}
132
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530133static inline int adreno_is_a203(struct adreno_device *adreno_dev)
134{
135 return (adreno_dev->gpurev == ADRENO_REV_A203);
136}
137
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138static inline int adreno_is_a205(struct adreno_device *adreno_dev)
139{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530140 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141}
142
143static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
144{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530145 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146}
147
148static inline int adreno_is_a220(struct adreno_device *adreno_dev)
149{
150 return (adreno_dev->gpurev == ADRENO_REV_A220);
151}
152
153static inline int adreno_is_a225(struct adreno_device *adreno_dev)
154{
155 return (adreno_dev->gpurev == ADRENO_REV_A225);
156}
157
158static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
159{
160 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
161 adreno_dev->gpurev == ADRENO_REV_A225);
162}
163
Jordan Crouse196c45b2011-07-28 08:37:57 -0600164static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
165{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700166 return (adreno_dev->gpurev <= 299);
167}
168
169static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
170{
171 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600172}
173
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700174/**
175 * adreno_encode_istore_size - encode istore size in CP format
176 * @adreno_dev - The 3D device.
177 *
178 * Encode the istore size into the format expected that the
179 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
180 * bits 31:29 - istore size as encoded by this function
181 * bits 27:16 - vertex shader start offset in instructions
182 * bits 11:0 - pixel shader start offset in instructions.
183 */
184static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
185{
186 unsigned int size;
187 /* in a225 the CP microcode multiplies the encoded
188 * value by 3 while decoding.
189 */
190 if (adreno_is_a225(adreno_dev))
191 size = adreno_dev->istore_size/3;
192 else
193 size = adreno_dev->istore_size;
194
195 return (ilog2(size) - 5) << 29;
196}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600197
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198#endif /*__ADRENO_H */