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