trace: reimplement the DTRACE function so it doesn't use a vector
[gem5.git] / src / dev / uart8250.hh
1 /*
2 * Copyright (c) 2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 */
30
31 /** @file
32 * Defines a 8250 UART
33 */
34
35 #ifndef __DEV_UART8250_HH__
36 #define __DEV_UART8250_HH__
37
38 #include "base/range.hh"
39 #include "dev/io_device.hh"
40 #include "dev/uart.hh"
41 #include "params/Uart8250.hh"
42
43 /* UART8250 Interrupt ID Register
44 * bit 0 Interrupt Pending 0 = true, 1 = false
45 * bit 2:1 ID of highest priority interrupt
46 * bit 7:3 zeroes
47 */
48 const uint8_t IIR_NOPEND = 0x1;
49
50 // Interrupt IDs
51 const uint8_t IIR_MODEM = 0x00; /* Modem Status (lowest priority) */
52 const uint8_t IIR_TXID = 0x02; /* Tx Data */
53 const uint8_t IIR_RXID = 0x04; /* Rx Data */
54 const uint8_t IIR_LINE = 0x06; /* Rx Line Status (highest priority)*/
55
56 const uint8_t UART_IER_RDI = 0x01;
57 const uint8_t UART_IER_THRI = 0x02;
58 const uint8_t UART_IER_RLSI = 0x04;
59
60
61 const uint8_t UART_LSR_TEMT = 0x40;
62 const uint8_t UART_LSR_THRE = 0x20;
63 const uint8_t UART_LSR_DR = 0x01;
64
65 const uint8_t UART_MCR_LOOP = 0x10;
66
67
68 class Terminal;
69 class Platform;
70
71 class Uart8250 : public Uart
72 {
73 protected:
74 uint8_t IER, DLAB, LCR, MCR;
75 Tick lastTxInt;
76
77 class IntrEvent : public Event
78 {
79 protected:
80 Uart8250 *uart;
81 int intrBit;
82 public:
83 IntrEvent(Uart8250 *u, int bit);
84 virtual void process();
85 virtual const char *description() const;
86 void scheduleIntr();
87 };
88
89 IntrEvent txIntrEvent;
90 IntrEvent rxIntrEvent;
91
92 public:
93 typedef Uart8250Params Params;
94 const Params *
95 params() const
96 {
97 return dynamic_cast<const Params *>(_params);
98 }
99 Uart8250(const Params *p);
100
101 virtual Tick read(PacketPtr pkt);
102 virtual Tick write(PacketPtr pkt);
103 virtual void addressRanges(AddrRangeList &range_list);
104
105 /**
106 * Inform the uart that there is data available.
107 */
108 virtual void dataAvailable();
109
110
111 /**
112 * Return if we have an interrupt pending
113 * @return interrupt status
114 */
115 virtual bool intStatus() { return status ? true : false; }
116
117 virtual void serialize(std::ostream &os);
118 virtual void unserialize(Checkpoint *cp, const std::string &section);
119
120 };
121
122 #endif // __TSUNAMI_UART_HH__