blob: c62f67b4a5c68fad7af6e29969e66091b8ccae88 [file] [log] [blame]
Jordan Crouse013cf422013-05-28 17:03:32 -06001/* Copyright (c) 2002,2007-2013, The Linux Foundation. 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"
Jordan Crouse72bb70b2013-05-28 17:03:52 -060020#include "kgsl_trace.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021
22#include "z180.h"
23#include "z180_reg.h"
Norman Geed7402ff2011-10-28 08:51:11 -060024#include "z180_trace.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025
26#define DRIVER_VERSION_MAJOR 3
27#define DRIVER_VERSION_MINOR 1
28
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029#define GSL_VGC_INT_MASK \
30 (REG_VGC_IRQSTATUS__MH_MASK | \
31 REG_VGC_IRQSTATUS__G2D_MASK | \
32 REG_VGC_IRQSTATUS__FIFO_MASK)
33
34#define VGV3_NEXTCMD_JUMP 0x01
35
36#define VGV3_NEXTCMD_NEXTCMD_FSHIFT 12
37#define VGV3_NEXTCMD_NEXTCMD_FMASK 0x7
38
39#define VGV3_CONTROL_MARKADD_FSHIFT 0
40#define VGV3_CONTROL_MARKADD_FMASK 0xfff
41
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042#define Z180_MARKER_SIZE 10
43#define Z180_CALL_CMD 0x1000
44#define Z180_MARKER_CMD 0x8000
45#define Z180_STREAM_END_CMD 0x9000
46#define Z180_STREAM_PACKET 0x7C000176
47#define Z180_STREAM_PACKET_CALL 0x7C000275
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048
49#define NUMTEXUNITS 4
50#define TEXUNITREGCOUNT 25
51#define VG_REGCOUNT 0x39
52
53#define PACKETSIZE_BEGIN 3
54#define PACKETSIZE_G2DCOLOR 2
55#define PACKETSIZE_TEXUNIT (TEXUNITREGCOUNT * 2)
56#define PACKETSIZE_REG (VG_REGCOUNT * 2)
57#define PACKETSIZE_STATE (PACKETSIZE_TEXUNIT * NUMTEXUNITS + \
58 PACKETSIZE_REG + PACKETSIZE_BEGIN + \
59 PACKETSIZE_G2DCOLOR)
60#define PACKETSIZE_STATESTREAM (ALIGN((PACKETSIZE_STATE * \
61 sizeof(unsigned int)), 32) / \
62 sizeof(unsigned int))
63
64#define Z180_INVALID_CONTEXT UINT_MAX
65
66/* z180 MH arbiter config*/
67#define Z180_CFG_MHARB \
68 (0x10 \
69 | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \
70 | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \
71 | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \
72 | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \
73 | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \
74 | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \
75 | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \
76 | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \
77 | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \
78 | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \
79 | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \
80 | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \
81 | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \
82 | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT))
83
84#define Z180_TIMESTAMP_EPSILON 20000
85#define Z180_IDLE_COUNT_MAX 1000000
86
87enum z180_cmdwindow_type {
88 Z180_CMDWINDOW_2D = 0x00000000,
89 Z180_CMDWINDOW_MMU = 0x00000002,
90};
91
92#define Z180_CMDWINDOW_TARGET_MASK 0x000000FF
93#define Z180_CMDWINDOW_ADDR_MASK 0x00FFFF00
94#define Z180_CMDWINDOW_TARGET_SHIFT 0
95#define Z180_CMDWINDOW_ADDR_SHIFT 8
96
97static int z180_start(struct kgsl_device *device, unsigned int init_ram);
98static int z180_stop(struct kgsl_device *device);
99static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700100 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101 unsigned int timestamp,
102 unsigned int msecs);
103static void z180_regread(struct kgsl_device *device,
104 unsigned int offsetwords,
105 unsigned int *value);
106static void z180_regwrite(struct kgsl_device *device,
107 unsigned int offsetwords,
108 unsigned int value);
109static void z180_cmdwindow_write(struct kgsl_device *device,
110 unsigned int addr,
111 unsigned int data);
112
113#define Z180_MMU_CONFIG \
114 (0x01 \
115 | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \
116 | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \
117 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \
118 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \
119 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \
120 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \
121 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \
122 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \
123 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \
124 | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \
125 | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT))
126
127static const struct kgsl_functable z180_functable;
128
129static struct z180_device device_2d0 = {
130 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700131 KGSL_DEVICE_COMMON_INIT(device_2d0.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132 .name = DEVICE_2D0_NAME,
133 .id = KGSL_DEVICE_2D0,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600134 .mh = {
135 .mharb = Z180_CFG_MHARB,
136 .mh_intf_cfg1 = 0x00032f07,
137 .mh_intf_cfg2 = 0x004b274f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138 /* turn off memory protection unit by setting
139 acceptable physical address range to include
140 all pages. */
141 .mpu_base = 0x00000000,
142 .mpu_range = 0xFFFFF000,
143 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600144 .mmu = {
145 .config = Z180_MMU_CONFIG,
146 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148 .irq_name = KGSL_2D0_IRQ,
149 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150 .iomemname = KGSL_2D0_REG_MEMORY,
151 .ftbl = &z180_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152 },
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700153 .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154};
155
156static struct z180_device device_2d1 = {
157 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700158 KGSL_DEVICE_COMMON_INIT(device_2d1.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159 .name = DEVICE_2D1_NAME,
160 .id = KGSL_DEVICE_2D1,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600161 .mh = {
162 .mharb = Z180_CFG_MHARB,
163 .mh_intf_cfg1 = 0x00032f07,
164 .mh_intf_cfg2 = 0x004b274f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165 /* turn off memory protection unit by setting
166 acceptable physical address range to include
167 all pages. */
168 .mpu_base = 0x00000000,
169 .mpu_range = 0xFFFFF000,
170 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600171 .mmu = {
172 .config = Z180_MMU_CONFIG,
173 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175 .irq_name = KGSL_2D1_IRQ,
176 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177 .iomemname = KGSL_2D1_REG_MEMORY,
178 .ftbl = &z180_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179 },
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700180 .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181};
182
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600183static irqreturn_t z180_irq_handler(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184{
185 irqreturn_t result = IRQ_NONE;
186 unsigned int status;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 struct z180_device *z180_dev = Z180_DEVICE(device);
188
189 z180_regread(device, ADDR_VGC_IRQSTATUS >> 2, &status);
190
Norman Geed7402ff2011-10-28 08:51:11 -0600191 trace_kgsl_z180_irq_status(device, status);
192
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 if (status & GSL_VGC_INT_MASK) {
194 z180_regwrite(device,
195 ADDR_VGC_IRQSTATUS >> 2, status & GSL_VGC_INT_MASK);
196
197 result = IRQ_HANDLED;
198
199 if (status & REG_VGC_IRQSTATUS__FIFO_MASK)
200 KGSL_DRV_ERR(device, "z180 fifo interrupt\n");
201 if (status & REG_VGC_IRQSTATUS__MH_MASK)
202 kgsl_mh_intrcallback(device);
203 if (status & REG_VGC_IRQSTATUS__G2D_MASK) {
204 int count;
205
206 z180_regread(device,
207 ADDR_VGC_IRQ_ACTIVE_CNT >> 2,
208 &count);
209
210 count >>= 8;
211 count &= 255;
212 z180_dev->timestamp += count;
213
Jordan Crouse1bf80aa2011-10-12 16:57:47 -0600214 queue_work(device->work_queue, &device->ts_expired_ws);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 wake_up_interruptible(&device->wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216 }
217 }
218
219 if ((device->pwrctrl.nap_allowed == true) &&
220 (device->requested_state == KGSL_STATE_NONE)) {
Jeremy Gebben388c2972011-12-16 09:05:07 -0700221 kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700222 queue_work(device->work_queue, &device->idle_check_ws);
223 }
Tarun Karra68755762012-01-12 16:07:09 -0800224 mod_timer_pending(&device->idle_timer,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225 jiffies + device->pwrctrl.interval_timeout);
226
227 return result;
228}
229
Jordan Crouse9f739212011-07-28 08:37:57 -0600230static void z180_cleanup_pt(struct kgsl_device *device,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700231 struct kgsl_pagetable *pagetable)
232{
233 struct z180_device *z180_dev = Z180_DEVICE(device);
234
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600235 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700236
237 kgsl_mmu_unmap(pagetable, &device->memstore);
238
239 kgsl_mmu_unmap(pagetable, &z180_dev->ringbuffer.cmdbufdesc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700240}
241
242static int z180_setup_pt(struct kgsl_device *device,
243 struct kgsl_pagetable *pagetable)
244{
245 int result = 0;
246 struct z180_device *z180_dev = Z180_DEVICE(device);
247
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600248 result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700249 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
250
251 if (result)
252 goto error;
253
254 result = kgsl_mmu_map_global(pagetable, &device->memstore,
255 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
256 if (result)
257 goto error_unmap_dummy;
258
259 result = kgsl_mmu_map_global(pagetable,
260 &z180_dev->ringbuffer.cmdbufdesc,
261 GSL_PT_PAGE_RV);
262 if (result)
263 goto error_unmap_memstore;
Jeremy Gebben2aba0f32013-05-28 16:54:00 -0600264 /*
265 * Set the mpu end to the last "normal" global memory we use.
266 * For the IOMMU, this will be used to restrict access to the
267 * mapped registers.
268 */
269 device->mh.mpu_range = z180_dev->ringbuffer.cmdbufdesc.gpuaddr +
270 z180_dev->ringbuffer.cmdbufdesc.size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700271 return result;
272
273error_unmap_dummy:
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600274 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700275
276error_unmap_memstore:
277 kgsl_mmu_unmap(pagetable, &device->memstore);
278
279error:
280 return result;
281}
282
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600283static inline unsigned int rb_offset(unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700284{
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600285 return (timestamp % Z180_PACKET_COUNT)
286 *sizeof(unsigned int)*(Z180_PACKET_SIZE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700287}
288
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600289static inline unsigned int rb_gpuaddr(struct z180_device *z180_dev,
290 unsigned int timestamp)
291{
292 return z180_dev->ringbuffer.cmdbufdesc.gpuaddr + rb_offset(timestamp);
293}
294
295static void addmarker(struct z180_ringbuffer *rb, unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700296{
297 char *ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600298 unsigned int *p = (unsigned int *)(ptr + rb_offset(timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299
300 *p++ = Z180_STREAM_PACKET;
301 *p++ = (Z180_MARKER_CMD | 5);
302 *p++ = ADDR_VGV3_LAST << 24;
303 *p++ = ADDR_VGV3_LAST << 24;
304 *p++ = ADDR_VGV3_LAST << 24;
305 *p++ = Z180_STREAM_PACKET;
306 *p++ = 5;
307 *p++ = ADDR_VGV3_LAST << 24;
308 *p++ = ADDR_VGV3_LAST << 24;
309 *p++ = ADDR_VGV3_LAST << 24;
310}
311
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600312static void addcmd(struct z180_ringbuffer *rb, unsigned int timestamp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700313 unsigned int cmd, unsigned int nextcnt)
314{
315 char * ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600316 unsigned int *p = (unsigned int *)(ptr + (rb_offset(timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700317 + (Z180_MARKER_SIZE * sizeof(unsigned int))));
318
319 *p++ = Z180_STREAM_PACKET_CALL;
320 *p++ = cmd;
321 *p++ = Z180_CALL_CMD | nextcnt;
322 *p++ = ADDR_VGV3_LAST << 24;
323 *p++ = ADDR_VGV3_LAST << 24;
324}
325
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700326static void z180_cmdstream_start(struct kgsl_device *device, int init_ram)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700327{
328 struct z180_device *z180_dev = Z180_DEVICE(device);
329 unsigned int cmd = VGV3_NEXTCMD_JUMP << VGV3_NEXTCMD_NEXTCMD_FSHIFT;
330
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700331 if (init_ram) {
332 z180_dev->timestamp = 0;
333 z180_dev->current_timestamp = 0;
334 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700335
336 addmarker(&z180_dev->ringbuffer, 0);
337
338 z180_cmdwindow_write(device, ADDR_VGV3_MODE, 4);
339
340 z180_cmdwindow_write(device, ADDR_VGV3_NEXTADDR,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600341 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700342
343 z180_cmdwindow_write(device, ADDR_VGV3_NEXTCMD, cmd | 5);
344
345 z180_cmdwindow_write(device, ADDR_VGV3_WRITEADDR,
346 device->memstore.gpuaddr);
347
348 cmd = (int)(((1) & VGV3_CONTROL_MARKADD_FMASK)
349 << VGV3_CONTROL_MARKADD_FSHIFT);
350
351 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
352
353 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
354}
355
356static int room_in_rb(struct z180_device *device)
357{
358 int ts_diff;
359
360 ts_diff = device->current_timestamp - device->timestamp;
361
362 return ts_diff < Z180_PACKET_COUNT;
363}
364
Jordan Crousea29a2e02012-08-14 09:09:23 -0600365static int z180_idle(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700366{
367 int status = 0;
368 struct z180_device *z180_dev = Z180_DEVICE(device);
369
Jordan Crousee6239dd2011-11-17 13:39:21 -0700370 if (timestamp_cmp(z180_dev->current_timestamp,
371 z180_dev->timestamp) > 0)
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700372 status = z180_wait(device, NULL,
Jordan Crousea29a2e02012-08-14 09:09:23 -0600373 z180_dev->current_timestamp,
374 Z180_IDLE_TIMEOUT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700375
376 if (status)
377 KGSL_DRV_ERR(device, "z180_waittimestamp() timed out\n");
378
379 return status;
380}
381
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700382int
383z180_cmdstream_issueibcmds(struct kgsl_device_private *dev_priv,
384 struct kgsl_context *context,
385 struct kgsl_ibdesc *ibdesc,
386 unsigned int numibs,
387 uint32_t *timestamp,
388 unsigned int ctrl)
389{
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700390 long result = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700391 unsigned int ofs = PACKETSIZE_STATESTREAM * sizeof(unsigned int);
392 unsigned int cnt = 5;
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600393 unsigned int old_timestamp = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700394 unsigned int nextcnt = Z180_STREAM_END_CMD | 5;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600395 struct kgsl_mem_entry *entry = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396 unsigned int cmd;
397 struct kgsl_device *device = dev_priv->device;
398 struct kgsl_pagetable *pagetable = dev_priv->process_priv->pagetable;
399 struct z180_device *z180_dev = Z180_DEVICE(device);
400 unsigned int sizedwords;
401
402 if (device->state & KGSL_STATE_HUNG) {
Carter Cooperb90880d2011-10-26 14:38:02 -0600403 result = -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404 goto error;
405 }
406 if (numibs != 1) {
407 KGSL_DRV_ERR(device, "Invalid number of ibs: %d\n", numibs);
408 result = -EINVAL;
409 goto error;
410 }
411 cmd = ibdesc[0].gpuaddr;
412 sizedwords = ibdesc[0].sizedwords;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600413 /*
414 * Get a kernel mapping to the IB for monkey patching.
415 * See the end of this function.
416 */
417 entry = kgsl_sharedmem_find_region(dev_priv->process_priv, cmd,
418 sizedwords);
419 if (entry == NULL) {
420 KGSL_DRV_ERR(device, "Bad ibdesc: gpuaddr 0x%x size %d\n",
421 cmd, sizedwords);
422 result = -EINVAL;
423 goto error;
424 }
425 /*
426 * This will only map memory if it exists, otherwise it will reuse the
427 * mapping. And the 2d userspace reuses IBs so we likely won't create
428 * too many mappings.
429 */
430 if (kgsl_gpuaddr_to_vaddr(&entry->memdesc, cmd) == NULL) {
431 KGSL_DRV_ERR(device,
432 "Cannot make kernel mapping for gpuaddr 0x%x\n",
433 cmd);
434 result = -EINVAL;
435 goto error;
436 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437
438 KGSL_CMD_INFO(device, "ctxt %d ibaddr 0x%08x sizedwords %d\n",
439 context->id, cmd, sizedwords);
440 /* context switch */
441 if ((context->id != (int)z180_dev->ringbuffer.prevctx) ||
442 (ctrl & KGSL_CONTEXT_CTX_SWITCH)) {
443 KGSL_CMD_INFO(device, "context switch %d -> %d\n",
444 context->id, z180_dev->ringbuffer.prevctx);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600445 kgsl_mmu_setstate(&device->mmu, pagetable,
446 KGSL_MEMSTORE_GLOBAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700447 cnt = PACKETSIZE_STATESTREAM;
448 ofs = 0;
449 }
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600450 kgsl_setstate(&device->mmu,
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600451 KGSL_MEMSTORE_GLOBAL,
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600452 kgsl_mmu_pt_get_flags(device->mmu.hwpagetable,
453 device->id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700454
455 result = wait_event_interruptible_timeout(device->wait_queue,
456 room_in_rb(z180_dev),
457 msecs_to_jiffies(KGSL_TIMEOUT_DEFAULT));
458 if (result < 0) {
459 KGSL_CMD_ERR(device, "wait_event_interruptible_timeout "
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700460 "failed: %ld\n", result);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700461 goto error;
462 }
463 result = 0;
464
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600465 old_timestamp = z180_dev->current_timestamp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466 z180_dev->current_timestamp++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700467 *timestamp = z180_dev->current_timestamp;
468
469 z180_dev->ringbuffer.prevctx = context->id;
470
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600471 addcmd(&z180_dev->ringbuffer, old_timestamp, cmd + ofs, cnt);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700472 kgsl_pwrscale_busy(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473
474 /* Make sure the next ringbuffer entry has a marker */
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600475 addmarker(&z180_dev->ringbuffer, z180_dev->current_timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700476
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600477 /* monkey patch the IB so that it jumps back to the ringbuffer */
478 kgsl_sharedmem_writel(&entry->memdesc,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600479 ((sizedwords + 1) * sizeof(unsigned int)),
480 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600481 kgsl_sharedmem_writel(&entry->memdesc,
482 ((sizedwords + 2) * sizeof(unsigned int)),
483 nextcnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700484
485 /* sync memory before activating the hardware for the new command*/
486 mb();
487
488 cmd = (int)(((2) & VGV3_CONTROL_MARKADD_FMASK)
489 << VGV3_CONTROL_MARKADD_FSHIFT);
490
491 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
492 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
493error:
Jordan Crouse72bb70b2013-05-28 17:03:52 -0600494
495 trace_kgsl_issueibcmds(device, context->id, ibdesc, numibs,
496 *timestamp, ctrl, result, 0);
497
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700498 return (int)result;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700499}
500
501static int z180_ringbuffer_init(struct kgsl_device *device)
502{
503 struct z180_device *z180_dev = Z180_DEVICE(device);
504 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
505 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
506 return kgsl_allocate_contiguous(&z180_dev->ringbuffer.cmdbufdesc,
507 Z180_RB_SIZE);
508}
509
510static void z180_ringbuffer_close(struct kgsl_device *device)
511{
512 struct z180_device *z180_dev = Z180_DEVICE(device);
513 kgsl_sharedmem_free(&z180_dev->ringbuffer.cmdbufdesc);
514 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
515}
516
517static int __devinit z180_probe(struct platform_device *pdev)
518{
519 int status = -EINVAL;
520 struct kgsl_device *device = NULL;
521 struct z180_device *z180_dev;
522
523 device = (struct kgsl_device *)pdev->id_entry->driver_data;
524 device->parentdev = &pdev->dev;
525
526 z180_dev = Z180_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527
528 status = z180_ringbuffer_init(device);
529 if (status != 0)
530 goto error;
531
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600532 status = kgsl_device_platform_probe(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700533 if (status)
534 goto error_close_ringbuffer;
535
Lucille Sylvester591ea032011-07-21 16:08:37 -0600536 kgsl_pwrscale_init(device);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700537 kgsl_pwrscale_attach_policy(device, Z180_DEFAULT_PWRSCALE_POLICY);
Lucille Sylvester591ea032011-07-21 16:08:37 -0600538
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700539 return status;
540
541error_close_ringbuffer:
542 z180_ringbuffer_close(device);
543error:
544 device->parentdev = NULL;
545 return status;
546}
547
548static int __devexit z180_remove(struct platform_device *pdev)
549{
550 struct kgsl_device *device = NULL;
551
552 device = (struct kgsl_device *)pdev->id_entry->driver_data;
553
Lucille Sylvester591ea032011-07-21 16:08:37 -0600554 kgsl_pwrscale_close(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700555 kgsl_device_platform_remove(device);
556
557 z180_ringbuffer_close(device);
558
559 return 0;
560}
561
562static int z180_start(struct kgsl_device *device, unsigned int init_ram)
563{
564 int status = 0;
565
Jeremy Gebben388c2972011-12-16 09:05:07 -0700566 kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700567
568 kgsl_pwrctrl_enable(device);
569
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570 /* Set interrupts to 0 to ensure a good state */
571 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0x0);
572
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600573 kgsl_mh_start(device);
574
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575 status = kgsl_mmu_start(device);
576 if (status)
577 goto error_clk_off;
578
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700579 z180_cmdstream_start(device, init_ram);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700580
581 mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
Jeremy Gebbenb46f4152011-10-14 14:27:00 -0600582 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700583 device->ftbl->irqctrl(device, 1);
Jordan Crouse013cf422013-05-28 17:03:32 -0600584
585 device->reset_counter++;
586
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700587 return 0;
588
589error_clk_off:
590 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
591 kgsl_pwrctrl_disable(device);
592 return status;
593}
594
595static int z180_stop(struct kgsl_device *device)
596{
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700597 device->ftbl->irqctrl(device, 0);
Jordan Crousea29a2e02012-08-14 09:09:23 -0600598 z180_idle(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599
Suman Tatiraju4a32c652012-02-17 11:59:05 -0800600 del_timer_sync(&device->idle_timer);
601
Shubhraprakash Das79447952012-04-26 18:12:23 -0600602 kgsl_mmu_stop(&device->mmu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603
604 /* Disable the clocks before the power rail. */
605 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
606
607 kgsl_pwrctrl_disable(device);
608
609 return 0;
610}
611
612static int z180_getproperty(struct kgsl_device *device,
613 enum kgsl_property_type type,
614 void *value,
615 unsigned int sizebytes)
616{
617 int status = -EINVAL;
618
619 switch (type) {
620 case KGSL_PROP_DEVICE_INFO:
621 {
622 struct kgsl_devinfo devinfo;
623
624 if (sizebytes != sizeof(devinfo)) {
625 status = -EINVAL;
626 break;
627 }
628
629 memset(&devinfo, 0, sizeof(devinfo));
630 devinfo.device_id = device->id+1;
631 devinfo.chip_id = 0;
632 devinfo.mmu_enabled = kgsl_mmu_enabled();
633
634 if (copy_to_user(value, &devinfo, sizeof(devinfo)) !=
635 0) {
636 status = -EFAULT;
637 break;
638 }
639 status = 0;
640 }
641 break;
642 case KGSL_PROP_MMU_ENABLE:
643 {
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600644 int mmu_prop = kgsl_mmu_enabled();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700645 if (sizebytes != sizeof(int)) {
646 status = -EINVAL;
647 break;
648 }
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600649 if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650 status = -EFAULT;
651 break;
652 }
653 status = 0;
654 }
655 break;
656
657 default:
658 KGSL_DRV_ERR(device, "invalid property: %d\n", type);
659 status = -EINVAL;
660 }
661 return status;
662}
663
664static unsigned int z180_isidle(struct kgsl_device *device)
665{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700666 struct z180_device *z180_dev = Z180_DEVICE(device);
667
Jordan Crousee6239dd2011-11-17 13:39:21 -0700668 return (timestamp_cmp(z180_dev->timestamp,
669 z180_dev->current_timestamp) == 0) ? true : false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700670}
671
672static int z180_suspend_context(struct kgsl_device *device)
673{
674 struct z180_device *z180_dev = Z180_DEVICE(device);
675
676 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
677
678 return 0;
679}
680
681/* Not all Z180 registers are directly accessible.
682 * The _z180_(read|write)_simple functions below handle the ones that are.
683 */
684static void _z180_regread_simple(struct kgsl_device *device,
685 unsigned int offsetwords,
686 unsigned int *value)
687{
688 unsigned int *reg;
689
Jordan Crouse7501d452012-04-19 08:58:44 -0600690 BUG_ON(offsetwords * sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691
Jordan Crouse7501d452012-04-19 08:58:44 -0600692 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700693
694 /*ensure this read finishes before the next one.
695 * i.e. act like normal readl() */
696 *value = __raw_readl(reg);
697 rmb();
698
699}
700
701static void _z180_regwrite_simple(struct kgsl_device *device,
702 unsigned int offsetwords,
703 unsigned int value)
704{
705 unsigned int *reg;
706
Jordan Crouse7501d452012-04-19 08:58:44 -0600707 BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708
Jordan Crouse7501d452012-04-19 08:58:44 -0600709 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700710 kgsl_cffdump_regwrite(device->id, offsetwords << 2, value);
711 /*ensure previous writes post before this one,
712 * i.e. act like normal writel() */
713 wmb();
714 __raw_writel(value, reg);
715}
716
717
718/* The MH registers must be accessed through via a 2 step write, (read|write)
719 * process. These registers may be accessed from interrupt context during
720 * the handling of MH or MMU error interrupts. Therefore a spin lock is used
721 * to ensure that the 2 step sequence is not interrupted.
722 */
723static void _z180_regread_mmu(struct kgsl_device *device,
724 unsigned int offsetwords,
725 unsigned int *value)
726{
727 struct z180_device *z180_dev = Z180_DEVICE(device);
728 unsigned long flags;
729
730 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
731 _z180_regwrite_simple(device, (ADDR_VGC_MH_READ_ADDR >> 2),
732 offsetwords);
733 _z180_regread_simple(device, (ADDR_VGC_MH_DATA_ADDR >> 2), value);
734 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
735}
736
737
738static void _z180_regwrite_mmu(struct kgsl_device *device,
739 unsigned int offsetwords,
740 unsigned int value)
741{
742 struct z180_device *z180_dev = Z180_DEVICE(device);
743 unsigned int cmdwinaddr;
744 unsigned long flags;
745
746 cmdwinaddr = ((Z180_CMDWINDOW_MMU << Z180_CMDWINDOW_TARGET_SHIFT) &
747 Z180_CMDWINDOW_TARGET_MASK);
748 cmdwinaddr |= ((offsetwords << Z180_CMDWINDOW_ADDR_SHIFT) &
749 Z180_CMDWINDOW_ADDR_MASK);
750
751 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
752 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2,
753 cmdwinaddr);
754 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2, value);
755 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
756}
757
758/* the rest of the code doesn't want to think about if it is writing mmu
759 * registers or normal registers so handle it here
760 */
761static void z180_regread(struct kgsl_device *device,
762 unsigned int offsetwords,
763 unsigned int *value)
764{
765 if (!in_interrupt())
766 kgsl_pre_hwaccess(device);
767
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600768 if ((offsetwords >= MH_ARBITER_CONFIG &&
769 offsetwords <= MH_AXI_HALT_CONTROL) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700770 (offsetwords >= MH_MMU_CONFIG &&
771 offsetwords <= MH_MMU_MPU_END)) {
772 _z180_regread_mmu(device, offsetwords, value);
773 } else {
774 _z180_regread_simple(device, offsetwords, value);
775 }
776}
777
778static void z180_regwrite(struct kgsl_device *device,
779 unsigned int offsetwords,
780 unsigned int value)
781{
782 if (!in_interrupt())
783 kgsl_pre_hwaccess(device);
784
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600785 if ((offsetwords >= MH_ARBITER_CONFIG &&
786 offsetwords <= MH_CLNT_INTF_CTRL_CONFIG2) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 (offsetwords >= MH_MMU_CONFIG &&
788 offsetwords <= MH_MMU_MPU_END)) {
789 _z180_regwrite_mmu(device, offsetwords, value);
790 } else {
791 _z180_regwrite_simple(device, offsetwords, value);
792 }
793}
794
795static void z180_cmdwindow_write(struct kgsl_device *device,
796 unsigned int addr, unsigned int data)
797{
798 unsigned int cmdwinaddr;
799
800 cmdwinaddr = ((Z180_CMDWINDOW_2D << Z180_CMDWINDOW_TARGET_SHIFT) &
801 Z180_CMDWINDOW_TARGET_MASK);
802 cmdwinaddr |= ((addr << Z180_CMDWINDOW_ADDR_SHIFT) &
803 Z180_CMDWINDOW_ADDR_MASK);
804
805 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, cmdwinaddr);
806 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, data);
807}
808
809static unsigned int z180_readtimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700810 struct kgsl_context *context, enum kgsl_timestamp_type type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811{
812 struct z180_device *z180_dev = Z180_DEVICE(device);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700813 (void)context;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700814 /* get current EOP timestamp */
815 return z180_dev->timestamp;
816}
817
818static int z180_waittimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700819 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820 unsigned int timestamp,
821 unsigned int msecs)
822{
823 int status = -EINVAL;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +0530824
825 /* Don't wait forever, set a max (10 sec) value for now */
826 if (msecs == -1)
827 msecs = 10 * MSEC_PER_SEC;
828
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829 mutex_unlock(&device->mutex);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700830 status = z180_wait(device, context, timestamp, msecs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831 mutex_lock(&device->mutex);
832
833 return status;
834}
835
836static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700837 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700838 unsigned int timestamp,
839 unsigned int msecs)
840{
841 int status = -EINVAL;
842 long timeout = 0;
843
844 timeout = wait_io_event_interruptible_timeout(
845 device->wait_queue,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700846 kgsl_check_timestamp(device, context, timestamp),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847 msecs_to_jiffies(msecs));
848
849 if (timeout > 0)
850 status = 0;
851 else if (timeout == 0) {
852 status = -ETIMEDOUT;
Jeremy Gebben388c2972011-12-16 09:05:07 -0700853 kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG);
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600854 kgsl_postmortem_dump(device, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855 } else
856 status = timeout;
857
858 return status;
859}
860
861static void
862z180_drawctxt_destroy(struct kgsl_device *device,
863 struct kgsl_context *context)
864{
865 struct z180_device *z180_dev = Z180_DEVICE(device);
866
Jordan Crousea29a2e02012-08-14 09:09:23 -0600867 z180_idle(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868
869 if (z180_dev->ringbuffer.prevctx == context->id) {
870 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
871 device->mmu.hwpagetable = device->mmu.defaultpagetable;
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600872 kgsl_setstate(&device->mmu, KGSL_MEMSTORE_GLOBAL,
873 KGSL_MMUFLAGS_PTUPDATE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 }
875}
876
877static void z180_power_stats(struct kgsl_device *device,
878 struct kgsl_power_stats *stats)
879{
Lucille Sylvester591ea032011-07-21 16:08:37 -0600880 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700881 s64 tmp = ktime_to_us(ktime_get());
Lucille Sylvester591ea032011-07-21 16:08:37 -0600882
883 if (pwr->time == 0) {
Lucille Sylvester808eca22011-11-03 10:26:29 -0700884 pwr->time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600885 stats->total_time = 0;
886 stats->busy_time = 0;
887 } else {
Lucille Sylvester591ea032011-07-21 16:08:37 -0600888 stats->total_time = tmp - pwr->time;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600889 pwr->time = tmp;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700890 stats->busy_time = tmp - device->on_time;
891 device->on_time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600892 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893}
894
895static void z180_irqctrl(struct kgsl_device *device, int state)
896{
897 /* Control interrupts for Z180 and the Z180 MMU */
898
899 if (state) {
900 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 3);
Anoop Kumar Yerukala5479c9c2012-07-08 14:53:06 +0530901 z180_regwrite(device, MH_INTERRUPT_MASK,
902 kgsl_mmu_get_int_mask());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903 } else {
904 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
905 z180_regwrite(device, MH_INTERRUPT_MASK, 0);
906 }
907}
908
Jordan Croused6535882012-06-20 08:22:16 -0600909static unsigned int z180_gpuid(struct kgsl_device *device, unsigned int *chipid)
Jordan Crousea0758f22011-12-07 11:19:22 -0700910{
Jordan Croused6535882012-06-20 08:22:16 -0600911 if (chipid != NULL)
912 *chipid = 0;
913
Jordan Crousea0758f22011-12-07 11:19:22 -0700914 /* Standard KGSL gpuid format:
915 * top word is 0x0002 for 2D or 0x0003 for 3D
916 * Bottom word is core specific identifer
917 */
918
919 return (0x0002 << 16) | 180;
920}
921
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922static const struct kgsl_functable z180_functable = {
923 /* Mandatory functions */
924 .regread = z180_regread,
925 .regwrite = z180_regwrite,
926 .idle = z180_idle,
927 .isidle = z180_isidle,
928 .suspend_context = z180_suspend_context,
929 .start = z180_start,
930 .stop = z180_stop,
931 .getproperty = z180_getproperty,
932 .waittimestamp = z180_waittimestamp,
933 .readtimestamp = z180_readtimestamp,
934 .issueibcmds = z180_cmdstream_issueibcmds,
935 .setup_pt = z180_setup_pt,
936 .cleanup_pt = z180_cleanup_pt,
937 .power_stats = z180_power_stats,
938 .irqctrl = z180_irqctrl,
Jordan Crousea0758f22011-12-07 11:19:22 -0700939 .gpuid = z180_gpuid,
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600940 .irq_handler = z180_irq_handler,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941 /* Optional functions */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700942 .drawctxt_create = NULL,
943 .drawctxt_destroy = z180_drawctxt_destroy,
944 .ioctl = NULL,
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600945 .postmortem_dump = z180_dump,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700946};
947
948static struct platform_device_id z180_id_table[] = {
949 { DEVICE_2D0_NAME, (kernel_ulong_t)&device_2d0.dev, },
950 { DEVICE_2D1_NAME, (kernel_ulong_t)&device_2d1.dev, },
951 { },
952};
953MODULE_DEVICE_TABLE(platform, z180_id_table);
954
955static struct platform_driver z180_platform_driver = {
956 .probe = z180_probe,
957 .remove = __devexit_p(z180_remove),
958 .suspend = kgsl_suspend_driver,
959 .resume = kgsl_resume_driver,
960 .id_table = z180_id_table,
961 .driver = {
962 .owner = THIS_MODULE,
963 .name = DEVICE_2D_NAME,
964 .pm = &kgsl_pm_ops,
965 }
966};
967
968static int __init kgsl_2d_init(void)
969{
970 return platform_driver_register(&z180_platform_driver);
971}
972
973static void __exit kgsl_2d_exit(void)
974{
975 platform_driver_unregister(&z180_platform_driver);
976}
977
978module_init(kgsl_2d_init);
979module_exit(kgsl_2d_exit);
980
981MODULE_DESCRIPTION("2D Graphics driver");
982MODULE_VERSION("1.2");
983MODULE_LICENSE("GPL v2");
984MODULE_ALIAS("platform:kgsl_2d");