Import of XFree86 3.9.18
[gstreamer-omap:libdrm.git] / linux / mga_drv.c
1 /* mga_drv.c -- Matrox g200/g400 driver -*- linux-c -*-
2  * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
3  * 
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  * 
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  * Authors: Rickard E. (Rik) Faith <faith@precisioninsight.com>
27  *          Jeff Hartmann <jhartmann@precisioninsight.com>
28  *
29  * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_drv.c,v 1.1 2000/02/11 17:26:07 dawes Exp $
30  *
31  */
32
33 #define EXPORT_SYMTAB
34 #include "drmP.h"
35 #include "mga_drv.h"
36 EXPORT_SYMBOL(mga_init);
37 EXPORT_SYMBOL(mga_cleanup);
38
39 #define MGA_NAME         "mga"
40 #define MGA_DESC         "Matrox g200/g400"
41 #define MGA_DATE         "19991213"
42 #define MGA_MAJOR        0
43 #define MGA_MINOR        0
44 #define MGA_PATCHLEVEL   1
45
46 static drm_device_t           mga_device;
47 drm_ctx_t                     mga_res_ctx;
48
49 static struct file_operations mga_fops = {
50         open:    mga_open,
51         flush:   drm_flush,
52         release: mga_release,
53         ioctl:   mga_ioctl,
54         mmap:    drm_mmap,
55         read:    drm_read,
56         fasync:  drm_fasync,
57 };
58
59 static struct miscdevice      mga_misc = {
60         minor: MISC_DYNAMIC_MINOR,
61         name:  MGA_NAME,
62         fops:  &mga_fops,
63 };
64
65 static drm_ioctl_desc_t       mga_ioctls[] = {
66         [DRM_IOCTL_NR(DRM_IOCTL_VERSION)]     = { mga_version,    0, 0 },
67         [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)]  = { drm_getunique,  0, 0 },
68         [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)]   = { drm_getmagic,   0, 0 },
69         [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)]   = { drm_irq_busid,  0, 1 },
70
71         [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)]  = { drm_setunique,  1, 1 },
72         [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)]       = { drm_block,      1, 1 },
73         [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)]     = { drm_unblock,    1, 1 },
74         [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]     = { mga_control,    1, 1 },
75         [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)]  = { drm_authmagic,  1, 1 },
76         [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)]     = { drm_addmap,     1, 1 },
77         [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)]    = { mga_addbufs,    1, 1 },
78         [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)]   = { mga_markbufs,   1, 1 },
79         [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]   = { mga_infobufs,   1, 0 },
80         [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]    = { mga_mapbufs,    1, 0 },
81         [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]   = { mga_freebufs,   1, 0 },
82
83         [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)]     = { mga_addctx,     1, 1 },
84         [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)]      = { mga_rmctx,      1, 1 },
85         [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)]     = { mga_modctx,     1, 1 },
86         [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)]     = { mga_getctx,     1, 0 },
87         [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)]  = { mga_switchctx,  1, 1 },
88         [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)]     = { mga_newctx,     1, 1 },
89         [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)]     = { mga_resctx,     1, 0 },
90         [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)]    = { drm_adddraw,    1, 1 },
91         [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)]     = { drm_rmdraw,     1, 1 },
92
93         [DRM_IOCTL_NR(DRM_IOCTL_DMA)]         = { mga_dma,        1, 0 },
94
95         [DRM_IOCTL_NR(DRM_IOCTL_LOCK)]        = { mga_lock,       1, 0 },
96         [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)]      = { mga_unlock,     1, 0 },
97         [DRM_IOCTL_NR(DRM_IOCTL_FINISH)]      = { drm_finish,     1, 0 },
98
99         [DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { drm_agp_acquire, 1, 1 },
100         [DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { drm_agp_release, 1, 1 },
101         [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)]  = { drm_agp_enable,  1, 1 },
102         [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)]    = { drm_agp_info,    1, 0 },
103         [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)]   = { drm_agp_alloc,   1, 1 },
104         [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)]    = { drm_agp_free,    1, 1 },
105         [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)]    = { drm_agp_bind,    1, 1 },
106         [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)]  = { drm_agp_unbind,  1, 1 },
107         [DRM_IOCTL_NR(DRM_IOCTL_MGA_INIT)]    = { mga_dma_init,    1, 1 },
108         [DRM_IOCTL_NR(DRM_IOCTL_MGA_SWAP)]    = { mga_clear_bufs,  1, 1 },
109         [DRM_IOCTL_NR(DRM_IOCTL_MGA_CLEAR)]   = { mga_swap_bufs,   1, 1 },
110         [DRM_IOCTL_NR(DRM_IOCTL_MGA_ILOAD)]   = { mga_iload,       1, 1 },
111 };
112
113 #define MGA_IOCTL_COUNT DRM_ARRAY_SIZE(mga_ioctls)
114
115 #ifdef MODULE
116 int                           init_module(void);
117 void                          cleanup_module(void);
118 static char                   *mga = NULL;
119
120 MODULE_AUTHOR("Precision Insight, Inc., Cedar Park, Texas.");
121 MODULE_DESCRIPTION("Matrox g200/g400");
122 MODULE_PARM(mga, "s");
123
124 /* init_module is called when insmod is used to load the module */
125
126 int init_module(void)
127 {
128         DRM_DEBUG("doing mga_init()\n");
129         return mga_init();
130 }
131
132 /* cleanup_module is called when rmmod is used to unload the module */
133
134 void cleanup_module(void)
135 {
136         mga_cleanup();
137 }
138 #endif
139
140 #ifndef MODULE
141 /* mga_setup is called by the kernel to parse command-line options passed
142  * via the boot-loader (e.g., LILO).  It calls the insmod option routine,
143  * drm_parse_drm.
144  *
145  * This is not currently supported, since it requires changes to
146  * linux/init/main.c. */
147  
148
149 void __init mga_setup(char *str, int *ints)
150 {
151         if (ints[0] != 0) {
152                 DRM_ERROR("Illegal command line format, ignored\n");
153                 return;
154         }
155         drm_parse_options(str);
156 }
157 #endif
158
159 static int mga_setup(drm_device_t *dev)
160 {
161         int i;
162         
163         atomic_set(&dev->ioctl_count, 0);
164         atomic_set(&dev->vma_count, 0);
165         dev->buf_use      = 0;
166         atomic_set(&dev->buf_alloc, 0);
167
168         drm_dma_setup(dev);
169
170         atomic_set(&dev->total_open, 0);
171         atomic_set(&dev->total_close, 0);
172         atomic_set(&dev->total_ioctl, 0);
173         atomic_set(&dev->total_irq, 0);
174         atomic_set(&dev->total_ctx, 0);
175         atomic_set(&dev->total_locks, 0);
176         atomic_set(&dev->total_unlocks, 0);
177         atomic_set(&dev->total_contends, 0);
178         atomic_set(&dev->total_sleeps, 0);
179
180         for (i = 0; i < DRM_HASH_SIZE; i++) {
181                 dev->magiclist[i].head = NULL;
182                 dev->magiclist[i].tail = NULL;
183         }
184         dev->maplist        = NULL;
185         dev->map_count      = 0;
186         dev->vmalist        = NULL;
187         dev->lock.hw_lock   = NULL;
188         init_waitqueue_head(&dev->lock.lock_queue);
189         dev->queue_count    = 0;
190         dev->queue_reserved = 0;
191         dev->queue_slots    = 0;
192         dev->queuelist      = NULL;
193         dev->irq            = 0;
194         dev->context_flag   = 0;
195         dev->interrupt_flag = 0;
196         dev->dma_flag       = 0;
197         dev->last_context   = 0;
198         dev->last_switch    = 0;
199         dev->last_checked   = 0;
200         init_timer(&dev->timer);
201         init_waitqueue_head(&dev->context_wait);
202
203         dev->ctx_start      = 0;
204         dev->lck_start      = 0;
205         
206         dev->buf_rp       = dev->buf;
207         dev->buf_wp       = dev->buf;
208         dev->buf_end      = dev->buf + DRM_BSZ;
209         dev->buf_async    = NULL;
210         init_waitqueue_head(&dev->buf_readers);
211         init_waitqueue_head(&dev->buf_writers);
212                         
213         DRM_DEBUG("\n");
214                         
215         /* The kernel's context could be created here, but is now created
216            in drm_dma_enqueue.  This is more resource-efficient for
217            hardware that does not do DMA, but may mean that
218            drm_select_queue fails between the time the interrupt is
219            initialized and the time the queues are initialized. */
220                         
221         return 0;
222 }
223
224
225 static int mga_takedown(drm_device_t *dev)
226 {
227         int               i;
228         drm_magic_entry_t *pt, *next;
229         drm_map_t         *map;
230         drm_vma_entry_t   *vma, *vma_next;
231
232         DRM_DEBUG("\n");
233
234         if (dev->irq) mga_irq_uninstall(dev);
235         
236         down(&dev->struct_sem);
237         del_timer(&dev->timer);
238         
239         if (dev->devname) {
240                 drm_free(dev->devname, strlen(dev->devname)+1, DRM_MEM_DRIVER);
241                 dev->devname = NULL;
242         }
243         
244         if (dev->unique) {
245                 drm_free(dev->unique, strlen(dev->unique)+1, DRM_MEM_DRIVER);
246                 dev->unique = NULL;
247                 dev->unique_len = 0;
248         }
249                                 /* Clear pid list */
250         for (i = 0; i < DRM_HASH_SIZE; i++) {
251                 for (pt = dev->magiclist[i].head; pt; pt = next) {
252                         next = pt->next;
253                         drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
254                 }
255                 dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
256         }
257                                 /* Clear AGP information */
258         if (dev->agp) {
259                 drm_agp_mem_t *entry;
260                 drm_agp_mem_t *nexte;
261                 
262                                 /* Remove AGP resources, but leave dev->agp
263                                    intact until cleanup is called. */
264                 for (entry = dev->agp->memory; entry; entry = nexte) {
265                         nexte = entry->next;
266                         if (entry->bound) drm_unbind_agp(entry->memory);
267                         drm_free_agp(entry->memory, entry->pages);
268                         drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
269                 }
270                 dev->agp->memory = NULL;
271                 
272                 if (dev->agp->acquired && drm_agp.release)
273                         (*drm_agp.release)();
274                 
275                 dev->agp->acquired = 0;
276                 dev->agp->enabled  = 0;
277         }
278                                 /* Clear vma list (only built for debugging) */
279         if (dev->vmalist) {
280                 for (vma = dev->vmalist; vma; vma = vma_next) {
281                         vma_next = vma->next;
282                         drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
283                 }
284                 dev->vmalist = NULL;
285         }
286         
287                                 /* Clear map area and mtrr information */
288         if (dev->maplist) {
289                 for (i = 0; i < dev->map_count; i++) {
290                         map = dev->maplist[i];
291                         switch (map->type) {
292                         case _DRM_REGISTERS:
293                         case _DRM_FRAME_BUFFER:
294 #ifdef CONFIG_MTRR
295                                 if (map->mtrr >= 0) {
296                                         int retcode;
297                                         retcode = mtrr_del(map->mtrr,
298                                                            map->offset,
299                                                            map->size);
300                                         DRM_DEBUG("mtrr_del = %d\n", retcode);
301                                 }
302 #endif
303                                 drm_ioremapfree(map->handle, map->size);
304                                 break;
305                         case _DRM_SHM:
306                                 drm_free_pages((unsigned long)map->handle,
307                                                drm_order(map->size)
308                                                - PAGE_SHIFT,
309                                                DRM_MEM_SAREA);
310                                 break;
311                         case _DRM_AGP:
312                                 break;
313                         }
314                         drm_free(map, sizeof(*map), DRM_MEM_MAPS);
315                 }
316                 drm_free(dev->maplist,
317                          dev->map_count * sizeof(*dev->maplist),
318                          DRM_MEM_MAPS);
319                 dev->maplist   = NULL;
320                 dev->map_count = 0;
321         }
322         
323         if (dev->queuelist) {
324                 for (i = 0; i < dev->queue_count; i++) {
325                         drm_waitlist_destroy(&dev->queuelist[i]->waitlist);
326                         if (dev->queuelist[i]) {
327                                 drm_free(dev->queuelist[i],
328                                          sizeof(*dev->queuelist[0]),
329                                          DRM_MEM_QUEUES);
330                                 dev->queuelist[i] = NULL;
331                         }
332                 }
333                 drm_free(dev->queuelist,
334                          dev->queue_slots * sizeof(*dev->queuelist),
335                          DRM_MEM_QUEUES);
336                 dev->queuelist   = NULL;
337         }
338
339         drm_dma_takedown(dev);
340
341         dev->queue_count     = 0;
342         if (dev->lock.hw_lock) {
343                 dev->lock.hw_lock    = NULL; /* SHM removed */
344                 dev->lock.pid        = 0;
345                 wake_up_interruptible(&dev->lock.lock_queue);
346         }
347         up(&dev->struct_sem);
348         
349         return 0;
350 }
351
352 /* mga_init is called via init_module at module load time, or via
353  * linux/init/main.c (this is not currently supported). */
354
355 int mga_init(void)
356 {
357         int                   retcode;
358         drm_device_t          *dev = &mga_device;
359
360         DRM_DEBUG("\n");
361
362         memset((void *)dev, 0, sizeof(*dev));
363         dev->count_lock   = SPIN_LOCK_UNLOCKED;
364         sema_init(&dev->struct_sem, 1);
365         
366 #ifdef MODULE
367         drm_parse_options(mga);
368 #endif
369         DRM_DEBUG("doing misc_register\n");
370         if ((retcode = misc_register(&mga_misc))) {
371                 DRM_ERROR("Cannot register \"%s\"\n", MGA_NAME);
372                 return retcode;
373         }
374         dev->device = MKDEV(MISC_MAJOR, mga_misc.minor);
375         dev->name   = MGA_NAME;
376
377         DRM_DEBUG("doing mem init\n");
378         drm_mem_init();
379         DRM_DEBUG("doing proc init\n");
380         drm_proc_init(dev);
381         DRM_DEBUG("doing agp init\n");
382         dev->agp    = drm_agp_init();
383         DRM_DEBUG("doing ctxbitmap init\n");
384         if((retcode = drm_ctxbitmap_init(dev))) {
385                 DRM_ERROR("Cannot allocate memory for context bitmap.\n");
386                 drm_proc_cleanup();
387                 misc_deregister(&mga_misc);
388                 mga_takedown(dev);
389                 return retcode;
390         }
391
392         DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
393                  MGA_NAME,
394                  MGA_MAJOR,
395                  MGA_MINOR,
396                  MGA_PATCHLEVEL,
397                  MGA_DATE,
398                  mga_misc.minor);
399
400         return 0;
401 }
402
403 /* mga_cleanup is called via cleanup_module at module unload time. */
404
405 void mga_cleanup(void)
406 {
407         drm_device_t          *dev = &mga_device;
408
409         DRM_DEBUG("\n");
410         
411         drm_proc_cleanup();
412         if (misc_deregister(&mga_misc)) {
413                 DRM_ERROR("Cannot unload module\n");
414         } else {
415                 DRM_INFO("Module unloaded\n");
416         }
417         drm_ctxbitmap_cleanup(dev);
418         mga_dma_cleanup(dev);
419         mga_takedown(dev);
420         if (dev->agp) {
421                 drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
422                 dev->agp = NULL;
423         }
424 }
425
426 int mga_version(struct inode *inode, struct file *filp, unsigned int cmd,
427                   unsigned long arg)
428 {
429         drm_version_t version;
430         int           len;
431
432         copy_from_user_ret(&version,
433                            (drm_version_t *)arg,
434                            sizeof(version),
435                            -EFAULT);
436
437 #define DRM_COPY(name,value)                                 \
438         len = strlen(value);                                 \
439         if (len > name##_len) len = name##_len;              \
440         name##_len = strlen(value);                          \
441         if (len && name) {                                   \
442                 copy_to_user_ret(name, value, len, -EFAULT); \
443         }
444
445         version.version_major      = MGA_MAJOR;
446         version.version_minor      = MGA_MINOR;
447         version.version_patchlevel = MGA_PATCHLEVEL;
448
449         DRM_COPY(version.name, MGA_NAME);
450         DRM_COPY(version.date, MGA_DATE);
451         DRM_COPY(version.desc, MGA_DESC);
452
453         copy_to_user_ret((drm_version_t *)arg,
454                          &version,
455                          sizeof(version),
456                          -EFAULT);
457         return 0;
458 }
459
460 int mga_open(struct inode *inode, struct file *filp)
461 {
462         drm_device_t  *dev    = &mga_device;
463         int           retcode = 0;
464         
465         DRM_DEBUG("open_count = %d\n", dev->open_count);
466         if (!(retcode = drm_open_helper(inode, filp, dev))) {
467                 MOD_INC_USE_COUNT;
468                 atomic_inc(&dev->total_open);
469                 spin_lock(&dev->count_lock);
470                 if (!dev->open_count++) {
471                         spin_unlock(&dev->count_lock);
472                         return mga_setup(dev);
473                 }
474                 spin_unlock(&dev->count_lock);
475         }
476         return retcode;
477 }
478
479 int mga_release(struct inode *inode, struct file *filp)
480 {
481         drm_file_t    *priv   = filp->private_data;
482         drm_device_t  *dev    = priv->dev;
483         int           retcode = 0;
484
485         DRM_DEBUG("open_count = %d\n", dev->open_count);
486         if (!(retcode = drm_release(inode, filp))) {
487                 MOD_DEC_USE_COUNT;
488                 atomic_inc(&dev->total_close);
489                 spin_lock(&dev->count_lock);
490                 if (!--dev->open_count) {
491                         if (atomic_read(&dev->ioctl_count) || dev->blocked) {
492                                 DRM_ERROR("Device busy: %d %d\n",
493                                           atomic_read(&dev->ioctl_count),
494                                           dev->blocked);
495                                 spin_unlock(&dev->count_lock);
496                                 return -EBUSY;
497                         }
498                         spin_unlock(&dev->count_lock);
499                         return mga_takedown(dev);
500                 }
501                 spin_unlock(&dev->count_lock);
502         }
503         return retcode;
504 }
505
506 /* drm_ioctl is called whenever a process performs an ioctl on /dev/drm. */
507
508 int mga_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
509                 unsigned long arg)
510 {
511         int              nr      = DRM_IOCTL_NR(cmd);
512         drm_file_t       *priv   = filp->private_data;
513         drm_device_t     *dev    = priv->dev;
514         int              retcode = 0;
515         drm_ioctl_desc_t *ioctl;
516         drm_ioctl_t      *func;
517
518         atomic_inc(&dev->ioctl_count);
519         atomic_inc(&dev->total_ioctl);
520         ++priv->ioctl_count;
521         
522         DRM_DEBUG("pid = %d, cmd = 0x%02x, nr = 0x%02x, dev 0x%x, auth = %d\n",
523                   current->pid, cmd, nr, dev->device, priv->authenticated);
524
525         if (nr >= MGA_IOCTL_COUNT) {
526                 retcode = -EINVAL;
527         } else {
528                 ioctl     = &mga_ioctls[nr];
529                 func      = ioctl->func;
530
531                 if (!func) {
532                         DRM_DEBUG("no function\n");
533                         retcode = -EINVAL;
534                 } else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN))
535                             || (ioctl->auth_needed && !priv->authenticated)) {
536                         retcode = -EACCES;
537                 } else {
538                         retcode = (func)(inode, filp, cmd, arg);
539                 }
540         }
541         
542         atomic_dec(&dev->ioctl_count);
543         return retcode;
544 }
545
546 int mga_unlock(struct inode *inode, struct file *filp, unsigned int cmd,
547                  unsigned long arg)
548 {
549         drm_file_t        *priv   = filp->private_data;
550         drm_device_t      *dev    = priv->dev;
551         drm_lock_t        lock;
552
553         copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT);
554         
555         if (lock.context == DRM_KERNEL_CONTEXT) {
556                 DRM_ERROR("Process %d using kernel context %d\n",
557                           current->pid, lock.context);
558                 return -EINVAL;
559         }
560
561         DRM_DEBUG("%d frees lock (%d holds)\n",
562                   lock.context,
563                   _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
564         atomic_inc(&dev->total_unlocks);
565         if (_DRM_LOCK_IS_CONT(dev->lock.hw_lock->lock))
566                 atomic_inc(&dev->total_contends);
567         drm_lock_transfer(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
568         mga_dma_schedule(dev, 1);
569
570         if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
571                           DRM_KERNEL_CONTEXT)) {
572            DRM_ERROR("\n");
573         }
574
575         return 0;
576 }