blob: ad0ec48c620d89dfb1203ece4be0681255d6851b [file] [log] [blame]
Lucille Sylvester51b764d2011-12-15 16:51:52 -07001/* Copyright (c) 2002,2007-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 Mucklef132c6c2012-06-06 18:30:57 -070013#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070014#include <linux/uaccess.h>
15#include <linux/vmalloc.h>
16#include <linux/ioctl.h>
17#include <linux/sched.h>
18
19#include <mach/socinfo.h>
20
21#include "kgsl.h"
22#include "kgsl_pwrscale.h"
23#include "kgsl_cffdump.h"
24#include "kgsl_sharedmem.h"
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -060025#include "kgsl_iommu.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026
27#include "adreno.h"
28#include "adreno_pm4types.h"
29#include "adreno_debugfs.h"
30#include "adreno_postmortem.h"
31
Jeremy Gebbeneebc4612011-08-31 10:15:21 -070032#include "a2xx_reg.h"
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070033#include "a3xx_reg.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034
35#define DRIVER_VERSION_MAJOR 3
36#define DRIVER_VERSION_MINOR 1
37
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038/* Adreno MH arbiter config*/
39#define ADRENO_CFG_MHARB \
40 (0x10 \
41 | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \
42 | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \
43 | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \
44 | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \
45 | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \
46 | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \
47 | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \
48 | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \
49 | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \
50 | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \
51 | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \
52 | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \
53 | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \
54 | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT))
55
56#define ADRENO_MMU_CONFIG \
57 (0x01 \
58 | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \
59 | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \
60 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \
61 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \
62 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \
63 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \
64 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \
65 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \
66 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \
67 | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \
68 | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT))
69
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070static const struct kgsl_functable adreno_functable;
71
72static struct adreno_device device_3d0 = {
73 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -070074 KGSL_DEVICE_COMMON_INIT(device_3d0.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075 .name = DEVICE_3D0_NAME,
76 .id = KGSL_DEVICE_3D0,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -060077 .mh = {
78 .mharb = ADRENO_CFG_MHARB,
79 /* Remove 1k boundary check in z470 to avoid a GPU
80 * hang. Notice that this solution won't work if
81 * both EBI and SMI are used
82 */
83 .mh_intf_cfg1 = 0x00032f07,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 /* turn off memory protection unit by setting
85 acceptable physical address range to include
86 all pages. */
87 .mpu_base = 0x00000000,
88 .mpu_range = 0xFFFFF000,
89 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -060090 .mmu = {
91 .config = ADRENO_MMU_CONFIG,
92 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094 .irq_name = KGSL_3D0_IRQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096 .iomemname = KGSL_3D0_REG_MEMORY,
97 .ftbl = &adreno_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098#ifdef CONFIG_HAS_EARLYSUSPEND
Jordan Crouse9f739212011-07-28 08:37:57 -060099 .display_off = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700100 .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING,
101 .suspend = kgsl_early_suspend_driver,
102 .resume = kgsl_late_resume_driver,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103 },
Jordan Crouse9f739212011-07-28 08:37:57 -0600104#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700105 },
Jordan Crouse7501d452012-04-19 08:58:44 -0600106 .gmem_base = 0,
107 .gmem_size = SZ_256K,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108 .pfp_fw = NULL,
109 .pm4_fw = NULL,
Jordan Crouse95b33272011-11-11 14:50:12 -0700110 .wait_timeout = 10000, /* in milliseconds */
Jeremy Gebbend0ab6ad2012-04-06 11:13:35 -0600111 .ib_check_level = 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700112};
113
Jordan Crouse95b33272011-11-11 14:50:12 -0700114
Jordan Crouse505df9c2011-07-28 08:37:59 -0600115/*
116 * This is the master list of all GPU cores that are supported by this
117 * driver.
118 */
119
120#define ANY_ID (~0)
121
122static const struct {
123 enum adreno_gpurev gpurev;
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600124 unsigned int core, major, minor, patchid;
Jordan Crouse505df9c2011-07-28 08:37:59 -0600125 const char *pm4fw;
126 const char *pfpfw;
127 struct adreno_gpudev *gpudev;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700128 unsigned int istore_size;
129 unsigned int pix_shader_start;
Jordan Crousec6b3a992012-02-04 10:23:51 -0700130 unsigned int instruction_size; /* Size of an instruction in dwords */
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530131 unsigned int gmem_size; /* size of gmem for gpu*/
Jordan Crouse505df9c2011-07-28 08:37:59 -0600132} adreno_gpulist[] = {
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600133 { ADRENO_REV_A200, 0, 2, ANY_ID, ANY_ID,
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700134 "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530135 512, 384, 3, SZ_256K },
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530136 { ADRENO_REV_A203, 0, 1, 1, ANY_ID,
137 "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530138 512, 384, 3, SZ_256K },
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600139 { ADRENO_REV_A205, 0, 1, 0, ANY_ID,
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700140 "yamato_pm4.fw", "yamato_pfp.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530141 512, 384, 3, SZ_256K },
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600142 { ADRENO_REV_A220, 2, 1, ANY_ID, ANY_ID,
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700143 "leia_pm4_470.fw", "leia_pfp_470.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530144 512, 384, 3, SZ_512K },
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600145 /*
146 * patchlevel 5 (8960v2) needs special pm4 firmware to work around
147 * a hardware problem.
148 */
149 { ADRENO_REV_A225, 2, 2, 0, 5,
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700150 "a225p5_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530151 1536, 768, 3, SZ_512K },
Carter Cooperf27ec722011-11-17 15:20:38 -0700152 { ADRENO_REV_A225, 2, 2, 0, 6,
153 "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530154 1536, 768, 3, SZ_512K },
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600155 { ADRENO_REV_A225, 2, 2, ANY_ID, ANY_ID,
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700156 "a225_pm4.fw", "a225_pfp.fw", &adreno_a2xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530157 1536, 768, 3, SZ_512K },
158 /* A3XX doesn't use the pix_shader_start */
Sudhakara Rao Tentue13766d2012-06-12 06:00:26 +0530159 { ADRENO_REV_A305, 3, 0, 5, ANY_ID,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530160 "a300_pm4.fw", "a300_pfp.fw", &adreno_a3xx_gpudev,
161 512, 0, 2, SZ_256K },
Jordan Crousec6b3a992012-02-04 10:23:51 -0700162 /* A3XX doesn't use the pix_shader_start */
Jordan Croused2b30d22012-05-21 08:41:51 -0600163 { ADRENO_REV_A320, 3, 2, 0, ANY_ID,
Jordan Crousec6b3a992012-02-04 10:23:51 -0700164 "a300_pm4.fw", "a300_pfp.fw", &adreno_a3xx_gpudev,
Sudhakara Rao Tentu79853832012-03-06 15:52:38 +0530165 512, 0, 2, SZ_512K },
Jordan Crousec6b3a992012-02-04 10:23:51 -0700166
Jordan Crouse505df9c2011-07-28 08:37:59 -0600167};
168
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600169static irqreturn_t adreno_irq_handler(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170{
Jordan Crousea78c9172011-07-11 13:14:09 -0600171 irqreturn_t result;
Jordan Crousea78c9172011-07-11 13:14:09 -0600172 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173
Jordan Crousea78c9172011-07-11 13:14:09 -0600174 result = adreno_dev->gpudev->irq_handler(adreno_dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175
176 if (device->requested_state == KGSL_STATE_NONE) {
177 if (device->pwrctrl.nap_allowed == true) {
Jeremy Gebben388c2972011-12-16 09:05:07 -0700178 kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179 queue_work(device->work_queue, &device->idle_check_ws);
180 } else if (device->pwrscale.policy != NULL) {
181 queue_work(device->work_queue, &device->idle_check_ws);
182 }
183 }
184
185 /* Reset the time-out in our idle timer */
Tarun Karra68755762012-01-12 16:07:09 -0800186 mod_timer_pending(&device->idle_timer,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 jiffies + device->pwrctrl.interval_timeout);
188 return result;
189}
190
Jordan Crouse9f739212011-07-28 08:37:57 -0600191static void adreno_cleanup_pt(struct kgsl_device *device,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192 struct kgsl_pagetable *pagetable)
193{
194 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
195 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
196
197 kgsl_mmu_unmap(pagetable, &rb->buffer_desc);
198
199 kgsl_mmu_unmap(pagetable, &rb->memptrs_desc);
200
201 kgsl_mmu_unmap(pagetable, &device->memstore);
202
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600203 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204}
205
206static int adreno_setup_pt(struct kgsl_device *device,
207 struct kgsl_pagetable *pagetable)
208{
209 int result = 0;
210 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
211 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
212
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 result = kgsl_mmu_map_global(pagetable, &rb->buffer_desc,
214 GSL_PT_PAGE_RV);
215 if (result)
216 goto error;
217
218 result = kgsl_mmu_map_global(pagetable, &rb->memptrs_desc,
219 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
220 if (result)
221 goto unmap_buffer_desc;
222
223 result = kgsl_mmu_map_global(pagetable, &device->memstore,
224 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
225 if (result)
226 goto unmap_memptrs_desc;
227
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600228 result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700229 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
230 if (result)
231 goto unmap_memstore_desc;
232
233 return result;
234
235unmap_memstore_desc:
236 kgsl_mmu_unmap(pagetable, &device->memstore);
237
238unmap_memptrs_desc:
239 kgsl_mmu_unmap(pagetable, &rb->memptrs_desc);
240
241unmap_buffer_desc:
242 kgsl_mmu_unmap(pagetable, &rb->buffer_desc);
243
244error:
245 return result;
246}
247
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600248static void adreno_iommu_setstate(struct kgsl_device *device,
249 uint32_t flags)
250{
251 unsigned int pt_val, reg_pt_val;
252 unsigned int link[200];
253 unsigned int *cmds = &link[0];
254 int sizedwords = 0;
255 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
256 struct kgsl_memdesc **reg_map_desc;
Pu Chened8cbb52012-06-04 18:18:48 -0700257 void *reg_map_array = NULL;
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600258 int num_iommu_units, i;
259
260 if (!adreno_dev->drawctxt_active)
261 return kgsl_mmu_device_setstate(&device->mmu, flags);
262 num_iommu_units = kgsl_mmu_get_reg_map_desc(&device->mmu,
263 &reg_map_array);
264 reg_map_desc = reg_map_array;
265
266 if (kgsl_mmu_enable_clk(&device->mmu,
267 KGSL_IOMMU_CONTEXT_USER))
268 goto done;
269
Shubhraprakash Das19ca4a62012-05-18 12:11:20 -0600270 if (cpu_is_msm8960())
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600271 cmds += adreno_add_change_mh_phys_limit_cmds(cmds, 0xFFFFF000,
272 device->mmu.setstate_memory.gpuaddr +
273 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
274 else
275 cmds += adreno_add_bank_change_cmds(cmds,
276 KGSL_IOMMU_CONTEXT_USER,
277 device->mmu.setstate_memory.gpuaddr +
278 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
279
280 if (flags & KGSL_MMUFLAGS_PTUPDATE) {
281 pt_val = kgsl_mmu_pt_get_base_addr(device->mmu.hwpagetable);
282 /*
283 * We need to perfrom the following operations for all
284 * IOMMU units
285 */
286 for (i = 0; i < num_iommu_units; i++) {
287 reg_pt_val = (pt_val &
288 (KGSL_IOMMU_TTBR0_PA_MASK <<
289 KGSL_IOMMU_TTBR0_PA_SHIFT)) +
290 kgsl_mmu_get_pt_lsb(&device->mmu, i,
291 KGSL_IOMMU_CONTEXT_USER);
292 /*
293 * Set address of the new pagetable by writng to IOMMU
294 * TTBR0 register
295 */
296 *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2);
297 *cmds++ = reg_map_desc[i]->gpuaddr +
298 (KGSL_IOMMU_CONTEXT_USER <<
299 KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_TTBR0;
300 *cmds++ = reg_pt_val;
301 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
302 *cmds++ = 0x00000000;
303
304 /*
305 * Read back the ttbr0 register as a barrier to ensure
306 * above writes have completed
307 */
308 cmds += adreno_add_read_cmds(device, cmds,
309 reg_map_desc[i]->gpuaddr +
310 (KGSL_IOMMU_CONTEXT_USER <<
311 KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_TTBR0,
312 reg_pt_val,
313 device->mmu.setstate_memory.gpuaddr +
314 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
315
316 /* set the asid */
317 *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2);
318 *cmds++ = reg_map_desc[i]->gpuaddr +
319 (KGSL_IOMMU_CONTEXT_USER <<
320 KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_CONTEXTIDR;
321 *cmds++ = kgsl_mmu_get_hwpagetable_asid(&device->mmu);
322 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
323 *cmds++ = 0x00000000;
324
325 /* Read back asid to ensure above write completes */
326 cmds += adreno_add_read_cmds(device, cmds,
327 reg_map_desc[i]->gpuaddr +
328 (KGSL_IOMMU_CONTEXT_USER <<
329 KGSL_IOMMU_CTX_SHIFT) + KGSL_IOMMU_CONTEXTIDR,
330 kgsl_mmu_get_hwpagetable_asid(&device->mmu),
331 device->mmu.setstate_memory.gpuaddr +
332 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
333 }
334 /* invalidate all base pointers */
335 *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1);
336 *cmds++ = 0x7fff;
337
338 if (flags & KGSL_MMUFLAGS_TLBFLUSH)
339 cmds += __adreno_add_idle_indirect_cmds(cmds,
340 device->mmu.setstate_memory.gpuaddr +
341 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
342 }
343 if (flags & KGSL_MMUFLAGS_TLBFLUSH) {
344 /*
345 * tlb flush based on asid, no need to flush entire tlb
346 */
347 for (i = 0; i < num_iommu_units; i++) {
348 *cmds++ = cp_type3_packet(CP_MEM_WRITE, 2);
349 *cmds++ = (reg_map_desc[i]->gpuaddr +
350 (KGSL_IOMMU_CONTEXT_USER <<
351 KGSL_IOMMU_CTX_SHIFT) +
352 KGSL_IOMMU_CTX_TLBIASID);
353 *cmds++ = kgsl_mmu_get_hwpagetable_asid(&device->mmu);
354 cmds += adreno_add_read_cmds(device, cmds,
355 reg_map_desc[i]->gpuaddr +
356 (KGSL_IOMMU_CONTEXT_USER <<
357 KGSL_IOMMU_CTX_SHIFT) +
358 KGSL_IOMMU_CONTEXTIDR,
359 kgsl_mmu_get_hwpagetable_asid(&device->mmu),
360 device->mmu.setstate_memory.gpuaddr +
361 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
362 }
363 }
364
Shubhraprakash Das19ca4a62012-05-18 12:11:20 -0600365 if (cpu_is_msm8960())
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600366 cmds += adreno_add_change_mh_phys_limit_cmds(cmds,
367 reg_map_desc[num_iommu_units - 1]->gpuaddr - PAGE_SIZE,
368 device->mmu.setstate_memory.gpuaddr +
369 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
370 else
371 cmds += adreno_add_bank_change_cmds(cmds,
372 KGSL_IOMMU_CONTEXT_PRIV,
373 device->mmu.setstate_memory.gpuaddr +
374 KGSL_IOMMU_SETSTATE_NOP_OFFSET);
375
376 sizedwords += (cmds - &link[0]);
Shubhraprakash Dascb068072012-06-07 17:52:41 -0600377 if (sizedwords) {
378 unsigned int ts;
379 /*
380 * add an interrupt at the end of commands so that the smmu
381 * disable clock off function will get called
382 */
383 *cmds++ = cp_type3_packet(CP_INTERRUPT, 1);
384 *cmds++ = CP_INT_CNTL__RB_INT_MASK;
385 sizedwords += 2;
386 ts = adreno_ringbuffer_issuecmds(device, KGSL_CMD_FLAGS_PMODE,
387 &link[0], sizedwords);
388 kgsl_mmu_disable_clk_on_ts(&device->mmu, ts, true);
389 }
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600390done:
391 if (num_iommu_units)
392 kfree(reg_map_array);
393}
394
395static void adreno_gpummu_setstate(struct kgsl_device *device,
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600396 uint32_t flags)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700397{
398 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
399 unsigned int link[32];
400 unsigned int *cmds = &link[0];
401 int sizedwords = 0;
402 unsigned int mh_mmu_invalidate = 0x00000003; /*invalidate all and tc */
403
Jeremy Gebbena3d07a42011-10-17 12:08:16 -0600404 /*
Rajesh Kemisetti22a06d12012-06-29 20:21:31 +0530405 * Fix target freeze issue by adding TLB flush for each submit
406 * on A20X based targets.
407 */
408 if (adreno_is_a20x(adreno_dev))
409 flags |= KGSL_MMUFLAGS_TLBFLUSH;
410 /*
Jeremy Gebbena3d07a42011-10-17 12:08:16 -0600411 * If possible, then set the state via the command stream to avoid
412 * a CPU idle. Otherwise, use the default setstate which uses register
413 * writes For CFF dump we must idle and use the registers so that it is
414 * easier to filter out the mmu accesses from the dump
415 */
416 if (!kgsl_cff_dump_enable && adreno_dev->drawctxt_active) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700417 if (flags & KGSL_MMUFLAGS_PTUPDATE) {
418 /* wait for graphics pipe to be idle */
Jordan Crouse084427d2011-07-28 08:37:58 -0600419 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700420 *cmds++ = 0x00000000;
421
422 /* set page table base */
Jordan Crouse084427d2011-07-28 08:37:58 -0600423 *cmds++ = cp_type0_packet(MH_MMU_PT_BASE, 1);
Shubhraprakash Das5a610b52012-05-09 17:31:54 -0600424 *cmds++ = kgsl_mmu_pt_get_base_addr(
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600425 device->mmu.hwpagetable);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 sizedwords += 4;
427 }
428
429 if (flags & KGSL_MMUFLAGS_TLBFLUSH) {
430 if (!(flags & KGSL_MMUFLAGS_PTUPDATE)) {
Jordan Crouse084427d2011-07-28 08:37:58 -0600431 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700432 1);
433 *cmds++ = 0x00000000;
434 sizedwords += 2;
435 }
Jordan Crouse084427d2011-07-28 08:37:58 -0600436 *cmds++ = cp_type0_packet(MH_MMU_INVALIDATE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437 *cmds++ = mh_mmu_invalidate;
438 sizedwords += 2;
439 }
440
441 if (flags & KGSL_MMUFLAGS_PTUPDATE &&
Jeremy Gebben5bb7ece2011-08-02 11:04:48 -0600442 adreno_is_a20x(adreno_dev)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700443 /* HW workaround: to resolve MMU page fault interrupts
444 * caused by the VGT.It prevents the CP PFP from filling
445 * the VGT DMA request fifo too early,thereby ensuring
446 * that the VGT will not fetch vertex/bin data until
447 * after the page table base register has been updated.
448 *
449 * Two null DRAW_INDX_BIN packets are inserted right
450 * after the page table base update, followed by a
451 * wait for idle. The null packets will fill up the
452 * VGT DMA request fifo and prevent any further
453 * vertex/bin updates from occurring until the wait
454 * has finished. */
Jordan Crouse084427d2011-07-28 08:37:58 -0600455 *cmds++ = cp_type3_packet(CP_SET_CONSTANT, 2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456 *cmds++ = (0x4 << 16) |
457 (REG_PA_SU_SC_MODE_CNTL - 0x2000);
458 *cmds++ = 0; /* disable faceness generation */
Jordan Crouse084427d2011-07-28 08:37:58 -0600459 *cmds++ = cp_type3_packet(CP_SET_BIN_BASE_OFFSET, 1);
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600460 *cmds++ = device->mmu.setstate_memory.gpuaddr;
Jordan Crouse084427d2011-07-28 08:37:58 -0600461 *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700462 *cmds++ = 0; /* viz query info */
463 *cmds++ = 0x0003C004; /* draw indicator */
464 *cmds++ = 0; /* bin base */
465 *cmds++ = 3; /* bin size */
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600466 *cmds++ =
467 device->mmu.setstate_memory.gpuaddr; /* dma base */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700468 *cmds++ = 6; /* dma size */
Jordan Crouse084427d2011-07-28 08:37:58 -0600469 *cmds++ = cp_type3_packet(CP_DRAW_INDX_BIN, 6);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700470 *cmds++ = 0; /* viz query info */
471 *cmds++ = 0x0003C004; /* draw indicator */
472 *cmds++ = 0; /* bin base */
473 *cmds++ = 3; /* bin size */
474 /* dma base */
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600475 *cmds++ = device->mmu.setstate_memory.gpuaddr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700476 *cmds++ = 6; /* dma size */
Jordan Crouse084427d2011-07-28 08:37:58 -0600477 *cmds++ = cp_type3_packet(CP_WAIT_FOR_IDLE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478 *cmds++ = 0x00000000;
479 sizedwords += 21;
480 }
481
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600482
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483 if (flags & (KGSL_MMUFLAGS_PTUPDATE | KGSL_MMUFLAGS_TLBFLUSH)) {
Jordan Crouse084427d2011-07-28 08:37:58 -0600484 *cmds++ = cp_type3_packet(CP_INVALIDATE_STATE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485 *cmds++ = 0x7fff; /* invalidate all base pointers */
486 sizedwords += 2;
487 }
488
489 adreno_ringbuffer_issuecmds(device, KGSL_CMD_FLAGS_PMODE,
490 &link[0], sizedwords);
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600491 } else {
Shubhraprakash Das79447952012-04-26 18:12:23 -0600492 kgsl_mmu_device_setstate(&device->mmu, flags);
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600493 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700494}
495
Shubhraprakash Dasc6e21012012-05-11 17:24:51 -0600496static void adreno_setstate(struct kgsl_device *device,
497 uint32_t flags)
498{
499 /* call the mmu specific handler */
500 if (KGSL_MMU_TYPE_GPU == kgsl_mmu_get_mmutype())
501 return adreno_gpummu_setstate(device, flags);
502 else if (KGSL_MMU_TYPE_IOMMU == kgsl_mmu_get_mmutype())
503 return adreno_iommu_setstate(device, flags);
504}
505
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700506static unsigned int
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700507a3xx_getchipid(struct kgsl_device *device)
508{
Steve Mucklef132c6c2012-06-06 18:30:57 -0700509 unsigned int majorid = 0, minorid = 0, patchid = 0;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700510
Jordan Crouse54154c62012-03-27 16:33:26 -0600511 /*
512 * We could detect the chipID from the hardware but it takes multiple
513 * registers to find the right combination. Since we traffic exclusively
514 * in system on chips, we can be (mostly) confident that a SOC version
515 * will match a GPU (at this juncture at least). So do the lazy/quick
516 * thing and set the chip_id based on the SoC
517 */
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700518
Sudhakara Rao Tentue13766d2012-06-12 06:00:26 +0530519 unsigned int version = socinfo_get_version();
520
Jordan Crouse54154c62012-03-27 16:33:26 -0600521 if (cpu_is_apq8064()) {
Jordan Croused2b30d22012-05-21 08:41:51 -0600522
Jordan Crouse54154c62012-03-27 16:33:26 -0600523 /* A320 */
524 majorid = 2;
525 minorid = 0;
Jordan Croused2b30d22012-05-21 08:41:51 -0600526
527 /*
528 * V1.1 has some GPU work arounds that we need to communicate
529 * up to user space via the patchid
530 */
531
532 if ((SOCINFO_VERSION_MAJOR(version) == 1) &&
533 (SOCINFO_VERSION_MINOR(version) == 1))
534 patchid = 1;
535 else
536 patchid = 0;
Jordan Crouse54154c62012-03-27 16:33:26 -0600537 } else if (cpu_is_msm8930()) {
Sudhakara Rao Tentue13766d2012-06-12 06:00:26 +0530538
Jordan Crouse54154c62012-03-27 16:33:26 -0600539 /* A305 */
540 majorid = 0;
541 minorid = 5;
Sudhakara Rao Tentue13766d2012-06-12 06:00:26 +0530542
543 /*
544 * V1.2 has some GPU work arounds that we need to communicate
545 * up to user space via the patchid
546 */
547
548 if ((SOCINFO_VERSION_MAJOR(version) == 1) &&
549 (SOCINFO_VERSION_MINOR(version) == 2))
550 patchid = 2;
551 else
552 patchid = 0;
Jordan Crouse54154c62012-03-27 16:33:26 -0600553 }
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700554
Jordan Crouse54154c62012-03-27 16:33:26 -0600555 return (0x03 << 24) | (majorid << 16) | (minorid << 8) | patchid;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700556}
557
558static unsigned int
559a2xx_getchipid(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700560{
561 unsigned int chipid = 0;
562 unsigned int coreid, majorid, minorid, patchid, revid;
Carter Cooperf27ec722011-11-17 15:20:38 -0700563 uint32_t soc_platform_version = socinfo_get_version();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700564
565 adreno_regread(device, REG_RBBM_PERIPHID1, &coreid);
566 adreno_regread(device, REG_RBBM_PERIPHID2, &majorid);
567 adreno_regread(device, REG_RBBM_PATCH_RELEASE, &revid);
568
569 /*
570 * adreno 22x gpus are indicated by coreid 2,
571 * but REG_RBBM_PERIPHID1 always contains 0 for this field
572 */
Sudhakara Rao Tentudaebac22012-04-02 14:51:29 -0700573 if (cpu_is_msm8960() || cpu_is_msm8x60())
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574 chipid = 2 << 24;
575 else
576 chipid = (coreid & 0xF) << 24;
577
578 chipid |= ((majorid >> 4) & 0xF) << 16;
579
580 minorid = ((revid >> 0) & 0xFF);
581
582 patchid = ((revid >> 16) & 0xFF);
583
584 /* 8x50 returns 0 for patch release, but it should be 1 */
Carter Cooperf27ec722011-11-17 15:20:38 -0700585 /* 8960v3 returns 5 for patch release, but it should be 6 */
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530586 /* 8x25 returns 0 for minor id, but it should be 1 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700587 if (cpu_is_qsd8x50())
588 patchid = 1;
Carter Cooperf27ec722011-11-17 15:20:38 -0700589 else if (cpu_is_msm8960() &&
590 SOCINFO_VERSION_MAJOR(soc_platform_version) == 3)
591 patchid = 6;
Ranjhith Kalisamy938e00f2012-02-17 14:39:47 +0530592 else if (cpu_is_msm8625() && minorid == 0)
593 minorid = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594
595 chipid |= (minorid << 8) | patchid;
596
597 return chipid;
598}
599
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700600static unsigned int
601adreno_getchipid(struct kgsl_device *device)
602{
Sudhakara Rao Tentu8ebb2282012-03-06 14:52:58 +0530603 if (cpu_is_apq8064() || cpu_is_msm8930())
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700604 return a3xx_getchipid(device);
605 else
606 return a2xx_getchipid(device);
607}
608
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700609static inline bool _rev_match(unsigned int id, unsigned int entry)
610{
Jordan Crouse505df9c2011-07-28 08:37:59 -0600611 return (entry == ANY_ID || entry == id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700612}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700613
614static void
615adreno_identify_gpu(struct adreno_device *adreno_dev)
616{
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600617 unsigned int i, core, major, minor, patchid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700618
619 adreno_dev->chip_id = adreno_getchipid(&adreno_dev->dev);
620
621 core = (adreno_dev->chip_id >> 24) & 0xff;
622 major = (adreno_dev->chip_id >> 16) & 0xff;
623 minor = (adreno_dev->chip_id >> 8) & 0xff;
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600624 patchid = (adreno_dev->chip_id & 0xff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700625
Jordan Crouse505df9c2011-07-28 08:37:59 -0600626 for (i = 0; i < ARRAY_SIZE(adreno_gpulist); i++) {
627 if (core == adreno_gpulist[i].core &&
628 _rev_match(major, adreno_gpulist[i].major) &&
Jeremy Gebbene2e61d42011-09-27 15:45:41 -0600629 _rev_match(minor, adreno_gpulist[i].minor) &&
630 _rev_match(patchid, adreno_gpulist[i].patchid))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700631 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700632 }
633
Jordan Crouse505df9c2011-07-28 08:37:59 -0600634 if (i == ARRAY_SIZE(adreno_gpulist)) {
635 adreno_dev->gpurev = ADRENO_REV_UNKNOWN;
636 return;
637 }
638
639 adreno_dev->gpurev = adreno_gpulist[i].gpurev;
640 adreno_dev->gpudev = adreno_gpulist[i].gpudev;
641 adreno_dev->pfp_fwfile = adreno_gpulist[i].pfpfw;
642 adreno_dev->pm4_fwfile = adreno_gpulist[i].pm4fw;
Jeremy Gebbenddf6b572011-09-09 13:39:49 -0700643 adreno_dev->istore_size = adreno_gpulist[i].istore_size;
644 adreno_dev->pix_shader_start = adreno_gpulist[i].pix_shader_start;
Jordan Crouse55d98fd2012-02-04 10:23:51 -0700645 adreno_dev->instruction_size = adreno_gpulist[i].instruction_size;
Jordan Crouse7501d452012-04-19 08:58:44 -0600646 adreno_dev->gmem_size = adreno_gpulist[i].gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647}
648
649static int __devinit
650adreno_probe(struct platform_device *pdev)
651{
652 struct kgsl_device *device;
653 struct adreno_device *adreno_dev;
654 int status = -EINVAL;
655
656 device = (struct kgsl_device *)pdev->id_entry->driver_data;
657 adreno_dev = ADRENO_DEVICE(device);
658 device->parentdev = &pdev->dev;
659
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700660 status = adreno_ringbuffer_init(device);
661 if (status != 0)
662 goto error;
663
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600664 status = kgsl_device_platform_probe(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700665 if (status)
666 goto error_close_rb;
667
668 adreno_debugfs_init(device);
669
670 kgsl_pwrscale_init(device);
671 kgsl_pwrscale_attach_policy(device, ADRENO_DEFAULT_PWRSCALE_POLICY);
672
673 device->flags &= ~KGSL_FLAGS_SOFT_RESET;
674 return 0;
675
676error_close_rb:
677 adreno_ringbuffer_close(&adreno_dev->ringbuffer);
678error:
679 device->parentdev = NULL;
680 return status;
681}
682
683static int __devexit adreno_remove(struct platform_device *pdev)
684{
685 struct kgsl_device *device;
686 struct adreno_device *adreno_dev;
687
688 device = (struct kgsl_device *)pdev->id_entry->driver_data;
689 adreno_dev = ADRENO_DEVICE(device);
690
691 kgsl_pwrscale_detach_policy(device);
692 kgsl_pwrscale_close(device);
693
694 adreno_ringbuffer_close(&adreno_dev->ringbuffer);
695 kgsl_device_platform_remove(device);
696
697 return 0;
698}
699
700static int adreno_start(struct kgsl_device *device, unsigned int init_ram)
701{
702 int status = -EINVAL;
703 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700704
Jeremy Gebben388c2972011-12-16 09:05:07 -0700705 kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700706
707 /* Power up the device */
708 kgsl_pwrctrl_enable(device);
709
710 /* Identify the specific GPU */
711 adreno_identify_gpu(adreno_dev);
712
Jordan Crouse505df9c2011-07-28 08:37:59 -0600713 if (adreno_dev->gpurev == ADRENO_REV_UNKNOWN) {
714 KGSL_DRV_ERR(device, "Unknown chip ID %x\n",
715 adreno_dev->chip_id);
716 goto error_clk_off;
717 }
718
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700719 /* Set up the MMU */
720 if (adreno_is_a2xx(adreno_dev)) {
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600721 /*
722 * the MH_CLNT_INTF_CTRL_CONFIG registers aren't present
723 * on older gpus
724 */
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700725 if (adreno_is_a20x(adreno_dev)) {
726 device->mh.mh_intf_cfg1 = 0;
727 device->mh.mh_intf_cfg2 = 0;
728 }
729
730 kgsl_mh_start(device);
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600731 }
732
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700733 status = kgsl_mmu_start(device);
734 if (status)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700735 goto error_clk_off;
736
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700737 /* Start the GPU */
738 adreno_dev->gpudev->start(adreno_dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700739
740 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700741 device->ftbl->irqctrl(device, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700742
743 status = adreno_ringbuffer_start(&adreno_dev->ringbuffer, init_ram);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700744 if (status == 0) {
745 mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
746 return 0;
747 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700748
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700749 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
Shubhraprakash Das79447952012-04-26 18:12:23 -0600750 kgsl_mmu_stop(&device->mmu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700751error_clk_off:
752 kgsl_pwrctrl_disable(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700753
754 return status;
755}
756
757static int adreno_stop(struct kgsl_device *device)
758{
759 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
760
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700761 adreno_dev->drawctxt_active = NULL;
762
763 adreno_ringbuffer_stop(&adreno_dev->ringbuffer);
764
Shubhraprakash Das79447952012-04-26 18:12:23 -0600765 kgsl_mmu_stop(&device->mmu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700766
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700767 device->ftbl->irqctrl(device, 0);
Ranjhith Kalisamyce75b0c2012-02-01 19:31:23 +0530768 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
Suman Tatiraju4a32c652012-02-17 11:59:05 -0800769 del_timer_sync(&device->idle_timer);
Lucille Sylvester844b1c82011-08-29 15:26:06 -0600770
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700771 /* Power down the device */
772 kgsl_pwrctrl_disable(device);
773
774 return 0;
775}
776
777static int
778adreno_recover_hang(struct kgsl_device *device)
779{
780 int ret;
781 unsigned int *rb_buffer;
782 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
783 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
784 unsigned int timestamp;
785 unsigned int num_rb_contents;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700786 unsigned int reftimestamp;
787 unsigned int enable_ts;
788 unsigned int soptimestamp;
789 unsigned int eoptimestamp;
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700790 unsigned int context_id;
Shubhraprakash Das2dfe5dd2012-02-10 13:49:53 -0700791 struct kgsl_context *context;
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700792 struct adreno_context *adreno_context;
Shubhraprakash Das2dfe5dd2012-02-10 13:49:53 -0700793 int next = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700794
795 KGSL_DRV_ERR(device, "Starting recovery from 3D GPU hang....\n");
796 rb_buffer = vmalloc(rb->buffer_desc.size);
797 if (!rb_buffer) {
798 KGSL_MEM_ERR(device,
799 "Failed to allocate memory for recovery: %x\n",
800 rb->buffer_desc.size);
801 return -ENOMEM;
802 }
803 /* Extract valid contents from rb which can stil be executed after
804 * hang */
805 ret = adreno_ringbuffer_extract(rb, rb_buffer, &num_rb_contents);
806 if (ret)
807 goto done;
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700808 kgsl_sharedmem_readl(&device->memstore, &context_id,
809 KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL,
810 current_context));
811 context = idr_find(&device->context_idr, context_id);
812 if (context == NULL) {
813 KGSL_DRV_ERR(device, "Last context unknown id:%d\n",
814 context_id);
815 context_id = KGSL_MEMSTORE_GLOBAL;
816 }
817
818 timestamp = rb->timestamp[KGSL_MEMSTORE_GLOBAL];
819 KGSL_DRV_ERR(device, "Last issued global timestamp: %x\n", timestamp);
820
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821 kgsl_sharedmem_readl(&device->memstore, &reftimestamp,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700822 KGSL_MEMSTORE_OFFSET(context_id,
823 ref_wait_ts));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824 kgsl_sharedmem_readl(&device->memstore, &enable_ts,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700825 KGSL_MEMSTORE_OFFSET(context_id,
826 ts_cmp_enable));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827 kgsl_sharedmem_readl(&device->memstore, &soptimestamp,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700828 KGSL_MEMSTORE_OFFSET(context_id,
829 soptimestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 kgsl_sharedmem_readl(&device->memstore, &eoptimestamp,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700831 KGSL_MEMSTORE_OFFSET(context_id,
832 eoptimestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 /* Make sure memory is synchronized before restarting the GPU */
834 mb();
835 KGSL_CTXT_ERR(device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700836 "Context id that caused a GPU hang: %d\n", context_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700837 /* restart device */
838 ret = adreno_stop(device);
839 if (ret)
840 goto done;
841 ret = adreno_start(device, true);
842 if (ret)
843 goto done;
844 KGSL_DRV_ERR(device, "Device has been restarted after hang\n");
845 /* Restore timestamp states */
846 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700847 KGSL_MEMSTORE_OFFSET(context_id, soptimestamp),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700848 soptimestamp);
849 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700850 KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851 eoptimestamp);
Carter Cooperae4c7bc2012-04-10 09:40:49 -0600852
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700853 if (num_rb_contents) {
854 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700855 KGSL_MEMSTORE_OFFSET(context_id, ref_wait_ts),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700856 reftimestamp);
857 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700858 KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859 enable_ts);
860 }
861 /* Make sure all writes are posted before the GPU reads them */
862 wmb();
863 /* Mark the invalid context so no more commands are accepted from
864 * that context */
865
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700866 adreno_context = context->devctxt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867
868 KGSL_CTXT_ERR(device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700869 "Context that caused a GPU hang: %d\n", adreno_context->id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700871 adreno_context->flags |= CTXT_FLAGS_GPU_HANG;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700872
Shubhraprakash Das2dfe5dd2012-02-10 13:49:53 -0700873 /*
874 * Set the reset status of all contexts to
875 * INNOCENT_CONTEXT_RESET_EXT except for the bad context
876 * since thats the guilty party
877 */
878 while ((context = idr_get_next(&device->context_idr, &next))) {
879 if (KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT !=
880 context->reset_status) {
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700881 if (context->id != context_id)
Shubhraprakash Das2dfe5dd2012-02-10 13:49:53 -0700882 context->reset_status =
883 KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT;
884 else
885 context->reset_status =
886 KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT;
887 }
888 next = next + 1;
889 }
890
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 /* Restore valid commands in ringbuffer */
892 adreno_ringbuffer_restore(rb, rb_buffer, num_rb_contents);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700893 rb->timestamp[KGSL_MEMSTORE_GLOBAL] = timestamp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700894done:
895 vfree(rb_buffer);
896 return ret;
897}
898
899static int
900adreno_dump_and_recover(struct kgsl_device *device)
901{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 int result = -ETIMEDOUT;
903
904 if (device->state == KGSL_STATE_HUNG)
905 goto done;
Jeremy Gebben388c2972011-12-16 09:05:07 -0700906 if (device->state == KGSL_STATE_DUMP_AND_RECOVER) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700907 mutex_unlock(&device->mutex);
908 wait_for_completion(&device->recovery_gate);
909 mutex_lock(&device->mutex);
Jeremy Gebben388c2972011-12-16 09:05:07 -0700910 if (device->state != KGSL_STATE_HUNG)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 result = 0;
912 } else {
Jeremy Gebben388c2972011-12-16 09:05:07 -0700913 kgsl_pwrctrl_set_state(device, KGSL_STATE_DUMP_AND_RECOVER);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914 INIT_COMPLETION(device->recovery_gate);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700915 /* Detected a hang */
916
917
918 /*
919 * Trigger an automatic dump of the state to
920 * the console
921 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922 adreno_postmortem_dump(device, 0);
Jordan Crouse156cfbc2012-01-24 09:32:04 -0700923
924 /*
925 * Make a GPU snapshot. For now, do it after the PM dump so we
926 * can at least be sure the PM dump will work as it always has
927 */
928 kgsl_device_snapshot(device, 1);
929
Jeremy Gebben388c2972011-12-16 09:05:07 -0700930 result = adreno_recover_hang(device);
931 if (result)
932 kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG);
933 else
934 kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE);
935 complete_all(&device->recovery_gate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700936 }
937done:
938 return result;
939}
940
941static int adreno_getproperty(struct kgsl_device *device,
942 enum kgsl_property_type type,
943 void *value,
944 unsigned int sizebytes)
945{
946 int status = -EINVAL;
947 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
948
949 switch (type) {
950 case KGSL_PROP_DEVICE_INFO:
951 {
952 struct kgsl_devinfo devinfo;
953
954 if (sizebytes != sizeof(devinfo)) {
955 status = -EINVAL;
956 break;
957 }
958
959 memset(&devinfo, 0, sizeof(devinfo));
960 devinfo.device_id = device->id+1;
961 devinfo.chip_id = adreno_dev->chip_id;
962 devinfo.mmu_enabled = kgsl_mmu_enabled();
963 devinfo.gpu_id = adreno_dev->gpurev;
Jordan Crouse7501d452012-04-19 08:58:44 -0600964 devinfo.gmem_gpubaseaddr = adreno_dev->gmem_base;
965 devinfo.gmem_sizebytes = adreno_dev->gmem_size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700966
967 if (copy_to_user(value, &devinfo, sizeof(devinfo)) !=
968 0) {
969 status = -EFAULT;
970 break;
971 }
972 status = 0;
973 }
974 break;
975 case KGSL_PROP_DEVICE_SHADOW:
976 {
977 struct kgsl_shadowprop shadowprop;
978
979 if (sizebytes != sizeof(shadowprop)) {
980 status = -EINVAL;
981 break;
982 }
983 memset(&shadowprop, 0, sizeof(shadowprop));
984 if (device->memstore.hostptr) {
985 /*NOTE: with mmu enabled, gpuaddr doesn't mean
986 * anything to mmap().
987 */
988 shadowprop.gpuaddr = device->memstore.physaddr;
989 shadowprop.size = device->memstore.size;
990 /* GSL needs this to be set, even if it
991 appears to be meaningless */
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700992 shadowprop.flags = KGSL_FLAGS_INITIALIZED |
993 KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700994 }
995 if (copy_to_user(value, &shadowprop,
996 sizeof(shadowprop))) {
997 status = -EFAULT;
998 break;
999 }
1000 status = 0;
1001 }
1002 break;
1003 case KGSL_PROP_MMU_ENABLE:
1004 {
Shubhraprakash Das767fdda2011-08-15 15:49:45 -06001005 int mmu_prop = kgsl_mmu_enabled();
1006
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001007 if (sizebytes != sizeof(int)) {
1008 status = -EINVAL;
1009 break;
1010 }
Shubhraprakash Das767fdda2011-08-15 15:49:45 -06001011 if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001012 status = -EFAULT;
1013 break;
1014 }
1015 status = 0;
1016 }
1017 break;
1018 case KGSL_PROP_INTERRUPT_WAITS:
1019 {
1020 int int_waits = 1;
1021 if (sizebytes != sizeof(int)) {
1022 status = -EINVAL;
1023 break;
1024 }
1025 if (copy_to_user(value, &int_waits, sizeof(int))) {
1026 status = -EFAULT;
1027 break;
1028 }
1029 status = 0;
1030 }
1031 break;
1032 default:
1033 status = -EINVAL;
1034 }
1035
1036 return status;
1037}
1038
Jordan Crousef7370f82012-04-18 09:31:07 -06001039static int adreno_setproperty(struct kgsl_device *device,
1040 enum kgsl_property_type type,
1041 void *value,
1042 unsigned int sizebytes)
1043{
1044 int status = -EINVAL;
1045
1046 switch (type) {
1047 case KGSL_PROP_PWRCTRL: {
1048 unsigned int enable;
1049 struct kgsl_device_platform_data *pdata =
1050 kgsl_device_get_drvdata(device);
1051
1052 if (sizebytes != sizeof(enable))
1053 break;
1054
1055 if (copy_from_user(&enable, (void __user *) value,
1056 sizeof(enable))) {
1057 status = -EFAULT;
1058 break;
1059 }
1060
1061 if (enable) {
1062 if (pdata->nap_allowed)
1063 device->pwrctrl.nap_allowed = true;
1064
1065 kgsl_pwrscale_enable(device);
1066 } else {
1067 device->pwrctrl.nap_allowed = false;
1068 kgsl_pwrscale_disable(device);
1069 }
1070
1071 status = 0;
1072 }
1073 break;
1074 default:
1075 break;
1076 }
1077
1078 return status;
1079}
1080
Lynus Vaz06a9a902011-10-04 19:25:33 +05301081static inline void adreno_poke(struct kgsl_device *device)
1082{
1083 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1084 adreno_regwrite(device, REG_CP_RB_WPTR, adreno_dev->ringbuffer.wptr);
1085}
1086
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001087/* Caller must hold the device mutex. */
1088int adreno_idle(struct kgsl_device *device, unsigned int timeout)
1089{
1090 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1091 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
1092 unsigned int rbbm_status;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +05301093 unsigned long wait_timeout =
1094 msecs_to_jiffies(adreno_dev->wait_timeout);
Lynus Vaz284d1042012-01-31 16:32:31 +05301095 unsigned long wait_time;
1096 unsigned long wait_time_part;
1097 unsigned int msecs;
1098 unsigned int msecs_first;
1099 unsigned int msecs_part;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001100
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001101 kgsl_cffdump_regpoll(device->id,
1102 adreno_dev->gpudev->reg_rbbm_status << 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001103 0x00000000, 0x80000000);
1104 /* first, wait until the CP has consumed all the commands in
1105 * the ring buffer
1106 */
1107retry:
1108 if (rb->flags & KGSL_FLAGS_STARTED) {
Lynus Vaz284d1042012-01-31 16:32:31 +05301109 msecs = adreno_dev->wait_timeout;
1110 msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100;
1111 msecs_part = (msecs - msecs_first + 3) / 4;
1112 wait_time = jiffies + wait_timeout;
1113 wait_time_part = jiffies + msecs_to_jiffies(msecs_first);
Jeremy Gebbenf8594542012-01-13 12:27:21 -07001114 adreno_poke(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001115 do {
Lynus Vaz284d1042012-01-31 16:32:31 +05301116 if (time_after(jiffies, wait_time_part)) {
1117 adreno_poke(device);
1118 wait_time_part = jiffies +
1119 msecs_to_jiffies(msecs_part);
1120 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001121 GSL_RB_GET_READPTR(rb, &rb->rptr);
1122 if (time_after(jiffies, wait_time)) {
1123 KGSL_DRV_ERR(device, "rptr: %x, wptr: %x\n",
1124 rb->rptr, rb->wptr);
1125 goto err;
1126 }
1127 } while (rb->rptr != rb->wptr);
1128 }
1129
1130 /* now, wait for the GPU to finish its operations */
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +05301131 wait_time = jiffies + wait_timeout;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001132 while (time_before(jiffies, wait_time)) {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001133 adreno_regread(device, adreno_dev->gpudev->reg_rbbm_status,
1134 &rbbm_status);
1135 if (adreno_is_a2xx(adreno_dev)) {
1136 if (rbbm_status == 0x110)
1137 return 0;
1138 } else {
1139 if (!(rbbm_status & 0x80000000))
1140 return 0;
1141 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001142 }
1143
1144err:
1145 KGSL_DRV_ERR(device, "spun too long waiting for RB to idle\n");
1146 if (!adreno_dump_and_recover(device)) {
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +05301147 wait_time = jiffies + wait_timeout;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001148 goto retry;
1149 }
1150 return -ETIMEDOUT;
1151}
1152
1153static unsigned int adreno_isidle(struct kgsl_device *device)
1154{
1155 int status = false;
1156 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1157 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
1158 unsigned int rbbm_status;
1159
Lucille Sylvester51b764d2011-12-15 16:51:52 -07001160 WARN_ON(device->state == KGSL_STATE_INIT);
1161 /* If the device isn't active, don't force it on. */
1162 if (device->state == KGSL_STATE_ACTIVE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001163 /* Is the ring buffer is empty? */
1164 GSL_RB_GET_READPTR(rb, &rb->rptr);
1165 if (!device->active_cnt && (rb->rptr == rb->wptr)) {
1166 /* Is the core idle? */
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001167 adreno_regread(device,
1168 adreno_dev->gpudev->reg_rbbm_status,
1169 &rbbm_status);
1170
1171 if (adreno_is_a2xx(adreno_dev)) {
1172 if (rbbm_status == 0x110)
1173 status = true;
1174 } else {
1175 if (!(rbbm_status & 0x80000000))
1176 status = true;
1177 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001178 }
1179 } else {
Jeremy Gebbenaeb23872011-12-13 15:58:24 -07001180 status = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001181 }
1182 return status;
1183}
1184
1185/* Caller must hold the device mutex. */
1186static int adreno_suspend_context(struct kgsl_device *device)
1187{
1188 int status = 0;
1189 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1190
1191 /* switch to NULL ctxt */
1192 if (adreno_dev->drawctxt_active != NULL) {
1193 adreno_drawctxt_switch(adreno_dev, NULL, 0);
1194 status = adreno_idle(device, KGSL_TIMEOUT_DEFAULT);
1195 }
1196
1197 return status;
1198}
1199
Jordan Crouse233b2092012-04-18 09:31:09 -06001200/* Find a memory structure attached to an adreno context */
1201
1202struct kgsl_memdesc *adreno_find_ctxtmem(struct kgsl_device *device,
1203 unsigned int pt_base, unsigned int gpuaddr, unsigned int size)
1204{
1205 struct kgsl_context *context;
1206 struct adreno_context *adreno_context = NULL;
1207 int next = 0;
1208
1209 while (1) {
1210 context = idr_get_next(&device->context_idr, &next);
1211 if (context == NULL)
1212 break;
1213
1214 adreno_context = (struct adreno_context *)context->devctxt;
1215
1216 if (kgsl_mmu_pt_equal(adreno_context->pagetable, pt_base)) {
1217 struct kgsl_memdesc *desc;
1218
1219 desc = &adreno_context->gpustate;
1220 if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size))
1221 return desc;
1222
1223 desc = &adreno_context->context_gmem_shadow.gmemshadow;
1224 if (kgsl_gpuaddr_in_memdesc(desc, gpuaddr, size))
1225 return desc;
1226 }
1227 next = next + 1;
1228 }
1229
1230 return NULL;
1231}
1232
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -06001233struct kgsl_memdesc *adreno_find_region(struct kgsl_device *device,
Jeremy Gebben16e80fa2011-11-30 15:56:29 -07001234 unsigned int pt_base,
1235 unsigned int gpuaddr,
1236 unsigned int size)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001237{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238 struct kgsl_mem_entry *entry;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001239 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1240 struct adreno_ringbuffer *ringbuffer = &adreno_dev->ringbuffer;
1241
Jeremy Gebben16e80fa2011-11-30 15:56:29 -07001242 if (kgsl_gpuaddr_in_memdesc(&ringbuffer->buffer_desc, gpuaddr, size))
1243 return &ringbuffer->buffer_desc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001244
Jeremy Gebben16e80fa2011-11-30 15:56:29 -07001245 if (kgsl_gpuaddr_in_memdesc(&ringbuffer->memptrs_desc, gpuaddr, size))
1246 return &ringbuffer->memptrs_desc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001247
Jeremy Gebben16e80fa2011-11-30 15:56:29 -07001248 if (kgsl_gpuaddr_in_memdesc(&device->memstore, gpuaddr, size))
1249 return &device->memstore;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250
Shubhraprakash Das9a140972012-04-12 13:12:42 -06001251 if (kgsl_gpuaddr_in_memdesc(&device->mmu.setstate_memory, gpuaddr,
1252 size))
1253 return &device->mmu.setstate_memory;
1254
Jordan Crouse0fdf3a02012-03-16 14:53:41 -06001255 entry = kgsl_get_mem_entry(pt_base, gpuaddr, size);
1256
1257 if (entry)
1258 return &entry->memdesc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001259
Jordan Crouse233b2092012-04-18 09:31:09 -06001260 return adreno_find_ctxtmem(device, pt_base, gpuaddr, size);
Jeremy Gebben16e80fa2011-11-30 15:56:29 -07001261}
1262
1263uint8_t *adreno_convertaddr(struct kgsl_device *device, unsigned int pt_base,
1264 unsigned int gpuaddr, unsigned int size)
1265{
Harsh Vardhan Dwivedi8cb835b2012-03-29 17:23:11 -06001266 struct kgsl_memdesc *memdesc;
Jeremy Gebben16e80fa2011-11-30 15:56:29 -07001267
1268 memdesc = adreno_find_region(device, pt_base, gpuaddr, size);
1269
1270 return memdesc ? kgsl_gpuaddr_to_vaddr(memdesc, gpuaddr) : NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001271}
1272
1273void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
1274 unsigned int *value)
1275{
1276 unsigned int *reg;
Jordan Crouse7501d452012-04-19 08:58:44 -06001277 BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len);
1278 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001279
1280 if (!in_interrupt())
1281 kgsl_pre_hwaccess(device);
1282
1283 /*ensure this read finishes before the next one.
1284 * i.e. act like normal readl() */
1285 *value = __raw_readl(reg);
1286 rmb();
1287}
1288
1289void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
1290 unsigned int value)
1291{
1292 unsigned int *reg;
1293
Jordan Crouse7501d452012-04-19 08:58:44 -06001294 BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001295
1296 if (!in_interrupt())
1297 kgsl_pre_hwaccess(device);
1298
1299 kgsl_cffdump_regwrite(device->id, offsetwords << 2, value);
Jordan Crouse7501d452012-04-19 08:58:44 -06001300 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001301
1302 /*ensure previous writes post before this one,
1303 * i.e. act like normal writel() */
1304 wmb();
1305 __raw_writel(value, reg);
1306}
1307
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001308static unsigned int _get_context_id(struct kgsl_context *k_ctxt)
1309{
1310 unsigned int context_id = KGSL_MEMSTORE_GLOBAL;
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001311 if (k_ctxt != NULL) {
1312 struct adreno_context *a_ctxt = k_ctxt->devctxt;
Jeremy Gebben9ad86922012-05-08 15:33:23 -06001313 if (k_ctxt->id == KGSL_CONTEXT_INVALID || a_ctxt == NULL)
1314 context_id = KGSL_CONTEXT_INVALID;
1315 else if (a_ctxt->flags & CTXT_FLAGS_PER_CONTEXT_TS)
1316 context_id = k_ctxt->id;
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001317 }
1318
1319 return context_id;
1320}
1321
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001322static int kgsl_check_interrupt_timestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001323 struct kgsl_context *context, unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001324{
1325 int status;
1326 unsigned int ref_ts, enableflag;
Jeremy Gebben9ad86922012-05-08 15:33:23 -06001327 unsigned int context_id;
1328
1329 mutex_lock(&device->mutex);
1330 context_id = _get_context_id(context);
1331 /*
1332 * If the context ID is invalid, we are in a race with
1333 * the context being destroyed by userspace so bail.
1334 */
1335 if (context_id == KGSL_CONTEXT_INVALID) {
1336 KGSL_DRV_WARN(device, "context was detached");
1337 status = -EINVAL;
1338 goto unlock;
1339 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001340
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001341 status = kgsl_check_timestamp(device, context, timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001342 if (!status) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001343 kgsl_sharedmem_readl(&device->memstore, &enableflag,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001344 KGSL_MEMSTORE_OFFSET(context_id, ts_cmp_enable));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001345 mb();
1346
1347 if (enableflag) {
1348 kgsl_sharedmem_readl(&device->memstore, &ref_ts,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001349 KGSL_MEMSTORE_OFFSET(context_id,
1350 ref_wait_ts));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001351 mb();
Jordan Crousee6239dd2011-11-17 13:39:21 -07001352 if (timestamp_cmp(ref_ts, timestamp) >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001353 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001354 KGSL_MEMSTORE_OFFSET(context_id,
1355 ref_wait_ts), timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001356 wmb();
1357 }
1358 } else {
1359 unsigned int cmds[2];
1360 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001361 KGSL_MEMSTORE_OFFSET(context_id,
1362 ref_wait_ts), timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001363 enableflag = 1;
1364 kgsl_sharedmem_writel(&device->memstore,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001365 KGSL_MEMSTORE_OFFSET(context_id,
1366 ts_cmp_enable), enableflag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001367 wmb();
1368 /* submit a dummy packet so that even if all
1369 * commands upto timestamp get executed we will still
1370 * get an interrupt */
Jordan Crouse084427d2011-07-28 08:37:58 -06001371 cmds[0] = cp_type3_packet(CP_NOP, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001372 cmds[1] = 0;
Zhoulu Luo552905e2012-06-21 15:21:52 -07001373 adreno_ringbuffer_issuecmds(device, KGSL_CMD_FLAGS_NONE,
Jordan Crousee0ea7622012-01-24 09:32:04 -07001374 &cmds[0], 2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001375 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001376 }
Jeremy Gebben9ad86922012-05-08 15:33:23 -06001377unlock:
1378 mutex_unlock(&device->mutex);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001379
1380 return status;
1381}
1382
1383/*
Lucille Sylvester02e46292011-09-21 14:59:17 -06001384 wait_event_interruptible_timeout checks for the exit condition before
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001385 placing a process in wait q. For conditional interrupts we expect the
1386 process to already be in its wait q when its exit condition checking
1387 function is called.
1388*/
Lucille Sylvester02e46292011-09-21 14:59:17 -06001389#define kgsl_wait_event_interruptible_timeout(wq, condition, timeout, io)\
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001390({ \
1391 long __ret = timeout; \
Lucille Sylvester02e46292011-09-21 14:59:17 -06001392 if (io) \
1393 __wait_io_event_interruptible_timeout(wq, condition, __ret);\
1394 else \
1395 __wait_event_interruptible_timeout(wq, condition, __ret);\
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001396 __ret; \
1397})
1398
1399/* MUST be called with the device mutex held */
1400static int adreno_waittimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001401 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001402 unsigned int timestamp,
1403 unsigned int msecs)
1404{
1405 long status = 0;
Lucille Sylvester02e46292011-09-21 14:59:17 -06001406 uint io = 1;
Lucille Sylvester596d4c22011-10-19 18:04:01 -06001407 static uint io_cnt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001408 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Lucille Sylvester02e46292011-09-21 14:59:17 -06001409 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
Lynus Vaz06a9a902011-10-04 19:25:33 +05301410 int retries;
1411 unsigned int msecs_first;
1412 unsigned int msecs_part;
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001413 unsigned int ts_issued;
1414 unsigned int context_id = _get_context_id(context);
1415
1416 ts_issued = adreno_dev->ringbuffer.timestamp[context_id];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001417
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +05301418 /* Don't wait forever, set a max value for now */
1419 if (msecs == -1)
1420 msecs = adreno_dev->wait_timeout;
1421
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001422 if (timestamp_cmp(timestamp, ts_issued) > 0) {
1423 KGSL_DRV_ERR(device, "Cannot wait for invalid ts <%d:0x%x>, "
1424 "last issued ts <%d:0x%x>\n",
1425 context_id, timestamp, context_id, ts_issued);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001426 status = -EINVAL;
1427 goto done;
1428 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001429
Lynus Vaz06a9a902011-10-04 19:25:33 +05301430 /* Keep the first timeout as 100msecs before rewriting
1431 * the WPTR. Less visible impact if the WPTR has not
1432 * been updated properly.
1433 */
1434 msecs_first = (msecs <= 100) ? ((msecs + 4) / 5) : 100;
1435 msecs_part = (msecs - msecs_first + 3) / 4;
1436 for (retries = 0; retries < 5; retries++) {
Jeremy Gebben9ad86922012-05-08 15:33:23 -06001437 /*
1438 * If the context ID is invalid, we are in a race with
1439 * the context being destroyed by userspace so bail.
1440 */
1441 if (context_id == KGSL_CONTEXT_INVALID) {
1442 KGSL_DRV_WARN(device, "context was detached");
1443 status = -EINVAL;
1444 goto done;
1445 }
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001446 if (kgsl_check_timestamp(device, context, timestamp)) {
Jeremy Gebben63904832012-02-07 16:10:55 -07001447 /* if the timestamp happens while we're not
1448 * waiting, there's a chance that an interrupt
1449 * will not be generated and thus the timestamp
1450 * work needs to be queued.
Lynus Vaz06a9a902011-10-04 19:25:33 +05301451 */
Jeremy Gebben63904832012-02-07 16:10:55 -07001452 queue_work(device->work_queue, &device->ts_expired_ws);
1453 status = 0;
1454 goto done;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001455 }
Jeremy Gebben63904832012-02-07 16:10:55 -07001456 adreno_poke(device);
1457 io_cnt = (io_cnt + 1) % 100;
1458 if (io_cnt <
1459 pwr->pwrlevels[pwr->active_pwrlevel].io_fraction)
1460 io = 0;
1461 mutex_unlock(&device->mutex);
1462 /* We need to make sure that the process is
1463 * placed in wait-q before its condition is called
1464 */
1465 status = kgsl_wait_event_interruptible_timeout(
1466 device->wait_queue,
1467 kgsl_check_interrupt_timestamp(device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001468 context, timestamp),
Jeremy Gebben63904832012-02-07 16:10:55 -07001469 msecs_to_jiffies(retries ?
1470 msecs_part : msecs_first), io);
1471 mutex_lock(&device->mutex);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001472
Jeremy Gebben63904832012-02-07 16:10:55 -07001473 if (status > 0) {
1474 /*completed before the wait finished */
1475 status = 0;
1476 goto done;
1477 } else if (status < 0) {
1478 /*an error occurred*/
1479 goto done;
1480 }
1481 /*this wait timed out*/
1482 }
1483 status = -ETIMEDOUT;
1484 KGSL_DRV_ERR(device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001485 "Device hang detected while waiting for timestamp: "
1486 "<%d:0x%x>, last submitted timestamp: <%d:0x%x>, "
1487 "wptr: 0x%x\n",
1488 context_id, timestamp, context_id, ts_issued,
Jeremy Gebben63904832012-02-07 16:10:55 -07001489 adreno_dev->ringbuffer.wptr);
1490 if (!adreno_dump_and_recover(device)) {
1491 /* wait for idle after recovery as the
1492 * timestamp that this process wanted
1493 * to wait on may be invalid */
1494 if (!adreno_idle(device, KGSL_TIMEOUT_DEFAULT))
1495 status = 0;
1496 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001497done:
1498 return (int)status;
1499}
1500
1501static unsigned int adreno_readtimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001502 struct kgsl_context *context, enum kgsl_timestamp_type type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001503{
1504 unsigned int timestamp = 0;
Carter Cooper7e7f02e2012-02-15 09:36:31 -07001505 unsigned int context_id = _get_context_id(context);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001506
Jeremy Gebben9ad86922012-05-08 15:33:23 -06001507 /*
1508 * If the context ID is invalid, we are in a race with
1509 * the context being destroyed by userspace so bail.
1510 */
1511 if (context_id == KGSL_CONTEXT_INVALID) {
1512 KGSL_DRV_WARN(device, "context was detached");
1513 return timestamp;
1514 }
Jordan Crousec659f382012-04-16 11:10:41 -06001515 switch (type) {
1516 case KGSL_TIMESTAMP_QUEUED: {
1517 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1518 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
1519
1520 timestamp = rb->timestamp[context_id];
1521 break;
1522 }
1523 case KGSL_TIMESTAMP_CONSUMED:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001524 adreno_regread(device, REG_CP_TIMESTAMP, &timestamp);
Jordan Crousec659f382012-04-16 11:10:41 -06001525 break;
1526 case KGSL_TIMESTAMP_RETIRED:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001527 kgsl_sharedmem_readl(&device->memstore, &timestamp,
Jordan Crousec659f382012-04-16 11:10:41 -06001528 KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp));
1529 break;
1530 }
1531
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001532 rmb();
1533
1534 return timestamp;
1535}
1536
1537static long adreno_ioctl(struct kgsl_device_private *dev_priv,
1538 unsigned int cmd, void *data)
1539{
1540 int result = 0;
1541 struct kgsl_drawctxt_set_bin_base_offset *binbase;
1542 struct kgsl_context *context;
1543
1544 switch (cmd) {
1545 case IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET:
1546 binbase = data;
1547
1548 context = kgsl_find_context(dev_priv, binbase->drawctxt_id);
1549 if (context) {
1550 adreno_drawctxt_set_bin_base_offset(
1551 dev_priv->device, context, binbase->offset);
1552 } else {
1553 result = -EINVAL;
1554 KGSL_DRV_ERR(dev_priv->device,
1555 "invalid drawctxt drawctxt_id %d "
1556 "device_id=%d\n",
1557 binbase->drawctxt_id, dev_priv->device->id);
1558 }
1559 break;
1560
1561 default:
1562 KGSL_DRV_INFO(dev_priv->device,
1563 "invalid ioctl code %08x\n", cmd);
Jeremy Gebbenc15b4612012-01-09 09:44:11 -07001564 result = -ENOIOCTLCMD;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001565 break;
1566 }
1567 return result;
1568
1569}
1570
1571static inline s64 adreno_ticks_to_us(u32 ticks, u32 gpu_freq)
1572{
1573 gpu_freq /= 1000000;
1574 return ticks / gpu_freq;
1575}
1576
1577static void adreno_power_stats(struct kgsl_device *device,
1578 struct kgsl_power_stats *stats)
1579{
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001580 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001581 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001582 unsigned int cycles;
1583
1584 /* Get the busy cycles counted since the counter was last reset */
1585 /* Calling this function also resets and restarts the counter */
1586
1587 cycles = adreno_dev->gpudev->busy_cycles(adreno_dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001588
1589 /* In order to calculate idle you have to have run the algorithm *
1590 * at least once to get a start time. */
1591 if (pwr->time != 0) {
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001592 s64 tmp = ktime_to_us(ktime_get());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001593 stats->total_time = tmp - pwr->time;
1594 pwr->time = tmp;
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001595 stats->busy_time = adreno_ticks_to_us(cycles, device->pwrctrl.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001596 pwrlevels[device->pwrctrl.active_pwrlevel].
1597 gpu_freq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001598 } else {
1599 stats->total_time = 0;
1600 stats->busy_time = 0;
1601 pwr->time = ktime_to_us(ktime_get());
1602 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001603}
1604
1605void adreno_irqctrl(struct kgsl_device *device, int state)
1606{
Jordan Crousea78c9172011-07-11 13:14:09 -06001607 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1608 adreno_dev->gpudev->irq_control(adreno_dev, state);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001609}
1610
Jordan Croused6535882012-06-20 08:22:16 -06001611static unsigned int adreno_gpuid(struct kgsl_device *device,
1612 unsigned int *chipid)
Jordan Crousea0758f22011-12-07 11:19:22 -07001613{
1614 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1615
Jordan Croused6535882012-06-20 08:22:16 -06001616 /* Some applications need to know the chip ID too, so pass
1617 * that as a parameter */
1618
1619 if (chipid != NULL)
1620 *chipid = adreno_dev->chip_id;
1621
Jordan Crousea0758f22011-12-07 11:19:22 -07001622 /* Standard KGSL gpuid format:
1623 * top word is 0x0002 for 2D or 0x0003 for 3D
1624 * Bottom word is core specific identifer
1625 */
1626
1627 return (0x0003 << 16) | ((int) adreno_dev->gpurev);
1628}
1629
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001630static const struct kgsl_functable adreno_functable = {
1631 /* Mandatory functions */
1632 .regread = adreno_regread,
1633 .regwrite = adreno_regwrite,
1634 .idle = adreno_idle,
1635 .isidle = adreno_isidle,
1636 .suspend_context = adreno_suspend_context,
1637 .start = adreno_start,
1638 .stop = adreno_stop,
1639 .getproperty = adreno_getproperty,
1640 .waittimestamp = adreno_waittimestamp,
1641 .readtimestamp = adreno_readtimestamp,
1642 .issueibcmds = adreno_ringbuffer_issueibcmds,
1643 .ioctl = adreno_ioctl,
1644 .setup_pt = adreno_setup_pt,
1645 .cleanup_pt = adreno_cleanup_pt,
1646 .power_stats = adreno_power_stats,
1647 .irqctrl = adreno_irqctrl,
Jordan Crousea0758f22011-12-07 11:19:22 -07001648 .gpuid = adreno_gpuid,
Jordan Crouse156cfbc2012-01-24 09:32:04 -07001649 .snapshot = adreno_snapshot,
Jordan Crouseb368e9b2012-04-27 14:01:59 -06001650 .irq_handler = adreno_irq_handler,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001651 /* Optional functions */
1652 .setstate = adreno_setstate,
1653 .drawctxt_create = adreno_drawctxt_create,
1654 .drawctxt_destroy = adreno_drawctxt_destroy,
Jordan Crousef7370f82012-04-18 09:31:07 -06001655 .setproperty = adreno_setproperty,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001656};
1657
1658static struct platform_device_id adreno_id_table[] = {
1659 { DEVICE_3D0_NAME, (kernel_ulong_t)&device_3d0.dev, },
1660 { },
1661};
1662MODULE_DEVICE_TABLE(platform, adreno_id_table);
1663
1664static struct platform_driver adreno_platform_driver = {
1665 .probe = adreno_probe,
1666 .remove = __devexit_p(adreno_remove),
1667 .suspend = kgsl_suspend_driver,
1668 .resume = kgsl_resume_driver,
1669 .id_table = adreno_id_table,
1670 .driver = {
1671 .owner = THIS_MODULE,
1672 .name = DEVICE_3D_NAME,
1673 .pm = &kgsl_pm_ops,
1674 }
1675};
1676
1677static int __init kgsl_3d_init(void)
1678{
1679 return platform_driver_register(&adreno_platform_driver);
1680}
1681
1682static void __exit kgsl_3d_exit(void)
1683{
1684 platform_driver_unregister(&adreno_platform_driver);
1685}
1686
1687module_init(kgsl_3d_init);
1688module_exit(kgsl_3d_exit);
1689
1690MODULE_DESCRIPTION("3D Graphics driver");
1691MODULE_VERSION("1.2");
1692MODULE_LICENSE("GPL v2");
1693MODULE_ALIAS("platform:kgsl_3d");