2 * Isochronous IO functionality
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>
27 #include "fw-transaction.h"
28 #include "fw-topology.h"
29 #include "fw-device.h"
31 int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
32 int page_count, enum dma_data_direction direction)
37 buffer->page_count = page_count;
38 buffer->direction = direction;
40 buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]),
42 if (buffer->pages == NULL)
45 for (i = 0; i < buffer->page_count; i++) {
46 buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
47 if (buffer->pages[i] == NULL)
50 address = dma_map_page(card->device, buffer->pages[i],
51 0, PAGE_SIZE, direction);
52 if (dma_mapping_error(card->device, address)) {
53 __free_page(buffer->pages[i]);
56 set_page_private(buffer->pages[i], address);
62 for (j = 0; j < i; j++) {
63 address = page_private(buffer->pages[j]);
64 dma_unmap_page(card->device, address,
65 PAGE_SIZE, DMA_TO_DEVICE);
66 __free_page(buffer->pages[j]);
74 int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
79 uaddr = vma->vm_start;
80 for (i = 0; i < buffer->page_count; i++) {
81 ret = vm_insert_page(vma, uaddr, buffer->pages[i]);
90 void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
96 for (i = 0; i < buffer->page_count; i++) {
97 address = page_private(buffer->pages[i]);
98 dma_unmap_page(card->device, address,
99 PAGE_SIZE, DMA_TO_DEVICE);
100 __free_page(buffer->pages[i]);
103 kfree(buffer->pages);
104 buffer->pages = NULL;
107 struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
108 int type, int channel, int speed, size_t header_size,
109 fw_iso_callback_t callback, void *callback_data)
111 struct fw_iso_context *ctx;
113 ctx = card->driver->allocate_iso_context(card, type, header_size);
119 ctx->channel = channel;
121 ctx->header_size = header_size;
122 ctx->callback = callback;
123 ctx->callback_data = callback_data;
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);
135 int fw_iso_context_start(struct fw_iso_context *ctx,
136 int cycle, int sync, int tags)
138 return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
141 int fw_iso_context_queue(struct fw_iso_context *ctx,
142 struct fw_iso_packet *packet,
143 struct fw_iso_buffer *buffer,
144 unsigned long payload)
146 struct fw_card *card = ctx->card;
148 return card->driver->queue_iso(ctx, packet, buffer, payload);
151 int fw_iso_context_stop(struct fw_iso_context *ctx)
153 return ctx->card->driver->stop_iso(ctx);