1 /*
2 * Copyright (c) 2019, 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_os_virtualengine_next.h
24 //! \brief    Common interface and structure used in MOS OS VirtualEngine
25 //! \details  Common interface and structure used in MOS OS VirtualEngine, and only necessary when KMD supports virtual engine
26 //!
27 #ifndef __MOS_OS_VIRTUALENGINE_NEXT_H__
28 #define __MOS_OS_VIRTUALENGINE_NEXT_H__
29 
30 #include "mos_os_virtualengine_specific.h"
31 #include "mos_os.h"
32 #define MOS_VE_HAVE_SECONDARY_CMDBUFFER 0x2
33 
34 typedef struct _MOS_VIRTUALENGINE_INIT_PARAMS
35 {
36     bool bScalabilitySupported;
37 
38     //below only valid when scalability is supported
39     bool    bFESeparateSubmit;  //!< for decode only
40     uint8_t ucMaxNumOfSdryCmdBufInOneFrame;
41     uint8_t ucMaxNumPipesInUse;
42     uint8_t ucNumOfSdryCmdBufSets;
43 } MOS_VIRTUALENGINE_INIT_PARAMS, *PMOS_VIRTUALENGINE_INIT_PARAMS;
44 
45 typedef struct _MOS_VIRTUALENGINE_SET_PARAMS
46 {
47     bool bSameEngineAsLastSubmission;
48     bool bNeedSyncWithPrevious;
49     bool bSFCInUse;
50 
51     //below only valid when scalability is supported
52     bool         bScalableMode;
53     bool         bHaveFrontEndCmds;
54     uint8_t      ucScalablePipeNum;
55     MOS_RESOURCE veBatchBuffer[MOS_MAX_ENGINE_INSTANCE_PER_CLASS];
56 } MOS_VIRTUALENGINE_SET_PARAMS, *PMOS_VIRTUALENGINE_SET_PARAMS;
57 
58 class MosVeInterface
59 {
60 public:
61     //!
62     //! \brief    Construct
63     //!
MosVeInterface()64     MosVeInterface() {}
65 
66     //!
67     //! \brief    Deconstruct
68     //!
~MosVeInterface()69     virtual ~MosVeInterface() {}
70 
71     //!
72     //! \brief    initialize virtual engine interface
73     //! \details  initialize virtual engine interface
74     //! \param    [in]  stream
75     //!           MOS stream state
76     //! \param    [in]  veInitParms
77     //!           pointer to VE init parameters
78     //! \return   MOS_STATUS
79     //!           MOS_STATUS_SUCCESS if success, else fail reason
80     //!
81     virtual MOS_STATUS Initialize(
82         MOS_STREAM_HANDLE stream,
83         PMOS_VIRTUALENGINE_INIT_PARAMS veInitParms);
84 
85     //!
86     //! \brief     check if scalability is supported
87     //! \param    [out] pbScalabilitySupported
88     //!                pointer to a bool value
89     //! \return   MOS_STATUS
90     //!           MOS_STATUS_SUCCESS if success, else fail reason
91     //!
92     virtual MOS_STATUS IsScalabilitySupported(
93         bool *pbScalabilitySupported);
94 
95     //!
96     //! \brief     Reset secondary cmd buffer state
97     //! \details  Reset secondary cmd buffer state in scalability virtual engine interface
98     //! \return   void
99     //!
100     virtual void ResetSecdryCmdBufStates() = 0;
101 
102     //!
103     //! \brief    Verify secondary cmd buffer size
104     //! \param    [in]  dwNewRequestSize
105     //!                new request cmd buffer size
106     //! \return   bool
107     //!           true if size is enough, else the size < new requested size
108     //!
109     virtual bool VerifySecdryCmdBufSize(
110         uint32_t dwNewRequestSize) = 0;
111 
112     //!
113     //! \brief    resize secondary cmd buffer
114     //! \param    [in]  dwNewRequestSize
115     //!                new request cmd buffer size
116     //! \return   MOS_STATUS
117     //!           MOS_STATUS_SUCCESS if success, else fail reason
118     //!
119     virtual MOS_STATUS ResizeSecdryCmdBuf(
120         uint32_t dwNewRequestSize) = 0;
121 
122     //!
123     //! \brief    get secondary cmd buffer
124     //! \param    [in]  pScdryCmdBuf
125     //!                pointer to secondry cmd buffer
126     //! \param    [in]  dwBufIdxPlus1
127     //!                secondary cmd buffer index plus 1
128     //! \return   MOS_STATUS
129     //!           MOS_STATUS_SUCCESS if success, else fail reason
130     //!
131     virtual MOS_STATUS GetSecdryCmdBuf(
132         PMOS_COMMAND_BUFFER pScdryCmdBuf,
133         uint32_t dwBufIdxPlus1) = 0;
134 
135     //!
136     //! \brief    return secondary cmd buffer
137     //! \param    [in] pScdryCmdBuf
138     //!                pointer to secondry cmd buffer address
139     //! \param    [in]  dwBufIdxPlus1
140     //!                secondary cmd buffer index plus 1
141     //! \return   MOS_STATUS
142     //!           MOS_STATUS_SUCCESS if success, else fail reason
143     //!
144     virtual MOS_STATUS ReturnSecdryCmdBuf(
145         PMOS_COMMAND_BUFFER pScdryCmdBuf,
146         uint32_t dwBufIdxPlus1) = 0;
147 
148     //!
149     //! \brief    done virtual engine secondary command buffers
150     //! \details  UnLock virtual engine secondary command buffers
151     //! \return   MOS_STATUS
152     //!           MOS_STATUS_SUCCESS if success, else fail reason
153     //!
154     virtual MOS_STATUS DoneSecdryCmdBuf() = 0;
155 
156     //!
157     //! \brief    set hint parameters
158     //! \details  set hint parameters for virtual engine scalability or single pipe mode
159     //! \param    [in] pVEParams
160     //!                pointer to VE parameter data structure
161     //! \return   MOS_STATUS
162     //!           MOS_STATUS_SUCCESS if success, else fail reason
163     //!
164     virtual MOS_STATUS SetHintParams(
165         PMOS_VIRTUALENGINE_SET_PARAMS pVEParams) = 0;
166 
167     //!
168     //! \brief    get hint parameters
169     //! \details  get hint parameters for virtual engine scalability or single pipe mode
170     //! \param    [in] bScalableMode
171     //!                flag to indicate if scalability mode
172     //! \param    [in] ppHintParams
173     //!                pointer to VE hint parameter address
174     //! \return   MOS_STATUS
175     //!           MOS_STATUS_SUCCESS if success, else fail reason
176     //!
177     virtual MOS_STATUS GetHintParams(
178         bool                           bScalableMode,
179         PMOS_VIRTUALENGINE_HINT_PARAMS *ppHintParams) = 0;
180 
181     //!
182     //! \brief    check hint parameters
183     //! \details  check hint parameters for virtual engine scalability or single pipe mode
184     //! \return   MOS_STATUS
185     //!           MOS_STATUS_SUCCESS if success, else fail reason
186     //!
187     virtual MOS_STATUS CheckHintParamsValidity() = 0;
188 
189     //!
190     //! \brief    Destroy resources for virtual engine scalability
191     //!
192     //! \return   void
193     //!
194     virtual void Destroy() = 0;
195 
196     //!
197     //! \brief    Set Submission Type for cmd buffer
198     //! \param    [out] cmdBuf
199     //!           Handle of cmd buffer to set submission type
200     //! \param    [in] type
201     //!           Submission type to set
202     //! \return   MOS_STATUS
203     //!           MOS_STATUS_SUCCESS if success, else fail reason
204     //!
SetSubmissionType(COMMAND_BUFFER_HANDLE cmdBuf,MOS_SUBMISSION_TYPE type)205     MOS_STATUS SetSubmissionType(
206         COMMAND_BUFFER_HANDLE cmdBuf,
207         MOS_SUBMISSION_TYPE   type)
208     {
209         MOS_OS_CHK_NULL_RETURN(cmdBuf);
210         cmdBuf->iSubmissionType = type;
211         return MOS_STATUS_SUCCESS;
212     }
213 
214 #if _DEBUG || _RELEASE_INTERNAL
215     //!
216     //! \brief    Get Engine Count
217     //! \return   uint8_t
218     //!
GetEngineCount()219     uint8_t GetEngineCount()
220     {
221         return ucEngineCount;
222     }
223 
224     //!
225     //! \brief    Get Engine Logic Id
226     //! \param    [in] instanceIdx
227     //!                Engine instance index
228     //! \return   uint8_t
229     //!
GetEngineLogicId(uint32_t instanceIdx)230     uint8_t GetEngineLogicId(uint32_t instanceIdx)
231     {
232         return EngineLogicId[instanceIdx];
233     }
234 #endif // _DEBUG || _RELEASE_INTERNAL
235 
236 protected:
237     MOS_STREAM_HANDLE m_stream = MOS_INVALID_HANDLE;
238     bool bScalabilitySupported = false;
239 
240 #if _DEBUG || _RELEASE_INTERNAL
241     uint8_t EngineLogicId[MOS_MAX_ENGINE_INSTANCE_PER_CLASS] = {};
242     uint8_t ucEngineCount = 1;
243     bool    m_enableDbgOvrdInVirtualEngine = false;
244 #endif // _DEBUG || _RELEASE_INTERNAL
245 
246     uint8_t ucMaxNumPipesInUse       = 1;
247     bool    m_contextBasedScheduling = false;
248 
249     MOS_VIRTUALENGINE_HINT_PARAMS ScalabilityHintParams = {};
250     MOS_VIRTUALENGINE_HINT_PARAMS SinglePipeHintParams = {};
251 MEDIA_CLASS_DEFINE_END(MosVeInterface)
252 };
253 
254 #endif //__MOS_OS_VIRTUALENGINE_SCALABILITY_NEXT_H__
255 
256