LCOV - code coverage report
Current view: top level - drivers/gpu/drm/amd/display/dc/dml/calcs - dcn_calc_auto.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 1126 0.0 %
Date: 2022-12-09 01:23:36 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright 2017 Advanced Micro Devices, Inc.
       3             :  *
       4             :  * Permission is hereby granted, free of charge, to any person obtaining a
       5             :  * copy of this software and associated documentation files (the "Software"),
       6             :  * to deal in the Software without restriction, including without limitation
       7             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
       8             :  * and/or sell copies of the Software, and to permit persons to whom the
       9             :  * Software is furnished to do so, subject to the following conditions:
      10             :  *
      11             :  * The above copyright notice and this permission notice shall be included in
      12             :  * all copies or substantial portions of the Software.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
      17             :  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
      18             :  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      19             :  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
      20             :  * OTHER DEALINGS IN THE SOFTWARE.
      21             :  *
      22             :  * Authors: AMD
      23             :  *
      24             :  */
      25             : 
      26             : #include "dm_services.h"
      27             : #include "dcn_calc_auto.h"
      28             : #include "dcn_calc_math.h"
      29             : 
      30             : /*
      31             :  * NOTE:
      32             :  *   This file is gcc-parseable HW gospel, coming straight from HW engineers.
      33             :  *
      34             :  * It doesn't adhere to Linux kernel style and sometimes will do things in odd
      35             :  * ways. Unless there is something clearly wrong with it the code should
      36             :  * remain as-is as it provides us with a guarantee from HW that it is correct.
      37             :  */
      38             : 
      39             : /*REVISION#250*/
      40           0 : void scaler_settings_calculation(struct dcn_bw_internal_vars *v)
      41             : {
      42             :         int k;
      43           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
      44           0 :                 if (v->allow_different_hratio_vratio == dcn_bw_yes) {
      45           0 :                         if (v->source_scan[k] == dcn_bw_hor) {
      46           0 :                                 v->h_ratio[k] = v->viewport_width[k] / v->scaler_rec_out_width[k];
      47           0 :                                 v->v_ratio[k] = v->viewport_height[k] / v->scaler_recout_height[k];
      48             :                         }
      49             :                         else {
      50           0 :                                 v->h_ratio[k] = v->viewport_height[k] / v->scaler_rec_out_width[k];
      51           0 :                                 v->v_ratio[k] = v->viewport_width[k] / v->scaler_recout_height[k];
      52             :                         }
      53             :                 }
      54             :                 else {
      55           0 :                         if (v->source_scan[k] == dcn_bw_hor) {
      56           0 :                                 v->h_ratio[k] =dcn_bw_max2(v->viewport_width[k] / v->scaler_rec_out_width[k], v->viewport_height[k] / v->scaler_recout_height[k]);
      57             :                         }
      58             :                         else {
      59           0 :                                 v->h_ratio[k] =dcn_bw_max2(v->viewport_height[k] / v->scaler_rec_out_width[k], v->viewport_width[k] / v->scaler_recout_height[k]);
      60             :                         }
      61           0 :                         v->v_ratio[k] = v->h_ratio[k];
      62             :                 }
      63           0 :                 if (v->interlace_output[k] == 1.0) {
      64           0 :                         v->v_ratio[k] = 2.0 * v->v_ratio[k];
      65             :                 }
      66           0 :                 if (v->underscan_output[k] == 1.0) {
      67           0 :                         v->h_ratio[k] = v->h_ratio[k] * v->under_scan_factor;
      68           0 :                         v->v_ratio[k] = v->v_ratio[k] * v->under_scan_factor;
      69             :                 }
      70             :         }
      71             :         /*scaler taps calculation*/
      72             : 
      73           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
      74           0 :                 if (v->h_ratio[k] > 1.0) {
      75           0 :                         v->acceptable_quality_hta_ps =dcn_bw_min2(v->max_hscl_taps, 2.0 *dcn_bw_ceil2(v->h_ratio[k], 1.0));
      76             :                 }
      77           0 :                 else if (v->h_ratio[k] < 1.0) {
      78           0 :                         v->acceptable_quality_hta_ps = 4.0;
      79             :                 }
      80             :                 else {
      81           0 :                         v->acceptable_quality_hta_ps = 1.0;
      82             :                 }
      83           0 :                 if (v->ta_pscalculation == dcn_bw_override) {
      84           0 :                         v->htaps[k] = v->override_hta_ps[k];
      85             :                 }
      86             :                 else {
      87           0 :                         v->htaps[k] = v->acceptable_quality_hta_ps;
      88             :                 }
      89           0 :                 if (v->v_ratio[k] > 1.0) {
      90           0 :                         v->acceptable_quality_vta_ps =dcn_bw_min2(v->max_vscl_taps, 2.0 *dcn_bw_ceil2(v->v_ratio[k], 1.0));
      91             :                 }
      92           0 :                 else if (v->v_ratio[k] < 1.0) {
      93           0 :                         v->acceptable_quality_vta_ps = 4.0;
      94             :                 }
      95             :                 else {
      96           0 :                         v->acceptable_quality_vta_ps = 1.0;
      97             :                 }
      98           0 :                 if (v->ta_pscalculation == dcn_bw_override) {
      99           0 :                         v->vtaps[k] = v->override_vta_ps[k];
     100             :                 }
     101             :                 else {
     102           0 :                         v->vtaps[k] = v->acceptable_quality_vta_ps;
     103             :                 }
     104           0 :                 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
     105           0 :                         v->vta_pschroma[k] = 0.0;
     106           0 :                         v->hta_pschroma[k] = 0.0;
     107             :                 }
     108             :                 else {
     109           0 :                         if (v->ta_pscalculation == dcn_bw_override) {
     110           0 :                                 v->vta_pschroma[k] = v->override_vta_pschroma[k];
     111           0 :                                 v->hta_pschroma[k] = v->override_hta_pschroma[k];
     112             :                         }
     113             :                         else {
     114           0 :                                 v->vta_pschroma[k] = v->acceptable_quality_vta_ps;
     115           0 :                                 v->hta_pschroma[k] = v->acceptable_quality_hta_ps;
     116             :                         }
     117             :                 }
     118             :         }
     119           0 : }
     120             : 
     121           0 : void mode_support_and_system_configuration(struct dcn_bw_internal_vars *v)
     122             : {
     123             :         int i;
     124             :         int j;
     125             :         int k;
     126             :         /*mode support, voltage state and soc configuration*/
     127             : 
     128             :         /*scale ratio support check*/
     129             : 
     130           0 :         v->scale_ratio_support = dcn_bw_yes;
     131           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     132           0 :                 if (v->h_ratio[k] > v->max_hscl_ratio || v->v_ratio[k] > v->max_vscl_ratio || v->h_ratio[k] > v->htaps[k] || v->v_ratio[k] > v->vtaps[k] || (v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16 && (v->h_ratio[k] / 2.0 > v->hta_pschroma[k] || v->v_ratio[k] / 2.0 > v->vta_pschroma[k]))) {
     133           0 :                         v->scale_ratio_support = dcn_bw_no;
     134             :                 }
     135             :         }
     136             :         /*source format, pixel format and scan support check*/
     137             : 
     138           0 :         v->source_format_pixel_and_scan_support = dcn_bw_yes;
     139           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     140           0 :                 if ((v->source_surface_mode[k] == dcn_bw_sw_linear && v->source_scan[k] != dcn_bw_hor) || ((v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x || v->source_surface_mode[k] == dcn_bw_sw_var_d || v->source_surface_mode[k] == dcn_bw_sw_var_d_x) && v->source_pixel_format[k] != dcn_bw_rgb_sub_64)) {
     141           0 :                         v->source_format_pixel_and_scan_support = dcn_bw_no;
     142             :                 }
     143             :         }
     144             :         /*bandwidth support check*/
     145             : 
     146           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     147           0 :                 if (v->source_scan[k] == dcn_bw_hor) {
     148           0 :                         v->swath_width_ysingle_dpp[k] = v->viewport_width[k];
     149             :                 }
     150             :                 else {
     151           0 :                         v->swath_width_ysingle_dpp[k] = v->viewport_height[k];
     152             :                 }
     153           0 :                 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
     154           0 :                         v->byte_per_pixel_in_dety[k] = 8.0;
     155           0 :                         v->byte_per_pixel_in_detc[k] = 0.0;
     156             :                 }
     157           0 :                 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) {
     158           0 :                         v->byte_per_pixel_in_dety[k] = 4.0;
     159           0 :                         v->byte_per_pixel_in_detc[k] = 0.0;
     160             :                 }
     161           0 :                 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
     162           0 :                         v->byte_per_pixel_in_dety[k] = 2.0;
     163           0 :                         v->byte_per_pixel_in_detc[k] = 0.0;
     164             :                 }
     165           0 :                 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
     166           0 :                         v->byte_per_pixel_in_dety[k] = 1.0;
     167           0 :                         v->byte_per_pixel_in_detc[k] = 2.0;
     168             :                 }
     169             :                 else {
     170           0 :                         v->byte_per_pixel_in_dety[k] = 4.0f / 3.0f;
     171           0 :                         v->byte_per_pixel_in_detc[k] = 8.0f / 3.0f;
     172             :                 }
     173             :         }
     174           0 :         v->total_read_bandwidth_consumed_gbyte_per_second = 0.0;
     175           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     176           0 :                 v->read_bandwidth[k] = v->swath_width_ysingle_dpp[k] * (dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) * v->v_ratio[k] +dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 2.0 * v->v_ratio[k] / 2) / (v->htotal[k] / v->pixel_clock[k]);
     177             :                 if (v->dcc_enable[k] == dcn_bw_yes) {
     178             :                         v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 256);
     179             :                 }
     180             :                 if (v->pte_enable == dcn_bw_yes && v->source_scan[k] != dcn_bw_hor && (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x)) {
     181             :                         v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 64);
     182             :                 }
     183             :                 else if (v->pte_enable == dcn_bw_yes && v->source_scan[k] == dcn_bw_hor && (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32) && (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x)) {
     184             :                         v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 256);
     185             :                 }
     186             :                 else if (v->pte_enable == dcn_bw_yes) {
     187             :                         v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 512);
     188             :                 }
     189           0 :                 v->total_read_bandwidth_consumed_gbyte_per_second = v->total_read_bandwidth_consumed_gbyte_per_second + v->read_bandwidth[k] / 1000.0;
     190             :         }
     191           0 :         v->total_write_bandwidth_consumed_gbyte_per_second = 0.0;
     192           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     193           0 :                 if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444) {
     194           0 :                         v->write_bandwidth[k] = v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0;
     195             :                 }
     196           0 :                 else if (v->output[k] == dcn_bw_writeback) {
     197           0 :                         v->write_bandwidth[k] = v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 1.5;
     198             :                 }
     199             :                 else {
     200           0 :                         v->write_bandwidth[k] = 0.0;
     201             :                 }
     202           0 :                 v->total_write_bandwidth_consumed_gbyte_per_second = v->total_write_bandwidth_consumed_gbyte_per_second + v->write_bandwidth[k] / 1000.0;
     203             :         }
     204           0 :         v->total_bandwidth_consumed_gbyte_per_second = v->total_read_bandwidth_consumed_gbyte_per_second + v->total_write_bandwidth_consumed_gbyte_per_second;
     205           0 :         v->dcc_enabled_in_any_plane = dcn_bw_no;
     206           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     207           0 :                 if (v->dcc_enable[k] == dcn_bw_yes) {
     208           0 :                         v->dcc_enabled_in_any_plane = dcn_bw_yes;
     209             :                 }
     210             :         }
     211           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     212           0 :                 v->return_bw_todcn_per_state =dcn_bw_min2(v->return_bus_width * v->dcfclk_per_state[i], v->fabric_and_dram_bandwidth_per_state[i] * 1000.0 * v->percent_of_ideal_drambw_received_after_urg_latency / 100.0);
     213           0 :                 v->return_bw_per_state[i] = v->return_bw_todcn_per_state;
     214           0 :                 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->return_bw_todcn_per_state > v->dcfclk_per_state[i] * v->return_bus_width / 4.0) {
     215           0 :                         v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], v->return_bw_todcn_per_state * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bw_todcn_per_state - v->dcfclk_per_state[i] * v->return_bus_width / 4.0) + v->urgent_latency)));
     216             :                 }
     217           0 :                 v->critical_point = 2.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0);
     218           0 :                 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->critical_point > 1.0 && v->critical_point < 4.0) {
     219           0 :                         v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], dcn_bw_pow(4.0 * v->return_bw_todcn_per_state * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2));
     220             :                 }
     221           0 :                 v->return_bw_todcn_per_state =dcn_bw_min2(v->return_bus_width * v->dcfclk_per_state[i], v->fabric_and_dram_bandwidth_per_state[i] * 1000.0);
     222           0 :                 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->return_bw_todcn_per_state > v->dcfclk_per_state[i] * v->return_bus_width / 4.0) {
     223           0 :                         v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], v->return_bw_todcn_per_state * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bw_todcn_per_state - v->dcfclk_per_state[i] * v->return_bus_width / 4.0) + v->urgent_latency)));
     224             :                 }
     225           0 :                 v->critical_point = 2.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0);
     226           0 :                 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->critical_point > 1.0 && v->critical_point < 4.0) {
     227           0 :                         v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], dcn_bw_pow(4.0 * v->return_bw_todcn_per_state * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2));
     228             :                 }
     229             :         }
     230           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     231           0 :                 if ((v->total_read_bandwidth_consumed_gbyte_per_second * 1000.0 <= v->return_bw_per_state[i]) && (v->total_bandwidth_consumed_gbyte_per_second * 1000.0 <= v->fabric_and_dram_bandwidth_per_state[i] * 1000.0 * v->percent_of_ideal_drambw_received_after_urg_latency / 100.0)) {
     232           0 :                         v->bandwidth_support[i] = dcn_bw_yes;
     233             :                 }
     234             :                 else {
     235           0 :                         v->bandwidth_support[i] = dcn_bw_no;
     236             :                 }
     237             :         }
     238             :         /*writeback latency support check*/
     239             : 
     240           0 :         v->writeback_latency_support = dcn_bw_yes;
     241           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     242           0 :                 if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444 && v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0 > (v->writeback_luma_buffer_size + v->writeback_chroma_buffer_size) * 1024.0 / v->write_back_latency) {
     243           0 :                         v->writeback_latency_support = dcn_bw_no;
     244             :                 }
     245           0 :                 else if (v->output[k] == dcn_bw_writeback && v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) >dcn_bw_min2(v->writeback_luma_buffer_size, 2.0 * v->writeback_chroma_buffer_size) * 1024.0 / v->write_back_latency) {
     246           0 :                         v->writeback_latency_support = dcn_bw_no;
     247             :                 }
     248             :         }
     249             :         /*re-ordering buffer support check*/
     250             : 
     251           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     252           0 :                 v->urgent_round_trip_and_out_of_order_latency_per_state[i] = (v->round_trip_ping_latency_cycles + 32.0) / v->dcfclk_per_state[i] + v->urgent_out_of_order_return_per_channel * v->number_of_channels / v->return_bw_per_state[i];
     253           0 :                 if ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / v->return_bw_per_state[i] > v->urgent_round_trip_and_out_of_order_latency_per_state[i]) {
     254           0 :                         v->rob_support[i] = dcn_bw_yes;
     255             :                 }
     256             :                 else {
     257           0 :                         v->rob_support[i] = dcn_bw_no;
     258             :                 }
     259             :         }
     260             :         /*display io support check*/
     261             : 
     262           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     263           0 :                 if (v->output[k] == dcn_bw_dp && v->dsc_capability == dcn_bw_yes) {
     264           0 :                         if (v->output_format[k] == dcn_bw_420) {
     265           0 :                                 v->required_output_bw = v->pixel_clock[k] / 2.0;
     266             :                         }
     267             :                         else {
     268           0 :                                 v->required_output_bw = v->pixel_clock[k];
     269             :                         }
     270             :                 }
     271           0 :                 else if (v->output_format[k] == dcn_bw_420) {
     272           0 :                         v->required_output_bw = v->pixel_clock[k] * 3.0 / 2.0;
     273             :                 }
     274             :                 else {
     275           0 :                         v->required_output_bw = v->pixel_clock[k] * 3.0;
     276             :                 }
     277           0 :                 if (v->output[k] == dcn_bw_hdmi) {
     278           0 :                         v->required_phyclk[k] = v->required_output_bw;
     279           0 :                         switch (v->output_deep_color[k]) {
     280             :                         case dcn_bw_encoder_10bpc:
     281           0 :                                 v->required_phyclk[k] =  v->required_phyclk[k] * 5.0 / 4;
     282           0 :                         break;
     283             :                         case dcn_bw_encoder_12bpc:
     284           0 :                                 v->required_phyclk[k] =  v->required_phyclk[k] * 3.0 / 2;
     285           0 :                                 break;
     286             :                         default:
     287             :                                 break;
     288             :                         }
     289           0 :                         v->required_phyclk[k] = v->required_phyclk[k] / 3.0;
     290             :                 }
     291           0 :                 else if (v->output[k] == dcn_bw_dp) {
     292           0 :                         v->required_phyclk[k] = v->required_output_bw / 4.0;
     293             :                 }
     294             :                 else {
     295           0 :                         v->required_phyclk[k] = 0.0;
     296             :                 }
     297             :         }
     298           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     299           0 :                 v->dio_support[i] = dcn_bw_yes;
     300           0 :                 for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     301           0 :                         if (v->required_phyclk[k] > v->phyclk_per_state[i] || (v->output[k] == dcn_bw_hdmi && v->required_phyclk[k] > 600.0)) {
     302           0 :                                 v->dio_support[i] = dcn_bw_no;
     303             :                         }
     304             :                 }
     305             :         }
     306             :         /*total available writeback support check*/
     307             : 
     308           0 :         v->total_number_of_active_writeback = 0.0;
     309           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     310           0 :                 if (v->output[k] == dcn_bw_writeback) {
     311           0 :                         v->total_number_of_active_writeback = v->total_number_of_active_writeback + 1.0;
     312             :                 }
     313             :         }
     314           0 :         if (v->total_number_of_active_writeback <= v->max_num_writeback) {
     315           0 :                 v->total_available_writeback_support = dcn_bw_yes;
     316             :         }
     317             :         else {
     318           0 :                 v->total_available_writeback_support = dcn_bw_no;
     319             :         }
     320             :         /*maximum dispclk/dppclk support check*/
     321             : 
     322           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     323           0 :                 if (v->h_ratio[k] > 1.0) {
     324           0 :                         v->pscl_factor[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] /dcn_bw_ceil2(v->htaps[k] / 6.0, 1.0));
     325             :                 }
     326             :                 else {
     327           0 :                         v->pscl_factor[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
     328             :                 }
     329           0 :                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
     330           0 :                         v->pscl_factor_chroma[k] = 0.0;
     331           0 :                         v->min_dppclk_using_single_dpp[k] = v->pixel_clock[k] *dcn_bw_max3(v->vtaps[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k]), v->h_ratio[k] * v->v_ratio[k] / v->pscl_factor[k], 1.0);
     332             :                 }
     333             :                 else {
     334           0 :                         if (v->h_ratio[k] / 2.0 > 1.0) {
     335           0 :                                 v->pscl_factor_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] / 2.0 /dcn_bw_ceil2(v->hta_pschroma[k] / 6.0, 1.0));
     336             :                         }
     337             :                         else {
     338           0 :                                 v->pscl_factor_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
     339             :                         }
     340           0 :                         v->min_dppclk_using_single_dpp[k] = v->pixel_clock[k] *dcn_bw_max5(v->vtaps[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k]), v->h_ratio[k] * v->v_ratio[k] / v->pscl_factor[k], v->vta_pschroma[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k] / 2.0), v->h_ratio[k] * v->v_ratio[k] / 4.0 / v->pscl_factor_chroma[k], 1.0);
     341             :                 }
     342             :         }
     343           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     344           0 :                 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) {
     345           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     346           0 :                                 v->read256_block_height_y[k] = 1.0;
     347             :                         }
     348           0 :                         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
     349           0 :                                 v->read256_block_height_y[k] = 4.0;
     350             :                         }
     351             :                         else {
     352           0 :                                 v->read256_block_height_y[k] = 8.0;
     353             :                         }
     354           0 :                         v->read256_block_width_y[k] = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->read256_block_height_y[k];
     355           0 :                         v->read256_block_height_c[k] = 0.0;
     356           0 :                         v->read256_block_width_c[k] = 0.0;
     357             :                 }
     358             :                 else {
     359           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     360           0 :                                 v->read256_block_height_y[k] = 1.0;
     361           0 :                                 v->read256_block_height_c[k] = 1.0;
     362             :                         }
     363           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
     364           0 :                                 v->read256_block_height_y[k] = 16.0;
     365           0 :                                 v->read256_block_height_c[k] = 8.0;
     366             :                         }
     367             :                         else {
     368           0 :                                 v->read256_block_height_y[k] = 8.0;
     369           0 :                                 v->read256_block_height_c[k] = 8.0;
     370             :                         }
     371           0 :                         v->read256_block_width_y[k] = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->read256_block_height_y[k];
     372           0 :                         v->read256_block_width_c[k] = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->read256_block_height_c[k];
     373             :                 }
     374           0 :                 if (v->source_scan[k] == dcn_bw_hor) {
     375           0 :                         v->max_swath_height_y[k] = v->read256_block_height_y[k];
     376           0 :                         v->max_swath_height_c[k] = v->read256_block_height_c[k];
     377             :                 }
     378             :                 else {
     379           0 :                         v->max_swath_height_y[k] = v->read256_block_width_y[k];
     380           0 :                         v->max_swath_height_c[k] = v->read256_block_width_c[k];
     381             :                 }
     382           0 :                 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) {
     383           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear || (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 && (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_var_s || v->source_surface_mode[k] == dcn_bw_sw_var_s_x) && v->source_scan[k] == dcn_bw_hor)) {
     384           0 :                                 v->min_swath_height_y[k] = v->max_swath_height_y[k];
     385             :                         }
     386             :                         else {
     387           0 :                                 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0;
     388             :                         }
     389           0 :                         v->min_swath_height_c[k] = v->max_swath_height_c[k];
     390             :                 }
     391             :                 else {
     392           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     393           0 :                                 v->min_swath_height_y[k] = v->max_swath_height_y[k];
     394           0 :                                 v->min_swath_height_c[k] = v->max_swath_height_c[k];
     395             :                         }
     396           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 && v->source_scan[k] == dcn_bw_hor) {
     397           0 :                                 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0;
     398           0 :                                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
     399           0 :                                         v->min_swath_height_c[k] = v->max_swath_height_c[k];
     400             :                                 }
     401             :                                 else {
     402           0 :                                         v->min_swath_height_c[k] = v->max_swath_height_c[k] / 2.0;
     403             :                                 }
     404             :                         }
     405           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10 && v->source_scan[k] == dcn_bw_hor) {
     406           0 :                                 v->min_swath_height_c[k] = v->max_swath_height_c[k] / 2.0;
     407           0 :                                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
     408           0 :                                         v->min_swath_height_y[k] = v->max_swath_height_y[k];
     409             :                                 }
     410             :                                 else {
     411           0 :                                         v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0;
     412             :                                 }
     413             :                         }
     414             :                         else {
     415           0 :                                 v->min_swath_height_y[k] = v->max_swath_height_y[k];
     416           0 :                                 v->min_swath_height_c[k] = v->max_swath_height_c[k];
     417             :                         }
     418             :                 }
     419           0 :                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     420           0 :                         v->maximum_swath_width = 8192.0;
     421             :                 }
     422             :                 else {
     423           0 :                         v->maximum_swath_width = 5120.0;
     424             :                 }
     425           0 :                 v->number_of_dpp_required_for_det_size =dcn_bw_ceil2(v->swath_width_ysingle_dpp[k] /dcn_bw_min2(v->maximum_swath_width, v->det_buffer_size_in_kbyte * 1024.0 / 2.0 / (v->byte_per_pixel_in_dety[k] * v->min_swath_height_y[k] + v->byte_per_pixel_in_detc[k] / 2.0 * v->min_swath_height_c[k])), 1.0);
     426           0 :                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
     427           0 :                         v->number_of_dpp_required_for_lb_size =dcn_bw_ceil2((v->vtaps[k] +dcn_bw_max2(dcn_bw_ceil2(v->v_ratio[k], 1.0) - 2, 0.0)) * v->swath_width_ysingle_dpp[k] /dcn_bw_max2(v->h_ratio[k], 1.0) * v->lb_bit_per_pixel[k] / v->line_buffer_size, 1.0);
     428             :                 }
     429             :                 else {
     430           0 :                         v->number_of_dpp_required_for_lb_size =dcn_bw_max2(dcn_bw_ceil2((v->vtaps[k] +dcn_bw_max2(dcn_bw_ceil2(v->v_ratio[k], 1.0) - 2, 0.0)) * v->swath_width_ysingle_dpp[k] /dcn_bw_max2(v->h_ratio[k], 1.0) * v->lb_bit_per_pixel[k] / v->line_buffer_size, 1.0),dcn_bw_ceil2((v->vta_pschroma[k] +dcn_bw_max2(dcn_bw_ceil2(v->v_ratio[k] / 2.0, 1.0) - 2, 0.0)) * v->swath_width_ysingle_dpp[k] / 2.0 /dcn_bw_max2(v->h_ratio[k] / 2.0, 1.0) * v->lb_bit_per_pixel[k] / v->line_buffer_size, 1.0));
     431             :                 }
     432           0 :                 v->number_of_dpp_required_for_det_and_lb_size[k] =dcn_bw_max2(v->number_of_dpp_required_for_det_size, v->number_of_dpp_required_for_lb_size);
     433             :         }
     434           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     435           0 :                 for (j = 0; j <= 1; j++) {
     436           0 :                         v->total_number_of_active_dpp[i][j] = 0.0;
     437           0 :                         v->required_dispclk[i][j] = 0.0;
     438           0 :                         v->dispclk_dppclk_support[i][j] = dcn_bw_yes;
     439           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     440           0 :                                 v->min_dispclk_using_single_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] * (j + 1)) * (1.0 + v->downspreading / 100.0);
     441           0 :                                 if (v->odm_capability == dcn_bw_yes) {
     442           0 :                                         v->min_dispclk_using_dual_dpp =dcn_bw_max2(v->pixel_clock[k] / 2.0, v->min_dppclk_using_single_dpp[k] / 2.0 * (j + 1)) * (1.0 + v->downspreading / 100.0);
     443             :                                 }
     444             :                                 else {
     445           0 :                                         v->min_dispclk_using_dual_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] / 2.0 * (j + 1)) * (1.0 + v->downspreading / 100.0);
     446             :                                 }
     447           0 :                                 if (i < number_of_states) {
     448           0 :                                         v->min_dispclk_using_single_dpp = v->min_dispclk_using_single_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
     449           0 :                                         v->min_dispclk_using_dual_dpp = v->min_dispclk_using_dual_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
     450             :                                 }
     451           0 :                                 if (v->min_dispclk_using_single_dpp <=dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i]) && v->number_of_dpp_required_for_det_and_lb_size[k] <= 1.0) {
     452           0 :                                         v->no_of_dpp[i][j][k] = 1.0;
     453           0 :                                         v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_single_dpp);
     454             :                                 }
     455           0 :                                 else if (v->min_dispclk_using_dual_dpp <=dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) {
     456           0 :                                         v->no_of_dpp[i][j][k] = 2.0;
     457           0 :                                         v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp);
     458             :                                 }
     459             :                                 else {
     460           0 :                                         v->no_of_dpp[i][j][k] = 2.0;
     461           0 :                                         v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp);
     462           0 :                                         v->dispclk_dppclk_support[i][j] = dcn_bw_no;
     463             :                                 }
     464           0 :                                 v->total_number_of_active_dpp[i][j] = v->total_number_of_active_dpp[i][j] + v->no_of_dpp[i][j][k];
     465             :                         }
     466           0 :                         if (v->total_number_of_active_dpp[i][j] > v->max_num_dpp) {
     467           0 :                                 v->total_number_of_active_dpp[i][j] = 0.0;
     468           0 :                                 v->required_dispclk[i][j] = 0.0;
     469           0 :                                 v->dispclk_dppclk_support[i][j] = dcn_bw_yes;
     470           0 :                                 for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     471           0 :                                         v->min_dispclk_using_single_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] * (j + 1)) * (1.0 + v->downspreading / 100.0);
     472           0 :                                         v->min_dispclk_using_dual_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] / 2.0 * (j + 1)) * (1.0 + v->downspreading / 100.0);
     473           0 :                                         if (i < number_of_states) {
     474           0 :                                                 v->min_dispclk_using_single_dpp = v->min_dispclk_using_single_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
     475           0 :                                                 v->min_dispclk_using_dual_dpp = v->min_dispclk_using_dual_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
     476             :                                         }
     477           0 :                                         if (v->number_of_dpp_required_for_det_and_lb_size[k] <= 1.0) {
     478           0 :                                                 v->no_of_dpp[i][j][k] = 1.0;
     479           0 :                                                 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_single_dpp);
     480           0 :                                                 if (v->min_dispclk_using_single_dpp >dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) {
     481           0 :                                                         v->dispclk_dppclk_support[i][j] = dcn_bw_no;
     482             :                                                 }
     483             :                                         }
     484             :                                         else {
     485           0 :                                                 v->no_of_dpp[i][j][k] = 2.0;
     486           0 :                                                 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp);
     487           0 :                                                 if (v->min_dispclk_using_dual_dpp >dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) {
     488           0 :                                                         v->dispclk_dppclk_support[i][j] = dcn_bw_no;
     489             :                                                 }
     490             :                                         }
     491           0 :                                         v->total_number_of_active_dpp[i][j] = v->total_number_of_active_dpp[i][j] + v->no_of_dpp[i][j][k];
     492             :                                 }
     493             :                         }
     494             :                 }
     495             :         }
     496             :         /*viewport size check*/
     497             : 
     498           0 :         v->viewport_size_support = dcn_bw_yes;
     499           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     500           0 :                 if (v->number_of_dpp_required_for_det_and_lb_size[k] > 2.0) {
     501           0 :                         v->viewport_size_support = dcn_bw_no;
     502             :                 }
     503             :         }
     504             :         /*total available pipes support check*/
     505             : 
     506           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     507           0 :                 for (j = 0; j <= 1; j++) {
     508           0 :                         if (v->total_number_of_active_dpp[i][j] <= v->max_num_dpp) {
     509           0 :                                 v->total_available_pipes_support[i][j] = dcn_bw_yes;
     510             :                         }
     511             :                         else {
     512           0 :                                 v->total_available_pipes_support[i][j] = dcn_bw_no;
     513             :                         }
     514             :                 }
     515             :         }
     516             :         /*urgent latency support check*/
     517             : 
     518           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     519           0 :                 for (i = 0; i <= number_of_states_plus_one; i++) {
     520           0 :                         for (j = 0; j <= 1; j++) {
     521           0 :                                 v->swath_width_yper_state[i][j][k] = v->swath_width_ysingle_dpp[k] / v->no_of_dpp[i][j][k];
     522           0 :                                 v->swath_width_granularity_y = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->max_swath_height_y[k];
     523           0 :                                 v->rounded_up_max_swath_size_bytes_y = (dcn_bw_ceil2(v->swath_width_yper_state[i][j][k] - 1.0, v->swath_width_granularity_y) + v->swath_width_granularity_y) * v->byte_per_pixel_in_dety[k] * v->max_swath_height_y[k];
     524           0 :                                 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
     525           0 :                                         v->rounded_up_max_swath_size_bytes_y =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_y, 256.0) + 256;
     526             :                                 }
     527           0 :                                 if (v->max_swath_height_c[k] > 0.0) {
     528           0 :                                         v->swath_width_granularity_c = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->max_swath_height_c[k];
     529             :                                 }
     530           0 :                                 v->rounded_up_max_swath_size_bytes_c = (dcn_bw_ceil2(v->swath_width_yper_state[i][j][k] / 2.0 - 1.0, v->swath_width_granularity_c) + v->swath_width_granularity_c) * v->byte_per_pixel_in_detc[k] * v->max_swath_height_c[k];
     531           0 :                                 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
     532           0 :                                         v->rounded_up_max_swath_size_bytes_c =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_c, 256.0) + 256;
     533             :                                 }
     534           0 :                                 if (v->rounded_up_max_swath_size_bytes_y + v->rounded_up_max_swath_size_bytes_c <= v->det_buffer_size_in_kbyte * 1024.0 / 2.0) {
     535           0 :                                         v->swath_height_yper_state[i][j][k] = v->max_swath_height_y[k];
     536           0 :                                         v->swath_height_cper_state[i][j][k] = v->max_swath_height_c[k];
     537             :                                 }
     538             :                                 else {
     539           0 :                                         v->swath_height_yper_state[i][j][k] = v->min_swath_height_y[k];
     540           0 :                                         v->swath_height_cper_state[i][j][k] = v->min_swath_height_c[k];
     541             :                                 }
     542           0 :                                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
     543           0 :                                         v->lines_in_det_luma = v->det_buffer_size_in_kbyte * 1024.0 / v->byte_per_pixel_in_dety[k] / v->swath_width_yper_state[i][j][k];
     544           0 :                                         v->lines_in_det_chroma = 0.0;
     545             :                                 }
     546           0 :                                 else if (v->swath_height_yper_state[i][j][k] <= v->swath_height_cper_state[i][j][k]) {
     547           0 :                                         v->lines_in_det_luma = v->det_buffer_size_in_kbyte * 1024.0 / 2.0 / v->byte_per_pixel_in_dety[k] / v->swath_width_yper_state[i][j][k];
     548           0 :                                         v->lines_in_det_chroma = v->det_buffer_size_in_kbyte * 1024.0 / 2.0 / v->byte_per_pixel_in_detc[k] / (v->swath_width_yper_state[i][j][k] / 2.0);
     549             :                                 }
     550             :                                 else {
     551           0 :                                         v->lines_in_det_luma = v->det_buffer_size_in_kbyte * 1024.0 * 2.0 / 3.0 / v->byte_per_pixel_in_dety[k] / v->swath_width_yper_state[i][j][k];
     552           0 :                                         v->lines_in_det_chroma = v->det_buffer_size_in_kbyte * 1024.0 / 3.0 / v->byte_per_pixel_in_dety[k] / (v->swath_width_yper_state[i][j][k] / 2.0);
     553             :                                 }
     554           0 :                                 v->effective_lb_latency_hiding_source_lines_luma =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_yper_state[i][j][k] /dcn_bw_max2(v->h_ratio[k], 1.0)), 1.0)) - (v->vtaps[k] - 1.0);
     555           0 :                                 v->effective_lb_latency_hiding_source_lines_chroma =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_yper_state[i][j][k] / 2.0 /dcn_bw_max2(v->h_ratio[k] / 2.0, 1.0)), 1.0)) - (v->vta_pschroma[k] - 1.0);
     556           0 :                                 v->effective_detlb_lines_luma =dcn_bw_floor2(v->lines_in_det_luma +dcn_bw_min2(v->lines_in_det_luma * v->required_dispclk[i][j] * v->byte_per_pixel_in_dety[k] * v->pscl_factor[k] / v->return_bw_per_state[i], v->effective_lb_latency_hiding_source_lines_luma), v->swath_height_yper_state[i][j][k]);
     557           0 :                                 v->effective_detlb_lines_chroma =dcn_bw_floor2(v->lines_in_det_chroma +dcn_bw_min2(v->lines_in_det_chroma * v->required_dispclk[i][j] * v->byte_per_pixel_in_detc[k] * v->pscl_factor_chroma[k] / v->return_bw_per_state[i], v->effective_lb_latency_hiding_source_lines_chroma), v->swath_height_cper_state[i][j][k]);
     558           0 :                                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
     559           0 :                                         v->urgent_latency_support_us_per_state[i][j][k] = v->effective_detlb_lines_luma * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k] - v->effective_detlb_lines_luma * v->swath_width_yper_state[i][j][k] *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / (v->return_bw_per_state[i] / v->no_of_dpp[i][j][k]);
     560             :                                 }
     561             :                                 else {
     562           0 :                                         v->urgent_latency_support_us_per_state[i][j][k] =dcn_bw_min2(v->effective_detlb_lines_luma * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k] - v->effective_detlb_lines_luma * v->swath_width_yper_state[i][j][k] *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / (v->return_bw_per_state[i] / v->no_of_dpp[i][j][k]), v->effective_detlb_lines_chroma * (v->htotal[k] / v->pixel_clock[k]) / (v->v_ratio[k] / 2.0) - v->effective_detlb_lines_chroma * v->swath_width_yper_state[i][j][k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / (v->return_bw_per_state[i] / v->no_of_dpp[i][j][k]));
     563             :                                 }
     564             :                         }
     565             :                 }
     566           0 :         }
     567           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     568           0 :                 for (j = 0; j <= 1; j++) {
     569           0 :                         v->urgent_latency_support[i][j] = dcn_bw_yes;
     570           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     571           0 :                                 if (v->urgent_latency_support_us_per_state[i][j][k] < v->urgent_latency / 1.0) {
     572           0 :                                         v->urgent_latency_support[i][j] = dcn_bw_no;
     573             :                                 }
     574             :                         }
     575             :                 }
     576             :         }
     577             :         /*prefetch check*/
     578             : 
     579           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     580           0 :                 for (j = 0; j <= 1; j++) {
     581           0 :                         v->total_number_of_dcc_active_dpp[i][j] = 0.0;
     582           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     583           0 :                                 if (v->dcc_enable[k] == dcn_bw_yes) {
     584           0 :                                         v->total_number_of_dcc_active_dpp[i][j] = v->total_number_of_dcc_active_dpp[i][j] + v->no_of_dpp[i][j][k];
     585             :                                 }
     586             :                         }
     587             :                 }
     588             :         }
     589           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     590           0 :                 for (j = 0; j <= 1; j++) {
     591           0 :                         v->projected_dcfclk_deep_sleep = 8.0;
     592           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     593           0 :                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, v->pixel_clock[k] / 16.0);
     594           0 :                                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
     595           0 :                                         if (v->v_ratio[k] <= 1.0) {
     596           0 :                                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 64.0 * v->h_ratio[k] * v->pixel_clock[k] / v->no_of_dpp[i][j][k]);
     597             :                                         }
     598             :                                         else {
     599           0 :                                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 64.0 * v->pscl_factor[k] * v->required_dispclk[i][j] / (1 + j));
     600             :                                         }
     601             :                                 }
     602             :                                 else {
     603           0 :                                         if (v->v_ratio[k] <= 1.0) {
     604           0 :                                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 32.0 * v->h_ratio[k] * v->pixel_clock[k] / v->no_of_dpp[i][j][k]);
     605             :                                         }
     606             :                                         else {
     607           0 :                                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 32.0 * v->pscl_factor[k] * v->required_dispclk[i][j] / (1 + j));
     608             :                                         }
     609           0 :                                         if (v->v_ratio[k] / 2.0 <= 1.0) {
     610           0 :                                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 32.0 * v->h_ratio[k] / 2.0 * v->pixel_clock[k] / v->no_of_dpp[i][j][k]);
     611             :                                         }
     612             :                                         else {
     613           0 :                                                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 32.0 * v->pscl_factor_chroma[k] * v->required_dispclk[i][j] / (1 + j));
     614             :                                         }
     615             :                                 }
     616             :                         }
     617           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     618           0 :                                 if (v->dcc_enable[k] == dcn_bw_yes) {
     619           0 :                                         v->meta_req_height_y = 8.0 * v->read256_block_height_y[k];
     620           0 :                                         v->meta_req_width_y = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->meta_req_height_y;
     621           0 :                                         v->meta_surface_width_y =dcn_bw_ceil2(v->viewport_width[k] / v->no_of_dpp[i][j][k] - 1.0, v->meta_req_width_y) + v->meta_req_width_y;
     622           0 :                                         v->meta_surface_height_y =dcn_bw_ceil2(v->viewport_height[k] - 1.0, v->meta_req_height_y) + v->meta_req_height_y;
     623           0 :                                         if (v->pte_enable == dcn_bw_yes) {
     624           0 :                                                 v->meta_pte_bytes_per_frame_y = (dcn_bw_ceil2((v->meta_surface_width_y * v->meta_surface_height_y *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0;
     625             :                                         }
     626             :                                         else {
     627           0 :                                                 v->meta_pte_bytes_per_frame_y = 0.0;
     628             :                                         }
     629           0 :                                         if (v->source_scan[k] == dcn_bw_hor) {
     630           0 :                                                 v->meta_row_bytes_y = v->meta_surface_width_y * v->meta_req_height_y *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 256.0;
     631             :                                         }
     632             :                                         else {
     633           0 :                                                 v->meta_row_bytes_y = v->meta_surface_height_y * v->meta_req_width_y *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 256.0;
     634             :                                         }
     635             :                                 }
     636             :                                 else {
     637           0 :                                         v->meta_pte_bytes_per_frame_y = 0.0;
     638           0 :                                         v->meta_row_bytes_y = 0.0;
     639             :                                 }
     640           0 :                                 if (v->pte_enable == dcn_bw_yes) {
     641           0 :                                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     642           0 :                                                 v->macro_tile_block_size_bytes_y = 256.0;
     643           0 :                                                 v->macro_tile_block_height_y = 1.0;
     644             :                                         }
     645           0 :                                         else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) {
     646           0 :                                                 v->macro_tile_block_size_bytes_y = 4096.0;
     647           0 :                                                 v->macro_tile_block_height_y = 4.0 * v->read256_block_height_y[k];
     648             :                                         }
     649           0 :                                         else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) {
     650           0 :                                                 v->macro_tile_block_size_bytes_y = 64.0 * 1024;
     651           0 :                                                 v->macro_tile_block_height_y = 16.0 * v->read256_block_height_y[k];
     652             :                                         }
     653             :                                         else {
     654           0 :                                                 v->macro_tile_block_size_bytes_y = 256.0 * 1024;
     655           0 :                                                 v->macro_tile_block_height_y = 32.0 * v->read256_block_height_y[k];
     656             :                                         }
     657           0 :                                         if (v->macro_tile_block_size_bytes_y <= 65536.0) {
     658           0 :                                                 v->data_pte_req_height_y = v->macro_tile_block_height_y;
     659             :                                         }
     660             :                                         else {
     661           0 :                                                 v->data_pte_req_height_y = 16.0 * v->read256_block_height_y[k];
     662             :                                         }
     663           0 :                                         v->data_pte_req_width_y = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->data_pte_req_height_y * 8;
     664           0 :                                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     665           0 :                                                 v->dpte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] *dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->data_pte_req_width_y / (v->viewport_width[k] / v->no_of_dpp[i][j][k]), 2.0), 1.0))) - 1.0) / v->data_pte_req_width_y, 1.0) + 1);
     666             :                                         }
     667           0 :                                         else if (v->source_scan[k] == dcn_bw_hor) {
     668           0 :                                                 v->dpte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] - 1.0) / v->data_pte_req_width_y, 1.0) + 1);
     669             :                                         }
     670             :                                         else {
     671           0 :                                                 v->dpte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] - 1.0) / v->data_pte_req_height_y, 1.0) + 1);
     672             :                                         }
     673             :                                 }
     674             :                                 else {
     675           0 :                                         v->dpte_bytes_per_row_y = 0.0;
     676             :                                 }
     677           0 :                                 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) {
     678           0 :                                         if (v->dcc_enable[k] == dcn_bw_yes) {
     679           0 :                                                 v->meta_req_height_c = 8.0 * v->read256_block_height_c[k];
     680           0 :                                                 v->meta_req_width_c = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->meta_req_height_c;
     681           0 :                                                 v->meta_surface_width_c =dcn_bw_ceil2(v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0 - 1.0, v->meta_req_width_c) + v->meta_req_width_c;
     682           0 :                                                 v->meta_surface_height_c =dcn_bw_ceil2(v->viewport_height[k] / 2.0 - 1.0, v->meta_req_height_c) + v->meta_req_height_c;
     683           0 :                                                 if (v->pte_enable == dcn_bw_yes) {
     684           0 :                                                         v->meta_pte_bytes_per_frame_c = (dcn_bw_ceil2((v->meta_surface_width_c * v->meta_surface_height_c *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0;
     685             :                                                 }
     686             :                                                 else {
     687           0 :                                                         v->meta_pte_bytes_per_frame_c = 0.0;
     688             :                                                 }
     689           0 :                                                 if (v->source_scan[k] == dcn_bw_hor) {
     690           0 :                                                         v->meta_row_bytes_c = v->meta_surface_width_c * v->meta_req_height_c *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 256.0;
     691             :                                                 }
     692             :                                                 else {
     693           0 :                                                         v->meta_row_bytes_c = v->meta_surface_height_c * v->meta_req_width_c *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 256.0;
     694             :                                                 }
     695             :                                         }
     696             :                                         else {
     697           0 :                                                 v->meta_pte_bytes_per_frame_c = 0.0;
     698           0 :                                                 v->meta_row_bytes_c = 0.0;
     699             :                                         }
     700           0 :                                         if (v->pte_enable == dcn_bw_yes) {
     701           0 :                                                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     702           0 :                                                         v->macro_tile_block_size_bytes_c = 256.0;
     703           0 :                                                         v->macro_tile_block_height_c = 1.0;
     704             :                                                 }
     705           0 :                                                 else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) {
     706           0 :                                                         v->macro_tile_block_size_bytes_c = 4096.0;
     707           0 :                                                         v->macro_tile_block_height_c = 4.0 * v->read256_block_height_c[k];
     708             :                                                 }
     709           0 :                                                 else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) {
     710           0 :                                                         v->macro_tile_block_size_bytes_c = 64.0 * 1024;
     711           0 :                                                         v->macro_tile_block_height_c = 16.0 * v->read256_block_height_c[k];
     712             :                                                 }
     713             :                                                 else {
     714           0 :                                                         v->macro_tile_block_size_bytes_c = 256.0 * 1024;
     715           0 :                                                         v->macro_tile_block_height_c = 32.0 * v->read256_block_height_c[k];
     716             :                                                 }
     717           0 :                                                 v->macro_tile_block_width_c = v->macro_tile_block_size_bytes_c /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->macro_tile_block_height_c;
     718           0 :                                                 if (v->macro_tile_block_size_bytes_c <= 65536.0) {
     719           0 :                                                         v->data_pte_req_height_c = v->macro_tile_block_height_c;
     720             :                                                 }
     721             :                                                 else {
     722           0 :                                                         v->data_pte_req_height_c = 16.0 * v->read256_block_height_c[k];
     723             :                                                 }
     724           0 :                                                 v->data_pte_req_width_c = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->data_pte_req_height_c * 8;
     725           0 :                                                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
     726           0 :                                                         v->dpte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0 * dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->data_pte_req_width_c / (v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0), 2.0), 1.0))) - 1.0) / v->data_pte_req_width_c, 1.0) + 1);
     727             :                                                 }
     728           0 :                                                 else if (v->source_scan[k] == dcn_bw_hor) {
     729           0 :                                                         v->dpte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0 - 1.0) / v->data_pte_req_width_c, 1.0) + 1);
     730             :                                                 }
     731             :                                                 else {
     732           0 :                                                         v->dpte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] / 2.0 - 1.0) / v->data_pte_req_height_c, 1.0) + 1);
     733             :                                                 }
     734             :                                         }
     735             :                                         else {
     736           0 :                                                 v->dpte_bytes_per_row_c = 0.0;
     737             :                                         }
     738             :                                 }
     739             :                                 else {
     740           0 :                                         v->dpte_bytes_per_row_c = 0.0;
     741           0 :                                         v->meta_pte_bytes_per_frame_c = 0.0;
     742           0 :                                         v->meta_row_bytes_c = 0.0;
     743             :                                 }
     744           0 :                                 v->dpte_bytes_per_row[k] = v->dpte_bytes_per_row_y + v->dpte_bytes_per_row_c;
     745           0 :                                 v->meta_pte_bytes_per_frame[k] = v->meta_pte_bytes_per_frame_y + v->meta_pte_bytes_per_frame_c;
     746           0 :                                 v->meta_row_bytes[k] = v->meta_row_bytes_y + v->meta_row_bytes_c;
     747           0 :                                 v->v_init_y = (v->v_ratio[k] + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k]) / 2.0;
     748           0 :                                 v->prefill_y[k] =dcn_bw_floor2(v->v_init_y, 1.0);
     749           0 :                                 v->max_num_sw_y[k] =dcn_bw_ceil2((v->prefill_y[k] - 1.0) / v->swath_height_yper_state[i][j][k], 1.0) + 1;
     750           0 :                                 if (v->prefill_y[k] > 1.0) {
     751           0 :                                         v->max_partial_sw_y =dcn_bw_mod((v->prefill_y[k] - 2.0), v->swath_height_yper_state[i][j][k]);
     752             :                                 }
     753             :                                 else {
     754           0 :                                         v->max_partial_sw_y =dcn_bw_mod((v->prefill_y[k] + v->swath_height_yper_state[i][j][k] - 2.0), v->swath_height_yper_state[i][j][k]);
     755             :                                 }
     756           0 :                                 v->max_partial_sw_y =dcn_bw_max2(1.0, v->max_partial_sw_y);
     757           0 :                                 v->prefetch_lines_y[k] = v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k] + v->max_partial_sw_y;
     758           0 :                                 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) {
     759           0 :                                         v->v_init_c = (v->v_ratio[k] / 2.0 + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k] / 2.0) / 2.0;
     760           0 :                                         v->prefill_c[k] =dcn_bw_floor2(v->v_init_c, 1.0);
     761           0 :                                         v->max_num_sw_c[k] =dcn_bw_ceil2((v->prefill_c[k] - 1.0) / v->swath_height_cper_state[i][j][k], 1.0) + 1;
     762           0 :                                         if (v->prefill_c[k] > 1.0) {
     763           0 :                                                 v->max_partial_sw_c =dcn_bw_mod((v->prefill_c[k] - 2.0), v->swath_height_cper_state[i][j][k]);
     764             :                                         }
     765             :                                         else {
     766           0 :                                                 v->max_partial_sw_c =dcn_bw_mod((v->prefill_c[k] + v->swath_height_cper_state[i][j][k] - 2.0), v->swath_height_cper_state[i][j][k]);
     767             :                                         }
     768           0 :                                         v->max_partial_sw_c =dcn_bw_max2(1.0, v->max_partial_sw_c);
     769           0 :                                         v->prefetch_lines_c[k] = v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k] + v->max_partial_sw_c;
     770             :                                 }
     771             :                                 else {
     772           0 :                                         v->prefetch_lines_c[k] = 0.0;
     773             :                                 }
     774           0 :                                 v->dst_x_after_scaler = 90.0 * v->pixel_clock[k] / (v->required_dispclk[i][j] / (j + 1)) + 42.0 * v->pixel_clock[k] / v->required_dispclk[i][j];
     775           0 :                                 if (v->no_of_dpp[i][j][k] > 1.0) {
     776           0 :                                         v->dst_x_after_scaler = v->dst_x_after_scaler + v->scaler_rec_out_width[k] / 2.0;
     777             :                                 }
     778           0 :                                 if (v->output_format[k] == dcn_bw_420) {
     779           0 :                                         v->dst_y_after_scaler = 1.0;
     780             :                                 }
     781             :                                 else {
     782           0 :                                         v->dst_y_after_scaler = 0.0;
     783             :                                 }
     784           0 :                                 v->time_calc = 24.0 / v->projected_dcfclk_deep_sleep;
     785           0 :                                 v->v_update_offset[k][j] = dcn_bw_ceil2(v->htotal[k] / 4.0, 1.0);
     786           0 :                                 v->total_repeater_delay = v->max_inter_dcn_tile_repeaters * (2.0 / (v->required_dispclk[i][j] / (j + 1)) + 3.0 / v->required_dispclk[i][j]);
     787           0 :                                 v->v_update_width[k][j] = (14.0 / v->projected_dcfclk_deep_sleep + 12.0 / (v->required_dispclk[i][j] / (j + 1)) + v->total_repeater_delay) * v->pixel_clock[k];
     788           0 :                                 v->v_ready_offset[k][j] = dcn_bw_max2(150.0 / (v->required_dispclk[i][j] / (j + 1)), v->total_repeater_delay + 20.0 / v->projected_dcfclk_deep_sleep + 10.0 / (v->required_dispclk[i][j] / (j + 1))) * v->pixel_clock[k];
     789           0 :                                 v->time_setup = (v->v_update_offset[k][j] + v->v_update_width[k][j] + v->v_ready_offset[k][j]) / v->pixel_clock[k];
     790           0 :                                 v->extra_latency = v->urgent_round_trip_and_out_of_order_latency_per_state[i] + (v->total_number_of_active_dpp[i][j] * v->pixel_chunk_size_in_kbyte + v->total_number_of_dcc_active_dpp[i][j] * v->meta_chunk_size) * 1024.0 / v->return_bw_per_state[i];
     791           0 :                                 if (v->pte_enable == dcn_bw_yes) {
     792           0 :                                         v->extra_latency = v->extra_latency + v->total_number_of_active_dpp[i][j] * v->pte_chunk_size * 1024.0 / v->return_bw_per_state[i];
     793             :                                 }
     794           0 :                                 if (v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes) {
     795           0 :                                         v->maximum_vstartup = v->vtotal[k] - v->vactive[k] - 1.0;
     796             :                                 }
     797             :                                 else {
     798           0 :                                         v->maximum_vstartup = v->v_sync_plus_back_porch[k] - 1.0;
     799             :                                 }
     800             : 
     801             :                                 do {
     802           0 :                                         v->line_times_for_prefetch[k] = v->maximum_vstartup - v->urgent_latency / (v->htotal[k] / v->pixel_clock[k]) - (v->time_calc + v->time_setup) / (v->htotal[k] / v->pixel_clock[k]) - (v->dst_y_after_scaler + v->dst_x_after_scaler / v->htotal[k]);
     803           0 :                                         v->line_times_for_prefetch[k] =dcn_bw_floor2(4.0 * (v->line_times_for_prefetch[k] + 0.125), 1.0) / 4;
     804           0 :                                         v->prefetch_bw[k] = (v->meta_pte_bytes_per_frame[k] + 2.0 * v->meta_row_bytes[k] + 2.0 * v->dpte_bytes_per_row[k] + v->prefetch_lines_y[k] * v->swath_width_yper_state[i][j][k] *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) + v->prefetch_lines_c[k] * v->swath_width_yper_state[i][j][k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0)) / (v->line_times_for_prefetch[k] * v->htotal[k] / v->pixel_clock[k]);
     805             : 
     806           0 :                                         if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) {
     807           0 :                                                 v->time_for_meta_pte_without_immediate_flip = dcn_bw_max3(
     808           0 :                                                                 v->meta_pte_bytes_frame[k] / v->prefetch_bw[k],
     809             :                                                                 v->extra_latency,
     810           0 :                                                                 v->htotal[k] / v->pixel_clock[k] / 4.0);
     811             :                                         } else {
     812           0 :                                                 v->time_for_meta_pte_without_immediate_flip = v->htotal[k] / v->pixel_clock[k] / 4.0;
     813             :                                         }
     814             : 
     815           0 :                                         if (v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes) {
     816           0 :                                                 v->time_for_meta_and_dpte_row_without_immediate_flip = dcn_bw_max3((
     817           0 :                                                                 v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / v->prefetch_bw[k],
     818           0 :                                                                 v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_without_immediate_flip,
     819             :                                                                 v->extra_latency);
     820             :                                         } else {
     821           0 :                                                 v->time_for_meta_and_dpte_row_without_immediate_flip = dcn_bw_max2(
     822           0 :                                                                 v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_without_immediate_flip,
     823           0 :                                                                 v->extra_latency - v->time_for_meta_pte_with_immediate_flip);
     824             :                                         }
     825             : 
     826           0 :                                         v->lines_for_meta_pte_without_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_pte_without_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4;
     827           0 :                                         v->lines_for_meta_and_dpte_row_without_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_and_dpte_row_without_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4;
     828           0 :                                         v->maximum_vstartup = v->maximum_vstartup - 1;
     829             : 
     830           0 :                                         if (v->lines_for_meta_pte_without_immediate_flip[k] < 32.0 && v->lines_for_meta_and_dpte_row_without_immediate_flip[k] < 16.0)
     831             :                                                 break;
     832             : 
     833             :                                 } while(1);
     834             :                         }
     835           0 :                         v->bw_available_for_immediate_flip = v->return_bw_per_state[i];
     836           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     837           0 :                                 v->bw_available_for_immediate_flip = v->bw_available_for_immediate_flip -dcn_bw_max2(v->read_bandwidth[k], v->prefetch_bw[k]);
     838             :                         }
     839           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     840           0 :                                 v->total_immediate_flip_bytes[k] = 0.0;
     841           0 :                                 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
     842           0 :                                         v->total_immediate_flip_bytes[k] = v->total_immediate_flip_bytes[k] + v->meta_pte_bytes_per_frame[k] + v->meta_row_bytes[k] + v->dpte_bytes_per_row[k];
     843             :                                 }
     844             :                         }
     845           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     846           0 :                                 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) {
     847           0 :                                         v->time_for_meta_pte_with_immediate_flip =dcn_bw_max5(v->meta_pte_bytes_per_frame[k] / v->prefetch_bw[k], v->meta_pte_bytes_per_frame[k] * v->total_immediate_flip_bytes[k] / (v->bw_available_for_immediate_flip * (v->meta_pte_bytes_per_frame[k] + v->meta_row_bytes[k] + v->dpte_bytes_per_row[k])), v->extra_latency, v->urgent_latency, v->htotal[k] / v->pixel_clock[k] / 4.0);
     848             :                                 }
     849             :                                 else {
     850           0 :                                         v->time_for_meta_pte_with_immediate_flip = v->htotal[k] / v->pixel_clock[k] / 4.0;
     851             :                                 }
     852           0 :                                 if (v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes) {
     853           0 :                                         v->time_for_meta_and_dpte_row_with_immediate_flip =dcn_bw_max5((v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / v->prefetch_bw[k], (v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) * v->total_immediate_flip_bytes[k] / (v->bw_available_for_immediate_flip * (v->meta_pte_bytes_per_frame[k] + v->meta_row_bytes[k] + v->dpte_bytes_per_row[k])), v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_with_immediate_flip, v->extra_latency, 2.0 * v->urgent_latency);
     854             :                                 }
     855             :                                 else {
     856           0 :                                         v->time_for_meta_and_dpte_row_with_immediate_flip =dcn_bw_max2(v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_with_immediate_flip, v->extra_latency - v->time_for_meta_pte_with_immediate_flip);
     857             :                                 }
     858           0 :                                 v->lines_for_meta_pte_with_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_pte_with_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4;
     859           0 :                                 v->lines_for_meta_and_dpte_row_with_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_and_dpte_row_with_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4;
     860           0 :                                 v->line_times_to_request_prefetch_pixel_data_with_immediate_flip = v->line_times_for_prefetch[k] - v->lines_for_meta_pte_with_immediate_flip[k] - v->lines_for_meta_and_dpte_row_with_immediate_flip[k];
     861           0 :                                 v->line_times_to_request_prefetch_pixel_data_without_immediate_flip = v->line_times_for_prefetch[k] - v->lines_for_meta_pte_without_immediate_flip[k] - v->lines_for_meta_and_dpte_row_without_immediate_flip[k];
     862           0 :                                 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip > 0.0) {
     863           0 :                                         v->v_ratio_pre_ywith_immediate_flip[i][j][k] = v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip;
     864           0 :                                         if ((v->swath_height_yper_state[i][j][k] > 4.0)) {
     865           0 :                                                 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0 > 0.0) {
     866           0 :                                                         v->v_ratio_pre_ywith_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_ywith_immediate_flip[i][j][k], (v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0));
     867             :                                                 }
     868             :                                                 else {
     869           0 :                                                         v->v_ratio_pre_ywith_immediate_flip[i][j][k] = 999999.0;
     870             :                                                 }
     871             :                                         }
     872           0 :                                         v->v_ratio_pre_cwith_immediate_flip[i][j][k] = v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip;
     873           0 :                                         if ((v->swath_height_cper_state[i][j][k] > 4.0)) {
     874           0 :                                                 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0 > 0.0) {
     875           0 :                                                         v->v_ratio_pre_cwith_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_cwith_immediate_flip[i][j][k], (v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0));
     876             :                                                 }
     877             :                                                 else {
     878           0 :                                                         v->v_ratio_pre_cwith_immediate_flip[i][j][k] = 999999.0;
     879             :                                                 }
     880             :                                         }
     881           0 :                                         v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k] = v->no_of_dpp[i][j][k] * (v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) + v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 2.0) * v->swath_width_yper_state[i][j][k] / (v->htotal[k] / v->pixel_clock[k]);
     882             :                                 }
     883             :                                 else {
     884           0 :                                         v->v_ratio_pre_ywith_immediate_flip[i][j][k] = 999999.0;
     885           0 :                                         v->v_ratio_pre_cwith_immediate_flip[i][j][k] = 999999.0;
     886           0 :                                         v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k] = 999999.0;
     887             :                                 }
     888           0 :                                 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip > 0.0) {
     889           0 :                                         v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip;
     890           0 :                                         if ((v->swath_height_yper_state[i][j][k] > 4.0)) {
     891           0 :                                                 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0 > 0.0) {
     892           0 :                                                         v->v_ratio_pre_ywithout_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_ywithout_immediate_flip[i][j][k], (v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0));
     893             :                                                 }
     894             :                                                 else {
     895           0 :                                                         v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = 999999.0;
     896             :                                                 }
     897             :                                         }
     898           0 :                                         v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip;
     899           0 :                                         if ((v->swath_height_cper_state[i][j][k] > 4.0)) {
     900           0 :                                                 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0 > 0.0) {
     901           0 :                                                         v->v_ratio_pre_cwithout_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_cwithout_immediate_flip[i][j][k], (v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0));
     902             :                                                 }
     903             :                                                 else {
     904           0 :                                                         v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = 999999.0;
     905             :                                                 }
     906             :                                         }
     907           0 :                                         v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k] = v->no_of_dpp[i][j][k] * (v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) + v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 2.0) * v->swath_width_yper_state[i][j][k] / (v->htotal[k] / v->pixel_clock[k]);
     908             :                                 }
     909             :                                 else {
     910           0 :                                         v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = 999999.0;
     911           0 :                                         v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = 999999.0;
     912           0 :                                         v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k] = 999999.0;
     913             :                                 }
     914             :                         }
     915           0 :                         v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = 0.0;
     916           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     917           0 :                                 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
     918           0 :                                         v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = v->maximum_read_bandwidth_with_prefetch_with_immediate_flip +dcn_bw_max2(v->read_bandwidth[k], v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k]) +dcn_bw_max2(v->meta_pte_bytes_per_frame[k] / (v->lines_for_meta_pte_with_immediate_flip[k] * v->htotal[k] / v->pixel_clock[k]), (v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / (v->lines_for_meta_and_dpte_row_with_immediate_flip[k] * v->htotal[k] / v->pixel_clock[k]));
     919             :                                 }
     920             :                                 else {
     921           0 :                                         v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = v->maximum_read_bandwidth_with_prefetch_with_immediate_flip +dcn_bw_max2(v->read_bandwidth[k], v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k]);
     922             :                                 }
     923             :                         }
     924           0 :                         v->maximum_read_bandwidth_with_prefetch_without_immediate_flip = 0.0;
     925           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     926           0 :                                 v->maximum_read_bandwidth_with_prefetch_without_immediate_flip = v->maximum_read_bandwidth_with_prefetch_without_immediate_flip +dcn_bw_max2(v->read_bandwidth[k], v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k]);
     927             :                         }
     928           0 :                         v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_yes;
     929           0 :                         if (v->maximum_read_bandwidth_with_prefetch_with_immediate_flip > v->return_bw_per_state[i]) {
     930           0 :                                 v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no;
     931             :                         }
     932           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     933           0 :                                 if (v->line_times_for_prefetch[k] < 2.0 || v->lines_for_meta_pte_with_immediate_flip[k] >= 8.0 || v->lines_for_meta_and_dpte_row_with_immediate_flip[k] >= 16.0) {
     934           0 :                                         v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no;
     935             :                                 }
     936             :                         }
     937           0 :                         v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_yes;
     938           0 :                         if (v->maximum_read_bandwidth_with_prefetch_without_immediate_flip > v->return_bw_per_state[i]) {
     939           0 :                                 v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no;
     940             :                         }
     941           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     942           0 :                                 if (v->line_times_for_prefetch[k] < 2.0 || v->lines_for_meta_pte_without_immediate_flip[k] >= 8.0 || v->lines_for_meta_and_dpte_row_without_immediate_flip[k] >= 16.0) {
     943           0 :                                         v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no;
     944             :                                 }
     945             :                         }
     946             :                 }
     947             :         }
     948           0 :         for (i = 0; i <= number_of_states_plus_one; i++) {
     949           0 :                 for (j = 0; j <= 1; j++) {
     950           0 :                         v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] = dcn_bw_yes;
     951           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     952           0 :                                 if ((((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10) && (v->v_ratio_pre_ywith_immediate_flip[i][j][k] > 4.0 || v->v_ratio_pre_cwith_immediate_flip[i][j][k] > 4.0)) || ((v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 || v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) && (v->v_ratio_pre_ywithout_immediate_flip[i][j][k] > 4.0 || v->v_ratio_pre_cwithout_immediate_flip[i][j][k] > 4.0)))) {
     953           0 :                                         v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no;
     954             :                                 }
     955             :                         }
     956           0 :                         v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] = dcn_bw_yes;
     957           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
     958           0 :                                 if ((v->v_ratio_pre_ywithout_immediate_flip[i][j][k] > 4.0 || v->v_ratio_pre_cwithout_immediate_flip[i][j][k] > 4.0)) {
     959           0 :                                         v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no;
     960             :                                 }
     961             :                         }
     962             :                 }
     963             :         }
     964             :         /*mode support, voltage state and soc configuration*/
     965             : 
     966           0 :         for (i = number_of_states_plus_one; i >= 0; i--) {
     967           0 :                 for (j = 0; j <= 1; j++) {
     968           0 :                         if (v->scale_ratio_support == dcn_bw_yes && v->source_format_pixel_and_scan_support == dcn_bw_yes && v->viewport_size_support == dcn_bw_yes && v->bandwidth_support[i] == dcn_bw_yes && v->dio_support[i] == dcn_bw_yes && v->urgent_latency_support[i][j] == dcn_bw_yes && v->rob_support[i] == dcn_bw_yes && v->dispclk_dppclk_support[i][j] == dcn_bw_yes && v->total_available_pipes_support[i][j] == dcn_bw_yes && v->total_available_writeback_support == dcn_bw_yes && v->writeback_latency_support == dcn_bw_yes) {
     969           0 :                                 if (v->prefetch_supported_with_immediate_flip[i][j] == dcn_bw_yes && v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] == dcn_bw_yes) {
     970           0 :                                         v->mode_support_with_immediate_flip[i][j] = dcn_bw_yes;
     971             :                                 }
     972             :                                 else {
     973           0 :                                         v->mode_support_with_immediate_flip[i][j] = dcn_bw_no;
     974             :                                 }
     975           0 :                                 if (v->prefetch_supported_without_immediate_flip[i][j] == dcn_bw_yes && v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] == dcn_bw_yes) {
     976           0 :                                         v->mode_support_without_immediate_flip[i][j] = dcn_bw_yes;
     977             :                                 }
     978             :                                 else {
     979           0 :                                         v->mode_support_without_immediate_flip[i][j] = dcn_bw_no;
     980             :                                 }
     981             :                         }
     982             :                         else {
     983           0 :                                 v->mode_support_with_immediate_flip[i][j] = dcn_bw_no;
     984           0 :                                 v->mode_support_without_immediate_flip[i][j] = dcn_bw_no;
     985             :                         }
     986             :                 }
     987             :         }
     988           0 :         for (i = number_of_states_plus_one; i >= 0; i--) {
     989           0 :                 if ((i == number_of_states_plus_one || v->mode_support_with_immediate_flip[i][1] == dcn_bw_yes || v->mode_support_with_immediate_flip[i][0] == dcn_bw_yes) && i >= v->voltage_override_level) {
     990           0 :                         v->voltage_level_with_immediate_flip = i;
     991             :                 }
     992             :         }
     993           0 :         for (i = number_of_states_plus_one; i >= 0; i--) {
     994           0 :                 if ((i == number_of_states_plus_one || v->mode_support_without_immediate_flip[i][1] == dcn_bw_yes || v->mode_support_without_immediate_flip[i][0] == dcn_bw_yes) && i >= v->voltage_override_level) {
     995           0 :                         v->voltage_level_without_immediate_flip = i;
     996             :                 }
     997             :         }
     998           0 :         if (v->voltage_level_with_immediate_flip == number_of_states_plus_one) {
     999           0 :                 v->immediate_flip_supported = dcn_bw_no;
    1000           0 :                 v->voltage_level = v->voltage_level_without_immediate_flip;
    1001             :         }
    1002             :         else {
    1003           0 :                 v->immediate_flip_supported = dcn_bw_yes;
    1004           0 :                 v->voltage_level = v->voltage_level_with_immediate_flip;
    1005             :         }
    1006           0 :         v->dcfclk = v->dcfclk_per_state[v->voltage_level];
    1007           0 :         v->fabric_and_dram_bandwidth = v->fabric_and_dram_bandwidth_per_state[v->voltage_level];
    1008           0 :         for (j = 0; j <= 1; j++) {
    1009           0 :                 v->required_dispclk_per_ratio[j] = v->required_dispclk[v->voltage_level][j];
    1010           0 :                 for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1011           0 :                         v->dpp_per_plane_per_ratio[j][k] = v->no_of_dpp[v->voltage_level][j][k];
    1012             :                 }
    1013           0 :                 v->dispclk_dppclk_support_per_ratio[j] = v->dispclk_dppclk_support[v->voltage_level][j];
    1014             :         }
    1015           0 :         v->max_phyclk = v->phyclk_per_state[v->voltage_level];
    1016           0 : }
    1017           0 : void display_pipe_configuration(struct dcn_bw_internal_vars *v)
    1018             : {
    1019             :         int j;
    1020             :         int k;
    1021             :         /*display pipe configuration*/
    1022             : 
    1023           0 :         for (j = 0; j <= 1; j++) {
    1024           0 :                 v->total_number_of_active_dpp_per_ratio[j] = 0.0;
    1025           0 :                 for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1026           0 :                         v->total_number_of_active_dpp_per_ratio[j] = v->total_number_of_active_dpp_per_ratio[j] + v->dpp_per_plane_per_ratio[j][k];
    1027             :                 }
    1028             :         }
    1029           0 :         if ((v->dispclk_dppclk_support_per_ratio[0] == dcn_bw_yes && v->dispclk_dppclk_support_per_ratio[1] == dcn_bw_no) || (v->dispclk_dppclk_support_per_ratio[0] == v->dispclk_dppclk_support_per_ratio[1] && (v->total_number_of_active_dpp_per_ratio[0] < v->total_number_of_active_dpp_per_ratio[1] || (((v->total_number_of_active_dpp_per_ratio[0] == v->total_number_of_active_dpp_per_ratio[1]) && v->required_dispclk_per_ratio[0] <= 0.5 * v->required_dispclk_per_ratio[1]))))) {
    1030           0 :                 v->dispclk_dppclk_ratio = 1;
    1031           0 :                 v->final_error_message = v->error_message[0];
    1032             :         }
    1033             :         else {
    1034           0 :                 v->dispclk_dppclk_ratio = 2;
    1035           0 :                 v->final_error_message = v->error_message[1];
    1036             :         }
    1037           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1038           0 :                 v->dpp_per_plane[k] = v->dpp_per_plane_per_ratio[v->dispclk_dppclk_ratio - 1][k];
    1039             :         }
    1040           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1041           0 :                 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
    1042           0 :                         v->byte_per_pix_dety = 8.0;
    1043           0 :                         v->byte_per_pix_detc = 0.0;
    1044             :                 }
    1045           0 :                 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) {
    1046           0 :                         v->byte_per_pix_dety = 4.0;
    1047           0 :                         v->byte_per_pix_detc = 0.0;
    1048             :                 }
    1049           0 :                 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
    1050           0 :                         v->byte_per_pix_dety = 2.0;
    1051           0 :                         v->byte_per_pix_detc = 0.0;
    1052             :                 }
    1053           0 :                 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
    1054           0 :                         v->byte_per_pix_dety = 1.0;
    1055           0 :                         v->byte_per_pix_detc = 2.0;
    1056             :                 }
    1057             :                 else {
    1058           0 :                         v->byte_per_pix_dety = 4.0f / 3.0f;
    1059           0 :                         v->byte_per_pix_detc = 8.0f / 3.0f;
    1060             :                 }
    1061           0 :                 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) {
    1062           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1063           0 :                                 v->read256_bytes_block_height_y = 1.0;
    1064             :                         }
    1065           0 :                         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
    1066           0 :                                 v->read256_bytes_block_height_y = 4.0;
    1067             :                         }
    1068             :                         else {
    1069           0 :                                 v->read256_bytes_block_height_y = 8.0;
    1070             :                         }
    1071           0 :                         v->read256_bytes_block_width_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->read256_bytes_block_height_y;
    1072           0 :                         v->read256_bytes_block_height_c = 0.0;
    1073           0 :                         v->read256_bytes_block_width_c = 0.0;
    1074             :                 }
    1075             :                 else {
    1076           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1077           0 :                                 v->read256_bytes_block_height_y = 1.0;
    1078           0 :                                 v->read256_bytes_block_height_c = 1.0;
    1079             :                         }
    1080           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
    1081           0 :                                 v->read256_bytes_block_height_y = 16.0;
    1082           0 :                                 v->read256_bytes_block_height_c = 8.0;
    1083             :                         }
    1084             :                         else {
    1085           0 :                                 v->read256_bytes_block_height_y = 8.0;
    1086           0 :                                 v->read256_bytes_block_height_c = 8.0;
    1087             :                         }
    1088           0 :                         v->read256_bytes_block_width_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->read256_bytes_block_height_y;
    1089           0 :                         v->read256_bytes_block_width_c = 256.0 /dcn_bw_ceil2(v->byte_per_pix_detc, 2.0) / v->read256_bytes_block_height_c;
    1090             :                 }
    1091           0 :                 if (v->source_scan[k] == dcn_bw_hor) {
    1092           0 :                         v->maximum_swath_height_y = v->read256_bytes_block_height_y;
    1093           0 :                         v->maximum_swath_height_c = v->read256_bytes_block_height_c;
    1094             :                 }
    1095             :                 else {
    1096           0 :                         v->maximum_swath_height_y = v->read256_bytes_block_width_y;
    1097           0 :                         v->maximum_swath_height_c = v->read256_bytes_block_width_c;
    1098             :                 }
    1099           0 :                 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) {
    1100           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear || (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 && (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_var_s || v->source_surface_mode[k] == dcn_bw_sw_var_s_x) && v->source_scan[k] == dcn_bw_hor)) {
    1101           0 :                                 v->minimum_swath_height_y = v->maximum_swath_height_y;
    1102             :                         }
    1103             :                         else {
    1104           0 :                                 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0;
    1105             :                         }
    1106           0 :                         v->minimum_swath_height_c = v->maximum_swath_height_c;
    1107             :                 }
    1108             :                 else {
    1109           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1110           0 :                                 v->minimum_swath_height_y = v->maximum_swath_height_y;
    1111           0 :                                 v->minimum_swath_height_c = v->maximum_swath_height_c;
    1112             :                         }
    1113           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 && v->source_scan[k] == dcn_bw_hor) {
    1114           0 :                                 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0;
    1115           0 :                                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
    1116           0 :                                         v->minimum_swath_height_c = v->maximum_swath_height_c;
    1117             :                                 }
    1118             :                                 else {
    1119           0 :                                         v->minimum_swath_height_c = v->maximum_swath_height_c / 2.0;
    1120             :                                 }
    1121             :                         }
    1122           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10 && v->source_scan[k] == dcn_bw_hor) {
    1123           0 :                                 v->minimum_swath_height_c = v->maximum_swath_height_c / 2.0;
    1124           0 :                                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
    1125           0 :                                         v->minimum_swath_height_y = v->maximum_swath_height_y;
    1126             :                                 }
    1127             :                                 else {
    1128           0 :                                         v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0;
    1129             :                                 }
    1130             :                         }
    1131             :                         else {
    1132           0 :                                 v->minimum_swath_height_y = v->maximum_swath_height_y;
    1133           0 :                                 v->minimum_swath_height_c = v->maximum_swath_height_c;
    1134             :                         }
    1135             :                 }
    1136           0 :                 if (v->source_scan[k] == dcn_bw_hor) {
    1137           0 :                         v->swath_width = v->viewport_width[k] / v->dpp_per_plane[k];
    1138             :                 }
    1139             :                 else {
    1140           0 :                         v->swath_width = v->viewport_height[k] / v->dpp_per_plane[k];
    1141             :                 }
    1142           0 :                 v->swath_width_granularity_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->maximum_swath_height_y;
    1143           0 :                 v->rounded_up_max_swath_size_bytes_y = (dcn_bw_ceil2(v->swath_width - 1.0, v->swath_width_granularity_y) + v->swath_width_granularity_y) * v->byte_per_pix_dety * v->maximum_swath_height_y;
    1144           0 :                 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
    1145           0 :                         v->rounded_up_max_swath_size_bytes_y =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_y, 256.0) + 256;
    1146             :                 }
    1147           0 :                 if (v->maximum_swath_height_c > 0.0) {
    1148           0 :                         v->swath_width_granularity_c = 256.0 /dcn_bw_ceil2(v->byte_per_pix_detc, 2.0) / v->maximum_swath_height_c;
    1149             :                 }
    1150           0 :                 v->rounded_up_max_swath_size_bytes_c = (dcn_bw_ceil2(v->swath_width / 2.0 - 1.0, v->swath_width_granularity_c) + v->swath_width_granularity_c) * v->byte_per_pix_detc * v->maximum_swath_height_c;
    1151           0 :                 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
    1152           0 :                         v->rounded_up_max_swath_size_bytes_c =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_c, 256.0) + 256;
    1153             :                 }
    1154           0 :                 if (v->rounded_up_max_swath_size_bytes_y + v->rounded_up_max_swath_size_bytes_c <= v->det_buffer_size_in_kbyte * 1024.0 / 2.0) {
    1155           0 :                         v->swath_height_y[k] = v->maximum_swath_height_y;
    1156           0 :                         v->swath_height_c[k] = v->maximum_swath_height_c;
    1157             :                 }
    1158             :                 else {
    1159           0 :                         v->swath_height_y[k] = v->minimum_swath_height_y;
    1160           0 :                         v->swath_height_c[k] = v->minimum_swath_height_c;
    1161             :                 }
    1162           0 :                 if (v->swath_height_c[k] == 0.0) {
    1163           0 :                         v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0;
    1164           0 :                         v->det_buffer_size_c[k] = 0.0;
    1165             :                 }
    1166           0 :                 else if (v->swath_height_y[k] <= v->swath_height_c[k]) {
    1167           0 :                         v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0 / 2.0;
    1168           0 :                         v->det_buffer_size_c[k] = v->det_buffer_size_in_kbyte * 1024.0 / 2.0;
    1169             :                 }
    1170             :                 else {
    1171           0 :                         v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0 * 2.0 / 3.0;
    1172           0 :                         v->det_buffer_size_c[k] = v->det_buffer_size_in_kbyte * 1024.0 / 3.0;
    1173             :                 }
    1174             :         }
    1175           0 : }
    1176           0 : void dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(struct dcn_bw_internal_vars *v)
    1177             : {
    1178             :         int k;
    1179             :         /*dispclk and dppclk calculation*/
    1180             : 
    1181           0 :         v->dispclk_with_ramping = 0.0;
    1182           0 :         v->dispclk_without_ramping = 0.0;
    1183           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1184           0 :                 if (v->h_ratio[k] > 1.0) {
    1185           0 :                         v->pscl_throughput[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] /dcn_bw_ceil2(v->htaps[k] / 6.0, 1.0));
    1186             :                 }
    1187             :                 else {
    1188           0 :                         v->pscl_throughput[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
    1189             :                 }
    1190           0 :                 v->dppclk_using_single_dpp_luma = v->pixel_clock[k] *dcn_bw_max3(v->vtaps[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k]), v->h_ratio[k] * v->v_ratio[k] / v->pscl_throughput[k], 1.0);
    1191           0 :                 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
    1192           0 :                         v->pscl_throughput_chroma[k] = 0.0;
    1193           0 :                         v->dppclk_using_single_dpp = v->dppclk_using_single_dpp_luma;
    1194             :                 }
    1195             :                 else {
    1196           0 :                         if (v->h_ratio[k] > 1.0) {
    1197           0 :                                 v->pscl_throughput_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] / 2.0 /dcn_bw_ceil2(v->hta_pschroma[k] / 6.0, 1.0));
    1198             :                         }
    1199             :                         else {
    1200           0 :                                 v->pscl_throughput_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
    1201             :                         }
    1202           0 :                         v->dppclk_using_single_dpp_chroma = v->pixel_clock[k] *dcn_bw_max3(v->vta_pschroma[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k] / 2.0), v->h_ratio[k] * v->v_ratio[k] / 4.0 / v->pscl_throughput_chroma[k], 1.0);
    1203           0 :                         v->dppclk_using_single_dpp =dcn_bw_max2(v->dppclk_using_single_dpp_luma, v->dppclk_using_single_dpp_chroma);
    1204             :                 }
    1205           0 :                 if (v->odm_capable == dcn_bw_yes) {
    1206           0 :                         v->dispclk_with_ramping =dcn_bw_max2(v->dispclk_with_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k] / v->dpp_per_plane[k]) * (1.0 + v->downspreading / 100.0) * (1.0 + v->dispclk_ramping_margin / 100.0));
    1207           0 :                         v->dispclk_without_ramping =dcn_bw_max2(v->dispclk_without_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k] / v->dpp_per_plane[k]) * (1.0 + v->downspreading / 100.0));
    1208             :                 }
    1209             :                 else {
    1210           0 :                         v->dispclk_with_ramping =dcn_bw_max2(v->dispclk_with_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k]) * (1.0 + v->downspreading / 100.0) * (1.0 + v->dispclk_ramping_margin / 100.0));
    1211           0 :                         v->dispclk_without_ramping =dcn_bw_max2(v->dispclk_without_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k]) * (1.0 + v->downspreading / 100.0));
    1212             :                 }
    1213             :         }
    1214           0 :         if (v->dispclk_without_ramping > v->max_dispclk[number_of_states]) {
    1215           0 :                 v->dispclk = v->dispclk_without_ramping;
    1216             :         }
    1217           0 :         else if (v->dispclk_with_ramping > v->max_dispclk[number_of_states]) {
    1218           0 :                 v->dispclk = v->max_dispclk[number_of_states];
    1219             :         }
    1220             :         else {
    1221           0 :                 v->dispclk = v->dispclk_with_ramping;
    1222             :         }
    1223           0 :         v->dppclk = v->dispclk / v->dispclk_dppclk_ratio;
    1224             :         /*urgent watermark*/
    1225             : 
    1226           0 :         v->return_bandwidth_to_dcn =dcn_bw_min2(v->return_bus_width * v->dcfclk, v->fabric_and_dram_bandwidth * 1000.0 * v->percent_of_ideal_drambw_received_after_urg_latency / 100.0);
    1227           0 :         v->dcc_enabled_any_plane = dcn_bw_no;
    1228           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1229           0 :                 if (v->dcc_enable[k] == dcn_bw_yes) {
    1230           0 :                         v->dcc_enabled_any_plane = dcn_bw_yes;
    1231             :                 }
    1232             :         }
    1233           0 :         v->return_bw = v->return_bandwidth_to_dcn;
    1234           0 :         if (v->dcc_enabled_any_plane == dcn_bw_yes && v->return_bandwidth_to_dcn > v->dcfclk * v->return_bus_width / 4.0) {
    1235           0 :                 v->return_bw =dcn_bw_min2(v->return_bw, v->return_bandwidth_to_dcn * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bandwidth_to_dcn - v->dcfclk * v->return_bus_width / 4.0) + v->urgent_latency)));
    1236             :         }
    1237           0 :         v->critical_compression = 2.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0);
    1238           0 :         if (v->dcc_enabled_any_plane == dcn_bw_yes && v->critical_compression > 1.0 && v->critical_compression < 4.0) {
    1239           0 :                 v->return_bw =dcn_bw_min2(v->return_bw, dcn_bw_pow(4.0 * v->return_bandwidth_to_dcn * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2));
    1240             :         }
    1241           0 :         v->return_bandwidth_to_dcn =dcn_bw_min2(v->return_bus_width * v->dcfclk, v->fabric_and_dram_bandwidth * 1000.0);
    1242           0 :         if (v->dcc_enabled_any_plane == dcn_bw_yes && v->return_bandwidth_to_dcn > v->dcfclk * v->return_bus_width / 4.0) {
    1243           0 :                 v->return_bw =dcn_bw_min2(v->return_bw, v->return_bandwidth_to_dcn * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bandwidth_to_dcn - v->dcfclk * v->return_bus_width / 4.0) + v->urgent_latency)));
    1244             :         }
    1245           0 :         v->critical_compression = 2.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0);
    1246           0 :         if (v->dcc_enabled_any_plane == dcn_bw_yes && v->critical_compression > 1.0 && v->critical_compression < 4.0) {
    1247           0 :                 v->return_bw =dcn_bw_min2(v->return_bw, dcn_bw_pow(4.0 * v->return_bandwidth_to_dcn * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2));
    1248             :         }
    1249           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1250           0 :                 if (v->source_scan[k] == dcn_bw_hor) {
    1251           0 :                         v->swath_width_y[k] = v->viewport_width[k] / v->dpp_per_plane[k];
    1252             :                 }
    1253             :                 else {
    1254           0 :                         v->swath_width_y[k] = v->viewport_height[k] / v->dpp_per_plane[k];
    1255             :                 }
    1256             :         }
    1257           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1258           0 :                 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
    1259           0 :                         v->byte_per_pixel_dety[k] = 8.0;
    1260           0 :                         v->byte_per_pixel_detc[k] = 0.0;
    1261             :                 }
    1262           0 :                 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) {
    1263           0 :                         v->byte_per_pixel_dety[k] = 4.0;
    1264           0 :                         v->byte_per_pixel_detc[k] = 0.0;
    1265             :                 }
    1266           0 :                 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
    1267           0 :                         v->byte_per_pixel_dety[k] = 2.0;
    1268           0 :                         v->byte_per_pixel_detc[k] = 0.0;
    1269             :                 }
    1270           0 :                 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
    1271           0 :                         v->byte_per_pixel_dety[k] = 1.0;
    1272           0 :                         v->byte_per_pixel_detc[k] = 2.0;
    1273             :                 }
    1274             :                 else {
    1275           0 :                         v->byte_per_pixel_dety[k] = 4.0f / 3.0f;
    1276           0 :                         v->byte_per_pixel_detc[k] = 8.0f / 3.0f;
    1277             :                 }
    1278             :         }
    1279           0 :         v->total_data_read_bandwidth = 0.0;
    1280           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1281           0 :                 v->read_bandwidth_plane_luma[k] = v->swath_width_y[k] * v->dpp_per_plane[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / (v->htotal[k] / v->pixel_clock[k]) * v->v_ratio[k];
    1282           0 :                 v->read_bandwidth_plane_chroma[k] = v->swath_width_y[k] / 2.0 * v->dpp_per_plane[k] *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / (v->htotal[k] / v->pixel_clock[k]) * v->v_ratio[k] / 2.0;
    1283           0 :                 v->total_data_read_bandwidth = v->total_data_read_bandwidth + v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k];
    1284             :         }
    1285           0 :         v->total_active_dpp = 0.0;
    1286           0 :         v->total_dcc_active_dpp = 0.0;
    1287           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1288           0 :                 v->total_active_dpp = v->total_active_dpp + v->dpp_per_plane[k];
    1289           0 :                 if (v->dcc_enable[k] == dcn_bw_yes) {
    1290           0 :                         v->total_dcc_active_dpp = v->total_dcc_active_dpp + v->dpp_per_plane[k];
    1291             :                 }
    1292             :         }
    1293           0 :         v->urgent_round_trip_and_out_of_order_latency = (v->round_trip_ping_latency_cycles + 32.0) / v->dcfclk + v->urgent_out_of_order_return_per_channel * v->number_of_channels / v->return_bw;
    1294           0 :         v->last_pixel_of_line_extra_watermark = 0.0;
    1295           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1296           0 :                 if (v->v_ratio[k] <= 1.0) {
    1297           0 :                         v->display_pipe_line_delivery_time_luma[k] = v->swath_width_y[k] * v->dpp_per_plane[k] / v->h_ratio[k] / v->pixel_clock[k];
    1298             :                 }
    1299             :                 else {
    1300           0 :                         v->display_pipe_line_delivery_time_luma[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk;
    1301             :                 }
    1302           0 :                 v->data_fabric_line_delivery_time_luma = v->swath_width_y[k] * v->swath_height_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / (v->return_bw * v->read_bandwidth_plane_luma[k] / v->dpp_per_plane[k] / v->total_data_read_bandwidth);
    1303           0 :                 v->last_pixel_of_line_extra_watermark =dcn_bw_max2(v->last_pixel_of_line_extra_watermark, v->data_fabric_line_delivery_time_luma - v->display_pipe_line_delivery_time_luma[k]);
    1304           0 :                 if (v->byte_per_pixel_detc[k] == 0.0) {
    1305           0 :                         v->display_pipe_line_delivery_time_chroma[k] = 0.0;
    1306             :                 }
    1307             :                 else {
    1308           0 :                         if (v->v_ratio[k] / 2.0 <= 1.0) {
    1309           0 :                                 v->display_pipe_line_delivery_time_chroma[k] = v->swath_width_y[k] / 2.0 * v->dpp_per_plane[k] / (v->h_ratio[k] / 2.0) / v->pixel_clock[k];
    1310             :                         }
    1311             :                         else {
    1312           0 :                                 v->display_pipe_line_delivery_time_chroma[k] = v->swath_width_y[k] / 2.0 / v->pscl_throughput_chroma[k] / v->dppclk;
    1313             :                         }
    1314           0 :                         v->data_fabric_line_delivery_time_chroma = v->swath_width_y[k] / 2.0 * v->swath_height_c[k] *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / (v->return_bw * v->read_bandwidth_plane_chroma[k] / v->dpp_per_plane[k] / v->total_data_read_bandwidth);
    1315           0 :                         v->last_pixel_of_line_extra_watermark =dcn_bw_max2(v->last_pixel_of_line_extra_watermark, v->data_fabric_line_delivery_time_chroma - v->display_pipe_line_delivery_time_chroma[k]);
    1316             :                 }
    1317             :         }
    1318           0 :         v->urgent_extra_latency = v->urgent_round_trip_and_out_of_order_latency + (v->total_active_dpp * v->pixel_chunk_size_in_kbyte + v->total_dcc_active_dpp * v->meta_chunk_size) * 1024.0 / v->return_bw;
    1319           0 :         if (v->pte_enable == dcn_bw_yes) {
    1320           0 :                 v->urgent_extra_latency = v->urgent_extra_latency + v->total_active_dpp * v->pte_chunk_size * 1024.0 / v->return_bw;
    1321             :         }
    1322           0 :         v->urgent_watermark = v->urgent_latency + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency;
    1323           0 :         v->ptemeta_urgent_watermark = v->urgent_watermark + 2.0 * v->urgent_latency;
    1324             :         /*nb p-state/dram clock change watermark*/
    1325             : 
    1326           0 :         v->dram_clock_change_watermark = v->dram_clock_change_latency + v->urgent_watermark;
    1327           0 :         v->total_active_writeback = 0.0;
    1328           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1329           0 :                 if (v->output[k] == dcn_bw_writeback) {
    1330           0 :                         v->total_active_writeback = v->total_active_writeback + 1.0;
    1331             :                 }
    1332             :         }
    1333           0 :         if (v->total_active_writeback <= 1.0) {
    1334           0 :                 v->writeback_dram_clock_change_watermark = v->dram_clock_change_latency + v->write_back_latency;
    1335             :         }
    1336             :         else {
    1337           0 :                 v->writeback_dram_clock_change_watermark = v->dram_clock_change_latency + v->write_back_latency + v->writeback_chunk_size * 1024.0 / 32.0 / v->socclk;
    1338             :         }
    1339             :         /*stutter efficiency*/
    1340             : 
    1341           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1342           0 :                 v->lines_in_dety[k] = v->det_buffer_size_y[k] / v->byte_per_pixel_dety[k] / v->swath_width_y[k];
    1343           0 :                 v->lines_in_dety_rounded_down_to_swath[k] =dcn_bw_floor2(v->lines_in_dety[k], v->swath_height_y[k]);
    1344           0 :                 v->full_det_buffering_time_y[k] = v->lines_in_dety_rounded_down_to_swath[k] * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k];
    1345           0 :                 if (v->byte_per_pixel_detc[k] > 0.0) {
    1346           0 :                         v->lines_in_detc[k] = v->det_buffer_size_c[k] / v->byte_per_pixel_detc[k] / (v->swath_width_y[k] / 2.0);
    1347           0 :                         v->lines_in_detc_rounded_down_to_swath[k] =dcn_bw_floor2(v->lines_in_detc[k], v->swath_height_c[k]);
    1348           0 :                         v->full_det_buffering_time_c[k] = v->lines_in_detc_rounded_down_to_swath[k] * (v->htotal[k] / v->pixel_clock[k]) / (v->v_ratio[k] / 2.0);
    1349             :                 }
    1350             :                 else {
    1351           0 :                         v->lines_in_detc[k] = 0.0;
    1352           0 :                         v->lines_in_detc_rounded_down_to_swath[k] = 0.0;
    1353           0 :                         v->full_det_buffering_time_c[k] = 999999.0;
    1354             :                 }
    1355             :         }
    1356           0 :         v->min_full_det_buffering_time = 999999.0;
    1357           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1358           0 :                 if (v->full_det_buffering_time_y[k] < v->min_full_det_buffering_time) {
    1359           0 :                         v->min_full_det_buffering_time = v->full_det_buffering_time_y[k];
    1360           0 :                         v->frame_time_for_min_full_det_buffering_time = v->vtotal[k] * v->htotal[k] / v->pixel_clock[k];
    1361             :                 }
    1362           0 :                 if (v->full_det_buffering_time_c[k] < v->min_full_det_buffering_time) {
    1363           0 :                         v->min_full_det_buffering_time = v->full_det_buffering_time_c[k];
    1364           0 :                         v->frame_time_for_min_full_det_buffering_time = v->vtotal[k] * v->htotal[k] / v->pixel_clock[k];
    1365             :                 }
    1366             :         }
    1367           0 :         v->average_read_bandwidth_gbyte_per_second = 0.0;
    1368           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1369           0 :                 if (v->dcc_enable[k] == dcn_bw_yes) {
    1370           0 :                         v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / v->dcc_rate[k] / 1000.0 + v->read_bandwidth_plane_chroma[k] / v->dcc_rate[k] / 1000.0;
    1371             :                 }
    1372             :                 else {
    1373           0 :                         v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / 1000.0 + v->read_bandwidth_plane_chroma[k] / 1000.0;
    1374             :                 }
    1375           0 :                 if (v->dcc_enable[k] == dcn_bw_yes) {
    1376           0 :                         v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / 1000.0 / 256.0 + v->read_bandwidth_plane_chroma[k] / 1000.0 / 256.0;
    1377             :                 }
    1378           0 :                 if (v->pte_enable == dcn_bw_yes) {
    1379           0 :                         v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / 1000.0 / 512.0 + v->read_bandwidth_plane_chroma[k] / 1000.0 / 512.0;
    1380             :                 }
    1381             :         }
    1382           0 :         v->part_of_burst_that_fits_in_rob =dcn_bw_min2(v->min_full_det_buffering_time * v->total_data_read_bandwidth, v->rob_buffer_size_in_kbyte * 1024.0 * v->total_data_read_bandwidth / (v->average_read_bandwidth_gbyte_per_second * 1000.0));
    1383           0 :         v->stutter_burst_time = v->part_of_burst_that_fits_in_rob * (v->average_read_bandwidth_gbyte_per_second * 1000.0) / v->total_data_read_bandwidth / v->return_bw + (v->min_full_det_buffering_time * v->total_data_read_bandwidth - v->part_of_burst_that_fits_in_rob) / (v->dcfclk * 64.0);
    1384           0 :         if (v->total_active_writeback == 0.0) {
    1385           0 :                 v->stutter_efficiency_not_including_vblank = (1.0 - (v->sr_exit_time + v->stutter_burst_time) / v->min_full_det_buffering_time) * 100.0;
    1386             :         }
    1387             :         else {
    1388           0 :                 v->stutter_efficiency_not_including_vblank = 0.0;
    1389             :         }
    1390           0 :         v->smallest_vblank = 999999.0;
    1391           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1392           0 :                 if (v->synchronized_vblank == dcn_bw_yes || v->number_of_active_planes == 1) {
    1393           0 :                         v->v_blank_time = (v->vtotal[k] - v->vactive[k]) * v->htotal[k] / v->pixel_clock[k];
    1394             :                 }
    1395             :                 else {
    1396           0 :                         v->v_blank_time = 0.0;
    1397             :                 }
    1398           0 :                 v->smallest_vblank =dcn_bw_min2(v->smallest_vblank, v->v_blank_time);
    1399             :         }
    1400           0 :         v->stutter_efficiency = (v->stutter_efficiency_not_including_vblank / 100.0 * (v->frame_time_for_min_full_det_buffering_time - v->smallest_vblank) + v->smallest_vblank) / v->frame_time_for_min_full_det_buffering_time * 100.0;
    1401             :         /*dcfclk deep sleep*/
    1402             : 
    1403           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1404           0 :                 if (v->byte_per_pixel_detc[k] > 0.0) {
    1405           0 :                         v->dcfclk_deep_sleep_per_plane[k] =dcn_bw_max2(1.1 * v->swath_width_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 32.0 / v->display_pipe_line_delivery_time_luma[k], 1.1 * v->swath_width_y[k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 32.0 / v->display_pipe_line_delivery_time_chroma[k]);
    1406             :                 }
    1407             :                 else {
    1408           0 :                         v->dcfclk_deep_sleep_per_plane[k] = 1.1 * v->swath_width_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 64.0 / v->display_pipe_line_delivery_time_luma[k];
    1409             :                 }
    1410           0 :                 v->dcfclk_deep_sleep_per_plane[k] =dcn_bw_max2(v->dcfclk_deep_sleep_per_plane[k], v->pixel_clock[k] / 16.0);
    1411             :         }
    1412           0 :         v->dcf_clk_deep_sleep = 8.0;
    1413           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1414           0 :                 v->dcf_clk_deep_sleep =dcn_bw_max2(v->dcf_clk_deep_sleep, v->dcfclk_deep_sleep_per_plane[k]);
    1415             :         }
    1416             :         /*stutter watermark*/
    1417             : 
    1418           0 :         v->stutter_exit_watermark = v->sr_exit_time + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency + 10.0 / v->dcf_clk_deep_sleep;
    1419           0 :         v->stutter_enter_plus_exit_watermark = v->sr_enter_plus_exit_time + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency;
    1420             :         /*urgent latency supported*/
    1421             : 
    1422           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1423           0 :                 v->effective_det_plus_lb_lines_luma =dcn_bw_floor2(v->lines_in_dety[k] +dcn_bw_min2(v->lines_in_dety[k] * v->dppclk * v->byte_per_pixel_dety[k] * v->pscl_throughput[k] / (v->return_bw / v->dpp_per_plane[k]), v->effective_lb_latency_hiding_source_lines_luma), v->swath_height_y[k]);
    1424           0 :                 v->urgent_latency_support_us_luma = v->effective_det_plus_lb_lines_luma * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k] - v->effective_det_plus_lb_lines_luma * v->swath_width_y[k] * v->byte_per_pixel_dety[k] / (v->return_bw / v->dpp_per_plane[k]);
    1425           0 :                 if (v->byte_per_pixel_detc[k] > 0.0) {
    1426           0 :                         v->effective_det_plus_lb_lines_chroma =dcn_bw_floor2(v->lines_in_detc[k] +dcn_bw_min2(v->lines_in_detc[k] * v->dppclk * v->byte_per_pixel_detc[k] * v->pscl_throughput_chroma[k] / (v->return_bw / v->dpp_per_plane[k]), v->effective_lb_latency_hiding_source_lines_chroma), v->swath_height_c[k]);
    1427           0 :                         v->urgent_latency_support_us_chroma = v->effective_det_plus_lb_lines_chroma * (v->htotal[k] / v->pixel_clock[k]) / (v->v_ratio[k] / 2.0) - v->effective_det_plus_lb_lines_chroma * (v->swath_width_y[k] / 2.0) * v->byte_per_pixel_detc[k] / (v->return_bw / v->dpp_per_plane[k]);
    1428           0 :                         v->urgent_latency_support_us[k] =dcn_bw_min2(v->urgent_latency_support_us_luma, v->urgent_latency_support_us_chroma);
    1429             :                 }
    1430             :                 else {
    1431           0 :                         v->urgent_latency_support_us[k] = v->urgent_latency_support_us_luma;
    1432             :                 }
    1433             :         }
    1434           0 :         v->min_urgent_latency_support_us = 999999.0;
    1435           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1436           0 :                 v->min_urgent_latency_support_us =dcn_bw_min2(v->min_urgent_latency_support_us, v->urgent_latency_support_us[k]);
    1437             :         }
    1438             :         /*non-urgent latency tolerance*/
    1439             : 
    1440           0 :         v->non_urgent_latency_tolerance = v->min_urgent_latency_support_us - v->urgent_watermark;
    1441             :         /*prefetch*/
    1442             : 
    1443           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1444           0 :                 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) {
    1445           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1446           0 :                                 v->block_height256_bytes_y = 1.0;
    1447             :                         }
    1448           0 :                         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
    1449           0 :                                 v->block_height256_bytes_y = 4.0;
    1450             :                         }
    1451             :                         else {
    1452           0 :                                 v->block_height256_bytes_y = 8.0;
    1453             :                         }
    1454           0 :                         v->block_height256_bytes_c = 0.0;
    1455             :                 }
    1456             :                 else {
    1457           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1458           0 :                                 v->block_height256_bytes_y = 1.0;
    1459           0 :                                 v->block_height256_bytes_c = 1.0;
    1460             :                         }
    1461           0 :                         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
    1462           0 :                                 v->block_height256_bytes_y = 16.0;
    1463           0 :                                 v->block_height256_bytes_c = 8.0;
    1464             :                         }
    1465             :                         else {
    1466           0 :                                 v->block_height256_bytes_y = 8.0;
    1467           0 :                                 v->block_height256_bytes_c = 8.0;
    1468             :                         }
    1469             :                 }
    1470           0 :                 if (v->dcc_enable[k] == dcn_bw_yes) {
    1471           0 :                         v->meta_request_width_y = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / (8.0 * v->block_height256_bytes_y);
    1472           0 :                         v->meta_surf_width_y =dcn_bw_ceil2(v->swath_width_y[k] - 1.0, v->meta_request_width_y) + v->meta_request_width_y;
    1473           0 :                         v->meta_surf_height_y =dcn_bw_ceil2(v->viewport_height[k] - 1.0, 8.0 * v->block_height256_bytes_y) + 8.0 * v->block_height256_bytes_y;
    1474           0 :                         if (v->pte_enable == dcn_bw_yes) {
    1475           0 :                                 v->meta_pte_bytes_frame_y = (dcn_bw_ceil2((v->meta_surf_width_y * v->meta_surf_height_y *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0;
    1476             :                         }
    1477             :                         else {
    1478           0 :                                 v->meta_pte_bytes_frame_y = 0.0;
    1479             :                         }
    1480           0 :                         if (v->source_scan[k] == dcn_bw_hor) {
    1481           0 :                                 v->meta_row_byte_y = v->meta_surf_width_y * 8.0 * v->block_height256_bytes_y *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 256.0;
    1482             :                         }
    1483             :                         else {
    1484           0 :                                 v->meta_row_byte_y = v->meta_surf_height_y * v->meta_request_width_y *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 256.0;
    1485             :                         }
    1486             :                 }
    1487             :                 else {
    1488           0 :                         v->meta_pte_bytes_frame_y = 0.0;
    1489           0 :                         v->meta_row_byte_y = 0.0;
    1490             :                 }
    1491           0 :                 if (v->pte_enable == dcn_bw_yes) {
    1492           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1493           0 :                                 v->macro_tile_size_byte_y = 256.0;
    1494           0 :                                 v->macro_tile_height_y = 1.0;
    1495             :                         }
    1496           0 :                         else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) {
    1497           0 :                                 v->macro_tile_size_byte_y = 4096.0;
    1498           0 :                                 v->macro_tile_height_y = 4.0 * v->block_height256_bytes_y;
    1499             :                         }
    1500           0 :                         else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) {
    1501           0 :                                 v->macro_tile_size_byte_y = 64.0 * 1024;
    1502           0 :                                 v->macro_tile_height_y = 16.0 * v->block_height256_bytes_y;
    1503             :                         }
    1504             :                         else {
    1505           0 :                                 v->macro_tile_size_byte_y = 256.0 * 1024;
    1506           0 :                                 v->macro_tile_height_y = 32.0 * v->block_height256_bytes_y;
    1507             :                         }
    1508           0 :                         if (v->macro_tile_size_byte_y <= 65536.0) {
    1509           0 :                                 v->pixel_pte_req_height_y = v->macro_tile_height_y;
    1510             :                         }
    1511             :                         else {
    1512           0 :                                 v->pixel_pte_req_height_y = 16.0 * v->block_height256_bytes_y;
    1513             :                         }
    1514           0 :                         v->pixel_pte_req_width_y = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / v->pixel_pte_req_height_y * 8;
    1515           0 :                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1516           0 :                                 v->pixel_pte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] *dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->pixel_pte_req_width_y / v->swath_width_y[k], 2.0), 1.0))) - 1.0) / v->pixel_pte_req_width_y, 1.0) + 1);
    1517             :                         }
    1518           0 :                         else if (v->source_scan[k] == dcn_bw_hor) {
    1519           0 :                                 v->pixel_pte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] - 1.0) / v->pixel_pte_req_width_y, 1.0) + 1);
    1520             :                         }
    1521             :                         else {
    1522           0 :                                 v->pixel_pte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] - 1.0) / v->pixel_pte_req_height_y, 1.0) + 1);
    1523             :                         }
    1524             :                 }
    1525             :                 else {
    1526           0 :                         v->pixel_pte_bytes_per_row_y = 0.0;
    1527             :                 }
    1528           0 :                 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) {
    1529           0 :                         if (v->dcc_enable[k] == dcn_bw_yes) {
    1530           0 :                                 v->meta_request_width_c = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / (8.0 * v->block_height256_bytes_c);
    1531           0 :                                 v->meta_surf_width_c =dcn_bw_ceil2(v->swath_width_y[k] / 2.0 - 1.0, v->meta_request_width_c) + v->meta_request_width_c;
    1532           0 :                                 v->meta_surf_height_c =dcn_bw_ceil2(v->viewport_height[k] / 2.0 - 1.0, 8.0 * v->block_height256_bytes_c) + 8.0 * v->block_height256_bytes_c;
    1533           0 :                                 if (v->pte_enable == dcn_bw_yes) {
    1534           0 :                                         v->meta_pte_bytes_frame_c = (dcn_bw_ceil2((v->meta_surf_width_c * v->meta_surf_height_c *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0;
    1535             :                                 }
    1536             :                                 else {
    1537           0 :                                         v->meta_pte_bytes_frame_c = 0.0;
    1538             :                                 }
    1539           0 :                                 if (v->source_scan[k] == dcn_bw_hor) {
    1540           0 :                                         v->meta_row_byte_c = v->meta_surf_width_c * 8.0 * v->block_height256_bytes_c *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 256.0;
    1541             :                                 }
    1542             :                                 else {
    1543           0 :                                         v->meta_row_byte_c = v->meta_surf_height_c * v->meta_request_width_c *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 256.0;
    1544             :                                 }
    1545             :                         }
    1546             :                         else {
    1547           0 :                                 v->meta_pte_bytes_frame_c = 0.0;
    1548           0 :                                 v->meta_row_byte_c = 0.0;
    1549             :                         }
    1550           0 :                         if (v->pte_enable == dcn_bw_yes) {
    1551           0 :                                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1552           0 :                                         v->macro_tile_size_bytes_c = 256.0;
    1553           0 :                                         v->macro_tile_height_c = 1.0;
    1554             :                                 }
    1555           0 :                                 else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) {
    1556           0 :                                         v->macro_tile_size_bytes_c = 4096.0;
    1557           0 :                                         v->macro_tile_height_c = 4.0 * v->block_height256_bytes_c;
    1558             :                                 }
    1559           0 :                                 else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) {
    1560           0 :                                         v->macro_tile_size_bytes_c = 64.0 * 1024;
    1561           0 :                                         v->macro_tile_height_c = 16.0 * v->block_height256_bytes_c;
    1562             :                                 }
    1563             :                                 else {
    1564           0 :                                         v->macro_tile_size_bytes_c = 256.0 * 1024;
    1565           0 :                                         v->macro_tile_height_c = 32.0 * v->block_height256_bytes_c;
    1566             :                                 }
    1567           0 :                                 if (v->macro_tile_size_bytes_c <= 65536.0) {
    1568           0 :                                         v->pixel_pte_req_height_c = v->macro_tile_height_c;
    1569             :                                 }
    1570             :                                 else {
    1571           0 :                                         v->pixel_pte_req_height_c = 16.0 * v->block_height256_bytes_c;
    1572             :                                 }
    1573           0 :                                 v->pixel_pte_req_width_c = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / v->pixel_pte_req_height_c * 8;
    1574           0 :                                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
    1575           0 :                                         v->pixel_pte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] / 2.0 * dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->pixel_pte_req_width_c / (v->swath_width_y[k] / 2.0), 2.0), 1.0))) - 1.0) / v->pixel_pte_req_width_c, 1.0) + 1);
    1576             :                                 }
    1577           0 :                                 else if (v->source_scan[k] == dcn_bw_hor) {
    1578           0 :                                         v->pixel_pte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] / 2.0 - 1.0) / v->pixel_pte_req_width_c, 1.0) + 1);
    1579             :                                 }
    1580             :                                 else {
    1581           0 :                                         v->pixel_pte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] / 2.0 - 1.0) / v->pixel_pte_req_height_c, 1.0) + 1);
    1582             :                                 }
    1583             :                         }
    1584             :                         else {
    1585           0 :                                 v->pixel_pte_bytes_per_row_c = 0.0;
    1586             :                         }
    1587             :                 }
    1588             :                 else {
    1589           0 :                         v->pixel_pte_bytes_per_row_c = 0.0;
    1590           0 :                         v->meta_pte_bytes_frame_c = 0.0;
    1591           0 :                         v->meta_row_byte_c = 0.0;
    1592             :                 }
    1593           0 :                 v->pixel_pte_bytes_per_row[k] = v->pixel_pte_bytes_per_row_y + v->pixel_pte_bytes_per_row_c;
    1594           0 :                 v->meta_pte_bytes_frame[k] = v->meta_pte_bytes_frame_y + v->meta_pte_bytes_frame_c;
    1595           0 :                 v->meta_row_byte[k] = v->meta_row_byte_y + v->meta_row_byte_c;
    1596           0 :                 v->v_init_pre_fill_y[k] =dcn_bw_floor2((v->v_ratio[k] + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k]) / 2.0, 1.0);
    1597           0 :                 v->max_num_swath_y[k] =dcn_bw_ceil2((v->v_init_pre_fill_y[k] - 1.0) / v->swath_height_y[k], 1.0) + 1;
    1598           0 :                 if (v->v_init_pre_fill_y[k] > 1.0) {
    1599           0 :                         v->max_partial_swath_y =dcn_bw_mod((v->v_init_pre_fill_y[k] - 2.0), v->swath_height_y[k]);
    1600             :                 }
    1601             :                 else {
    1602           0 :                         v->max_partial_swath_y =dcn_bw_mod((v->v_init_pre_fill_y[k] + v->swath_height_y[k] - 2.0), v->swath_height_y[k]);
    1603             :                 }
    1604           0 :                 v->max_partial_swath_y =dcn_bw_max2(1.0, v->max_partial_swath_y);
    1605           0 :                 v->prefetch_source_lines_y[k] = v->max_num_swath_y[k] * v->swath_height_y[k] + v->max_partial_swath_y;
    1606           0 :                 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) {
    1607           0 :                         v->v_init_pre_fill_c[k] =dcn_bw_floor2((v->v_ratio[k] / 2.0 + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k] / 2.0) / 2.0, 1.0);
    1608           0 :                         v->max_num_swath_c[k] =dcn_bw_ceil2((v->v_init_pre_fill_c[k] - 1.0) / v->swath_height_c[k], 1.0) + 1;
    1609           0 :                         if (v->v_init_pre_fill_c[k] > 1.0) {
    1610           0 :                                 v->max_partial_swath_c =dcn_bw_mod((v->v_init_pre_fill_c[k] - 2.0), v->swath_height_c[k]);
    1611             :                         }
    1612             :                         else {
    1613           0 :                                 v->max_partial_swath_c =dcn_bw_mod((v->v_init_pre_fill_c[k] + v->swath_height_c[k] - 2.0), v->swath_height_c[k]);
    1614             :                         }
    1615           0 :                         v->max_partial_swath_c =dcn_bw_max2(1.0, v->max_partial_swath_c);
    1616             :                 }
    1617             :                 else {
    1618           0 :                         v->max_num_swath_c[k] = 0.0;
    1619           0 :                         v->max_partial_swath_c = 0.0;
    1620             :                 }
    1621           0 :                 v->prefetch_source_lines_c[k] = v->max_num_swath_c[k] * v->swath_height_c[k] + v->max_partial_swath_c;
    1622             :         }
    1623           0 :         v->t_calc = 24.0 / v->dcf_clk_deep_sleep;
    1624           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1625           0 :                 if (v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes) {
    1626           0 :                         v->max_vstartup_lines[k] = v->vtotal[k] - v->vactive[k] - 1.0;
    1627             :                 }
    1628             :                 else {
    1629           0 :                         v->max_vstartup_lines[k] = v->v_sync_plus_back_porch[k] - 1.0;
    1630             :                 }
    1631             :         }
    1632           0 :         v->next_prefetch_mode = 0.0;
    1633             :         do {
    1634           0 :                 v->v_startup_lines = 13.0;
    1635             :                 do {
    1636           0 :                         v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw = dcn_bw_yes;
    1637           0 :                         v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 = dcn_bw_no;
    1638           0 :                         v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 = dcn_bw_no;
    1639           0 :                         v->v_ratio_prefetch_more_than4 = dcn_bw_no;
    1640           0 :                         v->destination_line_times_for_prefetch_less_than2 = dcn_bw_no;
    1641           0 :                         v->prefetch_mode = v->next_prefetch_mode;
    1642           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1643           0 :                                 v->dstx_after_scaler = 90.0 * v->pixel_clock[k] / v->dppclk + 42.0 * v->pixel_clock[k] / v->dispclk;
    1644           0 :                                 if (v->dpp_per_plane[k] > 1.0) {
    1645           0 :                                         v->dstx_after_scaler = v->dstx_after_scaler + v->scaler_rec_out_width[k] / 2.0;
    1646             :                                 }
    1647           0 :                                 if (v->output_format[k] == dcn_bw_420) {
    1648           0 :                                         v->dsty_after_scaler = 1.0;
    1649             :                                 }
    1650             :                                 else {
    1651           0 :                                         v->dsty_after_scaler = 0.0;
    1652             :                                 }
    1653           0 :                                 v->v_update_offset_pix[k] = dcn_bw_ceil2(v->htotal[k] / 4.0, 1.0);
    1654           0 :                                 v->total_repeater_delay_time = v->max_inter_dcn_tile_repeaters * (2.0 / v->dppclk + 3.0 / v->dispclk);
    1655           0 :                                 v->v_update_width_pix[k] = (14.0 / v->dcf_clk_deep_sleep + 12.0 / v->dppclk + v->total_repeater_delay_time) * v->pixel_clock[k];
    1656           0 :                                 v->v_ready_offset_pix[k] = dcn_bw_max2(150.0 / v->dppclk, v->total_repeater_delay_time + 20.0 / v->dcf_clk_deep_sleep + 10.0 / v->dppclk) * v->pixel_clock[k];
    1657           0 :                                 v->t_setup = (v->v_update_offset_pix[k] + v->v_update_width_pix[k] + v->v_ready_offset_pix[k]) / v->pixel_clock[k];
    1658           0 :                                 v->v_startup[k] =dcn_bw_min2(v->v_startup_lines, v->max_vstartup_lines[k]);
    1659           0 :                                 if (v->prefetch_mode == 0.0) {
    1660           0 :                                         v->t_wait =dcn_bw_max3(v->dram_clock_change_latency + v->urgent_latency, v->sr_enter_plus_exit_time, v->urgent_latency);
    1661             :                                 }
    1662           0 :                                 else if (v->prefetch_mode == 1.0) {
    1663           0 :                                         v->t_wait =dcn_bw_max2(v->sr_enter_plus_exit_time, v->urgent_latency);
    1664             :                                 }
    1665             :                                 else {
    1666           0 :                                         v->t_wait = v->urgent_latency;
    1667             :                                 }
    1668           0 :                                 v->destination_lines_for_prefetch[k] =dcn_bw_floor2(4.0 * (v->v_startup[k] - v->t_wait / (v->htotal[k] / v->pixel_clock[k]) - (v->t_calc + v->t_setup) / (v->htotal[k] / v->pixel_clock[k]) - (v->dsty_after_scaler + v->dstx_after_scaler / v->htotal[k]) + 0.125), 1.0) / 4;
    1669           0 :                                 if (v->destination_lines_for_prefetch[k] > 0.0) {
    1670           0 :                                         v->prefetch_bandwidth[k] = (v->meta_pte_bytes_frame[k] + 2.0 * v->meta_row_byte[k] + 2.0 * v->pixel_pte_bytes_per_row[k] + v->prefetch_source_lines_y[k] * v->swath_width_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) + v->prefetch_source_lines_c[k] * v->swath_width_y[k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0)) / (v->destination_lines_for_prefetch[k] * v->htotal[k] / v->pixel_clock[k]);
    1671             :                                 }
    1672             :                                 else {
    1673           0 :                                         v->prefetch_bandwidth[k] = 999999.0;
    1674             :                                 }
    1675             :                         }
    1676           0 :                         v->bandwidth_available_for_immediate_flip = v->return_bw;
    1677           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1678           0 :                                 v->bandwidth_available_for_immediate_flip = v->bandwidth_available_for_immediate_flip -dcn_bw_max2(v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k], v->prefetch_bandwidth[k]);
    1679             :                         }
    1680           0 :                         v->tot_immediate_flip_bytes = 0.0;
    1681           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1682           0 :                                 if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
    1683           0 :                                         v->tot_immediate_flip_bytes = v->tot_immediate_flip_bytes + v->meta_pte_bytes_frame[k] + v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k];
    1684             :                                 }
    1685             :                         }
    1686           0 :                         v->max_rd_bandwidth = 0.0;
    1687           0 :                         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1688           0 :                                 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) {
    1689           0 :                                         if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
    1690           0 :                                                 v->time_for_fetching_meta_pte =dcn_bw_max5(v->meta_pte_bytes_frame[k] / v->prefetch_bandwidth[k], v->meta_pte_bytes_frame[k] * v->tot_immediate_flip_bytes / (v->bandwidth_available_for_immediate_flip * (v->meta_pte_bytes_frame[k] + v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k])), v->urgent_extra_latency, v->urgent_latency, v->htotal[k] / v->pixel_clock[k] / 4.0);
    1691             :                                         }
    1692             :                                         else {
    1693           0 :                                                 v->time_for_fetching_meta_pte =dcn_bw_max3(v->meta_pte_bytes_frame[k] / v->prefetch_bandwidth[k], v->urgent_extra_latency, v->htotal[k] / v->pixel_clock[k] / 4.0);
    1694             :                                         }
    1695             :                                 }
    1696             :                                 else {
    1697           0 :                                         v->time_for_fetching_meta_pte = v->htotal[k] / v->pixel_clock[k] / 4.0;
    1698             :                                 }
    1699           0 :                                 v->destination_lines_to_request_vm_inv_blank[k] =dcn_bw_floor2(4.0 * (v->time_for_fetching_meta_pte / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4;
    1700           0 :                                 if ((v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes)) {
    1701           0 :                                         if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
    1702           0 :                                                 v->time_for_fetching_row_in_vblank =dcn_bw_max5((v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) / v->prefetch_bandwidth[k], (v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) * v->tot_immediate_flip_bytes / (v->bandwidth_available_for_immediate_flip * (v->meta_pte_bytes_frame[k] + v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k])), v->urgent_extra_latency, 2.0 * v->urgent_latency, v->htotal[k] / v->pixel_clock[k] - v->time_for_fetching_meta_pte);
    1703             :                                         }
    1704             :                                         else {
    1705           0 :                                                 v->time_for_fetching_row_in_vblank =dcn_bw_max3((v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) / v->prefetch_bandwidth[k], v->urgent_extra_latency, v->htotal[k] / v->pixel_clock[k] - v->time_for_fetching_meta_pte);
    1706             :                                         }
    1707             :                                 }
    1708             :                                 else {
    1709           0 :                                         v->time_for_fetching_row_in_vblank =dcn_bw_max2(v->urgent_extra_latency - v->time_for_fetching_meta_pte, v->htotal[k] / v->pixel_clock[k] - v->time_for_fetching_meta_pte);
    1710             :                                 }
    1711           0 :                                 v->destination_lines_to_request_row_in_vblank[k] =dcn_bw_floor2(4.0 * (v->time_for_fetching_row_in_vblank / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4;
    1712           0 :                                 v->lines_to_request_prefetch_pixel_data = v->destination_lines_for_prefetch[k] - v->destination_lines_to_request_vm_inv_blank[k] - v->destination_lines_to_request_row_in_vblank[k];
    1713           0 :                                 if (v->lines_to_request_prefetch_pixel_data > 0.0) {
    1714           0 :                                         v->v_ratio_prefetch_y[k] = v->prefetch_source_lines_y[k] / v->lines_to_request_prefetch_pixel_data;
    1715           0 :                                         if ((v->swath_height_y[k] > 4.0)) {
    1716           0 :                                                 if (v->lines_to_request_prefetch_pixel_data > (v->v_init_pre_fill_y[k] - 3.0) / 2.0) {
    1717           0 :                                                         v->v_ratio_prefetch_y[k] =dcn_bw_max2(v->v_ratio_prefetch_y[k], v->max_num_swath_y[k] * v->swath_height_y[k] / (v->lines_to_request_prefetch_pixel_data - (v->v_init_pre_fill_y[k] - 3.0) / 2.0));
    1718             :                                                 }
    1719             :                                                 else {
    1720           0 :                                                         v->v_ratio_prefetch_y[k] = 999999.0;
    1721             :                                                 }
    1722             :                                         }
    1723             :                                 }
    1724             :                                 else {
    1725           0 :                                         v->v_ratio_prefetch_y[k] = 999999.0;
    1726             :                                 }
    1727           0 :                                 v->v_ratio_prefetch_y[k] =dcn_bw_max2(v->v_ratio_prefetch_y[k], 1.0);
    1728           0 :                                 if (v->lines_to_request_prefetch_pixel_data > 0.0) {
    1729           0 :                                         v->v_ratio_prefetch_c[k] = v->prefetch_source_lines_c[k] / v->lines_to_request_prefetch_pixel_data;
    1730           0 :                                         if ((v->swath_height_c[k] > 4.0)) {
    1731           0 :                                                 if (v->lines_to_request_prefetch_pixel_data > (v->v_init_pre_fill_c[k] - 3.0) / 2.0) {
    1732           0 :                                                         v->v_ratio_prefetch_c[k] =dcn_bw_max2(v->v_ratio_prefetch_c[k], v->max_num_swath_c[k] * v->swath_height_c[k] / (v->lines_to_request_prefetch_pixel_data - (v->v_init_pre_fill_c[k] - 3.0) / 2.0));
    1733             :                                                 }
    1734             :                                                 else {
    1735           0 :                                                         v->v_ratio_prefetch_c[k] = 999999.0;
    1736             :                                                 }
    1737             :                                         }
    1738             :                                 }
    1739             :                                 else {
    1740           0 :                                         v->v_ratio_prefetch_c[k] = 999999.0;
    1741             :                                 }
    1742           0 :                                 v->v_ratio_prefetch_c[k] =dcn_bw_max2(v->v_ratio_prefetch_c[k], 1.0);
    1743           0 :                                 if (v->lines_to_request_prefetch_pixel_data > 0.0) {
    1744           0 :                                         v->required_prefetch_pix_data_bw = v->dpp_per_plane[k] * (v->prefetch_source_lines_y[k] / v->lines_to_request_prefetch_pixel_data *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) + v->prefetch_source_lines_c[k] / v->lines_to_request_prefetch_pixel_data *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 2.0) * v->swath_width_y[k] / (v->htotal[k] / v->pixel_clock[k]);
    1745             :                                 }
    1746             :                                 else {
    1747           0 :                                         v->required_prefetch_pix_data_bw = 999999.0;
    1748             :                                 }
    1749           0 :                                 v->max_rd_bandwidth = v->max_rd_bandwidth +dcn_bw_max2(v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k], v->required_prefetch_pix_data_bw);
    1750           0 :                                 if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
    1751           0 :                                         v->max_rd_bandwidth = v->max_rd_bandwidth +dcn_bw_max2(v->meta_pte_bytes_frame[k] / (v->destination_lines_to_request_vm_inv_blank[k] * v->htotal[k] / v->pixel_clock[k]), (v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) / (v->destination_lines_to_request_row_in_vblank[k] * v->htotal[k] / v->pixel_clock[k]));
    1752             :                                 }
    1753           0 :                                 if (v->v_ratio_prefetch_y[k] > 4.0 || v->v_ratio_prefetch_c[k] > 4.0) {
    1754           0 :                                         v->v_ratio_prefetch_more_than4 = dcn_bw_yes;
    1755             :                                 }
    1756           0 :                                 if (v->destination_lines_for_prefetch[k] < 2.0) {
    1757           0 :                                         v->destination_line_times_for_prefetch_less_than2 = dcn_bw_yes;
    1758             :                                 }
    1759           0 :                                 if (v->max_vstartup_lines[k] > v->v_startup_lines) {
    1760           0 :                                         if (v->required_prefetch_pix_data_bw > (v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k])) {
    1761           0 :                                                 v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw = dcn_bw_no;
    1762             :                                         }
    1763           0 :                                         if (v->v_ratio_prefetch_y[k] > 4.0 || v->v_ratio_prefetch_c[k] > 4.0) {
    1764           0 :                                                 v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 = dcn_bw_yes;
    1765             :                                         }
    1766           0 :                                         if (v->destination_lines_for_prefetch[k] < 2.0) {
    1767           0 :                                                 v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 = dcn_bw_yes;
    1768             :                                         }
    1769             :                                 }
    1770             :                         }
    1771           0 :                         if (v->max_rd_bandwidth <= v->return_bw && v->v_ratio_prefetch_more_than4 == dcn_bw_no && v->destination_line_times_for_prefetch_less_than2 == dcn_bw_no) {
    1772           0 :                                 v->prefetch_mode_supported = dcn_bw_yes;
    1773             :                         }
    1774             :                         else {
    1775           0 :                                 v->prefetch_mode_supported = dcn_bw_no;
    1776             :                         }
    1777           0 :                         v->v_startup_lines = v->v_startup_lines + 1.0;
    1778           0 :                 } while (!(v->prefetch_mode_supported == dcn_bw_yes || (v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw == dcn_bw_yes && v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 == dcn_bw_no && v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 == dcn_bw_no)));
    1779           0 :                 v->next_prefetch_mode = v->next_prefetch_mode + 1.0;
    1780           0 :         } while (!(v->prefetch_mode_supported == dcn_bw_yes || v->prefetch_mode == 2.0));
    1781           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1782           0 :                 if (v->v_ratio_prefetch_y[k] <= 1.0) {
    1783           0 :                         v->display_pipe_line_delivery_time_luma_prefetch[k] = v->swath_width_y[k] * v->dpp_per_plane[k] / v->h_ratio[k] / v->pixel_clock[k];
    1784             :                 }
    1785             :                 else {
    1786           0 :                         v->display_pipe_line_delivery_time_luma_prefetch[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk;
    1787             :                 }
    1788           0 :                 if (v->byte_per_pixel_detc[k] == 0.0) {
    1789           0 :                         v->display_pipe_line_delivery_time_chroma_prefetch[k] = 0.0;
    1790             :                 }
    1791             :                 else {
    1792           0 :                         if (v->v_ratio_prefetch_c[k] <= 1.0) {
    1793           0 :                                 v->display_pipe_line_delivery_time_chroma_prefetch[k] = v->swath_width_y[k] * v->dpp_per_plane[k] / v->h_ratio[k] / v->pixel_clock[k];
    1794             :                         }
    1795             :                         else {
    1796           0 :                                 v->display_pipe_line_delivery_time_chroma_prefetch[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk;
    1797             :                         }
    1798             :                 }
    1799             :         }
    1800             :         /*min ttuv_blank*/
    1801             : 
    1802           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1803           0 :                 if (v->prefetch_mode == 0.0) {
    1804           0 :                         v->allow_dram_clock_change_during_vblank[k] = dcn_bw_yes;
    1805           0 :                         v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_yes;
    1806           0 :                         v->min_ttuv_blank[k] = v->t_calc +dcn_bw_max3(v->dram_clock_change_watermark, v->stutter_enter_plus_exit_watermark, v->urgent_watermark);
    1807             :                 }
    1808           0 :                 else if (v->prefetch_mode == 1.0) {
    1809           0 :                         v->allow_dram_clock_change_during_vblank[k] = dcn_bw_no;
    1810           0 :                         v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_yes;
    1811           0 :                         v->min_ttuv_blank[k] = v->t_calc +dcn_bw_max2(v->stutter_enter_plus_exit_watermark, v->urgent_watermark);
    1812             :                 }
    1813             :                 else {
    1814           0 :                         v->allow_dram_clock_change_during_vblank[k] = dcn_bw_no;
    1815           0 :                         v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_no;
    1816           0 :                         v->min_ttuv_blank[k] = v->t_calc + v->urgent_watermark;
    1817             :                 }
    1818             :         }
    1819             :         /*nb p-state/dram clock change support*/
    1820             : 
    1821           0 :         v->active_dp_ps = 0.0;
    1822           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1823           0 :                 v->active_dp_ps = v->active_dp_ps + v->dpp_per_plane[k];
    1824             :         }
    1825           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1826           0 :                 v->lb_latency_hiding_source_lines_y =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_y[k] /dcn_bw_max2(v->h_ratio[k], 1.0)), 1.0)) - (v->vtaps[k] - 1.0);
    1827           0 :                 v->lb_latency_hiding_source_lines_c =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_y[k] / 2.0 /dcn_bw_max2(v->h_ratio[k] / 2.0, 1.0)), 1.0)) - (v->vta_pschroma[k] - 1.0);
    1828           0 :                 v->effective_lb_latency_hiding_y = v->lb_latency_hiding_source_lines_y / v->v_ratio[k] * (v->htotal[k] / v->pixel_clock[k]);
    1829           0 :                 v->effective_lb_latency_hiding_c = v->lb_latency_hiding_source_lines_c / (v->v_ratio[k] / 2.0) * (v->htotal[k] / v->pixel_clock[k]);
    1830           0 :                 if (v->swath_width_y[k] > 2.0 * v->dpp_output_buffer_pixels) {
    1831           0 :                         v->dpp_output_buffer_lines_y = v->dpp_output_buffer_pixels / v->swath_width_y[k];
    1832             :                 }
    1833           0 :                 else if (v->swath_width_y[k] > v->dpp_output_buffer_pixels) {
    1834           0 :                         v->dpp_output_buffer_lines_y = 0.5;
    1835             :                 }
    1836             :                 else {
    1837           0 :                         v->dpp_output_buffer_lines_y = 1.0;
    1838             :                 }
    1839           0 :                 if (v->swath_width_y[k] / 2.0 > 2.0 * v->dpp_output_buffer_pixels) {
    1840           0 :                         v->dpp_output_buffer_lines_c = v->dpp_output_buffer_pixels / (v->swath_width_y[k] / 2.0);
    1841             :                 }
    1842           0 :                 else if (v->swath_width_y[k] / 2.0 > v->dpp_output_buffer_pixels) {
    1843           0 :                         v->dpp_output_buffer_lines_c = 0.5;
    1844             :                 }
    1845             :                 else {
    1846           0 :                         v->dpp_output_buffer_lines_c = 1.0;
    1847             :                 }
    1848           0 :                 v->dppopp_buffering_y = (v->htotal[k] / v->pixel_clock[k]) * (v->dpp_output_buffer_lines_y + v->opp_output_buffer_lines);
    1849           0 :                 v->max_det_buffering_time_y = v->full_det_buffering_time_y[k] + (v->lines_in_dety[k] - v->lines_in_dety_rounded_down_to_swath[k]) / v->swath_height_y[k] * (v->htotal[k] / v->pixel_clock[k]);
    1850           0 :                 v->active_dram_clock_change_latency_margin_y = v->dppopp_buffering_y + v->effective_lb_latency_hiding_y + v->max_det_buffering_time_y - v->dram_clock_change_watermark;
    1851           0 :                 if (v->active_dp_ps > 1.0) {
    1852           0 :                         v->active_dram_clock_change_latency_margin_y = v->active_dram_clock_change_latency_margin_y - (1.0 - 1.0 / (v->active_dp_ps - 1.0)) * v->swath_height_y[k] * (v->htotal[k] / v->pixel_clock[k]);
    1853             :                 }
    1854           0 :                 if (v->byte_per_pixel_detc[k] > 0.0) {
    1855           0 :                         v->dppopp_buffering_c = (v->htotal[k] / v->pixel_clock[k]) * (v->dpp_output_buffer_lines_c + v->opp_output_buffer_lines);
    1856           0 :                         v->max_det_buffering_time_c = v->full_det_buffering_time_c[k] + (v->lines_in_detc[k] - v->lines_in_detc_rounded_down_to_swath[k]) / v->swath_height_c[k] * (v->htotal[k] / v->pixel_clock[k]);
    1857           0 :                         v->active_dram_clock_change_latency_margin_c = v->dppopp_buffering_c + v->effective_lb_latency_hiding_c + v->max_det_buffering_time_c - v->dram_clock_change_watermark;
    1858           0 :                         if (v->active_dp_ps > 1.0) {
    1859           0 :                                 v->active_dram_clock_change_latency_margin_c = v->active_dram_clock_change_latency_margin_c - (1.0 - 1.0 / (v->active_dp_ps - 1.0)) * v->swath_height_c[k] * (v->htotal[k] / v->pixel_clock[k]);
    1860             :                         }
    1861           0 :                         v->active_dram_clock_change_latency_margin[k] =dcn_bw_min2(v->active_dram_clock_change_latency_margin_y, v->active_dram_clock_change_latency_margin_c);
    1862             :                 }
    1863             :                 else {
    1864           0 :                         v->active_dram_clock_change_latency_margin[k] = v->active_dram_clock_change_latency_margin_y;
    1865             :                 }
    1866           0 :                 if (v->output_format[k] == dcn_bw_444) {
    1867           0 :                         v->writeback_dram_clock_change_latency_margin = (v->writeback_luma_buffer_size + v->writeback_chroma_buffer_size) * 1024.0 / (v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0) - v->writeback_dram_clock_change_watermark;
    1868             :                 }
    1869             :                 else {
    1870           0 :                         v->writeback_dram_clock_change_latency_margin =dcn_bw_min2(v->writeback_luma_buffer_size, 2.0 * v->writeback_chroma_buffer_size) * 1024.0 / (v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k])) - v->writeback_dram_clock_change_watermark;
    1871             :                 }
    1872           0 :                 if (v->output[k] == dcn_bw_writeback) {
    1873           0 :                         v->active_dram_clock_change_latency_margin[k] =dcn_bw_min2(v->active_dram_clock_change_latency_margin[k], v->writeback_dram_clock_change_latency_margin);
    1874             :                 }
    1875             :         }
    1876           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1877           0 :                 if (v->allow_dram_clock_change_during_vblank[k] == dcn_bw_yes) {
    1878           0 :                         v->v_blank_dram_clock_change_latency_margin[k] = (v->vtotal[k] - v->scaler_recout_height[k]) * (v->htotal[k] / v->pixel_clock[k]) -dcn_bw_max2(v->dram_clock_change_watermark, v->writeback_dram_clock_change_watermark);
    1879             :                 }
    1880             :                 else {
    1881           0 :                         v->v_blank_dram_clock_change_latency_margin[k] = 0.0;
    1882             :                 }
    1883             :         }
    1884           0 :         v->min_active_dram_clock_change_margin = 999999.0;
    1885           0 :         v->v_blank_of_min_active_dram_clock_change_margin = 999999.0;
    1886           0 :         v->second_min_active_dram_clock_change_margin = 999999.0;
    1887           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1888           0 :                 if (v->active_dram_clock_change_latency_margin[k] < v->min_active_dram_clock_change_margin) {
    1889           0 :                         v->second_min_active_dram_clock_change_margin = v->min_active_dram_clock_change_margin;
    1890           0 :                         v->min_active_dram_clock_change_margin = v->active_dram_clock_change_latency_margin[k];
    1891           0 :                         v->v_blank_of_min_active_dram_clock_change_margin = v->v_blank_dram_clock_change_latency_margin[k];
    1892             :                 }
    1893           0 :                 else if (v->active_dram_clock_change_latency_margin[k] < v->second_min_active_dram_clock_change_margin) {
    1894           0 :                         v->second_min_active_dram_clock_change_margin = v->active_dram_clock_change_latency_margin[k];
    1895             :                 }
    1896             :         }
    1897           0 :         v->min_vblank_dram_clock_change_margin = 999999.0;
    1898           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1899           0 :                 if (v->min_vblank_dram_clock_change_margin > v->v_blank_dram_clock_change_latency_margin[k]) {
    1900           0 :                         v->min_vblank_dram_clock_change_margin = v->v_blank_dram_clock_change_latency_margin[k];
    1901             :                 }
    1902             :         }
    1903           0 :         if (v->synchronized_vblank == dcn_bw_yes || v->number_of_active_planes == 1) {
    1904           0 :                 v->dram_clock_change_margin =dcn_bw_max2(v->min_active_dram_clock_change_margin, v->min_vblank_dram_clock_change_margin);
    1905             :         }
    1906           0 :         else if (v->v_blank_of_min_active_dram_clock_change_margin > v->min_active_dram_clock_change_margin) {
    1907           0 :                 v->dram_clock_change_margin =dcn_bw_min2(v->second_min_active_dram_clock_change_margin, v->v_blank_of_min_active_dram_clock_change_margin);
    1908             :         }
    1909             :         else {
    1910           0 :                 v->dram_clock_change_margin = v->min_active_dram_clock_change_margin;
    1911             :         }
    1912           0 :         if (v->min_active_dram_clock_change_margin > 0.0) {
    1913           0 :                 v->dram_clock_change_support = dcn_bw_supported_in_v_active;
    1914             :         }
    1915           0 :         else if (v->dram_clock_change_margin > 0.0) {
    1916           0 :                 v->dram_clock_change_support = dcn_bw_supported_in_v_blank;
    1917             :         }
    1918             :         else {
    1919           0 :                 v->dram_clock_change_support = dcn_bw_not_supported;
    1920             :         }
    1921             :         /*maximum bandwidth used*/
    1922             : 
    1923           0 :         v->wr_bandwidth = 0.0;
    1924           0 :         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
    1925           0 :                 if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444) {
    1926           0 :                         v->wr_bandwidth = v->wr_bandwidth + v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0;
    1927             :                 }
    1928           0 :                 else if (v->output[k] == dcn_bw_writeback) {
    1929           0 :                         v->wr_bandwidth = v->wr_bandwidth + v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 1.5;
    1930             :                 }
    1931             :         }
    1932           0 :         v->max_used_bw = v->max_rd_bandwidth + v->wr_bandwidth;
    1933           0 : }

Generated by: LCOV version 1.14