[PATCH 3/5][time][x86_64] Split x86_64/kernel/time.c up

2006-12-19 Thread john stultz
In preparation for the x86_64 generic time conversion, this patch 
splits out TSC and HPET related code from arch/x86_64/kernel/time.c 
into respective hpet.c and tsc.c files.

Signed-off-by: John Stultz <[EMAIL PROTECTED]>

 arch/x86_64/kernel/Makefile |2 
 arch/x86_64/kernel/hpet.c   |  437 ++
 arch/x86_64/kernel/time.c   |  628 
 arch/x86_64/kernel/tsc.c|  201 ++
 include/asm-x86_64/hpet.h   |6 
 include/asm-x86_64/timex.h  |   11 
 6 files changed, 660 insertions(+), 625 deletions(-)

linux-2.6.20-rc1_timeofday-arch-x86-64-split-hpet-tsc-time_C7.patch

diff --git a/arch/x86_64/kernel/Makefile b/arch/x86_64/kernel/Makefile
index 3c7cbff..e68a87e 100644
--- a/arch/x86_64/kernel/Makefile
+++ b/arch/x86_64/kernel/Makefile
@@ -8,7 +8,7 @@ obj-y   := process.o signal.o entry.o trap
ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \
x8664_ksyms.o i387.o syscall.o vsyscall.o \
setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \
-   pci-dma.o pci-nommu.o alternative.o
+   pci-dma.o pci-nommu.o alternative.o hpet.o tsc.o
 
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_X86_MCE)  += mce.o therm_throt.o
diff --git a/arch/x86_64/kernel/hpet.c b/arch/x86_64/kernel/hpet.c
new file mode 100644
index 000..ad67c6b
--- /dev/null
+++ b/arch/x86_64/kernel/hpet.c
@@ -0,0 +1,437 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int nohpet __initdata = 0;
+
+unsigned long hpet_address;
+unsigned long hpet_period; /* fsecs / HPET clock */
+unsigned long hpet_tick;   /* HPET clocks / interrupt */
+
+int hpet_use_timer;/* Use counter of hpet for time keeping,
+* otherwise PIT
+*/
+unsigned int do_gettimeoffset_hpet(void)
+{
+   /* cap counter read to one tick to avoid inconsistencies */
+   unsigned long counter = hpet_readl(HPET_COUNTER) - vxtime.last;
+   return (min(counter,hpet_tick) * vxtime.quot) >> US_SCALE;
+}
+
+#ifdef CONFIG_HPET
+static __init int late_hpet_init(void)
+{
+   struct hpet_datahd;
+   unsigned intntimer;
+
+   if (!hpet_address)
+   return 0;
+
+   memset(&hd, 0, sizeof (hd));
+
+   ntimer = hpet_readl(HPET_ID);
+   ntimer = (ntimer & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT;
+   ntimer++;
+
+   /*
+* Register with driver.
+* Timer0 and Timer1 is used by platform.
+*/
+   hd.hd_phys_address = hpet_address;
+   hd.hd_address = (void __iomem *)fix_to_virt(FIX_HPET_BASE);
+   hd.hd_nirqs = ntimer;
+   hd.hd_flags = HPET_DATA_PLATFORM;
+   hpet_reserve_timer(&hd, 0);
+#ifdef CONFIG_HPET_EMULATE_RTC
+   hpet_reserve_timer(&hd, 1);
+#endif
+   hd.hd_irq[0] = HPET_LEGACY_8254;
+   hd.hd_irq[1] = HPET_LEGACY_RTC;
+   if (ntimer > 2) {
+   struct hpet *hpet;
+   struct hpet_timer   *timer;
+   int i;
+
+   hpet = (struct hpet *) fix_to_virt(FIX_HPET_BASE);
+   timer = &hpet->hpet_timers[2];
+   for (i = 2; i < ntimer; timer++, i++)
+   hd.hd_irq[i] = (timer->hpet_config &
+   Tn_INT_ROUTE_CNF_MASK) >>
+   Tn_INT_ROUTE_CNF_SHIFT;
+
+   }
+
+   hpet_alloc(&hd);
+   return 0;
+}
+fs_initcall(late_hpet_init);
+#endif
+
+int hpet_timer_stop_set_go(unsigned long tick)
+{
+   unsigned int cfg;
+
+/*
+ * Stop the timers and reset the main counter.
+ */
+
+   cfg = hpet_readl(HPET_CFG);
+   cfg &= ~(HPET_CFG_ENABLE | HPET_CFG_LEGACY);
+   hpet_writel(cfg, HPET_CFG);
+   hpet_writel(0, HPET_COUNTER);
+   hpet_writel(0, HPET_COUNTER + 4);
+
+/*
+ * Set up timer 0, as periodic with first interrupt to happen at hpet_tick,
+ * and period also hpet_tick.
+ */
+   if (hpet_use_timer) {
+   hpet_writel(HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL |
+   HPET_TN_32BIT, HPET_T0_CFG);
+   hpet_writel(hpet_tick, HPET_T0_CMP); /* next interrupt */
+   hpet_writel(hpet_tick, HPET_T0_CMP); /* period */
+   cfg |= HPET_CFG_LEGACY;
+   }
+/*
+ * Go!
+ */
+
+   cfg |= HPET_CFG_ENABLE;
+   hpet_writel(cfg, HPET_CFG);
+
+   return 0;
+}
+
+int hpet_arch_init(void)
+{
+   unsigned int id;
+
+   if (!hpet_address)
+   return -1;
+   set_fixmap_nocache(FIX_HPET_BASE, hpet_address);
+   __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE);
+
+/*
+ * Read the period, compute tick and quotient.
+ */
+
+   id = hpet_readl(HPET

[PATCH 3/5][time][x86_64] Split x86_64/kernel/time.c up

2006-11-28 Thread john stultz
In preperation for the x86_64 generic time conversion, this patch 
splits out TSC and HPET related code from arch/x86_64/kernel/time.c 
into respective hpet.c and tsc.c files.

Signed-off-by: John Stultz <[EMAIL PROTECTED]>

 arch/x86_64/kernel/Makefile |2 
 arch/x86_64/kernel/hpet.c   |  435 ++
 arch/x86_64/kernel/time.c   |  628 
 arch/x86_64/kernel/tsc.c|  201 ++
 include/asm-x86_64/hpet.h   |6 
 include/asm-x86_64/timex.h  |   11 
 6 files changed, 658 insertions(+), 625 deletions(-)

linux-2.6.19-rc6git11_timeofday-arch-x86-64-split-hpet-tsc-time_C7.patch

diff --git a/arch/x86_64/kernel/Makefile b/arch/x86_64/kernel/Makefile
index 3c7cbff..e68a87e 100644
--- a/arch/x86_64/kernel/Makefile
+++ b/arch/x86_64/kernel/Makefile
@@ -8,7 +8,7 @@ obj-y   := process.o signal.o entry.o trap
ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \
x8664_ksyms.o i387.o syscall.o vsyscall.o \
setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \
-   pci-dma.o pci-nommu.o alternative.o
+   pci-dma.o pci-nommu.o alternative.o hpet.o tsc.o
 
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_X86_MCE)  += mce.o therm_throt.o
diff --git a/arch/x86_64/kernel/hpet.c b/arch/x86_64/kernel/hpet.c
new file mode 100644
index 000..a219786
--- /dev/null
+++ b/arch/x86_64/kernel/hpet.c
@@ -0,0 +1,435 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int nohpet __initdata = 0;
+
+unsigned long hpet_address;
+unsigned long hpet_period; /* fsecs / HPET clock */
+unsigned long hpet_tick;   /* HPET clocks / interrupt */
+
+int hpet_use_timer;/* Use counter of hpet for time keeping,
+* otherwise PIT
+*/
+unsigned int do_gettimeoffset_hpet(void)
+{
+   /* cap counter read to one tick to avoid inconsistencies */
+   unsigned long counter = hpet_readl(HPET_COUNTER) - vxtime.last;
+   return (min(counter,hpet_tick) * vxtime.quot) >> US_SCALE;
+}
+
+#ifdef CONFIG_HPET
+static __init int late_hpet_init(void)
+{
+   struct hpet_datahd;
+   unsigned intntimer;
+
+   if (!hpet_address)
+   return 0;
+
+   memset(&hd, 0, sizeof (hd));
+
+   ntimer = hpet_readl(HPET_ID);
+   ntimer = (ntimer & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT;
+   ntimer++;
+
+   /*
+* Register with driver.
+* Timer0 and Timer1 is used by platform.
+*/
+   hd.hd_phys_address = hpet_address;
+   hd.hd_address = (void __iomem *)fix_to_virt(FIX_HPET_BASE);
+   hd.hd_nirqs = ntimer;
+   hd.hd_flags = HPET_DATA_PLATFORM;
+   hpet_reserve_timer(&hd, 0);
+#ifdef CONFIG_HPET_EMULATE_RTC
+   hpet_reserve_timer(&hd, 1);
+#endif
+   hd.hd_irq[0] = HPET_LEGACY_8254;
+   hd.hd_irq[1] = HPET_LEGACY_RTC;
+   if (ntimer > 2) {
+   struct hpet *hpet;
+   struct hpet_timer   *timer;
+   int i;
+
+   hpet = (struct hpet *) fix_to_virt(FIX_HPET_BASE);
+   timer = &hpet->hpet_timers[2];
+   for (i = 2; i < ntimer; timer++, i++)
+   hd.hd_irq[i] = (timer->hpet_config &
+   Tn_INT_ROUTE_CNF_MASK) >>
+   Tn_INT_ROUTE_CNF_SHIFT;
+
+   }
+
+   hpet_alloc(&hd);
+   return 0;
+}
+fs_initcall(late_hpet_init);
+#endif
+
+int hpet_timer_stop_set_go(unsigned long tick)
+{
+   unsigned int cfg;
+
+/*
+ * Stop the timers and reset the main counter.
+ */
+
+   cfg = hpet_readl(HPET_CFG);
+   cfg &= ~(HPET_CFG_ENABLE | HPET_CFG_LEGACY);
+   hpet_writel(cfg, HPET_CFG);
+   hpet_writel(0, HPET_COUNTER);
+   hpet_writel(0, HPET_COUNTER + 4);
+
+/*
+ * Set up timer 0, as periodic with first interrupt to happen at hpet_tick,
+ * and period also hpet_tick.
+ */
+   if (hpet_use_timer) {
+   hpet_writel(HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL |
+   HPET_TN_32BIT, HPET_T0_CFG);
+   hpet_writel(hpet_tick, HPET_T0_CMP); /* next interrupt */
+   hpet_writel(hpet_tick, HPET_T0_CMP); /* period */
+   cfg |= HPET_CFG_LEGACY;
+   }
+/*
+ * Go!
+ */
+
+   cfg |= HPET_CFG_ENABLE;
+   hpet_writel(cfg, HPET_CFG);
+
+   return 0;
+}
+
+int hpet_arch_init(void)
+{
+   unsigned int id;
+
+   if (!hpet_address)
+   return -1;
+   set_fixmap_nocache(FIX_HPET_BASE, hpet_address);
+   __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE);
+
+/*
+ * Read the period, compute tick and quotient.
+ */
+
+   id = hpet_readl(HPET_ID);
+
+   i