1*793a5791Sriastradh /*	$NetBSD: drm_legacy_misc.c,v 1.3 2021/12/19 12:30:04 riastradh Exp $	*/
21571a7a1Sriastradh 
31571a7a1Sriastradh /*
41571a7a1Sriastradh  * \file drm_legacy_misc.c
51571a7a1Sriastradh  * Misc legacy support functions.
61571a7a1Sriastradh  *
71571a7a1Sriastradh  * \author Rickard E. (Rik) Faith <faith@valinux.com>
81571a7a1Sriastradh  * \author Gareth Hughes <gareth@valinux.com>
91571a7a1Sriastradh  */
101571a7a1Sriastradh 
111571a7a1Sriastradh /*
121571a7a1Sriastradh  * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
131571a7a1Sriastradh  *
141571a7a1Sriastradh  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
151571a7a1Sriastradh  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
161571a7a1Sriastradh  * All Rights Reserved.
171571a7a1Sriastradh  *
181571a7a1Sriastradh  * Permission is hereby granted, free of charge, to any person obtaining a
191571a7a1Sriastradh  * copy of this software and associated documentation files (the "Software"),
201571a7a1Sriastradh  * to deal in the Software without restriction, including without limitation
211571a7a1Sriastradh  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
221571a7a1Sriastradh  * and/or sell copies of the Software, and to permit persons to whom the
231571a7a1Sriastradh  * Software is furnished to do so, subject to the following conditions:
241571a7a1Sriastradh  *
251571a7a1Sriastradh  * The above copyright notice and this permission notice (including the next
261571a7a1Sriastradh  * paragraph) shall be included in all copies or substantial portions of the
271571a7a1Sriastradh  * Software.
281571a7a1Sriastradh  *
291571a7a1Sriastradh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
301571a7a1Sriastradh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
311571a7a1Sriastradh  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
321571a7a1Sriastradh  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
331571a7a1Sriastradh  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
341571a7a1Sriastradh  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
351571a7a1Sriastradh  * OTHER DEALINGS IN THE SOFTWARE.
361571a7a1Sriastradh  */
371571a7a1Sriastradh 
381571a7a1Sriastradh #include <sys/cdefs.h>
39*793a5791Sriastradh __KERNEL_RCSID(0, "$NetBSD: drm_legacy_misc.c,v 1.3 2021/12/19 12:30:04 riastradh Exp $");
401571a7a1Sriastradh 
411571a7a1Sriastradh #include <drm/drm_agpsupport.h>
421571a7a1Sriastradh #include <drm/drm_device.h>
431571a7a1Sriastradh #include <drm/drm_drv.h>
441571a7a1Sriastradh #include <drm/drm_irq.h>
451571a7a1Sriastradh #include <drm/drm_print.h>
461571a7a1Sriastradh 
471571a7a1Sriastradh #include "drm_internal.h"
481571a7a1Sriastradh #include "drm_legacy.h"
491571a7a1Sriastradh 
50*793a5791Sriastradh #include <linux/nbsd-namespace.h>
51*793a5791Sriastradh 
drm_legacy_init_members(struct drm_device * dev)521571a7a1Sriastradh void drm_legacy_init_members(struct drm_device *dev)
531571a7a1Sriastradh {
541571a7a1Sriastradh 	INIT_LIST_HEAD(&dev->ctxlist);
551571a7a1Sriastradh 	INIT_LIST_HEAD(&dev->vmalist);
561571a7a1Sriastradh 	INIT_LIST_HEAD(&dev->maplist);
571571a7a1Sriastradh 	spin_lock_init(&dev->buf_lock);
581571a7a1Sriastradh 	mutex_init(&dev->ctxlist_mutex);
591571a7a1Sriastradh }
601571a7a1Sriastradh 
drm_legacy_destroy_members(struct drm_device * dev)611571a7a1Sriastradh void drm_legacy_destroy_members(struct drm_device *dev)
621571a7a1Sriastradh {
631571a7a1Sriastradh 	mutex_destroy(&dev->ctxlist_mutex);
64*793a5791Sriastradh 	spin_lock_destroy(&dev->buf_lock);
651571a7a1Sriastradh }
661571a7a1Sriastradh 
drm_legacy_setup(struct drm_device * dev)671571a7a1Sriastradh int drm_legacy_setup(struct drm_device * dev)
681571a7a1Sriastradh {
691571a7a1Sriastradh 	int ret;
701571a7a1Sriastradh 
711571a7a1Sriastradh 	if (dev->driver->firstopen &&
721571a7a1Sriastradh 	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
731571a7a1Sriastradh 		ret = dev->driver->firstopen(dev);
741571a7a1Sriastradh 		if (ret != 0)
751571a7a1Sriastradh 			return ret;
761571a7a1Sriastradh 	}
771571a7a1Sriastradh 
781571a7a1Sriastradh 	ret = drm_legacy_dma_setup(dev);
791571a7a1Sriastradh 	if (ret < 0)
801571a7a1Sriastradh 		return ret;
811571a7a1Sriastradh 
821571a7a1Sriastradh 
831571a7a1Sriastradh 	DRM_DEBUG("\n");
841571a7a1Sriastradh 	return 0;
851571a7a1Sriastradh }
861571a7a1Sriastradh 
drm_legacy_dev_reinit(struct drm_device * dev)871571a7a1Sriastradh void drm_legacy_dev_reinit(struct drm_device *dev)
881571a7a1Sriastradh {
891571a7a1Sriastradh 	if (dev->irq_enabled)
901571a7a1Sriastradh 		drm_irq_uninstall(dev);
911571a7a1Sriastradh 
921571a7a1Sriastradh 	mutex_lock(&dev->struct_mutex);
931571a7a1Sriastradh 
941571a7a1Sriastradh 	drm_legacy_agp_clear(dev);
951571a7a1Sriastradh 
961571a7a1Sriastradh 	drm_legacy_sg_cleanup(dev);
971571a7a1Sriastradh 	drm_legacy_vma_flush(dev);
981571a7a1Sriastradh 	drm_legacy_dma_takedown(dev);
991571a7a1Sriastradh 
1001571a7a1Sriastradh 	mutex_unlock(&dev->struct_mutex);
1011571a7a1Sriastradh 
1021571a7a1Sriastradh 	dev->sigdata.lock = NULL;
1031571a7a1Sriastradh 
1041571a7a1Sriastradh 	dev->context_flag = 0;
1051571a7a1Sriastradh 	dev->last_context = 0;
1061571a7a1Sriastradh 	dev->if_version = 0;
1071571a7a1Sriastradh 
1081571a7a1Sriastradh 	DRM_DEBUG("lastclose completed\n");
1091571a7a1Sriastradh }
1101571a7a1Sriastradh 
drm_master_legacy_init(struct drm_master * master)1111571a7a1Sriastradh void drm_master_legacy_init(struct drm_master *master)
1121571a7a1Sriastradh {
1131571a7a1Sriastradh 	spin_lock_init(&master->lock.spinlock);
114*793a5791Sriastradh 	DRM_INIT_WAITQUEUE(&master->lock.lock_queue, "drmlock");
1151571a7a1Sriastradh }
116