tsunami_io.hh revision 2665
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Ali Saidi 29 * Andrew Schultz 30 * Miguel Serrano 31 */ 32 33/** @file 34 * Tsunami I/O Space mapping including RTC/timer interrupts 35 */ 36 37#ifndef __DEV_TSUNAMI_IO_HH__ 38#define __DEV_TSUNAMI_IO_HH__ 39 40#include "dev/io_device.hh" 41#include "base/range.hh" 42#include "dev/tsunami.hh" 43#include "sim/eventq.hh" 44 45/** 46 * Tsunami I/O device is a catch all for all the south bridge stuff we care 47 * to implement. 48 */ 49class TsunamiIO : public BasicPioDevice 50{ 51 private: 52 struct tm tm; 53 54 protected: 55 /** Real-Time Clock (MC146818) */ 56 class RTC 57 { 58 private: 59 /** Event for RTC periodic interrupt */ 60 struct RTCEvent : public Event 61 { 62 /** A pointer back to tsunami to create interrupt the processor. */ 63 Tsunami* tsunami; 64 Tick interval; 65 66 RTCEvent(Tsunami* t, Tick i); 67 68 /** Schedule the RTC periodic interrupt */ 69 void scheduleIntr(); 70 71 /** Event process to occur at interrupt*/ 72 virtual void process(); 73 74 /** Event description */ 75 virtual const char *description(); 76 }; 77 78 private: 79 std::string _name; 80 const std::string &name() const { return _name; } 81 82 /** RTC periodic interrupt event */ 83 RTCEvent event; 84 85 /** Current RTC register address/index */ 86 int addr; 87 88 /** Data for real-time clock function */ 89 union { 90 uint8_t clock_data[10]; 91 92 struct { 93 uint8_t sec; 94 uint8_t sec_alrm; 95 uint8_t min; 96 uint8_t min_alrm; 97 uint8_t hour; 98 uint8_t hour_alrm; 99 uint8_t wday; 100 uint8_t mday; 101 uint8_t mon; 102 uint8_t year; 103 }; 104 }; 105 106 /** RTC status register A */ 107 uint8_t stat_regA; 108 109 /** RTC status register B */ 110 uint8_t stat_regB; 111 112 public: 113 RTC(const std::string &name, Tsunami* t, Tick i); 114 115 /** Set the initial RTC time/date */ 116 void set_time(time_t t); 117 118 /** RTC address port: write address of RTC RAM data to access */ 119 void writeAddr(const uint8_t data); 120 121 /** RTC write data */ 122 void writeData(const uint8_t data); 123 124 /** RTC read data */ 125 uint8_t readData(); 126 127 /** 128 * Serialize this object to the given output stream. 129 * @param os The stream to serialize to. 130 */ 131 void serialize(const std::string &base, std::ostream &os); 132 133 /** 134 * Reconstruct the state of this object from a checkpoint. 135 * @param cp The checkpoint use. 136 * @param section The section name of this object 137 */ 138 void unserialize(const std::string &base, Checkpoint *cp, 139 const std::string §ion); 140 }; 141 142 /** Programmable Interval Timer (Intel 8254) */ 143 class PITimer 144 { 145 /** Counter element for PIT */ 146 class Counter 147 { 148 /** Event for counter interrupt */ 149 class CounterEvent : public Event 150 { 151 private: 152 /** Pointer back to Counter */ 153 Counter* counter; 154 Tick interval; 155 156 public: 157 CounterEvent(Counter*); 158 159 /** Event process */ 160 virtual void process(); 161 162 /** Event description */ 163 virtual const char *description(); 164 165 friend class Counter; 166 }; 167 168 private: 169 std::string _name; 170 const std::string &name() const { return _name; } 171 172 CounterEvent event; 173 174 /** Current count value */ 175 uint16_t count; 176 177 /** Latched count */ 178 uint16_t latched_count; 179 180 /** Interrupt period */ 181 uint16_t period; 182 183 /** Current mode of operation */ 184 uint8_t mode; 185 186 /** Output goes high when the counter reaches zero */ 187 bool output_high; 188 189 /** State of the count latch */ 190 bool latch_on; 191 192 /** Set of values for read_byte and write_byte */ 193 enum {LSB, MSB}; 194 195 /** Determine which byte of a 16-bit count value to read/write */ 196 uint8_t read_byte, write_byte; 197 198 public: 199 Counter(const std::string &name); 200 201 /** Latch the current count (if one is not already latched) */ 202 void latchCount(); 203 204 /** Set the read/write mode */ 205 void setRW(int rw_val); 206 207 /** Set operational mode */ 208 void setMode(int mode_val); 209 210 /** Set count encoding */ 211 void setBCD(int bcd_val); 212 213 /** Read a count byte */ 214 uint8_t read(); 215 216 /** Write a count byte */ 217 void write(const uint8_t data); 218 219 /** Is the output high? */ 220 bool outputHigh(); 221 222 /** 223 * Serialize this object to the given output stream. 224 * @param os The stream to serialize to. 225 */ 226 void serialize(const std::string &base, std::ostream &os); 227 228 /** 229 * Reconstruct the state of this object from a checkpoint. 230 * @param cp The checkpoint use. 231 * @param section The section name of this object 232 */ 233 void unserialize(const std::string &base, Checkpoint *cp, 234 const std::string §ion); 235 }; 236 237 private: 238 std::string _name; 239 const std::string &name() const { return _name; } 240 241 /** PIT has three seperate counters */ 242 Counter *counter[3]; 243 244 public: 245 /** Public way to access individual counters (avoid array accesses) */ 246 Counter counter0; 247 Counter counter1; 248 Counter counter2; 249 250 PITimer(const std::string &name); 251 252 /** Write control word */ 253 void writeControl(const uint8_t data); 254 255 /** 256 * Serialize this object to the given output stream. 257 * @param os The stream to serialize to. 258 */ 259 void serialize(const std::string &base, std::ostream &os); 260 261 /** 262 * Reconstruct the state of this object from a checkpoint. 263 * @param cp The checkpoint use. 264 * @param section The section name of this object 265 */ 266 void unserialize(const std::string &base, Checkpoint *cp, 267 const std::string §ion); 268 }; 269 270 /** Mask of the PIC1 */ 271 uint8_t mask1; 272 273 /** Mask of the PIC2 */ 274 uint8_t mask2; 275 276 /** Mode of PIC1. Not used for anything */ 277 uint8_t mode1; 278 279 /** Mode of PIC2. Not used for anything */ 280 uint8_t mode2; 281 282 /** Raw PIC interrupt register before masking */ 283 uint8_t picr; //Raw PIC interrput register 284 285 /** Is the pic interrupting right now or not. */ 286 bool picInterrupting; 287 288 /** A pointer to the Tsunami device which be belong to */ 289 Tsunami *tsunami; 290 291 /** Intel 8253 Periodic Interval Timer */ 292 PITimer pitimer; 293 294 RTC rtc; 295 296 /** The interval is set via two writes to the PIT. 297 * This variable contains a flag as to how many writes have happened, and 298 * the time so far. 299 */ 300 uint16_t timerData; 301 302 public: 303 /** 304 * Return the freqency of the RTC 305 * @return interrupt rate of the RTC 306 */ 307 Tick frequency() const; 308 309 struct Params : public BasicPioDevice::Params 310 { 311 Tick frequency; 312 Tsunami *tsunami; 313 time_t init_time; 314 }; 315 protected: 316 const Params *params() const { return (const Params*)_params; } 317 318 public: 319 /** 320 * Initialize all the data for devices supported by Tsunami I/O. 321 * @param p pointer to Params struct 322 */ 323 TsunamiIO(Params *p); 324 325 virtual Tick read(Packet *pkt); 326 virtual Tick write(Packet *pkt); 327 328 /** 329 * Post an PIC interrupt to the CPU via the CChip 330 * @param bitvector interrupt to post. 331 */ 332 void postPIC(uint8_t bitvector); 333 334 /** 335 * Clear a posted interrupt 336 * @param bitvector interrupt to clear 337 */ 338 void clearPIC(uint8_t bitvector); 339 340 /** 341 * Serialize this object to the given output stream. 342 * @param os The stream to serialize to. 343 */ 344 virtual void serialize(std::ostream &os); 345 346 /** 347 * Reconstruct the state of this object from a checkpoint. 348 * @param cp The checkpoint use. 349 * @param section The section name of this object 350 */ 351 virtual void unserialize(Checkpoint *cp, const std::string §ion); 352 353}; 354 355#endif // __DEV_TSUNAMI_IO_HH__ 356