layerscape: make uImage with zImage for 32-bit kernel
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 7030-fmd-use-kernel-api-for-64bit-division.patch
1 From c86be7b4f9ca4f4c8c916a9c350edbcd0e86a528 Mon Sep 17 00:00:00 2001
2 From: Madalin Bucur <madalin.bucur@freescale.com>
3 Date: Mon, 18 Apr 2016 16:41:59 +0300
4 Subject: [PATCH 30/70] fmd: use kernel api for 64bit division
5
6 Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
7 ---
8 .../freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c | 1 +
9 .../sdk_fman/Peripherals/FM/Pcd/fm_plcr.c | 5 +++--
10 .../freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c | 1 +
11 .../freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c | 12 ++++++------
12 .../freescale/sdk_fman/Peripherals/FM/fm.c | 5 +++--
13 .../freescale/sdk_fman/Peripherals/FM/fman.c | 7 +++----
14 .../net/ethernet/freescale/sdk_fman/inc/math_ext.h | 1 +
15 .../net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h | 2 +-
16 8 files changed, 19 insertions(+), 15 deletions(-)
17
18 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
19 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
20 @@ -36,6 +36,7 @@
21
22 @Description FM Coarse Classifier implementation
23 *//***************************************************************************/
24 +#include <linux/math64.h>
25 #include "std_ext.h"
26 #include "error_ext.h"
27 #include "string_ext.h"
28 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
29 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
30 @@ -36,6 +36,7 @@
31
32 @Description FM PCD POLICER...
33 *//***************************************************************************/
34 +#include <linux/math64.h>
35 #include "std_ext.h"
36 #include "error_ext.h"
37 #include "string_ext.h"
38 @@ -205,13 +206,13 @@ static void GetInfoRateReg(e_FmPcdPlcrRa
39 div = 1000000000; /* nano */
40 div *= 10; /* 10 nano */
41 }
42 - *p_Integer = (tmp<<fppShift)/div;
43 + *p_Integer = div64_u64(tmp<<fppShift, div);
44
45 /* for calculating the fraction, we will recalculate cir and deduct the integer.
46 * For precision, we will multiply by 2^16. we do not divid back, since we write
47 * this value as fraction - see spec.
48 */
49 - *p_Fraction = (((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div))/div;
50 + *p_Fraction = div64_u64(((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div), div);
51 }
52
53 /* .......... */
54 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
55 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
56 @@ -36,6 +36,7 @@
57
58 @Description FM PCD ...
59 *//***************************************************************************/
60 +#include <linux/math64.h>
61 #include "std_ext.h"
62 #include "error_ext.h"
63 #include "string_ext.h"
64 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
65 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
66 @@ -38,7 +38,7 @@
67
68 @Cautions None
69 *//***************************************************************************/
70 -
71 +#include <linux/math64.h>
72 #include "error_ext.h"
73 #include "debug_ext.h"
74 #include "string_ext.h"
75 @@ -470,11 +470,11 @@ t_Error FM_RTC_SetAlarm(t_Handle h_FmRtc
76 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
77 ("Alarm time must be equal or larger than RTC period - %d nanoseconds",
78 p_Rtc->clockPeriodNanoSec));
79 - if (p_FmRtcAlarmParams->alarmTime % (uint64_t)p_Rtc->clockPeriodNanoSec)
80 + tmpAlarm = p_FmRtcAlarmParams->alarmTime;
81 + if (do_div(tmpAlarm, p_Rtc->clockPeriodNanoSec))
82 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
83 ("Alarm time must be a multiple of RTC period - %d nanoseconds",
84 p_Rtc->clockPeriodNanoSec));
85 - tmpAlarm = p_FmRtcAlarmParams->alarmTime/(uint64_t)p_Rtc->clockPeriodNanoSec;
86
87 if (p_FmRtcAlarmParams->f_AlarmCallback)
88 {
89 @@ -508,11 +508,11 @@ t_Error FM_RTC_SetPeriodicPulse(t_Handle
90 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
91 ("Periodic pulse must be equal or larger than RTC period - %d nanoseconds",
92 p_Rtc->clockPeriodNanoSec));
93 - if (p_FmRtcPeriodicPulseParams->periodicPulsePeriod % (uint64_t)p_Rtc->clockPeriodNanoSec)
94 + tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod;
95 + if (do_div(tmpFiper, p_Rtc->clockPeriodNanoSec))
96 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
97 ("Periodic pulse must be a multiple of RTC period - %d nanoseconds",
98 p_Rtc->clockPeriodNanoSec));
99 - tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod/(uint64_t)p_Rtc->clockPeriodNanoSec;
100 if (tmpFiper & 0xffffffff00000000LL)
101 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
102 ("Periodic pulse/RTC Period must be smaller than 4294967296",
103 @@ -628,7 +628,7 @@ t_Error FM_RTC_SetCurrentTime(t_Handle h
104 SANITY_CHECK_RETURN_ERROR(p_Rtc, E_INVALID_HANDLE);
105 SANITY_CHECK_RETURN_ERROR(!p_Rtc->p_RtcDriverParam, E_INVALID_STATE);
106
107 - ts = ts/p_Rtc->clockPeriodNanoSec;
108 + do_div(ts, p_Rtc->clockPeriodNanoSec);
109 fman_rtc_set_timer(p_Rtc->p_MemMap, (int64_t)ts);
110
111 return E_OK;
112 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
113 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
114 @@ -43,6 +43,7 @@
115 #include "sprint_ext.h"
116 #include "debug_ext.h"
117 #include "fm_muram_ext.h"
118 +#include <linux/math64.h>
119
120 #include "fm_common.h"
121 #include "fm_ipc.h"
122 @@ -5087,9 +5088,9 @@ t_Error FM_CtrlMonGetCounters(t_Handle h
123 effValue = (uint64_t)
124 ((uint64_t)GET_UINT32(p_MonRegs->tpc2h) << 32 | GET_UINT32(p_MonRegs->tpc2l));
125
126 - p_Mon->percentCnt[0] = (uint8_t)((clkCnt - utilValue) * 100 / clkCnt);
127 + p_Mon->percentCnt[0] = (uint8_t)div64_u64((clkCnt - utilValue) * 100, clkCnt);
128 if (clkCnt != utilValue)
129 - p_Mon->percentCnt[1] = (uint8_t)(((clkCnt - utilValue) - effValue) * 100 / (clkCnt - utilValue));
130 + p_Mon->percentCnt[1] = (uint8_t)div64_u64(((clkCnt - utilValue) - effValue) * 100, clkCnt - utilValue);
131 else
132 p_Mon->percentCnt[1] = 0;
133
134 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
135 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
136 @@ -31,7 +31,7 @@
137 */
138
139
140 -
141 +#include <linux/math64.h>
142 #include "fsl_fman.h"
143 #include "dpaa_integration_ext.h"
144
145 @@ -186,10 +186,9 @@ void fman_enable_time_stamp(struct fman_
146 * we do not div back, since we write this value as a fraction
147 * see spec */
148
149 - frac = (((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq)
150 - / fm_clk_freq;
151 + frac = ((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq;
152 /* we check remainder of the division in order to round up if not int */
153 - if (((ts_freq << 16) - (intgr << 16)*fm_clk_freq) % fm_clk_freq)
154 + if (do_div(frac, fm_clk_freq))
155 frac++;
156
157 tmp = (intgr << FPM_TS_INT_SHIFT) | (uint16_t)frac;
158 --- a/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
159 +++ b/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
160 @@ -37,6 +37,7 @@
161
162 #if defined(NCSW_LINUX) && defined(__KERNEL__)
163 #include <linux/math.h>
164 +#include <linux/math64.h>
165
166 #elif defined(__MWERKS__)
167 #define LOW(x) ( sizeof(x)==8 ? *(1+(int32_t*)&x) : (*(int32_t*)&x))
168 --- a/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
169 +++ b/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
170 @@ -142,7 +142,7 @@ do
171 } while (0)
172
173 /* Ceiling division - not the fastest way, but safer in terms of overflow */
174 -#define DIV_CEIL(x,y) (((x)/(y)) + ((((((x)/(y)))*(y)) == (x)) ? 0 : 1))
175 +#define DIV_CEIL(x,y) (div64_u64((x),(y)) + (((div64_u64((x),(y))*(y)) == (x)) ? 0 : 1))
176
177 /* Round up a number to be a multiple of a second number */
178 #define ROUND_UP(x,y) ((((x) + (y) - 1) / (y)) * (y))