From 4006d229e50204c93c1aa04c58385ce2e66d597e Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Sat, 1 Dec 2007 07:07:01 +0300 Subject: Introduce the new timer subsystem. Timer subsystem initialization code in core/timer.c Split the BIOS and RTDSC timer drivers from i386_timer.c Split arch/i386/firmware/pcbios/bios.c into the RTSDC timer driver and arch/i386/core/nap.c Split the headers properly: include/unistd.h - delay functions to be used by the gPXE core and drivers. include/gpxe/timer.h - the fimer subsystem interface to be used by the timer drivers and currticks() to be used by the code gPXE subsystems. include/latch.h - removed include/timer.h - scheduled for removal. Some driver are using currticks, which is only for core subsystems. Signed-off-by: Alexey Zaytsev --- src/config.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/config.h') diff --git a/src/config.h b/src/config.h index 9aa9e8fd..af0df1b6 100644 --- a/src/config.h +++ b/src/config.h @@ -18,11 +18,14 @@ */ #define CONSOLE_FIRMWARE /* Default BIOS console */ -#undef CONSOLE_SERIAL /* Serial port */ +#define CONSOLE_SERIAL /* Serial port */ #undef CONSOLE_DIRECT_VGA /* Direct access to VGA card */ #undef CONSOLE_BTEXT /* Who knows what this does? */ #undef CONSOLE_PC_KBD /* Direct access to PC keyboard */ +#define TIMER_BIOS +#define TIMER_RTDSC + /* @END general.h */ /* @BEGIN serial.h -- cgit v1.2.3-55-g7522 From 1935439f863a43986ce386c830f4824d10c4cc18 Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Sun, 2 Mar 2008 05:19:29 +0300 Subject: fix the rdtsc namimg --- src/arch/i386/drivers/timer_rdtsc.c | 91 ++++++++++++++++++++++++++++++++++++ src/arch/i386/drivers/timer_rtdsc.c | 91 ------------------------------------ src/arch/i386/include/bits/errfile.h | 2 +- src/config.h | 2 +- src/core/config.c | 4 +- 5 files changed, 95 insertions(+), 95 deletions(-) create mode 100644 src/arch/i386/drivers/timer_rdtsc.c delete mode 100644 src/arch/i386/drivers/timer_rtdsc.c (limited to 'src/config.h') diff --git a/src/arch/i386/drivers/timer_rdtsc.c b/src/arch/i386/drivers/timer_rdtsc.c new file mode 100644 index 00000000..57b8826c --- /dev/null +++ b/src/arch/i386/drivers/timer_rdtsc.c @@ -0,0 +1,91 @@ + +#include +#include +#include +#include +#include +#include +#include + + +#define rdtsc(low,high) \ + __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) + +#define rdtscll(val) \ + __asm__ __volatile__ ("rdtsc" : "=A" (val)) + +static unsigned long long calibrate_tsc(void) +{ + uint32_t startlow, starthigh; + uint32_t endlow, endhigh; + + rdtsc(startlow,starthigh); + i386_timer2_udelay(USECS_IN_MSEC/2); + rdtsc(endlow,endhigh); + + /* 64-bit subtract - gcc just messes up with long longs */ + /* XXX ORLY? Check it. */ + __asm__("subl %2,%0\n\t" + "sbbl %3,%1" + :"=a" (endlow), "=d" (endhigh) + :"g" (startlow), "g" (starthigh), + "0" (endlow), "1" (endhigh)); + + /* Error: ECPUTOOFAST */ + if (endhigh) + goto bad_ctc; + + endlow *= MSECS_IN_SEC*2; + return endlow; + + /* + * The CTC wasn't reliable: we got a hit on the very first read, + * or the CPU was so fast/slow that the quotient wouldn't fit in + * 32 bits.. + */ +bad_ctc: + return 0; +} +static uint32_t clocks_per_second = 0; + +static tick_t rdtsc_currticks(void) +{ + uint32_t clocks_high, clocks_low; + uint32_t currticks; + + /* Read the Time Stamp Counter */ + rdtsc(clocks_low, clocks_high); + + /* currticks = clocks / clocks_per_tick; */ + __asm__("divl %1" + :"=a" (currticks) + :"r" (clocks_per_second/USECS_IN_SEC), "0" (clocks_low), "d" (clocks_high)); + + return currticks; +} + +static int rdtsc_ts_init(void) +{ + + struct cpuinfo_x86 cpu_info; + + get_cpuinfo(&cpu_info); + if (cpu_info.features & X86_FEATURE_TSC) { + clocks_per_second = calibrate_tsc(); + if (clocks_per_second) { + DBG("RDTSC ticksource installed. CPU running at %ld Mhz\n", + clocks_per_second/(1000*1000)); + return 0; + } + } + + DBG("RDTSC ticksource not available on this machine.\n"); + return -ENODEV; +} + +struct timer rdtsc_ts __timer (01) = { + .init = rdtsc_ts_init, + .udelay = generic_currticks_udelay, + .currticks = rdtsc_currticks, +}; + diff --git a/src/arch/i386/drivers/timer_rtdsc.c b/src/arch/i386/drivers/timer_rtdsc.c deleted file mode 100644 index 336e3e6f..00000000 --- a/src/arch/i386/drivers/timer_rtdsc.c +++ /dev/null @@ -1,91 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include - - -#define rdtsc(low,high) \ - __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) - -#define rdtscll(val) \ - __asm__ __volatile__ ("rdtsc" : "=A" (val)) - -static unsigned long long calibrate_tsc(void) -{ - uint32_t startlow, starthigh; - uint32_t endlow, endhigh; - - rdtsc(startlow,starthigh); - i386_timer2_udelay(USECS_IN_MSEC/2); - rdtsc(endlow,endhigh); - - /* 64-bit subtract - gcc just messes up with long longs */ - /* XXX ORLY? Check it. */ - __asm__("subl %2,%0\n\t" - "sbbl %3,%1" - :"=a" (endlow), "=d" (endhigh) - :"g" (startlow), "g" (starthigh), - "0" (endlow), "1" (endhigh)); - - /* Error: ECPUTOOFAST */ - if (endhigh) - goto bad_ctc; - - endlow *= MSECS_IN_SEC*2; - return endlow; - - /* - * The CTC wasn't reliable: we got a hit on the very first read, - * or the CPU was so fast/slow that the quotient wouldn't fit in - * 32 bits.. - */ -bad_ctc: - return 0; -} -static uint32_t clocks_per_second = 0; - -static tick_t rtdsc_currticks(void) -{ - uint32_t clocks_high, clocks_low; - uint32_t currticks; - - /* Read the Time Stamp Counter */ - rdtsc(clocks_low, clocks_high); - - /* currticks = clocks / clocks_per_tick; */ - __asm__("divl %1" - :"=a" (currticks) - :"r" (clocks_per_second/USECS_IN_SEC), "0" (clocks_low), "d" (clocks_high)); - - return currticks; -} - -static int rtdsc_ts_init(void) -{ - - struct cpuinfo_x86 cpu_info; - - get_cpuinfo(&cpu_info); - if (cpu_info.features & X86_FEATURE_TSC) { - clocks_per_second = calibrate_tsc(); - if (clocks_per_second) { - DBG("RTDSC Ticksource installed. CPU running at %ld Mhz\n", - clocks_per_second/(1000*1000)); - return 0; - } - } - - DBG("RTDSC timer not available on this machine.\n"); - return -ENODEV; -} - -struct timer rtdsc_ts __timer (01) = { - .init = rtdsc_ts_init, - .udelay = generic_currticks_udelay, - .currticks = rtdsc_currticks, -}; - diff --git a/src/arch/i386/include/bits/errfile.h b/src/arch/i386/include/bits/errfile.h index ce58eefd..0f140214 100644 --- a/src/arch/i386/include/bits/errfile.h +++ b/src/arch/i386/include/bits/errfile.h @@ -26,7 +26,7 @@ #define ERRFILE_undionly ( ERRFILE_ARCH | ERRFILE_NET | 0x00030000 ) #define ERRFILE_undirom ( ERRFILE_ARCH | ERRFILE_NET | 0x00040000 ) -#define ERRFILE_timer_rtdsc ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00000000 ) +#define ERRFILE_timer_rdtsc ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00000000 ) #define ERRFILE_timer_bios ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00010000 ) /** @} */ diff --git a/src/config.h b/src/config.h index af0df1b6..4aac654a 100644 --- a/src/config.h +++ b/src/config.h @@ -24,7 +24,7 @@ #undef CONSOLE_PC_KBD /* Direct access to PC keyboard */ #define TIMER_BIOS -#define TIMER_RTDSC +#define TIMER_RDTSC /* @END general.h */ diff --git a/src/core/config.c b/src/core/config.c index f3e17b62..94fd0b82 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -82,8 +82,8 @@ REQUIRE_OBJECT ( syslog ); REQUIRE_OBJECT ( timer_bios ); #endif -#ifdef TIMER_RTDSC -REQUIRE_OBJECT ( timer_rtdsc ); +#ifdef TIMER_RDTSC +REQUIRE_OBJECT ( timer_rdtsc ); #endif /* * Drag in all requested protocols -- cgit v1.2.3-55-g7522 From 3dd897f98693a320ee8ca1546677ec6d093c5c2f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 2 Mar 2008 02:32:12 +0000 Subject: [Timers] Do not enable serial console by default; this change should not be propagated to master. --- src/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/config.h') diff --git a/src/config.h b/src/config.h index 4aac654a..b3e57269 100644 --- a/src/config.h +++ b/src/config.h @@ -18,7 +18,7 @@ */ #define CONSOLE_FIRMWARE /* Default BIOS console */ -#define CONSOLE_SERIAL /* Serial port */ +#undef CONSOLE_SERIAL /* Serial port */ #undef CONSOLE_DIRECT_VGA /* Direct access to VGA card */ #undef CONSOLE_BTEXT /* Who knows what this does? */ #undef CONSOLE_PC_KBD /* Direct access to PC keyboard */ -- cgit v1.2.3-55-g7522 From 4704abbc5075c13230e00dd30b559c6e8ca07dbb Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 2 Mar 2008 02:33:54 +0000 Subject: [Timers] Move TIMER_BIOS and TIMER_RDTSC to their own config.h section. --- src/config.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/config.h') diff --git a/src/config.h b/src/config.h index b3e57269..67fdd64c 100644 --- a/src/config.h +++ b/src/config.h @@ -23,9 +23,6 @@ #undef CONSOLE_BTEXT /* Who knows what this does? */ #undef CONSOLE_PC_KBD /* Direct access to PC keyboard */ -#define TIMER_BIOS -#define TIMER_RDTSC - /* @END general.h */ /* @BEGIN serial.h @@ -54,6 +51,16 @@ /* @END serial.h */ +/* @BEGIN general.h + * + * Timer configuration + * + */ +#define TIMER_BIOS /* 18Hz BIOS timer */ +#define TIMER_RDTSC /* CPU TimeStamp Counter timer */ + +/* @END general.h */ + /* @BEGIN isa.h * * ISA probe address configuration -- cgit v1.2.3-55-g7522