summaryrefslogtreecommitdiffstats
path: root/dma_private.h
blob: 53e951ba81eaef2a8dd6faefbdcbdd46eb588d71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef _PCIDEV_DMA_PRIVATE_H
#define _PCIDEV_DMA_PRIVATE_H

#include <pcilib/dma.h>

#define PCIDEV_DMA_DESCRIPTOR_SIZE	128
#define PCIDEV_DMA_DESCRIPTOR_ALIGNMENT	64

#define PCIDEV_DMA_FLAG_NOSYNC		0x01		/**< Do not call kernel space for page synchronization */
#define PCIDEV_DMA_FLAG_NOSLEEP		0x02		/**< Do not sleep in the loop while waiting for the data */
#define PCIDEV_DMA_NODATA_SLEEP		100		/**< To keep CPU free, in nanoseconds */

typedef uint32_t reg_t;
typedef struct pcidev_dma_s pcidev_dma_t;
typedef struct pcidev_dma_desc_s pcidev_dma_desc_t;

struct pcidev_dma_desc_s {
    uint32_t page_count;
    volatile uintptr_t last_write_addr;
    volatile uintptr_t last_read_addr;
};

struct pcidev_dma_s {
    pcilib_dma_context_t dmactx;

    pcilib_kmem_handle_t *desc;		/**< in-memory status descriptor written by DMA engine upon operation progess */
    pcilib_kmem_handle_t *pages;	/**< collection of memory-locked pages for DMA operation */

    pcilib_dma_engine_t rdma;

    uint32_t version;			/**< hardware revision */

    int started;			/**< indicates that DMA buffers are initialized and reading is allowed */
    int writting;			/**< indicates that we are in middle of writting packet */
    int reused;				/**< indicates that DMA was found intialized, buffers were reused, and no additional initialization is needed */
    int preserve;			/**< indicates that DMA should not be stopped during clean-up */

    uint32_t dma_flags;			/**< Various operation flags, see PCIDEV_DMA_FLAG_* */
    size_t dma_timeout;			/**< DMA timeout, PCIDEV_DMA_TIMEOUT is used by default */
    size_t dma_pages;			/**< Number of DMA pages in ring buffer to allocate */

    size_t ring_size, page_size;	/**< Number of pages in ring buffer and the size of a single DMA page */
    size_t last_read;
};

#endif /* _PCIDEV_DMA_PRIVATE_H */