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