1 #ifndef _G_CE_UTILS_NVOC_H_
2 #define _G_CE_UTILS_NVOC_H_
3 #include "nvoc/runtime.h"
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 /*
10  * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
11  * SPDX-License-Identifier: MIT
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  */
31 
32 #include "g_ce_utils_nvoc.h"
33 
34 #ifndef CE_UTILS_H
35 #define CE_UTILS_H
36 
37 #include "gpu/gpu_resource.h" // GpuResource
38 #include "class/cl0050.h"
39 #include "ctrl/ctrl0050.h"
40 
41 #include "kernel/gpu/mem_mgr/channel_utils.h"
42 
43 typedef struct
44 {
45     MEMORY_DESCRIPTOR *pMemDesc;
46     NvU64 offset;
47     NvU64 length;
48     NvU32 pattern;
49     NvU64 flags;
50     NvU64 submittedWorkId;   // Payload to poll for async completion
51 } CEUTILS_MEMSET_PARAMS;
52 
53 typedef struct
54 {
55     MEMORY_DESCRIPTOR *pSrcMemDesc;
56     MEMORY_DESCRIPTOR *pDstMemDesc;
57     NvU64 dstOffset;
58     NvU64 srcOffset;
59     NvU64 length;
60     NvU64 flags;
61     NvU64 submittedWorkId;   // Payload to poll for async completion
62 } CEUTILS_MEMCOPY_PARAMS;
63 
64 
65 #ifdef NVOC_CE_UTILS_H_PRIVATE_ACCESS_ALLOWED
66 #define PRIVATE_FIELD(x) x
67 #else
68 #define PRIVATE_FIELD(x) NVOC_PRIVATE_FIELD(x)
69 #endif
70 struct CeUtils {
71     const struct NVOC_RTTI *__nvoc_rtti;
72     struct Object __nvoc_base_Object;
73     struct Object *__nvoc_pbase_Object;
74     struct CeUtils *__nvoc_pbase_CeUtils;
75     NvHandle hClient;
76     NvHandle hDevice;
77     NvHandle hSubdevice;
78     OBJCHANNEL *pChannel;
79     KERNEL_MIG_GPU_INSTANCE *pKernelMIGGPUInstance;
80     OBJGPU *pGpu;
81     struct KernelCE *pKCe;
82     NvBool bUseVasForCeCopy;
83     NvU32 hTdCopyClass;
84     NvU64 lastSubmittedPayload;
85     NvU64 lastCompletedPayload;
86 };
87 
88 #ifndef __NVOC_CLASS_CeUtils_TYPEDEF__
89 #define __NVOC_CLASS_CeUtils_TYPEDEF__
90 typedef struct CeUtils CeUtils;
91 #endif /* __NVOC_CLASS_CeUtils_TYPEDEF__ */
92 
93 #ifndef __nvoc_class_id_CeUtils
94 #define __nvoc_class_id_CeUtils 0x8b8bae
95 #endif /* __nvoc_class_id_CeUtils */
96 
97 extern const struct NVOC_CLASS_DEF __nvoc_class_def_CeUtils;
98 
99 #define __staticCast_CeUtils(pThis) \
100     ((pThis)->__nvoc_pbase_CeUtils)
101 
102 #ifdef __nvoc_ce_utils_h_disabled
103 #define __dynamicCast_CeUtils(pThis) ((CeUtils*)NULL)
104 #else //__nvoc_ce_utils_h_disabled
105 #define __dynamicCast_CeUtils(pThis) \
106     ((CeUtils*)__nvoc_dynamicCast(staticCast((pThis), Dynamic), classInfo(CeUtils)))
107 #endif //__nvoc_ce_utils_h_disabled
108 
109 
110 NV_STATUS __nvoc_objCreateDynamic_CeUtils(CeUtils**, Dynamic*, NvU32, va_list);
111 
112 NV_STATUS __nvoc_objCreate_CeUtils(CeUtils**, Dynamic*, NvU32, OBJGPU * arg_pGpu, NV0050_ALLOCATION_PARAMETERS * arg_pAllocParams);
113 #define __objCreate_CeUtils(ppNewObj, pParent, createFlags, arg_pGpu, arg_pAllocParams) \
114     __nvoc_objCreate_CeUtils((ppNewObj), staticCast((pParent), Dynamic), (createFlags), arg_pGpu, arg_pAllocParams)
115 
116 NV_STATUS ceutilsConstruct_IMPL(struct CeUtils *arg_pCeUtils, OBJGPU *arg_pGpu, NV0050_ALLOCATION_PARAMETERS *arg_pAllocParams);
117 
118 #define __nvoc_ceutilsConstruct(arg_pCeUtils, arg_pGpu, arg_pAllocParams) ceutilsConstruct_IMPL(arg_pCeUtils, arg_pGpu, arg_pAllocParams)
119 void ceutilsDestruct_IMPL(struct CeUtils *pCeUtils);
120 
121 #define __nvoc_ceutilsDestruct(pCeUtils) ceutilsDestruct_IMPL(pCeUtils)
122 NV_STATUS ceutilsInitialize_IMPL(struct CeUtils *pCeUtils, OBJGPU *pGpu, NV0050_ALLOCATION_PARAMETERS *pAllocParams);
123 
124 #ifdef __nvoc_ce_utils_h_disabled
125 static inline NV_STATUS ceutilsInitialize(struct CeUtils *pCeUtils, OBJGPU *pGpu, NV0050_ALLOCATION_PARAMETERS *pAllocParams) {
126     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
127     return NV_ERR_NOT_SUPPORTED;
128 }
129 #else //__nvoc_ce_utils_h_disabled
130 #define ceutilsInitialize(pCeUtils, pGpu, pAllocParams) ceutilsInitialize_IMPL(pCeUtils, pGpu, pAllocParams)
131 #endif //__nvoc_ce_utils_h_disabled
132 
133 void ceutilsDeinit_IMPL(struct CeUtils *pCeUtils);
134 
135 #ifdef __nvoc_ce_utils_h_disabled
136 static inline void ceutilsDeinit(struct CeUtils *pCeUtils) {
137     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
138 }
139 #else //__nvoc_ce_utils_h_disabled
140 #define ceutilsDeinit(pCeUtils) ceutilsDeinit_IMPL(pCeUtils)
141 #endif //__nvoc_ce_utils_h_disabled
142 
143 void ceutilsRegisterGPUInstance_IMPL(struct CeUtils *pCeUtils, KERNEL_MIG_GPU_INSTANCE *pKernelMIGGPUInstance);
144 
145 #ifdef __nvoc_ce_utils_h_disabled
146 static inline void ceutilsRegisterGPUInstance(struct CeUtils *pCeUtils, KERNEL_MIG_GPU_INSTANCE *pKernelMIGGPUInstance) {
147     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
148 }
149 #else //__nvoc_ce_utils_h_disabled
150 #define ceutilsRegisterGPUInstance(pCeUtils, pKernelMIGGPUInstance) ceutilsRegisterGPUInstance_IMPL(pCeUtils, pKernelMIGGPUInstance)
151 #endif //__nvoc_ce_utils_h_disabled
152 
153 NV_STATUS ceutilsMemset_IMPL(struct CeUtils *pCeUtils, CEUTILS_MEMSET_PARAMS *pParams);
154 
155 #ifdef __nvoc_ce_utils_h_disabled
156 static inline NV_STATUS ceutilsMemset(struct CeUtils *pCeUtils, CEUTILS_MEMSET_PARAMS *pParams) {
157     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
158     return NV_ERR_NOT_SUPPORTED;
159 }
160 #else //__nvoc_ce_utils_h_disabled
161 #define ceutilsMemset(pCeUtils, pParams) ceutilsMemset_IMPL(pCeUtils, pParams)
162 #endif //__nvoc_ce_utils_h_disabled
163 
164 NV_STATUS ceutilsMemcopy_IMPL(struct CeUtils *pCeUtils, CEUTILS_MEMCOPY_PARAMS *pParams);
165 
166 #ifdef __nvoc_ce_utils_h_disabled
167 static inline NV_STATUS ceutilsMemcopy(struct CeUtils *pCeUtils, CEUTILS_MEMCOPY_PARAMS *pParams) {
168     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
169     return NV_ERR_NOT_SUPPORTED;
170 }
171 #else //__nvoc_ce_utils_h_disabled
172 #define ceutilsMemcopy(pCeUtils, pParams) ceutilsMemcopy_IMPL(pCeUtils, pParams)
173 #endif //__nvoc_ce_utils_h_disabled
174 
175 NvU64 ceutilsUpdateProgress_IMPL(struct CeUtils *pCeUtils);
176 
177 #ifdef __nvoc_ce_utils_h_disabled
178 static inline NvU64 ceutilsUpdateProgress(struct CeUtils *pCeUtils) {
179     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
180     return 0;
181 }
182 #else //__nvoc_ce_utils_h_disabled
183 #define ceutilsUpdateProgress(pCeUtils) ceutilsUpdateProgress_IMPL(pCeUtils)
184 #endif //__nvoc_ce_utils_h_disabled
185 
186 void ceutilsServiceInterrupts_IMPL(struct CeUtils *pCeUtils);
187 
188 #ifdef __nvoc_ce_utils_h_disabled
189 static inline void ceutilsServiceInterrupts(struct CeUtils *pCeUtils) {
190     NV_ASSERT_FAILED_PRECOMP("CeUtils was disabled!");
191 }
192 #else //__nvoc_ce_utils_h_disabled
193 #define ceutilsServiceInterrupts(pCeUtils) ceutilsServiceInterrupts_IMPL(pCeUtils)
194 #endif //__nvoc_ce_utils_h_disabled
195 
196 #undef PRIVATE_FIELD
197 
198 
199 
200 #if defined(DEBUG) || defined (DEVELOP)
201 NVOC_PREFIX(ceutilsapi) class CeUtilsApi : GpuResource
202 {
203 public:
204     NV_STATUS ceutilsapiConstruct(CeUtilsApi *pCeUtilsApi, CALL_CONTEXT *pCallContext,
205                                   RS_RES_ALLOC_PARAMS_INTERNAL *pParams)
206                                   : GpuResource(pCallContext, pParams);
207 
208     void ceutilsapiDestruct(CeUtilsApi *pCeUtilsApi);
209 
210     //
211     // Below APIs are only provided for SRT testing, thus only available for debug or
212     // develop driver builds
213     //
214     //
215     RMCTRL_EXPORT(NV0050_CTRL_CMD_MEMSET, RMCTRL_FLAGS(PRIVILEGED, API_LOCK_READONLY))
216     NV_STATUS ceutilsapiCtrlCmdMemset(CeUtilsApi *pCeUtilsApi, NV0050_CTRL_MEMSET_PARAMS *pParams);
217 
218     RMCTRL_EXPORT(NV0050_CTRL_CMD_MEMCOPY, RMCTRL_FLAGS(PRIVILEGED, API_LOCK_READONLY))
219     NV_STATUS ceutilsapiCtrlCmdMemcopy(CeUtilsApi *pCeUtilsApi, NV0050_CTRL_MEMCOPY_PARAMS *pParams);
220 
221     RMCTRL_EXPORT(NV0050_CTRL_CMD_CHECK_PROGRESS, RMCTRL_FLAGS(PRIVILEGED, API_LOCK_READONLY))
222     NV_STATUS ceutilsapiCtrlCmdCheckProgress(CeUtilsApi *pCeUtilsApi, NV0050_CTRL_CHECK_PROGRESS_PARAMS *pParams);
223 
224     CeUtils *pCeUtils;
225 };
226 #endif
227 
228 #endif // CE_UTILS_H
229 
230 #ifdef __cplusplus
231 } // extern "C"
232 #endif
233 #endif // _G_CE_UTILS_NVOC_H_
234