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__
36 #include "dev/x86/intdev.hh"
37 #include "dev/io_device.hh"
38 #include "params/I8042.hh"
48 std::deque<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)
64 virtual void serialize(const std::string &base, CheckpointOut &cp) const;
65 virtual void unserialize(const std::string &base, CheckpointIn &cp);
69 return !outBuffer.empty();
74 uint8_t data = outBuffer.front();
75 outBuffer.pop_front();
79 virtual bool processData(uint8_t data) = 0;
82 class PS2Mouse : public PS2Device
85 static const uint8_t ID[];
99 EnableReporting = 0xF4,
100 DisableReporting = 0xF5,
101 DefaultsAndDisable = 0xF6,
109 Bitfield<4> twoToOne;
110 Bitfield<2> leftButton;
111 Bitfield<0> rightButton;
118 PS2Mouse() : PS2Device(), status(0), resolution(4), sampleRate(100)
121 bool processData(uint8_t data) override;
123 void serialize(const std::string &base, CheckpointOut &cp) const override;
124 void unserialize(const std::string &base, CheckpointIn &cp) override;
127 class PS2Keyboard : public PS2Device
130 static const uint8_t ID[];
135 DiagnosticEcho = 0xEE,
136 AlternateScanCodes = 0xF0,
138 TypematicInfo = 0xF3,
141 DefaultsAndDisable = 0xF6,
142 AllKeysToTypematic = 0xF7,
143 AllKeysToMakeRelease = 0xF8,
144 AllKeysToMake = 0xF9,
145 AllKeysToTypematicMakeRelease = 0xFA,
146 KeyToTypematic = 0xFB,
147 KeyToMakeRelease = 0xFC,
148 KeyToMakeOnly = 0xFD,
154 bool processData(uint8_t data) override;
157 class I8042 : public BasicPioDevice
162 GetCommandByte = 0x20,
163 ReadControllerRamBase = 0x20,
164 WriteCommandByte = 0x60,
165 WriteControllerRamBase = 0x60,
166 CheckForPassword = 0xA4,
168 CheckPassword = 0xA6,
173 InterfaceTest = 0xAB,
174 DiagnosticDump = 0xAC,
175 DisableKeyboard = 0xAD,
176 EnableKeyboard = 0xAE,
177 ReadInputPort = 0xC0,
178 ContinuousPollLow = 0xC1,
179 ContinuousPollHigh = 0xC2,
180 ReadOutputPort = 0xD0,
181 WriteOutputPort = 0xD1,
182 WriteKeyboardOutputBuff = 0xD2,
183 WriteMouseOutputBuff = 0xD3,
187 ReadTestInputs = 0xE0,
188 PulseOutputBitBase = 0xF0,
193 Bitfield<7> parityError;
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)
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)
217 CommandByte commandByte;
221 static const uint16_t NoCommand = (uint16_t)(-1);
222 uint16_t lastCommand;
224 IntSourcePin *mouseIntPin;
225 IntSourcePin *keyboardIntPin;
228 PS2Keyboard keyboard;
230 void writeData(uint8_t newData, bool mouse = false);
231 uint8_t readDataOut();
234 typedef I8042Params Params;
239 return dynamic_cast<const Params *>(_params);
244 AddrRangeList getAddrRanges() const override;
246 Tick read(PacketPtr pkt) override;
248 Tick write(PacketPtr pkt) override;
250 void serialize(CheckpointOut &cp) const override;
251 void unserialize(CheckpointIn &cp) override;
254 } // namespace X86ISA
256 #endif //__DEV_X86_I8042_HH__