gem5  v22.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 #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
#define DPRINTF(x,...)
Definition: trace.hh:186
const char data[]
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: device.cc:65
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition: device.cc:113
void sendAck()
Send an ACK byte to the host.
Definition: device.cc:128
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: device.cc:75
PS2Mouse(const PS2MouseParams &p)
Definition: mouse.cc:56
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition: mouse.cc:63
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mouse.cc:158
uint8_t resolution
Definition: mouse.hh:67
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mouse.cc:168
uint8_t sampleRate
Definition: mouse.hh:68
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define warn(...)
Definition: logging.hh:246
Bitfield< 5, 0 > status
Definition: misc_types.hh:429
Bitfield< 54 > p
Definition: pagetable.hh:70
const std::vector< uint8_t > ID
Definition: types.cc:53
@ Resend
Definition: types.hh:69
@ DefaultsAndDisable
Definition: types.hh:66
@ ReadID
Definition: types.hh:63
@ Disable
Definition: types.hh:65
@ Reset
Definition: types.hh:70
@ Enable
Definition: types.hh:64
@ SelfTestPass
Definition: types.hh:62
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568

Generated on Wed Dec 21 2022 10:22:34 for gem5 by doxygen 1.9.1