gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
i8042.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Gabe Black
29  */
30 
31 #ifndef __DEV_X86_I8042_HH__
32 #define __DEV_X86_I8042_HH__
33 
34 #include <deque>
35 
36 #include "dev/x86/intdev.hh"
37 #include "dev/io_device.hh"
38 #include "params/I8042.hh"
39 
40 namespace X86ISA
41 {
42 
43 class IntPin;
44 
45 class PS2Device
46 {
47  protected:
49 
50  static const uint16_t NoCommand = (uint16_t)(-1);
51 
52  uint16_t lastCommand;
53  void bufferData(const uint8_t *data, int size);
54  void ack();
55  void nack();
56 
57  public:
58  virtual ~PS2Device()
59  {};
60 
62  {}
63 
64  virtual void serialize(const std::string &base, CheckpointOut &cp) const;
65  virtual void unserialize(const std::string &base, CheckpointIn &cp);
66 
67  bool hasData()
68  {
69  return !outBuffer.empty();
70  }
71 
72  uint8_t getData()
73  {
74  uint8_t data = outBuffer.front();
75  outBuffer.pop_front();
76  return data;
77  }
78 
79  virtual bool processData(uint8_t data) = 0;
80 };
81 
82 class PS2Mouse : public PS2Device
83 {
84  protected:
85  static const uint8_t ID[];
86 
87  enum Command
88  {
89  Scale1to1 = 0xE6,
90  Scale2to1 = 0xE7,
91  SetResolution = 0xE8,
92  GetStatus = 0xE9,
93  ReadData = 0xEB,
94  ResetWrapMode = 0xEC,
95  WrapMode = 0xEE,
96  RemoteMode = 0xF0,
97  ReadID = 0xF2,
98  SampleRate = 0xF3,
102  Resend = 0xFE,
103  Reset = 0xFF
104  };
105 
106  BitUnion8(Status)
107  Bitfield<6> remote;
108  Bitfield<5> enabled;
109  Bitfield<4> twoToOne;
110  Bitfield<2> leftButton;
111  Bitfield<0> rightButton;
112  EndBitUnion(Status)
113 
114  Status status;
115  uint8_t resolution;
116  uint8_t sampleRate;
117  public:
118  PS2Mouse() : PS2Device(), status(0), resolution(4), sampleRate(100)
119  {}
120 
121  bool processData(uint8_t data) override;
122 
123  void serialize(const std::string &base, CheckpointOut &cp) const override;
124  void unserialize(const std::string &base, CheckpointIn &cp) override;
125 };
126 
127 class PS2Keyboard : public PS2Device
128 {
129  protected:
130  static const uint8_t ID[];
131 
132  enum Command
133  {
134  LEDWrite = 0xED,
137  ReadID = 0xF2,
139  Enable = 0xF4,
140  Disable = 0xF5,
149  Resend = 0xFE,
150  Reset = 0xFF
151  };
152 
153  public:
154  bool processData(uint8_t data) override;
155 };
156 
157 class I8042 : public BasicPioDevice
158 {
159  protected:
160  enum Command
161  {
167  LoadPassword = 0xA5,
169  DisableMouse = 0xA7,
170  EnableMouse = 0xA8,
171  TestMouse = 0xA9,
172  SelfTest = 0xAA,
184  WriteToMouse = 0xD4,
185  DisableA20 = 0xDD,
186  EnableA20 = 0xDF,
189  SystemReset = 0xFE
190  };
191 
192  BitUnion8(StatusReg)
193  Bitfield<7> parityError;
194  Bitfield<6> timeout;
195  Bitfield<5> mouseOutputFull;
196  Bitfield<4> keyboardUnlocked;
197  Bitfield<3> commandLast;
198  Bitfield<2> passedSelfTest;
199  Bitfield<1> inputFull;
200  Bitfield<0> outputFull;
201  EndBitUnion(StatusReg)
202 
203  BitUnion8(CommandByte)
204  Bitfield<6> convertScanCodes;
205  Bitfield<5> disableMouse;
206  Bitfield<4> disableKeyboard;
207  Bitfield<2> passedSelfTest;
208  Bitfield<1> mouseFullInt;
209  Bitfield<0> keyboardFullInt;
210  EndBitUnion(CommandByte)
211 
212  Tick latency;
215 
216  StatusReg statusReg;
217  CommandByte commandByte;
218 
219  uint8_t dataReg;
220 
221  static const uint16_t NoCommand = (uint16_t)(-1);
222  uint16_t lastCommand;
223 
226 
229 
230  void writeData(uint8_t newData, bool mouse = false);
231  uint8_t readDataOut();
232 
233  public:
234  typedef I8042Params Params;
235 
236  const Params *
237  params() const
238  {
239  return dynamic_cast<const Params *>(_params);
240  }
241 
242  I8042(Params *p);
243 
244  AddrRangeList getAddrRanges() const override;
245 
246  Tick read(PacketPtr pkt) override;
247 
248  Tick write(PacketPtr pkt) override;
249 
250  void serialize(CheckpointOut &cp) const override;
251  void unserialize(CheckpointIn &cp) override;
252 };
253 
254 } // namespace X86ISA
255 
256 #endif //__DEV_X86_I8042_HH__
IntSourcePin * keyboardIntPin
Definition: i8042.hh:225
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: i8042.cc:506
uint16_t lastCommand
Definition: i8042.hh:52
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: i8042.cc:490
Addr commandPort
Definition: i8042.hh:214
bool processData(uint8_t data) override
Definition: i8042.cc:155
Bitfield< 1 > inputFull
Definition: i8042.hh:199
AddrRangeList getAddrRanges() const override
Determine the address ranges that this device responds to.
Definition: i8042.cc:66
bool hasData()
Definition: i8042.hh:67
EndBitUnion(StatusReg) BitUnion8(CommandByte) Bitfield< 6 > convertScanCodes
BitUnion8(Status) Bitfield< 6 > remote
PioDeviceParams Params
Definition: io_device.hh:116
uint16_t lastCommand
Definition: i8042.hh:222
Bitfield< 0 > keyboardFullInt
Definition: i8042.hh:209
void serialize(const std::string &base, CheckpointOut &cp) const override
Definition: i8042.cc:525
Bitfield< 4 > disableKeyboard
Definition: i8042.hh:206
Bitfield< 2 > leftButton
Definition: i8042.hh:110
uint8_t dataReg
Definition: i8042.hh:219
StatusReg statusReg
Definition: i8042.hh:216
const char data[]
Definition: circlebuf.cc:43
Bitfield< 6 > timeout
Definition: i8042.hh:194
Bitfield< 5, 0 > status
Definition: miscregs.hh:1604
static const uint16_t NoCommand
Definition: i8042.hh:50
uint8_t resolution
Definition: i8042.hh:115
Bitfield< 5 > disableMouse
Definition: i8042.hh:205
I8042(Params *p)
Definition: i8042.cc:48
void bufferData(const uint8_t *data, int size)
Definition: i8042.cc:131
uint8_t getData()
Definition: i8042.hh:72
uint8_t readDataOut()
Definition: i8042.cc:141
Bitfield< 0 > outputFull
Definition: i8042.hh:200
CommandByte commandByte
Definition: i8042.hh:217
std::deque< uint8_t > outBuffer
Definition: i8042.hh:48
Addr dataPort
Definition: i8042.hh:213
uint8_t sampleRate
Definition: i8042.hh:116
uint64_t Tick
Tick count type.
Definition: types.hh:63
virtual bool processData(uint8_t data)=0
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: i8042.cc:356
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
BitUnion8(StatusReg) Bitfield< 7 > parityError
const Params * params() const
Definition: i8042.hh:237
void writeData(uint8_t newData, bool mouse=false)
Definition: i8042.cc:76
Bitfield< 2 > passedSelfTest
Definition: i8042.hh:198
PS2Mouse mouse
Definition: i8042.hh:227
EndBitUnion(Status) Status status
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Bitfield< 0 > rightButton
Definition: i8042.hh:111
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
static const uint8_t ID[]
Definition: i8042.hh:130
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: i8042.cc:337
Bitfield< 4 > keyboardUnlocked
Definition: i8042.hh:196
virtual void serialize(const std::string &base, CheckpointOut &cp) const
Definition: i8042.cc:96
Bitfield< 3 > commandLast
Definition: i8042.hh:197
int size()
Definition: pagetable.hh:146
virtual void unserialize(const std::string &base, CheckpointIn &cp)
Definition: i8042.cc:106
PS2Keyboard keyboard
Definition: i8042.hh:228
std::ostream CheckpointOut
Definition: serialize.hh:67
static const uint16_t NoCommand
Definition: i8042.hh:221
void unserialize(const std::string &base, CheckpointIn &cp) override
Definition: i8042.cc:535
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:107
Bitfield< 1 > mouseFullInt
Definition: i8042.hh:208
I8042Params Params
Definition: i8042.hh:234
IntSourcePin * mouseIntPin
Definition: i8042.hh:224
Bitfield< 5 > enabled
Definition: i8042.hh:108
Bitfield< 0 > p
Definition: pagetable.hh:95
static const uint8_t ID[]
Definition: i8042.hh:85
bool processData(uint8_t data) override
Definition: i8042.cc:234
Bitfield< 5 > mouseOutputFull
Definition: i8042.hh:195
Bitfield< 4 > twoToOne
Definition: i8042.hh:109
virtual ~PS2Device()
Definition: i8042.hh:58

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6