Merge tag 'DISPLAY.LA.3.0.r1-10700-KAILUA.0' of https://git.codelinaro.org/clo/la/platform/hardware/qcom/display into HEAD

DISPLAY.LA.3.0.r1-10700-KAILUA.0

* tag 'DISPLAY.LA.3.0.r1-10700-KAILUA.0' of https://git.codelinaro.org/clo/la/platform/hardware/qcom/display:
  init: disable BG blur feature for Crow
  sdm: remove vsync enable as part of commit cycle
  init: update target version for crow as v5.
  display: update SetColorModeWithRenderIntent for virtual display
  init: update target version for crow as v5.
  init: disable BG blur feature for Crow
  sdm: remove vsync enable as part of commit cycle
  composer: Add 100ms delay upon releasing of large comp hint
  dal: handle blend mode setting for lut update case
  composer: add check for color metadata length
  gralloc: handle unknown dataspace
  sdm: add content type transition for detail enhancer
  composer: Fix corruption issue due to wrong index
  sdm: handle concurrency between PostCommit and SetPanelBrightness
  composer: Don't allow power mode switch during TUI end
  sdm: Check panel HDR capability when declaring HDR capabilities to SF
  Revert "hwc_layer: Validate metadata"
  init: enable qsync based idle fallback for crow
  sdm: Make first power on synchronous for all physical displays.
  composer: Fix HandlePluggableDisplays scope call
  sde-drm: Parse ddr version
  composer: validate layer before mapping it to buffer
  dal: teardown cwb on display flush
  composer: do not allow TUI if target display is not powered on
  init: Add new target crow
  config: Set debug.sf.auto_latch_unsignaled to 0.
  sdm: pass display interface to dpps creation
  sdm: limit mutex lock scope to update refresh variable
  init: Set property for Crow
  sdm: support for layer_stack output buffer as shared_ptr

Change-Id: Ibe803492625943260135ac8b42defe9089fdd779
diff --git a/composer/QtiComposerClient.cpp b/composer/QtiComposerClient.cpp
index a8e4a9c..b772193 100644
--- a/composer/QtiComposerClient.cpp
+++ b/composer/QtiComposerClient.cpp
@@ -17,6 +17,13 @@
  * limitations under the License.
  */
 
+/*
+ * Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
+
 #include <vector>
 #include <string>
 
@@ -1989,7 +1996,7 @@
   for (const auto& m : metadata) {
     keys.push_back(static_cast<int32_t>(m.key));
     sizes_of_metablob_.push_back(m.blob.size());
-    for (uint8_t i = 0; i < m.blob.size(); i++) {
+    for (size_t i = 0; i < m.blob.size(); i++) {
       blob_of_data_.push_back(m.blob[i]);
     }
   }
@@ -2105,15 +2112,14 @@
 Error QtiComposerClient::CommandReader::lookupBuffer(BufferCache cache, uint32_t slot,
                                                      bool useCache, buffer_handle_t handle,
                                                      buffer_handle_t* outHandle) {
+  std::lock_guard<std::mutex> lock(mClient.mDisplayDataMutex);
+  BufferCacheEntry* entry;
+  Error error = lookupBufferCacheEntryLocked(cache, slot, &entry);
+  if (error != Error::NONE) {
+    return error;
+  }
+
   if (useCache) {
-    std::lock_guard<std::mutex> lock(mClient.mDisplayDataMutex);
-
-    BufferCacheEntry* entry;
-    Error error = lookupBufferCacheEntryLocked(cache, slot, &entry);
-    if (error != Error::NONE) {
-      return error;
-    }
-
     // input handle is ignored
     *outHandle = entry->getHandle();
   } else if (cache == BufferCache::LAYER_SIDEBAND_STREAMS) {
diff --git a/composer/hwc_display_builtin.cpp b/composer/hwc_display_builtin.cpp
index 35051f6..0047b1d 100644
--- a/composer/hwc_display_builtin.cpp
+++ b/composer/hwc_display_builtin.cpp
@@ -1386,10 +1386,6 @@
   HandleFrameOutput();
   PostCommitStitchLayers();
 
-  if (flush_ && layer_stack_.output_buffer == nullptr) {
-    display_intf_->FlushConcurrentWriteback();
-  }
-
   auto status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
 /*  display_intf_->GetConfig(&fixed_info);
   is_cmd_mode_ = fixed_info.is_cmdmode;
@@ -1585,11 +1581,15 @@
       }
     }
 
-    // For long term large composition hint, release the acquired handle after a consecutive number
-    // of basic frames to avoid resending hints in animation launch use cases and others.
-    num_basic_frames_++;
+    // For long term large composition hint, release the acquired handle after 100 milliseconds
+    // to avoid resending hints in animation launch use cases and others.
+    if (hint_release_start_time_ == 0) {
+      hint_release_start_time_ = systemTime(SYSTEM_TIME_MONOTONIC);
+    }
 
-    if (num_basic_frames_ >= active_refresh_rate_) {
+    nsecs_t current_time = systemTime(SYSTEM_TIME_MONOTONIC);
+    if (nanoseconds_to_milliseconds(current_time - hint_release_start_time_) >=
+        elapse_time_threshold_) {
       cpu_hint_->ReqHintRelease();
     }
     return;
@@ -1604,7 +1604,8 @@
     cpu_hint_->ReqHintsOffload(kPerfHintLargeCompCycle, 0);
   }
 
-  num_basic_frames_ = 0;
+  // Reset time when large composition hint is active
+  hint_release_start_time_ = 0;
 }
 
 void HWCDisplayBuiltIn::ReqPerfHintRelease() {
diff --git a/composer/hwc_display_builtin.h b/composer/hwc_display_builtin.h
index 1ddbb5a..5cd318b 100644
--- a/composer/hwc_display_builtin.h
+++ b/composer/hwc_display_builtin.h
@@ -228,8 +228,9 @@
 
   // Long term large composition hint
   int hwc_tid_ = 0;
-  uint32_t num_basic_frames_ = 0;
   uint32_t large_comp_hint_threshold_ = 0;
+  nsecs_t hint_release_start_time_ = 0;
+  nsecs_t elapse_time_threshold_ = 100;  // Time is in milliseconds
 };
 
 }  // namespace sdm
diff --git a/composer/hwc_display_pluggable.cpp b/composer/hwc_display_pluggable.cpp
index 53efc3c..5c970c6 100644
--- a/composer/hwc_display_pluggable.cpp
+++ b/composer/hwc_display_pluggable.cpp
@@ -181,10 +181,6 @@
   auto status = HWC2::Error::None;
 
   HandleFrameOutput();
-
-  if (flush_ && layer_stack_.output_buffer == nullptr) {
-    display_intf_->FlushConcurrentWriteback();
-  }
   status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
 
   return status;
diff --git a/composer/hwc_display_virtual.cpp b/composer/hwc_display_virtual.cpp
index 94d7ccf..23153ce 100644
--- a/composer/hwc_display_virtual.cpp
+++ b/composer/hwc_display_virtual.cpp
@@ -1,8 +1,6 @@
 /*
 * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
 *
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
@@ -29,41 +27,11 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
-* Changes from Qualcomm Innovation Center are provided under the following license:
-*
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted (subject to the limitations in the
-* disclaimer below) provided that the following conditions are met:
-*
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*
-*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
-* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
-* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+/* Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
 
 #include <utils/constants.h>
 #include <utils/debug.h>
@@ -123,7 +91,7 @@
     if (output_handle_) {
       BufferInfo buffer_info;
       const native_handle_t *output_handle =
-          reinterpret_cast<const native_handle_t *>(output_buffer_.buffer_id);
+          reinterpret_cast<const native_handle_t *>(output_buffer_->buffer_id);
       void *base_ptr = NULL;
       int error = buffer_allocator_->MapBuffer(output_handle, nullptr, &base_ptr);
       if (error != 0) {
@@ -183,16 +151,16 @@
       return HWC2::Error::BadParameter;
     }
 
-    output_buffer_.flags.secure = 0;
-    output_buffer_.flags.video = 0;
-    output_buffer_.buffer_id = reinterpret_cast<uint64_t>(output_handle);
-    output_buffer_.format = new_sdm_format;
-    output_buffer_.color_metadata = color_metadata;
+    output_buffer_->flags.secure = 0;
+    output_buffer_->flags.video = 0;
+    output_buffer_->buffer_id = reinterpret_cast<uint64_t>(output_handle);
+    output_buffer_->format = new_sdm_format;
+    output_buffer_->color_metadata = color_metadata;
     output_handle_ = output_handle;
 
     // TZ Protected Buffer - L1
     if (output_handle_flags & qtigralloc::PRIV_FLAGS_SECURE_BUFFER) {
-      output_buffer_.flags.secure = 1;
+      output_buffer_->flags.secure = 1;
     }
 
     // ToDo: Need to extend for non-RGB formats
@@ -200,12 +168,12 @@
     uint32_t width = 0;
     buffer_allocator_->GetFd((void *)output_handle, fd);
     buffer_allocator_->GetWidth((void *)output_handle, width);
-    output_buffer_.planes[0].fd = fd;
-    output_buffer_.planes[0].offset = 0;
-    output_buffer_.planes[0].stride = width;
+    output_buffer_->planes[0].fd = fd;
+    output_buffer_->planes[0].offset = 0;
+    output_buffer_->planes[0].stride = width;
   }
 
-  output_buffer_.acquire_fence = release_fence;
+  output_buffer_->acquire_fence = release_fence;
 
   return HWC2::Error::None;
 }
@@ -233,4 +201,8 @@
   return HWC2::Error::None;
 }
 
+HWC2::Error HWCDisplayVirtual::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
+  return HWC2::Error::None;
+}
+
 }  // namespace sdm
diff --git a/composer/hwc_display_virtual.h b/composer/hwc_display_virtual.h
index fb15e41..a7db0ed 100644
--- a/composer/hwc_display_virtual.h
+++ b/composer/hwc_display_virtual.h
@@ -27,41 +27,11 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
-* Changes from Qualcomm Innovation Center are provided under the following license:
-*
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted (subject to the limitations in the
-* disclaimer below) provided that the following conditions are met:
-*
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*
-*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
-* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
-* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+/* Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
 
 #ifndef __HWC_DISPLAY_VIRTUAL_H__
 #define __HWC_DISPLAY_VIRTUAL_H__
@@ -81,6 +51,7 @@
                                          int32_t format, CwbConfig &cwb_config);
   virtual HWC2::Error GetDisplayType(int32_t *out_type);
   virtual HWC2::Error SetColorMode(ColorMode mode);
+  virtual HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
   virtual HWC2::Error SetOutputBuffer(buffer_handle_t buf, shared_ptr<Fence> release_fence);
   virtual HWC2::Error DumpVDSBuffer();
   bool NeedsGPUBypass();
@@ -95,7 +66,7 @@
  protected:
   uint32_t width_ = 0;
   uint32_t height_ = 0;
-  LayerBuffer output_buffer_ = {};
+  std::shared_ptr<LayerBuffer> output_buffer_ = std::make_shared<LayerBuffer>();
   const native_handle_t *output_handle_ = nullptr;
 
  private:
diff --git a/composer/hwc_display_virtual_dpu.cpp b/composer/hwc_display_virtual_dpu.cpp
index de3e4ed..681df00 100644
--- a/composer/hwc_display_virtual_dpu.cpp
+++ b/composer/hwc_display_virtual_dpu.cpp
@@ -27,6 +27,12 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/* Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
+
 #include <hwc_display_virtual_dpu.h>
 
 #define __CLASS__ "HWCDisplayVirtualDPU"
@@ -121,10 +127,10 @@
       }
     }
 
-    output_buffer_.width = UINT32(new_aligned_w);
-    output_buffer_.height = UINT32(new_aligned_h);
-    output_buffer_.unaligned_width = UINT32(new_width);
-    output_buffer_.unaligned_height = UINT32(new_height);
+    output_buffer_->width = UINT32(new_aligned_w);
+    output_buffer_->height = UINT32(new_aligned_h);
+    output_buffer_->unaligned_width = UINT32(new_width);
+    output_buffer_->unaligned_height = UINT32(new_height);
   }
 
   return HWC2::Error::None;
@@ -148,9 +154,9 @@
     layer->flags.updating = true;
   }
 
-  layer_stack_.output_buffer = &output_buffer_;
+  layer_stack_.output_buffer = output_buffer_;
   // If Output buffer of Virtual Display is not secure, set SKIP flag on the secure layers.
-  if (!output_buffer_.flags.secure && layer_stack_.flags.secure_present) {
+  if (!output_buffer_->flags.secure && layer_stack_.flags.secure_present) {
     for (auto hwc_layer : layer_set_) {
       Layer *layer = hwc_layer->GetSDMLayer();
       if (layer->input_buffer.flags.secure) {
@@ -178,7 +184,7 @@
 HWC2::Error HWCDisplayVirtualDPU::Present(shared_ptr<Fence> *out_retire_fence) {
   auto status = HWC2::Error::None;
 
-  if (!output_buffer_.buffer_id) {
+  if (!output_buffer_->buffer_id) {
     return HWC2::Error::NoResources;
   }
 
@@ -186,7 +192,7 @@
     return HWC2::Error::None;
   }
 
-  layer_stack_.output_buffer = &output_buffer_;
+  layer_stack_.output_buffer = output_buffer_;
 
   status = HWCDisplay::CommitLayerStack();
   if (status != HWC2::Error::None) {
@@ -217,7 +223,7 @@
                                                   uint32_t *out_num_requests, bool *needs_commit) {
   DTRACE_SCOPED();
 
-  layer_stack_.output_buffer = &output_buffer_;
+  layer_stack_.output_buffer = output_buffer_;
   auto status = HWCDisplay::CommitOrPrepare(validate_only, out_retire_fence, out_num_types,
                                             out_num_requests, needs_commit);
   return status;
diff --git a/composer/hwc_display_virtual_gpu.cpp b/composer/hwc_display_virtual_gpu.cpp
index e8b897f..89e5182 100644
--- a/composer/hwc_display_virtual_gpu.cpp
+++ b/composer/hwc_display_virtual_gpu.cpp
@@ -27,8 +27,7 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Changes from Qualcomm Innovation Center are provided under the following license:
+/* Changes from Qualcomm Innovation Center are provided under the following license:
  *
  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
@@ -144,17 +143,17 @@
   }
 
   native_handle_t *hnd = const_cast<native_handle_t *>(buf);
-  buffer_allocator_->GetWidth(hnd, output_buffer_.width);
-  buffer_allocator_->GetHeight(hnd, output_buffer_.height);
-  buffer_allocator_->GetUnalignedWidth(hnd, output_buffer_.unaligned_width);
-  buffer_allocator_->GetUnalignedHeight(hnd, output_buffer_.unaligned_height);
+  buffer_allocator_->GetWidth(hnd, output_buffer_->width);
+  buffer_allocator_->GetHeight(hnd, output_buffer_->height);
+  buffer_allocator_->GetUnalignedWidth(hnd, output_buffer_->unaligned_width);
+  buffer_allocator_->GetUnalignedHeight(hnd, output_buffer_->unaligned_height);
 
   // Update active dimensions.
   if (qtigralloc::getMetadataState(hnd, android::gralloc4::MetadataType_Crop.value)) {
     int32_t slice_width = 0, slice_height = 0;
     if (!buffer_allocator_->GetBufferGeometry(hnd, slice_width, slice_height)) {
-      output_buffer_.unaligned_width = slice_width;
-      output_buffer_.unaligned_height = slice_height;
+      output_buffer_->unaligned_width = slice_width;
+      output_buffer_->unaligned_height = slice_height;
       // Update buffer width and height.
       int new_aligned_w = 0;
       int new_aligned_h = 0;
@@ -163,8 +162,8 @@
       buffer_allocator_->GetAlignedWidthAndHeight(INT(slice_width), INT(slice_height),
                                                   output_handle_format, 0, &new_aligned_w,
                                                   &new_aligned_h);
-      output_buffer_.width = UINT32(new_aligned_w);
-      output_buffer_.height = UINT32(new_aligned_h);
+      output_buffer_->width = UINT32(new_aligned_w);
+      output_buffer_->height = UINT32(new_aligned_h);
       color_convert_task_.PerformTask(ColorConvertTaskCode::kCodeReset, nullptr);
     }
   }
@@ -177,7 +176,7 @@
 
   auto status = HWC2::Error::None;
 
-  if (!output_buffer_.buffer_id) {
+  if (!output_buffer_->buffer_id) {
     return HWC2::Error::NoResources;
   }
 
@@ -185,7 +184,7 @@
     return status;
   }
 
-  layer_stack_.output_buffer = &output_buffer_;
+  layer_stack_.output_buffer = output_buffer_;
 
   // Ensure that blit is initialized.
   // GPU context gets in secure or non-secure mode depending on output buffer provided.
@@ -206,10 +205,10 @@
   LayerBuffer &input_buffer = sdm_layer->input_buffer;
   ctx.src_hnd = reinterpret_cast<const native_handle_t *>(input_buffer.buffer_id);
   ctx.dst_hnd = reinterpret_cast<const native_handle_t *>(output_handle_);
-  ctx.dst_rect = {0, 0, FLOAT(output_buffer_.unaligned_width),
-                  FLOAT(output_buffer_.unaligned_height)};
+  ctx.dst_rect = {0, 0, FLOAT(output_buffer_->unaligned_width),
+                  FLOAT(output_buffer_->unaligned_height)};
   ctx.src_acquire_fence = input_buffer.acquire_fence;
-  ctx.dst_acquire_fence = output_buffer_.acquire_fence;
+  ctx.dst_acquire_fence = output_buffer_->acquire_fence;
 
   color_convert_task_.PerformTask(ColorConvertTaskCode::kCodeBlit, &ctx);
 
@@ -225,7 +224,7 @@
                                   SyncTask<ColorConvertTaskCode>::TaskContext *task_context) {
   switch (task_code) {
     case ColorConvertTaskCode::kCodeGetInstance: {
-        gl_color_convert_ = GLColorConvert::GetInstance(kTargetYUV, output_buffer_.flags.secure);
+        gl_color_convert_ = GLColorConvert::GetInstance(kTargetYUV, output_buffer_->flags.secure);
       }
       break;
     case ColorConvertTaskCode::kCodeBlit: {
diff --git a/composer/hwc_layers.cpp b/composer/hwc_layers.cpp
index 42bc42f..32be96f 100644
--- a/composer/hwc_layers.cpp
+++ b/composer/hwc_layers.cpp
@@ -24,7 +24,7 @@
 /*
 * Changes from Qualcomm Innovation Center are provided under the following license:
 *
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted (subject to the limitations in the
@@ -1079,9 +1079,6 @@
   if (gralloc::GetMetaDataValue(handle, qtigralloc::MetadataType_LinearFormat.value,
                                 &linear_format) == gralloc::Error::NONE) {
     layer_buffer->format = GetSDMFormat(INT32(linear_format), 0);
-    if (layer_buffer->format == kFormatInvalid) {
-      return kErrorNotSupported;
-    }
   }
 
   if ((interlace != layer_buffer->flags.interlace) || (frame_rate != layer->frame_rate)) {
@@ -1102,9 +1099,6 @@
       gralloc::Error::NONE) {
     // Only copy top layer for now as only top field for interlaced is used
     GetUBWCStatsFromMetaData(&cr_stats[0], &(layer_buffer->ubwc_crstats[0]));
-    if (cr_stats[0].version < 0 || cr_stats[0].version >= UBWC_MAX_VERSION) {
-      return kErrorNotSupported;
-    }
   }
 
   uint32_t single_buffer = 0;
@@ -1267,6 +1261,7 @@
         layer_->update_mask.set(kMetadataUpdate);
       }
       if (new_metadata.dynamicMetaDataValid &&
+          new_metadata.dynamicMetaDataLen < HDR_DYNAMIC_META_DATA_SZ &&
           ((new_metadata.dynamicMetaDataLen != layer_buffer->color_metadata.dynamicMetaDataLen) ||
             !SameConfig(layer_buffer->color_metadata.dynamicMetaDataPayload,
                         new_metadata.dynamicMetaDataPayload, new_metadata.dynamicMetaDataLen))) {
diff --git a/composer/hwc_session.cpp b/composer/hwc_session.cpp
index d719b35..5d99958 100644
--- a/composer/hwc_session.cpp
+++ b/composer/hwc_session.cpp
@@ -1208,6 +1208,15 @@
     }
   }
 
+  if (tui_start_success_ && is_builtin && is_power_off) {
+    DLOGI("TUI session in progress, defer power state change");
+    SCOPE_LOCK(locker_[display]);
+    if (hwc_display_[display]) {
+      hwc_display_[display]->SetPendingPowerMode(mode);
+      return HWC2_ERROR_NONE;
+    }
+  }
+
   if (secure_session_active_ && is_builtin && is_power_off) {
     if (GetActiveBuiltinDisplay() != HWCCallbacks::kNumDisplays) {
       DLOGI("Secure session in progress, defer power state change");
@@ -3025,33 +3034,30 @@
 }
 
 int HWCSession::HandlePluggableDisplays(bool delay_hotplug) {
+  SCOPE_LOCK(pluggable_handler_lock_);
   HWDisplaysInfo hw_displays_info = {};
-  {
-    SCOPE_LOCK(pluggable_handler_lock_);
+  hwc2_display_t virtual_display_index =
+      (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
+  std::bitset<kSecureMax> secure_sessions = 0;
 
-    hwc2_display_t virtual_display_index =
-        (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
-    std::bitset<kSecureMax> secure_sessions = 0;
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
+    Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
+    hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
+  }
 
-    hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
-    if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
-      Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
-      hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
-    }
+  if (secure_sessions.any() || hwc_display_[virtual_display_index]) {
+    // Defer hotplug handling.
+    DLOGI("Marking hotplug pending...");
+    pending_hotplug_event_ = kHotPlugEvent;
+    return -EAGAIN;
+  }
 
-    if (secure_sessions.any() || hwc_display_[virtual_display_index]) {
-      // Defer hotplug handling.
-      DLOGI("Marking hotplug pending...");
-      pending_hotplug_event_ = kHotPlugEvent;
-      return -EAGAIN;
-    }
-
-    DLOGI("Handling hotplug...");
-    DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info);
-    if (error != kErrorNone) {
-      DLOGE("Failed to get connected display list. Error = %d", error);
-      return -EINVAL;
-    }
+  DLOGI("Handling hotplug...");
+  DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info);
+  if (error != kErrorNone) {
+    DLOGE("Failed to get connected display list. Error = %d", error);
+    return -EINVAL;
   }
 
   int status = HandleDisconnectedDisplays(&hw_displays_info);
@@ -4162,10 +4168,12 @@
   }
 
   std::bitset<kSecureMax> secure_sessions = 0;
+  HWC2::PowerMode current_power_mode = HWC2::PowerMode::Off;
   {
     SEQUENCE_WAIT_SCOPE_LOCK(locker_[target_display]);
     if (hwc_display_[target_display]) {
       hwc_display_[target_display]->GetActiveSecureSession(&secure_sessions);
+      current_power_mode = hwc_display_[target_display]->GetCurrentPowerMode();
     }
   }
 
@@ -4174,6 +4182,11 @@
     return -ENOTSUP;
   }
 
+  if (current_power_mode != HWC2::PowerMode::On) {
+    DLOGW("TUI session not allowed as target display is not powered On");
+    return -ENOTSUP;
+  }
+
   std::vector<DisplayMapInfo> map_info = {map_info_primary_};
   std::copy(map_info_builtin_.begin(), map_info_builtin_.end(), std::back_inserter(map_info));
   std::copy(map_info_pluggable_.begin(), map_info_pluggable_.end(), std::back_inserter(map_info));
@@ -4267,6 +4280,7 @@
     }
   }
 
+  tui_start_success_ = true;
   return 0;
 }
 android::status_t HWCSession::TUITransitionEnd(int disp_id) {
@@ -4291,10 +4305,12 @@
     if (hwc_display_[target_display]) {
       if (hwc_display_[target_display]->HandleSecureEvent(kTUITransitionEnd, &needs_refresh,
                                                           false) != kErrorNone) {
+        tui_start_success_ = false;
         return -EINVAL;
       }
     } else {
       DLOGW("Target display %d is not ready", disp_id);
+      tui_start_success_ = false;
       return -ENODEV;
     }
   }
@@ -4307,6 +4323,7 @@
         DLOGE("Device unassign failed with error %d", ret);
       }
       TUITransitionUnPrepare(disp_id);
+      tui_start_success_ = false;
       return 0;
     }
   }
@@ -4373,6 +4390,7 @@
   }
   // Reset tui session state variable.
   DLOGI("End of TUI session on display %d", disp_id);
+  tui_start_success_ = false;
   return 0;
 }
 
diff --git a/composer/hwc_session.h b/composer/hwc_session.h
index 8c32a01..c4edded 100644
--- a/composer/hwc_session.h
+++ b/composer/hwc_session.h
@@ -666,6 +666,7 @@
   bool async_vds_creation_ = false;
   std::bitset<HWCCallbacks::kNumDisplays> display_ready_;
   bool secure_session_active_ = false;
+  bool tui_start_success_ = false;
   bool is_client_up_ = false;
   std::shared_ptr<IPCIntf> ipc_intf_ = nullptr;
   bool primary_pending_ = true;
diff --git a/config/display-product.mk b/config/display-product.mk
index 169a954..74f0db8 100644
--- a/config/display-product.mk
+++ b/config/display-product.mk
@@ -56,6 +56,7 @@
     debug.sf.hw=0 \
     debug.egl.hw=0 \
     debug.sf.latch_unsignaled=1 \
+    debug.sf.auto_latch_unsignaled=0 \
     debug.mdpcomp.logs=0 \
     vendor.gralloc.disable_ubwc=0 \
     vendor.gralloc.enable_logs=0 \
@@ -124,7 +125,13 @@
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.force_hwc_copy_for_virtual_displays=true
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.max_frame_buffer_acquired_buffers=3
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.max_virtual_display_dimension=4096
+
+#BG blur support
+ifeq ($(TARGET_BOARD_PLATFORM),kalama)
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.supports_background_blur=1
+else
+PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.supports_background_blur=0
+endif
 
 ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
 # Recovery is enabled, logging is enabled
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index d81fa5a..b0d08fb 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -1470,7 +1470,10 @@
       if (android::gralloc4::decodeDataspace(in, &dataspace)) {
         return Error::UNSUPPORTED;
       }
-      dataspaceToColorMetadata(dataspace, &metadata->color);
+      // Avoid setting standard dataspace flag for unknown/invalid dataspace
+      if (dataspaceToColorMetadata(dataspace, &metadata->color) != Error::NONE) {
+        return Error::NONE;
+      }
       break;
     case (int64_t)StandardMetadataType::BLEND_MODE:
       BlendMode mode;
diff --git a/init/init.qti.display_boot.sh b/init/init.qti.display_boot.sh
index 35d8cb6..dbc9db3 100644
--- a/init/init.qti.display_boot.sh
+++ b/init/init.qti.display_boot.sh
@@ -90,6 +90,29 @@
         ;;
     esac
     ;;
+    "crow")
+    #SOC ID for Crow is 608
+    case "$soc_hwid" in
+       608)
+        #SOC ID for Crow is 608
+        setprop vendor.display.enable_fb_scaling 0
+        setprop vendor.display.target.version 5
+        setprop vendor.gralloc.use_dma_buf_heaps 1
+        setprop vendor.display.enable_posted_start_dyn 2
+        setprop vendor.display.enable_allow_idle_fallback 1
+        setprop vendor.display.enable_perf_hint_large_comp_cycle 1
+        setprop vendor.display.enable_rotator_ui 1
+        setprop vendor.display.enable_spec_fence 1
+        setprop vendor.display.thermal.version 1
+        setprop vendor.display.enable_rc_support 1
+        setprop vendor.display.enable_latch_media_content 1
+        setprop vendor.display.enable_inline_writeback 0
+        setprop vendor.display.timed_render_enable 1
+        setprop debug.sf.disable_client_composition_cache 0
+        setprop vendor.display.enable_qsync_idle 1
+        ;;
+    esac
+    ;;
     "taro")
     #Set property to differentiate Waipio
     #SOC ID for Waipio is 457
diff --git a/libdrmutils/drm_interface.h b/libdrmutils/drm_interface.h
index a987365..ce31f82 100644
--- a/libdrmutils/drm_interface.h
+++ b/libdrmutils/drm_interface.h
@@ -30,37 +30,8 @@
 /*
 * Changes from Qualcomm Innovation Center are provided under the following license:
 *
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted (subject to the limitations in the
-* disclaimer below) provided that the following conditions are met:
-*
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*
-*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
-* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
-* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+* SPDX-License-Identifier: BSD-3-Clause-Clear
 */
 
 #ifndef __DRM_INTERFACE_H__
@@ -680,6 +651,12 @@
   kInlineRotationV2,
 };
 
+/* DDR Version */
+enum struct DDRVersion {
+  kDDRVersion4,
+  kDDRVersion5,
+};
+
 /* Type for panel feature resource reservation info */
 typedef std::tuple<std::string, int32_t, int8_t> FetchResource;
 typedef std::vector<FetchResource> FetchResourceList;
@@ -734,6 +711,7 @@
   bool skip_inline_rot_threshold = false;
   bool has_noise_layer = false;
   uint32_t dsc_block_count = 0;
+  DDRVersion ddr_version = DDRVersion::kDDRVersion5;
 };
 
 enum struct DRMPlaneType {
diff --git a/sde-drm/drm_crtc.cpp b/sde-drm/drm_crtc.cpp
index f6a0341..dc4230f 100755
--- a/sde-drm/drm_crtc.cpp
+++ b/sde-drm/drm_crtc.cpp
@@ -27,6 +27,13 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+/*
+* Changes from Qualcomm Innovation Center are provided under the following license:
+*
+* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+* SPDX-License-Identifier: BSD-3-Clause-Clear
+*/
+
 #include <stdint.h>
 #include <stdlib.h>
 #include <drm.h>
@@ -454,6 +461,7 @@
   string dspp_count = "dspp_count=";
   string skip_inline_rot_threshold="skip_inline_rot_threshold=";
   string dsc_block_count = "dsc_block_count=";
+  string ddr_version = "DDR version=";
 
   while (std::getline(stream, line)) {
     if (line.find(max_blendstages) != string::npos) {
@@ -584,6 +592,12 @@
         std::stoi(string(line, skip_inline_rot_threshold.length()));
     } else if (line.find(dsc_block_count) != string::npos) {
       crtc_info_.dsc_block_count = std::stoi(string(line, dsc_block_count.length()));
+    } else if (line.find(ddr_version) != string::npos) {
+      if (string(line, ddr_version.length()) == "DDR4") {
+        crtc_info_.ddr_version = DDRVersion::kDDRVersion4;
+      } else if(string(line, ddr_version.length()) == "DDR5") {
+        crtc_info_.ddr_version = DDRVersion::kDDRVersion5;
+        }
     }
   }
   drmModeFreePropertyBlob(blob);
diff --git a/sdm/include/core/dpps_interface.h b/sdm/include/core/dpps_interface.h
index af5dc81..2d68f08 100644
--- a/sdm/include/core/dpps_interface.h
+++ b/sdm/include/core/dpps_interface.h
@@ -27,13 +27,18 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+/*
+* Changes from Qualcomm Innovation Center are provided under the following license:
+*
+* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+* SPDX-License-Identifier: BSD-3-Clause-Clear
+*/
+
 #ifndef __DPPS_INTERFACE_H__
 #define __DPPS_INTERFACE_H__
 
 #include <core/sdm_types.h>
-#if !defined(LINUX_COMPILE) && !defined(WIN32) && !defined(_WIN64) && !defined(__APPLE__)
 #include <core/display_interface.h>
-#endif
 #include <color_metadata.h>
 
 #include <string>
@@ -95,7 +100,8 @@
 
 class DppsInterface {
  public:
-  virtual int Init(DppsPropIntf* intf, const std::string &panel_name) = 0;
+  virtual int Init(DppsPropIntf *intf, const std::string &panel_name,
+                   DisplayInterface *display_intf) = 0;
   virtual int Deinit() = 0;
   virtual int DppsNotifyOps(enum DppsNotifyOps op, void *payload, size_t size) = 0;
 
@@ -105,9 +111,11 @@
 
 class DppsDummyImpl : public DppsInterface {
  public:
-  int Init(DppsPropIntf* intf, const std::string &panel_name) {
+  int Init(DppsPropIntf *intf, const std::string &panel_name,
+           DisplayInterface *display_intf = nullptr) {
     (void)intf;
     (void)panel_name;
+    (void)display_intf;
     return 0;
   }
   int Deinit() {
diff --git a/sdm/include/core/layer_stack.h b/sdm/include/core/layer_stack.h
index 5995739..71452ed 100644
--- a/sdm/include/core/layer_stack.h
+++ b/sdm/include/core/layer_stack.h
@@ -22,41 +22,11 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
-* Changes from Qualcomm Innovation Center are provided under the following license:
-*
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted (subject to the limitations in the
-* disclaimer below) provided that the following conditions are met:
-*
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*
-*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
-* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
-* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+/* Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
 
 /*! @file layer_stack.h
   @brief File for display layer stack structure which represents a drawing buffer.
@@ -571,7 +541,8 @@
                                        //!< descriptor.
                                        //!< NOTE: This field applies to a physical display only.
 
-  LayerBuffer *output_buffer = NULL;   //!< Pointer to the buffer where composed buffer would be
+  std::shared_ptr<LayerBuffer> output_buffer = nullptr;
+                                       //!< Pointer to the buffer where composed buffer would be
                                        //!< rendered for virtual displays.
                                        //!< NOTE: This field applies to a virtual display only.
 
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index cc4b47a..4376199 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -22,41 +22,11 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
-* Changes from Qualcomm Innovation Center are provided under the following license:
-*
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted (subject to the limitations in the
-* disclaimer below) provided that the following conditions are met:
-*
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*
-*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
-* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
-* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+/* Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
 
 #ifndef __HW_INFO_TYPES_H__
 #define __HW_INFO_TYPES_H__
@@ -337,6 +307,11 @@
   kInlineRotationV2,
 };
 
+enum DDRVersion {
+  kDDRVersion4,
+  kDDRVersion5,
+};
+
 struct InlineRotationInfo {
   InlineRotationVersion inrot_version = kInlineRotationNone;
   std::vector<LayerBufferFormat> inrot_fmts_supported;
@@ -423,6 +398,7 @@
   bool skip_inline_rot_threshold = false;
   bool has_noise_layer = false;
   uint32_t dsc_block_count = 0;
+  DDRVersion ddr_version = kDDRVersion5;
 };
 
 struct HWSplitInfo {
@@ -908,7 +884,8 @@
   shared_ptr<Fence> retire_fence = nullptr;  // Retire fence for current draw cycle.
   LayerStackFlags flags;               //!< Flags associated with this layer set.
   PrimariesTransfer blend_cs = {};     //!< o/p - Blending color space of the frame, updated by SDM
-  LayerBuffer *output_buffer = NULL;   //!< Pointer to the buffer where composed buffer would be
+  std::shared_ptr<LayerBuffer> output_buffer = nullptr;
+                                       //!< Pointer to the buffer where composed buffer would be
                                        //!< rendered for virtual displays.
                                        //!< NOTE: This field applies to a virtual display only.
   uint32_t output_fb_id = 0;           //!< FB ID of the output buffer of virtual display
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 54996f2..331a0cc 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -2101,7 +2101,7 @@
     return os.str();
   }
 
-  LayerBuffer *out_buffer = disp_layer_stack_.info.output_buffer;
+  std::shared_ptr<LayerBuffer> out_buffer = disp_layer_stack_.info.output_buffer;
   if (out_buffer) {
     os << "\n Output buffer res: " << out_buffer->width << "x" << out_buffer->height
        << " format: " << GetFormatString(out_buffer->format);
@@ -3883,7 +3883,7 @@
 
 DisplayError DisplayBase::GetOutputBufferAcquireFence(shared_ptr<Fence> *out_fence) {
   ClientLock lock(disp_mutex_);
-  LayerBuffer *out_buffer = disp_layer_stack_.info.output_buffer;
+  std::shared_ptr<LayerBuffer> out_buffer = disp_layer_stack_.info.output_buffer;
   if (out_buffer == nullptr) {
     return kErrorNotSupported;
   }
@@ -4067,6 +4067,19 @@
         }
       }
 
+      switch (de_tuning_cfg_data->params.content_type) {
+        case kDeContentTypeVideo:
+          de_data.content_type = kContentTypeVideo;
+          break;
+        case kDeContentTypeGraphics:
+          de_data.content_type = kContentTypeGraphics;
+          break;
+        case kDeContentTypeUnknown:
+        default:
+          de_data.content_type = kContentTypeUnknown;
+          break;
+      }
+
       if (de_tuning_cfg_data->params.flags & kDeTuningFlagDeBlend) {
         de_data.override_flags |= kOverrideDEBlend;
         de_data.de_blend = de_tuning_cfg_data->params.de_blend;
@@ -4179,9 +4192,11 @@
 
 /* this func is called by DC dimming feature only after PCC updates */
 void DisplayBase::ScreenRefresh() {
-  ClientLock lock(disp_mutex_);
-  /* do not skip validate */
-  validated_ = false;
+  {
+    ClientLock lock(disp_mutex_);
+    /* do not skip validate */
+    validated_ = false;
+  }
   event_handler_->Refresh();
 }
 
diff --git a/sdm/libs/core/display_builtin.cpp b/sdm/libs/core/display_builtin.cpp
index 6a074a9..af0a67c 100644
--- a/sdm/libs/core/display_builtin.cpp
+++ b/sdm/libs/core/display_builtin.cpp
@@ -673,15 +673,6 @@
     }
   }
 
-  if (vsync_enable_) {
-    DTRACE_BEGIN("RegisterVsync");
-    // wait for previous frame's retire fence to signal.
-    Fence::Wait(retire_fence_);
-
-    // Register for vsync and then commit the frame.
-    hw_events_intf_->SetEventState(HWEvent::VSYNC, true);
-    DTRACE_END();
-  }
   // effectively drmModeAtomicAddProperty for SDE_DSPP_HIST_IRQ_V1
   if (histogramSetup) {
     SetDppsFeatureLocked(&histogramIRQ, sizeof(histogramIRQ));
@@ -949,11 +940,14 @@
 
 DisplayError DisplayBuiltIn::PostCommit(HWLayersInfo *hw_layers_info) {
   DisplayBase::PostCommit(hw_layers_info);
-
-  if (pending_brightness_) {
-    Fence::Wait(retire_fence_);
-    SetPanelBrightness(cached_brightness_);
-    pending_brightness_ = false;
+  // Mutex scope
+  {
+    lock_guard<recursive_mutex> obj(brightness_lock_);
+    if (pending_brightness_) {
+      Fence::Wait(retire_fence_);
+      SetPanelBrightness(cached_brightness_);
+      pending_brightness_ = false;
+    }
   }
 
   if (commit_event_enabled_) {
@@ -990,7 +984,7 @@
     dpps_pu_nofiy_pending_ = false;
     dpps_pu_lock_.Broadcast();
   }
-  dpps_info_.Init(this, hw_panel_info_.panel_name);
+  dpps_info_.Init(this, hw_panel_info_.panel_name, this);
 
   if (demuratn_)
     EnableDemuraTn(true);
@@ -1776,7 +1770,7 @@
     return os.str();
   }
 
-  LayerBuffer *out_buffer = disp_layer_stack_.info.output_buffer;
+  std::shared_ptr<LayerBuffer> out_buffer = disp_layer_stack_.info.output_buffer;
   if (out_buffer) {
     os << "\n Output buffer res: " << out_buffer->width << "x" << out_buffer->height
        << " format: " << GetFormatString(out_buffer->format);
@@ -1927,12 +1921,13 @@
 DppsInterface* DppsInfo::dpps_intf_ = NULL;
 std::vector<int32_t> DppsInfo::display_id_ = {};
 
-void DppsInfo::Init(DppsPropIntf *intf, const std::string &panel_name) {
+void DppsInfo::Init(DppsPropIntf *intf, const std::string &panel_name,
+                    DisplayInterface *display_intf) {
   std::lock_guard<std::mutex> guard(lock_);
   int error = 0;
 
-  if (!intf) {
-    DLOGE("Invalid intf is null");
+  if (!intf || !display_intf) {
+    DLOGE("Invalid intf %pK display_intf %pK", intf, display_intf);
     return;
   }
 
@@ -1967,7 +1962,7 @@
       goto exit;
     }
   }
-  error = dpps_intf_->Init(intf, panel_name);
+  error = dpps_intf_->Init(intf, panel_name, display_intf);
   if (error) {
     DLOGE("DPPS Interface init failure with err %d", error);
     goto exit;
@@ -2532,10 +2527,10 @@
   // Checking library support for HDR10+
   comp_manager_->GetHDRCapability(&hdr_plus_supported, &dolby_vision_supported);
 
-  fixed_info->hdr_supported = hw_resource_info.has_hdr;
+  fixed_info->hdr_supported = hw_resource_info.has_hdr && hw_panel_info_.hdr_enabled;
   // Built-in displays always support HDR10+ when the target supports HDR
-  fixed_info->hdr_plus_supported = hw_resource_info.has_hdr && hdr_plus_supported;
-  fixed_info->dolby_vision_supported = hw_resource_info.has_hdr && dolby_vision_supported;
+  fixed_info->hdr_plus_supported = fixed_info->hdr_supported && hdr_plus_supported;
+  fixed_info->dolby_vision_supported = fixed_info->hdr_supported && dolby_vision_supported;
   // Populate luminance values only if hdr will be supported on that display
   fixed_info->max_luminance = fixed_info->hdr_supported ? hw_panel_info_.peak_luminance: 0;
   fixed_info->average_luminance = fixed_info->hdr_supported ? hw_panel_info_.average_luminance : 0;
diff --git a/sdm/libs/core/display_builtin.h b/sdm/libs/core/display_builtin.h
index 758e8db..b2fe25c 100644
--- a/sdm/libs/core/display_builtin.h
+++ b/sdm/libs/core/display_builtin.h
@@ -94,7 +94,7 @@
 
 class DppsInfo {
  public:
-  void Init(DppsPropIntf *intf, const std::string &panel_name);
+  void Init(DppsPropIntf *intf, const std::string &panel_name, DisplayInterface *display_intf);
   void Deinit();
   void DppsNotifyOps(enum DppsNotifyOps op, void *payload, size_t size);
   bool disable_pu_ = false;
diff --git a/sdm/libs/dal/hw_device_drm.cpp b/sdm/libs/dal/hw_device_drm.cpp
index b5f9987..8ce6a1d 100644
--- a/sdm/libs/dal/hw_device_drm.cpp
+++ b/sdm/libs/dal/hw_device_drm.cpp
@@ -27,8 +27,7 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
- * Changes from Qualcomm Innovation Center are provided under the following license:
+/* Changes from Qualcomm Innovation Center are provided under the following license:
  *
  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
@@ -429,7 +428,7 @@
   }
 }
 
-void HWDeviceDRM::Registry::MapOutputBufferToFbId(LayerBuffer *output_buffer) {
+void HWDeviceDRM::Registry::MapOutputBufferToFbId(std::shared_ptr<LayerBuffer> output_buffer) {
   if (output_buffer->planes[0].fd < 0) {
     return;
   }
@@ -570,6 +569,12 @@
     DLOGI("aspect_ratio_threshold_: %f", aspect_ratio_threshold_);
   }
 
+  value = 0;
+  if (Debug::GetProperty(FORCE_TONEMAPPING, &value) == kErrorNone) {
+    force_tonemapping_ = (value == 1);
+    DLOGI("force_tonemapping_ %d", force_tonemapping_);
+  }
+
   return kErrorNone;
 }
 
@@ -1524,6 +1529,37 @@
 
           SetSsppTonemapFeatures(pipe_info);
         } else if (update_luts) {
+          if (force_tonemapping_) {
+            sde_drm::DRMFp16CscType fp16_csc_type = sde_drm::DRMFp16CscType::kFP16CscTypeMax;
+            int fp16_igc_en = 0;
+            int fp16_unmult_en = 0;
+            drm_msm_fp16_gc fp16_gc_config = {.flags = 0, .mode = FP16_GC_MODE_INVALID};
+            SelectFp16Config(layer.input_buffer, &fp16_igc_en, &fp16_unmult_en, &fp16_csc_type,
+                             &fp16_gc_config, layer.blending);
+
+            // Account for PMA block activation directly at translation time to preserve layer
+            // blending definition and avoid issues when a layer structure is reused.
+            DRMBlendType blending = DRMBlendType::UNDEFINED;
+            LayerBlending layer_blend = layer.blending;
+            if (layer_blend == kBlendingPremultiplied) {
+              // If blending type is premultiplied alpha and FP16 unmult is enabled,
+              // prevent performing alpha unmultiply twice
+              if (fp16_unmult_en) {
+                layer_blend = kBlendingCoverage;
+                pipe_info->inverse_pma_info.inverse_pma = false;
+                pipe_info->inverse_pma_info.op = kReset;
+                DLOGI_IF(kTagDriverConfig,
+                         "PMA handled by FP16 UNMULT block - Pipe id: %u", pipe_id);
+              } else if (pipe_info->inverse_pma_info.inverse_pma) {
+                layer_blend = kBlendingCoverage;
+                DLOGI_IF(kTagDriverConfig,
+                         "PMA handled by Inverse PMA block - Pipe id: %u", pipe_id);
+              }
+            }
+            SetBlending(layer_blend, &blending);
+            drm_atomic_intf_->Perform(DRMOps::PLANE_SET_BLEND_TYPE, pipe_id, blending);
+          }
+
           SetSsppTonemapFeatures(pipe_info);
         }
 
@@ -1953,11 +1989,25 @@
   // dpps commit feature ops doesn't use the obj id, set it as -1
   drm_atomic_intf_->Perform(DRMOps::DPPS_COMMIT_FEATURE, -1);
 
+  if (cwb_config_.cwb_disp_id == display_id_ && cwb_config_.enabled) {
+    drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_CRTC, cwb_config_.token.conn_id, 0);
+    DLOGI("Tearing down the CWB topology");
+  }
+
   int ret = NullCommit(sync_commit /* synchronous */, false /* retain_planes*/);
   if (ret) {
     DLOGE("failed with error %d", ret);
     return kErrorHardware;
   }
+
+  if (cwb_config_.cwb_disp_id == display_id_) {
+    if (cwb_config_.enabled) {
+      FlushConcurrentWriteback();
+    } else {
+      cwb_config_.cwb_disp_id = -1;
+    }
+  }
+
   return kErrorNone;
 }
 
@@ -2999,7 +3049,7 @@
 
 void HWDeviceDRM::ConfigureConcurrentWriteback(const HWLayersInfo &hw_layer_info) {
   CwbConfig *cwb_config = hw_layer_info.hw_cwb_config;
-  LayerBuffer *output_buffer = hw_layer_info.output_buffer;
+  std::shared_ptr<LayerBuffer> output_buffer = hw_layer_info.output_buffer;
   registry_.MapOutputBufferToFbId(output_buffer);
   uint32_t &vitual_conn_id = cwb_config_.token.conn_id;
 
@@ -3094,7 +3144,7 @@
   return kErrorNone;
 }
 
-void HWDeviceDRM::PostCommitConcurrentWriteback(LayerBuffer *output_buffer) {
+void HWDeviceDRM::PostCommitConcurrentWriteback(std::shared_ptr<LayerBuffer> output_buffer) {
   if (hw_resource_.has_concurrent_writeback && output_buffer) {
     return;
   }
diff --git a/sdm/libs/dal/hw_device_drm.h b/sdm/libs/dal/hw_device_drm.h
index 18506f3..1653b6b 100644
--- a/sdm/libs/dal/hw_device_drm.h
+++ b/sdm/libs/dal/hw_device_drm.h
@@ -27,8 +27,7 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
- * Changes from Qualcomm Innovation Center are provided under the following license:
+/* Changes from Qualcomm Innovation Center are provided under the following license:
  *
  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
@@ -114,7 +113,7 @@
                                 int64_t *release_fence_fd);
   DisplayError TeardownConcurrentWriteback(void);
   void ConfigureConcurrentWriteback(const HWLayersInfo &hw_layer_info);
-  void PostCommitConcurrentWriteback(LayerBuffer *output_buffer);
+  void PostCommitConcurrentWriteback(std::shared_ptr<LayerBuffer> output_buffer);
   virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers);
   virtual DisplayError SetPPFeature(PPFeatureInfo *feature);
   // This API is no longer supported, expectation is to call the correct API on HWEvents
@@ -262,7 +261,7 @@
     // Find handle_id in the layer map. Else create fb_id and add <handle_id,fb_id> in map.
     void MapBufferToFbId(Layer* layer, const LayerBuffer &buffer);
     // Find handle_id in output buffer map. Else create fb_id and add <handle_id,fb_id> in map.
-    void MapOutputBufferToFbId(LayerBuffer* buffer);
+    void MapOutputBufferToFbId(std::shared_ptr<LayerBuffer> buffer);
     // Find fb_id for given handle_id in the layer map.
     uint32_t GetFbId(Layer *layer, uint64_t handle_id);
     // Find fb_id for given handle_id in output buffer map.
@@ -335,6 +334,7 @@
   static HWCwbConfig cwb_config_;
   static std::mutex cwb_state_lock_;  // cwb state lock. Set before accesing or updating cwb_config_
   uint32_t transfer_time_updated_ = 0;
+  bool force_tonemapping_ = false;
 
  private:
   void GetCWBCapabilities();
diff --git a/sdm/libs/dal/hw_info_drm.cpp b/sdm/libs/dal/hw_info_drm.cpp
index 573b0b7..fd46ad5 100644
--- a/sdm/libs/dal/hw_info_drm.cpp
+++ b/sdm/libs/dal/hw_info_drm.cpp
@@ -368,6 +368,12 @@
   hw_resource->skip_inline_rot_threshold = info.skip_inline_rot_threshold;
   hw_resource->has_noise_layer = info.has_noise_layer;
 
+  if (info.ddr_version == sde_drm::DDRVersion::kDDRVersion4) {
+    hw_resource->ddr_version = kDDRVersion4;
+  } else if (info.ddr_version == sde_drm::DDRVersion::kDDRVersion5) {
+    hw_resource->ddr_version = kDDRVersion5;
+  }
+
   for (int index = 0; index < kBwModeMax; index++) {
     if (index == kBwVFEOn) {
       hw_resource->dyn_bw_info.total_bw_limit[index] = info.max_bandwidth_low / kKiloUnit;
diff --git a/sdm/libs/dal/hw_virtual_drm.cpp b/sdm/libs/dal/hw_virtual_drm.cpp
index 37d323f..9cc4a2d 100644
--- a/sdm/libs/dal/hw_virtual_drm.cpp
+++ b/sdm/libs/dal/hw_virtual_drm.cpp
@@ -27,41 +27,11 @@
 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
-* Changes from Qualcomm Innovation Center are provided under the following license:
-*
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted (subject to the limitations in the
-* disclaimer below) provided that the following conditions are met:
-*
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*
-*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
-* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
-* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+/* Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ */
 
 #include <stdio.h>
 #include <ctype.h>
@@ -223,7 +193,7 @@
 }
 
 DisplayError HWVirtualDRM::Commit(HWLayersInfo *hw_layers_info) {
-  LayerBuffer *output_buffer = hw_layers_info->output_buffer;
+  std::shared_ptr<LayerBuffer> output_buffer = hw_layers_info->output_buffer;
   DisplayError err = kErrorNone;
 
   registry_.Register(hw_layers_info);
@@ -259,7 +229,7 @@
 }
 
 DisplayError HWVirtualDRM::Validate(HWLayersInfo *hw_layers_info) {
-  LayerBuffer *output_buffer = hw_layers_info->output_buffer;
+  std::shared_ptr<LayerBuffer> output_buffer = hw_layers_info->output_buffer;
 
   registry_.MapOutputBufferToFbId(output_buffer);
   uint32_t fb_id = registry_.GetOutputFbId(output_buffer->handle_id);