1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2021 NVIDIA Corporation & Affiliates
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.
11 #ifndef RTE_GPUDEV_DRIVER_H
12 #define RTE_GPUDEV_DRIVER_H
15 #include <sys/queue.h>
19 #include "rte_gpudev.h"
21 /* Flags indicate current state of device. */
23 RTE_GPU_STATE_UNUSED, /* not initialized */
24 RTE_GPU_STATE_INITIALIZED, /* initialized */
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 typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr);
31 typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr);
32 typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr);
33 typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr);
36 /* Get device info. If NULL, info is just copied. */
37 rte_gpu_info_get_t *dev_info_get;
38 /* Close device or child context. */
39 rte_gpu_close_t *dev_close;
40 /* Allocate memory in device. */
41 rte_gpu_mem_alloc_t *mem_alloc;
42 /* Free memory allocated in device. */
43 rte_gpu_mem_free_t *mem_free;
44 /* Register CPU memory in device. */
45 rte_gpu_mem_register_t *mem_register;
46 /* Unregister CPU memory from device. */
47 rte_gpu_mem_unregister_t *mem_unregister;
50 struct rte_gpu_mpshared {
51 /* Unique identifier name. */
52 char name[RTE_DEV_NAME_MAX_LEN]; /* Updated by this library. */
53 /* Driver-specific private data shared in multi-process. */
55 /* Device info structure. */
56 struct rte_gpu_info info;
57 /* Counter of processes using the device. */
58 uint16_t process_refcnt; /* Updated by this library. */
63 struct rte_device *device;
64 /* Data shared between processes. */
65 struct rte_gpu_mpshared *mpshared;
66 /* Driver functions. */
67 struct rte_gpu_ops ops;
68 /* Event callback list. */
69 TAILQ_HEAD(rte_gpu_callback_list, rte_gpu_callback) callbacks;
70 /* Current state (used or not) in the running process. */
71 enum rte_gpu_state process_state; /* Updated by this library. */
72 /* Driver-specific private data for the running process. */
73 void *process_private;
74 } __rte_cache_aligned;
77 struct rte_gpu *rte_gpu_get_by_name(const char *name);
79 /* First step of initialization in primary process. */
81 struct rte_gpu *rte_gpu_allocate(const char *name);
83 /* First step of initialization in secondary process. */
85 struct rte_gpu *rte_gpu_attach(const char *name);
87 /* Last step of initialization. */
89 void rte_gpu_complete_new(struct rte_gpu *dev);
91 /* Last step of removal (primary or secondary process). */
93 int rte_gpu_release(struct rte_gpu *dev);
95 /* Call registered callbacks. No multi-process event. */
97 void rte_gpu_notify(struct rte_gpu *dev, enum rte_gpu_event);
99 #endif /* RTE_GPUDEV_DRIVER_H */