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