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 | #include <linux/delay.h> |
| 14 | #include <linux/uaccess.h> |
| 15 | #include <linux/vmalloc.h> |
| 16 | #include <linux/ioctl.h> |
| 17 | #include <linux/sched.h> |
| 18 | |
| 19 | #include <mach/socinfo.h> |
| 20 | |
| 21 | #include "kgsl.h" |
| 22 | #include "kgsl_pwrscale.h" |
| 23 | #include "kgsl_cffdump.h" |
| 24 | #include "kgsl_sharedmem.h" |
| 25 | |
| 26 | #include "adreno.h" |
| 27 | #include "adreno_pm4types.h" |
| 28 | #include "adreno_debugfs.h" |
| 29 | #include "adreno_postmortem.h" |
| 30 | |
Jeremy Gebben | eebc461 | 2011-08-31 10:15:21 -0700 | [diff] [blame] | 31 | #include "a2xx_reg.h" |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 32 | #include "kgsl_mmu.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | |
| 34 | #define DRIVER_VERSION_MAJOR 3 |
| 35 | #define DRIVER_VERSION_MINOR 1 |
| 36 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | /* Adreno MH arbiter config*/ |
| 38 | #define ADRENO_CFG_MHARB \ |
| 39 | (0x10 \ |
| 40 | | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \ |
| 41 | | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \ |
| 42 | | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \ |
| 43 | | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \ |
| 44 | | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \ |
| 45 | | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \ |
| 46 | | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \ |
| 47 | | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \ |
| 48 | | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \ |
| 49 | | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \ |
| 50 | | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \ |
| 51 | | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \ |
| 52 | | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \ |
| 53 | | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT)) |
| 54 | |
| 55 | #define ADRENO_MMU_CONFIG \ |
| 56 | (0x01 \ |
| 57 | | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \ |
| 58 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \ |
| 59 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 60 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 61 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \ |
| 62 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \ |
| 63 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \ |
| 64 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 65 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 66 | | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \ |
| 67 | | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT)) |
| 68 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 69 | static const struct kgsl_functable adreno_functable; |
| 70 | |
| 71 | static struct adreno_device device_3d0 = { |
| 72 | .dev = { |
| 73 | .name = DEVICE_3D0_NAME, |
| 74 | .id = KGSL_DEVICE_3D0, |
| 75 | .ver_major = DRIVER_VERSION_MAJOR, |
| 76 | .ver_minor = DRIVER_VERSION_MINOR, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 77 | .mh = { |
| 78 | .mharb = ADRENO_CFG_MHARB, |
| 79 | /* Remove 1k boundary check in z470 to avoid a GPU |
| 80 | * hang. Notice that this solution won't work if |
| 81 | * both EBI and SMI are used |
| 82 | */ |
| 83 | .mh_intf_cfg1 = 0x00032f07, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | /* turn off memory protection unit by setting |
| 85 | acceptable physical address range to include |
| 86 | all pages. */ |
| 87 | .mpu_base = 0x00000000, |
| 88 | .mpu_range = 0xFFFFF000, |
| 89 | }, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 90 | .mmu = { |
| 91 | .config = ADRENO_MMU_CONFIG, |
| 92 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | .pwrctrl = { |
| 94 | .regulator_name = "fs_gfx3d", |
| 95 | .irq_name = KGSL_3D0_IRQ, |
Matt Wagantall | 9dc0163 | 2011-08-17 18:55:04 -0700 | [diff] [blame] | 96 | .src_clk_name = "src_clk", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | }, |
| 98 | .mutex = __MUTEX_INITIALIZER(device_3d0.dev.mutex), |
| 99 | .state = KGSL_STATE_INIT, |
| 100 | .active_cnt = 0, |
| 101 | .iomemname = KGSL_3D0_REG_MEMORY, |
| 102 | .ftbl = &adreno_functable, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | #ifdef CONFIG_HAS_EARLYSUSPEND |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 104 | .display_off = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING, |
| 106 | .suspend = kgsl_early_suspend_driver, |
| 107 | .resume = kgsl_late_resume_driver, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | }, |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 109 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 110 | }, |
| 111 | .gmemspace = { |
| 112 | .gpu_base = 0, |
| 113 | .sizebytes = SZ_256K, |
| 114 | }, |
| 115 | .pfp_fw = NULL, |
| 116 | .pm4_fw = NULL, |
Jordan Crouse | 95b3327 | 2011-11-11 14:50:12 -0700 | [diff] [blame] | 117 | .wait_timeout = 10000, /* in milliseconds */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Jordan Crouse | 95b3327 | 2011-11-11 14:50:12 -0700 | [diff] [blame] | 120 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 121 | /* |
| 122 | * This is the master list of all GPU cores that are supported by this |
| 123 | * driver. |
| 124 | */ |
| 125 | |
| 126 | #define ANY_ID (~0) |
| 127 | |
| 128 | static const struct { |
| 129 | enum adreno_gpurev gpurev; |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 130 | unsigned int core, major, minor, patchid; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 131 | const char *pm4fw; |
| 132 | const char *pfpfw; |
| 133 | struct adreno_gpudev *gpudev; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 134 | unsigned int istore_size; |
| 135 | unsigned int pix_shader_start; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 136 | } adreno_gpulist[] = { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 137 | { ADRENO_REV_A200, 0, 2, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 138 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
| 139 | 512, 384}, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 140 | { ADRENO_REV_A205, 0, 1, 0, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 141 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
| 142 | 512, 384}, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 143 | { ADRENO_REV_A220, 2, 1, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 144 | "leia_pm4_470.fw", "leia_pfp_470.fw", &adreno_a2xx_gpudev, |
| 145 | 512, 384}, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 146 | /* |
| 147 | * patchlevel 5 (8960v2) needs special pm4 firmware to work around |
| 148 | * a hardware problem. |
| 149 | */ |
| 150 | { ADRENO_REV_A225, 2, 2, 0, 5, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 151 | "a225p5_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
| 152 | 1536, 768 }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 153 | { ADRENO_REV_A225, 2, 2, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 154 | "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
| 155 | 1536, 768 }, |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 156 | }; |
| 157 | |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 158 | static void adreno_gmeminit(struct adreno_device *adreno_dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 159 | { |
| 160 | struct kgsl_device *device = &adreno_dev->dev; |
| 161 | union reg_rb_edram_info rb_edram_info; |
| 162 | unsigned int gmem_size; |
| 163 | unsigned int edram_value = 0; |
| 164 | |
| 165 | /* make sure edram range is aligned to size */ |
| 166 | BUG_ON(adreno_dev->gmemspace.gpu_base & |
| 167 | (adreno_dev->gmemspace.sizebytes - 1)); |
| 168 | |
| 169 | /* get edram_size value equivalent */ |
| 170 | gmem_size = (adreno_dev->gmemspace.sizebytes >> 14); |
| 171 | while (gmem_size >>= 1) |
| 172 | edram_value++; |
| 173 | |
| 174 | rb_edram_info.val = 0; |
| 175 | |
| 176 | rb_edram_info.f.edram_size = edram_value; |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 177 | rb_edram_info.f.edram_mapping_mode = 0; /* EDRAM_MAP_UPPER */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | |
| 179 | /* must be aligned to size */ |
| 180 | rb_edram_info.f.edram_range = (adreno_dev->gmemspace.gpu_base >> 14); |
| 181 | |
| 182 | adreno_regwrite(device, REG_RB_EDRAM_INFO, rb_edram_info.val); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 185 | static irqreturn_t adreno_isr(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 186 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 187 | irqreturn_t result; |
| 188 | struct kgsl_device *device = data; |
| 189 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 190 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 191 | result = adreno_dev->gpudev->irq_handler(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 192 | |
| 193 | if (device->requested_state == KGSL_STATE_NONE) { |
| 194 | if (device->pwrctrl.nap_allowed == true) { |
| 195 | device->requested_state = KGSL_STATE_NAP; |
| 196 | queue_work(device->work_queue, &device->idle_check_ws); |
| 197 | } else if (device->pwrscale.policy != NULL) { |
| 198 | queue_work(device->work_queue, &device->idle_check_ws); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /* Reset the time-out in our idle timer */ |
| 203 | mod_timer(&device->idle_timer, |
| 204 | jiffies + device->pwrctrl.interval_timeout); |
| 205 | return result; |
| 206 | } |
| 207 | |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 208 | static void adreno_cleanup_pt(struct kgsl_device *device, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 209 | struct kgsl_pagetable *pagetable) |
| 210 | { |
| 211 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 212 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 213 | |
| 214 | kgsl_mmu_unmap(pagetable, &rb->buffer_desc); |
| 215 | |
| 216 | kgsl_mmu_unmap(pagetable, &rb->memptrs_desc); |
| 217 | |
| 218 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 219 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 220 | kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static int adreno_setup_pt(struct kgsl_device *device, |
| 224 | struct kgsl_pagetable *pagetable) |
| 225 | { |
| 226 | int result = 0; |
| 227 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 228 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 229 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | result = kgsl_mmu_map_global(pagetable, &rb->buffer_desc, |
| 231 | GSL_PT_PAGE_RV); |
| 232 | if (result) |
| 233 | goto error; |
| 234 | |
| 235 | result = kgsl_mmu_map_global(pagetable, &rb->memptrs_desc, |
| 236 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 237 | if (result) |
| 238 | goto unmap_buffer_desc; |
| 239 | |
| 240 | result = kgsl_mmu_map_global(pagetable, &device->memstore, |
| 241 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 242 | if (result) |
| 243 | goto unmap_memptrs_desc; |
| 244 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 245 | result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 246 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 247 | if (result) |
| 248 | goto unmap_memstore_desc; |
| 249 | |
| 250 | return result; |
| 251 | |
| 252 | unmap_memstore_desc: |
| 253 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 254 | |
| 255 | unmap_memptrs_desc: |
| 256 | kgsl_mmu_unmap(pagetable, &rb->memptrs_desc); |
| 257 | |
| 258 | unmap_buffer_desc: |
| 259 | kgsl_mmu_unmap(pagetable, &rb->buffer_desc); |
| 260 | |
| 261 | error: |
| 262 | return result; |
| 263 | } |
| 264 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 265 | static void adreno_setstate(struct kgsl_device *device, |
| 266 | uint32_t flags) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 267 | { |
| 268 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 269 | unsigned int link[32]; |
| 270 | unsigned int *cmds = &link[0]; |
| 271 | int sizedwords = 0; |
| 272 | unsigned int mh_mmu_invalidate = 0x00000003; /*invalidate all and tc */ |
| 273 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 274 | /* If possible, then set the state via the command stream to avoid |
| 275 | a CPU idle. Otherwise, use the default setstate which uses register |
| 276 | writes */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 277 | if (adreno_dev->drawctxt_active) { |
| 278 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
| 279 | /* wait for graphics pipe to be idle */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 280 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 281 | *cmds++ = 0x00000000; |
| 282 | |
| 283 | /* set page table base */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 284 | *cmds++ = cp_type0_packet(MH_MMU_PT_BASE, 1); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 285 | *cmds++ = kgsl_pt_get_base_addr( |
| 286 | device->mmu.hwpagetable); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 287 | sizedwords += 4; |
| 288 | } |
| 289 | |
| 290 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 291 | if (!(flags & KGSL_MMUFLAGS_PTUPDATE)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 292 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 293 | 1); |
| 294 | *cmds++ = 0x00000000; |
| 295 | sizedwords += 2; |
| 296 | } |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 297 | *cmds++ = cp_type0_packet(MH_MMU_INVALIDATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 298 | *cmds++ = mh_mmu_invalidate; |
| 299 | sizedwords += 2; |
| 300 | } |
| 301 | |
| 302 | if (flags & KGSL_MMUFLAGS_PTUPDATE && |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 303 | adreno_is_a20x(adreno_dev)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 304 | /* HW workaround: to resolve MMU page fault interrupts |
| 305 | * caused by the VGT.It prevents the CP PFP from filling |
| 306 | * the VGT DMA request fifo too early,thereby ensuring |
| 307 | * that the VGT will not fetch vertex/bin data until |
| 308 | * after the page table base register has been updated. |
| 309 | * |
| 310 | * Two null DRAW_INDX_BIN packets are inserted right |
| 311 | * after the page table base update, followed by a |
| 312 | * wait for idle. The null packets will fill up the |
| 313 | * VGT DMA request fifo and prevent any further |
| 314 | * vertex/bin updates from occurring until the wait |
| 315 | * has finished. */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 316 | *cmds++ = cp_type3_packet(CP_SET_CONSTANT, 2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 317 | *cmds++ = (0x4 << 16) | |
| 318 | (REG_PA_SU_SC_MODE_CNTL - 0x2000); |
| 319 | *cmds++ = 0; /* disable faceness generation */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 320 | *cmds++ = cp_type3_packet(CP_SET_BIN_BASE_OFFSET, 1); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 321 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 322 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 323 | *cmds++ = 0; /* viz query info */ |
| 324 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 325 | *cmds++ = 0; /* bin base */ |
| 326 | *cmds++ = 3; /* bin size */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 327 | *cmds++ = |
| 328 | device->mmu.setstate_memory.gpuaddr; /* dma base */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 329 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 330 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | *cmds++ = 0; /* viz query info */ |
| 332 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 333 | *cmds++ = 0; /* bin base */ |
| 334 | *cmds++ = 3; /* bin size */ |
| 335 | /* dma base */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 336 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 337 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 338 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 339 | *cmds++ = 0x00000000; |
| 340 | sizedwords += 21; |
| 341 | } |
| 342 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 343 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 344 | if (flags & (KGSL_MMUFLAGS_PTUPDATE | KGSL_MMUFLAGS_TLBFLUSH)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 345 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 346 | *cmds++ = 0x7fff; /* invalidate all base pointers */ |
| 347 | sizedwords += 2; |
| 348 | } |
| 349 | |
| 350 | adreno_ringbuffer_issuecmds(device, KGSL_CMD_FLAGS_PMODE, |
| 351 | &link[0], sizedwords); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 352 | } else { |
| 353 | kgsl_mmu_device_setstate(device, flags); |
| 354 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static unsigned int |
| 358 | adreno_getchipid(struct kgsl_device *device) |
| 359 | { |
| 360 | unsigned int chipid = 0; |
| 361 | unsigned int coreid, majorid, minorid, patchid, revid; |
| 362 | |
| 363 | adreno_regread(device, REG_RBBM_PERIPHID1, &coreid); |
| 364 | adreno_regread(device, REG_RBBM_PERIPHID2, &majorid); |
| 365 | adreno_regread(device, REG_RBBM_PATCH_RELEASE, &revid); |
| 366 | |
| 367 | /* |
| 368 | * adreno 22x gpus are indicated by coreid 2, |
| 369 | * but REG_RBBM_PERIPHID1 always contains 0 for this field |
| 370 | */ |
Stepan Moskovchenko | 8eea9cf | 2011-10-25 14:45:42 -0700 | [diff] [blame] | 371 | if (cpu_is_msm8960() || cpu_is_msm8x60() || cpu_is_msm8930()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | chipid = 2 << 24; |
| 373 | else |
| 374 | chipid = (coreid & 0xF) << 24; |
| 375 | |
| 376 | chipid |= ((majorid >> 4) & 0xF) << 16; |
| 377 | |
| 378 | minorid = ((revid >> 0) & 0xFF); |
| 379 | |
| 380 | patchid = ((revid >> 16) & 0xFF); |
| 381 | |
| 382 | /* 8x50 returns 0 for patch release, but it should be 1 */ |
| 383 | if (cpu_is_qsd8x50()) |
| 384 | patchid = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 385 | |
| 386 | chipid |= (minorid << 8) | patchid; |
| 387 | |
| 388 | return chipid; |
| 389 | } |
| 390 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 391 | static inline bool _rev_match(unsigned int id, unsigned int entry) |
| 392 | { |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 393 | return (entry == ANY_ID || entry == id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 394 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 395 | |
| 396 | static void |
| 397 | adreno_identify_gpu(struct adreno_device *adreno_dev) |
| 398 | { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 399 | unsigned int i, core, major, minor, patchid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 400 | |
| 401 | adreno_dev->chip_id = adreno_getchipid(&adreno_dev->dev); |
| 402 | |
| 403 | core = (adreno_dev->chip_id >> 24) & 0xff; |
| 404 | major = (adreno_dev->chip_id >> 16) & 0xff; |
| 405 | minor = (adreno_dev->chip_id >> 8) & 0xff; |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 406 | patchid = (adreno_dev->chip_id & 0xff); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 407 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 408 | for (i = 0; i < ARRAY_SIZE(adreno_gpulist); i++) { |
| 409 | if (core == adreno_gpulist[i].core && |
| 410 | _rev_match(major, adreno_gpulist[i].major) && |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 411 | _rev_match(minor, adreno_gpulist[i].minor) && |
| 412 | _rev_match(patchid, adreno_gpulist[i].patchid)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 413 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 416 | if (i == ARRAY_SIZE(adreno_gpulist)) { |
| 417 | adreno_dev->gpurev = ADRENO_REV_UNKNOWN; |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | adreno_dev->gpurev = adreno_gpulist[i].gpurev; |
| 422 | adreno_dev->gpudev = adreno_gpulist[i].gpudev; |
| 423 | adreno_dev->pfp_fwfile = adreno_gpulist[i].pfpfw; |
| 424 | adreno_dev->pm4_fwfile = adreno_gpulist[i].pm4fw; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 425 | adreno_dev->istore_size = adreno_gpulist[i].istore_size; |
| 426 | adreno_dev->pix_shader_start = adreno_gpulist[i].pix_shader_start; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static int __devinit |
| 430 | adreno_probe(struct platform_device *pdev) |
| 431 | { |
| 432 | struct kgsl_device *device; |
| 433 | struct adreno_device *adreno_dev; |
| 434 | int status = -EINVAL; |
| 435 | |
| 436 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 437 | adreno_dev = ADRENO_DEVICE(device); |
| 438 | device->parentdev = &pdev->dev; |
| 439 | |
| 440 | init_completion(&device->recovery_gate); |
| 441 | |
| 442 | status = adreno_ringbuffer_init(device); |
| 443 | if (status != 0) |
| 444 | goto error; |
| 445 | |
| 446 | status = kgsl_device_platform_probe(device, adreno_isr); |
| 447 | if (status) |
| 448 | goto error_close_rb; |
| 449 | |
| 450 | adreno_debugfs_init(device); |
| 451 | |
| 452 | kgsl_pwrscale_init(device); |
| 453 | kgsl_pwrscale_attach_policy(device, ADRENO_DEFAULT_PWRSCALE_POLICY); |
| 454 | |
| 455 | device->flags &= ~KGSL_FLAGS_SOFT_RESET; |
| 456 | return 0; |
| 457 | |
| 458 | error_close_rb: |
| 459 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 460 | error: |
| 461 | device->parentdev = NULL; |
| 462 | return status; |
| 463 | } |
| 464 | |
| 465 | static int __devexit adreno_remove(struct platform_device *pdev) |
| 466 | { |
| 467 | struct kgsl_device *device; |
| 468 | struct adreno_device *adreno_dev; |
| 469 | |
| 470 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 471 | adreno_dev = ADRENO_DEVICE(device); |
| 472 | |
| 473 | kgsl_pwrscale_detach_policy(device); |
| 474 | kgsl_pwrscale_close(device); |
| 475 | |
| 476 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 477 | kgsl_device_platform_remove(device); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int adreno_start(struct kgsl_device *device, unsigned int init_ram) |
| 483 | { |
| 484 | int status = -EINVAL; |
| 485 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 486 | int init_reftimestamp = 0x7fffffff; |
| 487 | |
| 488 | device->state = KGSL_STATE_INIT; |
| 489 | device->requested_state = KGSL_STATE_NONE; |
| 490 | |
| 491 | /* Power up the device */ |
| 492 | kgsl_pwrctrl_enable(device); |
| 493 | |
| 494 | /* Identify the specific GPU */ |
| 495 | adreno_identify_gpu(adreno_dev); |
| 496 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 497 | if (adreno_dev->gpurev == ADRENO_REV_UNKNOWN) { |
| 498 | KGSL_DRV_ERR(device, "Unknown chip ID %x\n", |
| 499 | adreno_dev->chip_id); |
| 500 | goto error_clk_off; |
| 501 | } |
| 502 | |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 503 | if (adreno_is_a20x(adreno_dev)) { |
| 504 | /* |
| 505 | * the MH_CLNT_INTF_CTRL_CONFIG registers aren't present |
| 506 | * on older gpus |
| 507 | */ |
| 508 | device->mh.mh_intf_cfg1 = 0; |
| 509 | device->mh.mh_intf_cfg2 = 0; |
| 510 | } |
| 511 | |
| 512 | kgsl_mh_start(device); |
| 513 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 514 | if (kgsl_mmu_start(device)) |
| 515 | goto error_clk_off; |
| 516 | |
| 517 | /*We need to make sure all blocks are powered up and clocked before |
| 518 | *issuing a soft reset. The overrides will then be turned off (set to 0) |
| 519 | */ |
| 520 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE1, 0xfffffffe); |
| 521 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0xffffffff); |
| 522 | |
| 523 | /* Only reset CP block if all blocks have previously been reset */ |
| 524 | if (!(device->flags & KGSL_FLAGS_SOFT_RESET) || |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 525 | !adreno_is_a22x(adreno_dev)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | adreno_regwrite(device, REG_RBBM_SOFT_RESET, 0xFFFFFFFF); |
| 527 | device->flags |= KGSL_FLAGS_SOFT_RESET; |
| 528 | } else |
| 529 | adreno_regwrite(device, REG_RBBM_SOFT_RESET, 0x00000001); |
| 530 | |
| 531 | /* The core is in an indeterminate state until the reset completes |
| 532 | * after 30ms. |
| 533 | */ |
| 534 | msleep(30); |
| 535 | |
| 536 | adreno_regwrite(device, REG_RBBM_SOFT_RESET, 0x00000000); |
| 537 | |
| 538 | adreno_regwrite(device, REG_RBBM_CNTL, 0x00004442); |
| 539 | |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 540 | if (adreno_is_a225(adreno_dev)) { |
| 541 | /* Enable large instruction store for A225 */ |
| 542 | adreno_regwrite(device, REG_SQ_FLOW_CONTROL, 0x18000000); |
| 543 | } |
| 544 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 545 | adreno_regwrite(device, REG_SQ_VS_PROGRAM, 0x00000000); |
| 546 | adreno_regwrite(device, REG_SQ_PS_PROGRAM, 0x00000000); |
| 547 | |
Stepan Moskovchenko | 8eea9cf | 2011-10-25 14:45:42 -0700 | [diff] [blame] | 548 | if (cpu_is_msm8960() || cpu_is_msm8930()) |
Tarun Karra | 96a1267 | 2011-09-23 18:52:39 -0700 | [diff] [blame] | 549 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE1, 0x200); |
| 550 | else |
| 551 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE1, 0); |
| 552 | |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 553 | if (!adreno_is_a22x(adreno_dev)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 554 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0); |
| 555 | else |
| 556 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0x80); |
| 557 | |
Sushmita Susheelendra | f389606 | 2011-08-12 16:33:10 -0600 | [diff] [blame] | 558 | kgsl_sharedmem_set(&device->memstore, 0, 0, device->memstore.size); |
| 559 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 560 | kgsl_sharedmem_writel(&device->memstore, |
| 561 | KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts), |
| 562 | init_reftimestamp); |
| 563 | |
Ranjhith Kalisamy | f81dcd0 | 2011-09-30 16:45:24 +0530 | [diff] [blame] | 564 | adreno_regwrite(device, REG_RBBM_DEBUG, 0x00080000); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 565 | |
| 566 | /* Make sure interrupts are disabled */ |
| 567 | |
| 568 | adreno_regwrite(device, REG_RBBM_INT_CNTL, 0); |
| 569 | adreno_regwrite(device, REG_CP_INT_CNTL, 0); |
| 570 | adreno_regwrite(device, REG_SQ_INT_CNTL, 0); |
| 571 | |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 572 | if (adreno_is_a22x(adreno_dev)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 573 | adreno_dev->gmemspace.sizebytes = SZ_512K; |
| 574 | else |
| 575 | adreno_dev->gmemspace.sizebytes = SZ_256K; |
| 576 | adreno_gmeminit(adreno_dev); |
| 577 | |
| 578 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); |
| 579 | |
| 580 | status = adreno_ringbuffer_start(&adreno_dev->ringbuffer, init_ram); |
| 581 | if (status != 0) |
| 582 | goto error_irq_off; |
| 583 | |
| 584 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
| 585 | return status; |
| 586 | |
| 587 | error_irq_off: |
| 588 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 589 | kgsl_mmu_stop(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 590 | error_clk_off: |
| 591 | kgsl_pwrctrl_disable(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 592 | |
| 593 | return status; |
| 594 | } |
| 595 | |
| 596 | static int adreno_stop(struct kgsl_device *device) |
| 597 | { |
| 598 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 599 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 600 | adreno_dev->drawctxt_active = NULL; |
| 601 | |
| 602 | adreno_ringbuffer_stop(&adreno_dev->ringbuffer); |
| 603 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 604 | kgsl_mmu_stop(device); |
| 605 | |
Lucille Sylvester | 844b1c8 | 2011-08-29 15:26:06 -0600 | [diff] [blame] | 606 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
| 607 | del_timer_sync(&device->idle_timer); |
| 608 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 609 | /* Power down the device */ |
| 610 | kgsl_pwrctrl_disable(device); |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static int |
| 616 | adreno_recover_hang(struct kgsl_device *device) |
| 617 | { |
| 618 | int ret; |
| 619 | unsigned int *rb_buffer; |
| 620 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 621 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 622 | unsigned int timestamp; |
| 623 | unsigned int num_rb_contents; |
| 624 | unsigned int bad_context; |
| 625 | unsigned int reftimestamp; |
| 626 | unsigned int enable_ts; |
| 627 | unsigned int soptimestamp; |
| 628 | unsigned int eoptimestamp; |
| 629 | struct adreno_context *drawctxt; |
| 630 | |
| 631 | KGSL_DRV_ERR(device, "Starting recovery from 3D GPU hang....\n"); |
| 632 | rb_buffer = vmalloc(rb->buffer_desc.size); |
| 633 | if (!rb_buffer) { |
| 634 | KGSL_MEM_ERR(device, |
| 635 | "Failed to allocate memory for recovery: %x\n", |
| 636 | rb->buffer_desc.size); |
| 637 | return -ENOMEM; |
| 638 | } |
| 639 | /* Extract valid contents from rb which can stil be executed after |
| 640 | * hang */ |
| 641 | ret = adreno_ringbuffer_extract(rb, rb_buffer, &num_rb_contents); |
| 642 | if (ret) |
| 643 | goto done; |
| 644 | timestamp = rb->timestamp; |
| 645 | KGSL_DRV_ERR(device, "Last issued timestamp: %x\n", timestamp); |
| 646 | kgsl_sharedmem_readl(&device->memstore, &bad_context, |
| 647 | KGSL_DEVICE_MEMSTORE_OFFSET(current_context)); |
| 648 | kgsl_sharedmem_readl(&device->memstore, &reftimestamp, |
| 649 | KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts)); |
| 650 | kgsl_sharedmem_readl(&device->memstore, &enable_ts, |
| 651 | KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable)); |
| 652 | kgsl_sharedmem_readl(&device->memstore, &soptimestamp, |
| 653 | KGSL_DEVICE_MEMSTORE_OFFSET(soptimestamp)); |
| 654 | kgsl_sharedmem_readl(&device->memstore, &eoptimestamp, |
| 655 | KGSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp)); |
| 656 | /* Make sure memory is synchronized before restarting the GPU */ |
| 657 | mb(); |
| 658 | KGSL_CTXT_ERR(device, |
| 659 | "Context that caused a GPU hang: %x\n", bad_context); |
| 660 | /* restart device */ |
| 661 | ret = adreno_stop(device); |
| 662 | if (ret) |
| 663 | goto done; |
| 664 | ret = adreno_start(device, true); |
| 665 | if (ret) |
| 666 | goto done; |
| 667 | KGSL_DRV_ERR(device, "Device has been restarted after hang\n"); |
| 668 | /* Restore timestamp states */ |
| 669 | kgsl_sharedmem_writel(&device->memstore, |
| 670 | KGSL_DEVICE_MEMSTORE_OFFSET(soptimestamp), |
| 671 | soptimestamp); |
| 672 | kgsl_sharedmem_writel(&device->memstore, |
| 673 | KGSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), |
| 674 | eoptimestamp); |
| 675 | kgsl_sharedmem_writel(&device->memstore, |
| 676 | KGSL_DEVICE_MEMSTORE_OFFSET(soptimestamp), |
| 677 | soptimestamp); |
| 678 | if (num_rb_contents) { |
| 679 | kgsl_sharedmem_writel(&device->memstore, |
| 680 | KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts), |
| 681 | reftimestamp); |
| 682 | kgsl_sharedmem_writel(&device->memstore, |
| 683 | KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable), |
| 684 | enable_ts); |
| 685 | } |
| 686 | /* Make sure all writes are posted before the GPU reads them */ |
| 687 | wmb(); |
| 688 | /* Mark the invalid context so no more commands are accepted from |
| 689 | * that context */ |
| 690 | |
| 691 | drawctxt = (struct adreno_context *) bad_context; |
| 692 | |
| 693 | KGSL_CTXT_ERR(device, |
| 694 | "Context that caused a GPU hang: %x\n", bad_context); |
| 695 | |
| 696 | drawctxt->flags |= CTXT_FLAGS_GPU_HANG; |
| 697 | |
| 698 | /* Restore valid commands in ringbuffer */ |
| 699 | adreno_ringbuffer_restore(rb, rb_buffer, num_rb_contents); |
| 700 | rb->timestamp = timestamp; |
| 701 | done: |
| 702 | vfree(rb_buffer); |
| 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | static int |
| 707 | adreno_dump_and_recover(struct kgsl_device *device) |
| 708 | { |
| 709 | static int recovery; |
| 710 | int result = -ETIMEDOUT; |
| 711 | |
| 712 | if (device->state == KGSL_STATE_HUNG) |
| 713 | goto done; |
| 714 | if (device->state == KGSL_STATE_DUMP_AND_RECOVER && !recovery) { |
| 715 | mutex_unlock(&device->mutex); |
| 716 | wait_for_completion(&device->recovery_gate); |
| 717 | mutex_lock(&device->mutex); |
| 718 | if (!(device->state & KGSL_STATE_HUNG)) |
| 719 | /* recovery success */ |
| 720 | result = 0; |
| 721 | } else { |
| 722 | INIT_COMPLETION(device->recovery_gate); |
| 723 | /* Detected a hang - trigger an automatic dump */ |
| 724 | adreno_postmortem_dump(device, 0); |
| 725 | if (!recovery) { |
| 726 | recovery = 1; |
| 727 | result = adreno_recover_hang(device); |
| 728 | if (result) |
| 729 | device->state = KGSL_STATE_HUNG; |
| 730 | recovery = 0; |
| 731 | complete_all(&device->recovery_gate); |
| 732 | } else |
| 733 | KGSL_DRV_ERR(device, |
| 734 | "Cannot recover from another hang while " |
| 735 | "recovering from a hang\n"); |
| 736 | } |
| 737 | done: |
| 738 | return result; |
| 739 | } |
| 740 | |
| 741 | static int adreno_getproperty(struct kgsl_device *device, |
| 742 | enum kgsl_property_type type, |
| 743 | void *value, |
| 744 | unsigned int sizebytes) |
| 745 | { |
| 746 | int status = -EINVAL; |
| 747 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 748 | |
| 749 | switch (type) { |
| 750 | case KGSL_PROP_DEVICE_INFO: |
| 751 | { |
| 752 | struct kgsl_devinfo devinfo; |
| 753 | |
| 754 | if (sizebytes != sizeof(devinfo)) { |
| 755 | status = -EINVAL; |
| 756 | break; |
| 757 | } |
| 758 | |
| 759 | memset(&devinfo, 0, sizeof(devinfo)); |
| 760 | devinfo.device_id = device->id+1; |
| 761 | devinfo.chip_id = adreno_dev->chip_id; |
| 762 | devinfo.mmu_enabled = kgsl_mmu_enabled(); |
| 763 | devinfo.gpu_id = adreno_dev->gpurev; |
| 764 | devinfo.gmem_gpubaseaddr = adreno_dev->gmemspace. |
| 765 | gpu_base; |
| 766 | devinfo.gmem_sizebytes = adreno_dev->gmemspace. |
| 767 | sizebytes; |
| 768 | |
| 769 | if (copy_to_user(value, &devinfo, sizeof(devinfo)) != |
| 770 | 0) { |
| 771 | status = -EFAULT; |
| 772 | break; |
| 773 | } |
| 774 | status = 0; |
| 775 | } |
| 776 | break; |
| 777 | case KGSL_PROP_DEVICE_SHADOW: |
| 778 | { |
| 779 | struct kgsl_shadowprop shadowprop; |
| 780 | |
| 781 | if (sizebytes != sizeof(shadowprop)) { |
| 782 | status = -EINVAL; |
| 783 | break; |
| 784 | } |
| 785 | memset(&shadowprop, 0, sizeof(shadowprop)); |
| 786 | if (device->memstore.hostptr) { |
| 787 | /*NOTE: with mmu enabled, gpuaddr doesn't mean |
| 788 | * anything to mmap(). |
| 789 | */ |
| 790 | shadowprop.gpuaddr = device->memstore.physaddr; |
| 791 | shadowprop.size = device->memstore.size; |
| 792 | /* GSL needs this to be set, even if it |
| 793 | appears to be meaningless */ |
| 794 | shadowprop.flags = KGSL_FLAGS_INITIALIZED; |
| 795 | } |
| 796 | if (copy_to_user(value, &shadowprop, |
| 797 | sizeof(shadowprop))) { |
| 798 | status = -EFAULT; |
| 799 | break; |
| 800 | } |
| 801 | status = 0; |
| 802 | } |
| 803 | break; |
| 804 | case KGSL_PROP_MMU_ENABLE: |
| 805 | { |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 806 | int mmu_prop = kgsl_mmu_enabled(); |
| 807 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 808 | if (sizebytes != sizeof(int)) { |
| 809 | status = -EINVAL; |
| 810 | break; |
| 811 | } |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 812 | if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 813 | status = -EFAULT; |
| 814 | break; |
| 815 | } |
| 816 | status = 0; |
| 817 | } |
| 818 | break; |
| 819 | case KGSL_PROP_INTERRUPT_WAITS: |
| 820 | { |
| 821 | int int_waits = 1; |
| 822 | if (sizebytes != sizeof(int)) { |
| 823 | status = -EINVAL; |
| 824 | break; |
| 825 | } |
| 826 | if (copy_to_user(value, &int_waits, sizeof(int))) { |
| 827 | status = -EFAULT; |
| 828 | break; |
| 829 | } |
| 830 | status = 0; |
| 831 | } |
| 832 | break; |
| 833 | default: |
| 834 | status = -EINVAL; |
| 835 | } |
| 836 | |
| 837 | return status; |
| 838 | } |
| 839 | |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 840 | static inline void adreno_poke(struct kgsl_device *device) |
| 841 | { |
| 842 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 843 | adreno_regwrite(device, REG_CP_RB_WPTR, adreno_dev->ringbuffer.wptr); |
| 844 | } |
| 845 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 846 | /* Caller must hold the device mutex. */ |
| 847 | int adreno_idle(struct kgsl_device *device, unsigned int timeout) |
| 848 | { |
| 849 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 850 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 851 | unsigned int rbbm_status; |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 852 | unsigned long wait_timeout = |
| 853 | msecs_to_jiffies(adreno_dev->wait_timeout); |
| 854 | unsigned long wait_time = jiffies + wait_timeout; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 855 | |
| 856 | kgsl_cffdump_regpoll(device->id, REG_RBBM_STATUS << 2, |
| 857 | 0x00000000, 0x80000000); |
| 858 | /* first, wait until the CP has consumed all the commands in |
| 859 | * the ring buffer |
| 860 | */ |
| 861 | retry: |
| 862 | if (rb->flags & KGSL_FLAGS_STARTED) { |
| 863 | do { |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 864 | adreno_poke(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 865 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 866 | if (time_after(jiffies, wait_time)) { |
| 867 | KGSL_DRV_ERR(device, "rptr: %x, wptr: %x\n", |
| 868 | rb->rptr, rb->wptr); |
| 869 | goto err; |
| 870 | } |
| 871 | } while (rb->rptr != rb->wptr); |
| 872 | } |
| 873 | |
| 874 | /* now, wait for the GPU to finish its operations */ |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 875 | wait_time = jiffies + wait_timeout; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 876 | while (time_before(jiffies, wait_time)) { |
| 877 | adreno_regread(device, REG_RBBM_STATUS, &rbbm_status); |
| 878 | if (rbbm_status == 0x110) |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | err: |
| 883 | KGSL_DRV_ERR(device, "spun too long waiting for RB to idle\n"); |
| 884 | if (!adreno_dump_and_recover(device)) { |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 885 | wait_time = jiffies + wait_timeout; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 886 | goto retry; |
| 887 | } |
| 888 | return -ETIMEDOUT; |
| 889 | } |
| 890 | |
| 891 | static unsigned int adreno_isidle(struct kgsl_device *device) |
| 892 | { |
| 893 | int status = false; |
| 894 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 895 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 896 | unsigned int rbbm_status; |
| 897 | |
| 898 | if (rb->flags & KGSL_FLAGS_STARTED) { |
| 899 | /* Is the ring buffer is empty? */ |
| 900 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 901 | if (!device->active_cnt && (rb->rptr == rb->wptr)) { |
| 902 | /* Is the core idle? */ |
| 903 | adreno_regread(device, REG_RBBM_STATUS, |
| 904 | &rbbm_status); |
| 905 | if (rbbm_status == 0x110) |
| 906 | status = true; |
| 907 | } |
| 908 | } else { |
| 909 | KGSL_DRV_ERR(device, "ringbuffer not started\n"); |
| 910 | BUG(); |
| 911 | } |
| 912 | return status; |
| 913 | } |
| 914 | |
| 915 | /* Caller must hold the device mutex. */ |
| 916 | static int adreno_suspend_context(struct kgsl_device *device) |
| 917 | { |
| 918 | int status = 0; |
| 919 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 920 | |
| 921 | /* switch to NULL ctxt */ |
| 922 | if (adreno_dev->drawctxt_active != NULL) { |
| 923 | adreno_drawctxt_switch(adreno_dev, NULL, 0); |
| 924 | status = adreno_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 925 | } |
| 926 | |
| 927 | return status; |
| 928 | } |
| 929 | |
| 930 | uint8_t *kgsl_sharedmem_convertaddr(struct kgsl_device *device, |
| 931 | unsigned int pt_base, unsigned int gpuaddr, unsigned int *size) |
| 932 | { |
| 933 | uint8_t *result = NULL; |
| 934 | struct kgsl_mem_entry *entry; |
| 935 | struct kgsl_process_private *priv; |
| 936 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 937 | struct adreno_ringbuffer *ringbuffer = &adreno_dev->ringbuffer; |
| 938 | |
| 939 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->buffer_desc, gpuaddr)) { |
| 940 | return kgsl_gpuaddr_to_vaddr(&ringbuffer->buffer_desc, |
| 941 | gpuaddr, size); |
| 942 | } |
| 943 | |
| 944 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->memptrs_desc, gpuaddr)) { |
| 945 | return kgsl_gpuaddr_to_vaddr(&ringbuffer->memptrs_desc, |
| 946 | gpuaddr, size); |
| 947 | } |
| 948 | |
| 949 | if (kgsl_gpuaddr_in_memdesc(&device->memstore, gpuaddr)) { |
| 950 | return kgsl_gpuaddr_to_vaddr(&device->memstore, |
| 951 | gpuaddr, size); |
| 952 | } |
| 953 | |
| 954 | mutex_lock(&kgsl_driver.process_mutex); |
| 955 | list_for_each_entry(priv, &kgsl_driver.process_list, list) { |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 956 | if (!kgsl_mmu_pt_equal(priv->pagetable, pt_base)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 957 | continue; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 958 | spin_lock(&priv->mem_lock); |
| 959 | entry = kgsl_sharedmem_find_region(priv, gpuaddr, |
| 960 | sizeof(unsigned int)); |
| 961 | if (entry) { |
| 962 | result = kgsl_gpuaddr_to_vaddr(&entry->memdesc, |
| 963 | gpuaddr, size); |
| 964 | spin_unlock(&priv->mem_lock); |
| 965 | mutex_unlock(&kgsl_driver.process_mutex); |
| 966 | return result; |
| 967 | } |
| 968 | spin_unlock(&priv->mem_lock); |
| 969 | } |
| 970 | mutex_unlock(&kgsl_driver.process_mutex); |
| 971 | |
| 972 | BUG_ON(!mutex_is_locked(&device->mutex)); |
| 973 | list_for_each_entry(entry, &device->memqueue, list) { |
| 974 | if (kgsl_gpuaddr_in_memdesc(&entry->memdesc, gpuaddr)) { |
| 975 | result = kgsl_gpuaddr_to_vaddr(&entry->memdesc, |
| 976 | gpuaddr, size); |
| 977 | break; |
| 978 | } |
| 979 | |
| 980 | } |
| 981 | return result; |
| 982 | } |
| 983 | |
| 984 | void adreno_regread(struct kgsl_device *device, unsigned int offsetwords, |
| 985 | unsigned int *value) |
| 986 | { |
| 987 | unsigned int *reg; |
| 988 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->regspace.sizebytes); |
| 989 | reg = (unsigned int *)(device->regspace.mmio_virt_base |
| 990 | + (offsetwords << 2)); |
| 991 | |
| 992 | if (!in_interrupt()) |
| 993 | kgsl_pre_hwaccess(device); |
| 994 | |
| 995 | /*ensure this read finishes before the next one. |
| 996 | * i.e. act like normal readl() */ |
| 997 | *value = __raw_readl(reg); |
| 998 | rmb(); |
| 999 | } |
| 1000 | |
| 1001 | void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords, |
| 1002 | unsigned int value) |
| 1003 | { |
| 1004 | unsigned int *reg; |
| 1005 | |
| 1006 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->regspace.sizebytes); |
| 1007 | |
| 1008 | if (!in_interrupt()) |
| 1009 | kgsl_pre_hwaccess(device); |
| 1010 | |
| 1011 | kgsl_cffdump_regwrite(device->id, offsetwords << 2, value); |
| 1012 | reg = (unsigned int *)(device->regspace.mmio_virt_base |
| 1013 | + (offsetwords << 2)); |
| 1014 | |
| 1015 | /*ensure previous writes post before this one, |
| 1016 | * i.e. act like normal writel() */ |
| 1017 | wmb(); |
| 1018 | __raw_writel(value, reg); |
| 1019 | } |
| 1020 | |
| 1021 | static int kgsl_check_interrupt_timestamp(struct kgsl_device *device, |
| 1022 | unsigned int timestamp) |
| 1023 | { |
| 1024 | int status; |
| 1025 | unsigned int ref_ts, enableflag; |
| 1026 | |
| 1027 | status = kgsl_check_timestamp(device, timestamp); |
| 1028 | if (!status) { |
| 1029 | mutex_lock(&device->mutex); |
| 1030 | kgsl_sharedmem_readl(&device->memstore, &enableflag, |
| 1031 | KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable)); |
| 1032 | mb(); |
| 1033 | |
| 1034 | if (enableflag) { |
| 1035 | kgsl_sharedmem_readl(&device->memstore, &ref_ts, |
| 1036 | KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts)); |
| 1037 | mb(); |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame^] | 1038 | if (timestamp_cmp(ref_ts, timestamp) >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1039 | kgsl_sharedmem_writel(&device->memstore, |
| 1040 | KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts), |
| 1041 | timestamp); |
| 1042 | wmb(); |
| 1043 | } |
| 1044 | } else { |
| 1045 | unsigned int cmds[2]; |
| 1046 | kgsl_sharedmem_writel(&device->memstore, |
| 1047 | KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts), |
| 1048 | timestamp); |
| 1049 | enableflag = 1; |
| 1050 | kgsl_sharedmem_writel(&device->memstore, |
| 1051 | KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable), |
| 1052 | enableflag); |
| 1053 | wmb(); |
| 1054 | /* submit a dummy packet so that even if all |
| 1055 | * commands upto timestamp get executed we will still |
| 1056 | * get an interrupt */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 1057 | cmds[0] = cp_type3_packet(CP_NOP, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1058 | cmds[1] = 0; |
| 1059 | adreno_ringbuffer_issuecmds(device, 0, &cmds[0], 2); |
| 1060 | } |
| 1061 | mutex_unlock(&device->mutex); |
| 1062 | } |
| 1063 | |
| 1064 | return status; |
| 1065 | } |
| 1066 | |
| 1067 | /* |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1068 | wait_event_interruptible_timeout checks for the exit condition before |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1069 | placing a process in wait q. For conditional interrupts we expect the |
| 1070 | process to already be in its wait q when its exit condition checking |
| 1071 | function is called. |
| 1072 | */ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1073 | #define kgsl_wait_event_interruptible_timeout(wq, condition, timeout, io)\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1074 | ({ \ |
| 1075 | long __ret = timeout; \ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1076 | if (io) \ |
| 1077 | __wait_io_event_interruptible_timeout(wq, condition, __ret);\ |
| 1078 | else \ |
| 1079 | __wait_event_interruptible_timeout(wq, condition, __ret);\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1080 | __ret; \ |
| 1081 | }) |
| 1082 | |
| 1083 | /* MUST be called with the device mutex held */ |
| 1084 | static int adreno_waittimestamp(struct kgsl_device *device, |
| 1085 | unsigned int timestamp, |
| 1086 | unsigned int msecs) |
| 1087 | { |
| 1088 | long status = 0; |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1089 | uint io = 1; |
Lucille Sylvester | 596d4c2 | 2011-10-19 18:04:01 -0600 | [diff] [blame] | 1090 | static uint io_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1091 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1092 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1093 | int retries; |
| 1094 | unsigned int msecs_first; |
| 1095 | unsigned int msecs_part; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1096 | |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1097 | /* Don't wait forever, set a max value for now */ |
| 1098 | if (msecs == -1) |
| 1099 | msecs = adreno_dev->wait_timeout; |
| 1100 | |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame^] | 1101 | if (timestamp_cmp(timestamp, adreno_dev->ringbuffer.timestamp) > 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1102 | KGSL_DRV_ERR(device, "Cannot wait for invalid ts: %x, " |
| 1103 | "rb->timestamp: %x\n", |
| 1104 | timestamp, adreno_dev->ringbuffer.timestamp); |
| 1105 | status = -EINVAL; |
| 1106 | goto done; |
| 1107 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1108 | |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1109 | /* Keep the first timeout as 100msecs before rewriting |
| 1110 | * the WPTR. Less visible impact if the WPTR has not |
| 1111 | * been updated properly. |
| 1112 | */ |
| 1113 | msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100; |
| 1114 | msecs_part = (msecs - msecs_first + 3) / 4; |
| 1115 | for (retries = 0; retries < 5; retries++) { |
| 1116 | if (!kgsl_check_timestamp(device, timestamp)) { |
| 1117 | adreno_poke(device); |
| 1118 | io_cnt = (io_cnt + 1) % 100; |
| 1119 | if (io_cnt < |
| 1120 | pwr->pwrlevels[pwr->active_pwrlevel]. |
| 1121 | io_fraction) |
| 1122 | io = 0; |
| 1123 | mutex_unlock(&device->mutex); |
| 1124 | /* We need to make sure that the process is |
| 1125 | * placed in wait-q before its condition is called |
| 1126 | */ |
| 1127 | status = kgsl_wait_event_interruptible_timeout( |
| 1128 | device->wait_queue, |
| 1129 | kgsl_check_interrupt_timestamp(device, |
| 1130 | timestamp), |
| 1131 | msecs_to_jiffies(retries ? |
| 1132 | msecs_part : msecs_first), io); |
| 1133 | mutex_lock(&device->mutex); |
| 1134 | |
| 1135 | if (status > 0) { |
| 1136 | status = 0; |
| 1137 | goto done; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | } |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1141 | if (!kgsl_check_timestamp(device, timestamp)) { |
| 1142 | status = -ETIMEDOUT; |
| 1143 | KGSL_DRV_ERR(device, |
| 1144 | "Device hang detected while waiting " |
| 1145 | "for timestamp: %x, last " |
| 1146 | "submitted(rb->timestamp): %x, wptr: " |
| 1147 | "%x\n", timestamp, |
| 1148 | adreno_dev->ringbuffer.timestamp, |
| 1149 | adreno_dev->ringbuffer.wptr); |
| 1150 | if (!adreno_dump_and_recover(device)) { |
| 1151 | /* wait for idle after recovery as the |
| 1152 | * timestamp that this process wanted |
| 1153 | * to wait on may be invalid */ |
| 1154 | if (!adreno_idle(device, |
| 1155 | KGSL_TIMEOUT_DEFAULT)) |
| 1156 | status = 0; |
| 1157 | } |
| 1158 | } else { |
| 1159 | status = 0; |
| 1160 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1161 | |
| 1162 | done: |
| 1163 | return (int)status; |
| 1164 | } |
| 1165 | |
| 1166 | static unsigned int adreno_readtimestamp(struct kgsl_device *device, |
| 1167 | enum kgsl_timestamp_type type) |
| 1168 | { |
| 1169 | unsigned int timestamp = 0; |
| 1170 | |
| 1171 | if (type == KGSL_TIMESTAMP_CONSUMED) |
| 1172 | adreno_regread(device, REG_CP_TIMESTAMP, ×tamp); |
| 1173 | else if (type == KGSL_TIMESTAMP_RETIRED) |
| 1174 | kgsl_sharedmem_readl(&device->memstore, ×tamp, |
| 1175 | KGSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp)); |
| 1176 | rmb(); |
| 1177 | |
| 1178 | return timestamp; |
| 1179 | } |
| 1180 | |
| 1181 | static long adreno_ioctl(struct kgsl_device_private *dev_priv, |
| 1182 | unsigned int cmd, void *data) |
| 1183 | { |
| 1184 | int result = 0; |
| 1185 | struct kgsl_drawctxt_set_bin_base_offset *binbase; |
| 1186 | struct kgsl_context *context; |
| 1187 | |
| 1188 | switch (cmd) { |
| 1189 | case IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET: |
| 1190 | binbase = data; |
| 1191 | |
| 1192 | context = kgsl_find_context(dev_priv, binbase->drawctxt_id); |
| 1193 | if (context) { |
| 1194 | adreno_drawctxt_set_bin_base_offset( |
| 1195 | dev_priv->device, context, binbase->offset); |
| 1196 | } else { |
| 1197 | result = -EINVAL; |
| 1198 | KGSL_DRV_ERR(dev_priv->device, |
| 1199 | "invalid drawctxt drawctxt_id %d " |
| 1200 | "device_id=%d\n", |
| 1201 | binbase->drawctxt_id, dev_priv->device->id); |
| 1202 | } |
| 1203 | break; |
| 1204 | |
| 1205 | default: |
| 1206 | KGSL_DRV_INFO(dev_priv->device, |
| 1207 | "invalid ioctl code %08x\n", cmd); |
| 1208 | result = -EINVAL; |
| 1209 | break; |
| 1210 | } |
| 1211 | return result; |
| 1212 | |
| 1213 | } |
| 1214 | |
| 1215 | static inline s64 adreno_ticks_to_us(u32 ticks, u32 gpu_freq) |
| 1216 | { |
| 1217 | gpu_freq /= 1000000; |
| 1218 | return ticks / gpu_freq; |
| 1219 | } |
| 1220 | |
| 1221 | static void adreno_power_stats(struct kgsl_device *device, |
| 1222 | struct kgsl_power_stats *stats) |
| 1223 | { |
| 1224 | unsigned int reg; |
| 1225 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 1226 | |
| 1227 | /* In order to calculate idle you have to have run the algorithm * |
| 1228 | * at least once to get a start time. */ |
| 1229 | if (pwr->time != 0) { |
| 1230 | s64 tmp; |
| 1231 | /* Stop the performance moniter and read the current * |
| 1232 | * busy cycles. */ |
| 1233 | adreno_regwrite(device, |
| 1234 | REG_CP_PERFMON_CNTL, |
| 1235 | REG_PERF_MODE_CNT | |
| 1236 | REG_PERF_STATE_FREEZE); |
| 1237 | adreno_regread(device, REG_RBBM_PERFCOUNTER1_LO, ®); |
| 1238 | tmp = ktime_to_us(ktime_get()); |
| 1239 | stats->total_time = tmp - pwr->time; |
| 1240 | pwr->time = tmp; |
| 1241 | stats->busy_time = adreno_ticks_to_us(reg, device->pwrctrl. |
| 1242 | pwrlevels[device->pwrctrl.active_pwrlevel]. |
| 1243 | gpu_freq); |
| 1244 | |
| 1245 | adreno_regwrite(device, |
| 1246 | REG_CP_PERFMON_CNTL, |
| 1247 | REG_PERF_MODE_CNT | |
| 1248 | REG_PERF_STATE_RESET); |
| 1249 | } else { |
| 1250 | stats->total_time = 0; |
| 1251 | stats->busy_time = 0; |
| 1252 | pwr->time = ktime_to_us(ktime_get()); |
| 1253 | } |
| 1254 | |
| 1255 | /* re-enable the performance moniters */ |
| 1256 | adreno_regread(device, REG_RBBM_PM_OVERRIDE2, ®); |
| 1257 | adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, (reg | 0x40)); |
| 1258 | adreno_regwrite(device, REG_RBBM_PERFCOUNTER1_SELECT, 0x1); |
| 1259 | adreno_regwrite(device, |
| 1260 | REG_CP_PERFMON_CNTL, |
| 1261 | REG_PERF_MODE_CNT | REG_PERF_STATE_ENABLE); |
| 1262 | } |
| 1263 | |
| 1264 | void adreno_irqctrl(struct kgsl_device *device, int state) |
| 1265 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 1266 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1267 | adreno_dev->gpudev->irq_control(adreno_dev, state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | static const struct kgsl_functable adreno_functable = { |
| 1271 | /* Mandatory functions */ |
| 1272 | .regread = adreno_regread, |
| 1273 | .regwrite = adreno_regwrite, |
| 1274 | .idle = adreno_idle, |
| 1275 | .isidle = adreno_isidle, |
| 1276 | .suspend_context = adreno_suspend_context, |
| 1277 | .start = adreno_start, |
| 1278 | .stop = adreno_stop, |
| 1279 | .getproperty = adreno_getproperty, |
| 1280 | .waittimestamp = adreno_waittimestamp, |
| 1281 | .readtimestamp = adreno_readtimestamp, |
| 1282 | .issueibcmds = adreno_ringbuffer_issueibcmds, |
| 1283 | .ioctl = adreno_ioctl, |
| 1284 | .setup_pt = adreno_setup_pt, |
| 1285 | .cleanup_pt = adreno_cleanup_pt, |
| 1286 | .power_stats = adreno_power_stats, |
| 1287 | .irqctrl = adreno_irqctrl, |
| 1288 | /* Optional functions */ |
| 1289 | .setstate = adreno_setstate, |
| 1290 | .drawctxt_create = adreno_drawctxt_create, |
| 1291 | .drawctxt_destroy = adreno_drawctxt_destroy, |
| 1292 | }; |
| 1293 | |
| 1294 | static struct platform_device_id adreno_id_table[] = { |
| 1295 | { DEVICE_3D0_NAME, (kernel_ulong_t)&device_3d0.dev, }, |
| 1296 | { }, |
| 1297 | }; |
| 1298 | MODULE_DEVICE_TABLE(platform, adreno_id_table); |
| 1299 | |
| 1300 | static struct platform_driver adreno_platform_driver = { |
| 1301 | .probe = adreno_probe, |
| 1302 | .remove = __devexit_p(adreno_remove), |
| 1303 | .suspend = kgsl_suspend_driver, |
| 1304 | .resume = kgsl_resume_driver, |
| 1305 | .id_table = adreno_id_table, |
| 1306 | .driver = { |
| 1307 | .owner = THIS_MODULE, |
| 1308 | .name = DEVICE_3D_NAME, |
| 1309 | .pm = &kgsl_pm_ops, |
| 1310 | } |
| 1311 | }; |
| 1312 | |
| 1313 | static int __init kgsl_3d_init(void) |
| 1314 | { |
| 1315 | return platform_driver_register(&adreno_platform_driver); |
| 1316 | } |
| 1317 | |
| 1318 | static void __exit kgsl_3d_exit(void) |
| 1319 | { |
| 1320 | platform_driver_unregister(&adreno_platform_driver); |
| 1321 | } |
| 1322 | |
| 1323 | module_init(kgsl_3d_init); |
| 1324 | module_exit(kgsl_3d_exit); |
| 1325 | |
| 1326 | MODULE_DESCRIPTION("3D Graphics driver"); |
| 1327 | MODULE_VERSION("1.2"); |
| 1328 | MODULE_LICENSE("GPL v2"); |
| 1329 | MODULE_ALIAS("platform:kgsl_3d"); |