Skip to contentSkip to conversation

hw/input: add basic support for a PCI PS/2 controller

RFC New Liav Albani 1 participant 2 messages May 19, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover hw/input: add basic support for a PCI PS/2 controller

This small patch I wrote might raise few questions on the motivation to why someone would write such thing like this - I'll try my best to be descriptive about this.

I am SerenityOS developer. In that project I mainly work on kernel stuff for the most part.
Recently I started to fix issues with the HID code in the SerenityOS kernel and I stumbled upon fixing some issues with our PS/2 abstractions in relation to hardware implementations (such as the i8042) and the rest of the HID subsystem. I figured that it would be nice that with strong abstractions in place that I could write more drivers for other PS2 serial IO controllers.

That's where I started to look into the Linux source code and I found that sometime in the past, someone wrote a driver for PS/2 controller, which is connected over the PCI bus. This driver is called pcips2 and almost nobody touched it since its initial write in 2003 (by now it's 20 years old, so getting hardware to test it might be even harder today!).

Therefore, my goal was to see if I could actually use that driver, and so I wrote this small patch for letting QEMU to emulate that very old PS/2 PCI card. If this ever goes into the tree, a SerenityOS kernel driver could be written too, and will probably be used someday in our upcoming aarch64 port (probably for the virt machine as it supports the PCI bus).

As for what it gives, keyboard works perfectly fine. I had some struggle with interrupts initially (mainly getting "bogus" interrupts). As for the mouse support - I tried to boot Manjaro live-CD on QEMU with either both of the "pci-ps2-keyboard" and "pci-ps2-mouse" devices and also with only "pci-ps2-mouse" - both options resulted in a kernel panic a few seconds after booting. The panic seemed to be some sort of nullptr dereference in the linux PS/2 core code, which I still need to debug.

In general, this potentially could benefit multiple projects, which is the best case I'd imagine - more emulation options for QEMU, more drivers for SerenityOS, and maybe even fixing issues in PS/2 core (in Linux) and improving the pcips2 driver code in Linux as well.

Liav Albani (1):
hw/input: add basic support for a PCI PS/2 controller

 hw/i386/Kconfig           |   1 +
 hw/input/Kconfig          |   5 +
 hw/input/meson.build      |   2 +
 hw/input/ps2pci.c         | 282 ++++++++++++++++++++++++++++++++++++++
 include/hw/input/ps2pci.h |  52 +++++++
 5 files changed, 342 insertions(+)
 create mode 100644 hw/input/ps2pci.c
 create mode 100644 include/hw/input/ps2pci.h
Signature · 1 line
2.40.1
#1 lore raw

RFC 1/1 hw/input: add basic support for a PCI PS/2 controller

The linux pcips2 driver is responsible for driving this device.

---
 hw/i386/Kconfig           |   1 +
 hw/input/Kconfig          |   5 +
 hw/input/meson.build      |   2 +
 hw/input/ps2pci.c         | 282 ++++++++++++++++++++++++++++++++++++++
 include/hw/input/ps2pci.h |  52 +++++++
 5 files changed, 342 insertions(+)
 create mode 100644 hw/input/ps2pci.c
 create mode 100644 include/hw/input/ps2pci.h
hw/i386/Kconfig +1 -0
index d40802d..dad6188 100644
@@ -36,6 +36,7 @@ config PC
     select I8259
     select I8254
     select PCKBD
+    select PS2PCI
     select PCSPK
     select I8257
     select MC146818RTC
hw/input/Kconfig +5 -0
index 55865bb..04c97e8 100644
@@ -17,6 +17,11 @@ config PL050
     bool
     select PS2
 
+config PS2PCI
+    bool
+    depends on PCI
+    select PS2
+
 config PS2
     bool
 
hw/input/meson.build +2 -0
index 8deb011..4fa1462 100644
@@ -16,3 +16,5 @@ softmmu_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input
 softmmu_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_keypad.c'))
 softmmu_ss.add(when: 'CONFIG_TSC210X', if_true: files('tsc210x.c'))
 softmmu_ss.add(when: 'CONFIG_LASIPS2', if_true: files('lasips2.c'))
+
+softmmu_ss.add(when: 'CONFIG_PS2PCI', if_true: files('ps2pci.c'))
hw/input/ps2pci.c new file +282 -0

282 lines not on this page · raw message

include/hw/input/ps2pci.h new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.40.1