[virtio_magma] Remove unused map handler

Change-Id: Ia126efdfe6e922cc2592b7a30c84f4f202a3fba3
diff --git a/drivers/virtio/virtio_magma.c b/drivers/virtio/virtio_magma.c
index 9ca8635..1704301 100644
--- a/drivers/virtio/virtio_magma.c
+++ b/drivers/virtio/virtio_magma.c
@@ -95,12 +95,6 @@
 	struct virtmagma_info *vi;
 	int id;
 	DECLARE_HASHTABLE(connections, CONNECTIONS_HASHTABLE_BITS);
-	int mmfd;
-	struct {
-		struct virtmagma_buffer *buffer;
-		u64 phys_addr;
-		bool pending;
-	} mmap_params;
 	struct {
 		pid_t pid;
 		pid_t tgid;
@@ -499,44 +493,6 @@
 	return 0;
 }
 
-static int virtmagma_mmfd_mmap(struct file *filp, struct vm_area_struct *vma)
-{
-	struct virtmagma_instance *instance = filp->private_data;
-	unsigned long vm_size = vma->vm_end - vma->vm_start;
-	size_t max_map_size;
-	int ret;
-
-	if (!instance)
-		return -ENODEV;
-
-	if (!instance->mmap_params.pending) {
-		pr_warn("virtmagma: user called mmap on the mmfd without first submitting a magma_map ioctl");
-		return -EINVAL;
-	}
-
-	instance->mmap_params.pending = false;
-
-	max_map_size = instance->mmap_params.buffer->size_allocated;
-	max_map_size = PAGE_ALIGN(max_map_size);
-
-	if (vm_size > max_map_size) {
-		pr_warn("virtmagma: user tried to mmap with a size (%ld) larger than the buffer's size (%ld)",
-			vm_size, max_map_size);
-		return -EINVAL;
-	}
-
-	ret = io_remap_pfn_range(vma, vma->vm_start,
-				 instance->mmap_params.phys_addr / PAGE_SIZE,
-				 vm_size, vma->vm_page_prot);
-
-	if (ret)
-		return ret;
-
-	vma->vm_flags |= VM_PFNMAP | VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
-
-	return ret;
-}
-
 static int virtmagma_buffer_fd_release(struct inode *inodep, struct file *filp)
 {
 	struct virtmagma_buffer_fd_priv *priv = filp->private_data;
@@ -685,10 +641,6 @@
 	return 0;
 }
 
-static const struct file_operations virtmagma_mmfd_fops = {
-	.mmap = virtmagma_mmfd_mmap,
-};
-
 static const struct file_operations virtmagma_buffer_fd_fops = {
 	.mmap = virtmagma_buffer_fd_mmap,
 	.release = virtmagma_buffer_fd_release,
@@ -717,13 +669,6 @@
 	}
 	instance->id = ret;
 
-	ret = anon_inode_getfd("[virtmagma_mmfd]", &virtmagma_mmfd_fops,
-			       instance, O_RDWR);
-	if (ret < 0) {
-		goto free_instance;
-	}
-	instance->mmfd = ret;
-
 	hash_init(instance->connections);
 	instance->creator.pid = current->pid;
 	instance->creator.tgid = current->tgid;
@@ -1155,52 +1100,6 @@
 	return 0;
 }
 
-static int virtmagma_command_magma_map(struct virtmagma_instance *instance,
-				       struct virtmagma_virtio_command *command)
-{
-	int ret;
-	struct virtmagma_connection *connection;
-	struct virtmagma_connection_object *object;
-	struct virtio_magma_map_ctrl *request = command->request_ptr;
-	/* this ioctl has a size_t output parameter appended */
-	struct {
-		struct virtio_magma_map_resp virtio_response;
-		size_t size_to_mmap_out;
-	} *response = command->response_ptr;
-
-	if (!COMMAND_OK(command, request, response))
-		return -EINVAL;
-
-	connection = get_connection(instance, request->connection);
-	if (!connection)
-		return -EINVAL;
-
-	object = get_connection_object(connection, request->buffer,
-				       MAGMA_BUFFER);
-	if (!object)
-		return -EINVAL;
-
-	ret = vq_out_send_sync(instance->vi, command);
-	if (ret)
-		return ret;
-
-	ret = virtmagma_check_expected_response_type(request, response);
-	if (ret)
-		return ret;
-
-	/* store parameters for subsequent mmap call */
-
-	instance->mmap_params.buffer = &object->buffer;
-	instance->mmap_params.phys_addr = response->virtio_response.addr_out;
-	instance->mmap_params.pending = true;
-
-	/* user must use the returned size in its subsequent mmap call */
-
-	response->size_to_mmap_out = object->buffer.size_requested;
-
-	return 0;
-}
-
 static int
 	virtmagma_command_magma_poll(struct virtmagma_instance *instance,
 				     struct virtmagma_virtio_command *command)
@@ -1398,16 +1297,6 @@
 	return copy_to_user(ptr, &ioctl_args, sizeof(ioctl_args));
 }
 
-static int virtmagma_ioctl_get_mmfd(struct file *filp, void __user *ptr)
-{
-	struct virtmagma_ioctl_args_get_mmfd ioctl_args;
-	struct virtmagma_instance *instance = filp->private_data;
-	if (!instance)
-		return -ENODEV;
-	ioctl_args.fd_out = instance->mmfd;
-	return copy_to_user(ptr, &ioctl_args, sizeof(ioctl_args));
-}
-
 int virtmagma_ioctl_magma_command(struct file *filp, void __user *ptr)
 {
 	struct virtmagma_ioctl_args_magma_command ioctl_args;
@@ -1423,11 +1312,6 @@
 	if (!instance)
 		return -ENODEV;
 
-	if (instance->mmap_params.pending) {
-		pr_warn("virtmagma: user failed to mmap on the mmfd after submitting a magma_map ioctl");
-		return -EINVAL;
-	}
-
 	/* copy in command arguments */
 
 	ret = copy_from_user(&ioctl_args, ptr, sizeof(ioctl_args));
@@ -1509,9 +1393,6 @@
 		ret = virtmagma_command_magma_release_semaphore(instance,
 								&command);
 		break;
-	case VIRTIO_MAGMA_CMD_MAP:
-		ret = virtmagma_command_magma_map(instance, &command);
-		break;
 	case VIRTIO_MAGMA_CMD_POLL:
 		ret = virtmagma_command_magma_poll(instance, &command);
 		break;
@@ -1535,7 +1416,6 @@
 	case VIRTIO_MAGMA_CMD_SET_CACHE_POLICY:
 	case VIRTIO_MAGMA_CMD_GET_BUFFER_CACHE_POLICY:
 	case VIRTIO_MAGMA_CMD_GET_BUFFER_IS_MAPPABLE:
-	case VIRTIO_MAGMA_CMD_UNMAP:
 	case VIRTIO_MAGMA_CMD_MAP_BUFFER_GPU:
 	case VIRTIO_MAGMA_CMD_UNMAP_BUFFER_GPU:
 	case VIRTIO_MAGMA_CMD_COMMIT_BUFFER:
@@ -1649,8 +1529,6 @@
 	switch (cmd) {
 	case VIRTMAGMA_IOCTL_HANDSHAKE:
 		return virtmagma_ioctl_handshake(filp, ptr);
-	case VIRTMAGMA_IOCTL_GET_MMFD:
-		return virtmagma_ioctl_get_mmfd(filp, ptr);
 	case VIRTMAGMA_IOCTL_MAGMA_COMMAND:
 		return virtmagma_ioctl_magma_command(filp, ptr);
 	default:
diff --git a/include/uapi/linux/virtmagma.h b/include/uapi/linux/virtmagma.h
index 01bf455..55b7436 100644
--- a/include/uapi/linux/virtmagma.h
+++ b/include/uapi/linux/virtmagma.h
@@ -28,10 +28,6 @@
 	__u32 version_out;
 };
 
-struct virtmagma_ioctl_args_get_mmfd {
-	__s32 fd_out;
-};
-
 struct virtmagma_ioctl_args_magma_command {
 	__u64 request_address;
 	__u64 request_size;
@@ -49,7 +45,6 @@
 };
 
 #define VIRTMAGMA_IOCTL_HANDSHAKE VIRTMAGMA_IOWR(0x00, struct virtmagma_ioctl_args_handshake)
-#define VIRTMAGMA_IOCTL_GET_MMFD VIRTMAGMA_IOWR(0x01, struct virtmagma_ioctl_args_get_mmfd)
 #define VIRTMAGMA_IOCTL_MAGMA_COMMAND VIRTMAGMA_IOWR(0x02, struct virtmagma_ioctl_args_magma_command)
 
 #endif /* _LINUX_VIRTMAGMA_H */