Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-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_H |
| 14 | #define __ADRENO_H |
| 15 | |
| 16 | #include "kgsl_device.h" |
| 17 | #include "adreno_drawctxt.h" |
| 18 | #include "adreno_ringbuffer.h" |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame^] | 19 | #include "kgsl_iommu.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | |
| 21 | #define DEVICE_3D_NAME "kgsl-3d" |
| 22 | #define DEVICE_3D0_NAME "kgsl-3d0" |
| 23 | |
| 24 | #define ADRENO_DEVICE(device) \ |
| 25 | KGSL_CONTAINER_OF(device, struct adreno_device, dev) |
| 26 | |
| 27 | /* Flags to control command packet settings */ |
Jordan Crouse | e0ea762 | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 28 | #define KGSL_CMD_FLAGS_NONE 0x00000000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | #define KGSL_CMD_FLAGS_PMODE 0x00000001 |
| 30 | #define KGSL_CMD_FLAGS_NO_TS_CMP 0x00000002 |
| 31 | #define KGSL_CMD_FLAGS_NOT_KERNEL_CMD 0x00000004 |
| 32 | |
| 33 | /* Command identifiers */ |
Shubhraprakash Das | d23ff4b | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 34 | #define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF |
| 35 | #define KGSL_CMD_IDENTIFIER 0x2EEDFACE |
| 36 | #define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE |
| 37 | #define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | |
| 39 | #ifdef CONFIG_MSM_SCM |
| 40 | #define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz) |
Lynus Vaz | 31754cb | 2012-02-22 18:07:02 +0530 | [diff] [blame] | 41 | #elif defined CONFIG_MSM_SLEEP_STATS_DEVICE |
| 42 | #define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | #else |
| 44 | #define ADRENO_DEFAULT_PWRSCALE_POLICY NULL |
| 45 | #endif |
| 46 | |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 47 | #define ADRENO_ISTORE_START 0x5000 /* Istore offset */ |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 48 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 49 | enum adreno_gpurev { |
| 50 | ADRENO_REV_UNKNOWN = 0, |
| 51 | ADRENO_REV_A200 = 200, |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 52 | ADRENO_REV_A203 = 203, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | ADRENO_REV_A205 = 205, |
| 54 | ADRENO_REV_A220 = 220, |
| 55 | ADRENO_REV_A225 = 225, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 56 | ADRENO_REV_A305 = 305, |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 57 | ADRENO_REV_A320 = 320, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 60 | struct adreno_gpudev; |
| 61 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | struct adreno_device { |
| 63 | struct kgsl_device dev; /* Must be first field in this struct */ |
| 64 | unsigned int chip_id; |
| 65 | enum adreno_gpurev gpurev; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 66 | unsigned long gmem_base; |
| 67 | unsigned int gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | struct adreno_context *drawctxt_active; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 69 | const char *pfp_fwfile; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 70 | unsigned int *pfp_fw; |
| 71 | size_t pfp_fw_size; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 72 | const char *pm4_fwfile; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | unsigned int *pm4_fw; |
| 74 | size_t pm4_fw_size; |
| 75 | struct adreno_ringbuffer ringbuffer; |
| 76 | unsigned int mharb; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 77 | struct adreno_gpudev *gpudev; |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 78 | unsigned int wait_timeout; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 79 | unsigned int istore_size; |
| 80 | unsigned int pix_shader_start; |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 81 | unsigned int instruction_size; |
Jeremy Gebben | d0ab6ad | 2012-04-06 11:13:35 -0600 | [diff] [blame] | 82 | unsigned int ib_check_level; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 85 | struct adreno_gpudev { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 86 | /* |
| 87 | * These registers are in a different location on A3XX, so define |
| 88 | * them in the structure and use them as variables. |
| 89 | */ |
| 90 | unsigned int reg_rbbm_status; |
| 91 | unsigned int reg_cp_pfp_ucode_data; |
| 92 | unsigned int reg_cp_pfp_ucode_addr; |
| 93 | |
| 94 | /* GPU specific function hooks */ |
Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 95 | int (*ctxt_create)(struct adreno_device *, struct adreno_context *); |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 96 | void (*ctxt_save)(struct adreno_device *, struct adreno_context *); |
| 97 | void (*ctxt_restore)(struct adreno_device *, struct adreno_context *); |
| 98 | irqreturn_t (*irq_handler)(struct adreno_device *); |
| 99 | void (*irq_control)(struct adreno_device *, int); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 100 | void * (*snapshot)(struct adreno_device *, void *, int *, int); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 101 | void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *); |
| 102 | void (*start)(struct adreno_device *); |
| 103 | unsigned int (*busy_cycles)(struct adreno_device *); |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | extern struct adreno_gpudev adreno_a2xx_gpudev; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 107 | extern struct adreno_gpudev adreno_a3xx_gpudev; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 108 | |
Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 109 | /* A2XX register sets defined in adreno_a2xx.c */ |
| 110 | extern const unsigned int a200_registers[]; |
| 111 | extern const unsigned int a220_registers[]; |
Jeremy Gebben | 6be78d1 | 2012-03-07 16:02:47 -0700 | [diff] [blame] | 112 | extern const unsigned int a225_registers[]; |
Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 113 | extern const unsigned int a200_registers_count; |
| 114 | extern const unsigned int a220_registers_count; |
Jeremy Gebben | 6be78d1 | 2012-03-07 16:02:47 -0700 | [diff] [blame] | 115 | extern const unsigned int a225_registers_count; |
Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 116 | |
Jordan Crouse | 0c2761a | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 117 | /* A3XX register set defined in adreno_a3xx.c */ |
| 118 | extern const unsigned int a3xx_registers[]; |
| 119 | extern const unsigned int a3xx_registers_count; |
| 120 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | int adreno_idle(struct kgsl_device *device, unsigned int timeout); |
| 122 | void adreno_regread(struct kgsl_device *device, unsigned int offsetwords, |
| 123 | unsigned int *value); |
| 124 | void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords, |
| 125 | unsigned int value); |
| 126 | |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 127 | struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device, |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 128 | unsigned int pt_base, |
| 129 | unsigned int gpuaddr, |
| 130 | unsigned int size); |
| 131 | |
| 132 | uint8_t *adreno_convertaddr(struct kgsl_device *device, |
| 133 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 135 | struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device, |
| 136 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size); |
| 137 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 138 | void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain, |
| 139 | int hang); |
| 140 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 141 | static inline int adreno_is_a200(struct adreno_device *adreno_dev) |
| 142 | { |
| 143 | return (adreno_dev->gpurev == ADRENO_REV_A200); |
| 144 | } |
| 145 | |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 146 | static inline int adreno_is_a203(struct adreno_device *adreno_dev) |
| 147 | { |
| 148 | return (adreno_dev->gpurev == ADRENO_REV_A203); |
| 149 | } |
| 150 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | static inline int adreno_is_a205(struct adreno_device *adreno_dev) |
| 152 | { |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 153 | return (adreno_dev->gpurev == ADRENO_REV_A205); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static inline int adreno_is_a20x(struct adreno_device *adreno_dev) |
| 157 | { |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 158 | return (adreno_dev->gpurev <= 209); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static inline int adreno_is_a220(struct adreno_device *adreno_dev) |
| 162 | { |
| 163 | return (adreno_dev->gpurev == ADRENO_REV_A220); |
| 164 | } |
| 165 | |
| 166 | static inline int adreno_is_a225(struct adreno_device *adreno_dev) |
| 167 | { |
| 168 | return (adreno_dev->gpurev == ADRENO_REV_A225); |
| 169 | } |
| 170 | |
| 171 | static inline int adreno_is_a22x(struct adreno_device *adreno_dev) |
| 172 | { |
| 173 | return (adreno_dev->gpurev == ADRENO_REV_A220 || |
| 174 | adreno_dev->gpurev == ADRENO_REV_A225); |
| 175 | } |
| 176 | |
Jordan Crouse | 196c45b | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 177 | static inline int adreno_is_a2xx(struct adreno_device *adreno_dev) |
| 178 | { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 179 | return (adreno_dev->gpurev <= 299); |
| 180 | } |
| 181 | |
| 182 | static inline int adreno_is_a3xx(struct adreno_device *adreno_dev) |
| 183 | { |
| 184 | return (adreno_dev->gpurev >= 300); |
Jordan Crouse | 196c45b | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 185 | } |
| 186 | |
Kevin Matlage | 48d0e2e | 2012-04-26 10:52:36 -0600 | [diff] [blame] | 187 | static inline int adreno_is_a305(struct adreno_device *adreno_dev) |
| 188 | { |
| 189 | return (adreno_dev->gpurev == ADRENO_REV_A305); |
| 190 | } |
| 191 | |
| 192 | static inline int adreno_is_a320(struct adreno_device *adreno_dev) |
| 193 | { |
| 194 | return (adreno_dev->gpurev == ADRENO_REV_A320); |
| 195 | } |
| 196 | |
Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 197 | static inline int adreno_rb_ctxtswitch(unsigned int *cmd) |
| 198 | { |
| 199 | return (cmd[0] == cp_nop_packet(1) && |
| 200 | cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER); |
| 201 | } |
| 202 | |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 203 | /** |
| 204 | * adreno_encode_istore_size - encode istore size in CP format |
| 205 | * @adreno_dev - The 3D device. |
| 206 | * |
| 207 | * Encode the istore size into the format expected that the |
| 208 | * CP_SET_SHADER_BASES and CP_ME_INIT commands: |
| 209 | * bits 31:29 - istore size as encoded by this function |
| 210 | * bits 27:16 - vertex shader start offset in instructions |
| 211 | * bits 11:0 - pixel shader start offset in instructions. |
| 212 | */ |
| 213 | static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev) |
| 214 | { |
| 215 | unsigned int size; |
| 216 | /* in a225 the CP microcode multiplies the encoded |
| 217 | * value by 3 while decoding. |
| 218 | */ |
| 219 | if (adreno_is_a225(adreno_dev)) |
| 220 | size = adreno_dev->istore_size/3; |
| 221 | else |
| 222 | size = adreno_dev->istore_size; |
| 223 | |
| 224 | return (ilog2(size) - 5) << 29; |
| 225 | } |
Jordan Crouse | 196c45b | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 226 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame^] | 227 | static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds, |
| 228 | unsigned int nop_gpuaddr) |
| 229 | { |
| 230 | /* Adding an indirect buffer ensures that the prefetch stalls until |
| 231 | * the commands in indirect buffer have completed. We need to stall |
| 232 | * prefetch with a nop indirect buffer when updating pagetables |
| 233 | * because it provides stabler synchronization */ |
| 234 | *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD; |
| 235 | *cmds++ = nop_gpuaddr; |
| 236 | *cmds++ = 2; |
| 237 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 238 | *cmds++ = 0x00000000; |
| 239 | return 5; |
| 240 | } |
| 241 | |
| 242 | static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds, |
| 243 | unsigned int new_phys_limit, |
| 244 | unsigned int nop_gpuaddr) |
| 245 | { |
| 246 | unsigned int *start = cmds; |
| 247 | |
| 248 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 249 | *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1); |
| 250 | *cmds++ = new_phys_limit; |
| 251 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 252 | return cmds - start; |
| 253 | } |
| 254 | |
| 255 | static inline int adreno_add_bank_change_cmds(unsigned int *cmds, |
| 256 | int cur_ctx_bank, |
| 257 | unsigned int nop_gpuaddr) |
| 258 | { |
| 259 | unsigned int *start = cmds; |
| 260 | |
| 261 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 262 | *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1); |
| 263 | *cmds++ = (cur_ctx_bank ? 0 : 0x20); |
| 264 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 265 | return cmds - start; |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * adreno_read_cmds - Add pm4 packets to perform read |
| 270 | * @device - Pointer to device structure |
| 271 | * @cmds - Pointer to memory where read commands need to be added |
| 272 | * @addr - gpu address of the read |
| 273 | * @val - The GPU will wait until the data at address addr becomes |
| 274 | * equal to value |
| 275 | */ |
| 276 | static inline int adreno_add_read_cmds(struct kgsl_device *device, |
| 277 | unsigned int *cmds, unsigned int addr, |
| 278 | unsigned int val, unsigned int nop_gpuaddr) |
| 279 | { |
| 280 | unsigned int *start = cmds; |
| 281 | |
| 282 | *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5); |
| 283 | /* MEM SPACE = memory, FUNCTION = equals */ |
| 284 | *cmds++ = 0x13; |
| 285 | *cmds++ = addr; |
| 286 | *cmds++ = val; |
| 287 | *cmds++ = 0xFFFFFFFF; |
| 288 | *cmds++ = 0xFFFFFFFF; |
| 289 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 290 | return cmds - start; |
| 291 | } |
| 292 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 293 | #endif /*__ADRENO_H */ |