1 #ifndef _G_FECS_EVENT_LIST_NVOC_H_
2 #define _G_FECS_EVENT_LIST_NVOC_H_
3 #include "nvoc/runtime.h"
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 /*
10  * SPDX-FileCopyrightText: Copyright (c) 2013-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_fecs_event_list_nvoc.h"
33 
34 #ifndef _FECS_EVENT_LIST_H_
35 #define _FECS_EVENT_LIST_H_
36 
37 /*!
38  * @file   fecs_event_list.h
39  * @brief  Provides definition for FECS callback on EventBuffer, as well as a list holding the subscribers to the event
40  */
41 
42 #include "core/core.h"
43 #include "class/cl90cd.h"
44 #include "class/cl90cdfecs.h"
45 #include "containers/multimap.h"
46 #include "resserv/resserv.h"
47 #include "rmapi/client.h"
48 
49 #include "ctrl/ctrl2080/ctrl2080gr.h" // NV2080_CTRL_GR_FECS_BIND_EVTBUF_LOD
50 
51 struct KernelGraphics;
52 
53 #ifndef __NVOC_CLASS_KernelGraphics_TYPEDEF__
54 #define __NVOC_CLASS_KernelGraphics_TYPEDEF__
55 typedef struct KernelGraphics KernelGraphics;
56 #endif /* __NVOC_CLASS_KernelGraphics_TYPEDEF__ */
57 
58 #ifndef __nvoc_class_id_KernelGraphics
59 #define __nvoc_class_id_KernelGraphics 0xea3fa9
60 #endif /* __nvoc_class_id_KernelGraphics */
61 
62 
63 struct KernelGraphicsManager;
64 
65 #ifndef __NVOC_CLASS_KernelGraphicsManager_TYPEDEF__
66 #define __NVOC_CLASS_KernelGraphicsManager_TYPEDEF__
67 typedef struct KernelGraphicsManager KernelGraphicsManager;
68 #endif /* __NVOC_CLASS_KernelGraphicsManager_TYPEDEF__ */
69 
70 #ifndef __nvoc_class_id_KernelGraphicsManager
71 #define __nvoc_class_id_KernelGraphicsManager 0xd22179
72 #endif /* __nvoc_class_id_KernelGraphicsManager */
73 
74 
75 struct EventBuffer;
76 
77 #ifndef __NVOC_CLASS_EventBuffer_TYPEDEF__
78 #define __NVOC_CLASS_EventBuffer_TYPEDEF__
79 typedef struct EventBuffer EventBuffer;
80 #endif /* __NVOC_CLASS_EventBuffer_TYPEDEF__ */
81 
82 #ifndef __nvoc_class_id_EventBuffer
83 #define __nvoc_class_id_EventBuffer 0x63502b
84 #endif /* __nvoc_class_id_EventBuffer */
85 
86 
87 struct Subdevice;
88 
89 #ifndef __NVOC_CLASS_Subdevice_TYPEDEF__
90 #define __NVOC_CLASS_Subdevice_TYPEDEF__
91 typedef struct Subdevice Subdevice;
92 #endif /* __NVOC_CLASS_Subdevice_TYPEDEF__ */
93 
94 #ifndef __nvoc_class_id_Subdevice
95 #define __nvoc_class_id_Subdevice 0x4b01b3
96 #endif /* __nvoc_class_id_Subdevice */
97 
98 
99 
100 // TODO move to cl90cdfecs.h
101 #define NV_EVENT_BUFFER_INVALID_MIG_GI      0xFF
102 #define NV_EVENT_BUFFER_INVALID_MIG_CI      0xFF
103 #define NV_EVENT_BUFFER_HIDDEN_MIG_GI       0xFE
104 #define NV_EVENT_BUFFER_HIDDEN_MIG_CI       0xFE
105 #define NV_EVENT_BUFFER_KERNEL_MIG_GI       0xFD
106 #define NV_EVENT_BUFFER_KERNEL_MIG_CI       0xFD
107 
108 typedef struct
109 {
110     struct EventBuffer *pEventBuffer;
111     NvHandle hClient;
112     NvHandle hNotifier;
113     NvHandle hEventBuffer;
114 
115     NvU64    pUserInfo;
116 
117     NvBool   bAdmin;
118     NvBool   bKernel;
119     NvU32    eventMask;
120 
121     NvU8     version;
122     NvU32    swizzId;
123     NvU32    computeInstanceId;
124 
125 } NV_EVENT_BUFFER_BIND_POINT_FECS;
126 MAKE_MULTIMAP(FecsEventBufferBindMultiMap, NV_EVENT_BUFFER_BIND_POINT_FECS);
127 MAKE_MAP(EventBufferMap, EventBuffer*);
128 
129 typedef struct
130 {
131     NvU8    tag;
132     NvU64   userInfo;
133     NvU32   context_id;
134     NvU32   pid;
135     NvU32   subpid;
136     NvU8    swizzId;
137     NvU8    computeInstanceId;
138     NvU16   dropCount;
139     NvU64   timestamp;
140     NvU64   noisyTimestamp;
141 } FECS_EVENT_NOTIFICATION_DATA;
142 
143 typedef struct
144 {
145     NV_EVENT_BUFFER_RECORD_HEADER header;
146     NV_EVENT_BUFFER_FECS_RECORD_V2 record;
147 } FECS_EVENT_RECORD_OUTPUT;
148 ct_assert(NV_OFFSETOF(FECS_EVENT_RECORD_OUTPUT, record) == sizeof(NV_EVENT_BUFFER_RECORD_HEADER));
149 ct_assert(sizeof(FECS_EVENT_RECORD_OUTPUT) == sizeof(NV_EVENT_BUFFER_RECORD_HEADER) + sizeof(NV_EVENT_BUFFER_FECS_RECORD_V2));
150 
151 
152 NV_STATUS fecsAddBindpoint
153 (
154     OBJGPU *pGpu,
155     struct RmClient *pClient,
156     RsResourceRef *pEventBufferRef,
157     struct Subdevice *pNotifier,
158     NvBool bAllUsers,
159     NV2080_CTRL_GR_FECS_BIND_EVTBUF_LOD levelOfDetail,
160     NvU32 eventFilter,
161     NvU8 version,
162     NvU32 *pReasonCode
163 );
164 
165 // Set cached internal routing handles and GR index for MIG
166 void fecsSetRoutingInfo
167 (
168     OBJGPU *pGpu,
169     struct KernelGraphics *pKernelGraphics,
170     NvHandle hClient,
171     NvHandle hSubdevice,
172     NvU32 localGrEngineIdx
173 );
174 
175 // Clear cached internal routing handles and GR index for MIG
176 void fecsClearRoutingInfo(OBJGPU *, struct KernelGraphics *);
177 
178 /*! Opaque FECS event buffer private data */
179 typedef struct KGRAPHICS_FECS_TRACE_INFO KGRAPHICS_FECS_TRACE_INFO;
180 typedef struct KGRMGR_FECS_GLOBAL_TRACE_INFO KGRMGR_FECS_GLOBAL_TRACE_INFO;
181 
182 NV_STATUS fecsCtxswLoggingInit
183 (
184     OBJGPU *pGpu,
185     struct KernelGraphics *pKernelGraphics,
186     KGRAPHICS_FECS_TRACE_INFO **ppFecsTraceInfo
187 );
188 
189 void fecsCtxswLoggingTeardown(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
190 
191 NV_STATUS fecsGlobalLoggingInit
192 (
193     OBJGPU *pGpu,
194     struct KernelGraphicsManager *pKernelGraphicsManager,
195     KGRMGR_FECS_GLOBAL_TRACE_INFO **ppFecsGlobalTraceInfo
196 );
197 
198 void fecsGlobalLoggingTeardown(OBJGPU *pGpu, struct KernelGraphicsManager *pKernelGraphicsManager);
199 
200 /*! set num records to process per intr */
201 void fecsSetRecordsPerIntr
202 (
203     OBJGPU *pGpu,
204     struct KernelGraphics *pKernelGraphics,
205     NvU32 recordsPerIntr
206 );
207 
208 /**
209  * Returns true if a GR's FECS trace buffer has a record ready for processing
210  */
211 NvBool fecsBufferChanged(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
212 
213 /**
214  * Scrub the FECS tracing buffer and enable tracing (if a buffer has been mapped).
215  *
216  * The ctx logging state in GR will be set to enabled if the operation succeeded.
217  */
218 void fecsBufferReset(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
219 
220 /*! Is the FECS trace buffer mapped? */
221 NvBool fecsBufferIsMapped(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
222 
223 /**
224  * Map the FECS trace buffer
225  */
226 NV_STATUS fecsBufferMap(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
227 
228 /**
229  * Unmap the FECS trace buffer
230  */
231 void fecsBufferUnmap(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
232 
233 /**
234  * Disable FECS trace logging, unmap the trace log buffer, and remove any
235  * registered FECS trace logging callbacks.
236  *
237  * The ctx logging state in GR will be set to disabled after this operation.
238  */
239 void fecsBufferTeardown(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
240 
241 /**
242  * Disable FECS logging at hardware level
243  */
244 void fecsBufferDisableHw(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
245 
246 void fecsRemoveAllBindpoints(struct EventBuffer *pEventBuffer);
247 void fecsRemoveBindpoint(OBJGPU *pGpu, NvU64 uid, NV_EVENT_BUFFER_BIND_POINT_FECS* pBind);
248 
249 /* The callback function that transfers FECS Buffer entries to an EventBuffer */
250 void nvEventBufferFecsCallback(OBJGPU *pGpu, void *pArgs);
251 
252 void notifyEventBuffers
253 (
254     OBJGPU *pGpu,
255     FecsEventBufferBindMultiMapSubmap *pSubmap,
256     FECS_EVENT_NOTIFICATION_DATA const *pRecord
257 );
258 
259 /*! Atomically set intr callback pending, return NV_TRUE if wasn't pending prior */
260 NvBool fecsSignalIntrPendingIfNotPending(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
261 
262 /*! Atomically clear intr callback pending, return NV_TRUE if was pending */
263 NvBool fecsClearIntrPendingIfPending(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
264 
265 /*! Atomically check is intr callback pending */
266 NvBool fecsIsIntrPending(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
267 
268 /*! Retrieve or modify Ctxsw logging consumer count */
269 NvS16 fecsGetCtxswLogConsumerCount(OBJGPU *pGpu, struct KernelGraphicsManager *pKernelGraphicsManager);
270 NV_STATUS fecsDecrementCtxswLogConsumerCount(OBJGPU *pGpu, struct KernelGraphicsManager *pKernelGraphicsManager);
271 NV_STATUS fecsIncrementCtxswLogConsumerCount(OBJGPU *pGpu, struct KernelGraphicsManager *pKernelGraphicsManager);
272 
273 /*! Opaque VGPU fecs event buffer private data */
274 typedef struct VGPU_FECS_TRACE_STAGING_BUFFER VGPU_FECS_TRACE_STAGING_BUFFER;
275 
276 /*! Retrieve the current VGPU staging buffer */
277 VGPU_FECS_TRACE_STAGING_BUFFER *fecsGetVgpuStagingBuffer(OBJGPU *pGpu, struct KernelGraphics *pKernelGraphics);
278 
279 /*! Store the given VGPU staging buffer */
280 void fecsSetVgpuStagingBuffer
281 (
282     OBJGPU *pGpu,
283     struct KernelGraphics *pKernelGraphics,
284     VGPU_FECS_TRACE_STAGING_BUFFER *pStagingBuffer
285 );
286 
287 /*! Retreive map of logging consumers */
288 FecsEventBufferBindMultiMap *fecsGetEventBufferBindMultiMap(OBJGPU *pGpu, struct KernelGraphicsManager *pKernelGraphicsManager);
289 
290 #endif // _FECS_EVENT_LIST_H_
291 
292 #ifdef __cplusplus
293 } // extern "C"
294 #endif
295 
296 #endif // _G_FECS_EVENT_LIST_NVOC_H_
297