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 null_hardware.cpp
24 //! \brief Defines interfaces for null hardware
25 #include "mos_os_mock_adaptor.h"
26 #include "null_hardware.h"
27 #include "mhw_mi.h"
28
29 bool NullHW::m_initilized = false;
30 bool NullHW::m_enabled = false;
31
Init(PMOS_CONTEXT osContext)32 MOS_STATUS NullHW::Init(
33 PMOS_CONTEXT osContext)
34 {
35 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
36 MOS_OS_CHK_NULL_RETURN(osContext);
37
38 if (!m_initilized) {
39 m_initilized = true;
40
41 MOS_USER_FEATURE_VALUE_DATA UserFeatureData = {};
42 MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
43 MOS_UserFeature_ReadValue_ID(
44 nullptr,
45 __MEDIA_USER_FEATURE_VALUE_NULLHW_ENABLE_ID,
46 &UserFeatureData,
47 osContext);
48
49 m_enabled = (UserFeatureData.i32Data) ? true : false;
50
51 if (m_enabled)
52 {
53 eStatus = MosMockAdaptor::Init(osContext);
54 }
55 else
56 {
57 eStatus = MOS_STATUS_INVALID_HANDLE;
58 }
59
60 }
61 return eStatus;
62 }
63
Destroy()64 MOS_STATUS NullHW::Destroy()
65 {
66 return MosMockAdaptor::Destroy();
67 }
68
StartPredicate(MhwMiInterface * miInterface,PMOS_COMMAND_BUFFER cmdBuffer)69 MOS_STATUS NullHW::StartPredicate(MhwMiInterface* miInterface, PMOS_COMMAND_BUFFER cmdBuffer)
70 {
71 if (!m_enabled)
72 {
73 return MOS_STATUS_SUCCESS;
74 }
75 MOS_OS_CHK_NULL_RETURN(miInterface);
76 MOS_OS_CHK_NULL_RETURN(cmdBuffer);
77
78 return miInterface->AddMiSetPredicateCmd(cmdBuffer, MHW_MI_SET_PREDICATE_ENABLE_ALWAYS);
79 }
80
StopPredicate(MhwMiInterface * miInterface,PMOS_COMMAND_BUFFER cmdBuffer)81 MOS_STATUS NullHW::StopPredicate(MhwMiInterface* miInterface, PMOS_COMMAND_BUFFER cmdBuffer)
82 {
83 if (!m_enabled)
84 {
85 return MOS_STATUS_SUCCESS;
86 }
87 MOS_OS_CHK_NULL_RETURN(miInterface);
88 MOS_OS_CHK_NULL_RETURN(cmdBuffer);
89
90 return miInterface->AddMiSetPredicateCmd(cmdBuffer, MHW_MI_SET_PREDICATE_DISABLE);
91 }
92
StatusReport(uint32_t & status,uint32_t & streamSize)93 void NullHW::StatusReport(uint32_t &status, uint32_t &streamSize)
94 {
95 if (!m_enabled)
96 {
97 return;
98 }
99
100 status = 0;
101 streamSize = 1024;
102 }