summaryrefslogtreecommitdiff
path: root/src/dev/ps2/device.cc
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2018-04-09 20:07:52 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2018-04-17 11:16:26 +0000
commit8f94eeac0c2cd35f883944e5d552a428027a0d70 (patch)
tree2050149cbdcf34eff829e806655c08b7ac5775bc /src/dev/ps2/device.cc
parentc85d51e6d62a9591bd5b99dcb0146aae5dbee43f (diff)
downloadgem5-8f94eeac0c2cd35f883944e5d552a428027a0d70.tar.xz
ps2: Unify device data buffering
All PS/2 device currently implement various ad-hoc mechanisms to handle multi-byte commands. This is error-prone and makes it hard to implement new devices. Create a buffering mechanism in the base class to avoid this. Change-Id: If5638b0ab68decea8de7631ecead0a9ebad1547b Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/9765 Reviewed-by: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/dev/ps2/device.cc')
-rw-r--r--src/dev/ps2/device.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/dev/ps2/device.cc b/src/dev/ps2/device.cc
index deedb49bf..c4d33d505 100644
--- a/src/dev/ps2/device.cc
+++ b/src/dev/ps2/device.cc
@@ -44,12 +44,14 @@
#include "dev/ps2/device.hh"
#include "base/logging.hh"
+#include "debug/PS2.hh"
#include "dev/ps2.hh"
#include "params/PS2Device.hh"
PS2Device::PS2Device(const PS2DeviceParams *p)
: SimObject(p)
{
+ inBuffer.reserve(16);
}
void
@@ -58,6 +60,8 @@ PS2Device::serialize(CheckpointOut &cp) const
std::vector<uint8_t> buffer(outBuffer.size());
std::copy(outBuffer.begin(), outBuffer.end(), buffer.begin());
arrayParamOut(cp, "outBuffer", buffer);
+
+ SERIALIZE_CONTAINER(inBuffer);
}
void
@@ -67,6 +71,8 @@ PS2Device::unserialize(CheckpointIn &cp)
arrayParamIn(cp, "outBuffer", buffer);
for (auto c : buffer)
outBuffer.push_back(c);
+
+ UNSERIALIZE_CONTAINER(inBuffer);
}
void
@@ -90,7 +96,10 @@ PS2Device::hostRead()
void
PS2Device::hostWrite(uint8_t c)
{
- recv(c);
+ DPRINTF(PS2, "PS2: Host -> device: %#x\n", c);
+ inBuffer.push_back(c);
+ if (recv(inBuffer))
+ inBuffer.clear();
}
void
@@ -98,6 +107,7 @@ PS2Device::send(const uint8_t *data, size_t size)
{
assert(data || size == 0);
while (size) {
+ DPRINTF(PS2, "PS2: Device -> host: %#x\n", *data);
outBuffer.push_back(*(data++));
size--;
}