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