]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/dma/dmaengine.h
dmaengine: consolidate tx_status functions
[mirror_ubuntu-bionic-kernel.git] / drivers / dma / dmaengine.h
CommitLineData
d2ebfb33
RKAL
1/*
2 * The contents of this file are private to DMA engine drivers, and is not
3 * part of the API to be used by DMA engine users.
4 */
5#ifndef DMAENGINE_H
6#define DMAENGINE_H
7
f7fbce07 8#include <linux/bug.h>
d2ebfb33
RKAL
9#include <linux/dmaengine.h>
10
884485e1
RKAL
11/**
12 * dma_cookie_assign - assign a DMA engine cookie to the descriptor
13 * @tx: descriptor needing cookie
14 *
15 * Assign a unique non-zero per-channel cookie to the descriptor.
16 * Note: caller is expected to hold a lock to prevent concurrency.
17 */
18static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
19{
20 struct dma_chan *chan = tx->chan;
21 dma_cookie_t cookie;
22
23 cookie = chan->cookie + 1;
24 if (cookie < DMA_MIN_COOKIE)
25 cookie = DMA_MIN_COOKIE;
26 tx->cookie = chan->cookie = cookie;
27
28 return cookie;
29}
30
f7fbce07
RKAL
31/**
32 * dma_cookie_complete - complete a descriptor
33 * @tx: descriptor to complete
34 *
35 * Mark this descriptor complete by updating the channels completed
36 * cookie marker. Zero the descriptors cookie to prevent accidental
37 * repeated completions.
38 *
39 * Note: caller is expected to hold a lock to prevent concurrency.
40 */
41static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
42{
43 BUG_ON(tx->cookie < DMA_MIN_COOKIE);
44 tx->chan->completed_cookie = tx->cookie;
45 tx->cookie = 0;
46}
47
96a2af41
RKAL
48/**
49 * dma_cookie_status - report cookie status
50 * @chan: dma channel
51 * @cookie: cookie we are interested in
52 * @state: dma_tx_state structure to return last/used cookies
53 *
54 * Report the status of the cookie, filling in the state structure if
55 * non-NULL. No locking is required.
56 */
57static inline enum dma_status dma_cookie_status(struct dma_chan *chan,
58 dma_cookie_t cookie, struct dma_tx_state *state)
59{
60 dma_cookie_t used, complete;
61
62 used = chan->cookie;
63 complete = chan->completed_cookie;
64 barrier();
65 if (state) {
66 state->last = complete;
67 state->used = used;
68 state->residue = 0;
69 }
70 return dma_async_is_complete(cookie, complete, used);
71}
72
73static inline void dma_set_residue(struct dma_tx_state *state, u32 residue)
74{
75 if (state)
76 state->residue = residue;
77}
78
d2ebfb33 79#endif