1 #ifndef _G_THIRD_PARTY_P2P_NVOC_H_
2 #define _G_THIRD_PARTY_P2P_NVOC_H_
3 #include "nvoc/runtime.h"
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 /*
10  * SPDX-FileCopyrightText: Copyright (c) 2009-2021 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_third_party_p2p_nvoc.h"
33 
34 #ifndef _THIRD_PARTY_P2P_H_
35 #define _THIRD_PARTY_P2P_H_
36 
37 #include "rmapi/client.h"
38 #include "gpu/mem_mgr/mem_desc.h"
39 #include "gpu/subdevice/subdevice.h"
40 #include "gpu/gpu_resource.h"
41 
42 #include <ctrl/ctrl503c.h>
43 
44 //
45 // The third-party P2P token is a 64bit integer.
46 //
47 // The value may be passed by the RM client enabling the third-party P2P access.
48 // Otherwise the P2P token format is:
49 //
50 //   fn  [  *GPU ID*  ]  [ *UNUSED*  ]  [  *PEER INDEX*  ]
51 //   bit 63          32  31          8  7                0
52 //
53 // The third-party P2P token is a globally unique identifier for one
54 // of an attached GPU's several P2P slots.  It is passed, as an
55 // opaque handle, to third-party driver stacks to allow the setup
56 // of a P2P mapping between a given GPU and a third-party device with
57 // NVIDIA P2P capabilities.
58 //
59 
60 #define CLI_ENCODEP2PTOKEN(gpuId, peerIndex) (((NvU64)gpuId << 32) | peerIndex)
61 
62 #define CLI_THIRD_PARTY_P2P_FLAGS_INITIALIZED   NVBIT(0)
63 
64 #define CLI_THIRD_PARTY_P2P_MAX_CLIENT 256
65 
66 //
67 // CUDA tools has requested that the third-party P2P code reserve at least
68 // 32MB of BAR1 address space for RM clients. Pad this reservation by
69 // 4MB to account for miscellaneous RM mappings.
70 //
71 #define CLI_THIRD_PARTY_P2P_BAR1_RESERVE (36 << 20)
72 
73 // ****************************************************************************
74 //                          Type definitions
75 // ****************************************************************************
76 
77 //
78 // third-party p2p support types
79 //
80 struct _def_client_third_party_p2p_vaspace_info
81 {
82     NvHandle                 hClient;
83     NvHandle                 hThirdPartyP2P;
84     NvHandle                 hVASpace;
85     NvU32                    vaSpaceToken;
86 };
87 typedef struct _def_client_third_party_p2p_vaspace_info CLI_THIRD_PARTY_P2P_VASPACE_INFO, *PCLI_THIRD_PARTY_P2P_VASPACE_INFO;
88 
89 MAKE_MAP(CLI_THIRD_PARTY_P2P_VASPACE_INFO_MAP, CLI_THIRD_PARTY_P2P_VASPACE_INFO);
90 
91 typedef void (THIRD_PARTY_P2P_VIDMEM_FREE_CALLBACK)(void *);
92 
93 struct _def_client_third_party_p2p_mapping_info
94 {
95     NODE                                                     Node;
96     THIRD_PARTY_P2P_VIDMEM_FREE_CALLBACK                    *pFreeCallback;
97     void                                                    *pData;
98 
99     // Address and length describe a subrange of the parent vidmem info address range
100     NvU64                                                    address;
101     NvU64                                                    length;
102 
103     struct _def_client_third_party_p2p_mapping_extent_info  *pStart;
104 };
105 typedef struct _def_client_third_party_p2p_mapping_info CLI_THIRD_PARTY_P2P_MAPPING_INFO, *PCLI_THIRD_PARTY_P2P_MAPPING_INFO;
106 
107 struct _def_client_third_party_p2p_mapping_extent_info
108 {
109     // Address and length describe a subrange of the parent vidmem info address range
110     NvU64                    address;
111     NvU64                    length;
112 
113     NvU64                    fbApertureOffset;
114     PMEMORY_DESCRIPTOR       pMemDesc;
115     NvU32                    refCount;
116     ListNode                 listNode;  // Node in the list.
117 };
118 typedef struct _def_client_third_party_p2p_mapping_extent_info CLI_THIRD_PARTY_P2P_MAPPING_EXTENT_INFO, *PCLI_THIRD_PARTY_P2P_MAPPING_EXTENT_INFO;
119 
120 MAKE_INTRUSIVE_LIST(CLI_THIRD_PARTY_P2P_MAPPING_EXTENT_INFO_LIST, CLI_THIRD_PARTY_P2P_MAPPING_EXTENT_INFO, listNode);
121 
122 struct _def_client_third_party_p2p_vidmem_info
123 {
124     NvHandle                   hClient;
125     NvHandle                   hThirdPartyP2P;
126     NvHandle                   hMemory;
127 
128     //
129     // A node in the PCLI_THIRD_PARTY_P2P_INFO::pAddressRangeTree btree tracking
130     // the address range registered for this vidmem allocation.
131     //
132     // Notably the address ranges come from the user and are not enforced to
133     // be mapped in any GPU VA space. It's up to the user to pick them and they
134     // are used purely for exposing the registered vidmem allocations through
135     // the third-party P2P APIs at the specified ranges. See documentation of
136     // NV503C_CTRL_CMD_REGISTER_VIDMEM for more details.
137     //
138     // Commonly clients will map the allocation at the same address as it's
139     // registered with for third-party P2P and the third-party P2P APIs still
140     // call the address parameter a virtual address, but the implementation
141     // refers to them just as addresses to make it clear they are not enforced
142     // to be actually mapped.
143     //
144     // Notably in the past the addresses have been indeed looked up in the GPU
145     // VA spaces directly, but that became challenging with the introduction of
146     // externally managed VA spaces and now it's up to the clients to register
147     // them explicitly.
148     //
149     NODE                                         addressRangeNode;
150     MapNode                                      mapNode;
151     // Offset at which the address range starts in the vidmem allocation.
152     NvU64                                        offset;
153 
154     // VidmemInfo ID used for persistent mappings
155     NvU64                                        id;
156 
157     PMEMORY_DESCRIPTOR                           pMemDesc;
158     PNODE                                        pMappingInfoList;
159     CLI_THIRD_PARTY_P2P_MAPPING_EXTENT_INFO_LIST mappingExtentList;
160 };
161 typedef struct _def_client_third_party_p2p_vidmem_info  CLI_THIRD_PARTY_P2P_VIDMEM_INFO, *PCLI_THIRD_PARTY_P2P_VIDMEM_INFO;
162 
163 MAKE_INTRUSIVE_MAP(CLI_THIRD_PARTY_P2P_VIDMEM_INFO_MAP, CLI_THIRD_PARTY_P2P_VIDMEM_INFO, mapNode);
164 
165 typedef void (THIRD_PARTY_P2P_DESTROY_CALLBACK)(void *);
166 
167 enum _def_client_third_party_p2p_type
168 {
169     CLI_THIRD_PARTY_P2P_TYPE_PROPRIETARY,
170     CLI_THIRD_PARTY_P2P_TYPE_BAR1,
171     CLI_THIRD_PARTY_P2P_TYPE_NVLINK
172 };
173 typedef enum   _def_client_third_party_p2p_type     CLI_THIRD_PARTY_P2P_TYPE;
174 
175 struct _def_client_third_party_p2p_pid_client_mapping_info
176 {
177     NvU32       pid;
178     NvHandle    hClient;
179 };
180 typedef struct _def_client_third_party_p2p_pid_client_mapping_info CLI_THIRD_PARTY_P2P_PID_CLIENT_INFO, *PCLI_THIRD_PARTY_P2P_PID_CLIENT_INFO;
181 
182 
183 #ifdef NVOC_THIRD_PARTY_P2P_H_PRIVATE_ACCESS_ALLOWED
184 #define PRIVATE_FIELD(x) x
185 #else
186 #define PRIVATE_FIELD(x) NVOC_PRIVATE_FIELD(x)
187 #endif
188 struct ThirdPartyP2P {
189     const struct NVOC_RTTI *__nvoc_rtti;
190     struct GpuResource __nvoc_base_GpuResource;
191     struct Object *__nvoc_pbase_Object;
192     struct RsResource *__nvoc_pbase_RsResource;
193     struct RmResourceCommon *__nvoc_pbase_RmResourceCommon;
194     struct RmResource *__nvoc_pbase_RmResource;
195     struct GpuResource *__nvoc_pbase_GpuResource;
196     struct ThirdPartyP2P *__nvoc_pbase_ThirdPartyP2P;
197     NV_STATUS (*__thirdpartyp2pCtrlCmdRegisterVaSpace__)(struct ThirdPartyP2P *, NV503C_CTRL_REGISTER_VA_SPACE_PARAMS *);
198     NV_STATUS (*__thirdpartyp2pCtrlCmdUnregisterVaSpace__)(struct ThirdPartyP2P *, NV503C_CTRL_UNREGISTER_VA_SPACE_PARAMS *);
199     NV_STATUS (*__thirdpartyp2pCtrlCmdRegisterVidmem__)(struct ThirdPartyP2P *, NV503C_CTRL_REGISTER_VIDMEM_PARAMS *);
200     NV_STATUS (*__thirdpartyp2pCtrlCmdUnregisterVidmem__)(struct ThirdPartyP2P *, NV503C_CTRL_UNREGISTER_VIDMEM_PARAMS *);
201     NV_STATUS (*__thirdpartyp2pCtrlCmdRegisterPid__)(struct ThirdPartyP2P *, NV503C_CTRL_REGISTER_PID_PARAMS *);
202     NvBool (*__thirdpartyp2pShareCallback__)(struct ThirdPartyP2P *, struct RsClient *, struct RsResourceRef *, RS_SHARE_POLICY *);
203     NV_STATUS (*__thirdpartyp2pControl__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, struct RS_RES_CONTROL_PARAMS_INTERNAL *);
204     NV_STATUS (*__thirdpartyp2pUnmap__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, struct RsCpuMapping *);
205     NV_STATUS (*__thirdpartyp2pGetMemInterMapParams__)(struct ThirdPartyP2P *, RMRES_MEM_INTER_MAP_PARAMS *);
206     NV_STATUS (*__thirdpartyp2pGetMemoryMappingDescriptor__)(struct ThirdPartyP2P *, struct MEMORY_DESCRIPTOR **);
207     NV_STATUS (*__thirdpartyp2pGetMapAddrSpace__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, NvU32, NV_ADDRESS_SPACE *);
208     NvHandle (*__thirdpartyp2pGetInternalObjectHandle__)(struct ThirdPartyP2P *);
209     NV_STATUS (*__thirdpartyp2pControlFilter__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, struct RS_RES_CONTROL_PARAMS_INTERNAL *);
210     void (*__thirdpartyp2pAddAdditionalDependants__)(struct RsClient *, struct ThirdPartyP2P *, RsResourceRef *);
211     NvU32 (*__thirdpartyp2pGetRefCount__)(struct ThirdPartyP2P *);
212     NV_STATUS (*__thirdpartyp2pCheckMemInterUnmap__)(struct ThirdPartyP2P *, NvBool);
213     NV_STATUS (*__thirdpartyp2pMapTo__)(struct ThirdPartyP2P *, RS_RES_MAP_TO_PARAMS *);
214     NV_STATUS (*__thirdpartyp2pControl_Prologue__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, struct RS_RES_CONTROL_PARAMS_INTERNAL *);
215     NV_STATUS (*__thirdpartyp2pGetRegBaseOffsetAndSize__)(struct ThirdPartyP2P *, struct OBJGPU *, NvU32 *, NvU32 *);
216     NvBool (*__thirdpartyp2pCanCopy__)(struct ThirdPartyP2P *);
217     NV_STATUS (*__thirdpartyp2pInternalControlForward__)(struct ThirdPartyP2P *, NvU32, void *, NvU32);
218     void (*__thirdpartyp2pPreDestruct__)(struct ThirdPartyP2P *);
219     NV_STATUS (*__thirdpartyp2pUnmapFrom__)(struct ThirdPartyP2P *, RS_RES_UNMAP_FROM_PARAMS *);
220     void (*__thirdpartyp2pControl_Epilogue__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, struct RS_RES_CONTROL_PARAMS_INTERNAL *);
221     NV_STATUS (*__thirdpartyp2pControlLookup__)(struct ThirdPartyP2P *, struct RS_RES_CONTROL_PARAMS_INTERNAL *, const struct NVOC_EXPORTED_METHOD_DEF **);
222     NV_STATUS (*__thirdpartyp2pMap__)(struct ThirdPartyP2P *, struct CALL_CONTEXT *, struct RS_CPU_MAP_PARAMS *, struct RsCpuMapping *);
223     NvBool (*__thirdpartyp2pAccessCallback__)(struct ThirdPartyP2P *, struct RsClient *, void *, RsAccessRight);
224     NODE Node;
225     NvHandle hClient;
226     NvHandle hThirdPartyP2P;
227     CLI_THIRD_PARTY_P2P_TYPE type;
228     struct Subdevice *pSubdevice;
229     NvU32 peerIndex;
230     NvU32 flags;
231     NvU64 p2pToken;
232     CLI_THIRD_PARTY_P2P_PID_CLIENT_INFO pidClientList[256];
233     CLI_THIRD_PARTY_P2P_VASPACE_INFO_MAP vaSpaceInfoMap;
234     THIRD_PARTY_P2P_DESTROY_CALLBACK *pDestroyCallback;
235     void *pData;
236     CLI_THIRD_PARTY_P2P_VIDMEM_INFO_MAP vidmemInfoMap;
237     PNODE pAddressRangeTree;
238 };
239 
240 #ifndef __NVOC_CLASS_ThirdPartyP2P_TYPEDEF__
241 #define __NVOC_CLASS_ThirdPartyP2P_TYPEDEF__
242 typedef struct ThirdPartyP2P ThirdPartyP2P;
243 #endif /* __NVOC_CLASS_ThirdPartyP2P_TYPEDEF__ */
244 
245 #ifndef __nvoc_class_id_ThirdPartyP2P
246 #define __nvoc_class_id_ThirdPartyP2P 0x34d08b
247 #endif /* __nvoc_class_id_ThirdPartyP2P */
248 
249 extern const struct NVOC_CLASS_DEF __nvoc_class_def_ThirdPartyP2P;
250 
251 #define __staticCast_ThirdPartyP2P(pThis) \
252     ((pThis)->__nvoc_pbase_ThirdPartyP2P)
253 
254 #ifdef __nvoc_third_party_p2p_h_disabled
255 #define __dynamicCast_ThirdPartyP2P(pThis) ((ThirdPartyP2P*)NULL)
256 #else //__nvoc_third_party_p2p_h_disabled
257 #define __dynamicCast_ThirdPartyP2P(pThis) \
258     ((ThirdPartyP2P*)__nvoc_dynamicCast(staticCast((pThis), Dynamic), classInfo(ThirdPartyP2P)))
259 #endif //__nvoc_third_party_p2p_h_disabled
260 
261 
262 NV_STATUS __nvoc_objCreateDynamic_ThirdPartyP2P(ThirdPartyP2P**, Dynamic*, NvU32, va_list);
263 
264 NV_STATUS __nvoc_objCreate_ThirdPartyP2P(ThirdPartyP2P**, Dynamic*, NvU32, struct CALL_CONTEXT * arg_pCallContext, struct RS_RES_ALLOC_PARAMS_INTERNAL * arg_pParams);
265 #define __objCreate_ThirdPartyP2P(ppNewObj, pParent, createFlags, arg_pCallContext, arg_pParams) \
266     __nvoc_objCreate_ThirdPartyP2P((ppNewObj), staticCast((pParent), Dynamic), (createFlags), arg_pCallContext, arg_pParams)
267 
268 #define thirdpartyp2pCtrlCmdRegisterVaSpace(pThirdPartyP2P, pRegisterVaSpaceParams) thirdpartyp2pCtrlCmdRegisterVaSpace_DISPATCH(pThirdPartyP2P, pRegisterVaSpaceParams)
269 #define thirdpartyp2pCtrlCmdUnregisterVaSpace(pThirdPartyP2P, pUnregisterVaSpaceParams) thirdpartyp2pCtrlCmdUnregisterVaSpace_DISPATCH(pThirdPartyP2P, pUnregisterVaSpaceParams)
270 #define thirdpartyp2pCtrlCmdRegisterVidmem(pThirdPartyP2P, pRegisterVidmemParams) thirdpartyp2pCtrlCmdRegisterVidmem_DISPATCH(pThirdPartyP2P, pRegisterVidmemParams)
271 #define thirdpartyp2pCtrlCmdUnregisterVidmem(pThirdPartyP2P, pUnregisterVidmemParams) thirdpartyp2pCtrlCmdUnregisterVidmem_DISPATCH(pThirdPartyP2P, pUnregisterVidmemParams)
272 #define thirdpartyp2pCtrlCmdRegisterPid(pThirdPartyP2P, pParams) thirdpartyp2pCtrlCmdRegisterPid_DISPATCH(pThirdPartyP2P, pParams)
273 #define thirdpartyp2pShareCallback(pGpuResource, pInvokingClient, pParentRef, pSharePolicy) thirdpartyp2pShareCallback_DISPATCH(pGpuResource, pInvokingClient, pParentRef, pSharePolicy)
274 #define thirdpartyp2pControl(pGpuResource, pCallContext, pParams) thirdpartyp2pControl_DISPATCH(pGpuResource, pCallContext, pParams)
275 #define thirdpartyp2pUnmap(pGpuResource, pCallContext, pCpuMapping) thirdpartyp2pUnmap_DISPATCH(pGpuResource, pCallContext, pCpuMapping)
276 #define thirdpartyp2pGetMemInterMapParams(pRmResource, pParams) thirdpartyp2pGetMemInterMapParams_DISPATCH(pRmResource, pParams)
277 #define thirdpartyp2pGetMemoryMappingDescriptor(pRmResource, ppMemDesc) thirdpartyp2pGetMemoryMappingDescriptor_DISPATCH(pRmResource, ppMemDesc)
278 #define thirdpartyp2pGetMapAddrSpace(pGpuResource, pCallContext, mapFlags, pAddrSpace) thirdpartyp2pGetMapAddrSpace_DISPATCH(pGpuResource, pCallContext, mapFlags, pAddrSpace)
279 #define thirdpartyp2pGetInternalObjectHandle(pGpuResource) thirdpartyp2pGetInternalObjectHandle_DISPATCH(pGpuResource)
280 #define thirdpartyp2pControlFilter(pResource, pCallContext, pParams) thirdpartyp2pControlFilter_DISPATCH(pResource, pCallContext, pParams)
281 #define thirdpartyp2pAddAdditionalDependants(pClient, pResource, pReference) thirdpartyp2pAddAdditionalDependants_DISPATCH(pClient, pResource, pReference)
282 #define thirdpartyp2pGetRefCount(pResource) thirdpartyp2pGetRefCount_DISPATCH(pResource)
283 #define thirdpartyp2pCheckMemInterUnmap(pRmResource, bSubdeviceHandleProvided) thirdpartyp2pCheckMemInterUnmap_DISPATCH(pRmResource, bSubdeviceHandleProvided)
284 #define thirdpartyp2pMapTo(pResource, pParams) thirdpartyp2pMapTo_DISPATCH(pResource, pParams)
285 #define thirdpartyp2pControl_Prologue(pResource, pCallContext, pParams) thirdpartyp2pControl_Prologue_DISPATCH(pResource, pCallContext, pParams)
286 #define thirdpartyp2pGetRegBaseOffsetAndSize(pGpuResource, pGpu, pOffset, pSize) thirdpartyp2pGetRegBaseOffsetAndSize_DISPATCH(pGpuResource, pGpu, pOffset, pSize)
287 #define thirdpartyp2pCanCopy(pResource) thirdpartyp2pCanCopy_DISPATCH(pResource)
288 #define thirdpartyp2pInternalControlForward(pGpuResource, command, pParams, size) thirdpartyp2pInternalControlForward_DISPATCH(pGpuResource, command, pParams, size)
289 #define thirdpartyp2pPreDestruct(pResource) thirdpartyp2pPreDestruct_DISPATCH(pResource)
290 #define thirdpartyp2pUnmapFrom(pResource, pParams) thirdpartyp2pUnmapFrom_DISPATCH(pResource, pParams)
291 #define thirdpartyp2pControl_Epilogue(pResource, pCallContext, pParams) thirdpartyp2pControl_Epilogue_DISPATCH(pResource, pCallContext, pParams)
292 #define thirdpartyp2pControlLookup(pResource, pParams, ppEntry) thirdpartyp2pControlLookup_DISPATCH(pResource, pParams, ppEntry)
293 #define thirdpartyp2pMap(pGpuResource, pCallContext, pParams, pCpuMapping) thirdpartyp2pMap_DISPATCH(pGpuResource, pCallContext, pParams, pCpuMapping)
294 #define thirdpartyp2pAccessCallback(pResource, pInvokingClient, pAllocParams, accessRight) thirdpartyp2pAccessCallback_DISPATCH(pResource, pInvokingClient, pAllocParams, accessRight)
295 NV_STATUS thirdpartyp2pCtrlCmdRegisterVaSpace_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_REGISTER_VA_SPACE_PARAMS *pRegisterVaSpaceParams);
296 
297 static inline NV_STATUS thirdpartyp2pCtrlCmdRegisterVaSpace_DISPATCH(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_REGISTER_VA_SPACE_PARAMS *pRegisterVaSpaceParams) {
298     return pThirdPartyP2P->__thirdpartyp2pCtrlCmdRegisterVaSpace__(pThirdPartyP2P, pRegisterVaSpaceParams);
299 }
300 
301 NV_STATUS thirdpartyp2pCtrlCmdUnregisterVaSpace_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_UNREGISTER_VA_SPACE_PARAMS *pUnregisterVaSpaceParams);
302 
303 static inline NV_STATUS thirdpartyp2pCtrlCmdUnregisterVaSpace_DISPATCH(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_UNREGISTER_VA_SPACE_PARAMS *pUnregisterVaSpaceParams) {
304     return pThirdPartyP2P->__thirdpartyp2pCtrlCmdUnregisterVaSpace__(pThirdPartyP2P, pUnregisterVaSpaceParams);
305 }
306 
307 NV_STATUS thirdpartyp2pCtrlCmdRegisterVidmem_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_REGISTER_VIDMEM_PARAMS *pRegisterVidmemParams);
308 
309 static inline NV_STATUS thirdpartyp2pCtrlCmdRegisterVidmem_DISPATCH(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_REGISTER_VIDMEM_PARAMS *pRegisterVidmemParams) {
310     return pThirdPartyP2P->__thirdpartyp2pCtrlCmdRegisterVidmem__(pThirdPartyP2P, pRegisterVidmemParams);
311 }
312 
313 NV_STATUS thirdpartyp2pCtrlCmdUnregisterVidmem_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_UNREGISTER_VIDMEM_PARAMS *pUnregisterVidmemParams);
314 
315 static inline NV_STATUS thirdpartyp2pCtrlCmdUnregisterVidmem_DISPATCH(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_UNREGISTER_VIDMEM_PARAMS *pUnregisterVidmemParams) {
316     return pThirdPartyP2P->__thirdpartyp2pCtrlCmdUnregisterVidmem__(pThirdPartyP2P, pUnregisterVidmemParams);
317 }
318 
319 NV_STATUS thirdpartyp2pCtrlCmdRegisterPid_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_REGISTER_PID_PARAMS *pParams);
320 
321 static inline NV_STATUS thirdpartyp2pCtrlCmdRegisterPid_DISPATCH(struct ThirdPartyP2P *pThirdPartyP2P, NV503C_CTRL_REGISTER_PID_PARAMS *pParams) {
322     return pThirdPartyP2P->__thirdpartyp2pCtrlCmdRegisterPid__(pThirdPartyP2P, pParams);
323 }
324 
325 static inline NvBool thirdpartyp2pShareCallback_DISPATCH(struct ThirdPartyP2P *pGpuResource, struct RsClient *pInvokingClient, struct RsResourceRef *pParentRef, RS_SHARE_POLICY *pSharePolicy) {
326     return pGpuResource->__thirdpartyp2pShareCallback__(pGpuResource, pInvokingClient, pParentRef, pSharePolicy);
327 }
328 
329 static inline NV_STATUS thirdpartyp2pControl_DISPATCH(struct ThirdPartyP2P *pGpuResource, struct CALL_CONTEXT *pCallContext, struct RS_RES_CONTROL_PARAMS_INTERNAL *pParams) {
330     return pGpuResource->__thirdpartyp2pControl__(pGpuResource, pCallContext, pParams);
331 }
332 
333 static inline NV_STATUS thirdpartyp2pUnmap_DISPATCH(struct ThirdPartyP2P *pGpuResource, struct CALL_CONTEXT *pCallContext, struct RsCpuMapping *pCpuMapping) {
334     return pGpuResource->__thirdpartyp2pUnmap__(pGpuResource, pCallContext, pCpuMapping);
335 }
336 
337 static inline NV_STATUS thirdpartyp2pGetMemInterMapParams_DISPATCH(struct ThirdPartyP2P *pRmResource, RMRES_MEM_INTER_MAP_PARAMS *pParams) {
338     return pRmResource->__thirdpartyp2pGetMemInterMapParams__(pRmResource, pParams);
339 }
340 
341 static inline NV_STATUS thirdpartyp2pGetMemoryMappingDescriptor_DISPATCH(struct ThirdPartyP2P *pRmResource, struct MEMORY_DESCRIPTOR **ppMemDesc) {
342     return pRmResource->__thirdpartyp2pGetMemoryMappingDescriptor__(pRmResource, ppMemDesc);
343 }
344 
345 static inline NV_STATUS thirdpartyp2pGetMapAddrSpace_DISPATCH(struct ThirdPartyP2P *pGpuResource, struct CALL_CONTEXT *pCallContext, NvU32 mapFlags, NV_ADDRESS_SPACE *pAddrSpace) {
346     return pGpuResource->__thirdpartyp2pGetMapAddrSpace__(pGpuResource, pCallContext, mapFlags, pAddrSpace);
347 }
348 
349 static inline NvHandle thirdpartyp2pGetInternalObjectHandle_DISPATCH(struct ThirdPartyP2P *pGpuResource) {
350     return pGpuResource->__thirdpartyp2pGetInternalObjectHandle__(pGpuResource);
351 }
352 
353 static inline NV_STATUS thirdpartyp2pControlFilter_DISPATCH(struct ThirdPartyP2P *pResource, struct CALL_CONTEXT *pCallContext, struct RS_RES_CONTROL_PARAMS_INTERNAL *pParams) {
354     return pResource->__thirdpartyp2pControlFilter__(pResource, pCallContext, pParams);
355 }
356 
357 static inline void thirdpartyp2pAddAdditionalDependants_DISPATCH(struct RsClient *pClient, struct ThirdPartyP2P *pResource, RsResourceRef *pReference) {
358     pResource->__thirdpartyp2pAddAdditionalDependants__(pClient, pResource, pReference);
359 }
360 
361 static inline NvU32 thirdpartyp2pGetRefCount_DISPATCH(struct ThirdPartyP2P *pResource) {
362     return pResource->__thirdpartyp2pGetRefCount__(pResource);
363 }
364 
365 static inline NV_STATUS thirdpartyp2pCheckMemInterUnmap_DISPATCH(struct ThirdPartyP2P *pRmResource, NvBool bSubdeviceHandleProvided) {
366     return pRmResource->__thirdpartyp2pCheckMemInterUnmap__(pRmResource, bSubdeviceHandleProvided);
367 }
368 
369 static inline NV_STATUS thirdpartyp2pMapTo_DISPATCH(struct ThirdPartyP2P *pResource, RS_RES_MAP_TO_PARAMS *pParams) {
370     return pResource->__thirdpartyp2pMapTo__(pResource, pParams);
371 }
372 
373 static inline NV_STATUS thirdpartyp2pControl_Prologue_DISPATCH(struct ThirdPartyP2P *pResource, struct CALL_CONTEXT *pCallContext, struct RS_RES_CONTROL_PARAMS_INTERNAL *pParams) {
374     return pResource->__thirdpartyp2pControl_Prologue__(pResource, pCallContext, pParams);
375 }
376 
377 static inline NV_STATUS thirdpartyp2pGetRegBaseOffsetAndSize_DISPATCH(struct ThirdPartyP2P *pGpuResource, struct OBJGPU *pGpu, NvU32 *pOffset, NvU32 *pSize) {
378     return pGpuResource->__thirdpartyp2pGetRegBaseOffsetAndSize__(pGpuResource, pGpu, pOffset, pSize);
379 }
380 
381 static inline NvBool thirdpartyp2pCanCopy_DISPATCH(struct ThirdPartyP2P *pResource) {
382     return pResource->__thirdpartyp2pCanCopy__(pResource);
383 }
384 
385 static inline NV_STATUS thirdpartyp2pInternalControlForward_DISPATCH(struct ThirdPartyP2P *pGpuResource, NvU32 command, void *pParams, NvU32 size) {
386     return pGpuResource->__thirdpartyp2pInternalControlForward__(pGpuResource, command, pParams, size);
387 }
388 
389 static inline void thirdpartyp2pPreDestruct_DISPATCH(struct ThirdPartyP2P *pResource) {
390     pResource->__thirdpartyp2pPreDestruct__(pResource);
391 }
392 
393 static inline NV_STATUS thirdpartyp2pUnmapFrom_DISPATCH(struct ThirdPartyP2P *pResource, RS_RES_UNMAP_FROM_PARAMS *pParams) {
394     return pResource->__thirdpartyp2pUnmapFrom__(pResource, pParams);
395 }
396 
397 static inline void thirdpartyp2pControl_Epilogue_DISPATCH(struct ThirdPartyP2P *pResource, struct CALL_CONTEXT *pCallContext, struct RS_RES_CONTROL_PARAMS_INTERNAL *pParams) {
398     pResource->__thirdpartyp2pControl_Epilogue__(pResource, pCallContext, pParams);
399 }
400 
401 static inline NV_STATUS thirdpartyp2pControlLookup_DISPATCH(struct ThirdPartyP2P *pResource, struct RS_RES_CONTROL_PARAMS_INTERNAL *pParams, const struct NVOC_EXPORTED_METHOD_DEF **ppEntry) {
402     return pResource->__thirdpartyp2pControlLookup__(pResource, pParams, ppEntry);
403 }
404 
405 static inline NV_STATUS thirdpartyp2pMap_DISPATCH(struct ThirdPartyP2P *pGpuResource, struct CALL_CONTEXT *pCallContext, struct RS_CPU_MAP_PARAMS *pParams, struct RsCpuMapping *pCpuMapping) {
406     return pGpuResource->__thirdpartyp2pMap__(pGpuResource, pCallContext, pParams, pCpuMapping);
407 }
408 
409 static inline NvBool thirdpartyp2pAccessCallback_DISPATCH(struct ThirdPartyP2P *pResource, struct RsClient *pInvokingClient, void *pAllocParams, RsAccessRight accessRight) {
410     return pResource->__thirdpartyp2pAccessCallback__(pResource, pInvokingClient, pAllocParams, accessRight);
411 }
412 
413 NV_STATUS thirdpartyp2pConstruct_IMPL(struct ThirdPartyP2P *arg_pResource, struct CALL_CONTEXT *arg_pCallContext, struct RS_RES_ALLOC_PARAMS_INTERNAL *arg_pParams);
414 #define __nvoc_thirdpartyp2pConstruct(arg_pResource, arg_pCallContext, arg_pParams) thirdpartyp2pConstruct_IMPL(arg_pResource, arg_pCallContext, arg_pParams)
415 void thirdpartyp2pDestruct_IMPL(struct ThirdPartyP2P *pResource);
416 #define __nvoc_thirdpartyp2pDestruct(pResource) thirdpartyp2pDestruct_IMPL(pResource)
417 NvBool thirdpartyp2pIsValidClientPid_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NvU32 pid, NvHandle hClient);
418 #ifdef __nvoc_third_party_p2p_h_disabled
419 static inline NvBool thirdpartyp2pIsValidClientPid(struct ThirdPartyP2P *pThirdPartyP2P, NvU32 pid, NvHandle hClient) {
420     NV_ASSERT_FAILED_PRECOMP("ThirdPartyP2P was disabled!");
421     return NV_FALSE;
422 }
423 #else //__nvoc_third_party_p2p_h_disabled
424 #define thirdpartyp2pIsValidClientPid(pThirdPartyP2P, pid, hClient) thirdpartyp2pIsValidClientPid_IMPL(pThirdPartyP2P, pid, hClient)
425 #endif //__nvoc_third_party_p2p_h_disabled
426 
427 NV_STATUS thirdpartyp2pDelMappingInfoByKey_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, void *pKey, NvBool bIsRsyncNeeded);
428 #ifdef __nvoc_third_party_p2p_h_disabled
429 static inline NV_STATUS thirdpartyp2pDelMappingInfoByKey(struct ThirdPartyP2P *pThirdPartyP2P, void *pKey, NvBool bIsRsyncNeeded) {
430     NV_ASSERT_FAILED_PRECOMP("ThirdPartyP2P was disabled!");
431     return NV_ERR_NOT_SUPPORTED;
432 }
433 #else //__nvoc_third_party_p2p_h_disabled
434 #define thirdpartyp2pDelMappingInfoByKey(pThirdPartyP2P, pKey, bIsRsyncNeeded) thirdpartyp2pDelMappingInfoByKey_IMPL(pThirdPartyP2P, pKey, bIsRsyncNeeded)
435 #endif //__nvoc_third_party_p2p_h_disabled
436 
437 NV_STATUS thirdpartyp2pDelPersistentMappingInfoByKey_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, void *pKey, NvBool bIsRsyncNeeded);
438 #ifdef __nvoc_third_party_p2p_h_disabled
439 static inline NV_STATUS thirdpartyp2pDelPersistentMappingInfoByKey(struct ThirdPartyP2P *pThirdPartyP2P, void *pKey, NvBool bIsRsyncNeeded) {
440     NV_ASSERT_FAILED_PRECOMP("ThirdPartyP2P was disabled!");
441     return NV_ERR_NOT_SUPPORTED;
442 }
443 #else //__nvoc_third_party_p2p_h_disabled
444 #define thirdpartyp2pDelPersistentMappingInfoByKey(pThirdPartyP2P, pKey, bIsRsyncNeeded) thirdpartyp2pDelPersistentMappingInfoByKey_IMPL(pThirdPartyP2P, pKey, bIsRsyncNeeded)
445 #endif //__nvoc_third_party_p2p_h_disabled
446 
447 NV_STATUS thirdpartyp2pGetVASpaceInfoFromToken_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, NvU32 vaSpaceToken, PCLI_THIRD_PARTY_P2P_VASPACE_INFO *ppVASpaceInfo);
448 #ifdef __nvoc_third_party_p2p_h_disabled
449 static inline NV_STATUS thirdpartyp2pGetVASpaceInfoFromToken(struct ThirdPartyP2P *pThirdPartyP2P, NvU32 vaSpaceToken, PCLI_THIRD_PARTY_P2P_VASPACE_INFO *ppVASpaceInfo) {
450     NV_ASSERT_FAILED_PRECOMP("ThirdPartyP2P was disabled!");
451     return NV_ERR_NOT_SUPPORTED;
452 }
453 #else //__nvoc_third_party_p2p_h_disabled
454 #define thirdpartyp2pGetVASpaceInfoFromToken(pThirdPartyP2P, vaSpaceToken, ppVASpaceInfo) thirdpartyp2pGetVASpaceInfoFromToken_IMPL(pThirdPartyP2P, vaSpaceToken, ppVASpaceInfo)
455 #endif //__nvoc_third_party_p2p_h_disabled
456 
457 NV_STATUS thirdpartyp2pGetNextVASpaceInfo_IMPL(struct ThirdPartyP2P *pThirdPartyP2P, PCLI_THIRD_PARTY_P2P_VASPACE_INFO *arg0);
458 #ifdef __nvoc_third_party_p2p_h_disabled
459 static inline NV_STATUS thirdpartyp2pGetNextVASpaceInfo(struct ThirdPartyP2P *pThirdPartyP2P, PCLI_THIRD_PARTY_P2P_VASPACE_INFO *arg0) {
460     NV_ASSERT_FAILED_PRECOMP("ThirdPartyP2P was disabled!");
461     return NV_ERR_NOT_SUPPORTED;
462 }
463 #else //__nvoc_third_party_p2p_h_disabled
464 #define thirdpartyp2pGetNextVASpaceInfo(pThirdPartyP2P, arg0) thirdpartyp2pGetNextVASpaceInfo_IMPL(pThirdPartyP2P, arg0)
465 #endif //__nvoc_third_party_p2p_h_disabled
466 
467 #undef PRIVATE_FIELD
468 
469 
470 typedef struct ThirdPartyP2P *PCLI_THIRD_PARTY_P2P_INFO; // RS-TODO: Remove
471 
472 // ****************************************************************************
473 //                          Functions prototypes
474 // ****************************************************************************
475 
476 // Create and add/register a third-party P2P object
477 NV_STATUS           CliAddThirdPartyP2P          (NvHandle, NvHandle, struct Subdevice *, NvU32, NvU64);
478 
479 // Delete the specified third-party P2P object
480 NV_STATUS           CliDelThirdPartyP2P          (NvHandle, NvHandle);
481 
482 // Get third-party P2P info given client/object handles
483 NV_STATUS           CliGetThirdPartyP2PInfo      (NvHandle, NvHandle, PCLI_THIRD_PARTY_P2P_INFO *);
484 
485 // Get registered third-party P2P info from pid. Also match the provided client handle if provided.
486 NV_STATUS           CliNextThirdPartyP2PInfoWithPid (struct OBJGPU *, NvU32, NvHandle, struct RmClient**, PCLI_THIRD_PARTY_P2P_INFO *);
487 
488 // Get third-party P2P info given a P2P token
489 NV_STATUS           CliGetThirdPartyP2PInfoFromToken (NvU64, PCLI_THIRD_PARTY_P2P_INFO *);
490 
491 // Register an address space with a third-party P2P object
492 NV_STATUS           CliAddThirdPartyP2PVASpace   (NvHandle, NvHandle, NvHandle, NvU32 *);
493 
494 // Unregister an address space from a third-party P2P object
495 NV_STATUS           CliDelThirdPartyP2PVASpace   (struct ThirdPartyP2P*, NvHandle);
496 
497 // Register video memory with a third-party P2P object
498 NV_STATUS           CliAddThirdPartyP2PVidmemInfo (NvHandle, NvHandle, NvHandle, NvU64, NvU64, NvU64, struct Memory *);
499 
500 // Unregister video memory from a third-party P2P object
501 NV_STATUS           CliDelThirdPartyP2PVidmemInfo (struct ThirdPartyP2P*, NvHandle);
502 
503 // Unregister video memory from a third-party P2P object only if the VidmemInfo is not used
504 void                CliDelThirdPartyP2PVidmemInfoPersistent (struct ThirdPartyP2P*, CLI_THIRD_PARTY_P2P_VIDMEM_INFO*);
505 
506 // Find registered video memory given an address
507 NV_STATUS           CliGetThirdPartyP2PVidmemInfoFromAddress (NvHandle, NvHandle, NvU64, NvU64, NvU64 *, PCLI_THIRD_PARTY_P2P_VIDMEM_INFO *);
508 
509 // Find registered video memory given a VidmemInfo ID
510 NV_STATUS           CliGetThirdPartyP2PVidmemInfoFromId(NvHandle, NvHandle, NvU64, CLI_THIRD_PARTY_P2P_VIDMEM_INFO **);
511 
512 // Find platformData given a P2PInfo object
513 NV_STATUS           CliGetThirdPartyP2PPlatformData (PCLI_THIRD_PARTY_P2P_INFO, void *);
514 
515 // Associate a P2P mapping with registered video memory
516 NV_STATUS           CliAddThirdPartyP2PMappingInfo (NvHandle, NvHandle, NvHandle, void *, THIRD_PARTY_P2P_VIDMEM_FREE_CALLBACK *, void *, PCLI_THIRD_PARTY_P2P_MAPPING_INFO *);
517 
518 // Find a P2P mapping given its platform specific data
519 NV_STATUS           CliGetThirdPartyP2PMappingInfoFromKey (NvHandle, NvHandle, NvHandle, void *, PCLI_THIRD_PARTY_P2P_MAPPING_INFO *);
520 
521 // Register pid & client with a third-party P2P Info object
522 NV_STATUS           CliAddThirdPartyP2PClientPid (NvHandle, NvHandle, NvU32, NvU32);
523 
524 // Unregister pid & client from a third-party P2P Info object
525 NV_STATUS           CliDelThirdPartyP2PClientPid (struct RmClient*, NvHandle, NvU32, NvU32);
526 
527 // Remove association of a client from any existing third-Party P2P Info object
528 NV_STATUS           CliUnregisterFromThirdPartyP2P (struct RmClient*);
529 
530 // Register a free callback
531 NV_STATUS           CliRegisterThirdPartyP2PMappingCallback (NvHandle, NvHandle, NvHandle, void *, THIRD_PARTY_P2P_VIDMEM_FREE_CALLBACK *, void *);
532 
533 // Unregister memory from a third-party P2P Info object
534 void                CliUnregisterMemoryFromThirdPartyP2P(struct Memory *pMemory);
535 
536 #endif // _THIRD_PARTY_P2P_H_
537 
538 #ifdef __cplusplus
539 } // extern "C"
540 #endif
541 #endif // _G_THIRD_PARTY_P2P_NVOC_H_
542