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 #define TYPE_I8042 "i8042" 43 OBJECT_DECLARE_SIMPLE_TYPE(ISAKBDState, I8042) 44 45 struct ISAKBDState { 46 ISADevice parent_obj; 47 48 KBDState kbd; 49 bool kbd_throttle; 50 MemoryRegion io[2]; 51 uint8_t kbd_irq; 52 uint8_t mouse_irq; 53 }; 54 55 #define TYPE_I8042_MMIO "i8042-mmio" 56 OBJECT_DECLARE_SIMPLE_TYPE(MMIOKBDState, I8042_MMIO) 57 58 struct MMIOKBDState { 59 SysBusDevice parent_obj; 60 61 KBDState kbd; 62 uint32_t size; 63 MemoryRegion region; 64 }; 65 66 #define I8042_A20_LINE "a20" 67 68 69 MMIOKBDState *i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, 70 ram_addr_t size, hwaddr mask); 71 void i8042_isa_mouse_fake_event(ISAKBDState *isa); 72 void i8042_setup_a20_line(ISADevice *dev, qemu_irq a20_out); 73 74 static inline bool i8042_present(void) 75 { 76 bool amb = false; 77 return object_resolve_path_type("", TYPE_I8042, &amb) || amb; 78 } 79 80 /* 81 * ACPI v2, Table 5-10 - Fixed ACPI Description Table Boot Architecture 82 * Flags, bit offset 1 - 8042. 83 */ 84 static inline uint16_t iapc_boot_arch_8042(void) 85 { 86 return i8042_present() ? 0x1 << 1 : 0x0 ; 87 } 88 89 #endif /* HW_INPUT_I8042_H */ 90