diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2012-04-13 07:07:23 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2012-07-01 09:15:21 -0400 |
commit | 50437bff7f7374f86837986f66e15e73a364f894 (patch) | |
tree | 60f2ed3601d374dcc1bf074265e5ab891a3dee55 /drivers/dma/virt-dma.c | |
parent | 6887a4131da3adaab011613776d865f4bcfb5678 (diff) |
dmaengine: split out virtual channel DMA support from sa11x0 driver
Split the virtual slave channel DMA support from the sa11x0 driver so
this code can be shared with other slave DMA engine drivers.
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/dma/virt-dma.c')
-rw-r--r-- | drivers/dma/virt-dma.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/drivers/dma/virt-dma.c b/drivers/dma/virt-dma.c new file mode 100644 index 000000000000..bd85b052b481 --- /dev/null +++ b/drivers/dma/virt-dma.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * Virtual DMA channel support for DMAengine | ||
3 | * | ||
4 | * Copyright (C) 2012 Russell King | ||
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 version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/device.h> | ||
11 | #include <linux/dmaengine.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/spinlock.h> | ||
14 | |||
15 | #include "virt-dma.h" | ||
16 | |||
17 | static struct virt_dma_desc *to_virt_desc(struct dma_async_tx_descriptor *tx) | ||
18 | { | ||
19 | return container_of(tx, struct virt_dma_desc, tx); | ||
20 | } | ||
21 | |||
22 | dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *tx) | ||
23 | { | ||
24 | struct virt_dma_chan *vc = to_virt_chan(tx->chan); | ||
25 | struct virt_dma_desc *vd = to_virt_desc(tx); | ||
26 | unsigned long flags; | ||
27 | dma_cookie_t cookie; | ||
28 | |||
29 | spin_lock_irqsave(&vc->lock, flags); | ||
30 | cookie = dma_cookie_assign(tx); | ||
31 | |||
32 | list_add_tail(&vd->node, &vc->desc_submitted); | ||
33 | spin_unlock_irqrestore(&vc->lock, flags); | ||
34 | |||
35 | dev_dbg(vc->chan.device->dev, "vchan %p: txd %p[%x]: submitted\n", | ||
36 | vc, vd, cookie); | ||
37 | |||
38 | return cookie; | ||
39 | } | ||
40 | EXPORT_SYMBOL_GPL(vchan_tx_submit); | ||
41 | |||
42 | /* | ||
43 | * This tasklet handles the completion of a DMA descriptor by | ||
44 | * calling its callback and freeing it. | ||
45 | */ | ||
46 | static void vchan_complete(unsigned long arg) | ||
47 | { | ||
48 | struct virt_dma_chan *vc = (struct virt_dma_chan *)arg; | ||
49 | LIST_HEAD(head); | ||
50 | |||
51 | spin_lock_irq(&vc->lock); | ||
52 | list_splice_tail_init(&vc->desc_completed, &head); | ||
53 | spin_unlock_irq(&vc->lock); | ||
54 | |||
55 | while (!list_empty(&head)) { | ||
56 | struct virt_dma_desc *vd = list_first_entry(&head, | ||
57 | struct virt_dma_desc, node); | ||
58 | dma_async_tx_callback cb = vd->tx.callback; | ||
59 | void *cb_data = vd->tx.callback_param; | ||
60 | |||
61 | list_del(&vd->node); | ||
62 | |||
63 | vc->desc_free(vd); | ||
64 | |||
65 | if (cb) | ||
66 | cb(cb_data); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | void vchan_dma_desc_free_list(struct virt_dma_chan *vc, struct list_head *head) | ||
71 | { | ||
72 | while (!list_empty(head)) { | ||
73 | struct virt_dma_desc *vd = list_first_entry(head, | ||
74 | struct virt_dma_desc, node); | ||
75 | list_del(&vd->node); | ||
76 | dev_dbg(vc->chan.device->dev, "txd %p: freeing\n", vd); | ||
77 | vc->desc_free(vd); | ||
78 | } | ||
79 | } | ||
80 | EXPORT_SYMBOL_GPL(vchan_dma_desc_free_list); | ||
81 | |||
82 | void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev) | ||
83 | { | ||
84 | dma_cookie_init(&vc->chan); | ||
85 | |||
86 | spin_lock_init(&vc->lock); | ||
87 | INIT_LIST_HEAD(&vc->desc_submitted); | ||
88 | INIT_LIST_HEAD(&vc->desc_issued); | ||
89 | INIT_LIST_HEAD(&vc->desc_completed); | ||
90 | |||
91 | tasklet_init(&vc->task, vchan_complete, (unsigned long)vc); | ||
92 | |||
93 | vc->chan.device = dmadev; | ||
94 | list_add_tail(&vc->chan.device_node, &dmadev->channels); | ||
95 | } | ||
96 | EXPORT_SYMBOL_GPL(vchan_init); | ||
97 | |||
98 | MODULE_AUTHOR("Russell King"); | ||
99 | MODULE_LICENSE("GPL"); | ||