Skip to content

Commit d26b381

Browse files
chleroympe
authored andcommitted
powerpc/time: Move timebase functions into new asm/vdso/timebase.h
In order to easily use get_tb() from C VDSO, move timebase functions into a new header named asm/vdso/timebase.h Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8f8cffd commit d26b381

File tree

4 files changed

+73
-61
lines changed

4 files changed

+73
-61
lines changed

arch/powerpc/include/asm/reg.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,37 +1419,6 @@ static inline void msr_check_and_clear(unsigned long bits)
14191419
__msr_check_and_clear(bits);
14201420
}
14211421

1422-
#if defined(CONFIG_PPC_CELL) || defined(CONFIG_E500)
1423-
#define mftb() ({unsigned long rval; \
1424-
asm volatile( \
1425-
"90: mfspr %0, %2;\n" \
1426-
ASM_FTR_IFSET( \
1427-
"97: cmpwi %0,0;\n" \
1428-
" beq- 90b;\n", "", %1) \
1429-
: "=r" (rval) \
1430-
: "i" (CPU_FTR_CELL_TB_BUG), "i" (SPRN_TBRL) : "cr0"); \
1431-
rval;})
1432-
#elif defined(CONFIG_PPC_8xx)
1433-
#define mftb() ({unsigned long rval; \
1434-
asm volatile("mftbl %0" : "=r" (rval)); rval;})
1435-
#else
1436-
#define mftb() ({unsigned long rval; \
1437-
asm volatile("mfspr %0, %1" : \
1438-
"=r" (rval) : "i" (SPRN_TBRL)); rval;})
1439-
#endif /* !CONFIG_PPC_CELL */
1440-
1441-
#if defined(CONFIG_PPC_8xx)
1442-
#define mftbu() ({unsigned long rval; \
1443-
asm volatile("mftbu %0" : "=r" (rval)); rval;})
1444-
#else
1445-
#define mftbu() ({unsigned long rval; \
1446-
asm volatile("mfspr %0, %1" : "=r" (rval) : \
1447-
"i" (SPRN_TBRU)); rval;})
1448-
#endif
1449-
1450-
#define mttbl(v) asm volatile("mttbl %0":: "r"(v))
1451-
#define mttbu(v) asm volatile("mttbu %0":: "r"(v))
1452-
14531422
#ifdef CONFIG_PPC32
14541423
#define mfsrin(v) ({unsigned int rval; \
14551424
asm volatile("mfsrin %0,%1" : "=r" (rval) : "r" (v)); \

arch/powerpc/include/asm/time.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <asm/processor.h>
1717
#include <asm/cpu_has_feature.h>
18+
#include <asm/vdso/timebase.h>
1819

1920
/* time.c */
2021
extern unsigned long tb_ticks_per_jiffy;
@@ -38,12 +39,6 @@ struct div_result {
3839
u64 result_low;
3940
};
4041

41-
/* For compatibility, get_tbl() is defined as get_tb() on ppc64 */
42-
static inline unsigned long get_tbl(void)
43-
{
44-
return mftb();
45-
}
46-
4742
static inline u64 get_vtb(void)
4843
{
4944
#ifdef CONFIG_PPC_BOOK3S_64
@@ -53,29 +48,6 @@ static inline u64 get_vtb(void)
5348
return 0;
5449
}
5550

56-
static inline u64 get_tb(void)
57-
{
58-
unsigned int tbhi, tblo, tbhi2;
59-
60-
if (IS_ENABLED(CONFIG_PPC64))
61-
return mftb();
62-
63-
do {
64-
tbhi = mftbu();
65-
tblo = mftb();
66-
tbhi2 = mftbu();
67-
} while (tbhi != tbhi2);
68-
69-
return ((u64)tbhi << 32) | tblo;
70-
}
71-
72-
static inline void set_tb(unsigned int upper, unsigned int lower)
73-
{
74-
mtspr(SPRN_TBWL, 0);
75-
mtspr(SPRN_TBWU, upper);
76-
mtspr(SPRN_TBWL, lower);
77-
}
78-
7951
/* Accessor functions for the decrementer register.
8052
* The 4xx doesn't even have a decrementer. I tried to use the
8153
* generic timer interrupt code, which seems OK, with the 4xx PIT

arch/powerpc/include/asm/timex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
#include <asm/cputable.h>
12-
#include <asm/reg.h>
12+
#include <asm/vdso/timebase.h>
1313

1414
#define CLOCK_TICK_RATE 1024000 /* Underlying HZ */
1515

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Common timebase prototypes and such for all ppc machines.
4+
*/
5+
6+
#ifndef _ASM_POWERPC_VDSO_TIMEBASE_H
7+
#define _ASM_POWERPC_VDSO_TIMEBASE_H
8+
9+
#include <asm/reg.h>
10+
11+
#if defined(CONFIG_PPC_CELL) || defined(CONFIG_E500)
12+
#define mftb() ({unsigned long rval; \
13+
asm volatile( \
14+
"90: mfspr %0, %2;\n" \
15+
ASM_FTR_IFSET( \
16+
"97: cmpwi %0,0;\n" \
17+
" beq- 90b;\n", "", %1) \
18+
: "=r" (rval) \
19+
: "i" (CPU_FTR_CELL_TB_BUG), "i" (SPRN_TBRL) : "cr0"); \
20+
rval;})
21+
#elif defined(CONFIG_PPC_8xx)
22+
#define mftb() ({unsigned long rval; \
23+
asm volatile("mftbl %0" : "=r" (rval)); rval;})
24+
#else
25+
#define mftb() ({unsigned long rval; \
26+
asm volatile("mfspr %0, %1" : \
27+
"=r" (rval) : "i" (SPRN_TBRL)); rval;})
28+
#endif /* !CONFIG_PPC_CELL */
29+
30+
#if defined(CONFIG_PPC_8xx)
31+
#define mftbu() ({unsigned long rval; \
32+
asm volatile("mftbu %0" : "=r" (rval)); rval;})
33+
#else
34+
#define mftbu() ({unsigned long rval; \
35+
asm volatile("mfspr %0, %1" : "=r" (rval) : \
36+
"i" (SPRN_TBRU)); rval;})
37+
#endif
38+
39+
#define mttbl(v) asm volatile("mttbl %0":: "r"(v))
40+
#define mttbu(v) asm volatile("mttbu %0":: "r"(v))
41+
42+
/* For compatibility, get_tbl() is defined as get_tb() on ppc64 */
43+
static inline unsigned long get_tbl(void)
44+
{
45+
return mftb();
46+
}
47+
48+
static inline u64 get_tb(void)
49+
{
50+
unsigned int tbhi, tblo, tbhi2;
51+
52+
if (IS_ENABLED(CONFIG_PPC64))
53+
return mftb();
54+
55+
do {
56+
tbhi = mftbu();
57+
tblo = mftb();
58+
tbhi2 = mftbu();
59+
} while (tbhi != tbhi2);
60+
61+
return ((u64)tbhi << 32) | tblo;
62+
}
63+
64+
static inline void set_tb(unsigned int upper, unsigned int lower)
65+
{
66+
mtspr(SPRN_TBWL, 0);
67+
mtspr(SPRN_TBWU, upper);
68+
mtspr(SPRN_TBWL, lower);
69+
}
70+
71+
#endif /* _ASM_POWERPC_VDSO_TIMEBASE_H */

0 commit comments

Comments
 (0)