blob: a942f3025da705deff954ef306f05ecaeeb3a1bf [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2002,2007-2011, Code Aurora Forum. All rights reserved.
2 *
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"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017#include "a200_reg.h"
18#include "a220_reg.h"
19
20/* Flags */
21
22#define CTXT_FLAGS_NOT_IN_USE 0x00000000
23#define CTXT_FLAGS_IN_USE 0x00000001
24
25/* state shadow memory allocated */
26#define CTXT_FLAGS_STATE_SHADOW 0x00000010
27
28/* gmem shadow memory allocated */
29#define CTXT_FLAGS_GMEM_SHADOW 0x00000100
30/* gmem must be copied to shadow */
31#define CTXT_FLAGS_GMEM_SAVE 0x00000200
32/* gmem can be restored from shadow */
33#define CTXT_FLAGS_GMEM_RESTORE 0x00000400
34/* shader must be copied to shadow */
35#define CTXT_FLAGS_SHADER_SAVE 0x00002000
36/* shader can be restored from shadow */
37#define CTXT_FLAGS_SHADER_RESTORE 0x00004000
38/* Context has caused a GPU hang */
39#define CTXT_FLAGS_GPU_HANG 0x00008000
40
41struct kgsl_device;
42struct adreno_device;
43struct kgsl_device_private;
44struct kgsl_context;
45
46/* draw context */
47struct gmem_shadow_t {
48 struct kgsl_memdesc gmemshadow; /* Shadow buffer address */
49
50 /* 256 KB GMEM surface = 4 bytes-per-pixel x 256 pixels/row x
51 * 256 rows. */
52 /* width & height must be a multiples of 32, in case tiled textures
53 * are used. */
54 enum COLORFORMATX format;
55 unsigned int size; /* Size of surface used to store GMEM */
56 unsigned int width; /* Width of surface used to store GMEM */
57 unsigned int height; /* Height of surface used to store GMEM */
58 unsigned int pitch; /* Pitch of surface used to store GMEM */
59 unsigned int gmem_pitch; /* Pitch value used for GMEM */
60 unsigned int *gmem_save_commands;
61 unsigned int *gmem_restore_commands;
62 unsigned int gmem_save[3];
63 unsigned int gmem_restore[3];
64 struct kgsl_memdesc quad_vertices;
65 struct kgsl_memdesc quad_texcoords;
66};
67
68struct adreno_context {
69 uint32_t flags;
70 struct kgsl_pagetable *pagetable;
71 struct kgsl_memdesc gpustate;
72 unsigned int reg_save[3];
73 unsigned int reg_restore[3];
74 unsigned int shader_save[3];
75 unsigned int shader_fixup[3];
76 unsigned int shader_restore[3];
77 unsigned int chicken_restore[3];
78 unsigned int bin_base_offset;
79 /* Information of the GMEM shadow that is created in context create */
80 struct gmem_shadow_t context_gmem_shadow;
81};
82
83int adreno_drawctxt_create(struct kgsl_device *device,
84 struct kgsl_pagetable *pagetable,
85 struct kgsl_context *context,
86 uint32_t flags);
87
88void adreno_drawctxt_destroy(struct kgsl_device *device,
89 struct kgsl_context *context);
90
91void adreno_drawctxt_switch(struct adreno_device *adreno_dev,
92 struct adreno_context *drawctxt,
93 unsigned int flags);
94void adreno_drawctxt_set_bin_base_offset(struct kgsl_device *device,
95 struct kgsl_context *context,
96 unsigned int offset);
97
Jordan Crousea78c9172011-07-11 13:14:09 -060098/* GPU context switch helper functions */
99
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600100void build_quad_vtxbuff(struct adreno_context *drawctxt,
101 struct gmem_shadow_t *shadow, unsigned int **incmd);
102
Jordan Crousea78c9172011-07-11 13:14:09 -0600103unsigned int uint2float(unsigned int);
104
105static inline unsigned int virt2gpu(unsigned int *cmd,
106 struct kgsl_memdesc *memdesc)
107{
108 return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr);
109}
110
111static inline void create_ib1(struct adreno_context *drawctxt,
112 unsigned int *cmd,
113 unsigned int *start,
114 unsigned int *end)
115{
Jordan Crouse084427d2011-07-28 08:37:58 -0600116 cmd[0] = CP_HDR_INDIRECT_BUFFER_PFD;
Jordan Crousea78c9172011-07-11 13:14:09 -0600117 cmd[1] = virt2gpu(start, &drawctxt->gpustate);
118 cmd[2] = end - start;
119}
120
Jordan Crouse0e0486f2011-07-28 08:37:58 -0600121
122static inline unsigned int *reg_range(unsigned int *cmd, unsigned int start,
123 unsigned int end)
124{
125 *cmd++ = CP_REG(start); /* h/w regs, start addr */
126 *cmd++ = end - start + 1; /* count */
127 return cmd;
128}
129
130static inline void calc_gmemsize(struct gmem_shadow_t *shadow, int gmem_size)
131{
132 int w = 64, h = 64;
133
134 shadow->format = COLORX_8_8_8_8;
135
136 /* convert from bytes to 32-bit words */
137 gmem_size = (gmem_size + 3) / 4;
138
139 while ((w * h) < gmem_size) {
140 if (w < h)
141 w *= 2;
142 else
143 h *= 2;
144 }
145
146 shadow->pitch = shadow->width = w;
147 shadow->height = h;
148 shadow->gmem_pitch = shadow->pitch;
149 shadow->size = shadow->pitch * shadow->height * 4;
150}
151
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152#endif /* __ADRENO_DRAWCTXT_H */