e1e1cd966c58de93843d7a09fe79960900c0a38c
[dpdk.git] / lib / librte_eventdev / rte_eventdev_pmd_vdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Cavium, Inc
3  */
4
5 #ifndef _RTE_EVENTDEV_PMD_VDEV_H_
6 #define _RTE_EVENTDEV_PMD_VDEV_H_
7
8 /** @file
9  * RTE Eventdev VDEV PMD APIs
10  *
11  * @note
12  * These API are from event VDEV PMD only and user applications should not call
13  * them directly.
14  */
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <string.h>
21
22 #include <rte_debug.h>
23 #include <rte_eal.h>
24 #include <rte_bus_vdev.h>
25
26 #include "rte_eventdev_pmd.h"
27
28 /**
29  * @internal
30  * Creates a new virtual event device and returns the pointer to that device.
31  *
32  * @param name
33  *   PMD type name
34  * @param dev_private_size
35  *   Size of event PMDs private data
36  * @param socket_id
37  *   Socket to allocate resources on.
38  *
39  * @return
40  *   - Eventdev pointer if device is successfully created.
41  *   - NULL if device cannot be created.
42  */
43 static inline struct rte_eventdev *
44 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
45                 int socket_id)
46 {
47
48         struct rte_eventdev *eventdev;
49
50         /* Allocate device structure */
51         eventdev = rte_event_pmd_allocate(name, socket_id);
52         if (eventdev == NULL)
53                 return NULL;
54
55         /* Allocate private device structure */
56         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
57                 eventdev->data->dev_private =
58                                 rte_zmalloc_socket("eventdev device private",
59                                                 dev_private_size,
60                                                 RTE_CACHE_LINE_SIZE,
61                                                 socket_id);
62
63                 if (eventdev->data->dev_private == NULL)
64                         rte_panic("Cannot allocate memzone for private device"
65                                         " data");
66         }
67
68         return eventdev;
69 }
70
71 /**
72  * @internal
73  * Destroy the given virtual event device
74  *
75  * @param name
76  *   PMD type name
77  * @return
78  *   - 0 on success, negative on error
79  */
80 static inline int
81 rte_event_pmd_vdev_uninit(const char *name)
82 {
83         int ret;
84         struct rte_eventdev *eventdev;
85
86         if (name == NULL)
87                 return -EINVAL;
88
89         eventdev = rte_event_pmd_get_named_dev(name);
90         if (eventdev == NULL)
91                 return -ENODEV;
92
93         ret = rte_event_dev_close(eventdev->data->dev_id);
94         if (ret < 0)
95                 return ret;
96
97         /* Free the event device */
98         rte_event_pmd_release(eventdev);
99
100         return 0;
101 }
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */