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#include <vector>
32
33#include "hw_interface.h"
34
35namespace sdm {
36
37class ResourceDefault : public ResourceInterface {
38 public:
39  DisplayError Init(const HWResourceInfo &hw_resource_info);
40  DisplayError Deinit();
41  virtual DisplayError RegisterDisplay(DisplayType type,
42                                       const HWDisplayAttributes &display_attributes,
43                                       const HWPanelInfo &hw_panel_info,
44                                       const HWMixerAttributes &mixer_attributes,
45                                       Handle *display_ctx);
46  virtual DisplayError UnregisterDisplay(Handle display_ctx);
47  virtual DisplayError ReconfigureDisplay(Handle display_ctx,
48                                          const HWDisplayAttributes &display_attributes,
49                                          const HWPanelInfo &hw_panel_info,
50                                          const HWMixerAttributes &mixer_attributes);
51  virtual DisplayError Start(Handle display_ctx);
52  virtual DisplayError Stop(Handle display_ctx);
53  virtual DisplayError Acquire(Handle display_ctx, HWLayers *hw_layers);
54  virtual DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers);
55  virtual DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers);
56  virtual void Purge(Handle display_ctx);
57  virtual DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages);
58  virtual DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst,
59                                       bool rotate90, bool ubwc_tiled, bool use_rotator_downscale);
60  DisplayError ValidateCursorConfig(Handle display_ctx, const Layer *layer, bool is_top);
61  DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y);
62  DisplayError SetMaxBandwidthMode(HWBwModes mode);
63  virtual DisplayError SetDetailEnhancerData(Handle display_ctx,
64                                             const DisplayDetailEnhancerData &de_data);
65
66 private:
67  enum PipeOwner {
68    kPipeOwnerUserMode,       // Pipe state when it is available for reservation
69    kPipeOwnerKernelMode,  // Pipe state when pipe is owned by kernel
70  };
71
72  // todo: retrieve all these from kernel
73  enum {
74    kMaxDecimationDownScaleRatio = 16,
75  };
76
77  struct SourcePipe {
78    PipeType type;
79    PipeOwner owner;
80    uint32_t mdss_pipe_id;
81    uint32_t index;
82    HWBlockType hw_block_id;
83    int priority;
84
85    SourcePipe() : type(kPipeTypeUnused), owner(kPipeOwnerUserMode), mdss_pipe_id(0),
86                  index(0), hw_block_id(kHWBlockMax), priority(0) { }
87
88    inline void ResetState() { hw_block_id = kHWBlockMax;}
89  };
90
91  struct DisplayResourceContext {
92    HWDisplayAttributes display_attributes;
93    HWBlockType hw_block_id;
94    uint64_t frame_count;
95    HWMixerAttributes mixer_attributes;
96
97    DisplayResourceContext() : hw_block_id(kHWBlockMax), frame_count(0) { }
98  };
99
100  struct HWBlockContext {
101    bool is_in_use;
102    HWBlockContext() : is_in_use(false) { }
103  };
104
105  uint32_t NextPipe(PipeType pipe_type, HWBlockType hw_block_id);
106  uint32_t SearchPipe(HWBlockType hw_block_id, SourcePipe *src_pipes, uint32_t num_pipe);
107  uint32_t GetPipe(HWBlockType hw_block_id, bool need_scale);
108  bool IsScalingNeeded(const HWPipeInfo *pipe_info);
109  DisplayError Config(DisplayResourceContext *display_resource_ctx, HWLayers *hw_layers);
110  DisplayError DisplaySplitConfig(DisplayResourceContext *display_resource_ctx,
111                                 const LayerRect &src_rect, const LayerRect &dst_rect,
112                                 HWLayerConfig *layer_config);
113  DisplayError SrcSplitConfig(DisplayResourceContext *display_resource_ctx,
114                             const LayerRect &src_rect, const LayerRect &dst_rect,
115                             HWLayerConfig *layer_config);
116  bool CalculateCropRects(const LayerRect &scissor, LayerRect *crop, LayerRect *dst);
117  DisplayError ValidateLayerParams(const Layer *layer);
118  DisplayError ValidateDimensions(const LayerRect &crop, const LayerRect &dst);
119  DisplayError ValidatePipeParams(HWPipeInfo *pipe_info, bool ubwc_tiled);
120  DisplayError ValidateDownScaling(float scale_x, float scale_y, bool ubwc_tiled);
121  DisplayError ValidateUpScaling(float scale_x, float scale_y);
122  DisplayError GetScaleFactor(const LayerRect &crop, const LayerRect &dst, float *scale_x,
123                             float *scale_y);
124  DisplayError SetDecimationFactor(HWPipeInfo *pipe);
125  void SplitRect(const LayerRect &src_rect, const LayerRect &dst_rect, LayerRect *src_left,
126                LayerRect *dst_left, LayerRect *src_right, LayerRect *dst_right);
127  DisplayError AlignPipeConfig(const Layer *layer, HWPipeInfo *left_pipe,
128                               HWPipeInfo *right_pipe);
129  void ResourceStateLog(void);
130  DisplayError CalculateDecimation(float downscale, uint8_t *decimation);
131  DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info);
132
133  Locker locker_;
134  HWResourceInfo hw_res_info_;
135  HWBlockContext hw_block_ctx_[kHWBlockMax];
136  std::vector<SourcePipe> src_pipes_;
137  uint32_t num_pipe_ = 0;
138};
139
140}  // namespace sdm
141
142#endif  // __RESOURCE_DEFAULT_H__
143
144