Merge "sde: strategy interface changes"
diff --git a/displayengine/include/core/display_interface.h b/displayengine/include/core/display_interface.h
index 97f7911..bdeb8a3 100755
--- a/displayengine/include/core/display_interface.h
+++ b/displayengine/include/core/display_interface.h
@@ -94,6 +94,7 @@
   float y_dpi;                //!< Dots per inch in Y-direction.
   float fps;                  //!< Frame rate per second.
   uint32_t vsync_period_ns;   //!< VSync period in nanoseconds.
+  uint32_t v_total;           //!< Total lines in Y-direction (vActive + vFP + vBP + vPulseWidth).
 
   DisplayConfigVariableInfo() : x_pixels(0), y_pixels(0), x_dpi(0.0f), y_dpi(0.0f),
                                fps(0.0f), vsync_period_ns(0) { }
diff --git a/displayengine/libs/core/hw_framebuffer.cpp b/displayengine/libs/core/hw_framebuffer.cpp
index 36b86b6..3a0f2d0 100644
--- a/displayengine/libs/core/hw_framebuffer.cpp
+++ b/displayengine/libs/core/hw_framebuffer.cpp
@@ -313,12 +313,14 @@
 
       display_attributes->x_pixels = var_screeninfo.xres;
       display_attributes->y_pixels = var_screeninfo.yres;
+      display_attributes->v_total = var_screeninfo.yres + var_screeninfo.lower_margin +
+          var_screeninfo.upper_margin + var_screeninfo.vsync_len;
       display_attributes->x_dpi =
           (FLOAT(var_screeninfo.xres) * 25.4f) / FLOAT(var_screeninfo.width);
       display_attributes->y_dpi =
           (FLOAT(var_screeninfo.yres) * 25.4f) / FLOAT(var_screeninfo.height);
-      display_attributes->vsync_period_ns =
-          UINT32(1000000000L / FLOAT(meta_data.data.panel_frame_rate));
+      display_attributes->fps = FLOAT(meta_data.data.panel_frame_rate);
+      display_attributes->vsync_period_ns = UINT32(1000000000L / display_attributes->fps);
       display_attributes->is_device_split = (hw_resource_.split_info.left_split ||
           (var_screeninfo.xres > hw_resource_.max_mixer_width)) ? true : false;
       display_attributes->split_left = hw_resource_.split_info.left_split ?
@@ -339,10 +341,12 @@
       }
       display_attributes->x_pixels = timing_mode->active_h;
       display_attributes->y_pixels = timing_mode->active_v;
+      display_attributes->v_total = timing_mode->active_v + timing_mode->front_porch_v +
+          timing_mode->back_porch_v + timing_mode->pulse_width_v;
       display_attributes->x_dpi = 0;
       display_attributes->y_dpi = 0;
-      display_attributes->vsync_period_ns =
-          UINT32(1000000000L / FLOAT(timing_mode->refresh_rate));
+      display_attributes->fps = FLOAT(timing_mode->refresh_rate);
+      display_attributes->vsync_period_ns = UINT32(1000000000L / display_attributes->fps);
       display_attributes->split_left = display_attributes->x_pixels;
       if (display_attributes->x_pixels > hw_resource_.max_mixer_width) {
         display_attributes->is_device_split = true;
@@ -830,6 +834,12 @@
         hw_resource_.max_bandwidth_high = atol(tokens[1]);
       } else if (!strncmp(tokens[0], "max_mixer_width", strlen("max_mixer_width"))) {
         hw_resource_.max_mixer_width = atoi(tokens[1]);
+      } else if (!strncmp(tokens[0], "max_pipe_bw", strlen("max_pipe_bw"))) {
+        hw_resource_.max_pipe_bw = atoi(tokens[1]);
+      } else if (!strncmp(tokens[0], "max_mdp_clk", strlen("max_mdp_clk"))) {
+        hw_resource_.max_sde_clk = atoi(tokens[1]);
+      } else if (!strncmp(tokens[0], "clk_fudge_factor", strlen("clk_fudge_factor"))) {
+        hw_resource_.clk_fudge_factor = FLOAT(atoi(tokens[1])) / FLOAT(atoi(tokens[2]));
       } else if (!strncmp(tokens[0], "features", strlen("features"))) {
         for (uint32_t i = 0; i < token_count; i++) {
           if (!strncmp(tokens[i], "bwc", strlen("bwc"))) {
@@ -896,6 +906,8 @@
   DLOGI("SourceSplit = %d, Always = %d", hw_resource_.is_src_split, hw_resource_.always_src_split);
   DLOGI("MaxLowBw = %"PRIu64", MaxHighBw = %"PRIu64"", hw_resource_.max_bandwidth_low,
         hw_resource_.max_bandwidth_high);
+  DLOGI("MaxPipeBw = %"PRIu64" KBps, MaxSDEClock = %"PRIu64" Hz, ClockFudgeFactor = %f",
+        hw_resource_.max_pipe_bw, hw_resource_.max_sde_clk, hw_resource_.clk_fudge_factor);
 
   return error;
 }
diff --git a/displayengine/libs/core/hw_interface.h b/displayengine/libs/core/hw_interface.h
index 3e620ce..84870b8 100644
--- a/displayengine/libs/core/hw_interface.h
+++ b/displayengine/libs/core/hw_interface.h
@@ -66,6 +66,9 @@
   uint64_t max_bandwidth_low;
   uint64_t max_bandwidth_high;
   uint32_t max_mixer_width;
+  uint32_t max_pipe_bw;
+  uint32_t max_sde_clk;
+  float clk_fudge_factor;
   struct SplitInfo {
     uint32_t left_split;
     uint32_t right_split;
@@ -84,7 +87,8 @@
       num_cursor_pipe(0), num_blending_stages(0), num_rotator(0), num_control(0),
       num_mixer_to_disp(0), smp_total(0), smp_size(0), num_smp_per_pipe(0), max_scale_up(0),
       max_scale_down(0), max_bandwidth_low(0), max_bandwidth_high(0), max_mixer_width(2048),
-      has_bwc(false), has_decimation(false), has_macrotile(false), has_rotator_downscale(false),
+      max_pipe_bw(0), max_sde_clk(0), clk_fudge_factor(1.0f), has_bwc(false),
+      has_decimation(false), has_macrotile(false), has_rotator_downscale(false),
       has_non_scalar_rgb(false), is_src_split(false), always_src_split(false) { }
 };
 
diff --git a/displayengine/libs/core/res_manager.cpp b/displayengine/libs/core/res_manager.cpp
index 9edca48..1ccb410 100755
--- a/displayengine/libs/core/res_manager.cpp
+++ b/displayengine/libs/core/res_manager.cpp
@@ -280,13 +280,12 @@
 }
 
 bool ResManager::CheckBandwidth(DisplayResourceContext *display_ctx, HWLayers *hw_layers) {
-  float max_pipe_bw = 1.8f;  // From MDP to hw_res_info_ (in GBps)
-  float max_sde_clk = 400.0f;  // From MDP to hw_res_info_ (in MHz)
-  float clk_fudge_factor = 1.0f;  // From MDP to hw_res_info_
+  float max_pipe_bw = FLOAT(hw_res_info_.max_pipe_bw) / 1000000;  // KBps to GBps
+  float max_sde_clk = FLOAT(hw_res_info_.max_sde_clk) / 1000000;  // Hz to MHz
   const struct HWLayersInfo &layer_info = hw_layers->info;
 
-  float left_pipe_bw[layer_info.count];
-  float right_pipe_bw[layer_info.count];
+  float left_pipe_bw[kMaxSDELayers] = {0};
+  float right_pipe_bw[kMaxSDELayers] = {0};
   float left_max_clk = 0;
   float right_max_clk = 0;
 
@@ -322,7 +321,7 @@
   }
 
   // If system has Video mode panel, use max_bandwidth_low, else use max_bandwidth_high
-  if ((display_bw + bw_claimed_) > hw_res_info_.max_bandwidth_low) {
+  if ((display_bw + bw_claimed_) > (hw_res_info_.max_bandwidth_low / 1000000)) {
     DLOGV_IF(kTagResources, "Overlap bandwidth exceeds limit!");
     return false;
   }
@@ -334,7 +333,7 @@
   float system_clk = MAX(display_clk, clk_claimed_);
 
   // Apply fudge factor to consider in-efficieny
-  if ((system_clk * clk_fudge_factor) > max_sde_clk) {
+  if ((system_clk * hw_res_info_.clk_fudge_factor) > max_sde_clk) {
     DLOGV_IF(kTagResources, "Clock requirement exceeds limit!");
     return false;
   }
@@ -353,9 +352,6 @@
 
 float ResManager::GetPipeBw(DisplayResourceContext *display_ctx, HWPipeInfo *pipe, float bpp) {
   HWDisplayAttributes &display_attributes = display_ctx->display_attributes;
-  float v_total = 2600.0f;  // From MDP to display_attributes (vBP + vFP + v_active)
-  float fps = 60.0f;  // display_attributes.fps;
-
   float src_w = pipe->src_roi.right - pipe->src_roi.left;
   float src_h = pipe->src_roi.bottom - pipe->src_roi.top;
   float dst_h = pipe->dst_roi.bottom - pipe->dst_roi.top;
@@ -363,11 +359,11 @@
   // Adjust src_h with pipe decimation
   src_h /= FLOAT(pipe->decimation);
 
-  float bw = src_w * src_h * bpp * fps;
+  float bw = src_w * src_h * bpp * display_attributes.fps;
 
   // Consider panel dimension
   // (v_total / v_active) * (v_active / dst_h)
-  bw *= (v_total / dst_h);
+  bw *= FLOAT(display_attributes.v_total) / dst_h;
 
   // Bandwidth in GBps
   return (bw / 1000000000.0f);
@@ -375,8 +371,8 @@
 
 float ResManager::GetClockForPipe(DisplayResourceContext *display_ctx, HWPipeInfo *pipe) {
   HWDisplayAttributes &display_attributes = display_ctx->display_attributes;
-  float v_total = 2600.0f;  // (vBP + vFP + v_active)
-  float fps = 60.0f;  // display_attributes.fps;
+  float v_total = FLOAT(display_attributes.v_total);
+  float fps = display_attributes.fps;
 
   float src_h = pipe->src_roi.bottom - pipe->src_roi.top;
   float dst_h = pipe->dst_roi.bottom - pipe->dst_roi.top;
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index fd81c70..596ca77 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -294,9 +294,6 @@
     data.uncached = useUncached(usage);
     data.allocType = 0;
 
-    if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP)
-        ionFlags |= ION_HEAP(ION_SF_HEAP_ID);
-
     if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP)
         ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID);
 
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 1fbff11..c5ecc42 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -40,8 +40,9 @@
     /* SYSTEM heap comes from kernel vmalloc,
      * can never be uncached, is not secured*/
     GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP     =       GRALLOC_USAGE_PRIVATE_0,
-    /* SF heap is used for application buffers, is not secured */
-    GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP  =       GRALLOC_USAGE_PRIVATE_1,
+
+    /* GRALLOC_USAGE_PRIVATE_1 is unused */
+
     /* IOMMU heap comes from manually allocated pages,
      * can be cached/uncached, is not secured */
     GRALLOC_USAGE_PRIVATE_IOMMU_HEAP      =       GRALLOC_USAGE_PRIVATE_2,
@@ -82,8 +83,7 @@
 #define GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE 6
 #define GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO 7
 
-#define GRALLOC_HEAP_MASK   (GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP |\
-                             GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP    |\
+#define GRALLOC_HEAP_MASK   (GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP    |\
                              GRALLOC_USAGE_PRIVATE_IOMMU_HEAP     |\
                              GRALLOC_USAGE_PRIVATE_MM_HEAP        |\
                              GRALLOC_USAGE_PRIVATE_ADSP_HEAP)