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