1 /*
2 * Copyright (c) 2017-2018, 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     codechal_mmc.h
24 //! \brief    Defines the public interface for CodecHal Media Memory Compression
25 //!
26 #ifndef __CODECHAL_MMC_H__
27 #define __CODECHAL_MMC_H__
28 
29 #include "codechal_utilities.h"
30 
31 //!
32 //! \brief Forward declarations
33 //!
34 typedef struct _MHW_PIPE_CONTROL_PARAMS        *PMHW_PIPE_CONTROL_PARAMS;
35 typedef struct _MHW_VDBOX_SURFACE_PARAMS       *PMHW_VDBOX_SURFACE_PARAMS;
36 using PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS = MHW_VDBOX_PIPE_BUF_ADDR_PARAMS * ;
37 //! \class CodecHalMmcState
38 //! \brief Media memory compression state. This class defines the member fields
39 //!        functions etc used by memory compression.
40 //!
41 class CodecHalMmcState
42 {
43 public:
44     //!
45     //! \brief    Constructor
46     //!
47     CodecHalMmcState(CodechalHwInterface  *hwInterface);
48 
49     //!
50     //! \brief    Destructor
51     //!
~CodecHalMmcState()52     virtual ~CodecHalMmcState() {};
53 
54     //!
55     //! \brief    Check if MMC is enabled
56     //!
57     //! \return   bool
58     //!           true if mmc is enabled, else false
59     //!
60     bool IsMmcEnabled();
61 
62     //!
63     //! \brief    Disable MMC state
64     //!
65     //! \return   void
66     //!
67     void SetMmcDisabled();
68 
69     //!
70     //! \brief    Get surface memory compression state
71     //! \param    [out] surface
72     //!           Pointer to PMOS_SURFACE
73     //!
74     //! \return   MOS_STATUS
75     //!           MOS_STATUS_SUCCESS if success, else fail reason
76     //!
77     MOS_STATUS GetSurfaceMmcState(PMOS_SURFACE surface);
78 
79     //!
80     //! \brief    Disable surface memory compression state
81     //! \param    [in,out] surface
82     //!           Pointer to PMOS_SURFACE
83     //!
84     //! \return   MOS_STATUS
85     //!           MOS_STATUS_SUCCESS if success, else fail reason
86     //!
87     MOS_STATUS DisableSurfaceMmcState(PMOS_SURFACE surface);
88 
89     //!
90     //! \brief    Set destinate surface memory compression state by source surface
91     //! \param    [out] dstSurface
92     //!           Pointer to PMOS_SURFACE
93     //! \param    [in] srcSurface
94     //!           Pointer to PMOS_SURFACE
95     //!
96     //! \return   MOS_STATUS
97     //!           MOS_STATUS_SUCCESS if success, else fail reason
98     //!
99     MOS_STATUS SetSurfaceMmcMode(
100         PMOS_SURFACE dstSurface,
101         PMOS_SURFACE srcSurface);
102 
103     //!
104     //! \brief    Set surface paramter
105     //! \param    [in,out] surfaceParams
106     //!           Pointer to PCODECHAL_SURFACE_CODEC_PARAMS
107     //!
108     //! \return   MOS_STATUS
109     //!           MOS_STATUS_SUCCESS if success, else fail reason
110     //!
111     virtual MOS_STATUS SetSurfaceParams(
112         PCODECHAL_SURFACE_CODEC_PARAMS surfaceParams);
113 
114     //!
115     //! \brief    Set pipe buffer address parameter
116     //! \details  Set pipe buffer address parameter in MMC case
117     //!
118     //! \param    [in,out] pipeBufAddrParams
119     //!           Pointer to PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS
120     //! \param    [in] cmdBuffer
121     //!           Pointer to MOS command buffer
122     //!
123     //! \return   MOS_STATUS
124     //!           MOS_STATUS_SUCCESS if success, else fail reason
125     //!
126     virtual MOS_STATUS SetPipeBufAddr(
127         PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams,
128         PMOS_COMMAND_BUFFER cmdBuffer = nullptr)
129     {
130         return MOS_STATUS_SUCCESS;
131     };
132 
133     //!
134     //! \brief    Set Surface State MMC state parameter
135     //! \details  Set MMC state for speficied SurfaceState cmd parameters
136     //!
137     //! \param    [in,out] surfaceStateParams
138     //!           Pointer to PMHW_VDBOX_SURFACE_PARAMS
139     //! \param    [in] cmdBuffer
140     //!           Pointer to MOS command buffer
141     //!
142     //! \return   MOS_STATUS
143     //!           MOS_STATUS_SUCCESS if success, else fail reason
144     //!
145     virtual MOS_STATUS SetSurfaceState(
146         PMHW_VDBOX_SURFACE_PARAMS surfaceStateParams,
147         PMOS_COMMAND_BUFFER cmdBuffer = nullptr)
148     {
149         return MOS_STATUS_SUCCESS;
150     };
151 
152     //!
153     //! \brief    Send prolog MI cmds used to control MMC state
154     //! \details  Send H/W MMIO cmds used to initialze MMC related states
155     //!
156     //! \param    [in] miInterface
157     //!           Pointer to MhwMiInterface
158     //! \param    [in] cmdBuffer
159     //!           Command buffer pointer
160     //! \param    [in] gpuContext
161     //!           Current pipe of the cmd buffer
162     //!
163     //! \return   MOS_STATUS
164     //!           Return status of sending register MMIOs
SendPrologCmd(MhwMiInterface * miInterface,MOS_COMMAND_BUFFER * cmdBuffer,MOS_GPU_CONTEXT gpuContext)165     virtual MOS_STATUS SendPrologCmd(
166         MhwMiInterface      *miInterface,
167         MOS_COMMAND_BUFFER  *cmdBuffer,
168         MOS_GPU_CONTEXT     gpuContext)
169     {
170         return MOS_STATUS_SUCCESS;
171     }
172 
173     //!
174     //! \brief    Set reference sync
175     //! \details  Set reference sync, check if reference surface needs to be synchronized in MMC case
176     //!
177     //! \param    [in] disableDecodeSyncLock
178     //!           Indicates if decode sync lock is disabled
179     //! \param    [in] disableLockForTranscode
180     //!           Indicates if transcoe lock is disabled
181     //!
182     //! \return   MOS_STATUS
183     //!           MOS_STATUS_SUCCESS if success, else fail reason
184     //!
SetRefrenceSync(bool disableDecodeSyncLock,bool disableLockForTranscode)185     virtual MOS_STATUS SetRefrenceSync(
186         bool disableDecodeSyncLock,
187         bool disableLockForTranscode)
188     {
189         MOS_UNUSED(disableDecodeSyncLock);
190         MOS_UNUSED(disableLockForTranscode);
191         return MOS_STATUS_SUCCESS;
192     };
193 
194     //!
195     //! \brief    Check reference list
196     //! \details  Check reference list, including self-reference detection and mmc state consistence detection
197     //!
198     //! \param    [in,out] pipeBufAddrParams
199     //!           Pointer to PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS
200     //!
201     //! \return   MOS_STATUS
202     //!           MOS_STATUS_SUCCESS if success, else fail reason
203     //!
CheckReferenceList(PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams)204     virtual MOS_STATUS CheckReferenceList(
205         PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams)
206     {
207         return MOS_STATUS_SUCCESS;
208     };
209 
210 #if (_DEBUG || _RELEASE_INTERNAL)
211     //!
212     //! \brief    Update mmc user feature key
213     //! \details  Report out the memory compression state for render target surface
214     //!
215     //! \param    [in] surface
216     //!           Pointer to PMOS_SURFACE
217     //!
218     //! \return   MOS_STATUS
219     //!           MOS_STATUS_SUCCESS if success, else fail reason
220     //!
221     MOS_STATUS UpdateUserFeatureKey(PMOS_SURFACE surface);
222 #endif
223 
224     //!
225     //! \brief    Is extension MMC
226     //! \details  Report if is extension MMC
227     //!
228     //! \return   bool
229     //!
IsMmcExtensionEnabled()230     bool IsMmcExtensionEnabled()
231     {
232         return m_mmcExtensionEnabled;
233     }
234 
235 protected:
236 
237     bool                    m_mmcEnabled = false;                   //!< Indicate if media memory compression is enabled
238     PMOS_INTERFACE          m_osInterface = nullptr;                //!< Os Inteface
239     CodechalHwInterface     *m_hwInterface = nullptr;               //!< Pointer to HW Interface
240     bool                    m_hcpMmcEnabled = false;                //!< Inidate if hcp mmc is enabled
241     bool                    m_10bitMmcEnabled = false;              //!< Inidate if 10bit mmc is enabled
242     bool                    m_gpuMmuPageFaultEnabled = false;       //!< Inidate if page fault is enabled
243 #if (_DEBUG || _RELEASE_INTERNAL)
244     bool                    m_userFeatureUpdated = false;              //!< Inidate if mmc user feature key is updated
245     uint32_t                m_compressibleId  = 0;
246     uint32_t                m_compressModeId  = 0;
247 #endif
248     bool                    m_mmcExtensionEnabled = false;          //!< Indicate if extension MMC
249 };
250 
251 #endif  // __CODECHAL_MMC_H__
252