Home | History | Annotate | Line # | Download | only in drm
drm_legacy_misc.c revision 1.2
      1 /*	$NetBSD: drm_legacy_misc.c,v 1.2 2021/12/18 23:44:57 riastradh Exp $	*/
      2 
      3 /*
      4  * \file drm_legacy_misc.c
      5  * Misc legacy support functions.
      6  *
      7  * \author Rickard E. (Rik) Faith <faith (at) valinux.com>
      8  * \author Gareth Hughes <gareth (at) valinux.com>
      9  */
     10 
     11 /*
     12  * Created: Tue Feb  2 08:37:54 1999 by faith (at) valinux.com
     13  *
     14  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
     15  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
     16  * All Rights Reserved.
     17  *
     18  * Permission is hereby granted, free of charge, to any person obtaining a
     19  * copy of this software and associated documentation files (the "Software"),
     20  * to deal in the Software without restriction, including without limitation
     21  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     22  * and/or sell copies of the Software, and to permit persons to whom the
     23  * Software is furnished to do so, subject to the following conditions:
     24  *
     25  * The above copyright notice and this permission notice (including the next
     26  * paragraph) shall be included in all copies or substantial portions of the
     27  * Software.
     28  *
     29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     30  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     31  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     32  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     33  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     34  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     35  * OTHER DEALINGS IN THE SOFTWARE.
     36  */
     37 
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: drm_legacy_misc.c,v 1.2 2021/12/18 23:44:57 riastradh Exp $");
     40 
     41 #include <drm/drm_agpsupport.h>
     42 #include <drm/drm_device.h>
     43 #include <drm/drm_drv.h>
     44 #include <drm/drm_irq.h>
     45 #include <drm/drm_print.h>
     46 
     47 #include "drm_internal.h"
     48 #include "drm_legacy.h"
     49 
     50 void drm_legacy_init_members(struct drm_device *dev)
     51 {
     52 	INIT_LIST_HEAD(&dev->ctxlist);
     53 	INIT_LIST_HEAD(&dev->vmalist);
     54 	INIT_LIST_HEAD(&dev->maplist);
     55 	spin_lock_init(&dev->buf_lock);
     56 	mutex_init(&dev->ctxlist_mutex);
     57 }
     58 
     59 void drm_legacy_destroy_members(struct drm_device *dev)
     60 {
     61 	mutex_destroy(&dev->ctxlist_mutex);
     62 }
     63 
     64 int drm_legacy_setup(struct drm_device * dev)
     65 {
     66 	int ret;
     67 
     68 	if (dev->driver->firstopen &&
     69 	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
     70 		ret = dev->driver->firstopen(dev);
     71 		if (ret != 0)
     72 			return ret;
     73 	}
     74 
     75 	ret = drm_legacy_dma_setup(dev);
     76 	if (ret < 0)
     77 		return ret;
     78 
     79 
     80 	DRM_DEBUG("\n");
     81 	return 0;
     82 }
     83 
     84 void drm_legacy_dev_reinit(struct drm_device *dev)
     85 {
     86 	if (dev->irq_enabled)
     87 		drm_irq_uninstall(dev);
     88 
     89 	mutex_lock(&dev->struct_mutex);
     90 
     91 	drm_legacy_agp_clear(dev);
     92 
     93 	drm_legacy_sg_cleanup(dev);
     94 	drm_legacy_vma_flush(dev);
     95 	drm_legacy_dma_takedown(dev);
     96 
     97 	mutex_unlock(&dev->struct_mutex);
     98 
     99 	dev->sigdata.lock = NULL;
    100 
    101 	dev->context_flag = 0;
    102 	dev->last_context = 0;
    103 	dev->if_version = 0;
    104 
    105 	DRM_DEBUG("lastclose completed\n");
    106 }
    107 
    108 void drm_master_legacy_init(struct drm_master *master)
    109 {
    110 	spin_lock_init(&master->lock.spinlock);
    111 	init_waitqueue_head(&master->lock.lock_queue);
    112 }
    113