Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2002,2007-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 16 | #include "adreno_pm4types.h" |
Jeremy Gebben | eebc461 | 2011-08-31 10:15:21 -0700 | [diff] [blame] | 17 | #include "a2xx_reg.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | |
| 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 Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 33 | /* preamble packed in cmdbuffer for context switching */ |
| 34 | #define CTXT_FLAGS_PREAMBLE 0x00000800 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | /* 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 Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 41 | /* Specifies there is no need to save GMEM */ |
| 42 | #define CTXT_FLAGS_NOGMEMALLOC 0x00010000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | |
| 44 | struct kgsl_device; |
| 45 | struct adreno_device; |
| 46 | struct kgsl_device_private; |
| 47 | struct kgsl_context; |
| 48 | |
| 49 | /* draw context */ |
| 50 | struct gmem_shadow_t { |
| 51 | struct kgsl_memdesc gmemshadow; /* Shadow buffer address */ |
| 52 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame^] | 53 | /* |
| 54 | * 256 KB GMEM surface = 4 bytes-per-pixel x 256 pixels/row x |
| 55 | * 256 rows. Width & height must be multiples of 32 in case tiled |
| 56 | * textures are used |
| 57 | */ |
| 58 | |
| 59 | enum COLORFORMATX format; /* Unused on A3XX */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | unsigned int size; /* Size of surface used to store GMEM */ |
| 61 | unsigned int width; /* Width of surface used to store GMEM */ |
| 62 | unsigned int height; /* Height of surface used to store GMEM */ |
| 63 | unsigned int pitch; /* Pitch of surface used to store GMEM */ |
| 64 | unsigned int gmem_pitch; /* Pitch value used for GMEM */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame^] | 65 | unsigned int *gmem_save_commands; /* Unused on A3XX */ |
| 66 | unsigned int *gmem_restore_commands; /* Unused on A3XX */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 67 | unsigned int gmem_save[3]; |
| 68 | unsigned int gmem_restore[3]; |
| 69 | struct kgsl_memdesc quad_vertices; |
| 70 | struct kgsl_memdesc quad_texcoords; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame^] | 71 | struct kgsl_memdesc quad_vertices_restore; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct adreno_context { |
| 75 | uint32_t flags; |
| 76 | struct kgsl_pagetable *pagetable; |
| 77 | struct kgsl_memdesc gpustate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | unsigned int reg_restore[3]; |
| 79 | unsigned int shader_save[3]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | unsigned int shader_restore[3]; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame^] | 81 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | /* Information of the GMEM shadow that is created in context create */ |
| 83 | struct gmem_shadow_t context_gmem_shadow; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame^] | 84 | |
| 85 | /* A2XX specific items */ |
| 86 | unsigned int reg_save[3]; |
| 87 | unsigned int shader_fixup[3]; |
| 88 | unsigned int chicken_restore[3]; |
| 89 | unsigned int bin_base_offset; |
| 90 | |
| 91 | /* A3XX specific items */ |
| 92 | unsigned int regconstant_save[3]; |
| 93 | unsigned int constant_restore[3]; |
| 94 | unsigned int hlsqcontrol_restore[3]; |
| 95 | unsigned int save_fixup[3]; |
| 96 | unsigned int restore_fixup[3]; |
| 97 | struct kgsl_memdesc shader_load_commands[2]; |
| 98 | struct kgsl_memdesc shader_save_commands[4]; |
| 99 | struct kgsl_memdesc constant_save_commands[3]; |
| 100 | struct kgsl_memdesc constant_load_commands[3]; |
| 101 | struct kgsl_memdesc cond_execs[4]; |
| 102 | struct kgsl_memdesc hlsqcontrol_restore_commands[1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | int adreno_drawctxt_create(struct kgsl_device *device, |
| 106 | struct kgsl_pagetable *pagetable, |
| 107 | struct kgsl_context *context, |
| 108 | uint32_t flags); |
| 109 | |
| 110 | void adreno_drawctxt_destroy(struct kgsl_device *device, |
| 111 | struct kgsl_context *context); |
| 112 | |
| 113 | void adreno_drawctxt_switch(struct adreno_device *adreno_dev, |
| 114 | struct adreno_context *drawctxt, |
| 115 | unsigned int flags); |
| 116 | void adreno_drawctxt_set_bin_base_offset(struct kgsl_device *device, |
Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 117 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 118 | unsigned int offset); |
| 119 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 120 | /* GPU context switch helper functions */ |
| 121 | |
Jordan Crouse | 0e0486f | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 122 | void build_quad_vtxbuff(struct adreno_context *drawctxt, |
| 123 | struct gmem_shadow_t *shadow, unsigned int **incmd); |
| 124 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 125 | unsigned int uint2float(unsigned int); |
| 126 | |
| 127 | static inline unsigned int virt2gpu(unsigned int *cmd, |
| 128 | struct kgsl_memdesc *memdesc) |
| 129 | { |
| 130 | return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr); |
| 131 | } |
| 132 | |
| 133 | static inline void create_ib1(struct adreno_context *drawctxt, |
| 134 | unsigned int *cmd, |
| 135 | unsigned int *start, |
| 136 | unsigned int *end) |
| 137 | { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 138 | cmd[0] = CP_HDR_INDIRECT_BUFFER_PFD; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 139 | cmd[1] = virt2gpu(start, &drawctxt->gpustate); |
| 140 | cmd[2] = end - start; |
| 141 | } |
| 142 | |
Jordan Crouse | 0e0486f | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 143 | |
| 144 | static inline unsigned int *reg_range(unsigned int *cmd, unsigned int start, |
| 145 | unsigned int end) |
| 146 | { |
| 147 | *cmd++ = CP_REG(start); /* h/w regs, start addr */ |
| 148 | *cmd++ = end - start + 1; /* count */ |
| 149 | return cmd; |
| 150 | } |
| 151 | |
| 152 | static inline void calc_gmemsize(struct gmem_shadow_t *shadow, int gmem_size) |
| 153 | { |
| 154 | int w = 64, h = 64; |
| 155 | |
| 156 | shadow->format = COLORX_8_8_8_8; |
| 157 | |
| 158 | /* convert from bytes to 32-bit words */ |
| 159 | gmem_size = (gmem_size + 3) / 4; |
| 160 | |
| 161 | while ((w * h) < gmem_size) { |
| 162 | if (w < h) |
| 163 | w *= 2; |
| 164 | else |
| 165 | h *= 2; |
| 166 | } |
| 167 | |
| 168 | shadow->pitch = shadow->width = w; |
| 169 | shadow->height = h; |
| 170 | shadow->gmem_pitch = shadow->pitch; |
| 171 | shadow->size = shadow->pitch * shadow->height * 4; |
| 172 | } |
| 173 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | #endif /* __ADRENO_DRAWCTXT_H */ |