Skip to content

Commit 1013e34

Browse files
siclimyauwai
authored andcommitted
HSD #14012726917: Replaced __udelay inline function with __socfpga_udelay inline function
The udelay function is used by both uboot proper and PSCI code for timeout handling.The __udelay inline function was not included in '__secure' section which causes random error when called by PSCI code that run in '__secure' section. The solution is replaced the __udelay inline function with __socfpga_udelay inline function in timer.h, so that the code can be included in '__secure' section. Signed-off-by: Siew Chin Lim <elly.siew.chin.lim@intel.com>
1 parent 4ce4304 commit 1013e34

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

arch/arm/mach-socfpga/include/mach/timer.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef _SOCFPGA_TIMER_H_
77
#define _SOCFPGA_TIMER_H_
88

9+
#include <div64.h>
10+
911
struct socfpga_timer {
1012
u32load_val;
1113
u32curr_val;
@@ -14,4 +16,32 @@ struct socfpga_timer {
1416
u32int_stat;
1517
};
1618

19+
static __always_inline u64 __socfpga_get_time_stamp(void)
20+
{
21+
u64 cntpct;
22+
23+
isb();
24+
asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
25+
return cntpct;
26+
}
27+
28+
static __always_inline u64 __socfpga_usec_to_tick(u64 usec)
29+
{
30+
u64 tick = usec;
31+
u64 cntfrq;
32+
33+
asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
34+
tick *= cntfrq;
35+
do_div(tick, 1000000);
36+
return tick;
37+
}
38+
39+
static __always_inline void __socfpga_udelay(u64 usec)
40+
{
41+
u64 tmp = __socfpga_get_time_stamp() + __socfpga_usec_to_tick(usec);
42+
43+
while (__socfpga_get_time_stamp() < tmp + 1)
44+
;
45+
}
46+
1747
#endif

arch/arm/mach-socfpga/mailbox_s10.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <asm/arch/mailbox_s10.h>
1212
#include <asm/arch/smc_api.h>
1313
#include <asm/arch/system_manager.h>
14+
#include <asm/arch/timer.h>
1415
#include <asm/arch/rsu.h>
1516
#include <asm/secure.h>
1617
#include <asm/system.h>
@@ -39,7 +40,7 @@ static __always_inline int mbox_polling_resp(u32 rout)
3940
if (rout != rin)
4041
return 0;
4142

42-
__udelay(1000);
43+
__socfpga_udelay(1000);
4344
i--;
4445
}
4546

@@ -63,7 +64,7 @@ static __always_inline int mbox_wait_for_cmdbuf_empty(u32 cin)
6364
while (timeout) {
6465
if (mbox_is_cmdbuf_empty(cin))
6566
return 0;
66-
__udelay(1000);
67+
__socfpga_udelay(1000);
6768
timeout--;
6869
}
6970

@@ -83,7 +84,7 @@ static __always_inline int mbox_write_cmd_buffer(u32 *cin, u32 data,
8384
MBOX_WRITEL(1, MBOX_DOORBELL_TO_SDM);
8485
*is_cmdbuf_overflow = 1;
8586
}
86-
__udelay(1000);
87+
__socfpga_udelay(1000);
8788
} else {
8889
/* write header to circular buffer */
8990
MBOX_WRITE_CMD_BUF(data, (*cin)++);
@@ -229,7 +230,7 @@ static __always_inline int mbox_send_cmd_common(u8 id, u32 cmd, u8 is_indirect,
229230
do {
230231
if (MBOX_READL(MBOX_DOORBELL_FROM_SDM))
231232
break;
232-
__udelay(1000);
233+
__socfpga_udelay(1000);
233234
} while (--ret);
234235

235236
if (!ret)
@@ -318,7 +319,7 @@ static __always_inline int mbox_send_cmd_common_retry(u8 id, u32 cmd,
318319
ret = mbox_send_cmd_common(id, cmd, is_indirect, len, arg,
319320
urgent, resp_buf_len, resp_buf);
320321
if (ret == MBOX_RESP_TIMEOUT || ret == MBOX_RESP_DEVICE_BUSY)
321-
__udelay(2000); /* wait for 2ms before resend */
322+
__socfpga_udelay(2000); /* wait for 2ms before resend */
322323
else
323324
break;
324325
}

arch/arm/mach-socfpga/reset_manager_s10.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <asm/arch/reset_manager.h>
1212
#include <asm/arch/smc_api.h>
1313
#include <asm/arch/system_manager.h>
14+
#include <asm/arch/timer.h>
1415
#include <dt-bindings/reset/altr,rst-mgr-s10.h>
1516
#include <exports.h>
1617
#include <linux/intel-smc.h>
@@ -24,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR;
2425
if (!timeout) \
2526
break; \
2627
timeout--; \
27-
__udelay(1000);\
28+
__socfpga_udelay(1000); \
2829
} \
2930
}
3031

arch/arm/mach-socfpga/timer_s10.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
*/
66

77
#include <common.h>
8-
#include <init.h>
9-
#include <div64.h>
108
#include <asm/io.h>
11-
#include <asm/arch/timer.h>
129

1310
/*
1411
* Timer initialization
@@ -28,33 +25,3 @@ int timer_init(void)
2825
return 0;
2926
}
3027

31-
__always_inline u64 __get_time_stamp(void)
32-
{
33-
u64 cntpct;
34-
35-
isb();
36-
asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
37-
38-
return cntpct;
39-
}
40-
41-
__always_inline uint64_t __usec_to_tick(unsigned long usec)
42-
{
43-
u64 tick = usec;
44-
u64 cntfrq;
45-
46-
asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
47-
tick *= cntfrq;
48-
do_div(tick, 1000000);
49-
50-
return tick;
51-
}
52-
53-
__always_inline void __udelay(unsigned long usec)
54-
{
55-
/* get current timestamp */
56-
u64 tmp = __get_time_stamp() + __usec_to_tick(usec);
57-
58-
while (__get_time_stamp() < tmp + 1)/* loop till event */
59-
;
60-
}

0 commit comments

Comments
 (0)