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 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 14 | #include <linux/uaccess.h> |
| 15 | #include <linux/vmalloc.h> |
| 16 | #include <linux/ioctl.h> |
| 17 | #include <linux/sched.h> |
| 18 | |
| 19 | #include <mach/socinfo.h> |
| 20 | |
| 21 | #include "kgsl.h" |
| 22 | #include "kgsl_pwrscale.h" |
| 23 | #include "kgsl_cffdump.h" |
| 24 | #include "kgsl_sharedmem.h" |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 25 | #include "kgsl_iommu.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | |
| 27 | #include "adreno.h" |
| 28 | #include "adreno_pm4types.h" |
| 29 | #include "adreno_debugfs.h" |
| 30 | #include "adreno_postmortem.h" |
| 31 | |
Jeremy Gebben | eebc461 | 2011-08-31 10:15:21 -0700 | [diff] [blame] | 32 | #include "a2xx_reg.h" |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 33 | #include "a3xx_reg.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | |
| 35 | #define DRIVER_VERSION_MAJOR 3 |
| 36 | #define DRIVER_VERSION_MINOR 1 |
| 37 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | /* Adreno MH arbiter config*/ |
| 39 | #define ADRENO_CFG_MHARB \ |
| 40 | (0x10 \ |
| 41 | | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \ |
| 42 | | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \ |
| 43 | | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \ |
| 44 | | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \ |
| 45 | | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \ |
| 46 | | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \ |
| 47 | | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \ |
| 48 | | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \ |
| 49 | | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \ |
| 50 | | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \ |
| 51 | | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \ |
| 52 | | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \ |
| 53 | | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \ |
| 54 | | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT)) |
| 55 | |
| 56 | #define ADRENO_MMU_CONFIG \ |
| 57 | (0x01 \ |
| 58 | | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \ |
| 59 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \ |
| 60 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 61 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 62 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \ |
| 63 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \ |
| 64 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \ |
| 65 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 66 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 67 | | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \ |
| 68 | | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT)) |
| 69 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 70 | static const struct kgsl_functable adreno_functable; |
| 71 | |
| 72 | static struct adreno_device device_3d0 = { |
| 73 | .dev = { |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 74 | KGSL_DEVICE_COMMON_INIT(device_3d0.dev), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | .name = DEVICE_3D0_NAME, |
| 76 | .id = KGSL_DEVICE_3D0, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 77 | .mh = { |
| 78 | .mharb = ADRENO_CFG_MHARB, |
| 79 | /* Remove 1k boundary check in z470 to avoid a GPU |
| 80 | * hang. Notice that this solution won't work if |
| 81 | * both EBI and SMI are used |
| 82 | */ |
| 83 | .mh_intf_cfg1 = 0x00032f07, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | /* turn off memory protection unit by setting |
| 85 | acceptable physical address range to include |
| 86 | all pages. */ |
| 87 | .mpu_base = 0x00000000, |
| 88 | .mpu_range = 0xFFFFF000, |
| 89 | }, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 90 | .mmu = { |
| 91 | .config = ADRENO_MMU_CONFIG, |
| 92 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | .pwrctrl = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 94 | .irq_name = KGSL_3D0_IRQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 96 | .iomemname = KGSL_3D0_REG_MEMORY, |
| 97 | .ftbl = &adreno_functable, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | #ifdef CONFIG_HAS_EARLYSUSPEND |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 99 | .display_off = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING, |
| 101 | .suspend = kgsl_early_suspend_driver, |
| 102 | .resume = kgsl_late_resume_driver, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | }, |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 104 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | }, |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 106 | .gmem_base = 0, |
| 107 | .gmem_size = SZ_256K, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | .pfp_fw = NULL, |
| 109 | .pm4_fw = NULL, |
Jordan Crouse | 95b3327 | 2011-11-11 14:50:12 -0700 | [diff] [blame] | 110 | .wait_timeout = 10000, /* in milliseconds */ |
Jeremy Gebben | d0ab6ad | 2012-04-06 11:13:35 -0600 | [diff] [blame] | 111 | .ib_check_level = 0, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 114 | /* This set of registers are used for Hang detection |
| 115 | * If the values of these registers are same after |
| 116 | * KGSL_TIMEOUT_PART time, GPU hang is reported in |
| 117 | * kernel log. |
| 118 | */ |
| 119 | unsigned int hang_detect_regs[] = { |
| 120 | A3XX_RBBM_STATUS, |
| 121 | REG_CP_RB_RPTR, |
| 122 | REG_CP_IB1_BASE, |
| 123 | REG_CP_IB1_BUFSZ, |
| 124 | REG_CP_IB2_BASE, |
| 125 | REG_CP_IB2_BUFSZ, |
| 126 | }; |
| 127 | |
| 128 | const unsigned int hang_detect_regs_count = ARRAY_SIZE(hang_detect_regs); |
Jordan Crouse | 95b3327 | 2011-11-11 14:50:12 -0700 | [diff] [blame] | 129 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 130 | /* |
| 131 | * This is the master list of all GPU cores that are supported by this |
| 132 | * driver. |
| 133 | */ |
| 134 | |
| 135 | #define ANY_ID (~0) |
| 136 | |
| 137 | static const struct { |
| 138 | enum adreno_gpurev gpurev; |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 139 | unsigned int core, major, minor, patchid; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 140 | const char *pm4fw; |
| 141 | const char *pfpfw; |
| 142 | struct adreno_gpudev *gpudev; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 143 | unsigned int istore_size; |
| 144 | unsigned int pix_shader_start; |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 145 | unsigned int instruction_size; /* Size of an instruction in dwords */ |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 146 | unsigned int gmem_size; /* size of gmem for gpu*/ |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 147 | } adreno_gpulist[] = { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 148 | { ADRENO_REV_A200, 0, 2, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 149 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 150 | 512, 384, 3, SZ_256K }, |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 151 | { ADRENO_REV_A203, 0, 1, 1, ANY_ID, |
| 152 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 153 | 512, 384, 3, SZ_256K }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 154 | { ADRENO_REV_A205, 0, 1, 0, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 155 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 156 | 512, 384, 3, SZ_256K }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 157 | { ADRENO_REV_A220, 2, 1, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 158 | "leia_pm4_470.fw", "leia_pfp_470.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 159 | 512, 384, 3, SZ_512K }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 160 | /* |
| 161 | * patchlevel 5 (8960v2) needs special pm4 firmware to work around |
| 162 | * a hardware problem. |
| 163 | */ |
| 164 | { ADRENO_REV_A225, 2, 2, 0, 5, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 165 | "a225p5_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 166 | 1536, 768, 3, SZ_512K }, |
Carter Cooper | f27ec72 | 2011-11-17 15:20:38 -0700 | [diff] [blame] | 167 | { ADRENO_REV_A225, 2, 2, 0, 6, |
| 168 | "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 169 | 1536, 768, 3, SZ_512K }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 170 | { ADRENO_REV_A225, 2, 2, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 171 | "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 172 | 1536, 768, 3, SZ_512K }, |
| 173 | /* A3XX doesn't use the pix_shader_start */ |
Sudhakara Rao Tentu | e13766d | 2012-06-12 06:00:26 +0530 | [diff] [blame] | 174 | { ADRENO_REV_A305, 3, 0, 5, ANY_ID, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 175 | "a300_pm4.fw", "a300_pfp.fw", &adreno_a3xx_gpudev, |
| 176 | 512, 0, 2, SZ_256K }, |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 177 | /* A3XX doesn't use the pix_shader_start */ |
Jordan Crouse | d2b30d2 | 2012-05-21 08:41:51 -0600 | [diff] [blame] | 178 | { ADRENO_REV_A320, 3, 2, 0, ANY_ID, |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 179 | "a300_pm4.fw", "a300_pfp.fw", &adreno_a3xx_gpudev, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 180 | 512, 0, 2, SZ_512K }, |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 181 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 182 | }; |
| 183 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 184 | static irqreturn_t adreno_irq_handler(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 186 | irqreturn_t result; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 187 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 188 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 189 | result = adreno_dev->gpudev->irq_handler(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 190 | |
| 191 | if (device->requested_state == KGSL_STATE_NONE) { |
| 192 | if (device->pwrctrl.nap_allowed == true) { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 193 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 194 | queue_work(device->work_queue, &device->idle_check_ws); |
| 195 | } else if (device->pwrscale.policy != NULL) { |
| 196 | queue_work(device->work_queue, &device->idle_check_ws); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /* Reset the time-out in our idle timer */ |
Tarun Karra | 6875576 | 2012-01-12 16:07:09 -0800 | [diff] [blame] | 201 | mod_timer_pending(&device->idle_timer, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 202 | jiffies + device->pwrctrl.interval_timeout); |
| 203 | return result; |
| 204 | } |
| 205 | |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 206 | static void adreno_cleanup_pt(struct kgsl_device *device, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 207 | struct kgsl_pagetable *pagetable) |
| 208 | { |
| 209 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 210 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 211 | |
| 212 | kgsl_mmu_unmap(pagetable, &rb->buffer_desc); |
| 213 | |
| 214 | kgsl_mmu_unmap(pagetable, &rb->memptrs_desc); |
| 215 | |
| 216 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 217 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 218 | kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int adreno_setup_pt(struct kgsl_device *device, |
| 222 | struct kgsl_pagetable *pagetable) |
| 223 | { |
| 224 | int result = 0; |
| 225 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 226 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 227 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | result = kgsl_mmu_map_global(pagetable, &rb->buffer_desc, |
| 229 | GSL_PT_PAGE_RV); |
| 230 | if (result) |
| 231 | goto error; |
| 232 | |
| 233 | result = kgsl_mmu_map_global(pagetable, &rb->memptrs_desc, |
| 234 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 235 | if (result) |
| 236 | goto unmap_buffer_desc; |
| 237 | |
| 238 | result = kgsl_mmu_map_global(pagetable, &device->memstore, |
| 239 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 240 | if (result) |
| 241 | goto unmap_memptrs_desc; |
| 242 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 243 | result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 244 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 245 | if (result) |
| 246 | goto unmap_memstore_desc; |
| 247 | |
| 248 | return result; |
| 249 | |
| 250 | unmap_memstore_desc: |
| 251 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 252 | |
| 253 | unmap_memptrs_desc: |
| 254 | kgsl_mmu_unmap(pagetable, &rb->memptrs_desc); |
| 255 | |
| 256 | unmap_buffer_desc: |
| 257 | kgsl_mmu_unmap(pagetable, &rb->buffer_desc); |
| 258 | |
| 259 | error: |
| 260 | return result; |
| 261 | } |
| 262 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 263 | static void adreno_iommu_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 264 | unsigned int context_id, |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 265 | uint32_t flags) |
| 266 | { |
| 267 | unsigned int pt_val, reg_pt_val; |
| 268 | unsigned int link[200]; |
| 269 | unsigned int *cmds = &link[0]; |
| 270 | int sizedwords = 0; |
| 271 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 272 | struct kgsl_memdesc **reg_map_desc; |
Pu Chen | ed8cbb5 | 2012-06-04 18:18:48 -0700 | [diff] [blame] | 273 | void *reg_map_array = NULL; |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 274 | int num_iommu_units, i; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 275 | struct kgsl_context *context; |
| 276 | struct adreno_context *adreno_ctx = NULL; |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 277 | |
| 278 | if (!adreno_dev->drawctxt_active) |
| 279 | return kgsl_mmu_device_setstate(&device->mmu, flags); |
| 280 | num_iommu_units = kgsl_mmu_get_reg_map_desc(&device->mmu, |
| 281 | ®_map_array); |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 282 | |
| 283 | context = idr_find(&device->context_idr, context_id); |
| 284 | adreno_ctx = context->devctxt; |
| 285 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 286 | reg_map_desc = reg_map_array; |
| 287 | |
| 288 | if (kgsl_mmu_enable_clk(&device->mmu, |
| 289 | KGSL_IOMMU_CONTEXT_USER)) |
| 290 | goto done; |
| 291 | |
Shubhraprakash Das | 939c0d4 | 2012-06-15 11:40:48 -0600 | [diff] [blame] | 292 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 293 | device->mmu.setstate_memory.gpuaddr + |
| 294 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 295 | |
Shubhraprakash Das | 19ca4a6 | 2012-05-18 12:11:20 -0600 | [diff] [blame] | 296 | if (cpu_is_msm8960()) |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 297 | cmds += adreno_add_change_mh_phys_limit_cmds(cmds, 0xFFFFF000, |
| 298 | device->mmu.setstate_memory.gpuaddr + |
| 299 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 300 | else |
| 301 | cmds += adreno_add_bank_change_cmds(cmds, |
| 302 | KGSL_IOMMU_CONTEXT_USER, |
| 303 | device->mmu.setstate_memory.gpuaddr + |
| 304 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 305 | |
| 306 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
| 307 | pt_val = kgsl_mmu_pt_get_base_addr(device->mmu.hwpagetable); |
| 308 | /* |
| 309 | * We need to perfrom the following operations for all |
| 310 | * IOMMU units |
| 311 | */ |
| 312 | for (i = 0; i < num_iommu_units; i++) { |
| 313 | reg_pt_val = (pt_val & |
| 314 | (KGSL_IOMMU_TTBR0_PA_MASK << |
| 315 | KGSL_IOMMU_TTBR0_PA_SHIFT)) + |
| 316 | kgsl_mmu_get_pt_lsb(&device->mmu, i, |
| 317 | KGSL_IOMMU_CONTEXT_USER); |
| 318 | /* |
| 319 | * Set address of the new pagetable by writng to IOMMU |
| 320 | * TTBR0 register |
| 321 | */ |
| 322 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
| 323 | *cmds++ = reg_map_desc[i]->gpuaddr + |
| 324 | (KGSL_IOMMU_CONTEXT_USER << |
| 325 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_TTBR0; |
| 326 | *cmds++ = reg_pt_val; |
| 327 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 328 | *cmds++ = 0x00000000; |
| 329 | |
| 330 | /* |
| 331 | * Read back the ttbr0 register as a barrier to ensure |
| 332 | * above writes have completed |
| 333 | */ |
| 334 | cmds += adreno_add_read_cmds(device, cmds, |
| 335 | reg_map_desc[i]->gpuaddr + |
| 336 | (KGSL_IOMMU_CONTEXT_USER << |
| 337 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_TTBR0, |
| 338 | reg_pt_val, |
| 339 | device->mmu.setstate_memory.gpuaddr + |
| 340 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 341 | |
| 342 | /* set the asid */ |
| 343 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
| 344 | *cmds++ = reg_map_desc[i]->gpuaddr + |
| 345 | (KGSL_IOMMU_CONTEXT_USER << |
| 346 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_CONTEXTIDR; |
| 347 | *cmds++ = kgsl_mmu_get_hwpagetable_asid(&device->mmu); |
| 348 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 349 | *cmds++ = 0x00000000; |
| 350 | |
| 351 | /* Read back asid to ensure above write completes */ |
| 352 | cmds += adreno_add_read_cmds(device, cmds, |
| 353 | reg_map_desc[i]->gpuaddr + |
| 354 | (KGSL_IOMMU_CONTEXT_USER << |
| 355 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_CONTEXTIDR, |
| 356 | kgsl_mmu_get_hwpagetable_asid(&device->mmu), |
| 357 | device->mmu.setstate_memory.gpuaddr + |
| 358 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 359 | } |
| 360 | /* invalidate all base pointers */ |
| 361 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
| 362 | *cmds++ = 0x7fff; |
| 363 | |
Shubhraprakash Das | 939c0d4 | 2012-06-15 11:40:48 -0600 | [diff] [blame] | 364 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 365 | device->mmu.setstate_memory.gpuaddr + |
| 366 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 367 | } |
| 368 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 369 | /* |
| 370 | * tlb flush based on asid, no need to flush entire tlb |
| 371 | */ |
| 372 | for (i = 0; i < num_iommu_units; i++) { |
| 373 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
| 374 | *cmds++ = (reg_map_desc[i]->gpuaddr + |
| 375 | (KGSL_IOMMU_CONTEXT_USER << |
| 376 | KGSL_IOMMU_CTX_SHIFT) + |
| 377 | KGSL_IOMMU_CTX_TLBIASID); |
| 378 | *cmds++ = kgsl_mmu_get_hwpagetable_asid(&device->mmu); |
Shubhraprakash Das | be39728 | 2012-07-09 10:25:01 -0600 | [diff] [blame] | 379 | |
| 380 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 381 | device->mmu.setstate_memory.gpuaddr + |
| 382 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 383 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 384 | cmds += adreno_add_read_cmds(device, cmds, |
| 385 | reg_map_desc[i]->gpuaddr + |
| 386 | (KGSL_IOMMU_CONTEXT_USER << |
| 387 | KGSL_IOMMU_CTX_SHIFT) + |
| 388 | KGSL_IOMMU_CONTEXTIDR, |
| 389 | kgsl_mmu_get_hwpagetable_asid(&device->mmu), |
| 390 | device->mmu.setstate_memory.gpuaddr + |
| 391 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 392 | } |
| 393 | } |
| 394 | |
Shubhraprakash Das | 19ca4a6 | 2012-05-18 12:11:20 -0600 | [diff] [blame] | 395 | if (cpu_is_msm8960()) |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 396 | cmds += adreno_add_change_mh_phys_limit_cmds(cmds, |
| 397 | reg_map_desc[num_iommu_units - 1]->gpuaddr - PAGE_SIZE, |
| 398 | device->mmu.setstate_memory.gpuaddr + |
| 399 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 400 | else |
| 401 | cmds += adreno_add_bank_change_cmds(cmds, |
| 402 | KGSL_IOMMU_CONTEXT_PRIV, |
| 403 | device->mmu.setstate_memory.gpuaddr + |
| 404 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 405 | |
| 406 | sizedwords += (cmds - &link[0]); |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 407 | if (sizedwords) { |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 408 | /* |
| 409 | * add an interrupt at the end of commands so that the smmu |
| 410 | * disable clock off function will get called |
| 411 | */ |
| 412 | *cmds++ = cp_type3_packet(CP_INTERRUPT, 1); |
| 413 | *cmds++ = CP_INT_CNTL__RB_INT_MASK; |
| 414 | sizedwords += 2; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 415 | /* This returns the per context timestamp but we need to |
| 416 | * use the global timestamp for iommu clock disablement */ |
| 417 | adreno_ringbuffer_issuecmds(device, adreno_ctx, |
| 418 | KGSL_CMD_FLAGS_PMODE, |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 419 | &link[0], sizedwords); |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 420 | kgsl_mmu_disable_clk_on_ts(&device->mmu, |
| 421 | adreno_dev->ringbuffer.timestamp[KGSL_MEMSTORE_GLOBAL], true); |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 422 | } |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 423 | done: |
| 424 | if (num_iommu_units) |
| 425 | kfree(reg_map_array); |
| 426 | } |
| 427 | |
| 428 | static void adreno_gpummu_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 429 | unsigned int context_id, |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 430 | uint32_t flags) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 431 | { |
| 432 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 433 | unsigned int link[32]; |
| 434 | unsigned int *cmds = &link[0]; |
| 435 | int sizedwords = 0; |
| 436 | unsigned int mh_mmu_invalidate = 0x00000003; /*invalidate all and tc */ |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 437 | struct kgsl_context *context; |
| 438 | struct adreno_context *adreno_ctx = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 439 | |
Jeremy Gebben | a3d07a4 | 2011-10-17 12:08:16 -0600 | [diff] [blame] | 440 | /* |
Rajesh Kemisetti | 22a06d1 | 2012-06-29 20:21:31 +0530 | [diff] [blame] | 441 | * Fix target freeze issue by adding TLB flush for each submit |
| 442 | * on A20X based targets. |
| 443 | */ |
| 444 | if (adreno_is_a20x(adreno_dev)) |
| 445 | flags |= KGSL_MMUFLAGS_TLBFLUSH; |
| 446 | /* |
Jeremy Gebben | a3d07a4 | 2011-10-17 12:08:16 -0600 | [diff] [blame] | 447 | * If possible, then set the state via the command stream to avoid |
| 448 | * a CPU idle. Otherwise, use the default setstate which uses register |
| 449 | * writes For CFF dump we must idle and use the registers so that it is |
| 450 | * easier to filter out the mmu accesses from the dump |
| 451 | */ |
| 452 | if (!kgsl_cff_dump_enable && adreno_dev->drawctxt_active) { |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 453 | context = idr_find(&device->context_idr, context_id); |
| 454 | adreno_ctx = context->devctxt; |
| 455 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 456 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
| 457 | /* wait for graphics pipe to be idle */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 458 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 459 | *cmds++ = 0x00000000; |
| 460 | |
| 461 | /* set page table base */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 462 | *cmds++ = cp_type0_packet(MH_MMU_PT_BASE, 1); |
Shubhraprakash Das | 5a610b5 | 2012-05-09 17:31:54 -0600 | [diff] [blame] | 463 | *cmds++ = kgsl_mmu_pt_get_base_addr( |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 464 | device->mmu.hwpagetable); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 465 | sizedwords += 4; |
| 466 | } |
| 467 | |
| 468 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 469 | if (!(flags & KGSL_MMUFLAGS_PTUPDATE)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 470 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 471 | 1); |
| 472 | *cmds++ = 0x00000000; |
| 473 | sizedwords += 2; |
| 474 | } |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 475 | *cmds++ = cp_type0_packet(MH_MMU_INVALIDATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 476 | *cmds++ = mh_mmu_invalidate; |
| 477 | sizedwords += 2; |
| 478 | } |
| 479 | |
| 480 | if (flags & KGSL_MMUFLAGS_PTUPDATE && |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 481 | adreno_is_a20x(adreno_dev)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 482 | /* HW workaround: to resolve MMU page fault interrupts |
| 483 | * caused by the VGT.It prevents the CP PFP from filling |
| 484 | * the VGT DMA request fifo too early,thereby ensuring |
| 485 | * that the VGT will not fetch vertex/bin data until |
| 486 | * after the page table base register has been updated. |
| 487 | * |
| 488 | * Two null DRAW_INDX_BIN packets are inserted right |
| 489 | * after the page table base update, followed by a |
| 490 | * wait for idle. The null packets will fill up the |
| 491 | * VGT DMA request fifo and prevent any further |
| 492 | * vertex/bin updates from occurring until the wait |
| 493 | * has finished. */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 494 | *cmds++ = cp_type3_packet(CP_SET_CONSTANT, 2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 495 | *cmds++ = (0x4 << 16) | |
| 496 | (REG_PA_SU_SC_MODE_CNTL - 0x2000); |
| 497 | *cmds++ = 0; /* disable faceness generation */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 498 | *cmds++ = cp_type3_packet(CP_SET_BIN_BASE_OFFSET, 1); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 499 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 500 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 501 | *cmds++ = 0; /* viz query info */ |
| 502 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 503 | *cmds++ = 0; /* bin base */ |
| 504 | *cmds++ = 3; /* bin size */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 505 | *cmds++ = |
| 506 | device->mmu.setstate_memory.gpuaddr; /* dma base */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 507 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 508 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 509 | *cmds++ = 0; /* viz query info */ |
| 510 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 511 | *cmds++ = 0; /* bin base */ |
| 512 | *cmds++ = 3; /* bin size */ |
| 513 | /* dma base */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 514 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 515 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 516 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 517 | *cmds++ = 0x00000000; |
| 518 | sizedwords += 21; |
| 519 | } |
| 520 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 521 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 522 | if (flags & (KGSL_MMUFLAGS_PTUPDATE | KGSL_MMUFLAGS_TLBFLUSH)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 523 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | *cmds++ = 0x7fff; /* invalidate all base pointers */ |
| 525 | sizedwords += 2; |
| 526 | } |
| 527 | |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 528 | adreno_ringbuffer_issuecmds(device, adreno_ctx, |
| 529 | KGSL_CMD_FLAGS_PMODE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 530 | &link[0], sizedwords); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 531 | } else { |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 532 | kgsl_mmu_device_setstate(&device->mmu, flags); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 533 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 536 | static void adreno_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 537 | unsigned int context_id, |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 538 | uint32_t flags) |
| 539 | { |
| 540 | /* call the mmu specific handler */ |
| 541 | if (KGSL_MMU_TYPE_GPU == kgsl_mmu_get_mmutype()) |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 542 | return adreno_gpummu_setstate(device, context_id, flags); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 543 | else if (KGSL_MMU_TYPE_IOMMU == kgsl_mmu_get_mmutype()) |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 544 | return adreno_iommu_setstate(device, context_id, flags); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 545 | } |
| 546 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 547 | static unsigned int |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 548 | a3xx_getchipid(struct kgsl_device *device) |
| 549 | { |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 550 | struct kgsl_device_platform_data *pdata = |
| 551 | kgsl_device_get_drvdata(device); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 552 | |
Jordan Crouse | 54154c6 | 2012-03-27 16:33:26 -0600 | [diff] [blame] | 553 | /* |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 554 | * All current A3XX chipids are detected at the SOC level. Leave this |
| 555 | * function here to support any future GPUs that have working |
| 556 | * chip ID registers |
Jordan Crouse | 54154c6 | 2012-03-27 16:33:26 -0600 | [diff] [blame] | 557 | */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 558 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 559 | return pdata->chipid; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static unsigned int |
| 563 | a2xx_getchipid(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | { |
| 565 | unsigned int chipid = 0; |
| 566 | unsigned int coreid, majorid, minorid, patchid, revid; |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 567 | struct kgsl_device_platform_data *pdata = |
| 568 | kgsl_device_get_drvdata(device); |
| 569 | |
| 570 | /* If the chip id is set at the platform level, then just use that */ |
| 571 | |
| 572 | if (pdata->chipid != 0) |
| 573 | return pdata->chipid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 574 | |
| 575 | adreno_regread(device, REG_RBBM_PERIPHID1, &coreid); |
| 576 | adreno_regread(device, REG_RBBM_PERIPHID2, &majorid); |
| 577 | adreno_regread(device, REG_RBBM_PATCH_RELEASE, &revid); |
| 578 | |
| 579 | /* |
| 580 | * adreno 22x gpus are indicated by coreid 2, |
| 581 | * but REG_RBBM_PERIPHID1 always contains 0 for this field |
| 582 | */ |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 583 | if (cpu_is_msm8x60()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 584 | chipid = 2 << 24; |
| 585 | else |
| 586 | chipid = (coreid & 0xF) << 24; |
| 587 | |
| 588 | chipid |= ((majorid >> 4) & 0xF) << 16; |
| 589 | |
| 590 | minorid = ((revid >> 0) & 0xFF); |
| 591 | |
| 592 | patchid = ((revid >> 16) & 0xFF); |
| 593 | |
| 594 | /* 8x50 returns 0 for patch release, but it should be 1 */ |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 595 | /* 8x25 returns 0 for minor id, but it should be 1 */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 596 | if (cpu_is_qsd8x50()) |
| 597 | patchid = 1; |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 598 | else if (cpu_is_msm8625() && minorid == 0) |
| 599 | minorid = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 600 | |
| 601 | chipid |= (minorid << 8) | patchid; |
| 602 | |
| 603 | return chipid; |
| 604 | } |
| 605 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 606 | static unsigned int |
| 607 | adreno_getchipid(struct kgsl_device *device) |
| 608 | { |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 609 | struct kgsl_device_platform_data *pdata = |
| 610 | kgsl_device_get_drvdata(device); |
| 611 | |
| 612 | /* |
| 613 | * All A3XX chipsets will have pdata set, so assume !pdata->chipid is |
| 614 | * an A2XX processor |
| 615 | */ |
| 616 | |
| 617 | if (pdata->chipid == 0 || ADRENO_CHIPID_MAJOR(pdata->chipid) == 2) |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 618 | return a2xx_getchipid(device); |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 619 | else |
| 620 | return a3xx_getchipid(device); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 623 | static inline bool _rev_match(unsigned int id, unsigned int entry) |
| 624 | { |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 625 | return (entry == ANY_ID || entry == id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 626 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 627 | |
| 628 | static void |
| 629 | adreno_identify_gpu(struct adreno_device *adreno_dev) |
| 630 | { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 631 | unsigned int i, core, major, minor, patchid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 632 | |
| 633 | adreno_dev->chip_id = adreno_getchipid(&adreno_dev->dev); |
| 634 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 635 | core = ADRENO_CHIPID_CORE(adreno_dev->chip_id); |
| 636 | major = ADRENO_CHIPID_MAJOR(adreno_dev->chip_id); |
| 637 | minor = ADRENO_CHIPID_MINOR(adreno_dev->chip_id); |
| 638 | patchid = ADRENO_CHIPID_PATCH(adreno_dev->chip_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 639 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 640 | for (i = 0; i < ARRAY_SIZE(adreno_gpulist); i++) { |
| 641 | if (core == adreno_gpulist[i].core && |
| 642 | _rev_match(major, adreno_gpulist[i].major) && |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 643 | _rev_match(minor, adreno_gpulist[i].minor) && |
| 644 | _rev_match(patchid, adreno_gpulist[i].patchid)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 645 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 648 | if (i == ARRAY_SIZE(adreno_gpulist)) { |
| 649 | adreno_dev->gpurev = ADRENO_REV_UNKNOWN; |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | adreno_dev->gpurev = adreno_gpulist[i].gpurev; |
| 654 | adreno_dev->gpudev = adreno_gpulist[i].gpudev; |
| 655 | adreno_dev->pfp_fwfile = adreno_gpulist[i].pfpfw; |
| 656 | adreno_dev->pm4_fwfile = adreno_gpulist[i].pm4fw; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 657 | adreno_dev->istore_size = adreno_gpulist[i].istore_size; |
| 658 | adreno_dev->pix_shader_start = adreno_gpulist[i].pix_shader_start; |
Jordan Crouse | 55d98fd | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 659 | adreno_dev->instruction_size = adreno_gpulist[i].instruction_size; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 660 | adreno_dev->gmem_size = adreno_gpulist[i].gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static int __devinit |
| 664 | adreno_probe(struct platform_device *pdev) |
| 665 | { |
| 666 | struct kgsl_device *device; |
| 667 | struct adreno_device *adreno_dev; |
| 668 | int status = -EINVAL; |
| 669 | |
| 670 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 671 | adreno_dev = ADRENO_DEVICE(device); |
| 672 | device->parentdev = &pdev->dev; |
| 673 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 674 | status = adreno_ringbuffer_init(device); |
| 675 | if (status != 0) |
| 676 | goto error; |
| 677 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 678 | status = kgsl_device_platform_probe(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 679 | if (status) |
| 680 | goto error_close_rb; |
| 681 | |
| 682 | adreno_debugfs_init(device); |
| 683 | |
| 684 | kgsl_pwrscale_init(device); |
| 685 | kgsl_pwrscale_attach_policy(device, ADRENO_DEFAULT_PWRSCALE_POLICY); |
| 686 | |
| 687 | device->flags &= ~KGSL_FLAGS_SOFT_RESET; |
| 688 | return 0; |
| 689 | |
| 690 | error_close_rb: |
| 691 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 692 | error: |
| 693 | device->parentdev = NULL; |
| 694 | return status; |
| 695 | } |
| 696 | |
| 697 | static int __devexit adreno_remove(struct platform_device *pdev) |
| 698 | { |
| 699 | struct kgsl_device *device; |
| 700 | struct adreno_device *adreno_dev; |
| 701 | |
| 702 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 703 | adreno_dev = ADRENO_DEVICE(device); |
| 704 | |
| 705 | kgsl_pwrscale_detach_policy(device); |
| 706 | kgsl_pwrscale_close(device); |
| 707 | |
| 708 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 709 | kgsl_device_platform_remove(device); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static int adreno_start(struct kgsl_device *device, unsigned int init_ram) |
| 715 | { |
| 716 | int status = -EINVAL; |
| 717 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 718 | |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 719 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state) |
| 720 | kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 721 | |
| 722 | /* Power up the device */ |
| 723 | kgsl_pwrctrl_enable(device); |
| 724 | |
| 725 | /* Identify the specific GPU */ |
| 726 | adreno_identify_gpu(adreno_dev); |
| 727 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 728 | if (adreno_dev->gpurev == ADRENO_REV_UNKNOWN) { |
| 729 | KGSL_DRV_ERR(device, "Unknown chip ID %x\n", |
| 730 | adreno_dev->chip_id); |
| 731 | goto error_clk_off; |
| 732 | } |
| 733 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 734 | /* Set up the MMU */ |
| 735 | if (adreno_is_a2xx(adreno_dev)) { |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 736 | /* |
| 737 | * the MH_CLNT_INTF_CTRL_CONFIG registers aren't present |
| 738 | * on older gpus |
| 739 | */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 740 | if (adreno_is_a20x(adreno_dev)) { |
| 741 | device->mh.mh_intf_cfg1 = 0; |
| 742 | device->mh.mh_intf_cfg2 = 0; |
| 743 | } |
| 744 | |
| 745 | kgsl_mh_start(device); |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 746 | } |
| 747 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 748 | /* Assign correct RBBM status register to hang detect regs |
| 749 | */ |
| 750 | hang_detect_regs[0] = adreno_dev->gpudev->reg_rbbm_status; |
| 751 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 752 | status = kgsl_mmu_start(device); |
| 753 | if (status) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 754 | goto error_clk_off; |
| 755 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 756 | /* Start the GPU */ |
| 757 | adreno_dev->gpudev->start(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 758 | |
| 759 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 760 | device->ftbl->irqctrl(device, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 761 | |
| 762 | status = adreno_ringbuffer_start(&adreno_dev->ringbuffer, init_ram); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 763 | if (status == 0) { |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 764 | /* While recovery is on we do not want timer to |
| 765 | * fire and attempt to change any device state */ |
| 766 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state) |
| 767 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 768 | return 0; |
| 769 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 770 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 771 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 772 | kgsl_mmu_stop(&device->mmu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | error_clk_off: |
| 774 | kgsl_pwrctrl_disable(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 775 | |
| 776 | return status; |
| 777 | } |
| 778 | |
| 779 | static int adreno_stop(struct kgsl_device *device) |
| 780 | { |
| 781 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 782 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 783 | adreno_dev->drawctxt_active = NULL; |
| 784 | |
| 785 | adreno_ringbuffer_stop(&adreno_dev->ringbuffer); |
| 786 | |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 787 | kgsl_mmu_stop(&device->mmu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 788 | |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 789 | device->ftbl->irqctrl(device, 0); |
Ranjhith Kalisamy | ce75b0c | 2012-02-01 19:31:23 +0530 | [diff] [blame] | 790 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Suman Tatiraju | 4a32c65 | 2012-02-17 11:59:05 -0800 | [diff] [blame] | 791 | del_timer_sync(&device->idle_timer); |
Lucille Sylvester | 844b1c8 | 2011-08-29 15:26:06 -0600 | [diff] [blame] | 792 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 793 | /* Power down the device */ |
| 794 | kgsl_pwrctrl_disable(device); |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
Shubhraprakash Das | 29ed38e | 2012-06-06 01:43:55 -0600 | [diff] [blame] | 799 | static void adreno_mark_context_status(struct kgsl_device *device, |
| 800 | int recovery_status) |
| 801 | { |
| 802 | struct kgsl_context *context; |
| 803 | int next = 0; |
| 804 | /* |
| 805 | * Set the reset status of all contexts to |
| 806 | * INNOCENT_CONTEXT_RESET_EXT except for the bad context |
| 807 | * since thats the guilty party, if recovery failed then |
| 808 | * mark all as guilty |
| 809 | */ |
| 810 | while ((context = idr_get_next(&device->context_idr, &next))) { |
| 811 | struct adreno_context *adreno_context = context->devctxt; |
| 812 | if (recovery_status) { |
| 813 | context->reset_status = |
| 814 | KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; |
| 815 | adreno_context->flags |= CTXT_FLAGS_GPU_HANG; |
| 816 | } else if (KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT != |
| 817 | context->reset_status) { |
| 818 | if (adreno_context->flags & (CTXT_FLAGS_GPU_HANG || |
| 819 | CTXT_FLAGS_GPU_HANG_RECOVERED)) |
| 820 | context->reset_status = |
| 821 | KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; |
| 822 | else |
| 823 | context->reset_status = |
| 824 | KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT; |
| 825 | } |
| 826 | next = next + 1; |
| 827 | } |
| 828 | } |
| 829 | |
Shubhraprakash Das | 5f085f4 | 2012-06-06 02:01:24 -0600 | [diff] [blame] | 830 | static void adreno_set_max_ts_for_bad_ctxs(struct kgsl_device *device) |
| 831 | { |
| 832 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 833 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 834 | struct kgsl_context *context; |
| 835 | struct adreno_context *temp_adreno_context; |
| 836 | int next = 0; |
| 837 | |
| 838 | while ((context = idr_get_next(&device->context_idr, &next))) { |
| 839 | temp_adreno_context = context->devctxt; |
| 840 | if (temp_adreno_context->flags & CTXT_FLAGS_GPU_HANG) { |
| 841 | kgsl_sharedmem_writel(&device->memstore, |
| 842 | KGSL_MEMSTORE_OFFSET(context->id, |
| 843 | soptimestamp), |
| 844 | rb->timestamp[context->id]); |
| 845 | kgsl_sharedmem_writel(&device->memstore, |
| 846 | KGSL_MEMSTORE_OFFSET(context->id, |
| 847 | eoptimestamp), |
| 848 | rb->timestamp[context->id]); |
| 849 | } |
| 850 | next = next + 1; |
| 851 | } |
| 852 | } |
| 853 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 854 | static void adreno_destroy_recovery_data(struct adreno_recovery_data *rec_data) |
| 855 | { |
| 856 | vfree(rec_data->rb_buffer); |
| 857 | vfree(rec_data->bad_rb_buffer); |
| 858 | } |
| 859 | |
| 860 | static int adreno_setup_recovery_data(struct kgsl_device *device, |
| 861 | struct adreno_recovery_data *rec_data) |
| 862 | { |
| 863 | int ret = 0; |
| 864 | unsigned int ib1_sz, ib2_sz; |
| 865 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 866 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 867 | |
| 868 | memset(rec_data, 0, sizeof(*rec_data)); |
| 869 | |
| 870 | adreno_regread(device, REG_CP_IB1_BUFSZ, &ib1_sz); |
| 871 | adreno_regread(device, REG_CP_IB2_BUFSZ, &ib2_sz); |
| 872 | if (ib1_sz || ib2_sz) |
| 873 | adreno_regread(device, REG_CP_IB1_BASE, &rec_data->ib1); |
| 874 | |
| 875 | kgsl_sharedmem_readl(&device->memstore, &rec_data->context_id, |
| 876 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 877 | current_context)); |
| 878 | |
| 879 | kgsl_sharedmem_readl(&device->memstore, |
| 880 | &rec_data->global_eop, |
| 881 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 882 | eoptimestamp)); |
| 883 | |
| 884 | rec_data->rb_buffer = vmalloc(rb->buffer_desc.size); |
| 885 | if (!rec_data->rb_buffer) { |
| 886 | KGSL_MEM_ERR(device, "vmalloc(%d) failed\n", |
| 887 | rb->buffer_desc.size); |
| 888 | return -ENOMEM; |
| 889 | } |
| 890 | |
| 891 | rec_data->bad_rb_buffer = vmalloc(rb->buffer_desc.size); |
| 892 | if (!rec_data->bad_rb_buffer) { |
| 893 | KGSL_MEM_ERR(device, "vmalloc(%d) failed\n", |
| 894 | rb->buffer_desc.size); |
| 895 | ret = -ENOMEM; |
| 896 | goto done; |
| 897 | } |
| 898 | |
| 899 | done: |
| 900 | if (ret) { |
| 901 | vfree(rec_data->rb_buffer); |
| 902 | vfree(rec_data->bad_rb_buffer); |
| 903 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 904 | return ret; |
| 905 | } |
| 906 | |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame^] | 907 | static int |
| 908 | _adreno_recover_hang(struct kgsl_device *device, |
| 909 | struct adreno_recovery_data *rec_data, |
| 910 | bool try_bad_commands) |
| 911 | { |
| 912 | int ret; |
| 913 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 914 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 915 | struct kgsl_context *context; |
| 916 | struct adreno_context *adreno_context = NULL; |
| 917 | struct adreno_context *last_active_ctx = adreno_dev->drawctxt_active; |
| 918 | |
| 919 | context = idr_find(&device->context_idr, rec_data->context_id); |
| 920 | if (context == NULL) { |
| 921 | KGSL_DRV_ERR(device, "Last context unknown id:%d\n", |
| 922 | rec_data->context_id); |
| 923 | } else { |
| 924 | adreno_context = context->devctxt; |
| 925 | adreno_context->flags |= CTXT_FLAGS_GPU_HANG; |
| 926 | } |
| 927 | |
| 928 | /* Extract valid contents from rb which can still be executed after |
| 929 | * hang */ |
| 930 | ret = adreno_ringbuffer_extract(rb, rec_data); |
| 931 | if (ret) |
| 932 | goto done; |
| 933 | |
| 934 | /* restart device */ |
| 935 | ret = adreno_stop(device); |
| 936 | if (ret) { |
| 937 | KGSL_DRV_ERR(device, "Device stop failed in recovery\n"); |
| 938 | goto done; |
| 939 | } |
| 940 | |
| 941 | ret = adreno_start(device, true); |
| 942 | if (ret) { |
| 943 | KGSL_DRV_ERR(device, "Device start failed in recovery\n"); |
| 944 | goto done; |
| 945 | } |
| 946 | |
| 947 | if (context) |
| 948 | kgsl_mmu_setstate(&device->mmu, adreno_context->pagetable, |
| 949 | KGSL_MEMSTORE_GLOBAL); |
| 950 | |
| 951 | /* Do not try the bad caommands if recovery has failed bad commands |
| 952 | * once already */ |
| 953 | if (!try_bad_commands) |
| 954 | rec_data->bad_rb_size = 0; |
| 955 | |
| 956 | if (rec_data->bad_rb_size) { |
| 957 | int idle_ret; |
| 958 | /* submit the bad and good context commands and wait for |
| 959 | * them to pass */ |
| 960 | adreno_ringbuffer_restore(rb, rec_data->bad_rb_buffer, |
| 961 | rec_data->bad_rb_size); |
| 962 | idle_ret = adreno_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 963 | if (idle_ret) { |
| 964 | ret = adreno_stop(device); |
| 965 | if (ret) { |
| 966 | KGSL_DRV_ERR(device, |
| 967 | "Device stop failed in recovery\n"); |
| 968 | goto done; |
| 969 | } |
| 970 | ret = adreno_start(device, true); |
| 971 | if (ret) { |
| 972 | KGSL_DRV_ERR(device, |
| 973 | "Device start failed in recovery\n"); |
| 974 | goto done; |
| 975 | } |
| 976 | ret = idle_ret; |
| 977 | KGSL_DRV_ERR(device, |
| 978 | "Bad context commands hung in recovery\n"); |
| 979 | } else { |
| 980 | KGSL_DRV_ERR(device, |
| 981 | "Bad context commands succeeded in recovery\n"); |
| 982 | if (adreno_context) |
| 983 | adreno_context->flags = (adreno_context->flags & |
| 984 | ~CTXT_FLAGS_GPU_HANG) | |
| 985 | CTXT_FLAGS_GPU_HANG_RECOVERED; |
| 986 | adreno_dev->drawctxt_active = last_active_ctx; |
| 987 | } |
| 988 | } |
| 989 | /* If either the bad command sequence failed or we did not play it */ |
| 990 | if (ret || !rec_data->bad_rb_size) { |
| 991 | adreno_ringbuffer_restore(rb, rec_data->rb_buffer, |
| 992 | rec_data->rb_size); |
| 993 | ret = adreno_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 994 | if (ret) { |
| 995 | /* If we fail here we can try to invalidate another |
| 996 | * context and try recovering again */ |
| 997 | ret = -EAGAIN; |
| 998 | goto done; |
| 999 | } |
| 1000 | /* ringbuffer now has data from the last valid context id, |
| 1001 | * so restore the active_ctx to the last valid context */ |
| 1002 | if (rec_data->last_valid_ctx_id) { |
| 1003 | struct kgsl_context *last_ctx = |
| 1004 | idr_find(&device->context_idr, |
| 1005 | rec_data->last_valid_ctx_id); |
| 1006 | if (last_ctx) |
| 1007 | adreno_dev->drawctxt_active = last_ctx->devctxt; |
| 1008 | } |
| 1009 | } |
| 1010 | done: |
| 1011 | return ret; |
| 1012 | } |
| 1013 | |
| 1014 | static int |
| 1015 | adreno_recover_hang(struct kgsl_device *device, |
| 1016 | struct adreno_recovery_data *rec_data) |
| 1017 | { |
| 1018 | int ret = 0; |
| 1019 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1020 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1021 | unsigned int timestamp; |
| 1022 | |
| 1023 | KGSL_DRV_ERR(device, |
| 1024 | "Starting recovery from 3D GPU hang. Recovery parameters: IB1: 0x%X, " |
| 1025 | "Bad context_id: %u, global_eop: 0x%x\n", |
| 1026 | rec_data->ib1, rec_data->context_id, rec_data->global_eop); |
| 1027 | |
| 1028 | timestamp = rb->timestamp[KGSL_MEMSTORE_GLOBAL]; |
| 1029 | KGSL_DRV_ERR(device, "Last issued global timestamp: %x\n", timestamp); |
| 1030 | |
| 1031 | /* We may need to replay commands multiple times based on whether |
| 1032 | * multiple contexts hang the GPU */ |
| 1033 | while (true) { |
| 1034 | if (!ret) |
| 1035 | ret = _adreno_recover_hang(device, rec_data, true); |
| 1036 | else |
| 1037 | ret = _adreno_recover_hang(device, rec_data, false); |
| 1038 | |
| 1039 | if (-EAGAIN == ret) { |
| 1040 | /* setup new recovery parameters and retry, this |
| 1041 | * means more than 1 contexts are causing hang */ |
| 1042 | adreno_destroy_recovery_data(rec_data); |
| 1043 | adreno_setup_recovery_data(device, rec_data); |
| 1044 | KGSL_DRV_ERR(device, |
| 1045 | "Retry recovery from 3D GPU hang. Recovery parameters: " |
| 1046 | "IB1: 0x%X, Bad context_id: %u, global_eop: 0x%x\n", |
| 1047 | rec_data->ib1, rec_data->context_id, |
| 1048 | rec_data->global_eop); |
| 1049 | } else { |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | if (ret) |
| 1055 | goto done; |
| 1056 | |
| 1057 | /* Restore correct states after recovery */ |
| 1058 | if (adreno_dev->drawctxt_active) |
| 1059 | device->mmu.hwpagetable = |
| 1060 | adreno_dev->drawctxt_active->pagetable; |
| 1061 | else |
| 1062 | device->mmu.hwpagetable = device->mmu.defaultpagetable; |
| 1063 | rb->timestamp[KGSL_MEMSTORE_GLOBAL] = timestamp; |
| 1064 | kgsl_sharedmem_writel(&device->memstore, |
| 1065 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 1066 | eoptimestamp), |
| 1067 | rb->timestamp[KGSL_MEMSTORE_GLOBAL]); |
| 1068 | done: |
| 1069 | adreno_set_max_ts_for_bad_ctxs(device); |
| 1070 | adreno_mark_context_status(device, ret); |
| 1071 | if (!ret) |
| 1072 | KGSL_DRV_ERR(device, "Recovery succeeded\n"); |
| 1073 | else |
| 1074 | KGSL_DRV_ERR(device, "Recovery failed\n"); |
| 1075 | return ret; |
| 1076 | } |
| 1077 | |
| 1078 | int |
| 1079 | adreno_dump_and_recover(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1080 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1081 | int result = -ETIMEDOUT; |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1082 | struct adreno_recovery_data rec_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1083 | |
| 1084 | if (device->state == KGSL_STATE_HUNG) |
| 1085 | goto done; |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1086 | if (device->state == KGSL_STATE_DUMP_AND_RECOVER) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1087 | mutex_unlock(&device->mutex); |
| 1088 | wait_for_completion(&device->recovery_gate); |
| 1089 | mutex_lock(&device->mutex); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1090 | if (device->state != KGSL_STATE_HUNG) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1091 | result = 0; |
| 1092 | } else { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1093 | kgsl_pwrctrl_set_state(device, KGSL_STATE_DUMP_AND_RECOVER); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1094 | INIT_COMPLETION(device->recovery_gate); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1095 | /* Detected a hang */ |
| 1096 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1097 | /* Get the recovery data as soon as hang is detected */ |
| 1098 | result = adreno_setup_recovery_data(device, &rec_data); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1099 | /* |
| 1100 | * Trigger an automatic dump of the state to |
| 1101 | * the console |
| 1102 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1103 | adreno_postmortem_dump(device, 0); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1104 | |
| 1105 | /* |
| 1106 | * Make a GPU snapshot. For now, do it after the PM dump so we |
| 1107 | * can at least be sure the PM dump will work as it always has |
| 1108 | */ |
| 1109 | kgsl_device_snapshot(device, 1); |
| 1110 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1111 | result = adreno_recover_hang(device, &rec_data); |
| 1112 | adreno_destroy_recovery_data(&rec_data); |
Shubhraprakash Das | df60930 | 2012-06-06 20:02:58 -0600 | [diff] [blame] | 1113 | if (result) { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1114 | kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG); |
Shubhraprakash Das | df60930 | 2012-06-06 20:02:58 -0600 | [diff] [blame] | 1115 | } else { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1116 | kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); |
Shubhraprakash Das | df60930 | 2012-06-06 20:02:58 -0600 | [diff] [blame] | 1117 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
| 1118 | } |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1119 | complete_all(&device->recovery_gate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1120 | } |
| 1121 | done: |
| 1122 | return result; |
| 1123 | } |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 1124 | EXPORT_SYMBOL(adreno_dump_and_recover); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1125 | |
| 1126 | static int adreno_getproperty(struct kgsl_device *device, |
| 1127 | enum kgsl_property_type type, |
| 1128 | void *value, |
| 1129 | unsigned int sizebytes) |
| 1130 | { |
| 1131 | int status = -EINVAL; |
| 1132 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1133 | |
| 1134 | switch (type) { |
| 1135 | case KGSL_PROP_DEVICE_INFO: |
| 1136 | { |
| 1137 | struct kgsl_devinfo devinfo; |
| 1138 | |
| 1139 | if (sizebytes != sizeof(devinfo)) { |
| 1140 | status = -EINVAL; |
| 1141 | break; |
| 1142 | } |
| 1143 | |
| 1144 | memset(&devinfo, 0, sizeof(devinfo)); |
| 1145 | devinfo.device_id = device->id+1; |
| 1146 | devinfo.chip_id = adreno_dev->chip_id; |
| 1147 | devinfo.mmu_enabled = kgsl_mmu_enabled(); |
| 1148 | devinfo.gpu_id = adreno_dev->gpurev; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1149 | devinfo.gmem_gpubaseaddr = adreno_dev->gmem_base; |
| 1150 | devinfo.gmem_sizebytes = adreno_dev->gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1151 | |
| 1152 | if (copy_to_user(value, &devinfo, sizeof(devinfo)) != |
| 1153 | 0) { |
| 1154 | status = -EFAULT; |
| 1155 | break; |
| 1156 | } |
| 1157 | status = 0; |
| 1158 | } |
| 1159 | break; |
| 1160 | case KGSL_PROP_DEVICE_SHADOW: |
| 1161 | { |
| 1162 | struct kgsl_shadowprop shadowprop; |
| 1163 | |
| 1164 | if (sizebytes != sizeof(shadowprop)) { |
| 1165 | status = -EINVAL; |
| 1166 | break; |
| 1167 | } |
| 1168 | memset(&shadowprop, 0, sizeof(shadowprop)); |
| 1169 | if (device->memstore.hostptr) { |
| 1170 | /*NOTE: with mmu enabled, gpuaddr doesn't mean |
| 1171 | * anything to mmap(). |
| 1172 | */ |
| 1173 | shadowprop.gpuaddr = device->memstore.physaddr; |
| 1174 | shadowprop.size = device->memstore.size; |
| 1175 | /* GSL needs this to be set, even if it |
| 1176 | appears to be meaningless */ |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1177 | shadowprop.flags = KGSL_FLAGS_INITIALIZED | |
| 1178 | KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1179 | } |
| 1180 | if (copy_to_user(value, &shadowprop, |
| 1181 | sizeof(shadowprop))) { |
| 1182 | status = -EFAULT; |
| 1183 | break; |
| 1184 | } |
| 1185 | status = 0; |
| 1186 | } |
| 1187 | break; |
| 1188 | case KGSL_PROP_MMU_ENABLE: |
| 1189 | { |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 1190 | int mmu_prop = kgsl_mmu_enabled(); |
| 1191 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1192 | if (sizebytes != sizeof(int)) { |
| 1193 | status = -EINVAL; |
| 1194 | break; |
| 1195 | } |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 1196 | if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1197 | status = -EFAULT; |
| 1198 | break; |
| 1199 | } |
| 1200 | status = 0; |
| 1201 | } |
| 1202 | break; |
| 1203 | case KGSL_PROP_INTERRUPT_WAITS: |
| 1204 | { |
| 1205 | int int_waits = 1; |
| 1206 | if (sizebytes != sizeof(int)) { |
| 1207 | status = -EINVAL; |
| 1208 | break; |
| 1209 | } |
| 1210 | if (copy_to_user(value, &int_waits, sizeof(int))) { |
| 1211 | status = -EFAULT; |
| 1212 | break; |
| 1213 | } |
| 1214 | status = 0; |
| 1215 | } |
| 1216 | break; |
| 1217 | default: |
| 1218 | status = -EINVAL; |
| 1219 | } |
| 1220 | |
| 1221 | return status; |
| 1222 | } |
| 1223 | |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 1224 | static int adreno_setproperty(struct kgsl_device *device, |
| 1225 | enum kgsl_property_type type, |
| 1226 | void *value, |
| 1227 | unsigned int sizebytes) |
| 1228 | { |
| 1229 | int status = -EINVAL; |
| 1230 | |
| 1231 | switch (type) { |
| 1232 | case KGSL_PROP_PWRCTRL: { |
| 1233 | unsigned int enable; |
| 1234 | struct kgsl_device_platform_data *pdata = |
| 1235 | kgsl_device_get_drvdata(device); |
| 1236 | |
| 1237 | if (sizebytes != sizeof(enable)) |
| 1238 | break; |
| 1239 | |
| 1240 | if (copy_from_user(&enable, (void __user *) value, |
| 1241 | sizeof(enable))) { |
| 1242 | status = -EFAULT; |
| 1243 | break; |
| 1244 | } |
| 1245 | |
| 1246 | if (enable) { |
| 1247 | if (pdata->nap_allowed) |
| 1248 | device->pwrctrl.nap_allowed = true; |
| 1249 | |
| 1250 | kgsl_pwrscale_enable(device); |
| 1251 | } else { |
| 1252 | device->pwrctrl.nap_allowed = false; |
| 1253 | kgsl_pwrscale_disable(device); |
| 1254 | } |
| 1255 | |
| 1256 | status = 0; |
| 1257 | } |
| 1258 | break; |
| 1259 | default: |
| 1260 | break; |
| 1261 | } |
| 1262 | |
| 1263 | return status; |
| 1264 | } |
| 1265 | |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1266 | static inline void adreno_poke(struct kgsl_device *device) |
| 1267 | { |
| 1268 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1269 | adreno_regwrite(device, REG_CP_RB_WPTR, adreno_dev->ringbuffer.wptr); |
| 1270 | } |
| 1271 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1272 | /* Caller must hold the device mutex. */ |
| 1273 | int adreno_idle(struct kgsl_device *device, unsigned int timeout) |
| 1274 | { |
| 1275 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1276 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1277 | unsigned int rbbm_status; |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1278 | unsigned long wait_timeout = |
| 1279 | msecs_to_jiffies(adreno_dev->wait_timeout); |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1280 | unsigned long wait_time; |
| 1281 | unsigned long wait_time_part; |
| 1282 | unsigned int msecs; |
| 1283 | unsigned int msecs_first; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1284 | unsigned int msecs_part = KGSL_TIMEOUT_PART; |
| 1285 | unsigned int prev_reg_val[hang_detect_regs_count]; |
| 1286 | |
| 1287 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1288 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1289 | kgsl_cffdump_regpoll(device->id, |
| 1290 | adreno_dev->gpudev->reg_rbbm_status << 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1291 | 0x00000000, 0x80000000); |
| 1292 | /* first, wait until the CP has consumed all the commands in |
| 1293 | * the ring buffer |
| 1294 | */ |
| 1295 | retry: |
| 1296 | if (rb->flags & KGSL_FLAGS_STARTED) { |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1297 | msecs = adreno_dev->wait_timeout; |
| 1298 | msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100; |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1299 | wait_time = jiffies + wait_timeout; |
| 1300 | wait_time_part = jiffies + msecs_to_jiffies(msecs_first); |
Jeremy Gebben | f859454 | 2012-01-13 12:27:21 -0700 | [diff] [blame] | 1301 | adreno_poke(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1302 | do { |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1303 | if (time_after(jiffies, wait_time_part)) { |
| 1304 | adreno_poke(device); |
| 1305 | wait_time_part = jiffies + |
| 1306 | msecs_to_jiffies(msecs_part); |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1307 | if ((adreno_hang_detect(device, prev_reg_val))) |
| 1308 | goto err; |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1309 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1310 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 1311 | if (time_after(jiffies, wait_time)) { |
| 1312 | KGSL_DRV_ERR(device, "rptr: %x, wptr: %x\n", |
| 1313 | rb->rptr, rb->wptr); |
| 1314 | goto err; |
| 1315 | } |
| 1316 | } while (rb->rptr != rb->wptr); |
| 1317 | } |
| 1318 | |
| 1319 | /* now, wait for the GPU to finish its operations */ |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1320 | wait_time = jiffies + wait_timeout; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1321 | wait_time_part = jiffies + msecs_to_jiffies(msecs_part); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1322 | while (time_before(jiffies, wait_time)) { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1323 | adreno_regread(device, adreno_dev->gpudev->reg_rbbm_status, |
| 1324 | &rbbm_status); |
| 1325 | if (adreno_is_a2xx(adreno_dev)) { |
| 1326 | if (rbbm_status == 0x110) |
| 1327 | return 0; |
| 1328 | } else { |
| 1329 | if (!(rbbm_status & 0x80000000)) |
| 1330 | return 0; |
| 1331 | } |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1332 | |
| 1333 | /* Dont wait for timeout, detect hang faster. |
| 1334 | */ |
| 1335 | if (time_after(jiffies, wait_time_part)) { |
| 1336 | wait_time_part = jiffies + |
| 1337 | msecs_to_jiffies(msecs_part); |
| 1338 | if ((adreno_hang_detect(device, prev_reg_val))) |
| 1339 | goto err; |
| 1340 | } |
| 1341 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | err: |
| 1345 | KGSL_DRV_ERR(device, "spun too long waiting for RB to idle\n"); |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 1346 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state && |
| 1347 | !adreno_dump_and_recover(device)) { |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1348 | wait_time = jiffies + wait_timeout; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1349 | goto retry; |
| 1350 | } |
| 1351 | return -ETIMEDOUT; |
| 1352 | } |
| 1353 | |
| 1354 | static unsigned int adreno_isidle(struct kgsl_device *device) |
| 1355 | { |
| 1356 | int status = false; |
| 1357 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1358 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1359 | unsigned int rbbm_status; |
| 1360 | |
Lucille Sylvester | 51b764d | 2011-12-15 16:51:52 -0700 | [diff] [blame] | 1361 | WARN_ON(device->state == KGSL_STATE_INIT); |
| 1362 | /* If the device isn't active, don't force it on. */ |
| 1363 | if (device->state == KGSL_STATE_ACTIVE) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1364 | /* Is the ring buffer is empty? */ |
| 1365 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 1366 | if (!device->active_cnt && (rb->rptr == rb->wptr)) { |
| 1367 | /* Is the core idle? */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1368 | adreno_regread(device, |
| 1369 | adreno_dev->gpudev->reg_rbbm_status, |
| 1370 | &rbbm_status); |
| 1371 | |
| 1372 | if (adreno_is_a2xx(adreno_dev)) { |
| 1373 | if (rbbm_status == 0x110) |
| 1374 | status = true; |
| 1375 | } else { |
| 1376 | if (!(rbbm_status & 0x80000000)) |
| 1377 | status = true; |
| 1378 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1379 | } |
| 1380 | } else { |
Jeremy Gebben | aeb2387 | 2011-12-13 15:58:24 -0700 | [diff] [blame] | 1381 | status = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1382 | } |
| 1383 | return status; |
| 1384 | } |
| 1385 | |
| 1386 | /* Caller must hold the device mutex. */ |
| 1387 | static int adreno_suspend_context(struct kgsl_device *device) |
| 1388 | { |
| 1389 | int status = 0; |
| 1390 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1391 | |
| 1392 | /* switch to NULL ctxt */ |
| 1393 | if (adreno_dev->drawctxt_active != NULL) { |
| 1394 | adreno_drawctxt_switch(adreno_dev, NULL, 0); |
| 1395 | status = adreno_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 1396 | } |
| 1397 | |
| 1398 | return status; |
| 1399 | } |
| 1400 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 1401 | /* Find a memory structure attached to an adreno context */ |
| 1402 | |
| 1403 | struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device, |
| 1404 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size) |
| 1405 | { |
| 1406 | struct kgsl_context *context; |
| 1407 | struct adreno_context *adreno_context = NULL; |
| 1408 | int next = 0; |
| 1409 | |
| 1410 | while (1) { |
| 1411 | context = idr_get_next(&device->context_idr, &next); |
| 1412 | if (context == NULL) |
| 1413 | break; |
| 1414 | |
| 1415 | adreno_context = (struct adreno_context *)context->devctxt; |
| 1416 | |
| 1417 | if (kgsl_mmu_pt_equal(adreno_context->pagetable, pt_base)) { |
| 1418 | struct kgsl_memdesc *desc; |
| 1419 | |
| 1420 | desc = &adreno_context->gpustate; |
| 1421 | if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size)) |
| 1422 | return desc; |
| 1423 | |
| 1424 | desc = &adreno_context->context_gmem_shadow.gmemshadow; |
| 1425 | if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size)) |
| 1426 | return desc; |
| 1427 | } |
| 1428 | next = next + 1; |
| 1429 | } |
| 1430 | |
| 1431 | return NULL; |
| 1432 | } |
| 1433 | |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 1434 | struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device, |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1435 | unsigned int pt_base, |
| 1436 | unsigned int gpuaddr, |
| 1437 | unsigned int size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1438 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1439 | struct kgsl_mem_entry *entry; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1440 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1441 | struct adreno_ringbuffer *ringbuffer = &adreno_dev->ringbuffer; |
| 1442 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1443 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->buffer_desc, gpuaddr, size)) |
| 1444 | return &ringbuffer->buffer_desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1445 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1446 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->memptrs_desc, gpuaddr, size)) |
| 1447 | return &ringbuffer->memptrs_desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1448 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1449 | if (kgsl_gpuaddr_in_memdesc(&device->memstore, gpuaddr, size)) |
| 1450 | return &device->memstore; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1451 | |
Shubhraprakash Das | 9a14097 | 2012-04-12 13:12:42 -0600 | [diff] [blame] | 1452 | if (kgsl_gpuaddr_in_memdesc(&device->mmu.setstate_memory, gpuaddr, |
| 1453 | size)) |
| 1454 | return &device->mmu.setstate_memory; |
| 1455 | |
Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 1456 | entry = kgsl_get_mem_entry(pt_base, gpuaddr, size); |
| 1457 | |
| 1458 | if (entry) |
| 1459 | return &entry->memdesc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1460 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 1461 | return adreno_find_ctxtmem(device, pt_base, gpuaddr, size); |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | uint8_t *adreno_convertaddr(struct kgsl_device *device, unsigned int pt_base, |
| 1465 | unsigned int gpuaddr, unsigned int size) |
| 1466 | { |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 1467 | struct kgsl_memdesc *memdesc; |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1468 | |
| 1469 | memdesc = adreno_find_region(device, pt_base, gpuaddr, size); |
| 1470 | |
| 1471 | return memdesc ? kgsl_gpuaddr_to_vaddr(memdesc, gpuaddr) : NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | void adreno_regread(struct kgsl_device *device, unsigned int offsetwords, |
| 1475 | unsigned int *value) |
| 1476 | { |
| 1477 | unsigned int *reg; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1478 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
| 1479 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1480 | |
| 1481 | if (!in_interrupt()) |
| 1482 | kgsl_pre_hwaccess(device); |
| 1483 | |
| 1484 | /*ensure this read finishes before the next one. |
| 1485 | * i.e. act like normal readl() */ |
| 1486 | *value = __raw_readl(reg); |
| 1487 | rmb(); |
| 1488 | } |
| 1489 | |
| 1490 | void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords, |
| 1491 | unsigned int value) |
| 1492 | { |
| 1493 | unsigned int *reg; |
| 1494 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1495 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1496 | |
| 1497 | if (!in_interrupt()) |
| 1498 | kgsl_pre_hwaccess(device); |
| 1499 | |
| 1500 | kgsl_cffdump_regwrite(device->id, offsetwords << 2, value); |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1501 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1502 | |
| 1503 | /*ensure previous writes post before this one, |
| 1504 | * i.e. act like normal writel() */ |
| 1505 | wmb(); |
| 1506 | __raw_writel(value, reg); |
| 1507 | } |
| 1508 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1509 | static unsigned int _get_context_id(struct kgsl_context *k_ctxt) |
| 1510 | { |
| 1511 | unsigned int context_id = KGSL_MEMSTORE_GLOBAL; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1512 | if (k_ctxt != NULL) { |
| 1513 | struct adreno_context *a_ctxt = k_ctxt->devctxt; |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1514 | if (k_ctxt->id == KGSL_CONTEXT_INVALID || a_ctxt == NULL) |
| 1515 | context_id = KGSL_CONTEXT_INVALID; |
| 1516 | else if (a_ctxt->flags & CTXT_FLAGS_PER_CONTEXT_TS) |
| 1517 | context_id = k_ctxt->id; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | return context_id; |
| 1521 | } |
| 1522 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1523 | static int kgsl_check_interrupt_timestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1524 | struct kgsl_context *context, unsigned int timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1525 | { |
| 1526 | int status; |
| 1527 | unsigned int ref_ts, enableflag; |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1528 | unsigned int context_id; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 1529 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1530 | |
| 1531 | mutex_lock(&device->mutex); |
| 1532 | context_id = _get_context_id(context); |
| 1533 | /* |
| 1534 | * If the context ID is invalid, we are in a race with |
| 1535 | * the context being destroyed by userspace so bail. |
| 1536 | */ |
| 1537 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 1538 | KGSL_DRV_WARN(device, "context was detached"); |
| 1539 | status = -EINVAL; |
| 1540 | goto unlock; |
| 1541 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1542 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1543 | status = kgsl_check_timestamp(device, context, timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1544 | if (!status) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1545 | kgsl_sharedmem_readl(&device->memstore, &enableflag, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1546 | KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1547 | mb(); |
| 1548 | |
| 1549 | if (enableflag) { |
| 1550 | kgsl_sharedmem_readl(&device->memstore, &ref_ts, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1551 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1552 | ref_wait_ts)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1553 | mb(); |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 1554 | if (timestamp_cmp(ref_ts, timestamp) >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1555 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1556 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1557 | ref_wait_ts), timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1558 | wmb(); |
| 1559 | } |
| 1560 | } else { |
| 1561 | unsigned int cmds[2]; |
| 1562 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1563 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1564 | ref_wait_ts), timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1565 | enableflag = 1; |
| 1566 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1567 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1568 | ts_cmp_enable), enableflag); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1569 | wmb(); |
| 1570 | /* submit a dummy packet so that even if all |
| 1571 | * commands upto timestamp get executed we will still |
| 1572 | * get an interrupt */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 1573 | cmds[0] = cp_type3_packet(CP_NOP, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1574 | cmds[1] = 0; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 1575 | |
| 1576 | if (adreno_dev->drawctxt_active) |
| 1577 | adreno_ringbuffer_issuecmds(device, |
| 1578 | adreno_dev->drawctxt_active, |
| 1579 | KGSL_CMD_FLAGS_NONE, &cmds[0], 2); |
| 1580 | else |
| 1581 | /* We would never call this function if there |
| 1582 | * was no active contexts running */ |
| 1583 | BUG(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1584 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1585 | } |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1586 | unlock: |
| 1587 | mutex_unlock(&device->mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1588 | |
| 1589 | return status; |
| 1590 | } |
| 1591 | |
| 1592 | /* |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1593 | wait_event_interruptible_timeout checks for the exit condition before |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1594 | placing a process in wait q. For conditional interrupts we expect the |
| 1595 | process to already be in its wait q when its exit condition checking |
| 1596 | function is called. |
| 1597 | */ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1598 | #define kgsl_wait_event_interruptible_timeout(wq, condition, timeout, io)\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1599 | ({ \ |
| 1600 | long __ret = timeout; \ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1601 | if (io) \ |
| 1602 | __wait_io_event_interruptible_timeout(wq, condition, __ret);\ |
| 1603 | else \ |
| 1604 | __wait_event_interruptible_timeout(wq, condition, __ret);\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1605 | __ret; \ |
| 1606 | }) |
| 1607 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1608 | |
| 1609 | |
| 1610 | unsigned int adreno_hang_detect(struct kgsl_device *device, |
| 1611 | unsigned int *prev_reg_val) |
| 1612 | { |
| 1613 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1614 | unsigned int curr_reg_val[hang_detect_regs_count]; |
| 1615 | unsigned int hang_detected = 1; |
| 1616 | unsigned int i; |
| 1617 | |
| 1618 | if (!adreno_dev->fast_hang_detect) |
| 1619 | return 0; |
| 1620 | |
| 1621 | for (i = 0; i < hang_detect_regs_count; i++) { |
| 1622 | adreno_regread(device, hang_detect_regs[i], |
| 1623 | &curr_reg_val[i]); |
| 1624 | if (curr_reg_val[i] != prev_reg_val[i]) { |
| 1625 | prev_reg_val[i] = curr_reg_val[i]; |
| 1626 | hang_detected = 0; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | return hang_detected; |
| 1631 | } |
| 1632 | |
| 1633 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1634 | /* MUST be called with the device mutex held */ |
| 1635 | static int adreno_waittimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1636 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1637 | unsigned int timestamp, |
| 1638 | unsigned int msecs) |
| 1639 | { |
| 1640 | long status = 0; |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1641 | uint io = 1; |
Lucille Sylvester | 596d4c2 | 2011-10-19 18:04:01 -0600 | [diff] [blame] | 1642 | static uint io_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1643 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1644 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1645 | int retries = 0; |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1646 | unsigned int msecs_first; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1647 | unsigned int msecs_part = KGSL_TIMEOUT_PART; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1648 | unsigned int ts_issued; |
| 1649 | unsigned int context_id = _get_context_id(context); |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1650 | unsigned int time_elapsed = 0; |
| 1651 | unsigned int prev_reg_val[hang_detect_regs_count]; |
| 1652 | |
| 1653 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1654 | |
| 1655 | ts_issued = adreno_dev->ringbuffer.timestamp[context_id]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1656 | |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1657 | /* Don't wait forever, set a max value for now */ |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1658 | if (msecs == KGSL_TIMEOUT_DEFAULT) |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1659 | msecs = adreno_dev->wait_timeout; |
| 1660 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1661 | if (timestamp_cmp(timestamp, ts_issued) > 0) { |
| 1662 | KGSL_DRV_ERR(device, "Cannot wait for invalid ts <%d:0x%x>, " |
| 1663 | "last issued ts <%d:0x%x>\n", |
| 1664 | context_id, timestamp, context_id, ts_issued); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1665 | status = -EINVAL; |
| 1666 | goto done; |
| 1667 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1668 | |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1669 | /* Keep the first timeout as 100msecs before rewriting |
| 1670 | * the WPTR. Less visible impact if the WPTR has not |
| 1671 | * been updated properly. |
| 1672 | */ |
| 1673 | msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1674 | do { |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1675 | /* |
| 1676 | * If the context ID is invalid, we are in a race with |
| 1677 | * the context being destroyed by userspace so bail. |
| 1678 | */ |
| 1679 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 1680 | KGSL_DRV_WARN(device, "context was detached"); |
| 1681 | status = -EINVAL; |
| 1682 | goto done; |
| 1683 | } |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1684 | if (kgsl_check_timestamp(device, context, timestamp)) { |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1685 | /* if the timestamp happens while we're not |
| 1686 | * waiting, there's a chance that an interrupt |
| 1687 | * will not be generated and thus the timestamp |
| 1688 | * work needs to be queued. |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1689 | */ |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1690 | queue_work(device->work_queue, &device->ts_expired_ws); |
| 1691 | status = 0; |
| 1692 | goto done; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1693 | } |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1694 | adreno_poke(device); |
| 1695 | io_cnt = (io_cnt + 1) % 100; |
| 1696 | if (io_cnt < |
| 1697 | pwr->pwrlevels[pwr->active_pwrlevel].io_fraction) |
| 1698 | io = 0; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1699 | |
| 1700 | if ((retries > 0) && |
| 1701 | (adreno_hang_detect(device, prev_reg_val))) |
| 1702 | goto hang_dump; |
| 1703 | |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1704 | mutex_unlock(&device->mutex); |
| 1705 | /* We need to make sure that the process is |
| 1706 | * placed in wait-q before its condition is called |
| 1707 | */ |
| 1708 | status = kgsl_wait_event_interruptible_timeout( |
| 1709 | device->wait_queue, |
| 1710 | kgsl_check_interrupt_timestamp(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1711 | context, timestamp), |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1712 | msecs_to_jiffies(retries ? |
| 1713 | msecs_part : msecs_first), io); |
| 1714 | mutex_lock(&device->mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1715 | |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1716 | if (status > 0) { |
| 1717 | /*completed before the wait finished */ |
| 1718 | status = 0; |
| 1719 | goto done; |
| 1720 | } else if (status < 0) { |
| 1721 | /*an error occurred*/ |
| 1722 | goto done; |
| 1723 | } |
| 1724 | /*this wait timed out*/ |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1725 | |
| 1726 | time_elapsed = time_elapsed + |
| 1727 | (retries ? msecs_part : msecs_first); |
| 1728 | retries++; |
| 1729 | |
| 1730 | } while (time_elapsed < msecs); |
| 1731 | |
| 1732 | hang_dump: |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1733 | status = -ETIMEDOUT; |
| 1734 | KGSL_DRV_ERR(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1735 | "Device hang detected while waiting for timestamp: " |
| 1736 | "<%d:0x%x>, last submitted timestamp: <%d:0x%x>, " |
| 1737 | "wptr: 0x%x\n", |
| 1738 | context_id, timestamp, context_id, ts_issued, |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1739 | adreno_dev->ringbuffer.wptr); |
| 1740 | if (!adreno_dump_and_recover(device)) { |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 1741 | /* The timestamp that this process wanted |
| 1742 | * to wait on may be invalid or expired now |
| 1743 | * after successful recovery */ |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1744 | status = 0; |
| 1745 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1746 | done: |
| 1747 | return (int)status; |
| 1748 | } |
| 1749 | |
| 1750 | static unsigned int adreno_readtimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1751 | struct kgsl_context *context, enum kgsl_timestamp_type type) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1752 | { |
| 1753 | unsigned int timestamp = 0; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1754 | unsigned int context_id = _get_context_id(context); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1755 | |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1756 | /* |
| 1757 | * If the context ID is invalid, we are in a race with |
| 1758 | * the context being destroyed by userspace so bail. |
| 1759 | */ |
| 1760 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 1761 | KGSL_DRV_WARN(device, "context was detached"); |
| 1762 | return timestamp; |
| 1763 | } |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 1764 | switch (type) { |
| 1765 | case KGSL_TIMESTAMP_QUEUED: { |
| 1766 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1767 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1768 | |
| 1769 | timestamp = rb->timestamp[context_id]; |
| 1770 | break; |
| 1771 | } |
| 1772 | case KGSL_TIMESTAMP_CONSUMED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1773 | adreno_regread(device, REG_CP_TIMESTAMP, ×tamp); |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 1774 | break; |
| 1775 | case KGSL_TIMESTAMP_RETIRED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | kgsl_sharedmem_readl(&device->memstore, ×tamp, |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 1777 | KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp)); |
| 1778 | break; |
| 1779 | } |
| 1780 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1781 | rmb(); |
| 1782 | |
| 1783 | return timestamp; |
| 1784 | } |
| 1785 | |
| 1786 | static long adreno_ioctl(struct kgsl_device_private *dev_priv, |
| 1787 | unsigned int cmd, void *data) |
| 1788 | { |
| 1789 | int result = 0; |
| 1790 | struct kgsl_drawctxt_set_bin_base_offset *binbase; |
| 1791 | struct kgsl_context *context; |
| 1792 | |
| 1793 | switch (cmd) { |
| 1794 | case IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET: |
| 1795 | binbase = data; |
| 1796 | |
| 1797 | context = kgsl_find_context(dev_priv, binbase->drawctxt_id); |
| 1798 | if (context) { |
| 1799 | adreno_drawctxt_set_bin_base_offset( |
| 1800 | dev_priv->device, context, binbase->offset); |
| 1801 | } else { |
| 1802 | result = -EINVAL; |
| 1803 | KGSL_DRV_ERR(dev_priv->device, |
| 1804 | "invalid drawctxt drawctxt_id %d " |
| 1805 | "device_id=%d\n", |
| 1806 | binbase->drawctxt_id, dev_priv->device->id); |
| 1807 | } |
| 1808 | break; |
| 1809 | |
| 1810 | default: |
| 1811 | KGSL_DRV_INFO(dev_priv->device, |
| 1812 | "invalid ioctl code %08x\n", cmd); |
Jeremy Gebben | c15b461 | 2012-01-09 09:44:11 -0700 | [diff] [blame] | 1813 | result = -ENOIOCTLCMD; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1814 | break; |
| 1815 | } |
| 1816 | return result; |
| 1817 | |
| 1818 | } |
| 1819 | |
| 1820 | static inline s64 adreno_ticks_to_us(u32 ticks, u32 gpu_freq) |
| 1821 | { |
| 1822 | gpu_freq /= 1000000; |
| 1823 | return ticks / gpu_freq; |
| 1824 | } |
| 1825 | |
| 1826 | static void adreno_power_stats(struct kgsl_device *device, |
| 1827 | struct kgsl_power_stats *stats) |
| 1828 | { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1829 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1830 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1831 | unsigned int cycles; |
| 1832 | |
| 1833 | /* Get the busy cycles counted since the counter was last reset */ |
| 1834 | /* Calling this function also resets and restarts the counter */ |
| 1835 | |
| 1836 | cycles = adreno_dev->gpudev->busy_cycles(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1837 | |
| 1838 | /* In order to calculate idle you have to have run the algorithm * |
| 1839 | * at least once to get a start time. */ |
| 1840 | if (pwr->time != 0) { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1841 | s64 tmp = ktime_to_us(ktime_get()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1842 | stats->total_time = tmp - pwr->time; |
| 1843 | pwr->time = tmp; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1844 | stats->busy_time = adreno_ticks_to_us(cycles, device->pwrctrl. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1845 | pwrlevels[device->pwrctrl.active_pwrlevel]. |
| 1846 | gpu_freq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1847 | } else { |
| 1848 | stats->total_time = 0; |
| 1849 | stats->busy_time = 0; |
| 1850 | pwr->time = ktime_to_us(ktime_get()); |
| 1851 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | void adreno_irqctrl(struct kgsl_device *device, int state) |
| 1855 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 1856 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1857 | adreno_dev->gpudev->irq_control(adreno_dev, state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 1860 | static unsigned int adreno_gpuid(struct kgsl_device *device, |
| 1861 | unsigned int *chipid) |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 1862 | { |
| 1863 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1864 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 1865 | /* Some applications need to know the chip ID too, so pass |
| 1866 | * that as a parameter */ |
| 1867 | |
| 1868 | if (chipid != NULL) |
| 1869 | *chipid = adreno_dev->chip_id; |
| 1870 | |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 1871 | /* Standard KGSL gpuid format: |
| 1872 | * top word is 0x0002 for 2D or 0x0003 for 3D |
| 1873 | * Bottom word is core specific identifer |
| 1874 | */ |
| 1875 | |
| 1876 | return (0x0003 << 16) | ((int) adreno_dev->gpurev); |
| 1877 | } |
| 1878 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1879 | static const struct kgsl_functable adreno_functable = { |
| 1880 | /* Mandatory functions */ |
| 1881 | .regread = adreno_regread, |
| 1882 | .regwrite = adreno_regwrite, |
| 1883 | .idle = adreno_idle, |
| 1884 | .isidle = adreno_isidle, |
| 1885 | .suspend_context = adreno_suspend_context, |
| 1886 | .start = adreno_start, |
| 1887 | .stop = adreno_stop, |
| 1888 | .getproperty = adreno_getproperty, |
| 1889 | .waittimestamp = adreno_waittimestamp, |
| 1890 | .readtimestamp = adreno_readtimestamp, |
| 1891 | .issueibcmds = adreno_ringbuffer_issueibcmds, |
| 1892 | .ioctl = adreno_ioctl, |
| 1893 | .setup_pt = adreno_setup_pt, |
| 1894 | .cleanup_pt = adreno_cleanup_pt, |
| 1895 | .power_stats = adreno_power_stats, |
| 1896 | .irqctrl = adreno_irqctrl, |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 1897 | .gpuid = adreno_gpuid, |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1898 | .snapshot = adreno_snapshot, |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 1899 | .irq_handler = adreno_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1900 | /* Optional functions */ |
| 1901 | .setstate = adreno_setstate, |
| 1902 | .drawctxt_create = adreno_drawctxt_create, |
| 1903 | .drawctxt_destroy = adreno_drawctxt_destroy, |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 1904 | .setproperty = adreno_setproperty, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1905 | }; |
| 1906 | |
| 1907 | static struct platform_device_id adreno_id_table[] = { |
| 1908 | { DEVICE_3D0_NAME, (kernel_ulong_t)&device_3d0.dev, }, |
| 1909 | { }, |
| 1910 | }; |
| 1911 | MODULE_DEVICE_TABLE(platform, adreno_id_table); |
| 1912 | |
| 1913 | static struct platform_driver adreno_platform_driver = { |
| 1914 | .probe = adreno_probe, |
| 1915 | .remove = __devexit_p(adreno_remove), |
| 1916 | .suspend = kgsl_suspend_driver, |
| 1917 | .resume = kgsl_resume_driver, |
| 1918 | .id_table = adreno_id_table, |
| 1919 | .driver = { |
| 1920 | .owner = THIS_MODULE, |
| 1921 | .name = DEVICE_3D_NAME, |
| 1922 | .pm = &kgsl_pm_ops, |
| 1923 | } |
| 1924 | }; |
| 1925 | |
| 1926 | static int __init kgsl_3d_init(void) |
| 1927 | { |
| 1928 | return platform_driver_register(&adreno_platform_driver); |
| 1929 | } |
| 1930 | |
| 1931 | static void __exit kgsl_3d_exit(void) |
| 1932 | { |
| 1933 | platform_driver_unregister(&adreno_platform_driver); |
| 1934 | } |
| 1935 | |
| 1936 | module_init(kgsl_3d_init); |
| 1937 | module_exit(kgsl_3d_exit); |
| 1938 | |
| 1939 | MODULE_DESCRIPTION("3D Graphics driver"); |
| 1940 | MODULE_VERSION("1.2"); |
| 1941 | MODULE_LICENSE("GPL v2"); |
| 1942 | MODULE_ALIAS("platform:kgsl_3d"); |