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