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_CONNECTOR_H__ 31 #define __DRM_CONNECTOR_H__ 32 33 #include <drm_interface.h> 34 #include <xf86drm.h> 35 #include <xf86drmMode.h> 36 #include <map> 37 #include <memory> 38 #include <memory> 39 #include <drm/msm_drm.h> 40 #include <mutex> 41 #include <set> 42 #include "drm_pp_manager.h" 43 44 #include "drm_utils.h" 45 #include "drm_property.h" 46 47 namespace sde_drm { 48 49 class DRMConnector { 50 public: DRMConnector(int fd)51 explicit DRMConnector(int fd) : fd_(fd) {} 52 ~DRMConnector(); 53 void InitAndParse(drmModeConnector *conn); Lock()54 void Lock() { status_ = DRMStatus::BUSY; } Unlock()55 void Unlock() { status_ = DRMStatus::FREE; } GetStatus()56 DRMStatus GetStatus() { return status_; } 57 int GetInfo(DRMConnectorInfo *info); GetType(uint32_t * conn_type)58 void GetType(uint32_t *conn_type) { *conn_type = drm_connector_->connector_type; } 59 void Perform(DRMOps code, drmModeAtomicReq *req, va_list args); IsConnected()60 int IsConnected() { return (DRM_MODE_CONNECTED == drm_connector_->connection); } 61 int GetPossibleEncoders(std::set<uint32_t> *possible_encoders); SetSkipConnectorReload(bool skip_reload)62 void SetSkipConnectorReload(bool skip_reload) { skip_connector_reload_ = skip_reload; }; 63 void Dump(); 64 65 private: 66 void ParseProperties(); 67 void ParseCapabilities(uint64_t blob_id, DRMConnectorInfo *info); 68 void ParseCapabilities(uint64_t blob_id, drm_panel_hdr_properties *hdr_info); 69 void ParseModeProperties(uint64_t blob_id, DRMConnectorInfo *info); 70 void ParseCapabilities(uint64_t blob_id, drm_msm_ext_hdr_properties *hdr_info); 71 void ParseCapabilities(uint64_t blob_id, std::vector<uint8_t> *edid); 72 void SetROI(drmModeAtomicReq *req, uint32_t obj_id, uint32_t num_roi, 73 DRMRect *conn_rois); 74 75 int fd_ = -1; 76 drmModeConnector *drm_connector_ = {}; 77 DRMPropertyManager prop_mgr_ {}; 78 bool skip_connector_reload_ = false; // Usually set to true for new TV/pluggable displays. 79 DRMStatus status_ = DRMStatus::FREE; 80 std::unique_ptr<DRMPPManager> pp_mgr_{}; 81 }; 82 83 class DRMConnectorManager { 84 public: DRMConnectorManager(int fd)85 explicit DRMConnectorManager(int fd) : fd_(fd) {} 86 void Init(drmModeRes *res); 87 void Update(); DeInit()88 void DeInit() {} 89 void DumpAll(); 90 void DumpByID(uint32_t id); 91 int Reserve(DRMDisplayType disp_type, DRMDisplayToken *token); 92 int Reserve(uint32_t conn_id, DRMDisplayToken *token); 93 void Free(DRMDisplayToken *token); 94 void Perform(DRMOps code, uint32_t obj_id, drmModeAtomicReq *req, va_list args); 95 int GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info); 96 void GetConnectorList(std::vector<uint32_t> *conn_ids); 97 int GetPossibleEncoders(uint32_t connector_id, std::set<uint32_t> *possible_encoders); ~DRMConnectorManager()98 ~DRMConnectorManager() {} 99 100 private: 101 int fd_ = -1; 102 std::mutex lock_; 103 // Map of connector id to DRMConnector * 104 std::map<uint32_t, std::unique_ptr<DRMConnector>> connector_pool_{}; 105 }; 106 107 } // namespace sde_drm 108 109 #endif // __DRM_CONNECTOR_H__ 110