]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Add ich2-timer.
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Thu, 2 Oct 2008 22:49:42 +0000 (18:49 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Thu, 2 Oct 2008 22:49:42 +0000 (18:49 -0400)
aseg/Makefile
ich2/ich2-timer.c [new file with mode: 0644]
include/reg-82801b.h

index 82836482654c44a016cbc9db8c877ae181632c10..3015bd7a4a48d951ec6e50a11af0f21d5827855e 100644 (file)
@@ -1,6 +1,9 @@
 CC=gcc
 CFLAGS=-I../include -I../include/raw -nostdlib -nostdinc -fno-builtin -D__RAW__ -Wall -Werror -pedantic -ansi -std=gnu99
-OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o ../ich2/smi.o vga-overlay.o packet.o ../lib/sprintf.o ../lib/doprnt.o ../pci/pci.o 3c905.o
+
+OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o \
+       ../ich2/smram-ich2.o ../ich2/smi.o vga-overlay.o packet.o ../lib/sprintf.o \
+       ../lib/doprnt.o ../pci/pci.o 3c905.o ../ich2/ich2-timer.o
 
 all: aseg.elf
 
diff --git a/ich2/ich2-timer.c b/ich2/ich2-timer.c
new file mode 100644 (file)
index 0000000..b98e381
--- /dev/null
@@ -0,0 +1,39 @@
+#include <pci.h>
+#include <io.h>
+#include <reg-82801b.h>
+
+static uint16_t _get_PMBASE()
+{
+       static long pmbase = -1;
+       
+       if (pmbase == -1)       /* Memoize it so that we don't have to hit PCI so often. */
+               pmbase = pci_read32(ICH2_LPC_BUS, ICH2_LPC_DEV, ICH2_LPC_FN, ICH2_LPC_PCI_PMBASE) & ICH2_PMBASE_MASK;
+       
+       return pmbase;
+}
+
+static unsigned long _curtmr()
+{
+       return inl(_get_PMBASE + ICH2_PMBASE_PM1_TMR) & 0xFFFFFF;
+}
+
+/* This is kind of a heuristic, since we can't get interrupts. */
+static unsigned long starttmr = 0, endtmr = 0;
+
+void oneshot_start_ms(unsigned long milliseconds)
+{
+       starttmr = _curtmr();
+       endtmr = (starttmr + milliseconds*(ICH2_PM1_TMR_FREQ/1000)) % 0xFFFFFF;
+}
+
+int oneshot_running(void)
+{
+       if (endtmr == 0 && starttmr == 0)
+               return 0;
+       if ((endtmr < starttmr) && ((_curtmr() > starttmr) || (_curtmr() < endtmr)))
+               return 1;
+       else if ((_curtmr() < endtmr) && (_curtmr() > starttmr))
+               return 1;
+       endtmr = starttmr = 0;
+       return 0;
+}
index a60c458ccd777858ebf83e0d944217522c880056..4e116c27c917568f20525d32af98da2e69d1e747 100644 (file)
@@ -44,6 +44,9 @@
 #define ICH2_PM1_EN_GBL_EN             (1 << 5)
 #define ICH2_PM1_EN_TMROF_EN           (1 << 0
 
+#define ICH2_PMBASE_PM1_TMR            0x08
+#define ICH2_PM1_TMR_FREQ              3579545         /* This will be the encryption key for a question on the test. */
+
 #define ICH2_PMBASE_SMI_EN             0x30
 #define ICH2_SMI_EN_PERIODIC_EN                (1 << 14)
 #define ICH2_SMI_EN_TCO_EN             (1 << 13)
This page took 0.032616 seconds and 4 git commands to generate.