aboutsummaryrefslogtreecommitdiffstats
path: root/sound/firewire/packets-buffer.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-18 13:46:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-18 13:46:37 -0400
commitd3e458d78167102cc961237cfceef6fffc80c0b3 (patch)
treee9195c1294daf053614e63ac52b0b44a28479017 /sound/firewire/packets-buffer.c
parentf2e1fbb5f2177227f71c4fc0491e531dd7acd385 (diff)
parentd351cf4603edb2a5bfa9a48d06c425511c63f2a3 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: (308 commits) ALSA: sound/pci/asihpi: check adapter index in hpi_ioctl ALSA: aloop - Fix possible IRQ lock inversion ALSA: sound/core: merge list_del()/list_add_tail() to list_move_tail() ALSA: ctxfi - use list_move() instead of list_del()/list_add() combination ALSA: firewire - msleep needs delay.h ALSA: firewire-lib, firewire-speakers: handle packet queueing errors ALSA: firewire-lib: allocate DMA buffer separately ALSA: firewire-lib: use no-info SYT for packets without SYT sample ALSA: add LaCie FireWire Speakers/Griffin FireWave Surround driver ALSA: hda - Remove an unused variable in patch_realtek.c ALSA: hda - pin-adc-mux-dmic auto-configuration of 92HD8X codecs ALSA: hda - fix digital mic selection in mixer on 92HD8X codecs ALSA: hda - Move default input-src selection to init part ALSA: hda - Initialize special cases for input src in init phase ALSA: ctxfi - Clear input settings before initialization ALSA: ctxfi - Fix SPDIF status retrieval ALSA: ctxfi - Fix incorrect SPDIF status bit mask ALSA: ctxfi - Fix microphone boost codes/comments ALSA: atiixp - Fix wrong time-out checks during ac-link reset ALSA: intel8x0m: append 'm' to "r_intel8x0" ...
Diffstat (limited to 'sound/firewire/packets-buffer.c')
-rw-r--r--sound/firewire/packets-buffer.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/sound/firewire/packets-buffer.c b/sound/firewire/packets-buffer.c
new file mode 100644
index 000000000000..1e20e60ba6a6
--- /dev/null
+++ b/sound/firewire/packets-buffer.c
@@ -0,0 +1,74 @@
1/*
2 * helpers for managing a buffer for many packets
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include <linux/firewire.h>
9#include <linux/slab.h>
10#include "packets-buffer.h"
11
12/**
13 * iso_packets_buffer_init - allocates the memory for packets
14 * @b: the buffer structure to initialize
15 * @unit: the device at the other end of the stream
16 * @count: the number of packets
17 * @packet_size: the (maximum) size of a packet, in bytes
18 * @direction: %DMA_TO_DEVICE or %DMA_FROM_DEVICE
19 */
20int iso_packets_buffer_init(struct iso_packets_buffer *b, struct fw_unit *unit,
21 unsigned int count, unsigned int packet_size,
22 enum dma_data_direction direction)
23{
24 unsigned int packets_per_page, pages;
25 unsigned int i, page_index, offset_in_page;
26 void *p;
27 int err;
28
29 b->packets = kmalloc(count * sizeof(*b->packets), GFP_KERNEL);
30 if (!b->packets) {
31 err = -ENOMEM;
32 goto error;
33 }
34
35 packet_size = L1_CACHE_ALIGN(packet_size);
36 packets_per_page = PAGE_SIZE / packet_size;
37 if (WARN_ON(!packets_per_page)) {
38 err = -EINVAL;
39 goto error;
40 }
41 pages = DIV_ROUND_UP(count, packets_per_page);
42
43 err = fw_iso_buffer_init(&b->iso_buffer, fw_parent_device(unit)->card,
44 pages, direction);
45 if (err < 0)
46 goto err_packets;
47
48 for (i = 0; i < count; ++i) {
49 page_index = i / packets_per_page;
50 p = page_address(b->iso_buffer.pages[page_index]);
51 offset_in_page = (i % packets_per_page) * packet_size;
52 b->packets[i].buffer = p + offset_in_page;
53 b->packets[i].offset = page_index * PAGE_SIZE + offset_in_page;
54 }
55
56 return 0;
57
58err_packets:
59 kfree(b->packets);
60error:
61 return err;
62}
63
64/**
65 * iso_packets_buffer_destroy - frees packet buffer resources
66 * @b: the buffer structure to free
67 * @unit: the device at the other end of the stream
68 */
69void iso_packets_buffer_destroy(struct iso_packets_buffer *b,
70 struct fw_unit *unit)
71{
72 fw_iso_buffer_destroy(&b->iso_buffer, fw_parent_device(unit)->card);
73 kfree(b->packets);
74}