2 * Copyright (c) 2010 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 "base/vnc/vncinput.hh"
45 #include "base/trace.hh"
46 #include "debug/Pl050.hh"
47 #include "dev/arm/amba_device.hh"
48 #include "dev/arm/kmi.hh"
50 #include "mem/packet.hh"
51 #include "mem/packet_access.hh"
53 Pl050::Pl050(const Params
*p
)
54 : AmbaIntDevice(p
, 0xfff), control(0), status(0x43), clkdiv(0),
55 interrupts(0), rawInterrupts(0), ackNext(false), shiftDown(false),
56 vnc(p
->vnc
), driverInitialized(false), intEvent(this)
60 vnc
->setKeyboard(this);
67 Pl050::read(PacketPtr pkt
)
69 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
71 Addr daddr
= pkt
->getAddr() - pioAddr
;
77 DPRINTF(Pl050
, "Read Commmand: %#x\n", (uint32_t)control
);
86 DPRINTF(Pl050
, "Read Status: %#x\n", (uint32_t)status
);
90 if (rxQueue
.empty()) {
93 data
= rxQueue
.front();
96 DPRINTF(Pl050
, "Read Data: %#x\n", (uint32_t)data
);
104 DPRINTF(Pl050
, "Read Interrupts: %#x\n", (uint32_t)interrupts
);
107 if (readId(pkt
, ambaId
, pioAddr
)) {
108 // Hack for variable size accesses
109 data
= pkt
->get
<uint32_t>();
113 warn("Tried to read PL050 at offset %#x that doesn't exist\n", daddr
);
117 switch(pkt
->getSize()) {
119 pkt
->set
<uint8_t>(data
);
122 pkt
->set
<uint16_t>(data
);
125 pkt
->set
<uint32_t>(data
);
128 panic("KMI read size too big?\n");
132 pkt
->makeAtomicResponse();
137 Pl050::write(PacketPtr pkt
)
140 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
142 Addr daddr
= pkt
->getAddr() - pioAddr
;
144 assert(pkt
->getSize() == sizeof(uint8_t));
149 DPRINTF(Pl050
, "Write Commmand: %#x\n", (uint32_t)pkt
->get
<uint8_t>());
150 control
= pkt
->get
<uint8_t>();
154 DPRINTF(Pl050
, "Write Data: %#x\n", (uint32_t)pkt
->get
<uint8_t>());
155 processCommand(pkt
->get
<uint8_t>());
159 clkdiv
= pkt
->get
<uint8_t>();
162 warn("Tried to write PL050 at offset %#x that doesn't exist\n", daddr
);
165 pkt
->makeAtomicResponse();
170 Pl050::processCommand(uint8_t byte
)
176 rxQueue
.push_back(Ack
);
183 rxQueue
.push_back(Ack
);
184 rxQueue
.push_back(SelfTestPass
);
191 rxQueue
.push_back(Ack
);
195 rxQueue
.push_back(Ack
);
196 if (params()->is_mouse
)
197 rxQueue
.push_back(MouseId
);
199 rxQueue
.push_back(KeyboardId
);
202 if (!params()->is_mouse
)
204 // We're not a trackpoint device, this should make the probe go away
205 rxQueue
.push_back(Ack
);
206 rxQueue
.push_back(0);
207 rxQueue
.push_back(0);
212 rxQueue
.push_back(Ack
);
215 rxQueue
.push_back(Ack
);
216 rxQueue
.push_back(0);
217 rxQueue
.push_back(2); // default resolution
218 rxQueue
.push_back(100); // default sample rate
222 rxQueue
.push_back(Ack
);
223 rxQueue
.push_back(TouchKitId
);
224 rxQueue
.push_back(1);
225 rxQueue
.push_back('A');
227 driverInitialized
= true;
230 panic("Unknown byte received: %d\n", byte
);
238 Pl050::updateIntStatus()
240 if (!rxQueue
.empty())
241 rawInterrupts
.rx
= 1;
243 rawInterrupts
.rx
= 0;
245 interrupts
.tx
= rawInterrupts
.tx
& control
.txint_enable
;
246 interrupts
.rx
= rawInterrupts
.rx
& control
.rxint_enable
;
248 DPRINTF(Pl050
, "rawInterupts=%#x control=%#x interrupts=%#x\n",
249 (uint32_t)rawInterrupts
, (uint32_t)control
, (uint32_t)interrupts
);
251 if (interrupts
&& !intEvent
.scheduled())
252 schedule(intEvent
, curTick() + intDelay
);
256 Pl050::generateInterrupt()
260 gic
->sendInt(intNum
);
261 DPRINTF(Pl050
, "Generated interrupt\n");
266 Pl050::mouseAt(uint16_t x
, uint16_t y
, uint8_t buttons
)
270 // If the driver hasn't initialized the device yet, no need to try and send
271 // it anything. Similarly we can get vnc mouse events orders of maginture
272 // faster than m5 can process them. Only queue up two sets mouse movements
273 // and don't add more until those are processed.
274 if (!driverInitialized
|| rxQueue
.size() > 10)
277 // We shouldn't be here unless a vnc server called us in which case
278 // we should have a pointer to it
281 // Convert screen coordinates to touchpad coordinates
282 uint16_t _x
= (2047.0/vnc
->videoWidth()) * x
;
283 uint16_t _y
= (2047.0/vnc
->videoHeight()) * y
;
285 rxQueue
.push_back(buttons
);
286 rxQueue
.push_back(_x
>> 7);
287 rxQueue
.push_back(_x
& 0x7f);
288 rxQueue
.push_back(_y
>> 7);
289 rxQueue
.push_back(_y
& 0x7f);
296 Pl050::keyPress(uint32_t key
, bool down
)
300 std::list
<uint8_t> keys
;
302 // convert the X11 keysym into ps2 codes
303 keySymToPs2(key
, down
, shiftDown
, keys
);
305 // Insert into our queue of charecters
306 rxQueue
.splice(rxQueue
.end(), keys
);
311 Pl050::serialize(CheckpointOut
&cp
) const
313 uint8_t ctrlreg
= control
;
314 SERIALIZE_SCALAR(ctrlreg
);
316 uint8_t stsreg
= status
;
317 SERIALIZE_SCALAR(stsreg
);
318 SERIALIZE_SCALAR(clkdiv
);
320 uint8_t ints
= interrupts
;
321 SERIALIZE_SCALAR(ints
);
323 uint8_t raw_ints
= rawInterrupts
;
324 SERIALIZE_SCALAR(raw_ints
);
326 SERIALIZE_SCALAR(ackNext
);
327 SERIALIZE_SCALAR(shiftDown
);
328 SERIALIZE_SCALAR(driverInitialized
);
330 SERIALIZE_CONTAINER(rxQueue
);
334 Pl050::unserialize(CheckpointIn
&cp
)
337 UNSERIALIZE_SCALAR(ctrlreg
);
341 UNSERIALIZE_SCALAR(stsreg
);
344 UNSERIALIZE_SCALAR(clkdiv
);
347 UNSERIALIZE_SCALAR(ints
);
351 UNSERIALIZE_SCALAR(raw_ints
);
352 rawInterrupts
= raw_ints
;
354 UNSERIALIZE_SCALAR(ackNext
);
355 UNSERIALIZE_SCALAR(shiftDown
);
356 UNSERIALIZE_SCALAR(driverInitialized
);
358 UNSERIALIZE_CONTAINER(rxQueue
);
364 Pl050Params::create()
366 return new Pl050(this);