drm: remove XFREE86_VERSION macros.
[deliverable/linux.git] / drivers / char / 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 */
bea5679f 43int drm_adddraw(DRM_IOCTL_ARGS)
1da177e4 44{
bea5679f
MCA
45 DRM_DEVICE;
46 unsigned long irqflags;
c60ce623 47 struct drm_draw draw;
d4e2cbe9
DA
48 int new_id = 0;
49 int ret;
1da177e4 50
d4e2cbe9
DA
51again:
52 if (idr_pre_get(&dev->drw_idr, GFP_KERNEL) == 0) {
53 DRM_ERROR("Out of memory expanding drawable idr\n");
54 return -ENOMEM;
bea5679f
MCA
55 }
56
b03ed6f2 57 spin_lock_irqsave(&dev->drw_lock, irqflags);
d4e2cbe9
DA
58 ret = idr_get_new_above(&dev->drw_idr, NULL, 1, &new_id);
59 if (ret == -EAGAIN) {
60 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
61 goto again;
b03ed6f2 62 }
bea5679f
MCA
63
64 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
65
d4e2cbe9
DA
66 draw.handle = new_id;
67
68 DRM_DEBUG("%d\n", draw.handle);
69
c60ce623 70 DRM_COPY_TO_USER_IOCTL((struct drm_draw __user *)data, draw, sizeof(draw));
bea5679f 71
1da177e4
LT
72 return 0;
73}
74
b03ed6f2
MCA
75/**
76 * Free drawable ID and memory to store information about it.
77 */
bea5679f 78int drm_rmdraw(DRM_IOCTL_ARGS)
1da177e4 79{
bea5679f 80 DRM_DEVICE;
c60ce623 81 struct drm_draw draw;
bea5679f
MCA
82 unsigned long irqflags;
83
c60ce623 84 DRM_COPY_FROM_USER_IOCTL(draw, (struct drm_draw __user *) data,
bea5679f
MCA
85 sizeof(draw));
86
b03ed6f2
MCA
87 spin_lock_irqsave(&dev->drw_lock, irqflags);
88
d4e2cbe9
DA
89 drm_free(drm_get_drawable_info(dev, draw.handle),
90 sizeof(struct drm_drawable_info), DRM_MEM_BUFS);
b03ed6f2 91
d4e2cbe9 92 idr_remove(&dev->drw_idr, draw.handle);
bea5679f 93
d4e2cbe9 94 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
bea5679f
MCA
95 DRM_DEBUG("%d\n", draw.handle);
96 return 0;
97}
98
d4e2cbe9
DA
99int drm_update_drawable_info(DRM_IOCTL_ARGS)
100{
bea5679f 101 DRM_DEVICE;
c60ce623 102 struct drm_update_draw update;
d4e2cbe9 103 unsigned long irqflags;
c60ce623 104 struct drm_clip_rect *rects;
d4e2cbe9 105 struct drm_drawable_info *info;
b03ed6f2 106 int err;
bea5679f 107
c60ce623 108 DRM_COPY_FROM_USER_IOCTL(update, (struct drm_update_draw __user *) data,
bea5679f
MCA
109 sizeof(update));
110
d4e2cbe9 111 info = idr_find(&dev->drw_idr, update.handle);
bea5679f 112 if (!info) {
d4e2cbe9
DA
113 info = drm_calloc(1, sizeof(*info), DRM_MEM_BUFS);
114 if (!info)
115 return -ENOMEM;
116 if (IS_ERR(idr_replace(&dev->drw_idr, info, update.handle))) {
117 DRM_ERROR("No such drawable %d\n", update.handle);
118 drm_free(info, sizeof(*info), DRM_MEM_BUFS);
119 return -EINVAL;
bea5679f 120 }
bea5679f
MCA
121 }
122
123 switch (update.type) {
124 case DRM_DRAWABLE_CLIPRECTS:
125 if (update.num != info->num_rects) {
c60ce623 126 rects = drm_alloc(update.num * sizeof(struct drm_clip_rect),
b03ed6f2
MCA
127 DRM_MEM_BUFS);
128 } else
129 rects = info->rects;
130
131 if (update.num && !rects) {
132 DRM_ERROR("Failed to allocate cliprect memory\n");
20caafa6 133 err = -ENOMEM;
b03ed6f2 134 goto error;
bea5679f
MCA
135 }
136
b03ed6f2 137 if (update.num && DRM_COPY_FROM_USER(rects,
c60ce623 138 (struct drm_clip_rect __user *)
b03ed6f2
MCA
139 (unsigned long)update.data,
140 update.num *
141 sizeof(*rects))) {
142 DRM_ERROR("Failed to copy cliprects from userspace\n");
20caafa6 143 err = -EFAULT;
b03ed6f2 144 goto error;
bea5679f
MCA
145 }
146
b03ed6f2
MCA
147 spin_lock_irqsave(&dev->drw_lock, irqflags);
148
149 if (rects != info->rects) {
bea5679f 150 drm_free(info->rects, info->num_rects *
c60ce623 151 sizeof(struct drm_clip_rect), DRM_MEM_BUFS);
bea5679f
MCA
152 }
153
b03ed6f2
MCA
154 info->rects = rects;
155 info->num_rects = update.num;
b03ed6f2
MCA
156
157 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
158
bea5679f 159 DRM_DEBUG("Updated %d cliprects for drawable %d\n",
d4e2cbe9 160 info->num_rects, update.handle);
bea5679f
MCA
161 break;
162 default:
163 DRM_ERROR("Invalid update type %d\n", update.type);
20caafa6 164 return -EINVAL;
bea5679f
MCA
165 }
166
bea5679f 167 return 0;
b03ed6f2
MCA
168
169error:
d4e2cbe9
DA
170 if (rects != info->rects)
171 drm_free(rects, update.num * sizeof(struct drm_clip_rect),
172 DRM_MEM_BUFS);
b03ed6f2
MCA
173
174 return err;
bea5679f
MCA
175}
176
177/**
178 * Caller must hold the drawable spinlock!
179 */
d4e2cbe9
DA
180struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, drm_drawable_t id)
181{
182 return idr_find(&dev->drw_idr, id);
183}
184EXPORT_SYMBOL(drm_get_drawable_info);
185
186static int drm_drawable_free(int idr, void *p, void *data)
187{
188 struct drm_drawable_info *info = p;
189
190 if (info) {
191 drm_free(info->rects, info->num_rects *
192 sizeof(struct drm_clip_rect), DRM_MEM_BUFS);
193 drm_free(info, sizeof(*info), DRM_MEM_BUFS);
bea5679f
MCA
194 }
195
d4e2cbe9
DA
196 return 0;
197}
198
199void drm_drawable_free_all(struct drm_device *dev)
200{
201 idr_for_each(&dev->drw_idr, drm_drawable_free, NULL);
202 idr_remove_all(&dev->drw_idr);
1da177e4 203}
This page took 0.25017 seconds and 5 git commands to generate.