aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/drm_bufs.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2007-08-25 06:23:09 -0400
committerDave Airlie <airlied@optimus.(none)>2007-10-14 20:38:20 -0400
commit6c340eac0285f3d62406d2d902d0e96fbf2a5dc0 (patch)
treea92039951cb7eaced306cfff2bad6af0ac5257ad /drivers/char/drm/drm_bufs.c
parent20caafa6ecb2487d9b223aa33e7cc704f912a758 (diff)
drm: Replace filp in ioctl arguments with drm_file *file_priv.
As a fallout, replace filp storage with file_priv storage for "unique identifier of a client" all over the DRM. There is a 1:1 mapping, so this should be a noop. This could be a minor performance improvement, as everyth on Linux dereferenced filp to get file_priv anyway, while only the mmap ioct went the other direction. Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm/drm_bufs.c')
-rw-r--r--drivers/char/drm/drm_bufs.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index c115b39b8517..e7253874fa8f 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -92,7 +92,7 @@ static int drm_map_handle(struct drm_device *dev, struct drm_hash_item *hash,
92 * Ioctl to specify a range of memory that is available for mapping by a non-root process. 92 * Ioctl to specify a range of memory that is available for mapping by a non-root process.
93 * 93 *
94 * \param inode device inode. 94 * \param inode device inode.
95 * \param filp file pointer. 95 * \param file_priv DRM file private.
96 * \param cmd command. 96 * \param cmd command.
97 * \param arg pointer to a drm_map structure. 97 * \param arg pointer to a drm_map structure.
98 * \return zero on success or a negative value on error. 98 * \return zero on success or a negative value on error.
@@ -332,19 +332,15 @@ int drm_addmap(struct drm_device * dev, unsigned int offset,
332 332
333EXPORT_SYMBOL(drm_addmap); 333EXPORT_SYMBOL(drm_addmap);
334 334
335int drm_addmap_ioctl(struct inode *inode, struct file *filp, 335int drm_addmap_ioctl(struct inode *inode, struct drm_file *file_priv,
336 unsigned int cmd, unsigned long arg) 336 unsigned int cmd, unsigned long arg)
337{ 337{
338 struct drm_file *priv = filp->private_data; 338 struct drm_device *dev = file_priv->head->dev;
339 struct drm_device *dev = priv->head->dev;
340 struct drm_map map; 339 struct drm_map map;
341 struct drm_map_list *maplist; 340 struct drm_map_list *maplist;
342 struct drm_map __user *argp = (void __user *)arg; 341 struct drm_map __user *argp = (void __user *)arg;
343 int err; 342 int err;
344 343
345 if (!(filp->f_mode & 3))
346 return -EACCES; /* Require read/write */
347
348 if (copy_from_user(&map, argp, sizeof(map))) { 344 if (copy_from_user(&map, argp, sizeof(map))) {
349 return -EFAULT; 345 return -EFAULT;
350 } 346 }
@@ -372,7 +368,7 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
372 * isn't in use. 368 * isn't in use.
373 * 369 *
374 * \param inode device inode. 370 * \param inode device inode.
375 * \param filp file pointer. 371 * \param file_priv DRM file private.
376 * \param cmd command. 372 * \param cmd command.
377 * \param arg pointer to a struct drm_map structure. 373 * \param arg pointer to a struct drm_map structure.
378 * \return zero on success or a negative value on error. 374 * \return zero on success or a negative value on error.
@@ -453,11 +449,10 @@ int drm_rmmap(struct drm_device *dev, drm_local_map_t *map)
453 * gets used by drivers that the server doesn't need to care about. This seems 449 * gets used by drivers that the server doesn't need to care about. This seems
454 * unlikely. 450 * unlikely.
455 */ 451 */
456int drm_rmmap_ioctl(struct inode *inode, struct file *filp, 452int drm_rmmap_ioctl(struct inode *inode, struct drm_file *file_priv,
457 unsigned int cmd, unsigned long arg) 453 unsigned int cmd, unsigned long arg)
458{ 454{
459 struct drm_file *priv = filp->private_data; 455 struct drm_device *dev = file_priv->head->dev;
460 struct drm_device *dev = priv->head->dev;
461 struct drm_map request; 456 struct drm_map request;
462 drm_local_map_t *map = NULL; 457 drm_local_map_t *map = NULL;
463 struct drm_map_list *r_list; 458 struct drm_map_list *r_list;
@@ -661,7 +656,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
661 buf->waiting = 0; 656 buf->waiting = 0;
662 buf->pending = 0; 657 buf->pending = 0;
663 init_waitqueue_head(&buf->dma_wait); 658 init_waitqueue_head(&buf->dma_wait);
664 buf->filp = NULL; 659 buf->file_priv = NULL;
665 660
666 buf->dev_priv_size = dev->driver->dev_priv_size; 661 buf->dev_priv_size = dev->driver->dev_priv_size;
667 buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS); 662 buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
@@ -872,7 +867,7 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
872 buf->waiting = 0; 867 buf->waiting = 0;
873 buf->pending = 0; 868 buf->pending = 0;
874 init_waitqueue_head(&buf->dma_wait); 869 init_waitqueue_head(&buf->dma_wait);
875 buf->filp = NULL; 870 buf->file_priv = NULL;
876 871
877 buf->dev_priv_size = dev->driver->dev_priv_size; 872 buf->dev_priv_size = dev->driver->dev_priv_size;
878 buf->dev_private = drm_alloc(buf->dev_priv_size, 873 buf->dev_private = drm_alloc(buf->dev_priv_size,
@@ -1050,7 +1045,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1050 buf->waiting = 0; 1045 buf->waiting = 0;
1051 buf->pending = 0; 1046 buf->pending = 0;
1052 init_waitqueue_head(&buf->dma_wait); 1047 init_waitqueue_head(&buf->dma_wait);
1053 buf->filp = NULL; 1048 buf->file_priv = NULL;
1054 1049
1055 buf->dev_priv_size = dev->driver->dev_priv_size; 1050 buf->dev_priv_size = dev->driver->dev_priv_size;
1056 buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS); 1051 buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
@@ -1211,7 +1206,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1211 buf->waiting = 0; 1206 buf->waiting = 0;
1212 buf->pending = 0; 1207 buf->pending = 0;
1213 init_waitqueue_head(&buf->dma_wait); 1208 init_waitqueue_head(&buf->dma_wait);
1214 buf->filp = NULL; 1209 buf->file_priv = NULL;
1215 1210
1216 buf->dev_priv_size = dev->driver->dev_priv_size; 1211 buf->dev_priv_size = dev->driver->dev_priv_size;
1217 buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS); 1212 buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
@@ -1275,7 +1270,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1275 * Add buffers for DMA transfers (ioctl). 1270 * Add buffers for DMA transfers (ioctl).
1276 * 1271 *
1277 * \param inode device inode. 1272 * \param inode device inode.
1278 * \param filp file pointer. 1273 * \param file_priv DRM file private.
1279 * \param cmd command. 1274 * \param cmd command.
1280 * \param arg pointer to a struct drm_buf_desc request. 1275 * \param arg pointer to a struct drm_buf_desc request.
1281 * \return zero on success or a negative number on failure. 1276 * \return zero on success or a negative number on failure.
@@ -1285,12 +1280,11 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1285 * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent 1280 * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent
1286 * PCI memory respectively. 1281 * PCI memory respectively.
1287 */ 1282 */
1288int drm_addbufs(struct inode *inode, struct file *filp, 1283int drm_addbufs(struct inode *inode, struct drm_file *file_priv,
1289 unsigned int cmd, unsigned long arg) 1284 unsigned int cmd, unsigned long arg)
1290{ 1285{
1291 struct drm_buf_desc request; 1286 struct drm_buf_desc request;
1292 struct drm_file *priv = filp->private_data; 1287 struct drm_device *dev = file_priv->head->dev;
1293 struct drm_device *dev = priv->head->dev;
1294 int ret; 1288 int ret;
1295 1289
1296 if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA)) 1290 if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
@@ -1328,7 +1322,7 @@ int drm_addbufs(struct inode *inode, struct file *filp,
1328 * large buffers can be used for image transfer). 1322 * large buffers can be used for image transfer).
1329 * 1323 *
1330 * \param inode device inode. 1324 * \param inode device inode.
1331 * \param filp file pointer. 1325 * \param file_priv DRM file private.
1332 * \param cmd command. 1326 * \param cmd command.
1333 * \param arg pointer to a drm_buf_info structure. 1327 * \param arg pointer to a drm_buf_info structure.
1334 * \return zero on success or a negative number on failure. 1328 * \return zero on success or a negative number on failure.
@@ -1337,11 +1331,10 @@ int drm_addbufs(struct inode *inode, struct file *filp,
1337 * lock, preventing of allocating more buffers after this call. Information 1331 * lock, preventing of allocating more buffers after this call. Information
1338 * about each requested buffer is then copied into user space. 1332 * about each requested buffer is then copied into user space.
1339 */ 1333 */
1340int drm_infobufs(struct inode *inode, struct file *filp, 1334int drm_infobufs(struct inode *inode, struct drm_file *file_priv,
1341 unsigned int cmd, unsigned long arg) 1335 unsigned int cmd, unsigned long arg)
1342{ 1336{
1343 struct drm_file *priv = filp->private_data; 1337 struct drm_device *dev = file_priv->head->dev;
1344 struct drm_device *dev = priv->head->dev;
1345 struct drm_device_dma *dma = dev->dma; 1338 struct drm_device_dma *dma = dev->dma;
1346 struct drm_buf_info request; 1339 struct drm_buf_info request;
1347 struct drm_buf_info __user *argp = (void __user *)arg; 1340 struct drm_buf_info __user *argp = (void __user *)arg;
@@ -1415,7 +1408,7 @@ int drm_infobufs(struct inode *inode, struct file *filp,
1415 * Specifies a low and high water mark for buffer allocation 1408 * Specifies a low and high water mark for buffer allocation
1416 * 1409 *
1417 * \param inode device inode. 1410 * \param inode device inode.
1418 * \param filp file pointer. 1411 * \param file_priv DRM file private.
1419 * \param cmd command. 1412 * \param cmd command.
1420 * \param arg a pointer to a drm_buf_desc structure. 1413 * \param arg a pointer to a drm_buf_desc structure.
1421 * \return zero on success or a negative number on failure. 1414 * \return zero on success or a negative number on failure.
@@ -1425,11 +1418,10 @@ int drm_infobufs(struct inode *inode, struct file *filp,
1425 * 1418 *
1426 * \note This ioctl is deprecated and mostly never used. 1419 * \note This ioctl is deprecated and mostly never used.
1427 */ 1420 */
1428int drm_markbufs(struct inode *inode, struct file *filp, 1421int drm_markbufs(struct inode *inode, struct drm_file *file_priv,
1429 unsigned int cmd, unsigned long arg) 1422 unsigned int cmd, unsigned long arg)
1430{ 1423{
1431 struct drm_file *priv = filp->private_data; 1424 struct drm_device *dev = file_priv->head->dev;
1432 struct drm_device *dev = priv->head->dev;
1433 struct drm_device_dma *dma = dev->dma; 1425 struct drm_device_dma *dma = dev->dma;
1434 struct drm_buf_desc request; 1426 struct drm_buf_desc request;
1435 int order; 1427 int order;
@@ -1467,7 +1459,7 @@ int drm_markbufs(struct inode *inode, struct file *filp,
1467 * Unreserve the buffers in list, previously reserved using drmDMA. 1459 * Unreserve the buffers in list, previously reserved using drmDMA.
1468 * 1460 *
1469 * \param inode device inode. 1461 * \param inode device inode.
1470 * \param filp file pointer. 1462 * \param file_priv DRM file private.
1471 * \param cmd command. 1463 * \param cmd command.
1472 * \param arg pointer to a drm_buf_free structure. 1464 * \param arg pointer to a drm_buf_free structure.
1473 * \return zero on success or a negative number on failure. 1465 * \return zero on success or a negative number on failure.
@@ -1475,11 +1467,10 @@ int drm_markbufs(struct inode *inode, struct file *filp,
1475 * Calls free_buffer() for each used buffer. 1467 * Calls free_buffer() for each used buffer.
1476 * This function is primarily used for debugging. 1468 * This function is primarily used for debugging.
1477 */ 1469 */
1478int drm_freebufs(struct inode *inode, struct file *filp, 1470int drm_freebufs(struct inode *inode, struct drm_file *file_priv,
1479 unsigned int cmd, unsigned long arg) 1471 unsigned int cmd, unsigned long arg)
1480{ 1472{
1481 struct drm_file *priv = filp->private_data; 1473 struct drm_device *dev = file_priv->head->dev;
1482 struct drm_device *dev = priv->head->dev;
1483 struct drm_device_dma *dma = dev->dma; 1474 struct drm_device_dma *dma = dev->dma;
1484 struct drm_buf_free request; 1475 struct drm_buf_free request;
1485 int i; 1476 int i;
@@ -1506,7 +1497,7 @@ int drm_freebufs(struct inode *inode, struct file *filp,
1506 return -EINVAL; 1497 return -EINVAL;
1507 } 1498 }
1508 buf = dma->buflist[idx]; 1499 buf = dma->buflist[idx];
1509 if (buf->filp != filp) { 1500 if (buf->file_priv != file_priv) {
1510 DRM_ERROR("Process %d freeing buffer not owned\n", 1501 DRM_ERROR("Process %d freeing buffer not owned\n",
1511 current->pid); 1502 current->pid);
1512 return -EINVAL; 1503 return -EINVAL;
@@ -1521,7 +1512,7 @@ int drm_freebufs(struct inode *inode, struct file *filp,
1521 * Maps all of the DMA buffers into client-virtual space (ioctl). 1512 * Maps all of the DMA buffers into client-virtual space (ioctl).
1522 * 1513 *
1523 * \param inode device inode. 1514 * \param inode device inode.
1524 * \param filp file pointer. 1515 * \param file_priv DRM file private.
1525 * \param cmd command. 1516 * \param cmd command.
1526 * \param arg pointer to a drm_buf_map structure. 1517 * \param arg pointer to a drm_buf_map structure.
1527 * \return zero on success or a negative number on failure. 1518 * \return zero on success or a negative number on failure.
@@ -1531,11 +1522,10 @@ int drm_freebufs(struct inode *inode, struct file *filp,
1531 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls 1522 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
1532 * drm_mmap_dma(). 1523 * drm_mmap_dma().
1533 */ 1524 */
1534int drm_mapbufs(struct inode *inode, struct file *filp, 1525int drm_mapbufs(struct inode *inode, struct drm_file *file_priv,
1535 unsigned int cmd, unsigned long arg) 1526 unsigned int cmd, unsigned long arg)
1536{ 1527{
1537 struct drm_file *priv = filp->private_data; 1528 struct drm_device *dev = file_priv->head->dev;
1538 struct drm_device *dev = priv->head->dev;
1539 struct drm_device_dma *dma = dev->dma; 1529 struct drm_device_dma *dma = dev->dma;
1540 struct drm_buf_map __user *argp = (void __user *)arg; 1530 struct drm_buf_map __user *argp = (void __user *)arg;
1541 int retcode = 0; 1531 int retcode = 0;
@@ -1577,13 +1567,13 @@ int drm_mapbufs(struct inode *inode, struct file *filp,
1577 } 1567 }
1578 1568
1579 down_write(&current->mm->mmap_sem); 1569 down_write(&current->mm->mmap_sem);
1580 virtual = do_mmap(filp, 0, map->size, 1570 virtual = do_mmap(file_priv->filp, 0, map->size,
1581 PROT_READ | PROT_WRITE, 1571 PROT_READ | PROT_WRITE,
1582 MAP_SHARED, token); 1572 MAP_SHARED, token);
1583 up_write(&current->mm->mmap_sem); 1573 up_write(&current->mm->mmap_sem);
1584 } else { 1574 } else {
1585 down_write(&current->mm->mmap_sem); 1575 down_write(&current->mm->mmap_sem);
1586 virtual = do_mmap(filp, 0, dma->byte_count, 1576 virtual = do_mmap(file_priv->filp, 0, dma->byte_count,
1587 PROT_READ | PROT_WRITE, 1577 PROT_READ | PROT_WRITE,
1588 MAP_SHARED, 0); 1578 MAP_SHARED, 0);
1589 up_write(&current->mm->mmap_sem); 1579 up_write(&current->mm->mmap_sem);