1 /*
2 * Copyright (c) 2014-2017, 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 mhw_mi.cpp
24 //! \brief MHW interface for MI and generic flush commands across all engines
25 //! \details Impelements the functionalities common across all platforms for MHW_MI
26 //!
27
28 #include "mhw_mi.h"
29 #include "mhw_cp_interface.h"
30
MhwMiInterface(MhwCpInterface * cpInterface,PMOS_INTERFACE osInterface)31 MhwMiInterface::MhwMiInterface(
32 MhwCpInterface *cpInterface,
33 PMOS_INTERFACE osInterface)
34 {
35 MHW_FUNCTION_ENTER;
36
37 MOS_ZeroMemory(&UseGlobalGtt, sizeof(UseGlobalGtt));
38 MOS_ZeroMemory(&MediaResetParam, sizeof(MediaResetParam));
39
40 if (cpInterface == nullptr || osInterface == nullptr)
41 {
42 MHW_ASSERTMESSAGE("Invalid input pointers provided");
43 return;
44 }
45
46 if (!osInterface->bUsesGfxAddress && !osInterface->bUsesPatchList)
47 {
48 MHW_ASSERTMESSAGE("No valid addressing mode indicated");
49 return;
50 }
51
52 if (cpInterface->RegisterMiInterface(this) != MOS_STATUS_SUCCESS)
53 {
54 MHW_ASSERTMESSAGE("Registering the MI interface should not have failed!");
55 return;
56 }
57
58 m_cpInterface = cpInterface;
59 m_osInterface = osInterface;
60
61 UseGlobalGtt.m_cs =
62 UseGlobalGtt.m_vcs =
63 UseGlobalGtt.m_vecs = MEDIA_IS_WA(m_osInterface->pfnGetWaTable(m_osInterface), WaForceGlobalGTT) ||
64 !MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrPPGTT);
65
66 MediaResetParam.watchdogCountThreshold = MHW_MI_DEFAULT_WATCHDOG_THRESHOLD_IN_MS;
67
68 GetWatchdogThreshold(m_osInterface);
69
70 if (m_osInterface->bUsesGfxAddress)
71 {
72 AddResourceToCmd = Mhw_AddResourceToCmd_GfxAddress;
73 }
74 else // if (pOsInterface->bUsesPatchList)
75 {
76 AddResourceToCmd = Mhw_AddResourceToCmd_PatchList;
77 }
78 }
79
IsGlobalGttInUse()80 bool MhwMiInterface::IsGlobalGttInUse()
81 {
82 MOS_GPU_CONTEXT gpuContext = m_osInterface->pfnGetGpuContext(m_osInterface);
83 bool vcsEngineUsed = MOS_VCS_ENGINE_USED(gpuContext);
84 bool renderEngineUsed = MOS_RCS_ENGINE_USED(gpuContext);
85
86 bool globalGttInUse = renderEngineUsed ? UseGlobalGtt.m_cs :
87 (vcsEngineUsed ? UseGlobalGtt.m_vcs : UseGlobalGtt.m_vecs);
88
89 return globalGttInUse;
90 }
91
AddProtectedProlog(MOS_COMMAND_BUFFER * cmdBuffer)92 MOS_STATUS MhwMiInterface::AddProtectedProlog(MOS_COMMAND_BUFFER *cmdBuffer)
93 {
94 MHW_MI_CHK_NULL(cmdBuffer);
95
96 MHW_MI_CHK_STATUS(m_cpInterface->AddProlog(m_osInterface, cmdBuffer));
97 MHW_MI_CHK_STATUS(m_cpInterface->AddCheckForEarlyExit(m_osInterface, cmdBuffer));
98
99 return MOS_STATUS_SUCCESS;
100 }
101
102