Hello Giacomo Travaglini,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/9763
to review the following change.
Change subject: ps2: Add VNC support to the keyboard model
......................................................................
ps2: Add VNC support to the keyboard model
Add support for keyboard input from the VNC server in the PS/2
keyboard model. The introduced code is based on the functionality in
the Arm PL050 KMI model.
Change-Id: If04a9713e5a15e2149d1a7471b999e3060d8ee7d
Signed-off-by: Andreas Sandberg <[email protected]>
Reviewed-by: Giacomo Travaglini <[email protected]>
---
M src/dev/ps2/PS2.py
M src/dev/ps2/keyboard.cc
M src/dev/ps2/keyboard.hh
3 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/src/dev/ps2/PS2.py b/src/dev/ps2/PS2.py
index 5db3b6e..da7eae9 100644
--- a/src/dev/ps2/PS2.py
+++ b/src/dev/ps2/PS2.py
@@ -48,6 +48,8 @@
type = 'PS2Keyboard'
cxx_header = "dev/ps2/keyboard.hh"
+ vnc = Param.VncInput(Parent.any, "Vnc server for remote frame buffer")
+
class PS2Mouse(PS2Device):
type = 'PS2Mouse'
cxx_header = "dev/ps2/mouse.hh"
diff --git a/src/dev/ps2/keyboard.cc b/src/dev/ps2/keyboard.cc
index a942d34..46b89fa 100644
--- a/src/dev/ps2/keyboard.cc
+++ b/src/dev/ps2/keyboard.cc
@@ -45,14 +45,19 @@
#include "base/logging.hh"
#include "debug/PS2.hh"
+#include "dev/ps2.hh"
#include "params/PS2Keyboard.hh"
const uint8_t PS2Keyboard::ID[] = {0xab, 0x83};
PS2Keyboard::PS2Keyboard(const PS2KeyboardParams *p)
: PS2Device(p),
- lastCommand(NoCommand)
+ lastCommand(NoCommand),
+ shiftDown(false),
+ enabled(false)
{
+ if (p->vnc)
+ p->vnc->setKeyboard(this);
}
void
@@ -60,6 +65,8 @@
{
PS2Device::serialize(cp);
SERIALIZE_SCALAR(lastCommand);
+ SERIALIZE_SCALAR(shiftDown);
+ SERIALIZE_SCALAR(enabled);
}
void
@@ -67,6 +74,8 @@
{
PS2Device::unserialize(cp);
UNSERIALIZE_SCALAR(lastCommand);
+ UNSERIALIZE_SCALAR(shiftDown);
+ UNSERIALIZE_SCALAR(enabled);
}
void
@@ -114,14 +123,17 @@
break;
case Enable:
DPRINTF(PS2, "Enabling the keyboard.\n");
+ enabled = true;
sendAck();
break;
case Disable:
DPRINTF(PS2, "Disabling the keyboard.\n");
+ enabled = false;
sendAck();
break;
case DefaultsAndDisable:
DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
+ enabled = false;
sendAck();
break;
case AllKeysToTypematic:
@@ -148,6 +160,27 @@
}
}
+void
+PS2Keyboard::keyPress(uint32_t key, bool down)
+{
+ std::list<uint8_t> keys;
+
+ // convert the X11 keysym into ps2 codes and update the shift
+ // state (shiftDown)
+ Ps2::keySymToPs2(key, down, shiftDown, keys);
+
+ // Drop key presses if the keyboard hasn't been enabled by the
+ // host. We do that after translating the key code to ensure that
+ // we keep track of the shift state.
+ if (!enabled)
+ return;
+
+ // Insert into our queue of characters
+ for (uint8_t c : keys)
+ send(c);
+}
+
+
PS2Keyboard *
PS2KeyboardParams::create()
{
diff --git a/src/dev/ps2/keyboard.hh b/src/dev/ps2/keyboard.hh
index 8943e7f..f5d8304 100644
--- a/src/dev/ps2/keyboard.hh
+++ b/src/dev/ps2/keyboard.hh
@@ -44,11 +44,12 @@
#ifndef __DEV_PS2_KEYBOARD_HH__
#define __DEV_PS2_KEYBOARD_HH__
+#include "base/vnc/vncinput.hh"
#include "dev/ps2/device.hh"
struct PS2KeyboardParams;
-class PS2Keyboard : public PS2Device
+class PS2Keyboard : public PS2Device, VncKeyboard
{
protected:
static const uint8_t ID[];
@@ -78,6 +79,12 @@
uint16_t lastCommand;
+ /** is the shift key currently down */
+ bool shiftDown;
+
+ /** Is the device enabled? */
+ bool enabled;
+
public:
PS2Keyboard(const PS2KeyboardParams *p);
@@ -86,6 +93,9 @@
protected: // PS2Device
void recv(uint8_t data) override;
+
+ public: // VncKeyboard
+ void keyPress(uint32_t key, bool down) override;
};
#endif // __DEV_PS2_KEYBOARD_hH__
--
To view, visit https://gem5-review.googlesource.com/9763
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: If04a9713e5a15e2149d1a7471b999e3060d8ee7d
Gerrit-Change-Number: 9763
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev