Input: gscps2 - supply PA-RISC keyboard keymap via device property
Subsystems (3)
Dmitry Torokhov
maintainerPATCH 1/1 Input: gscps2 - supply PA-RISC keyboard keymap via device property
Instead of hardcoding PA-RISC specific keycode tables into atkbd via compile-time inclusion, have the gscps2 PS/2 port driver attach a linux,keymap software node device property to the serio device when a keyboard port is registered. This allows atkbd to dynamically fetch and apply the custom keymap when probing the port using generic firmware property helpers, removing architecture-specific hacks from generic keyboard driver code.
Co-locate the keymap definitions with the serio port driver by moving hpps2atkbd.h from drivers/input/keyboard/ to drivers/input/serio/. To handle the five conflicting keys on RDI PrecisionBook laptops without runtime model string checks or duplicate keymap tables in memory, add CONFIG_SERIO_GSCPS2_RDI_KEYCODES to drivers/input/serio/Kconfig and resolve the conflicting keycodes at compile time via preprocessor macros.
---
v2:
- instead of using device_create_managed_software_node() that has issue if serio port is unregistered before it is fully registered, switch to creating software node when initializing the driver and attach it to the serio port
- added keycodes lost in movement (0x92 - silently ignored, 0xca - KEY_KPSLASH, 0xda - KEY_KPENTER).
drivers/input/keyboard/Kconfig | 38 --------- drivers/input/keyboard/atkbd.c | 8 -- drivers/input/keyboard/hpps2atkbd.h | 110 ------------------------- drivers/input/serio/Kconfig | 27 +++++++ drivers/input/serio/gscps2.c | 47 ++++++++--- drivers/input/serio/hpps2atkbd.h | 120 ++++++++++++++++++++++++++++ 6 files changed, 184 insertions(+), 166 deletions(-)
drivers/input/keyboard/Kconfig +0 -38
@@ -119,44 +119,6 @@ config KEYBOARD_ATKBD To compile this driver as a module, choose M here: the module will be called atkbd. -config KEYBOARD_ATKBD_HP_KEYCODES - bool "Use HP keyboard scancodes" - depends on PARISC && KEYBOARD_ATKBD - default y - help - Say Y here if you have a PA-RISC machine and want to use an AT or - PS/2 keyboard, and your keyboard uses keycodes that are specific to - PA-RISC keyboards. - - Say N if you use a standard keyboard. - -config KEYBOARD_ATKBD_RDI_KEYCODES - bool "Use PrecisionBook keyboard scancodes" - depends on KEYBOARD_ATKBD_HP_KEYCODES - default n - help - If you have an RDI PrecisionBook, say Y here if you want to use its - built-in keyboard (as opposed to an external keyboard). - - The PrecisionBook has five keys that conflict with those used by most - AT and PS/2 keyboards. These are as follows: - - PrecisionBook Standard AT or PS/2 - - F1 F12 - Left Ctrl Left Alt - Caps Lock Left Ctrl - Right Ctrl Caps Lock - Left 102nd key (the key to the right of Left Shift) - - If you say N here, and use the PrecisionBook keyboard, then each key - in the left-hand column will be interpreted as the corresponding key - in the right-hand column. - - If you say Y here, and use an external keyboard, then each key in the - right-hand column will be interpreted as the key shown in the - left-hand column. - config KEYBOARD_QT1050 tristate "Microchip AT42QT1050 Touch Sensor Chip" depends on I2C
drivers/input/keyboard/atkbd.c +0 -8
@@ -73,13 +73,6 @@ MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard conne#define ATKBD_KEYMAP_SIZE 512static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE ] = { -#ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES - -/* XXX: need a more general approach */ - -#include "hpps2atkbd.h" /* include the keyboard scancodes */ - -#else0 ,67 ,65 ,63 ,61 ,59 ,60 ,88 ,183 ,68 ,66 ,64 ,62 ,15 ,41 ,117 ,184 ,56 ,42 ,93 ,29 ,16 ,2 ,0 ,185 ,0 ,44 ,31 ,30 ,17 ,3 ,0 ,186 ,46 ,45 ,32 ,18 ,5 ,4 ,95 ,187 ,57 ,47 ,33 ,20 ,19 ,6 ,183 ,
@@ -99,7 +92,6 @@ static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE] = {110 ,111 ,108 ,112 ,106 ,103 ,0 ,119 ,0 ,118 ,109 ,0 ,99 ,104 ,119 ,0 , 0, 0, 0, 65, 99, -#endif }; static const unsigned short atkbd_set3_keycode[ATKBD_KEYMAP_SIZE] = {
drivers/input/keyboard/hpps2atkbd.h deleted +0 -110
110 lines not on this page · raw message
drivers/input/serio/Kconfig +27 -0
@@ -106,6 +106,33 @@ config SERIO_GSCPS2 To compile this driver as a module, choose M here: the module will be called gscps2. +config SERIO_GSCPS2_RDI_KEYCODES + bool "Use PrecisionBook keyboard scancodes" + depends on SERIO_GSCPS2 + default n + help + If you have an RDI PrecisionBook, say Y here if you want to use its + built-in keyboard (as opposed to an external keyboard). + + The PrecisionBook has five keys that conflict with those used by most + AT and PS/2 keyboards. These are as follows: + + PrecisionBook Standard AT or PS/2 + + F1 F12 + Left Ctrl Left Alt + Caps Lock Left Ctrl + Right Ctrl Caps Lock + Left 102nd key (the key to the right of Left Shift) + + If you say N here, and use the PrecisionBook keyboard, then each key + in the left-hand column will be interpreted as the corresponding key + in the right-hand column. + + If you say Y here, and use an external keyboard, then each key in the + right-hand column will be interpreted as the key shown in the + left-hand column. + config HP_SDC tristate "HP System Device Controller i8042 Support" depends on (GSC || HP300) && SERIO
drivers/input/serio/gscps2.c +37 -10
96 lines not on this page · raw message
drivers/input/serio/hpps2atkbd.h new file +120 -0
120 lines not on this page · raw message
Signature · 5 lines
2.55.0.508.g3f0d502094-goog -- Dmitry
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-after-free in shared interrupt handler during device removal.
- [High] Data race and hardware state corruption due to missing lock in gscps2_flush(). --
--- Patch [1]: [PATCH] Input: gscps2 - supply PA-RISC keyboard keymap via device property --- commit a01a8cad369fa3c00ef5c659a70dd84ac7f1e275
Author: Dmitry Torokhov <[email protected]>
Input: gscps2 - supply PA-RISC keyboard keymap via device property
This commit modifies the gscps2 PS/2 port driver to attach a software node with a linux,keymap property to the serio device. This replaces compile-time architecture-specific keyboard hacks in the generic atkbd driver. It also moves the keymap definitions to the serio driver and resolves conflicting keys via a compile-time config.
Quoted 4 lines
drivers/input/serio/gscps2.c +0
-0
[ ... ]
drivers/input/serio/gscps2.c static void __exit gscps2_remove(struct parisc_device *dev) · line 456
Quoted 9 lines
drivers/input/serio/gscps2.c +3
-0@@ -434,6 +449,9 @@ static void __exit gscps2_remove(struct parisc_device *dev) {struct gscps2port *ps2port =dev_get_drvdata (&dev->dev); +if (ps2port->id ==GSC_ID_KEYBOARD ) +device_remove_software_node (&ps2port->port->dev); +serio_unregister_port (ps2port->port);free_irq (dev->irq, ps2port);
[Severity: High]
This is a pre-existing issue, but could this sequence in gscps2_remove() lead to a use-after-free if a shared interrupt fires?
serio_unregister_port() synchronously disconnects the driver and drops the reference to the port, freeing the serio structure. However, the device remains in ps2port_list and the shared IRQ is still active since free_irq() hasn't been called yet.
If another device on the same shared IRQ line triggers an interrupt during this window, gscps2_interrupt() will iterate over ps2port_list, find this port, and call serio_interrupt(ps2port->port, ...).
Since ps2port->port was just freed by serio_unregister_port(), will this dereference freed memory?
Should the device be removed from ps2port_list and its IRQ disabled via free_irq() before unregistering the serio port?
drivers/input/serio/gscps2.c static void __exit gscps2_remove(struct parisc_device *dev) · line 457
Quoted 1 line
drivers/input/serio/gscps2.c +0
-0gscps2_flush (ps2port);
[Severity: High]
This is also a pre-existing issue, but is there a missing lock in gscps2_flush() that causes a data race?
Looking at gscps2_flush():
static void gscps2_flush(struct gscps2port *ps2port)
{
while (gscps2_readb_status(ps2port->addr) & GSC_STAT_RBNE)
gscps2_readb_input(ps2port->addr);
ps2port->act = ps2port->append = 0;
}This modifies the shared act and append indices and reads hardware registers without acquiring ps2port->lock.
When gscps2_open() executes, it calls gscps2_reset() which in turn calls gscps2_flush(). Since the shared IRQ is requested prior to registration, a concurrent interrupt triggered by another shared device could cause gscps2_interrupt() to run.
Because gscps2_interrupt() acquires the lock, reads the same registers, and modifies append via gscps2_read_data(), will this cause non-serialized hardware access and buffer state corruption?
Quoted 2 lines
drivers/input/serio/gscps2.c +0
-0list_del (&ps2port->node);iounmap (ps2port->addr);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Helge Deller
maintainerHi Dmitry,
Quoted 28 lines · Dmitry Torokhov
Instead of hardcoding PA-RISC specific keycode tables into atkbd via compile-time inclusion, have the gscps2 PS/2 port driver attach a linux,keymap software node device property to the serio device when a keyboard port is registered. This allows atkbd to dynamically fetch and apply the custom keymap when probing the port using generic firmware property helpers, removing architecture-specific hacks from generic keyboard driver code.
Co-locate the keymap definitions with the serio port driver by moving
hpps2atkbd.hfromdrivers/input/keyboard/todrivers/input/serio/. To handle the five conflicting keys on RDI PrecisionBook laptops without runtime model string checks or duplicate keymap tables in memory, addCONFIG_SERIO_GSCPS2_RDI_KEYCODEStodrivers/input/serio/Kconfigand resolve the conflicting keycodes at compile time via preprocessor macros.Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>---
v2:
- instead of usingdevice_create_managed_software_node()that has issue if serio port is unregistered before it is fully registered, switch to creating software node when initializing the driver and attach it to the serio port
- added keycodes lost in movement (0x92- silently ignored,0xca-KEY_KPSLASH,0xda-KEY_KPENTER).
Quoted 7 lines
drivers/input/keyboard/Kconfig | 38 --------- drivers/input/keyboard/atkbd.c | 8 -- drivers/input/keyboard/hpps2atkbd.h | 110 ------------------------- drivers/input/serio/Kconfig | 27 +++++++ drivers/input/serio/gscps2.c | 47 ++++++++--- drivers/input/serio/hpps2atkbd.h | 120 ++++++++++++++++++++++++++++ 6 files changed, 184 insertions(+), 166 deletions(-)
Thanks for cleaning it up.
Your solution is much cleaner and gets the hacks away. I'll test and report back very soon.
Quoted 17 lines
drivers/input/serio/gscps2.c +1
-6@@ -22,20 +22,19 @@* was usable/enabled ?) */ -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/serio.h> +#include <linux/delay.h> #include <linux/input.h> #include <linux/interrupt.h> -#include <linux/spinlock.h> -#include <linux/delay.h>
drivers/input/serio/gscps2.c line 36
Quoted 10 lines
drivers/input/serio/gscps2.c +4
-1+#include <linux/io.h> #include <linux/ioport.h> +#include <linux/property.h> +#include <linux/serio.h> #include <asm/irq.h> -#include <asm/io.h> #include <asm/parisc-device.h> +#include "hpps2atkbd.h"
Doesn't it makes sense to move the contents of the new file "hpps2atkbd.h" directly in here instead of keeping in own header?
Helge
Quoted 62 lines · Helge Deller
Hi Dmitry,
Quoted 28 lines · Dmitry Torokhov
Instead of hardcoding PA-RISC specific keycode tables into atkbd via compile-time inclusion, have the gscps2 PS/2 port driver attach a linux,keymap software node device property to the serio device when a keyboard port is registered. This allows atkbd to dynamically fetch and apply the custom keymap when probing the port using generic firmware property helpers, removing architecture-specific hacks from generic keyboard driver code.
Co-locate the keymap definitions with the serio port driver by moving
hpps2atkbd.hfromdrivers/input/keyboard/todrivers/input/serio/. To handle the five conflicting keys on RDI PrecisionBook laptops without runtime model string checks or duplicate keymap tables in memory, addCONFIG_SERIO_GSCPS2_RDI_KEYCODEStodrivers/input/serio/Kconfigand resolve the conflicting keycodes at compile time via preprocessor macros.Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>---
v2:
- instead of usingdevice_create_managed_software_node()that has issue if serio port is unregistered before it is fully registered, switch to creating software node when initializing the driver and attach it to the serio port
- added keycodes lost in movement (0x92- silently ignored,0xca-KEY_KPSLASH,0xda-KEY_KPENTER).Quoted 7 lines
drivers/input/keyboard/Kconfig | 38 --------- drivers/input/keyboard/atkbd.c | 8 --
drivers/input/keyboard/hpps2atkbd.h| 110 ------------------------- drivers/input/serio/Kconfig | 27 +++++++ drivers/input/serio/gscps2.c | 47 ++++++++--- drivers/input/serio/hpps2atkbd.h | 120 ++++++++++++++++++++++++++++6 files changed, 184 insertions(+), 166 deletions(-)Thanks for cleaning it up.
Your solution is much cleaner and gets the hacks away. I'll test and report back very soon.Quoted 19 lines
drivers/input/serio/gscps2.c +3
-6@@ -22,20 +22,19 @@* was usable/enabled ?) */ -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/serio.h> +#include <linux/delay.h> #include <linux/input.h> #include <linux/interrupt.h> -#include <linux/spinlock.h> -#include <linux/delay.h> +#include <linux/io.h> #include <linux/ioport.h> +#include <linux/property.h>
Quoted 8 lines
drivers/input/serio/gscps2.c line 36
Quoted 5 lines
drivers/input/serio/gscps2.c +2
-1+#include <linux/serio.h> #include <asm/irq.h> -#include <asm/io.h> #include <asm/parisc-device.h> +#include "hpps2atkbd.h" Doesn't it makes sense to move the contents of the new file "
hpps2atkbd.h" directly in here instead of keeping in own header?
Other than that, you may add:
Thanks!
Helge
Dmitry Torokhov
maintainerHi Helge,
Quoted 71 lines · Helge Deller
Quoted 62 lines · Helge Deller
Hi Dmitry,
Quoted 28 lines · Dmitry Torokhov
Instead of hardcoding PA-RISC specific keycode tables into atkbd via compile-time inclusion, have the gscps2 PS/2 port driver attach a linux,keymap software node device property to the serio device when a keyboard port is registered. This allows atkbd to dynamically fetch and apply the custom keymap when probing the port using generic firmware property helpers, removing architecture-specific hacks from generic keyboard driver code.
Co-locate the keymap definitions with the serio port driver by moving
hpps2atkbd.hfromdrivers/input/keyboard/todrivers/input/serio/. To handle the five conflicting keys on RDI PrecisionBook laptops without runtime model string checks or duplicate keymap tables in memory, addCONFIG_SERIO_GSCPS2_RDI_KEYCODEStodrivers/input/serio/Kconfigand resolve the conflicting keycodes at compile time via preprocessor macros.Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>---
v2:
- instead of usingdevice_create_managed_software_node()that has issue if serio port is unregistered before it is fully registered, switch to creating software node when initializing the driver and attach it to the serio port
- added keycodes lost in movement (0x92- silently ignored,0xca-KEY_KPSLASH,0xda-KEY_KPENTER).Quoted 7 lines
drivers/input/keyboard/Kconfig | 38 --------- drivers/input/keyboard/atkbd.c | 8 --
drivers/input/keyboard/hpps2atkbd.h| 110 ------------------------- drivers/input/serio/Kconfig | 27 +++++++ drivers/input/serio/gscps2.c | 47 ++++++++--- drivers/input/serio/hpps2atkbd.h | 120 ++++++++++++++++++++++++++++6 files changed, 184 insertions(+), 166 deletions(-)Thanks for cleaning it up.
Your solution is much cleaner and gets the hacks away. I'll test and report back very soon.Quoted 19 lines
drivers/input/serio/gscps2.c +3
-6@@ -22,20 +22,19 @@* was usable/enabled ?) */ -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/serio.h> +#include <linux/delay.h> #include <linux/input.h> #include <linux/interrupt.h> -#include <linux/spinlock.h> -#include <linux/delay.h> +#include <linux/io.h> #include <linux/ioport.h> +#include <linux/property.h> Quoted 8 lines
drivers/input/serio/gscps2.c line 36
Quoted 5 lines
drivers/input/serio/gscps2.c +2
-1+#include <linux/serio.h> #include <asm/irq.h> -#include <asm/io.h> #include <asm/parisc-device.h> +#include "hpps2atkbd.h" Doesn't it makes sense to move the contents of the new file "
hpps2atkbd.h" directly in here instead of keeping in own header?
Quoted 4 lines
Other than that, you may add:
Acked-by Helge Deller <[email protected]>Tested-by Helge Deller <[email protected]>
Thank you very much for testing it. I went ahead and merged the header into the driver code and applied.
I have a few more cleanups since I've been looking at the driver, I'll send them out in a couple of days.
Thanks.
Signature · 1 line
Dmitry