blob: d5d6a1d2aa346780baed5f5f0bad167dd7145af7 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2002,2007-2011, Code Aurora Forum. All rights reserved.
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 */
13#include <linux/delay.h>
14#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"
25
26#include "adreno.h"
27#include "adreno_pm4types.h"
28#include "adreno_debugfs.h"
29#include "adreno_postmortem.h"
30
31#include "a200_reg.h"
32
33#define DRIVER_VERSION_MAJOR 3
34#define DRIVER_VERSION_MINOR 1
35
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036/* Adreno MH arbiter config*/
37#define ADRENO_CFG_MHARB \
38 (0x10 \
39 | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \
40 | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \
41 | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \
42 | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \
43 | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \
44 | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \
45 | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \
46 | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \
47 | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \
48 | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \
49 | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \
50 | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \
51 | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \
52 | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT))
53
54#define ADRENO_MMU_CONFIG \
55 (0x01 \
56 | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \
57 | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \
58 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \
59 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \
60 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \
61 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \
62 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \
63 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \
64 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \
65 | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \
66 | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT))
67
68/* max msecs to wait for gpu to finish its operation(s) */
69#define MAX_WAITGPU_SECS (HZ + HZ/2)
70
71static const struct kgsl_functable adreno_functable;
72
73static struct adreno_device device_3d0 = {
74 .dev = {
75 .name = DEVICE_3D0_NAME,
76 .id = KGSL_DEVICE_3D0,
77 .ver_major = DRIVER_VERSION_MAJOR,
78 .ver_minor = DRIVER_VERSION_MINOR,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -060079 .mh = {
80 .mharb = ADRENO_CFG_MHARB,
81 /* Remove 1k boundary check in z470 to avoid a GPU
82 * hang. Notice that this solution won't work if
83 * both EBI and SMI are used
84 */
85 .mh_intf_cfg1 = 0x00032f07,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086 /* turn off memory protection unit by setting
87 acceptable physical address range to include
88 all pages. */
89 .mpu_base = 0x00000000,
90 .mpu_range = 0xFFFFF000,
91 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -060092 .mmu = {
93 .config = ADRENO_MMU_CONFIG,
94 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095 .pwrctrl = {
96 .regulator_name = "fs_gfx3d",
97 .irq_name = KGSL_3D0_IRQ,
98 .src_clk_name = "grp_src_clk",
99 },
100 .mutex = __MUTEX_INITIALIZER(device_3d0.dev.mutex),
101 .state = KGSL_STATE_INIT,
102 .active_cnt = 0,
103 .iomemname = KGSL_3D0_REG_MEMORY,
104 .ftbl = &adreno_functable,
105 .display_off = {
106#ifdef CONFIG_HAS_EARLYSUSPEND
107 .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING,
108 .suspend = kgsl_early_suspend_driver,
109 .resume = kgsl_late_resume_driver,
110#endif
111 },
112 },
113 .gmemspace = {
114 .gpu_base = 0,
115 .sizebytes = SZ_256K,
116 },
117 .pfp_fw = NULL,
118 .pm4_fw = NULL,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119};
120
121static int adreno_gmeminit(struct adreno_device *adreno_dev)
122{
123 struct kgsl_device *device = &adreno_dev->dev;
124 union reg_rb_edram_info rb_edram_info;
125 unsigned int gmem_size;
126 unsigned int edram_value = 0;
127
128 /* make sure edram range is aligned to size */
129 BUG_ON(adreno_dev->gmemspace.gpu_base &
130 (adreno_dev->gmemspace.sizebytes - 1));
131
132 /* get edram_size value equivalent */
133 gmem_size = (adreno_dev->gmemspace.sizebytes >> 14);
134 while (gmem_size >>= 1)
135 edram_value++;
136
137 rb_edram_info.val = 0;
138
139 rb_edram_info.f.edram_size = edram_value;
140 if (!adreno_is_a220(adreno_dev))
141 rb_edram_info.f.edram_mapping_mode = 0; /* EDRAM_MAP_UPPER */
142
143 /* must be aligned to size */
144 rb_edram_info.f.edram_range = (adreno_dev->gmemspace.gpu_base >> 14);
145
146 adreno_regwrite(device, REG_RB_EDRAM_INFO, rb_edram_info.val);
147
148 return 0;
149}
150
151static int adreno_gmemclose(struct kgsl_device *device)
152{
153 adreno_regwrite(device, REG_RB_EDRAM_INFO, 0x00000000);
154
155 return 0;
156}
157
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158irqreturn_t adreno_isr(int irq, void *data)
159{
Jordan Crousea78c9172011-07-11 13:14:09 -0600160 irqreturn_t result;
161 struct kgsl_device *device = data;
162 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163
Jordan Crousea78c9172011-07-11 13:14:09 -0600164 result = adreno_dev->gpudev->irq_handler(adreno_dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165
166 if (device->requested_state == KGSL_STATE_NONE) {
167 if (device->pwrctrl.nap_allowed == true) {
168 device->requested_state = KGSL_STATE_NAP;
169 queue_work(device->work_queue, &device->idle_check_ws);
170 } else if (device->pwrscale.policy != NULL) {
171 queue_work(device->work_queue, &device->idle_check_ws);
172 }
173 }
174
175 /* Reset the time-out in our idle timer */
176 mod_timer(&device->idle_timer,
177 jiffies + device->pwrctrl.interval_timeout);
178 return result;
179}
180
181static int adreno_cleanup_pt(struct kgsl_device *device,
182 struct kgsl_pagetable *pagetable)
183{
184 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
185 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
186
187 kgsl_mmu_unmap(pagetable, &rb->buffer_desc);
188
189 kgsl_mmu_unmap(pagetable, &rb->memptrs_desc);
190
191 kgsl_mmu_unmap(pagetable, &device->memstore);
192
193 kgsl_mmu_unmap(pagetable, &device->mmu.dummyspace);
194
195 return 0;
196}
197
198static int adreno_setup_pt(struct kgsl_device *device,
199 struct kgsl_pagetable *pagetable)
200{
201 int result = 0;
202 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
203 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
204
205 BUG_ON(rb->buffer_desc.physaddr == 0);
206 BUG_ON(rb->memptrs_desc.physaddr == 0);
207 BUG_ON(device->memstore.physaddr == 0);
208#ifdef CONFIG_MSM_KGSL_MMU
209 BUG_ON(device->mmu.dummyspace.physaddr == 0);
210#endif
211 result = kgsl_mmu_map_global(pagetable, &rb->buffer_desc,
212 GSL_PT_PAGE_RV);
213 if (result)
214 goto error;
215
216 result = kgsl_mmu_map_global(pagetable, &rb->memptrs_desc,
217 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
218 if (result)
219 goto unmap_buffer_desc;
220
221 result = kgsl_mmu_map_global(pagetable, &device->memstore,
222 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
223 if (result)
224 goto unmap_memptrs_desc;
225
226 result = kgsl_mmu_map_global(pagetable, &device->mmu.dummyspace,
227 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
228 if (result)
229 goto unmap_memstore_desc;
230
231 return result;
232
233unmap_memstore_desc:
234 kgsl_mmu_unmap(pagetable, &device->memstore);
235
236unmap_memptrs_desc:
237 kgsl_mmu_unmap(pagetable, &rb->memptrs_desc);
238
239unmap_buffer_desc:
240 kgsl_mmu_unmap(pagetable, &rb->buffer_desc);
241
242error:
243 return result;
244}
245
246static void adreno_setstate(struct kgsl_device *device, uint32_t flags)
247{
248 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
249 unsigned int link[32];
250 unsigned int *cmds = &link[0];
251 int sizedwords = 0;
252 unsigned int mh_mmu_invalidate = 0x00000003; /*invalidate all and tc */
253
254 if (!kgsl_mmu_enabled() || !flags)
255 return;
256
257 /* If possible, then set the state via the command stream to avoid
258 a CPU idle. Otherwise, use the default setstate which uses register
259 writes */
260
261 if (adreno_dev->drawctxt_active) {
262 if (flags & KGSL_MMUFLAGS_PTUPDATE) {
263 /* wait for graphics pipe to be idle */
264 *cmds++ = pm4_type3_packet(PM4_WAIT_FOR_IDLE, 1);
265 *cmds++ = 0x00000000;
266
267 /* set page table base */
268 *cmds++ = pm4_type0_packet(MH_MMU_PT_BASE, 1);
269 *cmds++ = device->mmu.hwpagetable->base.gpuaddr;
270 sizedwords += 4;
271 }
272
273 if (flags & KGSL_MMUFLAGS_TLBFLUSH) {
274 if (!(flags & KGSL_MMUFLAGS_PTUPDATE)) {
275 *cmds++ = pm4_type3_packet(PM4_WAIT_FOR_IDLE,
276 1);
277 *cmds++ = 0x00000000;
278 sizedwords += 2;
279 }
280 *cmds++ = pm4_type0_packet(MH_MMU_INVALIDATE, 1);
281 *cmds++ = mh_mmu_invalidate;
282 sizedwords += 2;
283 }
284
285 if (flags & KGSL_MMUFLAGS_PTUPDATE &&
286 !adreno_is_a220(adreno_dev)) {
287 /* HW workaround: to resolve MMU page fault interrupts
288 * caused by the VGT.It prevents the CP PFP from filling
289 * the VGT DMA request fifo too early,thereby ensuring
290 * that the VGT will not fetch vertex/bin data until
291 * after the page table base register has been updated.
292 *
293 * Two null DRAW_INDX_BIN packets are inserted right
294 * after the page table base update, followed by a
295 * wait for idle. The null packets will fill up the
296 * VGT DMA request fifo and prevent any further
297 * vertex/bin updates from occurring until the wait
298 * has finished. */
299 *cmds++ = pm4_type3_packet(PM4_SET_CONSTANT, 2);
300 *cmds++ = (0x4 << 16) |
301 (REG_PA_SU_SC_MODE_CNTL - 0x2000);
302 *cmds++ = 0; /* disable faceness generation */
303 *cmds++ = pm4_type3_packet(PM4_SET_BIN_BASE_OFFSET, 1);
304 *cmds++ = device->mmu.dummyspace.gpuaddr;
305 *cmds++ = pm4_type3_packet(PM4_DRAW_INDX_BIN, 6);
306 *cmds++ = 0; /* viz query info */
307 *cmds++ = 0x0003C004; /* draw indicator */
308 *cmds++ = 0; /* bin base */
309 *cmds++ = 3; /* bin size */
310 *cmds++ = device->mmu.dummyspace.gpuaddr; /* dma base */
311 *cmds++ = 6; /* dma size */
312 *cmds++ = pm4_type3_packet(PM4_DRAW_INDX_BIN, 6);
313 *cmds++ = 0; /* viz query info */
314 *cmds++ = 0x0003C004; /* draw indicator */
315 *cmds++ = 0; /* bin base */
316 *cmds++ = 3; /* bin size */
317 /* dma base */
318 *cmds++ = device->mmu.dummyspace.gpuaddr;
319 *cmds++ = 6; /* dma size */
320 *cmds++ = pm4_type3_packet(PM4_WAIT_FOR_IDLE, 1);
321 *cmds++ = 0x00000000;
322 sizedwords += 21;
323 }
324
325 if (flags & (KGSL_MMUFLAGS_PTUPDATE | KGSL_MMUFLAGS_TLBFLUSH)) {
326 *cmds++ = pm4_type3_packet(PM4_INVALIDATE_STATE, 1);
327 *cmds++ = 0x7fff; /* invalidate all base pointers */
328 sizedwords += 2;
329 }
330
331 adreno_ringbuffer_issuecmds(device, KGSL_CMD_FLAGS_PMODE,
332 &link[0], sizedwords);
333 } else
334 kgsl_default_setstate(device, flags);
335}
336
337static unsigned int
338adreno_getchipid(struct kgsl_device *device)
339{
340 unsigned int chipid = 0;
341 unsigned int coreid, majorid, minorid, patchid, revid;
342
343 adreno_regread(device, REG_RBBM_PERIPHID1, &coreid);
344 adreno_regread(device, REG_RBBM_PERIPHID2, &majorid);
345 adreno_regread(device, REG_RBBM_PATCH_RELEASE, &revid);
346
347 /*
348 * adreno 22x gpus are indicated by coreid 2,
349 * but REG_RBBM_PERIPHID1 always contains 0 for this field
350 */
351 if (cpu_is_msm8960() || cpu_is_msm8x60())
352 chipid = 2 << 24;
353 else
354 chipid = (coreid & 0xF) << 24;
355
356 chipid |= ((majorid >> 4) & 0xF) << 16;
357
358 minorid = ((revid >> 0) & 0xFF);
359
360 patchid = ((revid >> 16) & 0xFF);
361
362 /* 8x50 returns 0 for patch release, but it should be 1 */
363 if (cpu_is_qsd8x50())
364 patchid = 1;
365 /* userspace isn't prepared to deal with patch id for these chips yet */
366 else if (cpu_is_msm8960() || cpu_is_msm8x60())
367 patchid = 0;
368
369 chipid |= (minorid << 8) | patchid;
370
371 return chipid;
372}
373
374/* all chipid fields are 8 bits wide so 256 won't occur in a real chipid */
375#define DONT_CARE 256
376static const struct {
377 unsigned int core;
378 unsigned int major;
379 unsigned int minor;
380 enum adreno_gpurev gpurev;
381} gpurev_table[] = {
382 /* major and minor may be DONT_CARE, but core must not be */
383 {0, 2, DONT_CARE, ADRENO_REV_A200},
384 {0, 1, 0, ADRENO_REV_A205},
385 {2, 1, DONT_CARE, ADRENO_REV_A220},
386 {2, 2, DONT_CARE, ADRENO_REV_A225},
387};
388
389static inline bool _rev_match(unsigned int id, unsigned int entry)
390{
391 return (entry == DONT_CARE || entry == id);
392}
393#undef DONT_CARE
394
395static void
396adreno_identify_gpu(struct adreno_device *adreno_dev)
397{
398 enum adreno_gpurev gpurev = ADRENO_REV_UNKNOWN;
399 unsigned int i, core, major, minor;
400
401 adreno_dev->chip_id = adreno_getchipid(&adreno_dev->dev);
402
403 core = (adreno_dev->chip_id >> 24) & 0xff;
404 major = (adreno_dev->chip_id >> 16) & 0xff;
405 minor = (adreno_dev->chip_id >> 8) & 0xff;
406
407 for (i = 0; i < ARRAY_SIZE(gpurev_table); i++) {
408 if (core == gpurev_table[i].core &&
409 _rev_match(major, gpurev_table[i].major) &&
410 _rev_match(minor, gpurev_table[i].minor)) {
411 gpurev = gpurev_table[i].gpurev;
412 break;
413 }
414 }
415
416 adreno_dev->gpurev = gpurev;
Jordan Crousea78c9172011-07-11 13:14:09 -0600417 adreno_dev->gpudev = &adreno_a2xx_gpudev;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700418}
419
420static int __devinit
421adreno_probe(struct platform_device *pdev)
422{
423 struct kgsl_device *device;
424 struct adreno_device *adreno_dev;
425 int status = -EINVAL;
426
427 device = (struct kgsl_device *)pdev->id_entry->driver_data;
428 adreno_dev = ADRENO_DEVICE(device);
429 device->parentdev = &pdev->dev;
430
431 init_completion(&device->recovery_gate);
432
433 status = adreno_ringbuffer_init(device);
434 if (status != 0)
435 goto error;
436
437 status = kgsl_device_platform_probe(device, adreno_isr);
438 if (status)
439 goto error_close_rb;
440
441 adreno_debugfs_init(device);
442
443 kgsl_pwrscale_init(device);
444 kgsl_pwrscale_attach_policy(device, ADRENO_DEFAULT_PWRSCALE_POLICY);
445
446 device->flags &= ~KGSL_FLAGS_SOFT_RESET;
447 return 0;
448
449error_close_rb:
450 adreno_ringbuffer_close(&adreno_dev->ringbuffer);
451error:
452 device->parentdev = NULL;
453 return status;
454}
455
456static int __devexit adreno_remove(struct platform_device *pdev)
457{
458 struct kgsl_device *device;
459 struct adreno_device *adreno_dev;
460
461 device = (struct kgsl_device *)pdev->id_entry->driver_data;
462 adreno_dev = ADRENO_DEVICE(device);
463
464 kgsl_pwrscale_detach_policy(device);
465 kgsl_pwrscale_close(device);
466
467 adreno_ringbuffer_close(&adreno_dev->ringbuffer);
468 kgsl_device_platform_remove(device);
469
470 return 0;
471}
472
473static int adreno_start(struct kgsl_device *device, unsigned int init_ram)
474{
475 int status = -EINVAL;
476 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
477 int init_reftimestamp = 0x7fffffff;
478
479 device->state = KGSL_STATE_INIT;
480 device->requested_state = KGSL_STATE_NONE;
481
482 /* Power up the device */
483 kgsl_pwrctrl_enable(device);
484
485 /* Identify the specific GPU */
486 adreno_identify_gpu(adreno_dev);
487
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600488 if (adreno_is_a20x(adreno_dev)) {
489 /*
490 * the MH_CLNT_INTF_CTRL_CONFIG registers aren't present
491 * on older gpus
492 */
493 device->mh.mh_intf_cfg1 = 0;
494 device->mh.mh_intf_cfg2 = 0;
495 }
496
497 kgsl_mh_start(device);
498
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700499 if (kgsl_mmu_start(device))
500 goto error_clk_off;
501
502 /*We need to make sure all blocks are powered up and clocked before
503 *issuing a soft reset. The overrides will then be turned off (set to 0)
504 */
505 adreno_regwrite(device, REG_RBBM_PM_OVERRIDE1, 0xfffffffe);
506 adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0xffffffff);
507
508 /* Only reset CP block if all blocks have previously been reset */
509 if (!(device->flags & KGSL_FLAGS_SOFT_RESET) ||
510 !adreno_is_a220(adreno_dev)) {
511 adreno_regwrite(device, REG_RBBM_SOFT_RESET, 0xFFFFFFFF);
512 device->flags |= KGSL_FLAGS_SOFT_RESET;
513 } else
514 adreno_regwrite(device, REG_RBBM_SOFT_RESET, 0x00000001);
515
516 /* The core is in an indeterminate state until the reset completes
517 * after 30ms.
518 */
519 msleep(30);
520
521 adreno_regwrite(device, REG_RBBM_SOFT_RESET, 0x00000000);
522
523 adreno_regwrite(device, REG_RBBM_CNTL, 0x00004442);
524
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525 adreno_regwrite(device, REG_SQ_VS_PROGRAM, 0x00000000);
526 adreno_regwrite(device, REG_SQ_PS_PROGRAM, 0x00000000);
527
528 adreno_regwrite(device, REG_RBBM_PM_OVERRIDE1, 0);
529 if (!adreno_is_a220(adreno_dev))
530 adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0);
531 else
532 adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0x80);
533
534 kgsl_sharedmem_writel(&device->memstore,
535 KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts),
536 init_reftimestamp);
537
538 adreno_regwrite(device, REG_RBBM_DEBUG, 0x00080000);
539
540 /* Make sure interrupts are disabled */
541
542 adreno_regwrite(device, REG_RBBM_INT_CNTL, 0);
543 adreno_regwrite(device, REG_CP_INT_CNTL, 0);
544 adreno_regwrite(device, REG_SQ_INT_CNTL, 0);
545
546 if (adreno_is_a220(adreno_dev))
547 adreno_dev->gmemspace.sizebytes = SZ_512K;
548 else
549 adreno_dev->gmemspace.sizebytes = SZ_256K;
550 adreno_gmeminit(adreno_dev);
551
552 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
553
554 status = adreno_ringbuffer_start(&adreno_dev->ringbuffer, init_ram);
555 if (status != 0)
556 goto error_irq_off;
557
558 mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
559 return status;
560
561error_irq_off:
562 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600563 kgsl_mmu_stop(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700564error_clk_off:
565 kgsl_pwrctrl_disable(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700566
567 return status;
568}
569
570static int adreno_stop(struct kgsl_device *device)
571{
572 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
573
574 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
Jeremy Gebben1757a852011-07-11 16:04:38 -0600575 del_timer_sync(&device->idle_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576
577 adreno_dev->drawctxt_active = NULL;
578
579 adreno_ringbuffer_stop(&adreno_dev->ringbuffer);
580
581 adreno_gmemclose(device);
582
583 kgsl_mmu_stop(device);
584
585 /* Power down the device */
586 kgsl_pwrctrl_disable(device);
587
588 return 0;
589}
590
591static int
592adreno_recover_hang(struct kgsl_device *device)
593{
594 int ret;
595 unsigned int *rb_buffer;
596 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
597 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
598 unsigned int timestamp;
599 unsigned int num_rb_contents;
600 unsigned int bad_context;
601 unsigned int reftimestamp;
602 unsigned int enable_ts;
603 unsigned int soptimestamp;
604 unsigned int eoptimestamp;
605 struct adreno_context *drawctxt;
606
607 KGSL_DRV_ERR(device, "Starting recovery from 3D GPU hang....\n");
608 rb_buffer = vmalloc(rb->buffer_desc.size);
609 if (!rb_buffer) {
610 KGSL_MEM_ERR(device,
611 "Failed to allocate memory for recovery: %x\n",
612 rb->buffer_desc.size);
613 return -ENOMEM;
614 }
615 /* Extract valid contents from rb which can stil be executed after
616 * hang */
617 ret = adreno_ringbuffer_extract(rb, rb_buffer, &num_rb_contents);
618 if (ret)
619 goto done;
620 timestamp = rb->timestamp;
621 KGSL_DRV_ERR(device, "Last issued timestamp: %x\n", timestamp);
622 kgsl_sharedmem_readl(&device->memstore, &bad_context,
623 KGSL_DEVICE_MEMSTORE_OFFSET(current_context));
624 kgsl_sharedmem_readl(&device->memstore, &reftimestamp,
625 KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts));
626 kgsl_sharedmem_readl(&device->memstore, &enable_ts,
627 KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable));
628 kgsl_sharedmem_readl(&device->memstore, &soptimestamp,
629 KGSL_DEVICE_MEMSTORE_OFFSET(soptimestamp));
630 kgsl_sharedmem_readl(&device->memstore, &eoptimestamp,
631 KGSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp));
632 /* Make sure memory is synchronized before restarting the GPU */
633 mb();
634 KGSL_CTXT_ERR(device,
635 "Context that caused a GPU hang: %x\n", bad_context);
636 /* restart device */
637 ret = adreno_stop(device);
638 if (ret)
639 goto done;
640 ret = adreno_start(device, true);
641 if (ret)
642 goto done;
643 KGSL_DRV_ERR(device, "Device has been restarted after hang\n");
644 /* Restore timestamp states */
645 kgsl_sharedmem_writel(&device->memstore,
646 KGSL_DEVICE_MEMSTORE_OFFSET(soptimestamp),
647 soptimestamp);
648 kgsl_sharedmem_writel(&device->memstore,
649 KGSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp),
650 eoptimestamp);
651 kgsl_sharedmem_writel(&device->memstore,
652 KGSL_DEVICE_MEMSTORE_OFFSET(soptimestamp),
653 soptimestamp);
654 if (num_rb_contents) {
655 kgsl_sharedmem_writel(&device->memstore,
656 KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts),
657 reftimestamp);
658 kgsl_sharedmem_writel(&device->memstore,
659 KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable),
660 enable_ts);
661 }
662 /* Make sure all writes are posted before the GPU reads them */
663 wmb();
664 /* Mark the invalid context so no more commands are accepted from
665 * that context */
666
667 drawctxt = (struct adreno_context *) bad_context;
668
669 KGSL_CTXT_ERR(device,
670 "Context that caused a GPU hang: %x\n", bad_context);
671
672 drawctxt->flags |= CTXT_FLAGS_GPU_HANG;
673
674 /* Restore valid commands in ringbuffer */
675 adreno_ringbuffer_restore(rb, rb_buffer, num_rb_contents);
676 rb->timestamp = timestamp;
677done:
678 vfree(rb_buffer);
679 return ret;
680}
681
682static int
683adreno_dump_and_recover(struct kgsl_device *device)
684{
685 static int recovery;
686 int result = -ETIMEDOUT;
687
688 if (device->state == KGSL_STATE_HUNG)
689 goto done;
690 if (device->state == KGSL_STATE_DUMP_AND_RECOVER && !recovery) {
691 mutex_unlock(&device->mutex);
692 wait_for_completion(&device->recovery_gate);
693 mutex_lock(&device->mutex);
694 if (!(device->state & KGSL_STATE_HUNG))
695 /* recovery success */
696 result = 0;
697 } else {
698 INIT_COMPLETION(device->recovery_gate);
699 /* Detected a hang - trigger an automatic dump */
700 adreno_postmortem_dump(device, 0);
701 if (!recovery) {
702 recovery = 1;
703 result = adreno_recover_hang(device);
704 if (result)
705 device->state = KGSL_STATE_HUNG;
706 recovery = 0;
707 complete_all(&device->recovery_gate);
708 } else
709 KGSL_DRV_ERR(device,
710 "Cannot recover from another hang while "
711 "recovering from a hang\n");
712 }
713done:
714 return result;
715}
716
717static int adreno_getproperty(struct kgsl_device *device,
718 enum kgsl_property_type type,
719 void *value,
720 unsigned int sizebytes)
721{
722 int status = -EINVAL;
723 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
724
725 switch (type) {
726 case KGSL_PROP_DEVICE_INFO:
727 {
728 struct kgsl_devinfo devinfo;
729
730 if (sizebytes != sizeof(devinfo)) {
731 status = -EINVAL;
732 break;
733 }
734
735 memset(&devinfo, 0, sizeof(devinfo));
736 devinfo.device_id = device->id+1;
737 devinfo.chip_id = adreno_dev->chip_id;
738 devinfo.mmu_enabled = kgsl_mmu_enabled();
739 devinfo.gpu_id = adreno_dev->gpurev;
740 devinfo.gmem_gpubaseaddr = adreno_dev->gmemspace.
741 gpu_base;
742 devinfo.gmem_sizebytes = adreno_dev->gmemspace.
743 sizebytes;
744
745 if (copy_to_user(value, &devinfo, sizeof(devinfo)) !=
746 0) {
747 status = -EFAULT;
748 break;
749 }
750 status = 0;
751 }
752 break;
753 case KGSL_PROP_DEVICE_SHADOW:
754 {
755 struct kgsl_shadowprop shadowprop;
756
757 if (sizebytes != sizeof(shadowprop)) {
758 status = -EINVAL;
759 break;
760 }
761 memset(&shadowprop, 0, sizeof(shadowprop));
762 if (device->memstore.hostptr) {
763 /*NOTE: with mmu enabled, gpuaddr doesn't mean
764 * anything to mmap().
765 */
766 shadowprop.gpuaddr = device->memstore.physaddr;
767 shadowprop.size = device->memstore.size;
768 /* GSL needs this to be set, even if it
769 appears to be meaningless */
770 shadowprop.flags = KGSL_FLAGS_INITIALIZED;
771 }
772 if (copy_to_user(value, &shadowprop,
773 sizeof(shadowprop))) {
774 status = -EFAULT;
775 break;
776 }
777 status = 0;
778 }
779 break;
780 case KGSL_PROP_MMU_ENABLE:
781 {
782#ifdef CONFIG_MSM_KGSL_MMU
783 int mmuProp = 1;
784#else
785 int mmuProp = 0;
786#endif
787 if (sizebytes != sizeof(int)) {
788 status = -EINVAL;
789 break;
790 }
791 if (copy_to_user(value, &mmuProp, sizeof(mmuProp))) {
792 status = -EFAULT;
793 break;
794 }
795 status = 0;
796 }
797 break;
798 case KGSL_PROP_INTERRUPT_WAITS:
799 {
800 int int_waits = 1;
801 if (sizebytes != sizeof(int)) {
802 status = -EINVAL;
803 break;
804 }
805 if (copy_to_user(value, &int_waits, sizeof(int))) {
806 status = -EFAULT;
807 break;
808 }
809 status = 0;
810 }
811 break;
812 default:
813 status = -EINVAL;
814 }
815
816 return status;
817}
818
819/* Caller must hold the device mutex. */
820int adreno_idle(struct kgsl_device *device, unsigned int timeout)
821{
822 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
823 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
824 unsigned int rbbm_status;
825 unsigned long wait_time = jiffies + MAX_WAITGPU_SECS;
826
827 kgsl_cffdump_regpoll(device->id, REG_RBBM_STATUS << 2,
828 0x00000000, 0x80000000);
829 /* first, wait until the CP has consumed all the commands in
830 * the ring buffer
831 */
832retry:
833 if (rb->flags & KGSL_FLAGS_STARTED) {
834 do {
835 GSL_RB_GET_READPTR(rb, &rb->rptr);
836 if (time_after(jiffies, wait_time)) {
837 KGSL_DRV_ERR(device, "rptr: %x, wptr: %x\n",
838 rb->rptr, rb->wptr);
839 goto err;
840 }
841 } while (rb->rptr != rb->wptr);
842 }
843
844 /* now, wait for the GPU to finish its operations */
845 wait_time = jiffies + MAX_WAITGPU_SECS;
846 while (time_before(jiffies, wait_time)) {
847 adreno_regread(device, REG_RBBM_STATUS, &rbbm_status);
848 if (rbbm_status == 0x110)
849 return 0;
850 }
851
852err:
853 KGSL_DRV_ERR(device, "spun too long waiting for RB to idle\n");
854 if (!adreno_dump_and_recover(device)) {
855 wait_time = jiffies + MAX_WAITGPU_SECS;
856 goto retry;
857 }
858 return -ETIMEDOUT;
859}
860
861static unsigned int adreno_isidle(struct kgsl_device *device)
862{
863 int status = false;
864 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
865 struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
866 unsigned int rbbm_status;
867
868 if (rb->flags & KGSL_FLAGS_STARTED) {
869 /* Is the ring buffer is empty? */
870 GSL_RB_GET_READPTR(rb, &rb->rptr);
871 if (!device->active_cnt && (rb->rptr == rb->wptr)) {
872 /* Is the core idle? */
873 adreno_regread(device, REG_RBBM_STATUS,
874 &rbbm_status);
875 if (rbbm_status == 0x110)
876 status = true;
877 }
878 } else {
879 KGSL_DRV_ERR(device, "ringbuffer not started\n");
880 BUG();
881 }
882 return status;
883}
884
885/* Caller must hold the device mutex. */
886static int adreno_suspend_context(struct kgsl_device *device)
887{
888 int status = 0;
889 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
890
891 /* switch to NULL ctxt */
892 if (adreno_dev->drawctxt_active != NULL) {
893 adreno_drawctxt_switch(adreno_dev, NULL, 0);
894 status = adreno_idle(device, KGSL_TIMEOUT_DEFAULT);
895 }
896
897 return status;
898}
899
900uint8_t *kgsl_sharedmem_convertaddr(struct kgsl_device *device,
901 unsigned int pt_base, unsigned int gpuaddr, unsigned int *size)
902{
903 uint8_t *result = NULL;
904 struct kgsl_mem_entry *entry;
905 struct kgsl_process_private *priv;
906 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
907 struct adreno_ringbuffer *ringbuffer = &adreno_dev->ringbuffer;
908
909 if (kgsl_gpuaddr_in_memdesc(&ringbuffer->buffer_desc, gpuaddr)) {
910 return kgsl_gpuaddr_to_vaddr(&ringbuffer->buffer_desc,
911 gpuaddr, size);
912 }
913
914 if (kgsl_gpuaddr_in_memdesc(&ringbuffer->memptrs_desc, gpuaddr)) {
915 return kgsl_gpuaddr_to_vaddr(&ringbuffer->memptrs_desc,
916 gpuaddr, size);
917 }
918
919 if (kgsl_gpuaddr_in_memdesc(&device->memstore, gpuaddr)) {
920 return kgsl_gpuaddr_to_vaddr(&device->memstore,
921 gpuaddr, size);
922 }
923
924 mutex_lock(&kgsl_driver.process_mutex);
925 list_for_each_entry(priv, &kgsl_driver.process_list, list) {
926 if (pt_base != 0
927 && priv->pagetable
928 && priv->pagetable->base.gpuaddr != pt_base) {
929 continue;
930 }
931
932 spin_lock(&priv->mem_lock);
933 entry = kgsl_sharedmem_find_region(priv, gpuaddr,
934 sizeof(unsigned int));
935 if (entry) {
936 result = kgsl_gpuaddr_to_vaddr(&entry->memdesc,
937 gpuaddr, size);
938 spin_unlock(&priv->mem_lock);
939 mutex_unlock(&kgsl_driver.process_mutex);
940 return result;
941 }
942 spin_unlock(&priv->mem_lock);
943 }
944 mutex_unlock(&kgsl_driver.process_mutex);
945
946 BUG_ON(!mutex_is_locked(&device->mutex));
947 list_for_each_entry(entry, &device->memqueue, list) {
948 if (kgsl_gpuaddr_in_memdesc(&entry->memdesc, gpuaddr)) {
949 result = kgsl_gpuaddr_to_vaddr(&entry->memdesc,
950 gpuaddr, size);
951 break;
952 }
953
954 }
955 return result;
956}
957
958void adreno_regread(struct kgsl_device *device, unsigned int offsetwords,
959 unsigned int *value)
960{
961 unsigned int *reg;
962 BUG_ON(offsetwords*sizeof(uint32_t) >= device->regspace.sizebytes);
963 reg = (unsigned int *)(device->regspace.mmio_virt_base
964 + (offsetwords << 2));
965
966 if (!in_interrupt())
967 kgsl_pre_hwaccess(device);
968
969 /*ensure this read finishes before the next one.
970 * i.e. act like normal readl() */
971 *value = __raw_readl(reg);
972 rmb();
973}
974
975void adreno_regwrite(struct kgsl_device *device, unsigned int offsetwords,
976 unsigned int value)
977{
978 unsigned int *reg;
979
980 BUG_ON(offsetwords*sizeof(uint32_t) >= device->regspace.sizebytes);
981
982 if (!in_interrupt())
983 kgsl_pre_hwaccess(device);
984
985 kgsl_cffdump_regwrite(device->id, offsetwords << 2, value);
986 reg = (unsigned int *)(device->regspace.mmio_virt_base
987 + (offsetwords << 2));
988
989 /*ensure previous writes post before this one,
990 * i.e. act like normal writel() */
991 wmb();
992 __raw_writel(value, reg);
993}
994
995static int kgsl_check_interrupt_timestamp(struct kgsl_device *device,
996 unsigned int timestamp)
997{
998 int status;
999 unsigned int ref_ts, enableflag;
1000
1001 status = kgsl_check_timestamp(device, timestamp);
1002 if (!status) {
1003 mutex_lock(&device->mutex);
1004 kgsl_sharedmem_readl(&device->memstore, &enableflag,
1005 KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable));
1006 mb();
1007
1008 if (enableflag) {
1009 kgsl_sharedmem_readl(&device->memstore, &ref_ts,
1010 KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts));
1011 mb();
1012 if (timestamp_cmp(ref_ts, timestamp)) {
1013 kgsl_sharedmem_writel(&device->memstore,
1014 KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts),
1015 timestamp);
1016 wmb();
1017 }
1018 } else {
1019 unsigned int cmds[2];
1020 kgsl_sharedmem_writel(&device->memstore,
1021 KGSL_DEVICE_MEMSTORE_OFFSET(ref_wait_ts),
1022 timestamp);
1023 enableflag = 1;
1024 kgsl_sharedmem_writel(&device->memstore,
1025 KGSL_DEVICE_MEMSTORE_OFFSET(ts_cmp_enable),
1026 enableflag);
1027 wmb();
1028 /* submit a dummy packet so that even if all
1029 * commands upto timestamp get executed we will still
1030 * get an interrupt */
1031 cmds[0] = pm4_type3_packet(PM4_NOP, 1);
1032 cmds[1] = 0;
1033 adreno_ringbuffer_issuecmds(device, 0, &cmds[0], 2);
1034 }
1035 mutex_unlock(&device->mutex);
1036 }
1037
1038 return status;
1039}
1040
1041/*
1042 wait_io_event_interruptible_timeout checks for the exit condition before
1043 placing a process in wait q. For conditional interrupts we expect the
1044 process to already be in its wait q when its exit condition checking
1045 function is called.
1046*/
1047#define kgsl_wait_io_event_interruptible_timeout(wq, condition, timeout)\
1048({ \
1049 long __ret = timeout; \
1050 __wait_io_event_interruptible_timeout(wq, condition, __ret); \
1051 __ret; \
1052})
1053
1054/* MUST be called with the device mutex held */
1055static int adreno_waittimestamp(struct kgsl_device *device,
1056 unsigned int timestamp,
1057 unsigned int msecs)
1058{
1059 long status = 0;
1060 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1061
1062 if (timestamp != adreno_dev->ringbuffer.timestamp &&
1063 timestamp_cmp(timestamp,
1064 adreno_dev->ringbuffer.timestamp)) {
1065 KGSL_DRV_ERR(device, "Cannot wait for invalid ts: %x, "
1066 "rb->timestamp: %x\n",
1067 timestamp, adreno_dev->ringbuffer.timestamp);
1068 status = -EINVAL;
1069 goto done;
1070 }
1071 if (!kgsl_check_timestamp(device, timestamp)) {
1072 mutex_unlock(&device->mutex);
1073 /* We need to make sure that the process is placed in wait-q
1074 * before its condition is called */
1075 status = kgsl_wait_io_event_interruptible_timeout(
1076 device->wait_queue,
1077 kgsl_check_interrupt_timestamp(device,
1078 timestamp), msecs_to_jiffies(msecs));
1079 mutex_lock(&device->mutex);
1080
1081 if (status > 0)
1082 status = 0;
1083 else if (status == 0) {
1084 if (!kgsl_check_timestamp(device, timestamp)) {
1085 status = -ETIMEDOUT;
1086 KGSL_DRV_ERR(device,
1087 "Device hang detected while waiting "
1088 "for timestamp: %x, last "
1089 "submitted(rb->timestamp): %x, wptr: "
1090 "%x\n", timestamp,
1091 adreno_dev->ringbuffer.timestamp,
1092 adreno_dev->ringbuffer.wptr);
1093 if (!adreno_dump_and_recover(device)) {
1094 /* wait for idle after recovery as the
1095 * timestamp that this process wanted
1096 * to wait on may be invalid */
1097 if (!adreno_idle(device,
1098 KGSL_TIMEOUT_DEFAULT))
1099 status = 0;
1100 }
1101 }
1102 }
1103 }
1104
1105done:
1106 return (int)status;
1107}
1108
1109static unsigned int adreno_readtimestamp(struct kgsl_device *device,
1110 enum kgsl_timestamp_type type)
1111{
1112 unsigned int timestamp = 0;
1113
1114 if (type == KGSL_TIMESTAMP_CONSUMED)
1115 adreno_regread(device, REG_CP_TIMESTAMP, &timestamp);
1116 else if (type == KGSL_TIMESTAMP_RETIRED)
1117 kgsl_sharedmem_readl(&device->memstore, &timestamp,
1118 KGSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp));
1119 rmb();
1120
1121 return timestamp;
1122}
1123
1124static long adreno_ioctl(struct kgsl_device_private *dev_priv,
1125 unsigned int cmd, void *data)
1126{
1127 int result = 0;
1128 struct kgsl_drawctxt_set_bin_base_offset *binbase;
1129 struct kgsl_context *context;
1130
1131 switch (cmd) {
1132 case IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET:
1133 binbase = data;
1134
1135 context = kgsl_find_context(dev_priv, binbase->drawctxt_id);
1136 if (context) {
1137 adreno_drawctxt_set_bin_base_offset(
1138 dev_priv->device, context, binbase->offset);
1139 } else {
1140 result = -EINVAL;
1141 KGSL_DRV_ERR(dev_priv->device,
1142 "invalid drawctxt drawctxt_id %d "
1143 "device_id=%d\n",
1144 binbase->drawctxt_id, dev_priv->device->id);
1145 }
1146 break;
1147
1148 default:
1149 KGSL_DRV_INFO(dev_priv->device,
1150 "invalid ioctl code %08x\n", cmd);
1151 result = -EINVAL;
1152 break;
1153 }
1154 return result;
1155
1156}
1157
1158static inline s64 adreno_ticks_to_us(u32 ticks, u32 gpu_freq)
1159{
1160 gpu_freq /= 1000000;
1161 return ticks / gpu_freq;
1162}
1163
1164static void adreno_power_stats(struct kgsl_device *device,
1165 struct kgsl_power_stats *stats)
1166{
1167 unsigned int reg;
1168 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
1169
1170 /* In order to calculate idle you have to have run the algorithm *
1171 * at least once to get a start time. */
1172 if (pwr->time != 0) {
1173 s64 tmp;
1174 /* Stop the performance moniter and read the current *
1175 * busy cycles. */
1176 adreno_regwrite(device,
1177 REG_CP_PERFMON_CNTL,
1178 REG_PERF_MODE_CNT |
1179 REG_PERF_STATE_FREEZE);
1180 adreno_regread(device, REG_RBBM_PERFCOUNTER1_LO, &reg);
1181 tmp = ktime_to_us(ktime_get());
1182 stats->total_time = tmp - pwr->time;
1183 pwr->time = tmp;
1184 stats->busy_time = adreno_ticks_to_us(reg, device->pwrctrl.
1185 pwrlevels[device->pwrctrl.active_pwrlevel].
1186 gpu_freq);
1187
1188 adreno_regwrite(device,
1189 REG_CP_PERFMON_CNTL,
1190 REG_PERF_MODE_CNT |
1191 REG_PERF_STATE_RESET);
1192 } else {
1193 stats->total_time = 0;
1194 stats->busy_time = 0;
1195 pwr->time = ktime_to_us(ktime_get());
1196 }
1197
1198 /* re-enable the performance moniters */
1199 adreno_regread(device, REG_RBBM_PM_OVERRIDE2, &reg);
1200 adreno_regwrite(device, REG_RBBM_PM_OVERRIDE2, (reg | 0x40));
1201 adreno_regwrite(device, REG_RBBM_PERFCOUNTER1_SELECT, 0x1);
1202 adreno_regwrite(device,
1203 REG_CP_PERFMON_CNTL,
1204 REG_PERF_MODE_CNT | REG_PERF_STATE_ENABLE);
1205}
1206
1207void adreno_irqctrl(struct kgsl_device *device, int state)
1208{
Jordan Crousea78c9172011-07-11 13:14:09 -06001209 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1210 adreno_dev->gpudev->irq_control(adreno_dev, state);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001211}
1212
1213static const struct kgsl_functable adreno_functable = {
1214 /* Mandatory functions */
1215 .regread = adreno_regread,
1216 .regwrite = adreno_regwrite,
1217 .idle = adreno_idle,
1218 .isidle = adreno_isidle,
1219 .suspend_context = adreno_suspend_context,
1220 .start = adreno_start,
1221 .stop = adreno_stop,
1222 .getproperty = adreno_getproperty,
1223 .waittimestamp = adreno_waittimestamp,
1224 .readtimestamp = adreno_readtimestamp,
1225 .issueibcmds = adreno_ringbuffer_issueibcmds,
1226 .ioctl = adreno_ioctl,
1227 .setup_pt = adreno_setup_pt,
1228 .cleanup_pt = adreno_cleanup_pt,
1229 .power_stats = adreno_power_stats,
1230 .irqctrl = adreno_irqctrl,
1231 /* Optional functions */
1232 .setstate = adreno_setstate,
1233 .drawctxt_create = adreno_drawctxt_create,
1234 .drawctxt_destroy = adreno_drawctxt_destroy,
1235};
1236
1237static struct platform_device_id adreno_id_table[] = {
1238 { DEVICE_3D0_NAME, (kernel_ulong_t)&device_3d0.dev, },
1239 { },
1240};
1241MODULE_DEVICE_TABLE(platform, adreno_id_table);
1242
1243static struct platform_driver adreno_platform_driver = {
1244 .probe = adreno_probe,
1245 .remove = __devexit_p(adreno_remove),
1246 .suspend = kgsl_suspend_driver,
1247 .resume = kgsl_resume_driver,
1248 .id_table = adreno_id_table,
1249 .driver = {
1250 .owner = THIS_MODULE,
1251 .name = DEVICE_3D_NAME,
1252 .pm = &kgsl_pm_ops,
1253 }
1254};
1255
1256static int __init kgsl_3d_init(void)
1257{
1258 return platform_driver_register(&adreno_platform_driver);
1259}
1260
1261static void __exit kgsl_3d_exit(void)
1262{
1263 platform_driver_unregister(&adreno_platform_driver);
1264}
1265
1266module_init(kgsl_3d_init);
1267module_exit(kgsl_3d_exit);
1268
1269MODULE_DESCRIPTION("3D Graphics driver");
1270MODULE_VERSION("1.2");
1271MODULE_LICENSE("GPL v2");
1272MODULE_ALIAS("platform:kgsl_3d");