blob: 717805f9ede44abcdf389c99ddd8d68561d3d14f [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
100unsigned int uint2float(unsigned int);
101
102static inline unsigned int virt2gpu(unsigned int *cmd,
103 struct kgsl_memdesc *memdesc)
104{
105 return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr);
106}
107
108static inline void create_ib1(struct adreno_context *drawctxt,
109 unsigned int *cmd,
110 unsigned int *start,
111 unsigned int *end)
112{
113 cmd[0] = PM4_HDR_INDIRECT_BUFFER_PFD;
114 cmd[1] = virt2gpu(start, &drawctxt->gpustate);
115 cmd[2] = end - start;
116}
117
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118#endif /* __ADRENO_DRAWCTXT_H */