i8042.hh revision 11007
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 40namespace X86ISA 41{ 42 43class IntPin; 44 45class PS2Device 46{ 47 protected: 48 std::deque<uint8_t> outBuffer; 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 61 PS2Device() : lastCommand(NoCommand) 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 82class 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, 99 EnableReporting = 0xF4, 100 DisableReporting = 0xF5, 101 DefaultsAndDisable = 0xF6, 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); 122 123 void serialize(const std::string &base, 124 CheckpointOut &cp) const M5_ATTR_OVERRIDE; 125 void unserialize(const std::string &base, 126 CheckpointIn &cp) M5_ATTR_OVERRIDE; 127}; 128 129class PS2Keyboard : public PS2Device 130{ 131 protected: 132 static const uint8_t ID[]; 133 134 enum Command 135 { 136 LEDWrite = 0xED, 137 DiagnosticEcho = 0xEE, 138 AlternateScanCodes = 0xF0, 139 ReadID = 0xF2, 140 TypematicInfo = 0xF3, 141 Enable = 0xF4, 142 Disable = 0xF5, 143 DefaultsAndDisable = 0xF6, 144 AllKeysToTypematic = 0xF7, 145 AllKeysToMakeRelease = 0xF8, 146 AllKeysToMake = 0xF9, 147 AllKeysToTypematicMakeRelease = 0xFA, 148 KeyToTypematic = 0xFB, 149 KeyToMakeRelease = 0xFC, 150 KeyToMakeOnly = 0xFD, 151 Resend = 0xFE, 152 Reset = 0xFF 153 }; 154 155 public: 156 bool processData(uint8_t data); 157}; 158 159class I8042 : public BasicPioDevice 160{ 161 protected: 162 enum Command 163 { 164 GetCommandByte = 0x20, 165 ReadControllerRamBase = 0x20, 166 WriteCommandByte = 0x60, 167 WriteControllerRamBase = 0x60, 168 CheckForPassword = 0xA4, 169 LoadPassword = 0xA5, 170 CheckPassword = 0xA6, 171 DisableMouse = 0xA7, 172 EnableMouse = 0xA8, 173 TestMouse = 0xA9, 174 SelfTest = 0xAA, 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, 186 WriteToMouse = 0xD4, 187 DisableA20 = 0xDD, 188 EnableA20 = 0xDF, 189 ReadTestInputs = 0xE0, 190 PulseOutputBitBase = 0xF0, 191 SystemReset = 0xFE 192 }; 193 194 BitUnion8(StatusReg) 195 Bitfield<7> parityError; 196 Bitfield<6> timeout; 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) 204 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) 213 214 Tick latency; 215 Addr dataPort; 216 Addr commandPort; 217 218 StatusReg statusReg; 219 CommandByte commandByte; 220 221 uint8_t dataReg; 222 223 static const uint16_t NoCommand = (uint16_t)(-1); 224 uint16_t lastCommand; 225 226 IntSourcePin *mouseIntPin; 227 IntSourcePin *keyboardIntPin; 228 229 PS2Mouse mouse; 230 PS2Keyboard keyboard; 231 232 void writeData(uint8_t newData, bool mouse = false); 233 uint8_t readDataOut(); 234 235 public: 236 typedef I8042Params Params; 237 238 const Params * 239 params() const 240 { 241 return dynamic_cast<const Params *>(_params); 242 } 243 244 I8042(Params *p); 245 246 AddrRangeList getAddrRanges() const; 247 248 Tick read(PacketPtr pkt); 249 250 Tick write(PacketPtr pkt); 251 252 void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 253 void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 254}; 255 256} // namespace X86ISA 257 258#endif //__DEV_X86_I8042_HH__ 259