|
@@ -1443,15 +1443,15 @@ int drm_legacy_freebufs(struct drm_device *dev, void *data,
|
|
|
* offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
|
|
|
* drm_mmap_dma().
|
|
|
*/
|
|
|
-int drm_legacy_mapbufs(struct drm_device *dev, void *data,
|
|
|
- struct drm_file *file_priv)
|
|
|
+int __drm_legacy_mapbufs(struct drm_device *dev, void *data, int *p,
|
|
|
+ void __user **v,
|
|
|
+ int (*f)(void *, int, unsigned long,
|
|
|
+ struct drm_buf *),
|
|
|
+ struct drm_file *file_priv)
|
|
|
{
|
|
|
struct drm_device_dma *dma = dev->dma;
|
|
|
int retcode = 0;
|
|
|
- const int zero = 0;
|
|
|
unsigned long virtual;
|
|
|
- unsigned long address;
|
|
|
- struct drm_buf_map *request = data;
|
|
|
int i;
|
|
|
|
|
|
if (!drm_core_check_feature(dev, DRIVER_LEGACY))
|
|
@@ -1471,7 +1471,7 @@ int drm_legacy_mapbufs(struct drm_device *dev, void *data,
|
|
|
dev->buf_use++; /* Can't allocate more after this call */
|
|
|
spin_unlock(&dev->buf_lock);
|
|
|
|
|
|
- if (request->count >= dma->buf_count) {
|
|
|
+ if (*p >= dma->buf_count) {
|
|
|
if ((dev->agp && (dma->flags & _DRM_DMA_USE_AGP))
|
|
|
|| (drm_core_check_feature(dev, DRIVER_SG)
|
|
|
&& (dma->flags & _DRM_DMA_USE_SG))) {
|
|
@@ -1496,41 +1496,51 @@ int drm_legacy_mapbufs(struct drm_device *dev, void *data,
|
|
|
retcode = (signed long)virtual;
|
|
|
goto done;
|
|
|
}
|
|
|
- request->virtual = (void __user *)virtual;
|
|
|
+ *v = (void __user *)virtual;
|
|
|
|
|
|
for (i = 0; i < dma->buf_count; i++) {
|
|
|
- if (copy_to_user(&request->list[i].idx,
|
|
|
- &dma->buflist[i]->idx,
|
|
|
- sizeof(request->list[0].idx))) {
|
|
|
- retcode = -EFAULT;
|
|
|
- goto done;
|
|
|
- }
|
|
|
- if (copy_to_user(&request->list[i].total,
|
|
|
- &dma->buflist[i]->total,
|
|
|
- sizeof(request->list[0].total))) {
|
|
|
- retcode = -EFAULT;
|
|
|
- goto done;
|
|
|
- }
|
|
|
- if (copy_to_user(&request->list[i].used,
|
|
|
- &zero, sizeof(zero))) {
|
|
|
- retcode = -EFAULT;
|
|
|
- goto done;
|
|
|
- }
|
|
|
- address = virtual + dma->buflist[i]->offset; /* *** */
|
|
|
- if (copy_to_user(&request->list[i].address,
|
|
|
- &address, sizeof(address))) {
|
|
|
+ if (f(data, i, virtual, dma->buflist[i]) < 0) {
|
|
|
retcode = -EFAULT;
|
|
|
goto done;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
done:
|
|
|
- request->count = dma->buf_count;
|
|
|
- DRM_DEBUG("%d buffers, retcode = %d\n", request->count, retcode);
|
|
|
+ *p = dma->buf_count;
|
|
|
+ DRM_DEBUG("%d buffers, retcode = %d\n", *p, retcode);
|
|
|
|
|
|
return retcode;
|
|
|
}
|
|
|
|
|
|
+static int map_one_buf(void *data, int idx, unsigned long virtual,
|
|
|
+ struct drm_buf *buf)
|
|
|
+{
|
|
|
+ struct drm_buf_map *request = data;
|
|
|
+ unsigned long address = virtual + buf->offset; /* *** */
|
|
|
+
|
|
|
+ if (copy_to_user(&request->list[idx].idx, &buf->idx,
|
|
|
+ sizeof(request->list[0].idx)))
|
|
|
+ return -EFAULT;
|
|
|
+ if (copy_to_user(&request->list[idx].total, &buf->total,
|
|
|
+ sizeof(request->list[0].total)))
|
|
|
+ return -EFAULT;
|
|
|
+ if (clear_user(&request->list[idx].used, sizeof(int)))
|
|
|
+ return -EFAULT;
|
|
|
+ if (copy_to_user(&request->list[idx].address, &address,
|
|
|
+ sizeof(address)))
|
|
|
+ return -EFAULT;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int drm_legacy_mapbufs(struct drm_device *dev, void *data,
|
|
|
+ struct drm_file *file_priv)
|
|
|
+{
|
|
|
+ struct drm_buf_map *request = data;
|
|
|
+ return __drm_legacy_mapbufs(dev, data, &request->count,
|
|
|
+ &request->virtual, map_one_buf,
|
|
|
+ file_priv);
|
|
|
+}
|
|
|
+
|
|
|
int drm_legacy_dma_ioctl(struct drm_device *dev, void *data,
|
|
|
struct drm_file *file_priv)
|
|
|
{
|