2004-01-22 02:14:10 +01:00
|
|
|
/*
|
2004-06-04 19:43:50 +02:00
|
|
|
* Copyright (c) 2004 The Regents of The University of Michigan
|
2004-01-22 02:14:10 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* @file
|
2004-01-29 00:12:52 +01:00
|
|
|
* Tsunami Fake I/O Space mapping including RTC/timer interrupts
|
2004-01-22 02:14:10 +01:00
|
|
|
*/
|
|
|
|
|
2005-02-21 23:32:57 +01:00
|
|
|
#ifndef __DEV_TSUNAMI_IO_HH__
|
|
|
|
#define __DEV_TSUNAMI_IO_HH__
|
2004-01-22 02:14:10 +01:00
|
|
|
|
2004-06-10 19:30:58 +02:00
|
|
|
#include "dev/io_device.hh"
|
|
|
|
#include "base/range.hh"
|
2004-01-22 02:14:10 +01:00
|
|
|
#include "dev/tsunami.hh"
|
2004-06-27 03:26:28 +02:00
|
|
|
#include "sim/eventq.hh"
|
2004-01-22 02:14:10 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** How often the RTC interrupts */
|
|
|
|
static const int RTC_RATE = 1024;
|
|
|
|
|
2004-01-22 02:14:10 +01:00
|
|
|
/*
|
2004-05-30 23:45:46 +02:00
|
|
|
* Tsunami I/O device is a catch all for all the south bridge stuff we care
|
|
|
|
* to implement.
|
2004-01-22 02:14:10 +01:00
|
|
|
*/
|
2004-06-10 19:30:58 +02:00
|
|
|
class TsunamiIO : public PioDevice
|
2004-01-22 02:14:10 +01:00
|
|
|
{
|
2004-01-26 19:26:34 +01:00
|
|
|
private:
|
2004-05-30 23:45:46 +02:00
|
|
|
/** The base address of this device */
|
2004-02-10 06:19:43 +01:00
|
|
|
Addr addr;
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/** The size of mappad from the above address */
|
2004-02-10 06:19:43 +01:00
|
|
|
static const Addr size = 0xff;
|
|
|
|
|
2004-01-26 19:26:34 +01:00
|
|
|
struct tm tm;
|
|
|
|
|
2005-02-21 23:32:57 +01:00
|
|
|
/**
|
|
|
|
* In Tsunami RTC only has two i/o ports one for data and one for
|
|
|
|
* address, so you write the address and then read/write the
|
|
|
|
* data. This store the address you are going to be reading from
|
|
|
|
* on a read.
|
2004-05-30 23:45:46 +02:00
|
|
|
*/
|
2004-01-26 19:26:34 +01:00
|
|
|
uint8_t RTCAddress;
|
2004-01-22 02:14:10 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* The ClockEvent is handles the PIT interrupts
|
|
|
|
*/
|
2004-01-23 01:02:07 +01:00
|
|
|
class ClockEvent : public Event
|
|
|
|
{
|
2004-02-06 00:23:16 +01:00
|
|
|
protected:
|
2004-05-30 23:45:46 +02:00
|
|
|
/** how often the PIT fires */
|
2004-02-06 00:23:16 +01:00
|
|
|
Tick interval;
|
2004-05-30 23:45:46 +02:00
|
|
|
/** The mode of the PIT */
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t mode;
|
2004-05-30 23:45:46 +02:00
|
|
|
/** The status of the PIT */
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t status;
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-02-06 00:23:16 +01:00
|
|
|
public:
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Just set the mode to 0
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
ClockEvent();
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* processs the timer event
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
virtual void process();
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a description of this event
|
|
|
|
* @return the description
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
virtual const char *description();
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedule a timer interrupt to occur sometime in the future.
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
void Program(int count);
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the mode bits of the PIT.
|
|
|
|
* @param mode the new mode
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
void ChangeMode(uint8_t mode);
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current PIT status.
|
|
|
|
* @return the status of the PIT
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t Status();
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-06-17 00:20:10 +02:00
|
|
|
/**
|
|
|
|
* Serialize this object to the given output stream.
|
|
|
|
* @param os The stream to serialize to.
|
|
|
|
*/
|
|
|
|
virtual void serialize(std::ostream &os);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reconstruct the state of this object from a checkpoint.
|
|
|
|
* @param cp The checkpoint use.
|
|
|
|
* @param section The section name of this object
|
|
|
|
*/
|
|
|
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
|
|
|
};
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Process RTC timer events and generate interrupts appropriately.
|
|
|
|
*/
|
2004-01-23 19:01:32 +01:00
|
|
|
class RTCEvent : public Event
|
|
|
|
{
|
2004-01-28 03:36:46 +01:00
|
|
|
protected:
|
2005-02-21 23:32:57 +01:00
|
|
|
/** A pointer back to tsunami to create interrupt the processor. */
|
|
|
|
Tsunami* tsunami;
|
2004-01-23 19:01:32 +01:00
|
|
|
public:
|
2005-02-21 23:32:57 +01:00
|
|
|
/** RTC Event initializes the RTC event by scheduling an event
|
|
|
|
* RTC_RATE times pre second. */
|
|
|
|
RTCEvent(Tsunami* t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interrupth the processor and reschedule the event.
|
|
|
|
*/
|
|
|
|
virtual void process();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a description of this event.
|
|
|
|
* @return a description
|
|
|
|
*/
|
|
|
|
virtual const char *description();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize this object to the given output stream.
|
|
|
|
* @param os The stream to serialize to.
|
|
|
|
*/
|
|
|
|
virtual void serialize(std::ostream &os);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reconstruct the state of this object from a checkpoint.
|
|
|
|
* @param cp The checkpoint use.
|
|
|
|
* @param section The section name of this object
|
|
|
|
*/
|
|
|
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
|
|
|
};
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** uip UpdateInProgess says that the rtc is updating, but we just fake it
|
|
|
|
* by alternating it on every read of the bit since we are going to
|
|
|
|
* override the loop_per_jiffy time that it is trying to use the UIP to
|
|
|
|
* calculate.
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t uip;
|
2004-01-26 19:26:34 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** Mask of the PIC1 */
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t mask1;
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/** Mask of the PIC2 */
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t mask2;
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/** Mode of PIC1. Not used for anything */
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t mode1;
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/** Mode of PIC2. Not used for anything */
|
2004-02-06 00:23:16 +01:00
|
|
|
uint8_t mode2;
|
2004-01-22 06:08:48 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** Raw PIC interrupt register before masking */
|
|
|
|
uint8_t picr; //Raw PIC interrput register
|
|
|
|
|
|
|
|
/** Is the pic interrupting right now or not. */
|
2004-01-29 01:18:29 +01:00
|
|
|
bool picInterrupting;
|
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** A pointer to the Tsunami device which be belong to */
|
2004-01-28 03:36:46 +01:00
|
|
|
Tsunami *tsunami;
|
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
2004-02-06 00:23:16 +01:00
|
|
|
* This timer is initilized, but after I wrote the code
|
|
|
|
* it doesn't seem to be used again, and best I can tell
|
|
|
|
* it too is not connected to any interrupt port
|
|
|
|
*/
|
|
|
|
ClockEvent timer0;
|
2004-01-26 19:26:34 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
2004-02-06 00:23:16 +01:00
|
|
|
* This timer is used to control the speaker, which
|
|
|
|
* we normally could care less about, however it is
|
|
|
|
* also used to calculated the clockspeed and hense
|
|
|
|
* bogomips which is kinda important to the scheduler
|
|
|
|
* so we need to implemnt it although after boot I can't
|
|
|
|
* imagine we would be playing with the PC speaker much
|
|
|
|
*/
|
|
|
|
ClockEvent timer2;
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** This is the event used to interrupt the cpu like an RTC. */
|
2004-02-06 00:23:16 +01:00
|
|
|
RTCEvent rtc;
|
2004-01-26 19:26:34 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/** The interval is set via two writes to the PIT.
|
|
|
|
* This variable contains a flag as to how many writes have happened, and
|
|
|
|
* the time so far.
|
|
|
|
*/
|
2004-02-06 00:23:16 +01:00
|
|
|
uint32_t timerData;
|
2004-01-23 01:02:07 +01:00
|
|
|
|
2004-01-22 02:14:10 +01:00
|
|
|
public:
|
2004-06-01 23:36:38 +02:00
|
|
|
/**
|
|
|
|
* Return the freqency of the RTC
|
|
|
|
* @return interrupt rate of the RTC
|
|
|
|
*/
|
|
|
|
Tick frequency() const { return RTC_RATE; }
|
2004-01-28 03:36:46 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Initialize all the data for devices supported by Tsunami I/O.
|
|
|
|
* @param name name of this device.
|
|
|
|
* @param t pointer back to the Tsunami object that we belong to.
|
|
|
|
* @param init_time Time (as in seconds since 1970) to set RTC to.
|
|
|
|
* @param a address we are mapped at.
|
|
|
|
* @param mmu pointer to the memory controller that sends us events.
|
|
|
|
*/
|
2004-01-28 03:36:46 +01:00
|
|
|
TsunamiIO(const std::string &name, Tsunami *t, time_t init_time,
|
2004-07-13 04:58:22 +02:00
|
|
|
Addr a, MemoryController *mmu, HierParams *hier, Bus *bus,
|
|
|
|
Tick pio_latency);
|
2004-01-22 02:14:10 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Create the tm struct from seconds since 1970
|
|
|
|
*/
|
2004-01-26 19:26:34 +01:00
|
|
|
void set_time(time_t t);
|
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Process a read to one of the devices we are emulating.
|
|
|
|
* @param req Contains the address to read from.
|
|
|
|
* @param data A pointer to write the read data to.
|
|
|
|
* @return The fault condition of the access.
|
|
|
|
*/
|
2004-02-03 22:59:40 +01:00
|
|
|
virtual Fault read(MemReqPtr &req, uint8_t *data);
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a write to one of the devices we emulate.
|
|
|
|
* @param req Contains the address to write to.
|
|
|
|
* @param data The data to write.
|
|
|
|
* @return The fault condition of the access.
|
|
|
|
*/
|
2004-02-03 22:59:40 +01:00
|
|
|
virtual Fault write(MemReqPtr &req, const uint8_t *data);
|
2004-01-22 02:14:10 +01:00
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Post an PIC interrupt to the CPU via the CChip
|
|
|
|
* @param bitvector interrupt to post.
|
|
|
|
*/
|
2004-01-29 01:18:29 +01:00
|
|
|
void postPIC(uint8_t bitvector);
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a posted interrupt
|
|
|
|
* @param bitvector interrupt to clear
|
|
|
|
*/
|
2004-01-29 01:18:29 +01:00
|
|
|
void clearPIC(uint8_t bitvector);
|
|
|
|
|
2004-05-30 23:45:46 +02:00
|
|
|
/**
|
|
|
|
* Serialize this object to the given output stream.
|
|
|
|
* @param os The stream to serialize to.
|
|
|
|
*/
|
2004-01-22 02:14:10 +01:00
|
|
|
virtual void serialize(std::ostream &os);
|
2004-05-30 23:45:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reconstruct the state of this object from a checkpoint.
|
|
|
|
* @param cp The checkpoint use.
|
|
|
|
* @param section The section name of this object
|
|
|
|
*/
|
2004-01-22 02:14:10 +01:00
|
|
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
2004-06-10 19:30:58 +02:00
|
|
|
|
|
|
|
Tick cacheAccess(MemReqPtr &req);
|
2004-01-22 02:14:10 +01:00
|
|
|
};
|
|
|
|
|
2005-02-21 23:32:57 +01:00
|
|
|
#endif // __DEV_TSUNAMI_IO_HH__
|