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