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