tsunami_io.hh revision 4762
16313Sgblack@eecs.umich.edu/* 26313Sgblack@eecs.umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan 36313Sgblack@eecs.umich.edu * All rights reserved. 46313Sgblack@eecs.umich.edu * 56313Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 66313Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 76313Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 86313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 96313Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 106313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 116313Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 126313Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 136313Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 146313Sgblack@eecs.umich.edu * this software without specific prior written permission. 156313Sgblack@eecs.umich.edu * 166313Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176313Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186313Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196313Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206313Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216313Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226313Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236313Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246313Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256313Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276313Sgblack@eecs.umich.edu * 286313Sgblack@eecs.umich.edu * Authors: Ali Saidi 296313Sgblack@eecs.umich.edu * Andrew Schultz 306313Sgblack@eecs.umich.edu * Miguel Serrano 316313Sgblack@eecs.umich.edu */ 326313Sgblack@eecs.umich.edu 336313Sgblack@eecs.umich.edu/** @file 348229Snate@binkert.org * Tsunami I/O Space mapping including RTC/timer interrupts 356334Sgblack@eecs.umich.edu */ 366334Sgblack@eecs.umich.edu 376334Sgblack@eecs.umich.edu#ifndef __DEV_TSUNAMI_IO_HH__ 386334Sgblack@eecs.umich.edu#define __DEV_TSUNAMI_IO_HH__ 396313Sgblack@eecs.umich.edu 406334Sgblack@eecs.umich.edu#include "base/range.hh" 417878Sgblack@eecs.umich.edu#include "dev/alpha/tsunami.hh" 426313Sgblack@eecs.umich.edu#include "dev/io_device.hh" 436334Sgblack@eecs.umich.edu#include "params/TsunamiIO.hh" 446313Sgblack@eecs.umich.edu#include "sim/eventq.hh" 456313Sgblack@eecs.umich.edu 466334Sgblack@eecs.umich.edu/** 476313Sgblack@eecs.umich.edu * Tsunami I/O device is a catch all for all the south bridge stuff we care 486313Sgblack@eecs.umich.edu * to implement. 496313Sgblack@eecs.umich.edu */ 506313Sgblack@eecs.umich.educlass TsunamiIO : public BasicPioDevice 516313Sgblack@eecs.umich.edu{ 526334Sgblack@eecs.umich.edu private: 536334Sgblack@eecs.umich.edu struct tm tm; 546334Sgblack@eecs.umich.edu 556334Sgblack@eecs.umich.edu protected: 566313Sgblack@eecs.umich.edu /** Real-Time Clock (MC146818) */ 578181Sksewell@umich.edu class RTC 588181Sksewell@umich.edu { 598181Sksewell@umich.edu private: 608181Sksewell@umich.edu /** Event for RTC periodic interrupt */ 616334Sgblack@eecs.umich.edu struct RTCEvent : public Event 626334Sgblack@eecs.umich.edu { 636334Sgblack@eecs.umich.edu /** A pointer back to tsunami to create interrupt the processor. */ 646334Sgblack@eecs.umich.edu Tsunami* tsunami; 656334Sgblack@eecs.umich.edu Tick interval; 666334Sgblack@eecs.umich.edu 676334Sgblack@eecs.umich.edu RTCEvent(Tsunami* t, Tick i); 686334Sgblack@eecs.umich.edu 696334Sgblack@eecs.umich.edu /** Schedule the RTC periodic interrupt */ 706334Sgblack@eecs.umich.edu void scheduleIntr(); 716313Sgblack@eecs.umich.edu 728181Sksewell@umich.edu /** Event process to occur at interrupt*/ 736313Sgblack@eecs.umich.edu virtual void process(); 748181Sksewell@umich.edu 756334Sgblack@eecs.umich.edu /** Event description */ 768181Sksewell@umich.edu virtual const char *description(); 776334Sgblack@eecs.umich.edu }; 786334Sgblack@eecs.umich.edu 796334Sgblack@eecs.umich.edu private: 806334Sgblack@eecs.umich.edu std::string _name; 816334Sgblack@eecs.umich.edu const std::string &name() const { return _name; } 826334Sgblack@eecs.umich.edu 836334Sgblack@eecs.umich.edu /** RTC periodic interrupt event */ 846334Sgblack@eecs.umich.edu RTCEvent event; 856334Sgblack@eecs.umich.edu 866334Sgblack@eecs.umich.edu /** Current RTC register address/index */ 876334Sgblack@eecs.umich.edu int addr; 886334Sgblack@eecs.umich.edu 896334Sgblack@eecs.umich.edu /** Data for real-time clock function */ 906334Sgblack@eecs.umich.edu union { 916334Sgblack@eecs.umich.edu uint8_t clock_data[10]; 926334Sgblack@eecs.umich.edu 936334Sgblack@eecs.umich.edu struct { 946334Sgblack@eecs.umich.edu uint8_t sec; 956334Sgblack@eecs.umich.edu uint8_t sec_alrm; 966334Sgblack@eecs.umich.edu uint8_t min; 976334Sgblack@eecs.umich.edu uint8_t min_alrm; 986334Sgblack@eecs.umich.edu uint8_t hour; 996334Sgblack@eecs.umich.edu uint8_t hour_alrm; 1006334Sgblack@eecs.umich.edu uint8_t wday; 1016334Sgblack@eecs.umich.edu uint8_t mday; 1026334Sgblack@eecs.umich.edu uint8_t mon; 1036334Sgblack@eecs.umich.edu uint8_t year; 1046334Sgblack@eecs.umich.edu }; 1056334Sgblack@eecs.umich.edu }; 1066334Sgblack@eecs.umich.edu 1076334Sgblack@eecs.umich.edu /** RTC status register A */ 1086334Sgblack@eecs.umich.edu uint8_t stat_regA; 1096334Sgblack@eecs.umich.edu 1106334Sgblack@eecs.umich.edu /** RTC status register B */ 1116334Sgblack@eecs.umich.edu uint8_t stat_regB; 1126334Sgblack@eecs.umich.edu 1136334Sgblack@eecs.umich.edu public: 1146334Sgblack@eecs.umich.edu RTC(const std::string &name, Tsunami* tsunami, 1156334Sgblack@eecs.umich.edu const TsunamiIOParams *params); 1166334Sgblack@eecs.umich.edu 1176334Sgblack@eecs.umich.edu /** RTC address port: write address of RTC RAM data to access */ 1186334Sgblack@eecs.umich.edu void writeAddr(const uint8_t data); 1196334Sgblack@eecs.umich.edu 1206334Sgblack@eecs.umich.edu /** RTC write data */ 1216313Sgblack@eecs.umich.edu void writeData(const uint8_t data); 1226334Sgblack@eecs.umich.edu 1236334Sgblack@eecs.umich.edu /** RTC read data */ 1246334Sgblack@eecs.umich.edu uint8_t readData(); 1256334Sgblack@eecs.umich.edu 1266334Sgblack@eecs.umich.edu /** 1276313Sgblack@eecs.umich.edu * Serialize this object to the given output stream. 1286334Sgblack@eecs.umich.edu * @param base The base name of the counter object. 1296334Sgblack@eecs.umich.edu * @param os The stream to serialize to. 1306334Sgblack@eecs.umich.edu */ 1316313Sgblack@eecs.umich.edu void serialize(const std::string &base, std::ostream &os); 1326334Sgblack@eecs.umich.edu 1336334Sgblack@eecs.umich.edu /** 1346313Sgblack@eecs.umich.edu * Reconstruct the state of this object from a checkpoint. 1356334Sgblack@eecs.umich.edu * @param base The base name of the counter object. 1366334Sgblack@eecs.umich.edu * @param cp The checkpoint use. 1376334Sgblack@eecs.umich.edu * @param section The section name of this object 1386334Sgblack@eecs.umich.edu */ 1399180Sandreas.hansson@arm.com void unserialize(const std::string &base, Checkpoint *cp, 1406334Sgblack@eecs.umich.edu const std::string §ion); 1416334Sgblack@eecs.umich.edu }; 1426334Sgblack@eecs.umich.edu 1436334Sgblack@eecs.umich.edu /** Programmable Interval Timer (Intel 8254) */ 1446334Sgblack@eecs.umich.edu class PITimer 1456334Sgblack@eecs.umich.edu { 1469180Sandreas.hansson@arm.com /** Counter element for PIT */ 1476334Sgblack@eecs.umich.edu class Counter 1486334Sgblack@eecs.umich.edu { 1496334Sgblack@eecs.umich.edu /** Event for counter interrupt */ 1506806Sgblack@eecs.umich.edu class CounterEvent : public Event 1516334Sgblack@eecs.umich.edu { 1526334Sgblack@eecs.umich.edu private: 1536334Sgblack@eecs.umich.edu /** Pointer back to Counter */ 1546334Sgblack@eecs.umich.edu Counter* counter; 1556334Sgblack@eecs.umich.edu Tick interval; 1566334Sgblack@eecs.umich.edu 1576334Sgblack@eecs.umich.edu public: 1586313Sgblack@eecs.umich.edu CounterEvent(Counter*); 1596313Sgblack@eecs.umich.edu 1606313Sgblack@eecs.umich.edu /** Event process */ 1616313Sgblack@eecs.umich.edu virtual void process(); 1626313Sgblack@eecs.umich.edu 1636313Sgblack@eecs.umich.edu /** Event description */ 1646313Sgblack@eecs.umich.edu virtual const char *description(); 1656313Sgblack@eecs.umich.edu 1666313Sgblack@eecs.umich.edu friend class Counter; 1676313Sgblack@eecs.umich.edu }; 1686313Sgblack@eecs.umich.edu 1696313Sgblack@eecs.umich.edu private: 1706313Sgblack@eecs.umich.edu std::string _name; 1716678Sgblack@eecs.umich.edu const std::string &name() const { return _name; } 1726678Sgblack@eecs.umich.edu 1736678Sgblack@eecs.umich.edu CounterEvent event; 1746678Sgblack@eecs.umich.edu 1756678Sgblack@eecs.umich.edu /** Current count value */ 1766313Sgblack@eecs.umich.edu uint16_t count; 1776313Sgblack@eecs.umich.edu 1786313Sgblack@eecs.umich.edu /** Latched count */ 1796313Sgblack@eecs.umich.edu uint16_t latched_count; 180 181 /** Interrupt period */ 182 uint16_t period; 183 184 /** Current mode of operation */ 185 uint8_t mode; 186 187 /** Output goes high when the counter reaches zero */ 188 bool output_high; 189 190 /** State of the count latch */ 191 bool latch_on; 192 193 /** Set of values for read_byte and write_byte */ 194 enum {LSB, MSB}; 195 196 /** Determine which byte of a 16-bit count value to read/write */ 197 uint8_t read_byte, write_byte; 198 199 public: 200 Counter(const std::string &name); 201 202 /** Latch the current count (if one is not already latched) */ 203 void latchCount(); 204 205 /** Set the read/write mode */ 206 void setRW(int rw_val); 207 208 /** Set operational mode */ 209 void setMode(int mode_val); 210 211 /** Set count encoding */ 212 void setBCD(int bcd_val); 213 214 /** Read a count byte */ 215 uint8_t read(); 216 217 /** Write a count byte */ 218 void write(const uint8_t data); 219 220 /** Is the output high? */ 221 bool outputHigh(); 222 223 /** 224 * Serialize this object to the given output stream. 225 * @param base The base name of the counter object. 226 * @param os The stream to serialize to. 227 */ 228 void serialize(const std::string &base, std::ostream &os); 229 230 /** 231 * Reconstruct the state of this object from a checkpoint. 232 * @param base The base name of the counter object. 233 * @param cp The checkpoint use. 234 * @param section The section name of this object 235 */ 236 void unserialize(const std::string &base, Checkpoint *cp, 237 const std::string §ion); 238 }; 239 240 private: 241 std::string _name; 242 const std::string &name() const { return _name; } 243 244 /** PIT has three seperate counters */ 245 Counter *counter[3]; 246 247 public: 248 /** Public way to access individual counters (avoid array accesses) */ 249 Counter counter0; 250 Counter counter1; 251 Counter counter2; 252 253 PITimer(const std::string &name); 254 255 /** Write control word */ 256 void writeControl(const uint8_t data); 257 258 /** 259 * Serialize this object to the given output stream. 260 * @param base The base name of the counter object. 261 * @param os The stream to serialize to. 262 */ 263 void serialize(const std::string &base, std::ostream &os); 264 265 /** 266 * Reconstruct the state of this object from a checkpoint. 267 * @param base The base name of the counter object. 268 * @param cp The checkpoint use. 269 * @param section The section name of this object 270 */ 271 void unserialize(const std::string &base, Checkpoint *cp, 272 const std::string §ion); 273 }; 274 275 /** Mask of the PIC1 */ 276 uint8_t mask1; 277 278 /** Mask of the PIC2 */ 279 uint8_t mask2; 280 281 /** Mode of PIC1. Not used for anything */ 282 uint8_t mode1; 283 284 /** Mode of PIC2. Not used for anything */ 285 uint8_t mode2; 286 287 /** Raw PIC interrupt register before masking */ 288 uint8_t picr; //Raw PIC interrput register 289 290 /** Is the pic interrupting right now or not. */ 291 bool picInterrupting; 292 293 /** A pointer to the Tsunami device which be belong to */ 294 Tsunami *tsunami; 295 296 /** Intel 8253 Periodic Interval Timer */ 297 PITimer pitimer; 298 299 RTC rtc; 300 301 /** The interval is set via two writes to the PIT. 302 * This variable contains a flag as to how many writes have happened, and 303 * the time so far. 304 */ 305 uint16_t timerData; 306 307 public: 308 /** 309 * Return the freqency of the RTC 310 * @return interrupt rate of the RTC 311 */ 312 Tick frequency() const; 313 314 public: 315 typedef TsunamiIOParams Params; 316 /** 317 * Initialize all the data for devices supported by Tsunami I/O. 318 * @param p pointer to Params struct 319 */ 320 TsunamiIO(const Params *p); 321 322 const Params * 323 params() const 324 { 325 return dynamic_cast<const Params *>(_params); 326 } 327 328 virtual Tick read(PacketPtr pkt); 329 virtual Tick write(PacketPtr pkt); 330 331 /** 332 * Post an PIC interrupt to the CPU via the CChip 333 * @param bitvector interrupt to post. 334 */ 335 void postPIC(uint8_t bitvector); 336 337 /** 338 * Clear a posted interrupt 339 * @param bitvector interrupt to clear 340 */ 341 void clearPIC(uint8_t bitvector); 342 343 /** 344 * Serialize this object to the given output stream. 345 * @param os The stream to serialize to. 346 */ 347 virtual void serialize(std::ostream &os); 348 349 /** 350 * Reconstruct the state of this object from a checkpoint. 351 * @param cp The checkpoint use. 352 * @param section The section name of this object 353 */ 354 virtual void unserialize(Checkpoint *cp, const std::string §ion); 355 356}; 357 358#endif // __DEV_TSUNAMI_IO_HH__ 359