9e096e3b64e2d62d2ad7c2ae9cf4c7796cd72fb8
[dpdk.git] / lib / gpudev / gpudev_driver.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2021 NVIDIA Corporation & Affiliates
3  */
4
5 /*
6  * This header file must be included only by drivers.
7  * It is considered internal, i.e. hidden for the application.
8  * The prefix rte_ is used to avoid namespace clash in drivers.
9  */
10
11 #ifndef RTE_GPUDEV_DRIVER_H
12 #define RTE_GPUDEV_DRIVER_H
13
14 #include <stdint.h>
15
16 #include <rte_dev.h>
17
18 #include "rte_gpudev.h"
19
20 /* Flags indicate current state of device. */
21 enum rte_gpu_state {
22         RTE_GPU_STATE_UNUSED,        /* not initialized */
23         RTE_GPU_STATE_INITIALIZED,   /* initialized */
24 };
25
26 struct rte_gpu;
27 typedef int (rte_gpu_close_t)(struct rte_gpu *dev);
28 typedef int (rte_gpu_info_get_t)(struct rte_gpu *dev, struct rte_gpu_info *info);
29
30 struct rte_gpu_ops {
31         /* Get device info. If NULL, info is just copied. */
32         rte_gpu_info_get_t *dev_info_get;
33         /* Close device. */
34         rte_gpu_close_t *dev_close;
35 };
36
37 struct rte_gpu {
38         /* Backing device. */
39         struct rte_device *device;
40         /* Unique identifier name. */
41         char name[RTE_DEV_NAME_MAX_LEN]; /* Updated by this library. */
42         /* Device info structure. */
43         struct rte_gpu_info info;
44         /* Driver functions. */
45         struct rte_gpu_ops ops;
46         /* Current state (used or not) in the running process. */
47         enum rte_gpu_state state; /* Updated by this library. */
48         /* Driver-specific private data for the running process. */
49         void *process_private;
50 } __rte_cache_aligned;
51
52 __rte_internal
53 struct rte_gpu *rte_gpu_get_by_name(const char *name);
54
55 /* First step of initialization */
56 __rte_internal
57 struct rte_gpu *rte_gpu_allocate(const char *name);
58
59 /* Last step of initialization. */
60 __rte_internal
61 void rte_gpu_complete_new(struct rte_gpu *dev);
62
63 /* Last step of removal. */
64 __rte_internal
65 int rte_gpu_release(struct rte_gpu *dev);
66
67 #endif /* RTE_GPUDEV_DRIVER_H */