gem5  v22.1.0.0
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 
43 namespace gem5
44 {
45 
46 const uint8_t UART_MCR_LOOP = 0x10;
47 
48 class Terminal;
49 class Platform;
50 
51 class Uart8250 : public Uart
52 {
53  protected:
54  BitUnion8(Ier)
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 
94  class Registers : public RegisterBankLE
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 
119  {
120  private:
121  RegisterBase *selected = nullptr;
122 
123  public:
124  BankedRegister(RegisterBase &reg1, RegisterBase &reg2) :
125  PairedRegister(reg1, reg2), selected(&reg1)
126  {}
127 
128  void select(bool second) { selected = second ? &_reg2 : &_reg1; }
129 
130  const std::string &
131  name() const override
132  {
133  return selected->name();
134  }
135 
136  void read(void *buf) override { selected->read(buf); }
137  void
138  read(void *buf, off_t offset, size_t bytes) override
139  {
140  selected->read(buf, offset, bytes);
141  }
142  void write(const void *buf) override { selected->write(buf); }
143  void
144  write(const void *buf, off_t offset, size_t bytes) override
145  {
146  selected->write(buf, offset, bytes);
147  }
148  };
149 
151  {
152  public:
154 
155  void read(void *buf) override { _reg1.read(buf); }
156  void
157  read(void *buf, off_t offset, size_t bytes) override
158  {
159  _reg1.read(buf, offset, bytes);
160  }
161  void write(const void *buf) override { _reg2.write(buf); }
162  void
163  write(const void *buf, off_t offset, size_t bytes) override
164  {
165  _reg2.write(buf, offset, bytes);
166  }
167  };
168 
169  // Offset 0.
170  Register8 rbr = {"rbr"};
171  Register8 thr = {"thr"};
173 
174  Register8 dll = {"dll"};
176 
177  // Offset 1.
178  Register<Ier> ier = {"ier", 0};
179  Register8 dlh = {"dlh"};
181 
182  // Offset 2.
183  Register<Iir> iir = {"iir"};
184  Register8 fcr = {"fcr"};
186 
187  // Offsets 3 - 6.
188  Register<Lcr> lcr = {"lcr"};
189  Register8 mcr = {"mcr"};
190  Register<Lsr> lsr = {"lsr"};
191  Register8 msr = {"msr"};
192 
193  // The scratch register didn't exist on the 8250.
194  RegisterRaz sr = {"sr", 1};
195  };
197  template <class T>
198  using Register = Registers::Register<T>;
199 
201 
202  uint8_t readRbr(Register8 &reg);
203  void writeThr(Register8 &reg, const uint8_t &data);
204  void writeIer(Register<Ier> &reg, const Ier &ier);
205  Iir readIir(Register<Iir> &reg);
206 
208 
209  void processIntrEvent(int intrBit);
210  void scheduleIntr(Event *event);
211 
214 
215  public:
216  using Params = Uart8250Params;
217  Uart8250(const Params &p);
218 
219  Tick read(PacketPtr pkt) override;
220  Tick write(PacketPtr pkt) override;
221  AddrRangeList getAddrRanges() const override;
222 
226  void dataAvailable() override;
227 
228 
233  virtual bool intStatus() { return status ? true : false; }
234 
235  void serialize(CheckpointOut &cp) const override;
236  void unserialize(CheckpointIn &cp) override;
237 };
238 
239 } // namespace gem5
240 
241 #endif // __TSUNAMI_UART_HH__
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
PioDeviceParams Params
Definition: io_device.hh:134
const std::string & name() const
Definition: reg_bank.hh:824
void read(void *buf, off_t offset, size_t bytes) override
Definition: uart8250.hh:138
BankedRegister(RegisterBase &reg1, RegisterBase &reg2)
Definition: uart8250.hh:124
void write(const void *buf, off_t offset, size_t bytes) override
Definition: uart8250.hh:144
void write(const void *buf) override
Definition: uart8250.hh:142
const std::string & name() const override
Definition: uart8250.hh:131
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:163
void write(const void *buf) override
Definition: uart8250.hh:161
void read(void *buf, off_t offset, size_t bytes) override
Definition: uart8250.hh:157
Register< Lcr > lcr
Definition: uart8250.hh:188
Register< Ier > ier
Definition: uart8250.hh:178
Register< Lsr > lsr
Definition: uart8250.hh:190
RWSwitchedRegister rbrThr
Definition: uart8250.hh:172
BankedRegister ierDlh
Definition: uart8250.hh:180
BankedRegister rbrThrDll
Definition: uart8250.hh:175
Registers(Uart8250 *uart, const std::string &new_name)
Definition: uart8250.cc:96
RWSwitchedRegister iirFcr
Definition: uart8250.hh:185
Register< Iir > iir
Definition: uart8250.hh:183
Bitfield< 2 > stopBits
Definition: uart8250.hh:69
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:233
EndBitUnion(Iir) BitUnion8(Lcr) Bitfield< 1
Iir readIir(Register< Iir > &reg)
Definition: uart8250.cc:160
EventFunctionWrapper txIntrEvent
Definition: uart8250.hh:212
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: uart8250.cc:263
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:284
void writeThr(Register8 &reg, const uint8_t &data)
Definition: uart8250.cc:150
Bitfield< 7 > unused
Definition: uart8250.hh:83
Registers registers
Definition: uart8250.hh:200
EventFunctionWrapper rxIntrEvent
Definition: uart8250.hh:213
void dataAvailable() override
Inform the uart that there is data available.
Definition: uart8250.cc:244
Bitfield< 6 > breakCont
Definition: uart8250.hh:71
Uart8250(const Params &p)
Definition: uart8250.cc:88
AddrRangeList getAddrRanges() const override
Determine the address ranges that this device responds to.
Definition: uart8250.cc:255
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:230
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:76
Registers::Register< T > Register
Definition: uart8250.hh:198
Bitfield< 1 > overrunError
Definition: uart8250.hh:77
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: uart8250.cc:217
Registers::Register8 Register8
Definition: uart8250.hh:196
Bitfield< 1 > thri
Definition: uart8250.hh:56
uint8_t readRbr(Register8 &reg)
Definition: uart8250.cc:132
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:179
int status
Definition: uart.hh:52
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 10, 5 > event
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 17 > os
Definition: misc.hh:810
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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 Wed Dec 21 2022 10:22:35 for gem5 by doxygen 1.9.1