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