xref: /openbmc/qemu/include/hw/input/i8042.h (revision ed3a06b1)
1 /*
2  * QEMU PS/2 Controller
3  *
4  * Copyright (c) 2003 Fabrice Bellard
5  *
6  * SPDX-License-Identifier: MIT
7  */
8 #ifndef HW_INPUT_I8042_H
9 #define HW_INPUT_I8042_H
10 
11 #include "hw/isa/isa.h"
12 #include "hw/sysbus.h"
13 #include "qom/object.h"
14 
15 #define I8042_KBD_IRQ      0
16 #define I8042_MOUSE_IRQ    1
17 
18 typedef struct KBDState {
19     uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
20     uint8_t status;
21     uint8_t mode;
22     uint8_t outport;
23     uint32_t migration_flags;
24     uint32_t obsrc;
25     bool outport_present;
26     bool extended_state;
27     bool extended_state_loaded;
28     /* Bitmask of devices with data available.  */
29     uint8_t pending;
30     uint8_t obdata;
31     uint8_t cbdata;
32     uint8_t pending_tmp;
33     void *kbd;
34     void *mouse;
35     QEMUTimer *throttle_timer;
36 
37     qemu_irq irqs[2];
38     qemu_irq a20_out;
39     hwaddr mask;
40 } KBDState;
41 
42 /*
43  * QEMU interface:
44  * + Named GPIO input "ps2-kbd-input-irq": set to 1 if the downstream PS2
45  *   keyboard device has asserted its irq
46  * + Named GPIO input "ps2-mouse-input-irq": set to 1 if the downstream PS2
47  *   mouse device has asserted its irq
48  * + Named GPIO output "a20": A20 line for x86 PCs
49  * + Unnamed GPIO output 0-1: i8042 output irqs for keyboard (0) or mouse (1)
50  */
51 
52 #define TYPE_I8042 "i8042"
53 OBJECT_DECLARE_SIMPLE_TYPE(ISAKBDState, I8042)
54 
55 struct ISAKBDState {
56     ISADevice parent_obj;
57 
58     KBDState kbd;
59     bool kbd_throttle;
60     MemoryRegion io[2];
61     uint8_t kbd_irq;
62     uint8_t mouse_irq;
63 };
64 
65 /*
66  * QEMU interface:
67  * + sysbus MMIO region 0: MemoryRegion defining the command/status/data
68  *   registers (access determined by mask property and access type)
69  * + Named GPIO input "ps2-kbd-input-irq": set to 1 if the downstream PS2
70  *   keyboard device has asserted its irq
71  * + Named GPIO input "ps2-mouse-input-irq": set to 1 if the downstream PS2
72  *   mouse device has asserted its irq
73  * + Unnamed GPIO output 0-1: i8042 output irqs for keyboard (0) or mouse (1)
74  */
75 
76 #define TYPE_I8042_MMIO "i8042-mmio"
77 OBJECT_DECLARE_SIMPLE_TYPE(MMIOKBDState, I8042_MMIO)
78 
79 struct MMIOKBDState {
80     SysBusDevice parent_obj;
81 
82     KBDState kbd;
83     uint32_t size;
84     MemoryRegion region;
85 };
86 
87 #define I8042_A20_LINE "a20"
88 
89 
90 MMIOKBDState *i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
91                             ram_addr_t size, hwaddr mask);
92 void i8042_isa_mouse_fake_event(ISAKBDState *isa);
93 void i8042_setup_a20_line(ISADevice *dev, qemu_irq a20_out);
94 
95 static inline bool i8042_present(void)
96 {
97     bool amb = false;
98     return object_resolve_path_type("", TYPE_I8042, &amb) || amb;
99 }
100 
101 /*
102  * ACPI v2, Table 5-10 - Fixed ACPI Description Table Boot Architecture
103  * Flags, bit offset 1 - 8042.
104  */
105 static inline uint16_t iapc_boot_arch_8042(void)
106 {
107     return i8042_present() ? 0x1 << 1 : 0x0 ;
108 }
109 
110 #endif /* HW_INPUT_I8042_H */
111