blob: 5b14a69d8fdd5acb961640eaeba68315a903650a [file] [log] [blame]
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -07001/* Copyright (c) 2002,2007-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_DRAWCTXT_H
14#define __ADRENO_DRAWCTXT_H
15
Jordan Crousea78c9172011-07-11 13:14:09 -060016#include "adreno_pm4types.h"
Jeremy Gebbeneebc4612011-08-31 10:15:21 -070017#include "a2xx_reg.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018
19/* Flags */
20
21#define CTXT_FLAGS_NOT_IN_USE 0x00000000
22#define CTXT_FLAGS_IN_USE 0x00000001
23
24/* state shadow memory allocated */
25#define CTXT_FLAGS_STATE_SHADOW 0x00000010
26
27/* gmem shadow memory allocated */
28#define CTXT_FLAGS_GMEM_SHADOW 0x00000100
29/* gmem must be copied to shadow */
30#define CTXT_FLAGS_GMEM_SAVE 0x00000200
31/* gmem can be restored from shadow */
32#define CTXT_FLAGS_GMEM_RESTORE 0x00000400
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070033/* preamble packed in cmdbuffer for context switching */
34#define CTXT_FLAGS_PREAMBLE 0x00000800
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035/* shader must be copied to shadow */
36#define CTXT_FLAGS_SHADER_SAVE 0x00002000
37/* shader can be restored from shadow */
38#define CTXT_FLAGS_SHADER_RESTORE 0x00004000
39/* Context has caused a GPU hang */
40#define CTXT_FLAGS_GPU_HANG 0x00008000
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070041/* Specifies there is no need to save GMEM */
42#define CTXT_FLAGS_NOGMEMALLOC 0x00010000
Carter Cooper7e7f02e2012-02-15 09:36:31 -070043/* Trash state for context */
44#define CTXT_FLAGS_TRASHSTATE 0x00020000
45/* per context timestamps enabled */
46#define CTXT_FLAGS_PER_CONTEXT_TS 0x00040000
Shubhraprakash Das29ed38e2012-06-06 01:43:55 -060047/* Context has caused a GPU hang and recovered properly */
48#define CTXT_FLAGS_GPU_HANG_RECOVERED 0x00008000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049
50struct kgsl_device;
51struct adreno_device;
52struct kgsl_device_private;
53struct kgsl_context;
54
55/* draw context */
56struct gmem_shadow_t {
57 struct kgsl_memdesc gmemshadow; /* Shadow buffer address */
58
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070059 /*
60 * 256 KB GMEM surface = 4 bytes-per-pixel x 256 pixels/row x
61 * 256 rows. Width & height must be multiples of 32 in case tiled
62 * textures are used
63 */
64
65 enum COLORFORMATX format; /* Unused on A3XX */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 unsigned int size; /* Size of surface used to store GMEM */
67 unsigned int width; /* Width of surface used to store GMEM */
68 unsigned int height; /* Height of surface used to store GMEM */
69 unsigned int pitch; /* Pitch of surface used to store GMEM */
70 unsigned int gmem_pitch; /* Pitch value used for GMEM */
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070071 unsigned int *gmem_save_commands; /* Unused on A3XX */
72 unsigned int *gmem_restore_commands; /* Unused on A3XX */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073 unsigned int gmem_save[3];
74 unsigned int gmem_restore[3];
75 struct kgsl_memdesc quad_vertices;
76 struct kgsl_memdesc quad_texcoords;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070077 struct kgsl_memdesc quad_vertices_restore;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078};
79
80struct adreno_context {
Carter Cooper7e7f02e2012-02-15 09:36:31 -070081 unsigned int id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082 uint32_t flags;
83 struct kgsl_pagetable *pagetable;
84 struct kgsl_memdesc gpustate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085 unsigned int reg_restore[3];
86 unsigned int shader_save[3];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087 unsigned int shader_restore[3];
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070088
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089 /* Information of the GMEM shadow that is created in context create */
90 struct gmem_shadow_t context_gmem_shadow;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070091
92 /* A2XX specific items */
93 unsigned int reg_save[3];
94 unsigned int shader_fixup[3];
95 unsigned int chicken_restore[3];
96 unsigned int bin_base_offset;
97
98 /* A3XX specific items */
99 unsigned int regconstant_save[3];
100 unsigned int constant_restore[3];
101 unsigned int hlsqcontrol_restore[3];
102 unsigned int save_fixup[3];
103 unsigned int restore_fixup[3];
104 struct kgsl_memdesc shader_load_commands[2];
105 struct kgsl_memdesc shader_save_commands[4];
106 struct kgsl_memdesc constant_save_commands[3];
107 struct kgsl_memdesc constant_load_commands[3];
108 struct kgsl_memdesc cond_execs[4];
109 struct kgsl_memdesc hlsqcontrol_restore_commands[1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110};
111
112int adreno_drawctxt_create(struct kgsl_device *device,
113 struct kgsl_pagetable *pagetable,
114 struct kgsl_context *context,
115 uint32_t flags);
116
117void adreno_drawctxt_destroy(struct kgsl_device *device,
118 struct kgsl_context *context);
119
120void adreno_drawctxt_switch(struct adreno_device *adreno_dev,
121 struct adreno_context *drawctxt,
122 unsigned int flags);
123void adreno_drawctxt_set_bin_base_offset(struct kgsl_device *device,
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700124 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125 unsigned int offset);
126
Jordan Crousea78c9172011-07-11 13:14:09 -0600127/* GPU context switch helper functions */
128
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600129void build_quad_vtxbuff(struct adreno_context *drawctxt,
130 struct gmem_shadow_t *shadow, unsigned int **incmd);
131
Jordan Crousea78c9172011-07-11 13:14:09 -0600132unsigned int uint2float(unsigned int);
133
134static inline unsigned int virt2gpu(unsigned int *cmd,
135 struct kgsl_memdesc *memdesc)
136{
137 return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr);
138}
139
140static inline void create_ib1(struct adreno_context *drawctxt,
141 unsigned int *cmd,
142 unsigned int *start,
143 unsigned int *end)
144{
Jordan Crouse084427d2011-07-28 08:37:58 -0600145 cmd[0] = CP_HDR_INDIRECT_BUFFER_PFD;
Jordan Crousea78c9172011-07-11 13:14:09 -0600146 cmd[1] = virt2gpu(start, &drawctxt->gpustate);
147 cmd[2] = end - start;
148}
149
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600150
151static inline unsigned int *reg_range(unsigned int *cmd, unsigned int start,
152 unsigned int end)
153{
154 *cmd++ = CP_REG(start); /* h/w regs, start addr */
155 *cmd++ = end - start + 1; /* count */
156 return cmd;
157}
158
159static inline void calc_gmemsize(struct gmem_shadow_t *shadow, int gmem_size)
160{
161 int w = 64, h = 64;
162
163 shadow->format = COLORX_8_8_8_8;
164
165 /* convert from bytes to 32-bit words */
166 gmem_size = (gmem_size + 3) / 4;
167
168 while ((w * h) < gmem_size) {
169 if (w < h)
170 w *= 2;
171 else
172 h *= 2;
173 }
174
175 shadow->pitch = shadow->width = w;
176 shadow->height = h;
177 shadow->gmem_pitch = shadow->pitch;
178 shadow->size = shadow->pitch * shadow->height * 4;
179}
180
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181#endif /* __ADRENO_DRAWCTXT_H */