1 /* 2 * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are permitted 5 * provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided 10 * with the distribution. 11 * * Neither the name of The Linux Foundation nor the names of its contributors may be used to 12 * endorse or promote products derived from this software without specific prior written 13 * permission. 14 * 15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25 #ifndef __RESOURCE_DEFAULT_H__ 26 #define __RESOURCE_DEFAULT_H__ 27 28 #include <core/display_interface.h> 29 #include <private/resource_interface.h> 30 #include <utils/locker.h> 31 32 #include "hw_interface.h" 33 34 namespace sdm { 35 36 class ResourceDefault : public ResourceInterface { 37 public: 38 DisplayError Init(const HWResourceInfo &hw_resource_info); 39 DisplayError Deinit(); 40 virtual DisplayError RegisterDisplay(DisplayType type, const HWDisplayAttributes &attributes, 41 const HWPanelInfo &hw_panel_info, Handle *display_ctx); 42 virtual DisplayError UnregisterDisplay(Handle display_ctx); 43 virtual void ReconfigureDisplay(Handle display_ctx, const HWDisplayAttributes &attributes, 44 const HWPanelInfo &hw_panel_info); 45 virtual DisplayError Start(Handle display_ctx); 46 virtual DisplayError Stop(Handle display_ctx); 47 virtual DisplayError Acquire(Handle display_ctx, HWLayers *hw_layers); 48 virtual DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers); 49 virtual DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers); 50 virtual void Purge(Handle display_ctx); 51 virtual DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages); 52 virtual DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, 53 bool rotate90, bool ubwc_tiled, bool use_rotator_downscale); 54 DisplayError ValidateCursorConfig(Handle display_ctx, const Layer& layer, bool is_top); 55 DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y); 56 DisplayError SetMaxBandwidthMode(HWBwModes mode); 57 58 private: 59 enum PipeOwner { 60 kPipeOwnerUserMode, // Pipe state when it is available for reservation 61 kPipeOwnerKernelMode, // Pipe state when pipe is owned by kernel 62 }; 63 64 // todo: retrieve all these from kernel 65 enum { 66 kMaxDecimationDownScaleRatio = 16, 67 }; 68 69 struct SourcePipe { 70 PipeType type; 71 PipeOwner owner; 72 uint32_t mdss_pipe_id; 73 uint32_t index; 74 HWBlockType hw_block_id; 75 int priority; 76 SourcePipeSourcePipe77 SourcePipe() : type(kPipeTypeUnused), owner(kPipeOwnerUserMode), mdss_pipe_id(0), 78 index(0), hw_block_id(kHWBlockMax), priority(0) { } 79 ResetStateSourcePipe80 inline void ResetState() { hw_block_id = kHWBlockMax;} 81 }; 82 83 struct DisplayResourceContext { 84 HWDisplayAttributes display_attributes; 85 HWBlockType hw_block_id; 86 uint64_t frame_count; 87 DisplayResourceContextDisplayResourceContext88 DisplayResourceContext() : hw_block_id(kHWBlockMax), frame_count(0) { } 89 }; 90 91 struct HWBlockContext { 92 bool is_in_use; HWBlockContextHWBlockContext93 HWBlockContext() : is_in_use(false) { } 94 }; 95 96 uint32_t NextPipe(PipeType pipe_type, HWBlockType hw_block_id); 97 uint32_t SearchPipe(HWBlockType hw_block_id, SourcePipe *src_pipes, uint32_t num_pipe); 98 uint32_t GetPipe(HWBlockType hw_block_id, bool need_scale); 99 bool IsScalingNeeded(const HWPipeInfo *pipe_info); 100 DisplayError Config(DisplayResourceContext *display_resource_ctx, HWLayers *hw_layers); 101 DisplayError DisplaySplitConfig(DisplayResourceContext *display_resource_ctx, 102 const LayerRect &src_rect, const LayerRect &dst_rect, 103 HWLayerConfig *layer_config); 104 DisplayError SrcSplitConfig(DisplayResourceContext *display_resource_ctx, 105 const LayerRect &src_rect, const LayerRect &dst_rect, 106 HWLayerConfig *layer_config); 107 bool CalculateCropRects(const LayerRect &scissor, LayerRect *crop, LayerRect *dst); 108 DisplayError ValidateLayerParams(const Layer &layer); 109 DisplayError ValidateDimensions(const LayerRect &crop, const LayerRect &dst); 110 DisplayError ValidatePipeParams(HWPipeInfo *pipe_info, bool ubwc_tiled); 111 DisplayError ValidateDownScaling(float scale_x, float scale_y, bool ubwc_tiled); 112 DisplayError ValidateUpScaling(float scale_x, float scale_y); 113 DisplayError GetScaleFactor(const LayerRect &crop, const LayerRect &dst, float *scale_x, 114 float *scale_y); 115 DisplayError SetDecimationFactor(HWPipeInfo *pipe); 116 void SplitRect(const LayerRect &src_rect, const LayerRect &dst_rect, LayerRect *src_left, 117 LayerRect *dst_left, LayerRect *src_right, LayerRect *dst_right); 118 DisplayError AlignPipeConfig(const Layer &layer, HWPipeInfo *left_pipe, HWPipeInfo *right_pipe); 119 void ResourceStateLog(void); 120 DisplayError CalculateDecimation(float downscale, uint8_t *decimation); 121 122 Locker locker_; 123 HWResourceInfo hw_res_info_; 124 HWBlockContext hw_block_ctx_[kHWBlockMax]; 125 SourcePipe *src_pipes_ = NULL; 126 uint32_t num_pipe_ = 0; 127 }; 128 129 } // namespace sdm 130 131 #endif // __RESOURCE_DEFAULT_H__ 132 133