Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /** |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2 | * \file drm_drawable.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * IOCTLs for drawables |
| 4 | * |
| 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
| 6 | * \author Gareth Hughes <gareth@valinux.com> |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 7 | * \author Michel Dänzer <michel@tungstengraphics.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 15 | * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 40 | /** |
| 41 | * Allocate drawable ID and memory to store information about it. |
| 42 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 43 | int drm_adddraw(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 45 | unsigned long irqflags; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 46 | struct drm_draw *draw = data; |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 47 | int new_id = 0; |
| 48 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 50 | again: |
| 51 | if (idr_pre_get(&dev->drw_idr, GFP_KERNEL) == 0) { |
| 52 | DRM_ERROR("Out of memory expanding drawable idr\n"); |
| 53 | return -ENOMEM; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 54 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 55 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 56 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 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; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 61 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 62 | |
| 63 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 64 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 65 | draw->handle = new_id; |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 66 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 67 | DRM_DEBUG("%d\n", draw->handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 72 | /** |
| 73 | * Free drawable ID and memory to store information about it. |
| 74 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 75 | int drm_rmdraw(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 77 | struct drm_draw *draw = data; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 78 | unsigned long irqflags; |
Zhenyu Wang | 786225e | 2008-10-17 15:48:44 +0800 | [diff] [blame] | 79 | struct drm_drawable_info *info; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 80 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 81 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 82 | |
Zhenyu Wang | 786225e | 2008-10-17 15:48:44 +0800 | [diff] [blame] | 83 | info = drm_get_drawable_info(dev, draw->handle); |
Eric Anholt | 7e78f72 | 2008-10-21 11:53:01 -0700 | [diff] [blame] | 84 | if (info == NULL) { |
| 85 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 86 | return -EINVAL; |
| 87 | } |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 88 | kfree(info->rects); |
| 89 | kfree(info); |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 90 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 91 | idr_remove(&dev->drw_idr, draw->handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 92 | |
| 93 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 94 | DRM_DEBUG("%d\n", draw->handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 95 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 97 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 98 | int drm_update_drawable_info(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 99 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 100 | struct drm_update_draw *update = data; |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 101 | unsigned long irqflags; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 102 | struct drm_clip_rect *rects; |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 103 | struct drm_drawable_info *info; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 104 | int err; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 105 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 106 | info = idr_find(&dev->drw_idr, update->handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 107 | if (!info) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 108 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 109 | if (!info) |
| 110 | return -ENOMEM; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 111 | if (IS_ERR(idr_replace(&dev->drw_idr, info, update->handle))) { |
| 112 | DRM_ERROR("No such drawable %d\n", update->handle); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 113 | kfree(info); |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 114 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 115 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 116 | } |
| 117 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 118 | switch (update->type) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 119 | case DRM_DRAWABLE_CLIPRECTS: |
Zhenyu Wang | 8638427 | 2008-10-17 13:15:48 +0800 | [diff] [blame] | 120 | if (update->num == 0) |
| 121 | rects = NULL; |
| 122 | else if (update->num != info->num_rects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 123 | rects = kmalloc(update->num * |
| 124 | sizeof(struct drm_clip_rect), |
| 125 | GFP_KERNEL); |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 126 | } else |
| 127 | rects = info->rects; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 128 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 129 | if (update->num && !rects) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 130 | DRM_ERROR("Failed to allocate cliprect memory\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 131 | err = -ENOMEM; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 132 | goto error; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 133 | } |
| 134 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 135 | if (update->num && DRM_COPY_FROM_USER(rects, |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 136 | (struct drm_clip_rect __user *) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 137 | (unsigned long)update->data, |
| 138 | update->num * |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 139 | sizeof(*rects))) { |
| 140 | DRM_ERROR("Failed to copy cliprects from userspace\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 141 | err = -EFAULT; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 142 | goto error; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 143 | } |
| 144 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 145 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 146 | |
| 147 | if (rects != info->rects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 148 | kfree(info->rects); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 149 | } |
| 150 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 151 | info->rects = rects; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 152 | info->num_rects = update->num; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 153 | |
| 154 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 155 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 156 | DRM_DEBUG("Updated %d cliprects for drawable %d\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 157 | info->num_rects, update->handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 158 | break; |
| 159 | default: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 160 | DRM_ERROR("Invalid update type %d\n", update->type); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 161 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 162 | } |
| 163 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 164 | return 0; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 165 | |
| 166 | error: |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 167 | if (rects != info->rects) |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 168 | kfree(rects); |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 169 | |
| 170 | return err; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Caller must hold the drawable spinlock! |
| 175 | */ |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 176 | struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, drm_drawable_t id) |
| 177 | { |
| 178 | return idr_find(&dev->drw_idr, id); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 179 | } |
| 180 | EXPORT_SYMBOL(drm_get_drawable_info); |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 181 | |
| 182 | static int drm_drawable_free(int idr, void *p, void *data) |
| 183 | { |
| 184 | struct drm_drawable_info *info = p; |
| 185 | |
| 186 | if (info) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 187 | kfree(info->rects); |
| 188 | kfree(info); |
Dave Airlie | d4e2cbe | 2007-07-17 10:55:47 +1000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | void 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); |
| 198 | } |