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; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 50 | struct drm_drawable_info **info = dev->drw_info; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 51 | unsigned int info_length = dev->drw_info_length; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 52 | struct drm_draw draw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 95 | draw.handle = i * 8 * sizeof(*bitfield) + j + 1; |
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; |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 101 | info[draw.handle - 1] = NULL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 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 | |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 123 | DRM_COPY_TO_USER_IOCTL((struct drm_draw __user *)data, draw, sizeof(draw)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 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; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 134 | struct drm_draw draw; |
=?utf-8?q?Felix_K=C3=BChling?= | 507c018 | 2006-10-24 23:28:23 +1000 | [diff] [blame] | 135 | int id, idx; |
| 136 | unsigned int shift; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 137 | unsigned long irqflags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 138 | u32 *bitfield = dev->drw_bitfield; |
| 139 | unsigned int bitfield_length = dev->drw_bitfield_length; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 140 | struct drm_drawable_info **info = dev->drw_info; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 141 | 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] | 142 | |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 143 | DRM_COPY_FROM_USER_IOCTL(draw, (struct drm_draw __user *) data, |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 144 | sizeof(draw)); |
| 145 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 146 | id = draw.handle - 1; |
| 147 | idx = id / (8 * sizeof(*bitfield)); |
| 148 | shift = id % (8 * sizeof(*bitfield)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 149 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 150 | if (idx < 0 || idx >= bitfield_length || |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 151 | !(bitfield[idx] & (1 << shift))) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 152 | 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] | 153 | return 0; |
| 154 | } |
| 155 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 156 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 157 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 158 | bitfield[idx] &= ~(1 << shift); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 159 | |
| 160 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 161 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 162 | if (info[id]) { |
| 163 | drm_free(info[id]->rects, info[id]->num_rects * |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 164 | sizeof(struct drm_clip_rect), DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 165 | drm_free(info[id], sizeof(**info), DRM_MEM_BUFS); |
| 166 | } |
| 167 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 168 | /* Can we shrink the arrays? */ |
| 169 | if (idx == bitfield_length - 1) { |
| 170 | while (idx >= 0 && !bitfield[idx]) |
| 171 | --idx; |
| 172 | |
| 173 | bitfield_length = idx + 1; |
| 174 | |
Michel Dänzer | c4814f9 | 2007-05-26 04:37:08 +1000 | [diff] [blame] | 175 | bitfield = NULL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 176 | |
Michel Dänzer | c4814f9 | 2007-05-26 04:37:08 +1000 | [diff] [blame] | 177 | if (bitfield_length) { |
| 178 | if (bitfield_length != dev->drw_bitfield_length) |
| 179 | bitfield = drm_alloc(bitfield_length * |
| 180 | sizeof(*bitfield), |
| 181 | DRM_MEM_BUFS); |
| 182 | |
| 183 | if (!bitfield) { |
| 184 | bitfield = dev->drw_bitfield; |
| 185 | bitfield_length = dev->drw_bitfield_length; |
| 186 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | if (bitfield != dev->drw_bitfield) { |
| 191 | info_length = 8 * sizeof(*bitfield) * bitfield_length; |
| 192 | |
Michel Dänzer | c4814f9 | 2007-05-26 04:37:08 +1000 | [diff] [blame] | 193 | if (info_length) { |
| 194 | info = drm_alloc(info_length * sizeof(*info), |
| 195 | DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 196 | |
Michel Dänzer | c4814f9 | 2007-05-26 04:37:08 +1000 | [diff] [blame] | 197 | if (!info) { |
| 198 | info = dev->drw_info; |
| 199 | info_length = dev->drw_info_length; |
| 200 | } |
| 201 | } else |
| 202 | info = NULL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 203 | |
| 204 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 205 | |
Michel Dänzer | c4814f9 | 2007-05-26 04:37:08 +1000 | [diff] [blame] | 206 | if (bitfield) |
| 207 | memcpy(bitfield, dev->drw_bitfield, bitfield_length * |
| 208 | sizeof(*bitfield)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 209 | drm_free(dev->drw_bitfield, sizeof(*bitfield) * |
| 210 | dev->drw_bitfield_length, DRM_MEM_BUFS); |
| 211 | dev->drw_bitfield = bitfield; |
| 212 | dev->drw_bitfield_length = bitfield_length; |
| 213 | |
| 214 | if (info != dev->drw_info) { |
Michel Dänzer | c4814f9 | 2007-05-26 04:37:08 +1000 | [diff] [blame] | 215 | if (info) |
| 216 | memcpy(info, dev->drw_info, info_length * |
| 217 | sizeof(*info)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 218 | drm_free(dev->drw_info, sizeof(*info) * |
| 219 | dev->drw_info_length, DRM_MEM_BUFS); |
| 220 | dev->drw_info = info; |
| 221 | dev->drw_info_length = info_length; |
| 222 | } |
| 223 | |
| 224 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 225 | } |
| 226 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 227 | DRM_DEBUG("%d\n", draw.handle); |
| 228 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 230 | |
| 231 | int drm_update_drawable_info(DRM_IOCTL_ARGS) { |
| 232 | DRM_DEVICE; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 233 | struct drm_update_draw update; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 234 | unsigned int id, idx, shift; |
| 235 | u32 *bitfield = dev->drw_bitfield; |
| 236 | unsigned long irqflags, bitfield_length = dev->drw_bitfield_length; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 237 | struct drm_drawable_info *info; |
| 238 | struct drm_clip_rect *rects; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 239 | int err; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 240 | |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 241 | DRM_COPY_FROM_USER_IOCTL(update, (struct drm_update_draw __user *) data, |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 242 | sizeof(update)); |
| 243 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 244 | id = update.handle - 1; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 245 | idx = id / (8 * sizeof(*bitfield)); |
| 246 | shift = id % (8 * sizeof(*bitfield)); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 247 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 248 | if (idx < 0 || idx >= bitfield_length || |
| 249 | !(bitfield[idx] & (1 << shift))) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 250 | 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] | 251 | return DRM_ERR(EINVAL); |
| 252 | } |
| 253 | |
| 254 | info = dev->drw_info[id]; |
| 255 | |
| 256 | if (!info) { |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 257 | info = drm_calloc(1, sizeof(struct drm_drawable_info), DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 258 | |
| 259 | if (!info) { |
| 260 | 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] | 261 | return DRM_ERR(ENOMEM); |
| 262 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | switch (update.type) { |
| 266 | case DRM_DRAWABLE_CLIPRECTS: |
| 267 | if (update.num != info->num_rects) { |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 268 | rects = drm_alloc(update.num * sizeof(struct drm_clip_rect), |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 269 | DRM_MEM_BUFS); |
| 270 | } else |
| 271 | rects = info->rects; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 272 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 273 | if (update.num && !rects) { |
| 274 | DRM_ERROR("Failed to allocate cliprect memory\n"); |
| 275 | err = DRM_ERR(ENOMEM); |
| 276 | goto error; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 277 | } |
| 278 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 279 | if (update.num && DRM_COPY_FROM_USER(rects, |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 280 | (struct drm_clip_rect __user *) |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 281 | (unsigned long)update.data, |
| 282 | update.num * |
| 283 | sizeof(*rects))) { |
| 284 | DRM_ERROR("Failed to copy cliprects from userspace\n"); |
| 285 | err = DRM_ERR(EFAULT); |
| 286 | goto error; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 287 | } |
| 288 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 289 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 290 | |
| 291 | if (rects != info->rects) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 292 | drm_free(info->rects, info->num_rects * |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 293 | sizeof(struct drm_clip_rect), DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 294 | } |
| 295 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 296 | info->rects = rects; |
| 297 | info->num_rects = update.num; |
| 298 | dev->drw_info[id] = info; |
| 299 | |
| 300 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 301 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 302 | DRM_DEBUG("Updated %d cliprects for drawable %d\n", |
| 303 | info->num_rects, id); |
| 304 | break; |
| 305 | default: |
| 306 | 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] | 307 | return DRM_ERR(EINVAL); |
| 308 | } |
| 309 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 310 | return 0; |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 311 | |
| 312 | error: |
| 313 | if (!dev->drw_info[id]) |
| 314 | drm_free(info, sizeof(*info), DRM_MEM_BUFS); |
| 315 | else if (rects != dev->drw_info[id]->rects) |
| 316 | drm_free(rects, update.num * |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 317 | sizeof(struct drm_clip_rect), DRM_MEM_BUFS); |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 318 | |
| 319 | return err; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Caller must hold the drawable spinlock! |
| 324 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 325 | struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, drm_drawable_t id) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 326 | u32 *bitfield = dev->drw_bitfield; |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 327 | unsigned int idx, shift; |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 328 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | cdec2f8 | 2006-10-24 23:20:15 +1000 | [diff] [blame] | 329 | id--; |
| 330 | idx = id / (8 * sizeof(*bitfield)); |
| 331 | shift = id % (8 * sizeof(*bitfield)); |
| 332 | |
| 333 | if (idx < 0 || idx >= dev->drw_bitfield_length || |
=?utf-8?q?Michel_D=C3=A4nzer?= | b03ed6f | 2006-10-24 23:18:49 +1000 | [diff] [blame] | 334 | !(bitfield[idx] & (1 << shift))) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 335 | DRM_DEBUG("No such drawable %d\n", id); |
| 336 | return NULL; |
| 337 | } |
| 338 | |
| 339 | return dev->drw_info[id]; |
| 340 | } |
| 341 | EXPORT_SYMBOL(drm_get_drawable_info); |