blob: 24ac1d5e3a06212e0263dda2e1af08aec39b2c00 [file] [log] [blame]
Duy Truonge833aca2013-02-12 13:35:08 -08001/* Copyright (c) 2002,2007-2012, 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"
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);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 }
216 }
217
218 if ((device->pwrctrl.nap_allowed == true) &&
219 (device->requested_state == KGSL_STATE_NONE)) {
Jeremy Gebben388c2972011-12-16 09:05:07 -0700220 kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221 queue_work(device->work_queue, &device->idle_check_ws);
222 }
Tarun Karra68755762012-01-12 16:07:09 -0800223 mod_timer_pending(&device->idle_timer,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224 jiffies + device->pwrctrl.interval_timeout);
225
226 return result;
227}
228
Jordan Crouse9f739212011-07-28 08:37:57 -0600229static void z180_cleanup_pt(struct kgsl_device *device,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230 struct kgsl_pagetable *pagetable)
231{
232 struct z180_device *z180_dev = Z180_DEVICE(device);
233
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600234 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700235
236 kgsl_mmu_unmap(pagetable, &device->memstore);
237
238 kgsl_mmu_unmap(pagetable, &z180_dev->ringbuffer.cmdbufdesc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239}
240
241static int z180_setup_pt(struct kgsl_device *device,
242 struct kgsl_pagetable *pagetable)
243{
244 int result = 0;
245 struct z180_device *z180_dev = Z180_DEVICE(device);
246
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600247 result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700248 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
249
250 if (result)
251 goto error;
252
253 result = kgsl_mmu_map_global(pagetable, &device->memstore,
254 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
255 if (result)
256 goto error_unmap_dummy;
257
258 result = kgsl_mmu_map_global(pagetable,
259 &z180_dev->ringbuffer.cmdbufdesc,
260 GSL_PT_PAGE_RV);
261 if (result)
262 goto error_unmap_memstore;
Jeremy Gebben2aba0f32013-05-28 16:54:00 -0600263 /*
264 * Set the mpu end to the last "normal" global memory we use.
265 * For the IOMMU, this will be used to restrict access to the
266 * mapped registers.
267 */
268 device->mh.mpu_range = z180_dev->ringbuffer.cmdbufdesc.gpuaddr +
269 z180_dev->ringbuffer.cmdbufdesc.size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 return result;
271
272error_unmap_dummy:
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600273 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700274
275error_unmap_memstore:
276 kgsl_mmu_unmap(pagetable, &device->memstore);
277
278error:
279 return result;
280}
281
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600282static inline unsigned int rb_offset(unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283{
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600284 return (timestamp % Z180_PACKET_COUNT)
285 *sizeof(unsigned int)*(Z180_PACKET_SIZE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286}
287
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600288static inline unsigned int rb_gpuaddr(struct z180_device *z180_dev,
289 unsigned int timestamp)
290{
291 return z180_dev->ringbuffer.cmdbufdesc.gpuaddr + rb_offset(timestamp);
292}
293
294static void addmarker(struct z180_ringbuffer *rb, unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295{
296 char *ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600297 unsigned int *p = (unsigned int *)(ptr + rb_offset(timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298
299 *p++ = Z180_STREAM_PACKET;
300 *p++ = (Z180_MARKER_CMD | 5);
301 *p++ = ADDR_VGV3_LAST << 24;
302 *p++ = ADDR_VGV3_LAST << 24;
303 *p++ = ADDR_VGV3_LAST << 24;
304 *p++ = Z180_STREAM_PACKET;
305 *p++ = 5;
306 *p++ = ADDR_VGV3_LAST << 24;
307 *p++ = ADDR_VGV3_LAST << 24;
308 *p++ = ADDR_VGV3_LAST << 24;
309}
310
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600311static void addcmd(struct z180_ringbuffer *rb, unsigned int timestamp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700312 unsigned int cmd, unsigned int nextcnt)
313{
314 char * ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600315 unsigned int *p = (unsigned int *)(ptr + (rb_offset(timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316 + (Z180_MARKER_SIZE * sizeof(unsigned int))));
317
318 *p++ = Z180_STREAM_PACKET_CALL;
319 *p++ = cmd;
320 *p++ = Z180_CALL_CMD | nextcnt;
321 *p++ = ADDR_VGV3_LAST << 24;
322 *p++ = ADDR_VGV3_LAST << 24;
323}
324
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700325static void z180_cmdstream_start(struct kgsl_device *device, int init_ram)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700326{
327 struct z180_device *z180_dev = Z180_DEVICE(device);
328 unsigned int cmd = VGV3_NEXTCMD_JUMP << VGV3_NEXTCMD_NEXTCMD_FSHIFT;
329
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700330 if (init_ram) {
331 z180_dev->timestamp = 0;
332 z180_dev->current_timestamp = 0;
333 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700334
335 addmarker(&z180_dev->ringbuffer, 0);
336
337 z180_cmdwindow_write(device, ADDR_VGV3_MODE, 4);
338
339 z180_cmdwindow_write(device, ADDR_VGV3_NEXTADDR,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600340 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700341
342 z180_cmdwindow_write(device, ADDR_VGV3_NEXTCMD, cmd | 5);
343
344 z180_cmdwindow_write(device, ADDR_VGV3_WRITEADDR,
345 device->memstore.gpuaddr);
346
347 cmd = (int)(((1) & VGV3_CONTROL_MARKADD_FMASK)
348 << VGV3_CONTROL_MARKADD_FSHIFT);
349
350 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
351
352 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
353}
354
355static int room_in_rb(struct z180_device *device)
356{
357 int ts_diff;
358
359 ts_diff = device->current_timestamp - device->timestamp;
360
361 return ts_diff < Z180_PACKET_COUNT;
362}
363
Jordan Crousea29a2e02012-08-14 09:09:23 -0600364static int z180_idle(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700365{
366 int status = 0;
367 struct z180_device *z180_dev = Z180_DEVICE(device);
368
Jordan Crousee6239dd2011-11-17 13:39:21 -0700369 if (timestamp_cmp(z180_dev->current_timestamp,
370 z180_dev->timestamp) > 0)
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700371 status = z180_wait(device, NULL,
Jordan Crousea29a2e02012-08-14 09:09:23 -0600372 z180_dev->current_timestamp,
373 Z180_IDLE_TIMEOUT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700374
375 if (status)
376 KGSL_DRV_ERR(device, "z180_waittimestamp() timed out\n");
377
378 return status;
379}
380
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700381int
382z180_cmdstream_issueibcmds(struct kgsl_device_private *dev_priv,
383 struct kgsl_context *context,
384 struct kgsl_ibdesc *ibdesc,
385 unsigned int numibs,
386 uint32_t *timestamp,
387 unsigned int ctrl)
388{
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700389 long result = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700390 unsigned int ofs = PACKETSIZE_STATESTREAM * sizeof(unsigned int);
391 unsigned int cnt = 5;
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600392 unsigned int old_timestamp = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700393 unsigned int nextcnt = Z180_STREAM_END_CMD | 5;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600394 struct kgsl_mem_entry *entry = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700395 unsigned int cmd;
396 struct kgsl_device *device = dev_priv->device;
397 struct kgsl_pagetable *pagetable = dev_priv->process_priv->pagetable;
398 struct z180_device *z180_dev = Z180_DEVICE(device);
399 unsigned int sizedwords;
400
401 if (device->state & KGSL_STATE_HUNG) {
Carter Cooperb90880d2011-10-26 14:38:02 -0600402 result = -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700403 goto error;
404 }
405 if (numibs != 1) {
406 KGSL_DRV_ERR(device, "Invalid number of ibs: %d\n", numibs);
407 result = -EINVAL;
408 goto error;
409 }
410 cmd = ibdesc[0].gpuaddr;
411 sizedwords = ibdesc[0].sizedwords;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600412 /*
413 * Get a kernel mapping to the IB for monkey patching.
414 * See the end of this function.
415 */
416 entry = kgsl_sharedmem_find_region(dev_priv->process_priv, cmd,
417 sizedwords);
418 if (entry == NULL) {
419 KGSL_DRV_ERR(device, "Bad ibdesc: gpuaddr 0x%x size %d\n",
420 cmd, sizedwords);
421 result = -EINVAL;
422 goto error;
423 }
424 /*
425 * This will only map memory if it exists, otherwise it will reuse the
426 * mapping. And the 2d userspace reuses IBs so we likely won't create
427 * too many mappings.
428 */
429 if (kgsl_gpuaddr_to_vaddr(&entry->memdesc, cmd) == NULL) {
430 KGSL_DRV_ERR(device,
431 "Cannot make kernel mapping for gpuaddr 0x%x\n",
432 cmd);
433 result = -EINVAL;
434 goto error;
435 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436
437 KGSL_CMD_INFO(device, "ctxt %d ibaddr 0x%08x sizedwords %d\n",
438 context->id, cmd, sizedwords);
439 /* context switch */
440 if ((context->id != (int)z180_dev->ringbuffer.prevctx) ||
441 (ctrl & KGSL_CONTEXT_CTX_SWITCH)) {
442 KGSL_CMD_INFO(device, "context switch %d -> %d\n",
443 context->id, z180_dev->ringbuffer.prevctx);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600444 kgsl_mmu_setstate(&device->mmu, pagetable,
445 KGSL_MEMSTORE_GLOBAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700446 cnt = PACKETSIZE_STATESTREAM;
447 ofs = 0;
448 }
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600449 kgsl_setstate(&device->mmu,
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600450 KGSL_MEMSTORE_GLOBAL,
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600451 kgsl_mmu_pt_get_flags(device->mmu.hwpagetable,
452 device->id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700453
454 result = wait_event_interruptible_timeout(device->wait_queue,
455 room_in_rb(z180_dev),
456 msecs_to_jiffies(KGSL_TIMEOUT_DEFAULT));
457 if (result < 0) {
458 KGSL_CMD_ERR(device, "wait_event_interruptible_timeout "
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700459 "failed: %ld\n", result);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700460 goto error;
461 }
462 result = 0;
463
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600464 old_timestamp = z180_dev->current_timestamp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465 z180_dev->current_timestamp++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466 *timestamp = z180_dev->current_timestamp;
467
468 z180_dev->ringbuffer.prevctx = context->id;
469
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600470 addcmd(&z180_dev->ringbuffer, old_timestamp, cmd + ofs, cnt);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700471 kgsl_pwrscale_busy(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472
473 /* Make sure the next ringbuffer entry has a marker */
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600474 addmarker(&z180_dev->ringbuffer, z180_dev->current_timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700475
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600476 /* monkey patch the IB so that it jumps back to the ringbuffer */
477 kgsl_sharedmem_writel(&entry->memdesc,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600478 ((sizedwords + 1) * sizeof(unsigned int)),
479 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600480 kgsl_sharedmem_writel(&entry->memdesc,
481 ((sizedwords + 2) * sizeof(unsigned int)),
482 nextcnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483
484 /* sync memory before activating the hardware for the new command*/
485 mb();
486
487 cmd = (int)(((2) & VGV3_CONTROL_MARKADD_FMASK)
488 << VGV3_CONTROL_MARKADD_FSHIFT);
489
490 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
491 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
492error:
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700493 return (int)result;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700494}
495
496static int z180_ringbuffer_init(struct kgsl_device *device)
497{
498 struct z180_device *z180_dev = Z180_DEVICE(device);
499 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
500 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
501 return kgsl_allocate_contiguous(&z180_dev->ringbuffer.cmdbufdesc,
502 Z180_RB_SIZE);
503}
504
505static void z180_ringbuffer_close(struct kgsl_device *device)
506{
507 struct z180_device *z180_dev = Z180_DEVICE(device);
508 kgsl_sharedmem_free(&z180_dev->ringbuffer.cmdbufdesc);
509 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
510}
511
512static int __devinit z180_probe(struct platform_device *pdev)
513{
514 int status = -EINVAL;
515 struct kgsl_device *device = NULL;
516 struct z180_device *z180_dev;
517
518 device = (struct kgsl_device *)pdev->id_entry->driver_data;
519 device->parentdev = &pdev->dev;
520
521 z180_dev = Z180_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700522
523 status = z180_ringbuffer_init(device);
524 if (status != 0)
525 goto error;
526
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600527 status = kgsl_device_platform_probe(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700528 if (status)
529 goto error_close_ringbuffer;
530
Lucille Sylvester591ea032011-07-21 16:08:37 -0600531 kgsl_pwrscale_init(device);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700532 kgsl_pwrscale_attach_policy(device, Z180_DEFAULT_PWRSCALE_POLICY);
Lucille Sylvester591ea032011-07-21 16:08:37 -0600533
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700534 return status;
535
536error_close_ringbuffer:
537 z180_ringbuffer_close(device);
538error:
539 device->parentdev = NULL;
540 return status;
541}
542
543static int __devexit z180_remove(struct platform_device *pdev)
544{
545 struct kgsl_device *device = NULL;
546
547 device = (struct kgsl_device *)pdev->id_entry->driver_data;
548
Lucille Sylvester591ea032011-07-21 16:08:37 -0600549 kgsl_pwrscale_close(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700550 kgsl_device_platform_remove(device);
551
552 z180_ringbuffer_close(device);
553
554 return 0;
555}
556
557static int z180_start(struct kgsl_device *device, unsigned int init_ram)
558{
559 int status = 0;
560
Jeremy Gebben388c2972011-12-16 09:05:07 -0700561 kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700562
563 kgsl_pwrctrl_enable(device);
564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 /* Set interrupts to 0 to ensure a good state */
566 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0x0);
567
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600568 kgsl_mh_start(device);
569
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570 status = kgsl_mmu_start(device);
571 if (status)
572 goto error_clk_off;
573
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700574 z180_cmdstream_start(device, init_ram);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575
576 mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
Jeremy Gebbenb46f4152011-10-14 14:27:00 -0600577 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700578 device->ftbl->irqctrl(device, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700579 return 0;
580
581error_clk_off:
582 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
583 kgsl_pwrctrl_disable(device);
584 return status;
585}
586
587static int z180_stop(struct kgsl_device *device)
588{
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700589 device->ftbl->irqctrl(device, 0);
Jordan Crousea29a2e02012-08-14 09:09:23 -0600590 z180_idle(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700591
Suman Tatiraju4a32c652012-02-17 11:59:05 -0800592 del_timer_sync(&device->idle_timer);
593
Shubhraprakash Das79447952012-04-26 18:12:23 -0600594 kgsl_mmu_stop(&device->mmu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595
596 /* Disable the clocks before the power rail. */
597 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
598
599 kgsl_pwrctrl_disable(device);
600
601 return 0;
602}
603
604static int z180_getproperty(struct kgsl_device *device,
605 enum kgsl_property_type type,
606 void *value,
607 unsigned int sizebytes)
608{
609 int status = -EINVAL;
610
611 switch (type) {
612 case KGSL_PROP_DEVICE_INFO:
613 {
614 struct kgsl_devinfo devinfo;
615
616 if (sizebytes != sizeof(devinfo)) {
617 status = -EINVAL;
618 break;
619 }
620
621 memset(&devinfo, 0, sizeof(devinfo));
622 devinfo.device_id = device->id+1;
623 devinfo.chip_id = 0;
624 devinfo.mmu_enabled = kgsl_mmu_enabled();
625
626 if (copy_to_user(value, &devinfo, sizeof(devinfo)) !=
627 0) {
628 status = -EFAULT;
629 break;
630 }
631 status = 0;
632 }
633 break;
634 case KGSL_PROP_MMU_ENABLE:
635 {
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600636 int mmu_prop = kgsl_mmu_enabled();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700637 if (sizebytes != sizeof(int)) {
638 status = -EINVAL;
639 break;
640 }
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600641 if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700642 status = -EFAULT;
643 break;
644 }
645 status = 0;
646 }
647 break;
648
649 default:
650 KGSL_DRV_ERR(device, "invalid property: %d\n", type);
651 status = -EINVAL;
652 }
653 return status;
654}
655
656static unsigned int z180_isidle(struct kgsl_device *device)
657{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700658 struct z180_device *z180_dev = Z180_DEVICE(device);
659
Jordan Crousee6239dd2011-11-17 13:39:21 -0700660 return (timestamp_cmp(z180_dev->timestamp,
661 z180_dev->current_timestamp) == 0) ? true : false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700662}
663
664static int z180_suspend_context(struct kgsl_device *device)
665{
666 struct z180_device *z180_dev = Z180_DEVICE(device);
667
668 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
669
670 return 0;
671}
672
673/* Not all Z180 registers are directly accessible.
674 * The _z180_(read|write)_simple functions below handle the ones that are.
675 */
676static void _z180_regread_simple(struct kgsl_device *device,
677 unsigned int offsetwords,
678 unsigned int *value)
679{
680 unsigned int *reg;
681
Jordan Crouse7501d452012-04-19 08:58:44 -0600682 BUG_ON(offsetwords * sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700683
Jordan Crouse7501d452012-04-19 08:58:44 -0600684 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700685
686 /*ensure this read finishes before the next one.
687 * i.e. act like normal readl() */
688 *value = __raw_readl(reg);
689 rmb();
690
691}
692
693static void _z180_regwrite_simple(struct kgsl_device *device,
694 unsigned int offsetwords,
695 unsigned int value)
696{
697 unsigned int *reg;
698
Jordan Crouse7501d452012-04-19 08:58:44 -0600699 BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700700
Jordan Crouse7501d452012-04-19 08:58:44 -0600701 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700702 kgsl_cffdump_regwrite(device->id, offsetwords << 2, value);
703 /*ensure previous writes post before this one,
704 * i.e. act like normal writel() */
705 wmb();
706 __raw_writel(value, reg);
707}
708
709
710/* The MH registers must be accessed through via a 2 step write, (read|write)
711 * process. These registers may be accessed from interrupt context during
712 * the handling of MH or MMU error interrupts. Therefore a spin lock is used
713 * to ensure that the 2 step sequence is not interrupted.
714 */
715static void _z180_regread_mmu(struct kgsl_device *device,
716 unsigned int offsetwords,
717 unsigned int *value)
718{
719 struct z180_device *z180_dev = Z180_DEVICE(device);
720 unsigned long flags;
721
722 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
723 _z180_regwrite_simple(device, (ADDR_VGC_MH_READ_ADDR >> 2),
724 offsetwords);
725 _z180_regread_simple(device, (ADDR_VGC_MH_DATA_ADDR >> 2), value);
726 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
727}
728
729
730static void _z180_regwrite_mmu(struct kgsl_device *device,
731 unsigned int offsetwords,
732 unsigned int value)
733{
734 struct z180_device *z180_dev = Z180_DEVICE(device);
735 unsigned int cmdwinaddr;
736 unsigned long flags;
737
738 cmdwinaddr = ((Z180_CMDWINDOW_MMU << Z180_CMDWINDOW_TARGET_SHIFT) &
739 Z180_CMDWINDOW_TARGET_MASK);
740 cmdwinaddr |= ((offsetwords << Z180_CMDWINDOW_ADDR_SHIFT) &
741 Z180_CMDWINDOW_ADDR_MASK);
742
743 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
744 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2,
745 cmdwinaddr);
746 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2, value);
747 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
748}
749
750/* the rest of the code doesn't want to think about if it is writing mmu
751 * registers or normal registers so handle it here
752 */
753static void z180_regread(struct kgsl_device *device,
754 unsigned int offsetwords,
755 unsigned int *value)
756{
757 if (!in_interrupt())
758 kgsl_pre_hwaccess(device);
759
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600760 if ((offsetwords >= MH_ARBITER_CONFIG &&
761 offsetwords <= MH_AXI_HALT_CONTROL) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762 (offsetwords >= MH_MMU_CONFIG &&
763 offsetwords <= MH_MMU_MPU_END)) {
764 _z180_regread_mmu(device, offsetwords, value);
765 } else {
766 _z180_regread_simple(device, offsetwords, value);
767 }
768}
769
770static void z180_regwrite(struct kgsl_device *device,
771 unsigned int offsetwords,
772 unsigned int value)
773{
774 if (!in_interrupt())
775 kgsl_pre_hwaccess(device);
776
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600777 if ((offsetwords >= MH_ARBITER_CONFIG &&
778 offsetwords <= MH_CLNT_INTF_CTRL_CONFIG2) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 (offsetwords >= MH_MMU_CONFIG &&
780 offsetwords <= MH_MMU_MPU_END)) {
781 _z180_regwrite_mmu(device, offsetwords, value);
782 } else {
783 _z180_regwrite_simple(device, offsetwords, value);
784 }
785}
786
787static void z180_cmdwindow_write(struct kgsl_device *device,
788 unsigned int addr, unsigned int data)
789{
790 unsigned int cmdwinaddr;
791
792 cmdwinaddr = ((Z180_CMDWINDOW_2D << Z180_CMDWINDOW_TARGET_SHIFT) &
793 Z180_CMDWINDOW_TARGET_MASK);
794 cmdwinaddr |= ((addr << Z180_CMDWINDOW_ADDR_SHIFT) &
795 Z180_CMDWINDOW_ADDR_MASK);
796
797 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, cmdwinaddr);
798 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, data);
799}
800
801static unsigned int z180_readtimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700802 struct kgsl_context *context, enum kgsl_timestamp_type type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700803{
804 struct z180_device *z180_dev = Z180_DEVICE(device);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700805 (void)context;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700806 /* get current EOP timestamp */
807 return z180_dev->timestamp;
808}
809
810static int z180_waittimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700811 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700812 unsigned int timestamp,
813 unsigned int msecs)
814{
815 int status = -EINVAL;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +0530816
817 /* Don't wait forever, set a max (10 sec) value for now */
818 if (msecs == -1)
819 msecs = 10 * MSEC_PER_SEC;
820
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821 mutex_unlock(&device->mutex);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700822 status = z180_wait(device, context, timestamp, msecs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 mutex_lock(&device->mutex);
824
825 return status;
826}
827
828static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700829 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 unsigned int timestamp,
831 unsigned int msecs)
832{
833 int status = -EINVAL;
834 long timeout = 0;
835
836 timeout = wait_io_event_interruptible_timeout(
837 device->wait_queue,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700838 kgsl_check_timestamp(device, context, timestamp),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700839 msecs_to_jiffies(msecs));
840
841 if (timeout > 0)
842 status = 0;
843 else if (timeout == 0) {
844 status = -ETIMEDOUT;
Jeremy Gebben388c2972011-12-16 09:05:07 -0700845 kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG);
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600846 kgsl_postmortem_dump(device, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847 } else
848 status = timeout;
849
850 return status;
851}
852
853static void
854z180_drawctxt_destroy(struct kgsl_device *device,
855 struct kgsl_context *context)
856{
857 struct z180_device *z180_dev = Z180_DEVICE(device);
858
Jordan Crousea29a2e02012-08-14 09:09:23 -0600859 z180_idle(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860
861 if (z180_dev->ringbuffer.prevctx == context->id) {
862 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
863 device->mmu.hwpagetable = device->mmu.defaultpagetable;
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600864 kgsl_setstate(&device->mmu, KGSL_MEMSTORE_GLOBAL,
865 KGSL_MMUFLAGS_PTUPDATE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866 }
867}
868
869static void z180_power_stats(struct kgsl_device *device,
870 struct kgsl_power_stats *stats)
871{
Lucille Sylvester591ea032011-07-21 16:08:37 -0600872 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700873 s64 tmp = ktime_to_us(ktime_get());
Lucille Sylvester591ea032011-07-21 16:08:37 -0600874
875 if (pwr->time == 0) {
Lucille Sylvester808eca22011-11-03 10:26:29 -0700876 pwr->time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600877 stats->total_time = 0;
878 stats->busy_time = 0;
879 } else {
Lucille Sylvester591ea032011-07-21 16:08:37 -0600880 stats->total_time = tmp - pwr->time;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600881 pwr->time = tmp;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700882 stats->busy_time = tmp - device->on_time;
883 device->on_time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600884 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885}
886
887static void z180_irqctrl(struct kgsl_device *device, int state)
888{
889 /* Control interrupts for Z180 and the Z180 MMU */
890
891 if (state) {
892 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 3);
Anoop Kumar Yerukala5479c9c2012-07-08 14:53:06 +0530893 z180_regwrite(device, MH_INTERRUPT_MASK,
894 kgsl_mmu_get_int_mask());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 } else {
896 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
897 z180_regwrite(device, MH_INTERRUPT_MASK, 0);
898 }
899}
900
Jordan Croused6535882012-06-20 08:22:16 -0600901static unsigned int z180_gpuid(struct kgsl_device *device, unsigned int *chipid)
Jordan Crousea0758f22011-12-07 11:19:22 -0700902{
Jordan Croused6535882012-06-20 08:22:16 -0600903 if (chipid != NULL)
904 *chipid = 0;
905
Jordan Crousea0758f22011-12-07 11:19:22 -0700906 /* Standard KGSL gpuid format:
907 * top word is 0x0002 for 2D or 0x0003 for 3D
908 * Bottom word is core specific identifer
909 */
910
911 return (0x0002 << 16) | 180;
912}
913
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914static const struct kgsl_functable z180_functable = {
915 /* Mandatory functions */
916 .regread = z180_regread,
917 .regwrite = z180_regwrite,
918 .idle = z180_idle,
919 .isidle = z180_isidle,
920 .suspend_context = z180_suspend_context,
921 .start = z180_start,
922 .stop = z180_stop,
923 .getproperty = z180_getproperty,
924 .waittimestamp = z180_waittimestamp,
925 .readtimestamp = z180_readtimestamp,
926 .issueibcmds = z180_cmdstream_issueibcmds,
927 .setup_pt = z180_setup_pt,
928 .cleanup_pt = z180_cleanup_pt,
929 .power_stats = z180_power_stats,
930 .irqctrl = z180_irqctrl,
Jordan Crousea0758f22011-12-07 11:19:22 -0700931 .gpuid = z180_gpuid,
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600932 .irq_handler = z180_irq_handler,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700933 /* Optional functions */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700934 .drawctxt_create = NULL,
935 .drawctxt_destroy = z180_drawctxt_destroy,
936 .ioctl = NULL,
Harsh Vardhan Dwivedi715fb832012-05-18 00:24:18 -0600937 .postmortem_dump = z180_dump,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700938};
939
940static struct platform_device_id z180_id_table[] = {
941 { DEVICE_2D0_NAME, (kernel_ulong_t)&device_2d0.dev, },
942 { DEVICE_2D1_NAME, (kernel_ulong_t)&device_2d1.dev, },
943 { },
944};
945MODULE_DEVICE_TABLE(platform, z180_id_table);
946
947static struct platform_driver z180_platform_driver = {
948 .probe = z180_probe,
949 .remove = __devexit_p(z180_remove),
950 .suspend = kgsl_suspend_driver,
951 .resume = kgsl_resume_driver,
952 .id_table = z180_id_table,
953 .driver = {
954 .owner = THIS_MODULE,
955 .name = DEVICE_2D_NAME,
956 .pm = &kgsl_pm_ops,
957 }
958};
959
960static int __init kgsl_2d_init(void)
961{
962 return platform_driver_register(&z180_platform_driver);
963}
964
965static void __exit kgsl_2d_exit(void)
966{
967 platform_driver_unregister(&z180_platform_driver);
968}
969
970module_init(kgsl_2d_init);
971module_exit(kgsl_2d_exit);
972
973MODULE_DESCRIPTION("2D Graphics driver");
974MODULE_VERSION("1.2");
975MODULE_LICENSE("GPL v2");
976MODULE_ALIAS("platform:kgsl_2d");