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