ps2: Unify constant names
authorAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 10 Apr 2018 08:22:02 +0000 (09:22 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 17 Apr 2018 12:24:17 +0000 (12:24 +0000)
Move ps2.hh to dev/ps2/types.hh and update the device models to
consistently use well-known constants from this header.

Change-Id: Iadfdc774495957beb82f3d341107b1e9232ffd4c
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/9770
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

14 files changed:
src/dev/SConscript
src/dev/arm/kmi.cc
src/dev/ps2.cc [deleted file]
src/dev/ps2.hh [deleted file]
src/dev/ps2/SConscript
src/dev/ps2/device.cc
src/dev/ps2/keyboard.cc
src/dev/ps2/keyboard.hh
src/dev/ps2/mouse.cc
src/dev/ps2/mouse.hh
src/dev/ps2/touchkit.cc
src/dev/ps2/touchkit.hh
src/dev/ps2/types.cc [new file with mode: 0644]
src/dev/ps2/types.hh [new file with mode: 0644]

index 6939e03d19c383fa2bfa5499f25a51b427af2ca5..c9526c2a9cffd10650382e4e529c597ebcdf1077 100644 (file)
@@ -50,7 +50,6 @@ Source('intel_8254_timer.cc')
 Source('mc146818.cc')
 Source('pixelpump.cc')
 Source('platform.cc')
-Source('ps2.cc')
 
 DebugFlag('Intel8254Timer')
 DebugFlag('MC146818')
index d80bc14e98414a3e87450d02f044bc6357aa29ef..1636d5d62e8de052479916c599cbb8d9107cbf48 100644 (file)
@@ -47,7 +47,6 @@
 #include "base/vnc/vncinput.hh"
 #include "debug/Pl050.hh"
 #include "dev/arm/amba_device.hh"
-#include "dev/ps2.hh"
 #include "dev/ps2/device.hh"
 #include "mem/packet.hh"
 #include "mem/packet_access.hh"
diff --git a/src/dev/ps2.cc b/src/dev/ps2.cc
deleted file mode 100644 (file)
index 0d60527..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (c) 2011 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder.  You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Ali Saidi
- */
-
-#include "dev/ps2.hh"
-
-#include <list>
-
-#include "base/logging.hh"
-#include "x11keysym/keysym.h"
-
-namespace Ps2 {
-
-/** Table to convert simple key symbols (0x00XX) into ps2 bytes. Lower byte
- * is the scan code to send and upper byte is if a modifier is required to
- * generate it. The table generates us keyboard codes, (e.g. the guest is
- * supposed to recognize the keyboard as en_US). A new table would be required
- * for another locale.
- */
-
-static const uint16_t keySymToPs2Byte[128] = {
-// 0 / 8   1 / 9   2 / A   3 / B   4 / C   5 / D   6 / E   7 / F
-   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00-0x07
-   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x08-0x0f
-   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10-0x17
-   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x18-0x1f
-   0x0029, 0x0116, 0x0152, 0x0126, 0x0125, 0x012e, 0x013d, 0x0052, // 0x20-0x27
-   0x0146, 0x0145, 0x013e, 0x0155, 0x0041, 0x004e, 0x0049, 0x004a, // 0x28-0x2f
-   0x0045, 0x0016, 0x001e, 0x0026, 0x0025, 0x002e, 0x0036, 0x003d, // 0x30-0x37
-   0x003e, 0x0046, 0x014c, 0x004c, 0x0141, 0x0055, 0x0149, 0x014a, // 0x38-0x3f
-   0x011e, 0x011c, 0x0132, 0x0121, 0x0123, 0x0124, 0x012b, 0x0134, // 0x40-0x47
-   0x0133, 0x0143, 0x013b, 0x0142, 0x014b, 0x013a, 0x0131, 0x0144, // 0x48-0x4f
-   0x014d, 0x0115, 0x012d, 0x011b, 0x012c, 0x013c, 0x012a, 0x011d, // 0x50-0x57
-   0x0122, 0x0135, 0x011a, 0x0054, 0x005d, 0x005b, 0x0136, 0x014e, // 0x58-0x5f
-   0x000e, 0x001c, 0x0032, 0x0021, 0x0023, 0x0024, 0x002b, 0x0034, // 0x60-0x67
-   0x0033, 0x0043, 0x003b, 0x0042, 0x004b, 0x003a, 0x0031, 0x0044, // 0x68-0x6f
-   0x004d, 0x0015, 0x002d, 0x001b, 0x002c, 0x003c, 0x002a, 0x001d, // 0x70-0x77
-   0x0022, 0x0035, 0x001a, 0x0154, 0x015d, 0x015b, 0x010e, 0x0000  // 0x78-0x7f
-};
-
-const uint8_t ShiftKey = 0x12;
-const uint8_t BreakKey = 0xf0;
-const uint8_t ExtendedKey = 0xe0;
-const uint32_t UpperKeys = 0xff00;
-
-void
-keySymToPs2(uint32_t key, bool down, bool &cur_shift,
-        std::list<uint8_t> &keys)
-{
-    if (key <= XK_asciitilde) {
-        uint16_t tmp = keySymToPs2Byte[key];
-        uint8_t code = tmp & 0xff;
-        bool shift = tmp >> 8;
-
-        if (down) {
-            if (!cur_shift && shift) {
-                keys.push_back(ShiftKey);
-                cur_shift = true;
-            }
-            keys.push_back(code);
-        } else {
-            if (cur_shift && !shift) {
-                keys.push_back(BreakKey);
-                keys.push_back(ShiftKey);
-                cur_shift = false;
-            }
-            keys.push_back(BreakKey);
-            keys.push_back(code);
-        }
-    } else {
-        if ((key & UpperKeys) == UpperKeys) {
-            bool extended = false;
-            switch (key) {
-              case XK_BackSpace:
-                keys.push_back(0x66);
-                break;
-              case XK_Tab:
-                keys.push_back(0x0d);
-                break;
-              case XK_Return:
-                keys.push_back(0x5a);
-                break;
-             case XK_Escape:
-                keys.push_back(0x76);
-                break;
-             case XK_Delete:
-                extended = true;
-                keys.push_back(0x71);
-                break;
-             case XK_Home:
-                extended = true;
-                keys.push_back(0x6c);
-                break;
-             case XK_Left:
-                extended = true;
-                keys.push_back(0x6b);
-                break;
-             case XK_Right:
-                extended = true;
-                keys.push_back(0x74);
-                break;
-             case XK_Down:
-                extended = true;
-                keys.push_back(0x72);
-                break;
-             case XK_Up:
-                extended = true;
-                keys.push_back(0x75);
-                break;
-             case XK_Page_Up:
-                extended = true;
-                keys.push_back(0x7d);
-                break;
-             case XK_Page_Down:
-                extended = true;
-                keys.push_back(0x7a);
-                break;
-             case XK_End:
-                extended = true;
-                keys.push_back(0x69);
-                break;
-             case XK_Shift_L:
-                keys.push_back(0x12);
-                if (down)
-                    cur_shift = true;
-                else
-                    cur_shift = false;
-                break;
-             case XK_Shift_R:
-                keys.push_back(0x59);
-                if (down)
-                    cur_shift = true;
-                else
-                    cur_shift = false;
-                break;
-             case XK_Control_L:
-                keys.push_back(0x14);
-                break;
-             case XK_Control_R:
-                extended = true;
-                keys.push_back(0x14);
-                break;
-             case XK_Alt_L:
-                keys.push_back(0x11);
-                break;
-             case XK_Alt_R:
-                extended = true;
-                keys.push_back(0x11);
-                break;
-             default:
-               warn("Unknown extended key %#x\n", key);
-               return;
-            }
-
-            if (extended) {
-                if (down) {
-                    keys.push_front(ExtendedKey);
-                } else {
-                    keys.push_front(BreakKey);
-                    keys.push_front(ExtendedKey);
-                }
-            } else {
-                if (!down)
-                    keys.push_front(BreakKey);
-            }
-        } // upper keys
-    } // extended keys
-    return;
-}
-
-} /* namespace Ps2 */
-
diff --git a/src/dev/ps2.hh b/src/dev/ps2.hh
deleted file mode 100644 (file)
index 7b57835..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2011 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder.  You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Ali Saidi
- */
-
-#ifndef __DEV_PS2_HH__
-#define __DEV_PS2_HH__
-
-#include <stdint.h>
-#include <list>
-
-#include "base/bitunion.hh"
-
-/** @file misc functions and constants required to interface with or emulate ps2
- * devices
- */
-
-namespace Ps2 {
-enum {
-    Ps2Reset        = 0xff,
-    SelfTestPass    = 0xAA,
-    SetStatusLed    = 0xed,
-    SetResolution   = 0xe8,
-    StatusRequest   = 0xe9,
-    SetScaling1_2   = 0xe7,
-    SetScaling1_1   = 0xe6,
-    ReadId          = 0xf2,
-    TpReadId        = 0xe1,
-    Ack             = 0xfa,
-    Resend          = 0xfe,
-    SetRate         = 0xf3,
-    Enable          = 0xf4,
-    Disable         = 0xf5,
-    SetDefaults     = 0xf6,
-    KeyboardId      = 0xab,
-    TouchKitId      = 0x0a,
-    MouseId         = 0x00,
-};
-
-/** A bitfield that represents the first byte of a mouse movement packet
- */
-BitUnion8(Ps2MouseMovement)
-    Bitfield<0> leftButton;
-    Bitfield<1> rightButton;
-    Bitfield<2> middleButton;
-    Bitfield<3> one;
-    Bitfield<4> xSign;
-    Bitfield<5> ySign;
-    Bitfield<6> xOverflow;
-    Bitfield<7> yOverflow;
-EndBitUnion(Ps2MouseMovement)
-
-/** Convert an x11 key symbol into a set of ps2 charecters.
- * @param key x11 key symbol
- * @param down if the key is being pressed or released
- * @param cur_shift if device has already sent a shift
- * @param keys list of keys command to send to emulate the x11 key symbol
- */
-void keySymToPs2(uint32_t key, bool down, bool &cur_shift,
-        std::list<uint8_t> &keys);
-
-} /* namespace Ps2 */
-#endif // __DEV_PS2_HH__
index a73e47a1fb3707d13bd06d73d81011cb5b01071e..59bc242e6264f12d671310e58042bda84e58ba85 100644 (file)
@@ -47,5 +47,6 @@ Source('device.cc')
 Source('keyboard.cc')
 Source('mouse.cc')
 Source('touchkit.cc')
+Source('types.cc')
 
 DebugFlag('PS2')
index c4d33d5054827c40a559a51c98ecd5436bad061e..eb13f81063143e0e91401e34cbefb015f8fc3877 100644 (file)
@@ -45,7 +45,7 @@
 
 #include "base/logging.hh"
 #include "debug/PS2.hh"
-#include "dev/ps2.hh"
+#include "dev/ps2/types.hh"
 #include "params/PS2Device.hh"
 
 PS2Device::PS2Device(const PS2DeviceParams *p)
index c9bc21986061d43b4d972d5f272ed42bbc6af908..c7d5c1fabc04e0376441fb714199f6090d490fed 100644 (file)
 
 #include "base/logging.hh"
 #include "debug/PS2.hh"
-#include "dev/ps2.hh"
+#include "dev/ps2/types.hh"
 #include "params/PS2Keyboard.hh"
 
-const uint8_t PS2Keyboard::ID[] = {0xab, 0x83};
-
 PS2Keyboard::PS2Keyboard(const PS2KeyboardParams *p)
     : PS2Device(p),
       shiftDown(false),
@@ -79,7 +77,36 @@ bool
 PS2Keyboard::recv(const std::vector<uint8_t> &data)
 {
     switch (data[0]) {
-      case LEDWrite:
+      case Ps2::ReadID:
+        DPRINTF(PS2, "Got keyboard read ID command.\n");
+        sendAck();
+        send(Ps2::Keyboard::ID);
+        return true;
+      case Ps2::Enable:
+        DPRINTF(PS2, "Enabling the keyboard.\n");
+        enabled = true;
+        sendAck();
+        return true;
+      case Ps2::Disable:
+        DPRINTF(PS2, "Disabling the keyboard.\n");
+        enabled = false;
+        sendAck();
+        return true;
+      case Ps2::DefaultsAndDisable:
+        DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
+        enabled = false;
+        sendAck();
+        return true;
+      case Ps2::Reset:
+        DPRINTF(PS2, "Resetting keyboard.\n");
+        enabled = true;
+        sendAck();
+        send(Ps2::SelfTestPass);
+        return true;
+      case Ps2::Resend:
+        panic("Keyboard resend unimplemented.\n");
+
+      case Ps2::Keyboard::LEDWrite:
         if (data.size() == 1) {
             DPRINTF(PS2, "Got LED write command.\n");
             sendAck();
@@ -93,16 +120,11 @@ PS2Keyboard::recv(const std::vector<uint8_t> &data)
             sendAck();
             return true;
         }
-      case DiagnosticEcho:
+      case Ps2::Keyboard::DiagnosticEcho:
         panic("Keyboard diagnostic echo unimplemented.\n");
-      case AlternateScanCodes:
+      case Ps2::Keyboard::AlternateScanCodes:
         panic("Accessing alternate scan codes unimplemented.\n");
-      case ReadID:
-        DPRINTF(PS2, "Got keyboard read ID command.\n");
-        sendAck();
-        send((uint8_t *)&ID, sizeof(ID));
-        return true;
-      case TypematicInfo:
+      case Ps2::Keyboard::TypematicInfo:
         if (data.size() == 1) {
             DPRINTF(PS2, "Setting typematic info.\n");
             sendAck();
@@ -112,44 +134,21 @@ PS2Keyboard::recv(const std::vector<uint8_t> &data)
             sendAck();
             return true;
         }
-      case Enable:
-        DPRINTF(PS2, "Enabling the keyboard.\n");
-        enabled = true;
-        sendAck();
-        return true;
-      case Disable:
-        DPRINTF(PS2, "Disabling the keyboard.\n");
-        enabled = false;
-        sendAck();
-        return true;
-      case DefaultsAndDisable:
-        DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
-        enabled = false;
-        sendAck();
-        return true;
-      case Reset:
-        DPRINTF(PS2, "Resetting keyboard.\n");
-        sendAck();
-        enabled = true;
-        send(Ps2::SelfTestPass);
-        return true;
-      case AllKeysToTypematic:
+      case Ps2::Keyboard::AllKeysToTypematic:
         panic("Setting all keys to typemantic unimplemented.\n");
-      case AllKeysToMakeRelease:
+      case Ps2::Keyboard::AllKeysToMakeRelease:
         panic("Setting all keys to make/release unimplemented.\n");
-      case AllKeysToMake:
+      case Ps2::Keyboard::AllKeysToMake:
         panic("Setting all keys to make unimplemented.\n");
-      case AllKeysToTypematicMakeRelease:
+      case Ps2::Keyboard::AllKeysToTypematicMakeRelease:
         panic("Setting all keys to "
                 "typematic/make/release unimplemented.\n");
-      case KeyToTypematic:
+      case Ps2::Keyboard::KeyToTypematic:
         panic("Setting a key to typematic unimplemented.\n");
-      case KeyToMakeRelease:
+      case Ps2::Keyboard::KeyToMakeRelease:
         panic("Setting a key to make/release unimplemented.\n");
-      case KeyToMakeOnly:
+      case Ps2::Keyboard::KeyToMakeOnly:
         panic("Setting key to make only unimplemented.\n");
-      case Resend:
-        panic("Keyboard resend unimplemented.\n");
       default:
         panic("Unknown keyboard command %#02x.\n", data[0]);
     }
index 33db1cc76ff827921d70b98fc3b5c841dba2d225..ae0ca85e6e7387ccc1f72c9cfbe1f3ae8429aab8 100644 (file)
@@ -52,30 +52,6 @@ struct PS2KeyboardParams;
 class PS2Keyboard : public PS2Device, VncKeyboard
 {
   protected:
-    static const uint8_t ID[];
-
-    enum Command
-    {
-        LEDWrite = 0xED,
-        DiagnosticEcho = 0xEE,
-        AlternateScanCodes = 0xF0,
-        ReadID = 0xF2,
-        TypematicInfo = 0xF3,
-        Enable = 0xF4,
-        Disable = 0xF5,
-        DefaultsAndDisable = 0xF6,
-        AllKeysToTypematic = 0xF7,
-        AllKeysToMakeRelease = 0xF8,
-        AllKeysToMake = 0xF9,
-        AllKeysToTypematicMakeRelease = 0xFA,
-        KeyToTypematic = 0xFB,
-        KeyToMakeRelease = 0xFC,
-        KeyToMakeOnly = 0xFD,
-        Resend = 0xFE,
-        Reset = 0xFF
-    };
-
-
     /** is the shift key currently down */
     bool shiftDown;
 
index 5b6765bcca0a5bbecb2c7a40b50546230667f1e3..ac8d0ae6a4fd0d4022395a009f6f07540018db8a 100644 (file)
 
 #include "base/logging.hh"
 #include "debug/PS2.hh"
+#include "dev/ps2/types.hh"
 #include "params/PS2Mouse.hh"
 
-const uint8_t PS2Mouse::ID[] = {0x00};
-const uint8_t BatSuccessful = 0xaa;
-
 PS2Mouse::PS2Mouse(const PS2MouseParams *p)
     : PS2Device(p),
       status(0), resolution(4), sampleRate(100)
@@ -60,17 +58,45 @@ bool
 PS2Mouse::recv(const std::vector<uint8_t> &data)
 {
     switch (data[0]) {
-      case Scale1to1:
+      case Ps2::ReadID:
+        DPRINTF(PS2, "Mouse ID requested.\n");
+        sendAck();
+        send(Ps2::Mouse::ID);
+        return true;
+      case Ps2::Disable:
+        DPRINTF(PS2, "Disabling data reporting.\n");
+        status.enabled = 0;
+        sendAck();
+        return true;
+      case Ps2::Enable:
+        DPRINTF(PS2, "Enabling data reporting.\n");
+        status.enabled = 1;
+        sendAck();
+        return true;
+      case Ps2::Resend:
+        panic("Mouse resend unimplemented.\n");
+      case Ps2::Reset:
+        DPRINTF(PS2, "Resetting the mouse.\n");
+        sampleRate = 100;
+        resolution = 4;
+        status.twoToOne = 0;
+        status.enabled = 0;
+        sendAck();
+        send(Ps2::SelfTestPass);
+        send(Ps2::Mouse::ID);
+        return true;
+
+      case Ps2::Mouse::Scale1to1:
         DPRINTF(PS2, "Setting mouse scale to 1:1.\n");
         status.twoToOne = 0;
         sendAck();
         return true;
-      case Scale2to1:
+      case Ps2::Mouse::Scale2to1:
         DPRINTF(PS2, "Setting mouse scale to 2:1.\n");
         status.twoToOne = 1;
         sendAck();
         return true;
-      case SetResolution:
+      case Ps2::Mouse::SetResolution:
         if (data.size() == 1) {
             DPRINTF(PS2, "Setting mouse resolution.\n");
             sendAck();
@@ -81,27 +107,22 @@ PS2Mouse::recv(const std::vector<uint8_t> &data)
             sendAck();
             return true;
         }
-      case GetStatus:
+      case Ps2::Mouse::GetStatus:
         DPRINTF(PS2, "Getting mouse status.\n");
         sendAck();
         send((uint8_t *)&(status), 1);
         send(&resolution, sizeof(resolution));
         send(&sampleRate, sizeof(sampleRate));
         return true;
-      case ReadData:
+      case Ps2::Mouse::ReadData:
         panic("Reading mouse data unimplemented.\n");
-      case ResetWrapMode:
+      case Ps2::Mouse::ResetWrapMode:
         panic("Resetting mouse wrap mode unimplemented.\n");
-      case WrapMode:
+      case Ps2::Mouse::WrapMode:
         panic("Setting mouse wrap mode unimplemented.\n");
-      case RemoteMode:
+      case Ps2::Mouse::RemoteMode:
         panic("Setting mouse remote mode unimplemented.\n");
-      case ReadID:
-        DPRINTF(PS2, "Mouse ID requested.\n");
-        sendAck();
-        send(ID, sizeof(ID));
-        return true;
-      case SampleRate:
+      case Ps2::Mouse::SampleRate:
         if (data.size() == 1) {
             DPRINTF(PS2, "Setting mouse sample rate.\n");
             sendAck();
@@ -113,17 +134,7 @@ PS2Mouse::recv(const std::vector<uint8_t> &data)
             sendAck();
             return true;
         }
-      case DisableReporting:
-        DPRINTF(PS2, "Disabling data reporting.\n");
-        status.enabled = 0;
-        sendAck();
-        return true;
-      case EnableReporting:
-        DPRINTF(PS2, "Enabling data reporting.\n");
-        status.enabled = 1;
-        sendAck();
-        return true;
-      case DefaultsAndDisable:
+      case Ps2::DefaultsAndDisable:
         DPRINTF(PS2, "Disabling and resetting mouse.\n");
         sampleRate = 100;
         resolution = 4;
@@ -131,21 +142,9 @@ PS2Mouse::recv(const std::vector<uint8_t> &data)
         status.enabled = 0;
         sendAck();
         return true;
-      case Resend:
-        panic("Mouse resend unimplemented.\n");
-      case Reset:
-        DPRINTF(PS2, "Resetting the mouse.\n");
-        sampleRate = 100;
-        resolution = 4;
-        status.twoToOne = 0;
-        status.enabled = 0;
-        sendAck();
-        send(&BatSuccessful, sizeof(BatSuccessful));
-        send(ID, sizeof(ID));
-        return true;
       default:
         warn("Unknown mouse command %#02x.\n", data[0]);
-        send(Resend);
+        send(Ps2::Resend);
         return true;
     }
 }
index 9150f3f8f8b8a7f505a7408605b8ddbaf02840f5..c1a49717370d4476e6aae9ec6a2c65aed20eaa58 100644 (file)
@@ -51,27 +51,6 @@ struct PS2MouseParams;
 class PS2Mouse : public PS2Device
 {
   protected:
-    static const uint8_t ID[];
-
-    enum Command
-    {
-        Scale1to1 = 0xE6,
-        Scale2to1 = 0xE7,
-        SetResolution = 0xE8,
-        GetStatus = 0xE9,
-        ReadData = 0xEB,
-        ResetWrapMode = 0xEC,
-        WrapMode = 0xEE,
-        RemoteMode = 0xF0,
-        ReadID = 0xF2,
-        SampleRate = 0xF3,
-        EnableReporting = 0xF4,
-        DisableReporting = 0xF5,
-        DefaultsAndDisable = 0xF6,
-        Resend = 0xFE,
-        Reset = 0xFF
-    };
-
     BitUnion8(Status)
         Bitfield<6> remote;
         Bitfield<5> enabled;
index 819b06c5da0a46c5547cc8ce79c2ba0a91bbfccf..69387cfb40239f217a5066c39d325e565c4c72bd 100644 (file)
 
 #include "base/logging.hh"
 #include "debug/PS2.hh"
-#include "dev/ps2.hh"
+#include "dev/ps2/types.hh"
 #include "params/PS2TouchKit.hh"
 
-const uint8_t PS2TouchKit::ID[] = {0x00};
-
 PS2TouchKit::PS2TouchKit(const PS2TouchKitParams *p)
     : PS2Device(p),
       vnc(p->vnc),
@@ -82,7 +80,7 @@ bool
 PS2TouchKit::recv(const std::vector<uint8_t> &data)
 {
     switch (data[0]) {
-      case Ps2::Ps2Reset:
+      case Ps2::Reset:
         DPRINTF(PS2, "Resetting device.\n");
         enabled = false;
         touchKitEnabled = false;
@@ -90,29 +88,9 @@ PS2TouchKit::recv(const std::vector<uint8_t> &data)
         send(Ps2::SelfTestPass);
         return true;
 
-      case Ps2::SetResolution:
-      case Ps2::SetRate:
-      case Ps2::SetStatusLed:
-        sendAck();
-        return data.size() == 2;
-
-      case Ps2::ReadId:
-        sendAck();
-        send((const uint8_t *)&ID, sizeof(ID));
-        return true;
-
-      case Ps2::TpReadId:
-        // We're not a trackpoint device, this should make the probe
-        // go away
-        sendAck();
-        send(0);
-        send(0);
-        sendAck();
-        return true;
-
-      case Ps2::SetScaling1_1:
-      case Ps2::SetScaling1_2:
+      case Ps2::ReadID:
         sendAck();
+        send(Ps2::Mouse::ID);
         return true;
 
       case Ps2::Disable:
@@ -127,20 +105,39 @@ PS2TouchKit::recv(const std::vector<uint8_t> &data)
         sendAck();
         return true;
 
-      case Ps2::SetDefaults:
+      case Ps2::DefaultsAndDisable:
         DPRINTF(PS2, "Setting defaults and disabling device.\n");
         enabled = false;
         sendAck();
         return true;
 
-      case Ps2::StatusRequest:
+      case Ps2::Mouse::Scale1to1:
+      case Ps2::Mouse::Scale2to1:
+        sendAck();
+        return true;
+
+      case Ps2::Mouse::SetResolution:
+      case Ps2::Mouse::SampleRate:
+        sendAck();
+        return data.size() == 2;
+
+      case Ps2::Mouse::GetStatus:
         sendAck();
         send(0);
         send(2); // default resolution
         send(100); // default sample rate
         return true;
 
-      case Ps2::TouchKitId:
+      case TpReadId:
+        // We're not a trackpoint device, this should make the probe
+        // go away
+        sendAck();
+        send(0);
+        send(0);
+        sendAck();
+        return true;
+
+      case TouchKitDiag:
         return recvTouchKit(data);
 
       default:
@@ -155,7 +152,7 @@ PS2TouchKit::recvTouchKit(const std::vector<uint8_t> &data)
     sendAck();
 
     // Packet format is: 0x0A SIZE CMD DATA
-    assert(data[0] == Ps2::TouchKitId);
+    assert(data[0] == TouchKitDiag);
     if (data.size() < 3 || data.size() - 2 < data[1])
         return false;
 
@@ -181,7 +178,7 @@ PS2TouchKit::recvTouchKit(const std::vector<uint8_t> &data)
 void
 PS2TouchKit::sendTouchKit(const uint8_t *data, size_t size)
 {
-    send(Ps2::TouchKitId);
+    send(TouchKitDiag);
     send(size);
     for (int i = 0; i < size; ++i)
         send(data[i]);
index dc98a78fac73e93a96aad6d42a31606d7a80dbe1..aa413a5990a4859cee8c32552c5ce0c5ef0e0e2f 100644 (file)
@@ -48,7 +48,10 @@ struct PS2TouchKitParams;
 class PS2TouchKit : public PS2Device, public VncMouse
 {
   protected:
-    static const uint8_t ID[];
+    enum PS2Commands {
+        TpReadId = 0xE1,
+        TouchKitDiag = 0x0A,
+    };
 
     enum TKCommands {
         TouchKitActive = 'A',
diff --git a/src/dev/ps2/types.cc b/src/dev/ps2/types.cc
new file mode 100644 (file)
index 0000000..d921d74
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2011, 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Ali Saidi
+ */
+
+#include "dev/ps2/types.hh"
+
+#include <list>
+
+#include "base/logging.hh"
+#include "x11keysym/keysym.h"
+
+const std::vector<uint8_t> Ps2::Keyboard::ID{0xAB, 0x83};
+const std::vector<uint8_t> Ps2::Mouse::ID{0x00};
+
+namespace Ps2 {
+
+/** Table to convert simple key symbols (0x00XX) into ps2 bytes. Lower byte
+ * is the scan code to send and upper byte is if a modifier is required to
+ * generate it. The table generates us keyboard codes, (e.g. the guest is
+ * supposed to recognize the keyboard as en_US). A new table would be required
+ * for another locale.
+ */
+
+static const uint16_t keySymToPs2Byte[128] = {
+// 0 / 8   1 / 9   2 / A   3 / B   4 / C   5 / D   6 / E   7 / F
+   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00-0x07
+   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x08-0x0f
+   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10-0x17
+   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x18-0x1f
+   0x0029, 0x0116, 0x0152, 0x0126, 0x0125, 0x012e, 0x013d, 0x0052, // 0x20-0x27
+   0x0146, 0x0145, 0x013e, 0x0155, 0x0041, 0x004e, 0x0049, 0x004a, // 0x28-0x2f
+   0x0045, 0x0016, 0x001e, 0x0026, 0x0025, 0x002e, 0x0036, 0x003d, // 0x30-0x37
+   0x003e, 0x0046, 0x014c, 0x004c, 0x0141, 0x0055, 0x0149, 0x014a, // 0x38-0x3f
+   0x011e, 0x011c, 0x0132, 0x0121, 0x0123, 0x0124, 0x012b, 0x0134, // 0x40-0x47
+   0x0133, 0x0143, 0x013b, 0x0142, 0x014b, 0x013a, 0x0131, 0x0144, // 0x48-0x4f
+   0x014d, 0x0115, 0x012d, 0x011b, 0x012c, 0x013c, 0x012a, 0x011d, // 0x50-0x57
+   0x0122, 0x0135, 0x011a, 0x0054, 0x005d, 0x005b, 0x0136, 0x014e, // 0x58-0x5f
+   0x000e, 0x001c, 0x0032, 0x0021, 0x0023, 0x0024, 0x002b, 0x0034, // 0x60-0x67
+   0x0033, 0x0043, 0x003b, 0x0042, 0x004b, 0x003a, 0x0031, 0x0044, // 0x68-0x6f
+   0x004d, 0x0015, 0x002d, 0x001b, 0x002c, 0x003c, 0x002a, 0x001d, // 0x70-0x77
+   0x0022, 0x0035, 0x001a, 0x0154, 0x015d, 0x015b, 0x010e, 0x0000  // 0x78-0x7f
+};
+
+const uint8_t ShiftKey = 0x12;
+const uint8_t BreakKey = 0xf0;
+const uint8_t ExtendedKey = 0xe0;
+const uint32_t UpperKeys = 0xff00;
+
+void
+keySymToPs2(uint32_t key, bool down, bool &cur_shift,
+        std::list<uint8_t> &keys)
+{
+    if (key <= XK_asciitilde) {
+        uint16_t tmp = keySymToPs2Byte[key];
+        uint8_t code = tmp & 0xff;
+        bool shift = tmp >> 8;
+
+        if (down) {
+            if (!cur_shift && shift) {
+                keys.push_back(ShiftKey);
+                cur_shift = true;
+            }
+            keys.push_back(code);
+        } else {
+            if (cur_shift && !shift) {
+                keys.push_back(BreakKey);
+                keys.push_back(ShiftKey);
+                cur_shift = false;
+            }
+            keys.push_back(BreakKey);
+            keys.push_back(code);
+        }
+    } else {
+        if ((key & UpperKeys) == UpperKeys) {
+            bool extended = false;
+            switch (key) {
+              case XK_BackSpace:
+                keys.push_back(0x66);
+                break;
+              case XK_Tab:
+                keys.push_back(0x0d);
+                break;
+              case XK_Return:
+                keys.push_back(0x5a);
+                break;
+             case XK_Escape:
+                keys.push_back(0x76);
+                break;
+             case XK_Delete:
+                extended = true;
+                keys.push_back(0x71);
+                break;
+             case XK_Home:
+                extended = true;
+                keys.push_back(0x6c);
+                break;
+             case XK_Left:
+                extended = true;
+                keys.push_back(0x6b);
+                break;
+             case XK_Right:
+                extended = true;
+                keys.push_back(0x74);
+                break;
+             case XK_Down:
+                extended = true;
+                keys.push_back(0x72);
+                break;
+             case XK_Up:
+                extended = true;
+                keys.push_back(0x75);
+                break;
+             case XK_Page_Up:
+                extended = true;
+                keys.push_back(0x7d);
+                break;
+             case XK_Page_Down:
+                extended = true;
+                keys.push_back(0x7a);
+                break;
+             case XK_End:
+                extended = true;
+                keys.push_back(0x69);
+                break;
+             case XK_Shift_L:
+                keys.push_back(0x12);
+                if (down)
+                    cur_shift = true;
+                else
+                    cur_shift = false;
+                break;
+             case XK_Shift_R:
+                keys.push_back(0x59);
+                if (down)
+                    cur_shift = true;
+                else
+                    cur_shift = false;
+                break;
+             case XK_Control_L:
+                keys.push_back(0x14);
+                break;
+             case XK_Control_R:
+                extended = true;
+                keys.push_back(0x14);
+                break;
+             case XK_Alt_L:
+                keys.push_back(0x11);
+                break;
+             case XK_Alt_R:
+                extended = true;
+                keys.push_back(0x11);
+                break;
+             default:
+               warn("Unknown extended key %#x\n", key);
+               return;
+            }
+
+            if (extended) {
+                if (down) {
+                    keys.push_front(ExtendedKey);
+                } else {
+                    keys.push_front(BreakKey);
+                    keys.push_front(ExtendedKey);
+                }
+            } else {
+                if (!down)
+                    keys.push_front(BreakKey);
+            }
+        } // upper keys
+    } // extended keys
+    return;
+}
+
+} /* namespace Ps2 */
+
diff --git a/src/dev/ps2/types.hh b/src/dev/ps2/types.hh
new file mode 100644 (file)
index 0000000..1fb3679
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2011, 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Ali Saidi
+ */
+
+#ifndef __DEV_PS2_HH__
+#define __DEV_PS2_HH__
+
+#include <stdint.h>
+
+#include <list>
+#include <vector>
+
+#include "base/bitunion.hh"
+
+/** @file misc functions and constants required to interface with or
+ * emulate ps2 devices
+ */
+
+namespace Ps2 {
+
+enum {
+    SelfTestPass       = 0xAA,
+    ReadID             = 0xF2,
+    Enable             = 0xF4,
+    Disable            = 0xF5,
+    DefaultsAndDisable = 0xF6,
+    SelfTestFail       = 0xFC,
+    Ack                = 0xFA,
+    Resend             = 0xFE,
+    Reset              = 0xFF,
+};
+
+namespace Keyboard {
+
+enum {
+    LEDWrite = 0xED,
+    DiagnosticEcho = 0xEE,
+    AlternateScanCodes = 0xF0,
+    TypematicInfo = 0xF3,
+    AllKeysToTypematic = 0xF7,
+    AllKeysToMakeRelease = 0xF8,
+    AllKeysToMake = 0xF9,
+    AllKeysToTypematicMakeRelease = 0xFA,
+    KeyToTypematic = 0xFB,
+    KeyToMakeRelease = 0xFC,
+    KeyToMakeOnly = 0xFD,
+};
+
+extern const std::vector<uint8_t> ID;
+
+};
+
+namespace Mouse {
+
+enum {
+    Scale1to1 = 0xE6,
+    Scale2to1 = 0xE7,
+    SetResolution = 0xE8,
+    GetStatus = 0xE9,
+    ReadData = 0xEB,
+    ResetWrapMode = 0xEC,
+    WrapMode = 0xEE,
+    RemoteMode = 0xF0,
+    SampleRate = 0xF3,
+};
+
+extern const std::vector<uint8_t> ID;
+
+};
+
+/** A bitfield that represents the first byte of a mouse movement packet
+ */
+BitUnion8(Ps2MouseMovement)
+    Bitfield<0> leftButton;
+    Bitfield<1> rightButton;
+    Bitfield<2> middleButton;
+    Bitfield<3> one;
+    Bitfield<4> xSign;
+    Bitfield<5> ySign;
+    Bitfield<6> xOverflow;
+    Bitfield<7> yOverflow;
+EndBitUnion(Ps2MouseMovement)
+
+/** Convert an x11 key symbol into a set of ps2 charecters.
+ * @param key x11 key symbol
+ * @param down if the key is being pressed or released
+ * @param cur_shift if device has already sent a shift
+ * @param keys list of keys command to send to emulate the x11 key symbol
+ */
+void keySymToPs2(uint32_t key, bool down, bool &cur_shift,
+        std::list<uint8_t> &keys);
+
+} /* namespace Ps2 */
+#endif // __DEV_PS2_HH__