eventdev: make driver interface as internal
[dpdk.git] / lib / eventdev / 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 #include <string.h>
17
18 #include <rte_config.h>
19 #include <rte_debug.h>
20 #include <rte_eal.h>
21 #include <rte_bus_vdev.h>
22
23 #include "eventdev_pmd.h"
24
25 /**
26  * @internal
27  * Creates a new virtual event device and returns the pointer to that device.
28  *
29  * @param name
30  *   PMD type name
31  * @param dev_private_size
32  *   Size of event PMDs private data
33  * @param socket_id
34  *   Socket to allocate resources on.
35  *
36  * @return
37  *   - Eventdev pointer if device is successfully created.
38  *   - NULL if device cannot be created.
39  */
40 __rte_internal
41 static inline struct rte_eventdev *
42 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
43                 int socket_id)
44 {
45
46         struct rte_eventdev *eventdev;
47
48         /* Allocate device structure */
49         eventdev = rte_event_pmd_allocate(name, socket_id);
50         if (eventdev == NULL)
51                 return NULL;
52
53         /* Allocate private device structure */
54         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
55                 eventdev->data->dev_private =
56                                 rte_zmalloc_socket("eventdev device private",
57                                                 dev_private_size,
58                                                 RTE_CACHE_LINE_SIZE,
59                                                 socket_id);
60
61                 if (eventdev->data->dev_private == NULL)
62                         rte_panic("Cannot allocate memzone for private device"
63                                         " data");
64         }
65
66         return eventdev;
67 }
68
69 /**
70  * @internal
71  * Destroy the given virtual event device
72  *
73  * @param name
74  *   PMD type name
75  * @return
76  *   - 0 on success, negative on error
77  */
78 __rte_internal
79 static inline int
80 rte_event_pmd_vdev_uninit(const char *name)
81 {
82         int ret;
83         struct rte_eventdev *eventdev;
84
85         if (name == NULL)
86                 return -EINVAL;
87
88         eventdev = rte_event_pmd_get_named_dev(name);
89         if (eventdev == NULL)
90                 return -ENODEV;
91
92         ret = rte_event_dev_close(eventdev->data->dev_id);
93         if (ret < 0)
94                 return ret;
95
96         /* Free the event device */
97         rte_event_pmd_release(eventdev);
98
99         return 0;
100 }
101
102 #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */