| 1 |
/* |
| 2 |
* Copyright (c) 2022, 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 media_interfaces_mcpy_next.h |
| 24 |
//! \brief Gen-specific factory creation of the mcpy interfaces |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef __MEDIA_INTERFACES_MCPY_NEXT_H__ |
| 28 |
#define __MEDIA_INTERFACES_MCPY_NEXT_H__ |
| 29 |
#include "media_factory.h" |
| 30 |
|
| 31 |
// forward declaration |
| 32 |
class MediaCopyBaseState; |
| 33 |
class MhwInterfacesNext; |
| 34 |
//! |
| 35 |
//! \class McpyDevice |
| 36 |
//! \brief MCPY device |
| 37 |
//! |
| 38 |
class McpyDeviceNext |
| 39 |
{ |
| 40 |
public: |
| 41 |
virtual ~McpyDeviceNext() {} |
| 42 |
|
| 43 |
//! |
| 44 |
//! \brief Create Media memory copy instance |
| 45 |
//! \details Entry point to create Gen specific media memory compression instance |
| 46 |
//! \param [in] osDriverContext |
| 47 |
//! OS context used by to initialize the MOS_INTERFACE, includes information necessary for resource management and interfacing with KMD in general |
| 48 |
//! |
| 49 |
//! \return Pointer to Gen specific mediacopy instance if |
| 50 |
//! successful, otherwise return nullptr |
| 51 |
//! |
| 52 |
static void* CreateFactory( |
| 53 |
MOS_CONTEXT_HANDLE osDriverContext); |
| 54 |
|
| 55 |
//! |
| 56 |
//! \brief Initializes platform specific Media copy states |
| 57 |
//! \param [in] osInterface |
| 58 |
//! OS interface |
| 59 |
//! \param [in] mhwInterfaces |
| 60 |
//! HW interfaces to be used by media copy |
| 61 |
//! \return MOS_STATUS_SUCCESS if succeeded, else error code. |
| 62 |
//! |
| 63 |
virtual MOS_STATUS Initialize( |
| 64 |
PMOS_INTERFACE osInterface) = 0; |
| 65 |
|
| 66 |
protected: |
| 67 |
//! |
| 68 |
//! \brief Creat platform specific media copy HW interface |
| 69 |
//! \param [in] osInterface |
| 70 |
//! OS interface |
| 71 |
//! \return MhwInterfaces if succeeded. |
| 72 |
//! |
| 73 |
virtual MhwInterfacesNext* CreateMhwInterface( |
| 74 |
PMOS_INTERFACE osInterface); |
| 75 |
|
| 76 |
protected: |
| 77 |
MediaCopyBaseState *m_mcpyDevice = nullptr; //!< Media copy state |
| 78 |
|
| 79 |
MEDIA_CLASS_DEFINE_END(McpyDeviceNext) |
| 80 |
}; |
| 81 |
|
| 82 |
template <typename Mhw, typename Mcpy> |
| 83 |
class McpyDeviceNext_T : public McpyDeviceNext |
| 84 |
{ |
| 85 |
public: |
| 86 |
virtual MOS_STATUS Initialize( |
| 87 |
PMOS_INTERFACE osInterface) override |
| 88 |
{ |
| 89 |
Mcpy *device = nullptr; |
| 90 |
Mhw *mhwInterfaces = nullptr; |
| 91 |
|
| 92 |
auto deleterOnFailure = [&](bool deleteOsInterface, bool deleteMhwInterface) { |
| 93 |
if (deleteOsInterface && osInterface != nullptr) |
| 94 |
{ |
| 95 |
if (osInterface->pfnDestroy) |
| 96 |
{ |
| 97 |
osInterface->pfnDestroy(osInterface, false); |
| 98 |
} |
| 99 |
MOS_FreeMemory(osInterface); |
| 100 |
} |
| 101 |
|
| 102 |
if (deleteMhwInterface && mhwInterfaces != nullptr) |
| 103 |
{ |
| 104 |
mhwInterfaces->Destroy(); |
| 105 |
MOS_Delete(mhwInterfaces); |
| 106 |
} |
| 107 |
|
| 108 |
MOS_Delete(device); |
| 109 |
}; |
| 110 |
|
| 111 |
device = MOS_New(Mcpy); |
| 112 |
if (device == nullptr) |
| 113 |
{ |
| 114 |
deleterOnFailure(true, false); |
| 115 |
return MOS_STATUS_NO_SPACE; |
| 116 |
} |
| 117 |
|
| 118 |
mhwInterfaces = CreateMhwInterface(osInterface); |
| 119 |
if (mhwInterfaces->m_miItf == nullptr || |
| 120 |
mhwInterfaces->m_veboxItf == nullptr || |
| 121 |
mhwInterfaces->m_bltItf == nullptr) |
| 122 |
{ |
| 123 |
deleterOnFailure(true, true); |
| 124 |
return MOS_STATUS_NO_SPACE; |
| 125 |
} |
| 126 |
|
| 127 |
if (device->Initialize( |
| 128 |
osInterface, mhwInterfaces) != MOS_STATUS_SUCCESS) |
| 129 |
{ |
| 130 |
deleterOnFailure(false, false); |
| 131 |
MOS_OS_CHK_STATUS_RETURN(MOS_STATUS_UNINITIALIZED); |
| 132 |
} |
| 133 |
|
| 134 |
m_mcpyDevice = device; |
| 135 |
return MOS_STATUS_SUCCESS; |
| 136 |
} |
| 137 |
}; |
| 138 |
|
| 139 |
template <typename Mcpy> |
| 140 |
using McpyDeviceNextImpl = McpyDeviceNext_T<MhwInterfacesNext, Mcpy>; |
| 141 |
|
| 142 |
extern template class MediaFactory<uint32_t, McpyDeviceNext>; |
| 143 |
|
| 144 |
|
| 145 |
#endif // __MEDIA_INTERFACES_MCPY_NEXT_H__ |
| 146 |
|