Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2008-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_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" |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 20 | #include <mach/ocmem.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
| 22 | #define DEVICE_3D_NAME "kgsl-3d" |
| 23 | #define DEVICE_3D0_NAME "kgsl-3d0" |
| 24 | |
| 25 | #define ADRENO_DEVICE(device) \ |
| 26 | KGSL_CONTAINER_OF(device, struct adreno_device, dev) |
| 27 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 28 | #define ADRENO_CHIPID_CORE(_id) (((_id) >> 24) & 0xFF) |
| 29 | #define ADRENO_CHIPID_MAJOR(_id) (((_id) >> 16) & 0xFF) |
| 30 | #define ADRENO_CHIPID_MINOR(_id) (((_id) >> 8) & 0xFF) |
| 31 | #define ADRENO_CHIPID_PATCH(_id) ((_id) & 0xFF) |
| 32 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | /* Flags to control command packet settings */ |
Jordan Crouse | e0ea762 | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 34 | #define KGSL_CMD_FLAGS_NONE 0x00000000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | #define KGSL_CMD_FLAGS_PMODE 0x00000001 |
Vijay Krishnamoorthy | e80c346 | 2012-08-27 14:07:32 -0700 | [diff] [blame] | 36 | #define KGSL_CMD_FLAGS_INTERNAL_ISSUE 0x00000002 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | |
| 38 | /* Command identifiers */ |
Shubhraprakash Das | d23ff4b | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 39 | #define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF |
| 40 | #define KGSL_CMD_IDENTIFIER 0x2EEDFACE |
| 41 | #define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE |
| 42 | #define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | |
| 44 | #ifdef CONFIG_MSM_SCM |
| 45 | #define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_tz) |
Lynus Vaz | 31754cb | 2012-02-22 18:07:02 +0530 | [diff] [blame] | 46 | #elif defined CONFIG_MSM_SLEEP_STATS_DEVICE |
| 47 | #define ADRENO_DEFAULT_PWRSCALE_POLICY (&kgsl_pwrscale_policy_idlestats) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | #else |
| 49 | #define ADRENO_DEFAULT_PWRSCALE_POLICY NULL |
| 50 | #endif |
| 51 | |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 52 | void adreno_debugfs_init(struct kgsl_device *device); |
| 53 | |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 54 | #define ADRENO_ISTORE_START 0x5000 /* Istore offset */ |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 55 | |
Shubhraprakash Das | 4624b55 | 2012-06-01 14:08:03 -0600 | [diff] [blame] | 56 | #define ADRENO_NUM_CTX_SWITCH_ALLOWED_BEFORE_DRAW 50 |
| 57 | |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 58 | /* One cannot wait forever for the core to idle, so set an upper limit to the |
| 59 | * amount of time to wait for the core to go idle |
| 60 | */ |
| 61 | |
| 62 | #define ADRENO_IDLE_TIMEOUT (20 * 1000) |
| 63 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | enum adreno_gpurev { |
| 65 | ADRENO_REV_UNKNOWN = 0, |
| 66 | ADRENO_REV_A200 = 200, |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 67 | ADRENO_REV_A203 = 203, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | ADRENO_REV_A205 = 205, |
| 69 | ADRENO_REV_A220 = 220, |
| 70 | ADRENO_REV_A225 = 225, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 71 | ADRENO_REV_A305 = 305, |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 72 | ADRENO_REV_A320 = 320, |
liu zhong | fd42e62 | 2012-05-01 19:18:30 -0700 | [diff] [blame] | 73 | ADRENO_REV_A330 = 330, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 76 | struct adreno_gpudev; |
| 77 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | struct adreno_device { |
| 79 | struct kgsl_device dev; /* Must be first field in this struct */ |
| 80 | unsigned int chip_id; |
| 81 | enum adreno_gpurev gpurev; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 82 | unsigned long gmem_base; |
| 83 | unsigned int gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | struct adreno_context *drawctxt_active; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 85 | const char *pfp_fwfile; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 86 | unsigned int *pfp_fw; |
| 87 | size_t pfp_fw_size; |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 88 | unsigned int pfp_fw_version; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 89 | const char *pm4_fwfile; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | unsigned int *pm4_fw; |
| 91 | size_t pm4_fw_size; |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 92 | unsigned int pm4_fw_version; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | struct adreno_ringbuffer ringbuffer; |
| 94 | unsigned int mharb; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 95 | struct adreno_gpudev *gpudev; |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 96 | unsigned int wait_timeout; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 97 | unsigned int istore_size; |
| 98 | unsigned int pix_shader_start; |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 99 | unsigned int instruction_size; |
Jeremy Gebben | d0ab6ad | 2012-04-06 11:13:35 -0600 | [diff] [blame] | 100 | unsigned int ib_check_level; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 101 | unsigned int fast_hang_detect; |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 102 | unsigned int gpulist_index; |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 103 | struct ocmem_buf *ocmem_hdl; |
liu zhong | 5af32d9 | 2012-08-29 14:36:36 -0600 | [diff] [blame] | 104 | unsigned int ocmem_base; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 107 | struct adreno_gpudev { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 108 | /* |
| 109 | * These registers are in a different location on A3XX, so define |
| 110 | * them in the structure and use them as variables. |
| 111 | */ |
| 112 | unsigned int reg_rbbm_status; |
| 113 | unsigned int reg_cp_pfp_ucode_data; |
| 114 | unsigned int reg_cp_pfp_ucode_addr; |
Shubhraprakash Das | 4624b55 | 2012-06-01 14:08:03 -0600 | [diff] [blame] | 115 | /* keeps track of when we need to execute the draw workaround code */ |
| 116 | int ctx_switches_since_last_draw; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 117 | |
| 118 | /* GPU specific function hooks */ |
Vijay Krishnamoorthy | bef6693 | 2012-01-24 09:32:05 -0700 | [diff] [blame] | 119 | int (*ctxt_create)(struct adreno_device *, struct adreno_context *); |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 120 | void (*ctxt_save)(struct adreno_device *, struct adreno_context *); |
| 121 | void (*ctxt_restore)(struct adreno_device *, struct adreno_context *); |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 122 | void (*ctxt_draw_workaround)(struct adreno_device *, |
| 123 | struct adreno_context *); |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 124 | irqreturn_t (*irq_handler)(struct adreno_device *); |
| 125 | void (*irq_control)(struct adreno_device *, int); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 126 | void * (*snapshot)(struct adreno_device *, void *, int *, int); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 127 | void (*rb_init)(struct adreno_device *, struct adreno_ringbuffer *); |
| 128 | void (*start)(struct adreno_device *); |
| 129 | unsigned int (*busy_cycles)(struct adreno_device *); |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 130 | }; |
| 131 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 132 | /* |
| 133 | * struct adreno_recovery_data - Structure that contains all information to |
| 134 | * perform gpu recovery from hangs |
| 135 | * @ib1 - IB1 that the GPU was executing when hang happened |
| 136 | * @context_id - Context which caused the hang |
| 137 | * @global_eop - eoptimestamp at time of hang |
| 138 | * @rb_buffer - Buffer that holds the commands from good contexts |
| 139 | * @rb_size - Number of valid dwords in rb_buffer |
| 140 | * @bad_rb_buffer - Buffer that holds commands from the hanging context |
| 141 | * bad_rb_size - Number of valid dwords in bad_rb_buffer |
| 142 | * @last_valid_ctx_id - The last context from which commands were placed in |
| 143 | * ringbuffer before the GPU hung |
Shubhraprakash Das | 2747cf6 | 2012-09-27 23:05:43 -0700 | [diff] [blame] | 144 | * @fault - Indicates whether the hang was caused due to a pagefault |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 145 | */ |
| 146 | struct adreno_recovery_data { |
| 147 | unsigned int ib1; |
| 148 | unsigned int context_id; |
| 149 | unsigned int global_eop; |
| 150 | unsigned int *rb_buffer; |
| 151 | unsigned int rb_size; |
| 152 | unsigned int *bad_rb_buffer; |
| 153 | unsigned int bad_rb_size; |
| 154 | unsigned int last_valid_ctx_id; |
Shubhraprakash Das | 2747cf6 | 2012-09-27 23:05:43 -0700 | [diff] [blame] | 155 | int fault; |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 156 | }; |
| 157 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 158 | extern struct adreno_gpudev adreno_a2xx_gpudev; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 159 | extern struct adreno_gpudev adreno_a3xx_gpudev; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 160 | |
Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 161 | /* A2XX register sets defined in adreno_a2xx.c */ |
| 162 | extern const unsigned int a200_registers[]; |
| 163 | extern const unsigned int a220_registers[]; |
Jeremy Gebben | 6be78d1 | 2012-03-07 16:02:47 -0700 | [diff] [blame] | 164 | extern const unsigned int a225_registers[]; |
Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 165 | extern const unsigned int a200_registers_count; |
| 166 | extern const unsigned int a220_registers_count; |
Jeremy Gebben | 6be78d1 | 2012-03-07 16:02:47 -0700 | [diff] [blame] | 167 | extern const unsigned int a225_registers_count; |
Jordan Crouse | f7597bf | 2012-01-03 08:43:34 -0700 | [diff] [blame] | 168 | |
Jordan Crouse | 0c2761a | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 169 | /* A3XX register set defined in adreno_a3xx.c */ |
| 170 | extern const unsigned int a3xx_registers[]; |
| 171 | extern const unsigned int a3xx_registers_count; |
| 172 | |
Carter Cooper | f294e89 | 2012-11-26 10:45:53 -0700 | [diff] [blame] | 173 | extern const unsigned int a3xx_hlsq_registers[]; |
| 174 | extern const unsigned int a3xx_hlsq_registers_count; |
| 175 | |
Jordan Crouse | 9983925 | 2012-08-14 14:33:42 -0600 | [diff] [blame] | 176 | extern const unsigned int a330_registers[]; |
| 177 | extern const unsigned int a330_registers_count; |
| 178 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 179 | extern unsigned int hang_detect_regs[]; |
| 180 | extern const unsigned int hang_detect_regs_count; |
| 181 | |
| 182 | |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 183 | int adreno_idle(struct kgsl_device *device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 184 | void adreno_regread(struct kgsl_device *device, unsigned int offsetwords, |
| 185 | unsigned int *value); |
| 186 | void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords, |
| 187 | unsigned int value); |
| 188 | |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 189 | int adreno_dump(struct kgsl_device *device, int manual); |
| 190 | |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 191 | struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device, |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 192 | unsigned int pt_base, |
| 193 | unsigned int gpuaddr, |
| 194 | unsigned int size); |
| 195 | |
| 196 | uint8_t *adreno_convertaddr(struct kgsl_device *device, |
| 197 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 198 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 199 | struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device, |
| 200 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size); |
| 201 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 202 | void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain, |
| 203 | int hang); |
| 204 | |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 205 | int adreno_dump_and_recover(struct kgsl_device *device); |
| 206 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 207 | unsigned int adreno_hang_detect(struct kgsl_device *device, |
| 208 | unsigned int *prev_reg_val); |
| 209 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 210 | static inline int adreno_is_a200(struct adreno_device *adreno_dev) |
| 211 | { |
| 212 | return (adreno_dev->gpurev == ADRENO_REV_A200); |
| 213 | } |
| 214 | |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 215 | static inline int adreno_is_a203(struct adreno_device *adreno_dev) |
| 216 | { |
| 217 | return (adreno_dev->gpurev == ADRENO_REV_A203); |
| 218 | } |
| 219 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 220 | static inline int adreno_is_a205(struct adreno_device *adreno_dev) |
| 221 | { |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 222 | return (adreno_dev->gpurev == ADRENO_REV_A205); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static inline int adreno_is_a20x(struct adreno_device *adreno_dev) |
| 226 | { |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 227 | return (adreno_dev->gpurev <= 209); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static inline int adreno_is_a220(struct adreno_device *adreno_dev) |
| 231 | { |
| 232 | return (adreno_dev->gpurev == ADRENO_REV_A220); |
| 233 | } |
| 234 | |
| 235 | static inline int adreno_is_a225(struct adreno_device *adreno_dev) |
| 236 | { |
| 237 | return (adreno_dev->gpurev == ADRENO_REV_A225); |
| 238 | } |
| 239 | |
| 240 | static inline int adreno_is_a22x(struct adreno_device *adreno_dev) |
| 241 | { |
| 242 | return (adreno_dev->gpurev == ADRENO_REV_A220 || |
| 243 | adreno_dev->gpurev == ADRENO_REV_A225); |
| 244 | } |
| 245 | |
Jordan Crouse | 196c45b | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 246 | static inline int adreno_is_a2xx(struct adreno_device *adreno_dev) |
| 247 | { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 248 | return (adreno_dev->gpurev <= 299); |
| 249 | } |
| 250 | |
| 251 | static inline int adreno_is_a3xx(struct adreno_device *adreno_dev) |
| 252 | { |
| 253 | return (adreno_dev->gpurev >= 300); |
Jordan Crouse | 196c45b | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 254 | } |
| 255 | |
Kevin Matlage | 48d0e2e | 2012-04-26 10:52:36 -0600 | [diff] [blame] | 256 | static inline int adreno_is_a305(struct adreno_device *adreno_dev) |
| 257 | { |
| 258 | return (adreno_dev->gpurev == ADRENO_REV_A305); |
| 259 | } |
| 260 | |
| 261 | static inline int adreno_is_a320(struct adreno_device *adreno_dev) |
| 262 | { |
| 263 | return (adreno_dev->gpurev == ADRENO_REV_A320); |
| 264 | } |
| 265 | |
Jordan Crouse | c097820 | 2012-08-29 14:35:51 -0600 | [diff] [blame] | 266 | static inline int adreno_is_a330(struct adreno_device *adreno_dev) |
| 267 | { |
| 268 | return (adreno_dev->gpurev == ADRENO_REV_A330); |
| 269 | } |
| 270 | |
Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 271 | static inline int adreno_rb_ctxtswitch(unsigned int *cmd) |
| 272 | { |
| 273 | return (cmd[0] == cp_nop_packet(1) && |
| 274 | cmd[1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER); |
| 275 | } |
| 276 | |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 277 | /** |
| 278 | * adreno_encode_istore_size - encode istore size in CP format |
| 279 | * @adreno_dev - The 3D device. |
| 280 | * |
| 281 | * Encode the istore size into the format expected that the |
| 282 | * CP_SET_SHADER_BASES and CP_ME_INIT commands: |
| 283 | * bits 31:29 - istore size as encoded by this function |
| 284 | * bits 27:16 - vertex shader start offset in instructions |
| 285 | * bits 11:0 - pixel shader start offset in instructions. |
| 286 | */ |
| 287 | static inline int adreno_encode_istore_size(struct adreno_device *adreno_dev) |
| 288 | { |
| 289 | unsigned int size; |
| 290 | /* in a225 the CP microcode multiplies the encoded |
| 291 | * value by 3 while decoding. |
| 292 | */ |
| 293 | if (adreno_is_a225(adreno_dev)) |
| 294 | size = adreno_dev->istore_size/3; |
| 295 | else |
| 296 | size = adreno_dev->istore_size; |
| 297 | |
| 298 | return (ilog2(size) - 5) << 29; |
| 299 | } |
Jordan Crouse | 196c45b | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 300 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 301 | static inline int __adreno_add_idle_indirect_cmds(unsigned int *cmds, |
| 302 | unsigned int nop_gpuaddr) |
| 303 | { |
| 304 | /* Adding an indirect buffer ensures that the prefetch stalls until |
| 305 | * the commands in indirect buffer have completed. We need to stall |
| 306 | * prefetch with a nop indirect buffer when updating pagetables |
| 307 | * because it provides stabler synchronization */ |
| 308 | *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD; |
| 309 | *cmds++ = nop_gpuaddr; |
| 310 | *cmds++ = 2; |
| 311 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 312 | *cmds++ = 0x00000000; |
| 313 | return 5; |
| 314 | } |
| 315 | |
| 316 | static inline int adreno_add_change_mh_phys_limit_cmds(unsigned int *cmds, |
| 317 | unsigned int new_phys_limit, |
| 318 | unsigned int nop_gpuaddr) |
| 319 | { |
| 320 | unsigned int *start = cmds; |
| 321 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 322 | *cmds++ = cp_type0_packet(MH_MMU_MPU_END, 1); |
| 323 | *cmds++ = new_phys_limit; |
| 324 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 325 | return cmds - start; |
| 326 | } |
| 327 | |
| 328 | static inline int adreno_add_bank_change_cmds(unsigned int *cmds, |
| 329 | int cur_ctx_bank, |
| 330 | unsigned int nop_gpuaddr) |
| 331 | { |
| 332 | unsigned int *start = cmds; |
| 333 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 334 | *cmds++ = cp_type0_packet(REG_CP_STATE_DEBUG_INDEX, 1); |
| 335 | *cmds++ = (cur_ctx_bank ? 0 : 0x20); |
| 336 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 337 | return cmds - start; |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * adreno_read_cmds - Add pm4 packets to perform read |
| 342 | * @device - Pointer to device structure |
| 343 | * @cmds - Pointer to memory where read commands need to be added |
| 344 | * @addr - gpu address of the read |
| 345 | * @val - The GPU will wait until the data at address addr becomes |
| 346 | * equal to value |
| 347 | */ |
| 348 | static inline int adreno_add_read_cmds(struct kgsl_device *device, |
| 349 | unsigned int *cmds, unsigned int addr, |
| 350 | unsigned int val, unsigned int nop_gpuaddr) |
| 351 | { |
| 352 | unsigned int *start = cmds; |
| 353 | |
| 354 | *cmds++ = cp_type3_packet(CP_WAIT_REG_MEM, 5); |
| 355 | /* MEM SPACE = memory, FUNCTION = equals */ |
| 356 | *cmds++ = 0x13; |
| 357 | *cmds++ = addr; |
| 358 | *cmds++ = val; |
| 359 | *cmds++ = 0xFFFFFFFF; |
| 360 | *cmds++ = 0xFFFFFFFF; |
| 361 | cmds += __adreno_add_idle_indirect_cmds(cmds, nop_gpuaddr); |
| 362 | return cmds - start; |
| 363 | } |
| 364 | |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 365 | /* |
| 366 | * adreno_idle_cmds - Add pm4 packets for GPU idle |
| 367 | * @adreno_dev - Pointer to device structure |
| 368 | * @cmds - Pointer to memory where idle commands need to be added |
| 369 | */ |
| 370 | static inline int adreno_add_idle_cmds(struct adreno_device *adreno_dev, |
| 371 | unsigned int *cmds) |
| 372 | { |
| 373 | unsigned int *start = cmds; |
| 374 | |
| 375 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 376 | *cmds++ = 0x00000000; |
| 377 | |
| 378 | if ((adreno_dev->gpurev == ADRENO_REV_A305) || |
| 379 | (adreno_dev->gpurev == ADRENO_REV_A320)) { |
| 380 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_ME, 1); |
| 381 | *cmds++ = 0x00000000; |
| 382 | } |
| 383 | |
| 384 | return cmds - start; |
| 385 | } |
| 386 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 387 | #endif /*__ADRENO_H */ |