blob: 58e4791e11ee84a7909b9f998863386162cab248 [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
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070022#define CTXT_FLAGS_IN_USE BIT(0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023
24/* state shadow memory allocated */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070025#define CTXT_FLAGS_STATE_SHADOW BIT(1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026
27/* gmem shadow memory allocated */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070028#define CTXT_FLAGS_GMEM_SHADOW BIT(2)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029/* gmem must be copied to shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070030#define CTXT_FLAGS_GMEM_SAVE BIT(3)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031/* gmem can be restored from shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070032#define CTXT_FLAGS_GMEM_RESTORE BIT(4)
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070033/* preamble packed in cmdbuffer for context switching */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070034#define CTXT_FLAGS_PREAMBLE BIT(5)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035/* shader must be copied to shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070036#define CTXT_FLAGS_SHADER_SAVE BIT(6)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037/* shader can be restored from shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070038#define CTXT_FLAGS_SHADER_RESTORE BIT(7)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039/* Context has caused a GPU hang */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070040#define CTXT_FLAGS_GPU_HANG BIT(8)
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070041/* Specifies there is no need to save GMEM */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070042#define CTXT_FLAGS_NOGMEMALLOC BIT(9)
Carter Cooper7e7f02e2012-02-15 09:36:31 -070043/* Trash state for context */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070044#define CTXT_FLAGS_TRASHSTATE BIT(10)
Carter Cooper7e7f02e2012-02-15 09:36:31 -070045/* per context timestamps enabled */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070046#define CTXT_FLAGS_PER_CONTEXT_TS BIT(11)
Shubhraprakash Das29ed38e2012-06-06 01:43:55 -060047/* Context has caused a GPU hang and recovered properly */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070048#define CTXT_FLAGS_GPU_HANG_RECOVERED BIT(12)
Shubhraprakash Dasfc2c9042012-08-15 04:11:55 -070049/* Context is being destroyed so dont save it */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070050#define CTXT_FLAGS_BEING_DESTROYED BIT(13)
Vijay Krishnamoorthye80c3462012-08-27 14:07:32 -070051/* User mode generated timestamps enabled */
52#define CTXT_FLAGS_USER_GENERATED_TS BIT(14)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053
54struct kgsl_device;
55struct adreno_device;
56struct kgsl_device_private;
57struct kgsl_context;
58
59/* draw context */
60struct gmem_shadow_t {
61 struct kgsl_memdesc gmemshadow; /* Shadow buffer address */
62
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070063 /*
64 * 256 KB GMEM surface = 4 bytes-per-pixel x 256 pixels/row x
65 * 256 rows. Width & height must be multiples of 32 in case tiled
66 * textures are used
67 */
68
69 enum COLORFORMATX format; /* Unused on A3XX */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070 unsigned int size; /* Size of surface used to store GMEM */
71 unsigned int width; /* Width of surface used to store GMEM */
72 unsigned int height; /* Height of surface used to store GMEM */
73 unsigned int pitch; /* Pitch of surface used to store GMEM */
74 unsigned int gmem_pitch; /* Pitch value used for GMEM */
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070075 unsigned int *gmem_save_commands; /* Unused on A3XX */
76 unsigned int *gmem_restore_commands; /* Unused on A3XX */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077 unsigned int gmem_save[3];
78 unsigned int gmem_restore[3];
79 struct kgsl_memdesc quad_vertices;
80 struct kgsl_memdesc quad_texcoords;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070081 struct kgsl_memdesc quad_vertices_restore;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082};
83
84struct adreno_context {
Carter Cooper7e7f02e2012-02-15 09:36:31 -070085 unsigned int id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086 uint32_t flags;
87 struct kgsl_pagetable *pagetable;
88 struct kgsl_memdesc gpustate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089 unsigned int reg_restore[3];
90 unsigned int shader_save[3];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091 unsigned int shader_restore[3];
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070092
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093 /* Information of the GMEM shadow that is created in context create */
94 struct gmem_shadow_t context_gmem_shadow;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070095
96 /* A2XX specific items */
97 unsigned int reg_save[3];
98 unsigned int shader_fixup[3];
99 unsigned int chicken_restore[3];
100 unsigned int bin_base_offset;
101
102 /* A3XX specific items */
103 unsigned int regconstant_save[3];
104 unsigned int constant_restore[3];
105 unsigned int hlsqcontrol_restore[3];
106 unsigned int save_fixup[3];
107 unsigned int restore_fixup[3];
108 struct kgsl_memdesc shader_load_commands[2];
109 struct kgsl_memdesc shader_save_commands[4];
110 struct kgsl_memdesc constant_save_commands[3];
111 struct kgsl_memdesc constant_load_commands[3];
112 struct kgsl_memdesc cond_execs[4];
113 struct kgsl_memdesc hlsqcontrol_restore_commands[1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114};
115
116int adreno_drawctxt_create(struct kgsl_device *device,
117 struct kgsl_pagetable *pagetable,
118 struct kgsl_context *context,
119 uint32_t flags);
120
121void adreno_drawctxt_destroy(struct kgsl_device *device,
122 struct kgsl_context *context);
123
124void adreno_drawctxt_switch(struct adreno_device *adreno_dev,
125 struct adreno_context *drawctxt,
126 unsigned int flags);
127void adreno_drawctxt_set_bin_base_offset(struct kgsl_device *device,
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700128 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129 unsigned int offset);
130
Jordan Crousea78c9172011-07-11 13:14:09 -0600131/* GPU context switch helper functions */
132
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600133void build_quad_vtxbuff(struct adreno_context *drawctxt,
134 struct gmem_shadow_t *shadow, unsigned int **incmd);
135
Jordan Crousea78c9172011-07-11 13:14:09 -0600136unsigned int uint2float(unsigned int);
137
138static inline unsigned int virt2gpu(unsigned int *cmd,
139 struct kgsl_memdesc *memdesc)
140{
141 return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr);
142}
143
144static inline void create_ib1(struct adreno_context *drawctxt,
145 unsigned int *cmd,
146 unsigned int *start,
147 unsigned int *end)
148{
Jordan Crouse084427d2011-07-28 08:37:58 -0600149 cmd[0] = CP_HDR_INDIRECT_BUFFER_PFD;
Jordan Crousea78c9172011-07-11 13:14:09 -0600150 cmd[1] = virt2gpu(start, &drawctxt->gpustate);
151 cmd[2] = end - start;
152}
153
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600154
155static inline unsigned int *reg_range(unsigned int *cmd, unsigned int start,
156 unsigned int end)
157{
158 *cmd++ = CP_REG(start); /* h/w regs, start addr */
159 *cmd++ = end - start + 1; /* count */
160 return cmd;
161}
162
163static inline void calc_gmemsize(struct gmem_shadow_t *shadow, int gmem_size)
164{
165 int w = 64, h = 64;
166
167 shadow->format = COLORX_8_8_8_8;
168
169 /* convert from bytes to 32-bit words */
170 gmem_size = (gmem_size + 3) / 4;
171
172 while ((w * h) < gmem_size) {
173 if (w < h)
174 w *= 2;
175 else
176 h *= 2;
177 }
178
179 shadow->pitch = shadow->width = w;
180 shadow->height = h;
181 shadow->gmem_pitch = shadow->pitch;
182 shadow->size = shadow->pitch * shadow->height * 4;
183}
184
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185#endif /* __ADRENO_DRAWCTXT_H */