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 | */ |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 43 | int drm_adddraw(DRM_IOCTL_ARGS) |
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 | DRM_DEVICE; |
| 46 | unsigned long irqflags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 47 | int i, j; |
| 48 | u32 *bitfield = dev->drw_bitfield; |
| 49 | unsigned int bitfield_length = dev->drw_bitfield_length; |
| 50 | drm_drawable_info_t **info = dev->drw_info; |
| 51 | unsigned int info_length = dev->drw_info_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | drm_draw_t draw; |
| 53 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 54 | for (i = 0, j = 0; i < bitfield_length; i++) { |
| 55 | if (bitfield[i] == ~0) |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 56 | continue; |
| 57 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 58 | for (; j < 8 * sizeof(*bitfield); j++) |
| 59 | if (!(bitfield[i] & (1 << j))) |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 60 | goto done; |
| 61 | } |
| 62 | done: |
| 63 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 64 | if (i == bitfield_length) { |
| 65 | bitfield_length++; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 66 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 67 | bitfield = drm_alloc(bitfield_length * sizeof(*bitfield), |
| 68 | DRM_MEM_BUFS); |
| 69 | |
| 70 | if (!bitfield) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 71 | DRM_ERROR("Failed to allocate new drawable bitfield\n"); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 72 | return DRM_ERR(ENOMEM); |
| 73 | } |
| 74 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 75 | if (8 * sizeof(*bitfield) * bitfield_length > info_length) { |
| 76 | info_length += 8 * sizeof(*bitfield); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 77 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 78 | info = drm_alloc(info_length * sizeof(*info), |
| 79 | DRM_MEM_BUFS); |
| 80 | |
| 81 | if (!info) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 82 | DRM_ERROR("Failed to allocate new drawable info" |
| 83 | " array\n"); |
| 84 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 85 | drm_free(bitfield, |
| 86 | bitfield_length * sizeof(*bitfield), |
| 87 | DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 88 | return DRM_ERR(ENOMEM); |
| 89 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 90 | } |
| 91 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 92 | bitfield[i] = 0; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 93 | } |
| 94 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 95 | draw.handle = i * 8 * sizeof(*bitfield) + j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | DRM_DEBUG("%d\n", draw.handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 97 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 98 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 99 | |
| 100 | bitfield[i] |= 1 << j; |
| 101 | info[draw.handle] = NULL; |
| 102 | |
| 103 | if (bitfield != dev->drw_bitfield) { |
| 104 | memcpy(bitfield, dev->drw_bitfield, dev->drw_bitfield_length * |
| 105 | sizeof(*bitfield)); |
| 106 | drm_free(dev->drw_bitfield, sizeof(*bitfield) * |
| 107 | dev->drw_bitfield_length, DRM_MEM_BUFS); |
| 108 | dev->drw_bitfield = bitfield; |
| 109 | dev->drw_bitfield_length = bitfield_length; |
| 110 | } |
| 111 | |
| 112 | if (info != dev->drw_info) { |
| 113 | memcpy(info, dev->drw_info, dev->drw_info_length * |
| 114 | sizeof(*info)); |
| 115 | drm_free(dev->drw_info, sizeof(*info) * dev->drw_info_length, |
| 116 | DRM_MEM_BUFS); |
| 117 | dev->drw_info = info; |
| 118 | dev->drw_info_length = info_length; |
| 119 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 120 | |
| 121 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 122 | |
| 123 | DRM_COPY_TO_USER_IOCTL((drm_draw_t __user *)data, draw, sizeof(draw)); |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 128 | /** |
| 129 | * Free drawable ID and memory to store information about it. |
| 130 | */ |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 131 | int drm_rmdraw(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 133 | DRM_DEVICE; |
| 134 | drm_draw_t draw; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 135 | unsigned int idx, shift; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 136 | unsigned long irqflags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 137 | u32 *bitfield = dev->drw_bitfield; |
| 138 | unsigned int bitfield_length = dev->drw_bitfield_length; |
| 139 | drm_drawable_info_t **info = dev->drw_info; |
| 140 | unsigned int info_length = dev->drw_info_length; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 141 | |
| 142 | DRM_COPY_FROM_USER_IOCTL(draw, (drm_draw_t __user *) data, |
| 143 | sizeof(draw)); |
| 144 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 145 | idx = draw.handle / (8 * sizeof(*bitfield)); |
| 146 | shift = draw.handle % (8 * sizeof(*bitfield)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 147 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 148 | if (idx >= bitfield_length || |
| 149 | !(bitfield[idx] & (1 << shift))) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 150 | DRM_DEBUG("No such drawable %d\n", draw.handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 154 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 155 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 156 | bitfield[idx] &= ~(1 << shift); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 157 | |
| 158 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 159 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 160 | /* Can we shrink the arrays? */ |
| 161 | if (idx == bitfield_length - 1) { |
| 162 | while (idx >= 0 && !bitfield[idx]) |
| 163 | --idx; |
| 164 | |
| 165 | bitfield_length = idx + 1; |
| 166 | |
| 167 | if (idx != draw.handle / (8 * sizeof(*bitfield))) |
| 168 | bitfield = drm_alloc(bitfield_length * |
| 169 | sizeof(*bitfield), DRM_MEM_BUFS); |
| 170 | |
| 171 | if (!bitfield && bitfield_length) { |
| 172 | bitfield = dev->drw_bitfield; |
| 173 | bitfield_length = dev->drw_bitfield_length; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (bitfield != dev->drw_bitfield) { |
| 178 | info_length = 8 * sizeof(*bitfield) * bitfield_length; |
| 179 | |
| 180 | info = drm_alloc(info_length * sizeof(*info), DRM_MEM_BUFS); |
| 181 | |
| 182 | if (!info && info_length) { |
| 183 | info = dev->drw_info; |
| 184 | info_length = dev->drw_info_length; |
| 185 | } |
| 186 | |
| 187 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 188 | |
| 189 | memcpy(bitfield, dev->drw_bitfield, bitfield_length * |
| 190 | sizeof(*bitfield)); |
| 191 | drm_free(dev->drw_bitfield, sizeof(*bitfield) * |
| 192 | dev->drw_bitfield_length, DRM_MEM_BUFS); |
| 193 | dev->drw_bitfield = bitfield; |
| 194 | dev->drw_bitfield_length = bitfield_length; |
| 195 | |
| 196 | if (info != dev->drw_info) { |
| 197 | memcpy(info, dev->drw_info, info_length * |
| 198 | sizeof(*info)); |
| 199 | drm_free(dev->drw_info, sizeof(*info) * |
| 200 | dev->drw_info_length, DRM_MEM_BUFS); |
| 201 | dev->drw_info = info; |
| 202 | dev->drw_info_length = info_length; |
| 203 | } |
| 204 | |
| 205 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 206 | } |
| 207 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 208 | DRM_DEBUG("%d\n", draw.handle); |
| 209 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 211 | |
| 212 | int drm_update_drawable_info(DRM_IOCTL_ARGS) { |
| 213 | DRM_DEVICE; |
| 214 | drm_update_draw_t update; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 215 | unsigned int id, idx, shift; |
| 216 | u32 *bitfield = dev->drw_bitfield; |
| 217 | unsigned long irqflags, bitfield_length = dev->drw_bitfield_length; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 218 | drm_drawable_info_t *info; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 219 | drm_clip_rect_t *rects; |
| 220 | int err; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 221 | |
| 222 | DRM_COPY_FROM_USER_IOCTL(update, (drm_update_draw_t __user *) data, |
| 223 | sizeof(update)); |
| 224 | |
| 225 | id = update.handle; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 226 | idx = id / (8 * sizeof(*bitfield)); |
| 227 | shift = id % (8 * sizeof(*bitfield)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 228 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 229 | if (idx >= bitfield_length || !(bitfield[idx] & (1 << shift))) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 230 | DRM_ERROR("No such drawable %d\n", update.handle); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 231 | return DRM_ERR(EINVAL); |
| 232 | } |
| 233 | |
| 234 | info = dev->drw_info[id]; |
| 235 | |
| 236 | if (!info) { |
| 237 | info = drm_calloc(1, sizeof(drm_drawable_info_t), DRM_MEM_BUFS); |
| 238 | |
| 239 | if (!info) { |
| 240 | DRM_ERROR("Failed to allocate drawable info memory\n"); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 241 | return DRM_ERR(ENOMEM); |
| 242 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | switch (update.type) { |
| 246 | case DRM_DRAWABLE_CLIPRECTS: |
| 247 | if (update.num != info->num_rects) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 248 | rects = drm_alloc(update.num * sizeof(drm_clip_rect_t), |
| 249 | DRM_MEM_BUFS); |
| 250 | } else |
| 251 | rects = info->rects; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 252 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 253 | if (update.num && !rects) { |
| 254 | DRM_ERROR("Failed to allocate cliprect memory\n"); |
| 255 | err = DRM_ERR(ENOMEM); |
| 256 | goto error; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 257 | } |
| 258 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 259 | if (update.num && DRM_COPY_FROM_USER(rects, |
| 260 | (drm_clip_rect_t __user *) |
| 261 | (unsigned long)update.data, |
| 262 | update.num * |
| 263 | sizeof(*rects))) { |
| 264 | DRM_ERROR("Failed to copy cliprects from userspace\n"); |
| 265 | err = DRM_ERR(EFAULT); |
| 266 | goto error; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 267 | } |
| 268 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 269 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 270 | |
| 271 | if (rects != info->rects) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 272 | drm_free(info->rects, info->num_rects * |
| 273 | sizeof(drm_clip_rect_t), DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 274 | } |
| 275 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 276 | info->rects = rects; |
| 277 | info->num_rects = update.num; |
| 278 | dev->drw_info[id] = info; |
| 279 | |
| 280 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 281 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 282 | DRM_DEBUG("Updated %d cliprects for drawable %d\n", |
| 283 | info->num_rects, id); |
| 284 | break; |
| 285 | default: |
| 286 | DRM_ERROR("Invalid update type %d\n", update.type); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 287 | return DRM_ERR(EINVAL); |
| 288 | } |
| 289 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 290 | return 0; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 291 | |
| 292 | error: |
| 293 | if (!dev->drw_info[id]) |
| 294 | drm_free(info, sizeof(*info), DRM_MEM_BUFS); |
| 295 | else if (rects != dev->drw_info[id]->rects) |
| 296 | drm_free(rects, update.num * |
| 297 | sizeof(drm_clip_rect_t), DRM_MEM_BUFS); |
| 298 | |
| 299 | return err; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Caller must hold the drawable spinlock! |
| 304 | */ |
| 305 | drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev, drm_drawable_t id) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 306 | u32 *bitfield = dev->drw_bitfield; |
| 307 | unsigned int idx = id / (8 * sizeof(*bitfield)); |
| 308 | unsigned int shift = id % (8 * sizeof(*bitfield)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 309 | |
| 310 | if (idx >= dev->drw_bitfield_length || |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame^] | 311 | !(bitfield[idx] & (1 << shift))) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 312 | DRM_DEBUG("No such drawable %d\n", id); |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | return dev->drw_info[id]; |
| 317 | } |
| 318 | EXPORT_SYMBOL(drm_get_drawable_info); |