diff options
author | Kristian Høgsberg <krh@redhat.com> | 2006-12-19 19:58:27 -0500 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2007-03-09 16:02:33 -0500 |
commit | 3038e353cfaf548eb94f02b172b9dbe412abd24c (patch) | |
tree | 70e50c20e117e2dacb7cd810d00fe595e60d26ce /drivers/firewire/fw-iso.c | |
parent | 08e15e81a40e3241ce93b4a43886f3abda184aa6 (diff) |
firewire: Add core firewire stack.
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/firewire/fw-iso.c')
-rw-r--r-- | drivers/firewire/fw-iso.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/fw-iso.c new file mode 100644 index 000000000000..61548c4d18ec --- /dev/null +++ b/drivers/firewire/fw-iso.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* -*- c-basic-offset: 8 -*- | ||
2 | * | ||
3 | * fw-iso.c - Isochronous IO | ||
4 | * Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net> | ||
5 | * | ||
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. | ||
10 | * | ||
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. | ||
15 | * | ||
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. | ||
19 | */ | ||
20 | |||
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> | ||
26 | |||
27 | #include "fw-transaction.h" | ||
28 | #include "fw-topology.h" | ||
29 | |||
30 | static int | ||
31 | setup_iso_buffer(struct fw_iso_context *ctx, size_t size, | ||
32 | enum dma_data_direction direction) | ||
33 | { | ||
34 | struct page *page; | ||
35 | int i; | ||
36 | void *p; | ||
37 | |||
38 | ctx->buffer_size = PAGE_ALIGN(size); | ||
39 | if (size == 0) | ||
40 | return 0; | ||
41 | |||
42 | ctx->buffer = vmalloc_32_user(ctx->buffer_size); | ||
43 | if (ctx->buffer == NULL) | ||
44 | return -ENOMEM; | ||
45 | |||
46 | ctx->page_count = ctx->buffer_size >> PAGE_SHIFT; | ||
47 | ctx->pages = | ||
48 | kzalloc(ctx->page_count * sizeof(ctx->pages[0]), GFP_KERNEL); | ||
49 | if (ctx->pages == NULL) { | ||
50 | vfree(ctx->buffer); | ||
51 | return -ENOMEM; | ||
52 | } | ||
53 | |||
54 | p = ctx->buffer; | ||
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); | ||
59 | } | ||
60 | |||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static void destroy_iso_buffer(struct fw_iso_context *ctx) | ||
65 | { | ||
66 | int i; | ||
67 | |||
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); | ||
71 | |||
72 | kfree(ctx->pages); | ||
73 | vfree(ctx->buffer); | ||
74 | } | ||
75 | |||
76 | struct fw_iso_context *fw_iso_context_create(struct fw_card *card, int type, | ||
77 | size_t buffer_size, | ||
78 | fw_iso_callback_t callback, | ||
79 | void *callback_data) | ||
80 | { | ||
81 | struct fw_iso_context *ctx; | ||
82 | int retval; | ||
83 | |||
84 | ctx = card->driver->allocate_iso_context(card, type); | ||
85 | if (IS_ERR(ctx)) | ||
86 | return ctx; | ||
87 | |||
88 | ctx->card = card; | ||
89 | ctx->type = type; | ||
90 | ctx->callback = callback; | ||
91 | ctx->callback_data = callback_data; | ||
92 | |||
93 | retval = setup_iso_buffer(ctx, buffer_size, DMA_TO_DEVICE); | ||
94 | if (retval < 0) { | ||
95 | card->driver->free_iso_context(ctx); | ||
96 | return ERR_PTR(retval); | ||
97 | } | ||
98 | |||
99 | return ctx; | ||
100 | } | ||
101 | |||
102 | EXPORT_SYMBOL(fw_iso_context_create); | ||
103 | |||
104 | void fw_iso_context_destroy(struct fw_iso_context *ctx) | ||
105 | { | ||
106 | struct fw_card *card = ctx->card; | ||
107 | |||
108 | destroy_iso_buffer(ctx); | ||
109 | |||
110 | card->driver->free_iso_context(ctx); | ||
111 | } | ||
112 | |||
113 | EXPORT_SYMBOL(fw_iso_context_destroy); | ||
114 | |||
115 | int | ||
116 | fw_iso_context_send(struct fw_iso_context *ctx, | ||
117 | int channel, int speed, int cycle) | ||
118 | { | ||
119 | ctx->channel = channel; | ||
120 | ctx->speed = speed; | ||
121 | |||
122 | return ctx->card->driver->send_iso(ctx, cycle); | ||
123 | } | ||
124 | |||
125 | EXPORT_SYMBOL(fw_iso_context_send); | ||
126 | |||
127 | int | ||
128 | fw_iso_context_queue(struct fw_iso_context *ctx, | ||
129 | struct fw_iso_packet *packet, void *payload) | ||
130 | { | ||
131 | struct fw_card *card = ctx->card; | ||
132 | |||
133 | return card->driver->queue_iso(ctx, packet, payload); | ||
134 | } | ||
135 | |||
136 | EXPORT_SYMBOL(fw_iso_context_queue); | ||