xref: /dpdk/lib/eventdev/eventdev_pmd_vdev.h (revision 23d06e3766a82b97ff97bdd7021cbddc5e9ccc7e)
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 
1899a2dd95SBruce Richardson #include <rte_config.h>
1999a2dd95SBruce Richardson #include <rte_debug.h>
2099a2dd95SBruce Richardson #include <rte_eal.h>
2199a2dd95SBruce Richardson #include <rte_bus_vdev.h>
2299a2dd95SBruce Richardson 
2399a2dd95SBruce Richardson #include "eventdev_pmd.h"
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson /**
2699a2dd95SBruce Richardson  * @internal
2799a2dd95SBruce Richardson  * Creates a new virtual event device and returns the pointer to that device.
2899a2dd95SBruce Richardson  *
2999a2dd95SBruce Richardson  * @param name
3099a2dd95SBruce Richardson  *   PMD type name
3199a2dd95SBruce Richardson  * @param dev_private_size
3299a2dd95SBruce Richardson  *   Size of event PMDs private data
3399a2dd95SBruce Richardson  * @param socket_id
3499a2dd95SBruce Richardson  *   Socket to allocate resources on.
3599a2dd95SBruce Richardson  *
3699a2dd95SBruce Richardson  * @return
3799a2dd95SBruce Richardson  *   - Eventdev pointer if device is successfully created.
3899a2dd95SBruce Richardson  *   - NULL if device cannot be created.
3999a2dd95SBruce Richardson  */
40*23d06e37SPavan Nikhilesh __rte_internal
4199a2dd95SBruce Richardson static inline struct rte_eventdev *
4299a2dd95SBruce Richardson rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
4399a2dd95SBruce Richardson 		int socket_id)
4499a2dd95SBruce Richardson {
4599a2dd95SBruce Richardson 
4699a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
4799a2dd95SBruce Richardson 
4899a2dd95SBruce Richardson 	/* Allocate device structure */
4999a2dd95SBruce Richardson 	eventdev = rte_event_pmd_allocate(name, socket_id);
5099a2dd95SBruce Richardson 	if (eventdev == NULL)
5199a2dd95SBruce Richardson 		return NULL;
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson 	/* Allocate private device structure */
5499a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
5599a2dd95SBruce Richardson 		eventdev->data->dev_private =
5699a2dd95SBruce Richardson 				rte_zmalloc_socket("eventdev device private",
5799a2dd95SBruce Richardson 						dev_private_size,
5899a2dd95SBruce Richardson 						RTE_CACHE_LINE_SIZE,
5999a2dd95SBruce Richardson 						socket_id);
6099a2dd95SBruce Richardson 
6199a2dd95SBruce Richardson 		if (eventdev->data->dev_private == NULL)
6299a2dd95SBruce Richardson 			rte_panic("Cannot allocate memzone for private device"
6399a2dd95SBruce Richardson 					" data");
6499a2dd95SBruce Richardson 	}
6599a2dd95SBruce Richardson 
6699a2dd95SBruce Richardson 	return eventdev;
6799a2dd95SBruce Richardson }
6899a2dd95SBruce Richardson 
6999a2dd95SBruce Richardson /**
7099a2dd95SBruce Richardson  * @internal
7199a2dd95SBruce Richardson  * Destroy the given virtual event device
7299a2dd95SBruce Richardson  *
7399a2dd95SBruce Richardson  * @param name
7499a2dd95SBruce Richardson  *   PMD type name
7599a2dd95SBruce Richardson  * @return
7699a2dd95SBruce Richardson  *   - 0 on success, negative on error
7799a2dd95SBruce Richardson  */
78*23d06e37SPavan Nikhilesh __rte_internal
7999a2dd95SBruce Richardson static inline int
8099a2dd95SBruce Richardson rte_event_pmd_vdev_uninit(const char *name)
8199a2dd95SBruce Richardson {
8299a2dd95SBruce Richardson 	int ret;
8399a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
8499a2dd95SBruce Richardson 
8599a2dd95SBruce Richardson 	if (name == NULL)
8699a2dd95SBruce Richardson 		return -EINVAL;
8799a2dd95SBruce Richardson 
8899a2dd95SBruce Richardson 	eventdev = rte_event_pmd_get_named_dev(name);
8999a2dd95SBruce Richardson 	if (eventdev == NULL)
9099a2dd95SBruce Richardson 		return -ENODEV;
9199a2dd95SBruce Richardson 
9299a2dd95SBruce Richardson 	ret = rte_event_dev_close(eventdev->data->dev_id);
9399a2dd95SBruce Richardson 	if (ret < 0)
9499a2dd95SBruce Richardson 		return ret;
9599a2dd95SBruce Richardson 
9699a2dd95SBruce Richardson 	/* Free the event device */
9799a2dd95SBruce Richardson 	rte_event_pmd_release(eventdev);
9899a2dd95SBruce Richardson 
9999a2dd95SBruce Richardson 	return 0;
10099a2dd95SBruce Richardson }
10199a2dd95SBruce Richardson 
10299a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */
103