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/core/timer.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 15 deletions(-) (limited to 'src/core/timer.c') 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; +} + -- 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(-) (limited to 'src/core/timer.c') 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