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 * Malta I/O Space mapping including RTC/timer interrupts
37 #ifndef __DEV_MALTA_IO_HH__
38 #define __DEV_MALTA_IO_HH__
40 #include "dev/io_device.hh"
41 #include "base/range.hh"
42 #include "dev/mips/malta.hh"
43 #include "sim/eventq.hh"
44 #include "params/MaltaIO.hh"
47 * Malta I/O device is a catch all for all the south bridge stuff we care
50 class MaltaIO : public BasicPioDevice
55 /** Post an Interrupt to the CPU */
56 void postIntr(uint8_t interrupt);
58 /** Clear an Interrupt to the CPU */
59 void clearIntr(uint8_t interrupt);
62 /** Real-Time Clock (MC146818) */
66 /** Event for RTC periodic interrupt */
67 struct RTCEvent : public Event
69 /** A pointer back to malta to create interrupt the processor. */
73 RTCEvent(Malta* t, Tick i);
75 /** Schedule the RTC periodic interrupt */
78 /** Event process to occur at interrupt*/
79 virtual void process();
81 /** Event description */
82 virtual const char *description() const;
87 const std::string &name() const { return _name; }
89 /** RTC periodic interrupt event */
92 /** Current RTC register address/index */
95 /** Data for real-time clock function */
97 uint8_t clock_data[10];
113 /** RTC status register A */
116 /** RTC status register B */
120 RTC(const std::string &name, Malta* t, Tick i);
122 /** Set the initial RTC time/date */
123 void set_time(time_t t);
125 /** RTC address port: write address of RTC RAM data to access */
126 void writeAddr(const uint8_t data);
128 /** RTC write data */
129 void writeData(const uint8_t data);
137 * Serialize this object to the given output stream.
138 * @param base The base name of the counter object.
139 * @param os The stream to serialize to.
141 void serialize(const std::string &base, std::ostream &os);
144 * Reconstruct the state of this object from a checkpoint.
145 * @param base The base name of the counter object.
146 * @param cp The checkpoint use.
147 * @param section The section name of this object
149 void unserialize(const std::string &base, Checkpoint *cp,
150 const std::string §ion);
153 /** Programmable Interval Timer (Intel 8254) */
156 /** Counter element for PIT */
159 /** Event for counter interrupt */
160 class CounterEvent : public Event
163 /** Pointer back to Counter */
168 CounterEvent(Counter*);
171 virtual void process();
173 /** Event description */
174 virtual const char *description() const;
176 friend class Counter;
181 const std::string &name() const { return _name; }
185 /** Current count value */
189 uint16_t latched_count;
191 /** Interrupt period */
194 /** Current mode of operation */
197 /** Output goes high when the counter reaches zero */
200 /** State of the count latch */
203 /** Set of values for read_byte and write_byte */
206 /** Determine which byte of a 16-bit count value to read/write */
207 uint8_t read_byte, write_byte;
210 Counter(const std::string &name);
212 /** Latch the current count (if one is not already latched) */
215 /** Set the read/write mode */
216 void setRW(int rw_val);
218 /** Set operational mode */
219 void setMode(int mode_val);
221 /** Set count encoding */
222 void setBCD(int bcd_val);
224 /** Read a count byte */
227 /** Write a count byte */
228 void write(const uint8_t data);
230 /** Is the output high? */
234 * Serialize this object to the given output stream.
235 * @param base The base name of the counter object.
236 * @param os The stream to serialize to.
238 void serialize(const std::string &base, std::ostream &os);
241 * Reconstruct the state of this object from a checkpoint.
242 * @param base The base name of the counter object.
243 * @param cp The checkpoint use.
244 * @param section The section name of this object
246 void unserialize(const std::string &base, Checkpoint *cp,
247 const std::string §ion);
252 const std::string &name() const { return _name; }
254 /** PIT has three seperate counters */
258 /** Public way to access individual counters (avoid array accesses) */
263 PITimer(const std::string &name);
265 /** Write control word */
266 void writeControl(const uint8_t data);
269 * Serialize this object to the given output stream.
270 * @param base The base name of the counter object.
271 * @param os The stream to serialize to.
273 void serialize(const std::string &base, std::ostream &os);
276 * Reconstruct the state of this object from a checkpoint.
277 * @param base The base name of the counter object.
278 * @param cp The checkpoint use.
279 * @param section The section name of this object
281 void unserialize(const std::string &base, Checkpoint *cp,
282 const std::string §ion);
285 /** Mask of the PIC1 */
288 /** Mask of the PIC2 */
291 /** Mode of PIC1. Not used for anything */
294 /** Mode of PIC2. Not used for anything */
297 /** Raw PIC interrupt register before masking */
298 uint8_t picr; //Raw PIC interrput register
300 /** Is the pic interrupting right now or not. */
301 bool picInterrupting;
303 /** A pointer to the Malta device which be belong to */
306 /** Intel 8253 Periodic Interval Timer */
311 /** The interval is set via two writes to the PIT.
312 * This variable contains a flag as to how many writes have happened, and
319 * Return the freqency of the RTC
320 * @return interrupt rate of the RTC
322 Tick frequency() const;
324 typedef MaltaIOParams Params;
329 return dynamic_cast<const Params *>(_params);
334 * Initialize all the data for devices supported by Malta I/O.
335 * @param p pointer to Params struct
339 virtual Tick read(PacketPtr pkt);
340 virtual Tick write(PacketPtr pkt);
345 * Serialize this object to the given output stream.
346 * @param os The stream to serialize to.
348 virtual void serialize(std::ostream &os);
351 * Reconstruct the state of this object from a checkpoint.
352 * @param cp The checkpoint use.
353 * @param section The section name of this object
355 virtual void unserialize(Checkpoint *cp, const std::string §ion);
359 #endif // __DEV_MALTA_IO_HH__