From 1f5b992b582f0d8de792df24a81d4a25642b3e45 Mon Sep 17 00:00:00 2001
From: Gabe Black <gblack@eecs.umich.edu>
Date: Thu, 12 Jun 2008 00:56:54 -0400
Subject: [PATCH] X86: Make the platform object initialize channel 0 of the
 PIT.

---
 src/dev/x86/pc.cc                        | 18 +++++++++++++++++-
 src/dev/x86/pc.hh                        |  9 ++++++++-
 src/dev/x86/south_bridge/south_bridge.cc |  6 ++++++
 src/dev/x86/south_bridge/south_bridge.hh | 22 ++++++++++++----------
 4 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/src/dev/x86/pc.cc b/src/dev/x86/pc.cc
index 148ba92f7..0881672d2 100644
--- a/src/dev/x86/pc.cc
+++ b/src/dev/x86/pc.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2005 The Regents of The University of Michigan
+ * Copyright (c) 2008 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,6 +37,7 @@
 #include <vector>
 
 #include "arch/x86/x86_traits.hh"
+#include "dev/intel_8254_timer.hh"
 #include "cpu/intr_control.hh"
 #include "dev/simconsole.hh"
 #include "dev/x86/pc.hh"
@@ -48,10 +49,25 @@ using namespace TheISA;
 PC::PC(const Params *p)
     : Platform(p), system(p->system)
 {
+    southBridge = NULL;
     // set the back pointer from the system to myself
     system->platform = this;
 }
 
+void
+PC::init()
+{
+    assert(southBridge);
+    Intel8254Timer & timer = southBridge->pit.pit;
+    //Timer 0, mode 2, no bcd, 16 bit count
+    timer.writeControl(0x34);
+    //Timer 0, latch command
+    timer.writeControl(0x00);
+    //Write a 16 bit count of 0
+    timer.counter0.write(0);
+    timer.counter0.write(0);
+}
+
 Tick
 PC::intrFrequency()
 {
diff --git a/src/dev/x86/pc.hh b/src/dev/x86/pc.hh
index 6e3a7f45e..3a042fc46 100644
--- a/src/dev/x86/pc.hh
+++ b/src/dev/x86/pc.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2005 The Regents of The University of Michigan
+ * Copyright (c) 2008 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,6 +38,7 @@
 #define __DEV_PC_HH__
 
 #include "dev/platform.hh"
+#include "dev/x86/south_bridge/south_bridge.hh"
 #include "params/PC.hh"
 
 class IdeController;
@@ -48,10 +49,16 @@ class PC : public Platform
   public:
     /** Pointer to the system */
     System *system;
+    SouthBridge * southBridge;
 
   public:
     typedef PCParams Params;
 
+    /**
+     * Do platform initialization stuff
+     */
+    void init();
+
     PC(const Params *p);
 
     /**
diff --git a/src/dev/x86/south_bridge/south_bridge.cc b/src/dev/x86/south_bridge/south_bridge.cc
index 57cc27bcc..b1f0abfe6 100644
--- a/src/dev/x86/south_bridge/south_bridge.cc
+++ b/src/dev/x86/south_bridge/south_bridge.cc
@@ -30,6 +30,7 @@
 
 #include "arch/x86/x86_traits.hh"
 #include "base/range.hh"
+#include "dev/x86/pc.hh"
 #include "dev/x86/south_bridge/south_bridge.hh"
 
 using namespace X86ISA;
@@ -77,6 +78,11 @@ SouthBridge::SouthBridge(const Params *p) : PioDevice(p),
     addDevice(pit);
     addDevice(cmos);
     addDevice(speaker);
+
+    // Let the platform know where we are
+    PC * pc = dynamic_cast<PC *>(platform);
+    assert(pc);
+    pc->southBridge = this;
 }
 
 SouthBridge *
diff --git a/src/dev/x86/south_bridge/south_bridge.hh b/src/dev/x86/south_bridge/south_bridge.hh
index 28936fb91..203cb6ee2 100644
--- a/src/dev/x86/south_bridge/south_bridge.hh
+++ b/src/dev/x86/south_bridge/south_bridge.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2005 The Regents of The University of Michigan
+ * Copyright (c) 2008 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,16 @@
 class SouthBridge : public PioDevice
 {
   protected:
+    AddrRangeList rangeList;
+
+    typedef range_map<Addr, X86ISA::SubDevice *> RangeMap;
+    typedef RangeMap::iterator RangeMapIt;
+    RangeMap rangeMap;
+
+
+    void addDevice(X86ISA::SubDevice &);
+
+  public:
     // PICs
     X86ISA::I8259 pic1;
     X86ISA::I8259 pic2;
@@ -56,16 +66,8 @@ class SouthBridge : public PioDevice
     // PC speaker
     X86ISA::Speaker speaker;
 
-    AddrRangeList rangeList;
-
-    typedef range_map<Addr, X86ISA::SubDevice *> RangeMap;
-    typedef RangeMap::iterator RangeMapIt;
-    RangeMap rangeMap;
-
-
-    void addDevice(X86ISA::SubDevice &);
-
   public:
+
     void addressRanges(AddrRangeList &range_list);
 
     Tick read(PacketPtr pkt);
-- 
2.30.2