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_utilities_next.h
24 //! \brief    Common OS service across different platform
25 //! \details  Common OS service across different platform
26 //!
27 #ifndef __MOS_UTILITIES_NEXT_H__
28 #define __MOS_UTILITIES_NEXT_H__
29 #include "mos_utilities_common.h"
30 #include "mos_utilities_specific.h"
31 #include "mos_resource_defs.h"
32 #include "mos_os_trace_event.h"
33 
34 //------------------------------------------------------------------------------
35 // SECTION: Media User Feature Control
36 //
37 // ABSTRACT: Is an abstraction to read and write system level settings relating
38 //      to GEN media driver.
39 //------------------------------------------------------------------------------
40 class MediaUserSettingsMgr;
41 class MosMutex;
42 class MosUtilities
43 {
44 public:
45     MosUtilities()          = delete;
46     ~MosUtilities()         = delete;
47 
48     MOS_FUNC_EXPORT static void MosSetUltFlag(uint8_t ultFlag);
49     MOS_FUNC_EXPORT static int32_t MosGetMemNinjaCounter();
50     MOS_FUNC_EXPORT static int32_t MosGetMemNinjaCounterGfx();
51 
52     //!
53     //! \brief    Get current run time
54     //! \details  Get current run time in us
55     //! \return   double
56     //!           Returns time in us
57     //!
58     static double MosGetTime();
59 
60 #if MOS_MESSAGES_ENABLED
61     template<class _Ty, class... _Types>
MosNewUtil(const char * functionName,const char * filename,int32_t line,_Types &&..._Args)62     static _Ty* MosNewUtil(const char *functionName,
63         const char *filename,
64         int32_t line, _Types&&... _Args)
65 #else
66     template<class _Ty, class... _Types>
67     static _Ty* MosNewUtil(_Types&&... _Args)
68 #endif
69     {
70 #if (_DEBUG || _RELEASE_INTERNAL)
71         //Simulate allocate memory fail if flag turned on
72         if (MosSimulateAllocMemoryFail(sizeof(_Ty), NO_ALLOC_ALIGNMENT, functionName, filename, line))
73         {
74             return nullptr;
75         }
76 #endif
77         _Ty* ptr = new (std::nothrow) _Ty(std::forward<_Types>(_Args)...);
78         if (ptr != nullptr)
79         {
80             MosAtomicIncrement(&m_mosMemAllocCounter);
81             MOS_MEMNINJA_ALLOC_MESSAGE(ptr, sizeof(_Ty), functionName, filename, line);
82         }
83         else
84         {
85             MOS_OS_ASSERTMESSAGE("Fail to create class.");
86         }
87         return ptr;
88     }
89 
90 #if MOS_MESSAGES_ENABLED
91     template<class _Ty, class... _Types>
MosNewArrayUtil(const char * functionName,const char * filename,int32_t line,int32_t numElements)92     static _Ty *MosNewArrayUtil(const char *functionName,
93         const char *filename,
94         int32_t line, int32_t numElements)
95 #else
96     template<class _Ty, class... _Types>
97     static _Ty* MosNewArrayUtil(int32_t numElements)
98 #endif
99     {
100 #if (_DEBUG || _RELEASE_INTERNAL)
101         //Simulate allocate memory fail if flag turned on
102         if (MosSimulateAllocMemoryFail(sizeof(_Ty) * numElements, NO_ALLOC_ALIGNMENT, functionName, filename, line))
103         {
104             return nullptr;
105         }
106 #endif
107         _Ty* ptr = new (std::nothrow) _Ty[numElements]();
108         if (ptr != nullptr)
109         {
110             MosAtomicIncrement(&m_mosMemAllocCounter);
111             MOS_MEMNINJA_ALLOC_MESSAGE(ptr, numElements*sizeof(_Ty), functionName, filename, line);
112         }
113         return ptr;
114     }
115 
116 #if MOS_MESSAGES_ENABLED
117     template<class _Ty> inline
MosDeleteUtil(const char * functionName,const char * filename,int32_t line,_Ty & ptr)118     static void MosDeleteUtil(
119         const char *functionName,
120         const char *filename,
121         int32_t     line,
122         _Ty&        ptr)
123 #else
124     template<class _Ty> inline
125     static void MosDeleteUtil(_Ty& ptr)
126 #endif
127     {
128         if (ptr != nullptr)
129         {
130             MosAtomicDecrement(&m_mosMemAllocCounter);
131             MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line);
132             delete(ptr);
133             ptr = nullptr;
134         }
135     }
136 
137 #if MOS_MESSAGES_ENABLED
138     template<class _Ty> inline
MosDeleteArrayUtil(const char * functionName,const char * filename,int32_t line,_Ty & ptr)139     static void MosDeleteArrayUtil(
140         const char *functionName,
141         const char *filename,
142         int32_t     line,
143         _Ty&        ptr)
144 #else
145     template <class _Ty> inline
146     static void MosDeleteArrayUtil(_Ty& ptr)
147 #endif
148     {
149         if (ptr != nullptr)
150         {
151             MosAtomicDecrement(&m_mosMemAllocCounter);
152             MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line);
153 
154             delete[](ptr);
155             ptr = nullptr;
156         }
157     }
158 
159     //!
160     //! \brief    Init Function for MOS utilitiesNext
161     //! \details  Initial MOS utilitiesNext related structures, and only execute once for multiple entries
162     //! \param    [in] userFeatureKeyPathInfo
163     //!           user feature key path info
164     //! \return   MOS_STATUS
165     //!           Returns one of the MOS_STATUS error codes if failed,
166     //!           else MOS_STATUS_SUCCESS
167     //!
168     static MOS_STATUS MosUtilitiesInit(PMOS_USER_FEATURE_KEY_PATH_INFO userFeatureKeyPathInfo = NULL);
169 
170     //!
171     //! \brief    Close Function for MOS utilitiesNext
172     //! \details  close/remove MOS utilitiesNext related structures, and only execute once for multiple entries
173     //! \return   MOS_STATUS
174     //!           Returns one of the MOS_STATUS error codes if failed,
175     //!           else MOS_STATUS_SUCCESS
176     //!
177     static MOS_STATUS MosUtilitiesClose();
178 
179     //!
180     //! \brief    Init user feature key path for MOS OS specific utilitiesNext
181     //! \details  Init user feature key path from the parameter
182     //! \param    [in] userFeatureKeyPathInfo
183     //!           user feature key path info
184     //! \return   void
185     //!
186     static void MosInitUserFeatureKeyPathInfo(PMOS_USER_FEATURE_KEY_PATH_INFO userFeatureKeyPathInfo);
187 
188     //!
189     //! \brief    Deinit user feature key path for MOS OS specific utilitiesNext
190     //! \details  release the user feature key path memory and set null
191     //! \return   void
192     //!
193     static void MosDeinitUserFeatureKeyPathInfo();
194 
195 private:
196     //!
197     //! \brief    Init Function for MOS OS specific utilitiesNext
198     //! \details  Initial MOS OS specific utilitiesNext related structures, and only execute once for multiple entries
199     //! \param    [in] userFeatureKeyPathInfo
200     //!           user feature key path info
201     //! \return   MOS_STATUS
202     //!           Returns one of the MOS_STATUS error codes if failed,
203     //!           else MOS_STATUS_SUCCESS
204     //!
205     static MOS_STATUS MosOsUtilitiesInit(PMOS_USER_FEATURE_KEY_PATH_INFO userFeatureKeyPathInfo = NULL);
206 
207     //!
208     //! \brief    Close Function for MOS OS utilitiesNext
209     //! \details  close/remove MOS OS utilitiesNext related structures, and only execute once for multiple entries
210     //! \return   MOS_STATUS
211     //!           Returns one of the MOS_STATUS error codes if failed,
212     //!           else MOS_STATUS_SUCCESS
213     //!
214     static MOS_STATUS MosOsUtilitiesClose();
215 
216 #if (_DEBUG || _RELEASE_INTERNAL)
217     //!
218     //! \brief    Init simulate random memory allocation fail flag
219     //! \details  init MosSimulateRandomAllocMemoryFailFlag according user feature value:
220     //!           __MEDIA_USER_FEATURE_VALUE_SIMULATE_RANDOM_ALLOC_MEMORY_FAIL
221     //! \return   void
222     //!
223     static void MosInitAllocMemoryFailSimulateFlag();
224 
225     static bool MosSimulateAllocMemoryFail(
226         size_t      size,
227         size_t      alignment,
228         const char *functionName,
229         const char *filename,
230         int32_t     line);
231 
232 #endif  //(_DEBUG || _RELEASE_INTERNAL)
233 public:
234     //------------------------------------------------------------------------------
235     //  Allocate, free and set a memory region
236     //------------------------------------------------------------------------------
237     //!
238     //! \brief    Allocates aligned memory and performs error checking
239     //! \details  Wrapper for aligned_malloc(). Performs error checking.
240     //!           It increases memory allocation counter variable
241     //!           m_mosMemAllocCounter for checking memory leaks.
242     //! \param    [in] size
243     //!           Size of memorry to be allocated
244     //! \param    [in] alignment
245     //!           alignment
246     //! \return   void *
247     //!           Pointer to allocated memory
248     //!
249     // APO_MOS_WRAPPER
250 #if MOS_MESSAGES_ENABLED
251     static void *MosAlignedAllocMemoryUtils(
252         size_t     size,
253         size_t     alignment,
254         const char *functionName,
255         const char *filename,
256         int32_t    line);
257 
258 #else // !MOS_MESSAGES_ENABLED
259 
260     static void *MosAlignedAllocMemory(
261         size_t  size,
262         size_t  alignment);
263 
264 #endif // MOS_MESSAGES_ENABLED
265 
266     //!
267     //! \brief    Wrapper for aligned_free(). Performs error checking.
268     //! \details  Wrapper for aligned_free() - Free a block of memory that was allocated by MOS_AlignedAllocMemory.
269     //!             Performs error checking.
270     //!           It decreases memory allocation counter variable
271     //!           m_mosMemAllocCounter for checking memory leaks.
272     //! \param    [in] ptr
273     //!           Pointer to the memory to be freed
274     //! \return   void
275     //!
276 #if MOS_MESSAGES_ENABLED
277     static void MosAlignedFreeMemoryUtils(
278         void        *ptr,
279         const char  *functionName,
280         const char  *filename,
281         int32_t     line);
282 
283 #else // !MOS_MESSAGES_ENABLED
284 
285     static void MosAlignedFreeMemory(void *ptr);
286 
287 #endif // MOS_MESSAGES_ENABLED
288 
289     //!
290     //! \brief    Allocates memory and performs error checking
291     //! \details  Wrapper for malloc(). Performs error checking.
292     //!           It increases memory allocation counter variable
293     //!           m_mosMemAllocCounter for checking memory leaks.
294     //! \param    [in] size
295     //!           Size of memorry to be allocated
296     //! \return   void *
297     //!           Pointer to allocated memory
298     //!
299     // APO_MOS_WRAPPER
300 #if MOS_MESSAGES_ENABLED
301     static void *MosAllocMemoryUtils(
302         size_t     size,
303         const char *functionName,
304         const char *filename,
305         int32_t    line);
306 
307 #else // !MOS_MESSAGES_ENABLED
308 
309     static void *MosAllocMemory(
310         size_t  size);
311 
312 #endif // MOS_MESSAGES_ENABLED
313 
314     //!
315     //! \brief    Allocates and fills memory with 0
316     //! \details  Wrapper for malloc(). Performs error checking,
317     //!           and fills the allocated memory with 0.
318     //!           It increases memory allocation counter variable
319     //!           m_mosMemAllocCounter for checking memory leaks.
320     //! \param    [in] size
321     //!           Size of memorry to be allocated
322     //! \return   void *
323     //!           Pointer to allocated memory
324     //!
325 #if MOS_MESSAGES_ENABLED
326     static void *MosAllocAndZeroMemoryUtils(
327         size_t     size,
328         const char *functionName,
329         const char *filename,
330         int32_t    line);
331 
332 #else // !MOS_MESSAGES_ENABLED
333     static void *MosAllocAndZeroMemory(
334         size_t                   size);
335 #endif // MOS_MESSAGES_ENABLED
336 
337     //!
338     //! \brief    Reallocate memory
339     //! \details  Wrapper for realloc(). Performs error checking.
340     //!           It modifies memory allocation counter variable
341     //!           m_mosMemAllocCounter for checking memory leaks.
342     //! \param    [in] ptr
343     //!           Pointer to be reallocated
344     //! \param    [in] new_size
345     //!           Size of memory to be allocated
346     //! \return   void *
347     //!           Pointer to allocated memory
348     //!
349 #if MOS_MESSAGES_ENABLED
350     static void *MosReallocMemoryUtils(
351         void       *ptr,
352         size_t     newSize,
353         const char *functionName,
354         const char *filename,
355         int32_t    line);
356 
357 #else // !MOS_MESSAGES_ENABLED
358     static void *MosReallocMemory(
359         void       *ptr,
360         size_t     newSize);
361 #endif // MOS_MESSAGES_ENABLED
362 
363     //!
364     //! \brief    Wrapper for free(). Performs error checking.
365     //! \details  Wrapper for free(). Performs error checking.
366     //!           It decreases memory allocation counter variable
367     //!           m_mosMemAllocCounter for checking memory leaks.
368     //! \param    [in] ptr
369     //!           Pointer to the memory to be freed
370     //! \return   void
371     //!
372     // APO_MOS_WRAPPER
373 #if MOS_MESSAGES_ENABLED
374     static void MosFreeMemoryUtils(
375         void       *ptr,
376         const char *functionName,
377         const char *filename,
378         int32_t    line);
379 
380 #else // !MOS_MESSAGES_ENABLED
381     static void MosFreeMemory(
382         void            *ptr);
383 #endif // MOS_MESSAGES_ENABLED
384 
385     //!
386     //! \brief    Wrapper to set a block of memory with zeros.
387     //! \details  Wrapper to set a block of memory with zeros.
388     //! \param    [in] pDestination
389     //!           A pointer to the starting address of the memory
390     //!           block to fill with zeros.
391     //! \param    [in] stLength
392     //!           Size of the memory block in bytes to be filled
393     //! \return   void
394     //!
395     // APO_MOS_WRAPPER
396     static void MosZeroMemory(
397         void            *pDestination,
398         size_t          stLength);
399 
400     //!
401     //! \brief    Wrapper to set a block of memory with a specified value.
402     //! \details  Wrapper to set a block of memory with a specified value.
403     //! \param    [in] pDestination
404     //!           A pointer to the starting address of the memory
405     //!           block to fill with specified value bFill
406     //! \param    [in] stLength
407     //!           Size of the memory block in bytes to be filled
408     //! \param    [in] bFill
409     //!           The byte value with which to fill the memory block
410     //! \return   void
411     //!
412     // APO_MOS_WRAPPER
413     static void MosFillMemory(
414         void            *pDestination,
415         size_t          stLength,
416         uint8_t         bFill);
417 
418     //------------------------------------------------------------------------------
419     //  File I/O Functions
420     //------------------------------------------------------------------------------
421     //!
422     //! \brief    Allocate a buffer and read contents from a file into this buffer
423     //! \details  Allocate a buffer and read contents from a file into this buffer
424     //! \param    [in] PpFilename
425     //!           ointer to the filename from which to read
426     //! \param    [out] lpNumberOfBytesRead,
427     //!           pointer to return the number of bytes read
428     //! \param    [out] ppReadBuffer
429     //!           Pointer to return the buffer pointer where
430     //!           the contents from the file are read to
431     //! \return   MOS_STATUS
432     //!           Returns one of the MOS_STATUS error codes if failed,
433     //!           else MOS_STATUS_SUCCESS
434     //!
435     static MOS_STATUS MosReadFileToPtr(
436         const char         *pFilename,
437         uint32_t           *lpNumberOfBytesRead,
438         void               **ppReadBuffer);
439 
440     //!
441     //! \brief    Writes contents of buffer into a file
442     //! \details  Writes contents of buffer into a file
443     //! \param    [in] pFilename
444     //!           Pointer to the filename to write the contents to
445     //! \param    [in] lpBuffer
446     //!           Pointer to the buffer whose contents will be written to the file
447     //! \param    [in] writeSize
448     //!           Number of bytes to write to the file
449     //! \return   MOS_STATUS
450     //!           Returns one of the MOS_STATUS error codes if failed,
451     //!           else MOS_STATUS_SUCCESS
452     //!
453     static MOS_STATUS MosWriteFileFromPtr(
454         const char              *pFilename,
455         void                    *lpBuffer,
456         uint32_t                writeSize);
457 
458     //!
459     //! \brief    Retrieves the size of the specified File.
460     //! \details  Retrieves the size of the specified File.
461     //! \param    [in] hFile
462     //!           Handle to the File.
463     //! \param    [out] lpFileSizeLow
464     //!           Pointer to a variable where filesize is returned
465     //! \param    lpFileSizeHigh
466     //!           Reserved for now. Used to return higher uint32_t for
467     //!           filesizes more than 32 bit
468     //! \return   MOS_STATUS
469     //!           Returns one of the MOS_STATUS error codes if failed,
470     //!           else MOS_STATUS_SUCCESS
471     //!
472     static MOS_STATUS MosGetFileSize(
473         HANDLE             hFile,
474         uint32_t           *lpFileSizeLow,
475         uint32_t           *lpFileSizeHigh);
476 
477     //!
478     //! \brief    Creates a directory
479     //! \details  Creates a directory
480     //! \param    [in] lpPathName
481     //!           Pointer to the path name
482     //! \return   MOS_STATUS
483     //!           Returns MOS_STATUS_SUCCESS if directory was created or was already exists,
484     //!           else MOS_STATUS_DIR_CREATE_FAILED
485     //!
486     static MOS_STATUS MosCreateDirectory(
487         char * const       lpPathName);
488 
489     //!
490     //! \brief    Creates or opens a file/object
491     //! \details  Creates or opens a file/object
492     //!           The definitions of the mode flags for iOpenFlag are in OS's fcntl.h
493     //! \param    [out] pHandle
494     //!           Pointer to a variable that recieves the handle
495     //!           of the file or object oepned
496     //! \param    [in] lpFileName
497     //!           Pointer to the file name
498     //! \param    [in] iOpenFlag
499     //!           Flag specifying mode and other options for Creating
500     //! \return   MOS_STATUS
501     //!           Returns one of the MOS_STATUS error codes if failed,
502     //!           else MOS_STATUS_SUCCESS
503     //!
504     static MOS_STATUS MosCreateFile(
505         PHANDLE               pHandle,
506         char * const          lpFileName,
507         uint32_t              iOpenFlag);
508 
509     //!
510     //! \brief    Read data from a file
511     //! \details  Read data from a file
512     //! \param    [in] hFile
513     //!           Handle to the file to be read
514     //! \param    [out] lpBuffer
515     //!           Pointer to the buffer where the data read is placed
516     //! \param    [in] bytesToRead
517     //!           The maximum number of bytes to be read
518     //! \param    [out] pbytesRead
519     //!           Pointer to a variable that receives the number of bytes read
520     //! \param    [in/out] lpOverlapped
521     //!           Not used currently, can be nullptr
522     //!           When the hFile parameter was opened with FILE_FLAG_OVERLAPPED
523     //!           It should point to a valid OVERLAPPED structure
524     //! \return   MOS_STATUS
525     //!           Returns one of the MOS_STATUS error codes if failed,
526     //!           else MOS_STATUS_SUCCESS
527     //!
528     static MOS_STATUS MosReadFile(
529         HANDLE          hFile,
530         void            *lpBuffer,
531         uint32_t        bytesToRead,
532         uint32_t        *pbytesRead,
533         void            *lpOverlapped);
534 
535     //!
536     //! \brief    Write data to a file
537     //! \details  Write data to a file
538     //! \param    [in] hFile
539     //!           Handle to the file to which data will be written
540     //! \param    [in] lpBuffer
541     //!           Pointer to the buffer from where the data is read
542     //! \param    [in] bytesToWrite
543     //!           The maximum number of bytes to be written
544     //! \param    [out] pbytesWritten
545     //!           Pointer to a variable that receives the number of bytes written
546     //! \param    [in/out] lpOverlapped
547     //!           Not used currently, can be nullptr
548     //!           When the hFile parameter was opened with FILE_FLAG_OVERLAPPED
549     //!           It should point to a valid OVERLAPPED structure
550     //! \return   MOS_STATUS
551     //!           Returns one of the MOS_STATUS error codes if failed,
552     //!           else MOS_STATUS_SUCCESS
553     //!
554     static MOS_STATUS MosWriteFile(
555         HANDLE           hFile,
556         void             *lpBuffer,
557         uint32_t         bytesToWrite,
558         uint32_t         *pbytesWritten,
559         void             *lpOverlapped);
560 
561     //!
562     //! \brief    Moves the File pointer to the specified position
563     //! \details  Moves the File pointer to the specified position
564     //!           Specify dwMoveMethod as the same as fseek()
565     //! \param    [in] hFile
566     //!           Handle to the file
567     //! \param    [in] lDistanceToMove
568     //!           Specifies no. of bytes to move the pointer
569     //! \param    [in] lpDistanceToMoveHigh
570     //!           Pointer to the high order 32-bits of
571     //!           the signed 64-bit distance to move.
572     //! \param    [in] dwMoveMethod
573     //!           Starting point for the file pointer move
574     //! \return   MOS_STATUS
575     //!           Returns one of the MOS_STATUS error codes if failed,
576     //!           else MOS_STATUS_SUCCESS
577     //!
578     static MOS_STATUS MosSetFilePointer(
579         HANDLE                hFile,
580         int32_t               lDistanceToMove,
581         int32_t               *lpDistanceToMoveHigh,
582         int32_t               dwMoveMethod);
583 
584     //!
585     //! \brief    Closes an open object handle
586     //! \details  Closes an open object handle.
587     //! \param    [in] hObject
588     //!           A valid handle to an open object.
589     //! \return   int32_t
590     //!           true if success else false
591     //!
592     static int32_t MosCloseHandle(
593         HANDLE           hObject);
594 
595     //!
596     //! \brief    Appends at the end of File
597     //! \details  Appends at the end of File
598     //! \param    [in] pFilename
599     //!           Pointer to the filename to append the contents to
600     //! \param    [in] pData
601     //!           Pointer to the buffer whose contents will be appeneded to the file
602     //! \param    [in] dwSize
603     //!           Number of bytes to append to the file
604     //! \return   MOS_STATUS
605     //!           Returns one of the MOS_STATUS error codes if failed,
606     //!           else MOS_STATUS_SUCCESS
607     //!
608     static MOS_STATUS MosAppendFileFromPtr(
609         const char               *pFilename,
610         void                     *pData,
611         uint32_t                 dwSize);
612 
613     //!
614     //! \brief    Generate a User Feature Keys XML file according to user feature keys table in MOS
615     //! \details  Generate a User Feature Keys XML files according to m_mosUserFeatureDescFields
616     //! \return   MOS_STATUS
617     //!           Returns one of the MOS_STATUS error codes if failed,
618     //!           else MOS_STATUS_SUCCESS
619     //!
620     static MOS_STATUS MosGenerateUserFeatureKeyXML();
621 
622     //!
623     //! \brief    Link user feature key description table items to specified UserFeatureKeyTable
624     //! \details  Link user feature key description table items to specified UserFeatureKeyTable
625     //!           according to ID sequence and do some post processing such as malloc related memory
626     //! \param    [in] userValueDescTable
627     //!           The user feature key description table
628     //! \param    [in] numOfValues
629     //!           Number of user feature keys described in the table
630     //! \param    [in] maxId
631     //!           Max value ID in the table
632     //! \param    [out] keyValueMap
633     //!           optional pointer to the value map where the table items will be linked to, could be nullptr
634     //! \return   MOS_STATUS
635     //!           Returns one of the MOS_STATUS error codes if failed,
636     //!           else MOS_STATUS_SUCCESS
637     //!
638     static MOS_STATUS MosDeclareUserFeatureKeysFromDescFields(
639         MOS_USER_FEATURE_VALUE     *userValueDescTable,
640         uint32_t                   numOfValues,
641         uint32_t                   maxId);
642 
643     //!
644     //!
645     //! \brief    Destroy the User Feature Value pointer according to the DescField Table
646     //! \details  Destroy the User Feature Value pointer according to the DescField Table
647     //!           destroy the user feature key value Map according to Declare Count
648     //! \param    [in] descTable
649     //!           The user feature key description table
650     //! \param    [in] numOfItems
651     //!           Number of user feature keys described in the table
652     //! \param    [in] maxId
653     //!           Max value ID in the table
654     //! \return   MOS_STATUS
655     //!           Returns one of the MOS_STATUS error codes if failed,
656     //!           else MOS_STATUS_SUCCESS
657     //!
658     static MOS_STATUS MosDestroyUserFeatureKeysFromDescFields(
659         MOS_USER_FEATURE_VALUE     *descTable,
660         uint32_t                   numOfItems,
661         uint32_t                   maxId);
662 
663     //!
664     //! \brief    Copy the VALUE_DATA from source to destination pointer
665     //! \details  Copy the VALUE_DATA from source to destination pointer
666     //! \param    [in] pSrcData
667     //!           Pointer to the Source Value Data
668     //! \param    [in] pDstData
669     //!           Pointer to the Destination Value Data
670     //! \param    [in] ValueType
671     //!           Value Type for the copy data
672     //! \return   MOS_STATUS
673     //!           Returns one of the MOS_STATUS error codes if failed,
674     //!           else MOS_STATUS_SUCCESS
675     //!
676     static MOS_STATUS MosCopyUserFeatureValueData(
677         PMOS_USER_FEATURE_VALUE_DATA pSrcData,
678         PMOS_USER_FEATURE_VALUE_DATA pDstData,
679         MOS_USER_FEATURE_VALUE_TYPE ValueType
680     );
681 
682     //!
683     //! \brief    Read Single Value from User Feature based on value of enum type in MOS_USER_FEATURE_VALUE_TYPE
684     //! \details  This is a unified funtion to read user feature key for all components.
685     //!           (Codec/VP/CP/CM)
686     //!           It is required to prepare all memories for buffers before calling this function.
687     //!           User can choose to use array variable or allocated memory for the buffer.
688     //!           If the buffer is allocated dynamically, it must be freed by user to avoid memory leak.
689     //!           ------------------------------------------------------------------------------------
690     //!           Usage example:
691     //!           a) Initiation:
692     //!           MosZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
693     //!           b.0) Don't need to input a default value if the default value in user feature key Desc Fields table item is good
694     //!                for your case
695     //!           b.1) For uint32_t type:
696     //!           UserFeatureData.u32Data = 1;    // overwrite a custom default value
697     //!           UserFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
698     //!                                           // raise a flag to use this custom default value instead of
699     //!                                              default value in user feature key Desc Fields table item
700     //!           b.2) For String/Binary type:
701     //!           char cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE];
702     //!           UserFeatureData.StringData.pStringData = cStringData; // make sure the pointer is valid
703     //!           b.3) For MultiString type:
704     //!           char                          cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE];
705     //!           MOS_USER_FEATURE_VALUE_STRING Strings[__MAX_MULTI_STRING_COUNT];
706     //!           UserFeatureData.MultiStringData.pMultStringData = cStringData; // make sure the pointer is valid
707     //!           for (ui = 0; ui < VPHAL_3P_MAX_LIB_PATH_COUNT; ui++)
708     //!           {
709     //!             Strings[ui].pStringData = (char *)MOS_AllocAndZeroMemory(MOS_USER_CONTROL_MAX_DATA_SIZE);
710     //!           }
711     //!           UserFeatureData.MultiStringData.pStrings = Strings;
712     //!           c) Read user feature key:
713     //!           MosUserFeatureReadValueID();
714     //!           -------------------------------------------------------------------------------------
715     //!           Important note: The pointer pStringData/pMultStringData may be modified if the
716     //!           previous MOS_UserFeature_ReadValue() doesn't read a same user feature key type. So it's
717     //!           suggested to set the union members in UserFeatureValue every time before
718     //!           MOS_UserFeature_ReadValue() if you are not familiar with the details of this function.
719     //!           If a new key is added, please make sure to declare a definition in corresponding
720     //!           user feature key Desc Fields tableby MOS_DECLARE_UF_KEY
721     //! \param    [in] pOsUserFeatureInterface
722     //!           Pointer to OS User Interface structure
723     //! \param    [in] ValueID
724     //!           value of enum type in MOS_USER_FEATURE_VALUE_TYPE. declares the user feature key to be readed
725     //! \param    [in,out] pValueData
726     //!           Pointer to User Feature Data
727     //! \return   MOS_STATUS
728     //!           Returns one of the MOS_STATUS error codes if failed,
729     //!           else MOS_STATUS_SUCCESS
730     //!           For pValueData return value:
731     //!                 MOS_STATUS_SUCCESS: pValueData is from User Feature Key
732     //!                 MOS_STATUS_USER_FEATURE_KEY_OPEN_FAILED: pValueData is from default value
733     //!                 MOS_STATUS_UNKNOWN: pValueData is from default value
734     //!                 MOS_STATUS_USER_FEATURE_KEY_READ_FAILED: pValueData is from default value
735     //!                 MOS_STATUS_NULL_POINTER: NO USER FEATURE KEY DEFINITION in corresponding user feature key Desc Field table,
736     //!                                          No default value or User Feature Key value return
737     //!
738     //!
739     static MOS_STATUS MosUserFeatureReadValueID(
740         PMOS_USER_FEATURE_INTERFACE  pOsUserFeatureInterface,
741         uint32_t                     ValueID,
742         PMOS_USER_FEATURE_VALUE_DATA pValueData);
743 
744     //!
745     //! \brief    Write Values to User Feature with specified ID
746     //! \details  Write Values to User Feature with specified ID
747     //!           The caller is responsible to allocate values / names
748     //!           and free them later if necessary
749     //! \param    [in] pOsUserFeatureInterface
750     //!           Pointer to OS User Interface structure
751     //! \param    [in] pWriteValues
752     //!           Pointer to User Feature Data, and related User Feature Key ID (enum type in MOS_USER_FEATURE_VALUE_TYPE)
753     //! \param    [in] uiNumOfValues
754     //!           number of user feature keys to be written.
755     //! \return   MOS_STATUS
756     //!           Returns one of the MOS_STATUS error codes if failed,
757     //!           else MOS_STATUS_SUCCESS
758     //!
759     static MOS_STATUS MosUserFeatureWriteValuesID(
760         PMOS_USER_FEATURE_INTERFACE              pOsUserFeatureInterface,
761         PMOS_USER_FEATURE_VALUE_WRITE_DATA       pWriteValues,
762         uint32_t                                 uiNumOfValues);
763 
764     //!
765     //! \brief    Lookup the user feature value name associated with the ID
766     //! \details  Lookup the user feature value name associated with the ID
767     //! \param    [in] ValueId
768     //!           The user feature value ID to be looked up
769     //! \return   const char*
770     //!           pointer to the char array holding the user feature value name
771     //!
772     static const char *MosUserFeatureLookupValueName(uint32_t ValueID);
773 
774     //!
775     //! \brief    Lookup the read path associated with the ID
776     //! \param    [in] ValueId
777     //!           The user feature value ID to be looked up
778     //! \return   pointer to the char array holding the read path
779     //!
780     static const char *MosUserFeatureLookupReadPath(uint32_t ValueID);
781 
782     //!
783     //! \brief    Lookup the write path associated with the ID
784     //! \param    [in] ValueId
785     //!           The user feature value ID to be looked up
786     //! \return   pointer to the char array holding the write path
787     //!
788     static const char *MosUserFeatureLookupWritePath(uint32_t ValueID);
789 
790     //!
791     //! \brief    Enable user feature change notification
792     //! \details  Enable user feature change notification
793     //!           Create notification data and register the wait event
794     //! \param    [in] pOsUserFeatureInterface
795     //!           Pointer to OS User Interface structure
796     //! \param    [in/out] pNotification
797     //!           Pointer to User Feature Notification Data
798     //! \return   MOS_STATUS
799     //!           Returns one of the MOS_STATUS error codes if failed,
800     //!           else MOS_STATUS_SUCCESS
801     //!
802     static MOS_STATUS MosUserFeatureEnableNotification(
803         PMOS_USER_FEATURE_INTERFACE               pOsUserFeatureInterface,
804         PMOS_USER_FEATURE_NOTIFY_DATA             pNotification);
805 
806     //!
807     //! \brief    Disable user feature change notification
808     //! \details  Disable user feature change notification
809     //!           Unregister the wait event and frees notification data
810     //! \param    [in] pOsUserFeatureInterface
811     //!           Pointer to OS User Interface structure
812     //! \param    [in/out] pNotification
813     //!           Pointer to User Feature Notification Data
814     //! \return   MOS_STATUS
815     //!           Returns one of the MOS_STATUS error codes if failed,
816     //!           else MOS_STATUS_SUCCESS
817     //!
818     static MOS_STATUS MosUserFeatureDisableNotification(
819         PMOS_USER_FEATURE_INTERFACE                pOsUserFeatureInterface,
820         PMOS_USER_FEATURE_NOTIFY_DATA              pNotification);
821 
822     //!
823     //! \brief    Parses the user feature path and gets type and sub path
824     //! \details  Parses the user feature path and gets type and sub path
825     //!           It verifies if the user feature path is valid,
826     //!           and check if it belongs to UFEXT or UFINT UFKEY.
827     //!           The identified type and subpath are set accordingly.
828     //! \param    [in] pOsUserFeatureInterface,
829     //!           Pointer to OS User Interface structure
830     //! \param    [in] pInputPath
831     //!           The input user feature path
832     //! \param    [out] pUserFeatureType
833     //!           Pointer to the variable to receive user feature type
834     //! \param    [out] ppSubPath
835     //!           Pointer to a variable that accepts the pointer to the subpath
836     //! \return   MOS_STATUS
837     //!           Returns MOS_STATUS_INVALID_PARAMETER if failed, else MOS_STATUS_SUCCESS
838     //!
839     static MOS_STATUS MosUserFeatureParsePath(
840         PMOS_USER_FEATURE_INTERFACE  pOsUserFeatureInterface,
841         char * const                 pInputPath,
842         PMOS_USER_FEATURE_TYPE       pUserFeatureType,
843         char                         **ppSubPath);
844 
845     //!
846     //! \brief    Set the User Feature Default Value
847     //! \details  Set the User Feature Default Value in the user feature key map
848     //! \param    PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface
849     //!           [in] Pointer to OS User Interface structure
850     //! \param    PMOS_USER_FEATURE_VALUE_WRITE_DATA      pWriteValues
851     //!           [in] Pointer to User Feature Write Datas
852     //! \return   MOS_STATUS
853     //!           Returns one of the MOS_STATUS error codes if failed,
854     //!           else MOS_STATUS_SUCCESS
855     //!
856     MOS_STATUS MosUserFeatureSetDefaultValues(
857         PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues,
858         uint32_t                           uiNumOfValues);
859 
860 
861     //!
862     //! \brief    Read the User Feature Value of ApoMosEnabled
863     //! \details  Read the User Feature Value of ApoMosEnabled
864     //! \param    uint32_t& userfeatureValue
865     //!           [in] reference to a userfeatureValue
866     //! \param    char *path
867     //!           [in] stated uf key path
868     //! \return   MOS_STATUS
869     //!           Returns one of the MOS_STATUS error codes if failed,
870     //!           else MOS_STATUS_SUCCESS
871     //!
872     static MOS_STATUS MosReadApoMosEnabledUserFeature(uint32_t &userfeatureValue, char *path = nullptr);
873 
874     //------------------------------------------------------------------------------
875     // String Functions
876     //------------------------------------------------------------------------------
877     //!
878     //! \brief    String concatenation with security checks.
879     //! \details  String concatenation with security checks.
880     //!           Append strSource to strDestination, with buffer size checking
881     //! \param    [in/out] strDestination
882     //!           Pointer to destination string
883     //! \param    [in] numberOfElements
884     //!           Size of the destination buffer
885     //! \param    [in] strSource
886     //!           Pointer to the source string
887     //! \return   MOS_STATUS
888     //!           Returns one of the MOS_STATUS error codes if failed,
889     //!           else MOS_STATUS_SUCCESS
890     //!
891     static MOS_STATUS MosSecureStrcat(
892         char                *strDestination,
893         size_t              numberOfElements,
894         const char * const  strSource);
895 
896     //!
897     //! \brief    Find string token with security checks.
898     //! \details  Find string token with security checks.
899     //!           Subsequent calls with nullptr in strToken and same contex to get
900     //!           remaining tokens
901     //! \param    [in/out] strToken
902     //!           String containing token or tokens
903     //!           Pass nullptr for this parameter in subsequent calls
904     //!           to MOS_SecureStrtok to find the remaining tokens
905     //! \param    [in] strDelimit
906     //!           Set of delimiter characters
907     //! \param    [in/out] contex
908     //!           Used to store position information between calls to MOS_SecureStrtok
909     //! \return   char *
910     //!           Returns tokens else nullptr
911     //!
912     static char *MosSecureStrtok(
913         char                *strToken,
914         const char          *strDelimit,
915         char                **contex);
916 
917     //!
918     //! \brief    String copy with security checks.
919     //! \details  String copy with security checks.
920     //!           Copy strSource to strDestination, with buffer size checking
921     //! \param    [out] strDestination
922     //!           Pointer to destination string
923     //! \param    [in] numberOfElements
924     //!           Size of the destination buffer
925     //! \param    [in] strSource
926     //!           Pointer to the source string
927     //! \return   MOS_STATUS
928     //!           Returns one of the MOS_STATUS error codes if failed,
929     //!           else MOS_STATUS_SUCCESS
930     //!
931     static MOS_STATUS MosSecureStrcpy(
932         char                *strDestination,
933         size_t              numberOfElements,
934         const char * const  strSource);
935 
936     //!
937     //! \brief    Memory copy with security checks.
938     //! \details  Memory copy with security checks.
939     //!           Copy pSource to pDestination, with buffer size checking
940     //! \param    [out] pDestination
941     //!           Pointer to destination buffer
942     //! \param    [in] dstLength
943     //!           Size of the destination buffer
944     //! \param    [in] pSource
945     //!           Pointer to the source buffer
946     //! \param    [in] srcLength
947     //!           Number of bytes to copy from source to destination
948     //! \return   MOS_STATUS
949     //!           Returns one of the MOS_STATUS error codes if failed,
950     //!           else MOS_STATUS_SUCCESS
951     //!
952     static MOS_STATUS MosSecureMemcpy(
953         void                *pDestination,
954         size_t              dstLength,
955         const void          *pSource,
956         size_t              srcLength);
957 
958     //!
959     //! \brief    Open a file with security checks.
960     //! \details  Open a file with security checks.
961     //! \param    [out] ppFile
962     //!           Pointer to a variable that receives the file pointer.
963     //! \param    [in] filename
964     //!           Pointer to the file name string
965     //! \param    [in] mode
966     //!           Specifies open mode such as read, write etc
967     //! \return   MOS_STATUS
968     //!           Returns one of the MOS_STATUS error codes if failed,
969     //!           else MOS_STATUS_SUCCESS
970     //!
971     static MOS_STATUS MosSecureFileOpen(
972         FILE       **ppFile,
973         const char *filename,
974         const char *mode);
975 
976     //!
977     //! \brief    Write formatted data to a string with security checks.
978     //! \details  Write formatted data to a string with security checks.
979     //!           Optional arguments are passed in individually
980     //!           Buffer must have space for null character after copying length
981     //! \param    [out] buffer
982     //!           Pointer to a string to which formatted data is printed
983     //! \param    [in] bufSize
984     //!           Size of the buffer where the data is printed
985     //! \param    [in] length
986     //!           Number of characters to be printed
987     //! \param    [in] format
988     //!           Format string to be printed
989     //! \return   int32_t
990     //!           Returns the number of characters printed or -1 if an error occurs
991     //!
992     static int32_t MosSecureStringPrint(
993         char                     *buffer,
994         size_t                   bufSize,
995         size_t                   length,
996         const  char * const      format,
997                                      ...);
998 
999     //!
1000     //! \brief    Write formatted data to a string with security checks, va_list version
1001     //! \details  Write formatted data to a string with security checks.
1002     //!           Pointer to an optional arguments list is passed in
1003     //!           Buffer must have space for null character after copying length
1004     //! \param    [out] buffer
1005     //!           Pointer to a string to which formatted data is printed
1006     //! \param    [in] bufSize
1007     //!           Size of the buffer where the data is printed
1008     //! \param    [in] length
1009     //!           Number of characters to be printed
1010     //! \param    [in] format
1011     //!           Format string to be printed
1012     //! \param    [in] var_args
1013     //!           Optional argument list
1014     //! \return   int32_t
1015     //!           Returns the number of characters printed or -1 if an error occurs
1016     //!
1017     static MOS_STATUS MosSecureVStringPrint(
1018         char                      *buffer,
1019         size_t                    bufSize,
1020         size_t                    length,
1021         const char * const        format,
1022         va_list                   var_args);
1023 
1024     //------------------------------------------------------------------------------
1025     // Library, process and OS related functions
1026     //------------------------------------------------------------------------------
1027     //!
1028     //! \brief    Maps the specified executable module into the address space of
1029     //!           the calling process.
1030     //! \details  Maps the specified executable module into the address space of
1031     //!           the calling process.
1032     //! \param    [in] lpLibFileName
1033     //!           A valid handle to an open object.
1034     //! \param    [out] phModule
1035     //!           Pointer variable that accepts the module handle
1036     //! \return   MOS_STATUS
1037     //!           Returns one of the MOS_STATUS error codes if failed,
1038     //!           else MOS_STATUS_SUCCESS
1039     //!
1040     static MOS_STATUS MosLoadLibrary(
1041         const char * const lpLibFileName,
1042         PHMODULE           phModule);
1043 
1044     //!
1045     //! \brief    Free the loaded dynamic-link library
1046     //! \details  Free the loaded dynamic-link library
1047     //! \param    [in] hLibModule
1048     //!           A handle to the loaded DLL module
1049     //! \return   int32_t
1050     //!           true if success else false
1051     //!
1052     static int32_t MosFreeLibrary(HMODULE hLibModule);
1053 
1054     //!
1055     //! \brief    Retrieves the address of an exported function or variable from
1056     //!           the specified dynamic-link library
1057     //! \details  Retrieves the address of an exported function or variable from
1058     //!           the specified dynamic-link library
1059     //! \param    [in] hLibModule
1060     //!           A handle to the loaded DLL module.
1061     //!           The LoadLibrary function returns this handle.
1062     //! \param    [in] lpProcName
1063     //!           The function or variable name, or the function's ordinal value.
1064     //! \return   void *
1065     //!           If succeeds, the return value is the address of the exported
1066     //!           function or variable. If fails, the return value is NULL.
1067     //!           To get extended error information, call GetLastError.
1068     //!
1069     static void *MosGetProcAddress(
1070         HMODULE     hModule,
1071         const char  *lpProcName);
1072 
1073     //!
1074     //! \brief    Retrieves the current process id
1075     //! \details  Retrieves the current process id
1076     //! \return   int32_t
1077     //!           Return the current process id
1078     //!
1079     static int32_t MosGetPid();
1080 
1081     //!
1082     //! \brief    Retrieves the frequency of the high-resolution performance
1083     //!           counter, if one exists.
1084     //! \details  Retrieves the frequency of the high-resolution performance
1085     //!           counter, if one exists.
1086     //! \param    [out] pFrequency
1087     //!           Pointer to a variable that receives the current
1088     //!           performance-counter frequency, in counts per second.
1089     //! \return   int32_t
1090     //!           If the installed hardware supports a high-resolution performance
1091     //!           counter, the return value is nonzero. If the function fails, the
1092     //!           return value is zero.
1093     //!
1094     static int32_t MosQueryPerformanceFrequency(
1095         uint64_t                       *pFrequency);
1096 
1097     //!
1098     //! \brief    Retrieves the current value of the high-resolution performance
1099     //!           counter
1100     //! \details  Retrieves the current value of the high-resolution performance
1101     //!           counter
1102     //! \param    [out] pPerformanceCount
1103     //!           Pointer to a variable that receives the current
1104     //!           performance-counter value, in counts.
1105     //! \return   int32_t
1106     //!           If the installed hardware supports a high-resolution performance
1107     //!           counter, the return value is nonzero. If the function fails, the
1108     //!           return value is zero. To get extended error information, call GetLastError.
1109     //!
1110     static int32_t MosQueryPerformanceCounter(
1111         uint64_t                     *pPerformanceCount);
1112 
1113     //!
1114     //! \brief    Sleep for given duration in ms
1115     //! \details  Sleep for given duration ms
1116     //! \param    [in] mSec
1117     //!           Sleep duration in ms
1118     //! \return   void
1119     //!
1120     static void MosSleep(
1121         uint32_t   mSec);
1122 
1123     //------------------------------------------------------------------------------
1124     // Wrappers for OS Specific User Feature Functions Implementations
1125     //------------------------------------------------------------------------------
1126     //!
1127     //! \brief    Opens the specified user feature key
1128     //! \details  Opens the specified user feature key
1129     //! \param    [in] UFKey
1130     //!           A handle to an open user feature key.
1131     //! \param    [in] lpSubKey
1132     //!           The name of the user feature subkey to be opened.
1133     //! \param    [in] lOptions
1134     //!           This parameter is reserved and must be zero.
1135     //! \param    [in] samDesired
1136     //!           Reserved, could be any REGSAM type value
1137     //! \param    [out] phkResult
1138     //!           A pointer to a variable that receives a handle to the opened key.
1139     //! \return   MOS_STATUS
1140     //!           If the function succeeds, the return value is MOS_STATUS_SUCCESS.
1141     //!           If the function fails, the return value is a error code defined
1142     //!           in mos_utilitiesNext.h.
1143     //!
1144     static MOS_STATUS MosUserFeatureOpenKey(
1145         void              *UFKey,
1146         const char        *lpSubKey,
1147         uint32_t          ulOptions,
1148         uint32_t          samDesired,
1149         void              **phkResult);
1150 
1151     //!
1152     //! \brief    Closes a handle to the specified user feature key
1153     //! \details  Closes a handle to the specified user feature key
1154     //! \param    [in] UFKey
1155     //!           A handle to an open user feature key.
1156     //! \return   MOS_STATUS
1157     //!           If the function succeeds, the return value is MOS_STATUS_SUCCESS.
1158     //!           If the function fails, the return value is a error code defined
1159     //!           in mos_utilitiesNext.h.
1160     //!
1161     static MOS_STATUS MosUserFeatureCloseKey(
1162         void               *UFKey);
1163 
1164     //!
1165     //! \brief    Retrieves the type and data for the specified user feature value
1166     //! \details  Retrieves the type and data for the specified user feature value
1167     //! \param    [in] UFKey
1168     //!           A handle to an open user feature key.
1169     //! \param    [in] lpSubKey
1170     //!           The name of the user feature key. This key must be a
1171     //!           subkey of the key specified by the hkey parameter
1172     //! \param    [in] lpValue
1173     //!           The name of the user feature value
1174     //! \param    [in] dwFlags
1175     //!           The flags that restrict the data type of value to be queried
1176     //! \param    [out] pdwType
1177     //!           A pointer to a variable that receives a code indicating the type
1178     //!           of data stored in the specified value.
1179     //! \param    [out] pvData
1180     //!           A pointer to a buffer that receives the value's data.
1181     //! \param    [in/out] pcbData
1182     //!           A pointer to a variable that specifies the size of the buffer
1183     //!           pointed to by the pvData parameter, in bytes. When the function
1184     //!           returns, this variable contains the size of the data copied to lpData.
1185     //! \return   MOS_STATUS
1186     //!           If the function succeeds, the return value is MOS_STATUS_SUCCESS.
1187     //!           If the function fails, the return value is a error code defined
1188     //!           in mos_utilitiesNext.h.
1189     //!
1190     static MOS_STATUS MosUserFeatureGetValue(
1191         void               *UFKey,
1192         const char         *lpSubKey,
1193         const char         *lpValue,
1194         uint32_t           dwFlags,
1195         uint32_t           *pdwType,
1196         void               *pvData,
1197         uint32_t           *pcbData);
1198 
1199     //!
1200     //! \brief    Retrieves the type and data for the specified value name
1201     //!           associated with an open user feature key.
1202     //! \details  Retrieves the type and data for the specified value name
1203     //!           associated with an open user feature key.
1204     //! \param    [in] UFKey
1205     //!           A handle to an open user feature key
1206     //! \param    [in] lpValueName
1207     //!           The name of the user feature value
1208     //! \param    [in] lpReserved
1209     //!           This parameter is reserved and must be NULL.
1210     //! \param    [out] lpType
1211     //!           A pointer to a variable that receives a code indicating
1212     //!           the type of data stored in the specified value.
1213     //! \param    [out] lpData
1214     //!           A pointer to a buffer that receives the value's data.
1215     //! \param    [in/out] lpcbData
1216     //!           A pointer to a variable that specifies the size
1217     //!           of the buffer pointed to by the pvData parameter,
1218     //!           in bytes. When the function returns, this variable
1219     //!           contains the size of the data copied to lpData.
1220     //! \return   MOS_STATUS
1221     //!           If the function succeeds, the return value is MOS_STATUS_SUCCESS.
1222     //!           If the function fails, the return value is a error code defined
1223     //!           in mos_utilitiesNext.h.
1224     //!
1225     static MOS_STATUS MosUserFeatureQueryValueEx(
1226         void                    *UFKey,
1227         char                    *lpValueName,
1228         uint32_t                *lpReserved,
1229         uint32_t                *lpType,
1230         char                    *lpData,
1231         uint32_t                *lpcbData);
1232 
1233     //!
1234     //! \brief    Sets the data and type of a specified value under a user feature key
1235     //! \details  Sets the data and type of a specified value under a user feature key
1236     //! \param    [in] UFKey
1237     //!           A handle to an open user feature key
1238     //! \param    [in] lpValueName
1239     //!           The name of the user feature value
1240     //! \param    [in] Reserved
1241     //!           This parameter is reserved and must be nullptr
1242     //! \param    [in] dwType
1243     //!           The type of data pointed to by the lpData parameter
1244     //! \param    [in] lpData
1245     //!           The data to be stored.
1246     //! \param    [in] cbData
1247     //!           The size of the information pointed to by the lpData parameter, in bytes.
1248     //! \return   MOS_STATUS
1249     //!           If the function succeeds, the return value is MOS_STATUS_SUCCESS.
1250     //!           If the function fails, the return value is a error code defined
1251     //!           in mos_utilitiesNext.h.
1252     //!
1253     static MOS_STATUS MosUserFeatureSetValueEx(
1254         void                 *UFKey,
1255         const char           *lpValueName,
1256         uint32_t             Reserved,
1257         uint32_t             dwType,
1258         uint8_t              *lpData,
1259         uint32_t             cbData);
1260 
1261     //!
1262     //! \brief    Notifies the caller about changes to the attributes or contents
1263     //!           of a specified user feature key
1264     //! \details  Notifies the caller about changes to the attributes or contents
1265     //!           of a specified user feature key
1266     //!           Used internally by MosUserFeatureEnableNotification()
1267     //! \param    [in] UFKey
1268     //!           A handle to an open user feature key.
1269     //!           The key must have been opened with the KEY_NOTIFY access right.
1270     //! \param    [in] bWatchSubtree
1271     //!           true including subkey changes; false for the key itself
1272     //! \param    [in] hEvent
1273     //!           A handle to an event to be signaled when key changes if is true
1274     //! \param    [in] fAsynchronous
1275     //!           true: Return immediately and signal the hEvent when key change
1276     //!           false: Does not return until a change has occured
1277     //! \return   MOS_STATUS
1278     //!           If the function succeeds, the return value is MOS_STATUS_SUCCESS.
1279     //!           If the function fails, the return value is a error code defined
1280     //!           in mos_utilitiesNext.h.
1281     //!
1282     static MOS_STATUS MosUserFeatureNotifyChangeKeyValue(
1283         void                           *UFKey,
1284         int32_t                        bWatchSubtree,
1285         HANDLE                         hEvent,
1286         int32_t                        fAsynchronous);
1287 
1288     //!
1289     //! \brief    Creates or opens a event object and returns a handle to the object
1290     //! \details  Creates or opens a event object and returns a handle to the object
1291     //! \param    [in] lpEventAttributes
1292     //!           A pointer to a SECURITY_ATTRIBUTES structure.
1293     //!           If lpEventAttributes is nullptr, the event handle cannot be inherited
1294     //!           by child processes.
1295     //! \param    [in] lpName
1296     //!           The name of the event object.If lpName is nullptr, the event object is
1297     //!           created without a name.
1298     //! \param    [in] dwFlags
1299     //!           Combines the following flags
1300     //!           CREATE_EVENT_INITIAL_SET: Singal initial state or not
1301     //!           CREATE_EVENT_MANUAL_RESET: Must be manually reset or not
1302     //! \return   HANDLE
1303     //!           If the function succeeds, the return value is a handle to the
1304     //!           event object. If failed, returns NULL. To get extended error
1305     //!           information, call GetLastError.
1306     //!
1307     static HANDLE MosCreateEventEx(
1308         void                 *lpEventAttributes,
1309         char                 *lpName,
1310         uint32_t             dwFlags);
1311 
1312     //!
1313     //! \brief    Create a wait thread to wait on the object
1314     //! \details  Create a wait thread to wait on the object
1315     //!           Add this function to capatible WDK-9200 on vs2012.
1316     //! \param    [out] phNewWaitObject
1317     //!           A pointer to a variable that receives a wait handle on return.
1318     //! \param    [in] hObject
1319     //!           A handle to the object
1320     //! \param    [in] Callback
1321     //!           A pointer to the application-defined function of type
1322     //!           WAITORTIMERCALLBACK to be executed when wait ends.
1323     //! \param    [in] Context
1324     //!           A single value that is passed to the callback function
1325     //! \return   int32_t
1326     //!           The return value is int32_t type. If the function succeeds,
1327     //!           the return value is nonzero. If the function fails, the
1328     //!           return value is zero.
1329     //!
1330     static int32_t MosUserFeatureWaitForSingleObject(
1331         PTP_WAIT                         *phNewWaitObject,
1332         HANDLE                           hObject,
1333         void                             *Callback,
1334         void                             *Context);
1335 
1336     //!
1337     //! \brief    Cancels a registered wait operation issued by the
1338     //!           RegisterWaitForSingleObject function
1339     //! \details  Cancels a registered wait operation issued by the
1340     //!           RegisterWaitForSingleObject function
1341     //! \param    [in] hWaitHandle
1342     //!           The wait handle. This handle is returned by the
1343     //!           RegisterWaitForSingleObject function
1344     //! \return   int32_t
1345     //!           The return value is int32_t type. If the function succeeds,
1346     //!           the return value is nonzero. If the function fails, the
1347     //!           return value is zero.
1348     //!
1349     static int32_t MosUnregisterWaitEx(
1350         PTP_WAIT                hWaitHandle);
1351 
1352     //!
1353     //! \brief    Get logical core number of current CPU
1354     //! \details  Get logical core number of current CPU
1355     //! \return   uint32_t
1356     //!           If the function succeeds, the return value is the number of
1357     //!           current CPU.
1358     //!
1359     static uint32_t MosGetLogicalCoreNumber();
1360 
1361     //!
1362     //! \brief    Creates or opens a thread object and returns a handle to the object
1363     //! \details  Creates or opens a thread object and returns a handle to the object
1364     //! \param    [in] ThreadFunction
1365     //!           A pointer to a thread function.
1366     //! \param    [in] ThreadData
1367     //!           A pointer to thread data.
1368     //! \return   MOS_THREADHANDLE
1369     //!           If the function succeeds, the return value is a handle to the
1370     //!           thread object. If failed, returns NULL.
1371     //!
1372     static MOS_THREADHANDLE MosCreateThread(
1373         void                        *ThreadFunction,
1374         void                        *ThreadData);
1375 
1376     //!
1377     //! \brief    Get thread id
1378     //! \details  Get thread id
1379     //! \param    [in] hThread
1380     //!           A handle of thread object.
1381     //! \return   uint32_t
1382     //!           Return the current thread id
1383     //!
1384     static uint32_t MosGetThreadId(
1385         MOS_THREADHANDLE            hThread);
1386 
1387     //!
1388     //! \brief    Retrieves the current thread id
1389     //! \details  Retrieves the current thread id
1390     //! \return   uint32_t
1391     //!           Return the current thread id
1392     //!
1393     uint32_t MosGetCurrentThreadId();
1394 
1395     //!
1396     //! \brief    Wait for thread to terminate
1397     //! \details  Wait for thread to terminate
1398     //! \param    [in] hThread
1399     //!           A handle of thread object.
1400     //! \return   MOS_STATUS
1401     //!
1402     static MOS_STATUS MosWaitThread(
1403         MOS_THREADHANDLE            hThread);
1404 
1405     //!
1406     //! \brief    Create mutex for context protection across threads
1407     //! \details  Create mutex for context protection across threads
1408     //!           Used for multi-threading of Hybrid Decoder
1409     //! \param    NONE
1410     //! \return   PMOS_MUTEX
1411     //!           Pointer of mutex
1412     //!
1413     static PMOS_MUTEX MosCreateMutex();
1414 
1415     //!
1416     //! \brief    Destroy mutex for context protection across threads
1417     //! \details  Destroy mutex for context protection across threads
1418     //!           Used for multi-threading of Hybrid Decoder
1419     //! \param    [in] pMutex
1420     //!           Pointer of mutex
1421     //! \return   MOS_STATUS
1422     //!
1423     static MOS_STATUS MosDestroyMutex(PMOS_MUTEX pMutex);
1424 
1425     //!
1426     //! \brief    Lock mutex for context protection across threads
1427     //! \details  Lock mutex for context protection across threads
1428     //!           Used for multi-threading of Hybrid Decoder
1429     //! \param    [in] pMutex
1430     //!           Pointer of mutex
1431     //! \return   MOS_STATUS
1432     //!
1433     static MOS_STATUS MosLockMutex(PMOS_MUTEX pMutex);
1434 
1435     //!
1436     //! \brief    Unlock mutex for context protection across threads
1437     //! \details  Unlock mutex for context protection across threads
1438     //!           Used for multi-threading of Hybrid Decoder
1439     //! \param    [in] pMutex
1440     //!           Pointer of mutex
1441     //! \return   MOS_STATUS
1442     //!
1443     static MOS_STATUS MosUnlockMutex(PMOS_MUTEX pMutex);
1444 
1445     //!
1446     //! \brief    Creates or opens a semaphore object and returns a handle to the object
1447     //! \details  Creates or opens a semaphore object and returns a handle to the object
1448     //! \param    [in] uiInitialCount
1449     //!           Initial count of semaphore usage.
1450     //! \param    [in] uiMaximumCount
1451     //!           Maximum count of semaphore usage.
1452     //! \return   PMOS_SEMAPHORE
1453     //!           If the function succeeds, the return value is a handle to the
1454     //!           semaphore object. If failed, returns NULL. To get extended error
1455     //!           information, call GetLastError.
1456     //!
1457     static PMOS_SEMAPHORE MosCreateSemaphore(
1458         uint32_t                    uiInitialCount,
1459         uint32_t                    uiMaximumCount);
1460 
1461     //!
1462     //! \brief    Destroy a semaphore object
1463     //! \details  Destroy a semaphore object
1464     //! \param    [in] pSemaphore
1465     //!           A handle of semaphore object.
1466     //! \return   MOS_STATUS
1467     //!
1468     static MOS_STATUS MosDestroySemaphore(
1469         PMOS_SEMAPHORE              pSemaphore);
1470 
1471     //!
1472     //! \brief    Wait a semaphore object
1473     //! \details  Wait a semaphore object
1474     //! \param    [in] pSemaphore
1475     //!           A handle of semaphore object.
1476     //! \param    [in] uiMilliseconds
1477     //!           Wait time.
1478     //! \return   MOS_STATUS
1479     //!
1480     static MOS_STATUS MosWaitSemaphore(
1481         PMOS_SEMAPHORE              pSemaphore,
1482         uint32_t                    uiMilliseconds);
1483 
1484     //!
1485     //! \brief    Post a semaphore object
1486     //! \details  Post a semaphore object
1487     //! \param    [in] pSemaphore
1488     //!           A handle of semaphore object.
1489     //! \param    [in] uiPostCount
1490     //!           semaphore post count.
1491     //! \return   MOS_STATUS
1492     //!
1493     static MOS_STATUS MosPostSemaphore(
1494         PMOS_SEMAPHORE              pSemaphore,
1495         uint32_t                    uiPostCount);
1496 
1497     //!
1498     //! \brief    Wait for single object of semaphore/mutex/thread and returns the result
1499     //! \details  Wait for single object of semaphore/mutex/thread and returns the result
1500     //! \param    [in] pObject
1501     //!           Object handle.
1502     //! \param    [in] uiMilliseconds
1503     //!           Wait time.
1504     //! \return   uint32_t
1505     //!           If the function succeeds, the return value is the wait result of the
1506     //!           semaphore/mutex/thread object.
1507     //!
1508     static uint32_t MosWaitForSingleObject(
1509         void                        *pObject,
1510         uint32_t                    uiMilliseconds);
1511 
1512     //!
1513     //! \brief    Wait for multiple objects of semaphore/mutex/thread and returns the result
1514     //! \details  Wait for multiple objects of semaphore/mutex/thread and returns the result
1515     //! \param    [in] uiThreadCount
1516     //!           The number of object handles in the array pointed to by ppObjects.
1517     //! \param    [in] ppObjects
1518     //!           An array of object handles.
1519     //! \param    [in] bWaitAll
1520     //!           If true, the function returns when the state of all objects in the ppObjects array is signaled.
1521     //!           If false, the function returns when the state of any one of the objects is set to signaled.
1522     //! \param    [in] uiMilliseconds
1523     //!           The time-out interval, in milliseconds.
1524     //! \return   uint32_t
1525     //!           Return the wait result
1526     //!
1527     static uint32_t MosWaitForMultipleObjects(
1528         uint32_t                    uiThreadCount,
1529         void                        **ppObjects,
1530         uint32_t                    bWaitAll,
1531         uint32_t                    uiMilliseconds);
1532 
1533     //!
1534     //! \brief    Increments (increases by one) the value of the specified int32_t variable as an atomic operation.
1535     //! \param    [in] pValue
1536     //!           A pointer to the variable to be incremented.
1537     //! \return   int32_t
1538     //!           The function returns the resulting incremented value.
1539     //!
1540     static int32_t MosAtomicIncrement(
1541         int32_t *pValue);
1542 
1543     //!
1544     //! \brief    Decrements (decreases by one) the value of the specified int32_t variable as an atomic operation.
1545     //! \param    [in] pValue
1546     //!           A pointer to the variable to be decremented.
1547     //! \return   int32_t
1548     //!           The function returns the resulting decremented value.
1549     //!
1550     static int32_t MosAtomicDecrement(
1551         int32_t *pValue);
1552 
1553     //!
1554     //! \brief      Convert MOS_STATUS to OS dependent RESULT/Status
1555     //! \param      [in] eStatus
1556     //!             MOS_STATUS that will be converted
1557     //! \return     MOS_OSRESULT
1558     //!             Corresponding return code on different OSes
1559     //!
1560     static MOS_OSRESULT MosStatusToOsResult(
1561         MOS_STATUS               eStatus);
1562 
1563     //!
1564     //! \brief      Convert OS dependent RESULT/Status to MOS_STATUS
1565     //! \param      [in] eResult
1566     //!             OS dependent result that will be converted
1567     //! \return     MOS_STATUS
1568     //!             Corresponding MOS_STATUS
1569     //!
1570     static MOS_STATUS OsResultToMOSStatus(
1571         MOS_OSRESULT            eResult);
1572 
1573     //!
1574     //! \brief    sinc
1575     //! \details  Calculate sinc(x)
1576     //! \param    [in] x
1577     //!           float
1578     //! \return   float
1579     //!           sinc(x)
1580     //!
1581     static float MosSinc(
1582         float                   x);
1583 
1584     //!
1585     //! \brief    Lanczos
1586     //! \details  Calculate lanczos(x)
1587     //!           Basic formula is:  lanczos(x)= MOS_Sinc(x) * MOS_Sinc(x / fLanczosT)
1588     //! \param    [in] x
1589     //!           float
1590     //! \param    [in] dwNumEntries
1591     //!           dword
1592     //! \param    [in] fLanczosT
1593     //!
1594     //! \return   float
1595     //!           lanczos(x)
1596     //!
1597     static float MosLanczos(
1598         float                   x,
1599         uint32_t                dwNumEntries,
1600         float                   fLanczosT);
1601 
1602     //!
1603     //! \brief    General Lanczos
1604     //! \details  Calculate lanczos(x)  with odd entry num support
1605     //!           Basic formula is:  lanczos(x)= MOS_Sinc(x) * MOS_Sinc(x / fLanczosT)
1606     //! \param    [in] x
1607     //!           float
1608     //! \param    [in] dwNumEntries
1609     //!           dword
1610     //! \param    [in]fLanczosT
1611     //!
1612     //! \return   float
1613     //!           lanczos(x)
1614     //!
1615     static float MosLanczosG(
1616         float                   x,
1617         uint32_t                dwNumEntries,
1618         float                   fLanczosT);
1619 
1620     //!
1621     //! \brief    GCD
1622     //! \details  Recursive GCD calculation of two numbers
1623     //! \param    [in] a
1624     //!           uint32_t
1625     //! \param    [in] b
1626     //!           uint32_t
1627     //! \return   uint32_t
1628     //!           MosGCD(a, b)
1629     //!
1630     static uint32_t MosGCD(
1631         uint32_t               a,
1632         uint32_t               b);
1633 
1634     //!
1635     //! \brief    Get local time
1636     //! \details  Get local time
1637     //! \param    [out] tm
1638     //!           tm struct
1639     //! \return   MOS_STATUS
1640     //!
1641     static MOS_STATUS MosGetLocalTime(
1642         struct tm* tm);
1643 
1644     //!
1645     //! \brief    Swizzles the given linear offset via the specified tiling params.
1646     //! \details  Swizzles the given linear offset via the specified tiling parameters.
1647     //!           Used to provide linear access to raw, tiled data.
1648     //! \param    [in] OffsetX
1649     //!           Horizontal byte offset from left edge of tiled surface.
1650     //! \param    [in] OffsetY
1651     //!           Vertical offset from top of tiled surface.
1652     //! \param    [in] Pitch
1653     //!           Row-to-row byte stride.
1654     //! \param    [in] TileFormat
1655     //!           Either 'x' or 'y'--for X-Major or Y-Major tiling, respectively.
1656     //! \param    [in] CsxSwizzle
1657     //!           (Boolean) Additionally perform Channel Select XOR swizzling.
1658     //! \param    [in] flags
1659     //!           More flags to indicate different tileY.
1660     //! \return   int32_t
1661     //!           Return SwizzleOffset
1662     //!
1663     static int32_t MosSwizzleOffset(
1664         int32_t         OffsetX,
1665         int32_t         OffsetY,
1666         int32_t         Pitch,
1667         MOS_TILE_TYPE   TileFormat,
1668         int32_t         CsxSwizzle,
1669         int32_t         flags);
1670 
1671 #ifdef _MOS_UTILITY_EXT
1672     static int32_t MosSwizzleOffsetExt(
1673         int32_t       OffsetX,
1674         int32_t       OffsetY,
1675         int32_t       Pitch,
1676         MOS_TILE_TYPE TileFormat,
1677         int32_t       CsxSwizzle,
1678         int32_t       extFlags);
1679 #endif
1680 
1681     //!
1682     //! \brief    Wrapper function for SwizzleOffset
1683     //! \details  Wrapper function for SwizzleOffset in Mos
1684     //! \param    [in] pSrc
1685     //!           Pointer to source data.
1686     //! \param    [out] pDst
1687     //!           Pointer to destiny data.
1688     //! \param    [in] SrcTiling
1689     //!           Source Tile Type
1690     //! \param    [in] DstTiling
1691     //!           Destiny Tile Type
1692     //! \param    [in] iHeight
1693     //!           Height
1694     //! \param    [in] iPitch
1695     //!           Pitch
1696     //! \param    [in] extended flags
1697     //!           Pitch
1698     //! \return   void
1699     //!
1700     static void MosSwizzleData(
1701         uint8_t         *pSrc,
1702         uint8_t         *pDst,
1703         MOS_TILE_TYPE   SrcTiling,
1704         MOS_TILE_TYPE   DstTiling,
1705         int32_t         iHeight,
1706         int32_t         iPitch,
1707         int32_t         extFlags);
1708 
1709     //!
1710     //! \brief    MOS trace event initialize
1711     //! \details  register provide Global ID to the system.
1712     //! \param    void
1713     //! \return   void
1714     //!
1715     static void MosTraceEventInit();
1716 
1717     //!
1718     //! \brief    MOS trace event close
1719     //! \details  un-register provider Global ID.
1720     //! \param    void
1721     //! \return   void
1722     //!
1723     static void MosTraceEventClose();
1724 
1725     //!
1726     //! \brief    setup static platform info for trace events
1727     //! \details  send static platform info to trace struct, which itself determine when to send them.
1728     //!           static platform info should only send 1 time per trace capture, no more no less.
1729     //! \param    [in] driver version
1730     //! \param    [in] platform family
1731     //! \param    [in] render family
1732     //! \param    [in] device id
1733     //! \return   void
1734     //!
1735     static void MosTraceSetupInfo(uint32_t DrvVer, uint32_t PlatFamily, uint32_t RenderFamily, uint32_t DeviceID);
1736 
1737     //!
1738     //! \brief    MOS log trace event
1739     //! \details  log trace event by id and event type, arg1 and arg2 are optional arguments
1740     //!           arguments are in raw data format, need match data structure in manifest.
1741     //! \param    [in] usId
1742     //!           Indicates event id
1743     //! \param    [in] ucType
1744     //!           Indicates event type
1745     //! \param    [in] pArg1
1746     //!           event data address
1747     //! \param    [in] dwSize1
1748     //!           event data size
1749     //! \param    [in] pArg2
1750     //!           event data address
1751     //! \param    [in] dwSize2
1752     //!           event data size
1753     //! \return   void
1754     //!
1755     static void MosTraceEvent(
1756         uint16_t         usId,
1757         uint8_t          ucType,
1758         void * const     pArg1,
1759         uint32_t         dwSize1,
1760         void * const     pArg2,
1761         uint32_t         dwSize2);
1762 
1763     //!
1764     //! \brief    MOS log trace event Msg
1765     //! \details  log trace event msg w/ level/compID/functionname/lineNum arguments
1766     //!           arguments are in raw data format, need match data structure in manifest.
1767     //! \param    [in] level
1768     //!           Indicates msg level
1769     //! \param    [in] compID
1770     //!           Indicates compID
1771     //! \param    [in] message
1772     //!           event msg
1773     //! \param    [in] functionName
1774     //!           func name
1775     //! \param    [in] lineNum
1776     //!           event line number
1777     //! \return   void
1778     //!
1779     static void MosTraceEventMsg(
1780         uint8_t          level,
1781         uint8_t          compID,
1782         void*            message,
1783         void*            functionName,
1784         uint32_t         lineNum);
1785 
1786     static void MosTraceDataDump(
1787         const char *pcName,
1788         uint32_t    flags,
1789         const void *pBuf,
1790         uint32_t    dwSize);
1791 
1792     //!
1793     //! \brief    MosGfxInfoRTErr
1794     //! \details  Custom gfx info trace to report runtime errors detected by each component.
1795     //! \param    [in] ver
1796     //!           Version
1797     //! \param    [in] compId
1798     //!           Component ID defined in GFXINFO_COMP_ID
1799     //! \param    [in] FtrId
1800     //!           Feature ID, an unique identifier for each component.
1801     //! \param    [in] ErrorCode
1802     //!           Error code that will be recorded.
1803     //! \param    [in] num_of_triples
1804     //!           Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element
1805     //! \param    [in] ...
1806     //!           Triples (name, type, value), for example
1807     //!             int8_t i = 3;
1808     //!             "Name1", GFXINFO_PTYPE_UINT8, &i
1809     //!             "Name2", GFXINFO_PTYPE_ANSISTRING, "string value"
1810     //! \return   void
1811     //!
1812     static void MosGfxInfoRTErr(uint8_t ver,
1813         uint16_t    compId,
1814         uint16_t    FtrId,
1815         uint32_t    ErrorCode,
1816         uint8_t     num_of_triples,
1817         ...);
1818 
1819     //!
1820     //! \brief    MosGfxInfoRTErrInternal
1821     //! \details  Custom gfx info trace to report runtime errors detected by each component.
1822     //! \param    [in] ver
1823     //!           Version
1824     //! \param    [in] compId
1825     //!           Component ID defined in GFXINFO_COMP_ID
1826     //! \param    [in] FtrId
1827     //!           Feature ID, an unique identifier for each component.
1828     //! \param    [in] ErrorCode
1829     //!           Error code that will be recorded.
1830     //! \param    [in] num_of_triples
1831     //!           Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element
1832     //! \param    [in] var_args
1833     //!           Triples (name, type, value), for example
1834     //!             int8_t i = 3;
1835     //!             "Name1", GFXINFO_PTYPE_UINT8, &i
1836     //!             "Name2", GFXINFO_PTYPE_ANSISTRING, "string value"
1837     //! \return   void
1838     //!
1839     static void MosGfxInfoRTErrInternal(uint8_t ver,
1840         uint16_t                        compId,
1841         uint16_t                        FtrId,
1842         uint32_t                        ErrorCode,
1843         uint8_t                         num_of_triples,
1844         va_list                         args);
1845 
1846     //!
1847     //! \brief    MosGfxInfo
1848     //! \details  A helper function to help to compose gfx info xml string
1849     //! \param    [in] ver
1850     //!           Version
1851     //! \param    [in] compId
1852     //!           Component ID defined in GFXINFO_COMP_ID
1853     //! \param    [in] tmtryID
1854     //!           Gfx info ID, an unique identifier for each component.
1855     //! \param    [in] num_of_triples
1856     //!           Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element
1857     //! \param    [in] ...
1858     //!           Triples (name, type, value), for example
1859     //!             int8_t i = 3;
1860     //!             "Name1", GFXINFO_PTYPE_UINT8, &i
1861     //!             "Name2", GFXINFO_PTYPE_ANSISTRING, "string value"
1862     //! \return   void
1863     //!
1864     static void MosGfxInfo(
1865         uint8_t         ver,
1866         uint16_t        compId,
1867         uint32_t        tmtryID,
1868         uint8_t         num_of_triples,
1869         ...);
1870 
1871     //!
1872     //! \brief    MosGfxInfoInternal
1873     //! \details  A helper function to help to compose gfx info xml string
1874     //! \param    [in] ver
1875     //!           Version
1876     //! \param    [in] compId
1877     //!           Component ID defined in GFXINFO_COMP_ID
1878     //! \param    [in] tmtryID
1879     //!           Gfx info ID, an unique identifier for each component.
1880     //! \param    [in] num_of_triples
1881     //!           Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element
1882     //! \param    [in] var_args
1883     //!           Triples (name, type, value), for example
1884     //!             int8_t i = 3;
1885     //!             "Name1", GFXINFO_PTYPE_UINT8, &i
1886     //!             "Name2", GFXINFO_PTYPE_ANSISTRING, "string value"
1887     //! \return   void
1888     //!
1889     static void MosGfxInfoInternal(
1890         uint8_t  ver,
1891         uint16_t compId,
1892         uint32_t tmtryID,
1893         uint8_t  num_of_triples,
1894         va_list  args);
1895 
1896 private:
1897 
1898     //!
1899     //!
1900     //! \brief    Destroy the User Feature Value pointer according to the Global DescField Table
1901     //! \details  Destroy the User Feature Value pointer according to the Global DescField Table
1902     //!           destroy the gc_UserFeatureKeysMap according to Declare Count
1903     //! \return   MOS_STATUS
1904     //!           Returns one of the MOS_STATUS error codes if failed,
1905     //!           else MOS_STATUS_SUCCESS
1906     //!
1907     static MOS_STATUS MosDestroyUserFeatureKeysForAllDescFields();
1908 
1909     //!
1910     //! \brief    Write one user feature key into XML file
1911     //! \details  Write one user feature key into XML file
1912     //! \param    [out] keyValueMap
1913     //!           Unused in this function
1914     //! \param    [in] pUserFeature
1915     //!           Pointer to User Feature Value that is needed to be written
1916     //! \return   MOS_STATUS
1917     //!           Returns one of the MOS_STATUS error codes if failed,
1918     //!           else MOS_STATUS_SUCCESS
1919     //!
1920     static MOS_STATUS MosWriteOneUserFeatureKeyToXML(PMOS_USER_FEATURE_VALUE pUserFeature);
1921 
1922     //!
1923     //! \brief    Write one User Feature Group into XML file
1924     //! \details  Write one User Feature Group into XML file
1925     //! \param  MOS_USER_FEATURE_VALUE   UserFeatureFilter
1926     //!           [in] Pointer to User Feature Value filter that contains the targeted group
1927     //! \return   MOS_STATUS
1928     //!           Returns one of the MOS_STATUS error codes if failed,
1929     //!           else MOS_STATUS_SUCCESS
1930     //!
1931     static MOS_STATUS MosWriteOneUserFeatureGroupToXML(MOS_USER_FEATURE_VALUE   UserFeatureFilter);
1932 
1933     //!
1934     //! \brief    Link the m_mosUserFeatureDescFields table items to MosUtilUserInterface::m_userFeatureKeyMap
1935     //! \details  Link the m_mosUserFeatureDescFields table items to MosUtilUserInterface::m_userFeatureKeyMap
1936     //!           according to ID sequence and do some post processing such as malloc related memory
1937     //! \return   MOS_STATUS
1938     //!           Returns one of the MOS_STATUS error codes if failed,
1939     //!           else MOS_STATUS_SUCCESS
1940     //!
1941     static MOS_STATUS MosDeclareUserFeatureKeysForAllDescFields();
1942 
1943     //!
1944     //! \brief    Link the user feature key Desc Fields table items to key value map
1945     //! \details  Link the user feature key Desc Fields table items to key value map
1946     //!           according to ID sequence and do some post processing by calling MosAssignUserFeatureValueData
1947     //! \param    [in] pUserFeatureKey
1948     //!           Pointer to the User Feature Value needed to be declared
1949     //! \return   MOS_STATUS
1950     //!           Returns one of the MOS_STATUS error codes if failed,
1951     //!           else MOS_STATUS_SUCCESS
1952     //!
1953     static MOS_STATUS MosDeclareUserFeatureKey(PMOS_USER_FEATURE_VALUE pUserFeatureKey);
1954 
1955     //!
1956     //! \brief    Read Single Value from User Feature based on value of enum type in MOS_USER_FEATURE_VALUE_TYPE with specified map table
1957     //! \details  This is a unified funtion to read user feature key for all components.
1958     //!           (Codec/VP/CP/CM)
1959     //!           It is required to prepare all memories for buffers before calling this function.
1960     //!           User can choose to use array variable or allocated memory for the buffer.
1961     //!           If the buffer is allocated dynamically, it must be freed by user to avoid memory leak.
1962     //!           ------------------------------------------------------------------------------------
1963     //!           Usage example:
1964     //!           a) Initiation:
1965     //!           MosZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
1966     //!           b.0) Don't need to input a default value if the default value in user feature key Desc Fields table is good
1967     //!                for your case
1968     //!           b.1) For uint32_t type:
1969     //!           UserFeatureData.u32Data = 1;    // overwrite a custom default value
1970     //!           UserFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
1971      //!                                           // raise a flag to use this custom default value instead of
1972     //!                                              default value in user feature key Desc Fields table
1973     //!           b.2) For String/Binary type:
1974     //!           char cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE];
1975     //!           UserFeatureData.StringData.pStringData = cStringData; // make sure the pointer is valid
1976     //!           b.3) For MultiString type:
1977     //!           char                          cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE];
1978     //!           MOS_USER_FEATURE_VALUE_STRING Strings[__MAX_MULTI_STRING_COUNT];
1979     //!           UserFeatureData.MultiStringData.pMultStringData = cStringData; // make sure the pointer is valid
1980     //!           for (ui = 0; ui < VPHAL_3P_MAX_LIB_PATH_COUNT; ui++)
1981     //!           {
1982     //!             Strings[ui].pStringData = (char *)MOS_AllocAndZeroMemory(MOS_USER_CONTROL_MAX_DATA_SIZE);
1983     //!           }
1984     //!           UserFeatureData.MultiStringData.pStrings = Strings;
1985     //!           c) Read user feature key:
1986     //!           MosUserFeatureReadValueID();
1987     //!           -------------------------------------------------------------------------------------
1988     //!           Important note: The pointer pStringData/pMultStringData may be modified if the
1989     //!           previous MOS_UserFeature_ReadValue() doesn't read a same user feature key type. So it's
1990     //!           suggested to set the union members in UserFeatureValue every time before
1991     //!           MOS_UserFeature_ReadValue() if you are not familiar with the details of this function.
1992     //!           If a new key is added, please make sure to declare a definition in corresponding
1993     //!           user feature key Desc Fields table by MOS_DECLARE_UF_KEY
1994     //! \param    [in] pOsUserFeatureInterface
1995     //!           Pointer to OS User Interface structure
1996     //! \param    [in] ValueID
1997     //!           value of enum type in MOS_USER_FEATURE_VALUE_TYPE. declares the user feature key to be readed
1998     //! \param    [in,out] pUserData
1999     //!           Pointer to User Feature Data
2000     //! \return   MOS_STATUS
2001     //!           Returns one of the MOS_STATUS error codes if failed,
2002     //!           else MOS_STATUS_SUCCESS
2003     //!           For pValueData return value:
2004     //!                 MOS_STATUS_SUCCESS: pValueData is from User Feature Key
2005     //!                 MOS_STATUS_USER_FEATURE_KEY_OPEN_FAILED: pValueData is from default value
2006     //!                 MOS_STATUS_UNKNOWN: pValueData is from default value
2007     //!                 MOS_STATUS_USER_FEATURE_KEY_READ_FAILED: pValueData is from default value
2008     //!                 MOS_STATUS_NULL_POINTER: NO USER FEATURE KEY DEFINITION in corresponding user feature key Desc Field table,
2009     //!                                          No default value or User Feature Key value return
2010     //!
2011     //!
2012     static MOS_STATUS MosUserFeatureReadValueFromMapID(
2013         uint32_t                        ValueID,
2014         PMOS_USER_FEATURE_VALUE_DATA    pValueData);
2015 
2016 #if (_DEBUG || _RELEASE_INTERNAL)
2017     //!
2018     //! \brief    Get the User Feature File location
2019     //! \details  Get the User Feature File location
2020     //! \param    uint32_t& userfeatureValue
2021     //!           [in] reference to a userfeatureValue
2022     //! \return   MOS_STATUS
2023     //!           Returns one of the MOS_STATUS error codes if failed,
2024     //!           else MOS_STATUS_SUCCESS
2025     //!
2026     static MOS_STATUS MosGetApoMosEnabledUserFeatureFile();
2027 
2028 #endif
2029 
2030     //!
2031     //! \brief    User Feature Callback function
2032     //! \details  User Feature Callback function
2033     //!           Notifies the caller that the CB is triggered
2034     //! \param    void  *pvParameter
2035     //!           [out] Pointer to the User Feature Notification Data for
2036     //!                 which callback is requested
2037     //! \param    int32_t TimerOrWait
2038     //!           [in/out] Flag to indicate if a timer or wait is applied
2039     //!                    (Not used currently)
2040     //! \return   void
2041     //!
2042     static void MosUserFeatureCallback(
2043         PTP_CALLBACK_INSTANCE Instance,
2044         void *                pvParameter,
2045         PTP_WAIT              Wait,
2046         TP_WAIT_RESULT        WaitResult);
2047 
2048     //!
2049     //! \brief    Open the user feature based on the access type requested
2050     //! \details  Open the user feature based on the access type requested
2051     //!           MOS_USER_FEATURE_TYPE_USER will be UFINT
2052     //!           MOS_USER_FEATURE_TYPE_SYSTEM will be UFEXT
2053     //! \param    MOS_USER_FEATURE_TYPE KeyType
2054     //!           [in] User Feature Type
2055     //! \param    char  *pSubKey
2056     //!           [in] Pointer to the subkey
2057     //! \param    uint32_t dwAccess,
2058     //!           [in] Desired access rights
2059     //! \param    void ** pUFKey
2060     //!           [out] Pointer to the variable that accepts the handle to
2061     //!                 the user feature key opened
2062     //!           [in]  in ConfigFS implementation, use pUFKey to pass the pUserFeature as a handler
2063     //! \return   MOS_STATUS
2064     //!           Returns one of the MOS_STATUS error codes if failed,
2065     //!           else MOS_STATUS_SUCCESS
2066     //!
2067     static MOS_STATUS MosUserFeatureOpen(
2068         MOS_USER_FEATURE_TYPE KeyType,
2069         const char            *pSubKey,
2070         uint32_t              dwAccess,
2071         void                  **pUFKey);
2072 
2073     //!
2074     //! \brief    Write Values to User Feature with specified Table and ID
2075     //! \details  Write Values to User Feature with specified Table and ID
2076     //!           The caller is responsible to allocate values / names
2077     //!           and free them later if necessary
2078     //! \param    PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface
2079     //!           [in] Pointer to OS User Interface structure
2080     //! \param    PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues
2081     //!           [in] Pointer to User Feature Data, and related User Feature Key ID (enum type in MOS_USER_FEATURE_VALUE_TYPE)
2082     //! \param    uint32_t uiNumOfValues
2083     //!           [in] number of user feature keys to be written.
2084     //! \return   MOS_STATUS
2085     //!           Returns one of the MOS_STATUS error codes if failed,
2086     //!           else MOS_STATUS_SUCCESS
2087     //!
2088     static MOS_STATUS MosUserFeatureWriteValuesTblID(
2089         PMOS_USER_FEATURE_VALUE_WRITE_DATA      pWriteValues,
2090         uint32_t                                uiNumOfValues);
2091 
2092     //!
2093     //! \brief    Wrapper for user feature value string free(). Performs error checking.
2094     //! \details  Wrapper for user feature value string free(). Performs error checking.
2095     //! \param    PMOS_USER_FEATURE_VALUE_STRING pUserString
2096     //!           [in] Pointer to the string structure with memory to be freed
2097     //! \return   void
2098     //!
2099     static void MosFreeUserFeatureValueString(PMOS_USER_FEATURE_VALUE_STRING pUserString);
2100 
2101     //!
2102     //! \brief    Free the allocated memory for the related Value type
2103     //! \details  Free the allocated memory for the related Value type
2104     //! \param  PMOS_USER_FEATURE_VALUE_DATA pData
2105     //!           [in] Pointer to the User Feature Value Data
2106     //! \param    MOS_USER_FEATURE_VALUE_TYPE ValueType
2107     //!           [in] related Value Type needed to be deallocated.
2108     //! \return   MOS_STATUS
2109     //!           Returns one of the MOS_STATUS error codes if failed,
2110     //!           else MOS_STATUS_SUCCESS
2111     //!
2112     static MOS_STATUS MosDestroyUserFeatureData(PMOS_USER_FEATURE_VALUE_DATA pData, MOS_USER_FEATURE_VALUE_TYPE ValueType);
2113 
2114     //!
2115     //! \brief    Unlink the user feature key Desc Fields table items to key value map
2116     //! \details  Unlink the user feature key Desc Fields table items to key value map
2117     //!           according to ID sequence and do some post processing by calling MOS_DestroyUserFeatureData
2118     //! \param    [in] pUserFeatureKey
2119     //!           Pointer to the User Feature Value needed to be destroyed
2120     //! \return   MOS_STATUS
2121     //!           Returns one of the MOS_STATUS error codes if failed,
2122     //!           else MOS_STATUS_SUCCESS
2123     //!
2124     static MOS_STATUS MosDestroyUserFeatureKey(PMOS_USER_FEATURE_VALUE pUserFeatureKey);
2125 
2126     //!
2127     //! \brief    Assign the value as a string type to destination Value Data pointer
2128     //! \details  Assign the value as a string type to destination Value Data pointer
2129     //! \param    PMOS_USER_FEATURE_VALUE_DATA pDstData
2130     //!           [in] Pointer to the Destination Value Data
2131     //! \param    const char * pData
2132     //!           [in] Pointer to the Value Data as string type
2133     //! \param    MOS_USER_FEATURE_VALUE_TYPE ValueType
2134     //!           [in] Value Type for the copy data
2135     //! \return   MOS_STATUS
2136     //!           Returns one of the MOS_STATUS error codes if failed,
2137     //!           else MOS_STATUS_SUCCESS
2138     //!
2139     static MOS_STATUS MosAssignUserFeatureValueData(
2140         PMOS_USER_FEATURE_VALUE_DATA    pDstData,
2141         const char                      *pData,
2142         MOS_USER_FEATURE_VALUE_TYPE     ValueType);
2143 
2144     //!
2145     //! \brief     check the input Default Value type
2146     //! \details  check the input Default Value type
2147     //! \param  const char * pData
2148     //!           [in] Pointer to the Default Value String
2149     //! \param  MOS_USER_FEATURE_VALUE_TYPE ValueType
2150     //!           [in] User Feature Value type needed to be check
2151     //! \return   MOS_STATUS
2152     //!           Returns one of the MOS_STATUS error codes if failed,
2153     //!           else MOS_STATUS_SUCCESS
2154     //!
2155     static MOS_STATUS MosIsCorrectDefaultValueType(
2156         const char                  *pData,
2157         MOS_USER_FEATURE_VALUE_TYPE ValueType);
2158 
2159     //!
2160     //! \brief    Check the User Feature Value correct or not
2161     //! \details  Check the User Feature Value correct or not
2162     //! \param    [in] pUserFeatureKey
2163     //!           Pointer to the User Feature Value needed to be checked
2164     //! \param    [in] maxKeyID
2165     //!           The max possible key ID in the corresponding table
2166     //! \return   MOS_STATUS
2167     //!           Returns one of the MOS_STATUS error codes if failed,
2168     //!           else MOS_STATUS_SUCCESS
2169     //!
2170     static MOS_STATUS MosIsCorrectUserFeatureDescField(PMOS_USER_FEATURE_VALUE pUserFeatureKey, uint32_t maxKeyID);
2171 
2172     //!
2173     //! \brief    Get the User Feature Value from Table
2174     //! \details  Get the related User Feature Value item according to Filter rules , and pass the item
2175     //!            into return callback function
2176     //! \param    [in] descTable
2177     //!           The user feature key description table
2178     //! \param    [in] numOfItems
2179     //!           Number of user feature keys described in the table
2180     //! \param    [in] maxId
2181     //!           Max value ID in the table
2182     //! \param    [out] keyValueMap
2183     //!           Optional pointer to the value map where the table items will be linked to, could be nullptr
2184     //! \param    [in] CallbackFunc
2185     //!           Pointer to the Callback function, and pass the User Feature Value item as its parameter
2186     //! \param    [in] pUserFeatureKeyFilter
2187     //!           use the filter rule to select some User Feature Value item
2188     //! \return   MOS_STATUS
2189     //!           Returns one of the MOS_STATUS error codes if failed,
2190     //!           else MOS_STATUS_SUCCESS
2191     //!
2192     static MOS_STATUS MosGetItemFromMosUserFeatureDescField(
2193         MOS_USER_FEATURE_VALUE      *descTable,
2194         uint32_t                    numOfItems,
2195         uint32_t                    maxId,
2196         MOS_STATUS(*CallbackFunc)(PMOS_USER_FEATURE_VALUE),
2197         PMOS_USER_FEATURE_VALUE     pUserFeatureKeyFilter);
2198 
2199     //!
2200     //! \brief    Write string value to the user feature
2201     //! \details  Write string value to the user feature
2202     //! \param    void  *UFKey
2203     //!           [in] Handle to the user feature key
2204     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2205     //!           [in] Pointer to User Feature that contains user feature key info
2206     //! \param    PMOS_USER_FEATURE_VALUE_DATA pDataValue
2207     //!           [in] Pointer to User Feature Data that contains the string
2208     //! \return   MOS_STATUS
2209     //!           Returns one of the MOS_STATUS error codes if failed,
2210     //!           else MOS_STATUS_SUCCESS
2211     //!
2212     static MOS_STATUS  MosUserFeatureWriteValueString(
2213         void                            *UFKey,
2214         PMOS_USER_FEATURE_VALUE         pFeatureValue,
2215         PMOS_USER_FEATURE_VALUE_DATA    pDataValue);
2216 
2217     //!
2218     //! \brief    Write multi string value to the user feature
2219     //! \details  Write multi string value to the user feature
2220     //!           It combines the multi string into a temp buffer
2221     //!           and call routine to write the user feature
2222     //! \param    void  *UFKey
2223     //!           [in] Handle to the user feature key
2224     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2225     //!           [in] Pointer to User Feature that contains user feature key info
2226     //! \param    PMOS_USER_FEATURE_VALUE_DATA pDataValue
2227     //!           [in] Pointer to User Feature Data that contains the multi string
2228     //! \return   MOS_STATUS
2229     //!           Returns one of the MOS_STATUS error codes if failed,
2230     //!           else MOS_STATUS_SUCCESS
2231     //!
2232     static MOS_STATUS MosUserFeatureWriteValueMultiString(
2233         void                            *UFKey,
2234         PMOS_USER_FEATURE_VALUE         pFeatureValue,
2235         PMOS_USER_FEATURE_VALUE_DATA    pDataValue);
2236 
2237     //!
2238     //! \brief    Write Binary value to the user feature
2239     //! \details  Write Binary value to the user feature
2240     //! \param    void  *UFKey
2241     //!           [in] Handle to the user feature key
2242     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2243     //!           [in] Pointer to User Feature that contains user feature key info
2244     //! \param    PMOS_USER_FEATURE_VALUE_DATA pDataValue
2245     //!           [in] Pointer to User Feature Data that contains the binary data
2246     //! \return   MOS_STATUS
2247     //!           Returns one of the MOS_STATUS error codes if failed,
2248     //!           else MOS_STATUS_SUCCESS
2249     //!
2250     static MOS_STATUS MosUserFeatureWriteValueBinary(
2251         void                            *UFKey,
2252         PMOS_USER_FEATURE_VALUE         pFeatureValue,
2253         PMOS_USER_FEATURE_VALUE_DATA    pDataValue);
2254 
2255     //!
2256     //! \brief    Write Primitive data value to the user feature
2257     //! \details  Write Primitive data value to the user feature
2258     //! \param    void  *UFKey
2259     //!           [in] Handle to the user feature key
2260     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2261     //!           [in] Pointer to User Feature that contains user feature key info
2262     //! \param    PMOS_USER_FEATURE_VALUE_DATA pDataValue
2263     //!           [in] Pointer to User Feature Data that contains the primitive data
2264     //! \return   MOS_STATUS
2265     //!           Returns one of the MOS_STATUS error codes if failed,
2266     //!           else MOS_STATUS_SUCCESS
2267     //!
2268     static MOS_STATUS MosUserFeatureWriteValuePrimitive(
2269         void                            *UFKey,
2270         PMOS_USER_FEATURE_VALUE         pFeatureValue,
2271         PMOS_USER_FEATURE_VALUE_DATA    pDataValue);
2272 
2273     //!
2274     //! \brief    Read binary value from the user feature
2275     //! \details  Read binary value from the user feature,
2276     //!           and store it into the user feature data
2277     //! \param    void  *UFKey
2278     //!           [in] Handle to the user feature key
2279     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2280     //!           [in/out] Pointer to User Feature Data
2281     //! \return   MOS_STATUS
2282     //!           Returns one of the MOS_STATUS error codes if failed,
2283     //!           else MOS_STATUS_SUCCESS
2284     //!
2285     static MOS_STATUS MosUserFeatureReadValueBinary(
2286         void                       *UFKey,
2287         PMOS_USER_FEATURE_VALUE    pFeatureValue);
2288 
2289     //!
2290     //! \brief    Read string value from the user feature
2291     //! \details  Read string value from the user feature,
2292     //!           and store it into the user feature data
2293     //! \param    void  *UFKey
2294     //!           [in] Handle to the user feature key
2295     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2296     //!           [in/out] Pointer to User Feature Data
2297     //! \return   MOS_STATUS
2298     //!           Returns one of the MOS_STATUS error codes if failed,
2299     //!           else MOS_STATUS_SUCCESS
2300     //!
2301     static MOS_STATUS MosUserFeatureReadValueString(
2302         void                       *UFKey,
2303         PMOS_USER_FEATURE_VALUE    pFeatureValue);
2304 
2305     //!
2306     //! \brief    Read multi string value from the user feature
2307     //! \details  Read multi string value from the user feature,
2308     //!           and store it into the user feature data
2309     //! \param    void  *UFKey
2310     //!           [in] Handle to the user feature key
2311     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2312     //!           [in/out] Pointer to User Feature Data
2313     //! \return   MOS_STATUS
2314     //!           Returns one of the MOS_STATUS error codes if failed,
2315     //!           else MOS_STATUS_SUCCESS
2316     //!
2317     static MOS_STATUS MosUserFeatureReadValueMultiString(
2318         void                       *UFKey,
2319         PMOS_USER_FEATURE_VALUE    pFeatureValue);
2320 
2321     //!
2322     //! \brief    Read Primitive data value from the user feature
2323     //! \details  Read Primitive data value from the user feature,
2324     //!           and store it into the user feature data
2325     //! \param    void  *UFKey
2326     //!           [in] Handle to the user feature key
2327     //! \param    PMOS_USER_FEATURE_VALUE pFeatureValue
2328     //!           [in/out] Pointer to User Feature Data
2329     //! \return   MOS_STATUS
2330     //!           Returns one of the MOS_STATUS error codes if failed,
2331     //!           else MOS_STATUS_SUCCESS
2332     //!
2333     static MOS_STATUS MosUserFeatureReadValuePrimitive(
2334         void                       *UFKey,
2335         PMOS_USER_FEATURE_VALUE    pFeatureValue);
2336 
2337     //!
2338     //! \brief    Initializes read user feature value function
2339     //! \details  Initializes read user feature value function
2340     //!           This is an internal function of MOS utilitiesNext.
2341     //!           It is implemented to support two differnt usages of MOS_UserFeature_ReadValue()
2342     //!           One usage comes with user pre-allocated user value,
2343     //!           the other comes with nullptr user value, and this function will allocate for it.
2344     //!           Please refer to MOS_UserFeature_ReadValue() or function body for details.
2345     //! \param    PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface
2346     //!           [in] Pointer to OS user feature interface
2347     //! \param    PMOS_USER_FEATURE pUserFeature
2348     //!           [in/out] Pointer to user feature interface
2349     //! \param    char  *pValueName,
2350     //!           [in] Pointer to value name
2351     //! \param    MOS_USER_FEATURE_VALUE_TYPE ValueType
2352     //!           [in] User Feature Value type
2353     //! \return   MOS_STATUS
2354     //!           Returns one of the MOS_STATUS error codes if failed,
2355     //!           else MOS_STATUS_SUCCESS
2356     //!
2357     static MOS_STATUS MosUserFeatureReadValueInit(
2358         uint32_t                      uiNumValues);
2359 
2360     //!
2361     //! \brief    Set the Multi String Value to Settings Data
2362     //! \details  Set the Multi String Value to Settings Data
2363     //!           It parses the given multi string value,
2364     //!           assign UserFeatureValue's multistring data
2365     //!           with pointers to the strings
2366     //! \param    PMOS_USER_FEATURE_VALUE_DATA pFeatureData
2367     //!           [out] Pointer to User Feature Data
2368     //! \param    void  *pvData
2369     //!           [in] Pointer to the multi string value
2370     //! \param    uint32_t dwSize
2371     //!           [in] Size of the multi string value
2372     //! \return   MOS_STATUS
2373     //!           Returns one of the MOS_STATUS error codes if failed,
2374     //!           else MOS_STATUS_SUCCESS
2375     //!
2376     static MOS_STATUS MosUserFeatureSetMultiStringValue(
2377         PMOS_USER_FEATURE_VALUE_DATA     pFeatureData,
2378         uint32_t                         dwSize);
2379 
2380     //!
2381     //! \brief    MOS gfx info initialize
2382     //! \details  Load igdinfoXX.dll library and get gfx info function pointer
2383     //! \param    void
2384     //! \return   MOS_STATUS
2385     //!           Returns one of the MOS_STATUS error codes if failed,
2386     //!           else MOS_STATUS_SUCCESS
2387     //!
2388     static MOS_STATUS MosGfxInfoInit();
2389 
2390     //!
2391     //! \brief    MOS gfx info close
2392     //! \details  Release igdinfoXX.dll library
2393     //! \param    void
2394     //! \return   void
2395     //!
2396     static void MosGfxInfoClose();
2397 
2398 public:
2399     static uint8_t                      m_mosUltFlag;
2400     static int32_t                      m_mosMemAllocCounterNoUserFeature;
2401     static int32_t                      m_mosMemAllocCounterNoUserFeatureGfx;
2402 
2403     //Temporarily defined as the reference to compatible with the cases using uf key to enable/disable APG.
2404     static int32_t                      m_mosMemAllocCounter;
2405     static int32_t                      m_mosMemAllocFakeCounter;
2406     static int32_t                      m_mosMemAllocCounterGfx;
2407 
2408     static bool                         m_enableAddressDump;
2409 
2410 private:
2411     static MosMutex                     m_mutexLock;
2412     static char                         m_xmlFilePath[MOS_USER_CONTROL_MAX_DATA_SIZE];
2413     static PMOS_USER_FEATURE_VALUE const m_mosUserFeatureDescFields;
2414     static uint32_t                     m_mosUtilInitCount; // number count of mos utilities init
2415 #if _MEDIA_RESERVED
2416     static MediaUserSettingsMgr*        m_codecUserFeatureExt;
2417     static MediaUserSettingsMgr*        m_vpUserFeatureExt;
2418 #endif
2419 #if (_DEBUG || _RELEASE_INTERNAL)
2420     static uint32_t                     m_mosAllocMemoryFailSimulateMode;
2421     static uint32_t                     m_mosAllocMemoryFailSimulateFreq;
2422     static uint32_t                     m_mosAllocMemoryFailSimulateHint;
2423     static uint32_t                     m_mosAllocMemoryFailSimulateAllocCounter;
2424 #endif
2425     static MOS_USER_FEATURE_KEY_PATH_INFO m_mosUtilUserFeatureKeyPathInfo;
2426 };
2427 
2428 #endif // __MOS_UTILITIESNext_NEXT_H__
2429