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