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