xref: /dpdk/lib/eventdev/eventdev_pmd_vdev.h (revision 7a335720575507f55b723b1e10bfea7daeba1386)
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 static inline struct rte_eventdev *
41 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
42 		int socket_id)
43 {
44 
45 	struct rte_eventdev *eventdev;
46 
47 	/* Allocate device structure */
48 	eventdev = rte_event_pmd_allocate(name, socket_id);
49 	if (eventdev == NULL)
50 		return NULL;
51 
52 	/* Allocate private device structure */
53 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
54 		eventdev->data->dev_private =
55 				rte_zmalloc_socket("eventdev device private",
56 						dev_private_size,
57 						RTE_CACHE_LINE_SIZE,
58 						socket_id);
59 
60 		if (eventdev->data->dev_private == NULL)
61 			rte_panic("Cannot allocate memzone for private device"
62 					" data");
63 	}
64 
65 	return eventdev;
66 }
67 
68 /**
69  * @internal
70  * Destroy the given virtual event device
71  *
72  * @param name
73  *   PMD type name
74  * @return
75  *   - 0 on success, negative on error
76  */
77 static inline int
78 rte_event_pmd_vdev_uninit(const char *name)
79 {
80 	int ret;
81 	struct rte_eventdev *eventdev;
82 
83 	if (name == NULL)
84 		return -EINVAL;
85 
86 	eventdev = rte_event_pmd_get_named_dev(name);
87 	if (eventdev == NULL)
88 		return -ENODEV;
89 
90 	ret = rte_event_dev_close(eventdev->data->dev_id);
91 	if (ret < 0)
92 		return ret;
93 
94 	/* Free the event device */
95 	rte_event_pmd_release(eventdev);
96 
97 	return 0;
98 }
99 
100 #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */
101