Carter Cooper | 8179f5a | 2012-12-17 11:32:27 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2002,2007-2013, The Linux Foundation. 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> |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | |
| 21 | #include <mach/socinfo.h> |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 22 | #include <mach/msm_bus_board.h> |
| 23 | #include <mach/msm_bus.h> |
| 24 | #include <mach/msm_dcvs.h> |
| 25 | #include <mach/msm_dcvs_scm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | |
| 27 | #include "kgsl.h" |
| 28 | #include "kgsl_pwrscale.h" |
| 29 | #include "kgsl_cffdump.h" |
| 30 | #include "kgsl_sharedmem.h" |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 31 | #include "kgsl_iommu.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | |
| 33 | #include "adreno.h" |
| 34 | #include "adreno_pm4types.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | |
Jeremy Gebben | eebc461 | 2011-08-31 10:15:21 -0700 | [diff] [blame] | 36 | #include "a2xx_reg.h" |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 37 | #include "a3xx_reg.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | |
| 39 | #define DRIVER_VERSION_MAJOR 3 |
| 40 | #define DRIVER_VERSION_MINOR 1 |
| 41 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 42 | /* Adreno MH arbiter config*/ |
| 43 | #define ADRENO_CFG_MHARB \ |
| 44 | (0x10 \ |
| 45 | | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \ |
| 46 | | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \ |
| 47 | | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \ |
| 48 | | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \ |
| 49 | | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \ |
| 50 | | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \ |
| 51 | | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \ |
| 52 | | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \ |
| 53 | | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \ |
| 54 | | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \ |
| 55 | | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \ |
| 56 | | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \ |
| 57 | | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \ |
| 58 | | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT)) |
| 59 | |
| 60 | #define ADRENO_MMU_CONFIG \ |
| 61 | (0x01 \ |
| 62 | | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \ |
| 63 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \ |
| 64 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 65 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 66 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \ |
| 67 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \ |
| 68 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \ |
| 69 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 70 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 71 | | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \ |
| 72 | | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT)) |
| 73 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | static const struct kgsl_functable adreno_functable; |
| 75 | |
| 76 | static struct adreno_device device_3d0 = { |
| 77 | .dev = { |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 78 | KGSL_DEVICE_COMMON_INIT(device_3d0.dev), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | .name = DEVICE_3D0_NAME, |
| 80 | .id = KGSL_DEVICE_3D0, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 81 | .mh = { |
| 82 | .mharb = ADRENO_CFG_MHARB, |
| 83 | /* Remove 1k boundary check in z470 to avoid a GPU |
| 84 | * hang. Notice that this solution won't work if |
| 85 | * both EBI and SMI are used |
| 86 | */ |
| 87 | .mh_intf_cfg1 = 0x00032f07, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | /* turn off memory protection unit by setting |
| 89 | acceptable physical address range to include |
| 90 | all pages. */ |
| 91 | .mpu_base = 0x00000000, |
| 92 | .mpu_range = 0xFFFFF000, |
| 93 | }, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 94 | .mmu = { |
| 95 | .config = ADRENO_MMU_CONFIG, |
| 96 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | .pwrctrl = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | .irq_name = KGSL_3D0_IRQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 99 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | .iomemname = KGSL_3D0_REG_MEMORY, |
| 101 | .ftbl = &adreno_functable, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 102 | #ifdef CONFIG_HAS_EARLYSUSPEND |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 103 | .display_off = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING, |
| 105 | .suspend = kgsl_early_suspend_driver, |
| 106 | .resume = kgsl_late_resume_driver, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | }, |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 108 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 109 | }, |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 110 | .gmem_base = 0, |
| 111 | .gmem_size = SZ_256K, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 112 | .pfp_fw = NULL, |
| 113 | .pm4_fw = NULL, |
Jordan Crouse | 21f75a0 | 2012-08-09 15:08:59 -0600 | [diff] [blame] | 114 | .wait_timeout = 0, /* in milliseconds, 0 means disabled */ |
Jeremy Gebben | d0ab6ad | 2012-04-06 11:13:35 -0600 | [diff] [blame] | 115 | .ib_check_level = 0, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 118 | /* This set of registers are used for Hang detection |
| 119 | * If the values of these registers are same after |
| 120 | * KGSL_TIMEOUT_PART time, GPU hang is reported in |
| 121 | * kernel log. |
| 122 | */ |
| 123 | unsigned int hang_detect_regs[] = { |
| 124 | A3XX_RBBM_STATUS, |
| 125 | REG_CP_RB_RPTR, |
| 126 | REG_CP_IB1_BASE, |
| 127 | REG_CP_IB1_BUFSZ, |
| 128 | REG_CP_IB2_BASE, |
| 129 | REG_CP_IB2_BUFSZ, |
Jordan Crouse | b5c8048 | 2012-10-03 09:38:41 -0600 | [diff] [blame] | 130 | 0, |
Tarun Karra | 6e750d7 | 2013-01-04 10:28:40 -0800 | [diff] [blame] | 131 | 0, |
| 132 | 0, |
| 133 | 0, |
| 134 | 0, |
Jordan Crouse | b5c8048 | 2012-10-03 09:38:41 -0600 | [diff] [blame] | 135 | 0 |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | const unsigned int hang_detect_regs_count = ARRAY_SIZE(hang_detect_regs); |
Jordan Crouse | 95b3327 | 2011-11-11 14:50:12 -0700 | [diff] [blame] | 139 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 140 | /* |
| 141 | * This is the master list of all GPU cores that are supported by this |
| 142 | * driver. |
| 143 | */ |
| 144 | |
| 145 | #define ANY_ID (~0) |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 146 | #define NO_VER (~0) |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 147 | |
| 148 | static const struct { |
| 149 | enum adreno_gpurev gpurev; |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 150 | unsigned int core, major, minor, patchid; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 151 | const char *pm4fw; |
| 152 | const char *pfpfw; |
| 153 | struct adreno_gpudev *gpudev; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 154 | unsigned int istore_size; |
| 155 | unsigned int pix_shader_start; |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 156 | /* Size of an instruction in dwords */ |
| 157 | unsigned int instruction_size; |
| 158 | /* size of gmem for gpu*/ |
| 159 | unsigned int gmem_size; |
| 160 | /* version of pm4 microcode that supports sync_lock |
| 161 | between CPU and GPU for SMMU-v1 programming */ |
| 162 | unsigned int sync_lock_pm4_ver; |
| 163 | /* version of pfp microcode that supports sync_lock |
| 164 | between CPU and GPU for SMMU-v1 programming */ |
| 165 | unsigned int sync_lock_pfp_ver; |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 166 | } adreno_gpulist[] = { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 167 | { ADRENO_REV_A200, 0, 2, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 168 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 169 | 512, 384, 3, SZ_256K, NO_VER, NO_VER }, |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 170 | { ADRENO_REV_A203, 0, 1, 1, ANY_ID, |
| 171 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 172 | 512, 384, 3, SZ_256K, NO_VER, NO_VER }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 173 | { ADRENO_REV_A205, 0, 1, 0, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 174 | "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 175 | 512, 384, 3, SZ_256K, NO_VER, NO_VER }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 176 | { ADRENO_REV_A220, 2, 1, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 177 | "leia_pm4_470.fw", "leia_pfp_470.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 178 | 512, 384, 3, SZ_512K, NO_VER, NO_VER }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 179 | /* |
| 180 | * patchlevel 5 (8960v2) needs special pm4 firmware to work around |
| 181 | * a hardware problem. |
| 182 | */ |
| 183 | { ADRENO_REV_A225, 2, 2, 0, 5, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 184 | "a225p5_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 185 | 1536, 768, 3, SZ_512K, NO_VER, NO_VER }, |
Carter Cooper | f27ec72 | 2011-11-17 15:20:38 -0700 | [diff] [blame] | 186 | { ADRENO_REV_A225, 2, 2, 0, 6, |
| 187 | "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 188 | 1536, 768, 3, SZ_512K, 0x225011, 0x225002 }, |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 189 | { ADRENO_REV_A225, 2, 2, ANY_ID, ANY_ID, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 190 | "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 191 | 1536, 768, 3, SZ_512K, 0x225011, 0x225002 }, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 192 | /* A3XX doesn't use the pix_shader_start */ |
Sudhakara Rao Tentu | e13766d | 2012-06-12 06:00:26 +0530 | [diff] [blame] | 193 | { ADRENO_REV_A305, 3, 0, 5, ANY_ID, |
Sudhakara Rao Tentu | 7985383 | 2012-03-06 15:52:38 +0530 | [diff] [blame] | 194 | "a300_pm4.fw", "a300_pfp.fw", &adreno_a3xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 195 | 512, 0, 2, SZ_256K, 0x3FF037, 0x3FF016 }, |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 196 | /* A3XX doesn't use the pix_shader_start */ |
Carter Cooper | 95f7f79 | 2012-08-19 13:40:34 -0600 | [diff] [blame] | 197 | { ADRENO_REV_A320, 3, 2, ANY_ID, ANY_ID, |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 198 | "a300_pm4.fw", "a300_pfp.fw", &adreno_a3xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 199 | 512, 0, 2, SZ_512K, 0x3FF037, 0x3FF016 }, |
liu zhong | fd42e62 | 2012-05-01 19:18:30 -0700 | [diff] [blame] | 200 | { ADRENO_REV_A330, 3, 3, 0, 0, |
| 201 | "a330_pm4.fw", "a330_pfp.fw", &adreno_a3xx_gpudev, |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 202 | 512, 0, 2, SZ_1M, NO_VER, NO_VER }, |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 203 | }; |
| 204 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 205 | static irqreturn_t adreno_irq_handler(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 206 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 207 | irqreturn_t result; |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 208 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 209 | |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 210 | result = adreno_dev->gpudev->irq_handler(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 211 | |
| 212 | if (device->requested_state == KGSL_STATE_NONE) { |
| 213 | if (device->pwrctrl.nap_allowed == true) { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 214 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 215 | queue_work(device->work_queue, &device->idle_check_ws); |
| 216 | } else if (device->pwrscale.policy != NULL) { |
| 217 | queue_work(device->work_queue, &device->idle_check_ws); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /* Reset the time-out in our idle timer */ |
Tarun Karra | 6875576 | 2012-01-12 16:07:09 -0800 | [diff] [blame] | 222 | mod_timer_pending(&device->idle_timer, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 223 | jiffies + device->pwrctrl.interval_timeout); |
| 224 | return result; |
| 225 | } |
| 226 | |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 227 | static void adreno_cleanup_pt(struct kgsl_device *device, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | struct kgsl_pagetable *pagetable) |
| 229 | { |
| 230 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 231 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 232 | |
| 233 | kgsl_mmu_unmap(pagetable, &rb->buffer_desc); |
| 234 | |
| 235 | kgsl_mmu_unmap(pagetable, &rb->memptrs_desc); |
| 236 | |
| 237 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 238 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 239 | kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static int adreno_setup_pt(struct kgsl_device *device, |
| 243 | struct kgsl_pagetable *pagetable) |
| 244 | { |
| 245 | int result = 0; |
| 246 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 247 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 248 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 249 | result = kgsl_mmu_map_global(pagetable, &rb->buffer_desc, |
| 250 | GSL_PT_PAGE_RV); |
| 251 | if (result) |
| 252 | goto error; |
| 253 | |
| 254 | result = kgsl_mmu_map_global(pagetable, &rb->memptrs_desc, |
| 255 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 256 | if (result) |
| 257 | goto unmap_buffer_desc; |
| 258 | |
| 259 | result = kgsl_mmu_map_global(pagetable, &device->memstore, |
| 260 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 261 | if (result) |
| 262 | goto unmap_memptrs_desc; |
| 263 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 264 | result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 265 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 266 | if (result) |
| 267 | goto unmap_memstore_desc; |
| 268 | |
| 269 | return result; |
| 270 | |
| 271 | unmap_memstore_desc: |
| 272 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 273 | |
| 274 | unmap_memptrs_desc: |
| 275 | kgsl_mmu_unmap(pagetable, &rb->memptrs_desc); |
| 276 | |
| 277 | unmap_buffer_desc: |
| 278 | kgsl_mmu_unmap(pagetable, &rb->buffer_desc); |
| 279 | |
| 280 | error: |
| 281 | return result; |
| 282 | } |
| 283 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 284 | static void adreno_iommu_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 285 | unsigned int context_id, |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 286 | uint32_t flags) |
| 287 | { |
| 288 | unsigned int pt_val, reg_pt_val; |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 289 | unsigned int link[250]; |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 290 | unsigned int *cmds = &link[0]; |
| 291 | int sizedwords = 0; |
| 292 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 293 | int num_iommu_units, i; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 294 | struct kgsl_context *context; |
| 295 | struct adreno_context *adreno_ctx = NULL; |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 296 | |
| 297 | if (!adreno_dev->drawctxt_active) |
| 298 | return kgsl_mmu_device_setstate(&device->mmu, flags); |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 299 | num_iommu_units = kgsl_mmu_get_num_iommu_units(&device->mmu); |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 300 | |
| 301 | context = idr_find(&device->context_idr, context_id); |
Jordan Crouse | eef8a13 | 2013-01-11 11:17:16 -0700 | [diff] [blame] | 302 | if (context == NULL) |
| 303 | return; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 304 | adreno_ctx = context->devctxt; |
| 305 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 306 | if (kgsl_mmu_enable_clk(&device->mmu, |
| 307 | KGSL_IOMMU_CONTEXT_USER)) |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 308 | return; |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 309 | |
Shubhraprakash Das | 939c0d4 | 2012-06-15 11:40:48 -0600 | [diff] [blame] | 310 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 311 | device->mmu.setstate_memory.gpuaddr + |
| 312 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 313 | |
Shubhraprakash Das | 19ca4a6 | 2012-05-18 12:11:20 -0600 | [diff] [blame] | 314 | if (cpu_is_msm8960()) |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 315 | cmds += adreno_add_change_mh_phys_limit_cmds(cmds, 0xFFFFF000, |
| 316 | device->mmu.setstate_memory.gpuaddr + |
| 317 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 318 | else |
| 319 | cmds += adreno_add_bank_change_cmds(cmds, |
| 320 | KGSL_IOMMU_CONTEXT_USER, |
| 321 | device->mmu.setstate_memory.gpuaddr + |
| 322 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 323 | |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 324 | cmds += adreno_add_idle_cmds(adreno_dev, cmds); |
| 325 | |
| 326 | /* Acquire GPU-CPU sync Lock here */ |
| 327 | cmds += kgsl_mmu_sync_lock(&device->mmu, cmds); |
| 328 | |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 329 | pt_val = kgsl_mmu_get_pt_base_addr(&device->mmu, |
| 330 | device->mmu.hwpagetable); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 331 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 332 | /* |
| 333 | * We need to perfrom the following operations for all |
| 334 | * IOMMU units |
| 335 | */ |
| 336 | for (i = 0; i < num_iommu_units; i++) { |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 337 | reg_pt_val = (pt_val + kgsl_mmu_get_pt_lsb(&device->mmu, |
| 338 | i, KGSL_IOMMU_CONTEXT_USER)); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 339 | /* |
| 340 | * Set address of the new pagetable by writng to IOMMU |
| 341 | * TTBR0 register |
| 342 | */ |
| 343 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 344 | *cmds++ = kgsl_mmu_get_reg_gpuaddr(&device->mmu, i, |
| 345 | KGSL_IOMMU_CONTEXT_USER, KGSL_IOMMU_CTX_TTBR0); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 346 | *cmds++ = reg_pt_val; |
| 347 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
| 348 | *cmds++ = 0x00000000; |
| 349 | |
| 350 | /* |
| 351 | * Read back the ttbr0 register as a barrier to ensure |
| 352 | * above writes have completed |
| 353 | */ |
| 354 | cmds += adreno_add_read_cmds(device, cmds, |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 355 | kgsl_mmu_get_reg_gpuaddr(&device->mmu, i, |
| 356 | KGSL_IOMMU_CONTEXT_USER, KGSL_IOMMU_CTX_TTBR0), |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 357 | reg_pt_val, |
| 358 | device->mmu.setstate_memory.gpuaddr + |
| 359 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 360 | } |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 361 | } |
| 362 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 363 | /* |
Shubhraprakash Das | 8649fa5 | 2012-07-26 15:49:46 -0700 | [diff] [blame] | 364 | * tlb flush |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 365 | */ |
| 366 | for (i = 0; i < num_iommu_units; i++) { |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 367 | reg_pt_val = (pt_val + kgsl_mmu_get_pt_lsb(&device->mmu, |
| 368 | i, KGSL_IOMMU_CONTEXT_USER)); |
Shubhraprakash Das | 8649fa5 | 2012-07-26 15:49:46 -0700 | [diff] [blame] | 369 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 370 | *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2); |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 371 | *cmds++ = kgsl_mmu_get_reg_gpuaddr(&device->mmu, i, |
| 372 | KGSL_IOMMU_CONTEXT_USER, |
Shubhraprakash Das | 8649fa5 | 2012-07-26 15:49:46 -0700 | [diff] [blame] | 373 | KGSL_IOMMU_CTX_TLBIALL); |
| 374 | *cmds++ = 1; |
Shubhraprakash Das | be39728 | 2012-07-09 10:25:01 -0600 | [diff] [blame] | 375 | |
| 376 | cmds += __adreno_add_idle_indirect_cmds(cmds, |
| 377 | device->mmu.setstate_memory.gpuaddr + |
| 378 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 379 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 380 | cmds += adreno_add_read_cmds(device, cmds, |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 381 | kgsl_mmu_get_reg_gpuaddr(&device->mmu, i, |
| 382 | KGSL_IOMMU_CONTEXT_USER, |
| 383 | KGSL_IOMMU_CTX_TTBR0), |
Shubhraprakash Das | 8649fa5 | 2012-07-26 15:49:46 -0700 | [diff] [blame] | 384 | reg_pt_val, |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 385 | device->mmu.setstate_memory.gpuaddr + |
| 386 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 387 | } |
| 388 | } |
| 389 | |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 390 | /* Release GPU-CPU sync Lock here */ |
| 391 | cmds += kgsl_mmu_sync_unlock(&device->mmu, cmds); |
| 392 | |
Shubhraprakash Das | 19ca4a6 | 2012-05-18 12:11:20 -0600 | [diff] [blame] | 393 | if (cpu_is_msm8960()) |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 394 | cmds += adreno_add_change_mh_phys_limit_cmds(cmds, |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 395 | kgsl_mmu_get_reg_gpuaddr(&device->mmu, 0, |
| 396 | 0, KGSL_IOMMU_GLOBAL_BASE), |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 397 | device->mmu.setstate_memory.gpuaddr + |
| 398 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 399 | else |
| 400 | cmds += adreno_add_bank_change_cmds(cmds, |
| 401 | KGSL_IOMMU_CONTEXT_PRIV, |
| 402 | device->mmu.setstate_memory.gpuaddr + |
| 403 | KGSL_IOMMU_SETSTATE_NOP_OFFSET); |
| 404 | |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 405 | cmds += adreno_add_idle_cmds(adreno_dev, cmds); |
| 406 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 407 | sizedwords += (cmds - &link[0]); |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 408 | if (sizedwords) { |
Shubhraprakash Das | aef1984 | 2012-09-10 16:01:43 -0700 | [diff] [blame] | 409 | /* invalidate all base pointers */ |
| 410 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
| 411 | *cmds++ = 0x7fff; |
| 412 | sizedwords += 2; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 413 | /* This returns the per context timestamp but we need to |
| 414 | * use the global timestamp for iommu clock disablement */ |
| 415 | adreno_ringbuffer_issuecmds(device, adreno_ctx, |
| 416 | KGSL_CMD_FLAGS_PMODE, |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 417 | &link[0], sizedwords); |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 418 | kgsl_mmu_disable_clk_on_ts(&device->mmu, |
| 419 | adreno_dev->ringbuffer.timestamp[KGSL_MEMSTORE_GLOBAL], true); |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 420 | } |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 421 | |
| 422 | if (sizedwords > (sizeof(link)/sizeof(unsigned int))) { |
| 423 | KGSL_DRV_ERR(device, "Temp command buffer overflow\n"); |
| 424 | BUG(); |
| 425 | } |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static void adreno_gpummu_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 429 | unsigned int context_id, |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 430 | uint32_t flags) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 431 | { |
| 432 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 433 | unsigned int link[32]; |
| 434 | unsigned int *cmds = &link[0]; |
| 435 | int sizedwords = 0; |
| 436 | unsigned int mh_mmu_invalidate = 0x00000003; /*invalidate all and tc */ |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 437 | struct kgsl_context *context; |
| 438 | struct adreno_context *adreno_ctx = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 439 | |
Jeremy Gebben | a3d07a4 | 2011-10-17 12:08:16 -0600 | [diff] [blame] | 440 | /* |
Rajesh Kemisetti | 22a06d1 | 2012-06-29 20:21:31 +0530 | [diff] [blame] | 441 | * Fix target freeze issue by adding TLB flush for each submit |
| 442 | * on A20X based targets. |
| 443 | */ |
| 444 | if (adreno_is_a20x(adreno_dev)) |
| 445 | flags |= KGSL_MMUFLAGS_TLBFLUSH; |
| 446 | /* |
Jeremy Gebben | a3d07a4 | 2011-10-17 12:08:16 -0600 | [diff] [blame] | 447 | * If possible, then set the state via the command stream to avoid |
| 448 | * a CPU idle. Otherwise, use the default setstate which uses register |
| 449 | * writes For CFF dump we must idle and use the registers so that it is |
| 450 | * easier to filter out the mmu accesses from the dump |
| 451 | */ |
| 452 | if (!kgsl_cff_dump_enable && adreno_dev->drawctxt_active) { |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 453 | context = idr_find(&device->context_idr, context_id); |
Jordan Crouse | eef8a13 | 2013-01-11 11:17:16 -0700 | [diff] [blame] | 454 | if (context == NULL) |
| 455 | return; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 456 | adreno_ctx = context->devctxt; |
| 457 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 458 | if (flags & KGSL_MMUFLAGS_PTUPDATE) { |
| 459 | /* wait for graphics pipe to be idle */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 460 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 461 | *cmds++ = 0x00000000; |
| 462 | |
| 463 | /* set page table base */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 464 | *cmds++ = cp_type0_packet(MH_MMU_PT_BASE, 1); |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 465 | *cmds++ = kgsl_mmu_get_pt_base_addr(&device->mmu, |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 466 | device->mmu.hwpagetable); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 467 | sizedwords += 4; |
| 468 | } |
| 469 | |
| 470 | if (flags & KGSL_MMUFLAGS_TLBFLUSH) { |
| 471 | if (!(flags & KGSL_MMUFLAGS_PTUPDATE)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 472 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 473 | 1); |
| 474 | *cmds++ = 0x00000000; |
| 475 | sizedwords += 2; |
| 476 | } |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 477 | *cmds++ = cp_type0_packet(MH_MMU_INVALIDATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 478 | *cmds++ = mh_mmu_invalidate; |
| 479 | sizedwords += 2; |
| 480 | } |
| 481 | |
| 482 | if (flags & KGSL_MMUFLAGS_PTUPDATE && |
Jeremy Gebben | 5bb7ece | 2011-08-02 11:04:48 -0600 | [diff] [blame] | 483 | adreno_is_a20x(adreno_dev)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 484 | /* HW workaround: to resolve MMU page fault interrupts |
| 485 | * caused by the VGT.It prevents the CP PFP from filling |
| 486 | * the VGT DMA request fifo too early,thereby ensuring |
| 487 | * that the VGT will not fetch vertex/bin data until |
| 488 | * after the page table base register has been updated. |
| 489 | * |
| 490 | * Two null DRAW_INDX_BIN packets are inserted right |
| 491 | * after the page table base update, followed by a |
| 492 | * wait for idle. The null packets will fill up the |
| 493 | * VGT DMA request fifo and prevent any further |
| 494 | * vertex/bin updates from occurring until the wait |
| 495 | * has finished. */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 496 | *cmds++ = cp_type3_packet(CP_SET_CONSTANT, 2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | *cmds++ = (0x4 << 16) | |
| 498 | (REG_PA_SU_SC_MODE_CNTL - 0x2000); |
| 499 | *cmds++ = 0; /* disable faceness generation */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 500 | *cmds++ = cp_type3_packet(CP_SET_BIN_BASE_OFFSET, 1); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 501 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 502 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 503 | *cmds++ = 0; /* viz query info */ |
| 504 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 505 | *cmds++ = 0; /* bin base */ |
| 506 | *cmds++ = 3; /* bin size */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 507 | *cmds++ = |
| 508 | device->mmu.setstate_memory.gpuaddr; /* dma base */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 509 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 510 | *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 511 | *cmds++ = 0; /* viz query info */ |
| 512 | *cmds++ = 0x0003C004; /* draw indicator */ |
| 513 | *cmds++ = 0; /* bin base */ |
| 514 | *cmds++ = 3; /* bin size */ |
| 515 | /* dma base */ |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 516 | *cmds++ = device->mmu.setstate_memory.gpuaddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 517 | *cmds++ = 6; /* dma size */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 518 | *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 519 | *cmds++ = 0x00000000; |
| 520 | sizedwords += 21; |
| 521 | } |
| 522 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 523 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | if (flags & (KGSL_MMUFLAGS_PTUPDATE | KGSL_MMUFLAGS_TLBFLUSH)) { |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 525 | *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | *cmds++ = 0x7fff; /* invalidate all base pointers */ |
| 527 | sizedwords += 2; |
| 528 | } |
| 529 | |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 530 | adreno_ringbuffer_issuecmds(device, adreno_ctx, |
| 531 | KGSL_CMD_FLAGS_PMODE, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 532 | &link[0], sizedwords); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 533 | } else { |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 534 | kgsl_mmu_device_setstate(&device->mmu, flags); |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 535 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 538 | static void adreno_setstate(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 539 | unsigned int context_id, |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 540 | uint32_t flags) |
| 541 | { |
| 542 | /* call the mmu specific handler */ |
| 543 | if (KGSL_MMU_TYPE_GPU == kgsl_mmu_get_mmutype()) |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 544 | return adreno_gpummu_setstate(device, context_id, flags); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 545 | else if (KGSL_MMU_TYPE_IOMMU == kgsl_mmu_get_mmutype()) |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 546 | return adreno_iommu_setstate(device, context_id, flags); |
Shubhraprakash Das | c6e2101 | 2012-05-11 17:24:51 -0600 | [diff] [blame] | 547 | } |
| 548 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 549 | static unsigned int |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 550 | a3xx_getchipid(struct kgsl_device *device) |
| 551 | { |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 552 | struct kgsl_device_platform_data *pdata = |
| 553 | kgsl_device_get_drvdata(device); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 554 | |
Jordan Crouse | 54154c6 | 2012-03-27 16:33:26 -0600 | [diff] [blame] | 555 | /* |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 556 | * All current A3XX chipids are detected at the SOC level. Leave this |
| 557 | * function here to support any future GPUs that have working |
| 558 | * chip ID registers |
Jordan Crouse | 54154c6 | 2012-03-27 16:33:26 -0600 | [diff] [blame] | 559 | */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 560 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 561 | return pdata->chipid; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static unsigned int |
| 565 | a2xx_getchipid(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 566 | { |
| 567 | unsigned int chipid = 0; |
| 568 | unsigned int coreid, majorid, minorid, patchid, revid; |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 569 | struct kgsl_device_platform_data *pdata = |
| 570 | kgsl_device_get_drvdata(device); |
| 571 | |
| 572 | /* If the chip id is set at the platform level, then just use that */ |
| 573 | |
| 574 | if (pdata->chipid != 0) |
| 575 | return pdata->chipid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 576 | |
| 577 | adreno_regread(device, REG_RBBM_PERIPHID1, &coreid); |
| 578 | adreno_regread(device, REG_RBBM_PERIPHID2, &majorid); |
| 579 | adreno_regread(device, REG_RBBM_PATCH_RELEASE, &revid); |
| 580 | |
| 581 | /* |
| 582 | * adreno 22x gpus are indicated by coreid 2, |
| 583 | * but REG_RBBM_PERIPHID1 always contains 0 for this field |
| 584 | */ |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 585 | if (cpu_is_msm8x60()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 586 | chipid = 2 << 24; |
| 587 | else |
| 588 | chipid = (coreid & 0xF) << 24; |
| 589 | |
| 590 | chipid |= ((majorid >> 4) & 0xF) << 16; |
| 591 | |
| 592 | minorid = ((revid >> 0) & 0xFF); |
| 593 | |
| 594 | patchid = ((revid >> 16) & 0xFF); |
| 595 | |
| 596 | /* 8x50 returns 0 for patch release, but it should be 1 */ |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 597 | /* 8x25 returns 0 for minor id, but it should be 1 */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 598 | if (cpu_is_qsd8x50()) |
| 599 | patchid = 1; |
Ranjhith Kalisamy | 938e00f | 2012-02-17 14:39:47 +0530 | [diff] [blame] | 600 | else if (cpu_is_msm8625() && minorid == 0) |
| 601 | minorid = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 602 | |
| 603 | chipid |= (minorid << 8) | patchid; |
| 604 | |
| 605 | return chipid; |
| 606 | } |
| 607 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 608 | static unsigned int |
| 609 | adreno_getchipid(struct kgsl_device *device) |
| 610 | { |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 611 | struct kgsl_device_platform_data *pdata = |
| 612 | kgsl_device_get_drvdata(device); |
| 613 | |
| 614 | /* |
| 615 | * All A3XX chipsets will have pdata set, so assume !pdata->chipid is |
| 616 | * an A2XX processor |
| 617 | */ |
| 618 | |
| 619 | if (pdata->chipid == 0 || ADRENO_CHIPID_MAJOR(pdata->chipid) == 2) |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 620 | return a2xx_getchipid(device); |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 621 | else |
| 622 | return a3xx_getchipid(device); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 625 | static inline bool _rev_match(unsigned int id, unsigned int entry) |
| 626 | { |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 627 | return (entry == ANY_ID || entry == id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 628 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 629 | |
| 630 | static void |
| 631 | adreno_identify_gpu(struct adreno_device *adreno_dev) |
| 632 | { |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 633 | unsigned int i, core, major, minor, patchid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 634 | |
| 635 | adreno_dev->chip_id = adreno_getchipid(&adreno_dev->dev); |
| 636 | |
Jordan Crouse | 4815e9f | 2012-07-09 15:36:37 -0600 | [diff] [blame] | 637 | core = ADRENO_CHIPID_CORE(adreno_dev->chip_id); |
| 638 | major = ADRENO_CHIPID_MAJOR(adreno_dev->chip_id); |
| 639 | minor = ADRENO_CHIPID_MINOR(adreno_dev->chip_id); |
| 640 | patchid = ADRENO_CHIPID_PATCH(adreno_dev->chip_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 641 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 642 | for (i = 0; i < ARRAY_SIZE(adreno_gpulist); i++) { |
| 643 | if (core == adreno_gpulist[i].core && |
| 644 | _rev_match(major, adreno_gpulist[i].major) && |
Jeremy Gebben | e2e61d4 | 2011-09-27 15:45:41 -0600 | [diff] [blame] | 645 | _rev_match(minor, adreno_gpulist[i].minor) && |
| 646 | _rev_match(patchid, adreno_gpulist[i].patchid)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 647 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 650 | if (i == ARRAY_SIZE(adreno_gpulist)) { |
| 651 | adreno_dev->gpurev = ADRENO_REV_UNKNOWN; |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | adreno_dev->gpurev = adreno_gpulist[i].gpurev; |
| 656 | adreno_dev->gpudev = adreno_gpulist[i].gpudev; |
| 657 | adreno_dev->pfp_fwfile = adreno_gpulist[i].pfpfw; |
| 658 | adreno_dev->pm4_fwfile = adreno_gpulist[i].pm4fw; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame] | 659 | adreno_dev->istore_size = adreno_gpulist[i].istore_size; |
| 660 | adreno_dev->pix_shader_start = adreno_gpulist[i].pix_shader_start; |
Jordan Crouse | 55d98fd | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 661 | adreno_dev->instruction_size = adreno_gpulist[i].instruction_size; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 662 | adreno_dev->gmem_size = adreno_gpulist[i].gmem_size; |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 663 | adreno_dev->gpulist_index = i; |
| 664 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 667 | static struct platform_device_id adreno_id_table[] = { |
| 668 | { DEVICE_3D0_NAME, (kernel_ulong_t)&device_3d0.dev, }, |
| 669 | {}, |
| 670 | }; |
| 671 | |
| 672 | MODULE_DEVICE_TABLE(platform, adreno_id_table); |
| 673 | |
| 674 | static struct of_device_id adreno_match_table[] = { |
| 675 | { .compatible = "qcom,kgsl-3d0", }, |
| 676 | {} |
| 677 | }; |
| 678 | |
| 679 | static inline int adreno_of_read_property(struct device_node *node, |
| 680 | const char *prop, unsigned int *ptr) |
| 681 | { |
| 682 | int ret = of_property_read_u32(node, prop, ptr); |
| 683 | if (ret) |
| 684 | KGSL_CORE_ERR("Unable to read '%s'\n", prop); |
| 685 | return ret; |
| 686 | } |
| 687 | |
| 688 | static struct device_node *adreno_of_find_subnode(struct device_node *parent, |
| 689 | const char *name) |
| 690 | { |
| 691 | struct device_node *child; |
| 692 | |
| 693 | for_each_child_of_node(parent, child) { |
| 694 | if (of_device_is_compatible(child, name)) |
| 695 | return child; |
| 696 | } |
| 697 | |
| 698 | return NULL; |
| 699 | } |
| 700 | |
| 701 | static int adreno_of_get_pwrlevels(struct device_node *parent, |
| 702 | struct kgsl_device_platform_data *pdata) |
| 703 | { |
| 704 | struct device_node *node, *child; |
| 705 | int ret = -EINVAL; |
| 706 | |
| 707 | node = adreno_of_find_subnode(parent, "qcom,gpu-pwrlevels"); |
| 708 | |
| 709 | if (node == NULL) { |
| 710 | KGSL_CORE_ERR("Unable to find 'qcom,gpu-pwrlevels'\n"); |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | |
| 714 | pdata->num_levels = 0; |
| 715 | |
| 716 | for_each_child_of_node(node, child) { |
| 717 | unsigned int index; |
| 718 | struct kgsl_pwrlevel *level; |
| 719 | |
| 720 | if (adreno_of_read_property(child, "reg", &index)) |
| 721 | goto done; |
| 722 | |
| 723 | if (index >= KGSL_MAX_PWRLEVELS) { |
| 724 | KGSL_CORE_ERR("Pwrlevel index %d is out of range\n", |
| 725 | index); |
| 726 | continue; |
| 727 | } |
| 728 | |
| 729 | if (index >= pdata->num_levels) |
| 730 | pdata->num_levels = index + 1; |
| 731 | |
| 732 | level = &pdata->pwrlevel[index]; |
| 733 | |
| 734 | if (adreno_of_read_property(child, "qcom,gpu-freq", |
| 735 | &level->gpu_freq)) |
| 736 | goto done; |
| 737 | |
| 738 | if (adreno_of_read_property(child, "qcom,bus-freq", |
| 739 | &level->bus_freq)) |
| 740 | goto done; |
| 741 | |
| 742 | if (adreno_of_read_property(child, "qcom,io-fraction", |
| 743 | &level->io_fraction)) |
| 744 | level->io_fraction = 0; |
| 745 | } |
| 746 | |
| 747 | if (adreno_of_read_property(parent, "qcom,initial-pwrlevel", |
| 748 | &pdata->init_level)) |
| 749 | pdata->init_level = 1; |
| 750 | |
| 751 | if (pdata->init_level < 0 || pdata->init_level > pdata->num_levels) { |
| 752 | KGSL_CORE_ERR("Initial power level out of range\n"); |
| 753 | pdata->init_level = 1; |
| 754 | } |
| 755 | |
| 756 | ret = 0; |
| 757 | done: |
| 758 | return ret; |
| 759 | |
| 760 | } |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 761 | |
| 762 | static struct msm_dcvs_core_info *adreno_of_get_dcvs(struct device_node *parent) |
| 763 | { |
| 764 | struct device_node *node, *child; |
| 765 | struct msm_dcvs_core_info *info = NULL; |
| 766 | int count = 0; |
| 767 | int ret = -EINVAL; |
| 768 | |
| 769 | node = adreno_of_find_subnode(parent, "qcom,dcvs-core-info"); |
| 770 | if (node == NULL) |
| 771 | return ERR_PTR(-EINVAL); |
| 772 | |
| 773 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 774 | |
| 775 | if (info == NULL) { |
| 776 | KGSL_CORE_ERR("kzalloc(%d) failed\n", sizeof(*info)); |
| 777 | ret = -ENOMEM; |
| 778 | goto err; |
| 779 | } |
| 780 | |
| 781 | for_each_child_of_node(node, child) |
| 782 | count++; |
| 783 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 784 | info->power_param.num_freq = count; |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 785 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 786 | info->freq_tbl = kzalloc(info->power_param.num_freq * |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 787 | sizeof(struct msm_dcvs_freq_entry), |
| 788 | GFP_KERNEL); |
| 789 | |
| 790 | if (info->freq_tbl == NULL) { |
| 791 | KGSL_CORE_ERR("kzalloc(%d) failed\n", |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 792 | info->power_param.num_freq * |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 793 | sizeof(struct msm_dcvs_freq_entry)); |
| 794 | ret = -ENOMEM; |
| 795 | goto err; |
| 796 | } |
| 797 | |
| 798 | for_each_child_of_node(node, child) { |
| 799 | unsigned int index; |
| 800 | |
| 801 | if (adreno_of_read_property(child, "reg", &index)) |
| 802 | goto err; |
| 803 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 804 | if (index >= info->power_param.num_freq) { |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 805 | KGSL_CORE_ERR("DCVS freq entry %d is out of range\n", |
| 806 | index); |
| 807 | continue; |
| 808 | } |
| 809 | |
| 810 | if (adreno_of_read_property(child, "qcom,freq", |
| 811 | &info->freq_tbl[index].freq)) |
| 812 | goto err; |
| 813 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 814 | if (adreno_of_read_property(child, "qcom,voltage", |
| 815 | &info->freq_tbl[index].voltage)) |
| 816 | info->freq_tbl[index].voltage = 0; |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 817 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 818 | if (adreno_of_read_property(child, "qcom,is_trans_level", |
| 819 | &info->freq_tbl[index].is_trans_level)) |
| 820 | info->freq_tbl[index].is_trans_level = 0; |
| 821 | |
| 822 | if (adreno_of_read_property(child, "qcom,active-energy-offset", |
| 823 | &info->freq_tbl[index].active_energy_offset)) |
| 824 | info->freq_tbl[index].active_energy_offset = 0; |
| 825 | |
| 826 | if (adreno_of_read_property(child, "qcom,leakage-energy-offset", |
| 827 | &info->freq_tbl[index].leakage_energy_offset)) |
| 828 | info->freq_tbl[index].leakage_energy_offset = 0; |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 829 | } |
| 830 | |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 831 | if (adreno_of_read_property(node, "qcom,num-cores", &info->num_cores)) |
| 832 | goto err; |
| 833 | |
| 834 | info->sensors = kzalloc(info->num_cores * |
| 835 | sizeof(int), |
| 836 | GFP_KERNEL); |
| 837 | |
| 838 | for (count = 0; count < info->num_cores; count++) { |
| 839 | if (adreno_of_read_property(node, "qcom,sensors", |
| 840 | &(info->sensors[count]))) |
| 841 | goto err; |
| 842 | } |
| 843 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 844 | if (adreno_of_read_property(node, "qcom,core-core-type", |
| 845 | &info->core_param.core_type)) |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 846 | goto err; |
| 847 | |
| 848 | if (adreno_of_read_property(node, "qcom,algo-disable-pc-threshold", |
| 849 | &info->algo_param.disable_pc_threshold)) |
| 850 | goto err; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 851 | if (adreno_of_read_property(node, "qcom,algo-em-win-size-min-us", |
| 852 | &info->algo_param.em_win_size_min_us)) |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 853 | goto err; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 854 | if (adreno_of_read_property(node, "qcom,algo-em-win-size-max-us", |
| 855 | &info->algo_param.em_win_size_max_us)) |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 856 | goto err; |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 857 | if (adreno_of_read_property(node, "qcom,algo-em-max-util-pct", |
| 858 | &info->algo_param.em_max_util_pct)) |
| 859 | goto err; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 860 | if (adreno_of_read_property(node, "qcom,algo-group-id", |
| 861 | &info->algo_param.group_id)) |
| 862 | goto err; |
| 863 | if (adreno_of_read_property(node, "qcom,algo-max-freq-chg-time-us", |
| 864 | &info->algo_param.max_freq_chg_time_us)) |
| 865 | goto err; |
| 866 | if (adreno_of_read_property(node, "qcom,algo-slack-mode-dynamic", |
| 867 | &info->algo_param.slack_mode_dynamic)) |
| 868 | goto err; |
| 869 | if (adreno_of_read_property(node, "qcom,algo-slack-weight-thresh-pct", |
| 870 | &info->algo_param.slack_weight_thresh_pct)) |
| 871 | goto err; |
| 872 | if (adreno_of_read_property(node, "qcom,algo-slack-time-min-us", |
| 873 | &info->algo_param.slack_time_min_us)) |
| 874 | goto err; |
| 875 | if (adreno_of_read_property(node, "qcom,algo-slack-time-max-us", |
| 876 | &info->algo_param.slack_time_max_us)) |
| 877 | goto err; |
| 878 | if (adreno_of_read_property(node, "qcom,algo-ss-win-size-min-us", |
| 879 | &info->algo_param.ss_win_size_min_us)) |
| 880 | goto err; |
| 881 | if (adreno_of_read_property(node, "qcom,algo-ss-win-size-max-us", |
| 882 | &info->algo_param.ss_win_size_max_us)) |
| 883 | goto err; |
| 884 | if (adreno_of_read_property(node, "qcom,algo-ss-util-pct", |
| 885 | &info->algo_param.ss_util_pct)) |
| 886 | goto err; |
Steve Muckle | 8d0782e | 2012-12-06 14:31:00 -0800 | [diff] [blame] | 887 | if (adreno_of_read_property(node, "qcom,algo-ss-no-corr-below-freq", |
| 888 | &info->algo_param.ss_no_corr_below_freq)) |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 889 | goto err; |
| 890 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 891 | if (adreno_of_read_property(node, "qcom,energy-active-coeff-a", |
| 892 | &info->energy_coeffs.active_coeff_a)) |
| 893 | goto err; |
| 894 | if (adreno_of_read_property(node, "qcom,energy-active-coeff-b", |
| 895 | &info->energy_coeffs.active_coeff_b)) |
| 896 | goto err; |
| 897 | if (adreno_of_read_property(node, "qcom,energy-active-coeff-c", |
| 898 | &info->energy_coeffs.active_coeff_c)) |
| 899 | goto err; |
| 900 | if (adreno_of_read_property(node, "qcom,energy-leakage-coeff-a", |
| 901 | &info->energy_coeffs.leakage_coeff_a)) |
| 902 | goto err; |
| 903 | if (adreno_of_read_property(node, "qcom,energy-leakage-coeff-b", |
| 904 | &info->energy_coeffs.leakage_coeff_b)) |
| 905 | goto err; |
| 906 | if (adreno_of_read_property(node, "qcom,energy-leakage-coeff-c", |
| 907 | &info->energy_coeffs.leakage_coeff_c)) |
| 908 | goto err; |
| 909 | if (adreno_of_read_property(node, "qcom,energy-leakage-coeff-d", |
| 910 | &info->energy_coeffs.leakage_coeff_d)) |
| 911 | goto err; |
| 912 | |
| 913 | if (adreno_of_read_property(node, "qcom,power-current-temp", |
| 914 | &info->power_param.current_temp)) |
| 915 | goto err; |
| 916 | |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 917 | return info; |
| 918 | |
| 919 | err: |
| 920 | if (info) |
| 921 | kfree(info->freq_tbl); |
| 922 | |
| 923 | kfree(info); |
| 924 | |
| 925 | return ERR_PTR(ret); |
| 926 | } |
| 927 | |
| 928 | static int adreno_of_get_iommu(struct device_node *parent, |
| 929 | struct kgsl_device_platform_data *pdata) |
| 930 | { |
| 931 | struct device_node *node, *child; |
| 932 | struct kgsl_device_iommu_data *data = NULL; |
| 933 | struct kgsl_iommu_ctx *ctxs = NULL; |
| 934 | u32 reg_val[2]; |
| 935 | int ctx_index = 0; |
| 936 | |
| 937 | node = of_parse_phandle(parent, "iommu", 0); |
| 938 | if (node == NULL) |
| 939 | return -EINVAL; |
| 940 | |
| 941 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 942 | if (data == NULL) { |
| 943 | KGSL_CORE_ERR("kzalloc(%d) failed\n", sizeof(*data)); |
| 944 | goto err; |
| 945 | } |
| 946 | |
| 947 | if (of_property_read_u32_array(node, "reg", reg_val, 2)) |
| 948 | goto err; |
| 949 | |
| 950 | data->physstart = reg_val[0]; |
| 951 | data->physend = data->physstart + reg_val[1] - 1; |
| 952 | |
| 953 | data->iommu_ctx_count = 0; |
| 954 | |
| 955 | for_each_child_of_node(node, child) |
| 956 | data->iommu_ctx_count++; |
| 957 | |
| 958 | ctxs = kzalloc(data->iommu_ctx_count * sizeof(struct kgsl_iommu_ctx), |
| 959 | GFP_KERNEL); |
| 960 | |
| 961 | if (ctxs == NULL) { |
| 962 | KGSL_CORE_ERR("kzalloc(%d) failed\n", |
| 963 | data->iommu_ctx_count * sizeof(struct kgsl_iommu_ctx)); |
| 964 | goto err; |
| 965 | } |
| 966 | |
| 967 | for_each_child_of_node(node, child) { |
| 968 | int ret = of_property_read_string(child, "label", |
| 969 | &ctxs[ctx_index].iommu_ctx_name); |
| 970 | |
| 971 | if (ret) { |
| 972 | KGSL_CORE_ERR("Unable to read KGSL IOMMU 'label'\n"); |
| 973 | goto err; |
| 974 | } |
| 975 | |
| 976 | if (adreno_of_read_property(child, "qcom,iommu-ctx-sids", |
| 977 | &ctxs[ctx_index].ctx_id)) |
| 978 | goto err; |
| 979 | |
| 980 | ctx_index++; |
| 981 | } |
| 982 | |
| 983 | data->iommu_ctxs = ctxs; |
| 984 | |
| 985 | pdata->iommu_data = data; |
| 986 | pdata->iommu_count = 1; |
| 987 | |
| 988 | return 0; |
| 989 | |
| 990 | err: |
| 991 | kfree(ctxs); |
| 992 | kfree(data); |
| 993 | |
| 994 | return -EINVAL; |
| 995 | } |
| 996 | |
| 997 | static int adreno_of_get_pdata(struct platform_device *pdev) |
| 998 | { |
| 999 | struct kgsl_device_platform_data *pdata = NULL; |
| 1000 | struct kgsl_device *device; |
| 1001 | int ret = -EINVAL; |
| 1002 | |
| 1003 | pdev->id_entry = adreno_id_table; |
| 1004 | |
| 1005 | pdata = pdev->dev.platform_data; |
| 1006 | if (pdata) |
| 1007 | return 0; |
| 1008 | |
| 1009 | if (of_property_read_string(pdev->dev.of_node, "label", &pdev->name)) { |
| 1010 | KGSL_CORE_ERR("Unable to read 'label'\n"); |
| 1011 | goto err; |
| 1012 | } |
| 1013 | |
| 1014 | if (adreno_of_read_property(pdev->dev.of_node, "qcom,id", &pdev->id)) |
| 1015 | goto err; |
| 1016 | |
| 1017 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 1018 | if (pdata == NULL) { |
| 1019 | KGSL_CORE_ERR("kzalloc(%d) failed\n", sizeof(*pdata)); |
| 1020 | ret = -ENOMEM; |
| 1021 | goto err; |
| 1022 | } |
| 1023 | |
| 1024 | if (adreno_of_read_property(pdev->dev.of_node, "qcom,chipid", |
| 1025 | &pdata->chipid)) |
| 1026 | goto err; |
| 1027 | |
| 1028 | /* pwrlevel Data */ |
| 1029 | ret = adreno_of_get_pwrlevels(pdev->dev.of_node, pdata); |
| 1030 | if (ret) |
| 1031 | goto err; |
| 1032 | |
| 1033 | /* Default value is 83, if not found in DT */ |
| 1034 | if (adreno_of_read_property(pdev->dev.of_node, "qcom,idle-timeout", |
| 1035 | &pdata->idle_timeout)) |
| 1036 | pdata->idle_timeout = 83; |
| 1037 | |
| 1038 | if (adreno_of_read_property(pdev->dev.of_node, "qcom,nap-allowed", |
| 1039 | &pdata->nap_allowed)) |
| 1040 | pdata->nap_allowed = 1; |
| 1041 | |
| 1042 | if (adreno_of_read_property(pdev->dev.of_node, "qcom,clk-map", |
| 1043 | &pdata->clk_map)) |
| 1044 | goto err; |
| 1045 | |
| 1046 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 1047 | |
| 1048 | if (device->id != KGSL_DEVICE_3D0) |
| 1049 | goto err; |
| 1050 | |
| 1051 | /* Bus Scale Data */ |
| 1052 | |
Rajeev Kulkarni | c916200 | 2012-11-22 00:42:58 -0800 | [diff] [blame] | 1053 | pdata->bus_scale_table = msm_bus_cl_get_pdata(pdev); |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 1054 | if (IS_ERR_OR_NULL(pdata->bus_scale_table)) { |
| 1055 | ret = PTR_ERR(pdata->bus_scale_table); |
| 1056 | goto err; |
| 1057 | } |
| 1058 | |
| 1059 | pdata->core_info = adreno_of_get_dcvs(pdev->dev.of_node); |
| 1060 | if (IS_ERR_OR_NULL(pdata->core_info)) { |
| 1061 | ret = PTR_ERR(pdata->core_info); |
| 1062 | goto err; |
| 1063 | } |
| 1064 | |
| 1065 | ret = adreno_of_get_iommu(pdev->dev.of_node, pdata); |
| 1066 | if (ret) |
| 1067 | goto err; |
| 1068 | |
| 1069 | pdev->dev.platform_data = pdata; |
| 1070 | return 0; |
| 1071 | |
| 1072 | err: |
| 1073 | if (pdata) { |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 1074 | if (pdata->core_info) |
| 1075 | kfree(pdata->core_info->freq_tbl); |
| 1076 | kfree(pdata->core_info); |
| 1077 | |
| 1078 | if (pdata->iommu_data) |
| 1079 | kfree(pdata->iommu_data->iommu_ctxs); |
| 1080 | |
| 1081 | kfree(pdata->iommu_data); |
| 1082 | } |
| 1083 | |
| 1084 | kfree(pdata); |
| 1085 | |
| 1086 | return ret; |
| 1087 | } |
| 1088 | |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1089 | #ifdef CONFIG_MSM_OCMEM |
| 1090 | static int |
| 1091 | adreno_ocmem_gmem_malloc(struct adreno_device *adreno_dev) |
| 1092 | { |
Jordan Crouse | c097820 | 2012-08-29 14:35:51 -0600 | [diff] [blame] | 1093 | if (!adreno_is_a330(adreno_dev)) |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1094 | return 0; |
| 1095 | |
| 1096 | /* OCMEM is only needed once, do not support consective allocation */ |
| 1097 | if (adreno_dev->ocmem_hdl != NULL) |
| 1098 | return 0; |
| 1099 | |
| 1100 | adreno_dev->ocmem_hdl = |
| 1101 | ocmem_allocate(OCMEM_GRAPHICS, adreno_dev->gmem_size); |
| 1102 | if (adreno_dev->ocmem_hdl == NULL) |
| 1103 | return -ENOMEM; |
| 1104 | |
| 1105 | adreno_dev->gmem_size = adreno_dev->ocmem_hdl->len; |
liu zhong | 5af32d9 | 2012-08-29 14:36:36 -0600 | [diff] [blame] | 1106 | adreno_dev->ocmem_base = adreno_dev->ocmem_hdl->addr; |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1107 | |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | static void |
| 1112 | adreno_ocmem_gmem_free(struct adreno_device *adreno_dev) |
| 1113 | { |
Jordan Crouse | c097820 | 2012-08-29 14:35:51 -0600 | [diff] [blame] | 1114 | if (!adreno_is_a330(adreno_dev)) |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1115 | return; |
| 1116 | |
| 1117 | if (adreno_dev->ocmem_hdl == NULL) |
| 1118 | return; |
| 1119 | |
| 1120 | ocmem_free(OCMEM_GRAPHICS, adreno_dev->ocmem_hdl); |
| 1121 | adreno_dev->ocmem_hdl = NULL; |
| 1122 | } |
| 1123 | #else |
| 1124 | static int |
| 1125 | adreno_ocmem_gmem_malloc(struct adreno_device *adreno_dev) |
| 1126 | { |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
| 1130 | static void |
| 1131 | adreno_ocmem_gmem_free(struct adreno_device *adreno_dev) |
| 1132 | { |
| 1133 | } |
| 1134 | #endif |
| 1135 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1136 | static int __devinit |
| 1137 | adreno_probe(struct platform_device *pdev) |
| 1138 | { |
| 1139 | struct kgsl_device *device; |
| 1140 | struct adreno_device *adreno_dev; |
| 1141 | int status = -EINVAL; |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 1142 | bool is_dt; |
| 1143 | |
| 1144 | is_dt = of_match_device(adreno_match_table, &pdev->dev); |
| 1145 | |
| 1146 | if (is_dt && pdev->dev.of_node) { |
| 1147 | status = adreno_of_get_pdata(pdev); |
| 1148 | if (status) |
| 1149 | goto error_return; |
| 1150 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1151 | |
| 1152 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 1153 | adreno_dev = ADRENO_DEVICE(device); |
| 1154 | device->parentdev = &pdev->dev; |
| 1155 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1156 | status = adreno_ringbuffer_init(device); |
| 1157 | if (status != 0) |
| 1158 | goto error; |
| 1159 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 1160 | status = kgsl_device_platform_probe(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1161 | if (status) |
| 1162 | goto error_close_rb; |
| 1163 | |
| 1164 | adreno_debugfs_init(device); |
| 1165 | |
| 1166 | kgsl_pwrscale_init(device); |
| 1167 | kgsl_pwrscale_attach_policy(device, ADRENO_DEFAULT_PWRSCALE_POLICY); |
| 1168 | |
| 1169 | device->flags &= ~KGSL_FLAGS_SOFT_RESET; |
| 1170 | return 0; |
| 1171 | |
| 1172 | error_close_rb: |
| 1173 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 1174 | error: |
| 1175 | device->parentdev = NULL; |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 1176 | error_return: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1177 | return status; |
| 1178 | } |
| 1179 | |
| 1180 | static int __devexit adreno_remove(struct platform_device *pdev) |
| 1181 | { |
| 1182 | struct kgsl_device *device; |
| 1183 | struct adreno_device *adreno_dev; |
| 1184 | |
| 1185 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 1186 | adreno_dev = ADRENO_DEVICE(device); |
| 1187 | |
| 1188 | kgsl_pwrscale_detach_policy(device); |
| 1189 | kgsl_pwrscale_close(device); |
| 1190 | |
| 1191 | adreno_ringbuffer_close(&adreno_dev->ringbuffer); |
| 1192 | kgsl_device_platform_remove(device); |
| 1193 | |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | static int adreno_start(struct kgsl_device *device, unsigned int init_ram) |
| 1198 | { |
| 1199 | int status = -EINVAL; |
| 1200 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1201 | |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 1202 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state) |
| 1203 | kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1204 | |
| 1205 | /* Power up the device */ |
| 1206 | kgsl_pwrctrl_enable(device); |
| 1207 | |
| 1208 | /* Identify the specific GPU */ |
| 1209 | adreno_identify_gpu(adreno_dev); |
| 1210 | |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 1211 | if (adreno_ringbuffer_read_pm4_ucode(device)) { |
| 1212 | KGSL_DRV_ERR(device, "Reading pm4 microcode failed %s\n", |
| 1213 | adreno_dev->pm4_fwfile); |
| 1214 | BUG_ON(1); |
| 1215 | } |
| 1216 | |
| 1217 | if (adreno_ringbuffer_read_pfp_ucode(device)) { |
| 1218 | KGSL_DRV_ERR(device, "Reading pfp microcode failed %s\n", |
| 1219 | adreno_dev->pfp_fwfile); |
| 1220 | BUG_ON(1); |
| 1221 | } |
| 1222 | |
Jordan Crouse | 505df9c | 2011-07-28 08:37:59 -0600 | [diff] [blame] | 1223 | if (adreno_dev->gpurev == ADRENO_REV_UNKNOWN) { |
| 1224 | KGSL_DRV_ERR(device, "Unknown chip ID %x\n", |
| 1225 | adreno_dev->chip_id); |
| 1226 | goto error_clk_off; |
| 1227 | } |
| 1228 | |
Tarun Karra | 9c07082 | 2012-11-27 16:43:51 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* |
| 1231 | * Check if firmware supports the sync lock PM4 packets needed |
| 1232 | * for IOMMUv1 |
| 1233 | */ |
| 1234 | |
| 1235 | if ((adreno_dev->pm4_fw_version >= |
| 1236 | adreno_gpulist[adreno_dev->gpulist_index].sync_lock_pm4_ver) && |
| 1237 | (adreno_dev->pfp_fw_version >= |
| 1238 | adreno_gpulist[adreno_dev->gpulist_index].sync_lock_pfp_ver)) |
| 1239 | device->mmu.flags |= KGSL_MMU_FLAGS_IOMMU_SYNC; |
| 1240 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1241 | /* Set up the MMU */ |
| 1242 | if (adreno_is_a2xx(adreno_dev)) { |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 1243 | /* |
| 1244 | * the MH_CLNT_INTF_CTRL_CONFIG registers aren't present |
| 1245 | * on older gpus |
| 1246 | */ |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1247 | if (adreno_is_a20x(adreno_dev)) { |
| 1248 | device->mh.mh_intf_cfg1 = 0; |
| 1249 | device->mh.mh_intf_cfg2 = 0; |
| 1250 | } |
| 1251 | |
| 1252 | kgsl_mh_start(device); |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 1253 | } |
| 1254 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 1255 | /* Assign correct RBBM status register to hang detect regs |
| 1256 | */ |
| 1257 | hang_detect_regs[0] = adreno_dev->gpudev->reg_rbbm_status; |
| 1258 | |
Jordan Crouse | b5c8048 | 2012-10-03 09:38:41 -0600 | [diff] [blame] | 1259 | /* Add A3XX specific registers for hang detection */ |
| 1260 | if (adreno_is_a3xx(adreno_dev)) { |
| 1261 | hang_detect_regs[6] = A3XX_RBBM_PERFCTR_SP_7_LO; |
| 1262 | hang_detect_regs[7] = A3XX_RBBM_PERFCTR_SP_7_HI; |
Tarun Karra | 6e750d7 | 2013-01-04 10:28:40 -0800 | [diff] [blame] | 1263 | hang_detect_regs[8] = A3XX_RBBM_PERFCTR_SP_6_LO; |
| 1264 | hang_detect_regs[9] = A3XX_RBBM_PERFCTR_SP_6_HI; |
| 1265 | hang_detect_regs[10] = A3XX_RBBM_PERFCTR_SP_5_LO; |
| 1266 | hang_detect_regs[11] = A3XX_RBBM_PERFCTR_SP_5_HI; |
Jordan Crouse | b5c8048 | 2012-10-03 09:38:41 -0600 | [diff] [blame] | 1267 | } |
| 1268 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1269 | status = kgsl_mmu_start(device); |
| 1270 | if (status) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1271 | goto error_clk_off; |
| 1272 | |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1273 | status = adreno_ocmem_gmem_malloc(adreno_dev); |
| 1274 | if (status) { |
| 1275 | KGSL_DRV_ERR(device, "OCMEM malloc failed\n"); |
| 1276 | goto error_mmu_off; |
| 1277 | } |
| 1278 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1279 | /* Start the GPU */ |
| 1280 | adreno_dev->gpudev->start(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1281 | |
| 1282 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 1283 | device->ftbl->irqctrl(device, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1284 | |
| 1285 | status = adreno_ringbuffer_start(&adreno_dev->ringbuffer, init_ram); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1286 | if (status == 0) { |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 1287 | /* While recovery is on we do not want timer to |
| 1288 | * fire and attempt to change any device state */ |
| 1289 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state) |
| 1290 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1293 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1294 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1295 | |
| 1296 | error_mmu_off: |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 1297 | kgsl_mmu_stop(&device->mmu); |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1298 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1299 | error_clk_off: |
| 1300 | kgsl_pwrctrl_disable(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1301 | |
| 1302 | return status; |
| 1303 | } |
| 1304 | |
| 1305 | static int adreno_stop(struct kgsl_device *device) |
| 1306 | { |
| 1307 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1308 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1309 | adreno_dev->drawctxt_active = NULL; |
| 1310 | |
| 1311 | adreno_ringbuffer_stop(&adreno_dev->ringbuffer); |
| 1312 | |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 1313 | kgsl_mmu_stop(&device->mmu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1314 | |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 1315 | device->ftbl->irqctrl(device, 0); |
Ranjhith Kalisamy | ce75b0c | 2012-02-01 19:31:23 +0530 | [diff] [blame] | 1316 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Suman Tatiraju | 4a32c65 | 2012-02-17 11:59:05 -0800 | [diff] [blame] | 1317 | del_timer_sync(&device->idle_timer); |
Lucille Sylvester | 844b1c8 | 2011-08-29 15:26:06 -0600 | [diff] [blame] | 1318 | |
liu zhong | 7dfa2a3 | 2012-04-27 19:11:01 -0700 | [diff] [blame] | 1319 | adreno_ocmem_gmem_free(adreno_dev); |
| 1320 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1321 | /* Power down the device */ |
| 1322 | kgsl_pwrctrl_disable(device); |
| 1323 | |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
Shubhraprakash Das | 29ed38e | 2012-06-06 01:43:55 -0600 | [diff] [blame] | 1327 | static void adreno_mark_context_status(struct kgsl_device *device, |
| 1328 | int recovery_status) |
| 1329 | { |
| 1330 | struct kgsl_context *context; |
| 1331 | int next = 0; |
| 1332 | /* |
| 1333 | * Set the reset status of all contexts to |
| 1334 | * INNOCENT_CONTEXT_RESET_EXT except for the bad context |
| 1335 | * since thats the guilty party, if recovery failed then |
| 1336 | * mark all as guilty |
| 1337 | */ |
| 1338 | while ((context = idr_get_next(&device->context_idr, &next))) { |
| 1339 | struct adreno_context *adreno_context = context->devctxt; |
| 1340 | if (recovery_status) { |
| 1341 | context->reset_status = |
| 1342 | KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; |
| 1343 | adreno_context->flags |= CTXT_FLAGS_GPU_HANG; |
| 1344 | } else if (KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT != |
| 1345 | context->reset_status) { |
Carter Cooper | 8179f5a | 2012-12-17 11:32:27 -0700 | [diff] [blame] | 1346 | if (adreno_context->flags & (CTXT_FLAGS_GPU_HANG | |
Shubhraprakash Das | 29ed38e | 2012-06-06 01:43:55 -0600 | [diff] [blame] | 1347 | CTXT_FLAGS_GPU_HANG_RECOVERED)) |
| 1348 | context->reset_status = |
| 1349 | KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; |
| 1350 | else |
| 1351 | context->reset_status = |
| 1352 | KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT; |
| 1353 | } |
| 1354 | next = next + 1; |
| 1355 | } |
| 1356 | } |
| 1357 | |
Shubhraprakash Das | 5f085f4 | 2012-06-06 02:01:24 -0600 | [diff] [blame] | 1358 | static void adreno_set_max_ts_for_bad_ctxs(struct kgsl_device *device) |
| 1359 | { |
| 1360 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1361 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1362 | struct kgsl_context *context; |
| 1363 | struct adreno_context *temp_adreno_context; |
| 1364 | int next = 0; |
| 1365 | |
| 1366 | while ((context = idr_get_next(&device->context_idr, &next))) { |
| 1367 | temp_adreno_context = context->devctxt; |
| 1368 | if (temp_adreno_context->flags & CTXT_FLAGS_GPU_HANG) { |
| 1369 | kgsl_sharedmem_writel(&device->memstore, |
| 1370 | KGSL_MEMSTORE_OFFSET(context->id, |
| 1371 | soptimestamp), |
| 1372 | rb->timestamp[context->id]); |
| 1373 | kgsl_sharedmem_writel(&device->memstore, |
| 1374 | KGSL_MEMSTORE_OFFSET(context->id, |
| 1375 | eoptimestamp), |
| 1376 | rb->timestamp[context->id]); |
| 1377 | } |
| 1378 | next = next + 1; |
| 1379 | } |
| 1380 | } |
| 1381 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1382 | static void adreno_destroy_recovery_data(struct adreno_recovery_data *rec_data) |
| 1383 | { |
| 1384 | vfree(rec_data->rb_buffer); |
| 1385 | vfree(rec_data->bad_rb_buffer); |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1386 | vfree(rec_data->good_rb_buffer); |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1387 | } |
| 1388 | |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1389 | static int _find_start_of_cmd_seq(struct adreno_ringbuffer *rb, |
| 1390 | unsigned int *ptr, |
| 1391 | bool inc) |
| 1392 | { |
| 1393 | int status = -EINVAL; |
| 1394 | unsigned int val1; |
| 1395 | unsigned int size = rb->buffer_desc.size; |
| 1396 | unsigned int start_ptr = *ptr; |
| 1397 | |
| 1398 | while ((start_ptr / sizeof(unsigned int)) != rb->wptr) { |
| 1399 | if (inc) |
| 1400 | start_ptr = adreno_ringbuffer_inc_wrapped(start_ptr, |
| 1401 | size); |
| 1402 | else |
| 1403 | start_ptr = adreno_ringbuffer_dec_wrapped(start_ptr, |
| 1404 | size); |
| 1405 | kgsl_sharedmem_readl(&rb->buffer_desc, &val1, start_ptr); |
| 1406 | if (KGSL_CMD_IDENTIFIER == val1) { |
| 1407 | if ((start_ptr / sizeof(unsigned int)) != rb->wptr) |
| 1408 | start_ptr = adreno_ringbuffer_dec_wrapped( |
| 1409 | start_ptr, size); |
| 1410 | *ptr = start_ptr; |
| 1411 | status = 0; |
| 1412 | break; |
| 1413 | } |
| 1414 | } |
| 1415 | return status; |
| 1416 | } |
| 1417 | |
| 1418 | static int _find_cmd_seq_after_eop_ts(struct adreno_ringbuffer *rb, |
| 1419 | unsigned int *rb_rptr, |
| 1420 | unsigned int global_eop, |
| 1421 | bool inc) |
| 1422 | { |
| 1423 | int status = -EINVAL; |
| 1424 | unsigned int temp_rb_rptr = *rb_rptr; |
| 1425 | unsigned int size = rb->buffer_desc.size; |
| 1426 | unsigned int val[3]; |
| 1427 | int i = 0; |
| 1428 | bool check = false; |
| 1429 | |
| 1430 | if (inc && temp_rb_rptr / sizeof(unsigned int) != rb->wptr) |
| 1431 | return status; |
| 1432 | |
| 1433 | do { |
| 1434 | /* |
| 1435 | * when decrementing we need to decrement first and |
| 1436 | * then read make sure we cover all the data |
| 1437 | */ |
| 1438 | if (!inc) |
| 1439 | temp_rb_rptr = adreno_ringbuffer_dec_wrapped( |
| 1440 | temp_rb_rptr, size); |
| 1441 | kgsl_sharedmem_readl(&rb->buffer_desc, &val[i], |
| 1442 | temp_rb_rptr); |
| 1443 | |
| 1444 | if (check && ((inc && val[i] == global_eop) || |
| 1445 | (!inc && (val[i] == |
| 1446 | cp_type3_packet(CP_MEM_WRITE, 2) || |
| 1447 | val[i] == CACHE_FLUSH_TS)))) { |
| 1448 | /* decrement i, i.e i = (i - 1 + 3) % 3 if |
| 1449 | * we are going forward, else increment i */ |
| 1450 | i = (i + 2) % 3; |
| 1451 | if (val[i] == rb->device->memstore.gpuaddr + |
| 1452 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 1453 | eoptimestamp)) { |
| 1454 | int j = ((i + 2) % 3); |
| 1455 | if ((inc && (val[j] == CACHE_FLUSH_TS || |
| 1456 | val[j] == cp_type3_packet( |
| 1457 | CP_MEM_WRITE, 2))) || |
| 1458 | (!inc && val[j] == global_eop)) { |
| 1459 | /* Found the global eop */ |
| 1460 | status = 0; |
| 1461 | break; |
| 1462 | } |
| 1463 | } |
| 1464 | /* if no match found then increment i again |
| 1465 | * since we decremented before matching */ |
| 1466 | i = (i + 1) % 3; |
| 1467 | } |
| 1468 | if (inc) |
| 1469 | temp_rb_rptr = adreno_ringbuffer_inc_wrapped( |
| 1470 | temp_rb_rptr, size); |
| 1471 | |
| 1472 | i = (i + 1) % 3; |
| 1473 | if (2 == i) |
| 1474 | check = true; |
| 1475 | } while (temp_rb_rptr / sizeof(unsigned int) != rb->wptr); |
| 1476 | /* temp_rb_rptr points to the command stream after global eop, |
| 1477 | * move backward till the start of command sequence */ |
| 1478 | if (!status) { |
| 1479 | status = _find_start_of_cmd_seq(rb, &temp_rb_rptr, false); |
| 1480 | if (!status) { |
| 1481 | *rb_rptr = temp_rb_rptr; |
| 1482 | KGSL_DRV_ERR(rb->device, |
| 1483 | "Offset of cmd sequence after eop timestamp: 0x%x\n", |
| 1484 | temp_rb_rptr / sizeof(unsigned int)); |
| 1485 | } |
| 1486 | } |
| 1487 | if (status) |
| 1488 | KGSL_DRV_ERR(rb->device, |
| 1489 | "Failed to find the command sequence after eop timestamp\n"); |
| 1490 | return status; |
| 1491 | } |
| 1492 | |
| 1493 | static int _find_hanging_ib_sequence(struct adreno_ringbuffer *rb, |
| 1494 | unsigned int *rb_rptr, |
| 1495 | unsigned int ib1) |
| 1496 | { |
| 1497 | int status = -EINVAL; |
| 1498 | unsigned int temp_rb_rptr = *rb_rptr; |
| 1499 | unsigned int size = rb->buffer_desc.size; |
| 1500 | unsigned int val[2]; |
| 1501 | int i = 0; |
| 1502 | bool check = false; |
| 1503 | bool ctx_switch = false; |
| 1504 | |
| 1505 | while (temp_rb_rptr / sizeof(unsigned int) != rb->wptr) { |
| 1506 | kgsl_sharedmem_readl(&rb->buffer_desc, &val[i], temp_rb_rptr); |
| 1507 | |
| 1508 | if (check && val[i] == ib1) { |
| 1509 | /* decrement i, i.e i = (i - 1 + 2) % 2 */ |
| 1510 | i = (i + 1) % 2; |
| 1511 | if (adreno_cmd_is_ib(val[i])) { |
| 1512 | /* go till start of command sequence */ |
| 1513 | status = _find_start_of_cmd_seq(rb, |
| 1514 | &temp_rb_rptr, false); |
| 1515 | KGSL_DRV_INFO(rb->device, |
| 1516 | "Found the hanging IB at offset 0x%x\n", |
| 1517 | temp_rb_rptr / sizeof(unsigned int)); |
| 1518 | break; |
| 1519 | } |
| 1520 | /* if no match the increment i since we decremented |
| 1521 | * before checking */ |
| 1522 | i = (i + 1) % 2; |
| 1523 | } |
| 1524 | /* Make sure you do not encounter a context switch twice, we can |
| 1525 | * encounter it once for the bad context as the start of search |
| 1526 | * can point to the context switch */ |
| 1527 | if (val[i] == KGSL_CONTEXT_TO_MEM_IDENTIFIER) { |
| 1528 | if (ctx_switch) { |
| 1529 | KGSL_DRV_ERR(rb->device, |
| 1530 | "Context switch encountered before bad " |
| 1531 | "IB found\n"); |
| 1532 | break; |
| 1533 | } |
| 1534 | ctx_switch = true; |
| 1535 | } |
| 1536 | i = (i + 1) % 2; |
| 1537 | if (1 == i) |
| 1538 | check = true; |
| 1539 | temp_rb_rptr = adreno_ringbuffer_inc_wrapped(temp_rb_rptr, |
| 1540 | size); |
| 1541 | } |
| 1542 | if (!status) |
| 1543 | *rb_rptr = temp_rb_rptr; |
| 1544 | return status; |
| 1545 | } |
| 1546 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1547 | static int adreno_setup_recovery_data(struct kgsl_device *device, |
| 1548 | struct adreno_recovery_data *rec_data) |
| 1549 | { |
| 1550 | int ret = 0; |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1551 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1552 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1553 | struct kgsl_context *context; |
| 1554 | struct adreno_context *adreno_context; |
| 1555 | unsigned int rb_rptr = rb->wptr * sizeof(unsigned int); |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1556 | |
| 1557 | memset(rec_data, 0, sizeof(*rec_data)); |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1558 | rec_data->start_of_replay_cmds = 0xFFFFFFFF; |
| 1559 | rec_data->replay_for_snapshot = 0xFFFFFFFF; |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1560 | |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1561 | adreno_regread(device, REG_CP_IB1_BASE, &rec_data->ib1); |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1562 | |
| 1563 | kgsl_sharedmem_readl(&device->memstore, &rec_data->context_id, |
| 1564 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 1565 | current_context)); |
| 1566 | |
| 1567 | kgsl_sharedmem_readl(&device->memstore, |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1568 | &rec_data->global_eop, |
| 1569 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 1570 | eoptimestamp)); |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1571 | |
| 1572 | rec_data->rb_buffer = vmalloc(rb->buffer_desc.size); |
| 1573 | if (!rec_data->rb_buffer) { |
| 1574 | KGSL_MEM_ERR(device, "vmalloc(%d) failed\n", |
| 1575 | rb->buffer_desc.size); |
| 1576 | return -ENOMEM; |
| 1577 | } |
| 1578 | |
| 1579 | rec_data->bad_rb_buffer = vmalloc(rb->buffer_desc.size); |
| 1580 | if (!rec_data->bad_rb_buffer) { |
| 1581 | KGSL_MEM_ERR(device, "vmalloc(%d) failed\n", |
| 1582 | rb->buffer_desc.size); |
| 1583 | ret = -ENOMEM; |
| 1584 | goto done; |
| 1585 | } |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1586 | |
| 1587 | rec_data->good_rb_buffer = vmalloc(rb->buffer_desc.size); |
| 1588 | if (!rec_data->good_rb_buffer) { |
| 1589 | KGSL_MEM_ERR(device, "vmalloc(%d) failed\n", |
| 1590 | rb->buffer_desc.size); |
| 1591 | ret = -ENOMEM; |
| 1592 | goto done; |
| 1593 | } |
Shubhraprakash Das | 2747cf6 | 2012-09-27 23:05:43 -0700 | [diff] [blame] | 1594 | rec_data->fault = device->mmu.fault; |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1595 | rec_data->step = adreno_dev->ft_policy; |
| 1596 | |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1597 | /* find the start of bad command sequence in rb */ |
| 1598 | context = idr_find(&device->context_idr, rec_data->context_id); |
| 1599 | /* Look for the command stream that is right after the global eop */ |
| 1600 | |
| 1601 | if (!context) { |
| 1602 | /* |
| 1603 | * If there is no context then recovery does not need to |
| 1604 | * replay anything, just reset GPU and thats it |
| 1605 | */ |
| 1606 | goto done; |
| 1607 | } |
| 1608 | ret = _find_cmd_seq_after_eop_ts(rb, &rb_rptr, |
| 1609 | rec_data->global_eop + 1, false); |
| 1610 | if (ret) |
| 1611 | goto done; |
| 1612 | |
| 1613 | rec_data->start_of_replay_cmds = rb_rptr; |
| 1614 | |
| 1615 | adreno_context = context->devctxt; |
| 1616 | if (adreno_context->flags & CTXT_FLAGS_PREAMBLE) { |
| 1617 | if (rec_data->ib1) { |
| 1618 | ret = _find_hanging_ib_sequence(rb, |
| 1619 | &rb_rptr, rec_data->ib1); |
| 1620 | if (ret) { |
| 1621 | KGSL_DRV_ERR(device, |
| 1622 | "Start not found for replay IB sequence\n"); |
| 1623 | ret = 0; |
| 1624 | goto done; |
| 1625 | } |
| 1626 | rec_data->start_of_replay_cmds = rb_rptr; |
| 1627 | rec_data->replay_for_snapshot = rb_rptr; |
| 1628 | } |
| 1629 | } |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1630 | |
| 1631 | done: |
| 1632 | if (ret) { |
| 1633 | vfree(rec_data->rb_buffer); |
| 1634 | vfree(rec_data->bad_rb_buffer); |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1635 | vfree(rec_data->good_rb_buffer); |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1636 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1637 | return ret; |
| 1638 | } |
| 1639 | |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1640 | static int |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1641 | _adreno_restart_device(struct kgsl_device *device, |
| 1642 | struct kgsl_context *context) |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1643 | { |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1644 | |
| 1645 | struct adreno_context *adreno_context = context->devctxt; |
| 1646 | |
| 1647 | /* restart device */ |
| 1648 | if (adreno_stop(device)) { |
| 1649 | KGSL_DRV_ERR(device, "Device stop failed in recovery\n"); |
| 1650 | return 1; |
| 1651 | } |
| 1652 | |
| 1653 | if (adreno_start(device, true)) { |
| 1654 | KGSL_DRV_ERR(device, "Device start failed in recovery\n"); |
| 1655 | return 1; |
| 1656 | } |
| 1657 | |
| 1658 | if (context) |
| 1659 | kgsl_mmu_setstate(&device->mmu, adreno_context->pagetable, |
| 1660 | KGSL_MEMSTORE_GLOBAL); |
| 1661 | |
| 1662 | /* If iommu is used then we need to make sure that the iommu clocks |
| 1663 | * are on since there could be commands in pipeline that touch iommu */ |
| 1664 | if (KGSL_MMU_TYPE_IOMMU == kgsl_mmu_get_mmutype()) { |
| 1665 | if (kgsl_mmu_enable_clk(&device->mmu, |
| 1666 | KGSL_IOMMU_CONTEXT_USER)) |
| 1667 | return 1; |
| 1668 | } |
| 1669 | |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
| 1673 | static int |
| 1674 | _adreno_recovery_resubmit(struct kgsl_device *device, |
| 1675 | struct adreno_ringbuffer *rb, |
| 1676 | struct kgsl_context *context, |
| 1677 | struct adreno_recovery_data *rec_data, |
| 1678 | unsigned int *buff, unsigned int size) |
| 1679 | { |
| 1680 | unsigned int ret = 0; |
| 1681 | |
| 1682 | if (_adreno_restart_device(device, context)) |
| 1683 | return 1; |
| 1684 | |
| 1685 | if (size) { |
| 1686 | |
| 1687 | /* submit commands and wait for them to pass */ |
| 1688 | adreno_ringbuffer_restore(rb, buff, size); |
| 1689 | |
| 1690 | ret = adreno_idle(device); |
| 1691 | } |
| 1692 | |
| 1693 | return ret; |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | static int |
| 1698 | _adreno_recover_hang(struct kgsl_device *device, |
| 1699 | struct adreno_recovery_data *rec_data) |
| 1700 | { |
| 1701 | int ret = 0, i; |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1702 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1703 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1704 | struct kgsl_context *context; |
| 1705 | struct adreno_context *adreno_context = NULL; |
| 1706 | struct adreno_context *last_active_ctx = adreno_dev->drawctxt_active; |
| 1707 | |
| 1708 | context = idr_find(&device->context_idr, rec_data->context_id); |
| 1709 | if (context == NULL) { |
| 1710 | KGSL_DRV_ERR(device, "Last context unknown id:%d\n", |
| 1711 | rec_data->context_id); |
| 1712 | } else { |
| 1713 | adreno_context = context->devctxt; |
| 1714 | adreno_context->flags |= CTXT_FLAGS_GPU_HANG; |
Rajeev Kulkarni | 46ee109 | 2012-12-14 14:47:55 -0800 | [diff] [blame] | 1715 | /* |
| 1716 | * set the invalid ts flag to 0 for this context since we have |
| 1717 | * detected a hang for it |
| 1718 | */ |
| 1719 | context->wait_on_invalid_ts = false; |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | /* Extract valid contents from rb which can still be executed after |
| 1723 | * hang */ |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1724 | adreno_ringbuffer_extract(rb, rec_data); |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1725 | |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1726 | /* Do not try the bad commands if hang is due to a fault */ |
| 1727 | if (rec_data->fault) |
| 1728 | goto play_good_cmds; |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1729 | |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1730 | if (rec_data->step == FT_REPLAY_BAD_CTXT_CMDS) { |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1731 | |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1732 | ret = _adreno_recovery_resubmit(device, rb, context, rec_data, |
| 1733 | rec_data->bad_rb_buffer, rec_data->bad_rb_size); |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1734 | |
Shubhraprakash Das | bd39669 | 2012-06-15 14:19:34 -0600 | [diff] [blame] | 1735 | if (ret) |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1736 | rec_data->step = FT_NOT_IB_BAD_CTXT_CMDS; |
| 1737 | else |
| 1738 | goto play_good_cmds; |
| 1739 | |
Shubhraprakash Das | bd39669 | 2012-06-15 14:19:34 -0600 | [diff] [blame] | 1740 | } |
| 1741 | |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1742 | if (rec_data->step == FT_NOT_IB_BAD_CTXT_CMDS) { |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1743 | |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1744 | for (i = 0; i < rec_data->bad_rb_size; i++) { |
| 1745 | if ((rec_data->bad_rb_buffer[i] == |
| 1746 | CP_HDR_INDIRECT_BUFFER_PFD) && |
| 1747 | (rec_data->bad_rb_buffer[i+1] == |
| 1748 | rec_data->ib1)) { |
Shubhraprakash Das | bd39669 | 2012-06-15 14:19:34 -0600 | [diff] [blame] | 1749 | |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1750 | rec_data->bad_rb_buffer[i] = cp_nop_packet(2); |
| 1751 | rec_data->bad_rb_buffer[i+1] = |
| 1752 | KGSL_NOP_IB_IDENTIFIER; |
| 1753 | rec_data->bad_rb_buffer[i+2] = |
| 1754 | KGSL_NOP_IB_IDENTIFIER; |
| 1755 | break; |
Shubhraprakash Das | bd39669 | 2012-06-15 14:19:34 -0600 | [diff] [blame] | 1756 | } |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1757 | } |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1758 | |
| 1759 | if ((i == (rec_data->bad_rb_size)) || (!rec_data->ib1)) { |
| 1760 | KGSL_DRV_ERR(device, "Bad IB to NOP not found\n"); |
| 1761 | rec_data->step = FT_FAIL_BAD_CTXT_CMDS; |
| 1762 | goto play_good_cmds; |
| 1763 | } |
| 1764 | |
| 1765 | ret = _adreno_recovery_resubmit(device, rb, context, rec_data, |
| 1766 | rec_data->bad_rb_buffer, rec_data->bad_rb_size); |
| 1767 | |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1768 | if (ret) { |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1769 | KGSL_DRV_ERR(device, "NOP faulty IB unsuccessful\n"); |
| 1770 | rec_data->step = FT_SKIP_EOF_BAD_CTXT_CMDS; |
| 1771 | } else |
| 1772 | goto play_good_cmds; |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1773 | } |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1774 | |
| 1775 | if (rec_data->step == FT_SKIP_EOF_BAD_CTXT_CMDS) { |
| 1776 | |
| 1777 | for (i = 0; i < rec_data->bad_rb_size; i++) { |
| 1778 | if (rec_data->bad_rb_buffer[i] == |
| 1779 | KGSL_END_OF_FRAME_IDENTIFIER) { |
| 1780 | rec_data->bad_rb_buffer[0] = cp_nop_packet(i); |
| 1781 | break; |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | /* EOF not found in RB, discard till EOF in |
| 1786 | next IB submission */ |
| 1787 | if (i == rec_data->bad_rb_size) { |
| 1788 | adreno_context->flags |= CTXT_FLAGS_SKIP_EOF; |
| 1789 | rec_data->bad_rb_buffer[0] = cp_nop_packet(i); |
| 1790 | } |
| 1791 | |
| 1792 | ret = _adreno_recovery_resubmit(device, rb, context, rec_data, |
| 1793 | rec_data->bad_rb_buffer, rec_data->bad_rb_size); |
| 1794 | |
| 1795 | if (ret) { |
| 1796 | KGSL_DRV_ERR(device, "Skip EOF unsuccessful\n"); |
| 1797 | rec_data->step = FT_FAIL_BAD_CTXT_CMDS; |
| 1798 | } else |
| 1799 | goto play_good_cmds; |
| 1800 | } |
| 1801 | |
| 1802 | play_good_cmds: |
| 1803 | |
| 1804 | if (rec_data->step == FT_FAIL_BAD_CTXT_CMDS) |
| 1805 | KGSL_DRV_ERR(device, "Bad context commands failed\n"); |
| 1806 | else { |
| 1807 | |
| 1808 | if (adreno_context) { |
| 1809 | adreno_context->flags = (adreno_context->flags & |
| 1810 | ~CTXT_FLAGS_GPU_HANG) | CTXT_FLAGS_GPU_HANG_RECOVERED; |
| 1811 | } |
| 1812 | adreno_dev->drawctxt_active = last_active_ctx; |
| 1813 | } |
| 1814 | |
| 1815 | ret = _adreno_recovery_resubmit(device, rb, context, rec_data, |
| 1816 | rec_data->good_rb_buffer, rec_data->good_rb_size); |
| 1817 | |
| 1818 | if (ret) { |
| 1819 | /* If we fail here we can try to invalidate another |
| 1820 | * context and try fault tolerance again */ |
| 1821 | ret = -EAGAIN; |
| 1822 | KGSL_DRV_ERR(device, "Playing good commands unsuccessful\n"); |
| 1823 | goto done; |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | /* ringbuffer now has data from the last valid context id, |
| 1828 | * so restore the active_ctx to the last valid context */ |
| 1829 | if (rec_data->last_valid_ctx_id) { |
| 1830 | struct kgsl_context *last_ctx = |
| 1831 | idr_find(&device->context_idr, |
| 1832 | rec_data->last_valid_ctx_id); |
| 1833 | if (last_ctx) |
| 1834 | adreno_dev->drawctxt_active = last_ctx->devctxt; |
| 1835 | } |
| 1836 | |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1837 | done: |
Shubhraprakash Das | bd39669 | 2012-06-15 14:19:34 -0600 | [diff] [blame] | 1838 | /* Turn off iommu clocks */ |
| 1839 | if (KGSL_MMU_TYPE_IOMMU == kgsl_mmu_get_mmutype()) |
| 1840 | kgsl_mmu_disable_clk_on_ts(&device->mmu, 0, false); |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1841 | return ret; |
| 1842 | } |
| 1843 | |
| 1844 | static int |
| 1845 | adreno_recover_hang(struct kgsl_device *device, |
| 1846 | struct adreno_recovery_data *rec_data) |
| 1847 | { |
| 1848 | int ret = 0; |
| 1849 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1850 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 1851 | unsigned int timestamp; |
| 1852 | |
| 1853 | KGSL_DRV_ERR(device, |
| 1854 | "Starting recovery from 3D GPU hang. Recovery parameters: IB1: 0x%X, " |
| 1855 | "Bad context_id: %u, global_eop: 0x%x\n", |
| 1856 | rec_data->ib1, rec_data->context_id, rec_data->global_eop); |
| 1857 | |
| 1858 | timestamp = rb->timestamp[KGSL_MEMSTORE_GLOBAL]; |
| 1859 | KGSL_DRV_ERR(device, "Last issued global timestamp: %x\n", timestamp); |
| 1860 | |
| 1861 | /* We may need to replay commands multiple times based on whether |
| 1862 | * multiple contexts hang the GPU */ |
| 1863 | while (true) { |
Tarun Karra | deeecc0 | 2013-01-21 23:42:17 -0800 | [diff] [blame^] | 1864 | |
| 1865 | ret = _adreno_recover_hang(device, rec_data); |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1866 | |
| 1867 | if (-EAGAIN == ret) { |
| 1868 | /* setup new recovery parameters and retry, this |
| 1869 | * means more than 1 contexts are causing hang */ |
| 1870 | adreno_destroy_recovery_data(rec_data); |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1871 | ret = adreno_setup_recovery_data(device, rec_data); |
| 1872 | if (ret) |
| 1873 | goto done; |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1874 | KGSL_DRV_ERR(device, |
| 1875 | "Retry recovery from 3D GPU hang. Recovery parameters: " |
| 1876 | "IB1: 0x%X, Bad context_id: %u, global_eop: 0x%x\n", |
| 1877 | rec_data->ib1, rec_data->context_id, |
| 1878 | rec_data->global_eop); |
| 1879 | } else { |
| 1880 | break; |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | if (ret) |
| 1885 | goto done; |
| 1886 | |
| 1887 | /* Restore correct states after recovery */ |
| 1888 | if (adreno_dev->drawctxt_active) |
| 1889 | device->mmu.hwpagetable = |
| 1890 | adreno_dev->drawctxt_active->pagetable; |
| 1891 | else |
| 1892 | device->mmu.hwpagetable = device->mmu.defaultpagetable; |
| 1893 | rb->timestamp[KGSL_MEMSTORE_GLOBAL] = timestamp; |
| 1894 | kgsl_sharedmem_writel(&device->memstore, |
| 1895 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 1896 | eoptimestamp), |
| 1897 | rb->timestamp[KGSL_MEMSTORE_GLOBAL]); |
Carter Cooper | 8179f5a | 2012-12-17 11:32:27 -0700 | [diff] [blame] | 1898 | |
| 1899 | /* switch to NULL ctxt */ |
| 1900 | if (adreno_dev->drawctxt_active != NULL) |
| 1901 | adreno_drawctxt_switch(adreno_dev, NULL, 0); |
| 1902 | |
Shubhraprakash Das | 32240ef | 2012-06-06 20:27:46 -0600 | [diff] [blame] | 1903 | done: |
| 1904 | adreno_set_max_ts_for_bad_ctxs(device); |
| 1905 | adreno_mark_context_status(device, ret); |
| 1906 | if (!ret) |
| 1907 | KGSL_DRV_ERR(device, "Recovery succeeded\n"); |
| 1908 | else |
| 1909 | KGSL_DRV_ERR(device, "Recovery failed\n"); |
| 1910 | return ret; |
| 1911 | } |
| 1912 | |
| 1913 | int |
| 1914 | adreno_dump_and_recover(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1915 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1916 | int result = -ETIMEDOUT; |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1917 | struct adreno_recovery_data rec_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1918 | |
| 1919 | if (device->state == KGSL_STATE_HUNG) |
| 1920 | goto done; |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1921 | if (device->state == KGSL_STATE_DUMP_AND_RECOVER) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1922 | mutex_unlock(&device->mutex); |
| 1923 | wait_for_completion(&device->recovery_gate); |
| 1924 | mutex_lock(&device->mutex); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1925 | if (device->state != KGSL_STATE_HUNG) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1926 | result = 0; |
| 1927 | } else { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1928 | kgsl_pwrctrl_set_state(device, KGSL_STATE_DUMP_AND_RECOVER); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1929 | INIT_COMPLETION(device->recovery_gate); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1930 | /* Detected a hang */ |
| 1931 | |
Shubhraprakash Das | ba6c70b | 2012-05-31 02:53:06 -0600 | [diff] [blame] | 1932 | /* Get the recovery data as soon as hang is detected */ |
| 1933 | result = adreno_setup_recovery_data(device, &rec_data); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1934 | /* |
| 1935 | * Trigger an automatic dump of the state to |
| 1936 | * the console |
| 1937 | */ |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 1938 | kgsl_postmortem_dump(device, 0); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1939 | |
| 1940 | /* |
| 1941 | * Make a GPU snapshot. For now, do it after the PM dump so we |
| 1942 | * can at least be sure the PM dump will work as it always has |
| 1943 | */ |
| 1944 | kgsl_device_snapshot(device, 1); |
| 1945 | |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 1946 | if (!result) { |
| 1947 | result = adreno_recover_hang(device, &rec_data); |
| 1948 | adreno_destroy_recovery_data(&rec_data); |
| 1949 | } |
Shubhraprakash Das | df60930 | 2012-06-06 20:02:58 -0600 | [diff] [blame] | 1950 | if (result) { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1951 | kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG); |
Shubhraprakash Das | df60930 | 2012-06-06 20:02:58 -0600 | [diff] [blame] | 1952 | } else { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1953 | kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); |
Shubhraprakash Das | df60930 | 2012-06-06 20:02:58 -0600 | [diff] [blame] | 1954 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
| 1955 | } |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1956 | complete_all(&device->recovery_gate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1957 | } |
| 1958 | done: |
| 1959 | return result; |
| 1960 | } |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 1961 | EXPORT_SYMBOL(adreno_dump_and_recover); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1962 | |
| 1963 | static int adreno_getproperty(struct kgsl_device *device, |
| 1964 | enum kgsl_property_type type, |
| 1965 | void *value, |
| 1966 | unsigned int sizebytes) |
| 1967 | { |
| 1968 | int status = -EINVAL; |
| 1969 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1970 | |
| 1971 | switch (type) { |
| 1972 | case KGSL_PROP_DEVICE_INFO: |
| 1973 | { |
| 1974 | struct kgsl_devinfo devinfo; |
| 1975 | |
| 1976 | if (sizebytes != sizeof(devinfo)) { |
| 1977 | status = -EINVAL; |
| 1978 | break; |
| 1979 | } |
| 1980 | |
| 1981 | memset(&devinfo, 0, sizeof(devinfo)); |
| 1982 | devinfo.device_id = device->id+1; |
| 1983 | devinfo.chip_id = adreno_dev->chip_id; |
| 1984 | devinfo.mmu_enabled = kgsl_mmu_enabled(); |
| 1985 | devinfo.gpu_id = adreno_dev->gpurev; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 1986 | devinfo.gmem_gpubaseaddr = adreno_dev->gmem_base; |
| 1987 | devinfo.gmem_sizebytes = adreno_dev->gmem_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1988 | |
| 1989 | if (copy_to_user(value, &devinfo, sizeof(devinfo)) != |
| 1990 | 0) { |
| 1991 | status = -EFAULT; |
| 1992 | break; |
| 1993 | } |
| 1994 | status = 0; |
| 1995 | } |
| 1996 | break; |
| 1997 | case KGSL_PROP_DEVICE_SHADOW: |
| 1998 | { |
| 1999 | struct kgsl_shadowprop shadowprop; |
| 2000 | |
| 2001 | if (sizebytes != sizeof(shadowprop)) { |
| 2002 | status = -EINVAL; |
| 2003 | break; |
| 2004 | } |
| 2005 | memset(&shadowprop, 0, sizeof(shadowprop)); |
| 2006 | if (device->memstore.hostptr) { |
| 2007 | /*NOTE: with mmu enabled, gpuaddr doesn't mean |
| 2008 | * anything to mmap(). |
| 2009 | */ |
Shubhraprakash Das | 87f6813 | 2012-07-30 23:25:13 -0700 | [diff] [blame] | 2010 | shadowprop.gpuaddr = device->memstore.gpuaddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2011 | shadowprop.size = device->memstore.size; |
| 2012 | /* GSL needs this to be set, even if it |
| 2013 | appears to be meaningless */ |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2014 | shadowprop.flags = KGSL_FLAGS_INITIALIZED | |
| 2015 | KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2016 | } |
| 2017 | if (copy_to_user(value, &shadowprop, |
| 2018 | sizeof(shadowprop))) { |
| 2019 | status = -EFAULT; |
| 2020 | break; |
| 2021 | } |
| 2022 | status = 0; |
| 2023 | } |
| 2024 | break; |
| 2025 | case KGSL_PROP_MMU_ENABLE: |
| 2026 | { |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 2027 | int mmu_prop = kgsl_mmu_enabled(); |
| 2028 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2029 | if (sizebytes != sizeof(int)) { |
| 2030 | status = -EINVAL; |
| 2031 | break; |
| 2032 | } |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 2033 | if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2034 | status = -EFAULT; |
| 2035 | break; |
| 2036 | } |
| 2037 | status = 0; |
| 2038 | } |
| 2039 | break; |
| 2040 | case KGSL_PROP_INTERRUPT_WAITS: |
| 2041 | { |
| 2042 | int int_waits = 1; |
| 2043 | if (sizebytes != sizeof(int)) { |
| 2044 | status = -EINVAL; |
| 2045 | break; |
| 2046 | } |
| 2047 | if (copy_to_user(value, &int_waits, sizeof(int))) { |
| 2048 | status = -EFAULT; |
| 2049 | break; |
| 2050 | } |
| 2051 | status = 0; |
| 2052 | } |
| 2053 | break; |
| 2054 | default: |
| 2055 | status = -EINVAL; |
| 2056 | } |
| 2057 | |
| 2058 | return status; |
| 2059 | } |
| 2060 | |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 2061 | static int adreno_setproperty(struct kgsl_device *device, |
| 2062 | enum kgsl_property_type type, |
| 2063 | void *value, |
| 2064 | unsigned int sizebytes) |
| 2065 | { |
| 2066 | int status = -EINVAL; |
Tarun Karra | 6e750d7 | 2013-01-04 10:28:40 -0800 | [diff] [blame] | 2067 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 2068 | |
| 2069 | switch (type) { |
| 2070 | case KGSL_PROP_PWRCTRL: { |
| 2071 | unsigned int enable; |
| 2072 | struct kgsl_device_platform_data *pdata = |
| 2073 | kgsl_device_get_drvdata(device); |
| 2074 | |
| 2075 | if (sizebytes != sizeof(enable)) |
| 2076 | break; |
| 2077 | |
| 2078 | if (copy_from_user(&enable, (void __user *) value, |
| 2079 | sizeof(enable))) { |
| 2080 | status = -EFAULT; |
| 2081 | break; |
| 2082 | } |
| 2083 | |
| 2084 | if (enable) { |
| 2085 | if (pdata->nap_allowed) |
| 2086 | device->pwrctrl.nap_allowed = true; |
Tarun Karra | 6e750d7 | 2013-01-04 10:28:40 -0800 | [diff] [blame] | 2087 | adreno_dev->fast_hang_detect = 1; |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 2088 | kgsl_pwrscale_enable(device); |
| 2089 | } else { |
| 2090 | device->pwrctrl.nap_allowed = false; |
Tarun Karra | 6e750d7 | 2013-01-04 10:28:40 -0800 | [diff] [blame] | 2091 | adreno_dev->fast_hang_detect = 0; |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 2092 | kgsl_pwrscale_disable(device); |
| 2093 | } |
| 2094 | |
| 2095 | status = 0; |
| 2096 | } |
| 2097 | break; |
| 2098 | default: |
| 2099 | break; |
| 2100 | } |
| 2101 | |
| 2102 | return status; |
| 2103 | } |
| 2104 | |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2105 | static int adreno_ringbuffer_drain(struct kgsl_device *device, |
| 2106 | unsigned int *regs) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2107 | { |
| 2108 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2109 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2110 | unsigned long wait; |
| 2111 | unsigned long timeout = jiffies + msecs_to_jiffies(ADRENO_IDLE_TIMEOUT); |
| 2112 | |
| 2113 | if (!(rb->flags & KGSL_FLAGS_STARTED)) |
| 2114 | return 0; |
| 2115 | |
| 2116 | /* |
| 2117 | * The first time into the loop, wait for 100 msecs and kick wptr again |
| 2118 | * to ensure that the hardware has updated correctly. After that, kick |
| 2119 | * it periodically every KGSL_TIMEOUT_PART msecs until the timeout |
| 2120 | * expires |
| 2121 | */ |
| 2122 | |
| 2123 | wait = jiffies + msecs_to_jiffies(100); |
| 2124 | |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2125 | do { |
| 2126 | if (time_after(jiffies, wait)) { |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2127 | /* Check to see if the core is hung */ |
| 2128 | if (adreno_hang_detect(device, regs)) |
| 2129 | return -ETIMEDOUT; |
| 2130 | |
| 2131 | wait = jiffies + msecs_to_jiffies(KGSL_TIMEOUT_PART); |
| 2132 | } |
| 2133 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 2134 | |
| 2135 | if (time_after(jiffies, timeout)) { |
| 2136 | KGSL_DRV_ERR(device, "rptr: %x, wptr: %x\n", |
| 2137 | rb->rptr, rb->wptr); |
| 2138 | return -ETIMEDOUT; |
| 2139 | } |
| 2140 | } while (rb->rptr != rb->wptr); |
| 2141 | |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | /* Caller must hold the device mutex. */ |
| 2146 | int adreno_idle(struct kgsl_device *device) |
| 2147 | { |
| 2148 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2149 | unsigned int rbbm_status; |
Lynus Vaz | 284d104 | 2012-01-31 16:32:31 +0530 | [diff] [blame] | 2150 | unsigned long wait_time; |
| 2151 | unsigned long wait_time_part; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2152 | unsigned int prev_reg_val[hang_detect_regs_count]; |
| 2153 | |
| 2154 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2155 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 2156 | kgsl_cffdump_regpoll(device->id, |
| 2157 | adreno_dev->gpudev->reg_rbbm_status << 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2158 | 0x00000000, 0x80000000); |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2159 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2160 | retry: |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2161 | /* First, wait for the ringbuffer to drain */ |
| 2162 | if (adreno_ringbuffer_drain(device, prev_reg_val)) |
| 2163 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2164 | |
| 2165 | /* now, wait for the GPU to finish its operations */ |
Jordan Crouse | 0bcdb73 | 2012-10-25 09:37:43 -0600 | [diff] [blame] | 2166 | wait_time = jiffies + msecs_to_jiffies(ADRENO_IDLE_TIMEOUT); |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2167 | wait_time_part = jiffies + msecs_to_jiffies(KGSL_TIMEOUT_PART); |
| 2168 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2169 | while (time_before(jiffies, wait_time)) { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 2170 | adreno_regread(device, adreno_dev->gpudev->reg_rbbm_status, |
| 2171 | &rbbm_status); |
| 2172 | if (adreno_is_a2xx(adreno_dev)) { |
| 2173 | if (rbbm_status == 0x110) |
| 2174 | return 0; |
| 2175 | } else { |
| 2176 | if (!(rbbm_status & 0x80000000)) |
| 2177 | return 0; |
| 2178 | } |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2179 | |
| 2180 | /* Dont wait for timeout, detect hang faster. |
| 2181 | */ |
| 2182 | if (time_after(jiffies, wait_time_part)) { |
| 2183 | wait_time_part = jiffies + |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2184 | msecs_to_jiffies(KGSL_TIMEOUT_PART); |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2185 | if ((adreno_hang_detect(device, prev_reg_val))) |
| 2186 | goto err; |
| 2187 | } |
| 2188 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | err: |
| 2192 | KGSL_DRV_ERR(device, "spun too long waiting for RB to idle\n"); |
Shubhraprakash Das | 1088bdb | 2012-05-29 18:19:11 -0600 | [diff] [blame] | 2193 | if (KGSL_STATE_DUMP_AND_RECOVER != device->state && |
| 2194 | !adreno_dump_and_recover(device)) { |
Jordan Crouse | 0bcdb73 | 2012-10-25 09:37:43 -0600 | [diff] [blame] | 2195 | wait_time = jiffies + msecs_to_jiffies(ADRENO_IDLE_TIMEOUT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2196 | goto retry; |
| 2197 | } |
| 2198 | return -ETIMEDOUT; |
| 2199 | } |
| 2200 | |
Rajeev Kulkarni | 12d7dcd | 2012-11-22 00:27:35 -0800 | [diff] [blame] | 2201 | /** |
| 2202 | * is_adreno_rbbm_status_idle - Check if GPU core is idle by probing |
| 2203 | * rbbm_status register |
| 2204 | * @device - Pointer to the GPU device whose idle status is to be |
| 2205 | * checked |
| 2206 | * @returns - Returns whether the core is idle (based on rbbm_status) |
| 2207 | * false if the core is active, true if the core is idle |
| 2208 | */ |
| 2209 | static bool is_adreno_rbbm_status_idle(struct kgsl_device *device) |
| 2210 | { |
| 2211 | unsigned int reg_rbbm_status; |
| 2212 | bool status = false; |
| 2213 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2214 | |
| 2215 | /* Is the core idle? */ |
| 2216 | adreno_regread(device, |
| 2217 | adreno_dev->gpudev->reg_rbbm_status, |
| 2218 | ®_rbbm_status); |
| 2219 | |
| 2220 | if (adreno_is_a2xx(adreno_dev)) { |
| 2221 | if (reg_rbbm_status == 0x110) |
| 2222 | status = true; |
| 2223 | } else { |
| 2224 | if (!(reg_rbbm_status & 0x80000000)) |
| 2225 | status = true; |
| 2226 | } |
| 2227 | return status; |
| 2228 | } |
| 2229 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2230 | static unsigned int adreno_isidle(struct kgsl_device *device) |
| 2231 | { |
| 2232 | int status = false; |
| 2233 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2234 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2235 | |
Lucille Sylvester | 51b764d | 2011-12-15 16:51:52 -0700 | [diff] [blame] | 2236 | WARN_ON(device->state == KGSL_STATE_INIT); |
| 2237 | /* If the device isn't active, don't force it on. */ |
| 2238 | if (device->state == KGSL_STATE_ACTIVE) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2239 | /* Is the ring buffer is empty? */ |
| 2240 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 2241 | if (!device->active_cnt && (rb->rptr == rb->wptr)) { |
| 2242 | /* Is the core idle? */ |
Rajeev Kulkarni | 12d7dcd | 2012-11-22 00:27:35 -0800 | [diff] [blame] | 2243 | status = is_adreno_rbbm_status_idle(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2244 | } |
| 2245 | } else { |
Jeremy Gebben | aeb2387 | 2011-12-13 15:58:24 -0700 | [diff] [blame] | 2246 | status = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2247 | } |
| 2248 | return status; |
| 2249 | } |
| 2250 | |
| 2251 | /* Caller must hold the device mutex. */ |
| 2252 | static int adreno_suspend_context(struct kgsl_device *device) |
| 2253 | { |
| 2254 | int status = 0; |
| 2255 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2256 | |
| 2257 | /* switch to NULL ctxt */ |
| 2258 | if (adreno_dev->drawctxt_active != NULL) { |
| 2259 | adreno_drawctxt_switch(adreno_dev, NULL, 0); |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2260 | status = adreno_idle(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | return status; |
| 2264 | } |
| 2265 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 2266 | /* Find a memory structure attached to an adreno context */ |
| 2267 | |
| 2268 | struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device, |
| 2269 | unsigned int pt_base, unsigned int gpuaddr, unsigned int size) |
| 2270 | { |
| 2271 | struct kgsl_context *context; |
| 2272 | struct adreno_context *adreno_context = NULL; |
| 2273 | int next = 0; |
| 2274 | |
| 2275 | while (1) { |
| 2276 | context = idr_get_next(&device->context_idr, &next); |
| 2277 | if (context == NULL) |
| 2278 | break; |
| 2279 | |
| 2280 | adreno_context = (struct adreno_context *)context->devctxt; |
| 2281 | |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 2282 | if (kgsl_mmu_pt_equal(&device->mmu, adreno_context->pagetable, |
| 2283 | pt_base)) { |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 2284 | struct kgsl_memdesc *desc; |
| 2285 | |
| 2286 | desc = &adreno_context->gpustate; |
| 2287 | if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size)) |
| 2288 | return desc; |
| 2289 | |
| 2290 | desc = &adreno_context->context_gmem_shadow.gmemshadow; |
| 2291 | if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size)) |
| 2292 | return desc; |
| 2293 | } |
| 2294 | next = next + 1; |
| 2295 | } |
| 2296 | |
| 2297 | return NULL; |
| 2298 | } |
| 2299 | |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 2300 | struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device, |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 2301 | unsigned int pt_base, |
| 2302 | unsigned int gpuaddr, |
| 2303 | unsigned int size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2304 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2305 | struct kgsl_mem_entry *entry; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2306 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2307 | struct adreno_ringbuffer *ringbuffer = &adreno_dev->ringbuffer; |
| 2308 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 2309 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->buffer_desc, gpuaddr, size)) |
| 2310 | return &ringbuffer->buffer_desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2311 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 2312 | if (kgsl_gpuaddr_in_memdesc(&ringbuffer->memptrs_desc, gpuaddr, size)) |
| 2313 | return &ringbuffer->memptrs_desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2314 | |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 2315 | if (kgsl_gpuaddr_in_memdesc(&device->memstore, gpuaddr, size)) |
| 2316 | return &device->memstore; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2317 | |
Shubhraprakash Das | 9a14097 | 2012-04-12 13:12:42 -0600 | [diff] [blame] | 2318 | if (kgsl_gpuaddr_in_memdesc(&device->mmu.setstate_memory, gpuaddr, |
| 2319 | size)) |
| 2320 | return &device->mmu.setstate_memory; |
| 2321 | |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 2322 | entry = kgsl_get_mem_entry(device, pt_base, gpuaddr, size); |
Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 2323 | |
| 2324 | if (entry) |
| 2325 | return &entry->memdesc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2326 | |
Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 2327 | return adreno_find_ctxtmem(device, pt_base, gpuaddr, size); |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | uint8_t *adreno_convertaddr(struct kgsl_device *device, unsigned int pt_base, |
| 2331 | unsigned int gpuaddr, unsigned int size) |
| 2332 | { |
Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 2333 | struct kgsl_memdesc *memdesc; |
Jeremy Gebben | 16e80fa | 2011-11-30 15:56:29 -0700 | [diff] [blame] | 2334 | |
| 2335 | memdesc = adreno_find_region(device, pt_base, gpuaddr, size); |
| 2336 | |
| 2337 | return memdesc ? kgsl_gpuaddr_to_vaddr(memdesc, gpuaddr) : NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | void adreno_regread(struct kgsl_device *device, unsigned int offsetwords, |
| 2341 | unsigned int *value) |
| 2342 | { |
| 2343 | unsigned int *reg; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2344 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
| 2345 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2346 | |
| 2347 | if (!in_interrupt()) |
| 2348 | kgsl_pre_hwaccess(device); |
| 2349 | |
| 2350 | /*ensure this read finishes before the next one. |
| 2351 | * i.e. act like normal readl() */ |
| 2352 | *value = __raw_readl(reg); |
| 2353 | rmb(); |
| 2354 | } |
| 2355 | |
| 2356 | void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords, |
| 2357 | unsigned int value) |
| 2358 | { |
| 2359 | unsigned int *reg; |
| 2360 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2361 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2362 | |
| 2363 | if (!in_interrupt()) |
| 2364 | kgsl_pre_hwaccess(device); |
| 2365 | |
| 2366 | kgsl_cffdump_regwrite(device->id, offsetwords << 2, value); |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2367 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2368 | |
| 2369 | /*ensure previous writes post before this one, |
| 2370 | * i.e. act like normal writel() */ |
| 2371 | wmb(); |
| 2372 | __raw_writel(value, reg); |
| 2373 | } |
| 2374 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2375 | static unsigned int _get_context_id(struct kgsl_context *k_ctxt) |
| 2376 | { |
| 2377 | unsigned int context_id = KGSL_MEMSTORE_GLOBAL; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2378 | if (k_ctxt != NULL) { |
| 2379 | struct adreno_context *a_ctxt = k_ctxt->devctxt; |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 2380 | if (k_ctxt->id == KGSL_CONTEXT_INVALID || a_ctxt == NULL) |
| 2381 | context_id = KGSL_CONTEXT_INVALID; |
| 2382 | else if (a_ctxt->flags & CTXT_FLAGS_PER_CONTEXT_TS) |
| 2383 | context_id = k_ctxt->id; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | return context_id; |
| 2387 | } |
| 2388 | |
Jordan Crouse | 313faf6 | 2012-11-20 15:12:28 -0700 | [diff] [blame] | 2389 | static void adreno_next_event(struct kgsl_device *device, |
| 2390 | struct kgsl_event *event) |
| 2391 | { |
| 2392 | int status; |
| 2393 | unsigned int ref_ts, enableflag; |
| 2394 | unsigned int context_id = _get_context_id(event->context); |
| 2395 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2396 | |
| 2397 | status = kgsl_check_timestamp(device, event->context, event->timestamp); |
| 2398 | if (!status) { |
| 2399 | kgsl_sharedmem_readl(&device->memstore, &enableflag, |
| 2400 | KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable)); |
| 2401 | /* |
| 2402 | * Barrier is needed here to make sure the read from memstore |
| 2403 | * has posted |
| 2404 | */ |
| 2405 | |
| 2406 | mb(); |
| 2407 | |
| 2408 | if (enableflag) { |
| 2409 | kgsl_sharedmem_readl(&device->memstore, &ref_ts, |
| 2410 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2411 | ref_wait_ts)); |
| 2412 | |
| 2413 | /* Make sure the memstore read has posted */ |
| 2414 | mb(); |
| 2415 | if (timestamp_cmp(ref_ts, event->timestamp) >= 0) { |
| 2416 | kgsl_sharedmem_writel(&device->memstore, |
| 2417 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2418 | ref_wait_ts), event->timestamp); |
| 2419 | /* Make sure the memstore write is posted */ |
| 2420 | wmb(); |
| 2421 | } |
| 2422 | } else { |
| 2423 | unsigned int cmds[2]; |
| 2424 | kgsl_sharedmem_writel(&device->memstore, |
| 2425 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2426 | ref_wait_ts), event->timestamp); |
| 2427 | enableflag = 1; |
| 2428 | kgsl_sharedmem_writel(&device->memstore, |
| 2429 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2430 | ts_cmp_enable), enableflag); |
| 2431 | |
| 2432 | /* Make sure the memstore write gets posted */ |
| 2433 | wmb(); |
| 2434 | |
| 2435 | /* |
| 2436 | * submit a dummy packet so that even if all |
| 2437 | * commands upto timestamp get executed we will still |
| 2438 | * get an interrupt |
| 2439 | */ |
| 2440 | cmds[0] = cp_type3_packet(CP_NOP, 1); |
| 2441 | cmds[1] = 0; |
| 2442 | |
| 2443 | if (adreno_dev->drawctxt_active) |
| 2444 | adreno_ringbuffer_issuecmds_intr(device, |
| 2445 | event->context, &cmds[0], 2); |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2450 | static int kgsl_check_interrupt_timestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2451 | struct kgsl_context *context, unsigned int timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2452 | { |
| 2453 | int status; |
| 2454 | unsigned int ref_ts, enableflag; |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 2455 | unsigned int context_id; |
| 2456 | |
| 2457 | mutex_lock(&device->mutex); |
| 2458 | context_id = _get_context_id(context); |
| 2459 | /* |
| 2460 | * If the context ID is invalid, we are in a race with |
| 2461 | * the context being destroyed by userspace so bail. |
| 2462 | */ |
| 2463 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 2464 | KGSL_DRV_WARN(device, "context was detached"); |
| 2465 | status = -EINVAL; |
| 2466 | goto unlock; |
| 2467 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2468 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2469 | status = kgsl_check_timestamp(device, context, timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2470 | if (!status) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2471 | kgsl_sharedmem_readl(&device->memstore, &enableflag, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2472 | KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2473 | mb(); |
| 2474 | |
| 2475 | if (enableflag) { |
| 2476 | kgsl_sharedmem_readl(&device->memstore, &ref_ts, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2477 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2478 | ref_wait_ts)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2479 | mb(); |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2480 | if (timestamp_cmp(ref_ts, timestamp) >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2481 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2482 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2483 | ref_wait_ts), timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2484 | wmb(); |
| 2485 | } |
| 2486 | } else { |
| 2487 | unsigned int cmds[2]; |
| 2488 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2489 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2490 | ref_wait_ts), timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2491 | enableflag = 1; |
| 2492 | kgsl_sharedmem_writel(&device->memstore, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2493 | KGSL_MEMSTORE_OFFSET(context_id, |
| 2494 | ts_cmp_enable), enableflag); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2495 | wmb(); |
| 2496 | /* submit a dummy packet so that even if all |
| 2497 | * commands upto timestamp get executed we will still |
| 2498 | * get an interrupt */ |
Jordan Crouse | 084427d | 2011-07-28 08:37:58 -0600 | [diff] [blame] | 2499 | cmds[0] = cp_type3_packet(CP_NOP, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2500 | cmds[1] = 0; |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 2501 | |
Vladimir Razgulin | 3834530 | 2013-01-22 18:41:59 -0700 | [diff] [blame] | 2502 | if (context && device->state != KGSL_STATE_SLUMBER) |
Carter Cooper | 7ffaba6 | 2012-05-24 13:59:53 -0600 | [diff] [blame] | 2503 | adreno_ringbuffer_issuecmds_intr(device, |
| 2504 | context, &cmds[0], 2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2505 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2506 | } |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 2507 | unlock: |
| 2508 | mutex_unlock(&device->mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2509 | |
| 2510 | return status; |
| 2511 | } |
| 2512 | |
| 2513 | /* |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 2514 | wait_event_interruptible_timeout checks for the exit condition before |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2515 | placing a process in wait q. For conditional interrupts we expect the |
| 2516 | process to already be in its wait q when its exit condition checking |
| 2517 | function is called. |
| 2518 | */ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 2519 | #define kgsl_wait_event_interruptible_timeout(wq, condition, timeout, io)\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2520 | ({ \ |
| 2521 | long __ret = timeout; \ |
Lucille Sylvester | 02e4629 | 2011-09-21 14:59:17 -0600 | [diff] [blame] | 2522 | if (io) \ |
| 2523 | __wait_io_event_interruptible_timeout(wq, condition, __ret);\ |
| 2524 | else \ |
| 2525 | __wait_event_interruptible_timeout(wq, condition, __ret);\ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2526 | __ret; \ |
| 2527 | }) |
| 2528 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2529 | |
| 2530 | |
| 2531 | unsigned int adreno_hang_detect(struct kgsl_device *device, |
| 2532 | unsigned int *prev_reg_val) |
| 2533 | { |
| 2534 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2535 | unsigned int curr_reg_val[hang_detect_regs_count]; |
| 2536 | unsigned int hang_detected = 1; |
| 2537 | unsigned int i; |
Tarun Karra | 4648db9 | 2013-02-01 17:03:40 -0800 | [diff] [blame] | 2538 | static unsigned long next_hang_detect_time; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2539 | |
| 2540 | if (!adreno_dev->fast_hang_detect) |
| 2541 | return 0; |
| 2542 | |
Jordan Crouse | cca6114 | 2012-11-20 10:54:24 -0700 | [diff] [blame] | 2543 | if (is_adreno_rbbm_status_idle(device)) { |
| 2544 | |
| 2545 | /* |
| 2546 | * On A20X if the RPTR != WPTR and the device is idle, then |
| 2547 | * the last write to WPTR probably failed to latch so write it |
| 2548 | * again |
| 2549 | */ |
| 2550 | |
| 2551 | if (adreno_is_a2xx(adreno_dev)) { |
| 2552 | unsigned int rptr; |
| 2553 | adreno_regread(device, REG_CP_RB_RPTR, &rptr); |
| 2554 | if (rptr != adreno_dev->ringbuffer.wptr) |
| 2555 | adreno_regwrite(device, REG_CP_RB_WPTR, |
| 2556 | adreno_dev->ringbuffer.wptr); |
| 2557 | } |
| 2558 | |
Rajeev Kulkarni | 12d7dcd | 2012-11-22 00:27:35 -0800 | [diff] [blame] | 2559 | return 0; |
Jordan Crouse | cca6114 | 2012-11-20 10:54:24 -0700 | [diff] [blame] | 2560 | } |
Rajeev Kulkarni | 12d7dcd | 2012-11-22 00:27:35 -0800 | [diff] [blame] | 2561 | |
Tarun Karra | 4648db9 | 2013-02-01 17:03:40 -0800 | [diff] [blame] | 2562 | /* |
| 2563 | * Time interval between hang detection should be KGSL_TIMEOUT_PART |
| 2564 | * or more, if next hang detection is requested < KGSL_TIMEOUT_PART |
| 2565 | * from the last time do nothing. |
| 2566 | */ |
| 2567 | if ((next_hang_detect_time) && |
| 2568 | (time_before(jiffies, next_hang_detect_time))) |
| 2569 | return 0; |
| 2570 | else |
| 2571 | next_hang_detect_time = (jiffies + |
| 2572 | msecs_to_jiffies(KGSL_TIMEOUT_PART-1)); |
| 2573 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2574 | for (i = 0; i < hang_detect_regs_count; i++) { |
Jordan Crouse | b5c8048 | 2012-10-03 09:38:41 -0600 | [diff] [blame] | 2575 | |
| 2576 | if (hang_detect_regs[i] == 0) |
| 2577 | continue; |
| 2578 | |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2579 | adreno_regread(device, hang_detect_regs[i], |
| 2580 | &curr_reg_val[i]); |
| 2581 | if (curr_reg_val[i] != prev_reg_val[i]) { |
| 2582 | prev_reg_val[i] = curr_reg_val[i]; |
| 2583 | hang_detected = 0; |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | return hang_detected; |
| 2588 | } |
| 2589 | |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2590 | /** |
| 2591 | * adreno_handle_hang - Process a hang detected in adreno_waittimestamp |
| 2592 | * @device - pointer to a KGSL device structure |
| 2593 | * @context - pointer to the active KGSL context |
| 2594 | * @timestamp - the timestamp that the process was waiting for |
| 2595 | * |
| 2596 | * Process a possible GPU hang and try to recover from it cleanly |
| 2597 | */ |
| 2598 | static int adreno_handle_hang(struct kgsl_device *device, |
| 2599 | struct kgsl_context *context, unsigned int timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2600 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2601 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2602 | unsigned int context_id = _get_context_id(context); |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2603 | unsigned int ts_issued; |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 2604 | unsigned int rptr; |
Tarun Karra | 3335f14 | 2012-06-19 14:11:48 -0700 | [diff] [blame] | 2605 | |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2606 | /* Do one last check to see if we somehow made it through */ |
| 2607 | if (kgsl_check_timestamp(device, context, timestamp)) |
| 2608 | return 0; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2609 | |
| 2610 | ts_issued = adreno_dev->ringbuffer.timestamp[context_id]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2611 | |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 2612 | adreno_regread(device, REG_CP_RB_RPTR, &rptr); |
| 2613 | mb(); |
| 2614 | |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 2615 | KGSL_DRV_ERR(device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2616 | "Device hang detected while waiting for timestamp: " |
| 2617 | "<%d:0x%x>, last submitted timestamp: <%d:0x%x>, " |
Shubhraprakash Das | 460cc76 | 2013-01-16 16:57:46 -0800 | [diff] [blame] | 2618 | "retired timestamp: <%d:0x%x>, wptr: 0x%x, rptr: 0x%x\n", |
| 2619 | context_id, timestamp, context_id, ts_issued, context_id, |
| 2620 | kgsl_readtimestamp(device, context, |
| 2621 | KGSL_TIMESTAMP_RETIRED), |
| 2622 | adreno_dev->ringbuffer.wptr, rptr); |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2623 | |
| 2624 | /* Return 0 after a successful recovery */ |
| 2625 | if (!adreno_dump_and_recover(device)) |
| 2626 | return 0; |
| 2627 | |
| 2628 | return -ETIMEDOUT; |
| 2629 | } |
| 2630 | |
| 2631 | static int _check_pending_timestamp(struct kgsl_device *device, |
| 2632 | struct kgsl_context *context, unsigned int timestamp) |
| 2633 | { |
| 2634 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2635 | unsigned int context_id = _get_context_id(context); |
| 2636 | unsigned int ts_issued; |
| 2637 | |
| 2638 | if (context_id == KGSL_CONTEXT_INVALID) |
| 2639 | return -EINVAL; |
| 2640 | |
| 2641 | ts_issued = adreno_dev->ringbuffer.timestamp[context_id]; |
| 2642 | |
| 2643 | if (timestamp_cmp(timestamp, ts_issued) <= 0) |
| 2644 | return 0; |
| 2645 | |
| 2646 | if (context && !context->wait_on_invalid_ts) { |
| 2647 | KGSL_DRV_ERR(device, "Cannot wait for invalid ts <%d:0x%x>, last issued ts <%d:0x%x>\n", |
| 2648 | context_id, timestamp, context_id, ts_issued); |
| 2649 | |
| 2650 | /* Only print this message once */ |
| 2651 | context->wait_on_invalid_ts = true; |
Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 2652 | } |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2653 | |
| 2654 | return -EINVAL; |
| 2655 | } |
| 2656 | |
| 2657 | /** |
| 2658 | * adreno_waittimestamp - sleep while waiting for the specified timestamp |
| 2659 | * @device - pointer to a KGSL device structure |
| 2660 | * @context - pointer to the active kgsl context |
| 2661 | * @timestamp - GPU timestamp to wait for |
| 2662 | * @msecs - amount of time to wait (in milliseconds) |
| 2663 | * |
| 2664 | * Wait 'msecs' milliseconds for the specified timestamp to expire. Wake up |
| 2665 | * every KGSL_TIMEOUT_PART milliseconds to check for a device hang and process |
| 2666 | * one if it happened. Otherwise, spend most of our time in an interruptible |
| 2667 | * wait for the timestamp interrupt to be processed. This function must be |
| 2668 | * called with the mutex already held. |
| 2669 | */ |
| 2670 | static int adreno_waittimestamp(struct kgsl_device *device, |
| 2671 | struct kgsl_context *context, |
| 2672 | unsigned int timestamp, |
| 2673 | unsigned int msecs) |
| 2674 | { |
| 2675 | static unsigned int io_cnt; |
| 2676 | struct adreno_context *adreno_ctx = context ? context->devctxt : NULL; |
| 2677 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 2678 | unsigned int context_id = _get_context_id(context); |
| 2679 | unsigned int prev_reg_val[hang_detect_regs_count]; |
| 2680 | unsigned int time_elapsed = 0; |
| 2681 | unsigned int wait; |
| 2682 | int ts_compare = 1; |
| 2683 | int io, ret = -ETIMEDOUT; |
| 2684 | |
| 2685 | /* Get out early if the context has already been destroyed */ |
| 2686 | |
| 2687 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 2688 | KGSL_DRV_WARN(device, "context was detached"); |
| 2689 | return -EINVAL; |
| 2690 | } |
| 2691 | |
| 2692 | /* |
| 2693 | * Check to see if the requested timestamp is "newer" then the last |
| 2694 | * timestamp issued. If it is complain once and return error. Only |
| 2695 | * print the message once per context so that badly behaving |
| 2696 | * applications don't spam the logs |
| 2697 | */ |
| 2698 | |
| 2699 | if (adreno_ctx && !(adreno_ctx->flags & CTXT_FLAGS_USER_GENERATED_TS)) { |
| 2700 | if (_check_pending_timestamp(device, context, timestamp)) |
| 2701 | return -EINVAL; |
| 2702 | |
| 2703 | /* Reset the invalid timestamp flag on a valid wait */ |
| 2704 | context->wait_on_invalid_ts = false; |
| 2705 | } |
| 2706 | |
| 2707 | |
| 2708 | /* Clear the registers used for hang detection */ |
| 2709 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
| 2710 | |
| 2711 | /* |
| 2712 | * On the first time through the loop only wait 100ms. |
| 2713 | * this gives enough time for the engine to start moving and oddly |
| 2714 | * provides better hang detection results than just going the full |
| 2715 | * KGSL_TIMEOUT_PART right off the bat. The exception to this rule |
| 2716 | * is if msecs happens to be < 100ms then just use the full timeout |
| 2717 | */ |
| 2718 | |
| 2719 | wait = 100; |
| 2720 | |
| 2721 | do { |
| 2722 | long status; |
| 2723 | |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2724 | /* |
| 2725 | * if the timestamp happens while we're not |
| 2726 | * waiting, there's a chance that an interrupt |
| 2727 | * will not be generated and thus the timestamp |
| 2728 | * work needs to be queued. |
| 2729 | */ |
| 2730 | |
| 2731 | if (kgsl_check_timestamp(device, context, timestamp)) { |
| 2732 | queue_work(device->work_queue, &device->ts_expired_ws); |
| 2733 | ret = 0; |
| 2734 | break; |
| 2735 | } |
| 2736 | |
| 2737 | /* Check to see if the GPU is hung */ |
| 2738 | if (adreno_hang_detect(device, prev_reg_val)) { |
| 2739 | ret = adreno_handle_hang(device, context, timestamp); |
| 2740 | break; |
| 2741 | } |
| 2742 | |
| 2743 | /* |
| 2744 | * For proper power accounting sometimes we need to call |
| 2745 | * io_wait_interruptible_timeout and sometimes we need to call |
| 2746 | * plain old wait_interruptible_timeout. We call the regular |
| 2747 | * timeout N times out of 100, where N is a number specified by |
| 2748 | * the current power level |
| 2749 | */ |
| 2750 | |
| 2751 | io_cnt = (io_cnt + 1) % 100; |
| 2752 | io = (io_cnt < pwr->pwrlevels[pwr->active_pwrlevel].io_fraction) |
| 2753 | ? 0 : 1; |
| 2754 | |
| 2755 | mutex_unlock(&device->mutex); |
| 2756 | |
| 2757 | /* Wait for a timestamp event */ |
| 2758 | status = kgsl_wait_event_interruptible_timeout( |
| 2759 | device->wait_queue, |
| 2760 | kgsl_check_interrupt_timestamp(device, context, |
| 2761 | timestamp), msecs_to_jiffies(wait), io); |
| 2762 | |
| 2763 | mutex_lock(&device->mutex); |
| 2764 | |
| 2765 | /* |
| 2766 | * If status is non zero then either the condition was satisfied |
| 2767 | * or there was an error. In either event, this is the end of |
| 2768 | * the line for us |
| 2769 | */ |
| 2770 | |
| 2771 | if (status != 0) { |
| 2772 | ret = (status > 0) ? 0 : (int) status; |
| 2773 | break; |
| 2774 | } |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2775 | time_elapsed += wait; |
| 2776 | |
| 2777 | /* If user specified timestamps are being used, wait at least |
| 2778 | * KGSL_SYNCOBJ_SERVER_TIMEOUT msecs for the user driver to |
| 2779 | * issue a IB for a timestamp before checking to see if the |
| 2780 | * current timestamp we are waiting for is valid or not |
| 2781 | */ |
| 2782 | |
| 2783 | if (ts_compare && (adreno_ctx && |
| 2784 | (adreno_ctx->flags & CTXT_FLAGS_USER_GENERATED_TS))) { |
| 2785 | if (time_elapsed > KGSL_SYNCOBJ_SERVER_TIMEOUT) { |
| 2786 | ret = _check_pending_timestamp(device, context, |
| 2787 | timestamp); |
| 2788 | if (ret) |
| 2789 | break; |
| 2790 | |
| 2791 | /* Don't do this check again */ |
| 2792 | ts_compare = 0; |
| 2793 | |
| 2794 | /* |
| 2795 | * Reset the invalid timestamp flag on a valid |
| 2796 | * wait |
| 2797 | */ |
| 2798 | context->wait_on_invalid_ts = false; |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | /* |
Harsh Vardhan Dwivedi | 5e57bd3 | 2013-01-27 22:54:23 -0700 | [diff] [blame] | 2803 | * We want to wait the floor of KGSL_TIMEOUT_PART |
| 2804 | * and (msecs - time_elapsed). |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2805 | */ |
Harsh Vardhan Dwivedi | 5e57bd3 | 2013-01-27 22:54:23 -0700 | [diff] [blame] | 2806 | |
| 2807 | if (KGSL_TIMEOUT_PART < (msecs - time_elapsed)) |
| 2808 | wait = KGSL_TIMEOUT_PART; |
| 2809 | else |
| 2810 | wait = (msecs - time_elapsed); |
Jordan Crouse | 92446a6 | 2012-11-15 11:00:06 -0700 | [diff] [blame] | 2811 | |
| 2812 | } while (!msecs || time_elapsed < msecs); |
| 2813 | |
| 2814 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | static unsigned int adreno_readtimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2818 | struct kgsl_context *context, enum kgsl_timestamp_type type) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2819 | { |
| 2820 | unsigned int timestamp = 0; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2821 | unsigned int context_id = _get_context_id(context); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2822 | |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 2823 | /* |
| 2824 | * If the context ID is invalid, we are in a race with |
| 2825 | * the context being destroyed by userspace so bail. |
| 2826 | */ |
| 2827 | if (context_id == KGSL_CONTEXT_INVALID) { |
| 2828 | KGSL_DRV_WARN(device, "context was detached"); |
| 2829 | return timestamp; |
| 2830 | } |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 2831 | switch (type) { |
| 2832 | case KGSL_TIMESTAMP_QUEUED: { |
| 2833 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2834 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 2835 | |
| 2836 | timestamp = rb->timestamp[context_id]; |
| 2837 | break; |
| 2838 | } |
| 2839 | case KGSL_TIMESTAMP_CONSUMED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2840 | adreno_regread(device, REG_CP_TIMESTAMP, ×tamp); |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 2841 | break; |
| 2842 | case KGSL_TIMESTAMP_RETIRED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2843 | kgsl_sharedmem_readl(&device->memstore, ×tamp, |
Jordan Crouse | c659f38 | 2012-04-16 11:10:41 -0600 | [diff] [blame] | 2844 | KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp)); |
| 2845 | break; |
| 2846 | } |
| 2847 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2848 | rmb(); |
| 2849 | |
| 2850 | return timestamp; |
| 2851 | } |
| 2852 | |
| 2853 | static long adreno_ioctl(struct kgsl_device_private *dev_priv, |
| 2854 | unsigned int cmd, void *data) |
| 2855 | { |
| 2856 | int result = 0; |
| 2857 | struct kgsl_drawctxt_set_bin_base_offset *binbase; |
| 2858 | struct kgsl_context *context; |
| 2859 | |
| 2860 | switch (cmd) { |
| 2861 | case IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET: |
| 2862 | binbase = data; |
| 2863 | |
| 2864 | context = kgsl_find_context(dev_priv, binbase->drawctxt_id); |
| 2865 | if (context) { |
| 2866 | adreno_drawctxt_set_bin_base_offset( |
| 2867 | dev_priv->device, context, binbase->offset); |
| 2868 | } else { |
| 2869 | result = -EINVAL; |
| 2870 | KGSL_DRV_ERR(dev_priv->device, |
| 2871 | "invalid drawctxt drawctxt_id %d " |
| 2872 | "device_id=%d\n", |
| 2873 | binbase->drawctxt_id, dev_priv->device->id); |
| 2874 | } |
| 2875 | break; |
| 2876 | |
| 2877 | default: |
| 2878 | KGSL_DRV_INFO(dev_priv->device, |
| 2879 | "invalid ioctl code %08x\n", cmd); |
Jeremy Gebben | c15b461 | 2012-01-09 09:44:11 -0700 | [diff] [blame] | 2880 | result = -ENOIOCTLCMD; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2881 | break; |
| 2882 | } |
| 2883 | return result; |
| 2884 | |
| 2885 | } |
| 2886 | |
| 2887 | static inline s64 adreno_ticks_to_us(u32 ticks, u32 gpu_freq) |
| 2888 | { |
| 2889 | gpu_freq /= 1000000; |
| 2890 | return ticks / gpu_freq; |
| 2891 | } |
| 2892 | |
| 2893 | static void adreno_power_stats(struct kgsl_device *device, |
| 2894 | struct kgsl_power_stats *stats) |
| 2895 | { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 2896 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2897 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 2898 | unsigned int cycles; |
| 2899 | |
| 2900 | /* Get the busy cycles counted since the counter was last reset */ |
| 2901 | /* Calling this function also resets and restarts the counter */ |
| 2902 | |
| 2903 | cycles = adreno_dev->gpudev->busy_cycles(adreno_dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2904 | |
| 2905 | /* In order to calculate idle you have to have run the algorithm * |
| 2906 | * at least once to get a start time. */ |
| 2907 | if (pwr->time != 0) { |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 2908 | s64 tmp = ktime_to_us(ktime_get()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2909 | stats->total_time = tmp - pwr->time; |
| 2910 | pwr->time = tmp; |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 2911 | stats->busy_time = adreno_ticks_to_us(cycles, device->pwrctrl. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2912 | pwrlevels[device->pwrctrl.active_pwrlevel]. |
| 2913 | gpu_freq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2914 | } else { |
| 2915 | stats->total_time = 0; |
| 2916 | stats->busy_time = 0; |
| 2917 | pwr->time = ktime_to_us(ktime_get()); |
| 2918 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | void adreno_irqctrl(struct kgsl_device *device, int state) |
| 2922 | { |
Jordan Crouse | a78c917 | 2011-07-11 13:14:09 -0600 | [diff] [blame] | 2923 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2924 | adreno_dev->gpudev->irq_control(adreno_dev, state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 2927 | static unsigned int adreno_gpuid(struct kgsl_device *device, |
| 2928 | unsigned int *chipid) |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 2929 | { |
| 2930 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 2931 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 2932 | /* Some applications need to know the chip ID too, so pass |
| 2933 | * that as a parameter */ |
| 2934 | |
| 2935 | if (chipid != NULL) |
| 2936 | *chipid = adreno_dev->chip_id; |
| 2937 | |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 2938 | /* Standard KGSL gpuid format: |
| 2939 | * top word is 0x0002 for 2D or 0x0003 for 3D |
| 2940 | * Bottom word is core specific identifer |
| 2941 | */ |
| 2942 | |
| 2943 | return (0x0003 << 16) | ((int) adreno_dev->gpurev); |
| 2944 | } |
| 2945 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2946 | static const struct kgsl_functable adreno_functable = { |
| 2947 | /* Mandatory functions */ |
| 2948 | .regread = adreno_regread, |
| 2949 | .regwrite = adreno_regwrite, |
| 2950 | .idle = adreno_idle, |
| 2951 | .isidle = adreno_isidle, |
| 2952 | .suspend_context = adreno_suspend_context, |
| 2953 | .start = adreno_start, |
| 2954 | .stop = adreno_stop, |
| 2955 | .getproperty = adreno_getproperty, |
| 2956 | .waittimestamp = adreno_waittimestamp, |
| 2957 | .readtimestamp = adreno_readtimestamp, |
| 2958 | .issueibcmds = adreno_ringbuffer_issueibcmds, |
| 2959 | .ioctl = adreno_ioctl, |
| 2960 | .setup_pt = adreno_setup_pt, |
| 2961 | .cleanup_pt = adreno_cleanup_pt, |
| 2962 | .power_stats = adreno_power_stats, |
| 2963 | .irqctrl = adreno_irqctrl, |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 2964 | .gpuid = adreno_gpuid, |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 2965 | .snapshot = adreno_snapshot, |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 2966 | .irq_handler = adreno_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2967 | /* Optional functions */ |
| 2968 | .setstate = adreno_setstate, |
| 2969 | .drawctxt_create = adreno_drawctxt_create, |
| 2970 | .drawctxt_destroy = adreno_drawctxt_destroy, |
Jordan Crouse | f7370f8 | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 2971 | .setproperty = adreno_setproperty, |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 2972 | .postmortem_dump = adreno_dump, |
Jordan Crouse | 313faf6 | 2012-11-20 15:12:28 -0700 | [diff] [blame] | 2973 | .next_event = adreno_next_event, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2974 | }; |
| 2975 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2976 | static struct platform_driver adreno_platform_driver = { |
| 2977 | .probe = adreno_probe, |
| 2978 | .remove = __devexit_p(adreno_remove), |
| 2979 | .suspend = kgsl_suspend_driver, |
| 2980 | .resume = kgsl_resume_driver, |
| 2981 | .id_table = adreno_id_table, |
| 2982 | .driver = { |
| 2983 | .owner = THIS_MODULE, |
| 2984 | .name = DEVICE_3D_NAME, |
| 2985 | .pm = &kgsl_pm_ops, |
Lokesh Batra | 805e1e1 | 2012-08-03 08:34:06 -0600 | [diff] [blame] | 2986 | .of_match_table = adreno_match_table, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2987 | } |
| 2988 | }; |
| 2989 | |
| 2990 | static int __init kgsl_3d_init(void) |
| 2991 | { |
| 2992 | return platform_driver_register(&adreno_platform_driver); |
| 2993 | } |
| 2994 | |
| 2995 | static void __exit kgsl_3d_exit(void) |
| 2996 | { |
| 2997 | platform_driver_unregister(&adreno_platform_driver); |
| 2998 | } |
| 2999 | |
| 3000 | module_init(kgsl_3d_init); |
| 3001 | module_exit(kgsl_3d_exit); |
| 3002 | |
| 3003 | MODULE_DESCRIPTION("3D Graphics driver"); |
| 3004 | MODULE_VERSION("1.2"); |
| 3005 | MODULE_LICENSE("GPL v2"); |
| 3006 | MODULE_ALIAS("platform:kgsl_3d"); |