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>
27 #include "fw-transaction.h"
28 #include "fw-topology.h"
31 setup_iso_buffer(struct fw_iso_context *ctx, size_t size,
32 enum dma_data_direction direction)
38 ctx->buffer_size = PAGE_ALIGN(size);
42 ctx->buffer = vmalloc_32_user(ctx->buffer_size);
43 if (ctx->buffer == NULL)
46 ctx->page_count = ctx->buffer_size >> PAGE_SHIFT;
48 kzalloc(ctx->page_count * sizeof(ctx->pages[0]), GFP_KERNEL);
49 if (ctx->pages == NULL) {
55 for (i = 0; i < ctx->page_count; i++, p += PAGE_SIZE) {
56 page = vmalloc_to_page(p);
57 ctx->pages[i] = dma_map_page(ctx->card->device,
58 page, 0, PAGE_SIZE, direction);
64 static void destroy_iso_buffer(struct fw_iso_context *ctx)
68 for (i = 0; i < ctx->page_count; i++)
69 dma_unmap_page(ctx->card->device, ctx->pages[i],
70 PAGE_SIZE, DMA_TO_DEVICE);
76 struct fw_iso_context *fw_iso_context_create(struct fw_card *card, int type,
78 fw_iso_callback_t callback,
81 struct fw_iso_context *ctx;
84 ctx = card->driver->allocate_iso_context(card, type);
90 ctx->callback = callback;
91 ctx->callback_data = callback_data;
93 retval = setup_iso_buffer(ctx, buffer_size, DMA_TO_DEVICE);
95 card->driver->free_iso_context(ctx);
96 return ERR_PTR(retval);
102 EXPORT_SYMBOL(fw_iso_context_create);
104 void fw_iso_context_destroy(struct fw_iso_context *ctx)
106 struct fw_card *card = ctx->card;
108 destroy_iso_buffer(ctx);
110 card->driver->free_iso_context(ctx);
113 EXPORT_SYMBOL(fw_iso_context_destroy);
116 fw_iso_context_send(struct fw_iso_context *ctx,
117 int channel, int speed, int cycle)
119 ctx->channel = channel;
122 return ctx->card->driver->send_iso(ctx, cycle);
125 EXPORT_SYMBOL(fw_iso_context_send);
128 fw_iso_context_queue(struct fw_iso_context *ctx,
129 struct fw_iso_packet *packet, void *payload)
131 struct fw_card *card = ctx->card;
133 return card->driver->queue_iso(ctx, packet, payload);
136 EXPORT_SYMBOL(fw_iso_context_queue);