blob: f0f3b6b066b0ca7c41ba13b23f111dc21dd12cb6 [file] [log] [blame]
Jordan Crouse72bb70b2013-05-28 17:03:52 -06001/* Copyright (c) 2002,2007-2013, The Linux Foundation. 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
Tarun Karra5bea9c62013-01-27 17:39:17 -080016#include <linux/sched.h>
17
Jordan Crousea78c9172011-07-11 13:14:09 -060018#include "adreno_pm4types.h"
Jeremy Gebbeneebc4612011-08-31 10:15:21 -070019#include "a2xx_reg.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070020
21/* Flags */
22
23#define CTXT_FLAGS_NOT_IN_USE 0x00000000
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070024#define CTXT_FLAGS_IN_USE BIT(0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025
26/* state shadow memory allocated */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070027#define CTXT_FLAGS_STATE_SHADOW BIT(1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028
29/* gmem shadow memory allocated */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070030#define CTXT_FLAGS_GMEM_SHADOW BIT(2)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031/* gmem must be copied to shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070032#define CTXT_FLAGS_GMEM_SAVE BIT(3)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033/* gmem can be restored from shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070034#define CTXT_FLAGS_GMEM_RESTORE BIT(4)
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070035/* preamble packed in cmdbuffer for context switching */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070036#define CTXT_FLAGS_PREAMBLE BIT(5)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037/* shader must be copied to shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070038#define CTXT_FLAGS_SHADER_SAVE BIT(6)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039/* shader can be restored from shadow */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070040#define CTXT_FLAGS_SHADER_RESTORE BIT(7)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041/* Context has caused a GPU hang */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070042#define CTXT_FLAGS_GPU_HANG BIT(8)
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -070043/* Specifies there is no need to save GMEM */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070044#define CTXT_FLAGS_NOGMEMALLOC BIT(9)
Carter Cooper7e7f02e2012-02-15 09:36:31 -070045/* Trash state for context */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070046#define CTXT_FLAGS_TRASHSTATE BIT(10)
Carter Cooper7e7f02e2012-02-15 09:36:31 -070047/* per context timestamps enabled */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070048#define CTXT_FLAGS_PER_CONTEXT_TS BIT(11)
Tarun Karrad20d71a2013-01-25 15:38:57 -080049/* Context has caused a GPU hang and fault tolerance successful */
50#define CTXT_FLAGS_GPU_HANG_FT BIT(12)
Shubhraprakash Dasfc2c9042012-08-15 04:11:55 -070051/* Context is being destroyed so dont save it */
Shubhraprakash Dasc9ec2662012-11-20 11:10:41 -070052#define CTXT_FLAGS_BEING_DESTROYED BIT(13)
Vijay Krishnamoorthye80c3462012-08-27 14:07:32 -070053/* User mode generated timestamps enabled */
54#define CTXT_FLAGS_USER_GENERATED_TS BIT(14)
Tarun Karradeeecc02013-01-21 23:42:17 -080055/* Context skip till EOF */
56#define CTXT_FLAGS_SKIP_EOF BIT(15)
Tarun Karra83297222013-02-05 19:45:49 -080057/* Context no fault tolerance */
58#define CTXT_FLAGS_NO_FAULT_TOLERANCE BIT(16)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059
Jordan Crouse72bb70b2013-05-28 17:03:52 -060060/* Symbolic table for the adreno draw context type */
61#define ADRENO_DRAWCTXT_TYPES \
62 { KGSL_CONTEXT_TYPE_ANY, "any" }, \
63 { KGSL_CONTEXT_TYPE_GL, "GL" }, \
64 { KGSL_CONTEXT_TYPE_CL, "CL" }, \
65 { KGSL_CONTEXT_TYPE_C2D, "C2D" }, \
66 { KGSL_CONTEXT_TYPE_RS, "RS" }
67
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068struct kgsl_device;
69struct adreno_device;
70struct kgsl_device_private;
71struct kgsl_context;
72
73/* draw context */
74struct gmem_shadow_t {
75 struct kgsl_memdesc gmemshadow; /* Shadow buffer address */
76
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070077 /*
78 * 256 KB GMEM surface = 4 bytes-per-pixel x 256 pixels/row x
79 * 256 rows. Width & height must be multiples of 32 in case tiled
80 * textures are used
81 */
82
83 enum COLORFORMATX format; /* Unused on A3XX */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 unsigned int size; /* Size of surface used to store GMEM */
85 unsigned int width; /* Width of surface used to store GMEM */
86 unsigned int height; /* Height of surface used to store GMEM */
87 unsigned int pitch; /* Pitch of surface used to store GMEM */
88 unsigned int gmem_pitch; /* Pitch value used for GMEM */
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070089 unsigned int *gmem_save_commands; /* Unused on A3XX */
90 unsigned int *gmem_restore_commands; /* Unused on A3XX */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091 unsigned int gmem_save[3];
92 unsigned int gmem_restore[3];
93 struct kgsl_memdesc quad_vertices;
94 struct kgsl_memdesc quad_texcoords;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070095 struct kgsl_memdesc quad_vertices_restore;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096};
97
98struct adreno_context {
Tarun Karra5bea9c62013-01-27 17:39:17 -080099 pid_t pid;
100 char pid_name[TASK_COMM_LEN];
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700101 unsigned int id;
Tarun Karra696f89e2013-01-27 21:31:40 -0800102 unsigned int ib_gpu_time_used;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103 uint32_t flags;
Tarun Karra24e3dfa2013-02-25 21:58:05 -0800104 uint32_t pagefault;
105 unsigned long pagefault_ts;
Jordan Crouse72bb70b2013-05-28 17:03:52 -0600106 unsigned int type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107 struct kgsl_pagetable *pagetable;
108 struct kgsl_memdesc gpustate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109 unsigned int reg_restore[3];
110 unsigned int shader_save[3];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700111 unsigned int shader_restore[3];
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700112
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700113 /* Information of the GMEM shadow that is created in context create */
114 struct gmem_shadow_t context_gmem_shadow;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700115
116 /* A2XX specific items */
117 unsigned int reg_save[3];
118 unsigned int shader_fixup[3];
119 unsigned int chicken_restore[3];
120 unsigned int bin_base_offset;
121
122 /* A3XX specific items */
123 unsigned int regconstant_save[3];
124 unsigned int constant_restore[3];
125 unsigned int hlsqcontrol_restore[3];
126 unsigned int save_fixup[3];
127 unsigned int restore_fixup[3];
128 struct kgsl_memdesc shader_load_commands[2];
129 struct kgsl_memdesc shader_save_commands[4];
130 struct kgsl_memdesc constant_save_commands[3];
131 struct kgsl_memdesc constant_load_commands[3];
132 struct kgsl_memdesc cond_execs[4];
133 struct kgsl_memdesc hlsqcontrol_restore_commands[1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134};
135
136int adreno_drawctxt_create(struct kgsl_device *device,
137 struct kgsl_pagetable *pagetable,
138 struct kgsl_context *context,
Jordan Crouse72bb70b2013-05-28 17:03:52 -0600139 uint32_t *flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140
141void adreno_drawctxt_destroy(struct kgsl_device *device,
142 struct kgsl_context *context);
143
144void adreno_drawctxt_switch(struct adreno_device *adreno_dev,
145 struct adreno_context *drawctxt,
146 unsigned int flags);
147void adreno_drawctxt_set_bin_base_offset(struct kgsl_device *device,
Vijay Krishnamoorthybef66932012-01-24 09:32:05 -0700148 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149 unsigned int offset);
150
Jordan Crousea78c9172011-07-11 13:14:09 -0600151/* GPU context switch helper functions */
152
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600153void build_quad_vtxbuff(struct adreno_context *drawctxt,
154 struct gmem_shadow_t *shadow, unsigned int **incmd);
155
Jordan Crousea78c9172011-07-11 13:14:09 -0600156unsigned int uint2float(unsigned int);
157
158static inline unsigned int virt2gpu(unsigned int *cmd,
159 struct kgsl_memdesc *memdesc)
160{
161 return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr);
162}
163
164static inline void create_ib1(struct adreno_context *drawctxt,
165 unsigned int *cmd,
166 unsigned int *start,
167 unsigned int *end)
168{
Jordan Crouse084427d2011-07-28 08:37:58 -0600169 cmd[0] = CP_HDR_INDIRECT_BUFFER_PFD;
Jordan Crousea78c9172011-07-11 13:14:09 -0600170 cmd[1] = virt2gpu(start, &drawctxt->gpustate);
171 cmd[2] = end - start;
172}
173
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600174
175static inline unsigned int *reg_range(unsigned int *cmd, unsigned int start,
176 unsigned int end)
177{
178 *cmd++ = CP_REG(start); /* h/w regs, start addr */
179 *cmd++ = end - start + 1; /* count */
180 return cmd;
181}
182
183static inline void calc_gmemsize(struct gmem_shadow_t *shadow, int gmem_size)
184{
185 int w = 64, h = 64;
186
187 shadow->format = COLORX_8_8_8_8;
188
189 /* convert from bytes to 32-bit words */
190 gmem_size = (gmem_size + 3) / 4;
191
192 while ((w * h) < gmem_size) {
193 if (w < h)
194 w *= 2;
195 else
196 h *= 2;
197 }
198
199 shadow->pitch = shadow->width = w;
200 shadow->height = h;
201 shadow->gmem_pitch = shadow->pitch;
202 shadow->size = shadow->pitch * shadow->height * 4;
203}
204
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205#endif /* __ADRENO_DRAWCTXT_H */