static int fw_device_op_mmap()

in core-cdev.c [1667:1716]


static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma)
{
	struct client *client = file->private_data;
	unsigned long size;
	int page_count, ret;

	if (fw_device_is_shutdown(client->device))
		return -ENODEV;

	/* FIXME: We could support multiple buffers, but we don't. */
	if (client->buffer.pages != NULL)
		return -EBUSY;

	if (!(vma->vm_flags & VM_SHARED))
		return -EINVAL;

	if (vma->vm_start & ~PAGE_MASK)
		return -EINVAL;

	client->vm_start = vma->vm_start;
	size = vma->vm_end - vma->vm_start;
	page_count = size >> PAGE_SHIFT;
	if (size & ~PAGE_MASK)
		return -EINVAL;

	ret = fw_iso_buffer_alloc(&client->buffer, page_count);
	if (ret < 0)
		return ret;

	spin_lock_irq(&client->lock);
	if (client->iso_context) {
		ret = fw_iso_buffer_map_dma(&client->buffer,
				client->device->card,
				iso_dma_direction(client->iso_context));
		client->buffer_is_mapped = (ret == 0);
	}
	spin_unlock_irq(&client->lock);
	if (ret < 0)
		goto fail;

	ret = vm_map_pages_zero(vma, client->buffer.pages,
				client->buffer.page_count);
	if (ret < 0)
		goto fail;

	return 0;
 fail:
	fw_iso_buffer_destroy(&client->buffer, client->device->card);
	return ret;
}