kernel, libsys: make it arm-target-independent

. by making the address and frequency of the
	  free running clock kinfo members, set at runtime
	  in the kernel, instead of compile time constants
	  in libsys

Change-Id: I4a8387302d4d3ffd47d2448525725683a74c9a4f
This commit is contained in:
Ben Gras 2013-06-17 00:33:47 +02:00
parent 5120b43334
commit 5bc48ef12e
3 changed files with 20 additions and 27 deletions

View file

@ -168,7 +168,7 @@ struct minix_kerninfo {
u32_t kerninfo_magic;
u32_t minix_feature_flags; /* features in minix kernel */
u32_t ki_flags; /* what is present in this struct */
u32_t minix_frclock;
u32_t minix_frclock_tcrr;
u32_t flags_unused3;
u32_t flags_unused4;
struct kinfo *kinfo;
@ -176,6 +176,7 @@ struct minix_kerninfo {
struct kmessages *kmessages;
struct loadinfo *loadinfo;
struct minix_ipcvecs *minix_ipcvecs;
u64_t minix_arm_frclock_hz; /* minix_frclock_tcrr frequency */
} __packed;
#define MINIX_KIF_IPCVECS (1L << 0)

View file

@ -790,11 +790,14 @@ int arch_phys_map_reply(const int index, const vir_bytes addr)
return OK;
}
else if (index == frclock_index) {
#ifdef DM37XX
minix_kerninfo.minix_frclock = addr;
#endif
#ifdef AM335X
minix_kerninfo.minix_frclock = addr;
#if defined(DM37XX)
minix_kerninfo.minix_frclock_tcrr = addr + OMAP3_TIMER_TCRR;
minix_kerninfo.minix_arm_frclock_hz = 1625000;
#elif defined(AM335X)
minix_kerninfo.minix_frclock_tcrr = addr + AM335X_TIMER_TCRR;
minix_kerninfo.minix_arm_frclock_hz = 1500000;
#else
#error ARM: plese define either AM335X or DM37XX.
#endif
return OK;

View file

@ -11,18 +11,13 @@
#include <sys/types.h>
#include <assert.h>
#ifdef DM37XX
//keesj:todo we don't want to hardcode these values here but ratter
//get them using a system call. the same applies for the time offset
static u64_t calib_hz = 1625000, Hz;
#endif
#ifdef AM335X
static u64_t calib_hz = 1500000, Hz;
#endif
#define MICROHZ 1000000ULL /* number of micros per second */
#define MICROSPERTICK(h) (MICROHZ/(h)) /* number of micros per HZ tick */
static u64_t Hz;
extern struct minix_kerninfo *_minix_kerninfo;
int
micro_delay(u32_t micros)
{
@ -32,7 +27,8 @@ micro_delay(u32_t micros)
/* Start of delay. */
read_frclock_64(&start);
delta_end = (calib_hz * micros) / MICROHZ;
assert(_minix_kerninfo->minix_arm_frclock_hz);
delta_end = (_minix_kerninfo->minix_arm_frclock_hz * micros) / MICROHZ;
/* If we have to wait for at least one HZ tick, use the regular
* tickdelay first. Round downwards on purpose, so the average
@ -54,23 +50,16 @@ micro_delay(u32_t micros)
u32_t frclock_64_to_micros(u64_t tsc)
{
return (u32_t) tsc / (calib_hz / MICROHZ);
return (u32_t) tsc / (_minix_kerninfo->minix_arm_frclock_hz / MICROHZ);
}
void
read_frclock(u32_t *frclk)
{
extern struct minix_kerninfo *_minix_kerninfo;
volatile u32_t *frclock;
assert(frclk);
#ifdef DM37XX
frclock = (u32_t *)((u8_t *) _minix_kerninfo->minix_frclock + OMAP3_TIMER_TCRR);
#endif
#ifdef AM335X
frclock = (u32_t *)((u8_t *) _minix_kerninfo->minix_frclock + AM335X_TIMER_TCRR);
#endif
*frclk = *frclock;
assert(_minix_kerninfo->minix_frclock_tcrr);
assert(_minix_kerninfo->minix_arm_frclock_hz);
*frclk = *(volatile u32_t *)((u8_t *) _minix_kerninfo->minix_frclock_tcrr);
}
u32_t