2 * video1394.c - video driver for OHCI 1394 boards
3 * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
4 * Peter Schlaile <udbz@rz.uni-karlsruhe.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * jds -- add private data to file to keep track of iso contexts associated
23 * with each open -- so release won't kill all iso transfers.
25 * Damien Douxchamps: Fix failure when the number of DMA pages per frame is
29 * EFAULT is only for invalid address for the argp
30 * EINVAL for out of range values
31 * EBUSY when trying to use an already used resource
32 * ESRCH when trying to free/stop a not used resource
33 * EAGAIN for resource allocation failure that could perhaps succeed later
34 * ENOTTY for unsupported ioctl request
38 /* Markus Tavenrath <speedygoo@speedygoo.de> :
39 - fixed checks for valid buffer-numbers in video1394_icotl
40 - changed the ways the dma prg's are used, now it's possible to use
41 even a single dma buffer
43 #include <linux/config.h>
44 #include <linux/kernel.h>
45 #include <linux/list.h>
46 #include <linux/slab.h>
47 #include <linux/interrupt.h>
48 #include <linux/wait.h>
49 #include <linux/errno.h>
50 #include <linux/module.h>
51 #include <linux/init.h>
52 #include <linux/pci.h>
54 #include <linux/poll.h>
55 #include <linux/smp_lock.h>
56 #include <linux/delay.h>
57 #include <linux/devfs_fs_kernel.h>
58 #include <linux/bitops.h>
59 #include <linux/types.h>
60 #include <linux/vmalloc.h>
61 #include <linux/timex.h>
63 #include <linux/ioctl32.h>
64 #include <linux/compat.h>
65 #include <linux/cdev.h>
68 #include "ieee1394_types.h"
70 #include "ieee1394_core.h"
71 #include "highlevel.h"
72 #include "video1394.h"
78 #define ISO_CHANNELS 64
81 #define virt_to_page(x) MAP_NR(x)
85 #define vmalloc_32(x) vmalloc(x)
92 quadlet_t pad[4]; /* FIXME: quick hack for memory alignment */
97 int type; /* OHCI_ISO_TRANSMIT or OHCI_ISO_RECEIVE */
98 struct ohci1394_iso_tasklet iso_tasklet;
102 int * next_buffer; /* For ISO Transmit of video packets
103 to write the correct SYT field
104 into the next block */
105 unsigned int num_desc;
106 unsigned int buf_size;
107 unsigned int frame_size;
108 unsigned int packet_size;
109 unsigned int left_size;
112 struct dma_region dma;
114 struct dma_prog_region *prg_reg;
116 struct dma_cmd **ir_prg;
117 struct it_dma_prg **it_prg;
119 unsigned int *buffer_status;
120 unsigned int *buffer_prg_assignment;
121 struct timeval *buffer_time; /* time when the buffer was received */
122 unsigned int *last_used_cmd; /* For ISO Transmit with
123 variable sized packets only ! */
128 wait_queue_head_t waitq;
130 unsigned int syt_offset;
133 struct list_head link;
138 struct ti_ohci *ohci;
139 struct list_head context_list;
140 struct dma_iso_ctx *current_ctx;
143 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
144 #define VIDEO1394_DEBUG
151 #ifdef VIDEO1394_DEBUG
152 #define DBGMSG(card, fmt, args...) \
153 printk(KERN_INFO "video1394_%d: " fmt "\n" , card , ## args)
155 #define DBGMSG(card, fmt, args...)
158 /* print general (card independent) information */
159 #define PRINT_G(level, fmt, args...) \
160 printk(level "video1394: " fmt "\n" , ## args)
162 /* print card specific information */
163 #define PRINT(level, card, fmt, args...) \
164 printk(level "video1394_%d: " fmt "\n" , card , ## args)
166 static void wakeup_dma_ir_ctx(unsigned long l);
167 static void wakeup_dma_it_ctx(unsigned long l);
169 static struct hpsb_highlevel video1394_highlevel;
171 static int free_dma_iso_ctx(struct dma_iso_ctx *d)
175 DBGMSG(d->ohci->host->id, "Freeing dma_iso_ctx %d", d->ctx);
177 ohci1394_stop_context(d->ohci, d->ctrlClear, NULL);
178 if (d->iso_tasklet.link.next != NULL)
179 ohci1394_unregister_iso_tasklet(d->ohci, &d->iso_tasklet);
181 dma_region_free(&d->dma);
184 for (i = 0; i < d->num_desc; i++)
185 dma_prog_region_free(&d->prg_reg[i]);
191 kfree(d->buffer_status);
192 kfree(d->buffer_prg_assignment);
193 kfree(d->buffer_time);
194 kfree(d->last_used_cmd);
195 kfree(d->next_buffer);
202 static struct dma_iso_ctx *
203 alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
204 int buf_size, int channel, unsigned int packet_size)
206 struct dma_iso_ctx *d;
209 d = kzalloc(sizeof(*d), GFP_KERNEL);
211 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx");
217 d->channel = channel;
218 d->num_desc = num_desc;
219 d->frame_size = buf_size;
220 d->buf_size = PAGE_ALIGN(buf_size);
222 INIT_LIST_HEAD(&d->link);
223 init_waitqueue_head(&d->waitq);
225 /* Init the regions for easy cleanup */
226 dma_region_init(&d->dma);
228 if (dma_region_alloc(&d->dma, (d->num_desc - 1) * d->buf_size, ohci->dev,
229 PCI_DMA_BIDIRECTIONAL)) {
230 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma buffer");
235 if (type == OHCI_ISO_RECEIVE)
236 ohci1394_init_iso_tasklet(&d->iso_tasklet, type,
240 ohci1394_init_iso_tasklet(&d->iso_tasklet, type,
244 if (ohci1394_register_iso_tasklet(ohci, &d->iso_tasklet) < 0) {
245 PRINT(KERN_ERR, ohci->host->id, "no free iso %s contexts",
246 type == OHCI_ISO_RECEIVE ? "receive" : "transmit");
250 d->ctx = d->iso_tasklet.context;
252 d->prg_reg = kmalloc(d->num_desc * sizeof(*d->prg_reg), GFP_KERNEL);
254 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs");
258 /* Makes for easier cleanup */
259 for (i = 0; i < d->num_desc; i++)
260 dma_prog_region_init(&d->prg_reg[i]);
262 if (type == OHCI_ISO_RECEIVE) {
263 d->ctrlSet = OHCI1394_IsoRcvContextControlSet+32*d->ctx;
264 d->ctrlClear = OHCI1394_IsoRcvContextControlClear+32*d->ctx;
265 d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx;
266 d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx;
268 d->ir_prg = kzalloc(d->num_desc * sizeof(*d->ir_prg),
272 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg");
277 d->nb_cmd = d->buf_size / PAGE_SIZE + 1;
278 d->left_size = (d->frame_size % PAGE_SIZE) ?
279 d->frame_size % PAGE_SIZE : PAGE_SIZE;
281 for (i = 0;i < d->num_desc; i++) {
282 if (dma_prog_region_alloc(&d->prg_reg[i], d->nb_cmd *
283 sizeof(struct dma_cmd), ohci->dev)) {
284 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg");
288 d->ir_prg[i] = (struct dma_cmd *)d->prg_reg[i].kvirt;
291 } else { /* OHCI_ISO_TRANSMIT */
292 d->ctrlSet = OHCI1394_IsoXmitContextControlSet+16*d->ctx;
293 d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx;
294 d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx;
296 d->it_prg = kzalloc(d->num_desc * sizeof(*d->it_prg),
300 PRINT(KERN_ERR, ohci->host->id,
301 "Failed to allocate dma it prg");
306 d->packet_size = packet_size;
308 if (PAGE_SIZE % packet_size || packet_size>4096) {
309 PRINT(KERN_ERR, ohci->host->id,
310 "Packet size %d (page_size: %ld) "
311 "not yet supported\n",
312 packet_size, PAGE_SIZE);
317 d->nb_cmd = d->frame_size / d->packet_size;
318 if (d->frame_size % d->packet_size) {
320 d->left_size = d->frame_size % d->packet_size;
322 d->left_size = d->packet_size;
324 for (i = 0; i < d->num_desc; i++) {
325 if (dma_prog_region_alloc(&d->prg_reg[i], d->nb_cmd *
326 sizeof(struct it_dma_prg), ohci->dev)) {
327 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma it prg");
331 d->it_prg[i] = (struct it_dma_prg *)d->prg_reg[i].kvirt;
336 kzalloc(d->num_desc * sizeof(*d->buffer_status), GFP_KERNEL);
337 d->buffer_prg_assignment =
338 kzalloc(d->num_desc * sizeof(*d->buffer_prg_assignment), GFP_KERNEL);
340 kzalloc(d->num_desc * sizeof(*d->buffer_time), GFP_KERNEL);
342 kzalloc(d->num_desc * sizeof(*d->last_used_cmd), GFP_KERNEL);
344 kzalloc(d->num_desc * sizeof(*d->next_buffer), GFP_KERNEL);
346 if (!d->buffer_status || !d->buffer_prg_assignment || !d->buffer_time ||
347 !d->last_used_cmd || !d->next_buffer) {
348 PRINT(KERN_ERR, ohci->host->id,
349 "Failed to allocate dma_iso_ctx member");
354 spin_lock_init(&d->lock);
356 PRINT(KERN_INFO, ohci->host->id, "Iso %s DMA: %d buffers "
357 "of size %d allocated for a frame size %d, each with %d prgs",
358 (type == OHCI_ISO_RECEIVE) ? "receive" : "transmit",
359 d->num_desc - 1, d->buf_size, d->frame_size, d->nb_cmd);
364 static void reset_ir_status(struct dma_iso_ctx *d, int n)
367 d->ir_prg[n][0].status = cpu_to_le32(4);
368 d->ir_prg[n][1].status = cpu_to_le32(PAGE_SIZE-4);
369 for (i = 2; i < d->nb_cmd - 1; i++)
370 d->ir_prg[n][i].status = cpu_to_le32(PAGE_SIZE);
371 d->ir_prg[n][i].status = cpu_to_le32(d->left_size);
374 static void reprogram_dma_ir_prg(struct dma_iso_ctx *d, int n, int buffer, int flags)
376 struct dma_cmd *ir_prg = d->ir_prg[n];
377 unsigned long buf = (unsigned long)d->dma.kvirt + buffer * d->buf_size;
380 d->buffer_prg_assignment[n] = buffer;
382 ir_prg[0].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma, buf -
383 (unsigned long)d->dma.kvirt));
384 ir_prg[1].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
385 (buf + 4) - (unsigned long)d->dma.kvirt));
387 for (i=2;i<d->nb_cmd-1;i++) {
388 ir_prg[i].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
389 (buf+(i-1)*PAGE_SIZE) -
390 (unsigned long)d->dma.kvirt));
393 ir_prg[i].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
394 DMA_CTL_IRQ | DMA_CTL_BRANCH | d->left_size);
395 ir_prg[i].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
396 (buf+(i-1)*PAGE_SIZE) - (unsigned long)d->dma.kvirt));
399 static void initialize_dma_ir_prg(struct dma_iso_ctx *d, int n, int flags)
401 struct dma_cmd *ir_prg = d->ir_prg[n];
402 struct dma_prog_region *ir_reg = &d->prg_reg[n];
403 unsigned long buf = (unsigned long)d->dma.kvirt;
406 /* the first descriptor will read only 4 bytes */
407 ir_prg[0].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
410 /* set the sync flag */
411 if (flags & VIDEO1394_SYNC_FRAMES)
412 ir_prg[0].control |= cpu_to_le32(DMA_CTL_WAIT);
414 ir_prg[0].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma, buf -
415 (unsigned long)d->dma.kvirt));
416 ir_prg[0].branchAddress = cpu_to_le32((dma_prog_region_offset_to_bus(ir_reg,
417 1 * sizeof(struct dma_cmd)) & 0xfffffff0) | 0x1);
419 /* If there is *not* only one DMA page per frame (hence, d->nb_cmd==2) */
421 /* The second descriptor will read PAGE_SIZE-4 bytes */
422 ir_prg[1].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
423 DMA_CTL_BRANCH | (PAGE_SIZE-4));
424 ir_prg[1].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma, (buf + 4) -
425 (unsigned long)d->dma.kvirt));
426 ir_prg[1].branchAddress = cpu_to_le32((dma_prog_region_offset_to_bus(ir_reg,
427 2 * sizeof(struct dma_cmd)) & 0xfffffff0) | 0x1);
429 for (i = 2; i < d->nb_cmd - 1; i++) {
430 ir_prg[i].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
431 DMA_CTL_BRANCH | PAGE_SIZE);
432 ir_prg[i].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
433 (buf+(i-1)*PAGE_SIZE) -
434 (unsigned long)d->dma.kvirt));
436 ir_prg[i].branchAddress =
437 cpu_to_le32((dma_prog_region_offset_to_bus(ir_reg,
438 (i + 1) * sizeof(struct dma_cmd)) & 0xfffffff0) | 0x1);
441 /* The last descriptor will generate an interrupt */
442 ir_prg[i].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
443 DMA_CTL_IRQ | DMA_CTL_BRANCH | d->left_size);
444 ir_prg[i].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
445 (buf+(i-1)*PAGE_SIZE) -
446 (unsigned long)d->dma.kvirt));
448 /* Only one DMA page is used. Read d->left_size immediately and */
449 /* generate an interrupt as this is also the last page. */
450 ir_prg[1].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
451 DMA_CTL_IRQ | DMA_CTL_BRANCH | (d->left_size-4));
452 ir_prg[1].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
453 (buf + 4) - (unsigned long)d->dma.kvirt));
457 static void initialize_dma_ir_ctx(struct dma_iso_ctx *d, int tag, int flags)
459 struct ti_ohci *ohci = (struct ti_ohci *)d->ohci;
464 ohci1394_stop_context(ohci, d->ctrlClear, NULL);
466 for (i=0;i<d->num_desc;i++) {
467 initialize_dma_ir_prg(d, i, flags);
468 reset_ir_status(d, i);
471 /* reset the ctrl register */
472 reg_write(ohci, d->ctrlClear, 0xf0000000);
475 reg_write(ohci, d->ctrlSet, 0x80000000);
477 /* Set isoch header */
478 if (flags & VIDEO1394_INCLUDE_ISO_HEADERS)
479 reg_write(ohci, d->ctrlSet, 0x40000000);
481 /* Set the context match register to match on all tags,
482 sync for sync tag, and listen to d->channel */
483 reg_write(ohci, d->ctxMatch, 0xf0000000|((tag&0xf)<<8)|d->channel);
485 /* Set up isoRecvIntMask to generate interrupts */
486 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1<<d->ctx);
489 /* find which context is listening to this channel */
490 static struct dma_iso_ctx *
491 find_ctx(struct list_head *list, int type, int channel)
493 struct dma_iso_ctx *ctx;
495 list_for_each_entry(ctx, list, link) {
496 if (ctx->type == type && ctx->channel == channel)
503 static void wakeup_dma_ir_ctx(unsigned long l)
505 struct dma_iso_ctx *d = (struct dma_iso_ctx *) l;
510 for (i = 0; i < d->num_desc; i++) {
511 if (d->ir_prg[i][d->nb_cmd-1].status & cpu_to_le32(0xFFFF0000)) {
512 reset_ir_status(d, i);
513 d->buffer_status[d->buffer_prg_assignment[i]] = VIDEO1394_BUFFER_READY;
514 do_gettimeofday(&d->buffer_time[i]);
518 spin_unlock(&d->lock);
520 if (waitqueue_active(&d->waitq))
521 wake_up_interruptible(&d->waitq);
524 static inline void put_timestamp(struct ti_ohci *ohci, struct dma_iso_ctx * d,
527 unsigned char* buf = d->dma.kvirt + n * d->buf_size;
535 cycleTimer = reg_read(ohci, OHCI1394_IsochronousCycleTimer);
537 timeStamp = ((cycleTimer & 0x0fff) + d->syt_offset); /* 11059 = 450 us */
538 timeStamp = (timeStamp % 3072 + ((timeStamp / 3072) << 12)
539 + (cycleTimer & 0xf000)) & 0xffff;
541 buf[6] = timeStamp >> 8;
542 buf[7] = timeStamp & 0xff;
544 /* if first packet is empty packet, then put timestamp into the next full one too */
545 if ( (le32_to_cpu(d->it_prg[n][0].data[1]) >>16) == 0x008) {
546 buf += d->packet_size;
547 buf[6] = timeStamp >> 8;
548 buf[7] = timeStamp & 0xff;
551 /* do the next buffer frame too in case of irq latency */
552 n = d->next_buffer[n];
556 buf = d->dma.kvirt + n * d->buf_size;
558 timeStamp += (d->last_used_cmd[n] << 12) & 0xffff;
560 buf[6] = timeStamp >> 8;
561 buf[7] = timeStamp & 0xff;
563 /* if first packet is empty packet, then put timestamp into the next full one too */
564 if ( (le32_to_cpu(d->it_prg[n][0].data[1]) >>16) == 0x008) {
565 buf += d->packet_size;
566 buf[6] = timeStamp >> 8;
567 buf[7] = timeStamp & 0xff;
571 printk("curr: %d, next: %d, cycleTimer: %08x timeStamp: %08x\n",
572 curr, n, cycleTimer, timeStamp);
576 static void wakeup_dma_it_ctx(unsigned long l)
578 struct dma_iso_ctx *d = (struct dma_iso_ctx *) l;
579 struct ti_ohci *ohci = d->ohci;
584 for (i = 0; i < d->num_desc; i++) {
585 if (d->it_prg[i][d->last_used_cmd[i]].end.status &
586 cpu_to_le32(0xFFFF0000)) {
587 int next = d->next_buffer[i];
588 put_timestamp(ohci, d, next);
589 d->it_prg[i][d->last_used_cmd[i]].end.status = 0;
590 d->buffer_status[d->buffer_prg_assignment[i]] = VIDEO1394_BUFFER_READY;
594 spin_unlock(&d->lock);
596 if (waitqueue_active(&d->waitq))
597 wake_up_interruptible(&d->waitq);
600 static void reprogram_dma_it_prg(struct dma_iso_ctx *d, int n, int buffer)
602 struct it_dma_prg *it_prg = d->it_prg[n];
603 unsigned long buf = (unsigned long)d->dma.kvirt + buffer * d->buf_size;
606 d->buffer_prg_assignment[n] = buffer;
607 for (i=0;i<d->nb_cmd;i++) {
608 it_prg[i].end.address =
609 cpu_to_le32(dma_region_offset_to_bus(&d->dma,
610 (buf+i*d->packet_size) - (unsigned long)d->dma.kvirt));
614 static void initialize_dma_it_prg(struct dma_iso_ctx *d, int n, int sync_tag)
616 struct it_dma_prg *it_prg = d->it_prg[n];
617 struct dma_prog_region *it_reg = &d->prg_reg[n];
618 unsigned long buf = (unsigned long)d->dma.kvirt;
620 d->last_used_cmd[n] = d->nb_cmd - 1;
621 for (i=0;i<d->nb_cmd;i++) {
623 it_prg[i].begin.control = cpu_to_le32(DMA_CTL_OUTPUT_MORE |
624 DMA_CTL_IMMEDIATE | 8) ;
625 it_prg[i].begin.address = 0;
627 it_prg[i].begin.status = 0;
629 it_prg[i].data[0] = cpu_to_le32(
630 (IEEE1394_SPEED_100 << 16)
631 | (/* tag */ 1 << 14)
633 | (TCODE_ISO_DATA << 4));
634 if (i==0) it_prg[i].data[0] |= cpu_to_le32(sync_tag);
635 it_prg[i].data[1] = cpu_to_le32(d->packet_size << 16);
636 it_prg[i].data[2] = 0;
637 it_prg[i].data[3] = 0;
639 it_prg[i].end.control = cpu_to_le32(DMA_CTL_OUTPUT_LAST |
641 it_prg[i].end.address =
642 cpu_to_le32(dma_region_offset_to_bus(&d->dma, (buf+i*d->packet_size) -
643 (unsigned long)d->dma.kvirt));
646 it_prg[i].end.control |= cpu_to_le32(d->packet_size);
647 it_prg[i].begin.branchAddress =
648 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
649 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
650 it_prg[i].end.branchAddress =
651 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
652 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
654 /* the last prg generates an interrupt */
655 it_prg[i].end.control |= cpu_to_le32(DMA_CTL_UPDATE |
656 DMA_CTL_IRQ | d->left_size);
657 /* the last prg doesn't branch */
658 it_prg[i].begin.branchAddress = 0;
659 it_prg[i].end.branchAddress = 0;
661 it_prg[i].end.status = 0;
665 static void initialize_dma_it_prg_var_packet_queue(
666 struct dma_iso_ctx *d, int n, unsigned int * packet_sizes,
667 struct ti_ohci *ohci)
669 struct it_dma_prg *it_prg = d->it_prg[n];
670 struct dma_prog_region *it_reg = &d->prg_reg[n];
675 put_timestamp(ohci, d, n);
678 d->last_used_cmd[n] = d->nb_cmd - 1;
680 for (i = 0; i < d->nb_cmd; i++) {
682 if (packet_sizes[i] > d->packet_size) {
683 size = d->packet_size;
685 size = packet_sizes[i];
687 it_prg[i].data[1] = cpu_to_le32(size << 16);
688 it_prg[i].end.control = cpu_to_le32(DMA_CTL_OUTPUT_LAST | DMA_CTL_BRANCH);
690 if (i < d->nb_cmd-1 && packet_sizes[i+1] != 0) {
691 it_prg[i].end.control |= cpu_to_le32(size);
692 it_prg[i].begin.branchAddress =
693 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
694 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
695 it_prg[i].end.branchAddress =
696 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
697 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
699 /* the last prg generates an interrupt */
700 it_prg[i].end.control |= cpu_to_le32(DMA_CTL_UPDATE |
702 /* the last prg doesn't branch */
703 it_prg[i].begin.branchAddress = 0;
704 it_prg[i].end.branchAddress = 0;
705 d->last_used_cmd[n] = i;
711 static void initialize_dma_it_ctx(struct dma_iso_ctx *d, int sync_tag,
712 unsigned int syt_offset, int flags)
714 struct ti_ohci *ohci = (struct ti_ohci *)d->ohci;
718 d->syt_offset = (syt_offset == 0 ? 11000 : syt_offset);
720 ohci1394_stop_context(ohci, d->ctrlClear, NULL);
722 for (i=0;i<d->num_desc;i++)
723 initialize_dma_it_prg(d, i, sync_tag);
725 /* Set up isoRecvIntMask to generate interrupts */
726 reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1<<d->ctx);
729 static inline unsigned video1394_buffer_state(struct dma_iso_ctx *d,
734 spin_lock_irqsave(&d->lock, flags);
735 ret = d->buffer_status[buffer];
736 spin_unlock_irqrestore(&d->lock, flags);
740 static int __video1394_ioctl(struct file *file,
741 unsigned int cmd, unsigned long arg)
743 struct file_ctx *ctx = (struct file_ctx *)file->private_data;
744 struct ti_ohci *ohci = ctx->ohci;
746 void __user *argp = (void __user *)arg;
750 case VIDEO1394_IOC_LISTEN_CHANNEL:
751 case VIDEO1394_IOC_TALK_CHANNEL:
753 struct video1394_mmap v;
755 struct dma_iso_ctx *d;
758 if (copy_from_user(&v, argp, sizeof(v)))
761 /* if channel < 0, find lowest available one */
765 if (i == ISO_CHANNELS) {
766 PRINT(KERN_ERR, ohci->host->id,
767 "No free channel found");
770 if (!(ohci->ISO_channel_usage & mask)) {
772 PRINT(KERN_INFO, ohci->host->id, "Found free channel %d", i);
777 } else if (v.channel >= ISO_CHANNELS) {
778 PRINT(KERN_ERR, ohci->host->id,
779 "Iso channel %d out of bounds", v.channel);
782 mask = (u64)0x1<<v.channel;
784 PRINT(KERN_INFO, ohci->host->id, "mask: %08X%08X usage: %08X%08X\n",
785 (u32)(mask>>32),(u32)(mask&0xffffffff),
786 (u32)(ohci->ISO_channel_usage>>32),
787 (u32)(ohci->ISO_channel_usage&0xffffffff));
788 if (ohci->ISO_channel_usage & mask) {
789 PRINT(KERN_ERR, ohci->host->id,
790 "Channel %d is already taken", v.channel);
794 if (v.buf_size == 0 || v.buf_size > VIDEO1394_MAX_SIZE) {
795 PRINT(KERN_ERR, ohci->host->id,
796 "Invalid %d length buffer requested",v.buf_size);
800 if (v.nb_buffers == 0 || v.nb_buffers > VIDEO1394_MAX_SIZE) {
801 PRINT(KERN_ERR, ohci->host->id,
802 "Invalid %d buffers requested",v.nb_buffers);
806 if (v.nb_buffers * v.buf_size > VIDEO1394_MAX_SIZE) {
807 PRINT(KERN_ERR, ohci->host->id,
808 "%d buffers of size %d bytes is too big",
809 v.nb_buffers, v.buf_size);
813 if (cmd == VIDEO1394_IOC_LISTEN_CHANNEL) {
814 d = alloc_dma_iso_ctx(ohci, OHCI_ISO_RECEIVE,
815 v.nb_buffers + 1, v.buf_size,
819 PRINT(KERN_ERR, ohci->host->id,
820 "Couldn't allocate ir context");
823 initialize_dma_ir_ctx(d, v.sync_tag, v.flags);
825 ctx->current_ctx = d;
827 v.buf_size = d->buf_size;
828 list_add_tail(&d->link, &ctx->context_list);
830 PRINT(KERN_INFO, ohci->host->id,
831 "iso context %d listen on channel %d",
835 d = alloc_dma_iso_ctx(ohci, OHCI_ISO_TRANSMIT,
836 v.nb_buffers + 1, v.buf_size,
837 v.channel, v.packet_size);
840 PRINT(KERN_ERR, ohci->host->id,
841 "Couldn't allocate it context");
844 initialize_dma_it_ctx(d, v.sync_tag,
845 v.syt_offset, v.flags);
847 ctx->current_ctx = d;
849 v.buf_size = d->buf_size;
851 list_add_tail(&d->link, &ctx->context_list);
853 PRINT(KERN_INFO, ohci->host->id,
854 "Iso context %d talk on channel %d", d->ctx,
858 if (copy_to_user(argp, &v, sizeof(v))) {
859 /* FIXME : free allocated dma resources */
863 ohci->ISO_channel_usage |= mask;
867 case VIDEO1394_IOC_UNLISTEN_CHANNEL:
868 case VIDEO1394_IOC_UNTALK_CHANNEL:
872 struct dma_iso_ctx *d;
874 if (copy_from_user(&channel, argp, sizeof(int)))
877 if (channel < 0 || channel >= ISO_CHANNELS) {
878 PRINT(KERN_ERR, ohci->host->id,
879 "Iso channel %d out of bound", channel);
882 mask = (u64)0x1<<channel;
883 if (!(ohci->ISO_channel_usage & mask)) {
884 PRINT(KERN_ERR, ohci->host->id,
885 "Channel %d is not being used", channel);
889 /* Mark this channel as unused */
890 ohci->ISO_channel_usage &= ~mask;
892 if (cmd == VIDEO1394_IOC_UNLISTEN_CHANNEL)
893 d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, channel);
895 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, channel);
897 if (d == NULL) return -ESRCH;
898 PRINT(KERN_INFO, ohci->host->id, "Iso context %d "
899 "stop talking on channel %d", d->ctx, channel);
904 case VIDEO1394_IOC_LISTEN_QUEUE_BUFFER:
906 struct video1394_wait v;
907 struct dma_iso_ctx *d;
910 if (copy_from_user(&v, argp, sizeof(v)))
913 d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
914 if (d == NULL) return -EFAULT;
916 if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
917 PRINT(KERN_ERR, ohci->host->id,
918 "Buffer %d out of range",v.buffer);
922 spin_lock_irqsave(&d->lock,flags);
924 if (d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED) {
925 PRINT(KERN_ERR, ohci->host->id,
926 "Buffer %d is already used",v.buffer);
927 spin_unlock_irqrestore(&d->lock,flags);
931 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_QUEUED;
933 next_prg = (d->last_buffer + 1) % d->num_desc;
934 if (d->last_buffer>=0)
935 d->ir_prg[d->last_buffer][d->nb_cmd-1].branchAddress =
936 cpu_to_le32((dma_prog_region_offset_to_bus(&d->prg_reg[next_prg], 0)
937 & 0xfffffff0) | 0x1);
939 d->last_buffer = next_prg;
940 reprogram_dma_ir_prg(d, d->last_buffer, v.buffer, d->flags);
942 d->ir_prg[d->last_buffer][d->nb_cmd-1].branchAddress = 0;
944 spin_unlock_irqrestore(&d->lock,flags);
946 if (!(reg_read(ohci, d->ctrlSet) & 0x8000))
948 DBGMSG(ohci->host->id, "Starting iso DMA ctx=%d",d->ctx);
950 /* Tell the controller where the first program is */
951 reg_write(ohci, d->cmdPtr,
952 dma_prog_region_offset_to_bus(&d->prg_reg[d->last_buffer], 0) | 0x1);
955 reg_write(ohci, d->ctrlSet, 0x8000);
958 /* Wake up dma context if necessary */
959 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) {
960 PRINT(KERN_INFO, ohci->host->id,
961 "Waking up iso dma ctx=%d", d->ctx);
962 reg_write(ohci, d->ctrlSet, 0x1000);
968 case VIDEO1394_IOC_LISTEN_WAIT_BUFFER:
969 case VIDEO1394_IOC_LISTEN_POLL_BUFFER:
971 struct video1394_wait v;
972 struct dma_iso_ctx *d;
975 if (copy_from_user(&v, argp, sizeof(v)))
978 d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
979 if (d == NULL) return -EFAULT;
981 if ((v.buffer<0) || (v.buffer>d->num_desc - 1)) {
982 PRINT(KERN_ERR, ohci->host->id,
983 "Buffer %d out of range",v.buffer);
988 * I change the way it works so that it returns
989 * the last received frame.
991 spin_lock_irqsave(&d->lock, flags);
992 switch(d->buffer_status[v.buffer]) {
993 case VIDEO1394_BUFFER_READY:
994 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
996 case VIDEO1394_BUFFER_QUEUED:
997 if (cmd == VIDEO1394_IOC_LISTEN_POLL_BUFFER) {
998 /* for polling, return error code EINTR */
999 spin_unlock_irqrestore(&d->lock, flags);
1003 spin_unlock_irqrestore(&d->lock, flags);
1004 wait_event_interruptible(d->waitq,
1005 video1394_buffer_state(d, v.buffer) ==
1006 VIDEO1394_BUFFER_READY);
1007 if (signal_pending(current))
1009 spin_lock_irqsave(&d->lock, flags);
1010 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
1013 PRINT(KERN_ERR, ohci->host->id,
1014 "Buffer %d is not queued",v.buffer);
1015 spin_unlock_irqrestore(&d->lock, flags);
1019 /* set time of buffer */
1020 v.filltime = d->buffer_time[v.buffer];
1021 // printk("Buffer %d time %d\n", v.buffer, (d->buffer_time[v.buffer]).tv_usec);
1024 * Look ahead to see how many more buffers have been received
1027 while (d->buffer_status[(v.buffer+1)%(d->num_desc - 1)]==
1028 VIDEO1394_BUFFER_READY) {
1029 v.buffer=(v.buffer+1)%(d->num_desc - 1);
1032 spin_unlock_irqrestore(&d->lock, flags);
1035 if (copy_to_user(argp, &v, sizeof(v)))
1040 case VIDEO1394_IOC_TALK_QUEUE_BUFFER:
1042 struct video1394_wait v;
1043 unsigned int *psizes = NULL;
1044 struct dma_iso_ctx *d;
1047 if (copy_from_user(&v, argp, sizeof(v)))
1050 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
1051 if (d == NULL) return -EFAULT;
1053 if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
1054 PRINT(KERN_ERR, ohci->host->id,
1055 "Buffer %d out of range",v.buffer);
1059 if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) {
1060 int buf_size = d->nb_cmd * sizeof(*psizes);
1061 struct video1394_queue_variable __user *p = argp;
1062 unsigned int __user *qv;
1064 if (get_user(qv, &p->packet_sizes))
1067 psizes = kmalloc(buf_size, GFP_KERNEL);
1071 if (copy_from_user(psizes, qv, buf_size)) {
1077 spin_lock_irqsave(&d->lock,flags);
1079 // last_buffer is last_prg
1080 next_prg = (d->last_buffer + 1) % d->num_desc;
1081 if (d->buffer_status[v.buffer]!=VIDEO1394_BUFFER_FREE) {
1082 PRINT(KERN_ERR, ohci->host->id,
1083 "Buffer %d is already used",v.buffer);
1084 spin_unlock_irqrestore(&d->lock,flags);
1089 if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) {
1090 initialize_dma_it_prg_var_packet_queue(
1091 d, next_prg, psizes, ohci);
1094 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_QUEUED;
1096 if (d->last_buffer >= 0) {
1097 d->it_prg[d->last_buffer]
1098 [ d->last_used_cmd[d->last_buffer] ].end.branchAddress =
1099 cpu_to_le32((dma_prog_region_offset_to_bus(&d->prg_reg[next_prg],
1100 0) & 0xfffffff0) | 0x3);
1102 d->it_prg[d->last_buffer]
1103 [ d->last_used_cmd[d->last_buffer] ].begin.branchAddress =
1104 cpu_to_le32((dma_prog_region_offset_to_bus(&d->prg_reg[next_prg],
1105 0) & 0xfffffff0) | 0x3);
1106 d->next_buffer[d->last_buffer] = (v.buffer + 1) % (d->num_desc - 1);
1108 d->last_buffer = next_prg;
1109 reprogram_dma_it_prg(d, d->last_buffer, v.buffer);
1110 d->next_buffer[d->last_buffer] = -1;
1112 d->it_prg[d->last_buffer][d->last_used_cmd[d->last_buffer]].end.branchAddress = 0;
1114 spin_unlock_irqrestore(&d->lock,flags);
1116 if (!(reg_read(ohci, d->ctrlSet) & 0x8000))
1118 DBGMSG(ohci->host->id, "Starting iso transmit DMA ctx=%d",
1120 put_timestamp(ohci, d, d->last_buffer);
1122 /* Tell the controller where the first program is */
1123 reg_write(ohci, d->cmdPtr,
1124 dma_prog_region_offset_to_bus(&d->prg_reg[next_prg], 0) | 0x3);
1126 /* Run IT context */
1127 reg_write(ohci, d->ctrlSet, 0x8000);
1130 /* Wake up dma context if necessary */
1131 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) {
1132 PRINT(KERN_INFO, ohci->host->id,
1133 "Waking up iso transmit dma ctx=%d",
1135 put_timestamp(ohci, d, d->last_buffer);
1136 reg_write(ohci, d->ctrlSet, 0x1000);
1144 case VIDEO1394_IOC_TALK_WAIT_BUFFER:
1146 struct video1394_wait v;
1147 struct dma_iso_ctx *d;
1149 if (copy_from_user(&v, argp, sizeof(v)))
1152 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
1153 if (d == NULL) return -EFAULT;
1155 if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) {
1156 PRINT(KERN_ERR, ohci->host->id,
1157 "Buffer %d out of range",v.buffer);
1161 switch(d->buffer_status[v.buffer]) {
1162 case VIDEO1394_BUFFER_READY:
1163 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
1165 case VIDEO1394_BUFFER_QUEUED:
1166 wait_event_interruptible(d->waitq,
1167 (d->buffer_status[v.buffer] == VIDEO1394_BUFFER_READY));
1168 if (signal_pending(current))
1170 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
1173 PRINT(KERN_ERR, ohci->host->id,
1174 "Buffer %d is not queued",v.buffer);
1183 static long video1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1187 err = __video1394_ioctl(file, cmd, arg);
1193 * This maps the vmalloced and reserved buffer to user space.
1196 * - PAGE_READONLY should suffice!?
1197 * - remap_pfn_range is kind of inefficient for page by page remapping.
1198 * But e.g. pte_alloc() does not work in modules ... :-(
1201 static int video1394_mmap(struct file *file, struct vm_area_struct *vma)
1203 struct file_ctx *ctx = (struct file_ctx *)file->private_data;
1207 if (ctx->current_ctx == NULL) {
1208 PRINT(KERN_ERR, ctx->ohci->host->id, "Current iso context not set");
1210 res = dma_region_mmap(&ctx->current_ctx->dma, file, vma);
1216 static int video1394_open(struct inode *inode, struct file *file)
1218 int i = ieee1394_file_to_instance(file);
1219 struct ti_ohci *ohci;
1220 struct file_ctx *ctx;
1222 ohci = hpsb_get_hostinfo_bykey(&video1394_highlevel, i);
1226 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
1228 PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx");
1233 INIT_LIST_HEAD(&ctx->context_list);
1234 ctx->current_ctx = NULL;
1235 file->private_data = ctx;
1240 static int video1394_release(struct inode *inode, struct file *file)
1242 struct file_ctx *ctx = (struct file_ctx *)file->private_data;
1243 struct ti_ohci *ohci = ctx->ohci;
1244 struct list_head *lh, *next;
1248 list_for_each_safe(lh, next, &ctx->context_list) {
1249 struct dma_iso_ctx *d;
1250 d = list_entry(lh, struct dma_iso_ctx, link);
1251 mask = (u64) 1 << d->channel;
1253 if (!(ohci->ISO_channel_usage & mask))
1254 PRINT(KERN_ERR, ohci->host->id, "On release: Channel %d "
1255 "is not being used", d->channel);
1257 ohci->ISO_channel_usage &= ~mask;
1258 PRINT(KERN_INFO, ohci->host->id, "On release: Iso %s context "
1259 "%d stop listening on channel %d",
1260 d->type == OHCI_ISO_RECEIVE ? "receive" : "transmit",
1261 d->ctx, d->channel);
1262 free_dma_iso_ctx(d);
1266 file->private_data = NULL;
1272 #ifdef CONFIG_COMPAT
1273 static long video1394_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg);
1276 static struct cdev video1394_cdev;
1277 static struct file_operations video1394_fops=
1279 .owner = THIS_MODULE,
1280 .unlocked_ioctl = video1394_ioctl,
1281 #ifdef CONFIG_COMPAT
1282 .compat_ioctl = video1394_compat_ioctl,
1284 .mmap = video1394_mmap,
1285 .open = video1394_open,
1286 .release = video1394_release
1289 /*** HOTPLUG STUFF **********************************************************/
1291 * Export information about protocols/devices supported by this driver.
1293 static struct ieee1394_device_id video1394_id_table[] = {
1295 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
1296 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
1297 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff
1300 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
1301 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
1302 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff
1305 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
1306 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
1307 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff
1312 MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
1314 static struct hpsb_protocol_driver video1394_driver = {
1315 .name = "1394 Digital Camera Driver",
1316 .id_table = video1394_id_table,
1318 .name = VIDEO1394_DRIVER_NAME,
1319 .bus = &ieee1394_bus_type,
1324 static void video1394_add_host (struct hpsb_host *host)
1326 struct ti_ohci *ohci;
1329 /* We only work with the OHCI-1394 driver */
1330 if (strcmp(host->driver->name, OHCI1394_DRIVER_NAME))
1333 ohci = (struct ti_ohci *)host->hostdata;
1335 if (!hpsb_create_hostinfo(&video1394_highlevel, host, 0)) {
1336 PRINT(KERN_ERR, ohci->host->id, "Cannot allocate hostinfo");
1340 hpsb_set_hostinfo(&video1394_highlevel, host, ohci);
1341 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id);
1343 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id;
1344 class_device_create(hpsb_protocol_class, NULL, MKDEV(
1345 IEEE1394_MAJOR, minor),
1346 NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1347 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, minor),
1348 S_IFCHR | S_IRUSR | S_IWUSR,
1349 "%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1353 static void video1394_remove_host (struct hpsb_host *host)
1355 struct ti_ohci *ohci = hpsb_get_hostinfo(&video1394_highlevel, host);
1358 class_device_destroy(hpsb_protocol_class, MKDEV(IEEE1394_MAJOR,
1359 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id));
1360 devfs_remove("%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1367 static struct hpsb_highlevel video1394_highlevel = {
1368 .name = VIDEO1394_DRIVER_NAME,
1369 .add_host = video1394_add_host,
1370 .remove_host = video1394_remove_host,
1373 MODULE_AUTHOR("Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>");
1374 MODULE_DESCRIPTION("driver for digital video on OHCI board");
1375 MODULE_SUPPORTED_DEVICE(VIDEO1394_DRIVER_NAME);
1376 MODULE_LICENSE("GPL");
1378 #ifdef CONFIG_COMPAT
1380 #define VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER \
1381 _IOW ('#', 0x12, struct video1394_wait32)
1382 #define VIDEO1394_IOC32_LISTEN_WAIT_BUFFER \
1383 _IOWR('#', 0x13, struct video1394_wait32)
1384 #define VIDEO1394_IOC32_TALK_WAIT_BUFFER \
1385 _IOW ('#', 0x17, struct video1394_wait32)
1386 #define VIDEO1394_IOC32_LISTEN_POLL_BUFFER \
1387 _IOWR('#', 0x18, struct video1394_wait32)
1389 struct video1394_wait32 {
1392 struct compat_timeval filltime;
1395 static int video1394_wr_wait32(struct file *file, unsigned int cmd, unsigned long arg)
1397 struct video1394_wait32 __user *argp = (void __user *)arg;
1398 struct video1394_wait32 wait32;
1399 struct video1394_wait wait;
1400 mm_segment_t old_fs;
1403 if (copy_from_user(&wait32, argp, sizeof(wait32)))
1406 wait.channel = wait32.channel;
1407 wait.buffer = wait32.buffer;
1408 wait.filltime.tv_sec = (time_t)wait32.filltime.tv_sec;
1409 wait.filltime.tv_usec = (suseconds_t)wait32.filltime.tv_usec;
1413 if (cmd == VIDEO1394_IOC32_LISTEN_WAIT_BUFFER)
1414 ret = video1394_ioctl(file,
1415 VIDEO1394_IOC_LISTEN_WAIT_BUFFER,
1416 (unsigned long) &wait);
1418 ret = video1394_ioctl(file,
1419 VIDEO1394_IOC_LISTEN_POLL_BUFFER,
1420 (unsigned long) &wait);
1424 wait32.channel = wait.channel;
1425 wait32.buffer = wait.buffer;
1426 wait32.filltime.tv_sec = (int)wait.filltime.tv_sec;
1427 wait32.filltime.tv_usec = (int)wait.filltime.tv_usec;
1429 if (copy_to_user(argp, &wait32, sizeof(wait32)))
1436 static int video1394_w_wait32(struct file *file, unsigned int cmd, unsigned long arg)
1438 struct video1394_wait32 wait32;
1439 struct video1394_wait wait;
1440 mm_segment_t old_fs;
1443 if (copy_from_user(&wait32, (void __user *)arg, sizeof(wait32)))
1446 wait.channel = wait32.channel;
1447 wait.buffer = wait32.buffer;
1448 wait.filltime.tv_sec = (time_t)wait32.filltime.tv_sec;
1449 wait.filltime.tv_usec = (suseconds_t)wait32.filltime.tv_usec;
1453 if (cmd == VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER)
1454 ret = video1394_ioctl(file,
1455 VIDEO1394_IOC_LISTEN_QUEUE_BUFFER,
1456 (unsigned long) &wait);
1458 ret = video1394_ioctl(file,
1459 VIDEO1394_IOC_TALK_WAIT_BUFFER,
1460 (unsigned long) &wait);
1466 static int video1394_queue_buf32(struct file *file, unsigned int cmd, unsigned long arg)
1468 return -EFAULT; /* ??? was there before. */
1470 return video1394_ioctl(file,
1471 VIDEO1394_IOC_TALK_QUEUE_BUFFER, arg);
1474 static long video1394_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg)
1477 case VIDEO1394_IOC_LISTEN_CHANNEL:
1478 case VIDEO1394_IOC_UNLISTEN_CHANNEL:
1479 case VIDEO1394_IOC_TALK_CHANNEL:
1480 case VIDEO1394_IOC_UNTALK_CHANNEL:
1481 return video1394_ioctl(f, cmd, arg);
1483 case VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER:
1484 return video1394_w_wait32(f, cmd, arg);
1485 case VIDEO1394_IOC32_LISTEN_WAIT_BUFFER:
1486 return video1394_wr_wait32(f, cmd, arg);
1487 case VIDEO1394_IOC_TALK_QUEUE_BUFFER:
1488 return video1394_queue_buf32(f, cmd, arg);
1489 case VIDEO1394_IOC32_TALK_WAIT_BUFFER:
1490 return video1394_w_wait32(f, cmd, arg);
1491 case VIDEO1394_IOC32_LISTEN_POLL_BUFFER:
1492 return video1394_wr_wait32(f, cmd, arg);
1494 return -ENOIOCTLCMD;
1498 #endif /* CONFIG_COMPAT */
1500 static void __exit video1394_exit_module (void)
1502 hpsb_unregister_protocol(&video1394_driver);
1504 hpsb_unregister_highlevel(&video1394_highlevel);
1506 devfs_remove(VIDEO1394_DRIVER_NAME);
1507 cdev_del(&video1394_cdev);
1509 PRINT_G(KERN_INFO, "Removed " VIDEO1394_DRIVER_NAME " module");
1512 static int __init video1394_init_module (void)
1516 cdev_init(&video1394_cdev, &video1394_fops);
1517 video1394_cdev.owner = THIS_MODULE;
1518 kobject_set_name(&video1394_cdev.kobj, VIDEO1394_DRIVER_NAME);
1519 ret = cdev_add(&video1394_cdev, IEEE1394_VIDEO1394_DEV, 16);
1521 PRINT_G(KERN_ERR, "video1394: unable to get minor device block");
1525 devfs_mk_dir(VIDEO1394_DRIVER_NAME);
1527 hpsb_register_highlevel(&video1394_highlevel);
1529 ret = hpsb_register_protocol(&video1394_driver);
1531 PRINT_G(KERN_ERR, "video1394: failed to register protocol");
1532 hpsb_unregister_highlevel(&video1394_highlevel);
1533 devfs_remove(VIDEO1394_DRIVER_NAME);
1534 cdev_del(&video1394_cdev);
1538 PRINT_G(KERN_INFO, "Installed " VIDEO1394_DRIVER_NAME " module");
1543 module_init(video1394_init_module);
1544 module_exit(video1394_exit_module);