gem5  v21.1.0.2
mouse.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2008 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include "dev/ps2/mouse.hh"
42 
43 #include "base/logging.hh"
44 #include "base/trace.hh"
45 #include "debug/PS2.hh"
46 #include "dev/ps2/types.hh"
47 #include "params/PS2Mouse.hh"
48 #include "sim/serialize.hh"
49 
50 namespace gem5
51 {
52 
53 namespace ps2
54 {
55 
56 PS2Mouse::PS2Mouse(const PS2MouseParams &p)
57  : Device(p),
58  status(0), resolution(4), sampleRate(100)
59 {
60 }
61 
62 bool
64 {
65  switch (data[0]) {
66  case ReadID:
67  DPRINTF(PS2, "Mouse ID requested.\n");
68  sendAck();
69  send(mouse::ID);
70  return true;
71  case Disable:
72  DPRINTF(PS2, "Disabling data reporting.\n");
73  status.enabled = 0;
74  sendAck();
75  return true;
76  case Enable:
77  DPRINTF(PS2, "Enabling data reporting.\n");
78  status.enabled = 1;
79  sendAck();
80  return true;
81  case Resend:
82  panic("Mouse resend unimplemented.\n");
83  case Reset:
84  DPRINTF(PS2, "Resetting the mouse.\n");
85  sampleRate = 100;
86  resolution = 4;
87  status.twoToOne = 0;
88  status.enabled = 0;
89  sendAck();
91  send(mouse::ID);
92  return true;
93 
94  case mouse::Scale1to1:
95  DPRINTF(PS2, "Setting mouse scale to 1:1.\n");
96  status.twoToOne = 0;
97  sendAck();
98  return true;
99  case mouse::Scale2to1:
100  DPRINTF(PS2, "Setting mouse scale to 2:1.\n");
101  status.twoToOne = 1;
102  sendAck();
103  return true;
105  if (data.size() == 1) {
106  DPRINTF(PS2, "Setting mouse resolution.\n");
107  sendAck();
108  return false;
109  } else {
110  DPRINTF(PS2, "Mouse resolution set to %d.\n", data[1]);
111  resolution = data[1];
112  sendAck();
113  return true;
114  }
115  case mouse::GetStatus:
116  DPRINTF(PS2, "Getting mouse status.\n");
117  sendAck();
118  send((uint8_t *)&(status), 1);
119  send(&resolution, sizeof(resolution));
120  send(&sampleRate, sizeof(sampleRate));
121  return true;
122  case mouse::ReadData:
123  panic("Reading mouse data unimplemented.\n");
125  panic("Resetting mouse wrap mode unimplemented.\n");
126  case mouse::WrapMode:
127  panic("Setting mouse wrap mode unimplemented.\n");
128  case mouse::RemoteMode:
129  panic("Setting mouse remote mode unimplemented.\n");
130  case mouse::SampleRate:
131  if (data.size() == 1) {
132  DPRINTF(PS2, "Setting mouse sample rate.\n");
133  sendAck();
134  return false;
135  } else {
136  DPRINTF(PS2, "Mouse sample rate %d samples "
137  "per second.\n", data[1]);
138  sampleRate = data[1];
139  sendAck();
140  return true;
141  }
142  case DefaultsAndDisable:
143  DPRINTF(PS2, "Disabling and resetting mouse.\n");
144  sampleRate = 100;
145  resolution = 4;
146  status.twoToOne = 0;
147  status.enabled = 0;
148  sendAck();
149  return true;
150  default:
151  warn("Unknown mouse command %#02x.\n", data[0]);
152  send(Resend);
153  return true;
154  }
155 }
156 
157 void
159 {
160  Device::serialize(cp);
161 
165 }
166 
167 void
169 {
171 
175 }
176 
177 } // namespace ps2
178 } // namespace gem5
gem5::ps2::PS2Mouse::sampleRate
uint8_t sampleRate
Definition: mouse.hh:68
gem5::ps2::Device::send
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition: device.cc:113
warn
#define warn(...)
Definition: logging.hh:245
types.hh
data
const char data[]
Definition: circlebuf.test.cc:48
serialize.hh
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::ps2::mouse::WrapMode
@ WrapMode
Definition: types.hh:108
gem5::ps2::mouse::ID
const std::vector< uint8_t > ID
Definition: types.cc:53
std::vector< uint8_t >
gem5::ps2::PS2Mouse::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mouse.cc:168
gem5::ps2::PS2Mouse::PS2Mouse
PS2Mouse(const PS2MouseParams &p)
Definition: mouse.cc:56
mouse.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::ps2::SelfTestPass
@ SelfTestPass
Definition: types.hh:62
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ps2::Device::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: device.cc:65
gem5::ps2::Device::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: device.cc:75
gem5::ps2::PS2Mouse::resolution
uint8_t resolution
Definition: mouse.hh:67
gem5::ps2::Resend
@ Resend
Definition: types.hh:69
gem5::ps2::PS2Mouse::recv
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition: mouse.cc:63
gem5::ps2::mouse::ReadData
@ ReadData
Definition: types.hh:106
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
gem5::ps2::Reset
@ Reset
Definition: types.hh:70
gem5::ps2::Disable
@ Disable
Definition: types.hh:65
gem5::ps2::Device
Definition: device.hh:60
gem5::ps2::DefaultsAndDisable
@ DefaultsAndDisable
Definition: types.hh:66
gem5::ps2::mouse::SetResolution
@ SetResolution
Definition: types.hh:104
gem5::ps2::mouse::GetStatus
@ GetStatus
Definition: types.hh:105
gem5::ps2::PS2Mouse::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mouse.cc:158
logging.hh
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::ps2::mouse::ResetWrapMode
@ ResetWrapMode
Definition: types.hh:107
trace.hh
gem5::ps2::Device::sendAck
void sendAck()
Send an ACK byte to the host.
Definition: device.cc:128
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ps2::mouse::Scale1to1
@ Scale1to1
Definition: types.hh:102
gem5::ps2::ReadID
@ ReadID
Definition: types.hh:63
gem5::ps2::mouse::SampleRate
@ SampleRate
Definition: types.hh:110
gem5::ps2::Enable
@ Enable
Definition: types.hh:64
gem5::ps2::mouse::Scale2to1
@ Scale2to1
Definition: types.hh:103
gem5::ps2::mouse::RemoteMode
@ RemoteMode
Definition: types.hh:109
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::ArmISA::status
Bitfield< 5, 0 > status
Definition: misc_types.hh:422

Generated on Tue Sep 21 2021 12:25:17 for gem5 by doxygen 1.8.17