1/* $NetBSD: drm_legacy_misc.c,v 1.3 2021/12/19 12:30:04 riastradh Exp $ */ 2 3/* 4 * \file drm_legacy_misc.c 5 * Misc legacy support functions. 6 * 7 * \author Rickard E. (Rik) Faith <faith@valinux.com> 8 * \author Gareth Hughes <gareth@valinux.com> 9 */ 10 11/* 12 * Created: Tue Feb 2 08:37:54 1999 by faith@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.3 2021/12/19 12:30:04 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#include <linux/nbsd-namespace.h> 51 52void drm_legacy_init_members(struct drm_device *dev) 53{ 54 INIT_LIST_HEAD(&dev->ctxlist); 55 INIT_LIST_HEAD(&dev->vmalist); 56 INIT_LIST_HEAD(&dev->maplist); 57 spin_lock_init(&dev->buf_lock); 58 mutex_init(&dev->ctxlist_mutex); 59} 60 61void drm_legacy_destroy_members(struct drm_device *dev) 62{ 63 mutex_destroy(&dev->ctxlist_mutex); 64 spin_lock_destroy(&dev->buf_lock); 65} 66 67int drm_legacy_setup(struct drm_device * dev) 68{ 69 int ret; 70 71 if (dev->driver->firstopen && 72 drm_core_check_feature(dev, DRIVER_LEGACY)) { 73 ret = dev->driver->firstopen(dev); 74 if (ret != 0) 75 return ret; 76 } 77 78 ret = drm_legacy_dma_setup(dev); 79 if (ret < 0) 80 return ret; 81 82 83 DRM_DEBUG("\n"); 84 return 0; 85} 86 87void drm_legacy_dev_reinit(struct drm_device *dev) 88{ 89 if (dev->irq_enabled) 90 drm_irq_uninstall(dev); 91 92 mutex_lock(&dev->struct_mutex); 93 94 drm_legacy_agp_clear(dev); 95 96 drm_legacy_sg_cleanup(dev); 97 drm_legacy_vma_flush(dev); 98 drm_legacy_dma_takedown(dev); 99 100 mutex_unlock(&dev->struct_mutex); 101 102 dev->sigdata.lock = NULL; 103 104 dev->context_flag = 0; 105 dev->last_context = 0; 106 dev->if_version = 0; 107 108 DRM_DEBUG("lastclose completed\n"); 109} 110 111void drm_master_legacy_init(struct drm_master *master) 112{ 113 spin_lock_init(&master->lock.spinlock); 114 DRM_INIT_WAITQUEUE(&master->lock.lock_queue, "drmlock"); 115} 116