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_PROPERTY_H__ 31 #define __DRM_PROPERTY_H__ 32 33 #include <stdint.h> 34 #include <string> 35 #include <map> 36 #include <unordered_map> 37 #include <xf86drmMode.h> 38 39 namespace sde_drm { 40 41 enum struct DRMProperty { 42 INVALID, 43 TYPE, 44 FB_ID, 45 CRTC_ID, 46 CRTC_X, 47 CRTC_Y, 48 CRTC_W, 49 CRTC_H, 50 SRC_X, 51 SRC_Y, 52 SRC_W, 53 SRC_H, 54 ZPOS, 55 ALPHA, 56 EXCL_RECT, 57 H_DECIMATE, 58 V_DECIMATE, 59 INPUT_FENCE, 60 ROTATION, 61 BLEND_OP, 62 SRC_CONFIG, 63 SCALER_V1, 64 SCALER_V2, 65 CSC_V1, 66 CAPABILITIES, 67 MODE_PROPERTIES, 68 LUT_ED, 69 LUT_CIR, 70 LUT_SEP, 71 ROTATOR_CAPS_V1, 72 TRUE_INLINE_ROT_REV, 73 FB_TRANSLATION_MODE, 74 ACTIVE, 75 MODE_ID, 76 OUTPUT_FENCE_OFFSET, 77 OUTPUT_FENCE, 78 ROI_V1, 79 CORE_CLK, 80 CORE_AB, 81 CORE_IB, 82 LLCC_AB, 83 LLCC_IB, 84 DRAM_AB, 85 DRAM_IB, 86 ROT_PREFILL_BW, 87 ROT_CLK, 88 SECURITY_LEVEL, 89 DIM_STAGES_V1, 90 IDLE_TIME, 91 RETIRE_FENCE, 92 DST_X, 93 DST_Y, 94 DST_W, 95 DST_H, 96 LP, 97 HDR_PROPERTIES, 98 DEST_SCALER, 99 DS_LUT_ED, 100 DS_LUT_CIR, 101 DS_LUT_SEP, 102 SDE_DSPP_GAMUT_V3, 103 SDE_DSPP_GAMUT_V4, 104 SDE_DSPP_GAMUT_V5, 105 SDE_DSPP_GC_V1, 106 SDE_DSPP_GC_V2, 107 SDE_DSPP_IGC_V2, 108 SDE_DSPP_IGC_V3, 109 SDE_DSPP_IGC_V4, 110 SDE_DSPP_PCC_V3, 111 SDE_DSPP_PCC_V4, 112 SDE_DSPP_PCC_V5, 113 SDE_DSPP_PA_HSIC_V1, 114 SDE_DSPP_PA_HSIC_V2, 115 SDE_DSPP_PA_SIXZONE_V1, 116 SDE_DSPP_PA_SIXZONE_V2, 117 SDE_DSPP_PA_MEMCOL_SKIN_V1, 118 SDE_DSPP_PA_MEMCOL_SKIN_V2, 119 SDE_DSPP_PA_MEMCOL_SKY_V1, 120 SDE_DSPP_PA_MEMCOL_SKY_V2, 121 SDE_DSPP_PA_MEMCOL_FOLIAGE_V1, 122 SDE_DSPP_PA_MEMCOL_FOLIAGE_V2, 123 SDE_DSPP_PA_MEMCOL_PROT_V1, 124 SDE_DSPP_PA_MEMCOL_PROT_V2, 125 AUTOREFRESH, 126 EXT_HDR_PROPERTIES, 127 HDR_METADATA, 128 MULTIRECT_MODE, 129 ROT_FB_ID, 130 SDE_DSPP_PA_DITHER_V1, 131 SDE_DSPP_PA_DITHER_V2, 132 SDE_PP_DITHER_V1, 133 SDE_PP_DITHER_V2, 134 INVERSE_PMA, 135 CSC_DMA_V1, 136 SDE_DGM_1D_LUT_IGC_V5, 137 SDE_DGM_1D_LUT_GC_V5, 138 SDE_VIG_1D_LUT_IGC_V5, 139 SDE_VIG_1D_LUT_IGC_V6, 140 SDE_VIG_3D_LUT_GAMUT_V5, 141 SDE_VIG_3D_LUT_GAMUT_V6, 142 SDE_DSPP_AD4_MODE, 143 SDE_DSPP_AD4_INIT, 144 SDE_DSPP_AD4_CFG, 145 SDE_DSPP_AD4_INPUT, 146 SDE_DSPP_AD4_BACKLIGHT, 147 SDE_DSPP_AD4_ROI, 148 SDE_DSPP_AD4_ASSERTIVENESS, 149 SDE_DSPP_AD4_STRENGTH, 150 SDE_DSPP_ABA_HIST_CTRL, 151 SDE_DSPP_ABA_HIST_IRQ, 152 SDE_DSPP_ABA_LUT, 153 SDE_DSPP_SV_BL_SCALE, 154 SDE_DSPP_BL_SCALE, 155 CAPTURE_MODE, 156 QSYNC_MODE, 157 IDLE_PC_STATE, 158 TOPOLOGY_CONTROL, 159 EDID, 160 SDE_LTM_VERSION, 161 SDE_LTM_INIT, 162 SDE_LTM_CFG, 163 SDE_LTM_NOISE_THRESH, 164 SDE_LTM_HIST_CTRL, 165 SDE_LTM_BUFFER_CTRL, 166 SDE_LTM_QUEUE_BUFFER, 167 SDE_LTM_QUEUE_BUFFER2, 168 SDE_LTM_QUEUE_BUFFER3, 169 SDE_LTM_VLUT, 170 FRAME_TRIGGER, 171 COLORSPACE, 172 SUPPORTED_COLORSPACES, 173 SDE_SSPP_LAYOUT, 174 175 // Insert above 176 MAX 177 }; 178 179 struct DRMPropertyManager { 180 DRMProperty GetPropertyEnum(const std::string &name) const; 181 SetPropertyIdDRMPropertyManager182 void SetPropertyId(DRMProperty prop_enum, uint32_t prop_id) { 183 properties_[(uint32_t)prop_enum] = prop_id; 184 } 185 GetPropertyIdDRMPropertyManager186 uint32_t GetPropertyId(DRMProperty prop_enum) const { 187 return properties_[(uint32_t)prop_enum]; 188 } 189 IsPropertyAvailableDRMPropertyManager190 bool IsPropertyAvailable(DRMProperty prop_enum) const { 191 return !!properties_[(uint32_t)prop_enum]; 192 } 193 194 private: 195 uint32_t properties_[(uint32_t)DRMProperty::MAX] {}; 196 }; 197 198 struct DRMObject { 199 virtual ~DRMObject() = default; 200 virtual uint32_t GetObjectId() = 0; DumpDRMObject201 void Dump() {}; 202 203 void AddProperty(DRMProperty prop, uint64_t value, bool force_dirty = false); 204 void RemoveProperty(DRMProperty prop); 205 size_t ApplyDirtyProperties(drmModeAtomicReq *req); DiscardDirtyPropertiesDRMObject206 void DiscardDirtyProperties() { dirty_values_.clear(); } 207 void ClearProperties(); 208 void CommitProperties(); 209 210 protected: 211 explicit DRMObject(DRMPropertyManager &pm); 212 213 private: 214 std::unordered_map<uint32_t, uint64_t> property_values_ {}; 215 // store properties ordered by prop_id to avoid re-sort in libdrm 216 std::map<uint32_t, uint64_t, std::greater<uint32_t>> dirty_values_ {}; 217 DRMPropertyManager& property_manager_; 218 }; 219 220 template<class T> 221 struct DRMObjectManager { 222 virtual ~DRMObjectManager() = default; DumpByIdDRMObjectManager223 void DumpById(uint32_t id) { object_pool_.at(id)->Dump(); } DumpAllDRMObjectManager224 void DumpAll() { 225 for (auto &obj : object_pool_) 226 obj.second->Dump(); 227 } 228 ApplyDirtyPropertiesDRMObjectManager229 size_t ApplyDirtyProperties(drmModeAtomicReq *req) { 230 size_t dirty_count = 0; 231 for (auto &obj : object_pool_) 232 dirty_count += obj.second->ApplyDirtyProperties(req); 233 234 return dirty_count; 235 } 236 ClearPropertiesDRMObjectManager237 void ClearProperties() { 238 for (auto &obj : object_pool_) 239 obj.second->ClearProperties(); 240 } 241 GetObjectDRMObjectManager242 T* GetObject(uint32_t obj_id) { 243 auto it = object_pool_.find(obj_id); 244 if (it == object_pool_.end()) 245 return nullptr; 246 return it->second.get(); 247 } 248 protected: 249 // store objects ordered by obj_id to avoid re-sort in libdrm 250 std::map<uint32_t, std::unique_ptr<T>> object_pool_{}; 251 }; 252 253 } // namespace sde_drm 254 255 #endif // __DRM_PROPERTY_H__ 256