gem5  v20.1.0.0
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"
46 #include "dev/arm/amba_device.hh"
47 #include "dev/ps2/device.hh"
48 #include "mem/packet.hh"
49 #include "mem/packet_access.hh"
50 
51 Pl050::Pl050(const Pl050Params *p)
52  : AmbaIntDevice(p, 0x1000), control(0), status(0x43), clkdiv(0),
53  rawInterrupts(0),
54  ps2(p->ps2)
55 {
56  ps2->hostRegDataAvailable([this]() { this->updateRxInt(); });
57 }
58 
59 Tick
61 {
62  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
63 
64  Addr daddr = pkt->getAddr() - pioAddr;
65 
66  uint32_t data = 0;
67 
68  switch (daddr) {
69  case kmiCr:
70  DPRINTF(Pl050, "Read Commmand: %#x\n", (uint32_t)control);
71  data = control;
72  break;
73 
74  case kmiStat:
75  status.rxfull = ps2->hostDataAvailable() ? 1 : 0;
76  DPRINTF(Pl050, "Read Status: %#x\n", (uint32_t)status);
77  data = status;
78  break;
79 
80  case kmiData:
81  data = ps2->hostDataAvailable() ? ps2->hostRead() : 0;
82  updateRxInt();
83  DPRINTF(Pl050, "Read Data: %#x\n", (uint32_t)data);
84  break;
85 
86  case kmiClkDiv:
87  data = clkdiv;
88  break;
89 
90  case kmiISR:
91  data = getInterrupt();
92  DPRINTF(Pl050, "Read Interrupts: %#x\n", getInterrupt());
93  break;
94 
95  default:
96  if (readId(pkt, ambaId, pioAddr)) {
97  // Hack for variable size accesses
98  data = pkt->getUintX(ByteOrder::little);
99  break;
100  }
101 
102  warn("Tried to read PL050 at offset %#x that doesn't exist\n", daddr);
103  break;
104  }
105 
106  pkt->setUintX(data, ByteOrder::little);
107  pkt->makeAtomicResponse();
108  return pioDelay;
109 }
110 
111 Tick
113 {
114 
115  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
116 
117  Addr daddr = pkt->getAddr() - pioAddr;
118  const uint32_t data = pkt->getUintX(ByteOrder::little);
119 
120  panic_if(pkt->getSize() != 1,
121  "PL050: Unexpected write size "
122  "(offset: %#x, data: %#x, size: %u)\n",
123  daddr, data, pkt->getSize());
124 
125  switch (daddr) {
126  case kmiCr:
127  DPRINTF(Pl050, "Write Commmand: %#x\n", data);
128  // Use the update interrupts helper to make sure any interrupt
129  // mask changes are handled correctly.
130  setControl((uint8_t)data);
131  break;
132 
133  case kmiData:
134  DPRINTF(Pl050, "Write Data: %#x\n", data);
135  // Clear the TX interrupt before writing new data.
136  setTxInt(false);
137  ps2->hostWrite((uint8_t)data);
138  // Data is written in 0 time, so raise the TX interrupt again.
139  setTxInt(true);
140  break;
141 
142  case kmiClkDiv:
143  clkdiv = (uint8_t)data;
144  break;
145 
146  default:
147  warn("PL050: Unhandled write of %#x to offset %#x\n", data, daddr);
148  break;
149  }
150 
151  pkt->makeAtomicResponse();
152  return pioDelay;
153 }
154 
155 void
156 Pl050::setTxInt(bool value)
157 {
158  InterruptReg ints = rawInterrupts;
159 
160  ints.tx = value ? 1 : 0;
161 
162  setInterrupts(ints);
163 }
164 
165 void
167 {
168  InterruptReg ints = rawInterrupts;
169 
170  ints.rx = ps2->hostDataAvailable() ? 1 : 0;
171 
172  setInterrupts(ints);
173 }
174 
175 void
176 Pl050::updateIntCtrl(InterruptReg ints, ControlReg ctrl)
177 {
178  const bool old_pending(getInterrupt());
179  control = ctrl;
180  rawInterrupts = ints;
181  const bool new_pending(getInterrupt());
182 
183  if (!old_pending && new_pending) {
184  DPRINTF(Pl050, "Generate interrupt: rawInt=%#x ctrl=%#x int=%#x\n",
185  rawInterrupts, control, getInterrupt());
186  interrupt->raise();
187  } else if (old_pending && !new_pending) {
188  DPRINTF(Pl050, "Clear interrupt: rawInt=%#x ctrl=%#x int=%#x\n",
189  rawInterrupts, control, getInterrupt());
190  interrupt->clear();
191  }
192 }
193 
194 Pl050::InterruptReg
196 {
197  InterruptReg tmp_interrupt(0);
198 
199  tmp_interrupt.tx = rawInterrupts.tx & control.txint_enable;
200  tmp_interrupt.rx = rawInterrupts.rx & control.rxint_enable;
201 
202  return tmp_interrupt;
203 }
204 
205 void
207 {
208  paramOut(cp, "ctrlreg", control);
209  paramOut(cp, "stsreg", status);
211  paramOut(cp, "raw_ints", rawInterrupts);
212 }
213 
214 void
216 {
217  paramIn(cp, "ctrlreg", control);
218  paramIn(cp, "stsreg", status);
220  paramIn(cp, "raw_ints", rawInterrupts);
221 }
222 
223 Pl050 *
224 Pl050Params::create()
225 {
226  return new Pl050(this);
227 }
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1016
BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
warn
#define warn(...)
Definition: logging.hh:239
Pl050::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: kmi.cc:206
data
const char data[]
Definition: circlebuf.test.cc:42
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
AmbaPioDevice::ambaId
uint64_t ambaId
Definition: amba_device.hh:79
ArmInterruptPin::clear
virtual void clear()=0
Clear a signalled interrupt.
amba_device.hh
Pl050::kmiClkDiv
static const int kmiClkDiv
Definition: kmi.hh:63
vncinput.hh
ArmInterruptPin::raise
virtual void raise()=0
Signal an interrupt.
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
PS2Device::hostRegDataAvailable
void hostRegDataAvailable(const std::function< void()> &c)
Register a data available callback into the PS/2 interface.
Definition: device.cc:77
PS2Device::hostRead
uint8_t hostRead()
Read a character from the device.
Definition: device.cc:87
PS2Device::hostDataAvailable
bool hostDataAvailable() const
Check if there is pending data from the PS/2 device.
Definition: device.hh:73
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
Pl050::updateIntCtrl
void updateIntCtrl(InterruptReg ints, ControlReg ctrl)
Update the status of the interrupt and control registers and deliver an interrupt if required.
Definition: kmi.cc:176
Pl050::setInterrupts
void setInterrupts(InterruptReg ints)
Definition: kmi.hh:119
paramOut
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition: types.cc:38
packet.hh
Pl050::setTxInt
void setTxInt(bool value)
Set or clear the TX interrupt.
Definition: kmi.cc:156
Pl050::kmiISR
static const int kmiISR
Definition: kmi.hh:64
kmi.hh
cp
Definition: cprintf.cc:40
AmbaIntDevice::interrupt
ArmInterruptPin *const interrupt
Definition: amba_device.hh:89
Packet::getUintX
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:350
Pl050::kmiData
static const int kmiData
Definition: kmi.hh:62
Pl050::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: kmi.cc:60
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Pl050::ps2
PS2Device * ps2
PS2 device connected to this KMI interface.
Definition: kmi.hh:126
Pl050::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: kmi.cc:215
Pl050::setControl
void setControl(ControlReg ctrl)
Definition: kmi.hh:120
Packet::setUintX
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:367
AmbaDevice::readId
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
Definition: amba_device.cc:72
BasicPioDevice::pioSize
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:157
AmbaIntDevice
Definition: amba_device.hh:86
Pl050::Pl050
Pl050(const Pl050Params *p)
Definition: kmi.cc:51
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
device.hh
PS2Device::hostWrite
void hostWrite(uint8_t c)
Transmit a character from the host interface to the device.
Definition: device.cc:95
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
packet_access.hh
Pl050::kmiStat
static const int kmiStat
Definition: kmi.hh:61
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
Pl050::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: kmi.cc:112
Pl050
Definition: kmi.hh:57
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
paramIn
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition: types.cc:69
BasicPioDevice::pioDelay
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:160
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
trace.hh
Pl050::clkdiv
uint8_t clkdiv
clock divisor register This register is just kept around to satisfy reads after driver does writes.
Definition: kmi.hh:97
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CheckpointIn
Definition: serialize.hh:67
Pl050::getInterrupt
InterruptReg getInterrupt() const
Get current interrupt value.
Definition: kmi.cc:195
Pl050::kmiCr
static const int kmiCr
Definition: kmi.hh:60
Pl050::updateRxInt
void updateRxInt()
Update the RX interrupt using PS/2 device state.
Definition: kmi.cc:166

Generated on Wed Sep 30 2020 14:02:10 for gem5 by doxygen 1.8.17