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 | 19ca4a6 | 2012-05-18 12:11:20 -0600 | [diff] [blame] | 292 | if (cpu_is_msm8960()) |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 293 | cmds += adreno_add_change_mh_phys_limit_cmds(cmds, 0xFFFFF000, |
| 294 | device->mmu.setstate_memory.gpuaddr + |
| 295 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 296 | else |
| 297 | cmds += adreno_add_bank_change_cmds(cmds, |
| 298 | KGSL_IOMMU_CONTEXT_USER, |
| 299 | device->mmu.setstate_memory.gpuaddr + |
| 300 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 301 | |
| 302 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
| 303 | pt_val = kgsl_mmu_pt_get_base_addr(device->mmu.hwpagetable); |
| 304 | /* |
| 305 | * We need to perfrom the following operations for all |
| 306 | * IOMMU units |
| 307 | */ |
| 308 | for (i = 0; i < num_iommu_units; i++) { |
| 309 | reg_pt_val = (pt_val & |
| 310 | (KGSL_IOMMU_TTBR0_PA_MASK << |
| 311 | KGSL_IOMMU_TTBR0_PA_SHIFT)) + |
| 312 | kgsl_mmu_get_pt_lsb(&device->mmu, i, |
| 313 | KGSL_IOMMU_CONTEXT_USER); |
| 314 | /* |
| 315 | * Set address of the new pagetable by writng to IOMMU |
| 316 | * TTBR0 register |
| 317 | */ |
| 318 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
| 319 | *cmds++ = reg_map_desc[i]->gpuaddr + |
| 320 | (KGSL_IOMMU_CONTEXT_USER << |
| 321 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_TTBR0; |
| 322 | *cmds++ = reg_pt_val; |
| 323 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 324 | *cmds++ = 0x00000000; |
| 325 | |
| 326 | /* |
| 327 | * Read back the ttbr0 register as a barrier to ensure |
| 328 | * above writes have completed |
| 329 | */ |
| 330 | cmds += adreno_add_read_cmds(device, cmds, |
| 331 | reg_map_desc[i]->gpuaddr + |
| 332 | (KGSL_IOMMU_CONTEXT_USER << |
| 333 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_TTBR0, |
| 334 | reg_pt_val, |
| 335 | device->mmu.setstate_memory.gpuaddr + |
| 336 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 337 | |
| 338 | /* set the asid */ |
| 339 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
| 340 | *cmds++ = reg_map_desc[i]->gpuaddr + |
| 341 | (KGSL_IOMMU_CONTEXT_USER << |
| 342 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_CONTEXTIDR; |
| 343 | *cmds++ = kgsl_mmu_get_hwpagetable_asid(&device->mmu); |
| 344 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 345 | *cmds++ = 0x00000000; |
| 346 | |
| 347 | /* Read back asid to ensure above write completes */ |
| 348 | cmds += adreno_add_read_cmds(device, cmds, |
| 349 | reg_map_desc[i]->gpuaddr + |
| 350 | (KGSL_IOMMU_CONTEXT_USER << |
| 351 | KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_CONTEXTIDR, |
| 352 | kgsl_mmu_get_hwpagetable_asid(&device->mmu), |
| 353 | device->mmu.setstate_memory.gpuaddr + |
| 354 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 355 | } |
| 356 | /* invalidate all base pointers */ |
| 357 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
| 358 | *cmds++ = 0x7fff; |
| 359 | |
Sunil Joseph | cf21e44 | 2012-07-10 15:23:13 +0530 | [diff] [blame] | 360 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) |
| 361 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 362 | device->mmu.setstate_memory.gpuaddr + |
| 363 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 364 | } |
| 365 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 366 | /* |
| 367 | * tlb flush based on asid, no need to flush entire tlb |
| 368 | */ |
| 369 | for (i = 0; i < num_iommu_units; i++) { |
| 370 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
| 371 | *cmds++ = (reg_map_desc[i]->gpuaddr + |
| 372 | (KGSL_IOMMU_CONTEXT_USER << |
| 373 | KGSL_IOMMU_CTX_SHIFT) + |
| 374 | KGSL_IOMMU_CTX_TLBIASID); |
| 375 | *cmds++ = kgsl_mmu_get_hwpagetable_asid(&device->mmu); |
Shubhraprakash Das | be39728 | 2012-07-09 10:25:01 -0600 | [diff] [blame] | 376 | |
| 377 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 378 | device->mmu.setstate_memory.gpuaddr + |
| 379 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 380 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 381 | cmds += adreno_add_read_cmds(device, cmds, |
| 382 | reg_map_desc[i]->gpuaddr + |
| 383 | (KGSL_IOMMU_CONTEXT_USER << |
| 384 | KGSL_IOMMU_CTX_SHIFT) + |
| 385 | KGSL_IOMMU_CONTEXTIDR, |
| 386 | kgsl_mmu_get_hwpagetable_asid(&device->mmu), |
| 387 | device->mmu.setstate_memory.gpuaddr + |
| 388 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 389 | } |
| 390 | } |
| 391 | |
Shubhraprakash Das | 19ca4a6 | 2012-05-18 12:11:20 -0600 | [diff] [blame] | 392 | if (cpu_is_msm8960()) |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 393 | cmds += adreno_add_change_mh_phys_limit_cmds(cmds, |
| 394 | reg_map_desc[num_iommu_units - 1]->gpuaddr - PAGE_SIZE, |
| 395 | device->mmu.setstate_memory.gpuaddr + |
| 396 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 397 | else |
| 398 | cmds += adreno_add_bank_change_cmds(cmds, |
| 399 | KGSL_IOMMU_CONTEXT_PRIV, |
| 400 | device->mmu.setstate_memory.gpuaddr + |
| 401 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 402 | |
| 403 | sizedwords += (cmds - &link[0]); |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 404 | if (sizedwords) { |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 405 | /* |
| 406 | * add an interrupt at the end of commands so that the smmu |
| 407 | * disable clock off function will get called |
| 408 | */ |
| 409 | *cmds++ = cp_type3_packet(CP_INTERRUPT, 1); |
| 410 | *cmds++ = CP_INT_CNTL__RB_INT_MASK; |
| 411 | sizedwords += 2; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 412 | /* This returns the per context timestamp but we need to |
| 413 | * use the global timestamp for iommu clock disablement */ |
| 414 | adreno_ringbuffer_issuecmds(device, adreno_ctx, |
| 415 | KGSL_CMD_FLAGS_PMODE, |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 416 | &link[0], sizedwords); |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 417 | kgsl_mmu_disable_clk_on_ts(&device->mmu, |
| 418 | adreno_dev->ringbuffer.timestamp[KGSL_MEMSTORE_GLOBAL], true); |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 419 | } |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 420 | done: |
| 421 | if (num_iommu_units) |
| 422 | kfree(reg_map_array); |
| 423 | } |
| 424 | |
| 425 | static void adreno_gpummu_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 426 | unsigned int context_id, |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 427 | uint32_t flags) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 428 | { |
| 429 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 430 | unsigned int link[32]; |
| 431 | unsigned int *cmds = &link[0]; |
| 432 | int sizedwords = 0; |
| 433 | unsigned int mh_mmu_invalidate = 0x00000003; /*invalidate all and tc */ |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 434 | struct kgsl_context *context; |
| 435 | struct adreno_context *adreno_ctx = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 436 | |
Jeremy Gebben | a3d07a4 | 2011-10-17 12:08:16 -0600 | [diff] [blame] | 437 | /* |
Rajesh Kemisetti | 22a06d1 | 2012-06-29 20:21:31 +0530 | [diff] [blame] | 438 | * Fix target freeze issue by adding TLB flush for each submit |
| 439 | * on A20X based targets. |
| 440 | */ |
| 441 | if (adreno_is_a20x(adreno_dev)) |
| 442 | flags |= KGSL_MMUFLAGS_TLBFLUSH; |
| 443 | /* |
Jeremy Gebben | a3d07a4 | 2011-10-17 12:08:16 -0600 | [diff] [blame] | 444 | * If possible, then set the state via the command stream to avoid |
| 445 | * a CPU idle. Otherwise, use the default setstate which uses register |
| 446 | * writes For CFF dump we must idle and use the registers so that it is |
| 447 | * easier to filter out the mmu accesses from the dump |
| 448 | */ |
| 449 | if (!kgsl_cff_dump_enable && adreno_dev->drawctxt_active) { |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 450 | context = idr_find(&device->context_idr, context_id); |
| 451 | adreno_ctx = context->devctxt; |
| 452 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 453 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
| 454 | /* wait for graphics pipe to be idle */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 455 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 456 | *cmds++ = 0x00000000; |
| 457 | |
| 458 | /* set page table base */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 459 | *cmds++ = cp_type0_packet(MH_MMU_PT_BASE, 1); |
Shubhraprakash Das | 5a610b5 | 2012-05-09 17:31:54 -0600 | [diff] [blame] | 460 | *cmds++ = kgsl_mmu_pt_get_base_addr( |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 461 | device->mmu.hwpagetable); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 462 | sizedwords += 4; |
| 463 | } |
| 464 | |
| 465 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 466 | if (!(flags & KGSL_MMUFLAGS_PTUPDATE)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 467 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 468 | 1); |
| 469 | *cmds++ = 0x00000000; |
| 470 | sizedwords += 2; |
| 471 | } |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 472 | *cmds++ = cp_type0_packet(MH_MMU_INVALIDATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 473 | *cmds++ = mh_mmu_invalidate; |
| 474 | sizedwords += 2; |
| 475 | } |
| 476 | |
| 477 | if (flags & KGSL_MMUFLAGS_PTUPDATE && |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 478 | adreno_is_a20x(adreno_dev)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 479 | /* HW workaround: to resolve MMU page fault interrupts |
| 480 | * caused by the VGT.It prevents the CP PFP from filling |
| 481 | * the VGT DMA request fifo too early,thereby ensuring |
| 482 | * that the VGT will not fetch vertex/bin data until |
| 483 | * after the page table base register has been updated. |
| 484 | * |
| 485 | * Two null DRAW_INDX_BIN packets are inserted right |
| 486 | * after the page table base update, followed by a |
| 487 | * wait for idle. The null packets will fill up the |
| 488 | * VGT DMA request fifo and prevent any further |
| 489 | * vertex/bin updates from occurring until the wait |
| 490 | * has finished. */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 491 | *cmds++ = cp_type3_packet(CP_SET_CONSTANT, 2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 492 | *cmds++ = (0x4 << 16) | |
| 493 | (REG_PA_SU_SC_MODE_CNTL - 0x2000); |
| 494 | *cmds++ = 0; /* disable faceness generation */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 495 | *cmds++ = cp_type3_packet(CP_SET_BIN_BASE_OFFSET, 1); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 496 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 497 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 498 | *cmds++ = 0; /* viz query info */ |
| 499 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 500 | *cmds++ = 0; /* bin base */ |
| 501 | *cmds++ = 3; /* bin size */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 502 | *cmds++ = |
| 503 | device->mmu.setstate_memory.gpuaddr; /* dma base */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 504 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 505 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 506 | *cmds++ = 0; /* viz query info */ |
| 507 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 508 | *cmds++ = 0; /* bin base */ |
| 509 | *cmds++ = 3; /* bin size */ |
| 510 | /* dma base */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 511 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 512 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 513 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 514 | *cmds++ = 0x00000000; |
| 515 | sizedwords += 21; |
| 516 | } |
| 517 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 518 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 519 | if (flags & (KGSL_MMUFLAGS_PTUPDATE | KGSL_MMUFLAGS_TLBFLUSH)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 520 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 521 | *cmds++ = 0x7fff; /* invalidate all base pointers */ |
| 522 | sizedwords += 2; |
| 523 | } |
| 524 | |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 525 | adreno_ringbuffer_issuecmds(device, adreno_ctx, |
| 526 | KGSL_CMD_FLAGS_PMODE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 527 | &link[0], sizedwords); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 528 | } else { |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 529 | kgsl_mmu_device_setstate(&device->mmu, flags); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 530 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 533 | static void adreno_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 534 | unsigned int context_id, |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 535 | uint32_t flags) |
| 536 | { |
| 537 | /* call the mmu specific handler */ |
| 538 | if (KGSL_MMU_TYPE_GPU == kgsl_mmu_get_mmutype()) |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 539 | return adreno_gpummu_setstate(device, context_id, flags); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 540 | else if (KGSL_MMU_TYPE_IOMMU == kgsl_mmu_get_mmutype()) |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 541 | return adreno_iommu_setstate(device, context_id, flags); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 542 | } |
| 543 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 544 | static unsigned int |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 545 | a3xx_getchipid(struct kgsl_device *device) |
| 546 | { |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 547 | struct kgsl_device_platform_data *pdata = |
| 548 | kgsl_device_get_drvdata(device); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 549 | |
Jordan Crouse | 54154c6 | 2012-03-27 16:33:26 -0600 | [diff] [blame] | 550 | /* |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 551 | * All current A3XX chipids are detected at the SOC level. Leave this |
| 552 | * function here to support any future GPUs that have working |
| 553 | * chip ID registers |
Jordan Crouse | 54154c6 | 2012-03-27 16:33:26 -0600 | [diff] [blame] | 554 | */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 555 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 556 | return pdata->chipid; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static unsigned int |
| 560 | a2xx_getchipid(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 561 | { |
| 562 | unsigned int chipid = 0; |
| 563 | unsigned int coreid, majorid, minorid, patchid, revid; |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 564 | struct kgsl_device_platform_data *pdata = |
| 565 | kgsl_device_get_drvdata(device); |
| 566 | |
| 567 | /* If the chip id is set at the platform level, then just use that */ |
| 568 | |
| 569 | if (pdata->chipid != 0) |
| 570 | return pdata->chipid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 571 | |
| 572 | adreno_regread(device, REG_RBBM_PERIPHID1, &coreid); |
| 573 | adreno_regread(device, REG_RBBM_PERIPHID2, &majorid); |
| 574 | adreno_regread(device, REG_RBBM_PATCH_RELEASE, &revid); |
| 575 | |
| 576 | /* |
| 577 | * adreno 22x gpus are indicated by coreid 2, |
| 578 | * but REG_RBBM_PERIPHID1 always contains 0 for this field |
| 579 | */ |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 580 | if (cpu_is_msm8x60()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 581 | chipid = 2 << 24; |
| 582 | else |
| 583 | chipid = (coreid & 0xF) << 24; |
| 584 | |
| 585 | chipid |= ((majorid >> 4) & 0xF) << 16; |
| 586 | |
| 587 | minorid = ((revid >> 0) & 0xFF); |
| 588 | |
| 589 | patchid = ((revid >> 16) & 0xFF); |
| 590 | |
| 591 | /* 8x50 returns 0 for patch release, but it should be 1 */ |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 592 | /* 8x25 returns 0 for minor id, but it should be 1 */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 593 | if (cpu_is_qsd8x50()) |
| 594 | patchid = 1; |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 595 | else if (cpu_is_msm8625() && minorid == 0) |
| 596 | minorid = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 597 | |
| 598 | chipid |= (minorid << 8) | patchid; |
| 599 | |
| 600 | return chipid; |
| 601 | } |
| 602 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 603 | static unsigned int |
| 604 | adreno_getchipid(struct kgsl_device *device) |
| 605 | { |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 606 | struct kgsl_device_platform_data *pdata = |
| 607 | kgsl_device_get_drvdata(device); |
| 608 | |
| 609 | /* |
| 610 | * All A3XX chipsets will have pdata set, so assume !pdata->chipid is |
| 611 | * an A2XX processor |
| 612 | */ |
| 613 | |
| 614 | if (pdata->chipid == 0 || ADRENO_CHIPID_MAJOR(pdata->chipid) == 2) |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 615 | return a2xx_getchipid(device); |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 616 | else |
| 617 | return a3xx_getchipid(device); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 620 | static inline bool _rev_match(unsigned int id, unsigned int entry) |
| 621 | { |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 622 | return (entry == ANY_ID || entry == id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 623 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 624 | |
| 625 | static void |
| 626 | adreno_identify_gpu(struct adreno_device *adreno_dev) |
| 627 | { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 628 | unsigned int i, core, major, minor, patchid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 629 | |
| 630 | adreno_dev->chip_id = adreno_getchipid(&adreno_dev->dev); |
| 631 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame^] | 632 | core = ADRENO_CHIPID_CORE(adreno_dev->chip_id); |
| 633 | major = ADRENO_CHIPID_MAJOR(adreno_dev->chip_id); |
| 634 | minor = ADRENO_CHIPID_MINOR(adreno_dev->chip_id); |
| 635 | patchid = ADRENO_CHIPID_PATCH(adreno_dev->chip_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 636 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 637 | for (i = 0; i < ARRAY_SIZE(adreno_gpulist); i++) { |
| 638 | if (core == adreno_gpulist[i].core && |
| 639 | _rev_match(major, adreno_gpulist[i].major) && |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 640 | _rev_match(minor, adreno_gpulist[i].minor) && |
| 641 | _rev_match(patchid, adreno_gpulist[i].patchid)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 642 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 645 | if (i == ARRAY_SIZE(adreno_gpulist)) { |
| 646 | adreno_dev->gpurev = ADRENO_REV_UNKNOWN; |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | adreno_dev->gpurev = adreno_gpulist[i].gpurev; |
| 651 | adreno_dev->gpudev = adreno_gpulist[i].gpudev; |
| 652 | adreno_dev->pfp_fwfile = adreno_gpulist[i].pfpfw; |
| 653 | adreno_dev->pm4_fwfile = adreno_gpulist[i].pm4fw; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 654 | adreno_dev->istore_size = adreno_gpulist[i].istore_size; |
| 655 | adreno_dev->pix_shader_start = adreno_gpulist[i].pix_shader_start; |
Jordan Crouse | 55d98fd | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 656 | adreno_dev->instruction_size = adreno_gpulist[i].instruction_size; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 657 | adreno_dev->gmem_size = adreno_gpulist[i].gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static int __devinit |
| 661 | adreno_probe(struct platform_device *pdev) |
| 662 | { |
| 663 | struct kgsl_device *device; |
| 664 | struct adreno_device *adreno_dev; |
| 665 | int status = -EINVAL; |
| 666 | |
| 667 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 668 | adreno_dev = ADRENO_DEVICE(device); |
| 669 | device->parentdev = &pdev->dev; |
| 670 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 671 | status = adreno_ringbuffer_init(device); |
| 672 | if (status != 0) |
| 673 | goto error; |
| 674 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 675 | status = kgsl_device_platform_probe(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 676 | if (status) |
| 677 | goto error_close_rb; |
| 678 | |
| 679 | adreno_debugfs_init(device); |
| 680 | |
| 681 | kgsl_pwrscale_init(device); |
| 682 | kgsl_pwrscale_attach_policy(device, ADRENO_DEFAULT_PWRSCALE_POLICY); |
| 683 | |
| 684 | device->flags &= ~KGSL_FLAGS_SOFT_RESET; |
| 685 | return 0; |
| 686 | |
| 687 | error_close_rb: |
| 688 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 689 | error: |
| 690 | device->parentdev = NULL; |
| 691 | return status; |
| 692 | } |
| 693 | |
| 694 | static int __devexit adreno_remove(struct platform_device *pdev) |
| 695 | { |
| 696 | struct kgsl_device *device; |
| 697 | struct adreno_device *adreno_dev; |
| 698 | |
| 699 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 700 | adreno_dev = ADRENO_DEVICE(device); |
| 701 | |
| 702 | kgsl_pwrscale_detach_policy(device); |
| 703 | kgsl_pwrscale_close(device); |
| 704 | |
| 705 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 706 | kgsl_device_platform_remove(device); |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | static int adreno_start(struct kgsl_device *device, unsigned int init_ram) |
| 712 | { |
| 713 | int status = -EINVAL; |
| 714 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 715 | |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 716 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state) |
| 717 | kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 718 | |
| 719 | /* Power up the device */ |
| 720 | kgsl_pwrctrl_enable(device); |
| 721 | |
| 722 | /* Identify the specific GPU */ |
| 723 | adreno_identify_gpu(adreno_dev); |
| 724 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 725 | if (adreno_dev->gpurev == ADRENO_REV_UNKNOWN) { |
| 726 | KGSL_DRV_ERR(device, "Unknown chip ID %x\n", |
| 727 | adreno_dev->chip_id); |
| 728 | goto error_clk_off; |
| 729 | } |
| 730 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 731 | /* Set up the MMU */ |
| 732 | if (adreno_is_a2xx(adreno_dev)) { |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 733 | /* |
| 734 | * the MH_CLNT_INTF_CTRL_CONFIG registers aren't present |
| 735 | * on older gpus |
| 736 | */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 737 | if (adreno_is_a20x(adreno_dev)) { |
| 738 | device->mh.mh_intf_cfg1 = 0; |
| 739 | device->mh.mh_intf_cfg2 = 0; |
| 740 | } |
| 741 | |
| 742 | kgsl_mh_start(device); |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 743 | } |
| 744 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 745 | /* Assign correct RBBM status register to hang detect regs |
| 746 | */ |
| 747 | hang_detect_regs[0] = adreno_dev->gpudev->reg_rbbm_status; |
| 748 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 749 | status = kgsl_mmu_start(device); |
| 750 | if (status) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 751 | goto error_clk_off; |
| 752 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 753 | /* Start the GPU */ |
| 754 | adreno_dev->gpudev->start(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 755 | |
| 756 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 757 | device->ftbl->irqctrl(device, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 758 | |
| 759 | status = adreno_ringbuffer_start(&adreno_dev->ringbuffer, init_ram); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 760 | if (status == 0) { |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 761 | /* While recovery is on we do not want timer to |
| 762 | * fire and attempt to change any device state */ |
| 763 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state) |
| 764 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 765 | return 0; |
| 766 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 767 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 768 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 769 | kgsl_mmu_stop(&device->mmu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 770 | error_clk_off: |
| 771 | kgsl_pwrctrl_disable(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 772 | |
| 773 | return status; |
| 774 | } |
| 775 | |
| 776 | static int adreno_stop(struct kgsl_device *device) |
| 777 | { |
| 778 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 779 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 780 | adreno_dev->drawctxt_active = NULL; |
| 781 | |
| 782 | adreno_ringbuffer_stop(&adreno_dev->ringbuffer); |
| 783 | |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 784 | kgsl_mmu_stop(&device->mmu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 785 | |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 786 | device->ftbl->irqctrl(device, 0); |
Ranjhith Kalisamy | ce75b0c | 2012-02-01 19:31:23 +0530 | [diff] [blame] | 787 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Suman Tatiraju | 4a32c65 | 2012-02-17 11:59:05 -0800 | [diff] [blame] | 788 | del_timer_sync(&device->idle_timer); |
Lucille Sylvester | 844b1c8 | 2011-08-29 15:26:06 -0600 | [diff] [blame] | 789 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 790 | /* Power down the device */ |
| 791 | kgsl_pwrctrl_disable(device); |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static int |
| 797 | adreno_recover_hang(struct kgsl_device *device) |
| 798 | { |
| 799 | int ret; |
| 800 | unsigned int *rb_buffer; |
| 801 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 802 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 803 | unsigned int timestamp; |
| 804 | unsigned int num_rb_contents; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 805 | unsigned int reftimestamp; |
| 806 | unsigned int enable_ts; |
| 807 | unsigned int soptimestamp; |
| 808 | unsigned int eoptimestamp; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 809 | unsigned int context_id; |
Shubhraprakash Das | 2dfe5dd | 2012-02-10 13:49:53 -0700 | [diff] [blame] | 810 | struct kgsl_context *context; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 811 | struct adreno_context *adreno_context; |
Shubhraprakash Das | 2dfe5dd | 2012-02-10 13:49:53 -0700 | [diff] [blame] | 812 | int next = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 813 | |
| 814 | KGSL_DRV_ERR(device, "Starting recovery from 3D GPU hang....\n"); |
| 815 | rb_buffer = vmalloc(rb->buffer_desc.size); |
| 816 | if (!rb_buffer) { |
| 817 | KGSL_MEM_ERR(device, |
| 818 | "Failed to allocate memory for recovery: %x\n", |
| 819 | rb->buffer_desc.size); |
| 820 | return -ENOMEM; |
| 821 | } |
| 822 | /* Extract valid contents from rb which can stil be executed after |
| 823 | * hang */ |
| 824 | ret = adreno_ringbuffer_extract(rb, rb_buffer, &num_rb_contents); |
| 825 | if (ret) |
| 826 | goto done; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 827 | kgsl_sharedmem_readl(&device->memstore, &context_id, |
| 828 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 829 | current_context)); |
| 830 | context = idr_find(&device->context_idr, context_id); |
| 831 | if (context == NULL) { |
| 832 | KGSL_DRV_ERR(device, "Last context unknown id:%d\n", |
| 833 | context_id); |
| 834 | context_id = KGSL_MEMSTORE_GLOBAL; |
| 835 | } |
| 836 | |
| 837 | timestamp = rb->timestamp[KGSL_MEMSTORE_GLOBAL]; |
| 838 | KGSL_DRV_ERR(device, "Last issued global timestamp: %x\n", timestamp); |
| 839 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 840 | kgsl_sharedmem_readl(&device->memstore, &reftimestamp, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 841 | KGSL_MEMSTORE_OFFSET(context_id, |
| 842 | ref_wait_ts)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 843 | kgsl_sharedmem_readl(&device->memstore, &enable_ts, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 844 | KGSL_MEMSTORE_OFFSET(context_id, |
| 845 | ts_cmp_enable)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 846 | kgsl_sharedmem_readl(&device->memstore, &soptimestamp, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 847 | KGSL_MEMSTORE_OFFSET(context_id, |
| 848 | soptimestamp)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 849 | kgsl_sharedmem_readl(&device->memstore, &eoptimestamp, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 850 | KGSL_MEMSTORE_OFFSET(context_id, |
| 851 | eoptimestamp)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 852 | /* Make sure memory is synchronized before restarting the GPU */ |
| 853 | mb(); |
| 854 | KGSL_CTXT_ERR(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 855 | "Context id that caused a GPU hang: %d\n", context_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 856 | /* restart device */ |
| 857 | ret = adreno_stop(device); |
| 858 | if (ret) |
| 859 | goto done; |
| 860 | ret = adreno_start(device, true); |
| 861 | if (ret) |
| 862 | goto done; |
| 863 | KGSL_DRV_ERR(device, "Device has been restarted after hang\n"); |
| 864 | /* Restore timestamp states */ |
| 865 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 866 | KGSL_MEMSTORE_OFFSET(context_id, soptimestamp), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 867 | soptimestamp); |
| 868 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 869 | KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 870 | eoptimestamp); |
Carter Cooper | ae4c7bc | 2012-04-10 09:40:49 -0600 | [diff] [blame] | 871 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 872 | if (num_rb_contents) { |
| 873 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 874 | KGSL_MEMSTORE_OFFSET(context_id, ref_wait_ts), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 875 | reftimestamp); |
| 876 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 877 | KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 878 | enable_ts); |
| 879 | } |
| 880 | /* Make sure all writes are posted before the GPU reads them */ |
| 881 | wmb(); |
| 882 | /* Mark the invalid context so no more commands are accepted from |
| 883 | * that context */ |
| 884 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 885 | adreno_context = context->devctxt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 886 | |
| 887 | KGSL_CTXT_ERR(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 888 | "Context that caused a GPU hang: %d\n", adreno_context->id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 889 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 890 | adreno_context->flags |= CTXT_FLAGS_GPU_HANG; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 891 | |
Shubhraprakash Das | 2dfe5dd | 2012-02-10 13:49:53 -0700 | [diff] [blame] | 892 | /* |
| 893 | * Set the reset status of all contexts to |
| 894 | * INNOCENT_CONTEXT_RESET_EXT except for the bad context |
| 895 | * since thats the guilty party |
| 896 | */ |
| 897 | while ((context = idr_get_next(&device->context_idr, &next))) { |
| 898 | if (KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT != |
| 899 | context->reset_status) { |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 900 | if (context->id != context_id) |
Shubhraprakash Das | 2dfe5dd | 2012-02-10 13:49:53 -0700 | [diff] [blame] | 901 | context->reset_status = |
| 902 | KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT; |
| 903 | else |
| 904 | context->reset_status = |
| 905 | KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; |
| 906 | } |
| 907 | next = next + 1; |
| 908 | } |
| 909 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 910 | /* Restore valid commands in ringbuffer */ |
| 911 | adreno_ringbuffer_restore(rb, rb_buffer, num_rb_contents); |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 912 | rb->timestamp[KGSL_MEMSTORE_GLOBAL] = timestamp; |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 913 | /* wait for idle */ |
| 914 | ret = adreno_idle(device, KGSL_TIMEOUT_DEFAULT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 915 | done: |
| 916 | vfree(rb_buffer); |
| 917 | return ret; |
| 918 | } |
| 919 | |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 920 | int adreno_dump_and_recover(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 921 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 922 | int result = -ETIMEDOUT; |
| 923 | |
| 924 | if (device->state == KGSL_STATE_HUNG) |
| 925 | goto done; |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 926 | if (device->state == KGSL_STATE_DUMP_AND_RECOVER) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 927 | mutex_unlock(&device->mutex); |
| 928 | wait_for_completion(&device->recovery_gate); |
| 929 | mutex_lock(&device->mutex); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 930 | if (device->state != KGSL_STATE_HUNG) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 931 | result = 0; |
| 932 | } else { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 933 | kgsl_pwrctrl_set_state(device, KGSL_STATE_DUMP_AND_RECOVER); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 934 | INIT_COMPLETION(device->recovery_gate); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 935 | /* Detected a hang */ |
| 936 | |
| 937 | |
| 938 | /* |
| 939 | * Trigger an automatic dump of the state to |
| 940 | * the console |
| 941 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 942 | adreno_postmortem_dump(device, 0); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 943 | |
| 944 | /* |
| 945 | * Make a GPU snapshot. For now, do it after the PM dump so we |
| 946 | * can at least be sure the PM dump will work as it always has |
| 947 | */ |
| 948 | kgsl_device_snapshot(device, 1); |
| 949 | |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 950 | result = adreno_recover_hang(device); |
| 951 | if (result) |
| 952 | kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG); |
| 953 | else |
| 954 | kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); |
| 955 | complete_all(&device->recovery_gate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 956 | } |
| 957 | done: |
| 958 | return result; |
| 959 | } |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 960 | EXPORT_SYMBOL(adreno_dump_and_recover); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 961 | |
| 962 | static int adreno_getproperty(struct kgsl_device *device, |
| 963 | enum kgsl_property_type type, |
| 964 | void *value, |
| 965 | unsigned int sizebytes) |
| 966 | { |
| 967 | int status = -EINVAL; |
| 968 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 969 | |
| 970 | switch (type) { |
| 971 | case KGSL_PROP_DEVICE_INFO: |
| 972 | { |
| 973 | struct kgsl_devinfo devinfo; |
| 974 | |
| 975 | if (sizebytes != sizeof(devinfo)) { |
| 976 | status = -EINVAL; |
| 977 | break; |
| 978 | } |
| 979 | |
| 980 | memset(&devinfo, 0, sizeof(devinfo)); |
| 981 | devinfo.device_id = device->id+1; |
| 982 | devinfo.chip_id = adreno_dev->chip_id; |
| 983 | devinfo.mmu_enabled = kgsl_mmu_enabled(); |
| 984 | devinfo.gpu_id = adreno_dev->gpurev; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 985 | devinfo.gmem_gpubaseaddr = adreno_dev->gmem_base; |
| 986 | devinfo.gmem_sizebytes = adreno_dev->gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 987 | |
| 988 | if (copy_to_user(value, &devinfo, sizeof(devinfo)) != |
| 989 | 0) { |
| 990 | status = -EFAULT; |
| 991 | break; |
| 992 | } |
| 993 | status = 0; |
| 994 | } |
| 995 | break; |
| 996 | case KGSL_PROP_DEVICE_SHADOW: |
| 997 | { |
| 998 | struct kgsl_shadowprop shadowprop; |
| 999 | |
| 1000 | if (sizebytes != sizeof(shadowprop)) { |
| 1001 | status = -EINVAL; |
| 1002 | break; |
| 1003 | } |
| 1004 | memset(&shadowprop, 0, sizeof(shadowprop)); |
| 1005 | if (device->memstore.hostptr) { |
| 1006 | /*NOTE: with mmu enabled, gpuaddr doesn't mean |
| 1007 | * anything to mmap(). |
| 1008 | */ |
| 1009 | shadowprop.gpuaddr = device->memstore.physaddr; |
| 1010 | shadowprop.size = device->memstore.size; |
| 1011 | /* GSL needs this to be set, even if it |
| 1012 | appears to be meaningless */ |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1013 | shadowprop.flags = KGSL_FLAGS_INITIALIZED | |
| 1014 | KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1015 | } |
| 1016 | if (copy_to_user(value, &shadowprop, |
| 1017 | sizeof(shadowprop))) { |
| 1018 | status = -EFAULT; |
| 1019 | break; |
| 1020 | } |
| 1021 | status = 0; |
| 1022 | } |
| 1023 | break; |
| 1024 | case KGSL_PROP_MMU_ENABLE: |
| 1025 | { |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 1026 | int mmu_prop = kgsl_mmu_enabled(); |
| 1027 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1028 | if (sizebytes != sizeof(int)) { |
| 1029 | status = -EINVAL; |
| 1030 | break; |
| 1031 | } |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 1032 | if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1033 | status = -EFAULT; |
| 1034 | break; |
| 1035 | } |
| 1036 | status = 0; |
| 1037 | } |
| 1038 | break; |
| 1039 | case KGSL_PROP_INTERRUPT_WAITS: |
| 1040 | { |
| 1041 | int int_waits = 1; |
| 1042 | if (sizebytes != sizeof(int)) { |
| 1043 | status = -EINVAL; |
| 1044 | break; |
| 1045 | } |
| 1046 | if (copy_to_user(value, &int_waits, sizeof(int))) { |
| 1047 | status = -EFAULT; |
| 1048 | break; |
| 1049 | } |
| 1050 | status = 0; |
| 1051 | } |
| 1052 | break; |
| 1053 | default: |
| 1054 | status = -EINVAL; |
| 1055 | } |
| 1056 | |
| 1057 | return status; |
| 1058 | } |
| 1059 | |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 1060 | static int adreno_setproperty(struct kgsl_device *device, |
| 1061 | enum kgsl_property_type type, |
| 1062 | void *value, |
| 1063 | unsigned int sizebytes) |
| 1064 | { |
| 1065 | int status = -EINVAL; |
| 1066 | |
| 1067 | switch (type) { |
| 1068 | case KGSL_PROP_PWRCTRL: { |
| 1069 | unsigned int enable; |
| 1070 | struct kgsl_device_platform_data *pdata = |
| 1071 | kgsl_device_get_drvdata(device); |
| 1072 | |
| 1073 | if (sizebytes != sizeof(enable)) |
| 1074 | break; |
| 1075 | |
| 1076 | if (copy_from_user(&enable, (void __user *) value, |
| 1077 | sizeof(enable))) { |
| 1078 | status = -EFAULT; |
| 1079 | break; |
| 1080 | } |
| 1081 | |
| 1082 | if (enable) { |
| 1083 | if (pdata->nap_allowed) |
| 1084 | device->pwrctrl.nap_allowed = true; |
| 1085 | |
| 1086 | kgsl_pwrscale_enable(device); |
| 1087 | } else { |
| 1088 | device->pwrctrl.nap_allowed = false; |
| 1089 | kgsl_pwrscale_disable(device); |
| 1090 | } |
| 1091 | |
| 1092 | status = 0; |
| 1093 | } |
| 1094 | break; |
| 1095 | default: |
| 1096 | break; |
| 1097 | } |
| 1098 | |
| 1099 | return status; |
| 1100 | } |
| 1101 | |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1102 | static inline void adreno_poke(struct kgsl_device *device) |
| 1103 | { |
| 1104 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1105 | adreno_regwrite(device, REG_CP_RB_WPTR, adreno_dev->ringbuffer.wptr); |
| 1106 | } |
| 1107 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1108 | /* Caller must hold the device mutex. */ |
| 1109 | int adreno_idle(struct kgsl_device *device, unsigned int timeout) |
| 1110 | { |
| 1111 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1112 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1113 | unsigned int rbbm_status; |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1114 | unsigned long wait_timeout = |
| 1115 | msecs_to_jiffies(adreno_dev->wait_timeout); |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1116 | unsigned long wait_time; |
| 1117 | unsigned long wait_time_part; |
| 1118 | unsigned int msecs; |
| 1119 | unsigned int msecs_first; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1120 | unsigned int msecs_part = KGSL_TIMEOUT_PART; |
| 1121 | unsigned int prev_reg_val[hang_detect_regs_count]; |
| 1122 | |
| 1123 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1124 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1125 | kgsl_cffdump_regpoll(device->id, |
| 1126 | adreno_dev->gpudev->reg_rbbm_status << 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1127 | 0x00000000, 0x80000000); |
| 1128 | /* first, wait until the CP has consumed all the commands in |
| 1129 | * the ring buffer |
| 1130 | */ |
| 1131 | retry: |
| 1132 | if (rb->flags & KGSL_FLAGS_STARTED) { |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1133 | msecs = adreno_dev->wait_timeout; |
| 1134 | msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100; |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1135 | wait_time = jiffies + wait_timeout; |
| 1136 | wait_time_part = jiffies + msecs_to_jiffies(msecs_first); |
Jeremy Gebben | f859454 | 2012-01-13 12:27:21 -0700 | [diff] [blame] | 1137 | adreno_poke(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1138 | do { |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1139 | if (time_after(jiffies, wait_time_part)) { |
| 1140 | adreno_poke(device); |
| 1141 | wait_time_part = jiffies + |
| 1142 | msecs_to_jiffies(msecs_part); |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1143 | if ((adreno_hang_detect(device, prev_reg_val))) |
| 1144 | goto err; |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 1145 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1146 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 1147 | if (time_after(jiffies, wait_time)) { |
| 1148 | KGSL_DRV_ERR(device, "rptr: %x, wptr: %x\n", |
| 1149 | rb->rptr, rb->wptr); |
| 1150 | goto err; |
| 1151 | } |
| 1152 | } while (rb->rptr != rb->wptr); |
| 1153 | } |
| 1154 | |
| 1155 | /* now, wait for the GPU to finish its operations */ |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1156 | wait_time = jiffies + wait_timeout; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1157 | wait_time_part = jiffies + msecs_to_jiffies(msecs_part); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1158 | while (time_before(jiffies, wait_time)) { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1159 | adreno_regread(device, adreno_dev->gpudev->reg_rbbm_status, |
| 1160 | &rbbm_status); |
| 1161 | if (adreno_is_a2xx(adreno_dev)) { |
| 1162 | if (rbbm_status == 0x110) |
| 1163 | return 0; |
| 1164 | } else { |
| 1165 | if (!(rbbm_status & 0x80000000)) |
| 1166 | return 0; |
| 1167 | } |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1168 | |
| 1169 | /* Dont wait for timeout, detect hang faster. |
| 1170 | */ |
| 1171 | if (time_after(jiffies, wait_time_part)) { |
| 1172 | wait_time_part = jiffies + |
| 1173 | msecs_to_jiffies(msecs_part); |
| 1174 | if ((adreno_hang_detect(device, prev_reg_val))) |
| 1175 | goto err; |
| 1176 | } |
| 1177 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | err: |
| 1181 | 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] | 1182 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state && |
| 1183 | !adreno_dump_and_recover(device)) { |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1184 | wait_time = jiffies + wait_timeout; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1185 | goto retry; |
| 1186 | } |
| 1187 | return -ETIMEDOUT; |
| 1188 | } |
| 1189 | |
| 1190 | static unsigned int adreno_isidle(struct kgsl_device *device) |
| 1191 | { |
| 1192 | int status = false; |
| 1193 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1194 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1195 | unsigned int rbbm_status; |
| 1196 | |
Lucille Sylvester | 51b764d | 2011-12-15 16:51:52 -0700 | [diff] [blame] | 1197 | WARN_ON(device->state == KGSL_STATE_INIT); |
| 1198 | /* If the device isn't active, don't force it on. */ |
| 1199 | if (device->state == KGSL_STATE_ACTIVE) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1200 | /* Is the ring buffer is empty? */ |
| 1201 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 1202 | if (!device->active_cnt && (rb->rptr == rb->wptr)) { |
| 1203 | /* Is the core idle? */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1204 | adreno_regread(device, |
| 1205 | adreno_dev->gpudev->reg_rbbm_status, |
| 1206 | &rbbm_status); |
| 1207 | |
| 1208 | if (adreno_is_a2xx(adreno_dev)) { |
| 1209 | if (rbbm_status == 0x110) |
| 1210 | status = true; |
| 1211 | } else { |
| 1212 | if (!(rbbm_status & 0x80000000)) |
| 1213 | status = true; |
| 1214 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1215 | } |
| 1216 | } else { |
Jeremy Gebben | aeb2387 | 2011-12-13 15:58:24 -0700 | [diff] [blame] | 1217 | status = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1218 | } |
| 1219 | return status; |
| 1220 | } |
| 1221 | |
| 1222 | /* Caller must hold the device mutex. */ |
| 1223 | static int adreno_suspend_context(struct kgsl_device *device) |
| 1224 | { |
| 1225 | int status = 0; |
| 1226 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1227 | |
| 1228 | /* switch to NULL ctxt */ |
| 1229 | if (adreno_dev->drawctxt_active != NULL) { |
| 1230 | adreno_drawctxt_switch(adreno_dev, NULL, 0); |
| 1231 | status = adreno_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 1232 | } |
| 1233 | |
| 1234 | return status; |
| 1235 | } |
| 1236 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 1237 | /* Find a memory structure attached to an adreno context */ |
| 1238 | |
| 1239 | struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device, |
| 1240 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size) |
| 1241 | { |
| 1242 | struct kgsl_context *context; |
| 1243 | struct adreno_context *adreno_context = NULL; |
| 1244 | int next = 0; |
| 1245 | |
| 1246 | while (1) { |
| 1247 | context = idr_get_next(&device->context_idr, &next); |
| 1248 | if (context == NULL) |
| 1249 | break; |
| 1250 | |
| 1251 | adreno_context = (struct adreno_context *)context->devctxt; |
| 1252 | |
| 1253 | if (kgsl_mmu_pt_equal(adreno_context->pagetable, pt_base)) { |
| 1254 | struct kgsl_memdesc *desc; |
| 1255 | |
| 1256 | desc = &adreno_context->gpustate; |
| 1257 | if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size)) |
| 1258 | return desc; |
| 1259 | |
| 1260 | desc = &adreno_context->context_gmem_shadow.gmemshadow; |
| 1261 | if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size)) |
| 1262 | return desc; |
| 1263 | } |
| 1264 | next = next + 1; |
| 1265 | } |
| 1266 | |
| 1267 | return NULL; |
| 1268 | } |
| 1269 | |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 1270 | struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device, |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1271 | unsigned int pt_base, |
| 1272 | unsigned int gpuaddr, |
| 1273 | unsigned int size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1274 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1275 | struct kgsl_mem_entry *entry; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1276 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1277 | struct adreno_ringbuffer *ringbuffer = &adreno_dev->ringbuffer; |
| 1278 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1279 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->buffer_desc, gpuaddr, size)) |
| 1280 | return &ringbuffer->buffer_desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1281 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1282 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->memptrs_desc, gpuaddr, size)) |
| 1283 | return &ringbuffer->memptrs_desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1284 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1285 | if (kgsl_gpuaddr_in_memdesc(&device->memstore, gpuaddr, size)) |
| 1286 | return &device->memstore; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1287 | |
Shubhraprakash Das | 9a14097 | 2012-04-12 13:12:42 -0600 | [diff] [blame] | 1288 | if (kgsl_gpuaddr_in_memdesc(&device->mmu.setstate_memory, gpuaddr, |
| 1289 | size)) |
| 1290 | return &device->mmu.setstate_memory; |
| 1291 | |
Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 1292 | entry = kgsl_get_mem_entry(pt_base, gpuaddr, size); |
| 1293 | |
| 1294 | if (entry) |
| 1295 | return &entry->memdesc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1296 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 1297 | return adreno_find_ctxtmem(device, pt_base, gpuaddr, size); |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | uint8_t *adreno_convertaddr(struct kgsl_device *device, unsigned int pt_base, |
| 1301 | unsigned int gpuaddr, unsigned int size) |
| 1302 | { |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 1303 | struct kgsl_memdesc *memdesc; |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 1304 | |
| 1305 | memdesc = adreno_find_region(device, pt_base, gpuaddr, size); |
| 1306 | |
| 1307 | return memdesc ? kgsl_gpuaddr_to_vaddr(memdesc, gpuaddr) : NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | void adreno_regread(struct kgsl_device *device, unsigned int offsetwords, |
| 1311 | unsigned int *value) |
| 1312 | { |
| 1313 | unsigned int *reg; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1314 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
| 1315 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1316 | |
| 1317 | if (!in_interrupt()) |
| 1318 | kgsl_pre_hwaccess(device); |
| 1319 | |
| 1320 | /*ensure this read finishes before the next one. |
| 1321 | * i.e. act like normal readl() */ |
| 1322 | *value = __raw_readl(reg); |
| 1323 | rmb(); |
| 1324 | } |
| 1325 | |
| 1326 | void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords, |
| 1327 | unsigned int value) |
| 1328 | { |
| 1329 | unsigned int *reg; |
| 1330 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1331 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1332 | |
| 1333 | if (!in_interrupt()) |
| 1334 | kgsl_pre_hwaccess(device); |
| 1335 | |
| 1336 | kgsl_cffdump_regwrite(device->id, offsetwords << 2, value); |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1337 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1338 | |
| 1339 | /*ensure previous writes post before this one, |
| 1340 | * i.e. act like normal writel() */ |
| 1341 | wmb(); |
| 1342 | __raw_writel(value, reg); |
| 1343 | } |
| 1344 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1345 | static unsigned int _get_context_id(struct kgsl_context *k_ctxt) |
| 1346 | { |
| 1347 | unsigned int context_id = KGSL_MEMSTORE_GLOBAL; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1348 | if (k_ctxt != NULL) { |
| 1349 | struct adreno_context *a_ctxt = k_ctxt->devctxt; |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1350 | if (k_ctxt->id == KGSL_CONTEXT_INVALID || a_ctxt == NULL) |
| 1351 | context_id = KGSL_CONTEXT_INVALID; |
| 1352 | else if (a_ctxt->flags & CTXT_FLAGS_PER_CONTEXT_TS) |
| 1353 | context_id = k_ctxt->id; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | return context_id; |
| 1357 | } |
| 1358 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1359 | static int kgsl_check_interrupt_timestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1360 | struct kgsl_context *context, unsigned int timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1361 | { |
| 1362 | int status; |
| 1363 | unsigned int ref_ts, enableflag; |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1364 | unsigned int context_id; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 1365 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1366 | |
| 1367 | mutex_lock(&device->mutex); |
| 1368 | context_id = _get_context_id(context); |
| 1369 | /* |
| 1370 | * If the context ID is invalid, we are in a race with |
| 1371 | * the context being destroyed by userspace so bail. |
| 1372 | */ |
| 1373 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 1374 | KGSL_DRV_WARN(device, "context was detached"); |
| 1375 | status = -EINVAL; |
| 1376 | goto unlock; |
| 1377 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1378 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1379 | status = kgsl_check_timestamp(device, context, timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1380 | if (!status) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1381 | kgsl_sharedmem_readl(&device->memstore, &enableflag, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1382 | KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1383 | mb(); |
| 1384 | |
| 1385 | if (enableflag) { |
| 1386 | kgsl_sharedmem_readl(&device->memstore, &ref_ts, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1387 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1388 | ref_wait_ts)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1389 | mb(); |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 1390 | if (timestamp_cmp(ref_ts, timestamp) >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1391 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1392 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1393 | ref_wait_ts), timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1394 | wmb(); |
| 1395 | } |
| 1396 | } else { |
| 1397 | unsigned int cmds[2]; |
| 1398 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1399 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1400 | ref_wait_ts), timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1401 | enableflag = 1; |
| 1402 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1403 | KGSL_MEMSTORE_OFFSET(context_id, |
| 1404 | ts_cmp_enable), enableflag); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1405 | wmb(); |
| 1406 | /* submit a dummy packet so that even if all |
| 1407 | * commands upto timestamp get executed we will still |
| 1408 | * get an interrupt */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 1409 | cmds[0] = cp_type3_packet(CP_NOP, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1410 | cmds[1] = 0; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 1411 | |
| 1412 | if (adreno_dev->drawctxt_active) |
| 1413 | adreno_ringbuffer_issuecmds(device, |
| 1414 | adreno_dev->drawctxt_active, |
| 1415 | KGSL_CMD_FLAGS_NONE, &cmds[0], 2); |
| 1416 | else |
| 1417 | /* We would never call this function if there |
| 1418 | * was no active contexts running */ |
| 1419 | BUG(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1420 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1421 | } |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1422 | unlock: |
| 1423 | mutex_unlock(&device->mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1424 | |
| 1425 | return status; |
| 1426 | } |
| 1427 | |
| 1428 | /* |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1429 | wait_event_interruptible_timeout checks for the exit condition before |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1430 | placing a process in wait q. For conditional interrupts we expect the |
| 1431 | process to already be in its wait q when its exit condition checking |
| 1432 | function is called. |
| 1433 | */ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1434 | #define kgsl_wait_event_interruptible_timeout(wq, condition, timeout, io)\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1435 | ({ \ |
| 1436 | long __ret = timeout; \ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1437 | if (io) \ |
| 1438 | __wait_io_event_interruptible_timeout(wq, condition, __ret);\ |
| 1439 | else \ |
| 1440 | __wait_event_interruptible_timeout(wq, condition, __ret);\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1441 | __ret; \ |
| 1442 | }) |
| 1443 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1444 | |
| 1445 | |
| 1446 | unsigned int adreno_hang_detect(struct kgsl_device *device, |
| 1447 | unsigned int *prev_reg_val) |
| 1448 | { |
| 1449 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1450 | unsigned int curr_reg_val[hang_detect_regs_count]; |
| 1451 | unsigned int hang_detected = 1; |
| 1452 | unsigned int i; |
| 1453 | |
| 1454 | if (!adreno_dev->fast_hang_detect) |
| 1455 | return 0; |
| 1456 | |
| 1457 | for (i = 0; i < hang_detect_regs_count; i++) { |
| 1458 | adreno_regread(device, hang_detect_regs[i], |
| 1459 | &curr_reg_val[i]); |
| 1460 | if (curr_reg_val[i] != prev_reg_val[i]) { |
| 1461 | prev_reg_val[i] = curr_reg_val[i]; |
| 1462 | hang_detected = 0; |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | return hang_detected; |
| 1467 | } |
| 1468 | |
| 1469 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1470 | /* MUST be called with the device mutex held */ |
| 1471 | static int adreno_waittimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1472 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1473 | unsigned int timestamp, |
| 1474 | unsigned int msecs) |
| 1475 | { |
| 1476 | long status = 0; |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1477 | uint io = 1; |
Lucille Sylvester | 596d4c2 | 2011-10-19 18:04:01 -0600 | [diff] [blame] | 1478 | static uint io_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1479 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 1480 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1481 | int retries = 0; |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1482 | unsigned int msecs_first; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1483 | unsigned int msecs_part = KGSL_TIMEOUT_PART; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1484 | unsigned int ts_issued; |
| 1485 | unsigned int context_id = _get_context_id(context); |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1486 | unsigned int time_elapsed = 0; |
| 1487 | unsigned int prev_reg_val[hang_detect_regs_count]; |
| 1488 | |
| 1489 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1490 | |
| 1491 | ts_issued = adreno_dev->ringbuffer.timestamp[context_id]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1492 | |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1493 | /* Don't wait forever, set a max value for now */ |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1494 | if (msecs == KGSL_TIMEOUT_DEFAULT) |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 1495 | msecs = adreno_dev->wait_timeout; |
| 1496 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1497 | if (timestamp_cmp(timestamp, ts_issued) > 0) { |
| 1498 | KGSL_DRV_ERR(device, "Cannot wait for invalid ts <%d:0x%x>, " |
| 1499 | "last issued ts <%d:0x%x>\n", |
| 1500 | context_id, timestamp, context_id, ts_issued); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1501 | status = -EINVAL; |
| 1502 | goto done; |
| 1503 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1504 | |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1505 | /* Keep the first timeout as 100msecs before rewriting |
| 1506 | * the WPTR. Less visible impact if the WPTR has not |
| 1507 | * been updated properly. |
| 1508 | */ |
| 1509 | msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1510 | do { |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1511 | /* |
| 1512 | * If the context ID is invalid, we are in a race with |
| 1513 | * the context being destroyed by userspace so bail. |
| 1514 | */ |
| 1515 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 1516 | KGSL_DRV_WARN(device, "context was detached"); |
| 1517 | status = -EINVAL; |
| 1518 | goto done; |
| 1519 | } |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1520 | if (kgsl_check_timestamp(device, context, timestamp)) { |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1521 | /* if the timestamp happens while we're not |
| 1522 | * waiting, there's a chance that an interrupt |
| 1523 | * will not be generated and thus the timestamp |
| 1524 | * work needs to be queued. |
Lynus Vaz | 06a9a90 | 2011-10-04 19:25:33 +0530 | [diff] [blame] | 1525 | */ |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1526 | queue_work(device->work_queue, &device->ts_expired_ws); |
| 1527 | status = 0; |
| 1528 | goto done; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1529 | } |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1530 | adreno_poke(device); |
| 1531 | io_cnt = (io_cnt + 1) % 100; |
| 1532 | if (io_cnt < |
| 1533 | pwr->pwrlevels[pwr->active_pwrlevel].io_fraction) |
| 1534 | io = 0; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1535 | |
| 1536 | if ((retries > 0) && |
| 1537 | (adreno_hang_detect(device, prev_reg_val))) |
| 1538 | goto hang_dump; |
| 1539 | |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1540 | mutex_unlock(&device->mutex); |
| 1541 | /* We need to make sure that the process is |
| 1542 | * placed in wait-q before its condition is called |
| 1543 | */ |
| 1544 | status = kgsl_wait_event_interruptible_timeout( |
| 1545 | device->wait_queue, |
| 1546 | kgsl_check_interrupt_timestamp(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1547 | context, timestamp), |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1548 | msecs_to_jiffies(retries ? |
| 1549 | msecs_part : msecs_first), io); |
| 1550 | mutex_lock(&device->mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1551 | |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1552 | if (status > 0) { |
| 1553 | /*completed before the wait finished */ |
| 1554 | status = 0; |
| 1555 | goto done; |
| 1556 | } else if (status < 0) { |
| 1557 | /*an error occurred*/ |
| 1558 | goto done; |
| 1559 | } |
| 1560 | /*this wait timed out*/ |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1561 | |
| 1562 | time_elapsed = time_elapsed + |
| 1563 | (retries ? msecs_part : msecs_first); |
| 1564 | retries++; |
| 1565 | |
| 1566 | } while (time_elapsed < msecs); |
| 1567 | |
| 1568 | hang_dump: |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1569 | status = -ETIMEDOUT; |
| 1570 | KGSL_DRV_ERR(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1571 | "Device hang detected while waiting for timestamp: " |
| 1572 | "<%d:0x%x>, last submitted timestamp: <%d:0x%x>, " |
| 1573 | "wptr: 0x%x\n", |
| 1574 | context_id, timestamp, context_id, ts_issued, |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1575 | adreno_dev->ringbuffer.wptr); |
| 1576 | if (!adreno_dump_and_recover(device)) { |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 1577 | /* The timestamp that this process wanted |
| 1578 | * to wait on may be invalid or expired now |
| 1579 | * after successful recovery */ |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 1580 | status = 0; |
| 1581 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1582 | done: |
| 1583 | return (int)status; |
| 1584 | } |
| 1585 | |
| 1586 | static unsigned int adreno_readtimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1587 | struct kgsl_context *context, enum kgsl_timestamp_type type) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1588 | { |
| 1589 | unsigned int timestamp = 0; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1590 | unsigned int context_id = _get_context_id(context); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1591 | |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1592 | /* |
| 1593 | * If the context ID is invalid, we are in a race with |
| 1594 | * the context being destroyed by userspace so bail. |
| 1595 | */ |
| 1596 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 1597 | KGSL_DRV_WARN(device, "context was detached"); |
| 1598 | return timestamp; |
| 1599 | } |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 1600 | switch (type) { |
| 1601 | case KGSL_TIMESTAMP_QUEUED: { |
| 1602 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1603 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1604 | |
| 1605 | timestamp = rb->timestamp[context_id]; |
| 1606 | break; |
| 1607 | } |
| 1608 | case KGSL_TIMESTAMP_CONSUMED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1609 | adreno_regread(device, REG_CP_TIMESTAMP, ×tamp); |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 1610 | break; |
| 1611 | case KGSL_TIMESTAMP_RETIRED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1612 | kgsl_sharedmem_readl(&device->memstore, ×tamp, |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 1613 | KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp)); |
| 1614 | break; |
| 1615 | } |
| 1616 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1617 | rmb(); |
| 1618 | |
| 1619 | return timestamp; |
| 1620 | } |
| 1621 | |
| 1622 | static long adreno_ioctl(struct kgsl_device_private *dev_priv, |
| 1623 | unsigned int cmd, void *data) |
| 1624 | { |
| 1625 | int result = 0; |
| 1626 | struct kgsl_drawctxt_set_bin_base_offset *binbase; |
| 1627 | struct kgsl_context *context; |
| 1628 | |
| 1629 | switch (cmd) { |
| 1630 | case IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET: |
| 1631 | binbase = data; |
| 1632 | |
| 1633 | context = kgsl_find_context(dev_priv, binbase->drawctxt_id); |
| 1634 | if (context) { |
| 1635 | adreno_drawctxt_set_bin_base_offset( |
| 1636 | dev_priv->device, context, binbase->offset); |
| 1637 | } else { |
| 1638 | result = -EINVAL; |
| 1639 | KGSL_DRV_ERR(dev_priv->device, |
| 1640 | "invalid drawctxt drawctxt_id %d " |
| 1641 | "device_id=%d\n", |
| 1642 | binbase->drawctxt_id, dev_priv->device->id); |
| 1643 | } |
| 1644 | break; |
| 1645 | |
| 1646 | default: |
| 1647 | KGSL_DRV_INFO(dev_priv->device, |
| 1648 | "invalid ioctl code %08x\n", cmd); |
Jeremy Gebben | c15b461 | 2012-01-09 09:44:11 -0700 | [diff] [blame] | 1649 | result = -ENOIOCTLCMD; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1650 | break; |
| 1651 | } |
| 1652 | return result; |
| 1653 | |
| 1654 | } |
| 1655 | |
| 1656 | static inline s64 adreno_ticks_to_us(u32 ticks, u32 gpu_freq) |
| 1657 | { |
| 1658 | gpu_freq /= 1000000; |
| 1659 | return ticks / gpu_freq; |
| 1660 | } |
| 1661 | |
| 1662 | static void adreno_power_stats(struct kgsl_device *device, |
| 1663 | struct kgsl_power_stats *stats) |
| 1664 | { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1665 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1666 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1667 | unsigned int cycles; |
| 1668 | |
| 1669 | /* Get the busy cycles counted since the counter was last reset */ |
| 1670 | /* Calling this function also resets and restarts the counter */ |
| 1671 | |
| 1672 | cycles = adreno_dev->gpudev->busy_cycles(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1673 | |
| 1674 | /* In order to calculate idle you have to have run the algorithm * |
| 1675 | * at least once to get a start time. */ |
| 1676 | if (pwr->time != 0) { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1677 | s64 tmp = ktime_to_us(ktime_get()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1678 | stats->total_time = tmp - pwr->time; |
| 1679 | pwr->time = tmp; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1680 | stats->busy_time = adreno_ticks_to_us(cycles, device->pwrctrl. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1681 | pwrlevels[device->pwrctrl.active_pwrlevel]. |
| 1682 | gpu_freq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1683 | } else { |
| 1684 | stats->total_time = 0; |
| 1685 | stats->busy_time = 0; |
| 1686 | pwr->time = ktime_to_us(ktime_get()); |
| 1687 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | void adreno_irqctrl(struct kgsl_device *device, int state) |
| 1691 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 1692 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1693 | adreno_dev->gpudev->irq_control(adreno_dev, state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 1696 | static unsigned int adreno_gpuid(struct kgsl_device *device, |
| 1697 | unsigned int *chipid) |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 1698 | { |
| 1699 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1700 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 1701 | /* Some applications need to know the chip ID too, so pass |
| 1702 | * that as a parameter */ |
| 1703 | |
| 1704 | if (chipid != NULL) |
| 1705 | *chipid = adreno_dev->chip_id; |
| 1706 | |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 1707 | /* Standard KGSL gpuid format: |
| 1708 | * top word is 0x0002 for 2D or 0x0003 for 3D |
| 1709 | * Bottom word is core specific identifer |
| 1710 | */ |
| 1711 | |
| 1712 | return (0x0003 << 16) | ((int) adreno_dev->gpurev); |
| 1713 | } |
| 1714 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1715 | static const struct kgsl_functable adreno_functable = { |
| 1716 | /* Mandatory functions */ |
| 1717 | .regread = adreno_regread, |
| 1718 | .regwrite = adreno_regwrite, |
| 1719 | .idle = adreno_idle, |
| 1720 | .isidle = adreno_isidle, |
| 1721 | .suspend_context = adreno_suspend_context, |
| 1722 | .start = adreno_start, |
| 1723 | .stop = adreno_stop, |
| 1724 | .getproperty = adreno_getproperty, |
| 1725 | .waittimestamp = adreno_waittimestamp, |
| 1726 | .readtimestamp = adreno_readtimestamp, |
| 1727 | .issueibcmds = adreno_ringbuffer_issueibcmds, |
| 1728 | .ioctl = adreno_ioctl, |
| 1729 | .setup_pt = adreno_setup_pt, |
| 1730 | .cleanup_pt = adreno_cleanup_pt, |
| 1731 | .power_stats = adreno_power_stats, |
| 1732 | .irqctrl = adreno_irqctrl, |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 1733 | .gpuid = adreno_gpuid, |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1734 | .snapshot = adreno_snapshot, |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 1735 | .irq_handler = adreno_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1736 | /* Optional functions */ |
| 1737 | .setstate = adreno_setstate, |
| 1738 | .drawctxt_create = adreno_drawctxt_create, |
| 1739 | .drawctxt_destroy = adreno_drawctxt_destroy, |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 1740 | .setproperty = adreno_setproperty, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1741 | }; |
| 1742 | |
| 1743 | static struct platform_device_id adreno_id_table[] = { |
| 1744 | { DEVICE_3D0_NAME, (kernel_ulong_t)&device_3d0.dev, }, |
| 1745 | { }, |
| 1746 | }; |
| 1747 | MODULE_DEVICE_TABLE(platform, adreno_id_table); |
| 1748 | |
| 1749 | static struct platform_driver adreno_platform_driver = { |
| 1750 | .probe = adreno_probe, |
| 1751 | .remove = __devexit_p(adreno_remove), |
| 1752 | .suspend = kgsl_suspend_driver, |
| 1753 | .resume = kgsl_resume_driver, |
| 1754 | .id_table = adreno_id_table, |
| 1755 | .driver = { |
| 1756 | .owner = THIS_MODULE, |
| 1757 | .name = DEVICE_3D_NAME, |
| 1758 | .pm = &kgsl_pm_ops, |
| 1759 | } |
| 1760 | }; |
| 1761 | |
| 1762 | static int __init kgsl_3d_init(void) |
| 1763 | { |
| 1764 | return platform_driver_register(&adreno_platform_driver); |
| 1765 | } |
| 1766 | |
| 1767 | static void __exit kgsl_3d_exit(void) |
| 1768 | { |
| 1769 | platform_driver_unregister(&adreno_platform_driver); |
| 1770 | } |
| 1771 | |
| 1772 | module_init(kgsl_3d_init); |
| 1773 | module_exit(kgsl_3d_exit); |
| 1774 | |
| 1775 | MODULE_DESCRIPTION("3D Graphics driver"); |
| 1776 | MODULE_VERSION("1.2"); |
| 1777 | MODULE_LICENSE("GPL v2"); |
| 1778 | MODULE_ALIAS("platform:kgsl_3d"); |