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 /* 31 * Changes from Qualcomm Innovation Center are provided under the following license: 32 * 33 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted (subject to the limitations in the 37 * disclaimer below) provided that the following conditions are met: 38 * 39 * * Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 42 * * Redistributions in binary form must reproduce the above 43 * copyright notice, this list of conditions and the following 44 * disclaimer in the documentation and/or other materials provided 45 * with the distribution. 46 * 47 * * Neither the name of Qualcomm Innovation Center, Inc. nor the 48 * names of its contributors may be used to endorse or promote 49 * products derived from this software without specific prior 50 * written permission. 51 * 52 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 53 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 54 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 55 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 56 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 58 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 60 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 62 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 63 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 64 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65 */ 66 67 #ifndef __DRM_PLANE_H__ 68 #define __DRM_PLANE_H__ 69 70 #include <drm/sde_drm.h> 71 #include <drm_interface.h> 72 #include <xf86drm.h> 73 #include <xf86drmMode.h> 74 #include <map> 75 #include <memory> 76 #include <string> 77 #include <tuple> 78 #include <mutex> 79 80 #include "drm_property.h" 81 #include "drm_pp_manager.h" 82 83 namespace sde_drm { 84 85 class DRMPlaneManager; 86 87 enum DRMPlaneLutState { 88 kInactive, // Lut is not in use, default 89 kActive, // Lut is in use 90 kDirty, // Plane was unset while being LUT was active, mark LUT as dirty 91 // to make sure it's cleared the next time plane is used 92 }; 93 94 class DRMPlane : public DRMObject { 95 public: 96 explicit DRMPlane(int fd, uint32_t priority); 97 ~DRMPlane(); 98 void InitAndParse(drmModePlane *plane); GetObjectId()99 uint32_t GetObjectId() override { return drm_plane_->plane_id; } GetType(DRMPlaneType * type)100 void GetType(DRMPlaneType *type) { *type = plane_type_info_.type; } GetPriority(uint32_t * priority)101 void GetPriority(uint32_t *priority) { *priority = priority_; } GetAssignedCrtc(uint32_t * crtc_id)102 void GetAssignedCrtc(uint32_t *crtc_id) { *crtc_id = assigned_crtc_id_; } GetRequestedCrtc(uint32_t * crtc_id)103 void GetRequestedCrtc(uint32_t *crtc_id) { *crtc_id = requested_crtc_id_; } SetAssignedCrtc(uint32_t crtc_id)104 void SetAssignedCrtc(uint32_t crtc_id) { assigned_crtc_id_ = crtc_id; } SetRequestedCrtc(uint32_t crtc_id)105 void SetRequestedCrtc(uint32_t crtc_id) { requested_crtc_id_ = crtc_id; } 106 bool SetScalerConfig(uint64_t handle); 107 bool SetCscConfig(DRMCscType csc_type); 108 bool ConfigureScalerLUT(uint32_t dir_lut_blob_id, 109 uint32_t cir_lut_blob_id, uint32_t sep_lut_blob_id); GetPlaneTypeInfo()110 const DRMPlaneTypeInfo& GetPlaneTypeInfo() { return plane_type_info_; } 111 void SetDecimation(DRMProperty prop, uint32_t prop_value); 112 void SetExclRect(DRMRect rect); 113 void Perform(DRMOps code, drmModeAtomicReq *req, va_list args); 114 void Dump(); 115 void SetMultiRectMode(DRMMultiRectMode drm_multirect_mode); 116 void Unset(bool is_commit, drmModeAtomicReq *req); 117 void PostValidate(uint32_t crtc_id); 118 void PostCommit(uint32_t crtc_id, bool success); 119 bool SetDgmCscConfig(uint64_t handle); 120 void UpdatePPLutFeatureInuse(DRMPPFeatureInfo *data); 121 void ResetColorLUTs(bool is_commit, drmModeAtomicReq *req); 122 void ResetColorLUTState(DRMTonemapLutType lut_type, bool is_commit, drmModeAtomicReq *req); 123 void ResetColorLUT(DRMPPFeatureID id, drmModeAtomicReq *req); 124 125 private: 126 typedef std::map<DRMProperty, std::tuple<uint64_t, drmModePropertyRes *>> PropertyMap; 127 void ParseProperties(); 128 void GetTypeInfo(const PropertyMap &props); 129 void PerformWrapper(DRMOps code, drmModeAtomicReq *req, ...); 130 131 int fd_ = -1; 132 uint32_t priority_ = 0; 133 drmModePlane *drm_plane_ = {}; 134 DRMPlaneTypeInfo plane_type_info_{}; 135 uint32_t assigned_crtc_id_ = 0; 136 uint32_t requested_crtc_id_ = 0; 137 DRMPropertyManager prop_mgr_ {}; 138 bool has_excl_rect_ = false; 139 drm_clip_rect excl_rect_copy_ = {}; 140 std::unique_ptr<DRMPPManager> pp_mgr_ {}; 141 142 // Only applicable to planes that have scaler 143 sde_drm_scaler_v2 scaler_v2_config_copy_ = {}; 144 sde_drm_csc_v1 csc_config_copy_ = {}; 145 bool is_lut_configured_ = false; 146 147 bool dgm_csc_in_use_ = false; 148 // Tone-mapping lut properties 149 DRMPlaneLutState dgm_1d_lut_igc_state_ = kInactive; 150 DRMPlaneLutState dgm_1d_lut_gc_state_ = kInactive; 151 DRMPlaneLutState vig_1d_lut_igc_state_ = kInactive; 152 DRMPlaneLutState vig_3d_lut_gamut_state_ = kInactive; 153 }; 154 155 class DRMPlaneManager : public DRMObjectManager<DRMPlane> { 156 public: 157 explicit DRMPlaneManager(int fd); 158 void Init(); DeInit()159 void DeInit() {} 160 void GetPlanesInfo(DRMPlanesInfo *info); 161 void Perform(DRMOps code, uint32_t obj_id, drmModeAtomicReq *req, va_list args); 162 void UnsetUnusedResources(uint32_t crtc_id, bool is_commit, drmModeAtomicReq *req); 163 void ResetColorLutsOnUsedPlanes(uint32_t crtc_id, bool is_commit, drmModeAtomicReq *req); 164 void RetainPlanes(uint32_t crtc_id); 165 void SetScalerLUT(const DRMScalerLUTInfo &lut_info); 166 void UnsetScalerLUT(); 167 void PostValidate(uint32_t crtc_id); 168 void PostCommit(uint32_t crtc_id, bool success); 169 170 private: 171 int fd_ = -1; 172 // Global Scaler LUT blobs 173 uint32_t dir_lut_blob_id_ = 0; 174 uint32_t cir_lut_blob_id_ = 0; 175 uint32_t sep_lut_blob_id_ = 0; 176 std::mutex lock_; 177 }; 178 179 } // namespace sde_drm 180 181 #endif // __DRM_PLANE_H__ 182