From: Andreas Sandberg Date: Tue, 10 Apr 2018 08:22:02 +0000 (+0100) Subject: ps2: Unify constant names X-Git-Tag: v19.0.0.0~2159 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2c0ce271a604be0000b2f1cc1084541714e436ac;p=gem5.git ps2: Unify constant names 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 Reviewed-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/9770 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/dev/SConscript b/src/dev/SConscript index 6939e03d1..c9526c2a9 100644 --- a/src/dev/SConscript +++ b/src/dev/SConscript @@ -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') diff --git a/src/dev/arm/kmi.cc b/src/dev/arm/kmi.cc index d80bc14e9..1636d5d62 100644 --- a/src/dev/arm/kmi.cc +++ b/src/dev/arm/kmi.cc @@ -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 index 0d6052706..000000000 --- a/src/dev/ps2.cc +++ /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 - -#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 &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 index 7b5783547..000000000 --- a/src/dev/ps2.hh +++ /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 -#include - -#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 &keys); - -} /* namespace Ps2 */ -#endif // __DEV_PS2_HH__ diff --git a/src/dev/ps2/SConscript b/src/dev/ps2/SConscript index a73e47a1f..59bc242e6 100644 --- a/src/dev/ps2/SConscript +++ b/src/dev/ps2/SConscript @@ -47,5 +47,6 @@ Source('device.cc') Source('keyboard.cc') Source('mouse.cc') Source('touchkit.cc') +Source('types.cc') DebugFlag('PS2') diff --git a/src/dev/ps2/device.cc b/src/dev/ps2/device.cc index c4d33d505..eb13f8106 100644 --- a/src/dev/ps2/device.cc +++ b/src/dev/ps2/device.cc @@ -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) diff --git a/src/dev/ps2/keyboard.cc b/src/dev/ps2/keyboard.cc index c9bc21986..c7d5c1fab 100644 --- a/src/dev/ps2/keyboard.cc +++ b/src/dev/ps2/keyboard.cc @@ -45,11 +45,9 @@ #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 &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 &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 &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]); } diff --git a/src/dev/ps2/keyboard.hh b/src/dev/ps2/keyboard.hh index 33db1cc76..ae0ca85e6 100644 --- a/src/dev/ps2/keyboard.hh +++ b/src/dev/ps2/keyboard.hh @@ -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; diff --git a/src/dev/ps2/mouse.cc b/src/dev/ps2/mouse.cc index 5b6765bcc..ac8d0ae6a 100644 --- a/src/dev/ps2/mouse.cc +++ b/src/dev/ps2/mouse.cc @@ -45,11 +45,9 @@ #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 &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 &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 &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 &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; } } diff --git a/src/dev/ps2/mouse.hh b/src/dev/ps2/mouse.hh index 9150f3f8f..c1a497173 100644 --- a/src/dev/ps2/mouse.hh +++ b/src/dev/ps2/mouse.hh @@ -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; diff --git a/src/dev/ps2/touchkit.cc b/src/dev/ps2/touchkit.cc index 819b06c5d..69387cfb4 100644 --- a/src/dev/ps2/touchkit.cc +++ b/src/dev/ps2/touchkit.cc @@ -46,11 +46,9 @@ #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 &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 &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 &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 &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 &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]); diff --git a/src/dev/ps2/touchkit.hh b/src/dev/ps2/touchkit.hh index dc98a78fa..aa413a599 100644 --- a/src/dev/ps2/touchkit.hh +++ b/src/dev/ps2/touchkit.hh @@ -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 index 000000000..d921d7422 --- /dev/null +++ b/src/dev/ps2/types.cc @@ -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 + +#include "base/logging.hh" +#include "x11keysym/keysym.h" + +const std::vector Ps2::Keyboard::ID{0xAB, 0x83}; +const std::vector 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 &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 index 000000000..1fb3679fc --- /dev/null +++ b/src/dev/ps2/types.hh @@ -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 + +#include +#include + +#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 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 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 &keys); + +} /* namespace Ps2 */ +#endif // __DEV_PS2_HH__