2 * Copyright (c) 2008 The Regents of The University of Michigan
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.
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.
31 #ifndef __DEV_X86_I8042_HH__
32 #define __DEV_X86_I8042_HH__
34 #include "dev/io_device.hh"
35 #include "dev/x86/intdev.hh"
36 #include "params/I8042.hh"
48 std::queue<uint8_t> outBuffer;
50 static const uint16_t NoCommand = (uint16_t)(-1);
53 void bufferData(const uint8_t *data, int size);
61 PS2Device() : lastCommand(NoCommand)
66 return !outBuffer.empty();
71 uint8_t data = outBuffer.front();
76 virtual bool processData(uint8_t data) = 0;
79 class PS2Mouse : public PS2Device
82 static const uint8_t ID[];
96 EnableReporting = 0xF4,
97 DisableReporting = 0xF5,
98 DefaultsAndDisable = 0xF6,
106 Bitfield<4> twoToOne;
107 Bitfield<2> leftButton;
108 Bitfield<0> rightButton;
115 PS2Mouse() : PS2Device(), status(0), resolution(4), sampleRate(100)
118 bool processData(uint8_t data);
120 void serialize(const std::string &base, std::ostream &os);
121 void unserialize(const std::string &base, Checkpoint *cp,
122 const std::string §ion);
125 class PS2Keyboard : public PS2Device
128 static const uint8_t ID[];
133 DiagnosticEcho = 0xEE,
134 AlternateScanCodes = 0xF0,
136 TypematicInfo = 0xF3,
139 DefaultsAndDisable = 0xF6,
140 AllKeysToTypematic = 0xF7,
141 AllKeysToMakeRelease = 0xF8,
142 AllKeysToMake = 0xF9,
143 AllKeysToTypematicMakeRelease = 0xFA,
144 KeyToTypematic = 0xFB,
145 KeyToMakeRelease = 0xFC,
146 KeyToMakeOnly = 0xFD,
152 bool processData(uint8_t data);
154 void serialize(const std::string &base, std::ostream &os);
155 void unserialize(const std::string &base, Checkpoint *cp,
156 const std::string §ion);
159 class I8042 : public BasicPioDevice
164 GetCommandByte = 0x20,
165 ReadControllerRamBase = 0x20,
166 WriteCommandByte = 0x60,
167 WriteControllerRamBase = 0x60,
168 CheckForPassword = 0xA4,
170 CheckPassword = 0xA6,
175 InterfaceTest = 0xAB,
176 DiagnosticDump = 0xAC,
177 DisableKeyboard = 0xAD,
178 EnableKeyboard = 0xAE,
179 ReadInputPort = 0xC0,
180 ContinuousPollLow = 0xC1,
181 ContinuousPollHigh = 0xC2,
182 ReadOutputPort = 0xD0,
183 WriteOutputPort = 0xD1,
184 WriteKeyboardOutputBuff = 0xD2,
185 WriteMouseOutputBuff = 0xD3,
189 ReadTestInputs = 0xE0,
190 PulseOutputBitBase = 0xF0,
195 Bitfield<7> parityError;
197 Bitfield<5> mouseOutputFull;
198 Bitfield<4> keyboardUnlocked;
199 Bitfield<3> commandLast;
200 Bitfield<2> passedSelfTest;
201 Bitfield<1> inputFull;
202 Bitfield<0> outputFull;
203 EndBitUnion(StatusReg)
205 BitUnion8(CommandByte)
206 Bitfield<6> convertScanCodes;
207 Bitfield<5> disableMouse;
208 Bitfield<4> disableKeyboard;
209 Bitfield<2> passedSelfTest;
210 Bitfield<1> mouseFullInt;
211 Bitfield<0> keyboardFullInt;
212 EndBitUnion(CommandByte)
219 CommandByte commandByte;
223 static const uint16_t NoCommand = (uint16_t)(-1);
224 uint16_t lastCommand;
226 IntSourcePin *mouseIntPin;
227 IntSourcePin *keyboardIntPin;
230 PS2Keyboard keyboard;
232 void writeData(uint8_t newData, bool mouse = false);
233 uint8_t readDataOut();
236 typedef I8042Params Params;
241 return dynamic_cast<const Params *>(_params);
244 I8042(Params *p) : BasicPioDevice(p), latency(p->pio_latency),
245 dataPort(p->data_port), commandPort(p->command_port),
246 statusReg(0), commandByte(0), dataReg(0), lastCommand(NoCommand),
247 mouseIntPin(p->mouse_int_pin), keyboardIntPin(p->keyboard_int_pin)
249 statusReg.passedSelfTest = 1;
250 statusReg.commandLast = 1;
251 statusReg.keyboardUnlocked = 1;
253 commandByte.convertScanCodes = 1;
254 commandByte.passedSelfTest = 1;
255 commandByte.keyboardFullInt = 1;
258 void addressRanges(AddrRangeList &range_list);
260 Tick read(PacketPtr pkt);
262 Tick write(PacketPtr pkt);
264 virtual void serialize(std::ostream &os);
265 virtual void unserialize(Checkpoint *cp, const std::string §ion);
268 } // namespace X86ISA
270 #endif //__DEV_X86_I8042_HH__