dmadev: introduce DMA device library
[dpdk.git] / lib / dmadev / rte_dmadev_pmd.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2021 HiSilicon Limited
3  */
4
5 #ifndef RTE_DMADEV_PMD_H
6 #define RTE_DMADEV_PMD_H
7
8 /**
9  * @file
10  *
11  * DMA Device PMD interface
12  *
13  * Driver facing interface for a DMA device. These are not to be called directly
14  * by any application.
15  */
16
17 #include "rte_dmadev.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /**
24  * Possible states of a DMA device.
25  *
26  * @see struct rte_dma_dev::state
27  */
28 enum rte_dma_dev_state {
29         RTE_DMA_DEV_UNUSED = 0, /**< Device is unused. */
30         /** Device is registered, but not ready to be used. */
31         RTE_DMA_DEV_REGISTERED,
32         /** Device is ready for use. This is set by the PMD. */
33         RTE_DMA_DEV_READY,
34 };
35
36 /**
37  * @internal
38  * The generic data structure associated with each DMA device.
39  */
40 struct rte_dma_dev {
41         char dev_name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */
42         int16_t dev_id; /**< Device [external] identifier. */
43         int16_t numa_node; /**< Local NUMA memory ID. -1 if unknown. */
44         void *dev_private; /**< PMD-specific private data. */
45         /** Device info which supplied during device initialization. */
46         struct rte_device *device;
47         enum rte_dma_dev_state state; /**< Flag indicating the device state. */
48         uint64_t reserved[2]; /**< Reserved for future fields. */
49 } __rte_cache_aligned;
50
51 extern struct rte_dma_dev *rte_dma_devices;
52
53 /**
54  * @internal
55  * Allocate a new dmadev slot for an DMA device and return the pointer to that
56  * slot for the driver to use.
57  *
58  * @param name
59  *   DMA device name.
60  * @param numa_node
61  *   Driver's private data's NUMA node.
62  * @param private_data_size
63  *   Driver's private data size.
64  *
65  * @return
66  *   A pointer to the DMA device slot case of success,
67  *   NULL otherwise.
68  */
69 __rte_internal
70 struct rte_dma_dev *rte_dma_pmd_allocate(const char *name, int numa_node,
71                                          size_t private_data_size);
72
73 /**
74  * @internal
75  * Release the specified dmadev.
76  *
77  * @param name
78  *   DMA device name.
79  *
80  * @return
81  *   - 0 on success, negative on error.
82  */
83 __rte_internal
84 int rte_dma_pmd_release(const char *name);
85
86 #ifdef __cplusplus
87 }
88 #endif
89
90 #endif /* RTE_DMADEV_PMD_H */