blob: 3504dfc84a12115f8c06770dc8f4704145f65a70 [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
28#define Z180_DEVICE(device) \
29 KGSL_CONTAINER_OF(device, struct z180_device, dev)
30
31#define GSL_VGC_INT_MASK \
32 (REG_VGC_IRQSTATUS__MH_MASK | \
33 REG_VGC_IRQSTATUS__G2D_MASK | \
34 REG_VGC_IRQSTATUS__FIFO_MASK)
35
36#define VGV3_NEXTCMD_JUMP 0x01
37
38#define VGV3_NEXTCMD_NEXTCMD_FSHIFT 12
39#define VGV3_NEXTCMD_NEXTCMD_FMASK 0x7
40
41#define VGV3_CONTROL_MARKADD_FSHIFT 0
42#define VGV3_CONTROL_MARKADD_FMASK 0xfff
43
44#define Z180_PACKET_SIZE 15
45#define Z180_MARKER_SIZE 10
46#define Z180_CALL_CMD 0x1000
47#define Z180_MARKER_CMD 0x8000
48#define Z180_STREAM_END_CMD 0x9000
49#define Z180_STREAM_PACKET 0x7C000176
50#define Z180_STREAM_PACKET_CALL 0x7C000275
51#define Z180_PACKET_COUNT 8
52#define Z180_RB_SIZE (Z180_PACKET_SIZE*Z180_PACKET_COUNT \
53 *sizeof(uint32_t))
54
55#define NUMTEXUNITS 4
56#define TEXUNITREGCOUNT 25
57#define VG_REGCOUNT 0x39
58
59#define PACKETSIZE_BEGIN 3
60#define PACKETSIZE_G2DCOLOR 2
61#define PACKETSIZE_TEXUNIT (TEXUNITREGCOUNT * 2)
62#define PACKETSIZE_REG (VG_REGCOUNT * 2)
63#define PACKETSIZE_STATE (PACKETSIZE_TEXUNIT * NUMTEXUNITS + \
64 PACKETSIZE_REG + PACKETSIZE_BEGIN + \
65 PACKETSIZE_G2DCOLOR)
66#define PACKETSIZE_STATESTREAM (ALIGN((PACKETSIZE_STATE * \
67 sizeof(unsigned int)), 32) / \
68 sizeof(unsigned int))
69
70#define Z180_INVALID_CONTEXT UINT_MAX
71
72/* z180 MH arbiter config*/
73#define Z180_CFG_MHARB \
74 (0x10 \
75 | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \
76 | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \
77 | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \
78 | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \
79 | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \
80 | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \
81 | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \
82 | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \
83 | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \
84 | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \
85 | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \
86 | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \
87 | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \
88 | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT))
89
90#define Z180_TIMESTAMP_EPSILON 20000
91#define Z180_IDLE_COUNT_MAX 1000000
92
93enum z180_cmdwindow_type {
94 Z180_CMDWINDOW_2D = 0x00000000,
95 Z180_CMDWINDOW_MMU = 0x00000002,
96};
97
98#define Z180_CMDWINDOW_TARGET_MASK 0x000000FF
99#define Z180_CMDWINDOW_ADDR_MASK 0x00FFFF00
100#define Z180_CMDWINDOW_TARGET_SHIFT 0
101#define Z180_CMDWINDOW_ADDR_SHIFT 8
102
103static int z180_start(struct kgsl_device *device, unsigned int init_ram);
104static int z180_stop(struct kgsl_device *device);
105static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700106 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107 unsigned int timestamp,
108 unsigned int msecs);
109static void z180_regread(struct kgsl_device *device,
110 unsigned int offsetwords,
111 unsigned int *value);
112static void z180_regwrite(struct kgsl_device *device,
113 unsigned int offsetwords,
114 unsigned int value);
115static void z180_cmdwindow_write(struct kgsl_device *device,
116 unsigned int addr,
117 unsigned int data);
118
119#define Z180_MMU_CONFIG \
120 (0x01 \
121 | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \
122 | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \
123 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \
124 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \
125 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \
126 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \
127 | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \
128 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \
129 | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \
130 | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \
131 | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT))
132
133static const struct kgsl_functable z180_functable;
134
135static struct z180_device device_2d0 = {
136 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700137 KGSL_DEVICE_COMMON_INIT(device_2d0.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138 .name = DEVICE_2D0_NAME,
139 .id = KGSL_DEVICE_2D0,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600140 .mh = {
141 .mharb = Z180_CFG_MHARB,
142 .mh_intf_cfg1 = 0x00032f07,
143 .mh_intf_cfg2 = 0x004b274f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144 /* turn off memory protection unit by setting
145 acceptable physical address range to include
146 all pages. */
147 .mpu_base = 0x00000000,
148 .mpu_range = 0xFFFFF000,
149 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600150 .mmu = {
151 .config = Z180_MMU_CONFIG,
152 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700153 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154 .irq_name = KGSL_2D0_IRQ,
155 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700156 .iomemname = KGSL_2D0_REG_MEMORY,
157 .ftbl = &z180_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158 },
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700159 .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160};
161
162static struct z180_device device_2d1 = {
163 .dev = {
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700164 KGSL_DEVICE_COMMON_INIT(device_2d1.dev),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165 .name = DEVICE_2D1_NAME,
166 .id = KGSL_DEVICE_2D1,
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600167 .mh = {
168 .mharb = Z180_CFG_MHARB,
169 .mh_intf_cfg1 = 0x00032f07,
170 .mh_intf_cfg2 = 0x004b274f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 /* turn off memory protection unit by setting
172 acceptable physical address range to include
173 all pages. */
174 .mpu_base = 0x00000000,
175 .mpu_range = 0xFFFFF000,
176 },
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600177 .mmu = {
178 .config = Z180_MMU_CONFIG,
179 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180 .pwrctrl = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 .irq_name = KGSL_2D1_IRQ,
182 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183 .iomemname = KGSL_2D1_REG_MEMORY,
184 .ftbl = &z180_functable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 },
Jeremy Gebben84d75d02012-03-01 14:47:45 -0700186 .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187};
188
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600189static irqreturn_t z180_irq_handler(struct kgsl_device *device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190{
191 irqreturn_t result = IRQ_NONE;
192 unsigned int status;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 struct z180_device *z180_dev = Z180_DEVICE(device);
194
195 z180_regread(device, ADDR_VGC_IRQSTATUS >> 2, &status);
196
Norman Geed7402ff2011-10-28 08:51:11 -0600197 trace_kgsl_z180_irq_status(device, status);
198
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700199 if (status & GSL_VGC_INT_MASK) {
200 z180_regwrite(device,
201 ADDR_VGC_IRQSTATUS >> 2, status & GSL_VGC_INT_MASK);
202
203 result = IRQ_HANDLED;
204
205 if (status & REG_VGC_IRQSTATUS__FIFO_MASK)
206 KGSL_DRV_ERR(device, "z180 fifo interrupt\n");
207 if (status & REG_VGC_IRQSTATUS__MH_MASK)
208 kgsl_mh_intrcallback(device);
209 if (status & REG_VGC_IRQSTATUS__G2D_MASK) {
210 int count;
211
212 z180_regread(device,
213 ADDR_VGC_IRQ_ACTIVE_CNT >> 2,
214 &count);
215
216 count >>= 8;
217 count &= 255;
218 z180_dev->timestamp += count;
219
Jordan Crouse1bf80aa2011-10-12 16:57:47 -0600220 queue_work(device->work_queue, &device->ts_expired_ws);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221 wake_up_interruptible(&device->wait_queue);
222
223 atomic_notifier_call_chain(
224 &(device->ts_notifier_list),
225 device->id, NULL);
226 }
227 }
228
229 if ((device->pwrctrl.nap_allowed == true) &&
230 (device->requested_state == KGSL_STATE_NONE)) {
Jeremy Gebben388c2972011-12-16 09:05:07 -0700231 kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700232 queue_work(device->work_queue, &device->idle_check_ws);
233 }
Tarun Karra68755762012-01-12 16:07:09 -0800234 mod_timer_pending(&device->idle_timer,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700235 jiffies + device->pwrctrl.interval_timeout);
236
237 return result;
238}
239
Jordan Crouse9f739212011-07-28 08:37:57 -0600240static void z180_cleanup_pt(struct kgsl_device *device,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241 struct kgsl_pagetable *pagetable)
242{
243 struct z180_device *z180_dev = Z180_DEVICE(device);
244
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600245 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700246
247 kgsl_mmu_unmap(pagetable, &device->memstore);
248
249 kgsl_mmu_unmap(pagetable, &z180_dev->ringbuffer.cmdbufdesc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250}
251
252static int z180_setup_pt(struct kgsl_device *device,
253 struct kgsl_pagetable *pagetable)
254{
255 int result = 0;
256 struct z180_device *z180_dev = Z180_DEVICE(device);
257
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600258 result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700259 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
260
261 if (result)
262 goto error;
263
264 result = kgsl_mmu_map_global(pagetable, &device->memstore,
265 GSL_PT_PAGE_RV | GSL_PT_PAGE_WV);
266 if (result)
267 goto error_unmap_dummy;
268
269 result = kgsl_mmu_map_global(pagetable,
270 &z180_dev->ringbuffer.cmdbufdesc,
271 GSL_PT_PAGE_RV);
272 if (result)
273 goto error_unmap_memstore;
274 return result;
275
276error_unmap_dummy:
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600277 kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700278
279error_unmap_memstore:
280 kgsl_mmu_unmap(pagetable, &device->memstore);
281
282error:
283 return result;
284}
285
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600286static inline unsigned int rb_offset(unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700287{
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600288 return (timestamp % Z180_PACKET_COUNT)
289 *sizeof(unsigned int)*(Z180_PACKET_SIZE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700290}
291
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600292static inline unsigned int rb_gpuaddr(struct z180_device *z180_dev,
293 unsigned int timestamp)
294{
295 return z180_dev->ringbuffer.cmdbufdesc.gpuaddr + rb_offset(timestamp);
296}
297
298static void addmarker(struct z180_ringbuffer *rb, unsigned int timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299{
300 char *ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600301 unsigned int *p = (unsigned int *)(ptr + rb_offset(timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700302
303 *p++ = Z180_STREAM_PACKET;
304 *p++ = (Z180_MARKER_CMD | 5);
305 *p++ = ADDR_VGV3_LAST << 24;
306 *p++ = ADDR_VGV3_LAST << 24;
307 *p++ = ADDR_VGV3_LAST << 24;
308 *p++ = Z180_STREAM_PACKET;
309 *p++ = 5;
310 *p++ = ADDR_VGV3_LAST << 24;
311 *p++ = ADDR_VGV3_LAST << 24;
312 *p++ = ADDR_VGV3_LAST << 24;
313}
314
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600315static void addcmd(struct z180_ringbuffer *rb, unsigned int timestamp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316 unsigned int cmd, unsigned int nextcnt)
317{
318 char * ptr = (char *)(rb->cmdbufdesc.hostptr);
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600319 unsigned int *p = (unsigned int *)(ptr + (rb_offset(timestamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 + (Z180_MARKER_SIZE * sizeof(unsigned int))));
321
322 *p++ = Z180_STREAM_PACKET_CALL;
323 *p++ = cmd;
324 *p++ = Z180_CALL_CMD | nextcnt;
325 *p++ = ADDR_VGV3_LAST << 24;
326 *p++ = ADDR_VGV3_LAST << 24;
327}
328
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700329static void z180_cmdstream_start(struct kgsl_device *device, int init_ram)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700330{
331 struct z180_device *z180_dev = Z180_DEVICE(device);
332 unsigned int cmd = VGV3_NEXTCMD_JUMP << VGV3_NEXTCMD_NEXTCMD_FSHIFT;
333
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700334 if (init_ram) {
335 z180_dev->timestamp = 0;
336 z180_dev->current_timestamp = 0;
337 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700338
339 addmarker(&z180_dev->ringbuffer, 0);
340
341 z180_cmdwindow_write(device, ADDR_VGV3_MODE, 4);
342
343 z180_cmdwindow_write(device, ADDR_VGV3_NEXTADDR,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600344 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700345
346 z180_cmdwindow_write(device, ADDR_VGV3_NEXTCMD, cmd | 5);
347
348 z180_cmdwindow_write(device, ADDR_VGV3_WRITEADDR,
349 device->memstore.gpuaddr);
350
351 cmd = (int)(((1) & VGV3_CONTROL_MARKADD_FMASK)
352 << VGV3_CONTROL_MARKADD_FSHIFT);
353
354 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
355
356 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
357}
358
359static int room_in_rb(struct z180_device *device)
360{
361 int ts_diff;
362
363 ts_diff = device->current_timestamp - device->timestamp;
364
365 return ts_diff < Z180_PACKET_COUNT;
366}
367
368static int z180_idle(struct kgsl_device *device, unsigned int timeout)
369{
370 int status = 0;
371 struct z180_device *z180_dev = Z180_DEVICE(device);
372
Jordan Crousee6239dd2011-11-17 13:39:21 -0700373 if (timestamp_cmp(z180_dev->current_timestamp,
374 z180_dev->timestamp) > 0)
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700375 status = z180_wait(device, NULL,
376 z180_dev->current_timestamp, timeout);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700377
378 if (status)
379 KGSL_DRV_ERR(device, "z180_waittimestamp() timed out\n");
380
381 return status;
382}
383
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700384int
385z180_cmdstream_issueibcmds(struct kgsl_device_private *dev_priv,
386 struct kgsl_context *context,
387 struct kgsl_ibdesc *ibdesc,
388 unsigned int numibs,
389 uint32_t *timestamp,
390 unsigned int ctrl)
391{
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700392 long result = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700393 unsigned int ofs = PACKETSIZE_STATESTREAM * sizeof(unsigned int);
394 unsigned int cnt = 5;
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600395 unsigned int old_timestamp = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396 unsigned int nextcnt = Z180_STREAM_END_CMD | 5;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600397 struct kgsl_mem_entry *entry = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700398 unsigned int cmd;
399 struct kgsl_device *device = dev_priv->device;
400 struct kgsl_pagetable *pagetable = dev_priv->process_priv->pagetable;
401 struct z180_device *z180_dev = Z180_DEVICE(device);
402 unsigned int sizedwords;
403
404 if (device->state & KGSL_STATE_HUNG) {
Carter Cooperb90880d2011-10-26 14:38:02 -0600405 result = -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700406 goto error;
407 }
408 if (numibs != 1) {
409 KGSL_DRV_ERR(device, "Invalid number of ibs: %d\n", numibs);
410 result = -EINVAL;
411 goto error;
412 }
413 cmd = ibdesc[0].gpuaddr;
414 sizedwords = ibdesc[0].sizedwords;
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600415 /*
416 * Get a kernel mapping to the IB for monkey patching.
417 * See the end of this function.
418 */
419 entry = kgsl_sharedmem_find_region(dev_priv->process_priv, cmd,
420 sizedwords);
421 if (entry == NULL) {
422 KGSL_DRV_ERR(device, "Bad ibdesc: gpuaddr 0x%x size %d\n",
423 cmd, sizedwords);
424 result = -EINVAL;
425 goto error;
426 }
427 /*
428 * This will only map memory if it exists, otherwise it will reuse the
429 * mapping. And the 2d userspace reuses IBs so we likely won't create
430 * too many mappings.
431 */
432 if (kgsl_gpuaddr_to_vaddr(&entry->memdesc, cmd) == NULL) {
433 KGSL_DRV_ERR(device,
434 "Cannot make kernel mapping for gpuaddr 0x%x\n",
435 cmd);
436 result = -EINVAL;
437 goto error;
438 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439
440 KGSL_CMD_INFO(device, "ctxt %d ibaddr 0x%08x sizedwords %d\n",
441 context->id, cmd, sizedwords);
442 /* context switch */
443 if ((context->id != (int)z180_dev->ringbuffer.prevctx) ||
444 (ctrl & KGSL_CONTEXT_CTX_SWITCH)) {
445 KGSL_CMD_INFO(device, "context switch %d -> %d\n",
446 context->id, z180_dev->ringbuffer.prevctx);
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600447 kgsl_mmu_setstate(&device->mmu, pagetable,
448 KGSL_MEMSTORE_GLOBAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700449 cnt = PACKETSIZE_STATESTREAM;
450 ofs = 0;
451 }
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600452 kgsl_setstate(&device->mmu,
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600453 KGSL_MEMSTORE_GLOBAL,
Shubhraprakash Das1c528262012-04-26 17:38:13 -0600454 kgsl_mmu_pt_get_flags(device->mmu.hwpagetable,
455 device->id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456
457 result = wait_event_interruptible_timeout(device->wait_queue,
458 room_in_rb(z180_dev),
459 msecs_to_jiffies(KGSL_TIMEOUT_DEFAULT));
460 if (result < 0) {
461 KGSL_CMD_ERR(device, "wait_event_interruptible_timeout "
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700462 "failed: %ld\n", result);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463 goto error;
464 }
465 result = 0;
466
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600467 old_timestamp = z180_dev->current_timestamp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700468 z180_dev->current_timestamp++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700469 *timestamp = z180_dev->current_timestamp;
470
471 z180_dev->ringbuffer.prevctx = context->id;
472
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600473 addcmd(&z180_dev->ringbuffer, old_timestamp, cmd + ofs, cnt);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700474 kgsl_pwrscale_busy(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700475
476 /* Make sure the next ringbuffer entry has a marker */
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600477 addmarker(&z180_dev->ringbuffer, z180_dev->current_timestamp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600479 /* monkey patch the IB so that it jumps back to the ringbuffer */
480 kgsl_sharedmem_writel(&entry->memdesc,
Jeremy Gebben8b253bf2012-04-23 16:02:47 -0600481 ((sizedwords + 1) * sizeof(unsigned int)),
482 rb_gpuaddr(z180_dev, z180_dev->current_timestamp));
Jeremy Gebbend27b09f2012-04-06 16:09:13 -0600483 kgsl_sharedmem_writel(&entry->memdesc,
484 ((sizedwords + 2) * sizeof(unsigned int)),
485 nextcnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700486
487 /* sync memory before activating the hardware for the new command*/
488 mb();
489
490 cmd = (int)(((2) & VGV3_CONTROL_MARKADD_FMASK)
491 << VGV3_CONTROL_MARKADD_FSHIFT);
492
493 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd);
494 z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0);
495error:
Tarun Karra9b92ccd2011-08-19 10:59:57 -0700496 return (int)result;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700497}
498
499static int z180_ringbuffer_init(struct kgsl_device *device)
500{
501 struct z180_device *z180_dev = Z180_DEVICE(device);
502 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
503 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
504 return kgsl_allocate_contiguous(&z180_dev->ringbuffer.cmdbufdesc,
505 Z180_RB_SIZE);
506}
507
508static void z180_ringbuffer_close(struct kgsl_device *device)
509{
510 struct z180_device *z180_dev = Z180_DEVICE(device);
511 kgsl_sharedmem_free(&z180_dev->ringbuffer.cmdbufdesc);
512 memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer));
513}
514
515static int __devinit z180_probe(struct platform_device *pdev)
516{
517 int status = -EINVAL;
518 struct kgsl_device *device = NULL;
519 struct z180_device *z180_dev;
520
521 device = (struct kgsl_device *)pdev->id_entry->driver_data;
522 device->parentdev = &pdev->dev;
523
524 z180_dev = Z180_DEVICE(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525
526 status = z180_ringbuffer_init(device);
527 if (status != 0)
528 goto error;
529
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600530 status = kgsl_device_platform_probe(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531 if (status)
532 goto error_close_ringbuffer;
533
Lucille Sylvester591ea032011-07-21 16:08:37 -0600534 kgsl_pwrscale_init(device);
Lucille Sylvester808eca22011-11-03 10:26:29 -0700535 kgsl_pwrscale_attach_policy(device, Z180_DEFAULT_PWRSCALE_POLICY);
Lucille Sylvester591ea032011-07-21 16:08:37 -0600536
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537 return status;
538
539error_close_ringbuffer:
540 z180_ringbuffer_close(device);
541error:
542 device->parentdev = NULL;
543 return status;
544}
545
546static int __devexit z180_remove(struct platform_device *pdev)
547{
548 struct kgsl_device *device = NULL;
549
550 device = (struct kgsl_device *)pdev->id_entry->driver_data;
551
Lucille Sylvester591ea032011-07-21 16:08:37 -0600552 kgsl_pwrscale_close(device);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700553 kgsl_device_platform_remove(device);
554
555 z180_ringbuffer_close(device);
556
557 return 0;
558}
559
560static int z180_start(struct kgsl_device *device, unsigned int init_ram)
561{
562 int status = 0;
563
Jeremy Gebben388c2972011-12-16 09:05:07 -0700564 kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565
566 kgsl_pwrctrl_enable(device);
567
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700568 /* Set interrupts to 0 to ensure a good state */
569 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0x0);
570
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600571 kgsl_mh_start(device);
572
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700573 status = kgsl_mmu_start(device);
574 if (status)
575 goto error_clk_off;
576
Shubhraprakash Das8cbd2322012-03-04 14:41:39 -0700577 z180_cmdstream_start(device, init_ram);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700578
579 mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
Jeremy Gebbenb46f4152011-10-14 14:27:00 -0600580 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700581 device->ftbl->irqctrl(device, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 return 0;
583
584error_clk_off:
585 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
586 kgsl_pwrctrl_disable(device);
587 return status;
588}
589
590static int z180_stop(struct kgsl_device *device)
591{
Jeremy Gebbenb7bc9552012-01-09 13:32:49 -0700592 device->ftbl->irqctrl(device, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700593 z180_idle(device, KGSL_TIMEOUT_DEFAULT);
594
Suman Tatiraju4a32c652012-02-17 11:59:05 -0800595 del_timer_sync(&device->idle_timer);
596
Shubhraprakash Das79447952012-04-26 18:12:23 -0600597 kgsl_mmu_stop(&device->mmu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700598
599 /* Disable the clocks before the power rail. */
600 kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF);
601
602 kgsl_pwrctrl_disable(device);
603
604 return 0;
605}
606
607static int z180_getproperty(struct kgsl_device *device,
608 enum kgsl_property_type type,
609 void *value,
610 unsigned int sizebytes)
611{
612 int status = -EINVAL;
613
614 switch (type) {
615 case KGSL_PROP_DEVICE_INFO:
616 {
617 struct kgsl_devinfo devinfo;
618
619 if (sizebytes != sizeof(devinfo)) {
620 status = -EINVAL;
621 break;
622 }
623
624 memset(&devinfo, 0, sizeof(devinfo));
625 devinfo.device_id = device->id+1;
626 devinfo.chip_id = 0;
627 devinfo.mmu_enabled = kgsl_mmu_enabled();
628
629 if (copy_to_user(value, &devinfo, sizeof(devinfo)) !=
630 0) {
631 status = -EFAULT;
632 break;
633 }
634 status = 0;
635 }
636 break;
637 case KGSL_PROP_MMU_ENABLE:
638 {
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600639 int mmu_prop = kgsl_mmu_enabled();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700640 if (sizebytes != sizeof(int)) {
641 status = -EINVAL;
642 break;
643 }
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600644 if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700645 status = -EFAULT;
646 break;
647 }
648 status = 0;
649 }
650 break;
651
652 default:
653 KGSL_DRV_ERR(device, "invalid property: %d\n", type);
654 status = -EINVAL;
655 }
656 return status;
657}
658
659static unsigned int z180_isidle(struct kgsl_device *device)
660{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700661 struct z180_device *z180_dev = Z180_DEVICE(device);
662
Jordan Crousee6239dd2011-11-17 13:39:21 -0700663 return (timestamp_cmp(z180_dev->timestamp,
664 z180_dev->current_timestamp) == 0) ? true : false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700665}
666
667static int z180_suspend_context(struct kgsl_device *device)
668{
669 struct z180_device *z180_dev = Z180_DEVICE(device);
670
671 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
672
673 return 0;
674}
675
676/* Not all Z180 registers are directly accessible.
677 * The _z180_(read|write)_simple functions below handle the ones that are.
678 */
679static void _z180_regread_simple(struct kgsl_device *device,
680 unsigned int offsetwords,
681 unsigned int *value)
682{
683 unsigned int *reg;
684
Jordan Crouse7501d452012-04-19 08:58:44 -0600685 BUG_ON(offsetwords * sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686
Jordan Crouse7501d452012-04-19 08:58:44 -0600687 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700688
689 /*ensure this read finishes before the next one.
690 * i.e. act like normal readl() */
691 *value = __raw_readl(reg);
692 rmb();
693
694}
695
696static void _z180_regwrite_simple(struct kgsl_device *device,
697 unsigned int offsetwords,
698 unsigned int value)
699{
700 unsigned int *reg;
701
Jordan Crouse7501d452012-04-19 08:58:44 -0600702 BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700703
Jordan Crouse7501d452012-04-19 08:58:44 -0600704 reg = (unsigned int *)(device->reg_virt + (offsetwords << 2));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700705 kgsl_cffdump_regwrite(device->id, offsetwords << 2, value);
706 /*ensure previous writes post before this one,
707 * i.e. act like normal writel() */
708 wmb();
709 __raw_writel(value, reg);
710}
711
712
713/* The MH registers must be accessed through via a 2 step write, (read|write)
714 * process. These registers may be accessed from interrupt context during
715 * the handling of MH or MMU error interrupts. Therefore a spin lock is used
716 * to ensure that the 2 step sequence is not interrupted.
717 */
718static void _z180_regread_mmu(struct kgsl_device *device,
719 unsigned int offsetwords,
720 unsigned int *value)
721{
722 struct z180_device *z180_dev = Z180_DEVICE(device);
723 unsigned long flags;
724
725 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
726 _z180_regwrite_simple(device, (ADDR_VGC_MH_READ_ADDR >> 2),
727 offsetwords);
728 _z180_regread_simple(device, (ADDR_VGC_MH_DATA_ADDR >> 2), value);
729 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
730}
731
732
733static void _z180_regwrite_mmu(struct kgsl_device *device,
734 unsigned int offsetwords,
735 unsigned int value)
736{
737 struct z180_device *z180_dev = Z180_DEVICE(device);
738 unsigned int cmdwinaddr;
739 unsigned long flags;
740
741 cmdwinaddr = ((Z180_CMDWINDOW_MMU << Z180_CMDWINDOW_TARGET_SHIFT) &
742 Z180_CMDWINDOW_TARGET_MASK);
743 cmdwinaddr |= ((offsetwords << Z180_CMDWINDOW_ADDR_SHIFT) &
744 Z180_CMDWINDOW_ADDR_MASK);
745
746 spin_lock_irqsave(&z180_dev->cmdwin_lock, flags);
747 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2,
748 cmdwinaddr);
749 _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2, value);
750 spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags);
751}
752
753/* the rest of the code doesn't want to think about if it is writing mmu
754 * registers or normal registers so handle it here
755 */
756static void z180_regread(struct kgsl_device *device,
757 unsigned int offsetwords,
758 unsigned int *value)
759{
760 if (!in_interrupt())
761 kgsl_pre_hwaccess(device);
762
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600763 if ((offsetwords >= MH_ARBITER_CONFIG &&
764 offsetwords <= MH_AXI_HALT_CONTROL) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700765 (offsetwords >= MH_MMU_CONFIG &&
766 offsetwords <= MH_MMU_MPU_END)) {
767 _z180_regread_mmu(device, offsetwords, value);
768 } else {
769 _z180_regread_simple(device, offsetwords, value);
770 }
771}
772
773static void z180_regwrite(struct kgsl_device *device,
774 unsigned int offsetwords,
775 unsigned int value)
776{
777 if (!in_interrupt())
778 kgsl_pre_hwaccess(device);
779
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600780 if ((offsetwords >= MH_ARBITER_CONFIG &&
781 offsetwords <= MH_CLNT_INTF_CTRL_CONFIG2) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782 (offsetwords >= MH_MMU_CONFIG &&
783 offsetwords <= MH_MMU_MPU_END)) {
784 _z180_regwrite_mmu(device, offsetwords, value);
785 } else {
786 _z180_regwrite_simple(device, offsetwords, value);
787 }
788}
789
790static void z180_cmdwindow_write(struct kgsl_device *device,
791 unsigned int addr, unsigned int data)
792{
793 unsigned int cmdwinaddr;
794
795 cmdwinaddr = ((Z180_CMDWINDOW_2D << Z180_CMDWINDOW_TARGET_SHIFT) &
796 Z180_CMDWINDOW_TARGET_MASK);
797 cmdwinaddr |= ((addr << Z180_CMDWINDOW_ADDR_SHIFT) &
798 Z180_CMDWINDOW_ADDR_MASK);
799
800 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, cmdwinaddr);
801 z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, data);
802}
803
804static unsigned int z180_readtimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700805 struct kgsl_context *context, enum kgsl_timestamp_type type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700806{
807 struct z180_device *z180_dev = Z180_DEVICE(device);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700808 (void)context;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809 /* get current EOP timestamp */
810 return z180_dev->timestamp;
811}
812
813static int z180_waittimestamp(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700814 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700815 unsigned int timestamp,
816 unsigned int msecs)
817{
818 int status = -EINVAL;
Ranjhith Kalisamy823c1482011-09-05 20:31:07 +0530819
820 /* Don't wait forever, set a max (10 sec) value for now */
821 if (msecs == -1)
822 msecs = 10 * MSEC_PER_SEC;
823
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824 mutex_unlock(&device->mutex);
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700825 status = z180_wait(device, context, timestamp, msecs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700826 mutex_lock(&device->mutex);
827
828 return status;
829}
830
831static int z180_wait(struct kgsl_device *device,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700832 struct kgsl_context *context,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 unsigned int timestamp,
834 unsigned int msecs)
835{
836 int status = -EINVAL;
837 long timeout = 0;
838
839 timeout = wait_io_event_interruptible_timeout(
840 device->wait_queue,
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700841 kgsl_check_timestamp(device, context, timestamp),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700842 msecs_to_jiffies(msecs));
843
844 if (timeout > 0)
845 status = 0;
846 else if (timeout == 0) {
847 status = -ETIMEDOUT;
Jeremy Gebben388c2972011-12-16 09:05:07 -0700848 kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849 } else
850 status = timeout;
851
852 return status;
853}
854
855static void
856z180_drawctxt_destroy(struct kgsl_device *device,
857 struct kgsl_context *context)
858{
859 struct z180_device *z180_dev = Z180_DEVICE(device);
860
861 z180_idle(device, KGSL_TIMEOUT_DEFAULT);
862
863 if (z180_dev->ringbuffer.prevctx == context->id) {
864 z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT;
865 device->mmu.hwpagetable = device->mmu.defaultpagetable;
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600866 kgsl_setstate(&device->mmu, KGSL_MEMSTORE_GLOBAL,
867 KGSL_MMUFLAGS_PTUPDATE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 }
869}
870
871static void z180_power_stats(struct kgsl_device *device,
872 struct kgsl_power_stats *stats)
873{
Lucille Sylvester591ea032011-07-21 16:08:37 -0600874 struct kgsl_pwrctrl *pwr = &device->pwrctrl;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700875 s64 tmp = ktime_to_us(ktime_get());
Lucille Sylvester591ea032011-07-21 16:08:37 -0600876
877 if (pwr->time == 0) {
Lucille Sylvester808eca22011-11-03 10:26:29 -0700878 pwr->time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600879 stats->total_time = 0;
880 stats->busy_time = 0;
881 } else {
Lucille Sylvester591ea032011-07-21 16:08:37 -0600882 stats->total_time = tmp - pwr->time;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600883 pwr->time = tmp;
Lucille Sylvester808eca22011-11-03 10:26:29 -0700884 stats->busy_time = tmp - device->on_time;
885 device->on_time = tmp;
Lucille Sylvester591ea032011-07-21 16:08:37 -0600886 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887}
888
889static void z180_irqctrl(struct kgsl_device *device, int state)
890{
891 /* Control interrupts for Z180 and the Z180 MMU */
892
893 if (state) {
894 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 3);
Anoop Kumar Yerukala5479c9c2012-07-08 14:53:06 +0530895 z180_regwrite(device, MH_INTERRUPT_MASK,
896 kgsl_mmu_get_int_mask());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 } else {
898 z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0);
899 z180_regwrite(device, MH_INTERRUPT_MASK, 0);
900 }
901}
902
Jordan Croused6535882012-06-20 08:22:16 -0600903static unsigned int z180_gpuid(struct kgsl_device *device, unsigned int *chipid)
Jordan Crousea0758f22011-12-07 11:19:22 -0700904{
Jordan Croused6535882012-06-20 08:22:16 -0600905 if (chipid != NULL)
906 *chipid = 0;
907
Jordan Crousea0758f22011-12-07 11:19:22 -0700908 /* Standard KGSL gpuid format:
909 * top word is 0x0002 for 2D or 0x0003 for 3D
910 * Bottom word is core specific identifer
911 */
912
913 return (0x0002 << 16) | 180;
914}
915
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916static const struct kgsl_functable z180_functable = {
917 /* Mandatory functions */
918 .regread = z180_regread,
919 .regwrite = z180_regwrite,
920 .idle = z180_idle,
921 .isidle = z180_isidle,
922 .suspend_context = z180_suspend_context,
923 .start = z180_start,
924 .stop = z180_stop,
925 .getproperty = z180_getproperty,
926 .waittimestamp = z180_waittimestamp,
927 .readtimestamp = z180_readtimestamp,
928 .issueibcmds = z180_cmdstream_issueibcmds,
929 .setup_pt = z180_setup_pt,
930 .cleanup_pt = z180_cleanup_pt,
931 .power_stats = z180_power_stats,
932 .irqctrl = z180_irqctrl,
Jordan Crousea0758f22011-12-07 11:19:22 -0700933 .gpuid = z180_gpuid,
Jordan Crouseb368e9b2012-04-27 14:01:59 -0600934 .irq_handler = z180_irq_handler,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700935 /* Optional functions */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700936 .drawctxt_create = NULL,
937 .drawctxt_destroy = z180_drawctxt_destroy,
938 .ioctl = NULL,
939};
940
941static struct platform_device_id z180_id_table[] = {
942 { DEVICE_2D0_NAME, (kernel_ulong_t)&device_2d0.dev, },
943 { DEVICE_2D1_NAME, (kernel_ulong_t)&device_2d1.dev, },
944 { },
945};
946MODULE_DEVICE_TABLE(platform, z180_id_table);
947
948static struct platform_driver z180_platform_driver = {
949 .probe = z180_probe,
950 .remove = __devexit_p(z180_remove),
951 .suspend = kgsl_suspend_driver,
952 .resume = kgsl_resume_driver,
953 .id_table = z180_id_table,
954 .driver = {
955 .owner = THIS_MODULE,
956 .name = DEVICE_2D_NAME,
957 .pm = &kgsl_pm_ops,
958 }
959};
960
961static int __init kgsl_2d_init(void)
962{
963 return platform_driver_register(&z180_platform_driver);
964}
965
966static void __exit kgsl_2d_exit(void)
967{
968 platform_driver_unregister(&z180_platform_driver);
969}
970
971module_init(kgsl_2d_init);
972module_exit(kgsl_2d_exit);
973
974MODULE_DESCRIPTION("2D Graphics driver");
975MODULE_VERSION("1.2");
976MODULE_LICENSE("GPL v2");
977MODULE_ALIAS("platform:kgsl_2d");