xref: /freebsd/sys/arm/include/cpu.h (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
1 /* $NetBSD: cpu.h,v 1.2 2001/02/23 21:23:52 reinoud Exp $ */
2 /* $FreeBSD$ */
3 
4 #ifndef MACHINE_CPU_H
5 #define MACHINE_CPU_H
6 
7 #include <machine/acle-compat.h>
8 #include <machine/armreg.h>
9 #include <machine/frame.h>
10 
11 void	cpu_halt(void);
12 void	swi_vm(void *);
13 
14 #ifdef _KERNEL
15 #if __ARM_ARCH >= 6
16 #include <machine/cpu-v6.h>
17 #ifdef DEV_PMU
18 #include <sys/pcpu.h>
19 #define	PMU_OVSR_C		0x80000000	/* Cycle Counter */
20 extern uint32_t	ccnt_hi[MAXCPU];
21 extern int pmu_attched;
22 #endif /* DEV_PMU */
23 #endif /* __ARM_ARCH >= 6 */
24 
25 static __inline uint64_t
26 get_cyclecount(void)
27 {
28 #if __ARM_ARCH >= 6
29 #if (__ARM_ARCH > 6) && defined(DEV_PMU)
30 	if (pmu_attched) {
31 		u_int cpu;
32 		uint64_t h, h2;
33 		uint32_t l, r;
34 
35 		cpu = PCPU_GET(cpuid);
36 		h = (uint64_t)atomic_load_acq_32(&ccnt_hi[cpu]);
37 		l = cp15_pmccntr_get();
38 		/* In case interrupts are disabled we need to check for overflow. */
39 		r = cp15_pmovsr_get();
40 		if (r & PMU_OVSR_C) {
41 			atomic_add_32(&ccnt_hi[cpu], 1);
42 			/* Clear the event. */
43 			cp15_pmovsr_set(PMU_OVSR_C);
44 		}
45 		/* Make sure there was no wrap-around while we read the lo half. */
46 		h2 = (uint64_t)atomic_load_acq_32(&ccnt_hi[cpu]);
47 		if (h != h2)
48 			l = cp15_pmccntr_get();
49 		return (h2 << 32 | l);
50 	} else
51 #endif
52 		return cp15_pmccntr_get();
53 #else /* No performance counters, so use binuptime(9). This is slooooow */
54 	struct bintime bt;
55 
56 	binuptime(&bt);
57 	return ((uint64_t)bt.sec << 56 | bt.frac >> 8);
58 #endif
59 }
60 #endif
61 
62 #define TRAPF_USERMODE(frame)	((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
63 
64 #define TRAPF_PC(tfp)		((tfp)->tf_pc)
65 
66 #define cpu_getstack(td)	((td)->td_frame->tf_usr_sp)
67 #define cpu_setstack(td, sp)	((td)->td_frame->tf_usr_sp = (sp))
68 #define cpu_spinwait()		/* nothing */
69 
70 #define ARM_NVEC		8
71 #define ARM_VEC_ALL		0xffffffff
72 
73 extern vm_offset_t vector_page;
74 
75 /*
76  * Params passed into initarm. If you change the size of this you will
77  * need to update locore.S to allocate more memory on the stack before
78  * it calls initarm.
79  */
80 struct arm_boot_params {
81 	register_t	abp_size;	/* Size of this structure */
82 	register_t	abp_r0;		/* r0 from the boot loader */
83 	register_t	abp_r1;		/* r1 from the boot loader */
84 	register_t	abp_r2;		/* r2 from the boot loader */
85 	register_t	abp_r3;		/* r3 from the boot loader */
86 	vm_offset_t	abp_physaddr;	/* The kernel physical address */
87 	vm_offset_t	abp_pagetable;	/* The early page table */
88 };
89 
90 void	arm_vector_init(vm_offset_t, int);
91 void	fork_trampoline(void);
92 void	identify_arm_cpu(void);
93 void	*initarm(struct arm_boot_params *);
94 
95 extern char btext[];
96 extern char etext[];
97 int badaddr_read(void *, size_t, void *);
98 #endif /* !MACHINE_CPU_H */
99