2 * Copyright (c) 2004 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.
30 * Tsunami Fake I/O Space mapping including RTC/timer interrupts
33 #ifndef __DEV_TSUNAMI_IO_HH__
34 #define __DEV_TSUNAMI_IO_HH__
36 #include "dev/io_device.hh"
37 #include "base/range.hh"
38 #include "dev/tsunami.hh"
39 #include "sim/eventq.hh"
41 /** How often the RTC interrupts */
42 static const int RTC_RATE = 1024;
45 * Tsunami I/O device is a catch all for all the south bridge stuff we care
48 class TsunamiIO : public PioDevice
51 /** The base address of this device */
54 /** The size of mappad from the above address */
55 static const Addr size = 0xff;
60 * In Tsunami RTC only has two i/o ports one for data and one for
61 * address, so you write the address and then read/write the
62 * data. This store the address you are going to be reading from
70 * The ClockEvent is handles the PIT interrupts
72 class ClockEvent : public Event
75 /** how often the PIT fires */
77 /** The mode of the PIT */
79 /** The status of the PIT */
84 * Just set the mode to 0
89 * processs the timer event
91 virtual void process();
94 * Returns a description of this event
95 * @return the description
97 virtual const char *description();
100 * Schedule a timer interrupt to occur sometime in the future.
102 void Program(int count);
105 * Write the mode bits of the PIT.
106 * @param mode the new mode
108 void ChangeMode(uint8_t mode);
111 * The current PIT status.
112 * @return the status of the PIT
117 * Serialize this object to the given output stream.
118 * @param os The stream to serialize to.
120 virtual void serialize(std::ostream &os);
124 * Reconstruct the state of this object from a checkpoint.
125 * @param cp The checkpoint use.
126 * @param section The section name of this object
128 virtual void unserialize(Checkpoint *cp, const std::string §ion);
132 * Process RTC timer events and generate interrupts appropriately.
134 class RTCEvent : public Event
137 /** A pointer back to tsunami to create interrupt the processor. */
140 /** RTC Event initializes the RTC event by scheduling an event
141 * RTC_RATE times pre second. */
142 RTCEvent(Tsunami* t);
145 * Interrupth the processor and reschedule the event.
147 virtual void process();
150 * Return a description of this event.
151 * @return a description
153 virtual const char *description();
156 * Serialize this object to the given output stream.
157 * @param os The stream to serialize to.
159 virtual void serialize(std::ostream &os);
162 * Reconstruct the state of this object from a checkpoint.
163 * @param cp The checkpoint use.
164 * @param section The section name of this object
166 virtual void unserialize(Checkpoint *cp, const std::string §ion);
169 /** uip UpdateInProgess says that the rtc is updating, but we just fake it
170 * by alternating it on every read of the bit since we are going to
171 * override the loop_per_jiffy time that it is trying to use the UIP to
176 /** Mask of the PIC1 */
179 /** Mask of the PIC2 */
182 /** Mode of PIC1. Not used for anything */
185 /** Mode of PIC2. Not used for anything */
188 /** Raw PIC interrupt register before masking */
189 uint8_t picr; //Raw PIC interrput register
191 /** Is the pic interrupting right now or not. */
192 bool picInterrupting;
194 /** A pointer to the Tsunami device which be belong to */
198 * This timer is initilized, but after I wrote the code
199 * it doesn't seem to be used again, and best I can tell
200 * it too is not connected to any interrupt port
205 * This timer is used to control the speaker, which
206 * we normally could care less about, however it is
207 * also used to calculated the clockspeed and hense
208 * bogomips which is kinda important to the scheduler
209 * so we need to implemnt it although after boot I can't
210 * imagine we would be playing with the PC speaker much
214 /** This is the event used to interrupt the cpu like an RTC. */
217 /** The interval is set via two writes to the PIT.
218 * This variable contains a flag as to how many writes have happened, and
225 * Return the freqency of the RTC
226 * @return interrupt rate of the RTC
228 Tick frequency() const { return RTC_RATE; }
231 * Initialize all the data for devices supported by Tsunami I/O.
232 * @param name name of this device.
233 * @param t pointer back to the Tsunami object that we belong to.
234 * @param init_time Time (as in seconds since 1970) to set RTC to.
235 * @param a address we are mapped at.
236 * @param mmu pointer to the memory controller that sends us events.
238 TsunamiIO(const std::string &name, Tsunami *t, time_t init_time,
239 Addr a, MemoryController *mmu, HierParams *hier, Bus *bus,
243 * Create the tm struct from seconds since 1970
245 void set_time(time_t t);
248 * Process a read to one of the devices we are emulating.
249 * @param req Contains the address to read from.
250 * @param data A pointer to write the read data to.
251 * @return The fault condition of the access.
253 virtual Fault read(MemReqPtr &req, uint8_t *data);
256 * Process a write to one of the devices we emulate.
257 * @param req Contains the address to write to.
258 * @param data The data to write.
259 * @return The fault condition of the access.
261 virtual Fault write(MemReqPtr &req, const uint8_t *data);
264 * Post an PIC interrupt to the CPU via the CChip
265 * @param bitvector interrupt to post.
267 void postPIC(uint8_t bitvector);
270 * Clear a posted interrupt
271 * @param bitvector interrupt to clear
273 void clearPIC(uint8_t bitvector);
276 * Serialize this object to the given output stream.
277 * @param os The stream to serialize to.
279 virtual void serialize(std::ostream &os);
282 * Reconstruct the state of this object from a checkpoint.
283 * @param cp The checkpoint use.
284 * @param section The section name of this object
286 virtual void unserialize(Checkpoint *cp, const std::string §ion);
288 Tick cacheAccess(MemReqPtr &req);
291 #endif // __DEV_TSUNAMI_IO_HH__