xref: /openbmc/qemu/include/hw/input/ps2.h (revision 55745005e90a9deabd3d7900e13fc850f26f9d62)
10d09e41aSPaolo Bonzini /*
20d09e41aSPaolo Bonzini  * QEMU PS/2 keyboard/mouse emulation
30d09e41aSPaolo Bonzini  *
40d09e41aSPaolo Bonzini  * Copyright (C) 2003 Fabrice Bellard
50d09e41aSPaolo Bonzini  *
60d09e41aSPaolo Bonzini  * Permission is hereby granted, free of charge, to any person obtaining a copy
70d09e41aSPaolo Bonzini  * of this software and associated documentation files (the "Software"), to deal
80d09e41aSPaolo Bonzini  * in the Software without restriction, including without limitation the rights
90d09e41aSPaolo Bonzini  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
100d09e41aSPaolo Bonzini  * copies of the Software, and to permit persons to whom the Software is
110d09e41aSPaolo Bonzini  * furnished to do so, subject to the following conditions:
120d09e41aSPaolo Bonzini  *
130d09e41aSPaolo Bonzini  * The above copyright notice and this permission notice shall be included in
140d09e41aSPaolo Bonzini  * all copies or substantial portions of the Software.
150d09e41aSPaolo Bonzini  *
160d09e41aSPaolo Bonzini  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
170d09e41aSPaolo Bonzini  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
180d09e41aSPaolo Bonzini  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
190d09e41aSPaolo Bonzini  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
200d09e41aSPaolo Bonzini  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
210d09e41aSPaolo Bonzini  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
220d09e41aSPaolo Bonzini  * THE SOFTWARE.
230d09e41aSPaolo Bonzini  */
240d09e41aSPaolo Bonzini 
250d09e41aSPaolo Bonzini #ifndef HW_PS2_H
260d09e41aSPaolo Bonzini #define HW_PS2_H
270d09e41aSPaolo Bonzini 
280c235e38SMark Cave-Ayland #include "hw/sysbus.h"
290c235e38SMark Cave-Ayland 
308b0caab0SFabian Lesniak #define PS2_MOUSE_BUTTON_LEFT   0x01
31ed6f72b8SFabian Lesniak #define PS2_MOUSE_BUTTON_RIGHT  0x02
32ed6f72b8SFabian Lesniak #define PS2_MOUSE_BUTTON_MIDDLE 0x04
338b0caab0SFabian Lesniak #define PS2_MOUSE_BUTTON_SIDE   0x08
348b0caab0SFabian Lesniak #define PS2_MOUSE_BUTTON_EXTRA  0x10
358b0caab0SFabian Lesniak 
36494145b2SMark Cave-Ayland struct PS2DeviceClass {
37494145b2SMark Cave-Ayland     SysBusDeviceClass parent_class;
38108cb22eSMark Cave-Ayland 
39*fc2fc3c1SPeter Maydell     ResettablePhases parent_phases;
40494145b2SMark Cave-Ayland };
41494145b2SMark Cave-Ayland 
420c235e38SMark Cave-Ayland /*
430c235e38SMark Cave-Ayland  * PS/2 buffer size. Keep 256 bytes for compatibility with
440c235e38SMark Cave-Ayland  * older QEMU versions.
450c235e38SMark Cave-Ayland  */
460c235e38SMark Cave-Ayland #define PS2_BUFFER_SIZE     256
470c235e38SMark Cave-Ayland 
480c235e38SMark Cave-Ayland typedef struct {
490c235e38SMark Cave-Ayland     uint8_t data[PS2_BUFFER_SIZE];
500c235e38SMark Cave-Ayland     int rptr, wptr, cwptr, count;
510c235e38SMark Cave-Ayland } PS2Queue;
520c235e38SMark Cave-Ayland 
536beb79e1SMark Cave-Ayland /* Output IRQ */
546beb79e1SMark Cave-Ayland #define PS2_DEVICE_IRQ      0
556beb79e1SMark Cave-Ayland 
560c235e38SMark Cave-Ayland struct PS2State {
570c235e38SMark Cave-Ayland     SysBusDevice parent_obj;
580c235e38SMark Cave-Ayland 
590c235e38SMark Cave-Ayland     PS2Queue queue;
600c235e38SMark Cave-Ayland     int32_t write_cmd;
616beb79e1SMark Cave-Ayland     qemu_irq irq;
620c235e38SMark Cave-Ayland };
630c235e38SMark Cave-Ayland 
640c235e38SMark Cave-Ayland #define TYPE_PS2_DEVICE "ps2-device"
65494145b2SMark Cave-Ayland OBJECT_DECLARE_TYPE(PS2State, PS2DeviceClass, PS2_DEVICE)
660c235e38SMark Cave-Ayland 
670c235e38SMark Cave-Ayland struct PS2KbdState {
680c235e38SMark Cave-Ayland     PS2State parent_obj;
690c235e38SMark Cave-Ayland 
700c235e38SMark Cave-Ayland     int scan_enabled;
710c235e38SMark Cave-Ayland     int translate;
720c235e38SMark Cave-Ayland     int scancode_set; /* 1=XT, 2=AT, 3=PS/2 */
730c235e38SMark Cave-Ayland     int ledstate;
740c235e38SMark Cave-Ayland     bool need_high_bit;
750c235e38SMark Cave-Ayland     unsigned int modifiers; /* bitmask of MOD_* constants above */
760c235e38SMark Cave-Ayland };
770c235e38SMark Cave-Ayland 
780c235e38SMark Cave-Ayland #define TYPE_PS2_KBD_DEVICE "ps2-kbd"
790c235e38SMark Cave-Ayland OBJECT_DECLARE_SIMPLE_TYPE(PS2KbdState, PS2_KBD_DEVICE)
800c235e38SMark Cave-Ayland 
810c235e38SMark Cave-Ayland struct PS2MouseState {
820c235e38SMark Cave-Ayland     PS2State parent_obj;
830c235e38SMark Cave-Ayland 
840c235e38SMark Cave-Ayland     uint8_t mouse_status;
850c235e38SMark Cave-Ayland     uint8_t mouse_resolution;
860c235e38SMark Cave-Ayland     uint8_t mouse_sample_rate;
870c235e38SMark Cave-Ayland     uint8_t mouse_wrap;
880c235e38SMark Cave-Ayland     uint8_t mouse_type; /* 0 = PS2, 3 = IMPS/2, 4 = IMEX */
890c235e38SMark Cave-Ayland     uint8_t mouse_detect_state;
900c235e38SMark Cave-Ayland     int mouse_dx; /* current values, needed for 'poll' mode */
910c235e38SMark Cave-Ayland     int mouse_dy;
920c235e38SMark Cave-Ayland     int mouse_dz;
930c235e38SMark Cave-Ayland     int mouse_dw;
940c235e38SMark Cave-Ayland     uint8_t mouse_buttons;
950c235e38SMark Cave-Ayland };
960c235e38SMark Cave-Ayland 
970c235e38SMark Cave-Ayland #define TYPE_PS2_MOUSE_DEVICE "ps2-mouse"
980c235e38SMark Cave-Ayland OBJECT_DECLARE_SIMPLE_TYPE(PS2MouseState, PS2_MOUSE_DEVICE)
99fa9414e9SPhilippe Mathieu-Daudé 
1000d09e41aSPaolo Bonzini /* ps2.c */
10154334e73SMark Cave-Ayland void ps2_write_mouse(PS2MouseState *s, int val);
10254334e73SMark Cave-Ayland void ps2_write_keyboard(PS2KbdState *s, int val);
1038498bb8dSGerd Hoffmann uint32_t ps2_read_data(PS2State *s);
1047abe7eb2SGeoffrey McRae void ps2_queue_noirq(PS2State *s, int b);
1058498bb8dSGerd Hoffmann void ps2_queue(PS2State *s, int b);
1067abe7eb2SGeoffrey McRae void ps2_queue_2(PS2State *s, int b1, int b2);
1077abe7eb2SGeoffrey McRae void ps2_queue_3(PS2State *s, int b1, int b2, int b3);
1087abe7eb2SGeoffrey McRae void ps2_queue_4(PS2State *s, int b1, int b2, int b3, int b4);
10954334e73SMark Cave-Ayland void ps2_keyboard_set_translation(PS2KbdState *s, int mode);
11054334e73SMark Cave-Ayland void ps2_mouse_fake_event(PS2MouseState *s);
1112a6505b0SSven Schnelle int ps2_queue_empty(PS2State *s);
1120d09e41aSPaolo Bonzini 
113175de524SMarkus Armbruster #endif /* HW_PS2_H */
114