xref: /aosp_15_r20/external/intel-media-driver/media_common/agnostic/common/os/mos_oca_interface.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2009-2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     mos_oca_interface.h
24 //! \brief    Common interface and structure for OCA
25 //!
26 
27 #ifndef __MOS_OCA_INTERFACE_H__
28 #define __MOS_OCA_INTERFACE_H__
29 
30 #include "mos_oca_defs.h"
31 
32 class MosOcaInterface
33 {
34 public:
35     //!
36     //! \brief  Destructor
37     //!
~MosOcaInterface()38     virtual ~MosOcaInterface() {}
39 
40     //!
41     //! \brief  Get the idle oca buffer, which is neither used by hw nor locked, and lock it for edit.
42     //! \param  [in] pMosContext
43     //!         pointer to MOS_INTERFACE
44     //! \param  [in] CurrentGpuContextHandle
45     //!         Gpu context handle
46     //! \return MOS_OCA_BUFFER_HANDLE
47     //!         return the handle for oca buffer
48     //!
LockOcaBufAvailable(PMOS_CONTEXT pMosContext,uint32_t CurrentGpuContextHandle)49     virtual MOS_OCA_BUFFER_HANDLE LockOcaBufAvailable(PMOS_CONTEXT pMosContext, uint32_t CurrentGpuContextHandle)
50     {
51         return 0;
52     }
53 
54     //!
55     //! \brief  Unlock the oca buffer when edit complete.
56     //! \param  [in] hOcaBuf
57     //!         Oca buffer handle.
58     //! \return MOS_STATUS
59     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
60     //!
UnlockOcaBuf(MOS_OCA_BUFFER_HANDLE hOcaBuf)61     virtual MOS_STATUS UnlockOcaBuf(MOS_OCA_BUFFER_HANDLE hOcaBuf)
62     {
63         return MOS_STATUS_UNIMPLEMENTED;
64     }
65 
UnlockPendingOcaBuffers(PMOS_CONTEXT mosCtx,struct MOS_OCA_EXEC_LIST_INFO * info,int count)66     virtual void UnlockPendingOcaBuffers(PMOS_CONTEXT mosCtx, struct MOS_OCA_EXEC_LIST_INFO *info, int count)
67     {
68         MOS_OS_ASSERTMESSAGE("MosOcaInterface::UnlockPendingOcaBuffers should not be called!");
69     }
70 
UnlockOcaBufferWithDelay(MOS_OCA_BUFFER_HANDLE ocaBufHandle)71     virtual MOS_STATUS UnlockOcaBufferWithDelay(MOS_OCA_BUFFER_HANDLE ocaBufHandle)
72     {
73         return MOS_STATUS_UNIMPLEMENTED;
74     }
75 
76     //!
77     //! \brief  Oca operation which should be called at the beginning of 1st level batch buffer start.
78     //! \param  [out] gpuVaOcaBuffer
79     //!         The gfx virtual address of oca buffer, which should be set to GPR11 by LRI at the
80     //!         beginning of 1st level batch buffer no matter return value is MOS_STATUS_SUCCESS or not.
81     //! \param  [in] hOcaBuf
82     //!         Oca buffer handle.
83     //! \param  [in] pMosContext
84     //!         Pointer to MOS_CONTEXT.
85     //! \param  [in] pMosResource
86     //!         Pointer to the MOS_RESOURCE.
87     //! \param  [in] offsetOf1stLevelBB
88     //!         Offset for current BB in pMosResource.
89     //! \param  [in] bUseSizeOfResource
90     //!         If true, use size of pMosResource for batch buffer, else use sizeOf1stLevelBB.
91     //! \param  [in] sizeOf1stLevelBB
92     //!         Size of BB. Ignore if bUseSizeOfResource == true.
93     //! \return MOS_STATUS
94     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
95     //!
On1stLevelBBStart(uint64_t & gpuVaOcaBuffer,MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT pMosContext,void * pMosResource,uint32_t offsetOf1stLevelBB,bool bUseSizeOfResource,uint32_t sizeOf1stLevelBB)96     virtual MOS_STATUS On1stLevelBBStart(uint64_t &gpuVaOcaBuffer, MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT pMosContext, void *pMosResource,
97         uint32_t offsetOf1stLevelBB, bool bUseSizeOfResource, uint32_t sizeOf1stLevelBB)
98     {
99         // The GPR11 need to be reset to 0 to disable UMD_OCA for current workload.
100         gpuVaOcaBuffer = 0;
101         return MOS_STATUS_UNIMPLEMENTED;
102     }
103 
104     //!
105     //! \brief  Oca operation which should be called before adding batch buffer end command for 1st
106     //!         level batch buffer.
107     //! \param  [in] hOcaBuf
108     //!         Oca buffer handle.
109     //! \param  [in] mosCtx
110     //!         DDI device context.
111     //! \return MOS_STATUS
112     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
113     //!
On1stLevelBBEnd(MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT mosCtx)114     virtual MOS_STATUS On1stLevelBBEnd(MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT mosCtx)
115     {
116         return MOS_STATUS_UNIMPLEMENTED;
117     }
118 
119     //!
120     //! \brief  Oca operation which should be called before sending start sub level batch buffer command.
121     //! \param  [in] hOcaBuf
122     //!         Oca buffer handle.
123     //! \param  [in] pMosContext
124     //!         Pointer to MOS_CONTEXT.
125     //! \param  [in] pMosResource
126     //!         Pointer to the MOS_RESOURCE.
127     //! \param  [in] offsetOfSubLevelBB
128     //!         Offset for current BB in pMosResource.
129     //! \param  [in] bUseSizeOfResource
130     //!         If true, use size of pMosResource for batch buffer, else use sizeOfIndirectState.
131     //! \param  [in] sizeOfSubLevelBB
132     //!         Size of BB. Ignore if bUseSizeOfResource == true.
133     //! \return MOS_STATUS
134     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
135     //!
OnSubLevelBBStart(MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT pMosContext,void * pMosResource,uint32_t offsetOfSubLevelBB,bool bUseSizeOfResource,uint32_t sizeOfSubLevelBB)136     virtual MOS_STATUS OnSubLevelBBStart(MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT pMosContext, void *pMosResource, uint32_t offsetOfSubLevelBB, bool bUseSizeOfResource, uint32_t sizeOfSubLevelBB)
137     {
138         return MOS_STATUS_UNIMPLEMENTED;
139     }
140 
141     //!
142     //! \brief  Oca operation which should be called when indirect states being added.
143     //! \param  [in] hOcaBuf
144     //!         Oca buffer handle.
145     //! \param  [in] pMosContext
146     //!         Pointer to MOS_CONTEXT.
147     //! \param  [in] pMosResource
148     //!         Pointer to the MOS_RESOURCE.
149     //! \param  [in] offsetOfIndirectState
150     //!         Offset for current state in pMosResource.
151     //! \param  [in] bUseSizeOfResource
152     //!         If true, use size of pMosResource for indirect state, else use sizeOfIndirectState.
153     //! \param  [in] sizeOfIndirectState
154     //!         Size of indirect state. Ignore if bUseSizeOfResource == true.
155     //! \return MOS_STATUS
156     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
157     //!
OnIndirectState(MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT pMosContext,void * pMosResource,uint32_t offsetOfIndirectState,bool bUseSizeOfResource,uint32_t sizeOfIndirectState)158     virtual MOS_STATUS OnIndirectState(MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT pMosContext, void *pMosResource, uint32_t offsetOfIndirectState, bool bUseSizeOfResource, uint32_t sizeOfIndirectState)
159     {
160         return MOS_STATUS_UNIMPLEMENTED;
161     }
162 
163     //!
164     //! \brief  Oca operation which should be called before adding dispatch states,
165     //!         e.g. VEB_DI_IECP_STATE and MEDIA_OBJECT_WALKER.
166     //! \param  [out] offsetInIndirectStateHeap
167     //!         The start offset of current dispatch in indirect state heap, which should be set to low 32 bits
168     //!         of GPR12 by LRI before dispatch commands being added.
169     //!         OCA_HEAP_INVALID_OFFSET means no need to configure GPR12, otherwise the register need be configured
170     //!         no matter return value being MOS_STATUS_SUCCESS or not.
171     //! \param  [in] hOcaBuf
172     //!         Oca buffer handle.
173     //! \param  [in] mosCtx
174     //!         DDI device context.
175     //! \return MOS_STATUS
176     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
177     //!
OnDispatch(uint32_t & offsetInIndirectStateHeap,MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT mosCtx)178     virtual MOS_STATUS OnDispatch(uint32_t &offsetInIndirectStateHeap, MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT mosCtx)
179     {
180         offsetInIndirectStateHeap = OCA_HEAP_INVALID_OFFSET;
181         return MOS_STATUS_UNIMPLEMENTED;
182     }
183 
184     //!
185     //! \brief  Add string to oca log section
186     //! \param  [in] hOcaBuf
187     //!         Oca buffer handle.
188     //! \param  [in] mosCtx
189     //!         DDI device context.
190     //! \param  [in] str
191     //!         string to be added.
192     //! \param  [in] maxCount
193     //!         size of the buffer pointed by str.
194     //! \return MOS_STATUS
195     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
196     //!
TraceMessage(MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT mosCtx,const char * str,uint32_t maxCount)197     virtual MOS_STATUS TraceMessage(MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT mosCtx, const char *str, uint32_t maxCount)
198     {
199         return MOS_STATUS_UNIMPLEMENTED;
200     }
201 
202     //!
203     //! \brief  Add resource to dump list.
204     //! \param  [in] hOcaBuf
205     //!         Oca buffer handle.
206     //! \param  [in] mosCtx
207     //!         DDI device context.
208     //! \param  [in] resource
209     //!         Reference to MOS_RESOURCE.
210     //! \param  [in] hwCmdType
211     //!         Hw command Type.
212     //! \param  [in] locationInCmd
213     //!         Location in command.
214     //! \param  [in] offsetInRes
215     //!         Offset in resource.
216     //! \return MOS_STATUS
217     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
218     //!
AddResourceToDumpList(MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT mosCtx,MOS_RESOURCE & resource,MOS_HW_COMMAND hwCmdType,uint32_t locationInCmd,uint32_t offsetInRes)219     virtual MOS_STATUS AddResourceToDumpList(MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT mosCtx, MOS_RESOURCE &resource, MOS_HW_COMMAND hwCmdType, uint32_t locationInCmd, uint32_t offsetInRes)
220     {
221         return MOS_STATUS_UNIMPLEMENTED;
222     }
223 
224     //!
225     //! \brief  Add data block to oca log section.
226     //! \param  [in] hOcaBuf
227     //!         Oca buffer handle.
228     //! \param  [in] mosCtx
229     //!         DDI device context.
230     //! \param  [in] pHeader
231     //!         Log header. It can be extended by user. The acutal size of header is pHeader->m_HeaderSize.
232     //! \param  [in] pData
233     //!         Data block without log header. The acutal size of data block is pHeader->m_DataSize.
234     //! \return MOS_STATUS
235     //!         Return MOS_STATUS_SUCCESS if successful, otherwise failed
236     //!
DumpDataBlock(MOS_OCA_BUFFER_HANDLE hOcaBuf,PMOS_CONTEXT mosCtx,PMOS_OCA_LOG_HEADER pHeader,void * pData)237     virtual MOS_STATUS DumpDataBlock(MOS_OCA_BUFFER_HANDLE hOcaBuf, PMOS_CONTEXT mosCtx, PMOS_OCA_LOG_HEADER pHeader, void *pData)
238     {
239         return MOS_STATUS_UNIMPLEMENTED;
240     }
241 
242     //!
243     //! \brief  Get the mutex for oca buffer handles protection.
244     //! \return PMOS_MUTEX
245     //!         Return PMOS_MUTEX if successful, otherwise nullptr
246     //!
GetMutex()247     virtual PMOS_MUTEX GetMutex()
248     {
249         return nullptr;
250     }
251 
252     //!
253     //! \brief  Insert OCA buffer handle into m_hOcaMap
254     //! \param  [in] key
255     //!         The key of m_hOcaMap.
256     //! \param  [in] handle
257     //!         Oca buffer handle.
258     //! \return MOS_STATUS
259     //!         Return MOS_STATUS_SUCCESS if insert successfully, otherwise insert failed.
260     //!
261     virtual MOS_STATUS InsertOcaBufHandleMap(uint32_t *key, MOS_OCA_BUFFER_HANDLE handle) = 0;
262 
263     //!
264     //! \brief  Remove OCA buffer handle from m_hOcaMap
265     //! \param  [in] key
266     //!         The key of m_hOcaMap.
267     //! \return MOS_STATUS
268     //!         Return MOS_STATUS_SUCCESS if erase successfully, otherwise erase failed.
269     //!
270     virtual MOS_STATUS RemoveOcaBufHandleFromMap(uint32_t *key) = 0;
271 
272     //!
273     //! \brief  Get OCA buffer handle from m_hOcaMap
274     //! \param  [in] key
275     //!         The key of m_hOcaMap.
276     //! \return MOS_OCA_BUFFER_HANDLE
277     //!         Return oca buffer handle.
278     //!
279     virtual MOS_OCA_BUFFER_HANDLE GetOcaBufHandleFromMap(uint32_t *key) = 0;
280 
281     //!
282     //! \brief  Get OCA status.
283     //! \return MOS_STATUS
284     //!         Return oca status
285     //!
286     virtual MOS_STATUS GetOCAStatus() = 0;
287 
288     //!
289     //! \brief  Set OCA status
290     //! \param  [in] status
291     //!         oca status.
292     //! \return void
293     //!
294     virtual void SetOCAStatus(MOS_STATUS status) = 0;
295 
296     //!
297     //! \brief  Set OCA error line number
298     //! \param  [in] num
299     //!         line number
300     //! \return void
301     //!
302     virtual void SetOCAErrorLineNumber(uint32_t num) = 0;
303 };
304 
305 #endif // #ifndef __MOS_OCA_INTERFACE_H__
306