diff options
Diffstat (limited to 'drivers/char/drm/drm_agpsupport.c')
-rw-r--r-- | drivers/char/drm/drm_agpsupport.c | 133 |
1 files changed, 87 insertions, 46 deletions
diff --git a/drivers/char/drm/drm_agpsupport.c b/drivers/char/drm/drm_agpsupport.c index 2b6453a9ffce..fabc930c67a2 100644 --- a/drivers/char/drm/drm_agpsupport.c +++ b/drivers/char/drm/drm_agpsupport.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * \file drm_agpsupport.h | 2 | * \file drm_agpsupport.c |
3 | * DRM support for AGP/GART backend | 3 | * DRM support for AGP/GART backend |
4 | * | 4 | * |
5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> | 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
@@ -91,7 +91,7 @@ int drm_agp_info_ioctl(struct inode *inode, struct file *filp, | |||
91 | /** | 91 | /** |
92 | * Acquire the AGP device. | 92 | * Acquire the AGP device. |
93 | * | 93 | * |
94 | * \param dev DRM device that is to acquire AGP | 94 | * \param dev DRM device that is to acquire AGP. |
95 | * \return zero on success or a negative number on failure. | 95 | * \return zero on success or a negative number on failure. |
96 | * | 96 | * |
97 | * Verifies the AGP device hasn't been acquired before and calls | 97 | * Verifies the AGP device hasn't been acquired before and calls |
@@ -134,7 +134,7 @@ int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp, | |||
134 | /** | 134 | /** |
135 | * Release the AGP device. | 135 | * Release the AGP device. |
136 | * | 136 | * |
137 | * \param dev DRM device that is to release AGP | 137 | * \param dev DRM device that is to release AGP. |
138 | * \return zero on success or a negative number on failure. | 138 | * \return zero on success or a negative number on failure. |
139 | * | 139 | * |
140 | * Verifies the AGP device has been acquired and calls \c agp_backend_release. | 140 | * Verifies the AGP device has been acquired and calls \c agp_backend_release. |
@@ -147,7 +147,6 @@ int drm_agp_release(drm_device_t * dev) | |||
147 | dev->agp->acquired = 0; | 147 | dev->agp->acquired = 0; |
148 | return 0; | 148 | return 0; |
149 | } | 149 | } |
150 | |||
151 | EXPORT_SYMBOL(drm_agp_release); | 150 | EXPORT_SYMBOL(drm_agp_release); |
152 | 151 | ||
153 | int drm_agp_release_ioctl(struct inode *inode, struct file *filp, | 152 | int drm_agp_release_ioctl(struct inode *inode, struct file *filp, |
@@ -208,30 +207,22 @@ int drm_agp_enable_ioctl(struct inode *inode, struct file *filp, | |||
208 | * Verifies the AGP device is present and has been acquired, allocates the | 207 | * Verifies the AGP device is present and has been acquired, allocates the |
209 | * memory via alloc_agp() and creates a drm_agp_mem entry for it. | 208 | * memory via alloc_agp() and creates a drm_agp_mem entry for it. |
210 | */ | 209 | */ |
211 | int drm_agp_alloc(struct inode *inode, struct file *filp, | 210 | int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request) |
212 | unsigned int cmd, unsigned long arg) | ||
213 | { | 211 | { |
214 | drm_file_t *priv = filp->private_data; | ||
215 | drm_device_t *dev = priv->head->dev; | ||
216 | drm_agp_buffer_t request; | ||
217 | drm_agp_mem_t *entry; | 212 | drm_agp_mem_t *entry; |
218 | DRM_AGP_MEM *memory; | 213 | DRM_AGP_MEM *memory; |
219 | unsigned long pages; | 214 | unsigned long pages; |
220 | u32 type; | 215 | u32 type; |
221 | drm_agp_buffer_t __user *argp = (void __user *)arg; | ||
222 | 216 | ||
223 | if (!dev->agp || !dev->agp->acquired) | 217 | if (!dev->agp || !dev->agp->acquired) |
224 | return -EINVAL; | 218 | return -EINVAL; |
225 | if (copy_from_user(&request, argp, sizeof(request))) | ||
226 | return -EFAULT; | ||
227 | if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS))) | 219 | if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS))) |
228 | return -ENOMEM; | 220 | return -ENOMEM; |
229 | 221 | ||
230 | memset(entry, 0, sizeof(*entry)); | 222 | memset(entry, 0, sizeof(*entry)); |
231 | 223 | ||
232 | pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE; | 224 | pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE; |
233 | type = (u32) request.type; | 225 | type = (u32) request->type; |
234 | |||
235 | if (!(memory = drm_alloc_agp(dev, pages, type))) { | 226 | if (!(memory = drm_alloc_agp(dev, pages, type))) { |
236 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); | 227 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); |
237 | return -ENOMEM; | 228 | return -ENOMEM; |
@@ -247,16 +238,39 @@ int drm_agp_alloc(struct inode *inode, struct file *filp, | |||
247 | dev->agp->memory->prev = entry; | 238 | dev->agp->memory->prev = entry; |
248 | dev->agp->memory = entry; | 239 | dev->agp->memory = entry; |
249 | 240 | ||
250 | request.handle = entry->handle; | 241 | request->handle = entry->handle; |
251 | request.physical = memory->physical; | 242 | request->physical = memory->physical; |
243 | |||
244 | return 0; | ||
245 | } | ||
246 | EXPORT_SYMBOL(drm_agp_alloc); | ||
247 | |||
248 | int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp, | ||
249 | unsigned int cmd, unsigned long arg) | ||
250 | { | ||
251 | drm_file_t *priv = filp->private_data; | ||
252 | drm_device_t *dev = priv->head->dev; | ||
253 | drm_agp_buffer_t request; | ||
254 | drm_agp_buffer_t __user *argp = (void __user *)arg; | ||
255 | int err; | ||
256 | |||
257 | if (copy_from_user(&request, argp, sizeof(request))) | ||
258 | return -EFAULT; | ||
259 | |||
260 | err = drm_agp_alloc(dev, &request); | ||
261 | if (err) | ||
262 | return err; | ||
252 | 263 | ||
253 | if (copy_to_user(argp, &request, sizeof(request))) { | 264 | if (copy_to_user(argp, &request, sizeof(request))) { |
265 | drm_agp_mem_t *entry = dev->agp->memory; | ||
266 | |||
254 | dev->agp->memory = entry->next; | 267 | dev->agp->memory = entry->next; |
255 | dev->agp->memory->prev = NULL; | 268 | dev->agp->memory->prev = NULL; |
256 | drm_free_agp(memory, pages); | 269 | drm_free_agp(entry->memory, entry->pages); |
257 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); | 270 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); |
258 | return -EFAULT; | 271 | return -EFAULT; |
259 | } | 272 | } |
273 | |||
260 | return 0; | 274 | return 0; |
261 | } | 275 | } |
262 | 276 | ||
@@ -293,21 +307,14 @@ static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t * dev, | |||
293 | * Verifies the AGP device is present and acquired, looks-up the AGP memory | 307 | * Verifies the AGP device is present and acquired, looks-up the AGP memory |
294 | * entry and passes it to the unbind_agp() function. | 308 | * entry and passes it to the unbind_agp() function. |
295 | */ | 309 | */ |
296 | int drm_agp_unbind(struct inode *inode, struct file *filp, | 310 | int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request) |
297 | unsigned int cmd, unsigned long arg) | ||
298 | { | 311 | { |
299 | drm_file_t *priv = filp->private_data; | ||
300 | drm_device_t *dev = priv->head->dev; | ||
301 | drm_agp_binding_t request; | ||
302 | drm_agp_mem_t *entry; | 312 | drm_agp_mem_t *entry; |
303 | int ret; | 313 | int ret; |
304 | 314 | ||
305 | if (!dev->agp || !dev->agp->acquired) | 315 | if (!dev->agp || !dev->agp->acquired) |
306 | return -EINVAL; | 316 | return -EINVAL; |
307 | if (copy_from_user | 317 | if (!(entry = drm_agp_lookup_entry(dev, request->handle))) |
308 | (&request, (drm_agp_binding_t __user *) arg, sizeof(request))) | ||
309 | return -EFAULT; | ||
310 | if (!(entry = drm_agp_lookup_entry(dev, request.handle))) | ||
311 | return -EINVAL; | 318 | return -EINVAL; |
312 | if (!entry->bound) | 319 | if (!entry->bound) |
313 | return -EINVAL; | 320 | return -EINVAL; |
@@ -316,6 +323,21 @@ int drm_agp_unbind(struct inode *inode, struct file *filp, | |||
316 | entry->bound = 0; | 323 | entry->bound = 0; |
317 | return ret; | 324 | return ret; |
318 | } | 325 | } |
326 | EXPORT_SYMBOL(drm_agp_unbind); | ||
327 | |||
328 | int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp, | ||
329 | unsigned int cmd, unsigned long arg) | ||
330 | { | ||
331 | drm_file_t *priv = filp->private_data; | ||
332 | drm_device_t *dev = priv->head->dev; | ||
333 | drm_agp_binding_t request; | ||
334 | |||
335 | if (copy_from_user | ||
336 | (&request, (drm_agp_binding_t __user *) arg, sizeof(request))) | ||
337 | return -EFAULT; | ||
338 | |||
339 | return drm_agp_unbind(dev, &request); | ||
340 | } | ||
319 | 341 | ||
320 | /** | 342 | /** |
321 | * Bind AGP memory into the GATT (ioctl) | 343 | * Bind AGP memory into the GATT (ioctl) |
@@ -330,26 +352,19 @@ int drm_agp_unbind(struct inode *inode, struct file *filp, | |||
330 | * is currently bound into the GATT. Looks-up the AGP memory entry and passes | 352 | * is currently bound into the GATT. Looks-up the AGP memory entry and passes |
331 | * it to bind_agp() function. | 353 | * it to bind_agp() function. |
332 | */ | 354 | */ |
333 | int drm_agp_bind(struct inode *inode, struct file *filp, | 355 | int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request) |
334 | unsigned int cmd, unsigned long arg) | ||
335 | { | 356 | { |
336 | drm_file_t *priv = filp->private_data; | ||
337 | drm_device_t *dev = priv->head->dev; | ||
338 | drm_agp_binding_t request; | ||
339 | drm_agp_mem_t *entry; | 357 | drm_agp_mem_t *entry; |
340 | int retcode; | 358 | int retcode; |
341 | int page; | 359 | int page; |
342 | 360 | ||
343 | if (!dev->agp || !dev->agp->acquired) | 361 | if (!dev->agp || !dev->agp->acquired) |
344 | return -EINVAL; | 362 | return -EINVAL; |
345 | if (copy_from_user | 363 | if (!(entry = drm_agp_lookup_entry(dev, request->handle))) |
346 | (&request, (drm_agp_binding_t __user *) arg, sizeof(request))) | ||
347 | return -EFAULT; | ||
348 | if (!(entry = drm_agp_lookup_entry(dev, request.handle))) | ||
349 | return -EINVAL; | 364 | return -EINVAL; |
350 | if (entry->bound) | 365 | if (entry->bound) |
351 | return -EINVAL; | 366 | return -EINVAL; |
352 | page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE; | 367 | page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE; |
353 | if ((retcode = drm_bind_agp(entry->memory, page))) | 368 | if ((retcode = drm_bind_agp(entry->memory, page))) |
354 | return retcode; | 369 | return retcode; |
355 | entry->bound = dev->agp->base + (page << PAGE_SHIFT); | 370 | entry->bound = dev->agp->base + (page << PAGE_SHIFT); |
@@ -357,6 +372,21 @@ int drm_agp_bind(struct inode *inode, struct file *filp, | |||
357 | dev->agp->base, entry->bound); | 372 | dev->agp->base, entry->bound); |
358 | return 0; | 373 | return 0; |
359 | } | 374 | } |
375 | EXPORT_SYMBOL(drm_agp_bind); | ||
376 | |||
377 | int drm_agp_bind_ioctl(struct inode *inode, struct file *filp, | ||
378 | unsigned int cmd, unsigned long arg) | ||
379 | { | ||
380 | drm_file_t *priv = filp->private_data; | ||
381 | drm_device_t *dev = priv->head->dev; | ||
382 | drm_agp_binding_t request; | ||
383 | |||
384 | if (copy_from_user | ||
385 | (&request, (drm_agp_binding_t __user *) arg, sizeof(request))) | ||
386 | return -EFAULT; | ||
387 | |||
388 | return drm_agp_bind(dev, &request); | ||
389 | } | ||
360 | 390 | ||
361 | /** | 391 | /** |
362 | * Free AGP memory (ioctl). | 392 | * Free AGP memory (ioctl). |
@@ -372,20 +402,13 @@ int drm_agp_bind(struct inode *inode, struct file *filp, | |||
372 | * unbind_agp(). Frees it via free_agp() as well as the entry itself | 402 | * unbind_agp(). Frees it via free_agp() as well as the entry itself |
373 | * and unlinks from the doubly linked list it's inserted in. | 403 | * and unlinks from the doubly linked list it's inserted in. |
374 | */ | 404 | */ |
375 | int drm_agp_free(struct inode *inode, struct file *filp, | 405 | int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request) |
376 | unsigned int cmd, unsigned long arg) | ||
377 | { | 406 | { |
378 | drm_file_t *priv = filp->private_data; | ||
379 | drm_device_t *dev = priv->head->dev; | ||
380 | drm_agp_buffer_t request; | ||
381 | drm_agp_mem_t *entry; | 407 | drm_agp_mem_t *entry; |
382 | 408 | ||
383 | if (!dev->agp || !dev->agp->acquired) | 409 | if (!dev->agp || !dev->agp->acquired) |
384 | return -EINVAL; | 410 | return -EINVAL; |
385 | if (copy_from_user | 411 | if (!(entry = drm_agp_lookup_entry(dev, request->handle))) |
386 | (&request, (drm_agp_buffer_t __user *) arg, sizeof(request))) | ||
387 | return -EFAULT; | ||
388 | if (!(entry = drm_agp_lookup_entry(dev, request.handle))) | ||
389 | return -EINVAL; | 412 | return -EINVAL; |
390 | if (entry->bound) | 413 | if (entry->bound) |
391 | drm_unbind_agp(entry->memory); | 414 | drm_unbind_agp(entry->memory); |
@@ -402,12 +425,30 @@ int drm_agp_free(struct inode *inode, struct file *filp, | |||
402 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); | 425 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); |
403 | return 0; | 426 | return 0; |
404 | } | 427 | } |
428 | EXPORT_SYMBOL(drm_agp_free); | ||
429 | |||
430 | int drm_agp_free_ioctl(struct inode *inode, struct file *filp, | ||
431 | unsigned int cmd, unsigned long arg) | ||
432 | { | ||
433 | drm_file_t *priv = filp->private_data; | ||
434 | drm_device_t *dev = priv->head->dev; | ||
435 | drm_agp_buffer_t request; | ||
436 | |||
437 | if (copy_from_user | ||
438 | (&request, (drm_agp_buffer_t __user *) arg, sizeof(request))) | ||
439 | return -EFAULT; | ||
440 | |||
441 | return drm_agp_free(dev, &request); | ||
442 | } | ||
405 | 443 | ||
406 | /** | 444 | /** |
407 | * Initialize the AGP resources. | 445 | * Initialize the AGP resources. |
408 | * | 446 | * |
409 | * \return pointer to a drm_agp_head structure. | 447 | * \return pointer to a drm_agp_head structure. |
410 | * | 448 | * |
449 | * Gets the drm_agp_t structure which is made available by the agpgart module | ||
450 | * via the inter_module_* functions. Creates and initializes a drm_agp_head | ||
451 | * structure. | ||
411 | */ | 452 | */ |
412 | drm_agp_head_t *drm_agp_init(drm_device_t * dev) | 453 | drm_agp_head_t *drm_agp_init(drm_device_t * dev) |
413 | { | 454 | { |