xref: /dpdk/lib/eventdev/eventdev_pmd_vdev.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2016-2017 Cavium, Inc
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_EVENTDEV_PMD_VDEV_H_
699a2dd95SBruce Richardson #define _RTE_EVENTDEV_PMD_VDEV_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /** @file
999a2dd95SBruce Richardson  * RTE Eventdev VDEV PMD APIs
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * @note
1299a2dd95SBruce Richardson  * These API are from event VDEV PMD only and user applications should not call
1399a2dd95SBruce Richardson  * them directly.
1499a2dd95SBruce Richardson  */
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #include <string.h>
1799a2dd95SBruce Richardson 
181094dd94SDavid Marchand #include <rte_compat.h>
1999a2dd95SBruce Richardson #include <rte_config.h>
2099a2dd95SBruce Richardson #include <rte_debug.h>
2199a2dd95SBruce Richardson #include <rte_eal.h>
224851ef2bSDavid Marchand #include <bus_vdev_driver.h>
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson #include "eventdev_pmd.h"
2599a2dd95SBruce Richardson 
26*719834a6SMattias Rönnblom #ifdef __cplusplus
27*719834a6SMattias Rönnblom extern "C" {
28*719834a6SMattias Rönnblom #endif
29*719834a6SMattias Rönnblom 
3099a2dd95SBruce Richardson /**
3199a2dd95SBruce Richardson  * @internal
3299a2dd95SBruce Richardson  * Creates a new virtual event device and returns the pointer to that device.
3399a2dd95SBruce Richardson  *
3499a2dd95SBruce Richardson  * @param name
3599a2dd95SBruce Richardson  *   PMD type name
3699a2dd95SBruce Richardson  * @param dev_private_size
3799a2dd95SBruce Richardson  *   Size of event PMDs private data
3899a2dd95SBruce Richardson  * @param socket_id
3999a2dd95SBruce Richardson  *   Socket to allocate resources on.
4099a2dd95SBruce Richardson  *
4199a2dd95SBruce Richardson  * @return
4299a2dd95SBruce Richardson  *   - Eventdev pointer if device is successfully created.
4399a2dd95SBruce Richardson  *   - NULL if device cannot be created.
4499a2dd95SBruce Richardson  */
4523d06e37SPavan Nikhilesh __rte_internal
4699a2dd95SBruce Richardson static inline struct rte_eventdev *
4799a2dd95SBruce Richardson rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
48928b5c70SBruce Richardson 		int socket_id, struct rte_vdev_device *vdev)
4999a2dd95SBruce Richardson {
5099a2dd95SBruce Richardson 
5199a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson 	/* Allocate device structure */
5499a2dd95SBruce Richardson 	eventdev = rte_event_pmd_allocate(name, socket_id);
5599a2dd95SBruce Richardson 	if (eventdev == NULL)
5699a2dd95SBruce Richardson 		return NULL;
5799a2dd95SBruce Richardson 
5899a2dd95SBruce Richardson 	/* Allocate private device structure */
5999a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
6099a2dd95SBruce Richardson 		eventdev->data->dev_private =
6199a2dd95SBruce Richardson 				rte_zmalloc_socket("eventdev device private",
6299a2dd95SBruce Richardson 						dev_private_size,
6399a2dd95SBruce Richardson 						RTE_CACHE_LINE_SIZE,
6499a2dd95SBruce Richardson 						socket_id);
6599a2dd95SBruce Richardson 
6699a2dd95SBruce Richardson 		if (eventdev->data->dev_private == NULL)
6799a2dd95SBruce Richardson 			rte_panic("Cannot allocate memzone for private device"
6899a2dd95SBruce Richardson 					" data");
6999a2dd95SBruce Richardson 	}
70928b5c70SBruce Richardson 	eventdev->dev = &vdev->device;
7199a2dd95SBruce Richardson 
7299a2dd95SBruce Richardson 	return eventdev;
7399a2dd95SBruce Richardson }
7499a2dd95SBruce Richardson 
7599a2dd95SBruce Richardson /**
7699a2dd95SBruce Richardson  * @internal
7799a2dd95SBruce Richardson  * Destroy the given virtual event device
7899a2dd95SBruce Richardson  *
7999a2dd95SBruce Richardson  * @param name
8099a2dd95SBruce Richardson  *   PMD type name
8199a2dd95SBruce Richardson  * @return
8299a2dd95SBruce Richardson  *   - 0 on success, negative on error
8399a2dd95SBruce Richardson  */
8423d06e37SPavan Nikhilesh __rte_internal
8599a2dd95SBruce Richardson static inline int
8699a2dd95SBruce Richardson rte_event_pmd_vdev_uninit(const char *name)
8799a2dd95SBruce Richardson {
8899a2dd95SBruce Richardson 	int ret;
8999a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
9099a2dd95SBruce Richardson 
9199a2dd95SBruce Richardson 	if (name == NULL)
9299a2dd95SBruce Richardson 		return -EINVAL;
9399a2dd95SBruce Richardson 
9499a2dd95SBruce Richardson 	eventdev = rte_event_pmd_get_named_dev(name);
9599a2dd95SBruce Richardson 	if (eventdev == NULL)
9699a2dd95SBruce Richardson 		return -ENODEV;
9799a2dd95SBruce Richardson 
9899a2dd95SBruce Richardson 	ret = rte_event_dev_close(eventdev->data->dev_id);
9999a2dd95SBruce Richardson 	if (ret < 0)
10099a2dd95SBruce Richardson 		return ret;
10199a2dd95SBruce Richardson 
10299a2dd95SBruce Richardson 	/* Free the event device */
10399a2dd95SBruce Richardson 	rte_event_pmd_release(eventdev);
10499a2dd95SBruce Richardson 
10599a2dd95SBruce Richardson 	return 0;
10699a2dd95SBruce Richardson }
10799a2dd95SBruce Richardson 
1082c552933SBrian Dooley #ifdef __cplusplus
1092c552933SBrian Dooley }
1102c552933SBrian Dooley #endif
1112c552933SBrian Dooley 
11299a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */
113