xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/os/mos_os_mock_adaptor.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2020, 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 bool  MosMockAdaptor::m_enabled = false;
39 PRODUCT_FAMILY MosMockAdaptor::m_productFamily = {};
40 std::string MosMockAdaptor::m_stepping = {};
41 uint16_t MosMockAdaptor::m_deviceId = 0;
42 MosMockAdaptor *MosMockAdaptor::m_mocAdaptor = nullptr;
43 
MosMockAdaptor()44 MosMockAdaptor::MosMockAdaptor()
45 {
46 }
47 
~MosMockAdaptor()48 MosMockAdaptor::~MosMockAdaptor()
49 {
50 }
51 
RegkeyRead(PMOS_CONTEXT osContext)52 MOS_STATUS MosMockAdaptor::RegkeyRead(PMOS_CONTEXT osContext)
53 {
54     MOS_STATUS  eStatus = MOS_STATUS_SUCCESS;
55     int32_t     value   = 0;
56     MediaUserSetting::Value  id;
57     const char *pcDefaultValue  = nullptr;
58     MediaUserSettingSharedPtr userSettingPtr = MosInterface::MosGetUserSettingInstance(osContext);
59 
60     ReadUserSettingForDebug(
61         userSettingPtr,
62         value,
63         __MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_PLATFORM,
64         MediaUserSetting::Group::Device);
65     m_productFamily = (PRODUCT_FAMILY)value;
66 
67     ReadUserSettingForDebug(
68         userSettingPtr,
69         id,
70         __MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_STEPPING,
71         MediaUserSetting::Group::Device);
72 
73     if (id.ConstString().size() > 0)
74     {
75         m_stepping += id.ConstString();
76     }
77     else
78     {
79         pcDefaultValue = MOS_MOCKADAPTOR_DEFAULT_STEPPING;
80         m_stepping.append(pcDefaultValue);
81     }
82 
83     value = 0;
84     ReadUserSettingForDebug(
85         userSettingPtr,
86         value,
87         __MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_DEVICE,
88         MediaUserSetting::Group::Device);
89     m_deviceId = (uint16_t)value;
90 
91     return eStatus;
92 }
93 
Init(MOS_CONTEXT_HANDLE osDriverContext,OsContextNext * osDeviceContext)94 MOS_STATUS MosMockAdaptor::Init(
95     MOS_CONTEXT_HANDLE osDriverContext,
96     OsContextNext      *osDeviceContext)
97 {
98     MOS_STATUS   eStatus       = MOS_STATUS_SUCCESS;
99     uint32_t     value         = 0;
100     bool         nullHwEnabled = false;
101     PMOS_CONTEXT osContext     = (PMOS_CONTEXT)osDriverContext;
102     MOS_OS_CHK_NULL_RETURN(osContext);
103     MOS_OS_CHK_NULL_RETURN(osDeviceContext);
104 
105     MediaUserSettingSharedPtr userSettingPtr = MosInterface::MosGetUserSettingInstance(osContext);
106     ReadUserSettingForDebug(
107         userSettingPtr,
108         value,
109         __MEDIA_USER_FEATURE_VALUE_NULLHW_ENABLE,
110         MediaUserSetting::Group::Device);
111     nullHwEnabled = (value) ? true : false;
112     osDeviceContext->SetNullHwIsEnabled(nullHwEnabled);
113 
114     if (nullHwEnabled && !m_enabled) {
115         m_enabled = true;
116 
117         MOS_OS_CHK_STATUS_RETURN(RegkeyRead(osContext));
118 
119         m_mocAdaptor = MOS_New(MosMockAdaptorSpecific);
120         MOS_OS_CHK_NULL_RETURN(m_mocAdaptor);
121 
122         eStatus = m_mocAdaptor->Initialize(osContext);
123     }
124 
125     return eStatus;
126 }
127 
Destroy()128 MOS_STATUS MosMockAdaptor::Destroy()
129 {
130     if (m_mocAdaptor != nullptr)
131     {
132         MOS_Delete(m_mocAdaptor);
133         m_mocAdaptor = nullptr;
134     }
135 
136     m_enabled = false;
137 
138     return MOS_STATUS_SUCCESS;
139 }
140 
InitContext(PMOS_CONTEXT osContext)141 MOS_STATUS MosMockAdaptor::InitContext(
142     PMOS_CONTEXT osContext)
143 {
144     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
145 
146     MOS_OS_CHK_NULL_RETURN(osContext);
147 
148     m_pPlatform     = &osContext->m_platform;
149     m_pSkuTable     = &osContext->m_skuTable;
150     m_pWaTable      = &osContext->m_waTable;
151     m_pGtSystemInfo = &osContext->m_gtSystemInfo;
152 
153     MOS_OS_CHK_STATUS_RETURN(InitializePlatForm());
154 
155     if (m_pPlatform->eRenderCoreFamily >= IGFX_GEN12_CORE)
156     {
157         MOS_OS_CHK_STATUS_RETURN(InitializeSkuWaTable(osContext));
158     }
159     else
160     {
161         MOS_OS_ASSERTMESSAGE("Unsupported platform!");
162         eStatus = MOS_STATUS_PLATFORM_NOT_SUPPORTED;
163     }
164 
165     return eStatus;
166 }
167 
Initialize(PMOS_CONTEXT osContext)168 MOS_STATUS MosMockAdaptor::Initialize(
169     PMOS_CONTEXT osContext)
170 {
171     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
172 
173     MOS_OS_CHK_NULL_RETURN(osContext);
174     MOS_OS_CHK_STATUS_RETURN(InitContext(osContext));
175 
176     MOS_OS_CHK_STATUS_RETURN(ReplacePlatformInfo(osContext));
177 
178     MOS_OS_CHK_STATUS_RETURN(UpdateUserFeatureKey(osContext));
179 
180     return eStatus;
181 }