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