1 /*
2 * Copyright (c) 2017-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_vphal.h
24 //! \brief    Gen-specific factory creation of the vphal interfaces
25 //!
26 
27 #ifndef __MEDIA_INTERFACES_VPHAL_H__
28 #define __MEDIA_INTERFACES_VPHAL_H__
29 
30 #include "media_factory.h"
31 #include "vp_base.h"
32 #include "vp_utils.h"
33 #include "mhw_mi_itf.h"
34 #include "mhw_vebox_itf.h"
35 #include "mhw_sfc_itf.h"
36 namespace vp
37 {
38 class VpPipeline;
39 class VpPlatformInterface;
40 };
41 
42 //!
43 //! \class    VphalDevice
44 //! \brief    Vphal device
45 //!
46 class VphalDevice
47 {
48 public:
~VphalDevice()49     virtual ~VphalDevice() {}
50 
51     VpBase                  *m_vpBase               = nullptr;
52     bool                    m_isNextEnabled         = false;
53     vp::VpPipeline          *m_vpPipeline           = nullptr;  //!< vp pipeline created for specific gen, which is used for sfc service.
54     vp::VpPlatformInterface *m_vpPlatformInterface  = nullptr;  //!< platform interface created for specific gen, which is used for sfc service.
55 
56     //!
57     //! \brief    Creates the VpHal device.
58     //! \details  Allocates all interfaces necessary for VpHal to function in the requested configuration and sets up all function pointers.
59     //! \param    [in] osInterface
60     //!           If an OS interface already exists, it may be passed in here for use by the VpHal device, if not, one is created.
61     //! \param    [in] osDriverContext
62     //!           OS context used by to initialize the MOS_INTERFACE, includes information necessary for resource management and interfacing with KMD in general
63     //! \param    [out] eStatus
64     //!           MOS_STATUS, return MOS_STATUS_SUCCESS if successful, otherwise failed.
65     //! \return   VpBase*
66     //!           returns a valid pointer if successful and nullptr if failed.
67     //!
68     static VpBase* CreateFactory(
69         PMOS_INTERFACE  osInterface,
70         PMOS_CONTEXT    osDriverContext,
71         MOS_STATUS      *eStatus);
72     //!
73     //! \brief    Creates the VpHal device.
74     //! \details  Allocates all interfaces necessary for VpHal to function in the requested configuration and sets up all function pointers.
75     //! \param    [in] osInterface
76     //!           If an OS interface already exists, it may be passed in here for use by the VpHal device, if not, one is created.
77     //! \param    [in] osDriverContext
78     //!           OS context used by to initialize the MOS_INTERFACE, includes information necessary for resource management and interfacing with KMD in general
79     //! \param    [out] eStatus
80     //!           MOS_STATUS, return MOS_STATUS_SUCCESS if successful, otherwise failed.
81     //! \return   VpBase*
82     //!           returns a valid pointer if successful and nullptr if failed.
83     //!
84     static VpBase *CreateFactoryNext(
85         PMOS_INTERFACE     osInterface,
86         MOS_CONTEXT_HANDLE osDriverContext,
87         MOS_STATUS         *eStatus,
88         bool               clearViewMode = false);
89 
90     static MOS_STATUS CreateVPMhwInterfaces(
91         bool                             sfcNeeded,
92         bool                             veboxNeeded,
93         std::shared_ptr<mhw::vebox::Itf> &veboxItf,
94         std::shared_ptr<mhw::sfc::Itf>   &sfcItf,
95         std::shared_ptr<mhw::mi::Itf>    &miItf,
96         PMOS_INTERFACE                   osInterface);
97     //!
98     //! \brief    Initializes platform specific state
99     //! \param    [in] osInterface
100     //!           If an OS interface already exists, it may be passed in here for use by the VpHal device, if not, one is created.
101     //! \param    [in] osDriverContext
102     //!           OS context used by to initialize the MOS_INTERFACE, includes information necessary for resource management and interfacing with KMD in general
103     //! \param    [in] bInitVphalState
104     //!           true if initialize m_vpBase, otherwise, initialize m_vpPipeline and m_vpPlatformInterface.
105     //! \param    [out] eStatus
106     //!           MOS status, return MOS_STATUS_SUCCESS if successful, otherwise failed.
107     //! \return   MOS_STATUS_SUCCESS if succeeded, else error code.
108     //!
109     virtual MOS_STATUS Initialize(
110         PMOS_INTERFACE  osInterface,
111         bool            bInitVphalState,
112         MOS_STATUS      *eStatus,
113         bool            clearViewMode = false) = 0;
114 
CreateVpPlatformInterface(PMOS_INTERFACE osInterface,MOS_STATUS * eStatus)115     virtual MOS_STATUS CreateVpPlatformInterface(
116         PMOS_INTERFACE osInterface,
117         MOS_STATUS *   eStatus)
118     {
119         return MOS_STATUS_UNIMPLEMENTED;
120     }
121 
122     //!
123     //! \brief    Destroys all created VpHal interfaces
124     //! \details  If the HAL creation fails, this is used for cleanup
125     //!
126     void Destroy();
127 };
128 
129 extern template class MediaFactory<uint32_t, VphalDevice>;
130 
131 #endif // __MEDIA_INTERFACES_VPHAL_H__
132