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 #include <drm_logger.h>
31 #include "drm_property.h"
32 #include "drm_utils.h"
33 
34 namespace sde_drm {
35 
GetPropertyEnum(const std::string & name) const36 DRMProperty DRMPropertyManager::GetPropertyEnum(const std::string &name) const {
37   if (name == "type") { return DRMProperty::TYPE; }
38   if (name == "FB_ID") { return DRMProperty::FB_ID; }
39   if (name == "rot_fb_id") { return DRMProperty::ROT_FB_ID; }
40   if (name == "CRTC_ID") { return DRMProperty::CRTC_ID; }
41   if (name == "CRTC_X") { return DRMProperty::CRTC_X; }
42   if (name == "CRTC_Y") { return DRMProperty::CRTC_Y; }
43   if (name == "CRTC_W") { return DRMProperty::CRTC_W; }
44   if (name == "CRTC_H") { return DRMProperty::CRTC_H; }
45   if (name == "SRC_X") { return DRMProperty::SRC_X; }
46   if (name == "SRC_Y") { return DRMProperty::SRC_Y; }
47   if (name == "SRC_W") { return DRMProperty::SRC_W; }
48   if (name == "SRC_H") { return DRMProperty::SRC_H; }
49   if (name == "zpos") { return DRMProperty::ZPOS; }
50   if (name == "alpha") { return DRMProperty::ALPHA; }
51   if (name == "excl_rect_v1") { return DRMProperty::EXCL_RECT; }
52   if (name == "h_decimate") { return DRMProperty::H_DECIMATE; }
53   if (name == "v_decimate") { return DRMProperty::V_DECIMATE; }
54   if (name == "input_fence") { return DRMProperty::INPUT_FENCE; }
55   if (name == "rotation") { return DRMProperty::ROTATION; }
56   if (name == "blend_op") { return DRMProperty::BLEND_OP; }
57   if (name == "src_config") { return DRMProperty::SRC_CONFIG; }
58   if (name == "scaler_v1") { return DRMProperty::SCALER_V1; }
59   if (name == "scaler_v2") { return DRMProperty::SCALER_V2; }
60   if (name == "csc_v1") { return DRMProperty::CSC_V1; }
61   if (name == "capabilities") { return DRMProperty::CAPABILITIES; }
62   if (name == "mode_properties") { return DRMProperty::MODE_PROPERTIES; }
63   if (name == "lut_ed") { return DRMProperty::LUT_ED; }
64   if (name == "lut_cir") { return DRMProperty::LUT_CIR; }
65   if (name == "lut_sep") { return DRMProperty::LUT_SEP; }
66   if (name == "rot_caps_v1") { return DRMProperty::ROTATOR_CAPS_V1; }
67   if (name == "true_inline_rot_rev") { return DRMProperty::TRUE_INLINE_ROT_REV; }
68   if (name == "fb_translation_mode") { return DRMProperty::FB_TRANSLATION_MODE; }
69   if (name == "ACTIVE") { return DRMProperty::ACTIVE; }
70   if (name == "MODE_ID") { return DRMProperty::MODE_ID; }
71   if (name == "output_fence_offset") { return DRMProperty::OUTPUT_FENCE_OFFSET; }
72   if (name == "output_fence") { return DRMProperty::OUTPUT_FENCE; }
73   if (name == "sde_drm_roi_v1") { return DRMProperty::ROI_V1; }
74   if (name == "core_clk") { return DRMProperty::CORE_CLK; }
75   if (name == "core_ab") { return DRMProperty::CORE_AB; }
76   if (name == "core_ib") { return DRMProperty::CORE_IB; }
77   if (name == "llcc_ab") { return DRMProperty::LLCC_AB; }
78   if (name == "llcc_ib") { return DRMProperty::LLCC_IB; }
79   if (name == "dram_ab") { return DRMProperty::DRAM_AB; }
80   if (name == "dram_ib") { return DRMProperty::DRAM_IB; }
81   if (name == "rot_prefill_bw") { return DRMProperty::ROT_PREFILL_BW; }
82   if (name == "rot_clk") { return DRMProperty::ROT_CLK; }
83   if (name == "security_level") { return DRMProperty::SECURITY_LEVEL; }
84   if (name == "dim_layer_v1") { return DRMProperty::DIM_STAGES_V1; }
85   if (name == "idle_time") { return DRMProperty::IDLE_TIME; }
86   if (name == "RETIRE_FENCE") { return DRMProperty::RETIRE_FENCE; }
87   if (name == "DST_X") { return DRMProperty::DST_X; }
88   if (name == "DST_Y") { return DRMProperty::DST_Y; }
89   if (name == "DST_W") { return DRMProperty::DST_W; }
90   if (name == "DST_H") { return DRMProperty::DST_H; }
91   if (name == "LP") { return DRMProperty::LP; }
92   if (name == "dest_scaler") { return DRMProperty::DEST_SCALER; }
93   if (name == "ds_lut_ed") { return DRMProperty::DS_LUT_ED; }
94   if (name == "ds_lut_cir") { return DRMProperty::DS_LUT_CIR; }
95   if (name == "ds_lut_sep") { return DRMProperty::DS_LUT_SEP; }
96   if (name == "hdr_properties") { return DRMProperty::HDR_PROPERTIES; }
97   if (name == "SDE_DSPP_GAMUT_V3") { return DRMProperty::SDE_DSPP_GAMUT_V3; }
98   if (name == "SDE_DSPP_GAMUT_V4") { return DRMProperty::SDE_DSPP_GAMUT_V4; }
99   if (name == "SDE_DSPP_GAMUT_V5") { return DRMProperty::SDE_DSPP_GAMUT_V5; }
100   if (name == "SDE_DSPP_GC_V1") { return DRMProperty::SDE_DSPP_GC_V1; }
101   if (name == "SDE_DSPP_GC_V2") { return DRMProperty::SDE_DSPP_GC_V2; }
102   if (name == "SDE_DSPP_IGC_V2") { return DRMProperty::SDE_DSPP_IGC_V2; }
103   if (name == "SDE_DSPP_IGC_V3") { return DRMProperty::SDE_DSPP_IGC_V3; }
104   if (name == "SDE_DSPP_IGC_V4") { return DRMProperty::SDE_DSPP_IGC_V4; }
105   if (name == "SDE_DSPP_PCC_V3") { return DRMProperty::SDE_DSPP_PCC_V3; }
106   if (name == "SDE_DSPP_PCC_V4") { return DRMProperty::SDE_DSPP_PCC_V4; }
107   if (name == "SDE_DSPP_PCC_V5") { return DRMProperty::SDE_DSPP_PCC_V5; }
108   if (name == "SDE_DSPP_PA_HSIC_V1") { return DRMProperty::SDE_DSPP_PA_HSIC_V1; }
109   if (name == "SDE_DSPP_PA_HSIC_V2") { return DRMProperty::SDE_DSPP_PA_HSIC_V2; }
110   if (name == "SDE_DSPP_PA_SIXZONE_V1") { return DRMProperty::SDE_DSPP_PA_SIXZONE_V1; }
111   if (name == "SDE_DSPP_PA_SIXZONE_V2") { return DRMProperty::SDE_DSPP_PA_SIXZONE_V2; }
112   if (name == "SDE_DSPP_PA_MEMCOL_SKIN_V1") { return DRMProperty::SDE_DSPP_PA_MEMCOL_SKIN_V1; }
113   if (name == "SDE_DSPP_PA_MEMCOL_SKIN_V2") { return DRMProperty::SDE_DSPP_PA_MEMCOL_SKIN_V2; }
114   if (name == "SDE_DSPP_PA_MEMCOL_SKY_V1") { return DRMProperty::SDE_DSPP_PA_MEMCOL_SKY_V1; }
115   if (name == "SDE_DSPP_PA_MEMCOL_SKY_V2") { return DRMProperty::SDE_DSPP_PA_MEMCOL_SKY_V2; }
116   if (name == "SDE_DSPP_PA_MEMCOL_FOLIAGE_V1") { return DRMProperty::SDE_DSPP_PA_MEMCOL_FOLIAGE_V1; }
117   if (name == "SDE_DSPP_PA_MEMCOL_FOLIAGE_V2") { return DRMProperty::SDE_DSPP_PA_MEMCOL_FOLIAGE_V2; }
118   if (name == "SDE_DSPP_PA_MEMCOL_PROT_V1") { return DRMProperty::SDE_DSPP_PA_MEMCOL_PROT_V1; }
119   if (name == "SDE_DSPP_PA_MEMCOL_PROT_V2") { return DRMProperty::SDE_DSPP_PA_MEMCOL_PROT_V2; }
120   if (name == "autorefresh") { return DRMProperty::AUTOREFRESH; }
121   if (name == "ext_hdr_properties") { return DRMProperty::EXT_HDR_PROPERTIES; }
122   if (name == "hdr_metadata") { return DRMProperty::HDR_METADATA; }
123   if (name == "multirect_mode") { return DRMProperty::MULTIRECT_MODE; }
124   if (name == "SDE_DSPP_PA_DITHER_V1") { return DRMProperty::SDE_DSPP_PA_DITHER_V1; }
125   if (name == "SDE_DSPP_PA_DITHER_V2") { return DRMProperty::SDE_DSPP_PA_DITHER_V2; }
126   if (name == "SDE_PP_DITHER_V1") { return DRMProperty::SDE_PP_DITHER_V1; }
127   if (name == "SDE_PP_DITHER_V2") { return DRMProperty::SDE_PP_DITHER_V2; }
128   if (name == "inverse_pma") { return DRMProperty::INVERSE_PMA; }
129   if (name == "csc_dma_v1") { return DRMProperty::CSC_DMA_V1; }
130   if (name == "SDE_DGM_1D_LUT_IGC_V5") { return DRMProperty::SDE_DGM_1D_LUT_IGC_V5; }
131   if (name == "SDE_DGM_1D_LUT_GC_V5") { return DRMProperty::SDE_DGM_1D_LUT_GC_V5; }
132   if (name == "SDE_VIG_1D_LUT_IGC_V5") { return DRMProperty::SDE_VIG_1D_LUT_IGC_V5; }
133   if (name == "SDE_VIG_3D_LUT_GAMUT_V5") { return DRMProperty::SDE_VIG_3D_LUT_GAMUT_V5; }
134   if (name == "SDE_DSPP_AD_V4_MODE") { return DRMProperty::SDE_DSPP_AD4_MODE; }
135   if (name == "SDE_DSPP_AD_V4_INIT") { return DRMProperty::SDE_DSPP_AD4_INIT; }
136   if (name == "SDE_DSPP_AD_V4_CFG") { return DRMProperty::SDE_DSPP_AD4_CFG; }
137   if (name == "SDE_DSPP_AD_V4_ASSERTIVENESS") { return DRMProperty::SDE_DSPP_AD4_ASSERTIVENESS; }
138   if (name == "SDE_DSPP_AD_V4_STRENGTH") { return DRMProperty::SDE_DSPP_AD4_STRENGTH; }
139   if (name == "SDE_DSPP_AD_V4_INPUT") { return DRMProperty::SDE_DSPP_AD4_INPUT; }
140   if (name == "SDE_DSPP_AD_V4_BACKLIGHT") { return DRMProperty::SDE_DSPP_AD4_BACKLIGHT; }
141   if (name == "SDE_DSPP_AD_V4_ROI") { return DRMProperty::SDE_DSPP_AD4_ROI; }
142   if (name == "SDE_DSPP_HIST_CTRL_V1") { return DRMProperty::SDE_DSPP_ABA_HIST_CTRL; }
143   if (name == "SDE_DSPP_HIST_IRQ_V1") { return DRMProperty::SDE_DSPP_ABA_HIST_IRQ; }
144   if (name == "SDE_DSPP_VLUT_V1") { return DRMProperty::SDE_DSPP_ABA_LUT; }
145   if (name == "bl_scale") { return DRMProperty::SDE_DSPP_BL_SCALE; }
146   if (name == "sv_bl_scale") { return DRMProperty::SDE_DSPP_SV_BL_SCALE; }
147   if (name == "capture_mode") { return DRMProperty::CAPTURE_MODE; }
148   if (name == "qsync_mode") { return DRMProperty::QSYNC_MODE; }
149   if (name == "idle_pc_state") { return DRMProperty::IDLE_PC_STATE; }
150   if (name == "topology_control") { return DRMProperty::TOPOLOGY_CONTROL; }
151   if (name == "EDID") { return DRMProperty::EDID; }
152   if (name == "SDE_DSPP_LTM_V1") { return DRMProperty::SDE_LTM_VERSION; }
153   if (name == "SDE_DSPP_LTM_INIT_V1") { return DRMProperty::SDE_LTM_INIT; }
154   if (name == "SDE_DSPP_LTM_ROI_V1") { return DRMProperty::SDE_LTM_CFG; }
155   if (name == "SDE_DSPP_LTM_HIST_THRESH_V1") { return DRMProperty::SDE_LTM_NOISE_THRESH; }
156   if (name == "SDE_DSPP_LTM_HIST_CTRL_V1") { return DRMProperty::SDE_LTM_HIST_CTRL; }
157   if (name == "SDE_DSPP_LTM_SET_BUF_V1") { return DRMProperty::SDE_LTM_BUFFER_CTRL; }
158   if (name == "SDE_DSPP_LTM_QUEUE_BUF_V1") { return DRMProperty::SDE_LTM_QUEUE_BUFFER; }
159   if (name == "SDE_DSPP_LTM_QUEUE_BUF2_V1") { return DRMProperty::SDE_LTM_QUEUE_BUFFER2; }
160   if (name == "SDE_DSPP_LTM_QUEUE_BUF3_V1") { return DRMProperty::SDE_LTM_QUEUE_BUFFER3; }
161   if (name == "SDE_DSPP_LTM_VLUT_V1") { return DRMProperty::SDE_LTM_VLUT; }
162   if (name == "SDE_VIG_1D_LUT_IGC_V6") { return DRMProperty::SDE_VIG_1D_LUT_IGC_V6; }
163   if (name == "SDE_VIG_3D_LUT_GAMUT_V6") { return DRMProperty::SDE_VIG_3D_LUT_GAMUT_V6; }
164   if (name == "frame_trigger_mode") { return DRMProperty::FRAME_TRIGGER; }
165   if (name == "Colorspace") { return DRMProperty::COLORSPACE; }
166   if (name == "supported_colorspaces") { return DRMProperty::SUPPORTED_COLORSPACES; }
167   if (name == "sspp_layout") { return DRMProperty::SDE_SSPP_LAYOUT; }
168 
169   return DRMProperty::INVALID;
170 }
171 
172 #define __CLASS__ "DRMObject"
173 
DRMObject(DRMPropertyManager & pm)174 DRMObject::DRMObject(DRMPropertyManager& pm) : property_manager_(pm) {}
175 
AddProperty(DRMProperty prop,uint64_t value,bool force_dirty)176 void DRMObject::AddProperty(DRMProperty prop, uint64_t value, bool force_dirty) {
177   const uint32_t prop_id = property_manager_.GetPropertyId(prop);
178 
179   // bypass check if forced dirty or property is already dirty
180   if (!force_dirty && dirty_values_.find(prop_id) == dirty_values_.end()) {
181     auto it = property_values_.find(prop_id);
182 
183     // skip update if value hasn't changed
184     if (it != property_values_.end() && it->second == value) {
185       return;
186     }
187   }
188 
189   dirty_values_[prop_id] = value;
190 }
191 
RemoveProperty(DRMProperty prop)192 void DRMObject::RemoveProperty(DRMProperty prop) {
193   const uint32_t prop_id = property_manager_.GetPropertyId(prop);
194   dirty_values_.erase(prop_id);
195 }
196 
ApplyDirtyProperties(drmModeAtomicReq * req)197 size_t DRMObject::ApplyDirtyProperties(drmModeAtomicReq *req) {
198   const uint32_t obj_id = GetObjectId();
199 
200   for (const auto& it : dirty_values_)
201     drmModeAtomicAddProperty(req, obj_id, it.first, it.second);
202 
203   return dirty_values_.size();
204 }
205 
CommitProperties()206 void DRMObject::CommitProperties() {
207   for (const auto& it : dirty_values_)
208     property_values_[it.first] = it.second;
209   DiscardDirtyProperties();
210 }
211 
ClearProperties()212 void DRMObject::ClearProperties() {
213   property_values_.clear();
214   DiscardDirtyProperties();
215 }
216 
217 }  // namespace sde_drm
218