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