X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Ffirewire%2Ffw-iso.c;h=bcbe794a3ea5ca3198df3c1593ef696edf0f716c;hb=d7b6de14a0ef8a376f9d57b867545b47302b7bfb;hp=6b638568c2c992ef2ac4f9508a99f3602cfb4362;hpb=19a15b937b26638933307bb02f7b1801310d6eb2;p=linux-2.6 diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/fw-iso.c index 6b638568c2..bcbe794a3e 100644 --- a/drivers/firewire/fw-iso.c +++ b/drivers/firewire/fw-iso.c @@ -1,6 +1,6 @@ -/* -*- c-basic-offset: 8 -*- +/* + * Isochronous IO functionality * - * fw-iso.c - Isochronous IO * Copyright (C) 2006 Kristian Hoegsberg * * This program is free software; you can redistribute it and/or modify @@ -28,110 +28,131 @@ #include "fw-topology.h" #include "fw-device.h" -static int -setup_iso_buffer(struct fw_iso_context *ctx, size_t size, - enum dma_data_direction direction) +int +fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, + int page_count, enum dma_data_direction direction) { - struct page *page; - int i; - void *p; - - ctx->buffer_size = PAGE_ALIGN(size); - if (size == 0) - return 0; - - ctx->buffer = vmalloc_32_user(ctx->buffer_size); - if (ctx->buffer == NULL) - return -ENOMEM; - - ctx->page_count = ctx->buffer_size >> PAGE_SHIFT; - ctx->pages = - kzalloc(ctx->page_count * sizeof(ctx->pages[0]), GFP_KERNEL); - if (ctx->pages == NULL) { - vfree(ctx->buffer); - return -ENOMEM; + int i, j, retval = -ENOMEM; + dma_addr_t address; + + buffer->page_count = page_count; + buffer->direction = direction; + + buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]), + GFP_KERNEL); + if (buffer->pages == NULL) + goto out; + + for (i = 0; i < buffer->page_count; i++) { + buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO); + if (buffer->pages[i] == NULL) + goto out_pages; + + address = dma_map_page(card->device, buffer->pages[i], + 0, PAGE_SIZE, direction); + if (dma_mapping_error(address)) { + __free_page(buffer->pages[i]); + goto out_pages; + } + set_page_private(buffer->pages[i], address); + } + + return 0; + + out_pages: + for (j = 0; j < i; j++) { + address = page_private(buffer->pages[j]); + dma_unmap_page(card->device, address, + PAGE_SIZE, DMA_TO_DEVICE); + __free_page(buffer->pages[j]); } + kfree(buffer->pages); + out: + buffer->pages = NULL; + return retval; +} - p = ctx->buffer; - for (i = 0; i < ctx->page_count; i++, p += PAGE_SIZE) { - page = vmalloc_to_page(p); - ctx->pages[i] = dma_map_page(ctx->card->device, - page, 0, PAGE_SIZE, direction); +int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma) +{ + unsigned long uaddr; + int i, retval; + + uaddr = vma->vm_start; + for (i = 0; i < buffer->page_count; i++) { + retval = vm_insert_page(vma, uaddr, buffer->pages[i]); + if (retval) + return retval; + uaddr += PAGE_SIZE; } return 0; } -static void destroy_iso_buffer(struct fw_iso_context *ctx) +void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, + struct fw_card *card) { int i; + dma_addr_t address; - for (i = 0; i < ctx->page_count; i++) - dma_unmap_page(ctx->card->device, ctx->pages[i], + for (i = 0; i < buffer->page_count; i++) { + address = page_private(buffer->pages[i]); + dma_unmap_page(card->device, address, PAGE_SIZE, DMA_TO_DEVICE); + __free_page(buffer->pages[i]); + } - kfree(ctx->pages); - vfree(ctx->buffer); + kfree(buffer->pages); + buffer->pages = NULL; } -struct fw_iso_context *fw_iso_context_create(struct fw_card *card, int type, - size_t buffer_size, - fw_iso_callback_t callback, - void *callback_data) +struct fw_iso_context * +fw_iso_context_create(struct fw_card *card, int type, + int channel, int speed, size_t header_size, + fw_iso_callback_t callback, void *callback_data) { struct fw_iso_context *ctx; - int retval; - ctx = card->driver->allocate_iso_context(card, type); + ctx = card->driver->allocate_iso_context(card, type, header_size); if (IS_ERR(ctx)) return ctx; ctx->card = card; ctx->type = type; + ctx->channel = channel; + ctx->speed = speed; + ctx->header_size = header_size; ctx->callback = callback; ctx->callback_data = callback_data; - retval = setup_iso_buffer(ctx, buffer_size, DMA_TO_DEVICE); - if (retval < 0) { - card->driver->free_iso_context(ctx); - return ERR_PTR(retval); - } - return ctx; } -EXPORT_SYMBOL(fw_iso_context_create); - void fw_iso_context_destroy(struct fw_iso_context *ctx) { struct fw_card *card = ctx->card; - destroy_iso_buffer(ctx); - card->driver->free_iso_context(ctx); } -EXPORT_SYMBOL(fw_iso_context_destroy); - int -fw_iso_context_send(struct fw_iso_context *ctx, - int channel, int speed, int cycle) +fw_iso_context_start(struct fw_iso_context *ctx, int cycle, int sync, int tags) { - ctx->channel = channel; - ctx->speed = speed; - - return ctx->card->driver->send_iso(ctx, cycle); + return ctx->card->driver->start_iso(ctx, cycle, sync, tags); } -EXPORT_SYMBOL(fw_iso_context_send); - int fw_iso_context_queue(struct fw_iso_context *ctx, - struct fw_iso_packet *packet, void *payload) + struct fw_iso_packet *packet, + struct fw_iso_buffer *buffer, + unsigned long payload) { struct fw_card *card = ctx->card; - return card->driver->queue_iso(ctx, packet, payload); + return card->driver->queue_iso(ctx, packet, buffer, payload); } -EXPORT_SYMBOL(fw_iso_context_queue); +int +fw_iso_context_stop(struct fw_iso_context *ctx) +{ + return ctx->card->driver->stop_iso(ctx); +}