gem5  v20.1.0.0
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 
49 PS2Mouse::PS2Mouse(const PS2MouseParams *p)
50  : PS2Device(p),
51  status(0), resolution(4), sampleRate(100)
52 {
53 }
54 
55 bool
57 {
58  switch (data[0]) {
59  case Ps2::ReadID:
60  DPRINTF(PS2, "Mouse ID requested.\n");
61  sendAck();
63  return true;
64  case Ps2::Disable:
65  DPRINTF(PS2, "Disabling data reporting.\n");
66  status.enabled = 0;
67  sendAck();
68  return true;
69  case Ps2::Enable:
70  DPRINTF(PS2, "Enabling data reporting.\n");
71  status.enabled = 1;
72  sendAck();
73  return true;
74  case Ps2::Resend:
75  panic("Mouse resend unimplemented.\n");
76  case Ps2::Reset:
77  DPRINTF(PS2, "Resetting the mouse.\n");
78  sampleRate = 100;
79  resolution = 4;
80  status.twoToOne = 0;
81  status.enabled = 0;
82  sendAck();
85  return true;
86 
88  DPRINTF(PS2, "Setting mouse scale to 1:1.\n");
89  status.twoToOne = 0;
90  sendAck();
91  return true;
93  DPRINTF(PS2, "Setting mouse scale to 2:1.\n");
94  status.twoToOne = 1;
95  sendAck();
96  return true;
98  if (data.size() == 1) {
99  DPRINTF(PS2, "Setting mouse resolution.\n");
100  sendAck();
101  return false;
102  } else {
103  DPRINTF(PS2, "Mouse resolution set to %d.\n", data[1]);
104  resolution = data[1];
105  sendAck();
106  return true;
107  }
109  DPRINTF(PS2, "Getting mouse status.\n");
110  sendAck();
111  send((uint8_t *)&(status), 1);
112  send(&resolution, sizeof(resolution));
113  send(&sampleRate, sizeof(sampleRate));
114  return true;
116  panic("Reading mouse data unimplemented.\n");
118  panic("Resetting mouse wrap mode unimplemented.\n");
120  panic("Setting mouse wrap mode unimplemented.\n");
122  panic("Setting mouse remote mode unimplemented.\n");
124  if (data.size() == 1) {
125  DPRINTF(PS2, "Setting mouse sample rate.\n");
126  sendAck();
127  return false;
128  } else {
129  DPRINTF(PS2, "Mouse sample rate %d samples "
130  "per second.\n", data[1]);
131  sampleRate = data[1];
132  sendAck();
133  return true;
134  }
136  DPRINTF(PS2, "Disabling and resetting mouse.\n");
137  sampleRate = 100;
138  resolution = 4;
139  status.twoToOne = 0;
140  status.enabled = 0;
141  sendAck();
142  return true;
143  default:
144  warn("Unknown mouse command %#02x.\n", data[0]);
145  send(Ps2::Resend);
146  return true;
147  }
148 }
149 
150 void
152 {
154 
158 }
159 
160 void
162 {
164 
168 }
169 
170 PS2Mouse *
171 PS2MouseParams::create()
172 {
173  return new PS2Mouse(this);
174 }
PS2Mouse::recv
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition: mouse.cc:56
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
Ps2::Mouse::SetResolution
@ SetResolution
Definition: types.hh:91
PS2Device::send
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition: device.cc:104
warn
#define warn(...)
Definition: logging.hh:239
PS2Mouse::sampleRate
uint8_t sampleRate
Definition: mouse.hh:61
types.hh
data
const char data[]
Definition: circlebuf.test.cc:42
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
PS2Mouse::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mouse.cc:151
Ps2::DefaultsAndDisable
@ DefaultsAndDisable
Definition: types.hh:59
Ps2::SelfTestPass
@ SelfTestPass
Definition: types.hh:55
Ps2::Enable
@ Enable
Definition: types.hh:57
PS2Device::sendAck
void sendAck()
Send an ACK byte to the host.
Definition: device.cc:119
Ps2::Mouse::WrapMode
@ WrapMode
Definition: types.hh:95
PS2Mouse::resolution
uint8_t resolution
Definition: mouse.hh:60
Ps2::Mouse::GetStatus
@ GetStatus
Definition: types.hh:92
Ps2::Mouse::SampleRate
@ SampleRate
Definition: types.hh:97
std::vector< uint8_t >
PS2Device
Definition: device.hh:51
Ps2::Resend
@ Resend
Definition: types.hh:62
Ps2::Mouse::ResetWrapMode
@ ResetWrapMode
Definition: types.hh:94
mouse.hh
cp
Definition: cprintf.cc:40
PS2Mouse::PS2Mouse
PS2Mouse(const PS2MouseParams *p)
Definition: mouse.cc:49
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Ps2::ReadID
@ ReadID
Definition: types.hh:56
Ps2::Mouse::Scale1to1
@ Scale1to1
Definition: types.hh:89
Ps2::Disable
@ Disable
Definition: types.hh:58
Ps2::Mouse::Scale2to1
@ Scale2to1
Definition: types.hh:90
PS2Mouse::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mouse.cc:161
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
PS2Device::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: device.cc:56
logging.hh
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Ps2::Mouse::RemoteMode
@ RemoteMode
Definition: types.hh:96
PS2Device::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: device.cc:66
CheckpointIn
Definition: serialize.hh:67
PS2Mouse
Definition: mouse.hh:48
Ps2::Reset
@ Reset
Definition: types.hh:63
Ps2::Mouse::ID
const std::vector< uint8_t > ID
Definition: types.cc:46
Ps2::Mouse::ReadData
@ ReadData
Definition: types.hh:93
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17