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/armreg.h> 8 #include <machine/frame.h> 9 10 void cpu_halt(void); 11 void swi_vm(void *); 12 13 #ifdef _KERNEL 14 #if __ARM_ARCH >= 6 15 #include <machine/cpu-v6.h> 16 #else 17 #include <machine/cpu-v4.h> 18 #endif /* __ARM_ARCH >= 6 */ 19 20 static __inline uint64_t 21 get_cyclecount(void) 22 { 23 #if __ARM_ARCH > 6 || (__ARM_ARCH == 6 && defined(CPU_ARM1176)) 24 #if (__ARM_ARCH > 6) && defined(DEV_PMU) 25 if (pmu_attched) { 26 u_int cpu; 27 uint64_t h, h2; 28 uint32_t l, r; 29 30 cpu = PCPU_GET(cpuid); 31 h = (uint64_t)atomic_load_acq_32(&ccnt_hi[cpu]); 32 l = cp15_pmccntr_get(); 33 /* In case interrupts are disabled we need to check for overflow. */ 34 r = cp15_pmovsr_get(); 35 if (r & PMU_OVSR_C) { 36 atomic_add_32(&ccnt_hi[cpu], 1); 37 /* Clear the event. */ 38 cp15_pmovsr_set(PMU_OVSR_C); 39 } 40 /* Make sure there was no wrap-around while we read the lo half. */ 41 h2 = (uint64_t)atomic_load_acq_32(&ccnt_hi[cpu]); 42 if (h != h2) 43 l = cp15_pmccntr_get(); 44 return (h2 << 32 | l); 45 } else 46 #endif 47 return cp15_pmccntr_get(); 48 #else /* No performance counters, so use binuptime(9). This is slooooow */ 49 struct bintime bt; 50 51 binuptime(&bt); 52 return ((uint64_t)bt.sec << 56 | bt.frac >> 8); 53 #endif 54 } 55 #endif 56 57 #define TRAPF_USERMODE(frame) ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) 58 59 #define TRAPF_PC(tfp) ((tfp)->tf_pc) 60 61 #define cpu_getstack(td) ((td)->td_frame->tf_usr_sp) 62 #define cpu_setstack(td, sp) ((td)->td_frame->tf_usr_sp = (sp)) 63 #define cpu_spinwait() /* nothing */ 64 #define cpu_lock_delay() DELAY(1) 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