sdm: Add support for SSPP Tonemapping

- Add interfaces in SDM to support SSPP Tonemapping.
- Get the SSPP tonemap caps from the drm interface and
  populate the SDM private interfaces.
- Add support to set the sspp tonemap config to drm planes.
- Handle Idle PowerCollapse event for SSPP luts.

Crs-fixed: 2200881
Change-Id: I38590915fd05e5cc77f38cd1df4724f43990045b
diff --git a/sdm/include/core/layer_stack.h b/sdm/include/core/layer_stack.h
index afa120e..f85a337 100644
--- a/sdm/include/core/layer_stack.h
+++ b/sdm/include/core/layer_stack.h
@@ -193,6 +193,10 @@
       uint32_t flip_buffer: 1;  //!< This flag will be set by SDM when the layer needs FBT flip
       uint32_t dest_tone_map : 1;  //!< This flag will be set by SDM when the layer needs
                                    //!< destination tone map
+      uint32_t src_3d_tone_map: 1;  //!< This flag will be set by SDM when the layer needs
+                                    //!< 3d tonemap
+      uint32_t src_1d_tone_map: 1;  //!< This flag will be set by SDM when the layer needs
+                                    //!< 1d tone map
     };
     uint32_t request_flags = 0;  //!< For initialization purpose only.
                                  //!< Shall not be refered directly.
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index c9b5782..7526544 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -32,6 +32,7 @@
 #include <map>
 #include <string>
 #include <bitset>
+#include <memory>
 
 namespace sdm {
 using std::string;
@@ -44,6 +45,11 @@
 #define MINOR 16
 #define SDEVERSION(major, minor, hw_rev) ((major) << MAJOR) | ((minor) << MINOR) | (hw_rev)
 
+// CSC Max Size
+#define MAX_CSC_MATRIX_COEFF_SIZE   9
+#define MAX_CSC_CLAMP_SIZE          6
+#define MAX_CSC_BIAS_SIZE           3
+
 enum HWDeviceType {
   kDevicePrimary,
   kDeviceHDMI,
@@ -131,6 +137,25 @@
   kHdrEOTFHLG = 0x8,
 };
 
+enum HWSrcTonemap {
+  kSrcTonemap1d,  // DMA
+  kSrcTonemap3d,  // VIG
+};
+
+enum HWToneMapLut {
+  kLutNone,     // No valid lut
+  kDma1dIgc,    // DMA IGC Lut
+  kDma1dGc,     // DMA GC Lut
+  kVig1dIgc,    // VIG IGC Lut
+  kVig3dGamut,  // 3D Gamut Lut
+};
+
+enum HWWriteOperation {
+  kNoOp,   // No-op, previously set config holds good
+  kSet,    // Sets the new config
+  kReset,  // Resets/Clears the previously set config
+};
+
 typedef std::map<HWSubBlockType, std::vector<LayerBufferFormat>> FormatsMap;
 typedef std::map<LayerBufferFormat, float> CompRatioMap;
 
@@ -158,6 +183,9 @@
   uint32_t id = 0;
   uint32_t master_pipe_id = 0;
   uint32_t max_rects = 1;
+  bool inverse_pma = 0;
+  uint32_t dgm_csc_version = 0;
+  std::map<HWToneMapLut, uint32_t> tm_lut_version_map = {};
 };
 
 struct HWRotatorInfo {
@@ -257,6 +285,7 @@
   HWQseedStepVersion pipe_qseed3_version = kQseed3v2;  // only valid when has_qseed3=true
   uint32_t min_prefill_lines = 0;
   InlineRotationVersion inrot_version = kInlineRotationNone;
+  std::bitset<32> src_tone_map = 0;  //!< Stores the bit mask of src tone map capability
 };
 
 struct HWSplitInfo {
@@ -447,6 +476,14 @@
   uint32_t src_height = 0;
 };
 
+struct HWCsc {
+  int64_t ctm_coeff[MAX_CSC_MATRIX_COEFF_SIZE] = {0};
+  uint32_t pre_bias[MAX_CSC_BIAS_SIZE] = {0};
+  uint32_t post_bias[MAX_CSC_BIAS_SIZE] = {0};
+  uint32_t pre_clamp[MAX_CSC_CLAMP_SIZE] = {0};
+  uint32_t post_clamp[MAX_CSC_CLAMP_SIZE] = {0};
+};
+
 struct HWScaleData {
   struct enable {
     uint8_t scale = 0;
@@ -495,6 +532,22 @@
   HWAVRModes mode = kContinuousMode;  // Specifies the AVR mode
 };
 
+struct HWPipeCscInfo {
+  HWWriteOperation op = kNoOp;
+  HWCsc csc = {};
+};
+
+struct HWPipeTonemapLutInfo {
+  HWWriteOperation op = kNoOp;
+  HWToneMapLut type = kLutNone;
+  std::shared_ptr<PPFeatureInfo> pay_load = nullptr;
+};
+
+struct HWPipeTonemapInversePma {
+  HWWriteOperation op = kNoOp;
+  bool inverse_pma = false;
+};
+
 struct HWPipeInfo {
   HWPipeInfo *pair = NULL;
   uint8_t rect = 255;
@@ -510,6 +563,9 @@
   uint8_t flags = 0;
   bool valid = false;
   bool is_virtual = 0;
+  HWPipeTonemapInversePma inverse_pma_info = {};
+  HWPipeCscInfo dgm_csc_info = {};
+  std::vector<HWPipeTonemapLutInfo> lut_info = {};
 };
 
 struct HWSolidfillStage {
diff --git a/sdm/include/private/resource_interface.h b/sdm/include/private/resource_interface.h
index 1e75298..b9d047c 100644
--- a/sdm/include/private/resource_interface.h
+++ b/sdm/include/private/resource_interface.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved.
+* Copyright (c) 2015 - 2018, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -33,7 +33,7 @@
 class ResourceInterface {
  public:
   enum ResourceCmd {
-    kCmdResetScalarLUT,
+    kCmdResetLUT,
     kCmdMax,
   };
 
diff --git a/sdm/include/utils/utils.h b/sdm/include/utils/utils.h
index b1c55c4..b10fd6b 100644
--- a/sdm/include/utils/utils.h
+++ b/sdm/include/utils/utils.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016 - 2017, The Linux Foundation. All rights reserved.
+* Copyright (c) 2016 - 2018, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -30,6 +30,8 @@
 #ifndef __UTILS_H__
 #define __UTILS_H__
 
+#include <cstring>
+
 namespace sdm {
 
 float gcd(float a, float b);
@@ -43,6 +45,11 @@
 
 DriverType GetDriverType();
 
+template<class T>
+bool SameConfig(T *t1, T *t2, unsigned int size) {
+  return !(std::memcmp(t1, t2, size));
+}
+
 }  // namespace sdm
 
 #endif  // __UTILS_H__