gem5 v24.0.0.0
Loading...
Searching...
No Matches
uart8250.hh
Go to the documentation of this file.
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
33#ifndef __DEV_UART8250_HH__
34#define __DEV_UART8250_HH__
35
36#include "base/bitunion.hh"
37#include "base/logging.hh"
38#include "dev/io_device.hh"
39#include "dev/reg_bank.hh"
40#include "dev/serial/uart.hh"
41#include "params/Uart8250.hh"
42
43namespace gem5
44{
45
46const uint8_t UART_MCR_LOOP = 0x10;
47
48class Terminal;
49class Platform;
50
51class Uart8250 : public Uart
52{
53 protected:
55 Bitfield<0> rdi; // Receive data available interrupt.
56 Bitfield<1> thri; // Transmit holding register interrupt.
57 Bitfield<2> rlsi; // Receive line status interrupt.
58 Bitfield<3> msi; // Modem status interrupt.
60
61 BitUnion8(Iir)
62 Bitfield<0> pending; // 0 = pending, 1 = not pending.
63 Bitfield<2, 1> id; // ID of highest priority interrupt.
64 Bitfield<7, 3> zeroes;
66
67 BitUnion8(Lcr)
68 Bitfield<1, 0> wordSize;
69 Bitfield<2> stopBits;
70 Bitfield<5, 3> parity;
71 Bitfield<6> breakCont;
72 Bitfield<7> dlab;
74
75 BitUnion8(Lsr)
76 Bitfield<0> rdr; // Received data ready?
77 Bitfield<1> overrunError;
78 Bitfield<2> parityError;
79 Bitfield<3> framingError;
80 Bitfield<4> breakCond;
81 Bitfield<5> tbe; // Transmit buffer empty.
82 Bitfield<6> txEmpty; // Transmitter empty.
83 Bitfield<7> unused;
85
86 enum class InterruptIds
87 {
88 Modem = 0, // Modem Status (lowest priority).
89 Tx = 1, // Tx Data.
90 Rx = 2, // Rx Data.
91 Line = 3, // Rx Line Status (highest priority).
92 };
93
95 {
96 public:
97 Registers(Uart8250 *uart, const std::string &new_name);
98
99 class PairedRegister : public RegisterBase
100 {
101 protected:
102 RegisterBase &_reg1, &_reg2;
103
104 public:
105 PairedRegister(RegisterBase &reg1, RegisterBase &reg2) :
106 RegisterBase(reg1.name() + "/" + reg2.name(), reg1.size()),
107 _reg1(reg1), _reg2(reg2)
108 {
109 panic_if(reg1.size() != reg2.size(),
110 "Mismatched paired register sizes %d, %d",
111 reg1.size(), reg2.size());
112 }
113
114 void serialize(std::ostream &os) const override {}
115 bool unserialize(const std::string &s) override { return true; }
116
117 void
118 reset() override
119 {
120 _reg1.reset();
121 _reg2.reset();
122 }
123 };
124
126 {
127 private:
128 RegisterBase *selected = nullptr;
129
130 public:
131 BankedRegister(RegisterBase &reg1, RegisterBase &reg2) :
132 PairedRegister(reg1, reg2), selected(&reg1)
133 {}
134
135 void select(bool second) { selected = second ? &_reg2 : &_reg1; }
136
137 const std::string &
138 name() const override
139 {
140 return selected->name();
141 }
142
143 void read(void *buf) override { selected->read(buf); }
144 void
145 read(void *buf, off_t offset, size_t bytes) override
146 {
147 selected->read(buf, offset, bytes);
148 }
149 void write(const void *buf) override { selected->write(buf); }
150 void
151 write(const void *buf, off_t offset, size_t bytes) override
152 {
153 selected->write(buf, offset, bytes);
154 }
155 };
156
158 {
159 public:
161
162 void read(void *buf) override { _reg1.read(buf); }
163 void
164 read(void *buf, off_t offset, size_t bytes) override
165 {
166 _reg1.read(buf, offset, bytes);
167 }
168 void write(const void *buf) override { _reg2.write(buf); }
169 void
170 write(const void *buf, off_t offset, size_t bytes) override
171 {
172 _reg2.write(buf, offset, bytes);
173 }
174 };
175
176 // Offset 0.
177 Register8 rbr = {"rbr"};
178 Register8 thr = {"thr"};
180
181 Register8 dll = {"dll"};
183
184 // Offset 1.
185 Register<Ier> ier = {"ier", 0};
186 Register8 dlh = {"dlh"};
188
189 // Offset 2.
190 Register<Iir> iir = {"iir"};
191 Register8 fcr = {"fcr"};
193
194 // Offsets 3 - 6.
195 Register<Lcr> lcr = {"lcr"};
196 Register8 mcr = {"mcr"};
197 Register<Lsr> lsr = {"lsr"};
198 Register8 msr = {"msr"};
199
200 // The scratch register didn't exist on the 8250.
201 RegisterRaz sr = {"sr", 1};
202 };
204 template <class T>
205 using Register = Registers::Register<T>;
206
208
209 uint8_t readRbr(Register8 &reg);
210 void writeThr(Register8 &reg, const uint8_t &data);
211 void writeIer(Register<Ier> &reg, const Ier &ier);
213
215
216 void processIntrEvent(int intrBit);
217 void scheduleIntr(Event *event);
218 void clearIntr(int intrBit);
219
222
223 public:
224 using Params = Uart8250Params;
225 Uart8250(const Params &p);
226
227 Tick read(PacketPtr pkt) override;
228 Tick write(PacketPtr pkt) override;
229 AddrRangeList getAddrRanges() const override;
230
234 void dataAvailable() override;
235
236
241 virtual bool intStatus() { return status ? true : false; }
242
243 void serialize(CheckpointOut &cp) const override;
244 void unserialize(CheckpointIn &cp) override;
245};
246
247} // namespace gem5
248
249#endif // __TSUNAMI_UART_HH__
#define BitUnion8(name)
Definition bitunion.hh:497
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
virtual const std::string & name() const
Definition reg_bank.hh:388
void read(void *buf, off_t offset, size_t bytes) override
Definition uart8250.hh:145
BankedRegister(RegisterBase &reg1, RegisterBase &reg2)
Definition uart8250.hh:131
void write(const void *buf, off_t offset, size_t bytes) override
Definition uart8250.hh:151
void write(const void *buf) override
Definition uart8250.hh:149
const std::string & name() const override
Definition uart8250.hh:138
void serialize(std::ostream &os) const override
Definition uart8250.hh:114
bool unserialize(const std::string &s) override
Definition uart8250.hh:115
PairedRegister(RegisterBase &reg1, RegisterBase &reg2)
Definition uart8250.hh:105
void write(const void *buf, off_t offset, size_t bytes) override
Definition uart8250.hh:170
void write(const void *buf) override
Definition uart8250.hh:168
void read(void *buf, off_t offset, size_t bytes) override
Definition uart8250.hh:164
Register< Lcr > lcr
Definition uart8250.hh:195
Register< Ier > ier
Definition uart8250.hh:185
Register< Lsr > lsr
Definition uart8250.hh:197
RWSwitchedRegister rbrThr
Definition uart8250.hh:179
BankedRegister ierDlh
Definition uart8250.hh:187
BankedRegister rbrThrDll
Definition uart8250.hh:182
Registers(Uart8250 *uart, const std::string &new_name)
Definition uart8250.cc:109
RWSwitchedRegister iirFcr
Definition uart8250.hh:192
Register< Iir > iir
Definition uart8250.hh:190
Bitfield< 2 > stopBits
Definition uart8250.hh:69
void clearIntr(int intrBit)
Definition uart8250.cc:88
Bitfield< 6 > txEmpty
Definition uart8250.hh:82
Bitfield< 7, 3 > zeroes
Definition uart8250.hh:64
virtual bool intStatus()
Return if we have an interrupt pending.
Definition uart8250.hh:241
EndBitUnion(Iir) BitUnion8(Lcr) Bitfield< 1
Iir readIir(Register< Iir > &reg)
Definition uart8250.cc:180
EventFunctionWrapper txIntrEvent
Definition uart8250.hh:220
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition uart8250.cc:283
EndBitUnion(Ier) BitUnion8(Iir) Bitfield< 0 > pending
Bitfield< 5, 3 > parity
Definition uart8250.hh:70
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition uart8250.cc:306
void writeThr(Register8 &reg, const uint8_t &data)
Definition uart8250.cc:168
Bitfield< 7 > unused
Definition uart8250.hh:83
Registers registers
Definition uart8250.hh:207
EventFunctionWrapper rxIntrEvent
Definition uart8250.hh:221
Uart8250Params Params
Definition uart8250.hh:224
void dataAvailable() override
Inform the uart that there is data available.
Definition uart8250.cc:265
Bitfield< 6 > breakCont
Definition uart8250.hh:71
Uart8250(const Params &p)
Definition uart8250.cc:101
AddrRangeList getAddrRanges() const override
Determine the address ranges that this device responds to.
Definition uart8250.cc:275
Bitfield< 2 > parityError
Definition uart8250.hh:78
BitUnion8(Ier) Bitfield< 0 > rdi
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition uart8250.cc:251
Bitfield< 5 > tbe
Definition uart8250.hh:81
Bitfield< 2, 1 > id
Definition uart8250.hh:63
Bitfield< 7 > dlab
Definition uart8250.hh:72
Bitfield< 2 > rlsi
Definition uart8250.hh:57
Bitfield< 3 > framingError
Definition uart8250.hh:79
Bitfield< 3 > msi
Definition uart8250.hh:58
void scheduleIntr(Event *event)
Definition uart8250.cc:75
Registers::Register< T > Register
Definition uart8250.hh:205
Bitfield< 1 > overrunError
Definition uart8250.hh:77
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition uart8250.cc:238
Registers::Register8 Register8
Definition uart8250.hh:203
Bitfield< 1 > thri
Definition uart8250.hh:56
uint8_t readRbr(Register8 &reg)
Definition uart8250.cc:145
void processIntrEvent(int intrBit)
Definition uart8250.cc:50
Bitfield< 4 > breakCond
Definition uart8250.hh:80
void writeIer(Register< Ier > &reg, const Ier &ier)
Definition uart8250.cc:202
int status
Definition uart.hh:52
#define EndBitUnion(name)
This closes off the class and union started by the above macro.
Definition bitunion.hh:428
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Bitfield< 4 > s
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 10, 5 > event
Bitfield< 0 > p
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 17 > os
Definition misc.hh:838
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Tick
Tick count type.
Definition types.hh:58
const uint8_t UART_MCR_LOOP
Definition uart8250.hh:46
Base class for UART.

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0