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