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