2004-05-14 07:46:45 -04:00
|
|
|
/* $NetBSD: cpu.h,v 1.2 2001/02/23 21:23:52 reinoud Exp $ */
|
|
|
|
|
/* $FreeBSD$ */
|
|
|
|
|
|
|
|
|
|
#ifndef MACHINE_CPU_H
|
|
|
|
|
#define MACHINE_CPU_H
|
|
|
|
|
|
|
|
|
|
#include <machine/armreg.h>
|
2013-10-26 21:34:10 -04:00
|
|
|
#include <machine/frame.h>
|
2004-05-14 07:46:45 -04:00
|
|
|
|
2012-06-03 14:34:32 -04:00
|
|
|
void cpu_halt(void);
|
|
|
|
|
void swi_vm(void *);
|
2004-05-14 07:46:45 -04:00
|
|
|
|
2013-07-28 14:44:17 -04:00
|
|
|
#ifdef _KERNEL
|
2004-05-14 07:46:45 -04:00
|
|
|
static __inline uint64_t
|
|
|
|
|
get_cyclecount(void)
|
|
|
|
|
{
|
Give suitably-endowed ARMs a register similar to the x86 TSC register.
Here, "suitably endowed" means that the System Control Coprocessor
(#15) has Performance Monitoring Registers, including a CCNT (Cycle
Count) register.
The CCNT register is used in a way similar to the TSC register in
x86 processors by the get_cyclecount(9) function. The entropy-harvesting
thread is a heavy user of this function, and will benefit from not
having to call binuptime(9) instead.
One problem with the CCNT register is that it is 32-bit only, so
the upper 32-bits of the returned number are always 0. The entropy
harvester does not care, but in case any one else does, follow-up
work may include an interrup trap to increment an upper-32-bit
counter on CCNT overflow.
Another problem is that the CCNT register is not readable in user-mode
code; in can be made readable by userland, but then it is also
writable, and so is a good chunk of the PMU system. For that reason,
the CCNT is not enabled for user-mode access in this commit.
Like the x86, there is one CCNT per core, so they don't all run in
perfect sync.
Reviewed by: ian@ (an earlier version)
Tested by: ian@ (same earlier version)
Committed from: WANDBOARD-QUAD
2014-05-14 15:11:15 -04:00
|
|
|
/* This '#if' asks the question 'Does CP15/SCC include performance counters?' */
|
|
|
|
|
#if defined(CPU_ARM1136) || defined(CPU_ARM1176) \
|
|
|
|
|
|| defined(CPU_MV_PJ4B) \
|
|
|
|
|
|| defined(CPU_CORTEXA) || defined(CPU_KRAIT)
|
|
|
|
|
uint32_t ccnt;
|
|
|
|
|
uint64_t ccnt64;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read PMCCNTR. Curses! Its only 32 bits.
|
|
|
|
|
* TODO: Fix this by catching overflow with interrupt?
|
|
|
|
|
*/
|
2014-06-17 17:48:04 -04:00
|
|
|
/* The ARMv6 vs ARMv7 divide is going to need a better way of
|
|
|
|
|
* distinguishing between them.
|
|
|
|
|
*/
|
|
|
|
|
#if defined(CPU_ARM1136) || defined(CPU_ARM1176)
|
|
|
|
|
/* ARMv6 - Earlier model SCCs */
|
|
|
|
|
__asm __volatile("mrc p15, 0, %0, c15, c12, 1": "=r" (ccnt));
|
|
|
|
|
#else
|
|
|
|
|
/* ARMv7 - Later model SCCs */
|
Give suitably-endowed ARMs a register similar to the x86 TSC register.
Here, "suitably endowed" means that the System Control Coprocessor
(#15) has Performance Monitoring Registers, including a CCNT (Cycle
Count) register.
The CCNT register is used in a way similar to the TSC register in
x86 processors by the get_cyclecount(9) function. The entropy-harvesting
thread is a heavy user of this function, and will benefit from not
having to call binuptime(9) instead.
One problem with the CCNT register is that it is 32-bit only, so
the upper 32-bits of the returned number are always 0. The entropy
harvester does not care, but in case any one else does, follow-up
work may include an interrup trap to increment an upper-32-bit
counter on CCNT overflow.
Another problem is that the CCNT register is not readable in user-mode
code; in can be made readable by userland, but then it is also
writable, and so is a good chunk of the PMU system. For that reason,
the CCNT is not enabled for user-mode access in this commit.
Like the x86, there is one CCNT per core, so they don't all run in
perfect sync.
Reviewed by: ian@ (an earlier version)
Tested by: ian@ (same earlier version)
Committed from: WANDBOARD-QUAD
2014-05-14 15:11:15 -04:00
|
|
|
__asm __volatile("mrc p15, 0, %0, c9, c13, 0": "=r" (ccnt));
|
2014-06-17 17:48:04 -04:00
|
|
|
#endif
|
Give suitably-endowed ARMs a register similar to the x86 TSC register.
Here, "suitably endowed" means that the System Control Coprocessor
(#15) has Performance Monitoring Registers, including a CCNT (Cycle
Count) register.
The CCNT register is used in a way similar to the TSC register in
x86 processors by the get_cyclecount(9) function. The entropy-harvesting
thread is a heavy user of this function, and will benefit from not
having to call binuptime(9) instead.
One problem with the CCNT register is that it is 32-bit only, so
the upper 32-bits of the returned number are always 0. The entropy
harvester does not care, but in case any one else does, follow-up
work may include an interrup trap to increment an upper-32-bit
counter on CCNT overflow.
Another problem is that the CCNT register is not readable in user-mode
code; in can be made readable by userland, but then it is also
writable, and so is a good chunk of the PMU system. For that reason,
the CCNT is not enabled for user-mode access in this commit.
Like the x86, there is one CCNT per core, so they don't all run in
perfect sync.
Reviewed by: ian@ (an earlier version)
Tested by: ian@ (same earlier version)
Committed from: WANDBOARD-QUAD
2014-05-14 15:11:15 -04:00
|
|
|
ccnt64 = (uint64_t)ccnt;
|
|
|
|
|
return (ccnt64);
|
|
|
|
|
#else /* No performance counters, so use binuptime(9). This is slooooow */
|
2004-11-04 14:15:43 -05:00
|
|
|
struct bintime bt;
|
|
|
|
|
|
|
|
|
|
binuptime(&bt);
|
2011-03-14 19:30:14 -04:00
|
|
|
return ((uint64_t)bt.sec << 56 | bt.frac >> 8);
|
Give suitably-endowed ARMs a register similar to the x86 TSC register.
Here, "suitably endowed" means that the System Control Coprocessor
(#15) has Performance Monitoring Registers, including a CCNT (Cycle
Count) register.
The CCNT register is used in a way similar to the TSC register in
x86 processors by the get_cyclecount(9) function. The entropy-harvesting
thread is a heavy user of this function, and will benefit from not
having to call binuptime(9) instead.
One problem with the CCNT register is that it is 32-bit only, so
the upper 32-bits of the returned number are always 0. The entropy
harvester does not care, but in case any one else does, follow-up
work may include an interrup trap to increment an upper-32-bit
counter on CCNT overflow.
Another problem is that the CCNT register is not readable in user-mode
code; in can be made readable by userland, but then it is also
writable, and so is a good chunk of the PMU system. For that reason,
the CCNT is not enabled for user-mode access in this commit.
Like the x86, there is one CCNT per core, so they don't all run in
perfect sync.
Reviewed by: ian@ (an earlier version)
Tested by: ian@ (same earlier version)
Committed from: WANDBOARD-QUAD
2014-05-14 15:11:15 -04:00
|
|
|
#endif
|
2004-05-14 07:46:45 -04:00
|
|
|
}
|
2013-07-28 14:44:17 -04:00
|
|
|
#endif
|
2004-05-14 07:46:45 -04:00
|
|
|
|
|
|
|
|
#define TRAPF_USERMODE(frame) ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
|
|
|
|
|
|
|
|
|
|
#define TRAPF_PC(tfp) ((tfp)->tf_pc)
|
|
|
|
|
|
2012-06-03 14:34:32 -04:00
|
|
|
#define cpu_getstack(td) ((td)->td_frame->tf_usr_sp)
|
|
|
|
|
#define cpu_setstack(td, sp) ((td)->td_frame->tf_usr_sp = (sp))
|
2004-08-03 14:44:27 -04:00
|
|
|
#define cpu_spinwait() /* nothing */
|
2004-05-14 07:46:45 -04:00
|
|
|
|
|
|
|
|
#define ARM_NVEC 8
|
|
|
|
|
#define ARM_VEC_ALL 0xffffffff
|
|
|
|
|
|
|
|
|
|
extern vm_offset_t vector_page;
|
|
|
|
|
|
2014-02-09 10:54:31 -05:00
|
|
|
/*
|
|
|
|
|
* Params passed into initarm. If you change the size of this you will
|
|
|
|
|
* need to update locore.S to allocate more memory on the stack before
|
|
|
|
|
* it calls initarm.
|
|
|
|
|
*/
|
2012-06-03 14:34:32 -04:00
|
|
|
struct arm_boot_params {
|
|
|
|
|
register_t abp_size; /* Size of this structure */
|
|
|
|
|
register_t abp_r0; /* r0 from the boot loader */
|
|
|
|
|
register_t abp_r1; /* r1 from the boot loader */
|
|
|
|
|
register_t abp_r2; /* r2 from the boot loader */
|
|
|
|
|
register_t abp_r3; /* r3 from the boot loader */
|
2014-02-06 15:17:58 -05:00
|
|
|
vm_offset_t abp_physaddr; /* The kernel physical address */
|
2014-02-09 10:54:31 -05:00
|
|
|
vm_offset_t abp_pagetable; /* The early page table */
|
2012-06-03 14:34:32 -04:00
|
|
|
};
|
|
|
|
|
|
2005-02-01 01:36:27 -05:00
|
|
|
void arm_vector_init(vm_offset_t, int);
|
|
|
|
|
void fork_trampoline(void);
|
|
|
|
|
void identify_arm_cpu(void);
|
2012-06-03 14:34:32 -04:00
|
|
|
void *initarm(struct arm_boot_params *);
|
2004-05-14 07:46:45 -04:00
|
|
|
|
|
|
|
|
extern char btext[];
|
|
|
|
|
extern char etext[];
|
2012-06-03 14:34:32 -04:00
|
|
|
int badaddr_read(void *, size_t, void *);
|
2004-05-14 07:46:45 -04:00
|
|
|
#endif /* !MACHINE_CPU_H */
|