struct list_head event_list;
struct semaphore event_list_sem;
wait_queue_head_t wait;
- unsigned long vm_start;
+
struct fw_iso_context *iso_context;
+ struct fw_iso_buffer buffer;
+ unsigned long vm_start;
};
static inline void __user *
if (copy_from_user(&request, arg, sizeof request))
return -EFAULT;
+ if (request.type > FW_ISO_CONTEXT_RECEIVE)
+ return -EINVAL;
+
client->iso_context = fw_iso_context_create(client->device->card,
- FW_ISO_CONTEXT_TRANSMIT,
- request.buffer_size,
+ request.type,
+ request.header_size,
iso_callback, client);
if (IS_ERR(client->iso_context))
return PTR_ERR(client->iso_context);
{
struct fw_cdev_queue_iso request;
struct fw_cdev_iso_packet __user *p, *end, *next;
- void *payload, *payload_end;
- unsigned long index;
+ unsigned long payload, payload_end, header_length;
int count;
struct {
struct fw_iso_packet packet;
/* If the user passes a non-NULL data pointer, has mmap()'ed
* the iso buffer, and the pointer points inside the buffer,
* we setup the payload pointers accordingly. Otherwise we
- * set them both to NULL, which will still let packets with
+ * set them both to 0, which will still let packets with
* payload_length == 0 through. In other words, if no packets
* use the indirect payload, the iso buffer need not be mapped
* and the request.data pointer is ignored.*/
- index = (unsigned long)request.data - client->vm_start;
- if (request.data != 0 && client->vm_start != 0 &&
- index <= client->iso_context->buffer_size) {
- payload = client->iso_context->buffer + index;
- payload_end = client->iso_context->buffer +
- client->iso_context->buffer_size;
- } else {
- payload = NULL;
- payload_end = NULL;
+ payload = (unsigned long)request.data - client->vm_start;
+ payload_end = payload + (client->buffer.page_count << PAGE_SHIFT);
+ if (request.data == 0 || client->buffer.pages == NULL ||
+ payload >= payload_end) {
+ payload = 0;
+ payload_end = 0;
}
if (!access_ok(VERIFY_READ, request.packets, request.size))
while (p < end) {
if (__copy_from_user(&u.packet, p, sizeof *p))
return -EFAULT;
+
+ if (client->iso_context->type == FW_ISO_CONTEXT_TRANSMIT) {
+ header_length = u.packet.header_length;
+ } else {
+ /* We require that header_length is a multiple of
+ * the fixed header size, ctx->header_size */
+ if (u.packet.header_length % client->iso_context->header_size != 0)
+ return -EINVAL;
+ header_length = 0;
+ }
+
next = (struct fw_cdev_iso_packet __user *)
- &p->header[u.packet.header_length / 4];
+ &p->header[header_length / 4];
if (next > end)
return -EINVAL;
if (__copy_from_user
- (u.packet.header, p->header, u.packet.header_length))
+ (u.packet.header, p->header, header_length))
return -EFAULT;
if (u.packet.skip &&
u.packet.header_length + u.packet.payload_length > 0)
return -EINVAL;
if (fw_iso_context_queue(client->iso_context,
- &u.packet, payload))
+ &u.packet, &client->buffer, payload))
break;
p = next;
request.size -= uptr_to_u64(p) - request.packets;
request.packets = uptr_to_u64(p);
- request.data =
- client->vm_start + (payload - client->iso_context->buffer);
+ request.data = client->vm_start + payload;
if (copy_to_user(arg, &request, sizeof request))
return -EFAULT;
return count;
}
-static int ioctl_send_iso(struct client *client, void __user *arg)
+static int ioctl_start_iso(struct client *client, void __user *arg)
{
- struct fw_cdev_send_iso request;
+ struct fw_cdev_start_iso request;
if (copy_from_user(&request, arg, sizeof request))
return -EFAULT;
- return fw_iso_context_send(client->iso_context, request.channel,
- request.speed, request.cycle);
+ return fw_iso_context_start(client->iso_context, request.channel,
+ request.speed, request.cycle);
}
static int
return ioctl_create_iso_context(client, arg);
case FW_CDEV_IOC_QUEUE_ISO:
return ioctl_queue_iso(client, arg);
- case FW_CDEV_IOC_SEND_ISO:
- return ioctl_send_iso(client, arg);
+ case FW_CDEV_IOC_START_ISO:
+ return ioctl_start_iso(client, arg);
default:
return -EINVAL;
}
static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma)
{
struct client *client = file->private_data;
+ enum dma_data_direction direction;
+ unsigned long size;
+ int page_count, retval;
+
+ /* FIXME: We could support multiple buffers, but we don't. */
+ if (client->buffer.pages != NULL)
+ return -EBUSY;
- if (client->iso_context->buffer == NULL)
+ 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;
+
+ if (vma->vm_flags & VM_WRITE)
+ direction = DMA_TO_DEVICE;
+ else
+ direction = DMA_FROM_DEVICE;
- return remap_vmalloc_range(vma, client->iso_context->buffer, 0);
+ retval = fw_iso_buffer_init(&client->buffer, client->device->card,
+ page_count, direction);
+ if (retval < 0)
+ return retval;
+
+ retval = fw_iso_buffer_map(&client->buffer, vma);
+ if (retval < 0)
+ fw_iso_buffer_destroy(&client->buffer, client->device->card);
+
+ return retval;
}
static int fw_device_op_release(struct inode *inode, struct file *file)
struct address_handler *h, *next;
struct request *r, *next_r;
+ if (client->buffer.pages)
+ fw_iso_buffer_destroy(&client->buffer, client->device->card);
+
if (client->iso_context)
fw_iso_context_destroy(client->iso_context);