X86: Add a keyboard controller device.
[gem5.git] / src / dev / x86 / i8042.hh
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 "dev/io_device.hh"
35 #include "dev/x86/intdev.hh"
36 #include "params/I8042.hh"
37
38 #include <queue>
39
40 namespace X86ISA
41 {
42
43 class IntPin;
44
45 class I8042 : public BasicPioDevice
46 {
47 protected:
48 BitUnion8(StatusReg)
49 Bitfield<7> parityError;
50 Bitfield<6> timeout;
51 Bitfield<5> mouseOutputFull;
52 Bitfield<4> keyboardUnlocked;
53 Bitfield<3> commandLast;
54 Bitfield<2> passedSelfTest;
55 Bitfield<1> inputFull;
56 Bitfield<0> outputFull;
57 EndBitUnion(StatusReg)
58
59 BitUnion8(CommandByte)
60 Bitfield<6> convertScanCodes;
61 Bitfield<5> disableMouse;
62 Bitfield<4> disableKeyboard;
63 Bitfield<2> passedSelfTest;
64 Bitfield<1> mouseFullInt;
65 Bitfield<0> keyboardFullInt;
66 EndBitUnion(CommandByte)
67
68 Tick latency;
69 Addr dataPort;
70 Addr commandPort;
71
72 StatusReg statusReg;
73 CommandByte commandByte;
74
75 uint8_t dataReg;
76
77 static const uint16_t NoCommand = (uint16_t)(-1);
78 uint16_t lastCommand;
79
80 BitUnion8(MouseStatus)
81 Bitfield<6> remote;
82 Bitfield<5> enabled;
83 Bitfield<4> twoToOne;
84 Bitfield<2> leftButton;
85 Bitfield<0> rightButton;
86 EndBitUnion(MouseStatus)
87
88 IntSourcePin *mouseIntPin;
89 std::queue<uint8_t> mouseBuffer;
90 uint16_t lastMouseCommand;
91 uint8_t mouseResolution;
92 uint8_t mouseSampleRate;
93 MouseStatus mouseStatus;
94
95
96 IntSourcePin *keyboardIntPin;
97 std::queue<uint8_t> keyboardBuffer;
98 uint16_t lastKeyboardCommand;
99
100 bool writeData(uint8_t newData, bool mouse = false);
101 void keyboardAck();
102 void writeKeyboardData(const uint8_t *data, int size);
103 void mouseAck();
104 void mouseNack();
105 void writeMouseData(const uint8_t *data, int size);
106 uint8_t readDataOut();
107
108 public:
109 typedef I8042Params Params;
110
111 const Params *
112 params() const
113 {
114 return dynamic_cast<const Params *>(_params);
115 }
116
117 I8042(Params *p) : BasicPioDevice(p), latency(p->pio_latency),
118 dataPort(p->data_port), commandPort(p->command_port),
119 statusReg(0), commandByte(0), dataReg(0), lastCommand(NoCommand),
120 mouseIntPin(p->mouse_int_pin), lastMouseCommand(NoCommand),
121 keyboardIntPin(p->keyboard_int_pin),
122 lastKeyboardCommand(NoCommand)
123 {
124 statusReg.passedSelfTest = 1;
125 statusReg.commandLast = 1;
126 statusReg.keyboardUnlocked = 1;
127
128 commandByte.convertScanCodes = 1;
129 commandByte.passedSelfTest = 1;
130 commandByte.keyboardFullInt = 1;
131 }
132
133 void addressRanges(AddrRangeList &range_list);
134
135 Tick read(PacketPtr pkt);
136
137 Tick write(PacketPtr pkt);
138 };
139
140 }; // namespace X86ISA
141
142 #endif //__DEV_X86_I8042_HH__