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 "dev/io_device.hh"
41 #include "base/range.hh"
42 #include "dev/alpha/tsunami.hh"
43 #include "sim/eventq.hh"
46 * Tsunami I/O device is a catch all for all the south bridge stuff we care
49 class TsunamiIO : public BasicPioDevice
55 /** Real-Time Clock (MC146818) */
59 /** Event for RTC periodic interrupt */
60 struct RTCEvent : public Event
62 /** A pointer back to tsunami to create interrupt the processor. */
66 RTCEvent(Tsunami* t, Tick i);
68 /** Schedule the RTC periodic interrupt */
71 /** Event process to occur at interrupt*/
72 virtual void process();
74 /** Event description */
75 virtual const char *description();
80 const std::string &name() const { return _name; }
82 /** RTC periodic interrupt event */
85 /** Current RTC register address/index */
88 /** should the year be interpreted as BCD? */
91 /** Data for real-time clock function */
93 uint8_t clock_data[10];
109 /** RTC status register A */
112 /** RTC status register B */
116 RTC(const std::string &name, Tsunami* tsunami,
117 const std::vector<int> &t, bool bcd, Tick i);
119 /** RTC address port: write address of RTC RAM data to access */
120 void writeAddr(const uint8_t data);
122 /** RTC write data */
123 void writeData(const uint8_t data);
129 * Serialize this object to the given output stream.
130 * @param base The base name of the counter object.
131 * @param os The stream to serialize to.
133 void serialize(const std::string &base, std::ostream &os);
136 * Reconstruct the state of this object from a checkpoint.
137 * @param base The base name of the counter object.
138 * @param cp The checkpoint use.
139 * @param section The section name of this object
141 void unserialize(const std::string &base, Checkpoint *cp,
142 const std::string §ion);
145 /** Programmable Interval Timer (Intel 8254) */
148 /** Counter element for PIT */
151 /** Event for counter interrupt */
152 class CounterEvent : public Event
155 /** Pointer back to Counter */
160 CounterEvent(Counter*);
163 virtual void process();
165 /** Event description */
166 virtual const char *description();
168 friend class Counter;
173 const std::string &name() const { return _name; }
177 /** Current count value */
181 uint16_t latched_count;
183 /** Interrupt period */
186 /** Current mode of operation */
189 /** Output goes high when the counter reaches zero */
192 /** State of the count latch */
195 /** Set of values for read_byte and write_byte */
198 /** Determine which byte of a 16-bit count value to read/write */
199 uint8_t read_byte, write_byte;
202 Counter(const std::string &name);
204 /** Latch the current count (if one is not already latched) */
207 /** Set the read/write mode */
208 void setRW(int rw_val);
210 /** Set operational mode */
211 void setMode(int mode_val);
213 /** Set count encoding */
214 void setBCD(int bcd_val);
216 /** Read a count byte */
219 /** Write a count byte */
220 void write(const uint8_t data);
222 /** Is the output high? */
226 * Serialize this object to the given output stream.
227 * @param base The base name of the counter object.
228 * @param os The stream to serialize to.
230 void serialize(const std::string &base, std::ostream &os);
233 * Reconstruct the state of this object from a checkpoint.
234 * @param base The base name of the counter object.
235 * @param cp The checkpoint use.
236 * @param section The section name of this object
238 void unserialize(const std::string &base, Checkpoint *cp,
239 const std::string §ion);
244 const std::string &name() const { return _name; }
246 /** PIT has three seperate counters */
250 /** Public way to access individual counters (avoid array accesses) */
255 PITimer(const std::string &name);
257 /** Write control word */
258 void writeControl(const uint8_t data);
261 * Serialize this object to the given output stream.
262 * @param base The base name of the counter object.
263 * @param os The stream to serialize to.
265 void serialize(const std::string &base, std::ostream &os);
268 * Reconstruct the state of this object from a checkpoint.
269 * @param base The base name of the counter object.
270 * @param cp The checkpoint use.
271 * @param section The section name of this object
273 void unserialize(const std::string &base, Checkpoint *cp,
274 const std::string §ion);
277 /** Mask of the PIC1 */
280 /** Mask of the PIC2 */
283 /** Mode of PIC1. Not used for anything */
286 /** Mode of PIC2. Not used for anything */
289 /** Raw PIC interrupt register before masking */
290 uint8_t picr; //Raw PIC interrput register
292 /** Is the pic interrupting right now or not. */
293 bool picInterrupting;
295 /** A pointer to the Tsunami device which be belong to */
298 /** Intel 8253 Periodic Interval Timer */
303 /** The interval is set via two writes to the PIT.
304 * This variable contains a flag as to how many writes have happened, and
311 * Return the freqency of the RTC
312 * @return interrupt rate of the RTC
314 Tick frequency() const;
316 struct Params : public BasicPioDevice::Params
320 std::vector<int> init_time;
325 const Params *params() const { return (const Params*)_params; }
329 * Initialize all the data for devices supported by Tsunami I/O.
330 * @param p pointer to Params struct
332 TsunamiIO(Params *p);
334 virtual Tick read(PacketPtr pkt);
335 virtual Tick write(PacketPtr pkt);
338 * Post an PIC interrupt to the CPU via the CChip
339 * @param bitvector interrupt to post.
341 void postPIC(uint8_t bitvector);
344 * Clear a posted interrupt
345 * @param bitvector interrupt to clear
347 void clearPIC(uint8_t bitvector);
350 * Serialize this object to the given output stream.
351 * @param os The stream to serialize to.
353 virtual void serialize(std::ostream &os);
356 * Reconstruct the state of this object from a checkpoint.
357 * @param cp The checkpoint use.
358 * @param section The section name of this object
360 virtual void unserialize(Checkpoint *cp, const std::string §ion);
364 #endif // __DEV_TSUNAMI_IO_HH__