1 /* 2 * Copyright (c) 2017, 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 __HW_DEVICE_DRM_H__ 31 #define __HW_DEVICE_DRM_H__ 32 33 #include <drm_interface.h> 34 #include <errno.h> 35 #include <pthread.h> 36 #include <xf86drmMode.h> 37 #include <string> 38 #include <vector> 39 40 #include "hw_interface.h" 41 42 #define IOCTL_LOGE(ioctl, type) \ 43 DLOGE("ioctl %s, device = %d errno = %d, desc = %s", #ioctl, type, errno, strerror(errno)) 44 45 namespace sdm { 46 class HWInfoInterface; 47 48 class HWDeviceDRM : public HWInterface { 49 public: 50 explicit HWDeviceDRM(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf); 51 virtual ~HWDeviceDRM() {} 52 virtual DisplayError Init(); 53 virtual DisplayError Deinit(); 54 55 protected: 56 // From HWInterface 57 virtual DisplayError GetActiveConfig(uint32_t *active_config); 58 virtual DisplayError GetNumDisplayAttributes(uint32_t *count); 59 virtual DisplayError GetDisplayAttributes(uint32_t index, 60 HWDisplayAttributes *display_attributes); 61 virtual DisplayError GetHWPanelInfo(HWPanelInfo *panel_info); 62 virtual DisplayError SetDisplayAttributes(uint32_t index); 63 virtual DisplayError SetDisplayAttributes(const HWDisplayAttributes &display_attributes); 64 virtual DisplayError GetConfigIndex(uint32_t mode, uint32_t *index); 65 virtual DisplayError PowerOn(); 66 virtual DisplayError PowerOff(); 67 virtual DisplayError Doze(); 68 virtual DisplayError DozeSuspend(); 69 virtual DisplayError Standby(); 70 virtual DisplayError Validate(HWLayers *hw_layers); 71 virtual DisplayError Commit(HWLayers *hw_layers); 72 virtual DisplayError Flush(); 73 virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); 74 virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list); 75 virtual DisplayError SetVSyncState(bool enable); 76 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 77 virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode); 78 virtual DisplayError SetRefreshRate(uint32_t refresh_rate); 79 virtual DisplayError SetPanelBrightness(int level); 80 virtual DisplayError CachePanelBrightness(int level); 81 virtual DisplayError GetHWScanInfo(HWScanInfo *scan_info); 82 virtual DisplayError GetVideoFormat(uint32_t config_index, uint32_t *video_format); 83 virtual DisplayError GetMaxCEAFormat(uint32_t *max_cea_format); 84 virtual DisplayError SetCursorPosition(HWLayers *hw_layers, int x, int y); 85 virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); 86 virtual DisplayError GetPanelBrightness(int *level); 87 virtual DisplayError SetAutoRefresh(bool enable) { return kErrorNone; } 88 virtual DisplayError SetS3DMode(HWS3DMode s3d_mode); 89 virtual DisplayError SetScaleLutConfig(HWScaleLutInfo *lut_info); 90 virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes); 91 virtual DisplayError GetMixerAttributes(HWMixerAttributes *mixer_attributes); 92 virtual DisplayError DumpDebugData() { return kErrorNone; } 93 94 enum { 95 kHWEventVSync, 96 kHWEventBlank, 97 }; 98 99 static const int kMaxStringLength = 1024; 100 static const int kNumPhysicalDisplays = 2; 101 static const int kMaxSysfsCommandLength = 12; 102 103 DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target); 104 DisplayError SetStride(HWDeviceType device_type, LayerBufferFormat format, uint32_t width, 105 uint32_t *target); 106 DisplayError PopulateDisplayAttributes(); 107 void PopulateHWPanelInfo(); 108 void GetHWDisplayPortAndMode(); 109 void GetHWPanelMaxBrightness(); 110 void ResetDisplayParams(); 111 bool EnableHotPlugDetection(int enable); 112 void UpdateMixerAttributes(); 113 void InitializeConfigs(); 114 void SetBlending(const LayerBlending &source, sde_drm::DRMBlendType *target); 115 void SetRect(const LayerRect &source, sde_drm::DRMRect *target); 116 DisplayError DefaultCommit(HWLayers *hw_layers); 117 DisplayError AtomicCommit(HWLayers *hw_layers); 118 void SetupAtomic(HWLayers *hw_layers, bool validate); 119 120 HWResourceInfo hw_resource_ = {}; 121 HWPanelInfo hw_panel_info_ = {}; 122 HWInfoInterface *hw_info_intf_ = {}; 123 BufferSyncHandler *buffer_sync_handler_ = {}; 124 HWDeviceType device_type_ = {}; 125 const char *device_name_ = {}; 126 bool synchronous_commit_ = false; 127 HWDisplayAttributes display_attributes_ = {}; 128 HWMixerAttributes mixer_attributes_ = {}; 129 sde_drm::DRMManagerInterface *drm_mgr_intf_ = {}; 130 sde_drm::DRMAtomicReqInterface *drm_atomic_intf_ = {}; 131 sde_drm::DRMDisplayToken token_ = {}; 132 drmModeModeInfo current_mode_ = {}; 133 bool default_mode_ = false; 134 sde_drm::DRMConnectorInfo connector_info_ = {}; 135 std::string interface_str_ = "DSI"; 136 const char *kBrightnessNode = "/sys/class/backlight/panel0-backlight/brightness"; 137 }; 138 139 } // namespace sdm 140 141 #endif // __HW_DEVICE_DRM_H__ 142