test/mem: disable ASan when accessing unallocated memory
[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 typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, unsigned int align, 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);
34 typedef int (rte_gpu_mem_cpu_map_t)(struct rte_gpu *dev, size_t size, void *ptr_in, void **ptr_out);
35 typedef int (rte_gpu_mem_cpu_unmap_t)(struct rte_gpu *dev, void *ptr);
36 typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev);
37
38 struct rte_gpu_ops {
39         /* Get device info. If NULL, info is just copied. */
40         rte_gpu_info_get_t *dev_info_get;
41         /* Close device or child context. */
42         rte_gpu_close_t *dev_close;
43         /* Allocate memory in device. */
44         rte_gpu_mem_alloc_t *mem_alloc;
45         /* Free memory allocated in device. */
46         rte_gpu_mem_free_t *mem_free;
47         /* Register CPU memory in device. */
48         rte_gpu_mem_register_t *mem_register;
49         /* Unregister CPU memory from device. */
50         rte_gpu_mem_unregister_t *mem_unregister;
51         /* Map GPU memory for CPU visibility. */
52         rte_gpu_mem_cpu_map_t *mem_cpu_map;
53         /* Unmap GPU memory for CPU visibility. */
54         rte_gpu_mem_cpu_unmap_t *mem_cpu_unmap;
55         /* Enforce GPU write memory barrier. */
56         rte_gpu_wmb_t *wmb;
57 };
58
59 struct rte_gpu_mpshared {
60         /* Unique identifier name. */
61         char name[RTE_DEV_NAME_MAX_LEN]; /* Updated by this library. */
62         /* Driver-specific private data shared in multi-process. */
63         void *dev_private;
64         /* Device info structure. */
65         struct rte_gpu_info info;
66         /* Counter of processes using the device. */
67         uint16_t process_refcnt; /* Updated by this library. */
68 };
69
70 struct rte_gpu {
71         /* Backing device. */
72         struct rte_device *device;
73         /* Data shared between processes. */
74         struct rte_gpu_mpshared *mpshared;
75         /* Driver functions. */
76         struct rte_gpu_ops ops;
77         /* Event callback list. */
78         TAILQ_HEAD(rte_gpu_callback_list, rte_gpu_callback) callbacks;
79         /* Current state (used or not) in the running process. */
80         enum rte_gpu_state process_state; /* Updated by this library. */
81         /* Driver-specific private data for the running process. */
82         void *process_private;
83 } __rte_cache_aligned;
84
85 __rte_internal
86 struct rte_gpu *rte_gpu_get_by_name(const char *name);
87
88 /* First step of initialization in primary process. */
89 __rte_internal
90 struct rte_gpu *rte_gpu_allocate(const char *name);
91
92 /* First step of initialization in secondary process. */
93 __rte_internal
94 struct rte_gpu *rte_gpu_attach(const char *name);
95
96 /* Last step of initialization. */
97 __rte_internal
98 void rte_gpu_complete_new(struct rte_gpu *dev);
99
100 /* Last step of removal (primary or secondary process). */
101 __rte_internal
102 int rte_gpu_release(struct rte_gpu *dev);
103
104 /* Call registered callbacks. No multi-process event. */
105 __rte_internal
106 void rte_gpu_notify(struct rte_gpu *dev, enum rte_gpu_event);
107
108 #endif /* RTE_GPUDEV_DRIVER_H */