[PATCH 4/5] drm/vgem: getparam ioctl

Ben Widawsky ben at bwidawsk.net
Wed Feb 8 15:19:30 PST 2012


Similar to i915, it's nice to be able to query this device uniquely and
get some info

Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 drivers/gpu/drm/vgem/vgem_drv.c |   29 +++++++++++++++++++++--------
 include/drm/vgem_drm.h          |   11 +++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
index d47bd71..7a7a05f 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.c
+++ b/drivers/gpu/drm/vgem/vgem_drv.c
@@ -158,26 +158,39 @@ static int vgem_gem_mmap_ioctl(struct drm_device *dev, void *data,
 
 	obj->filp->private_data = obj;
 
-	down_write(&current->mm->mmap_sem);
-	addr = do_mmap(obj->filp, 0, args->size, PROT_READ | PROT_WRITE,
-		       MAP_SHARED, 0);
-	up_write(&current->mm->mmap_sem);
+	BUG_ON(!obj->map_list.map);
 
-	drm_gem_object_unreference_unlocked(obj);
+	args->mapped = obj->map_list.hash.key << PAGE_SHIFT;
 
-	if (IS_ERR((void *)addr))
-		return PTR_ERR((void *)addr);
+	return 0;
+}
 
-	args->mapped = addr;
+static int vgem_gem_getparam_ioctl(struct drm_device *dev, void *data,
+				 struct drm_file *file)
+{
+	struct vgem_gem_getparam *args = data;
+	int value=0, ret;
+
+	switch (args->param) {
+	case VGEM_PARAM_IS_VGEM:
+		value = 1;
+	}
+
+	ret = copy_to_user(args->value, &value, sizeof(int));
+	if (ret)
+		return ret;
 
 	return 0;
 }
 
+
 static struct drm_ioctl_desc vgem_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(VGEM_GEM_CREATE, vgem_gem_create_ioctl,
 			  DRM_UNLOCKED | DRM_AUTH),
 	DRM_IOCTL_DEF_DRV(VGEM_GEM_MMAP, vgem_gem_mmap_ioctl,
 			  DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(VGEM_GEM_GETPARAM, vgem_gem_getparam_ioctl,
+			  DRM_UNLOCKED),
 };
 
 static const struct file_operations vgem_driver_fops = {
diff --git a/include/drm/vgem_drm.h b/include/drm/vgem_drm.h
index d73b537..df83503 100644
--- a/include/drm/vgem_drm.h
+++ b/include/drm/vgem_drm.h
@@ -37,8 +37,15 @@ struct vgem_gem_mmap {
 	uint64_t mapped;
 };
 
+struct vgem_gem_getparam {
+#define VGEM_PARAM_IS_VGEM 1
+	unsigned int param;
+	unsigned int *value;
+};
+
 #define DRM_VGEM_GEM_CREATE	0x00
 #define DRM_VGEM_GEM_MMAP	0x01
+#define DRM_VGEM_GEM_GETPARAM	0x02
 
 #define DRM_IOCTL_VGEM_GEM_CREATE \
 		DRM_IOWR(DRM_COMMAND_BASE + DRM_VGEM_GEM_CREATE, \
@@ -48,4 +55,8 @@ struct vgem_gem_mmap {
 		DRM_IOWR(DRM_COMMAND_BASE + DRM_VGEM_GEM_MMAP, \
 			 struct vgem_gem_mmap)
 
+#define DRM_IOCTL_VGEM_GEM_GETPARAM \
+		DRM_IOWR(DRM_COMMAND_BASE + DRM_VGEM_GEM_GETPARAM, \
+			 struct vgem_gem_getparam)
+
 #endif
-- 
1.7.9



More information about the dri-devel mailing list