firewire: Implement basic isochronous receive functionality.
[linux-2.6/mini2440.git] / drivers / firewire / fw-iso.c
blob4c6dc99a1ff84880d0038cc940a7f2a968de0d8d
1 /* -*- c-basic-offset: 8 -*-
3 * fw-iso.c - Isochronous IO
4 * Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net>
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.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/vmalloc.h>
25 #include <linux/mm.h>
27 #include "fw-transaction.h"
28 #include "fw-topology.h"
29 #include "fw-device.h"
31 int
32 fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
33 int page_count, enum dma_data_direction direction)
35 int i, j, retval = -ENOMEM;
36 dma_addr_t address;
38 buffer->page_count = page_count;
39 buffer->direction = direction;
41 buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]),
42 GFP_KERNEL);
43 if (buffer->pages == NULL)
44 goto out;
46 for (i = 0; i < buffer->page_count; i++) {
47 buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32);
48 if (buffer->pages[i] == NULL)
49 goto out_pages;
51 address = dma_map_page(card->device, buffer->pages[i],
52 0, PAGE_SIZE, direction);
53 if (dma_mapping_error(address)) {
54 __free_page(buffer->pages[i]);
55 goto out_pages;
57 set_page_private(buffer->pages[i], address);
60 return 0;
62 out_pages:
63 for (j = 0; j < i; j++) {
64 address = page_private(buffer->pages[j]);
65 dma_unmap_page(card->device, address,
66 PAGE_SIZE, DMA_TO_DEVICE);
67 __free_page(buffer->pages[j]);
69 kfree(buffer->pages);
70 out:
71 buffer->pages = NULL;
72 return retval;
75 int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
77 unsigned long uaddr;
78 int i, retval;
80 uaddr = vma->vm_start;
81 for (i = 0; i < buffer->page_count; i++) {
82 retval = vm_insert_page(vma, uaddr, buffer->pages[i]);
83 if (retval)
84 return retval;
85 uaddr += PAGE_SIZE;
88 return 0;
91 void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
92 struct fw_card *card)
94 int i;
95 dma_addr_t address;
97 for (i = 0; i < buffer->page_count; i++) {
98 address = page_private(buffer->pages[i]);
99 dma_unmap_page(card->device, address,
100 PAGE_SIZE, DMA_TO_DEVICE);
101 __free_page(buffer->pages[i]);
104 kfree(buffer->pages);
105 buffer->pages = NULL;
108 struct fw_iso_context *
109 fw_iso_context_create(struct fw_card *card, int type, size_t header_size,
110 fw_iso_callback_t callback, void *callback_data)
112 struct fw_iso_context *ctx;
114 ctx = card->driver->allocate_iso_context(card, type);
115 if (IS_ERR(ctx))
116 return ctx;
118 ctx->card = card;
119 ctx->type = type;
120 ctx->header_size = header_size;
121 ctx->callback = callback;
122 ctx->callback_data = callback_data;
124 return ctx;
126 EXPORT_SYMBOL(fw_iso_context_create);
128 void fw_iso_context_destroy(struct fw_iso_context *ctx)
130 struct fw_card *card = ctx->card;
132 card->driver->free_iso_context(ctx);
134 EXPORT_SYMBOL(fw_iso_context_destroy);
137 fw_iso_context_send(struct fw_iso_context *ctx,
138 int channel, int speed, int cycle)
140 ctx->channel = channel;
141 ctx->speed = speed;
143 return ctx->card->driver->send_iso(ctx, cycle);
145 EXPORT_SYMBOL(fw_iso_context_send);
148 fw_iso_context_queue(struct fw_iso_context *ctx,
149 struct fw_iso_packet *packet,
150 struct fw_iso_buffer *buffer,
151 unsigned long payload)
153 struct fw_card *card = ctx->card;
155 return card->driver->queue_iso(ctx, packet, buffer, payload);
157 EXPORT_SYMBOL(fw_iso_context_queue);