| 1 |
/* |
| 2 |
* Copyright (c) 2020-2026, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file mos_os_mock_adaptor.cpp |
| 24 |
//! \brief Common interface and structure used in mock adaptor. |
| 25 |
//! |
| 26 |
|
| 27 |
#include "mos_os.h" |
| 28 |
#include "mos_os_specific.h" |
| 29 |
#include "mos_context_next.h" |
| 30 |
#include "mos_interface.h" |
| 31 |
#include "mos_os_mock_adaptor.h" |
| 32 |
#include "mos_os_mock_adaptor_specific.h" |
| 33 |
|
| 34 |
#define TGL_A0_REV_ID 0x00 |
| 35 |
#define TGL_B0_REV_ID 0x01 |
| 36 |
#define TGL_C0_REV_ID 0x02 |
| 37 |
|
| 38 |
MosMockAdaptor::MosMockAdaptor() |
| 39 |
{ |
| 40 |
m_pPlatform = nullptr; |
| 41 |
m_pWaTable = nullptr; |
| 42 |
m_pSkuTable = nullptr; |
| 43 |
m_pGtSystemInfo = nullptr; |
| 44 |
m_productFamily = {}; |
| 45 |
m_stepping = ""; |
| 46 |
m_deviceId = 0; |
| 47 |
m_numOfVdbox = 1; |
| 48 |
m_enabled = false; |
| 49 |
} |
| 50 |
|
| 51 |
MosMockAdaptor::~MosMockAdaptor() |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
MOS_STATUS MosMockAdaptor::RegkeyRead(PMOS_CONTEXT osContext) |
| 56 |
{ |
| 57 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 58 |
int32_t value = 0; |
| 59 |
MediaUserSetting::Value id; |
| 60 |
const char *pcDefaultValue = nullptr; |
| 61 |
MediaUserSettingSharedPtr userSettingPtr = MosInterface::MosGetUserSettingInstance(osContext); |
| 62 |
|
| 63 |
ReadUserSettingForDebug( |
| 64 |
userSettingPtr, |
| 65 |
value, |
| 66 |
__MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_PLATFORM, |
| 67 |
MediaUserSetting::Group::Device); |
| 68 |
m_productFamily = (PRODUCT_FAMILY)value; |
| 69 |
|
| 70 |
ReadUserSettingForDebug( |
| 71 |
userSettingPtr, |
| 72 |
id, |
| 73 |
__MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_STEPPING, |
| 74 |
MediaUserSetting::Group::Device); |
| 75 |
|
| 76 |
if (id.ConstString().size() > 0) |
| 77 |
{ |
| 78 |
m_stepping += id.ConstString(); |
| 79 |
} |
| 80 |
else |
| 81 |
{ |
| 82 |
pcDefaultValue = MOS_MOCKADAPTOR_DEFAULT_STEPPING; |
| 83 |
m_stepping.append(pcDefaultValue); |
| 84 |
} |
| 85 |
|
| 86 |
value = 0; |
| 87 |
ReadUserSettingForDebug( |
| 88 |
userSettingPtr, |
| 89 |
value, |
| 90 |
__MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_DEVICE, |
| 91 |
MediaUserSetting::Group::Device); |
| 92 |
m_deviceId = (uint16_t)value; |
| 93 |
|
| 94 |
value = 0; |
| 95 |
ReadUserSettingForDebug( |
| 96 |
userSettingPtr, |
| 97 |
value, |
| 98 |
__MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_PIPE, |
| 99 |
MediaUserSetting::Group::Device); |
| 100 |
// Extract fake VDBox number from bits [7:0] |
| 101 |
m_numOfVdbox = (uint16_t)(value & 0xFF); |
| 102 |
|
| 103 |
return eStatus; |
| 104 |
} |
| 105 |
|
| 106 |
MOS_STATUS MosMockAdaptor::Init( |
| 107 |
MOS_CONTEXT_HANDLE osDriverContext, |
| 108 |
OsContextNext *osDeviceContext) |
| 109 |
{ |
| 110 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 111 |
uint32_t value = 0; |
| 112 |
bool nullHwEnabled = false; |
| 113 |
PMOS_CONTEXT osContext = (PMOS_CONTEXT)osDriverContext; |
| 114 |
MOS_OS_CHK_NULL_RETURN(osContext); |
| 115 |
MOS_OS_CHK_NULL_RETURN(osDeviceContext); |
| 116 |
|
| 117 |
MediaUserSettingSharedPtr userSettingPtr = MosInterface::MosGetUserSettingInstance(osContext); |
| 118 |
ReadUserSettingForDebug( |
| 119 |
userSettingPtr, |
| 120 |
value, |
| 121 |
__MEDIA_USER_FEATURE_VALUE_NULLHW_ENABLE, |
| 122 |
MediaUserSetting::Group::Device); |
| 123 |
nullHwEnabled = (value) ? true : false; |
| 124 |
osDeviceContext->SetNullHwIsEnabled(nullHwEnabled); |
| 125 |
|
| 126 |
// Per-Context: Only initialize if not already enabled for this instance |
| 127 |
if (nullHwEnabled && !m_enabled) |
| 128 |
{ |
| 129 |
m_enabled = true; // Set flag to prevent re-initialization |
| 130 |
|
| 131 |
MOS_OS_CHK_STATUS_RETURN(RegkeyRead(osContext)); |
| 132 |
eStatus = Initialize(osContext); |
| 133 |
} |
| 134 |
|
| 135 |
return eStatus; |
| 136 |
} |
| 137 |
|
| 138 |
MOS_STATUS MosMockAdaptor::Destroy() |
| 139 |
{ |
| 140 |
// Per-Context: Simply reset the enabled flag |
| 141 |
// The object itself will be deleted by OsContextNext |
| 142 |
m_enabled = false; |
| 143 |
|
| 144 |
return MOS_STATUS_SUCCESS; |
| 145 |
} |
| 146 |
|
| 147 |
MOS_STATUS MosMockAdaptor::InitContext( |
| 148 |
PMOS_CONTEXT osContext) |
| 149 |
{ |
| 150 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 151 |
|
| 152 |
MOS_OS_CHK_NULL_RETURN(osContext); |
| 153 |
|
| 154 |
m_pPlatform = &osContext->m_platform; |
| 155 |
m_pSkuTable = &osContext->m_skuTable; |
| 156 |
m_pWaTable = &osContext->m_waTable; |
| 157 |
m_pGtSystemInfo = &osContext->m_gtSystemInfo; |
| 158 |
|
| 159 |
MOS_OS_CHK_STATUS_RETURN(InitializePlatForm()); |
| 160 |
|
| 161 |
if (m_pPlatform->eRenderCoreFamily >= IGFX_GEN12_CORE) |
| 162 |
{ |
| 163 |
MOS_OS_CHK_STATUS_RETURN(InitializeSkuWaTable(osContext)); |
| 164 |
} |
| 165 |
else |
| 166 |
{ |
| 167 |
MOS_OS_ASSERTMESSAGE("Unsupported platform!"); |
| 168 |
eStatus = MOS_STATUS_PLATFORM_NOT_SUPPORTED; |
| 169 |
} |
| 170 |
|
| 171 |
m_pGtSystemInfo->VDBoxInfo.NumberOfVDBoxEnabled = m_numOfVdbox; |
| 172 |
|
| 173 |
return eStatus; |
| 174 |
} |
| 175 |
|
| 176 |
MOS_STATUS MosMockAdaptor::Initialize( |
| 177 |
PMOS_CONTEXT osContext) |
| 178 |
{ |
| 179 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 180 |
|
| 181 |
MOS_OS_CHK_NULL_RETURN(osContext); |
| 182 |
MOS_OS_CHK_STATUS_RETURN(InitContext(osContext)); |
| 183 |
|
| 184 |
MOS_OS_CHK_STATUS_RETURN(ReplacePlatformInfo(osContext)); |
| 185 |
|
| 186 |
MOS_OS_CHK_STATUS_RETURN(UpdateUserFeatureKey(osContext)); |
| 187 |
|
| 188 |
return eStatus; |
| 189 |
} |