2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
34 * Tsunami I/O Space mapping including RTC/timer interrupts
37 #ifndef __DEV_TSUNAMI_IO_HH__
38 #define __DEV_TSUNAMI_IO_HH__
40 #include "base/range.hh"
41 #include "dev/alpha/tsunami.hh"
42 #include "dev/io_device.hh"
43 #include "params/TsunamiIO.hh"
44 #include "sim/eventq.hh"
47 * Tsunami I/O device is a catch all for all the south bridge stuff we care
50 class TsunamiIO : public BasicPioDevice
56 /** Real-Time Clock (MC146818) */
60 /** Event for RTC periodic interrupt */
61 struct RTCEvent : public Event
63 /** A pointer back to tsunami to create interrupt the processor. */
67 RTCEvent(Tsunami* t, Tick i);
69 /** Schedule the RTC periodic interrupt */
72 /** Event process to occur at interrupt*/
73 virtual void process();
75 /** Event description */
76 virtual const char *description();
81 const std::string &name() const { return _name; }
83 /** RTC periodic interrupt event */
86 /** Current RTC register address/index */
89 /** Data for real-time clock function */
91 uint8_t clock_data[10];
107 /** RTC status register A */
110 /** RTC status register B */
114 RTC(const std::string &name, Tsunami* tsunami,
115 const TsunamiIOParams *params);
117 /** RTC address port: write address of RTC RAM data to access */
118 void writeAddr(const uint8_t data);
120 /** RTC write data */
121 void writeData(const uint8_t data);
127 * Serialize this object to the given output stream.
128 * @param base The base name of the counter object.
129 * @param os The stream to serialize to.
131 void serialize(const std::string &base, std::ostream &os);
134 * Reconstruct the state of this object from a checkpoint.
135 * @param base The base name of the counter object.
136 * @param cp The checkpoint use.
137 * @param section The section name of this object
139 void unserialize(const std::string &base, Checkpoint *cp,
140 const std::string §ion);
143 /** Programmable Interval Timer (Intel 8254) */
146 /** Counter element for PIT */
149 /** Event for counter interrupt */
150 class CounterEvent : public Event
153 /** Pointer back to Counter */
158 CounterEvent(Counter*);
161 virtual void process();
163 /** Event description */
164 virtual const char *description();
166 friend class Counter;
171 const std::string &name() const { return _name; }
175 /** Current count value */
179 uint16_t latched_count;
181 /** Interrupt period */
184 /** Current mode of operation */
187 /** Output goes high when the counter reaches zero */
190 /** State of the count latch */
193 /** Set of values for read_byte and write_byte */
196 /** Determine which byte of a 16-bit count value to read/write */
197 uint8_t read_byte, write_byte;
200 Counter(const std::string &name);
202 /** Latch the current count (if one is not already latched) */
205 /** Set the read/write mode */
206 void setRW(int rw_val);
208 /** Set operational mode */
209 void setMode(int mode_val);
211 /** Set count encoding */
212 void setBCD(int bcd_val);
214 /** Read a count byte */
217 /** Write a count byte */
218 void write(const uint8_t data);
220 /** Is the output high? */
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.
228 void serialize(const std::string &base, std::ostream &os);
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
236 void unserialize(const std::string &base, Checkpoint *cp,
237 const std::string §ion);
242 const std::string &name() const { return _name; }
244 /** PIT has three seperate counters */
248 /** Public way to access individual counters (avoid array accesses) */
253 PITimer(const std::string &name);
255 /** Write control word */
256 void writeControl(const uint8_t data);
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.
263 void serialize(const std::string &base, std::ostream &os);
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
271 void unserialize(const std::string &base, Checkpoint *cp,
272 const std::string §ion);
275 /** Mask of the PIC1 */
278 /** Mask of the PIC2 */
281 /** Mode of PIC1. Not used for anything */
284 /** Mode of PIC2. Not used for anything */
287 /** Raw PIC interrupt register before masking */
288 uint8_t picr; //Raw PIC interrput register
290 /** Is the pic interrupting right now or not. */
291 bool picInterrupting;
293 /** A pointer to the Tsunami device which be belong to */
296 /** Intel 8253 Periodic Interval Timer */
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
309 * Return the freqency of the RTC
310 * @return interrupt rate of the RTC
312 Tick frequency() const;
315 typedef TsunamiIOParams Params;
317 * Initialize all the data for devices supported by Tsunami I/O.
318 * @param p pointer to Params struct
320 TsunamiIO(const Params *p);
325 return dynamic_cast<const Params *>(_params);
328 virtual Tick read(PacketPtr pkt);
329 virtual Tick write(PacketPtr pkt);
332 * Post an PIC interrupt to the CPU via the CChip
333 * @param bitvector interrupt to post.
335 void postPIC(uint8_t bitvector);
338 * Clear a posted interrupt
339 * @param bitvector interrupt to clear
341 void clearPIC(uint8_t bitvector);
344 * Serialize this object to the given output stream.
345 * @param os The stream to serialize to.
347 virtual void serialize(std::ostream &os);
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
354 virtual void unserialize(Checkpoint *cp, const std::string §ion);
358 #endif // __DEV_TSUNAMI_IO_HH__