1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2017-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 __vgpu_rpc_nv_headers_h__
25 #define __vgpu_rpc_nv_headers_h__
26 
27 #include "ctrl/ctrl0080/ctrl0080perf.h"
28 #include "ctrl/ctrl2080/ctrl2080perf.h"
29 #include "ctrl/ctrl2080/ctrl2080internal.h"
30 #include "nvstatus.h"
31 
32 #define MAX_GPC_COUNT           32
33 
34 /*
35  * Maximum number of RegOps that can be accommodated within one RPC call
36  * due to RPC message buffer size being limited to 4k
37  */
38 #define VGPU_MAX_REGOPS_PER_RPC 100
39 
40 #define VGPU_RESERVED_HANDLE_BASE   0xCAF3F000
41 #define VGPU_RESERVED_HANDLE_RANGE  0x1000
42 
43 #define VGPU_CALC_PARAM_OFFSET(prev_offset, prev_params)    (prev_offset + NV_ALIGN_UP(sizeof(prev_params), sizeof(NvU32)))
44 
45 /*
46  * Message header (in buffer addressed by ring entry)
47  *
48  * If message is invalid (bad length or signature), signature and length
49  * are forced to be valid (if in range of descriptor) and result is set to
50  * NV_VGPU_RESULT_INVALID_MESSAGE_FORMAT.  Otherwise, signature, length, and
51  * function are always unchanged and result is always set.
52  *
53  * The function message header, if defined, immediately follows the main message
54  * header.
55  */
56 #define NV_VGPU_MSG_HEADER_VERSION_MAJOR                             31:24 /* R---D */
57 #define NV_VGPU_MSG_HEADER_VERSION_MINOR                             23:16 /* R---D */
58 #define NV_VGPU_MSG_HEADER_VERSION_MAJOR_TOT                    0x00000003 /* R---D */
59 #define NV_VGPU_MSG_HEADER_VERSION_MINOR_TOT                    0x00000000 /* R---D */
60 /* signature must equal valid value */
61 #define NV_VGPU_MSG_SIGNATURE_VALID                             0x43505256 /* RW--V */
62 
63 #include "rpc_global_enums.h"
64 
65 /* result code */
66 /* codes below 0xFF000000 must match exactly the NV_STATUS codes in nvos.h */
67 #define NV_VGPU_MSG_RESULT__RM           NV_ERR_GENERIC:0x00000000 /* RW--D */
68 #define NV_VGPU_MSG_RESULT_SUCCESS                      NV_OK
69 #define NV_VGPU_MSG_RESULT_CARD_NOT_PRESENT             NV_ERR_CARD_NOT_PRESENT
70 #define NV_VGPU_MSG_RESULT_DUAL_LINK_INUSE              NV_ERR_DUAL_LINK_INUSE
71 #define NV_VGPU_MSG_RESULT_GENERIC                      NV_ERR_GENERIC
72 #define NV_VGPU_MSG_RESULT_GPU_NOT_FULL_POWER           NV_ERR_GPU_NOT_FULL_POWER
73 #define NV_VGPU_MSG_RESULT_IN_USE                       NV_ERR_IN_USE
74 #define NV_VGPU_MSG_RESULT_INSUFFICIENT_RESOURCES       NV_ERR_INSUFFICIENT_RESOURCES
75 #define NV_VGPU_MSG_RESULT_INVALID_ACCESS_TYPE          NV_ERR_INVALID_ACCESS_TYPE
76 #define NV_VGPU_MSG_RESULT_INVALID_ARGUMENT             NV_ERR_INVALID_ARGUMENT
77 #define NV_VGPU_MSG_RESULT_INVALID_BASE                 NV_ERR_INVALID_BASE
78 #define NV_VGPU_MSG_RESULT_INVALID_CHANNEL              NV_ERR_INVALID_CHANNEL
79 #define NV_VGPU_MSG_RESULT_INVALID_CLASS                NV_ERR_INVALID_CLASS
80 #define NV_VGPU_MSG_RESULT_INVALID_CLIENT               NV_ERR_INVALID_CLIENT
81 #define NV_VGPU_MSG_RESULT_INVALID_COMMAND              NV_ERR_INVALID_COMMAND
82 #define NV_VGPU_MSG_RESULT_INVALID_DATA                 NV_ERR_INVALID_DATA
83 #define NV_VGPU_MSG_RESULT_INVALID_DEVICE               NV_ERR_INVALID_DEVICE
84 #define NV_VGPU_MSG_RESULT_INVALID_DMA_SPECIFIER        NV_ERR_INVALID_DMA_SPECIFIER
85 #define NV_VGPU_MSG_RESULT_INVALID_EVENT                NV_ERR_INVALID_EVENT
86 #define NV_VGPU_MSG_RESULT_INVALID_FLAGS                NV_ERR_INVALID_FLAGS
87 #define NV_VGPU_MSG_RESULT_INVALID_FUNCTION             NV_ERR_INVALID_FUNCTION
88 #define NV_VGPU_MSG_RESULT_INVALID_HEAP                 NV_ERR_INVALID_HEAP
89 #define NV_VGPU_MSG_RESULT_INVALID_INDEX                NV_ERR_INVALID_INDEX
90 #define NV_VGPU_MSG_RESULT_INVALID_LIMIT                NV_ERR_INVALID_LIMIT
91 #define NV_VGPU_MSG_RESULT_INVALID_METHOD               NV_ERR_INVALID_METHOD
92 #define NV_VGPU_MSG_RESULT_INVALID_OBJECT_BUFFER        NV_ERR_INVALID_OBJECT_BUFFER
93 #define NV_VGPU_MSG_RESULT_INVALID_OBJECT_ERROR         NV_ERR_INVALID_OBJECT
94 #define NV_VGPU_MSG_RESULT_INVALID_OBJECT_HANDLE        NV_ERR_INVALID_OBJECT_HANDLE
95 #define NV_VGPU_MSG_RESULT_INVALID_OBJECT_NEW           NV_ERR_INVALID_OBJECT_NEW
96 #define NV_VGPU_MSG_RESULT_INVALID_OBJECT_OLD           NV_ERR_INVALID_OBJECT_OLD
97 #define NV_VGPU_MSG_RESULT_INVALID_OBJECT_PARENT        NV_ERR_INVALID_OBJECT_PARENT
98 #define NV_VGPU_MSG_RESULT_INVALID_OFFSET               NV_ERR_INVALID_OFFSET
99 #define NV_VGPU_MSG_RESULT_INVALID_OWNER                NV_ERR_INVALID_OWNER
100 #define NV_VGPU_MSG_RESULT_INVALID_PARAM_STRUCT         NV_ERR_INVALID_PARAM_STRUCT
101 #define NV_VGPU_MSG_RESULT_INVALID_PARAMETER            NV_ERR_INVALID_PARAMETER
102 #define NV_VGPU_MSG_RESULT_INVALID_POINTER              NV_ERR_INVALID_POINTER
103 #define NV_VGPU_MSG_RESULT_INVALID_REGISTRY_KEY         NV_ERR_INVALID_REGISTRY_KEY
104 #define NV_VGPU_MSG_RESULT_INVALID_STATE                NV_ERR_INVALID_STATE
105 #define NV_VGPU_MSG_RESULT_INVALID_STRING_LENGTH        NV_ERR_INVALID_STRING_LENGTH
106 #define NV_VGPU_MSG_RESULT_INVALID_XLATE                NV_ERR_INVALID_XLATE
107 #define NV_VGPU_MSG_RESULT_IRQ_NOT_FIRING               NV_ERR_IRQ_NOT_FIRING
108 #define NV_VGPU_MSG_RESULT_MULTIPLE_MEMORY_TYPES        NV_ERR_MULTIPLE_MEMORY_TYPES
109 #define NV_VGPU_MSG_RESULT_NOT_SUPPORTED                NV_ERR_NOT_SUPPORTED
110 #define NV_VGPU_MSG_RESULT_OPERATING_SYSTEM             NV_ERR_OPERATING_SYSTEM
111 #define NV_VGPU_MSG_RESULT_PROTECTION_FAULT             NV_ERR_PROTECTION_FAULT
112 #define NV_VGPU_MSG_RESULT_TIMEOUT                      NV_ERR_TIMEOUT
113 #define NV_VGPU_MSG_RESULT_TOO_MANY_PRIMARIES           NV_ERR_TOO_MANY_PRIMARIES
114 #define NV_VGPU_MSG_RESULT_IRQ_EDGE_TRIGGERED           NV_ERR_IRQ_EDGE_TRIGGERED
115 #define NV_VGPU_MSG_RESULT_GUEST_HOST_DRIVER_MISMATCH   NV_ERR_LIB_RM_VERSION_MISMATCH
116 
117 /*
118  * codes above 0xFF000000 and below 0xFF100000 must match one-for-one
119  * the vmiop_error_t codes in vmioplugin.h, with 0xFF000000 added.
120  */
121 #define NV_VGPU_MSG_RESULT__VMIOP             0xFF00000a:0xFF000000 /* RW--D */
122 #define NV_VGPU_MSG_RESULT_VMIOP_INVAL                   0xFF000001 /* RW--V */
123 #define NV_VGPU_MSG_RESULT_VMIOP_RESOURCE                0xFF000002 /* RW--V */
124 #define NV_VGPU_MSG_RESULT_VMIOP_RANGE                   0xFF000003 /* RW--V */
125 #define NV_VGPU_MSG_RESULT_VMIOP_READ_ONLY               0xFF000004 /* RW--V */
126 #define NV_VGPU_MSG_RESULT_VMIOP_NOT_FOUND               0xFF000005 /* RW--V */
127 #define NV_VGPU_MSG_RESULT_VMIOP_NO_ADDRESS_SPACE        0xFF000006 /* RW--V */
128 #define NV_VGPU_MSG_RESULT_VMIOP_TIMEOUT                 0xFF000007 /* RW--V */
129 #define NV_VGPU_MSG_RESULT_VMIOP_NOT_ALLOWED_IN_CALLBACK 0xFF000008 /* RW--V */
130 #define NV_VGPU_MSG_RESULT_VMIOP_ECC_MISMATCH            0xFF000009 /* RW--V */
131 #define NV_VGPU_MSG_RESULT_VMIOP_NOT_SUPPORTED           0xFF00000a /* RW--V */
132 /* RPC-specific error codes */
133 #define NV_VGPU_MSG_RESULT__RPC               0xFF100009:0xFF100000 /* RW--D */
134 #define NV_VGPU_MSG_RESULT_RPC_UNKNOWN_FUNCTION          0xFF100001 /* RW--V */
135 #define NV_VGPU_MSG_RESULT_RPC_INVALID_MESSAGE_FORMAT    0xFF100002 /* RW--V */
136 #define NV_VGPU_MSG_RESULT_RPC_HANDLE_NOT_FOUND          0xFF100003 /* RW--V */
137 #define NV_VGPU_MSG_RESULT_RPC_HANDLE_EXISTS             0xFF100004 /* RW--V */
138 #define NV_VGPU_MSG_RESULT_RPC_UNKNOWN_RM_ERROR          0xFF100005 /* RW--V */
139 #define NV_VGPU_MSG_RESULT_RPC_UNKNOWN_VMIOP_ERROR       0xFF100006 /* RW--V */
140 #define NV_VGPU_MSG_RESULT_RPC_RESERVED_HANDLE           0xFF100007 /* RW--V */
141 #define NV_VGPU_MSG_RESULT_RPC_CUDA_PROFILING_DISABLED   0xFF100008 /* RW--V */
142 // This error code is used by plugin to notify the guest the that API control
143 // is recognized but not supported. It used by the guest to avoid printing
144 // error message about a failed API control.
145 #define NV_VGPU_MSG_RESULT_RPC_API_CONTROL_NOT_SUPPORTED 0xFF100009 /* RW--V */
146 /* RPC-specific code in result for incomplete request */
147 #define NV_VGPU_MSG_RESULT_RPC_PENDING                   0xFFFFFFFF /* RW--V */
148 /* shared union field */
149 #define NV_VGPU_MSG_UNION_INIT                           0x00000000 /* RW--V */
150 
151 /*
152  * common PTEDESC message defines (used w/ ALLOC_MEMORY, ALLOC_VIDMEM, FILL_PTE_MEM)
153  */
154 #define NV_VGPU_PTEDESC_INIT                             0x00000000 /* RWI-V */
155 #define NV_VGPU_PTEDESC__PROD                            0x00000000 /* RW--V */
156 #define NV_VGPU_PTEDESC_IDR_NONE                         0x00000000 /* RW--V */
157 #define NV_VGPU_PTEDESC_IDR_SINGLE                       0x00000001 /* RW--V */
158 #define NV_VGPU_PTEDESC_IDR_DOUBLE                       0x00000002 /* RW--V */
159 #define NV_VGPU_PTEDESC_IDR_TRIPLE                       0x00000003 /* RW--V */
160 
161 #define NV_VGPU_PTE_PAGE_SIZE                                0x1000 /* R---V */
162 #define NV_VGPU_PTE_SIZE                                          4 /* R---V */
163 #define NV_VGPU_PTE_INDEX_SHIFT                                  10 /* R---V */
164 #define NV_VGPU_PTE_INDEX_MASK                                0x3FF /* R---V */
165 
166 #define NV_VGPU_PTE_64_PAGE_SIZE                             0x1000 /* R---V */
167 #define NV_VGPU_PTE_64_SIZE                                       8 /* R---V */
168 #define NV_VGPU_PTE_64_INDEX_SHIFT                                9 /* R---V */
169 #define NV_VGPU_PTE_64_INDEX_MASK                             0x1FF /* R---V */
170 
171 /*
172  * LOG message
173  */
174 #define NV_VGPU_LOG_LEVEL_FATAL                          0x00000000 /* RW--V */
175 #define NV_VGPU_LOG_LEVEL_ERROR                          0x00000001 /* RW--V */
176 #define NV_VGPU_LOG_LEVEL_NOTICE                         0x00000002 /* RW--V */
177 #define NV_VGPU_LOG_LEVEL_STATUS                         0x00000003 /* RW--V */
178 #define NV_VGPU_LOG_LEVEL_DEBUG                          0x00000004 /* RW--V */
179 
180 typedef enum
181 {
182     RPC_GR_BUFFER_TYPE_GRAPHICS                 = 0,
183     RPC_GR_BUFFER_TYPE_GRAPHICS_ZCULL           = 1,
184     RPC_GR_BUFFER_TYPE_GRAPHICS_GRAPHICS_PM     = 2,
185     RPC_GR_BUFFER_TYPE_COMPUTE_PREEMPT          = 3,
186     RPC_GR_BUFFER_TYPE_GRAPHICS_PATCH           = 4,
187     RPC_GR_BUFFER_TYPE_GRAPHICS_BUNDLE_CB       = 5,
188     RPC_GR_BUFFER_TYPE_GRAPHICS_PAGEPOOL_GLOBAL = 6,
189     RPC_GR_BUFFER_TYPE_GRAPHICS_ATTRIBUTE_CB    = 7,
190     RPC_GR_BUFFER_TYPE_GRAPHICS_RTV_CB_GLOBAL   = 8,
191     RPC_GR_BUFFER_TYPE_GRAPHICS_GFXP_POOL       = 9,
192     RPC_GR_BUFFER_TYPE_GRAPHICS_GFXP_CTRL_BLK   = 10,
193     RPC_GR_BUFFER_TYPE_GRAPHICS_FECS_EVENT      = 11,
194     RPC_GR_BUFFER_TYPE_GRAPHICS_PRIV_ACCESS_MAP = 12,
195     RPC_GR_BUFFER_TYPE_GRAPHICS_MAX             = 13,
196 } RPC_GR_BUFFER_TYPE;
197 
198 /*
199  * Maximum entries that can be sent in a single pass of RPC.
200  */
201 #define VGPU_RPC_GET_P2P_CAPS_V2_MAX_GPUS_SQUARED_PER_RPC               512
202 
203 /* Fetching NV2080_CTRL_GR_MAX_CTX_BUFFER_COUNT in single RPC mesaage
204  * causes RPC buffer to overflow. To accommodate, we will have to convert
205  * current RPC to multipass. But currently, RM allocates only
206  * (3 + GR_GLOBALCTX_BUFFER_COUNT) < 32 buffers and they accommodate in single
207  * RPC message size. Hence, not converting current RPC to multipass.
208  * and limiting the max buffer count per RPC to 32.
209  */
210 #define GR_MAX_RPC_CTX_BUFFER_COUNT   32
211 
212 /*
213  * Enums specifying the BAR number that we are going to update its PDE
214  */
215 typedef enum
216 {
217     NV_RPC_UPDATE_PDE_BAR_1,
218     NV_RPC_UPDATE_PDE_BAR_2,
219     NV_RPC_UPDATE_PDE_BAR_INVALID,
220 } NV_RPC_UPDATE_PDE_BAR_TYPE;
221 
222 typedef struct VIRTUAL_DISPLAY_GET_MAX_RESOLUTION_PARAMS
223 {
224     NvU32 headIndex;
225     NvU32 maxHResolution;
226     NvU32 maxVResolution;
227 } VIRTUAL_DISPLAY_GET_MAX_RESOLUTION_PARAMS;
228 
229 typedef struct VIRTUAL_DISPLAY_GET_NUM_HEADS_PARAMS
230 {
231     NvU32 numHeads;
232     NvU32 maxNumHeads;
233 } VIRTUAL_DISPLAY_GET_NUM_HEADS_PARAMS;
234 
235 
236 /*
237  *  Maximum number of SMs that can be read in one RPC call to get error states
238  */
239 
240 #define VGPU_RPC_CTRL_DEBUG_READ_ALL_SM_ERROR_STATES_PER_RPC_v21_06 80
241 
242 #endif // __vgpu_rpc_nv_headers_h__
243