Module Name: src Committed By: bouyer Date: Sat Apr 18 14:47:56 UTC 2020
Modified Files: src/sys/arch/amd64/amd64 [bouyer-xenpvh]: machdep.c src/sys/arch/i386/i386 [bouyer-xenpvh]: machdep.c src/sys/arch/x86/include [bouyer-xenpvh]: machdep.h src/sys/arch/x86/isa [bouyer-xenpvh]: clock.c src/sys/arch/x86/x86 [bouyer-xenpvh]: lapic.c x86_machdep.c Log Message: Centralize initialisations of delay_func and initclock_func in x86_machdep.c and export from <x86/machdep.h> Introduce a x86_dummy_initclock() and a x86_cpu_initclock_func pointer, to be used later for Xen HVM native clock support. rename rtclock_tval to x86_rtclock_tval and export from <x86/machdep.h>, for the benefit of lapic.c To generate a diff of this commit: cvs rdiff -u -r1.346.4.2 -r1.346.4.3 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.825.4.2 -r1.825.4.3 src/sys/arch/i386/i386/machdep.c cvs rdiff -u -r1.9 -r1.9.26.1 src/sys/arch/x86/include/machdep.h cvs rdiff -u -r1.36 -r1.36.6.1 src/sys/arch/x86/isa/clock.c cvs rdiff -u -r1.76.6.2 -r1.76.6.3 src/sys/arch/x86/x86/lapic.c cvs rdiff -u -r1.137.2.4 -r1.137.2.5 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.346.4.2 src/sys/arch/amd64/amd64/machdep.c:1.346.4.3 --- src/sys/arch/amd64/amd64/machdep.c:1.346.4.2 Thu Apr 16 09:45:56 2020 +++ src/sys/arch/amd64/amd64/machdep.c Sat Apr 18 14:47:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.346.4.2 2020/04/16 09:45:56 bouyer Exp $ */ +/* $NetBSD: machdep.c,v 1.346.4.3 2020/04/18 14:47:55 bouyer Exp $ */ /* * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -110,7 +110,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.346.4.2 2020/04/16 09:45:56 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.346.4.3 2020/04/18 14:47:55 bouyer Exp $"); #include "opt_modular.h" #include "opt_user_ldt.h" @@ -280,14 +280,6 @@ extern paddr_t avail_start, avail_end; extern paddr_t pmap_pa_start, pmap_pa_end; #endif -#ifndef XENPV -void (*delay_func)(unsigned int) = i8254_delay; -void (*initclock_func)(void) = i8254_initclocks; -#else /* XENPV */ -void (*delay_func)(unsigned int) = xen_delay; -void (*initclock_func)(void) = xen_initclocks; -#endif - struct nmistore { uint64_t cr3; uint64_t scratch; @@ -2129,12 +2121,6 @@ cpu_mcontext_validate(struct lwp *l, con return 0; } -void -cpu_initclocks(void) -{ - (*initclock_func)(); -} - int mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) { Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.825.4.2 src/sys/arch/i386/i386/machdep.c:1.825.4.3 --- src/sys/arch/i386/i386/machdep.c:1.825.4.2 Thu Apr 16 08:46:34 2020 +++ src/sys/arch/i386/i386/machdep.c Sat Apr 18 14:47:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.825.4.2 2020/04/16 08:46:34 bouyer Exp $ */ +/* $NetBSD: machdep.c,v 1.825.4.3 2020/04/18 14:47:55 bouyer Exp $ */ /* * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017 @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.825.4.2 2020/04/16 08:46:34 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.825.4.3 2020/04/18 14:47:55 bouyer Exp $"); #include "opt_beep.h" #include "opt_compat_freebsd.h" @@ -235,14 +235,6 @@ void hypervisor_callback(void); void failsafe_callback(void); #endif -#ifdef XENPV -void (*delay_func)(unsigned int) = xen_delay; -void (*initclock_func)(void) = xen_initclocks; -#else -void (*delay_func)(unsigned int) = i8254_delay; -void (*initclock_func)(void) = i8254_initclocks; -#endif - /* * Size of memory segments, before any memory is stolen. */ @@ -1624,13 +1616,6 @@ cpu_setmcontext(struct lwp *l, const mco return (0); } -void -cpu_initclocks(void) -{ - - (*initclock_func)(); -} - #define DEV_IO 14 /* iopl for compat_10 */ int Index: src/sys/arch/x86/include/machdep.h diff -u src/sys/arch/x86/include/machdep.h:1.9 src/sys/arch/x86/include/machdep.h:1.9.26.1 --- src/sys/arch/x86/include/machdep.h:1.9 Mon Dec 26 17:54:07 2016 +++ src/sys/arch/x86/include/machdep.h Sat Apr 18 14:47:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.h,v 1.9 2016/12/26 17:54:07 cherry Exp $ */ +/* $NetBSD: machdep.h,v 1.9.26.1 2020/04/18 14:47:55 bouyer Exp $ */ /* * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. * All rights reserved. @@ -51,6 +51,12 @@ void x86_cpu_idle_init(void); void x86_cpu_idle_get(void (**)(void), char *, size_t); void x86_cpu_idle_set(void (*)(void), const char *, bool); +extern u_long x86_rtclock_tval; +extern void (*x86_initclock_func)(void); +extern void (*x86_cpu_initclock_func)(void); + +void x86_dummy_initclock(void); + int x86_select_freelist(uint64_t); void init_x86_clusters(void); Index: src/sys/arch/x86/isa/clock.c diff -u src/sys/arch/x86/isa/clock.c:1.36 src/sys/arch/x86/isa/clock.c:1.36.6.1 --- src/sys/arch/x86/isa/clock.c:1.36 Wed Oct 16 18:29:49 2019 +++ src/sys/arch/x86/isa/clock.c Sat Apr 18 14:47:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.36 2019/10/16 18:29:49 christos Exp $ */ +/* $NetBSD: clock.c,v 1.36.6.1 2020/04/18 14:47:56 bouyer Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -121,7 +121,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.36 2019/10/16 18:29:49 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.36.6.1 2020/04/18 14:47:56 bouyer Exp $"); /* #define CLOCKDEBUG */ /* #define CLOCK_PARANOIA */ @@ -214,7 +214,7 @@ static struct timecounter i8254_timecoun NULL, /* next */ }; -u_long rtclock_tval; /* i8254 reload value for countdown */ +u_long x86_rtclock_tval; /* i8254 reload value for countdown */ int rtclock_init = 0; int clock_broken_latch = 0; @@ -286,7 +286,7 @@ gettick_broken_latch(void) return (v2); w1 = v2 - v3; - w2 = v3 - v1 + rtclock_tval; + w2 = v3 - v1 + x86_rtclock_tval; w3 = v1 - v2; if (w1 >= w2) { if (w1 >= w3) @@ -319,7 +319,7 @@ initrtclock(u_long freq) outb(IO_TIMER1+TIMER_CNTR0, tval % 256); outb(IO_TIMER1+TIMER_CNTR0, tval / 256); - rtclock_tval = tval ? tval : 0xFFFF; + x86_rtclock_tval = tval ? tval : 0xFFFF; rtclock_init = 1; } @@ -357,12 +357,13 @@ tickle_tc(void) if (CPU_IS_PRIMARY(ci) == 0) return; #endif - if (rtclock_tval && timecounter->tc_get_timecount == i8254_get_timecount) { + if (x86_rtclock_tval && + timecounter->tc_get_timecount == i8254_get_timecount) { __cpu_simple_lock(&tmr_lock); if (i8254_ticked) i8254_ticked = 0; else { - i8254_offset += rtclock_tval; + i8254_offset += x86_rtclock_tval; i8254_lastcount = 0; } __cpu_simple_unlock(&tmr_lock); @@ -402,11 +403,11 @@ i8254_get_timecount(struct timecounter * /* insb to make the read atomic */ rdval = inb(IO_TIMER1+TIMER_CNTR0); rdval |= (inb(IO_TIMER1+TIMER_CNTR0) << 8); - count = rtclock_tval - rdval; - if (rtclock_tval && (count < i8254_lastcount && - (!i8254_ticked || rtclock_tval == 0xFFFF))) { + count = x86_rtclock_tval - rdval; + if (x86_rtclock_tval && (count < i8254_lastcount && + (!i8254_ticked || x86_rtclock_tval == 0xFFFF))) { i8254_ticked = 1; - i8254_offset += rtclock_tval; + i8254_offset += x86_rtclock_tval; } i8254_lastcount = count; count += i8254_offset; @@ -481,10 +482,10 @@ i8254_delay(unsigned int n) int delta; cur_tick = gettick(); if (cur_tick > initial_tick) - delta = rtclock_tval - (cur_tick - initial_tick); + delta = x86_rtclock_tval - (cur_tick - initial_tick); else delta = initial_tick - cur_tick; - if (delta < 0 || delta >= rtclock_tval / 2) { + if (delta < 0 || delta >= x86_rtclock_tval / 2) { DPRINTF(("delay: ignore ticks %.4x-%.4x", initial_tick, cur_tick)); if (clock_broken_latch) { @@ -499,7 +500,7 @@ i8254_delay(unsigned int n) #else cur_tick = gettick(); if (cur_tick > initial_tick) - remaining -= rtclock_tval - (cur_tick - initial_tick); + remaining -= x86_rtclock_tval - (cur_tick - initial_tick); else remaining -= initial_tick - cur_tick; #endif Index: src/sys/arch/x86/x86/lapic.c diff -u src/sys/arch/x86/x86/lapic.c:1.76.6.2 src/sys/arch/x86/x86/lapic.c:1.76.6.3 --- src/sys/arch/x86/x86/lapic.c:1.76.6.2 Thu Apr 16 08:46:35 2020 +++ src/sys/arch/x86/x86/lapic.c Sat Apr 18 14:47:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lapic.c,v 1.76.6.2 2020/04/16 08:46:35 bouyer Exp $ */ +/* $NetBSD: lapic.c,v 1.76.6.3 2020/04/18 14:47:56 bouyer Exp $ */ /*- * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.76.6.2 2020/04/16 08:46:35 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.76.6.3 2020/04/18 14:47:56 bouyer Exp $"); #include "acpica.h" #include "ioapic.h" @@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1. #include <dev/ic/i8253reg.h> +#include <x86/machdep.h> #include <machine/cpu.h> #include <machine/cpu_counter.h> #include <machine/cpufunc.h> @@ -594,9 +595,6 @@ lapic_initclocks(void) lapic_writereg(LAPIC_EOI, 0); } -extern u_long rtclock_tval; /* XXX put in header file */ -extern void (*initclock_func)(void); /* XXX put in header file */ - /* * Calibrate the local apic count-down timer (which is running at * bus-clock speed) vs. the i8254 counter/timer (which is running at @@ -638,7 +636,7 @@ lapic_calibrate_timer(struct cpu_info *c for (seen = 0; seen < TIMER_FREQ / 100; seen += delta) { cur_i8254 = gettick(); if (cur_i8254 > initial_i8254) - delta = rtclock_tval - (cur_i8254 - initial_i8254); + delta = x86_rtclock_tval - (cur_i8254 - initial_i8254); else delta = initial_i8254 - cur_i8254; initial_i8254 = cur_i8254; @@ -703,7 +701,8 @@ calibrate_done: * for all our timing needs.. */ delay_func = lapic_delay; - initclock_func = lapic_initclocks; + x86_cpu_initclock_func = lapic_initclocks; + x86_initclock_func = x86_dummy_initclock; initrtclock(0); if (lapic_timecounter.tc_frequency == 0) { Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.137.2.4 src/sys/arch/x86/x86/x86_machdep.c:1.137.2.5 --- src/sys/arch/x86/x86/x86_machdep.c:1.137.2.4 Thu Apr 16 09:45:57 2020 +++ src/sys/arch/x86/x86/x86_machdep.c Sat Apr 18 14:47:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.137.2.4 2020/04/16 09:45:57 bouyer Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.137.2.5 2020/04/18 14:47:56 bouyer Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.137.2.4 2020/04/16 09:45:57 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.137.2.5 2020/04/18 14:47:56 bouyer Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -100,6 +100,16 @@ char module_machine_amd64_xen[] = "amd64 char module_machine_i386pae_xen[] = "i386pae-xen"; #endif +#ifndef XENPV +void (*delay_func)(unsigned int) = i8254_delay; +void (*x86_initclock_func)(void) = i8254_initclocks; +void (*x86_cpu_initclock_func)(void) = x86_dummy_initclock; +#else /* XENPV */ +void (*delay_func)(unsigned int) = xen_delay; +void (*x86_initclock_func)(void) = xen_initclocks; +void (*x86_cpu_initclock_func)(void) = xen_cpu_initclocks; +#endif + /* --------------------------------------------------------------------- */ @@ -1433,3 +1443,14 @@ intr_findpic(int num) } #endif +void +cpu_initclocks(void) +{ + + (*x86_initclock_func)(); +} + +void +x86_dummy_initclock(void) +{ +}