Debian Codegraph @

media_common/agnostic/common/hw/mhw_state_heap_generic.h

raw
1 /*
2 * Copyright (c) 2015-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_state_heap_generic.h
24 //! \brief MHW interface templates for state heap
25 //! \details Impelements shared HW command construction functions across all platforms as templates
26 //!
27
28 #ifndef __MHW_STATE_HEAP_GENERIC_H__
29 #define __MHW_STATE_HEAP_GENERIC_H__
30
31 #include "mhw_state_heap.h"
32 #include "mhw_mi.h"
33
34 template <class TCmds>
35 class MHW_STATE_HEAP_INTERFACE_GENERIC : public XMHW_STATE_HEAP_INTERFACE
36 {
37
38 public:
39 MHW_STATE_HEAP_INTERFACE_GENERIC(
40 PMOS_INTERFACE pInputOsInterface,
41 int8_t bDynamicMode) : XMHW_STATE_HEAP_INTERFACE(pInputOsInterface, bDynamicMode) {}
42
43 virtual ~MHW_STATE_HEAP_INTERFACE_GENERIC() { MHW_FUNCTION_ENTER; }
44
45 MOS_STATUS SetBindingTable(PMHW_KERNEL_STATE pKernelState)
46 {
47 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
48
49 MHW_FUNCTION_ENTER;
50
51 MHW_MI_CHK_NULL(pKernelState);
52 MHW_MI_CHK_NULL(m_pOsInterface);
53
54 uint8_t *pIndirectState = nullptr;
55 uint32_t uiIndirectStateSize = 0, uiIndirectStateOffset = 0;
56 MHW_MI_CHK_STATUS(m_pOsInterface->pfnGetIndirectStatePointer(m_pOsInterface, &pIndirectState));
57 MHW_MI_CHK_STATUS(m_pOsInterface->pfnGetIndirectState(m_pOsInterface, &uiIndirectStateOffset, &uiIndirectStateSize));
58
59 if ((pKernelState->dwSshOffset + pKernelState->dwSshSize) > uiIndirectStateSize)
60 {
61 MHW_ASSERTMESSAGE("SSH not large enough to hold data for this kernel.");
62 return MOS_STATUS_INVALID_PARAMETER;
63 }
64
65 uint32_t ui32BindingTableSize = pKernelState->dwSshSize;
66 uint8_t *pBindingTablePtr = (uint8_t*)(pIndirectState + pKernelState->dwSshOffset);
67 if (pBindingTablePtr != nullptr)
68 {
69 MOS_ZeroMemory(pBindingTablePtr, ui32BindingTableSize);
70 }
71
72 typename TCmds::BINDING_TABLE_STATE_CMD Cmd;
73 for (uint32_t i = 0; i < (uint32_t)pKernelState->KernelParams.iBTCount; i++)
74 {
75 MHW_MI_CHK_NULL(pBindingTablePtr);
76
77 Cmd.DW0.SurfaceStatePointer =
78 ((pKernelState->dwSshOffset + pKernelState->dwBindingTableSize) +
79 (i * m_dwMaxSurfaceStateSize)) >>
80 m_mhwBindingTableSurfaceShift;
81 MHW_MI_CHK_STATUS(MOS_SecureMemcpy(pBindingTablePtr, ui32BindingTableSize, &Cmd, Cmd.byteSize));
82 pBindingTablePtr += Cmd.byteSize;
83 ui32BindingTableSize -= Cmd.byteSize;
84 }
85
86 return eStatus;
87 }
88
89 MOS_STATUS SetBindingTableEntry(PMHW_BINDING_TABLE_PARAMS pParams)
90 {
91 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
92 MHW_MI_CHK_NULL(pParams);
93
94 uint8_t* pBindingTablePtr = pParams->pBindingTableEntry;
95 MHW_MI_CHK_NULL(pBindingTablePtr);
96
97 //Init Cmds
98 typename TCmds::BINDING_TABLE_STATE_CMD Cmd;
99 Cmd.DW0.SurfaceStatePointer = pParams->dwSurfaceStateOffset >> m_mhwBindingTableSurfaceShift;
100
101 //Copy to binding table Entry
102 MHW_MI_CHK_STATUS(MOS_SecureMemcpy(pBindingTablePtr, Cmd.byteSize, &Cmd, Cmd.byteSize));
103
104 // Move to next BT entry
105 pParams->pBindingTableEntry += Cmd.byteSize;
106
107 return eStatus;
108 }
109
110 MOS_STATUS SendBindingTableEntry(PMHW_BINDING_TABLE_SEND_PARAMS pParams)
111 {
112 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
113
114 if (pParams == nullptr ||
115 pParams->pBindingTableSource == nullptr ||
116 pParams->pBindingTableTarget == nullptr)
117 {
118 return MOS_STATUS_SUCCESS;
119 }
120
121 typename TCmds::BINDING_TABLE_STATE_CMD *pBtSrc =
122 (typename TCmds::BINDING_TABLE_STATE_CMD *)pParams->pBindingTableSource ;
123 MHW_MI_CHK_NULL(pBtSrc);
124
125 typename TCmds::BINDING_TABLE_STATE_CMD *pBtDst =
126 (typename TCmds::BINDING_TABLE_STATE_CMD *)pParams->pBindingTableTarget;
127 MHW_MI_CHK_NULL(pBtDst);
128
129 uint32_t CmdByteSize = TCmds::BINDING_TABLE_STATE_CMD::byteSize;
130
131 // Setup and increment BT pointers
132 pParams->pBindingTableSource += CmdByteSize;
133 pParams->pBindingTableTarget += CmdByteSize;
134
135 if (pBtSrc->DW0.SurfaceStatePointer != 0)
136 {
137 // Set binding table entry in indirect state
138 *pBtDst = *pBtSrc;
139
140 // Return surface state parameters associated with BT entry
141 pParams->iSurfaceStateOffset = pBtSrc->DW0.Value;
142 pParams->iSurfaceState = \
143 (pParams->iSurfaceStateOffset - pParams->iSurfaceStateBase)>> m_mhwBindingTableSurfaceShift;
144 }
145 else
146 {
147 *pBtDst = typename TCmds::BINDING_TABLE_STATE_CMD();
148 pParams->iSurfaceState = -1;
149 }
150
151 return eStatus;
152 }
153
154 MOS_STATUS SetInterfaceDescriptor(
155 uint32_t dwNumIdsToSet,
156 PMHW_INTERFACE_DESCRIPTOR_PARAMS pParams)
157 {
158 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
159
160 MHW_FUNCTION_ENTER;
161
162 return eStatus;
163 }
164 };
165
166 #endif