From: Ben Gras Date: Sun, 16 Jun 2013 22:33:47 +0000 (+0200) Subject: kernel, libsys: make it arm-target-independent X-Git-Tag: v3.3.0~917 X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=refs%2Fchanges%2F49%2F649%2F2;p=minix.git 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 --- diff --git a/include/minix/type.h b/include/minix/type.h index 29e59bcba..b6ed40d44 100644 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -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) diff --git a/kernel/arch/earm/memory.c b/kernel/arch/earm/memory.c index 0e7e449af..9ff7acab6 100644 --- a/kernel/arch/earm/memory.c +++ b/kernel/arch/earm/memory.c @@ -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; diff --git a/lib/libsys/arch/earm/frclock_util.c b/lib/libsys/arch/earm/frclock_util.c index b3bd2d0c0..c32b50151 100644 --- a/lib/libsys/arch/earm/frclock_util.c +++ b/lib/libsys/arch/earm/frclock_util.c @@ -11,18 +11,13 @@ #include #include -#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