TIMER selection via tunable

Joerg Sonnenberger joerg at britannica.bec.de
Sat Apr 2 09:01:24 PST 2005


Hi all,
the attached patch implements the timer selection as tunable and
removes the TIMER_USE_1 option.

I intend to commit this tomorrow.

Joerg
Index: conf/options.i386
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/conf/options.i386,v
retrieving revision 1.10
diff -u -r1.10 options.i386
--- conf/options.i386	28 Mar 2005 14:42:44 -0000	1.10
+++ conf/options.i386	28 Mar 2005 22:22:40 -0000
@@ -39,7 +39,6 @@
 CLK_USE_I8254_CALIBRATION	opt_clock.h
 CLK_USE_TSC_CALIBRATION		opt_clock.h
 TIMER_FREQ			opt_clock.h
-TIMER_USE_1			opt_clock.h
 KERN_TIMESTAMP			opt_global.h
 
 NO_F00F_HACK			opt_cpu.h
Index: i386/isa/clock.c
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/sys/i386/isa/clock.c,v
retrieving revision 1.21
diff -u -r1.21 clock.c
--- i386/isa/clock.c	27 Mar 2005 19:25:07 -0000	1.21
+++ i386/isa/clock.c	29 Mar 2005 00:04:42 -0000
@@ -116,13 +116,10 @@
 #define TIMER_FREQ   1193182
 #endif
 
-#ifdef TIMER_USE_1
-#define TIMER_SELX	TIMER_SEL1
-#define TIMER_CNTRX	TIMER_CNTR1
-#else
-#define TIMER_SELX	TIMER_SEL2
-#define TIMER_CNTRX	TIMER_CNTR2
-#endif
+int i8254_walltimer;
+TUNABLE_INT("hw.i8254.walltimer", &i8254_walltimer);
+static uint8_t i8254_walltimer_sel;
+static uint16_t i8254_walltimer_cntr;
 
 int	adjkerntz;		/* local offset from GMT in seconds */
 int	disable_rtc_set;	/* disable resettodr() if != 0 */
@@ -203,7 +200,6 @@
 int
 acquire_timer2(int mode)
 {
-#ifdef TIMER_USE_1
 	if (timer2_state != RELEASED)
 		return (-1);
 	timer2_state = ACQUIRED;
@@ -215,10 +211,6 @@
 	 */
 	outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
 	return (0);
-#else
-	/* Timer2 is being used for time count operation */
-	return(-1);
-#endif
 }
 
 int
@@ -300,9 +292,9 @@
 	sysclock_t ret;
 
 	clock_lock();
-	outb(TIMER_MODE, TIMER_SELX | TIMER_LATCH);
-	count = (__uint8_t)inb(TIMER_CNTRX);		/* get countdown */
-	count |= ((__uint8_t)inb(TIMER_CNTRX) << 8);
+	outb(TIMER_MODE, i8254_walltimer_sel | TIMER_LATCH);
+	count = (__uint8_t)inb(i8254_walltimer_cntr);		/* get countdown */
+	count |= ((__uint8_t)inb(i8254_walltimer_cntr) << 8);
 	count = -count;					/* -> countup */
 	if (count < cputimer_last)			/* rollover */
 		cputimer_base += 0x00010000;
@@ -584,18 +576,25 @@
 i8254_restore(void)
 {
 	timer0_state = ACQUIRED;
-#ifdef TIMER_USE_1
-	timer1_state = ACQUIRED;
-#else
-	timer2_state = ACQUIRED;
-#endif
+	if (i8254_walltimer != 1 && i8254_walltimer != 2)
+		i8254_walltimer = 2;
+
+	if (i8254_walltimer == 1) {
+		i8254_walltimer_sel = TIMER_SEL1;
+		i8254_walltimer_cntr = TIMER_CNTR1;
+		timer1_state = ACQUIRED;
+	} else {
+		i8254_walltimer_sel = TIMER_SEL2;
+		i8254_walltimer_cntr = TIMER_CNTR2;
+		timer2_state = ACQUIRED;
+	}
 	clock_lock();
 	outb(TIMER_MODE, TIMER_SEL0 | TIMER_SWSTROBE | TIMER_16BIT);
 	outb(TIMER_CNTR0, 2);	/* lsb */
 	outb(TIMER_CNTR0, 0);	/* msb */
-	outb(TIMER_MODE, TIMER_SELX | TIMER_RATEGEN | TIMER_16BIT);
-	outb(TIMER_CNTRX, 0);	/* lsb */
-	outb(TIMER_CNTRX, 0);	/* msb */
+	outb(TIMER_MODE, i8254_walltimer_sel | TIMER_RATEGEN | TIMER_16BIT);
+	outb(i8254_walltimer_cntr, 0);	/* lsb */
+	outb(i8254_walltimer_cntr, 0);	/* msb */
 	outb(IO_PPI, inb(IO_PPI) | 1);	/* bit 0: enable gate, bit 1: spkr */
 	clock_unlock();
 }
@@ -1118,7 +1117,10 @@
 }
 
 SYSCTL_NODE(_hw, OID_AUTO, i8254, CTLFLAG_RW, 0, "I8254");
-SYSCTL_UINT(_hw_i8254, OID_AUTO, freq, CTLFLAG_RD, &cputimer_freq, 0, "");
+SYSCTL_UINT(_hw_i8254, OID_AUTO, freq, CTLFLAG_RD, &cputimer_freq, 0,
+    "frequency");
 SYSCTL_PROC(_hw_i8254, OID_AUTO, timestamp, CTLTYPE_STRING|CTLFLAG_RD,
 		0, 0, hw_i8254_timestamp, "A", "");
+SYSCTL_INT(_hw_i8254, OID_AUTO, walltimer, CTLFLAG_RD, &i8254_walltimer, 0,
+    "timer used for the wall time; either 1 or 2");
 




More information about the Submit mailing list