e00ee835111eaf0fe377e9cfa691dd3f0538e2be
2 * Copyright (c) 2010, 2015 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2005 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #include "dev/arm/pl011.hh"
46 #include "base/trace.hh"
47 #include "debug/Checkpoint.hh"
48 #include "debug/Uart.hh"
49 #include "dev/arm/amba_device.hh"
50 #include "dev/arm/base_gic.hh"
51 #include "dev/terminal.hh"
52 #include "mem/packet.hh"
53 #include "mem/packet_access.hh"
54 #include "sim/sim_exit.hh"
55 #include "params/Pl011.hh"
57 Pl011::Pl011(const Pl011Params
*p
)
60 control(0x300), fbrd(0), ibrd(0), lcrh(0), ifls(0x12),
62 gic(p
->gic
), endOnEOT(p
->end_on_eot
), intNum(p
->int_num
),
63 intDelay(p
->int_delay
)
68 Pl011::read(PacketPtr pkt
)
70 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
72 Addr daddr
= pkt
->getAddr() - pioAddr
;
74 DPRINTF(Uart
, " read register %#x size=%d\n", daddr
, pkt
->getSize());
76 // use a temporary data since the uart registers are read/written with
77 // different size operations
84 if (term
->dataAvailable()) {
86 // Since we don't simulate a FIFO for incoming data, we
87 // assume it's empty and clear RXINTR and RTINTR.
88 clearInterrupts(UART_RXINTR
| UART_RTINTR
);
93 UART_FR_CTS
| // Clear To Send
94 // Given we do not simulate a FIFO we are either empty or full.
95 (!term
->dataAvailable() ? UART_FR_RXFE
: UART_FR_RXFF
) |
96 UART_FR_TXFE
; // TX FIFO empty
99 "Reading FR register as %#x rawInt=0x%x "
100 "imsc=0x%x maskInt=0x%x\n",
101 data
, rawInt
, imsc
, maskInt());
123 DPRINTF(Uart
, "Reading Raw Int status as 0x%x\n", rawInt
);
126 DPRINTF(Uart
, "Reading Masked Int status as 0x%x\n", maskInt());
130 if (readId(pkt
, AMBA_ID
, pioAddr
)) {
131 // Hack for variable size accesses
132 data
= pkt
->get
<uint32_t>();
136 panic("Tried to read PL011 at offset %#x that doesn't exist\n", daddr
);
140 switch(pkt
->getSize()) {
142 pkt
->set
<uint8_t>(data
);
145 pkt
->set
<uint16_t>(data
);
148 pkt
->set
<uint32_t>(data
);
151 panic("Uart read size too big?\n");
156 pkt
->makeAtomicResponse();
161 Pl011::write(PacketPtr pkt
)
164 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
166 Addr daddr
= pkt
->getAddr() - pioAddr
;
168 DPRINTF(Uart
, " write register %#x value %#x size=%d\n", daddr
,
169 pkt
->get
<uint8_t>(), pkt
->getSize());
171 // use a temporary data since the uart registers are read/written with
172 // different size operations
176 switch(pkt
->getSize()) {
178 data
= pkt
->get
<uint8_t>();
181 data
= pkt
->get
<uint16_t>();
184 data
= pkt
->get
<uint32_t>();
187 panic("Uart write size too big?\n");
194 if ((data
& 0xFF) == 0x04 && endOnEOT
)
195 exitSimLoop("UART received EOT", 0);
197 term
->out(data
& 0xFF);
198 // We're supposed to clear TXINTR when this register is
199 // written to, however. since we're also infinitely fast, we
200 // need to immediately raise it again.
201 clearInterrupts(UART_TXINTR
);
202 raiseInterrupts(UART_TXINTR
);
220 DPRINTF(Uart
, "Setting interrupt mask 0x%x\n", data
);
221 setInterruptMask(data
);
225 DPRINTF(Uart
, "Clearing interrupts 0x%x\n", data
);
226 clearInterrupts(data
);
229 panic("Tried to write PL011 at offset %#x that doesn't exist\n", daddr
);
232 pkt
->makeAtomicResponse();
237 Pl011::dataAvailable()
239 /*@todo ignore the fifo, just say we have data now
240 * We might want to fix this, or we might not care */
241 DPRINTF(Uart
, "Data available, scheduling interrupt\n");
242 raiseInterrupts(UART_RXINTR
| UART_RTINTR
);
246 Pl011::generateInterrupt()
248 DPRINTF(Uart
, "Generate Interrupt: imsc=0x%x rawInt=0x%x maskInt=0x%x\n",
249 imsc
, rawInt
, maskInt());
252 gic
->sendInt(intNum
);
253 DPRINTF(Uart
, " -- Generated\n");
258 Pl011::setInterrupts(uint16_t ints
, uint16_t mask
)
260 const bool old_ints(!!maskInt());
265 if (!old_ints
&& maskInt()) {
266 if (!intEvent
.scheduled())
267 schedule(intEvent
, curTick() + intDelay
);
268 } else if (old_ints
&& !maskInt()) {
269 gic
->clearInt(intNum
);
276 Pl011::serialize(CheckpointOut
&cp
) const
278 DPRINTF(Checkpoint
, "Serializing Arm PL011\n");
279 SERIALIZE_SCALAR(control
);
280 SERIALIZE_SCALAR(fbrd
);
281 SERIALIZE_SCALAR(ibrd
);
282 SERIALIZE_SCALAR(lcrh
);
283 SERIALIZE_SCALAR(ifls
);
285 // Preserve backwards compatibility by giving these silly names.
286 paramOut(cp
, "imsc_serial", imsc
);
287 paramOut(cp
, "rawInt_serial", rawInt
);
291 Pl011::unserialize(CheckpointIn
&cp
)
293 DPRINTF(Checkpoint
, "Unserializing Arm PL011\n");
295 UNSERIALIZE_SCALAR(control
);
296 UNSERIALIZE_SCALAR(fbrd
);
297 UNSERIALIZE_SCALAR(ibrd
);
298 UNSERIALIZE_SCALAR(lcrh
);
299 UNSERIALIZE_SCALAR(ifls
);
301 // Preserve backwards compatibility by giving these silly names.
302 paramIn(cp
, "imsc_serial", imsc
);
303 paramIn(cp
, "rawInt_serial", rawInt
);
307 Pl011Params::create()
309 return new Pl011(this);