gpudev: support multi-process
[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 #include <sys/queue.h>
16
17 #include <rte_dev.h>
18
19 #include "rte_gpudev.h"
20
21 /* Flags indicate current state of device. */
22 enum rte_gpu_state {
23         RTE_GPU_STATE_UNUSED,        /* not initialized */
24         RTE_GPU_STATE_INITIALIZED,   /* initialized */
25 };
26
27 struct rte_gpu;
28 typedef int (rte_gpu_close_t)(struct rte_gpu *dev);
29 typedef int (rte_gpu_info_get_t)(struct rte_gpu *dev, struct rte_gpu_info *info);
30
31 struct rte_gpu_ops {
32         /* Get device info. If NULL, info is just copied. */
33         rte_gpu_info_get_t *dev_info_get;
34         /* Close device or child context. */
35         rte_gpu_close_t *dev_close;
36 };
37
38 struct rte_gpu_mpshared {
39         /* Unique identifier name. */
40         char name[RTE_DEV_NAME_MAX_LEN]; /* Updated by this library. */
41         /* Driver-specific private data shared in multi-process. */
42         void *dev_private;
43         /* Device info structure. */
44         struct rte_gpu_info info;
45         /* Counter of processes using the device. */
46         uint16_t process_refcnt; /* Updated by this library. */
47 };
48
49 struct rte_gpu {
50         /* Backing device. */
51         struct rte_device *device;
52         /* Data shared between processes. */
53         struct rte_gpu_mpshared *mpshared;
54         /* Driver functions. */
55         struct rte_gpu_ops ops;
56         /* Event callback list. */
57         TAILQ_HEAD(rte_gpu_callback_list, rte_gpu_callback) callbacks;
58         /* Current state (used or not) in the running process. */
59         enum rte_gpu_state process_state; /* Updated by this library. */
60         /* Driver-specific private data for the running process. */
61         void *process_private;
62 } __rte_cache_aligned;
63
64 __rte_internal
65 struct rte_gpu *rte_gpu_get_by_name(const char *name);
66
67 /* First step of initialization in primary process. */
68 __rte_internal
69 struct rte_gpu *rte_gpu_allocate(const char *name);
70
71 /* First step of initialization in secondary process. */
72 __rte_internal
73 struct rte_gpu *rte_gpu_attach(const char *name);
74
75 /* Last step of initialization. */
76 __rte_internal
77 void rte_gpu_complete_new(struct rte_gpu *dev);
78
79 /* Last step of removal (primary or secondary process). */
80 __rte_internal
81 int rte_gpu_release(struct rte_gpu *dev);
82
83 /* Call registered callbacks. No multi-process event. */
84 __rte_internal
85 void rte_gpu_notify(struct rte_gpu *dev, enum rte_gpu_event);
86
87 #endif /* RTE_GPUDEV_DRIVER_H */