Debian Codegraph @

media_softlet/linux/common/os/osservice/mos_utilities_specific.h

raw
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_specific.h
24 //! \brief This module defines MOS interface on Linux/Android platform
25 //!
26 #ifndef __MOS_UTILITIES_SPECIFIC_H__
27 #define __MOS_UTILITIES_SPECIFIC_H__
28
29 #include <map>
30 #include <malloc.h>
31 #include <string>
32 #include "mos_defs.h"
33 #include "media_class_trace.h"
34
35 #define LINUX_OS_VERSION_FILE "/proc/version"
36
37 #define NOT_FOUND -1
38
39 #define _aligned_malloc(size, alignment) memalign(alignment, size)
40 #define _aligned_free(ptr) free(ptr)
41
42 typedef void (*MOS_UserFeatureCallback)( void*, bool);
43
44 class MosMutex;
45
46 #define USER_FEATURE_KEY_INTERNAL "UFKEY_INTERNAL\\"
47 #define USER_FEATURE_KEY_EXTERNAL "UFKEY_EXTERNAL\\"
48
49 //user feature
50 #if ANDROID_VERSION >= 800
51 #define USER_FEATURE_FILE "/data/igfx_user_feature.txt"
52 #else
53 #define USER_FEATURE_FILE "/etc/igfx_user_feature.txt"
54 #define USER_FEATURE_FILE_NEXT "/etc/igfx_user_feature_next.txt"
55 #define USER_FEATURE_FILE_REPORT "/etc/igfx_user_feature_report.txt"
56 #ifdef SYSCONFDIR
57 #define GFX_CONF_FILE SYSCONFDIR "/libva.conf"
58 #else
59 #define GFX_CONF_FILE "/etc/libva.conf"
60 #endif
61 #endif
62 #define UF_KEY_ID "[KEY]"
63 #define UF_VALUE_ID "[VALUE]"
64 #define UF_CAPABILITY 64
65 #define MAX_USERFEATURE_LINE_LENGTH 256
66 #define MAX_UF_LINE_STRING_FORMAT "%255[^\n]\n"
67
68 #define UF_NONE ( 0 ) // No value type
69 #define UF_SZ ( 1 ) // Unicode nul terminated string
70 #define UF_EXPAND_SZ ( 2 ) // Unicode nul terminated string
71 // (with environment variable references)
72 #define UF_BINARY ( 3 ) // Free form binary
73 #define UF_DWORD ( 4 ) // 32-bit number
74 #define UF_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as UF_DWORD)
75 #define UF_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
76 #define UF_LINK ( 6 ) // Symbolic Link (unicode)
77 #define UF_MULTI_SZ ( 7 ) // Multiple Unicode strings
78 #define UF_RESOURCE_LIST ( 8 ) // Resource list in the resource map
79 #define UF_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
80 #define UF_RESOURCE_REQUIREMENTS_LIST ( 10 )
81 #define UF_QWORD ( 11 ) // 64-bit number
82 #define UF_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as UF_QWORD)
83
84 #define RRF_RT_UF_NONE 0x00000001
85 #define RRF_RT_UF_SZ 0x00000002
86 #define RRF_RT_UF_EXPAND_SZ 0x00000004
87 #define RRF_RT_UF_BINARY 0x00000008
88 #define RRF_RT_UF_DWORD 0x00000010
89 #define RRF_RT_UF_MULTI_SZ 0x00000020
90 #define RRF_RT_UF_QWORD 0x00000040
91
92 #define KEY_READ 0
93 #define KEY_WRITE 1
94
95 #define UFKEY_INTERNAL (( uint32_t ) 0x80000001 )
96 #define UFKEY_EXTERNAL (( uint32_t ) 0x80000002 )
97
98 #define UFKEY_INTERNAL_NEXT ""
99 #define USER_SETTING_CONFIG_PATH "[config]"
100 #define USER_SETTING_CONFIG_PERF_PATH "[config]"
101 #define USER_SETTING_CONFIG_PERMANENT_PATH "[config]"
102 #define USER_SETTING_REPORT_PATH "[report]"
103
104 #define MAX_UF_PATH 256
105 #define DEFAULT_SUBKEY "LibVa"
106 #define UFINT_PATH_LINUX "UFINT"
107 #define UFEXT_PATH_LINUX "UFEXT"
108
109 using RegBufferMap = std::map<std::string, std::map<std::string, std::string>>;
110
111 #define __MEDIA_USER_FEATURE_SUBKEY_INTERNAL "LibVa"
112 #define __MEDIA_USER_FEATURE_SUBKEY_PERFORMANCE ""
113 #define __MEDIA_USER_FEATURE_SUBKEY_PERMANENT ""
114 #define __MEDIA_USER_FEATURE_SUBKEY_REPORT "Report"
115 #define __MOS_USER_FEATURE_KEY_XML_FILEPATH_LOCATION "LibVa"
116 #define __MEDIA_USER_FEATURE_SUBKEY_REPORT_EXTERNAL ""
117
118 #define __MOS_USER_FEATURE_VALUE_ADAPTIVE_TRANSFORM_DECISION_ENABLE_DEFAULT_VALUE "0"
119
120 //!
121 //! \brief User feature keys to define debug message levels and assertions.
122 //!
123
124 #if MOS_MESSAGES_ENABLED
125 //!
126 //! \brief Default setting is only critical prints are enabled, so users are not bombarded with irrelevant messages
127 //!
128 #define __MOS_USER_FEATURE_KEY_MESSAGE_DEFAULT_VALUE (0x1)
129 #endif // MOS_MESSAGES_ENABLED
130
131 typedef struct _MOS_UF_VALUE {
132 char pcValueName[MAX_USERFEATURE_LINE_LENGTH];
133 uint32_t ulValueLen;
134 void *ulValueBuf;
135 uint32_t ulValueType;
136 } MOS_UF_VALUE;
137
138 typedef struct _MOS_UF_KEY {
139 void *UFKey;
140 char pcKeyName[MAX_USERFEATURE_LINE_LENGTH];
141 int32_t valueNum;
142 MOS_UF_VALUE *pValueArray;
143 } MOS_UF_KEY;
144
145 typedef struct _MOS_UF_KEY_NODE_T
146 {
147 MOS_UF_KEY* pElem;
148 struct _MOS_UF_KEY_NODE_T* pNext;
149 } MOS_UF_KEYNODE;
150
151 typedef MOS_UF_KEYNODE* MOS_PUF_KEYLIST;
152
153 class MosUtilitiesSpecificNext
154 {
155 public:
156
157 /*----------------------------------------------------------------------------
158 | Name : MosUserFeatureSetValueExFile
159 | Purpose : Sets the data and type of a specified value under a user feature key.
160 | Arguments : UFKey [in] A handle to an open user feature key.
161 | lpValueName [in] The name of the user feature value.
162 | Reserved in] This parameter is reserved and must be NULL.
163 | dwType [in] The type of data pointed to by the lpData
164 | parameter.
165 | lpData [in] The data to be stored.
166 | cbData [in] The size of the information pointed to by the
167 | lpData parameter, in bytes.
168 | Returns : If the function succeeds, the return value is MOS_STATUS_SUCCESS.
169 | If the function fails, the return value is a error code defined
170 | in mos_utilities.h.
171 | Comments :
172 \---------------------------------------------------------------------------*/
173 static MOS_STATUS MosUserFeatureSetValueExFile(
174 void *UFKey,
175 const char *lpValueName,
176 uint32_t Reserved,
177 uint32_t dwType,
178 uint8_t *lpData,
179 uint32_t cbData);
180
181
182 /*----------------------------------------------------------------------------
183 | Name : MosUserFeatureGetValueFile
184 | Purpose : Retrieves the type and data for the specified user feature value.
185 | Arguments : UFKey [in] A handle to an open user feature key.
186 | lpSubKey [in] The name of the user feature key. This key must be a
187 | subkey of the key specified by the UFKey parameter
188 | lpValue [in] The name of the user feature value.
189 | dwFlags [in] Reserved, could be any uint32_t type value
190 | pdwType [out] A pointer to a variable that receives a code
191 | indicating the type of data stored in the
192 | specified value.
193 | pvData [out] A pointer to a buffer that receives the value's
194 | data.
195 | pcbData [out] A pointer to a variable that specifies the size
196 | of the buffer pointed to by the pvData parameter,
197 | in bytes.
198 | Returns : If the function succeeds, the return value is MOS_STATUS_SUCCESS.
199 | If the function fails, the return value is a error code defined
200 | in mos_utilities.h.
201 | Comments :
202 \---------------------------------------------------------------------------*/
203 static MOS_STATUS MosUserFeatureGetValueFile(
204 void *UFKey,
205 const char *lpSubKey,
206 const char *lpValue,
207 uint32_t dwFlags,
208 uint32_t *pdwType,
209 void *pvData,
210 uint32_t *pcbData);
211
212 /*----------------------------------------------------------------------------
213 | Name : MosUserFeatureOpenKeyFile
214 | Purpose : Opens the specified user feature key.
215 | Arguments : ufKey [in] A handle to an open user feature key.
216 | lpSubKey [in] The name of the user feature subkey to be opened.
217 | ulOptions [in] This parameter is reserved and must be zero.
218 | samDesired [in] Reserved, could be any REGSAM type value
219 | phkResult [out] A pointer to a variable that receives a handle
220 | to the opened key.
221 | Returns : If the function succeeds, the return value is MOS_STATUS_SUCCESS.
222 | If the function fails, the return value is a error code defined
223 | in mos_utilities.h.
224 | Comments :
225 \---------------------------------------------------------------------------*/
226 static MOS_STATUS MosUserFeatureOpenKeyFile(
227 void *ufKey,
228 const char *lpSubKey,
229 uint32_t ulOptions, // reserved
230 uint32_t samDesired,
231 void **phkResult);
232
233 /*----------------------------------------------------------------------------
234 | Name : UserFeatureDumpFile
235 | Purpose : This function read the whole User Feature File and dump User Feature File
236 | data to key linked list.
237 | Arguments : szFileName [in] User Feature File name.
238 | pKeyList [out] Key Linked list.
239 | Returns : MOS_STATUS_SUCCESS Operation success.
240 | MOS_STATUS_USER_FEATURE_KEY_READ_FAILED User Feature File can't be open as read.
241 | MOS_STATUS_NO_SPACE no space left for allocate
242 | MOS_STATUS_UNKNOWN unknown user feature type found in User Feature File
243 | MOS_STATUS_INVALID_PARAMETER unknown items found in User Feature File
244 | Comments :
245 \---------------------------------------------------------------------------*/
246 static MOS_STATUS UserFeatureDumpFile(const char *const szFileName, MOS_PUF_KEYLIST *pKeyList);
247
248 /*----------------------------------------------------------------------------
249 | Name : UserFeatureDumpDataToFile
250 | Purpose : This function dump key linked list data to File.
251 | Arguments : szFileName [in] A handle to the File.
252 | pKeyList [in] Reserved, any LPDWORD type value.
253 | Returns : MOS_STATUS_SUCCESS Operation success.
254 | MOS_STATUS_USER_FEATURE_KEY_WRITE_FAILED File can't be written.
255 | Comments :
256 \---------------------------------------------------------------------------*/
257
258 static MOS_STATUS UserFeatureDumpDataToFile(const char *szFileName, MOS_PUF_KEYLIST pKeyList);
259
260 /*----------------------------------------------------------------------------
261 | Name : UserFeatureFreeKeyList
262 | Purpose : Free key list
263 | Arguments : pKeyList [in] key list to be free.
264 | Returns : None
265 | Comments :
266 \---------------------------------------------------------------------------*/
267 static void UserFeatureFreeKeyList(MOS_PUF_KEYLIST pKeyList);
268
269 private:
270
271 /*----------------------------------------------------------------------------
272 | Name : UserFeatureFindKey
273 | Purpose : This function finds a key in keys linked list according to key
274 | name.
275 | Arguments : pKeyList [in] Key Linked list.
276 | pcKeyName [in] Name to the key to find.
277 | Returns : Matched uf_key data. otherwise return NULL.
278 | Comments :
279 \---------------------------------------------------------------------------*/
280 static MOS_UF_KEY*UserFeatureFindKey(MOS_PUF_KEYLIST pKeyList, char * const pcKeyName);
281
282 /*----------------------------------------------------------------------------
283 | Name : UserFeatureFindValue
284 | Purpose : Find a value in values array of a key. Return position in values
285 | array
286 | Arguments : UFKey [in] Searched Key node.
287 | pcValueName [in] Value name.
288 | Returns : Matched value No. if it can be found, otherwise, return
289 | NOT_FOUND(-1);
290 | Comments :
291 \---------------------------------------------------------------------------*/
292 static int32_t UserFeatureFindValue(MOS_UF_KEY UFKey, char * const pcValueName);
293
294 /*----------------------------------------------------------------------------
295 | Name : UserFeatureAdd
296 | Purpose : Add new key to keys' linked list.
297 | Arguments : pKeyList [in] Key linked list.
298 | NewKey [in] Added new key.
299 | Returns : MOS_STATUS_SUCCESS success
300 | MOS_STATUS_INVALID_PARAMETER invalid NewKey
301 | MOS_STATUS_NO_SPACE no space left for allocate
302 | Comments :
303 \---------------------------------------------------------------------------*/
304 static MOS_STATUS UserFeatureAdd(MOS_PUF_KEYLIST *pKeyList, MOS_UF_KEY *NewKey);
305
306 /*----------------------------------------------------------------------------
307 | Name : UserFeatureSet
308 | Purpose : This function set a key to the key list.
309 | Arguments : pKeyList [in] Key linked list.
310 | NewKey [in] Set key content.
311 | Returns : MOS_STATUS_SUCCESS Operation success.
312 | MOS_STATUS_UNKNOWN Can't find key in User Feature File.
313 | MOS_STATUS_NO_SPACE no space left for allocate
314 | Comments :
315 \---------------------------------------------------------------------------*/
316 static MOS_STATUS UserFeatureSet(MOS_PUF_KEYLIST *pKeyList, MOS_UF_KEY NewKey);
317
318 /*----------------------------------------------------------------------------
319 | Name : UserFeatureQuery
320 | Purpose : This function query a key's value and return matched key node
321 | content just with matched value content.
322 | Arguments : pKeyList [in] Key linked list.
323 | NewKey [in] New key content with matched value.
324 | Returns : MOS_STATUS_SUCCESS Operation success.
325 | MOS_STATUS_UNKNOWN Can't find key or value in User Feature File.
326 | Comments :
327 \---------------------------------------------------------------------------*/
328 static MOS_STATUS UserFeatureQuery(MOS_PUF_KEYLIST pKeyList, MOS_UF_KEY *NewKey);
329
330 static MOS_STATUS UserFeatureReadNextTokenFromFile(FILE *pFile, const char *szFormat, char *szToken);
331
332 /*----------------------------------------------------------------------------
333 | Name : UserFeatureSetValue
334 | Purpose : Modify or add a value of the specified user feature key.
335 | Arguments : strKey [in] Pointer to user feature key name.
336 | pcValueName [in] Pointer to a string containing the name of
337 | the value to set. If a value with this name
338 | is not already present in the key, the
339 | function adds it to the key.
340 | uiValueType [in] Type of information to be stored.
341 | szValueData [in] Pointer to a null-terminated string
342 | containing the data to set for the default
343 | value of the specified key
344 | uiValueDataLen [in] Size of the string pointed to by the
345 | szValueData parameter, not including the
346 | terminating null character, in bytes
347 | Returns : MOS_STATUS_SUCCESS function success
348 | MOS_STATUS_INVALID_PARAMETER invalid paramater
349 | MOS_STATUS_USER_FEATURE_KEY_READ_FAILED User Feature File can't be open as read.
350 | MOS_STATUS_NO_SPACE no space left for allocate
351 | MOS_STATUS_UNKNOWN unknown user feature type found in User Feature File
352 | MOS_STATUS_INVALID_PARAMETER unknown items found in User Feature File
353 | MOS_STATUS_USER_FEATURE_KEY_WRITE_FAILED User Feature File can't be written.
354 | Comments :
355 \---------------------------------------------------------------------------*/
356 static MOS_STATUS UserFeatureSetValue(
357 char * const strKey,
358 const char * const pcValueName,
359 uint32_t uiValueType,
360 void *pData,
361 int32_t nDataSize);
362
363 /*----------------------------------------------------------------------------
364 | Name : UserFeatureQueryValue
365 | Purpose : The QueryValue function retrieves the type and data for a
366 | specified value name associated with a special user feature key.
367 | Arguments : strKey [in] Pointer to user feature key name.
368 | pcValueName [in] Pointer to a string containing the name
369 | of the value to query.
370 | uiValueType [out] Output Value's type
371 | pData [out] Output value's content
372 | nDataSize [out] Output the size of value's content.
373 | Returns : MOS_STATUS_SUCCESS function success
374 | MOS_STATUS_INVALID_PARAMETER invalid paramater
375 | MOS_STATUS_USER_FEATURE_KEY_READ_FAILED User Feature File can't be open as read.
376 | MOS_STATUS_NO_SPACE no space left for allocate
377 | MOS_STATUS_UNKNOWN Can't find key or value in User Feature File.
378 | Comments :
379 \---------------------------------------------------------------------------*/
380 static MOS_STATUS UserFeatureQueryValue(
381 char * const strKey,
382 const char * const pcValueName,
383 uint32_t *uiValueType,
384 void *pData,
385 int32_t *nDataSize);
386
387 /*----------------------------------------------------------------------------
388 | Name : UserFeatureGetKeyIdbyName
389 | Purpose : Get ID of the user feature key bu its name
390 | Arguments : pcKeyName [in] Pointer to user feature key name.
391 | pUFKey [out] A UFKEY pointer to store returned UFKey
392 | Returns : If the function succeeds, the return value is MOS_STATUS_SUCCESS.
393 | If the function fails, the return value is a error code defined
394 | in mos_utilities.h.
395 | Comments :
396 \---------------------------------------------------------------------------*/
397 static MOS_STATUS UserFeatureGetKeyIdbyName(const char *pcKeyName, void **pUFKey);
398
399 /*----------------------------------------------------------------------------
400 | Name : UserFeatureGetKeyNamebyId
401 | Purpose : Get name of the user feature key bu its ID
402 | Arguments : UFKey [in] ID of the user feature key
403 | pcKeyName [out] To store user feature key name.
404 | Returns : If the function succeeds, the return value is MOS_STATUS_SUCCESS.
405 | If the function fails, the return value is a error code defined
406 | in mos_utilities.h.
407 | Comments :
408 \---------------------------------------------------------------------------*/
409 static MOS_STATUS UserFeatureGetKeyNamebyId(void *UFKey, char *pcKeyName);
410
411 public:
412 static const char* m_szUserFeatureFile;
413 static std::string m_szUserFeatureFileNext;
414 static std::string m_szUserFeatureFileReport;
415 static MOS_PUF_KEYLIST m_ufKeyList;
416 static int32_t m_mosTraceFd;
417 static uint64_t m_filterEnv;
418 static uint32_t m_levelEnv;
419 static const char* const m_mosTracePath;
420 static std::map<std::string, std::map<std::string, std::string>> m_regBuffer;
421
422 private:
423 static MosMutex m_userSettingMutex;
424 MEDIA_CLASS_DEFINE_END(MosUtilitiesSpecificNext)
425 };
426 #endif // __MOS_UTILITIES_SPECIFIC_H__