blob: 8ddc991630adb08600971d5941560fb84b742b84 [file] [log] [blame]
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -07001/* Copyright (c) 2002,2007-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
Steve Mucklef132c6c2012-06-06 18:30:57 -070013#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070014#include <linux/uaccess.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070015#include <linux/sched.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070016
17#include "kgsl.h"
18#include "kgsl_cffdump.h"
19#include "kgsl_sharedmem.h"
20
21#include "z180.h"
22#include "z180_reg.h"
Norman Geed7402ff2011-10-28 08:51:11 -060023#include "z180_trace.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024
25#define DRIVER_VERSION_MAJOR 3
26#define DRIVER_VERSION_MINOR 1
27
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#define GSL_VGC_INT_MASK \
29 (REG_VGC_IRQSTATUS__MH_MASK | \
30 REG_VGC_IRQSTATUS__G2D_MASK | \
31 REG_VGC_IRQSTATUS__FIFO_MASK)
32
33#define VGV3_NEXTCMD_JUMP 0x01
34
35#define VGV3_NEXTCMD_NEXTCMD_FSHIFT 12
36#define VGV3_NEXTCMD_NEXTCMD_FMASK 0x7
37
38#define VGV3_CONTROL_MARKADD_FSHIFT 0
39#define VGV3_CONTROL_MARKADD_FMASK 0xfff
40
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#define Z180_MARKER_SIZE 10
42#define Z180_CALL_CMD 0x1000
43#define Z180_MARKER_CMD 0x8000
44#define Z180_STREAM_END_CMD 0x9000
45#define Z180_STREAM_PACKET 0x7C000176
46#define Z180_STREAM_PACKET_CALL 0x7C000275
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047
48#define NUMTEXUNITS 4
49#define TEXUNITREGCOUNT 25
50#define VG_REGCOUNT 0x39
51
52#define PACKETSIZE_BEGIN 3
53#define PACKETSIZE_G2DCOLOR 2
54#define PACKETSIZE_TEXUNIT (TEXUNITREGCOUNT * 2)
55#define PACKETSIZE_REG (VG_REGCOUNT * 2)
56#define PACKETSIZE_STATE (PACKETSIZE_TEXUNIT * NUMTEXUNITS + \
57 PACKETSIZE_REG + PACKETSIZE_BEGIN + \
58 PACKETSIZE_G2DCOLOR)
59#define PACKETSIZE_STATESTREAM (ALIGN((PACKETSIZE_STATE * \
60 sizeof(unsigned int)), 32) / \
61 sizeof(unsigned int))
62
63#define Z180_INVALID_CONTEXT UINT_MAX
64
65/* z180 MH arbiter config*/
66#define Z180_CFG_MHARB \
67 (0x10 \
68 | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \
69 | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \
70 | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \
71 | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \
72 | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \
73 | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \
74 | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \
75 | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \
76 | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \
77 | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \
78 | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \
79 | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \
80 | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \
81 | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT))
82
83#define Z180_TIMESTAMP_EPSILON 20000
84#define Z180_IDLE_COUNT_MAX 1000000
85
86enum z180_cmdwindow_type {
87 Z180_CMDWINDOW_2D = 0x00000000,
88 Z180_CMDWINDOW_MMU = 0x00000002,
89};
90
91#define Z180_CMDWINDOW_TARGET_MASK 0x000000FF
92#define Z180_CMDWINDOW_ADDR_MASK 0x00FFFF00
93#define Z180_CMDWINDOW_TARGET_SHIFT 0
94#define Z180_CMDWINDOW_ADDR_SHIFT 8
95
96static int z180_start(struct kgsl_device *device, unsigned int init_ram);
97static int z180_stop(struct kgsl_device *device);
98static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -070099 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700100 unsigned int timestamp,
101 unsigned int msecs);
102static void z180_regread(struct kgsl_device *device,
103 unsigned int offsetwords,
104 unsigned int *value);
105static void z180_regwrite(struct kgsl_device *device,
106 unsigned int offsetwords,
107 unsigned int value);
108static void z180_cmdwindow_write(struct kgsl_device *device,
109 unsigned int addr,
110 unsigned int data);
111
112#define Z180_MMU_CONFIG \
113 (0x01 \
114 | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \
115 | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \
116 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \
117 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \
118 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \
119 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \
120 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \
121 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \
122 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \
123 | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \
124 | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT))
125
126static const struct kgsl_functable z180_functable;
127
128static struct z180_device device_2d0 = {
129 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700130 KGSL_DEVICE_COMMON_INIT(device_2d0.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131 .name = DEVICE_2D0_NAME,
132 .id = KGSL_DEVICE_2D0,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600133 .mh = {
134 .mharb = Z180_CFG_MHARB,
135 .mh_intf_cfg1 = 0x00032f07,
136 .mh_intf_cfg2 = 0x004b274f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137 /* turn off memory protection unit by setting
138 acceptable physical address range to include
139 all pages. */
140 .mpu_base = 0x00000000,
141 .mpu_range = 0xFFFFF000,
142 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600143 .mmu = {
144 .config = Z180_MMU_CONFIG,
145 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 .irq_name = KGSL_2D0_IRQ,
148 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149 .iomemname = KGSL_2D0_REG_MEMORY,
150 .ftbl = &z180_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151 },
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700152 .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700153};
154
155static struct z180_device device_2d1 = {
156 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700157 KGSL_DEVICE_COMMON_INIT(device_2d1.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158 .name = DEVICE_2D1_NAME,
159 .id = KGSL_DEVICE_2D1,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600160 .mh = {
161 .mharb = Z180_CFG_MHARB,
162 .mh_intf_cfg1 = 0x00032f07,
163 .mh_intf_cfg2 = 0x004b274f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164 /* turn off memory protection unit by setting
165 acceptable physical address range to include
166 all pages. */
167 .mpu_base = 0x00000000,
168 .mpu_range = 0xFFFFF000,
169 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600170 .mmu = {
171 .config = Z180_MMU_CONFIG,
172 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 .irq_name = KGSL_2D1_IRQ,
175 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176 .iomemname = KGSL_2D1_REG_MEMORY,
177 .ftbl = &z180_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 },
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700179 .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180};
181
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600182static irqreturn_t z180_irq_handler(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183{
184 irqreturn_t result = IRQ_NONE;
185 unsigned int status;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 struct z180_device *z180_dev = Z180_DEVICE(device);
187
188 z180_regread(device, ADDR_VGC_IRQSTATUS >> 2, &status);
189
Norman Geed7402ff2011-10-28 08:51:11 -0600190 trace_kgsl_z180_irq_status(device, status);
191
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192 if (status & GSL_VGC_INT_MASK) {
193 z180_regwrite(device,
194 ADDR_VGC_IRQSTATUS >> 2, status & GSL_VGC_INT_MASK);
195
196 result = IRQ_HANDLED;
197
198 if (status & REG_VGC_IRQSTATUS__FIFO_MASK)
199 KGSL_DRV_ERR(device, "z180 fifo interrupt\n");
200 if (status & REG_VGC_IRQSTATUS__MH_MASK)
201 kgsl_mh_intrcallback(device);
202 if (status & REG_VGC_IRQSTATUS__G2D_MASK) {
203 int count;
204
205 z180_regread(device,
206 ADDR_VGC_IRQ_ACTIVE_CNT >> 2,
207 &count);
208
209 count >>= 8;
210 count &= 255;
211 z180_dev->timestamp += count;
212
Jordan Crouse1bf80aa2011-10-12 16:57:47 -0600213 queue_work(device->work_queue, &device->ts_expired_ws);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700214 wake_up_interruptible(&device->wait_queue);
215
216 atomic_notifier_call_chain(
217 &(device->ts_notifier_list),
218 device->id, NULL);
219 }
220 }
221
222 if ((device->pwrctrl.nap_allowed == true) &&
223 (device->requested_state == KGSL_STATE_NONE)) {
Jeremy Gebben388c2972011-12-16 09:05:07 -0700224 kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225 queue_work(device->work_queue, &device->idle_check_ws);
226 }
Tarun Karra68755762012-01-12 16:07:09 -0800227 mod_timer_pending(&device->idle_timer,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700228 jiffies + device->pwrctrl.interval_timeout);
229
230 return result;
231}
232
Jordan Crouse9f739212011-07-28 08:37:57 -0600233static void z180_cleanup_pt(struct kgsl_device *device,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234 struct kgsl_pagetable *pagetable)
235{
236 struct z180_device *z180_dev = Z180_DEVICE(device);
237
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600238 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239
240 kgsl_mmu_unmap(pagetable, &device->memstore);
241
242 kgsl_mmu_unmap(pagetable, &z180_dev->ringbuffer.cmdbufdesc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700243}
244
245static int z180_setup_pt(struct kgsl_device *device,
246 struct kgsl_pagetable *pagetable)
247{
248 int result = 0;
249 struct z180_device *z180_dev = Z180_DEVICE(device);
250
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600251 result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700252 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
253
254 if (result)
255 goto error;
256
257 result = kgsl_mmu_map_global(pagetable, &device->memstore,
258 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
259 if (result)
260 goto error_unmap_dummy;
261
262 result = kgsl_mmu_map_global(pagetable,
263 &z180_dev->ringbuffer.cmdbufdesc,
264 GSL_PT_PAGE_RV);
265 if (result)
266 goto error_unmap_memstore;
267 return result;
268
269error_unmap_dummy:
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600270 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700271
272error_unmap_memstore:
273 kgsl_mmu_unmap(pagetable, &device->memstore);
274
275error:
276 return result;
277}
278
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600279static inline unsigned int rb_offset(unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280{
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600281 return (timestamp % Z180_PACKET_COUNT)
282 *sizeof(unsigned int)*(Z180_PACKET_SIZE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283}
284
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600285static inline unsigned int rb_gpuaddr(struct z180_device *z180_dev,
286 unsigned int timestamp)
287{
288 return z180_dev->ringbuffer.cmdbufdesc.gpuaddr + rb_offset(timestamp);
289}
290
291static void addmarker(struct z180_ringbuffer *rb, unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700292{
293 char *ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600294 unsigned int *p = (unsigned int *)(ptr + rb_offset(timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295
296 *p++ = Z180_STREAM_PACKET;
297 *p++ = (Z180_MARKER_CMD | 5);
298 *p++ = ADDR_VGV3_LAST << 24;
299 *p++ = ADDR_VGV3_LAST << 24;
300 *p++ = ADDR_VGV3_LAST << 24;
301 *p++ = Z180_STREAM_PACKET;
302 *p++ = 5;
303 *p++ = ADDR_VGV3_LAST << 24;
304 *p++ = ADDR_VGV3_LAST << 24;
305 *p++ = ADDR_VGV3_LAST << 24;
306}
307
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600308static void addcmd(struct z180_ringbuffer *rb, unsigned int timestamp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700309 unsigned int cmd, unsigned int nextcnt)
310{
311 char * ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600312 unsigned int *p = (unsigned int *)(ptr + (rb_offset(timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700313 + (Z180_MARKER_SIZE * sizeof(unsigned int))));
314
315 *p++ = Z180_STREAM_PACKET_CALL;
316 *p++ = cmd;
317 *p++ = Z180_CALL_CMD | nextcnt;
318 *p++ = ADDR_VGV3_LAST << 24;
319 *p++ = ADDR_VGV3_LAST << 24;
320}
321
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700322static void z180_cmdstream_start(struct kgsl_device *device, int init_ram)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700323{
324 struct z180_device *z180_dev = Z180_DEVICE(device);
325 unsigned int cmd = VGV3_NEXTCMD_JUMP << VGV3_NEXTCMD_NEXTCMD_FSHIFT;
326
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700327 if (init_ram) {
328 z180_dev->timestamp = 0;
329 z180_dev->current_timestamp = 0;
330 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331
332 addmarker(&z180_dev->ringbuffer, 0);
333
334 z180_cmdwindow_write(device, ADDR_VGV3_MODE, 4);
335
336 z180_cmdwindow_write(device, ADDR_VGV3_NEXTADDR,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600337 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700338
339 z180_cmdwindow_write(device, ADDR_VGV3_NEXTCMD, cmd | 5);
340
341 z180_cmdwindow_write(device, ADDR_VGV3_WRITEADDR,
342 device->memstore.gpuaddr);
343
344 cmd = (int)(((1) & VGV3_CONTROL_MARKADD_FMASK)
345 << VGV3_CONTROL_MARKADD_FSHIFT);
346
347 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
348
349 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
350}
351
352static int room_in_rb(struct z180_device *device)
353{
354 int ts_diff;
355
356 ts_diff = device->current_timestamp - device->timestamp;
357
358 return ts_diff < Z180_PACKET_COUNT;
359}
360
Jordan Crousea29a2e02012-08-14 09:09:23 -0600361static int z180_idle(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700362{
363 int status = 0;
364 struct z180_device *z180_dev = Z180_DEVICE(device);
365
Jordan Crousee6239dd2011-11-17 13:39:21 -0700366 if (timestamp_cmp(z180_dev->current_timestamp,
367 z180_dev->timestamp) > 0)
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700368 status = z180_wait(device, NULL,
Jordan Crousea29a2e02012-08-14 09:09:23 -0600369 z180_dev->current_timestamp,
370 Z180_IDLE_TIMEOUT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700371
372 if (status)
373 KGSL_DRV_ERR(device, "z180_waittimestamp() timed out\n");
374
375 return status;
376}
377
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700378int
379z180_cmdstream_issueibcmds(struct kgsl_device_private *dev_priv,
380 struct kgsl_context *context,
381 struct kgsl_ibdesc *ibdesc,
382 unsigned int numibs,
383 uint32_t *timestamp,
384 unsigned int ctrl)
385{
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700386 long result = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700387 unsigned int ofs = PACKETSIZE_STATESTREAM * sizeof(unsigned int);
388 unsigned int cnt = 5;
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600389 unsigned int old_timestamp = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700390 unsigned int nextcnt = Z180_STREAM_END_CMD | 5;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600391 struct kgsl_mem_entry *entry = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700392 unsigned int cmd;
393 struct kgsl_device *device = dev_priv->device;
394 struct kgsl_pagetable *pagetable = dev_priv->process_priv->pagetable;
395 struct z180_device *z180_dev = Z180_DEVICE(device);
396 unsigned int sizedwords;
397
398 if (device->state & KGSL_STATE_HUNG) {
Carter Cooperb90880d2011-10-26 14:38:02 -0600399 result = -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700400 goto error;
401 }
402 if (numibs != 1) {
403 KGSL_DRV_ERR(device, "Invalid number of ibs: %d\n", numibs);
404 result = -EINVAL;
405 goto error;
406 }
407 cmd = ibdesc[0].gpuaddr;
408 sizedwords = ibdesc[0].sizedwords;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600409 /*
410 * Get a kernel mapping to the IB for monkey patching.
411 * See the end of this function.
412 */
413 entry = kgsl_sharedmem_find_region(dev_priv->process_priv, cmd,
414 sizedwords);
415 if (entry == NULL) {
416 KGSL_DRV_ERR(device, "Bad ibdesc: gpuaddr 0x%x size %d\n",
417 cmd, sizedwords);
418 result = -EINVAL;
419 goto error;
420 }
421 /*
422 * This will only map memory if it exists, otherwise it will reuse the
423 * mapping. And the 2d userspace reuses IBs so we likely won't create
424 * too many mappings.
425 */
426 if (kgsl_gpuaddr_to_vaddr(&entry->memdesc, cmd) == NULL) {
427 KGSL_DRV_ERR(device,
428 "Cannot make kernel mapping for gpuaddr 0x%x\n",
429 cmd);
430 result = -EINVAL;
431 goto error;
432 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700433
434 KGSL_CMD_INFO(device, "ctxt %d ibaddr 0x%08x sizedwords %d\n",
435 context->id, cmd, sizedwords);
436 /* context switch */
437 if ((context->id != (int)z180_dev->ringbuffer.prevctx) ||
438 (ctrl & KGSL_CONTEXT_CTX_SWITCH)) {
439 KGSL_CMD_INFO(device, "context switch %d -> %d\n",
440 context->id, z180_dev->ringbuffer.prevctx);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600441 kgsl_mmu_setstate(&device->mmu, pagetable,
442 KGSL_MEMSTORE_GLOBAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700443 cnt = PACKETSIZE_STATESTREAM;
444 ofs = 0;
445 }
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600446 kgsl_setstate(&device->mmu,
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600447 KGSL_MEMSTORE_GLOBAL,
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600448 kgsl_mmu_pt_get_flags(device->mmu.hwpagetable,
449 device->id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700450
451 result = wait_event_interruptible_timeout(device->wait_queue,
452 room_in_rb(z180_dev),
453 msecs_to_jiffies(KGSL_TIMEOUT_DEFAULT));
454 if (result < 0) {
455 KGSL_CMD_ERR(device, "wait_event_interruptible_timeout "
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700456 "failed: %ld\n", result);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700457 goto error;
458 }
459 result = 0;
460
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600461 old_timestamp = z180_dev->current_timestamp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700462 z180_dev->current_timestamp++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463 *timestamp = z180_dev->current_timestamp;
464
465 z180_dev->ringbuffer.prevctx = context->id;
466
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600467 addcmd(&z180_dev->ringbuffer, old_timestamp, cmd + ofs, cnt);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700468 kgsl_pwrscale_busy(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700469
470 /* Make sure the next ringbuffer entry has a marker */
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600471 addmarker(&z180_dev->ringbuffer, z180_dev->current_timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600473 /* monkey patch the IB so that it jumps back to the ringbuffer */
474 kgsl_sharedmem_writel(&entry->memdesc,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600475 ((sizedwords + 1) * sizeof(unsigned int)),
476 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600477 kgsl_sharedmem_writel(&entry->memdesc,
478 ((sizedwords + 2) * sizeof(unsigned int)),
479 nextcnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480
481 /* sync memory before activating the hardware for the new command*/
482 mb();
483
484 cmd = (int)(((2) & VGV3_CONTROL_MARKADD_FMASK)
485 << VGV3_CONTROL_MARKADD_FSHIFT);
486
487 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
488 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
489error:
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700490 return (int)result;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491}
492
493static int z180_ringbuffer_init(struct kgsl_device *device)
494{
495 struct z180_device *z180_dev = Z180_DEVICE(device);
496 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
497 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
498 return kgsl_allocate_contiguous(&z180_dev->ringbuffer.cmdbufdesc,
499 Z180_RB_SIZE);
500}
501
502static void z180_ringbuffer_close(struct kgsl_device *device)
503{
504 struct z180_device *z180_dev = Z180_DEVICE(device);
505 kgsl_sharedmem_free(&z180_dev->ringbuffer.cmdbufdesc);
506 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
507}
508
509static int __devinit z180_probe(struct platform_device *pdev)
510{
511 int status = -EINVAL;
512 struct kgsl_device *device = NULL;
513 struct z180_device *z180_dev;
514
515 device = (struct kgsl_device *)pdev->id_entry->driver_data;
516 device->parentdev = &pdev->dev;
517
518 z180_dev = Z180_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700519
520 status = z180_ringbuffer_init(device);
521 if (status != 0)
522 goto error;
523
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600524 status = kgsl_device_platform_probe(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525 if (status)
526 goto error_close_ringbuffer;
527
Lucille Sylvester591ea032011-07-21 16:08:37 -0600528 kgsl_pwrscale_init(device);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700529 kgsl_pwrscale_attach_policy(device, Z180_DEFAULT_PWRSCALE_POLICY);
Lucille Sylvester591ea032011-07-21 16:08:37 -0600530
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531 return status;
532
533error_close_ringbuffer:
534 z180_ringbuffer_close(device);
535error:
536 device->parentdev = NULL;
537 return status;
538}
539
540static int __devexit z180_remove(struct platform_device *pdev)
541{
542 struct kgsl_device *device = NULL;
543
544 device = (struct kgsl_device *)pdev->id_entry->driver_data;
545
Lucille Sylvester591ea032011-07-21 16:08:37 -0600546 kgsl_pwrscale_close(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700547 kgsl_device_platform_remove(device);
548
549 z180_ringbuffer_close(device);
550
551 return 0;
552}
553
554static int z180_start(struct kgsl_device *device, unsigned int init_ram)
555{
556 int status = 0;
557
Jeremy Gebben388c2972011-12-16 09:05:07 -0700558 kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700559
560 kgsl_pwrctrl_enable(device);
561
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700562 /* Set interrupts to 0 to ensure a good state */
563 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0x0);
564
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600565 kgsl_mh_start(device);
566
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700567 status = kgsl_mmu_start(device);
568 if (status)
569 goto error_clk_off;
570
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700571 z180_cmdstream_start(device, init_ram);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700572
573 mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
Jeremy Gebbenb46f4152011-10-14 14:27:00 -0600574 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700575 device->ftbl->irqctrl(device, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 return 0;
577
578error_clk_off:
579 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
580 kgsl_pwrctrl_disable(device);
581 return status;
582}
583
584static int z180_stop(struct kgsl_device *device)
585{
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700586 device->ftbl->irqctrl(device, 0);
Jordan Crousea29a2e02012-08-14 09:09:23 -0600587 z180_idle(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588
Suman Tatiraju4a32c652012-02-17 11:59:05 -0800589 del_timer_sync(&device->idle_timer);
590
Shubhraprakash Das79447952012-04-26 18:12:23 -0600591 kgsl_mmu_stop(&device->mmu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592
593 /* Disable the clocks before the power rail. */
594 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
595
596 kgsl_pwrctrl_disable(device);
597
598 return 0;
599}
600
601static int z180_getproperty(struct kgsl_device *device,
602 enum kgsl_property_type type,
603 void *value,
604 unsigned int sizebytes)
605{
606 int status = -EINVAL;
607
608 switch (type) {
609 case KGSL_PROP_DEVICE_INFO:
610 {
611 struct kgsl_devinfo devinfo;
612
613 if (sizebytes != sizeof(devinfo)) {
614 status = -EINVAL;
615 break;
616 }
617
618 memset(&devinfo, 0, sizeof(devinfo));
619 devinfo.device_id = device->id+1;
620 devinfo.chip_id = 0;
621 devinfo.mmu_enabled = kgsl_mmu_enabled();
622
623 if (copy_to_user(value, &devinfo, sizeof(devinfo)) !=
624 0) {
625 status = -EFAULT;
626 break;
627 }
628 status = 0;
629 }
630 break;
631 case KGSL_PROP_MMU_ENABLE:
632 {
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600633 int mmu_prop = kgsl_mmu_enabled();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634 if (sizebytes != sizeof(int)) {
635 status = -EINVAL;
636 break;
637 }
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600638 if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 status = -EFAULT;
640 break;
641 }
642 status = 0;
643 }
644 break;
645
646 default:
647 KGSL_DRV_ERR(device, "invalid property: %d\n", type);
648 status = -EINVAL;
649 }
650 return status;
651}
652
653static unsigned int z180_isidle(struct kgsl_device *device)
654{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700655 struct z180_device *z180_dev = Z180_DEVICE(device);
656
Jordan Crousee6239dd2011-11-17 13:39:21 -0700657 return (timestamp_cmp(z180_dev->timestamp,
658 z180_dev->current_timestamp) == 0) ? true : false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659}
660
661static int z180_suspend_context(struct kgsl_device *device)
662{
663 struct z180_device *z180_dev = Z180_DEVICE(device);
664
665 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
666
667 return 0;
668}
669
670/* Not all Z180 registers are directly accessible.
671 * The _z180_(read|write)_simple functions below handle the ones that are.
672 */
673static void _z180_regread_simple(struct kgsl_device *device,
674 unsigned int offsetwords,
675 unsigned int *value)
676{
677 unsigned int *reg;
678
Jordan Crouse7501d452012-04-19 08:58:44 -0600679 BUG_ON(offsetwords * sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680
Jordan Crouse7501d452012-04-19 08:58:44 -0600681 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682
683 /*ensure this read finishes before the next one.
684 * i.e. act like normal readl() */
685 *value = __raw_readl(reg);
686 rmb();
687
688}
689
690static void _z180_regwrite_simple(struct kgsl_device *device,
691 unsigned int offsetwords,
692 unsigned int value)
693{
694 unsigned int *reg;
695
Jordan Crouse7501d452012-04-19 08:58:44 -0600696 BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700697
Jordan Crouse7501d452012-04-19 08:58:44 -0600698 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700699 kgsl_cffdump_regwrite(device->id, offsetwords << 2, value);
700 /*ensure previous writes post before this one,
701 * i.e. act like normal writel() */
702 wmb();
703 __raw_writel(value, reg);
704}
705
706
707/* The MH registers must be accessed through via a 2 step write, (read|write)
708 * process. These registers may be accessed from interrupt context during
709 * the handling of MH or MMU error interrupts. Therefore a spin lock is used
710 * to ensure that the 2 step sequence is not interrupted.
711 */
712static void _z180_regread_mmu(struct kgsl_device *device,
713 unsigned int offsetwords,
714 unsigned int *value)
715{
716 struct z180_device *z180_dev = Z180_DEVICE(device);
717 unsigned long flags;
718
719 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
720 _z180_regwrite_simple(device, (ADDR_VGC_MH_READ_ADDR >> 2),
721 offsetwords);
722 _z180_regread_simple(device, (ADDR_VGC_MH_DATA_ADDR >> 2), value);
723 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
724}
725
726
727static void _z180_regwrite_mmu(struct kgsl_device *device,
728 unsigned int offsetwords,
729 unsigned int value)
730{
731 struct z180_device *z180_dev = Z180_DEVICE(device);
732 unsigned int cmdwinaddr;
733 unsigned long flags;
734
735 cmdwinaddr = ((Z180_CMDWINDOW_MMU << Z180_CMDWINDOW_TARGET_SHIFT) &
736 Z180_CMDWINDOW_TARGET_MASK);
737 cmdwinaddr |= ((offsetwords << Z180_CMDWINDOW_ADDR_SHIFT) &
738 Z180_CMDWINDOW_ADDR_MASK);
739
740 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
741 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2,
742 cmdwinaddr);
743 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2, value);
744 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
745}
746
747/* the rest of the code doesn't want to think about if it is writing mmu
748 * registers or normal registers so handle it here
749 */
750static void z180_regread(struct kgsl_device *device,
751 unsigned int offsetwords,
752 unsigned int *value)
753{
754 if (!in_interrupt())
755 kgsl_pre_hwaccess(device);
756
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600757 if ((offsetwords >= MH_ARBITER_CONFIG &&
758 offsetwords <= MH_AXI_HALT_CONTROL) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700759 (offsetwords >= MH_MMU_CONFIG &&
760 offsetwords <= MH_MMU_MPU_END)) {
761 _z180_regread_mmu(device, offsetwords, value);
762 } else {
763 _z180_regread_simple(device, offsetwords, value);
764 }
765}
766
767static void z180_regwrite(struct kgsl_device *device,
768 unsigned int offsetwords,
769 unsigned int value)
770{
771 if (!in_interrupt())
772 kgsl_pre_hwaccess(device);
773
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600774 if ((offsetwords >= MH_ARBITER_CONFIG &&
775 offsetwords <= MH_CLNT_INTF_CTRL_CONFIG2) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700776 (offsetwords >= MH_MMU_CONFIG &&
777 offsetwords <= MH_MMU_MPU_END)) {
778 _z180_regwrite_mmu(device, offsetwords, value);
779 } else {
780 _z180_regwrite_simple(device, offsetwords, value);
781 }
782}
783
784static void z180_cmdwindow_write(struct kgsl_device *device,
785 unsigned int addr, unsigned int data)
786{
787 unsigned int cmdwinaddr;
788
789 cmdwinaddr = ((Z180_CMDWINDOW_2D << Z180_CMDWINDOW_TARGET_SHIFT) &
790 Z180_CMDWINDOW_TARGET_MASK);
791 cmdwinaddr |= ((addr << Z180_CMDWINDOW_ADDR_SHIFT) &
792 Z180_CMDWINDOW_ADDR_MASK);
793
794 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, cmdwinaddr);
795 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, data);
796}
797
798static unsigned int z180_readtimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700799 struct kgsl_context *context, enum kgsl_timestamp_type type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800{
801 struct z180_device *z180_dev = Z180_DEVICE(device);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700802 (void)context;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700803 /* get current EOP timestamp */
804 return z180_dev->timestamp;
805}
806
807static int z180_waittimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700808 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809 unsigned int timestamp,
810 unsigned int msecs)
811{
812 int status = -EINVAL;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +0530813
814 /* Don't wait forever, set a max (10 sec) value for now */
815 if (msecs == -1)
816 msecs = 10 * MSEC_PER_SEC;
817
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700818 mutex_unlock(&device->mutex);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700819 status = z180_wait(device, context, timestamp, msecs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820 mutex_lock(&device->mutex);
821
822 return status;
823}
824
825static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700826 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827 unsigned int timestamp,
828 unsigned int msecs)
829{
830 int status = -EINVAL;
831 long timeout = 0;
832
833 timeout = wait_io_event_interruptible_timeout(
834 device->wait_queue,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700835 kgsl_check_timestamp(device, context, timestamp),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700836 msecs_to_jiffies(msecs));
837
838 if (timeout > 0)
839 status = 0;
840 else if (timeout == 0) {
841 status = -ETIMEDOUT;
Jeremy Gebben388c2972011-12-16 09:05:07 -0700842 kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG);
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600843 kgsl_postmortem_dump(device, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844 } else
845 status = timeout;
846
847 return status;
848}
849
850static void
851z180_drawctxt_destroy(struct kgsl_device *device,
852 struct kgsl_context *context)
853{
854 struct z180_device *z180_dev = Z180_DEVICE(device);
855
Jordan Crousea29a2e02012-08-14 09:09:23 -0600856 z180_idle(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700857
858 if (z180_dev->ringbuffer.prevctx == context->id) {
859 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
860 device->mmu.hwpagetable = device->mmu.defaultpagetable;
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600861 kgsl_setstate(&device->mmu, KGSL_MEMSTORE_GLOBAL,
862 KGSL_MMUFLAGS_PTUPDATE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863 }
864}
865
866static void z180_power_stats(struct kgsl_device *device,
867 struct kgsl_power_stats *stats)
868{
Lucille Sylvester591ea032011-07-21 16:08:37 -0600869 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700870 s64 tmp = ktime_to_us(ktime_get());
Lucille Sylvester591ea032011-07-21 16:08:37 -0600871
872 if (pwr->time == 0) {
Lucille Sylvester808eca22011-11-03 10:26:29 -0700873 pwr->time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600874 stats->total_time = 0;
875 stats->busy_time = 0;
876 } else {
Lucille Sylvester591ea032011-07-21 16:08:37 -0600877 stats->total_time = tmp - pwr->time;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600878 pwr->time = tmp;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700879 stats->busy_time = tmp - device->on_time;
880 device->on_time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600881 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700882}
883
884static void z180_irqctrl(struct kgsl_device *device, int state)
885{
886 /* Control interrupts for Z180 and the Z180 MMU */
887
888 if (state) {
889 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 3);
Anoop Kumar Yerukala5479c9c2012-07-08 14:53:06 +0530890 z180_regwrite(device, MH_INTERRUPT_MASK,
891 kgsl_mmu_get_int_mask());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700892 } else {
893 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
894 z180_regwrite(device, MH_INTERRUPT_MASK, 0);
895 }
896}
897
Jordan Croused6535882012-06-20 08:22:16 -0600898static unsigned int z180_gpuid(struct kgsl_device *device, unsigned int *chipid)
Jordan Crousea0758f22011-12-07 11:19:22 -0700899{
Jordan Croused6535882012-06-20 08:22:16 -0600900 if (chipid != NULL)
901 *chipid = 0;
902
Jordan Crousea0758f22011-12-07 11:19:22 -0700903 /* Standard KGSL gpuid format:
904 * top word is 0x0002 for 2D or 0x0003 for 3D
905 * Bottom word is core specific identifer
906 */
907
908 return (0x0002 << 16) | 180;
909}
910
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911static const struct kgsl_functable z180_functable = {
912 /* Mandatory functions */
913 .regread = z180_regread,
914 .regwrite = z180_regwrite,
915 .idle = z180_idle,
916 .isidle = z180_isidle,
917 .suspend_context = z180_suspend_context,
918 .start = z180_start,
919 .stop = z180_stop,
920 .getproperty = z180_getproperty,
921 .waittimestamp = z180_waittimestamp,
922 .readtimestamp = z180_readtimestamp,
923 .issueibcmds = z180_cmdstream_issueibcmds,
924 .setup_pt = z180_setup_pt,
925 .cleanup_pt = z180_cleanup_pt,
926 .power_stats = z180_power_stats,
927 .irqctrl = z180_irqctrl,
Jordan Crousea0758f22011-12-07 11:19:22 -0700928 .gpuid = z180_gpuid,
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600929 .irq_handler = z180_irq_handler,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 /* Optional functions */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931 .drawctxt_create = NULL,
932 .drawctxt_destroy = z180_drawctxt_destroy,
933 .ioctl = NULL,
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600934 .postmortem_dump = z180_dump,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700935};
936
937static struct platform_device_id z180_id_table[] = {
938 { DEVICE_2D0_NAME, (kernel_ulong_t)&device_2d0.dev, },
939 { DEVICE_2D1_NAME, (kernel_ulong_t)&device_2d1.dev, },
940 { },
941};
942MODULE_DEVICE_TABLE(platform, z180_id_table);
943
944static struct platform_driver z180_platform_driver = {
945 .probe = z180_probe,
946 .remove = __devexit_p(z180_remove),
947 .suspend = kgsl_suspend_driver,
948 .resume = kgsl_resume_driver,
949 .id_table = z180_id_table,
950 .driver = {
951 .owner = THIS_MODULE,
952 .name = DEVICE_2D_NAME,
953 .pm = &kgsl_pm_ops,
954 }
955};
956
957static int __init kgsl_2d_init(void)
958{
959 return platform_driver_register(&z180_platform_driver);
960}
961
962static void __exit kgsl_2d_exit(void)
963{
964 platform_driver_unregister(&z180_platform_driver);
965}
966
967module_init(kgsl_2d_init);
968module_exit(kgsl_2d_exit);
969
970MODULE_DESCRIPTION("2D Graphics driver");
971MODULE_VERSION("1.2");
972MODULE_LICENSE("GPL v2");
973MODULE_ALIAS("platform:kgsl_2d");