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