1 #ifndef _G_FBSR_NVOC_H_
2 #define _G_FBSR_NVOC_H_
3 #include "nvoc/runtime.h"
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 /*
10  * SPDX-FileCopyrightText: Copyright (c) 2009-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_fbsr_nvoc.h"
33 
34 #ifndef FBSR_H
35 #define FBSR_H
36 
37 #include "core/core.h"
38 #include "gpu/gpu.h"
39 
40 
41 
42 /**************** Resource Manager Defines and Structures ******************\
43 *                                                                           *
44 * Module: OBJFBSR.H                                                         *
45 *       Defines and structures used for the FB Save/Restore Engine Object.  *
46 \***************************************************************************/
47 
48 typedef enum
49 {
50     FBSR_OP_SIZE_BUF = 0,
51     FBSR_OP_SAVE,
52     FBSR_OP_RESTORE,
53     FBSR_OP_DESTROY,
54 } FBSR_OP_TYPE;
55 
56 typedef struct _def_fbsr_node
57 {
58     struct _def_fbsr_node *pNext;
59     NvU32                  data[1];
60 } FBSR_NODE, *PFBSR_NODE;
61 
62 typedef struct
63 {
64     void*   sectionHandle;
65     void*   pMdl;               // MDL
66     NvP64   sysAddr;
67     NvU64   maxLength;          // MAX VA size allocated
68     NvU64   avblViewSz;         // Chunk of mapped view that's unprocessed i.e., not restored or can be saved.
69 } BACKINGSTORE_SECTION_INFO;
70 
71 // Struct to hold info on a region being saved/restored
72 typedef struct
73 {
74     MEMORY_DESCRIPTOR *pVidMemDesc;     // MEMORY_DESCRIPTOR of FBMEM region being saved/restored
75     MEMORY_DESCRIPTOR *pSysMemDesc;     // MEMORY_DESCRIPTOR of SYSMEM region used to save FB region to/restore from
76     NvU64              vidOffset;       // Offset in FBMEM region to save/restore
77     NvU64              sysOffset;       // Offset in SYSMEM region to save to/restore from
78     NvU64              size;            // Size of region being saved/restored
79 } FBSR_REGION_RECORD;
80 
81 typedef struct OBJFBSR *POBJFBSR;
82 
83 #ifndef __NVOC_CLASS_OBJFBSR_TYPEDEF__
84 #define __NVOC_CLASS_OBJFBSR_TYPEDEF__
85 typedef struct OBJFBSR OBJFBSR;
86 #endif /* __NVOC_CLASS_OBJFBSR_TYPEDEF__ */
87 
88 #ifndef __nvoc_class_id_OBJFBSR
89 #define __nvoc_class_id_OBJFBSR 0xa30fe6
90 #endif /* __nvoc_class_id_OBJFBSR */
91 
92 
93 
94 
95 // Private field names are wrapped in PRIVATE_FIELD, which does nothing for
96 // the matching C source file, but causes diagnostics to be issued if another
97 // source file references the field.
98 #ifdef NVOC_FBSR_H_PRIVATE_ACCESS_ALLOWED
99 #define PRIVATE_FIELD(x) x
100 #else
101 #define PRIVATE_FIELD(x) NVOC_PRIVATE_FIELD(x)
102 #endif
103 
104 struct OBJFBSR {
105     const struct NVOC_RTTI *__nvoc_rtti;
106     struct Object __nvoc_base_Object;
107     struct Object *__nvoc_pbase_Object;
108     struct OBJFBSR *__nvoc_pbase_OBJFBSR;
109     NV_STATUS (*__fbsrBegin__)(struct OBJGPU *, struct OBJFBSR *, FBSR_OP_TYPE);
110     NV_STATUS (*__fbsrEnd__)(struct OBJGPU *, struct OBJFBSR *);
111     NV_STATUS (*__fbsrSendMemsysProgramRawCompressionMode__)(struct OBJGPU *, struct OBJFBSR *, NvBool);
112     NvU32 type;
113     struct OBJCE *pCe;
114     FBSR_OP_TYPE op;
115     MEMORY_DESCRIPTOR *pSysMemDesc;
116     FBSR_NODE *pSysMemNodeHead;
117     FBSR_NODE *pSysMemNodeCurrent;
118     BACKINGSTORE_SECTION_INFO pagedBufferInfo;
119     FBSR_REGION_RECORD *pRegionRecords;
120     NvU32 *pPinnedBuffer;
121     NvU8 *pDmaBuffer;
122     void *pMapCookie;
123     NvU64 length;
124     NvU64 sysOffset;
125     NvU64 gspFbAllocsSysOffset;
126     NvU32 numRegions;
127     NvU32 regionRecordIndex;
128     NvBool bOperationFailed;
129     NvBool bValid;
130     NvBool bInitialized;
131     NvBool bRawModeWasEnabled;
132     MEMORY_DESCRIPTOR *pSysReservedMemDesc;
133 };
134 
135 #ifndef __NVOC_CLASS_OBJFBSR_TYPEDEF__
136 #define __NVOC_CLASS_OBJFBSR_TYPEDEF__
137 typedef struct OBJFBSR OBJFBSR;
138 #endif /* __NVOC_CLASS_OBJFBSR_TYPEDEF__ */
139 
140 #ifndef __nvoc_class_id_OBJFBSR
141 #define __nvoc_class_id_OBJFBSR 0xa30fe6
142 #endif /* __nvoc_class_id_OBJFBSR */
143 
144 extern const struct NVOC_CLASS_DEF __nvoc_class_def_OBJFBSR;
145 
146 #define __staticCast_OBJFBSR(pThis) \
147     ((pThis)->__nvoc_pbase_OBJFBSR)
148 
149 #ifdef __nvoc_fbsr_h_disabled
150 #define __dynamicCast_OBJFBSR(pThis) ((OBJFBSR*)NULL)
151 #else //__nvoc_fbsr_h_disabled
152 #define __dynamicCast_OBJFBSR(pThis) \
153     ((OBJFBSR*)__nvoc_dynamicCast(staticCast((pThis), Dynamic), classInfo(OBJFBSR)))
154 #endif //__nvoc_fbsr_h_disabled
155 
156 
157 NV_STATUS __nvoc_objCreateDynamic_OBJFBSR(OBJFBSR**, Dynamic*, NvU32, va_list);
158 
159 NV_STATUS __nvoc_objCreate_OBJFBSR(OBJFBSR**, Dynamic*, NvU32);
160 #define __objCreate_OBJFBSR(ppNewObj, pParent, createFlags) \
161     __nvoc_objCreate_OBJFBSR((ppNewObj), staticCast((pParent), Dynamic), (createFlags))
162 
163 #define fbsrBegin(pGpu, pFbsr, op) fbsrBegin_DISPATCH(pGpu, pFbsr, op)
164 #define fbsrBegin_HAL(pGpu, pFbsr, op) fbsrBegin_DISPATCH(pGpu, pFbsr, op)
165 #define fbsrEnd(pGpu, pFbsr) fbsrEnd_DISPATCH(pGpu, pFbsr)
166 #define fbsrEnd_HAL(pGpu, pFbsr) fbsrEnd_DISPATCH(pGpu, pFbsr)
167 #define fbsrSendMemsysProgramRawCompressionMode(pGpu, pFbsr, bRawMode) fbsrSendMemsysProgramRawCompressionMode_DISPATCH(pGpu, pFbsr, bRawMode)
168 #define fbsrSendMemsysProgramRawCompressionMode_HAL(pGpu, pFbsr, bRawMode) fbsrSendMemsysProgramRawCompressionMode_DISPATCH(pGpu, pFbsr, bRawMode)
169 NV_STATUS fbsrInit_GM107(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr);
170 
171 
172 #ifdef __nvoc_fbsr_h_disabled
fbsrInit(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr)173 static inline NV_STATUS fbsrInit(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr) {
174     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
175     return NV_ERR_NOT_SUPPORTED;
176 }
177 #else //__nvoc_fbsr_h_disabled
178 #define fbsrInit(pGpu, pFbsr) fbsrInit_GM107(pGpu, pFbsr)
179 #endif //__nvoc_fbsr_h_disabled
180 
181 #define fbsrInit_HAL(pGpu, pFbsr) fbsrInit(pGpu, pFbsr)
182 
183 void fbsrDestroy_GM107(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr);
184 
185 
186 #ifdef __nvoc_fbsr_h_disabled
fbsrDestroy(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr)187 static inline void fbsrDestroy(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr) {
188     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
189 }
190 #else //__nvoc_fbsr_h_disabled
191 #define fbsrDestroy(pGpu, pFbsr) fbsrDestroy_GM107(pGpu, pFbsr)
192 #endif //__nvoc_fbsr_h_disabled
193 
194 #define fbsrDestroy_HAL(pGpu, pFbsr) fbsrDestroy(pGpu, pFbsr)
195 
196 void fbsrCopyMemoryMemDesc_GM107(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, MEMORY_DESCRIPTOR *pVidMemDesc);
197 
198 
199 #ifdef __nvoc_fbsr_h_disabled
fbsrCopyMemoryMemDesc(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr,MEMORY_DESCRIPTOR * pVidMemDesc)200 static inline void fbsrCopyMemoryMemDesc(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, MEMORY_DESCRIPTOR *pVidMemDesc) {
201     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
202 }
203 #else //__nvoc_fbsr_h_disabled
204 #define fbsrCopyMemoryMemDesc(pGpu, pFbsr, pVidMemDesc) fbsrCopyMemoryMemDesc_GM107(pGpu, pFbsr, pVidMemDesc)
205 #endif //__nvoc_fbsr_h_disabled
206 
207 #define fbsrCopyMemoryMemDesc_HAL(pGpu, pFbsr, pVidMemDesc) fbsrCopyMemoryMemDesc(pGpu, pFbsr, pVidMemDesc)
208 
fbsrExecuteSaveRestore_46f6a7(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr)209 static inline NV_STATUS fbsrExecuteSaveRestore_46f6a7(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr) {
210     return NV_ERR_NOT_SUPPORTED;
211 }
212 
213 
214 #ifdef __nvoc_fbsr_h_disabled
fbsrExecuteSaveRestore(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr)215 static inline NV_STATUS fbsrExecuteSaveRestore(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr) {
216     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
217     return NV_ERR_NOT_SUPPORTED;
218 }
219 #else //__nvoc_fbsr_h_disabled
220 #define fbsrExecuteSaveRestore(pGpu, pFbsr) fbsrExecuteSaveRestore_46f6a7(pGpu, pFbsr)
221 #endif //__nvoc_fbsr_h_disabled
222 
223 #define fbsrExecuteSaveRestore_HAL(pGpu, pFbsr) fbsrExecuteSaveRestore(pGpu, pFbsr)
224 
225 NV_STATUS fbsrBegin_GA100(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, FBSR_OP_TYPE op);
226 
227 NV_STATUS fbsrBegin_GM107(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, FBSR_OP_TYPE op);
228 
fbsrBegin_DISPATCH(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr,FBSR_OP_TYPE op)229 static inline NV_STATUS fbsrBegin_DISPATCH(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, FBSR_OP_TYPE op) {
230     return pFbsr->__fbsrBegin__(pGpu, pFbsr, op);
231 }
232 
233 NV_STATUS fbsrEnd_GA100(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr);
234 
235 NV_STATUS fbsrEnd_GM107(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr);
236 
fbsrEnd_DISPATCH(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr)237 static inline NV_STATUS fbsrEnd_DISPATCH(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr) {
238     return pFbsr->__fbsrEnd__(pGpu, pFbsr);
239 }
240 
241 NV_STATUS fbsrSendMemsysProgramRawCompressionMode_GA100(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, NvBool bRawMode);
242 
fbsrSendMemsysProgramRawCompressionMode_56cd7a(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr,NvBool bRawMode)243 static inline NV_STATUS fbsrSendMemsysProgramRawCompressionMode_56cd7a(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, NvBool bRawMode) {
244     return NV_OK;
245 }
246 
fbsrSendMemsysProgramRawCompressionMode_DISPATCH(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr,NvBool bRawMode)247 static inline NV_STATUS fbsrSendMemsysProgramRawCompressionMode_DISPATCH(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, NvBool bRawMode) {
248     return pFbsr->__fbsrSendMemsysProgramRawCompressionMode__(pGpu, pFbsr, bRawMode);
249 }
250 
251 NV_STATUS fbsrObjectInit_IMPL(struct OBJFBSR *pFbsr, NvU32 arg0);
252 
253 #ifdef __nvoc_fbsr_h_disabled
fbsrObjectInit(struct OBJFBSR * pFbsr,NvU32 arg0)254 static inline NV_STATUS fbsrObjectInit(struct OBJFBSR *pFbsr, NvU32 arg0) {
255     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
256     return NV_ERR_NOT_SUPPORTED;
257 }
258 #else //__nvoc_fbsr_h_disabled
259 #define fbsrObjectInit(pFbsr, arg0) fbsrObjectInit_IMPL(pFbsr, arg0)
260 #endif //__nvoc_fbsr_h_disabled
261 
262 NV_STATUS fbsrReserveSysMemoryForPowerMgmt_IMPL(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, NvU64 arg0);
263 
264 #ifdef __nvoc_fbsr_h_disabled
fbsrReserveSysMemoryForPowerMgmt(struct OBJGPU * pGpu,struct OBJFBSR * pFbsr,NvU64 arg0)265 static inline NV_STATUS fbsrReserveSysMemoryForPowerMgmt(struct OBJGPU *pGpu, struct OBJFBSR *pFbsr, NvU64 arg0) {
266     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
267     return NV_ERR_NOT_SUPPORTED;
268 }
269 #else //__nvoc_fbsr_h_disabled
270 #define fbsrReserveSysMemoryForPowerMgmt(pGpu, pFbsr, arg0) fbsrReserveSysMemoryForPowerMgmt_IMPL(pGpu, pFbsr, arg0)
271 #endif //__nvoc_fbsr_h_disabled
272 
273 void fbsrFreeReservedSysMemoryForPowerMgmt_IMPL(struct OBJFBSR *pFbsr);
274 
275 #ifdef __nvoc_fbsr_h_disabled
fbsrFreeReservedSysMemoryForPowerMgmt(struct OBJFBSR * pFbsr)276 static inline void fbsrFreeReservedSysMemoryForPowerMgmt(struct OBJFBSR *pFbsr) {
277     NV_ASSERT_FAILED_PRECOMP("OBJFBSR was disabled!");
278 }
279 #else //__nvoc_fbsr_h_disabled
280 #define fbsrFreeReservedSysMemoryForPowerMgmt(pFbsr) fbsrFreeReservedSysMemoryForPowerMgmt_IMPL(pFbsr)
281 #endif //__nvoc_fbsr_h_disabled
282 
283 #undef PRIVATE_FIELD
284 
285 
286 // Method used for copying
287 #define FBSR_TYPE_WDDM_FAST_DMA_DEFERRED_NONPAGED     0   // Pre-reserve paged region during boot. Map and pin the region and DMA copy to it from FB and unpin it.
288 #define FBSR_TYPE_WDDM_SLOW_CPU_PAGED                 1   // Pre-reserve paged region during boot. Map in chunks of 64K and DMA copy to a scratch space of 64K and cpu copy to the paged region
289 #define FBSR_TYPE_PAGED_DMA                           2   // Copy using DMA approach, allocated from paged pool
290 #define FBSR_TYPE_PERSISTENT                          3   // Copy using DMA approach, memory will be persistent after allocation to avoid from system VM fragmentation.
291 #define FBSR_TYPE_DMA                                 4   // Copy using DMA. Fastest.
292 #define FBSR_TYPE_CPU                                 5   // CPU. Used when we don't have enough resources for DMA.
293 #define FBSR_TYPE_FILE                                6   // DMA from FB to scratch sysmem buffer of 64K size , which in turn copies to temporary file backed system memory
294 #define FBSR_TYPE_GSP                                 7   // FBSR for GSP regions
295 
296 #define NUM_FBSR_TYPES              (FBSR_TYPE_GSP + 1)   // FBSR_TYPE_GSP to be last FBSR Type, insert any new FBSR types above FBSR_TYPE_GSP
297 
298 #endif // FBSR_H
299 
300 #ifdef __cplusplus
301 } // extern "C"
302 #endif
303 
304 #endif // _G_FBSR_NVOC_H_
305