xref: /open-nvidia-gpu/src/nvidia/kernel/inc/objrpc.h (revision 91676d66)
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2004-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 // #ifndef NVOC
25 // #include "g_objrpc_nvoc.h"
26 // #endif
27 
28 #ifndef _OBJRPC_H_
29 #define _OBJRPC_H_
30 
31 #include "vgpu/rpc_headers.h"
32 #include "diagnostics/nv_debug_dump.h"
33 #include "ctrl/ctrl2080/ctrl2080event.h" // rmcontrol params (from hal)
34 #include "ctrl/ctrl2080/ctrl2080gpu.h" // rmcontrol params (from hal)
35 #include "ctrl/ctrl2080/ctrl2080rc.h" // rmcontrol params (from hal)
36 #include "ctrl/ctrl2080/ctrl2080perf.h" // rmcontrol params (from hal)
37 #include "ctrl/ctrl0080/ctrl0080fb.h" // rmcontrol params (from hal)
38 #include "ctrl/ctrl0080/ctrl0080dma.h" // rmcontrol params (from hal)
39 #include "gpu/gsp/message_queue.h"
40 #include "libraries/utils/nvbitvector.h"
41 
42 #include "objrpcstructurecopy.h"
43 
44 
45 typedef struct GSP_FIRMWARE GSP_FIRMWARE;
46 typedef struct _object_vgpu OBJVGPU, *POBJVGPU;
47 TYPEDEF_BITVECTOR(MC_ENGINE_BITVECTOR);
48 
49 #include "g_rpc_hal.h" // For RPC_HAL_IFACES
50 #include "g_rpc_odb.h" // For RPC_HAL_IFACES
51 
52 #define RPC_TIMEOUT_LIMIT_PRINT_RATE_THRESH 3  // rate limit after 3 prints
53 #define RPC_TIMEOUT_LIMIT_PRINT_RATE_SKIP   29 // skip 29 of 30 prints
54 
55 #define RPC_HISTORY_DEPTH 8
56 
57 typedef struct RpcHistoryEntry
58 {
59     NvU32 function;
60     NvU64 data[2];
61     NvU64 ts_start;
62     NvU64 ts_end;
63 } RpcHistoryEntry;
64 
65 struct OBJRPC{
66     OBJECT_BASE_DEFINITION(RPC);
67 
68     struct {
69         NvU32 ipVersion;
70     }__nvoc_pbase_Object[1]; // This nested structure mechanism is to bypass NVOC
71 
72     // Message buffer fields
73     NvU32 *message_buffer;
74     NvU32 *message_buffer_priv;
75     MEMORY_DESCRIPTOR *pMemDesc_mesg;
76     NvU32  maxRpcSize;
77     NvU32  largeRpcSize;
78 
79     // UVM Message buffer fields
80     NvU32 *message_buffer_uvm;
81     NvU32 *message_buffer_priv_uvm;
82     MEMORY_DESCRIPTOR *pMemDesc_mesg_uvm;
83 
84     /* Message Queue */
85     struct _message_queue_info *pMessageQueueInfo;
86 
87     RpcHistoryEntry rpcHistory[RPC_HISTORY_DEPTH];
88     NvU32 rpcHistoryCurrent;
89     RpcHistoryEntry rpcEventHistory[RPC_HISTORY_DEPTH];
90     NvU32 rpcEventHistoryCurrent;
91     NvU32 timeoutCount;
92     NvBool bQuietPrints;
93 
94     OBJRPCSTRUCTURECOPY rpcStructureCopy;
95 };
96 
97 //
98 // Utility macros for composing RPC messages.
99 // See <vgpu/dev_vgpu.h> for message formats.
100 // A message has a fixed-format header and optionally a variable length
101 // parameter after the header.
102 //
103 
104 #define vgpu_rpc_message_header_v  ((rpc_message_header_v*)(pRpc->message_buffer))
105 #define rpc_message                (vgpu_rpc_message_header_v->rpc_message_data)
106 
_objrpcStructureCopyAssignIpVersion(struct OBJRPCSTRUCTURECOPY * pRpcStructureCopy,NvU32 ipVersion)107 static inline void _objrpcStructureCopyAssignIpVersion(struct OBJRPCSTRUCTURECOPY* pRpcStructureCopy, NvU32 ipVersion)
108 {
109     pRpcStructureCopy->__nvoc_pbase_Object->ipVersion = ipVersion;
110 }
111 
_objrpcAssignIpVersion(struct OBJRPC * pRpc,NvU32 ipVersion)112 static inline void _objrpcAssignIpVersion(struct OBJRPC* pRpc, NvU32 ipVersion)
113 {
114     pRpc->__nvoc_pbase_Object->ipVersion = ipVersion;
115 }
116 
117 OBJRPC *initRpcObject(OBJGPU *pGpu);
118 void rpcSetIpVersion(OBJGPU *pGpu, OBJRPC *pRpc, NvU32 ipVersion);
119 void rpcObjIfacesSetup(OBJRPC *pRpc);
120 NV_STATUS rpcWriteCommonHeader(OBJGPU *pGpu, OBJRPC *pRpc, NvU32 func, NvU32 paramLength);
121 NV_STATUS rpcWriteCommonHeaderSim(OBJGPU *pGpu);
122 NV_STATUS vgpuGspSetupBuffers(OBJGPU *pGpu);
123 void vgpuGspTeardownBuffers(OBJGPU *pGpu);
124 NV_STATUS vgpuReinitializeRpcInfraOnStateLoad(OBJGPU *pGpu);
125 
126 // Initialize and free RPC infrastructure
127 NV_STATUS initRpcInfrastructure_VGPU(OBJGPU *pGpu);
128 NV_STATUS freeRpcInfrastructure_VGPU(OBJGPU *pGpu);
129 
130 NV_STATUS _allocRpcMemDesc(OBJGPU *pGpu, NvU64 size, NvBool bContig, NV_ADDRESS_SPACE addrSpace, NvU32 memFlags,
131                            MEMORY_DESCRIPTOR **ppMemDesc, void **ppMemBuffer, void **ppMemBufferPriv);
132 void _freeRpcMemDesc(OBJGPU *pGpu, MEMORY_DESCRIPTOR **ppMemDesc, void **ppMemBuffer, void **ppMemBufferPriv);
133 
134 NV_STATUS rpcDmaControl_wrapper(OBJGPU *pGpu, OBJRPC *pRpc, NvHandle hClient, NvHandle hObject, NvU32 cmd,
135                                void *pParamStructPtr, NvU32 paramSize);
136 //
137 // OBJGPU RPC member accessors.
138 // Historically, they have been defined inline by the following macros.
139 // These definitions were migrated to gpu.c in order to avoid having to include object headers in
140 // this file.
141 //
142 
143 OBJRPC *gpuGetGspClientRpc(OBJGPU*);
144 OBJRPC *gpuGetVgpuRpc(OBJGPU*);
145 OBJRPC *gpuGetRpc(OBJGPU*);
146 
147 #define GPU_GET_GSPCLIENT_RPC(u)   gpuGetGspClientRpc(u)
148 #define GPU_GET_VGPU_RPC(u)        gpuGetVgpuRpc(u)
149 #define GPU_GET_RPC(u)             gpuGetRpc(u)
150 
151 #endif // _OBJRPC_H_
152