xref: /kvm-unit-tests/lib/powerpc/asm/processor.h (revision 875ebbc79f2dfe040bc5aaece0520e3835ba87ff)
1 #ifndef _ASMPOWERPC_PROCESSOR_H_
2 #define _ASMPOWERPC_PROCESSOR_H_
3 
4 #include <libcflat.h>
5 #include <asm/ptrace.h>
6 
7 #ifndef __ASSEMBLY__
8 void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);
9 void do_handle_exception(struct pt_regs *regs);
10 #endif /* __ASSEMBLY__ */
11 
12 #define SPR_TB		0x10c
13 #define SPR_SPRG0	0x110
14 #define SPR_SPRG1	0x111
15 #define SPR_SPRG2	0x112
16 #define SPR_SPRG3	0x113
17 
18 static inline uint64_t mfspr(int nr)
19 {
20 	uint64_t ret;
21 
22 	asm volatile("mfspr %0,%1" : "=r"(ret) : "i"(nr) : "memory");
23 
24 	return ret;
25 }
26 
27 static inline void mtspr(int nr, uint64_t val)
28 {
29 	asm volatile("mtspr %0,%1" : : "i"(nr), "r"(val) : "memory");
30 }
31 
32 static inline uint64_t mfmsr(void)
33 {
34 	uint64_t msr;
35 
36 	asm volatile ("mfmsr %[msr]" : [msr] "=r" (msr) :: "memory");
37 
38 	return msr;
39 }
40 
41 static inline void mtmsr(uint64_t msr)
42 {
43 	asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory");
44 }
45 
46 static inline uint64_t get_tb(void)
47 {
48 	return mfspr(SPR_TB);
49 }
50 
51 extern void delay(uint64_t cycles);
52 extern void udelay(uint64_t us);
53 extern void sleep_tb(uint64_t cycles);
54 extern void usleep(uint64_t us);
55 
56 static inline void mdelay(uint64_t ms)
57 {
58 	while (ms--)
59 		udelay(1000);
60 }
61 
62 static inline void msleep(uint64_t ms)
63 {
64 	usleep(ms * 1000);
65 }
66 
67 #endif /* _ASMPOWERPC_PROCESSOR_H_ */
68