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