xref: /aosp_15_r20/external/intel-media-driver/media_softlet/linux/common/os/mos_os_specific_next.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2019-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      mos_os_specific.c
24 //! \brief     Common interface used in MOS LINUX OS
25 //! \details   Common interface used in MOS LINUX OS
26 //!
27 
28 #include <unistd.h>
29 #include <dlfcn.h>
30 #include <stdlib.h>
31 
32 #include <sys/ipc.h>
33 #include <sys/shm.h>
34 #include <sys/sem.h>
35 #include <sys/types.h>
36 
37 #include "mos_os_next.h"
38 #include "mos_util_debug.h"
39 #include "hwinfo_linux.h"
40 #include "media_fourcc.h"
41 #include "mos_graphicsresource_next.h"
42 #include "mos_gpucontext_specific_next.h"
43 #include "mos_gpucontextmgr_next.h"
44 
45 #if MOS_MEDIASOLO_SUPPORTED
46 #include "mos_os_solo.h"
47 #endif // MOS_MEDIASOLO_SUPPORTED
48 #include "mos_solo_generic.h"
49 
50 
51 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
52 struct GpuCmdResInfoDumpNext::GpuCmdResInfo
53 {
54     int32_t             iWidth;
55     int32_t             iHeight;
56     int32_t             iSize;
57     int32_t             iPitch;
58     int32_t             iDepth;
59     MOS_FORMAT          Format;
60     int32_t             iCount;
61     int32_t             iAllocationIndex[MOS_GPU_CONTEXT_MAX];
62     uint32_t            dwGfxAddress;
63     const char          *bufname;
64     uint32_t            isTiled;
65     MOS_TILE_TYPE       TileType;
66     uint32_t            bMapped;
67     uint32_t            name;
68     uint64_t            user_provided_va;
69     bool                bConvertedFromDDIResource;
70 };
71 
StoreCmdResPtr(PMOS_INTERFACE pOsInterface,const void * pRes) const72 void GpuCmdResInfoDumpNext::StoreCmdResPtr(PMOS_INTERFACE pOsInterface, const void *pRes) const
73 {
74     if (!m_dumpEnabled)
75     {
76         return;
77     }
78 
79     auto gpuContext = MosInterface::GetGpuContext(pOsInterface->osStreamState, pOsInterface->CurrentGpuContextHandle);
80     MOS_OS_CHK_NULL_NO_STATUS_RETURN(gpuContext);
81 
82     auto pResTmp1 = (const MOS_RESOURCE *)(pRes);
83     auto pResTmp2 = (GpuCmdResInfo *)MOS_AllocMemory(sizeof(GpuCmdResInfo));
84 
85     pResTmp2->iWidth                    = pResTmp1->iWidth;
86     pResTmp2->iHeight                   = pResTmp1->iHeight;
87     pResTmp2->iSize                     = pResTmp1->iSize;
88     pResTmp2->iPitch                    = pResTmp1->iPitch;
89     pResTmp2->iDepth                    = pResTmp1->iDepth;
90     pResTmp2->Format                    = pResTmp1->Format;
91     pResTmp2->iCount                    = pResTmp1->iCount;
92     for (auto i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
93     {
94         pResTmp2->iAllocationIndex[i] = pResTmp1->iAllocationIndex[i];
95     }
96     pResTmp2->dwGfxAddress              = pResTmp1->dwGfxAddress;
97     pResTmp2->bufname                   = pResTmp1->bufname;
98     pResTmp2->isTiled                   = pResTmp1->isTiled;
99     pResTmp2->TileType                  = pResTmp1->TileType;
100     pResTmp2->bMapped                   = pResTmp1->bMapped;
101     pResTmp2->name                      = pResTmp1->name;
102     pResTmp2->user_provided_va          = pResTmp1->user_provided_va;
103     pResTmp2->bConvertedFromDDIResource = pResTmp1->bConvertedFromDDIResource;
104 
105     gpuContext->PushCmdResPtr((const void *)pResTmp2);
106 }
107 
ClearCmdResPtrs(PMOS_INTERFACE pOsInterface) const108 void GpuCmdResInfoDumpNext::ClearCmdResPtrs(PMOS_INTERFACE pOsInterface) const
109 {
110     if (!m_dumpEnabled)
111     {
112         return;
113     }
114 
115     auto gpuContext = MosInterface::GetGpuContext(pOsInterface->osStreamState, pOsInterface->CurrentGpuContextHandle);
116     MOS_OS_CHK_NULL_NO_STATUS_RETURN(gpuContext);
117 
118     auto &cmdResInfoPtrs = gpuContext->GetCmdResPtrs();
119 
120     for (auto e : cmdResInfoPtrs)
121     {
122         MOS_FreeMemory((void *)e);
123     }
124 
125     gpuContext->ClearCmdResPtrs();
126 }
127 
Dump(const void * cmdResInfoPtr,std::ofstream & outputFile) const128 void GpuCmdResInfoDumpNext::Dump(const void *cmdResInfoPtr, std::ofstream &outputFile) const
129 {
130     using std::endl;
131 
132     auto pRes = (const GpuCmdResInfo *)(cmdResInfoPtr);
133 
134     outputFile << "Gpu Resource Pointer      : " << pRes << endl;
135     outputFile << "iWidth                    : " << pRes->iWidth << endl;
136     outputFile << "iHeight                   : " << pRes->iHeight << endl;
137     outputFile << "iSize                     : " << pRes->iSize << endl;
138     outputFile << "iPitch                    : " << pRes->iPitch << endl;
139     outputFile << "iDepth                    : " << pRes->iDepth << endl;
140     outputFile << "Format                    : " << (int32_t)pRes->Format << endl;
141     outputFile << "iCount                    : " << pRes->iCount << endl;
142     outputFile << "iAllocationIndex          : ";
143     for (auto i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
144     {
145         outputFile << pRes->iAllocationIndex[i] << " ";
146     }
147     outputFile << endl;
148     outputFile << "dwGfxAddress              : " << pRes->dwGfxAddress << endl;
149     outputFile << "bufname                   : " << pRes->bufname << endl;
150     outputFile << "isTiled                   : " << pRes->isTiled << endl;
151     outputFile << "TileType                  : " << GetTileType(pRes->TileType) << endl;
152     outputFile << "bMapped                   : " << pRes->bMapped << endl;
153     outputFile << "name                      : " << pRes->name << endl;
154     outputFile << "user_provided_va          : " << pRes->user_provided_va << endl;
155     outputFile << "bConvertedFromDDIResource : " << pRes->bConvertedFromDDIResource << endl;
156     outputFile << endl;
157 }
158 
GetCmdResPtrs(PMOS_INTERFACE pOsInterface) const159 const std::vector<const void *> &GpuCmdResInfoDumpNext::GetCmdResPtrs(PMOS_INTERFACE pOsInterface) const
160 {
161     const auto *gpuContext = MosInterface::GetGpuContext(pOsInterface->osStreamState, pOsInterface->CurrentGpuContextHandle);
162     if(gpuContext == nullptr)
163     {
164         MOS_OS_ASSERTMESSAGE("gpuContext == nullptr");
165         static const std::vector<const void*> dummyVec = {nullptr};
166         return dummyVec;
167     }
168 
169     return gpuContext->GetCmdResPtrs();
170 }
171 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
172