1 /* 2 * Copyright (c) 2019, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef __DRM_ENCODER_H__ 31 #define __DRM_ENCODER_H__ 32 33 #include <xf86drm.h> 34 #include <xf86drmMode.h> 35 #include <map> 36 #include <memory> 37 #include <vector> 38 #include <utility> 39 #include <set> 40 41 #include "drm_interface.h" 42 #include "drm_utils.h" 43 44 namespace sde_drm { 45 46 class DRMEncoder { 47 public: DRMEncoder(int fd)48 explicit DRMEncoder(int fd) : fd_(fd) {} DRMEncoder(int fd,uint32_t id,uint32_t type)49 DRMEncoder(int fd, uint32_t id, uint32_t type) : fd_(fd), fake_id_(id), fake_type_(type) {} 50 void InitAndParse(drmModeEncoder *encoder); GetStatus()51 DRMStatus GetStatus() { return status_; } 52 void GetInfo(DRMEncoderInfo *info); GetType(uint32_t * encoder_type)53 void GetType(uint32_t *encoder_type) { 54 drm_encoder_ ? *encoder_type = drm_encoder_->encoder_type 55 : *encoder_type = fake_type_; 56 } GetId(uint32_t * encoder_id)57 void GetId(uint32_t *encoder_id) { 58 drm_encoder_ ? *encoder_id = drm_encoder_->encoder_id 59 : *encoder_id = fake_id_; 60 } 61 int GetPossibleCrtcIndices(std::set<uint32_t> *possible_crtc_indices); 62 void Dump(); 63 void Lock(); 64 void Unlock(); 65 ~DRMEncoder(); 66 67 private: 68 int fd_ = -1; 69 drmModeEncoder *drm_encoder_ = {}; 70 DRMStatus status_ = DRMStatus::FREE; 71 DRMEncoderInfo encoder_info_ = {}; 72 73 // Userspace injected data, only used for creating object not reported by the driver 74 uint32_t fake_id_; 75 uint32_t fake_type_; 76 }; 77 78 class DRMEncoderManager { 79 public: DRMEncoderManager(int fd)80 explicit DRMEncoderManager(int fd) : fd_(fd) {} 81 ~DRMEncoderManager(); 82 void Init(drmModeRes *res); 83 void InsertSecondaryDSI(); DeInit()84 void DeInit() {} 85 void DumpAll(); 86 void DumpByID(uint32_t id); 87 int Reserve(const std::set<uint32_t> &possible_encoders, DRMDisplayToken *token); 88 void Free(DRMDisplayToken *token); 89 int GetEncoderInfo(uint32_t encoder_id, DRMEncoderInfo *info); 90 int GetEncoderList(std::vector<uint32_t> *encoder_ids); 91 int GetPossibleCrtcIndices(uint32_t encoder_id, std::set<uint32_t> *possible_crtc_indices); 92 93 private: 94 int fd_ = -1; 95 std::map<uint32_t, std::unique_ptr<DRMEncoder>> encoder_pool_{}; 96 int GetDisplayTypeCode(uint32_t encoder_type); 97 }; 98 99 } // namespace sde_drm 100 101 #endif // __DRM_ENCODER_H__ 102