xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/common/cm/hal/cm_global_api_os.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 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  cm_global_api_os.cpp
24 //! \brief Contains implementations of gloabl CM APIs which are Linux-dependent.
25 //!
26 
27 #include "cm_device_rt.h"
28 
29 using CMRT_UMD::CmDevice;
30 using CMRT_UMD::CmDeviceRT;
31 //!
32 //! \brief    Creates a CmDevice from a MOS context.
33 //! \details  If an existing CmDevice has already associated to the MOS context,
34 //!           the existing CmDevice will be returned. Otherwise, a new CmDevice
35 //!           instance will be created and associatied with that MOS context.
36 //! \param    mosContext
37 //!           [in] pointer to MOS conetext.
38 //! \param    device
39 //!           [in,out] reference to the pointer to the CmDevice.
40 //! \param    devCreateOption
41 //!           [in] option to customize CmDevice.
42 //! \retval   CM_SUCCESS if the CmDevice is successfully created.
43 //! \retval   CM_NULL_POINTER if mosContext is null.
44 //! \retval   CM_FAILURE otherwise.
45 //!
CreateCmDevice(MOS_CONTEXT * mosContext,CmDevice * & device,uint32_t devCreateOption,uint8_t priority)46 CM_RT_API int32_t CreateCmDevice(MOS_CONTEXT *mosContext,
47                                  CmDevice* &device,
48                                  uint32_t devCreateOption,
49                                  uint8_t  priority)
50 {
51     UNUSED(priority);
52     if (mosContext == nullptr)
53     {
54         return CM_NULL_POINTER;
55     }
56     CmDeviceRT* deviceRT = nullptr;
57 
58     int32_t ret = CmDeviceRT::Create(mosContext, deviceRT, devCreateOption);
59     if(ret == CM_SUCCESS)
60     {
61         device = deviceRT;
62     }
63 
64     return ret;
65 }
66 
67 //!
68 //! \brief    Destroys the CmDevice.
69 //! \details  This function also destroys surfaces, kernels, programs, samplers,
70 //!           threadspaces, tasks and the queues that were created using this
71 //!           device instance but haven't explicitly been destroyed by calling
72 //!           respective destroy functions.
73 //! \param    device
74 //!           [in] reference to the pointer to the CmDevice.
75 //! \retval   CM_SUCCESS if CmDevice is successfully destroyed.
76 //! \retval   CM_FAILURE otherwise.
77 //!
DestroyCmDevice(CmDevice * & device)78 CM_RT_API int32_t DestroyCmDevice(CmDevice* & device)
79 {
80     if (device == nullptr)
81     {
82         return CM_SUCCESS;
83     }
84 
85     CmDeviceRT* deviceRT = static_cast<CmDeviceRT*>(device);
86     int32_t ret = CmDeviceRT::Destroy(deviceRT);
87     if (ret != CM_SUCCESS)
88     {
89         return ret;
90     }
91 
92     device = nullptr;
93 
94     return CM_SUCCESS;
95 }
96 
97 //!
98 //! \brief    Initialize cm hal ddi interfaces
99 //! \details  Initialize cm hal ddi interfaces
100 //! \param    cmState
101 //!           [in,out] the pointer to the cm state.
102 //! \return   MOS_STATUS
103 //!           MOS_STATUS_SUCCESS if succeeded, otherwise error code
104 //!
InitCmOsDDIInterface(PCM_HAL_STATE cmState)105 MOS_STATUS InitCmOsDDIInterface(PCM_HAL_STATE cmState)
106 {
107     UNUSED(cmState);
108     return MOS_STATUS_SUCCESS;
109 }
110