diff options
author | Rex Zhu <Rex.Zhu@amd.com> | 2016-01-06 03:38:48 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2016-01-08 15:39:22 -0500 |
commit | 75ac63dbc3b0f4d3af67a5857790749e954e2ba6 (patch) | |
tree | 20bd5ccb1fb294cbc3034422e517ebe708c27c82 | |
parent | 53d3de140b668d37e1ebfe01c94ec36d369edcbf (diff) |
drm/amd/powerplay: fix Smatch static checker warnings with indenting (v2)
v2: AGD: rebase on upstream
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Ken Wang <Qingqing.Wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c | 51 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c | 12 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/powerplay/hwmgr/ppevvmath.h | 555 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c | 8 |
6 files changed, 312 insertions, 317 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c index 3b78982abaf1..4386cbac7f97 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | |||
@@ -807,7 +807,7 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) | |||
807 | struct amdgpu_ring *ring = adev->rings[i]; | 807 | struct amdgpu_ring *ring = adev->rings[i]; |
808 | if (ring && ring->ready) | 808 | if (ring && ring->ready) |
809 | amdgpu_fence_wait_empty(ring); | 809 | amdgpu_fence_wait_empty(ring); |
810 | } | 810 | } |
811 | mutex_unlock(&adev->ring_lock); | 811 | mutex_unlock(&adev->ring_lock); |
812 | 812 | ||
813 | amdgpu_dpm_dispatch_task(adev, AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE, NULL, NULL); | 813 | amdgpu_dpm_dispatch_task(adev, AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE, NULL, NULL); |
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c index 94f404c121b7..6dba5bf73e52 100644 --- a/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c | |||
@@ -941,8 +941,9 @@ static int fiji_trim_voltage_table(struct pp_hwmgr *hwmgr, | |||
941 | memcpy(vol_table, table, sizeof(struct pp_atomctrl_voltage_table)); | 941 | memcpy(vol_table, table, sizeof(struct pp_atomctrl_voltage_table)); |
942 | kfree(table); | 942 | kfree(table); |
943 | 943 | ||
944 | return 0; | 944 | return 0; |
945 | } | 945 | } |
946 | |||
946 | static int fiji_get_svi2_mvdd_voltage_table(struct pp_hwmgr *hwmgr, | 947 | static int fiji_get_svi2_mvdd_voltage_table(struct pp_hwmgr *hwmgr, |
947 | phm_ppt_v1_clock_voltage_dependency_table *dep_table) | 948 | phm_ppt_v1_clock_voltage_dependency_table *dep_table) |
948 | { | 949 | { |
@@ -1112,7 +1113,7 @@ static int fiji_construct_voltage_tables(struct pp_hwmgr *hwmgr) | |||
1112 | fiji_trim_voltage_table_to_fit_state_table(hwmgr, | 1113 | fiji_trim_voltage_table_to_fit_state_table(hwmgr, |
1113 | SMU73_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table))); | 1114 | SMU73_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table))); |
1114 | 1115 | ||
1115 | return 0; | 1116 | return 0; |
1116 | } | 1117 | } |
1117 | 1118 | ||
1118 | static int fiji_initialize_mc_reg_table(struct pp_hwmgr *hwmgr) | 1119 | static int fiji_initialize_mc_reg_table(struct pp_hwmgr *hwmgr) |
@@ -1158,7 +1159,7 @@ static int fiji_program_static_screen_threshold_parameters( | |||
1158 | CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD, | 1159 | CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD, |
1159 | data->static_screen_threshold); | 1160 | data->static_screen_threshold); |
1160 | 1161 | ||
1161 | return 0; | 1162 | return 0; |
1162 | } | 1163 | } |
1163 | 1164 | ||
1164 | /** | 1165 | /** |
@@ -1295,7 +1296,7 @@ static int fiji_process_firmware_header(struct pp_hwmgr *hwmgr) | |||
1295 | 1296 | ||
1296 | error |= (0 != result); | 1297 | error |= (0 != result); |
1297 | 1298 | ||
1298 | return error ? -1 : 0; | 1299 | return error ? -1 : 0; |
1299 | } | 1300 | } |
1300 | 1301 | ||
1301 | /* Copy one arb setting to another and then switch the active set. | 1302 | /* Copy one arb setting to another and then switch the active set. |
@@ -1339,12 +1340,12 @@ static int fiji_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr, | |||
1339 | return -EINVAL; | 1340 | return -EINVAL; |
1340 | } | 1341 | } |
1341 | 1342 | ||
1342 | mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG); | 1343 | mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG); |
1343 | mc_cg_config |= 0x0000000F; | 1344 | mc_cg_config |= 0x0000000F; |
1344 | cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config); | 1345 | cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config); |
1345 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest); | 1346 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest); |
1346 | 1347 | ||
1347 | return 0; | 1348 | return 0; |
1348 | } | 1349 | } |
1349 | 1350 | ||
1350 | /** | 1351 | /** |
@@ -1927,17 +1928,17 @@ static int fiji_populate_single_graphic_level(struct pp_hwmgr *hwmgr, | |||
1927 | 1928 | ||
1928 | threshold = clock * data->fast_watermark_threshold / 100; | 1929 | threshold = clock * data->fast_watermark_threshold / 100; |
1929 | 1930 | ||
1930 | /* | 1931 | /* |
1931 | * TODO: get minimum clocks from dal configaration | 1932 | * TODO: get minimum clocks from dal configaration |
1932 | * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks); | 1933 | * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks); |
1933 | */ | 1934 | */ |
1934 | /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */ | 1935 | /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */ |
1935 | 1936 | ||
1936 | /* get level->DeepSleepDivId | 1937 | /* get level->DeepSleepDivId |
1937 | if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) | 1938 | if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) |
1938 | { | 1939 | { |
1939 | level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR); | 1940 | level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR); |
1940 | } */ | 1941 | } */ |
1941 | 1942 | ||
1942 | /* Default to slow, highest DPM level will be | 1943 | /* Default to slow, highest DPM level will be |
1943 | * set to PPSMC_DISPLAY_WATERMARK_LOW later. | 1944 | * set to PPSMC_DISPLAY_WATERMARK_LOW later. |
@@ -2756,7 +2757,7 @@ static int fiji_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr) | |||
2756 | SclkFrequency) / 100); | 2757 | SclkFrequency) / 100); |
2757 | if (fiji_clock_stretcher_lookup_table[stretch_amount2][0] < | 2758 | if (fiji_clock_stretcher_lookup_table[stretch_amount2][0] < |
2758 | clock_freq_u16 && | 2759 | clock_freq_u16 && |
2759 | fiji_clock_stretcher_lookup_table[stretch_amount2][1] > | 2760 | fiji_clock_stretcher_lookup_table[stretch_amount2][1] > |
2760 | clock_freq_u16) { | 2761 | clock_freq_u16) { |
2761 | /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */ | 2762 | /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */ |
2762 | value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 16; | 2763 | value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 16; |
@@ -3172,9 +3173,9 @@ static int fiji_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) | |||
3172 | /* enable SCLK dpm */ | 3173 | /* enable SCLK dpm */ |
3173 | if(!data->sclk_dpm_key_disabled) | 3174 | if(!data->sclk_dpm_key_disabled) |
3174 | PP_ASSERT_WITH_CODE( | 3175 | PP_ASSERT_WITH_CODE( |
3175 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)), | 3176 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)), |
3176 | "Failed to enable SCLK DPM during DPM Start Function!", | 3177 | "Failed to enable SCLK DPM during DPM Start Function!", |
3177 | return -1); | 3178 | return -1); |
3178 | 3179 | ||
3179 | /* enable MCLK dpm */ | 3180 | /* enable MCLK dpm */ |
3180 | if(0 == data->mclk_dpm_key_disabled) { | 3181 | if(0 == data->mclk_dpm_key_disabled) { |
@@ -3320,7 +3321,7 @@ static int fiji_start_dpm(struct pp_hwmgr *hwmgr) | |||
3320 | return -1); | 3321 | return -1); |
3321 | } | 3322 | } |
3322 | 3323 | ||
3323 | return 0; | 3324 | return 0; |
3324 | } | 3325 | } |
3325 | 3326 | ||
3326 | static void fiji_set_dpm_event_sources(struct pp_hwmgr *hwmgr, | 3327 | static void fiji_set_dpm_event_sources(struct pp_hwmgr *hwmgr, |
@@ -3378,7 +3379,7 @@ static int fiji_enable_auto_throttle_source(struct pp_hwmgr *hwmgr, | |||
3378 | 3379 | ||
3379 | static int fiji_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr) | 3380 | static int fiji_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr) |
3380 | { | 3381 | { |
3381 | return fiji_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal); | 3382 | return fiji_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal); |
3382 | } | 3383 | } |
3383 | 3384 | ||
3384 | static int fiji_enable_dpm_tasks(struct pp_hwmgr *hwmgr) | 3385 | static int fiji_enable_dpm_tasks(struct pp_hwmgr *hwmgr) |
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c b/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c index f89c98fd759e..6efcb2bac45f 100644 --- a/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c | |||
@@ -93,9 +93,9 @@ void fiji_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr) | |||
93 | */ | 93 | */ |
94 | static uint16_t scale_fan_gain_settings(uint16_t raw_setting) | 94 | static uint16_t scale_fan_gain_settings(uint16_t raw_setting) |
95 | { | 95 | { |
96 | uint32_t tmp; | 96 | uint32_t tmp; |
97 | tmp = raw_setting * 4096 / 100; | 97 | tmp = raw_setting * 4096 / 100; |
98 | return (uint16_t)tmp; | 98 | return (uint16_t)tmp; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void get_scl_sda_value(uint8_t line, uint8_t *scl, uint8_t* sda) | 101 | static void get_scl_sda_value(uint8_t line, uint8_t *scl, uint8_t* sda) |
@@ -546,8 +546,8 @@ int fiji_power_control_set_level(struct pp_hwmgr *hwmgr) | |||
546 | * but message to be 8 bit fraction for messages | 546 | * but message to be 8 bit fraction for messages |
547 | */ | 547 | */ |
548 | target_tdp = ((100 + adjust_percent) * (int)(cac_table->usTDP * 256)) / 100; | 548 | target_tdp = ((100 + adjust_percent) * (int)(cac_table->usTDP * 256)) / 100; |
549 | result = fiji_set_overdriver_target_tdp(hwmgr, (uint32_t)target_tdp); | 549 | result = fiji_set_overdriver_target_tdp(hwmgr, (uint32_t)target_tdp); |
550 | } | 550 | } |
551 | 551 | ||
552 | return result; | 552 | return result; |
553 | } | 553 | } |
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c b/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c index 001b8bb4143d..f9bf4fccbc79 100644 --- a/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c | |||
@@ -317,4 +317,3 @@ int phm_set_cpu_power_state(struct pp_hwmgr *hwmgr) | |||
317 | 317 | ||
318 | return 0; | 318 | return 0; |
319 | } | 319 | } |
320 | |||
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppevvmath.h b/drivers/gpu/drm/amd/powerplay/hwmgr/ppevvmath.h index 411cb0fcdf98..b7429a527828 100644 --- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppevvmath.h +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppevvmath.h | |||
@@ -117,379 +117,380 @@ int GetRoundedValue(fInt); /* Incomplete function - Usef | |||
117 | */ | 117 | */ |
118 | fInt fExponential(fInt exponent) /*Can be used to calculate e^exponent*/ | 118 | fInt fExponential(fInt exponent) /*Can be used to calculate e^exponent*/ |
119 | { | 119 | { |
120 | uint32_t i; | 120 | uint32_t i; |
121 | bool bNegated = false; | 121 | bool bNegated = false; |
122 | 122 | ||
123 | fInt fPositiveOne = ConvertToFraction(1); | 123 | fInt fPositiveOne = ConvertToFraction(1); |
124 | fInt fZERO = ConvertToFraction(0); | 124 | fInt fZERO = ConvertToFraction(0); |
125 | 125 | ||
126 | fInt lower_bound = Divide(78, 10000); | 126 | fInt lower_bound = Divide(78, 10000); |
127 | fInt solution = fPositiveOne; /*Starting off with baseline of 1 */ | 127 | fInt solution = fPositiveOne; /*Starting off with baseline of 1 */ |
128 | fInt error_term; | 128 | fInt error_term; |
129 | 129 | ||
130 | uint32_t k_array[11] = {55452, 27726, 13863, 6931, 4055, 2231, 1178, 606, 308, 155, 78}; | 130 | uint32_t k_array[11] = {55452, 27726, 13863, 6931, 4055, 2231, 1178, 606, 308, 155, 78}; |
131 | uint32_t expk_array[11] = {2560000, 160000, 40000, 20000, 15000, 12500, 11250, 10625, 10313, 10156, 10078}; | 131 | uint32_t expk_array[11] = {2560000, 160000, 40000, 20000, 15000, 12500, 11250, 10625, 10313, 10156, 10078}; |
132 | 132 | ||
133 | if (GreaterThan(fZERO, exponent)) { | 133 | if (GreaterThan(fZERO, exponent)) { |
134 | exponent = fNegate(exponent); | 134 | exponent = fNegate(exponent); |
135 | bNegated = true; | 135 | bNegated = true; |
136 | } | 136 | } |
137 | 137 | ||
138 | while (GreaterThan(exponent, lower_bound)) { | 138 | while (GreaterThan(exponent, lower_bound)) { |
139 | for (i = 0; i < 11; i++) { | 139 | for (i = 0; i < 11; i++) { |
140 | if (GreaterThan(exponent, GetScaledFraction(k_array[i], 10000))) { | 140 | if (GreaterThan(exponent, GetScaledFraction(k_array[i], 10000))) { |
141 | exponent = fSubtract(exponent, GetScaledFraction(k_array[i], 10000)); | 141 | exponent = fSubtract(exponent, GetScaledFraction(k_array[i], 10000)); |
142 | solution = fMultiply(solution, GetScaledFraction(expk_array[i], 10000)); | 142 | solution = fMultiply(solution, GetScaledFraction(expk_array[i], 10000)); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | error_term = fAdd(fPositiveOne, exponent); | 147 | error_term = fAdd(fPositiveOne, exponent); |
148 | 148 | ||
149 | solution = fMultiply(solution, error_term); | 149 | solution = fMultiply(solution, error_term); |
150 | 150 | ||
151 | if (bNegated) | 151 | if (bNegated) |
152 | solution = fDivide(fPositiveOne, solution); | 152 | solution = fDivide(fPositiveOne, solution); |
153 | 153 | ||
154 | return solution; | 154 | return solution; |
155 | } | 155 | } |
156 | 156 | ||
157 | fInt fNaturalLog(fInt value) | 157 | fInt fNaturalLog(fInt value) |
158 | { | 158 | { |
159 | uint32_t i; | 159 | uint32_t i; |
160 | fInt upper_bound = Divide(8, 1000); | 160 | fInt upper_bound = Divide(8, 1000); |
161 | fInt fNegativeOne = ConvertToFraction(-1); | 161 | fInt fNegativeOne = ConvertToFraction(-1); |
162 | fInt solution = ConvertToFraction(0); /*Starting off with baseline of 0 */ | 162 | fInt solution = ConvertToFraction(0); /*Starting off with baseline of 0 */ |
163 | fInt error_term; | 163 | fInt error_term; |
164 | 164 | ||
165 | uint32_t k_array[10] = {160000, 40000, 20000, 15000, 12500, 11250, 10625, 10313, 10156, 10078}; | 165 | uint32_t k_array[10] = {160000, 40000, 20000, 15000, 12500, 11250, 10625, 10313, 10156, 10078}; |
166 | uint32_t logk_array[10] = {27726, 13863, 6931, 4055, 2231, 1178, 606, 308, 155, 78}; | 166 | uint32_t logk_array[10] = {27726, 13863, 6931, 4055, 2231, 1178, 606, 308, 155, 78}; |
167 | 167 | ||
168 | while (GreaterThan(fAdd(value, fNegativeOne), upper_bound)) { | 168 | while (GreaterThan(fAdd(value, fNegativeOne), upper_bound)) { |
169 | for (i = 0; i < 10; i++) { | 169 | for (i = 0; i < 10; i++) { |
170 | if (GreaterThan(value, GetScaledFraction(k_array[i], 10000))) { | 170 | if (GreaterThan(value, GetScaledFraction(k_array[i], 10000))) { |
171 | value = fDivide(value, GetScaledFraction(k_array[i], 10000)); | 171 | value = fDivide(value, GetScaledFraction(k_array[i], 10000)); |
172 | solution = fAdd(solution, GetScaledFraction(logk_array[i], 10000)); | 172 | solution = fAdd(solution, GetScaledFraction(logk_array[i], 10000)); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | error_term = fAdd(fNegativeOne, value); | 177 | error_term = fAdd(fNegativeOne, value); |
178 | 178 | ||
179 | return (fAdd(solution, error_term)); | 179 | return (fAdd(solution, error_term)); |
180 | } | 180 | } |
181 | 181 | ||
182 | fInt fDecodeLinearFuse(uint32_t fuse_value, fInt f_min, fInt f_range, uint32_t bitlength) | 182 | fInt fDecodeLinearFuse(uint32_t fuse_value, fInt f_min, fInt f_range, uint32_t bitlength) |
183 | { | 183 | { |
184 | fInt f_fuse_value = Convert_ULONG_ToFraction(fuse_value); | 184 | fInt f_fuse_value = Convert_ULONG_ToFraction(fuse_value); |
185 | fInt f_bit_max_value = Convert_ULONG_ToFraction((uPow(2, bitlength)) - 1); | 185 | fInt f_bit_max_value = Convert_ULONG_ToFraction((uPow(2, bitlength)) - 1); |
186 | 186 | ||
187 | fInt f_decoded_value; | 187 | fInt f_decoded_value; |
188 | 188 | ||
189 | f_decoded_value = fDivide(f_fuse_value, f_bit_max_value); | 189 | f_decoded_value = fDivide(f_fuse_value, f_bit_max_value); |
190 | f_decoded_value = fMultiply(f_decoded_value, f_range); | 190 | f_decoded_value = fMultiply(f_decoded_value, f_range); |
191 | f_decoded_value = fAdd(f_decoded_value, f_min); | 191 | f_decoded_value = fAdd(f_decoded_value, f_min); |
192 | 192 | ||
193 | return f_decoded_value; | 193 | return f_decoded_value; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | fInt fDecodeLogisticFuse(uint32_t fuse_value, fInt f_average, fInt f_range, uint32_t bitlength) | 197 | fInt fDecodeLogisticFuse(uint32_t fuse_value, fInt f_average, fInt f_range, uint32_t bitlength) |
198 | { | 198 | { |
199 | fInt f_fuse_value = Convert_ULONG_ToFraction(fuse_value); | 199 | fInt f_fuse_value = Convert_ULONG_ToFraction(fuse_value); |
200 | fInt f_bit_max_value = Convert_ULONG_ToFraction((uPow(2, bitlength)) - 1); | 200 | fInt f_bit_max_value = Convert_ULONG_ToFraction((uPow(2, bitlength)) - 1); |
201 | 201 | ||
202 | fInt f_CONSTANT_NEG13 = ConvertToFraction(-13); | 202 | fInt f_CONSTANT_NEG13 = ConvertToFraction(-13); |
203 | fInt f_CONSTANT1 = ConvertToFraction(1); | 203 | fInt f_CONSTANT1 = ConvertToFraction(1); |
204 | 204 | ||
205 | fInt f_decoded_value; | 205 | fInt f_decoded_value; |
206 | 206 | ||
207 | f_decoded_value = fSubtract(fDivide(f_bit_max_value, f_fuse_value), f_CONSTANT1); | 207 | f_decoded_value = fSubtract(fDivide(f_bit_max_value, f_fuse_value), f_CONSTANT1); |
208 | f_decoded_value = fNaturalLog(f_decoded_value); | 208 | f_decoded_value = fNaturalLog(f_decoded_value); |
209 | f_decoded_value = fMultiply(f_decoded_value, fDivide(f_range, f_CONSTANT_NEG13)); | 209 | f_decoded_value = fMultiply(f_decoded_value, fDivide(f_range, f_CONSTANT_NEG13)); |
210 | f_decoded_value = fAdd(f_decoded_value, f_average); | 210 | f_decoded_value = fAdd(f_decoded_value, f_average); |
211 | 211 | ||
212 | return f_decoded_value; | 212 | return f_decoded_value; |
213 | } | 213 | } |
214 | 214 | ||
215 | fInt fDecodeLeakageID (uint32_t leakageID_fuse, fInt ln_max_div_min, fInt f_min, uint32_t bitlength) | 215 | fInt fDecodeLeakageID (uint32_t leakageID_fuse, fInt ln_max_div_min, fInt f_min, uint32_t bitlength) |
216 | { | 216 | { |
217 | fInt fLeakage; | 217 | fInt fLeakage; |
218 | fInt f_bit_max_value = Convert_ULONG_ToFraction((uPow(2, bitlength)) - 1); | 218 | fInt f_bit_max_value = Convert_ULONG_ToFraction((uPow(2, bitlength)) - 1); |
219 | 219 | ||
220 | fLeakage = fMultiply(ln_max_div_min, Convert_ULONG_ToFraction(leakageID_fuse)); | 220 | fLeakage = fMultiply(ln_max_div_min, Convert_ULONG_ToFraction(leakageID_fuse)); |
221 | fLeakage = fDivide(fLeakage, f_bit_max_value); | 221 | fLeakage = fDivide(fLeakage, f_bit_max_value); |
222 | fLeakage = fExponential(fLeakage); | 222 | fLeakage = fExponential(fLeakage); |
223 | fLeakage = fMultiply(fLeakage, f_min); | 223 | fLeakage = fMultiply(fLeakage, f_min); |
224 | 224 | ||
225 | return fLeakage; | 225 | return fLeakage; |
226 | } | 226 | } |
227 | 227 | ||
228 | fInt ConvertToFraction(int X) /*Add all range checking here. Is it possible to make fInt a private declaration? */ | 228 | fInt ConvertToFraction(int X) /*Add all range checking here. Is it possible to make fInt a private declaration? */ |
229 | { | 229 | { |
230 | fInt temp; | 230 | fInt temp; |
231 | 231 | ||
232 | if (X <= MAX) | 232 | if (X <= MAX) |
233 | temp.full = (X << SHIFT_AMOUNT); | 233 | temp.full = (X << SHIFT_AMOUNT); |
234 | else | 234 | else |
235 | temp.full = 0; | 235 | temp.full = 0; |
236 | 236 | ||
237 | return temp; | 237 | return temp; |
238 | } | 238 | } |
239 | 239 | ||
240 | fInt fNegate(fInt X) | 240 | fInt fNegate(fInt X) |
241 | { | 241 | { |
242 | fInt CONSTANT_NEGONE = ConvertToFraction(-1); | 242 | fInt CONSTANT_NEGONE = ConvertToFraction(-1); |
243 | return (fMultiply(X, CONSTANT_NEGONE)); | 243 | return (fMultiply(X, CONSTANT_NEGONE)); |
244 | } | 244 | } |
245 | 245 | ||
246 | fInt Convert_ULONG_ToFraction(uint32_t X) | 246 | fInt Convert_ULONG_ToFraction(uint32_t X) |
247 | { | 247 | { |
248 | fInt temp; | 248 | fInt temp; |
249 | 249 | ||
250 | if (X <= MAX) | 250 | if (X <= MAX) |
251 | temp.full = (X << SHIFT_AMOUNT); | 251 | temp.full = (X << SHIFT_AMOUNT); |
252 | else | 252 | else |
253 | temp.full = 0; | 253 | temp.full = 0; |
254 | 254 | ||
255 | return temp; | 255 | return temp; |
256 | } | 256 | } |
257 | 257 | ||
258 | fInt GetScaledFraction(int X, int factor) | 258 | fInt GetScaledFraction(int X, int factor) |
259 | { | 259 | { |
260 | int times_shifted, factor_shifted; | 260 | int times_shifted, factor_shifted; |
261 | bool bNEGATED; | 261 | bool bNEGATED; |
262 | fInt fValue; | 262 | fInt fValue; |
263 | 263 | ||
264 | times_shifted = 0; | 264 | times_shifted = 0; |
265 | factor_shifted = 0; | 265 | factor_shifted = 0; |
266 | bNEGATED = false; | 266 | bNEGATED = false; |
267 | 267 | ||
268 | if (X < 0) { | 268 | if (X < 0) { |
269 | X = -1*X; | 269 | X = -1*X; |
270 | bNEGATED = true; | 270 | bNEGATED = true; |
271 | } | 271 | } |
272 | 272 | ||
273 | if (factor < 0) { | 273 | if (factor < 0) { |
274 | factor = -1*factor; | 274 | factor = -1*factor; |
275 | 275 | bNEGATED = !bNEGATED; /*If bNEGATED = true due to X < 0, this will cover the case of negative cancelling negative */ | |
276 | bNEGATED = !bNEGATED; /*If bNEGATED = true due to X < 0, this will cover the case of negative cancelling negative */ | 276 | } |
277 | } | 277 | |
278 | 278 | if ((X > MAX) || factor > MAX) { | |
279 | if ((X > MAX) || factor > MAX) { | 279 | if ((X/factor) <= MAX) { |
280 | if ((X/factor) <= MAX) { | 280 | while (X > MAX) { |
281 | while (X > MAX) { | 281 | X = X >> 1; |
282 | X = X >> 1; | 282 | times_shifted++; |
283 | times_shifted++; | 283 | } |
284 | } | 284 | |
285 | 285 | while (factor > MAX) { | |
286 | while (factor > MAX) { | 286 | factor = factor >> 1; |
287 | factor = factor >> 1; | 287 | factor_shifted++; |
288 | factor_shifted++; | 288 | } |
289 | } | 289 | } else { |
290 | } else { | 290 | fValue.full = 0; |
291 | fValue.full = 0; | 291 | return fValue; |
292 | return fValue; | 292 | } |
293 | } | 293 | } |
294 | } | 294 | |
295 | 295 | if (factor == 1) | |
296 | if (factor == 1) | 296 | return (ConvertToFraction(X)); |
297 | return (ConvertToFraction(X)); | 297 | |
298 | 298 | fValue = fDivide(ConvertToFraction(X * uPow(-1, bNEGATED)), ConvertToFraction(factor)); | |
299 | fValue = fDivide(ConvertToFraction(X * uPow(-1, bNEGATED)), ConvertToFraction(factor)); | 299 | |
300 | 300 | fValue.full = fValue.full << times_shifted; | |
301 | fValue.full = fValue.full << times_shifted; | 301 | fValue.full = fValue.full >> factor_shifted; |
302 | fValue.full = fValue.full >> factor_shifted; | 302 | |
303 | 303 | return fValue; | |
304 | return fValue; | ||
305 | } | 304 | } |
306 | 305 | ||
307 | /* Addition using two fInts */ | 306 | /* Addition using two fInts */ |
308 | fInt fAdd (fInt X, fInt Y) | 307 | fInt fAdd (fInt X, fInt Y) |
309 | { | 308 | { |
310 | fInt Sum; | 309 | fInt Sum; |
311 | 310 | ||
312 | Sum.full = X.full + Y.full; | 311 | Sum.full = X.full + Y.full; |
313 | 312 | ||
314 | return Sum; | 313 | return Sum; |
315 | } | 314 | } |
316 | 315 | ||
317 | /* Addition using two fInts */ | 316 | /* Addition using two fInts */ |
318 | fInt fSubtract (fInt X, fInt Y) | 317 | fInt fSubtract (fInt X, fInt Y) |
319 | { | 318 | { |
320 | fInt Difference; | 319 | fInt Difference; |
321 | 320 | ||
322 | Difference.full = X.full - Y.full; | 321 | Difference.full = X.full - Y.full; |
323 | 322 | ||
324 | return Difference; | 323 | return Difference; |
325 | } | 324 | } |
326 | 325 | ||
327 | bool Equal(fInt A, fInt B) | 326 | bool Equal(fInt A, fInt B) |
328 | { | 327 | { |
329 | if (A.full == B.full) | 328 | if (A.full == B.full) |
330 | return true; | 329 | return true; |
331 | else | 330 | else |
332 | return false; | 331 | return false; |
333 | } | 332 | } |
334 | 333 | ||
335 | bool GreaterThan(fInt A, fInt B) | 334 | bool GreaterThan(fInt A, fInt B) |
336 | { | 335 | { |
337 | if (A.full > B.full) | 336 | if (A.full > B.full) |
338 | return true; | 337 | return true; |
339 | else | 338 | else |
340 | return false; | 339 | return false; |
341 | } | 340 | } |
342 | 341 | ||
343 | fInt fMultiply (fInt X, fInt Y) /* Uses 64-bit integers (int64_t) */ | 342 | fInt fMultiply (fInt X, fInt Y) /* Uses 64-bit integers (int64_t) */ |
344 | { | 343 | { |
345 | fInt Product; | 344 | fInt Product; |
346 | int64_t tempProduct; | 345 | int64_t tempProduct; |
347 | bool X_LessThanOne, Y_LessThanOne; | 346 | bool X_LessThanOne, Y_LessThanOne; |
348 | 347 | ||
349 | X_LessThanOne = (X.partial.real == 0 && X.partial.decimal != 0 && X.full >= 0); | 348 | X_LessThanOne = (X.partial.real == 0 && X.partial.decimal != 0 && X.full >= 0); |
350 | Y_LessThanOne = (Y.partial.real == 0 && Y.partial.decimal != 0 && Y.full >= 0); | 349 | Y_LessThanOne = (Y.partial.real == 0 && Y.partial.decimal != 0 && Y.full >= 0); |
351 | 350 | ||
352 | /*The following is for a very specific common case: Non-zero number with ONLY fractional portion*/ | 351 | /*The following is for a very specific common case: Non-zero number with ONLY fractional portion*/ |
353 | /* TEMPORARILY DISABLED - CAN BE USED TO IMPROVE PRECISION | 352 | /* TEMPORARILY DISABLED - CAN BE USED TO IMPROVE PRECISION |
354 | 353 | ||
355 | if (X_LessThanOne && Y_LessThanOne) { | 354 | if (X_LessThanOne && Y_LessThanOne) { |
356 | Product.full = X.full * Y.full; | 355 | Product.full = X.full * Y.full; |
357 | return Product | 356 | return Product |
358 | }*/ | 357 | }*/ |
359 | 358 | ||
360 | tempProduct = ((int64_t)X.full) * ((int64_t)Y.full); /*Q(16,16)*Q(16,16) = Q(32, 32) - Might become a negative number! */ | 359 | tempProduct = ((int64_t)X.full) * ((int64_t)Y.full); /*Q(16,16)*Q(16,16) = Q(32, 32) - Might become a negative number! */ |
361 | tempProduct = tempProduct >> 16; /*Remove lagging 16 bits - Will lose some precision from decimal; */ | 360 | tempProduct = tempProduct >> 16; /*Remove lagging 16 bits - Will lose some precision from decimal; */ |
362 | Product.full = (int)tempProduct; /*The int64_t will lose the leading 16 bits that were part of the integer portion */ | 361 | Product.full = (int)tempProduct; /*The int64_t will lose the leading 16 bits that were part of the integer portion */ |
363 | 362 | ||
364 | return Product; | 363 | return Product; |
365 | } | 364 | } |
366 | 365 | ||
367 | fInt fDivide (fInt X, fInt Y) | 366 | fInt fDivide (fInt X, fInt Y) |
368 | { | 367 | { |
369 | fInt fZERO, fQuotient; | 368 | fInt fZERO, fQuotient; |
370 | int64_t longlongX, longlongY; | 369 | int64_t longlongX, longlongY; |
371 | 370 | ||
372 | fZERO = ConvertToFraction(0); | 371 | fZERO = ConvertToFraction(0); |
373 | 372 | ||
374 | if (Equal(Y, fZERO)) | 373 | if (Equal(Y, fZERO)) |
375 | return fZERO; | 374 | return fZERO; |
376 | 375 | ||
377 | longlongX = (int64_t)X.full; | 376 | longlongX = (int64_t)X.full; |
378 | longlongY = (int64_t)Y.full; | 377 | longlongY = (int64_t)Y.full; |
379 | 378 | ||
380 | longlongX = longlongX << 16; /*Q(16,16) -> Q(32,32) */ | 379 | longlongX = longlongX << 16; /*Q(16,16) -> Q(32,32) */ |
381 | 380 | ||
382 | div64_s64(longlongX, longlongY); /*Q(32,32) divided by Q(16,16) = Q(16,16) Back to original format */ | 381 | div64_s64(longlongX, longlongY); /*Q(32,32) divided by Q(16,16) = Q(16,16) Back to original format */ |
383 | 382 | ||
384 | fQuotient.full = (int)longlongX; | 383 | fQuotient.full = (int)longlongX; |
385 | return fQuotient; | 384 | return fQuotient; |
386 | } | 385 | } |
387 | 386 | ||
388 | int ConvertBackToInteger (fInt A) /*THIS is the function that will be used to check with the Golden settings table*/ | 387 | int ConvertBackToInteger (fInt A) /*THIS is the function that will be used to check with the Golden settings table*/ |
389 | { | 388 | { |
390 | fInt fullNumber, scaledDecimal, scaledReal; | 389 | fInt fullNumber, scaledDecimal, scaledReal; |
391 | 390 | ||
392 | scaledReal.full = GetReal(A) * uPow(10, PRECISION-1); /* DOUBLE CHECK THISSSS!!! */ | 391 | scaledReal.full = GetReal(A) * uPow(10, PRECISION-1); /* DOUBLE CHECK THISSSS!!! */ |
393 | 392 | ||
394 | scaledDecimal.full = uGetScaledDecimal(A); | 393 | scaledDecimal.full = uGetScaledDecimal(A); |
395 | 394 | ||
396 | fullNumber = fAdd(scaledDecimal,scaledReal); | 395 | fullNumber = fAdd(scaledDecimal,scaledReal); |
397 | 396 | ||
398 | return fullNumber.full; | 397 | return fullNumber.full; |
399 | } | 398 | } |
400 | 399 | ||
401 | fInt fGetSquare(fInt A) | 400 | fInt fGetSquare(fInt A) |
402 | { | 401 | { |
403 | return fMultiply(A,A); | 402 | return fMultiply(A,A); |
404 | } | 403 | } |
405 | 404 | ||
406 | /* x_new = x_old - (x_old^2 - C) / (2 * x_old) */ | 405 | /* x_new = x_old - (x_old^2 - C) / (2 * x_old) */ |
407 | fInt fSqrt(fInt num) | 406 | fInt fSqrt(fInt num) |
408 | { | 407 | { |
409 | fInt F_divide_Fprime, Fprime; | 408 | fInt F_divide_Fprime, Fprime; |
410 | fInt test; | 409 | fInt test; |
411 | fInt twoShifted; | 410 | fInt twoShifted; |
412 | int seed, counter, error; | 411 | int seed, counter, error; |
413 | fInt x_new, x_old, C, y; | 412 | fInt x_new, x_old, C, y; |
414 | 413 | ||
415 | fInt fZERO = ConvertToFraction(0); | 414 | fInt fZERO = ConvertToFraction(0); |
416 | /* (0 > num) is the same as (num < 0), i.e., num is negative */ | ||
417 | if (GreaterThan(fZERO, num) || Equal(fZERO, num)) | ||
418 | return fZERO; | ||
419 | 415 | ||
420 | C = num; | 416 | /* (0 > num) is the same as (num < 0), i.e., num is negative */ |
421 | 417 | ||
422 | if (num.partial.real > 3000) | 418 | if (GreaterThan(fZERO, num) || Equal(fZERO, num)) |
423 | seed = 60; | 419 | return fZERO; |
424 | else if (num.partial.real > 1000) | ||
425 | seed = 30; | ||
426 | else if (num.partial.real > 100) | ||
427 | seed = 10; | ||
428 | else | ||
429 | seed = 2; | ||
430 | 420 | ||
431 | counter = 0; | 421 | C = num; |
432 | 422 | ||
433 | if (Equal(num, fZERO)) /*Square Root of Zero is zero */ | 423 | if (num.partial.real > 3000) |
434 | return fZERO; | 424 | seed = 60; |
425 | else if (num.partial.real > 1000) | ||
426 | seed = 30; | ||
427 | else if (num.partial.real > 100) | ||
428 | seed = 10; | ||
429 | else | ||
430 | seed = 2; | ||
431 | |||
432 | counter = 0; | ||
435 | 433 | ||
436 | twoShifted = ConvertToFraction(2); | 434 | if (Equal(num, fZERO)) /*Square Root of Zero is zero */ |
437 | x_new = ConvertToFraction(seed); | 435 | return fZERO; |
438 | 436 | ||
439 | do { | 437 | twoShifted = ConvertToFraction(2); |
440 | counter++; | 438 | x_new = ConvertToFraction(seed); |
441 | 439 | ||
442 | x_old.full = x_new.full; | 440 | do { |
441 | counter++; | ||
443 | 442 | ||
444 | test = fGetSquare(x_old); /*1.75*1.75 is reverting back to 1 when shifted down */ | 443 | x_old.full = x_new.full; |
445 | y = fSubtract(test, C); /*y = f(x) = x^2 - C; */ | ||
446 | 444 | ||
447 | Fprime = fMultiply(twoShifted, x_old); | 445 | test = fGetSquare(x_old); /*1.75*1.75 is reverting back to 1 when shifted down */ |
448 | F_divide_Fprime = fDivide(y, Fprime); | 446 | y = fSubtract(test, C); /*y = f(x) = x^2 - C; */ |
449 | 447 | ||
450 | x_new = fSubtract(x_old, F_divide_Fprime); | 448 | Fprime = fMultiply(twoShifted, x_old); |
449 | F_divide_Fprime = fDivide(y, Fprime); | ||
451 | 450 | ||
452 | error = ConvertBackToInteger(x_new) - ConvertBackToInteger(x_old); | 451 | x_new = fSubtract(x_old, F_divide_Fprime); |
453 | 452 | ||
454 | if (counter > 20) /*20 is already way too many iterations. If we dont have an answer by then, we never will*/ | 453 | error = ConvertBackToInteger(x_new) - ConvertBackToInteger(x_old); |
455 | return x_new; | ||
456 | 454 | ||
457 | } while (uAbs(error) > 0); | 455 | if (counter > 20) /*20 is already way too many iterations. If we dont have an answer by then, we never will*/ |
456 | return x_new; | ||
458 | 457 | ||
459 | return (x_new); | 458 | } while (uAbs(error) > 0); |
459 | |||
460 | return (x_new); | ||
460 | } | 461 | } |
461 | 462 | ||
462 | void SolveQuadracticEqn(fInt A, fInt B, fInt C, fInt Roots[]) | 463 | void SolveQuadracticEqn(fInt A, fInt B, fInt C, fInt Roots[]) |
463 | { | 464 | { |
464 | fInt* pRoots = &Roots[0]; | 465 | fInt *pRoots = &Roots[0]; |
465 | fInt temp, root_first, root_second; | 466 | fInt temp, root_first, root_second; |
466 | fInt f_CONSTANT10, f_CONSTANT100; | 467 | fInt f_CONSTANT10, f_CONSTANT100; |
467 | 468 | ||
468 | f_CONSTANT100 = ConvertToFraction(100); | 469 | f_CONSTANT100 = ConvertToFraction(100); |
469 | f_CONSTANT10 = ConvertToFraction(10); | 470 | f_CONSTANT10 = ConvertToFraction(10); |
470 | 471 | ||
471 | while(GreaterThan(A, f_CONSTANT100) || GreaterThan(B, f_CONSTANT100) || GreaterThan(C, f_CONSTANT100)) { | 472 | while(GreaterThan(A, f_CONSTANT100) || GreaterThan(B, f_CONSTANT100) || GreaterThan(C, f_CONSTANT100)) { |
472 | A = fDivide(A, f_CONSTANT10); | 473 | A = fDivide(A, f_CONSTANT10); |
473 | B = fDivide(B, f_CONSTANT10); | 474 | B = fDivide(B, f_CONSTANT10); |
474 | C = fDivide(C, f_CONSTANT10); | 475 | C = fDivide(C, f_CONSTANT10); |
475 | } | 476 | } |
476 | 477 | ||
477 | temp = fMultiply(ConvertToFraction(4), A); /* root = 4*A */ | 478 | temp = fMultiply(ConvertToFraction(4), A); /* root = 4*A */ |
478 | temp = fMultiply(temp, C); /* root = 4*A*C */ | 479 | temp = fMultiply(temp, C); /* root = 4*A*C */ |
479 | temp = fSubtract(fGetSquare(B), temp); /* root = b^2 - 4AC */ | 480 | temp = fSubtract(fGetSquare(B), temp); /* root = b^2 - 4AC */ |
480 | temp = fSqrt(temp); /*root = Sqrt (b^2 - 4AC); */ | 481 | temp = fSqrt(temp); /*root = Sqrt (b^2 - 4AC); */ |
481 | 482 | ||
482 | root_first = fSubtract(fNegate(B), temp); /* b - Sqrt(b^2 - 4AC) */ | 483 | root_first = fSubtract(fNegate(B), temp); /* b - Sqrt(b^2 - 4AC) */ |
483 | root_second = fAdd(fNegate(B), temp); /* b + Sqrt(b^2 - 4AC) */ | 484 | root_second = fAdd(fNegate(B), temp); /* b + Sqrt(b^2 - 4AC) */ |
484 | 485 | ||
485 | root_first = fDivide(root_first, ConvertToFraction(2)); /* [b +- Sqrt(b^2 - 4AC)]/[2] */ | 486 | root_first = fDivide(root_first, ConvertToFraction(2)); /* [b +- Sqrt(b^2 - 4AC)]/[2] */ |
486 | root_first = fDivide(root_first, A); /*[b +- Sqrt(b^2 - 4AC)]/[2*A] */ | 487 | root_first = fDivide(root_first, A); /*[b +- Sqrt(b^2 - 4AC)]/[2*A] */ |
487 | 488 | ||
488 | root_second = fDivide(root_second, ConvertToFraction(2)); /* [b +- Sqrt(b^2 - 4AC)]/[2] */ | 489 | root_second = fDivide(root_second, ConvertToFraction(2)); /* [b +- Sqrt(b^2 - 4AC)]/[2] */ |
489 | root_second = fDivide(root_second, A); /*[b +- Sqrt(b^2 - 4AC)]/[2*A] */ | 490 | root_second = fDivide(root_second, A); /*[b +- Sqrt(b^2 - 4AC)]/[2*A] */ |
490 | 491 | ||
491 | *(pRoots + 0) = root_first; | 492 | *(pRoots + 0) = root_first; |
492 | *(pRoots + 1) = root_second; | 493 | *(pRoots + 1) = root_second; |
493 | } | 494 | } |
494 | 495 | ||
495 | /* ----------------------------------------------------------------------------- | 496 | /* ----------------------------------------------------------------------------- |
@@ -500,61 +501,58 @@ void SolveQuadracticEqn(fInt A, fInt B, fInt C, fInt Roots[]) | |||
500 | /* Addition using two normal ints - Temporary - Use only for testing purposes?. */ | 501 | /* Addition using two normal ints - Temporary - Use only for testing purposes?. */ |
501 | fInt Add (int X, int Y) | 502 | fInt Add (int X, int Y) |
502 | { | 503 | { |
503 | fInt A, B, Sum; | 504 | fInt A, B, Sum; |
504 | 505 | ||
505 | A.full = (X << SHIFT_AMOUNT); | 506 | A.full = (X << SHIFT_AMOUNT); |
506 | B.full = (Y << SHIFT_AMOUNT); | 507 | B.full = (Y << SHIFT_AMOUNT); |
507 | 508 | ||
508 | Sum.full = A.full + B.full; | 509 | Sum.full = A.full + B.full; |
509 | 510 | ||
510 | return Sum; | 511 | return Sum; |
511 | } | 512 | } |
512 | 513 | ||
513 | /* Conversion Functions */ | 514 | /* Conversion Functions */ |
514 | int GetReal (fInt A) | 515 | int GetReal (fInt A) |
515 | { | 516 | { |
516 | return (A.full >> SHIFT_AMOUNT); | 517 | return (A.full >> SHIFT_AMOUNT); |
517 | } | 518 | } |
518 | 519 | ||
519 | /* Temporarily Disabled */ | 520 | /* Temporarily Disabled */ |
520 | int GetRoundedValue(fInt A) /*For now, round the 3rd decimal place */ | 521 | int GetRoundedValue(fInt A) /*For now, round the 3rd decimal place */ |
521 | { | 522 | { |
522 | /* ROUNDING TEMPORARLY DISABLED | 523 | /* ROUNDING TEMPORARLY DISABLED |
523 | int temp = A.full; | 524 | int temp = A.full; |
524 | 525 | int decimal_cutoff, decimal_mask = 0x000001FF; | |
525 | int decimal_cutoff, decimal_mask = 0x000001FF; | 526 | decimal_cutoff = temp & decimal_mask; |
526 | 527 | if (decimal_cutoff > 0x147) { | |
527 | decimal_cutoff = temp & decimal_mask; | 528 | temp += 673; |
528 | 529 | }*/ | |
529 | 530 | ||
530 | if (decimal_cutoff > 0x147) { | 531 | return ConvertBackToInteger(A)/10000; /*Temporary - in case this was used somewhere else */ |
531 | temp += 673; | ||
532 | }*/ | ||
533 | |||
534 | return ConvertBackToInteger(A)/10000; /*Temporary - in case this was used somewhere else */ | ||
535 | } | 532 | } |
536 | 533 | ||
537 | fInt Multiply (int X, int Y) | 534 | fInt Multiply (int X, int Y) |
538 | { | 535 | { |
539 | fInt A, B, Product; | 536 | fInt A, B, Product; |
540 | 537 | ||
541 | A.full = X << SHIFT_AMOUNT; | 538 | A.full = X << SHIFT_AMOUNT; |
542 | B.full = Y << SHIFT_AMOUNT; | 539 | B.full = Y << SHIFT_AMOUNT; |
543 | 540 | ||
544 | Product = fMultiply(A, B); | 541 | Product = fMultiply(A, B); |
545 | 542 | ||
546 | return Product; | 543 | return Product; |
547 | } | 544 | } |
545 | |||
548 | fInt Divide (int X, int Y) | 546 | fInt Divide (int X, int Y) |
549 | { | 547 | { |
550 | fInt A, B, Quotient; | 548 | fInt A, B, Quotient; |
551 | 549 | ||
552 | A.full = X << SHIFT_AMOUNT; | 550 | A.full = X << SHIFT_AMOUNT; |
553 | B.full = Y << SHIFT_AMOUNT; | 551 | B.full = Y << SHIFT_AMOUNT; |
554 | 552 | ||
555 | Quotient = fDivide(A, B); | 553 | Quotient = fDivide(A, B); |
556 | 554 | ||
557 | return Quotient; | 555 | return Quotient; |
558 | } | 556 | } |
559 | 557 | ||
560 | int uGetScaledDecimal (fInt A) /*Converts the fractional portion to whole integers - Costly function */ | 558 | int uGetScaledDecimal (fInt A) /*Converts the fractional portion to whole integers - Costly function */ |
@@ -563,16 +561,13 @@ int uGetScaledDecimal (fInt A) /*Converts the fractional portion to whole intege | |||
563 | int i, scaledDecimal = 0, tmp = A.partial.decimal; | 561 | int i, scaledDecimal = 0, tmp = A.partial.decimal; |
564 | 562 | ||
565 | for (i = 0; i < PRECISION; i++) { | 563 | for (i = 0; i < PRECISION; i++) { |
566 | dec[i] = tmp / (1 << SHIFT_AMOUNT); | 564 | dec[i] = tmp / (1 << SHIFT_AMOUNT); |
567 | 565 | tmp = tmp - ((1 << SHIFT_AMOUNT)*dec[i]); | |
568 | tmp = tmp - ((1 << SHIFT_AMOUNT)*dec[i]); | 566 | tmp *= 10; |
569 | 567 | scaledDecimal = scaledDecimal + dec[i]*uPow(10, PRECISION - 1 -i); | |
570 | tmp *= 10; | 568 | } |
571 | |||
572 | scaledDecimal = scaledDecimal + dec[i]*uPow(10, PRECISION - 1 -i); | ||
573 | } | ||
574 | 569 | ||
575 | return scaledDecimal; | 570 | return scaledDecimal; |
576 | } | 571 | } |
577 | 572 | ||
578 | int uPow(int base, int power) | 573 | int uPow(int base, int power) |
@@ -601,17 +596,17 @@ int uAbs(int X) | |||
601 | 596 | ||
602 | fInt fRoundUpByStepSize(fInt A, fInt fStepSize, bool error_term) | 597 | fInt fRoundUpByStepSize(fInt A, fInt fStepSize, bool error_term) |
603 | { | 598 | { |
604 | fInt solution; | 599 | fInt solution; |
605 | 600 | ||
606 | solution = fDivide(A, fStepSize); | 601 | solution = fDivide(A, fStepSize); |
607 | solution.partial.decimal = 0; /*All fractional digits changes to 0 */ | 602 | solution.partial.decimal = 0; /*All fractional digits changes to 0 */ |
608 | 603 | ||
609 | if (error_term) | 604 | if (error_term) |
610 | solution.partial.real += 1; /*Error term of 1 added */ | 605 | solution.partial.real += 1; /*Error term of 1 added */ |
611 | 606 | ||
612 | solution = fMultiply(solution, fStepSize); | 607 | solution = fMultiply(solution, fStepSize); |
613 | solution = fAdd(solution, fStepSize); | 608 | solution = fAdd(solution, fStepSize); |
614 | 609 | ||
615 | return solution; | 610 | return solution; |
616 | } | 611 | } |
617 | 612 | ||
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c index 45997e609fd6..21c31db0df26 100644 --- a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c +++ b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c | |||
@@ -228,9 +228,9 @@ int fiji_send_msg_to_smc(struct pp_smumgr *smumgr, uint16_t msg) | |||
228 | } | 228 | } |
229 | 229 | ||
230 | cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg); | 230 | cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg); |
231 | SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0); | 231 | SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0); |
232 | 232 | ||
233 | return 0; | 233 | return 0; |
234 | } | 234 | } |
235 | 235 | ||
236 | /** | 236 | /** |
@@ -557,7 +557,7 @@ static int fiji_request_smu_specific_fw_load(struct pp_smumgr *smumgr, uint32_t | |||
557 | /* For non-virtualization cases, | 557 | /* For non-virtualization cases, |
558 | * SMU loads all FWs at once in fiji_request_smu_load_fw. | 558 | * SMU loads all FWs at once in fiji_request_smu_load_fw. |
559 | */ | 559 | */ |
560 | return 0; | 560 | return 0; |
561 | } | 561 | } |
562 | 562 | ||
563 | static int fiji_start_smu_in_protection_mode(struct pp_smumgr *smumgr) | 563 | static int fiji_start_smu_in_protection_mode(struct pp_smumgr *smumgr) |
@@ -723,7 +723,7 @@ static int fiji_start_avfs_btc(struct pp_smumgr *smumgr) | |||
723 | /* clear reset */ | 723 | /* clear reset */ |
724 | cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0); | 724 | cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0); |
725 | 725 | ||
726 | return result; | 726 | return result; |
727 | } | 727 | } |
728 | 728 | ||
729 | int fiji_setup_pm_fuse_for_avfs(struct pp_smumgr *smumgr) | 729 | int fiji_setup_pm_fuse_for_avfs(struct pp_smumgr *smumgr) |