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 360c235e38SMark Cave-Ayland /* 370c235e38SMark Cave-Ayland * PS/2 buffer size. Keep 256 bytes for compatibility with 380c235e38SMark Cave-Ayland * older QEMU versions. 390c235e38SMark Cave-Ayland */ 400c235e38SMark Cave-Ayland #define PS2_BUFFER_SIZE 256 410c235e38SMark Cave-Ayland 420c235e38SMark Cave-Ayland typedef struct { 430c235e38SMark Cave-Ayland uint8_t data[PS2_BUFFER_SIZE]; 440c235e38SMark Cave-Ayland int rptr, wptr, cwptr, count; 450c235e38SMark Cave-Ayland } PS2Queue; 460c235e38SMark Cave-Ayland 470c235e38SMark Cave-Ayland struct PS2State { 480c235e38SMark Cave-Ayland SysBusDevice parent_obj; 490c235e38SMark Cave-Ayland 500c235e38SMark Cave-Ayland PS2Queue queue; 510c235e38SMark Cave-Ayland int32_t write_cmd; 520c235e38SMark Cave-Ayland void (*update_irq)(void *, int); 530c235e38SMark Cave-Ayland void *update_arg; 540c235e38SMark Cave-Ayland }; 550c235e38SMark Cave-Ayland 560c235e38SMark Cave-Ayland #define TYPE_PS2_DEVICE "ps2-device" 570c235e38SMark Cave-Ayland OBJECT_DECLARE_SIMPLE_TYPE(PS2State, PS2_DEVICE) 580c235e38SMark Cave-Ayland 590c235e38SMark Cave-Ayland struct PS2KbdState { 600c235e38SMark Cave-Ayland PS2State parent_obj; 610c235e38SMark Cave-Ayland 620c235e38SMark Cave-Ayland int scan_enabled; 630c235e38SMark Cave-Ayland int translate; 640c235e38SMark Cave-Ayland int scancode_set; /* 1=XT, 2=AT, 3=PS/2 */ 650c235e38SMark Cave-Ayland int ledstate; 660c235e38SMark Cave-Ayland bool need_high_bit; 670c235e38SMark Cave-Ayland unsigned int modifiers; /* bitmask of MOD_* constants above */ 680c235e38SMark Cave-Ayland }; 690c235e38SMark Cave-Ayland 700c235e38SMark Cave-Ayland #define TYPE_PS2_KBD_DEVICE "ps2-kbd" 710c235e38SMark Cave-Ayland OBJECT_DECLARE_SIMPLE_TYPE(PS2KbdState, PS2_KBD_DEVICE) 720c235e38SMark Cave-Ayland 730c235e38SMark Cave-Ayland struct PS2MouseState { 740c235e38SMark Cave-Ayland PS2State parent_obj; 750c235e38SMark Cave-Ayland 760c235e38SMark Cave-Ayland uint8_t mouse_status; 770c235e38SMark Cave-Ayland uint8_t mouse_resolution; 780c235e38SMark Cave-Ayland uint8_t mouse_sample_rate; 790c235e38SMark Cave-Ayland uint8_t mouse_wrap; 800c235e38SMark Cave-Ayland uint8_t mouse_type; /* 0 = PS2, 3 = IMPS/2, 4 = IMEX */ 810c235e38SMark Cave-Ayland uint8_t mouse_detect_state; 820c235e38SMark Cave-Ayland int mouse_dx; /* current values, needed for 'poll' mode */ 830c235e38SMark Cave-Ayland int mouse_dy; 840c235e38SMark Cave-Ayland int mouse_dz; 850c235e38SMark Cave-Ayland int mouse_dw; 860c235e38SMark Cave-Ayland uint8_t mouse_buttons; 870c235e38SMark Cave-Ayland }; 880c235e38SMark Cave-Ayland 890c235e38SMark Cave-Ayland #define TYPE_PS2_MOUSE_DEVICE "ps2-mouse" 900c235e38SMark Cave-Ayland OBJECT_DECLARE_SIMPLE_TYPE(PS2MouseState, PS2_MOUSE_DEVICE) 91fa9414e9SPhilippe Mathieu-Daudé 920d09e41aSPaolo Bonzini /* ps2.c */ 930d09e41aSPaolo Bonzini void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg); 940d09e41aSPaolo Bonzini void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg); 95*54334e73SMark Cave-Ayland void ps2_write_mouse(PS2MouseState *s, int val); 96*54334e73SMark Cave-Ayland void ps2_write_keyboard(PS2KbdState *s, int val); 978498bb8dSGerd Hoffmann uint32_t ps2_read_data(PS2State *s); 987abe7eb2SGeoffrey McRae void ps2_queue_noirq(PS2State *s, int b); 997abe7eb2SGeoffrey McRae void ps2_raise_irq(PS2State *s); 1008498bb8dSGerd Hoffmann void ps2_queue(PS2State *s, int b); 1017abe7eb2SGeoffrey McRae void ps2_queue_2(PS2State *s, int b1, int b2); 1027abe7eb2SGeoffrey McRae void ps2_queue_3(PS2State *s, int b1, int b2, int b3); 1037abe7eb2SGeoffrey McRae void ps2_queue_4(PS2State *s, int b1, int b2, int b3, int b4); 104*54334e73SMark Cave-Ayland void ps2_keyboard_set_translation(PS2KbdState *s, int mode); 105*54334e73SMark Cave-Ayland void ps2_mouse_fake_event(PS2MouseState *s); 1062a6505b0SSven Schnelle int ps2_queue_empty(PS2State *s); 1070d09e41aSPaolo Bonzini 108175de524SMarkus Armbruster #endif /* HW_PS2_H */ 109