Hello Giacomo Travaglini,

I'd like you to do a code review. Please visit

    https://gem5-review.googlesource.com/9770

to review the following change.


Change subject: ps2: Unify constant names
......................................................................

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 <andreas.sandb...@arm.com>
Reviewed-by: Giacomo Travaglini <giacomo.travagl...@arm.com>
---
M src/dev/SConscript
M src/dev/arm/kmi.cc
M src/dev/ps2/SConscript
M src/dev/ps2/device.cc
M src/dev/ps2/keyboard.cc
M src/dev/ps2/keyboard.hh
M src/dev/ps2/mouse.cc
M src/dev/ps2/mouse.hh
M src/dev/ps2/touchkit.cc
M src/dev/ps2/touchkit.hh
R src/dev/ps2/types.cc
R src/dev/ps2/types.hh
12 files changed, 167 insertions(+), 174 deletions(-)



diff --git a/src/dev/SConscript b/src/dev/SConscript
index 6939e03..c9526c2 100644
--- a/src/dev/SConscript
+++ b/src/dev/SConscript
@@ -50,7 +50,6 @@
 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 e6e54a4..6603ef9 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/SConscript b/src/dev/ps2/SConscript
index a73e47a..59bc242 100644
--- a/src/dev/ps2/SConscript
+++ b/src/dev/ps2/SConscript
@@ -47,5 +47,6 @@
 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 073e015..8275cfc 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 78e287f..5e7dbcc 100644
--- a/src/dev/ps2/keyboard.cc
+++ b/src/dev/ps2/keyboard.cc
@@ -45,7 +45,7 @@

 #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};
@@ -79,7 +79,36 @@
 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((uint8_t *)&ID, sizeof(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 = false;
+        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 +122,11 @@
             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 +136,21 @@
             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 = false;
-        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 33db1cc..eef6e9b 100644
--- a/src/dev/ps2/keyboard.hh
+++ b/src/dev/ps2/keyboard.hh
@@ -54,28 +54,6 @@
   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 5b6765b..c5270ce 100644
--- a/src/dev/ps2/mouse.cc
+++ b/src/dev/ps2/mouse.cc
@@ -45,10 +45,10 @@

 #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),
@@ -60,17 +60,45 @@
 PS2Mouse::recv(const std::vector<uint8_t> &data)
 {
     switch (data[0]) {
-      case Scale1to1:
+      case Ps2::ReadID:
+        DPRINTF(PS2, "Mouse ID requested.\n");
+        sendAck();
+        send(ID, sizeof(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(ID, sizeof(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 +109,22 @@
             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 +136,7 @@
             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 +144,9 @@
         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 9150f3f..97af102 100644
--- a/src/dev/ps2/mouse.hh
+++ b/src/dev/ps2/mouse.hh
@@ -53,25 +53,6 @@
   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 cee4016..5935102 100644
--- a/src/dev/ps2/touchkit.cc
+++ b/src/dev/ps2/touchkit.cc
@@ -46,7 +46,7 @@

 #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};
@@ -82,7 +82,7 @@
 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,31 +90,11 @@
         send(Ps2::SelfTestPass);
         return true;

-      case Ps2::SetResolution:
-      case Ps2::SetRate:
-      case Ps2::SetStatusLed:
-        sendAck();
-        return data.size() == 2;
-
-      case Ps2::ReadId:
+      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:
-        sendAck();
-        return true;
-
       case Ps2::Disable:
         DPRINTF(PS2, "Disabling device.\n");
         enabled = false;
@@ -127,20 +107,39 @@
         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 +154,7 @@
     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 +180,7 @@
 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 1a344ec..e39682e 100644
--- a/src/dev/ps2/touchkit.hh
+++ b/src/dev/ps2/touchkit.hh
@@ -50,6 +50,11 @@
   protected:
     static const uint8_t ID[];

+    enum PS2Commands {
+        TpReadId = 0xe1,
+        TouchKitDiag = 0x0A,
+    };
+
     enum TKCommands {
         TouchKitActive = 'A',
         TouchKitFWRev = 'D',
diff --git a/src/dev/ps2.cc b/src/dev/ps2/types.cc
similarity index 98%
rename from src/dev/ps2.cc
rename to src/dev/ps2/types.cc
index 0d60527..1c53bd4 100644
--- a/src/dev/ps2.cc
+++ b/src/dev/ps2/types.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 ARM Limited
+ * Copyright (c) 2011, 2018 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -37,7 +37,7 @@
  * Authors: Ali Saidi
  */

-#include "dev/ps2.hh"
+#include "dev/ps2/types.hh"

 #include <list>

diff --git a/src/dev/ps2.hh b/src/dev/ps2/types.hh
similarity index 75%
rename from src/dev/ps2.hh
rename to src/dev/ps2/types.hh
index 7b57835..9ee498b 100644
--- a/src/dev/ps2.hh
+++ b/src/dev/ps2/types.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 ARM Limited
+ * Copyright (c) 2011, 2018 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -41,34 +41,63 @@
 #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
+/** @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,
+    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,
+};
+
+};
+
+namespace Mouse {
+
+enum {
+    Scale1to1 = 0xE6,
+    Scale2to1 = 0xE7,
+    SetResolution = 0xE8,
+    GetStatus = 0xE9,
+    ReadData = 0xEB,
+    ResetWrapMode = 0xEC,
+    WrapMode = 0xEE,
+    RemoteMode = 0xF0,
+    SampleRate = 0xF3,
+    Resend = 0xFE,
+    Reset = 0xFF
+};
+
 };

 /** A bitfield that represents the first byte of a mouse movement packet

--
To view, visit https://gem5-review.googlesource.com/9770
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: Iadfdc774495957beb82f3d341107b1e9232ffd4c
Gerrit-Change-Number: 9770
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to