drm: Remove memory debugging infrastructure.
[deliverable/linux.git] / drivers / gpu / drm / drm_drawable.c
CommitLineData
1da177e4 1/**
b5e89ed5 2 * \file drm_drawable.c
1da177e4
LT
3 * IOCTLs for drawables
4 *
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
bea5679f 7 * \author Michel Dänzer <michel@tungstengraphics.com>
1da177e4
LT
8 */
9
10/*
11 * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
12 *
13 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
14 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
b03ed6f2 15 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota.
1da177e4
LT
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 "drmP.h"
39
b03ed6f2
MCA
40/**
41 * Allocate drawable ID and memory to store information about it.
42 */
c153f45f 43int drm_adddraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
1da177e4 44{
bea5679f 45 unsigned long irqflags;
c153f45f 46 struct drm_draw *draw = data;
d4e2cbe9
DA
47 int new_id = 0;
48 int ret;
1da177e4 49
d4e2cbe9
DA
50again:
51 if (idr_pre_get(&dev->drw_idr, GFP_KERNEL) == 0) {
52 DRM_ERROR("Out of memory expanding drawable idr\n");
53 return -ENOMEM;
bea5679f
MCA
54 }
55
b03ed6f2 56 spin_lock_irqsave(&dev->drw_lock, irqflags);
d4e2cbe9
DA
57 ret = idr_get_new_above(&dev->drw_idr, NULL, 1, &new_id);
58 if (ret == -EAGAIN) {
59 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
60 goto again;
b03ed6f2 61 }
bea5679f
MCA
62
63 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
64
c153f45f 65 draw->handle = new_id;
d4e2cbe9 66
c153f45f 67 DRM_DEBUG("%d\n", draw->handle);
bea5679f 68
1da177e4
LT
69 return 0;
70}
71
b03ed6f2
MCA
72/**
73 * Free drawable ID and memory to store information about it.
74 */
c153f45f 75int drm_rmdraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
1da177e4 76{
c153f45f 77 struct drm_draw *draw = data;
bea5679f 78 unsigned long irqflags;
786225eb 79 struct drm_drawable_info *info;
bea5679f 80
b03ed6f2
MCA
81 spin_lock_irqsave(&dev->drw_lock, irqflags);
82
786225eb 83 info = drm_get_drawable_info(dev, draw->handle);
7e78f725
EA
84 if (info == NULL) {
85 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
86 return -EINVAL;
87 }
9a298b2a
EA
88 kfree(info->rects);
89 kfree(info);
b03ed6f2 90
c153f45f 91 idr_remove(&dev->drw_idr, draw->handle);
bea5679f 92
d4e2cbe9 93 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
c153f45f 94 DRM_DEBUG("%d\n", draw->handle);
bea5679f
MCA
95 return 0;
96}
97
c153f45f 98int drm_update_drawable_info(struct drm_device *dev, void *data, struct drm_file *file_priv)
d4e2cbe9 99{
c153f45f 100 struct drm_update_draw *update = data;
d4e2cbe9 101 unsigned long irqflags;
c60ce623 102 struct drm_clip_rect *rects;
d4e2cbe9 103 struct drm_drawable_info *info;
b03ed6f2 104 int err;
bea5679f 105
c153f45f 106 info = idr_find(&dev->drw_idr, update->handle);
bea5679f 107 if (!info) {
9a298b2a 108 info = kzalloc(sizeof(*info), GFP_KERNEL);
d4e2cbe9
DA
109 if (!info)
110 return -ENOMEM;
c153f45f
EA
111 if (IS_ERR(idr_replace(&dev->drw_idr, info, update->handle))) {
112 DRM_ERROR("No such drawable %d\n", update->handle);
9a298b2a 113 kfree(info);
d4e2cbe9 114 return -EINVAL;
bea5679f 115 }
bea5679f
MCA
116 }
117
c153f45f 118 switch (update->type) {
bea5679f 119 case DRM_DRAWABLE_CLIPRECTS:
86384273
ZW
120 if (update->num == 0)
121 rects = NULL;
122 else if (update->num != info->num_rects) {
9a298b2a
EA
123 rects = kmalloc(update->num *
124 sizeof(struct drm_clip_rect),
125 GFP_KERNEL);
b03ed6f2
MCA
126 } else
127 rects = info->rects;
128
c153f45f 129 if (update->num && !rects) {
b03ed6f2 130 DRM_ERROR("Failed to allocate cliprect memory\n");
20caafa6 131 err = -ENOMEM;
b03ed6f2 132 goto error;
bea5679f
MCA
133 }
134
c153f45f 135 if (update->num && DRM_COPY_FROM_USER(rects,
c60ce623 136 (struct drm_clip_rect __user *)
c153f45f
EA
137 (unsigned long)update->data,
138 update->num *
b03ed6f2
MCA
139 sizeof(*rects))) {
140 DRM_ERROR("Failed to copy cliprects from userspace\n");
20caafa6 141 err = -EFAULT;
b03ed6f2 142 goto error;
bea5679f
MCA
143 }
144
b03ed6f2
MCA
145 spin_lock_irqsave(&dev->drw_lock, irqflags);
146
147 if (rects != info->rects) {
9a298b2a 148 kfree(info->rects);
bea5679f
MCA
149 }
150
b03ed6f2 151 info->rects = rects;
c153f45f 152 info->num_rects = update->num;
b03ed6f2
MCA
153
154 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
155
bea5679f 156 DRM_DEBUG("Updated %d cliprects for drawable %d\n",
c153f45f 157 info->num_rects, update->handle);
bea5679f
MCA
158 break;
159 default:
c153f45f 160 DRM_ERROR("Invalid update type %d\n", update->type);
20caafa6 161 return -EINVAL;
bea5679f
MCA
162 }
163
bea5679f 164 return 0;
b03ed6f2
MCA
165
166error:
d4e2cbe9 167 if (rects != info->rects)
9a298b2a 168 kfree(rects);
b03ed6f2
MCA
169
170 return err;
bea5679f
MCA
171}
172
173/**
174 * Caller must hold the drawable spinlock!
175 */
d4e2cbe9
DA
176struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, drm_drawable_t id)
177{
178 return idr_find(&dev->drw_idr, id);
179}
180EXPORT_SYMBOL(drm_get_drawable_info);
181
182static int drm_drawable_free(int idr, void *p, void *data)
183{
184 struct drm_drawable_info *info = p;
185
186 if (info) {
9a298b2a
EA
187 kfree(info->rects);
188 kfree(info);
bea5679f
MCA
189 }
190
d4e2cbe9
DA
191 return 0;
192}
193
194void drm_drawable_free_all(struct drm_device *dev)
195{
196 idr_for_each(&dev->drw_idr, drm_drawable_free, NULL);
197 idr_remove_all(&dev->drw_idr);
1da177e4 198}
This page took 0.400075 seconds and 5 git commands to generate.