1 #ifndef _TCULIBDRM_HPP 2 #define _TCULIBDRM_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2022 NVIDIA, Inc. 8 * Copyright (c) 2022 The Khronos Group Inc. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Drm utilities. 25 *//*--------------------------------------------------------------------*/ 26 27 #if DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC) 28 29 #include "deDynamicLibrary.hpp" 30 31 #include "deUniquePtr.hpp" 32 33 #include <xf86drm.h> 34 #include <xf86drmMode.h> 35 36 namespace tcu 37 { 38 39 class LibDrm : protected de::DynamicLibrary 40 { 41 typedef void (*FdDeleter) (int*); 42 typedef void (*PFNDRMMODEFREERESOURCESPROC) (drmModeRes*); 43 typedef void (*PFNDRMMODEFREECONNECTORPROC) (drmModeConnector*); 44 typedef void (*PFNDRMMODEFREEENCODERPROC) (drmModeEncoder*); 45 46 public: 47 typedef de::UniquePtr<int, FdDeleter> FdPtr; 48 typedef de::UniquePtr<drmModeRes, PFNDRMMODEFREERESOURCESPROC> ResPtr; 49 typedef de::UniquePtr<drmModeConnector, PFNDRMMODEFREECONNECTORPROC> ConnectorPtr; 50 typedef de::UniquePtr<drmModeEncoder, PFNDRMMODEFREEENCODERPROC> EncoderPtr; 51 52 LibDrm (void); 53 virtual ~LibDrm (void); 54 55 drmDevicePtr* getDevices (int *pNumDevices) const; 56 const char* findDeviceNode (drmDevicePtr *devices, int count, deInt64 major, deInt64 minor) const; 57 void freeDevices (drmDevicePtr *devices, int count) const; 58 59 FdPtr openFd (const char* node) const; 60 ResPtr getResources (int fd) const; 61 ConnectorPtr getConnector (int fd, deUint32 connectorId) const; 62 EncoderPtr getEncoder (int fd, deUint32 encoderId) const; 63 FdPtr createLease (int fd, const deUint32 *objects, int numObjects, int flags) const; 64 int authMagic (int fd, drm_magic_t magic) const; 65 66 private: 67 int intGetDevices(drmDevicePtr devices[], int maxDevices) const; 68 69 static const char* libDrmFiles[]; 70 71 typedef int (*PFNDRMGETDEVICES2PROC) (deUint32, drmDevicePtr[], int); 72 typedef int (*PFNDRMGETDEVICESPROC) (drmDevicePtr[], int); 73 typedef void (*PFNDRMFREEDEVICESPROC) (drmDevicePtr[], int); 74 typedef drmModeRes* (*PFNDRMMODEGETRESOURCESPROC) (int); 75 typedef drmModeConnector* (*PFNDRMMODEGETCONNECTORPROC) (int, deUint32); 76 typedef drmModeEncoder* (*PFNDRMMODEGETENCODERPROC) (int, deUint32); 77 typedef int (*PFNDRMMODECREATELEASEPROC) (int, const deUint32*, int, int, deUint32*); 78 typedef int (*PFNDRMAUTHMAGIC) (int, drm_magic_t); 79 PFNDRMGETDEVICES2PROC pGetDevices2; 80 PFNDRMGETDEVICESPROC pGetDevices; 81 PFNDRMFREEDEVICESPROC pFreeDevices; 82 PFNDRMMODEGETRESOURCESPROC pGetResources; 83 PFNDRMMODEGETCONNECTORPROC pGetConnector; 84 PFNDRMMODEGETENCODERPROC pGetEncoder; 85 PFNDRMMODEFREERESOURCESPROC pFreeResources; 86 PFNDRMMODEFREECONNECTORPROC pFreeConnector; 87 PFNDRMMODEFREEENCODERPROC pFreeEncoder; 88 PFNDRMMODECREATELEASEPROC pCreateLease; 89 PFNDRMAUTHMAGIC pAuthMagic; 90 }; 91 92 } // tcu 93 94 #endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC) 95 96 #endif // _TCULIBDRM_HPP 97