From 0284027ea11f2fa480ade46bf23d4769748f91f3 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 2 Aug 2004 23:20:31 +0000 Subject: [PATCH] Make doubly sure that timer2 is not used for speaker operation. --- sys/bus/isa/syscons_isa.c | 6 +++++- sys/dev/sound/isa/i386/pca/pcaudio.c | 11 +++++++++- sys/i386/isa/clock.c | 14 +++++++----- sys/i386/isa/pmtimer.c | 27 +++-------------------- sys/kern/kern_clock.c | 32 +++++++++++++++++++++++++++- sys/platform/pc32/isa/clock.c | 14 +++++++----- sys/platform/pc32/isa/pmtimer.c | 27 +++-------------------- sys/sys/time.h | 3 ++- 8 files changed, 72 insertions(+), 62 deletions(-) diff --git a/sys/bus/isa/syscons_isa.c b/sys/bus/isa/syscons_isa.c index bbae98423b..aed02ecf6d 100644 --- a/sys/bus/isa/syscons_isa.c +++ b/sys/bus/isa/syscons_isa.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/isa/syscons_isa.c,v 1.11.2.2 2001/08/01 10:42:28 yokota Exp $ - * $DragonFly: src/sys/bus/isa/syscons_isa.c,v 1.4 2004/01/30 05:42:12 dillon Exp $ + * $DragonFly: src/sys/bus/isa/syscons_isa.c,v 1.5 2004/08/02 23:20:28 dillon Exp $ */ #include "opt_syscons.h" @@ -212,6 +212,9 @@ sc_get_bios_values(bios_values_t *values) int sc_tone(int herz) { + return EBUSY; +#if 0 + /* XXX use sound device if available */ #ifdef __i386__ int pitch; @@ -233,6 +236,7 @@ sc_tone(int herz) #endif /* __i386__ */ return 0; +#endif } DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); diff --git a/sys/dev/sound/isa/i386/pca/pcaudio.c b/sys/dev/sound/isa/i386/pca/pcaudio.c index d3274d1f23..8f84bef30b 100644 --- a/sys/dev/sound/isa/i386/pca/pcaudio.c +++ b/sys/dev/sound/isa/i386/pca/pcaudio.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/pcaudio.c,v 1.58 2000/01/25 21:58:43 dfr Exp $ - * $DragonFly: src/sys/dev/sound/isa/i386/pca/Attic/pcaudio.c,v 1.10 2004/05/19 22:52:50 dillon Exp $ + * $DragonFly: src/sys/dev/sound/isa/i386/pca/Attic/pcaudio.c,v 1.11 2004/08/02 23:20:29 dillon Exp $ */ #include @@ -232,6 +232,8 @@ pca_init(void) static int pca_start(void) { + return(-1); +#if 0 int x = splhigh(); int rv = 0; @@ -252,12 +254,14 @@ pca_start(void) splx(x); return rv; +#endif } static void pca_stop(void) { +#if 0 int x = splhigh(); /* release the timers */ @@ -271,24 +275,28 @@ pca_stop(void) pca_status.buffer = pca_status.buf[pca_status.current]; pca_status.timer_on = 0; splx(x); +#endif } static void pca_pause(void) { +#if 0 int x = splhigh(); release_timer0(); release_timer2(); pca_status.timer_on = 0; splx(x); +#endif } static void pca_continue(void) { +#if 0 int x = splhigh(); pca_status.oldval = inb(IO_PPI) | 0x03; @@ -296,6 +304,7 @@ pca_continue(void) acquire_timer0(INTERRUPT_RATE, pcaintr); pca_status.timer_on = 1; splx(x); +#endif } diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c index 1b140fbdb6..ed7145050f 100644 --- a/sys/i386/isa/clock.c +++ b/sys/i386/isa/clock.c @@ -35,7 +35,7 @@ * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 * $FreeBSD: src/sys/i386/isa/clock.c,v 1.149.2.6 2002/11/02 04:41:50 iwasaki Exp $ - * $DragonFly: src/sys/i386/isa/Attic/clock.c,v 1.15 2004/07/20 04:12:08 dillon Exp $ + * $DragonFly: src/sys/i386/isa/Attic/clock.c,v 1.16 2004/08/02 23:20:30 dillon Exp $ */ /* @@ -596,17 +596,21 @@ rtc_restore(void) } /* - * Restore all the timers non-atomically (XXX: should be atomically). + * Restore all the timers. * - * This function is called from apm_default_resume() to restore all the timers. - * This should not be necessary, but there are broken laptops that do not - * restore all the timers on resume. + * This function is called from apm_default_resume() / pmtimer to restore + * all the timers. We also have to restore our timebases, especially on + * MP systems, because cputimer_count() counter's delta may have grown + * too large for nanouptime() and friends to handle. */ void timer_restore(void) { + crit_enter(); i8254_restore(); /* restore timer_freq and hz */ rtc_restore(); /* reenable RTC interrupts */ + restoreclocks(); + crit_exit(); } /* diff --git a/sys/i386/isa/pmtimer.c b/sys/i386/isa/pmtimer.c index 15a1453795..555de101ea 100644 --- a/sys/i386/isa/pmtimer.c +++ b/sys/i386/isa/pmtimer.c @@ -22,7 +22,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * $DragonFly: src/sys/i386/isa/Attic/pmtimer.c,v 1.1 2003/09/24 03:32:17 drhodus Exp $ + * $DragonFly: src/sys/i386/isa/Attic/pmtimer.c,v 1.2 2004/08/02 23:20:30 dillon Exp $ */ #include @@ -98,37 +98,16 @@ pmtimer_resume(device_t dev) { int pl; u_int second, minute, hour; - struct timeval resume_time, tmp_time; + struct timeval resume_time; /* modified for adjkerntz */ pl = splsoftclock(); timer_restore(); /* restore the all timers */ inittodr(0); /* adjust time to RTC */ microtime(&resume_time); - getmicrotime(&tmp_time); - timevaladd(&tmp_time, &diff_time); - -#ifdef FIXME - /* XXX THIS DOESN'T WORK!!! */ - time = tmp_time; -#endif - -#ifdef PMTIMER_FIXUP_CALLTODO - /* Calculate the delta time suspended */ - timevalsub(&resume_time, &suspend_time); - /* Fixup the calltodo list with the delta time. */ - adjust_timeout_calltodo(&resume_time); -#endif /* PMTIMER_FIXUP_CALLTODOK */ + splx(pl); -#ifndef PMTIMER_FIXUP_CALLTODO second = resume_time.tv_sec - suspend_time.tv_sec; -#else /* PMTIMER_FIXUP_CALLTODO */ - /* - * We've already calculated resume_time to be the delta between - * the suspend and the resume. - */ - second = resume_time.tv_sec; -#endif /* PMTIMER_FIXUP_CALLTODO */ hour = second / 3600; second %= 3600; minute = second / 60; diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index d12da6385e..35cd2e27ae 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -70,7 +70,7 @@ * * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/kern_clock.c,v 1.105.2.10 2002/10/17 13:19:40 maxim Exp $ - * $DragonFly: src/sys/kern/kern_clock.c,v 1.22 2004/08/02 19:36:26 dillon Exp $ + * $DragonFly: src/sys/kern/kern_clock.c,v 1.23 2004/08/02 23:20:30 dillon Exp $ */ #include "opt_ntp.h" @@ -197,6 +197,36 @@ initclocks_pcpu(void) crit_exit(); } +/* + * Resynchronize gd_cpuclock_base after the system has been woken up from + * a sleep. It is absolutely essential that all the cpus be properly + * synchronized. Resynching is required because nanouptime() and friends + * will overflow intermediate multiplications if more then 2 seconds + * worth of cputimer_cont() delta has built up. + */ +#ifdef SMP + +static +void +restoreclocks_remote(lwkt_cpusync_t poll) +{ + mycpu->gd_cpuclock_base = *(sysclock_t *)poll->cs_data; + mycpu->gd_time_seconds = globaldata_find(0)->gd_time_seconds; +} + +#endif + +void +restoreclocks(void) +{ + sysclock_t base = cputimer_count(); +#ifdef SMP + lwkt_cpusync_simple(-1, restoreclocks_remote, &base); +#else + mycpu->gd_cpuclock_base = base; +#endif +} + /* * This sets the current real time of day. Timespecs are in seconds and * nanoseconds. We do not mess with gd_time_seconds and gd_cpuclock_base, diff --git a/sys/platform/pc32/isa/clock.c b/sys/platform/pc32/isa/clock.c index 31e91bdb2b..7a4bef3892 100644 --- a/sys/platform/pc32/isa/clock.c +++ b/sys/platform/pc32/isa/clock.c @@ -35,7 +35,7 @@ * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 * $FreeBSD: src/sys/i386/isa/clock.c,v 1.149.2.6 2002/11/02 04:41:50 iwasaki Exp $ - * $DragonFly: src/sys/platform/pc32/isa/clock.c,v 1.15 2004/07/20 04:12:08 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/isa/clock.c,v 1.16 2004/08/02 23:20:30 dillon Exp $ */ /* @@ -596,17 +596,21 @@ rtc_restore(void) } /* - * Restore all the timers non-atomically (XXX: should be atomically). + * Restore all the timers. * - * This function is called from apm_default_resume() to restore all the timers. - * This should not be necessary, but there are broken laptops that do not - * restore all the timers on resume. + * This function is called from apm_default_resume() / pmtimer to restore + * all the timers. We also have to restore our timebases, especially on + * MP systems, because cputimer_count() counter's delta may have grown + * too large for nanouptime() and friends to handle. */ void timer_restore(void) { + crit_enter(); i8254_restore(); /* restore timer_freq and hz */ rtc_restore(); /* reenable RTC interrupts */ + restoreclocks(); + crit_exit(); } /* diff --git a/sys/platform/pc32/isa/pmtimer.c b/sys/platform/pc32/isa/pmtimer.c index 6e64bf6f56..b0728e88e5 100644 --- a/sys/platform/pc32/isa/pmtimer.c +++ b/sys/platform/pc32/isa/pmtimer.c @@ -22,7 +22,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * $DragonFly: src/sys/platform/pc32/isa/pmtimer.c,v 1.1 2003/09/24 03:32:17 drhodus Exp $ + * $DragonFly: src/sys/platform/pc32/isa/pmtimer.c,v 1.2 2004/08/02 23:20:30 dillon Exp $ */ #include @@ -98,37 +98,16 @@ pmtimer_resume(device_t dev) { int pl; u_int second, minute, hour; - struct timeval resume_time, tmp_time; + struct timeval resume_time; /* modified for adjkerntz */ pl = splsoftclock(); timer_restore(); /* restore the all timers */ inittodr(0); /* adjust time to RTC */ microtime(&resume_time); - getmicrotime(&tmp_time); - timevaladd(&tmp_time, &diff_time); - -#ifdef FIXME - /* XXX THIS DOESN'T WORK!!! */ - time = tmp_time; -#endif - -#ifdef PMTIMER_FIXUP_CALLTODO - /* Calculate the delta time suspended */ - timevalsub(&resume_time, &suspend_time); - /* Fixup the calltodo list with the delta time. */ - adjust_timeout_calltodo(&resume_time); -#endif /* PMTIMER_FIXUP_CALLTODOK */ + splx(pl); -#ifndef PMTIMER_FIXUP_CALLTODO second = resume_time.tv_sec - suspend_time.tv_sec; -#else /* PMTIMER_FIXUP_CALLTODO */ - /* - * We've already calculated resume_time to be the delta between - * the suspend and the resume. - */ - second = resume_time.tv_sec; -#endif /* PMTIMER_FIXUP_CALLTODO */ hour = second / 3600; second %= 3600; minute = second / 60; diff --git a/sys/sys/time.h b/sys/sys/time.h index e3c84cb25e..e6b2bbd31a 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -32,7 +32,7 @@ * * @(#)time.h 8.5 (Berkeley) 5/4/95 * $FreeBSD: src/sys/sys/time.h,v 1.42 1999/12/29 04:24:48 peter Exp $ - * $DragonFly: src/sys/sys/time.h,v 1.8 2004/01/30 05:42:18 dillon Exp $ + * $DragonFly: src/sys/sys/time.h,v 1.9 2004/08/02 23:20:31 dillon Exp $ */ #ifndef _SYS_TIME_H_ @@ -192,6 +192,7 @@ struct clockinfo { extern time_t time_second; void initclocks_pcpu(void); +void restoreclocks(void); void getmicrouptime (struct timeval *tv); void getmicrotime (struct timeval *tv); void getnanouptime (struct timespec *tv); -- 2.41.0