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