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/arch/i386/core/i386_timer.c | 213 +++++++++-------------------------- src/arch/i386/core/nap.c | 12 ++ src/arch/i386/drivers/timer_bios.c | 57 ++++++++++ src/arch/i386/drivers/timer_rtdsc.c | 90 +++++++++++++++ src/arch/i386/firmware/pcbios/bios.c | 55 --------- src/arch/i386/include/bits/timer2.h | 8 ++ src/config.h | 5 +- src/core/config.c | 11 ++ src/core/misc.c | 12 -- src/core/timer.c | 107 +++++++++++++++--- src/include/gpxe/timer.h | 32 ++++++ src/include/timer.h | 70 +++--------- src/include/unistd.h | 8 +- 13 files changed, 384 insertions(+), 296 deletions(-) create mode 100644 src/arch/i386/core/nap.c create mode 100644 src/arch/i386/drivers/timer_bios.c create mode 100644 src/arch/i386/drivers/timer_rtdsc.c delete mode 100644 src/arch/i386/firmware/pcbios/bios.c create mode 100644 src/arch/i386/include/bits/timer2.h create mode 100644 src/include/gpxe/timer.h diff --git a/src/arch/i386/core/i386_timer.c b/src/arch/i386/core/i386_timer.c index 8d3a629ad..8f90ae05a 100644 --- a/src/arch/i386/core/i386_timer.c +++ b/src/arch/i386/core/i386_timer.c @@ -1,18 +1,58 @@ -/* A couple of routines to implement a low-overhead timer for drivers */ - - /* +/* + * arch/i386/core/i386_timer.c + * + * Use the "System Timer 2" to implement the udelay callback in + * the BIOS timer driver. Also used to calibrate the clock rate + * in the RTDSC timer driver. + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, or (at * your option) any later version. */ -#include "timer.h" -#include "latch.h" -#include -#include +#include +#include +#include +#include + +/* Timers tick over at this rate */ +#define TIMER2_TICK_RATE 1193180U + +/* Parallel Peripheral Controller Port B */ +#define PPC_PORTB 0x61 + +/* Meaning of the port bits */ +#define PPCB_T2OUT 0x20 /* Bit 5 */ +#define PPCB_SPKR 0x02 /* Bit 1 */ +#define PPCB_T2GATE 0x01 /* Bit 0 */ + +/* Ports for the 8254 timer chip */ +#define TIMER2_PORT 0x42 +#define TIMER_MODE_PORT 0x43 + +/* Meaning of the mode bits */ +#define TIMER0_SEL 0x00 +#define TIMER1_SEL 0x40 +#define TIMER2_SEL 0x80 +#define READBACK_SEL 0xC0 + +#define LATCH_COUNT 0x00 +#define LOBYTE_ACCESS 0x10 +#define HIBYTE_ACCESS 0x20 +#define WORD_ACCESS 0x30 + +#define MODE0 0x00 +#define MODE1 0x02 +#define MODE2 0x04 +#define MODE3 0x06 +#define MODE4 0x08 +#define MODE5 0x0A -void __load_timer2(unsigned int ticks) +#define BINARY_COUNT 0x00 +#define BCD_COUNT 0x01 + +static void load_timer2(unsigned int ticks) { /* * Now let's take care of PPC channel 2 @@ -35,162 +75,15 @@ void __load_timer2(unsigned int ticks) outb(ticks >> 8, TIMER2_PORT); } -static int __timer2_running(void) +static int timer2_running(void) { return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0); } -#if !defined(CONFIG_TSC_CURRTICKS) -static void setup_timers(void) -{ - return; -} - -void load_timer2(unsigned int ticks) -{ - return __load_timer2(ticks); -} - -int timer2_running(void) -{ - return __timer2_running(); -} - -void ndelay(unsigned int nsecs) -{ - waiton_timer2((nsecs * CLOCK_TICK_RATE)/1000000000); -} -void udelay(unsigned int usecs) -{ - waiton_timer2((usecs * TICKS_PER_MS)/1000); -} -#endif /* !defined(CONFIG_TSC_CURRTICKS) */ - -#if defined(CONFIG_TSC_CURRTICKS) - -#define rdtsc(low,high) \ - __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) - -#define rdtscll(val) \ - __asm__ __volatile__ ("rdtsc" : "=A" (val)) - - -/* Number of clock ticks to time with the rtc */ -#define LATCH 0xFF - -#define LATCHES_PER_SEC ((CLOCK_TICK_RATE + (LATCH/2))/LATCH) -#define TICKS_PER_LATCH ((LATCHES_PER_SEC + (TICKS_PER_SEC/2))/TICKS_PER_SEC) - -static void sleep_latch(void) +void i386_timer2_udelay(unsigned int usecs) { - __load_timer2(LATCH); - while(__timer2_running()); + load_timer2((usecs * TIMER2_TICK_RATE)/USECS_IN_SEC); + while (timer2_running()) + ; } -/* ------ Calibrate the TSC ------- - * Time how long it takes to excute a loop that runs in known time. - * And find the convertion needed to get to CLOCK_TICK_RATE - */ - - -static unsigned long long calibrate_tsc(void) -{ - unsigned long startlow, starthigh; - unsigned long endlow, endhigh; - - rdtsc(startlow,starthigh); - sleep_latch(); - rdtsc(endlow,endhigh); - - /* 64-bit subtract - gcc just messes up with long longs */ - __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 *= TICKS_PER_LATCH; - 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: - printf("bad_ctc\n"); - return 0; -} - -static unsigned long clocks_per_tick; -static void setup_timers(void) -{ - if (!clocks_per_tick) { - clocks_per_tick = calibrate_tsc(); - /* Display the CPU Mhz to easily test if the calibration was bad */ - printf("CPU %ld Mhz\n", (clocks_per_tick/1000 * TICKS_PER_SEC)/1000); - } -} - -unsigned long currticks(void) -{ - unsigned long clocks_high, clocks_low; - unsigned long currticks; - /* Read the Time Stamp Counter */ - rdtsc(clocks_low, clocks_high); - - /* currticks = clocks / clocks_per_tick; */ - __asm__("divl %1" - :"=a" (currticks) - :"r" (clocks_per_tick), "0" (clocks_low), "d" (clocks_high)); - - - return currticks; -} - -static unsigned long long timer_timeout; -static int __timer_running(void) -{ - unsigned long long now; - rdtscll(now); - return now < timer_timeout; -} - -void udelay(unsigned int usecs) -{ - unsigned long long now; - rdtscll(now); - timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000)); - while(__timer_running()); -} -void ndelay(unsigned int nsecs) -{ - unsigned long long now; - rdtscll(now); - timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000)); - while(__timer_running()); -} - -void load_timer2(unsigned int timer2_ticks) -{ - unsigned long long now; - unsigned long clocks; - rdtscll(now); - clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE); - timer_timeout = now + clocks; -} - -int timer2_running(void) -{ - return __timer_running(); -} - -#endif /* RTC_CURRTICKS */ - -struct init_fn timer_init_fn __init_fn ( INIT_NORMAL ) = { - .initialise = setup_timers, -}; diff --git a/src/arch/i386/core/nap.c b/src/arch/i386/core/nap.c new file mode 100644 index 000000000..12bb5699c --- /dev/null +++ b/src/arch/i386/core/nap.c @@ -0,0 +1,12 @@ + +#include +#include + +/************************************************************************** + * Save power by halting the CPU until the next interrupt + **************************************************************************/ +void cpu_nap ( void ) { + __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" + "hlt\n\t" + "cli\n\t" ) : : ); +} diff --git a/src/arch/i386/drivers/timer_bios.c b/src/arch/i386/drivers/timer_bios.c new file mode 100644 index 000000000..f9caf8d9a --- /dev/null +++ b/src/arch/i386/drivers/timer_bios.c @@ -0,0 +1,57 @@ +/* + * Etherboot routines for PCBIOS firmware. + * + * Body of routines taken from old pcbios.S + */ + +#include +#include +#include +#include +#include +#include + +/* A bit faster actually, but we don't care. */ +#define TIMER2_TICKS_PER_SEC 18 + +/* + * Use direct memory access to BIOS variables, longword 0040:006C (ticks + * today) and byte 0040:0070 (midnight crossover flag) instead of calling + * timeofday BIOS interrupt. + */ + +static tick_t bios_currticks ( void ) { + static int days = 0; + uint32_t ticks; + uint8_t midnight; + + /* Re-enable interrupts so that the timer interrupt can occur */ + __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" + "nop\n\t" + "nop\n\t" + "cli\n\t" ) : : ); + + get_real ( ticks, BDA_SEG, 0x006c ); + get_real ( midnight, BDA_SEG, 0x0070 ); + + if ( midnight ) { + midnight = 0; + put_real ( midnight, BDA_SEG, 0x0070 ); + days += 0x1800b0; + } + + return ( (days + ticks) * (USECS_IN_SEC / TIMER2_TICKS_PER_SEC) ); +} + +static int bios_ts_init(void) +{ + DBG("BIOS timer installed\n"); + return 0; +} + +struct timer bios_ts __timer ( 02 ) = { + .init = bios_ts_init, + .udelay = i386_timer2_udelay, + .currticks = bios_currticks, +}; + diff --git a/src/arch/i386/drivers/timer_rtdsc.c b/src/arch/i386/drivers/timer_rtdsc.c new file mode 100644 index 000000000..1cd2abead --- /dev/null +++ b/src/arch/i386/drivers/timer_rtdsc.c @@ -0,0 +1,90 @@ + +#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; + } + } + + printf("RTDSC timer not available on this machine.\n"); + return 1; +} + +struct timer rtdsc_ts __timer (01) = { + .init = rtdsc_ts_init, + .udelay = generic_currticks_udelay, + .currticks = rtdsc_currticks, +}; + diff --git a/src/arch/i386/firmware/pcbios/bios.c b/src/arch/i386/firmware/pcbios/bios.c deleted file mode 100644 index bcbe98a88..000000000 --- a/src/arch/i386/firmware/pcbios/bios.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Etherboot routines for PCBIOS firmware. - * - * Body of routines taken from old pcbios.S - */ - -#include -#include -#include - -#define CF ( 1 << 0 ) - -/************************************************************************** -CURRTICKS - Get Time -Use direct memory access to BIOS variables, longword 0040:006C (ticks -today) and byte 0040:0070 (midnight crossover flag) instead of calling -timeofday BIOS interrupt. -**************************************************************************/ -#if defined(CONFIG_TSC_CURRTICKS) -#undef CONFIG_BIOS_CURRTICKS -#else -#define CONFIG_BIOS_CURRTICKS 1 -#endif -#if defined(CONFIG_BIOS_CURRTICKS) -unsigned long currticks ( void ) { - static uint32_t days = 0; - uint32_t ticks; - uint8_t midnight; - - /* Re-enable interrupts so that the timer interrupt can occur - */ - __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" - "nop\n\t" - "nop\n\t" - "cli\n\t" ) : : ); - - get_real ( ticks, BDA_SEG, 0x006c ); - get_real ( midnight, BDA_SEG, 0x0070 ); - - if ( midnight ) { - midnight = 0; - put_real ( midnight, BDA_SEG, 0x0070 ); - days += 0x1800b0; - } - return ( days + ticks ); -} -#endif /* CONFIG_BIOS_CURRTICKS */ - -/************************************************************************** -CPU_NAP - Save power by halting the CPU until the next interrupt -**************************************************************************/ -void cpu_nap ( void ) { - __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" - "hlt\n\t" - "cli\n\t" ) : : ); -} diff --git a/src/arch/i386/include/bits/timer2.h b/src/arch/i386/include/bits/timer2.h new file mode 100644 index 000000000..83923b299 --- /dev/null +++ b/src/arch/i386/include/bits/timer2.h @@ -0,0 +1,8 @@ +#ifndef BITS_TIMER2_H +#define BITS_TIMER2_H + +#include + +void i386_timer2_udelay(unsigned int usecs); + +#endif diff --git a/src/config.h b/src/config.h index 9aa9e8fdf..af0df1b69 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 diff --git a/src/core/config.c b/src/core/config.c index d5accecfe..f3e17b62e 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -74,6 +74,17 @@ REQUIRE_OBJECT ( pc_kbd ); REQUIRE_OBJECT ( syslog ); #endif +/* + * Timers + */ + +#ifdef TIMER_BIOS +REQUIRE_OBJECT ( timer_bios ); +#endif + +#ifdef TIMER_RTDSC +REQUIRE_OBJECT ( timer_rtdsc ); +#endif /* * Drag in all requested protocols * diff --git a/src/core/misc.c b/src/core/misc.c index 4219a36c5..fcf0aeab3 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -7,18 +7,6 @@ MISC Support Routines #include #include -/************************************************************************** -SLEEP -**************************************************************************/ -unsigned int sleep(unsigned int secs) -{ - unsigned long tmo; - - for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; ) { - } - return 0; -} - /************************************************************************** INET_ATON - Convert an ascii x.x.x.x to binary form **************************************************************************/ diff --git a/src/core/timer.c b/src/core/timer.c index c56e53109..da53e0539 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -1,27 +1,104 @@ -/* A couple of routines to implement a low-overhead timer for drivers */ - - /* +/* + * core/timer.c + * + * Copyright (C) 2007 Alexey Zaytsev + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, or (at - * your option) any later version. + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "timer.h" +#include +#include +#include +#include +#include -/* Machine Independant timer helper functions */ +static struct timer ts_table[0] + __table_start ( struct timer, timers ); +static struct timer ts_table_end[0] + __table_end ( struct timer, timers ); -void mdelay(unsigned int msecs) + +static struct timer *used_ts = NULL; + +/* + * This function may be used in custom timer driver. + * + * This udelay implementation works well if you've got a + * fast currticks(). + */ +void generic_currticks_udelay(unsigned int usecs) { - unsigned int i; - for(i = 0; i < msecs; i++) { - udelay(1000); - } + tick_t t; + + t = currticks(); + while (t + usecs > currticks()) + ; /* xxx: Relax the cpu some way. */ } -void waiton_timer2(unsigned int ticks) + +static void timer_init(void) { - load_timer2(ticks); - while(timer2_running()) { + struct timer *ts; + + for (ts = ts_table; ts < ts_table_end; ts++) { + if (ts->init && !ts->init()) { + used_ts = ts; + break; + } + } + + if (!used_ts) { + printf("No timer available. This should never happen. Expect gPXE to die soon.\n"); + /* Panic */ } + } + +struct init_fn ts_init_fn __init_fn ( INIT_NORMAL ) = { + .initialise = timer_init, +}; + +/* Functions for public use. */ + +tick_t currticks(void) +{ + tick_t ct; + assert(used_ts); + + ct = used_ts->currticks(); + DBG("currticks: %ld seconds and %06ld microseconds\n", ct/USECS_IN_SEC, ct%USECS_IN_SEC); + + return ct; +} + +void udelay(unsigned int usecs) +{ + used_ts->udelay(usecs); +} + +void mdelay(unsigned int msecs) +{ + while(msecs--) + used_ts->udelay(USECS_IN_MSEC); +} + +unsigned int sleep(unsigned int secs) +{ + while (secs--) + mdelay(MSECS_IN_SEC); + + return 0; +} + diff --git a/src/include/gpxe/timer.h b/src/include/gpxe/timer.h new file mode 100644 index 000000000..4a4cf5b2f --- /dev/null +++ b/src/include/gpxe/timer.h @@ -0,0 +1,32 @@ +#ifndef GPXE_TIMER_H +#define GPXE_TIMER_H + +#include + +typedef uint32_t tick_t; + +#define MSECS_IN_SEC (1000) +#define USECS_IN_SEC (1000*1000) +#define USECS_IN_MSEC (1000) + +#define TICKS_PER_SEC USECS_IN_SEC + +tick_t currticks(void); + +void generic_currticks_udelay(unsigned int usecs); + +struct timer { + /* Returns zero on successful initialisation. */ + int (*init) (void); + + /* Return the current time, int mictoseconds since the beginning. */ + tick_t (*currticks) (void); + + /* Sleep for a few useconds. */ + void (*udelay) (unsigned int useconds); +}; + +#define __timer(order) __table (struct timer, timers, order) + +#endif /* GPXE_TIMER_H */ + diff --git a/src/include/timer.h b/src/include/timer.h index 0044d0c07..cd1b2821a 100644 --- a/src/include/timer.h +++ b/src/include/timer.h @@ -1,61 +1,27 @@ -/* Defines for routines to implement a low-overhead timer for drivers */ - - /* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, or (at - * your option) any later version. - */ - -#ifndef TIMER_H +#ifndef TIMER_H #define TIMER_H -/* Ports for the 8254 timer chip */ -#define TIMER2_PORT 0x42 -#define TIMER_MODE_PORT 0x43 - -/* Meaning of the mode bits */ -#define TIMER0_SEL 0x00 -#define TIMER1_SEL 0x40 -#define TIMER2_SEL 0x80 -#define READBACK_SEL 0xC0 - -#define LATCH_COUNT 0x00 -#define LOBYTE_ACCESS 0x10 -#define HIBYTE_ACCESS 0x20 -#define WORD_ACCESS 0x30 - -#define MODE0 0x00 -#define MODE1 0x02 -#define MODE2 0x04 -#define MODE3 0x06 -#define MODE4 0x08 -#define MODE5 0x0A - -#define BINARY_COUNT 0x00 -#define BCD_COUNT 0x01 +/* + * This file should be removed as soon as there are no + * currticks() abusers. + */ -/* Timers tick over at this rate */ -#define CLOCK_TICK_RATE 1193180U -#define TICKS_PER_MS (CLOCK_TICK_RATE/1000) +#include +/* +#warning Please fix me. I'm abusing the deprecated include/timer.h +*/ +#include -/* Parallel Peripheral Controller Port B */ -#define PPC_PORTB 0x61 +/* Duplicates include/gpxe/timer.h */ +typedef uint32_t tick_t; -/* Meaning of the port bits */ -#define PPCB_T2OUT 0x20 /* Bit 5 */ -#define PPCB_SPKR 0x02 /* Bit 1 */ -#define PPCB_T2GATE 0x01 /* Bit 0 */ +#define MSECS_IN_SEC (1000) +#define USECS_IN_SEC (1000*1000) +#define USECS_IN_MSEC (1000) -/* Ticks must be between 0 and 65535 (0 == 65536) - because it is a 16 bit counter */ -extern void load_timer2(unsigned int ticks); -extern inline int timer2_running(void); -extern void waiton_timer2(unsigned int ticks); +#define TICKS_PER_SEC USECS_IN_SEC -extern void ndelay(unsigned int nsecs); -extern void udelay(unsigned int usecs); -extern void mdelay(unsigned int msecs); +tick_t currticks(void); +#endif -#endif /* TIMER_H */ diff --git a/src/include/unistd.h b/src/include/unistd.h index 35dcf5845..7c44a0ced 100644 --- a/src/include/unistd.h +++ b/src/include/unistd.h @@ -4,7 +4,7 @@ #include #include -extern unsigned int sleep ( unsigned int seconds ); +unsigned int sleep ( unsigned int seconds ); extern int execv ( const char *command, char * const argv[] ); /** @@ -22,4 +22,10 @@ extern int execv ( const char *command, char * const argv[] ); rc; \ } ) +void udelay(unsigned int usecs); +void mdelay(unsigned int msecs); + +#define usleep(x) udelay(x) + + #endif /* _UNISTD_H */ -- cgit v1.2.3-55-g7522 From a1572e0ab0f5fab9a1f0185ded593bec811aa175 Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Sun, 2 Mar 2008 03:41:10 +0300 Subject: Modify gPXE core and drivers to work with the new timer subsystem Signed-off-by: Alexey Zaytsev --- src/arch/i386/Makefile | 1 + src/arch/i386/firmware/pcbios/gateA20.c | 7 +++---- src/arch/i386/include/latch.h | 12 ------------ src/core/getkey.c | 2 +- src/core/misc.c | 2 +- src/core/random.c | 2 +- src/core/serial.c | 2 +- src/drivers/bitbash/bitbash.c | 1 - src/drivers/bitbash/i2c_bit.c | 2 +- src/drivers/bitbash/spi_bit.c | 2 +- src/drivers/bus/eisa.c | 2 +- src/drivers/bus/isapnp.c | 2 +- src/drivers/bus/mca.c | 1 - src/drivers/infiniband/arbel.c | 1 - src/drivers/infiniband/hermon.c | 1 - src/drivers/net/3c509.c | 2 +- src/drivers/net/3c515.c | 1 - src/drivers/net/3c595.c | 1 - src/drivers/net/3c5x9.c | 1 - src/drivers/net/3c90x.c | 7 ++++--- src/drivers/net/amd8111e.c | 1 - src/drivers/net/bnx2.c | 1 - src/drivers/net/dmfe.c | 1 - src/drivers/net/e1000/e1000.h | 1 - src/drivers/net/e1000/e1000_osdep.h | 2 +- src/drivers/net/eepro.c | 1 - src/drivers/net/eepro100.c | 13 ++++++++----- src/drivers/net/epic100.c | 16 +++++++++------- src/drivers/net/etherfabric.c | 1 - src/drivers/net/forcedeth.c | 1 - src/drivers/net/ipoib.c | 1 - src/drivers/net/mlx_ipoib/mt23108_imp.c | 1 - src/drivers/net/mlx_ipoib/mt25218_imp.c | 1 - src/drivers/net/mtnic.c | 2 +- src/drivers/net/natsemi.c | 2 +- src/drivers/net/pcnet32.c | 1 - src/drivers/net/prism2.c | 1 - src/drivers/net/r8169.c | 1 - src/drivers/net/rtl8139.c | 2 +- src/drivers/net/sis900.c | 1 - src/drivers/net/smc9000.c | 1 - src/drivers/net/sundance.c | 1 - src/drivers/net/tg3.c | 1 - src/drivers/net/tlan.c | 1 - src/drivers/net/via-rhine.c | 21 ++++++++++++--------- src/drivers/net/via-velocity.h | 2 -- src/drivers/net/w89c840.c | 9 ++++----- src/drivers/nvs/spi.c | 2 +- src/drivers/nvs/threewire.c | 2 +- src/hci/mucurses/kb.c | 2 +- src/hci/shell_banner.c | 2 +- src/include/etherboot.h | 2 +- src/include/gpxe/dhcp.h | 1 - src/include/gpxe/tcp.h | 1 - src/include/timer.h | 27 --------------------------- src/net/retry.c | 2 +- src/net/tcp.c | 2 +- src/net/udp/dhcp.c | 1 + 58 files changed, 62 insertions(+), 121 deletions(-) delete mode 100644 src/arch/i386/include/latch.h delete mode 100644 src/include/timer.h diff --git a/src/arch/i386/Makefile b/src/arch/i386/Makefile index 5e7416cbb..da7976df7 100644 --- a/src/arch/i386/Makefile +++ b/src/arch/i386/Makefile @@ -7,6 +7,7 @@ ISOLINUX_BIN = /usr/lib/syslinux/isolinux.bin SRCDIRS += arch/i386/core arch/i386/transitions arch/i386/prefix SRCDIRS += arch/i386/firmware/pcbios SRCDIRS += arch/i386/image +SRCDIRS += arch/i386/drivers SRCDIRS += arch/i386/drivers/bus SRCDIRS += arch/i386/drivers/net SRCDIRS += arch/i386/drivers/disk diff --git a/src/arch/i386/firmware/pcbios/gateA20.c b/src/arch/i386/firmware/pcbios/gateA20.c index 66b4da18a..2caac8941 100644 --- a/src/arch/i386/firmware/pcbios/gateA20.c +++ b/src/arch/i386/firmware/pcbios/gateA20.c @@ -1,8 +1,7 @@ #include -#include "realmode.h" -#include "timer.h" -#include "latch.h" -#include "bios.h" +#include +#include +#include #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */ #define K_STATUS 0x64 /* keyboard status */ diff --git a/src/arch/i386/include/latch.h b/src/arch/i386/include/latch.h deleted file mode 100644 index 5000d5826..000000000 --- a/src/arch/i386/include/latch.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LATCH_H -#define LATCH_H - -#define TICKS_PER_SEC 18 - -/* For different calibrators of the TSC move the declaration of - * sleep_latch and the definitions of it's length here... - */ - -extern unsigned long currticks ( void ); - -#endif /* LATCH_H */ diff --git a/src/core/getkey.c b/src/core/getkey.c index 71ec6cc1b..1551cf37c 100644 --- a/src/core/getkey.c +++ b/src/core/getkey.c @@ -17,9 +17,9 @@ */ #include -#include #include #include +#include /** @file * diff --git a/src/core/misc.c b/src/core/misc.c index fcf0aeab3..a54f5a108 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -4,8 +4,8 @@ MISC Support Routines #include #include -#include #include +#include /************************************************************************** INET_ATON - Convert an ascii x.x.x.x to binary form diff --git a/src/core/random.c b/src/core/random.c index e4a70d434..d34e763a6 100644 --- a/src/core/random.c +++ b/src/core/random.c @@ -5,7 +5,7 @@ */ #include -#include +#include static int32_t rnd_seed = 0; diff --git a/src/core/serial.c b/src/core/serial.c index f325bc45b..f6d0ecbb9 100644 --- a/src/core/serial.c +++ b/src/core/serial.c @@ -15,7 +15,7 @@ #include "console.h" #include #include "io.h" -#include "timer.h" +#include #include "config/serial.h" /* Set default values if none specified */ diff --git a/src/drivers/bitbash/bitbash.c b/src/drivers/bitbash/bitbash.c index ec94feeea..c6f935202 100644 --- a/src/drivers/bitbash/bitbash.c +++ b/src/drivers/bitbash/bitbash.c @@ -16,7 +16,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include /** @file diff --git a/src/drivers/bitbash/i2c_bit.c b/src/drivers/bitbash/i2c_bit.c index d8fbacc0e..a3af610b0 100644 --- a/src/drivers/bitbash/i2c_bit.c +++ b/src/drivers/bitbash/i2c_bit.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/drivers/bitbash/spi_bit.c b/src/drivers/bitbash/spi_bit.c index a4e7136f8..ef87b5a24 100644 --- a/src/drivers/bitbash/spi_bit.c +++ b/src/drivers/bitbash/spi_bit.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/drivers/bus/eisa.c b/src/drivers/bus/eisa.c index d9d02d727..ee03df3af 100644 --- a/src/drivers/bus/eisa.c +++ b/src/drivers/bus/eisa.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include static struct eisa_driver eisa_drivers[0] diff --git a/src/drivers/bus/isapnp.c b/src/drivers/bus/isapnp.c index 7903208d0..f4968eb13 100644 --- a/src/drivers/bus/isapnp.c +++ b/src/drivers/bus/isapnp.c @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include /** diff --git a/src/drivers/bus/mca.c b/src/drivers/bus/mca.c index 375a68344..eb7b7e395 100644 --- a/src/drivers/bus/mca.c +++ b/src/drivers/bus/mca.c @@ -11,7 +11,6 @@ #include #include #include -#include #include static struct mca_driver mca_drivers[0] diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c index 147cf8b90..462638eae 100644 --- a/src/drivers/infiniband/arbel.c +++ b/src/drivers/infiniband/arbel.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c index fecf39882..c10559f98 100644 --- a/src/drivers/infiniband/hermon.c +++ b/src/drivers/infiniband/hermon.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/drivers/net/3c509.c b/src/drivers/net/3c509.c index e704cfca1..8a15aff29 100644 --- a/src/drivers/net/3c509.c +++ b/src/drivers/net/3c509.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include "3c509.h" diff --git a/src/drivers/net/3c515.c b/src/drivers/net/3c515.c index d0bf3189e..02f03dc78 100644 --- a/src/drivers/net/3c515.c +++ b/src/drivers/net/3c515.c @@ -50,7 +50,6 @@ #include "nic.h" #include #include /* for ISA_ROM */ -#include "timer.h" #include static void t3c515_wait(unsigned int nticks) diff --git a/src/drivers/net/3c595.c b/src/drivers/net/3c595.c index 572a99e0b..7138f936e 100644 --- a/src/drivers/net/3c595.c +++ b/src/drivers/net/3c595.c @@ -30,7 +30,6 @@ #include #include #include "3c595.h" -#include "timer.h" static struct nic_operations t595_operations; diff --git a/src/drivers/net/3c5x9.c b/src/drivers/net/3c5x9.c index 1ade6f47d..565044a11 100644 --- a/src/drivers/net/3c5x9.c +++ b/src/drivers/net/3c5x9.c @@ -28,7 +28,6 @@ $Id$ #include "etherboot.h" #include "nic.h" #include -#include "timer.h" #include "3c509.h" static enum { none, bnc, utp } connector = none; /* for 3C509 */ diff --git a/src/drivers/net/3c90x.c b/src/drivers/net/3c90x.c index 8e1f160ea..8158239d6 100644 --- a/src/drivers/net/3c90x.c +++ b/src/drivers/net/3c90x.c @@ -43,7 +43,6 @@ #include "nic.h" #include #include -#include "timer.h" static struct nic_operations a3c90x_operations; @@ -498,6 +497,7 @@ a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t, unsigned char status; unsigned i, retries; + tick_t ct; for (retries=0; retries < XMIT_RETRIES ; retries++) { @@ -540,9 +540,10 @@ a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t, ; /** Wait for NIC Transmit to Complete **/ - load_timer2(10*TICKS_PER_MS); /* Give it 10 ms */ + ct = currticks(); + while (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004) && - timer2_running()) + ct + 10*USECS_IN_MSEC < currticks()); ; if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004)) diff --git a/src/drivers/net/amd8111e.c b/src/drivers/net/amd8111e.c index c26c07cf0..1c41add12 100644 --- a/src/drivers/net/amd8111e.c +++ b/src/drivers/net/amd8111e.c @@ -33,7 +33,6 @@ #include "mii.h" #include #include -#include "timer.h" #include "string.h" #include "stdint.h" #include "amd8111e.h" diff --git a/src/drivers/net/bnx2.c b/src/drivers/net/bnx2.c index fdd6655bb..9c989c4c1 100644 --- a/src/drivers/net/bnx2.c +++ b/src/drivers/net/bnx2.c @@ -18,7 +18,6 @@ #include #include #include -#include "timer.h" #include "string.h" #include "bnx2.h" #include "bnx2_fw.h" diff --git a/src/drivers/net/dmfe.c b/src/drivers/net/dmfe.c index 34e211d4b..9cf50418d 100644 --- a/src/drivers/net/dmfe.c +++ b/src/drivers/net/dmfe.c @@ -43,7 +43,6 @@ /* to get the PCI support functions, if this is a PCI NIC */ #include #include -#include "timer.h" /* #define EDEBUG 1 */ #ifdef EDEBUG diff --git a/src/drivers/net/e1000/e1000.h b/src/drivers/net/e1000/e1000.h index b4bc1d874..4ae414513 100644 --- a/src/drivers/net/e1000/e1000.h +++ b/src/drivers/net/e1000/e1000.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include diff --git a/src/drivers/net/e1000/e1000_osdep.h b/src/drivers/net/e1000/e1000_osdep.h index 04e148927..7df9b5e9d 100644 --- a/src/drivers/net/e1000/e1000_osdep.h +++ b/src/drivers/net/e1000/e1000_osdep.h @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/net/eepro.c b/src/drivers/net/eepro.c index 0a9c95e65..2a163d1b3 100644 --- a/src/drivers/net/eepro.c +++ b/src/drivers/net/eepro.c @@ -35,7 +35,6 @@ has 34 pins, the top row of 2 are not used. #include #include "nic.h" #include -#include "timer.h" #include /* Different 82595 chips */ diff --git a/src/drivers/net/eepro100.c b/src/drivers/net/eepro100.c index bb46d163c..f746976ad 100644 --- a/src/drivers/net/eepro100.c +++ b/src/drivers/net/eepro100.c @@ -107,7 +107,6 @@ #include "nic.h" #include #include -#include "timer.h" static int ioaddr; @@ -408,6 +407,7 @@ static void eepro100_transmit(struct nic *nic, const char *d, unsigned int t, un } hdr; unsigned short status; int s1, s2; + tick_t ct; status = inw(ioaddr + SCBStatus); /* Acknowledge all of the current interrupt sources ASAP. */ @@ -445,8 +445,10 @@ static void eepro100_transmit(struct nic *nic, const char *d, unsigned int t, un wait_for_cmd_done(ioaddr + SCBCmd); s1 = inw (ioaddr + SCBStatus); - load_timer2(10*TICKS_PER_MS); /* timeout 10 ms for transmit */ - while (!txfd.status && timer2_running()) + + ct = currticks(); + /* timeout 10 ms for transmit */ + while (!txfd.status && ct + 10*USECS_IN_MSEC) /* Wait */; s2 = inw (ioaddr + SCBStatus); @@ -606,6 +608,7 @@ static int eepro100_probe ( struct nic *nic, struct pci_device *pci ) { int read_cmd, ee_size; int options; int rx_mode; + tick_t ct; /* we cache only the first few words of the EEPROM data be careful not to access beyond this array */ @@ -749,8 +752,8 @@ static int eepro100_probe ( struct nic *nic, struct pci_device *pci ) { whereami ("started TX thingy (config, iasetup)."); - load_timer2(10*TICKS_PER_MS); - while (!txfd.status && timer2_running()) + ct = currticks(); + while (!txfd.status && ct + 10*USECS_IN_MSEC < currticks()) /* Wait */; /* Read the status register once to disgard stale data */ diff --git a/src/drivers/net/epic100.c b/src/drivers/net/epic100.c index e79da2b9b..67b4f0fb4 100644 --- a/src/drivers/net/epic100.c +++ b/src/drivers/net/epic100.c @@ -8,7 +8,6 @@ #include #include #include "nic.h" -#include "timer.h" #include "console.h" #include "epic100.h" @@ -310,6 +309,7 @@ epic100_transmit(struct nic *nic, const char *destaddr, unsigned int type, unsigned short nstype; unsigned char *txp; int entry; + tick_t ct; /* Calculate the next Tx descriptor entry. */ entry = cur_tx % TX_RING_SIZE; @@ -339,18 +339,20 @@ epic100_transmit(struct nic *nic, const char *destaddr, unsigned int type, * set the base address with the "ownership" * bits last. */ - + tx_ring[entry].buflength |= cpu_to_le32(len); - tx_ring[entry].status = cpu_to_le32(len << 16) | + tx_ring[entry].status = cpu_to_le32(len << 16) | cpu_to_le32(TRING_OWN); /* Pass ownership to the chip. */ cur_tx++; /* Trigger an immediate transmit demand. */ - outl(CR_QUEUE_TX, command); - - load_timer2(10*TICKS_PER_MS); /* timeout 10 ms for transmit */ - while ((le32_to_cpu(tx_ring[entry].status) & (TRING_OWN)) && timer2_running()) + outl(CR_QUEUE_TX, command); + + ct = currticks(); + /* timeout 10 ms for transmit */ + while ((le32_to_cpu(tx_ring[entry].status) & (TRING_OWN)) && + ct + 10*USECS_IN_MSEC < currticks()) /* Wait */; if ((le32_to_cpu(tx_ring[entry].status) & TRING_OWN) != 0) diff --git a/src/drivers/net/etherfabric.c b/src/drivers/net/etherfabric.c index 6b7634516..90cc73f4b 100644 --- a/src/drivers/net/etherfabric.c +++ b/src/drivers/net/etherfabric.c @@ -24,7 +24,6 @@ #include #include #include -#include "timer.h" #define dma_addr_t unsigned long #include "etherfabric.h" diff --git a/src/drivers/net/forcedeth.c b/src/drivers/net/forcedeth.c index 9ef1dd793..f61958852 100644 --- a/src/drivers/net/forcedeth.c +++ b/src/drivers/net/forcedeth.c @@ -51,7 +51,6 @@ #include /* Include timer support functions */ #include -#include "timer.h" #include "mii.h" #define drv_version "v1.2" diff --git a/src/drivers/net/ipoib.c b/src/drivers/net/ipoib.c index 905051bfa..d457b258a 100644 --- a/src/drivers/net/ipoib.c +++ b/src/drivers/net/ipoib.c @@ -22,7 +22,6 @@ #include #include #include -#include "timer.h" #include #include #include diff --git a/src/drivers/net/mlx_ipoib/mt23108_imp.c b/src/drivers/net/mlx_ipoib/mt23108_imp.c index 4e601668c..bb2383c5f 100644 --- a/src/drivers/net/mlx_ipoib/mt23108_imp.c +++ b/src/drivers/net/mlx_ipoib/mt23108_imp.c @@ -37,7 +37,6 @@ static void be_to_cpu_buf(void *buf, int size) } } -#include "timer.h" #include "cmdif_mt23108.c" #include "cmdif_comm.c" #include "ib_mt23108.c" diff --git a/src/drivers/net/mlx_ipoib/mt25218_imp.c b/src/drivers/net/mlx_ipoib/mt25218_imp.c index fe407041e..007ee653c 100644 --- a/src/drivers/net/mlx_ipoib/mt25218_imp.c +++ b/src/drivers/net/mlx_ipoib/mt25218_imp.c @@ -37,7 +37,6 @@ static void be_to_cpu_buf(void *buf, int size) } } -#include "timer.h" #include "cmdif_mt25218.c" #include "cmdif_comm.c" #include "ib_mt25218.c" diff --git a/src/drivers/net/mtnic.c b/src/drivers/net/mtnic.c index a568b2f7e..536fcb8d7 100755 --- a/src/drivers/net/mtnic.c +++ b/src/drivers/net/mtnic.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/net/natsemi.c b/src/drivers/net/natsemi.c index 720476109..98a5ff848 100644 --- a/src/drivers/net/natsemi.c +++ b/src/drivers/net/natsemi.c @@ -63,8 +63,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/drivers/net/pcnet32.c b/src/drivers/net/pcnet32.c index e4318429a..d8529da17 100644 --- a/src/drivers/net/pcnet32.c +++ b/src/drivers/net/pcnet32.c @@ -43,7 +43,6 @@ #include "nic.h" #include #include -#include "timer.h" #include "mii.h" /* void hex_dump(const char *data, const unsigned int len); */ diff --git a/src/drivers/net/prism2.c b/src/drivers/net/prism2.c index 3c5125192..aaf4c968f 100644 --- a/src/drivers/net/prism2.c +++ b/src/drivers/net/prism2.c @@ -62,7 +62,6 @@ static const char hardcoded_ssid[] = ""; * quicker to convert code from the Linux Prism2 driver. */ #include -#include "timer.h" #define __le16_to_cpu(x) (x) #define __le32_to_cpu(x) (x) #define __cpu_to_le16(x) (x) diff --git a/src/drivers/net/r8169.c b/src/drivers/net/r8169.c index 52cb0d0e4..ab9a30f88 100644 --- a/src/drivers/net/r8169.c +++ b/src/drivers/net/r8169.c @@ -49,7 +49,6 @@ #include #include #include -#include "timer.h" #define drv_version "v1.6" #define drv_date "03-27-2004" diff --git a/src/drivers/net/rtl8139.c b/src/drivers/net/rtl8139.c index b4c99fcbd..83fac554a 100644 --- a/src/drivers/net/rtl8139.c +++ b/src/drivers/net/rtl8139.c @@ -71,7 +71,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/net/sis900.c b/src/drivers/net/sis900.c index cf9b2ce6a..585265063 100644 --- a/src/drivers/net/sis900.c +++ b/src/drivers/net/sis900.c @@ -46,7 +46,6 @@ #include "etherboot.h" #include #include "nic.h" -#include "timer.h" #include "sis900.h" diff --git a/src/drivers/net/smc9000.c b/src/drivers/net/smc9000.c index c6219ee74..31a1e1b11 100644 --- a/src/drivers/net/smc9000.c +++ b/src/drivers/net/smc9000.c @@ -40,7 +40,6 @@ #include "etherboot.h" #include "nic.h" #include -#include "timer.h" #include "smc9000.h" # define _outb outb diff --git a/src/drivers/net/sundance.c b/src/drivers/net/sundance.c index 3bbfbfbbd..3b6f5a88b 100644 --- a/src/drivers/net/sundance.c +++ b/src/drivers/net/sundance.c @@ -46,7 +46,6 @@ #include "nic.h" /* to get the PCI support functions, if this is a PCI NIC */ #include -#include "timer.h" #include "mii.h" #define drv_version "v1.12" diff --git a/src/drivers/net/tg3.c b/src/drivers/net/tg3.c index 2188def42..57b9df1e0 100644 --- a/src/drivers/net/tg3.c +++ b/src/drivers/net/tg3.c @@ -17,7 +17,6 @@ #include #include #include -#include "timer.h" #include "string.h" #include "tg3.h" diff --git a/src/drivers/net/tlan.c b/src/drivers/net/tlan.c index 60ca182e6..4fae01703 100644 --- a/src/drivers/net/tlan.c +++ b/src/drivers/net/tlan.c @@ -42,7 +42,6 @@ #include "nic.h" #include #include -#include "timer.h" #include "tlan.h" #define drv_version "v1.4" diff --git a/src/drivers/net/via-rhine.c b/src/drivers/net/via-rhine.c index 0c955fab3..81350091b 100644 --- a/src/drivers/net/via-rhine.c +++ b/src/drivers/net/via-rhine.c @@ -50,7 +50,6 @@ static const char *version = "rhine.c v1.0.2 2004-10-29\n"; #include "nic.h" #include #include -#include "timer.h" /* define all ioaddr */ @@ -785,6 +784,7 @@ ReadMII (int byMIIIndex, int ioaddr) char byMIIAdrbak; char byMIICRbak; char byMIItemp; + tick_t ct; byMIIAdrbak = inb (byMIIAD); byMIICRbak = inb (byMIICR); @@ -799,8 +799,8 @@ ReadMII (int byMIIIndex, int ioaddr) byMIItemp = inb (byMIICR); byMIItemp = byMIItemp & 0x40; - load_timer2(2*TICKS_PER_MS); - while (byMIItemp != 0 && timer2_running()) + ct = currticks(); + while (byMIItemp != 0 && ct + 2*USECS_IN_MSEC < currticks()) { byMIItemp = inb (byMIICR); byMIItemp = byMIItemp & 0x40; @@ -825,6 +825,7 @@ WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr) char byMIIAdrbak; char byMIICRbak; char byMIItemp; + tick_t ct; byMIIAdrbak = inb (byMIIAD); @@ -840,8 +841,8 @@ WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr) byMIItemp = inb (byMIICR); byMIItemp = byMIItemp & 0x40; - load_timer2(2*TICKS_PER_MS); - while (byMIItemp != 0 && timer2_running()) + ct = currticks(); + while (byMIItemp != 0 && ct + 2*USECS_IN_MSEC < currticks()) { byMIItemp = inb (byMIICR); byMIItemp = byMIItemp & 0x40; @@ -870,8 +871,8 @@ WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr) byMIItemp = inb (byMIICR); byMIItemp = byMIItemp & 0x20; - load_timer2(2*TICKS_PER_MS); - while (byMIItemp != 0 && timer2_running()) + ct = currticks(); + while (byMIItemp != 0 && ct + 2*USECS_IN_MSEC < currticks()) { byMIItemp = inb (byMIICR); byMIItemp = byMIItemp & 0x20; @@ -1345,6 +1346,7 @@ rhine_transmit (struct nic *nic, unsigned char CR1bak; unsigned char CR0bak; unsigned int nstype; + tick_t ct; /*printf ("rhine_transmit\n"); */ @@ -1385,9 +1387,10 @@ rhine_transmit (struct nic *nic, outb (CR1bak, byCR1); do { - load_timer2(10*TICKS_PER_MS); + ct = currticks(); /* Wait until transmit is finished or timeout*/ - while((tp->tx_ring[entry].tx_status.bits.own_bit !=0) && timer2_running()) + while((tp->tx_ring[entry].tx_status.bits.own_bit !=0) && + ct + 10*USECS_IN_MSEC < currticks()) ; if(tp->tx_ring[entry].tx_status.bits.terr == 0) diff --git a/src/drivers/net/via-velocity.h b/src/drivers/net/via-velocity.h index c296d2899..a43028bd9 100644 --- a/src/drivers/net/via-velocity.h +++ b/src/drivers/net/via-velocity.h @@ -24,8 +24,6 @@ * Copyright (c) 2006 by Timothy Legge */ -#include "timer.h" - #ifndef VELOCITY_H #define VELOCITY_H diff --git a/src/drivers/net/w89c840.c b/src/drivers/net/w89c840.c index 2f141aa98..144976404 100644 --- a/src/drivers/net/w89c840.c +++ b/src/drivers/net/w89c840.c @@ -81,7 +81,6 @@ #include "nic.h" #include #include -#include "timer.h" static const char *w89c840_version = "driver Version 0.94 - December 12, 2003"; @@ -113,7 +112,7 @@ static const char *w89c840_version = "driver Version 0.94 - December 12, 2003"; /* Operational parameters that usually are not changed. */ /* Time in jiffies before concluding the transmitter is hung. */ -#define TX_TIMEOUT (10*TICKS_PER_MS) +#define TX_TIMEOUT (10*USECS_IN_MSEC) #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/ @@ -487,6 +486,7 @@ static void w89c840_transmit( /* send the packet to destination */ unsigned entry; int transmit_status; + tick_t ct; /* Caution: the write order is important here, set the field with the "ownership" bits last. */ @@ -535,8 +535,7 @@ static void w89c840_transmit( /* Now wait for TX to complete. */ transmit_status = w840private.tx_ring[entry].status; - load_timer2(TX_TIMEOUT); - + ct = currticks(); { #if defined W89C840_DEBUG u32 intr_stat = 0; @@ -547,7 +546,7 @@ static void w89c840_transmit( decode_interrupt(intr_stat); #endif - while ( (transmit_status & DescOwn) && timer2_running()) { + while ( (transmit_status & DescOwn) && ct + TX_TIMEOUT < currticks()) { transmit_status = w840private.tx_ring[entry].status; } diff --git a/src/drivers/nvs/spi.c b/src/drivers/nvs/spi.c index be6b5904f..dbdc32f61 100644 --- a/src/drivers/nvs/spi.c +++ b/src/drivers/nvs/spi.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include /** @file diff --git a/src/drivers/nvs/threewire.c b/src/drivers/nvs/threewire.c index 622e85857..dbecf9099 100644 --- a/src/drivers/nvs/threewire.c +++ b/src/drivers/nvs/threewire.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include /** @file diff --git a/src/hci/mucurses/kb.c b/src/hci/mucurses/kb.c index 291ee6ac8..cada72917 100644 --- a/src/hci/mucurses/kb.c +++ b/src/hci/mucurses/kb.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include "mucurses.h" /** @file diff --git a/src/hci/shell_banner.c b/src/hci/shell_banner.c index d313d4dd0..62da487c7 100644 --- a/src/hci/shell_banner.c +++ b/src/hci/shell_banner.c @@ -18,8 +18,8 @@ #include #include -#include #include +#include #include /** @file diff --git a/src/include/etherboot.h b/src/include/etherboot.h index 8d658194f..2a465954f 100644 --- a/src/include/etherboot.h +++ b/src/include/etherboot.h @@ -12,8 +12,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h index 9a9ba7484..6db0e026c 100644 --- a/src/include/gpxe/dhcp.h +++ b/src/include/gpxe/dhcp.h @@ -12,7 +12,6 @@ #include #include #include -#include struct net_device; struct job_interface; diff --git a/src/include/gpxe/tcp.h b/src/include/gpxe/tcp.h index e2753120c..264ec29b4 100644 --- a/src/include/gpxe/tcp.h +++ b/src/include/gpxe/tcp.h @@ -9,7 +9,6 @@ * */ -#include "latch.h" #include /** diff --git a/src/include/timer.h b/src/include/timer.h deleted file mode 100644 index cd1b2821a..000000000 --- a/src/include/timer.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -/* - * This file should be removed as soon as there are no - * currticks() abusers. - */ - -#include -/* -#warning Please fix me. I'm abusing the deprecated include/timer.h -*/ -#include - -/* Duplicates include/gpxe/timer.h */ -typedef uint32_t tick_t; - -#define MSECS_IN_SEC (1000) -#define USECS_IN_SEC (1000*1000) -#define USECS_IN_MSEC (1000) - -#define TICKS_PER_SEC USECS_IN_SEC - -tick_t currticks(void); - -#endif - diff --git a/src/net/retry.c b/src/net/retry.c index 0f711e6d1..90b897112 100644 --- a/src/net/retry.c +++ b/src/net/retry.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/net/tcp.c b/src/net/tcp.c index d6b44b02b..da8e87b4b 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c index 081fa841a..2cb258e43 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -33,6 +33,7 @@ #include #include #include +#include /** @file * -- cgit v1.2.3-55-g7522 From 379c37bafba794b47afcb1e9970b6207fb0eb9f4 Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Sun, 2 Mar 2008 04:36:50 +0300 Subject: Cleanups Replace a printf with a DBG in timer_rtdsc.c Replace a printf in timer.c with assert Return proper error codes from timer drivers Signed-off-by: Alexey Zaytsev --- src/arch/i386/drivers/timer_rtdsc.c | 5 +++-- src/arch/i386/include/bits/errfile.h | 3 +++ src/core/timer.c | 8 ++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/arch/i386/drivers/timer_rtdsc.c b/src/arch/i386/drivers/timer_rtdsc.c index 1cd2abead..336e3e6fc 100644 --- a/src/arch/i386/drivers/timer_rtdsc.c +++ b/src/arch/i386/drivers/timer_rtdsc.c @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -78,8 +79,8 @@ static int rtdsc_ts_init(void) } } - printf("RTDSC timer not available on this machine.\n"); - return 1; + DBG("RTDSC timer not available on this machine.\n"); + return -ENODEV; } struct timer rtdsc_ts __timer (01) = { diff --git a/src/arch/i386/include/bits/errfile.h b/src/arch/i386/include/bits/errfile.h index a6f878254..ce58eefd0 100644 --- a/src/arch/i386/include/bits/errfile.h +++ b/src/arch/i386/include/bits/errfile.h @@ -26,6 +26,9 @@ #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_bios ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00010000 ) + /** @} */ #endif /* _BITS_ERRFILE_H */ diff --git a/src/core/timer.c b/src/core/timer.c index da53e0539..e736f5285 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -53,17 +53,13 @@ static void timer_init(void) struct timer *ts; for (ts = ts_table; ts < ts_table_end; ts++) { - if (ts->init && !ts->init()) { + if (ts->init && ts->init() >= 0) { used_ts = ts; break; } } - if (!used_ts) { - printf("No timer available. This should never happen. Expect gPXE to die soon.\n"); - /* Panic */ - } - + assert(used_ts); } struct init_fn ts_init_fn __init_fn ( INIT_NORMAL ) = { -- 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 diff --git a/src/arch/i386/drivers/timer_rdtsc.c b/src/arch/i386/drivers/timer_rdtsc.c new file mode 100644 index 000000000..57b8826c7 --- /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 336e3e6fc..000000000 --- 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 ce58eefd0..0f1402148 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 af0df1b69..4aac654a2 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 f3e17b62e..94fd0b82c 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(-) diff --git a/src/config.h b/src/config.h index 4aac654a2..b3e572692 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(-) diff --git a/src/config.h b/src/config.h index b3e572692..67fdd64c6 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 From 8de54ef9aa9817d878ad6a7ddef29e92615a5963 Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Thu, 6 Mar 2008 16:06:58 +0300 Subject: Use plain C in timer_rdtsc for division instead of inline asssembly. This also fixes a bug in rdtsc_currticks when the result did not fix in %eax Signed-off-by: Alexey Zaytsev --- src/arch/i386/drivers/timer_rdtsc.c | 64 ++++++++++++------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/src/arch/i386/drivers/timer_rdtsc.c b/src/arch/i386/drivers/timer_rdtsc.c index 57b8826c7..09b7df2f0 100644 --- a/src/arch/i386/drivers/timer_rdtsc.c +++ b/src/arch/i386/drivers/timer_rdtsc.c @@ -14,54 +14,32 @@ #define rdtscll(val) \ __asm__ __volatile__ ("rdtsc" : "=A" (val)) -static unsigned long long calibrate_tsc(void) + +/* Measure how many clocks we get in one microsecond */ +static inline uint64_t 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; + + uint64_t rdtsc_start; + uint64_t rdtsc_end; + + rdtscll(rdtsc_start); + i386_timer2_udelay(USECS_IN_MSEC); + rdtscll(rdtsc_end); + + return (rdtsc_end - rdtsc_start) / USECS_IN_MSEC; } -static uint32_t clocks_per_second = 0; +static uint32_t clocks_per_usec = 0; + +/* We measure time in microseconds. */ static tick_t rdtsc_currticks(void) { - uint32_t clocks_high, clocks_low; - uint32_t currticks; + uint64_t clocks; /* 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)); + rdtscll(clocks); - return currticks; + return clocks / clocks_per_usec; } static int rdtsc_ts_init(void) @@ -71,10 +49,10 @@ static int rdtsc_ts_init(void) get_cpuinfo(&cpu_info); if (cpu_info.features & X86_FEATURE_TSC) { - clocks_per_second = calibrate_tsc(); - if (clocks_per_second) { + clocks_per_usec= calibrate_tsc(); + if (clocks_per_usec) { DBG("RDTSC ticksource installed. CPU running at %ld Mhz\n", - clocks_per_second/(1000*1000)); + clocks_per_usec); return 0; } } -- cgit v1.2.3-55-g7522