gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
kmi.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2017-2018 ARM Limited
3 * All rights reserved
4 *
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.
13 *
14 * Copyright (c) 2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
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.
27 *
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.
39 */
40
41#include "dev/arm/kmi.hh"
42
43#include "base/trace.hh"
44#include "base/vnc/vncinput.hh"
45#include "debug/Pl050.hh"
47#include "dev/ps2/device.hh"
48#include "mem/packet.hh"
49#include "mem/packet_access.hh"
50#include "params/Pl050.hh"
51
52namespace gem5
53{
54
55Pl050::Pl050(const Pl050Params &p)
56 : AmbaIntDevice(p, 0x1000), control(0), status(0x43), clkdiv(0),
57 rawInterrupts(0),
59{
60 ps2Device->hostRegDataAvailable([this]() { this->updateRxInt(); });
61}
62
63Tick
65{
66 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
67
68 Addr daddr = pkt->getAddr() - pioAddr;
69
70 uint32_t data = 0;
71
72 switch (daddr) {
73 case kmiCr:
74 DPRINTF(Pl050, "Read Commmand: %#x\n", (uint32_t)control);
75 data = control;
76 break;
77
78 case kmiStat:
79 status.rxfull = ps2Device->hostDataAvailable() ? 1 : 0;
80 DPRINTF(Pl050, "Read Status: %#x\n", (uint32_t)status);
81 data = status;
82 break;
83
84 case kmiData:
85 data = ps2Device->hostDataAvailable() ? ps2Device->hostRead() : 0;
87 DPRINTF(Pl050, "Read Data: %#x\n", (uint32_t)data);
88 break;
89
90 case kmiClkDiv:
91 data = clkdiv;
92 break;
93
94 case kmiISR:
96 DPRINTF(Pl050, "Read Interrupts: %#x\n", getInterrupt());
97 break;
98
99 default:
100 if (readId(pkt, ambaId, pioAddr)) {
101 // Hack for variable size accesses
102 data = pkt->getUintX(ByteOrder::little);
103 break;
104 }
105
106 warn("Tried to read PL050 at offset %#x that doesn't exist\n", daddr);
107 break;
108 }
109
110 pkt->setUintX(data, ByteOrder::little);
111 pkt->makeAtomicResponse();
112 return pioDelay;
113}
114
115Tick
117{
118
119 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
120
121 Addr daddr = pkt->getAddr() - pioAddr;
122 const uint32_t data = pkt->getUintX(ByteOrder::little);
123
124 panic_if(pkt->getSize() != 1,
125 "PL050: Unexpected write size "
126 "(offset: %#x, data: %#x, size: %u)\n",
127 daddr, data, pkt->getSize());
128
129 switch (daddr) {
130 case kmiCr:
131 DPRINTF(Pl050, "Write Commmand: %#x\n", data);
132 // Use the update interrupts helper to make sure any interrupt
133 // mask changes are handled correctly.
134 setControl((uint8_t)data);
135 break;
136
137 case kmiData:
138 DPRINTF(Pl050, "Write Data: %#x\n", data);
139 // Clear the TX interrupt before writing new data.
140 setTxInt(false);
141 ps2Device->hostWrite((uint8_t)data);
142 // Data is written in 0 time, so raise the TX interrupt again.
143 setTxInt(true);
144 break;
145
146 case kmiClkDiv:
147 clkdiv = (uint8_t)data;
148 break;
149
150 default:
151 warn("PL050: Unhandled write of %#x to offset %#x\n", data, daddr);
152 break;
153 }
154
155 pkt->makeAtomicResponse();
156 return pioDelay;
157}
158
159void
161{
162 InterruptReg ints = rawInterrupts;
163
164 ints.tx = value ? 1 : 0;
165
166 setInterrupts(ints);
167}
168
169void
171{
172 InterruptReg ints = rawInterrupts;
173
174 ints.rx = ps2Device->hostDataAvailable() ? 1 : 0;
175
176 setInterrupts(ints);
177}
178
179void
180Pl050::updateIntCtrl(InterruptReg ints, ControlReg ctrl)
181{
182 const bool old_pending(getInterrupt());
183 control = ctrl;
184 rawInterrupts = ints;
185 const bool new_pending(getInterrupt());
186
187 if (!old_pending && new_pending) {
188 DPRINTF(Pl050, "Generate interrupt: rawInt=%#x ctrl=%#x int=%#x\n",
189 rawInterrupts, control, getInterrupt());
190 interrupt->raise();
191 } else if (old_pending && !new_pending) {
192 DPRINTF(Pl050, "Clear interrupt: rawInt=%#x ctrl=%#x int=%#x\n",
193 rawInterrupts, control, getInterrupt());
194 interrupt->clear();
195 }
196}
197
198Pl050::InterruptReg
200{
201 InterruptReg tmp_interrupt(0);
202
203 tmp_interrupt.tx = rawInterrupts.tx & control.txint_enable;
204 tmp_interrupt.rx = rawInterrupts.rx & control.rxint_enable;
205
206 return tmp_interrupt;
207}
208
209void
211{
212 paramOut(cp, "ctrlreg", control);
213 paramOut(cp, "stsreg", status);
215 paramOut(cp, "raw_ints", rawInterrupts);
216}
217
218void
220{
221 paramIn(cp, "ctrlreg", control);
222 paramIn(cp, "stsreg", status);
224 paramIn(cp, "raw_ints", rawInterrupts);
225}
226
227} // namespace gem5
This is a base class for AMBA devices that have to respond to Device and Implementer ID calls.
#define DPRINTF(x,...)
Definition trace.hh:209
const char data[]
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
AmbaIntDevice(const Params &p, Addr pio_size)
ArmInterruptPin *const interrupt
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition io_device.hh:157
Addr pioSize
Size that the device's address range.
Definition io_device.hh:154
Addr getAddr() const
Definition packet.hh:807
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition packet.cc:361
unsigned getSize() const
Definition packet.hh:817
uint64_t getUintX(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness and zero-extended to 64 bits.
Definition packet.cc:352
void makeAtomicResponse()
Definition packet.hh:1074
void setControl(ControlReg ctrl)
Definition kmi.hh:126
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition kmi.cc:116
static const int kmiClkDiv
Definition kmi.hh:69
static const int kmiISR
Definition kmi.hh:70
static const int kmiStat
Definition kmi.hh:67
static const int kmiCr
Definition kmi.hh:66
uint8_t clkdiv
clock divisor register This register is just kept around to satisfy reads after driver does writes.
Definition kmi.hh:103
Pl050(const Pl050Params &p)
Definition kmi.cc:55
void updateRxInt()
Update the RX interrupt using PS/2 device state.
Definition kmi.cc:170
void setInterrupts(InterruptReg ints)
Definition kmi.hh:125
static const int kmiData
Definition kmi.hh:68
InterruptReg getInterrupt() const
Get current interrupt value.
Definition kmi.cc:199
void setTxInt(bool value)
Set or clear the TX interrupt.
Definition kmi.cc:160
ps2::Device * ps2Device
PS2 device connected to this KMI interface.
Definition kmi.hh:132
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition kmi.cc:64
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition kmi.cc:219
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition kmi.cc:210
void updateIntCtrl(InterruptReg ints, ControlReg ctrl)
Update the status of the interrupt and control registers and deliver an interrupt if required.
Definition kmi.cc:180
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:246
Implementiation of a PL050 KMI.
#define warn(...)
Definition logging.hh:288
Bitfield< 5, 0 > status
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition types.cc:40
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition types.cc:72
uint64_t Tick
Tick count type.
Definition types.hh:58
Packet * PacketPtr
Declaration of the Packet class.
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568
Declaration of a VNC input.

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0