Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2002,2007-2012, The Linux Foundation. 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 | |
Tarun Karra | 5bea9c6 | 2013-01-27 17:39:17 -0800 | [diff] [blame] | 16 | #include <linux/sched.h> |
| 17 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 18 | #include "adreno_pm4types.h" |
Jeremy Gebben | eebc461 | 2011-08-31 10:15:21 -0700 | [diff] [blame] | 19 | #include "a2xx_reg.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | |
| 21 | /* Flags */ |
| 22 | |
| 23 | #define CTXT_FLAGS_NOT_IN_USE 0x00000000 |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 24 | #define CTXT_FLAGS_IN_USE BIT(0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | |
| 26 | /* state shadow memory allocated */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 27 | #define CTXT_FLAGS_STATE_SHADOW BIT(1) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | |
| 29 | /* gmem shadow memory allocated */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 30 | #define CTXT_FLAGS_GMEM_SHADOW BIT(2) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | /* gmem must be copied to shadow */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 32 | #define CTXT_FLAGS_GMEM_SAVE BIT(3) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | /* gmem can be restored from shadow */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 34 | #define CTXT_FLAGS_GMEM_RESTORE BIT(4) |
Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 35 | /* preamble packed in cmdbuffer for context switching */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 36 | #define CTXT_FLAGS_PREAMBLE BIT(5) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | /* shader must be copied to shadow */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 38 | #define CTXT_FLAGS_SHADER_SAVE BIT(6) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | /* shader can be restored from shadow */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 40 | #define CTXT_FLAGS_SHADER_RESTORE BIT(7) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | /* Context has caused a GPU hang */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 42 | #define CTXT_FLAGS_GPU_HANG BIT(8) |
Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 43 | /* Specifies there is no need to save GMEM */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 44 | #define CTXT_FLAGS_NOGMEMALLOC BIT(9) |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 45 | /* Trash state for context */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 46 | #define CTXT_FLAGS_TRASHSTATE BIT(10) |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 47 | /* per context timestamps enabled */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 48 | #define CTXT_FLAGS_PER_CONTEXT_TS BIT(11) |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 49 | /* Context has caused a GPU hang and fault tolerance successful */ |
| 50 | #define CTXT_FLAGS_GPU_HANG_FT BIT(12) |
Shubhraprakash Das | fc2c904 | 2012-08-15 04:11:55 -0700 | [diff] [blame] | 51 | /* Context is being destroyed so dont save it */ |
Shubhraprakash Das | c9ec266 | 2012-11-20 11:10:41 -0700 | [diff] [blame] | 52 | #define CTXT_FLAGS_BEING_DESTROYED BIT(13) |
Vijay Krishnamoorthy | e80c346 | 2012-08-27 14:07:32 -0700 | [diff] [blame] | 53 | /* User mode generated timestamps enabled */ |
| 54 | #define CTXT_FLAGS_USER_GENERATED_TS BIT(14) |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame] | 55 | /* Context skip till EOF */ |
| 56 | #define CTXT_FLAGS_SKIP_EOF BIT(15) |
Tarun Karra | 8329722 | 2013-02-05 19:45:49 -0800 | [diff] [blame] | 57 | /* Context no fault tolerance */ |
| 58 | #define CTXT_FLAGS_NO_FAULT_TOLERANCE BIT(16) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | |
| 60 | struct kgsl_device; |
| 61 | struct adreno_device; |
| 62 | struct kgsl_device_private; |
| 63 | struct kgsl_context; |
| 64 | |
| 65 | /* draw context */ |
| 66 | struct gmem_shadow_t { |
| 67 | struct kgsl_memdesc gmemshadow; /* Shadow buffer address */ |
| 68 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 69 | /* |
| 70 | * 256 KB GMEM surface = 4 bytes-per-pixel x 256 pixels/row x |
| 71 | * 256 rows. Width & height must be multiples of 32 in case tiled |
| 72 | * textures are used |
| 73 | */ |
| 74 | |
| 75 | enum COLORFORMATX format; /* Unused on A3XX */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 76 | unsigned int size; /* Size of surface used to store GMEM */ |
| 77 | unsigned int width; /* Width of surface used to store GMEM */ |
| 78 | unsigned int height; /* Height of surface used to store GMEM */ |
| 79 | unsigned int pitch; /* Pitch of surface used to store GMEM */ |
| 80 | unsigned int gmem_pitch; /* Pitch value used for GMEM */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 81 | unsigned int *gmem_save_commands; /* Unused on A3XX */ |
| 82 | unsigned int *gmem_restore_commands; /* Unused on A3XX */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 83 | unsigned int gmem_save[3]; |
| 84 | unsigned int gmem_restore[3]; |
| 85 | struct kgsl_memdesc quad_vertices; |
| 86 | struct kgsl_memdesc quad_texcoords; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 87 | struct kgsl_memdesc quad_vertices_restore; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | struct adreno_context { |
Tarun Karra | 5bea9c6 | 2013-01-27 17:39:17 -0800 | [diff] [blame] | 91 | pid_t pid; |
| 92 | char pid_name[TASK_COMM_LEN]; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 93 | unsigned int id; |
Tarun Karra | 696f89e | 2013-01-27 21:31:40 -0800 | [diff] [blame] | 94 | unsigned int ib_gpu_time_used; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | uint32_t flags; |
Tarun Karra | 24e3dfa | 2013-02-25 21:58:05 -0800 | [diff] [blame^] | 96 | uint32_t pagefault; |
| 97 | unsigned long pagefault_ts; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | struct kgsl_pagetable *pagetable; |
| 99 | struct kgsl_memdesc gpustate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | unsigned int reg_restore[3]; |
| 101 | unsigned int shader_save[3]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 102 | unsigned int shader_restore[3]; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 103 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | /* Information of the GMEM shadow that is created in context create */ |
| 105 | struct gmem_shadow_t context_gmem_shadow; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 106 | |
| 107 | /* A2XX specific items */ |
| 108 | unsigned int reg_save[3]; |
| 109 | unsigned int shader_fixup[3]; |
| 110 | unsigned int chicken_restore[3]; |
| 111 | unsigned int bin_base_offset; |
| 112 | |
| 113 | /* A3XX specific items */ |
| 114 | unsigned int regconstant_save[3]; |
| 115 | unsigned int constant_restore[3]; |
| 116 | unsigned int hlsqcontrol_restore[3]; |
| 117 | unsigned int save_fixup[3]; |
| 118 | unsigned int restore_fixup[3]; |
| 119 | struct kgsl_memdesc shader_load_commands[2]; |
| 120 | struct kgsl_memdesc shader_save_commands[4]; |
| 121 | struct kgsl_memdesc constant_save_commands[3]; |
| 122 | struct kgsl_memdesc constant_load_commands[3]; |
| 123 | struct kgsl_memdesc cond_execs[4]; |
| 124 | struct kgsl_memdesc hlsqcontrol_restore_commands[1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | int adreno_drawctxt_create(struct kgsl_device *device, |
| 128 | struct kgsl_pagetable *pagetable, |
| 129 | struct kgsl_context *context, |
| 130 | uint32_t flags); |
| 131 | |
| 132 | void adreno_drawctxt_destroy(struct kgsl_device *device, |
| 133 | struct kgsl_context *context); |
| 134 | |
| 135 | void adreno_drawctxt_switch(struct adreno_device *adreno_dev, |
| 136 | struct adreno_context *drawctxt, |
| 137 | unsigned int flags); |
| 138 | void adreno_drawctxt_set_bin_base_offset(struct kgsl_device *device, |
Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 139 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | unsigned int offset); |
| 141 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 142 | /* GPU context switch helper functions */ |
| 143 | |
Jordan Crouse | 0e0486f | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 144 | void build_quad_vtxbuff(struct adreno_context *drawctxt, |
| 145 | struct gmem_shadow_t *shadow, unsigned int **incmd); |
| 146 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 147 | unsigned int uint2float(unsigned int); |
| 148 | |
| 149 | static inline unsigned int virt2gpu(unsigned int *cmd, |
| 150 | struct kgsl_memdesc *memdesc) |
| 151 | { |
| 152 | return memdesc->gpuaddr + ((char *) cmd - (char *) memdesc->hostptr); |
| 153 | } |
| 154 | |
| 155 | static inline void create_ib1(struct adreno_context *drawctxt, |
| 156 | unsigned int *cmd, |
| 157 | unsigned int *start, |
| 158 | unsigned int *end) |
| 159 | { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 160 | cmd[0] = CP_HDR_INDIRECT_BUFFER_PFD; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 161 | cmd[1] = virt2gpu(start, &drawctxt->gpustate); |
| 162 | cmd[2] = end - start; |
| 163 | } |
| 164 | |
Jordan Crouse | 0e0486f | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 165 | |
| 166 | static inline unsigned int *reg_range(unsigned int *cmd, unsigned int start, |
| 167 | unsigned int end) |
| 168 | { |
| 169 | *cmd++ = CP_REG(start); /* h/w regs, start addr */ |
| 170 | *cmd++ = end - start + 1; /* count */ |
| 171 | return cmd; |
| 172 | } |
| 173 | |
| 174 | static inline void calc_gmemsize(struct gmem_shadow_t *shadow, int gmem_size) |
| 175 | { |
| 176 | int w = 64, h = 64; |
| 177 | |
| 178 | shadow->format = COLORX_8_8_8_8; |
| 179 | |
| 180 | /* convert from bytes to 32-bit words */ |
| 181 | gmem_size = (gmem_size + 3) / 4; |
| 182 | |
| 183 | while ((w * h) < gmem_size) { |
| 184 | if (w < h) |
| 185 | w *= 2; |
| 186 | else |
| 187 | h *= 2; |
| 188 | } |
| 189 | |
| 190 | shadow->pitch = shadow->width = w; |
| 191 | shadow->height = h; |
| 192 | shadow->gmem_pitch = shadow->pitch; |
| 193 | shadow->size = shadow->pitch * shadow->height * 4; |
| 194 | } |
| 195 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 196 | #endif /* __ADRENO_DRAWCTXT_H */ |