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