tsunami_io.hh revision 3932
1768SN/A/* 21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 3768SN/A * All rights reserved. 4768SN/A * 5768SN/A * Redistribution and use in source and binary forms, with or without 6768SN/A * modification, are permitted provided that the following conditions are 7768SN/A * met: redistributions of source code must retain the above copyright 8768SN/A * notice, this list of conditions and the following disclaimer; 9768SN/A * redistributions in binary form must reproduce the above copyright 10768SN/A * notice, this list of conditions and the following disclaimer in the 11768SN/A * documentation and/or other materials provided with the distribution; 12768SN/A * neither the name of the copyright holders nor the names of its 13768SN/A * contributors may be used to endorse or promote products derived from 14768SN/A * this software without specific prior written permission. 15768SN/A * 16768SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17768SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18768SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19768SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20768SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21768SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22768SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23768SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24768SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25768SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26768SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Ali Saidi 292665SN/A * Andrew Schultz 302665SN/A * Miguel Serrano 31768SN/A */ 32768SN/A 331722SN/A/** @file 341722SN/A * Tsunami I/O Space mapping including RTC/timer interrupts 35768SN/A */ 36768SN/A 371401SN/A#ifndef __DEV_TSUNAMI_IO_HH__ 381401SN/A#define __DEV_TSUNAMI_IO_HH__ 39768SN/A 40909SN/A#include "dev/io_device.hh" 41909SN/A#include "base/range.hh" 423540Sgblack@eecs.umich.edu#include "dev/alpha/tsunami.hh" 43932SN/A#include "sim/eventq.hh" 44768SN/A 451722SN/A/** 46885SN/A * Tsunami I/O device is a catch all for all the south bridge stuff we care 47885SN/A * to implement. 48768SN/A */ 492542SN/Aclass TsunamiIO : public BasicPioDevice 50768SN/A{ 51809SN/A private: 52773SN/A struct tm tm; 53773SN/A 54768SN/A protected: 551854SN/A /** Real-Time Clock (MC146818) */ 561854SN/A class RTC 571854SN/A { 581854SN/A private: 591854SN/A /** Event for RTC periodic interrupt */ 601854SN/A struct RTCEvent : public Event 611854SN/A { 621854SN/A /** A pointer back to tsunami to create interrupt the processor. */ 631854SN/A Tsunami* tsunami; 641854SN/A Tick interval; 65768SN/A 661854SN/A RTCEvent(Tsunami* t, Tick i); 671817SN/A 681854SN/A /** Schedule the RTC periodic interrupt */ 691854SN/A void scheduleIntr(); 701817SN/A 711854SN/A /** Event process to occur at interrupt*/ 721854SN/A virtual void process(); 731817SN/A 741854SN/A /** Event description */ 751854SN/A virtual const char *description(); 761854SN/A }; 771817SN/A 781817SN/A private: 791854SN/A std::string _name; 801854SN/A const std::string &name() const { return _name; } 811854SN/A 821817SN/A /** RTC periodic interrupt event */ 831817SN/A RTCEvent event; 841817SN/A 851817SN/A /** Current RTC register address/index */ 861817SN/A int addr; 871817SN/A 883932Sbinkertn@umich.edu /** should the year be interpreted as BCD? */ 893932Sbinkertn@umich.edu bool year_is_bcd; 903932Sbinkertn@umich.edu 911817SN/A /** Data for real-time clock function */ 921817SN/A union { 931817SN/A uint8_t clock_data[10]; 941817SN/A 951817SN/A struct { 961817SN/A uint8_t sec; 971817SN/A uint8_t sec_alrm; 981817SN/A uint8_t min; 991817SN/A uint8_t min_alrm; 1001817SN/A uint8_t hour; 1011817SN/A uint8_t hour_alrm; 1021817SN/A uint8_t wday; 1031817SN/A uint8_t mday; 1041817SN/A uint8_t mon; 1051817SN/A uint8_t year; 1061817SN/A }; 1071817SN/A }; 1081817SN/A 1091817SN/A /** RTC status register A */ 1101817SN/A uint8_t stat_regA; 1111817SN/A 1121817SN/A /** RTC status register B */ 1131817SN/A uint8_t stat_regB; 114771SN/A 115803SN/A public: 1163932Sbinkertn@umich.edu RTC(const std::string &name, Tsunami* tsunami, 1173932Sbinkertn@umich.edu const std::vector<int> &t, bool bcd, Tick i); 1181817SN/A 1191817SN/A /** RTC address port: write address of RTC RAM data to access */ 1202539SN/A void writeAddr(const uint8_t data); 1211817SN/A 1221817SN/A /** RTC write data */ 1232539SN/A void writeData(const uint8_t data); 1241817SN/A 1251817SN/A /** RTC read data */ 1262648SN/A uint8_t readData(); 127771SN/A 1283932Sbinkertn@umich.edu /** RTC get the date */ 1293932Sbinkertn@umich.edu std::string getDateString(); 1303932Sbinkertn@umich.edu 131885SN/A /** 1321817SN/A * Serialize this object to the given output stream. 1332982SN/A * @param base The base name of the counter object. 1341817SN/A * @param os The stream to serialize to. 1351817SN/A */ 1361854SN/A void serialize(const std::string &base, std::ostream &os); 137918SN/A 138918SN/A /** 139918SN/A * Reconstruct the state of this object from a checkpoint. 1402982SN/A * @param base The base name of the counter object. 141918SN/A * @param cp The checkpoint use. 142918SN/A * @param section The section name of this object 143918SN/A */ 1441854SN/A void unserialize(const std::string &base, Checkpoint *cp, 1451854SN/A const std::string §ion); 1461817SN/A }; 147771SN/A 1481817SN/A /** Programmable Interval Timer (Intel 8254) */ 1491854SN/A class PITimer 150772SN/A { 1511817SN/A /** Counter element for PIT */ 1521854SN/A class Counter 1531817SN/A { 1541817SN/A /** Event for counter interrupt */ 1551817SN/A class CounterEvent : public Event 1561817SN/A { 1571817SN/A private: 1581817SN/A /** Pointer back to Counter */ 1591817SN/A Counter* counter; 1601817SN/A Tick interval; 1611817SN/A 1621817SN/A public: 1631817SN/A CounterEvent(Counter*); 1641817SN/A 1651817SN/A /** Event process */ 1661817SN/A virtual void process(); 1671817SN/A 1681817SN/A /** Event description */ 1691817SN/A virtual const char *description(); 1701817SN/A 1711817SN/A friend class Counter; 1721817SN/A }; 1731817SN/A 1741817SN/A private: 1751854SN/A std::string _name; 1761854SN/A const std::string &name() const { return _name; } 1771854SN/A 1781817SN/A CounterEvent event; 1791817SN/A 1801817SN/A /** Current count value */ 1811817SN/A uint16_t count; 1821817SN/A 1831817SN/A /** Latched count */ 1841817SN/A uint16_t latched_count; 1851817SN/A 1861817SN/A /** Interrupt period */ 1871817SN/A uint16_t period; 1881817SN/A 1891817SN/A /** Current mode of operation */ 1901817SN/A uint8_t mode; 1911817SN/A 1921817SN/A /** Output goes high when the counter reaches zero */ 1931817SN/A bool output_high; 1941817SN/A 1951817SN/A /** State of the count latch */ 1961817SN/A bool latch_on; 1971817SN/A 1981817SN/A /** Set of values for read_byte and write_byte */ 1991817SN/A enum {LSB, MSB}; 2001817SN/A 2011817SN/A /** Determine which byte of a 16-bit count value to read/write */ 2021817SN/A uint8_t read_byte, write_byte; 2031817SN/A 2041817SN/A public: 2051854SN/A Counter(const std::string &name); 2061817SN/A 2071817SN/A /** Latch the current count (if one is not already latched) */ 2081817SN/A void latchCount(); 2091817SN/A 2101817SN/A /** Set the read/write mode */ 2111817SN/A void setRW(int rw_val); 2121817SN/A 2131817SN/A /** Set operational mode */ 2141817SN/A void setMode(int mode_val); 2151817SN/A 2161817SN/A /** Set count encoding */ 2171817SN/A void setBCD(int bcd_val); 2181817SN/A 2191817SN/A /** Read a count byte */ 2202648SN/A uint8_t read(); 2211817SN/A 2221817SN/A /** Write a count byte */ 2232539SN/A void write(const uint8_t data); 2241817SN/A 2251817SN/A /** Is the output high? */ 2261817SN/A bool outputHigh(); 2271817SN/A 2281817SN/A /** 2291817SN/A * Serialize this object to the given output stream. 2302982SN/A * @param base The base name of the counter object. 2312982SN/A * @param os The stream to serialize to. 2321817SN/A */ 2331854SN/A void serialize(const std::string &base, std::ostream &os); 2341817SN/A 2351817SN/A /** 2361817SN/A * Reconstruct the state of this object from a checkpoint. 2372982SN/A * @param base The base name of the counter object. 2381817SN/A * @param cp The checkpoint use. 2391817SN/A * @param section The section name of this object 2401817SN/A */ 2411854SN/A void unserialize(const std::string &base, Checkpoint *cp, 2421854SN/A const std::string §ion); 2431817SN/A }; 2441817SN/A 2451817SN/A private: 2461854SN/A std::string _name; 2471854SN/A const std::string &name() const { return _name; } 2481854SN/A 2491817SN/A /** PIT has three seperate counters */ 2501854SN/A Counter *counter[3]; 2511634SN/A 252772SN/A public: 2531817SN/A /** Public way to access individual counters (avoid array accesses) */ 2541854SN/A Counter counter0; 2551854SN/A Counter counter1; 2561854SN/A Counter counter2; 257772SN/A 2581854SN/A PITimer(const std::string &name); 259885SN/A 2601817SN/A /** Write control word */ 2612539SN/A void writeControl(const uint8_t data); 262909SN/A 2631401SN/A /** 2641401SN/A * Serialize this object to the given output stream. 2652982SN/A * @param base The base name of the counter object. 2661401SN/A * @param os The stream to serialize to. 2671401SN/A */ 2681854SN/A void serialize(const std::string &base, std::ostream &os); 269918SN/A 2701401SN/A /** 2711401SN/A * Reconstruct the state of this object from a checkpoint. 2722982SN/A * @param base The base name of the counter object. 2731401SN/A * @param cp The checkpoint use. 2741401SN/A * @param section The section name of this object 2751401SN/A */ 2761854SN/A void unserialize(const std::string &base, Checkpoint *cp, 2771854SN/A const std::string §ion); 2781401SN/A }; 279771SN/A 280885SN/A /** Mask of the PIC1 */ 281803SN/A uint8_t mask1; 282885SN/A 283885SN/A /** Mask of the PIC2 */ 284803SN/A uint8_t mask2; 285885SN/A 286885SN/A /** Mode of PIC1. Not used for anything */ 287803SN/A uint8_t mode1; 288885SN/A 289885SN/A /** Mode of PIC2. Not used for anything */ 290803SN/A uint8_t mode2; 291769SN/A 292885SN/A /** Raw PIC interrupt register before masking */ 293885SN/A uint8_t picr; //Raw PIC interrput register 294885SN/A 295885SN/A /** Is the pic interrupting right now or not. */ 296777SN/A bool picInterrupting; 297777SN/A 298885SN/A /** A pointer to the Tsunami device which be belong to */ 299775SN/A Tsunami *tsunami; 300775SN/A 3011817SN/A /** Intel 8253 Periodic Interval Timer */ 3021817SN/A PITimer pitimer; 303773SN/A 3041817SN/A RTC rtc; 305773SN/A 306885SN/A /** The interval is set via two writes to the PIT. 307885SN/A * This variable contains a flag as to how many writes have happened, and 308885SN/A * the time so far. 309885SN/A */ 3101817SN/A uint16_t timerData; 311771SN/A 312768SN/A public: 313891SN/A /** 314891SN/A * Return the freqency of the RTC 315891SN/A * @return interrupt rate of the RTC 316891SN/A */ 3171634SN/A Tick frequency() const; 318775SN/A 3192539SN/A struct Params : public BasicPioDevice::Params 3202539SN/A { 3212539SN/A Tick frequency; 3222539SN/A Tsunami *tsunami; 3233932Sbinkertn@umich.edu std::vector<int> init_time; 3243932Sbinkertn@umich.edu bool year_is_bcd; 3252539SN/A }; 3263932Sbinkertn@umich.edu 3272539SN/A protected: 3282539SN/A const Params *params() const { return (const Params*)_params; } 3292539SN/A 3302539SN/A public: 331885SN/A /** 332885SN/A * Initialize all the data for devices supported by Tsunami I/O. 3332539SN/A * @param p pointer to Params struct 334885SN/A */ 3352539SN/A TsunamiIO(Params *p); 336768SN/A 3373349SN/A virtual Tick read(PacketPtr pkt); 3383349SN/A virtual Tick write(PacketPtr pkt); 339768SN/A 340885SN/A /** 341885SN/A * Post an PIC interrupt to the CPU via the CChip 342885SN/A * @param bitvector interrupt to post. 343885SN/A */ 344777SN/A void postPIC(uint8_t bitvector); 345885SN/A 346885SN/A /** 347885SN/A * Clear a posted interrupt 348885SN/A * @param bitvector interrupt to clear 349885SN/A */ 350777SN/A void clearPIC(uint8_t bitvector); 351777SN/A 352885SN/A /** 353885SN/A * Serialize this object to the given output stream. 354885SN/A * @param os The stream to serialize to. 355885SN/A */ 356768SN/A virtual void serialize(std::ostream &os); 357885SN/A 358885SN/A /** 359885SN/A * Reconstruct the state of this object from a checkpoint. 360885SN/A * @param cp The checkpoint use. 361885SN/A * @param section The section name of this object 362885SN/A */ 363768SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 364909SN/A 365768SN/A}; 366768SN/A 3671401SN/A#endif // __DEV_TSUNAMI_IO_HH__ 368