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 __TSUNAMI_DMA_HH__
34 #define __TSUNAMI_DMA_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;
59 /** In Tsunami RTC only has two i/o ports one for data and one for address,
60 * so you write the address and then read/write the data. This store the
61 * address you are going to be reading from on a read.
68 * The ClockEvent is handles the PIT interrupts
70 class ClockEvent : public Event
73 /** how often the PIT fires */
75 /** The mode of the PIT */
77 /** The status of the PIT */
82 * Just set the mode to 0
87 * processs the timer event
89 virtual void process();
92 * Returns a description of this event
93 * @return the description
95 virtual const char *description();
98 * Schedule a timer interrupt to occur sometime in the future.
100 void Program(int count);
103 * Write the mode bits of the PIT.
104 * @param mode the new mode
106 void ChangeMode(uint8_t mode);
109 * The current PIT status.
110 * @return the status of the PIT
115 * Serialize this object to the given output stream.
116 * @param os The stream to serialize to.
118 virtual void serialize(std::ostream &os);
122 * Reconstruct the state of this object from a checkpoint.
123 * @param cp The checkpoint use.
124 * @param section The section name of this object
126 virtual void unserialize(Checkpoint *cp, const std::string §ion);
130 * Process RTC timer events and generate interrupts appropriately.
132 class RTCEvent : public Event
135 /** A pointer back to tsunami to create interrupt the processor. */
138 /** RTC Event initializes the RTC event by scheduling an event
139 * RTC_RATE times pre second. */
140 RTCEvent(Tsunami* t);
143 * Interrupth the processor and reschedule the event.
145 virtual void process();
148 * Return a description of this event.
149 * @return a description
151 virtual const char *description();
154 * Serialize this object to the given output stream.
155 * @param os The stream to serialize to.
157 virtual void serialize(std::ostream &os);
161 * Reconstruct the state of this object from a checkpoint.
162 * @param cp The checkpoint use.
163 * @param section The section name of this object
165 virtual void unserialize(Checkpoint *cp, const std::string §ion);
168 /** uip UpdateInProgess says that the rtc is updating, but we just fake it
169 * by alternating it on every read of the bit since we are going to
170 * override the loop_per_jiffy time that it is trying to use the UIP to
175 /** Mask of the PIC1 */
178 /** Mask of the PIC2 */
181 /** Mode of PIC1. Not used for anything */
184 /** Mode of PIC2. Not used for anything */
187 /** Raw PIC interrupt register before masking */
188 uint8_t picr; //Raw PIC interrput register
190 /** Is the pic interrupting right now or not. */
191 bool picInterrupting;
193 /** A pointer to the Tsunami device which be belong to */
197 * This timer is initilized, but after I wrote the code
198 * it doesn't seem to be used again, and best I can tell
199 * it too is not connected to any interrupt port
204 * This timer is used to control the speaker, which
205 * we normally could care less about, however it is
206 * also used to calculated the clockspeed and hense
207 * bogomips which is kinda important to the scheduler
208 * so we need to implemnt it although after boot I can't
209 * imagine we would be playing with the PC speaker much
213 /** This is the event used to interrupt the cpu like an RTC. */
216 /** The interval is set via two writes to the PIT.
217 * 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; }
232 * Initialize all the data for devices supported by Tsunami I/O.
233 * @param name name of this device.
234 * @param t pointer back to the Tsunami object that we belong to.
235 * @param init_time Time (as in seconds since 1970) to set RTC to.
236 * @param a address we are mapped at.
237 * @param mmu pointer to the memory controller that sends us events.
239 TsunamiIO(const std::string &name, Tsunami *t, time_t init_time,
240 Addr a, MemoryController *mmu, HierParams *hier, Bus *bus,
244 * Create the tm struct from seconds since 1970
246 void set_time(time_t t);
249 * Process a read to one of the devices we are emulating.
250 * @param req Contains the address to read from.
251 * @param data A pointer to write the read data to.
252 * @return The fault condition of the access.
254 virtual Fault read(MemReqPtr &req, uint8_t *data);
257 * Process a write to one of the devices we emulate.
258 * @param req Contains the address to write to.
259 * @param data The data to write.
260 * @return The fault condition of the access.
262 virtual Fault write(MemReqPtr &req, const uint8_t *data);
265 * Post an PIC interrupt to the CPU via the CChip
266 * @param bitvector interrupt to post.
268 void postPIC(uint8_t bitvector);
271 * Clear a posted interrupt
272 * @param bitvector interrupt to clear
274 void clearPIC(uint8_t bitvector);
277 * Serialize this object to the given output stream.
278 * @param os The stream to serialize to.
280 virtual void serialize(std::ostream &os);
284 * Reconstruct the state of this object from a checkpoint.
285 * @param cp The checkpoint use.
286 * @param section The section name of this object
288 virtual void unserialize(Checkpoint *cp, const std::string §ion);
291 Tick cacheAccess(MemReqPtr &req);
294 #endif // __TSUNAMI_IO_HH__