i8042.hh revision 5831
111103Snilay@cs.wisc.edu/*
211103Snilay@cs.wisc.edu * Copyright (c) 2008 The Regents of The University of Michigan
38441SN/A * All rights reserved.
48441SN/A *
57893SN/A * Redistribution and use in source and binary forms, with or without
611960Sgabeblack@google.com * modification, are permitted provided that the following conditions are
711960Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
811960Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
911960Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1010798Ssteve.reinhardt@amd.com * notice, this list of conditions and the following disclaimer in the
117893SN/A * documentation and/or other materials provided with the distribution;
127893SN/A * neither the name of the copyright holders nor the names of its
137893SN/A * contributors may be used to endorse or promote products derived from
147893SN/A * this software without specific prior written permission.
157893SN/A *
167893SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177893SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187893SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197893SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207893SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217893SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227893SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237893SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247893SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257893SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267893SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277893SN/A *
2811960Sgabeblack@google.com * 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
40namespace X86ISA
41{
42
43class IntPin;
44
45class 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__
143