gem5  v21.1.0.2
keyboard.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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) 2008 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/ps2/keyboard.hh"
42 
43 #include <cstdint>
44 #include <list>
45 
46 #include "base/logging.hh"
47 #include "base/trace.hh"
48 #include "debug/PS2.hh"
49 #include "dev/ps2/types.hh"
50 #include "params/PS2Keyboard.hh"
51 
52 namespace gem5
53 {
54 
55 namespace ps2
56 {
57 
58 PS2Keyboard::PS2Keyboard(const PS2KeyboardParams &p)
59  : Device(p),
60  shiftDown(false),
61  enabled(false)
62 {
63  if (p.vnc)
64  p.vnc->setKeyboard(this);
65 }
66 
67 void
69 {
73 }
74 
75 void
77 {
81 }
82 
83 bool
85 {
86  switch (data[0]) {
87  case ReadID:
88  DPRINTF(PS2, "Got keyboard read ID command.\n");
89  sendAck();
91  return true;
92  case Enable:
93  DPRINTF(PS2, "Enabling the keyboard.\n");
94  enabled = true;
95  sendAck();
96  return true;
97  case Disable:
98  DPRINTF(PS2, "Disabling the keyboard.\n");
99  enabled = false;
100  sendAck();
101  return true;
102  case DefaultsAndDisable:
103  DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
104  enabled = false;
105  sendAck();
106  return true;
107  case Reset:
108  DPRINTF(PS2, "Resetting keyboard.\n");
109  enabled = true;
110  sendAck();
112  return true;
113  case Resend:
114  panic("Keyboard resend unimplemented.\n");
115 
116  case keyboard::LEDWrite:
117  if (data.size() == 1) {
118  DPRINTF(PS2, "Got LED write command.\n");
119  sendAck();
120  return false;
121  } else {
122  DPRINTF(PS2, "Setting LEDs: "
123  "caps lock %s, num lock %s, scroll lock %s\n",
124  bits(data[1], 2) ? "on" : "off",
125  bits(data[1], 1) ? "on" : "off",
126  bits(data[1], 0) ? "on" : "off");
127  sendAck();
128  return true;
129  }
131  panic("Keyboard diagnostic echo unimplemented.\n");
133  panic("Accessing alternate scan codes unimplemented.\n");
135  if (data.size() == 1) {
136  DPRINTF(PS2, "Setting typematic info.\n");
137  sendAck();
138  return false;
139  } else {
140  DPRINTF(PS2, "Setting typematic info to %#02x.\n", data[1]);
141  sendAck();
142  return true;
143  }
145  panic("Setting all keys to typemantic unimplemented.\n");
147  panic("Setting all keys to make/release unimplemented.\n");
149  panic("Setting all keys to make unimplemented.\n");
151  panic("Setting all keys to "
152  "typematic/make/release unimplemented.\n");
154  panic("Setting a key to typematic unimplemented.\n");
156  panic("Setting a key to make/release unimplemented.\n");
158  panic("Setting key to make only unimplemented.\n");
159  default:
160  panic("Unknown keyboard command %#02x.\n", data[0]);
161  }
162 }
163 
164 void
165 PS2Keyboard::keyPress(uint32_t key, bool down)
166 {
168 
169  // convert the X11 keysym into ps2 codes and update the shift
170  // state (shiftDown)
171  keySymToPs2(key, down, shiftDown, keys);
172 
173  // Drop key presses if the keyboard hasn't been enabled by the
174  // host. We do that after translating the key code to ensure that
175  // we keep track of the shift state.
176  if (!enabled)
177  return;
178 
179  // Insert into our queue of characters
180  for (uint8_t c : keys)
181  send(c);
182 }
183 
184 } // namespace ps2
185 } // namespace gem5
gem5::ps2::keyboard::DiagnosticEcho
@ DiagnosticEcho
Definition: types.hh:80
gem5::ps2::Device::send
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition: device.cc:113
types.hh
data
const char data[]
Definition: circlebuf.test.cc:48
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
gem5::ps2::keyboard::KeyToTypematic
@ KeyToTypematic
Definition: types.hh:87
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::ps2::keySymToPs2
void keySymToPs2(uint32_t key, bool down, bool &cur_shift, std::list< uint8_t > &keys)
Definition: types.cc:88
gem5::ps2::keyboard::KeyToMakeOnly
@ KeyToMakeOnly
Definition: types.hh:89
gem5::ps2::PS2Keyboard::recv
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition: keyboard.cc:84
gem5::ps2::keyboard::TypematicInfo
@ TypematicInfo
Definition: types.hh:82
std::vector< uint8_t >
gem5::ps2::PS2Keyboard::enabled
bool enabled
Is the device enabled?
Definition: keyboard.hh:62
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::ps2::SelfTestPass
@ SelfTestPass
Definition: types.hh:62
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ps2::Device::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: device.cc:65
gem5::ps2::Device::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: device.cc:75
gem5::bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
gem5::ps2::keyboard::AllKeysToTypematicMakeRelease
@ AllKeysToTypematicMakeRelease
Definition: types.hh:86
gem5::ps2::Resend
@ Resend
Definition: types.hh:69
gem5::ps2::PS2Keyboard::keyPress
void keyPress(uint32_t key, bool down) override
Called when the vnc server receives a key press event from the client.
Definition: keyboard.cc:165
keyboard.hh
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
gem5::ps2::keys
bool bool std::list< uint8_t > & keys
Definition: types.hh:137
gem5::ps2::Reset
@ Reset
Definition: types.hh:70
gem5::ps2::keyboard::AlternateScanCodes
@ AlternateScanCodes
Definition: types.hh:81
gem5::statistics::enabled
bool enabled()
Definition: statistics.cc:280
gem5::ps2::Disable
@ Disable
Definition: types.hh:65
gem5::ps2::Device
Definition: device.hh:60
gem5::ps2::keyboard::AllKeysToMakeRelease
@ AllKeysToMakeRelease
Definition: types.hh:84
gem5::ps2::DefaultsAndDisable
@ DefaultsAndDisable
Definition: types.hh:66
gem5::ps2::PS2Keyboard::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: keyboard.cc:68
gem5::ps2::PS2Keyboard::shiftDown
bool shiftDown
is the shift key currently down
Definition: keyboard.hh:59
gem5::ps2::keyboard::KeyToMakeRelease
@ KeyToMakeRelease
Definition: types.hh:88
logging.hh
gem5::ps2::keyboard::LEDWrite
@ LEDWrite
Definition: types.hh:79
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::ps2::PS2Keyboard::PS2Keyboard
PS2Keyboard(const PS2KeyboardParams &p)
Definition: keyboard.cc:58
trace.hh
gem5::ps2::keyboard::AllKeysToTypematic
@ AllKeysToTypematic
Definition: types.hh:83
gem5::ps2::Device::sendAck
void sendAck()
Send an ACK byte to the host.
Definition: device.cc:128
std::list
STL list class.
Definition: stl.hh:51
gem5::ps2::PS2Keyboard::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: keyboard.cc:76
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ps2::keyboard::AllKeysToMake
@ AllKeysToMake
Definition: types.hh:85
gem5::ps2::down
bool down
Definition: types.hh:136
gem5::ps2::ReadID
@ ReadID
Definition: types.hh:63
gem5::ps2::Enable
@ Enable
Definition: types.hh:64
gem5::ps2::keyboard::ID
const std::vector< uint8_t > ID
Definition: types.cc:52
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177

Generated on Tue Sep 21 2021 12:25:17 for gem5 by doxygen 1.8.17