1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef HW_PS2_H
26#define HW_PS2_H
27
28#include "hw/sysbus.h"
29
30#define PS2_MOUSE_BUTTON_LEFT 0x01
31#define PS2_MOUSE_BUTTON_RIGHT 0x02
32#define PS2_MOUSE_BUTTON_MIDDLE 0x04
33#define PS2_MOUSE_BUTTON_SIDE 0x08
34#define PS2_MOUSE_BUTTON_EXTRA 0x10
35
36struct PS2DeviceClass {
37 SysBusDeviceClass parent_class;
38
39 ResettablePhases parent_phases;
40};
41
42
43
44
45
46#define PS2_BUFFER_SIZE 256
47
48typedef struct {
49 uint8_t data[PS2_BUFFER_SIZE];
50 int rptr, wptr, cwptr, count;
51} PS2Queue;
52
53
54#define PS2_DEVICE_IRQ 0
55
56struct PS2State {
57 SysBusDevice parent_obj;
58
59 PS2Queue queue;
60 int32_t write_cmd;
61 qemu_irq irq;
62};
63
64#define TYPE_PS2_DEVICE "ps2-device"
65OBJECT_DECLARE_TYPE(PS2State, PS2DeviceClass, PS2_DEVICE)
66
67struct PS2KbdState {
68 PS2State parent_obj;
69
70 int scan_enabled;
71 int translate;
72 int scancode_set;
73 int ledstate;
74 bool need_high_bit;
75 unsigned int modifiers;
76};
77
78#define TYPE_PS2_KBD_DEVICE "ps2-kbd"
79OBJECT_DECLARE_SIMPLE_TYPE(PS2KbdState, PS2_KBD_DEVICE)
80
81struct PS2MouseState {
82 PS2State parent_obj;
83
84 uint8_t mouse_status;
85 uint8_t mouse_resolution;
86 uint8_t mouse_sample_rate;
87 uint8_t mouse_wrap;
88 uint8_t mouse_type;
89 uint8_t mouse_detect_state;
90 int mouse_dx;
91 int mouse_dy;
92 int mouse_dz;
93 int mouse_dw;
94 uint8_t mouse_buttons;
95};
96
97#define TYPE_PS2_MOUSE_DEVICE "ps2-mouse"
98OBJECT_DECLARE_SIMPLE_TYPE(PS2MouseState, PS2_MOUSE_DEVICE)
99
100
101void ps2_write_mouse(PS2MouseState *s, int val);
102void ps2_write_keyboard(PS2KbdState *s, int val);
103uint32_t ps2_read_data(PS2State *s);
104void ps2_queue_noirq(PS2State *s, int b);
105void ps2_queue(PS2State *s, int b);
106void ps2_queue_2(PS2State *s, int b1, int b2);
107void ps2_queue_3(PS2State *s, int b1, int b2, int b3);
108void ps2_queue_4(PS2State *s, int b1, int b2, int b3, int b4);
109void ps2_keyboard_set_translation(PS2KbdState *s, int mode);
110void ps2_mouse_fake_event(PS2MouseState *s);
111int ps2_queue_empty(PS2State *s);
112
113#endif
114