blob: e08088d158faf97b8e059a5fc42e02685c5f5fbf [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)
Lynus Vaz31754cb2012-02-22 18:07:02 +053038#elif defined CONFIG_MSM_SLEEP_STATS_DEVICE
39#define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040#else
41#define ADRENO_DEFAULT_PWRSCALE_POLICY NULL
42#endif
43
Jordan Crousec6b3a992012-02-04 10:23:51 -070044#define ADRENO_ISTORE_START 0x5000 /* Istore offset */
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070045
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046enum adreno_gpurev {
47 ADRENO_REV_UNKNOWN = 0,
48 ADRENO_REV_A200 = 200,
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +053049 ADRENO_REV_A203 = 203,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050 ADRENO_REV_A205 = 205,
51 ADRENO_REV_A220 = 220,
52 ADRENO_REV_A225 = 225,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +053053 ADRENO_REV_A305 = 305,
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070054 ADRENO_REV_A320 = 320,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055};
56
Jordan Crousea78c9172011-07-11 13:14:09 -060057struct adreno_gpudev;
58
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059struct adreno_device {
60 struct kgsl_device dev; /* Must be first field in this struct */
61 unsigned int chip_id;
62 enum adreno_gpurev gpurev;
63 struct kgsl_memregion gmemspace;
64 struct adreno_context *drawctxt_active;
Jordan Crouse505df9c2011-07-28 08:37:59 -060065 const char *pfp_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 unsigned int *pfp_fw;
67 size_t pfp_fw_size;
Jordan Crouse505df9c2011-07-28 08:37:59 -060068 const char *pm4_fwfile;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069 unsigned int *pm4_fw;
70 size_t pm4_fw_size;
71 struct adreno_ringbuffer ringbuffer;
72 unsigned int mharb;
Jordan Crousea78c9172011-07-11 13:14:09 -060073 struct adreno_gpudev *gpudev;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +053074 unsigned int wait_timeout;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -070075 unsigned int istore_size;
76 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -070077 unsigned int instruction_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078};
79
Jordan Crousea78c9172011-07-11 13:14:09 -060080struct adreno_gpudev {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070081 /*
82 * These registers are in a different location on A3XX, so define
83 * them in the structure and use them as variables.
84 */
85 unsigned int reg_rbbm_status;
86 unsigned int reg_cp_pfp_ucode_data;
87 unsigned int reg_cp_pfp_ucode_addr;
88
89 /* GPU specific function hooks */
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070090 int (*ctxt_create)(struct adreno_device *, struct adreno_context *);
Jordan Crousea78c9172011-07-11 13:14:09 -060091 void (*ctxt_save)(struct adreno_device *, struct adreno_context *);
92 void (*ctxt_restore)(struct adreno_device *, struct adreno_context *);
93 irqreturn_t (*irq_handler)(struct adreno_device *);
94 void (*irq_control)(struct adreno_device *, int);
Jordan Crouse156cfbc2012-01-24 09:32:04 -070095 void * (*snapshot)(struct adreno_device *, void *, int *, int);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070096 void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *);
97 void (*start)(struct adreno_device *);
98 unsigned int (*busy_cycles)(struct adreno_device *);
Jordan Crousea78c9172011-07-11 13:14:09 -060099};
100
101extern struct adreno_gpudev adreno_a2xx_gpudev;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700102extern struct adreno_gpudev adreno_a3xx_gpudev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600103
Jordan Crousef7597bf2012-01-03 08:43:34 -0700104/* A2XX register sets defined in adreno_a2xx.c */
105extern const unsigned int a200_registers[];
106extern const unsigned int a220_registers[];
107extern const unsigned int a200_registers_count;
108extern const unsigned int a220_registers_count;
109
Jordan Crouse0c2761a2012-02-01 22:11:12 -0700110/* A3XX register set defined in adreno_a3xx.c */
111extern const unsigned int a3xx_registers[];
112extern const unsigned int a3xx_registers_count;
113
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114int adreno_idle(struct kgsl_device *device, unsigned int timeout);
115void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
116 unsigned int *value);
117void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
118 unsigned int value);
119
Jeremy Gebben16e80fa2011-11-30 15:56:29 -0700120const struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
121 unsigned int pt_base,
122 unsigned int gpuaddr,
123 unsigned int size);
124
125uint8_t *adreno_convertaddr(struct kgsl_device *device,
126 unsigned int pt_base, unsigned int gpuaddr, unsigned int size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700128void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain,
129 int hang);
130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131static inline int adreno_is_a200(struct adreno_device *adreno_dev)
132{
133 return (adreno_dev->gpurev == ADRENO_REV_A200);
134}
135
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530136static inline int adreno_is_a203(struct adreno_device *adreno_dev)
137{
138 return (adreno_dev->gpurev == ADRENO_REV_A203);
139}
140
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141static inline int adreno_is_a205(struct adreno_device *adreno_dev)
142{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530143 return (adreno_dev->gpurev == ADRENO_REV_A205);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144}
145
146static inline int adreno_is_a20x(struct adreno_device *adreno_dev)
147{
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530148 return (adreno_dev->gpurev <= 209);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149}
150
151static inline int adreno_is_a220(struct adreno_device *adreno_dev)
152{
153 return (adreno_dev->gpurev == ADRENO_REV_A220);
154}
155
156static inline int adreno_is_a225(struct adreno_device *adreno_dev)
157{
158 return (adreno_dev->gpurev == ADRENO_REV_A225);
159}
160
161static inline int adreno_is_a22x(struct adreno_device *adreno_dev)
162{
163 return (adreno_dev->gpurev == ADRENO_REV_A220 ||
164 adreno_dev->gpurev == ADRENO_REV_A225);
165}
166
Jordan Crouse196c45b2011-07-28 08:37:57 -0600167static inline int adreno_is_a2xx(struct adreno_device *adreno_dev)
168{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700169 return (adreno_dev->gpurev <= 299);
170}
171
172static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
173{
174 return (adreno_dev->gpurev >= 300);
Jordan Crouse196c45b2011-07-28 08:37:57 -0600175}
176
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700177/**
178 * adreno_encode_istore_size - encode istore size in CP format
179 * @adreno_dev - The 3D device.
180 *
181 * Encode the istore size into the format expected that the
182 * CP_SET_SHADER_BASES and CP_ME_INIT commands:
183 * bits 31:29 - istore size as encoded by this function
184 * bits 27:16 - vertex shader start offset in instructions
185 * bits 11:0 - pixel shader start offset in instructions.
186 */
187static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev)
188{
189 unsigned int size;
190 /* in a225 the CP microcode multiplies the encoded
191 * value by 3 while decoding.
192 */
193 if (adreno_is_a225(adreno_dev))
194 size = adreno_dev->istore_size/3;
195 else
196 size = adreno_dev->istore_size;
197
198 return (ilog2(size) - 5) << 29;
199}
Jordan Crouse196c45b2011-07-28 08:37:57 -0600200
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201#endif /*__ADRENO_H */