WSKBD(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… WSKBD(9) β€” Kernel Developer's Manual πŸ’…

Okay bestie, buckle up because we're diving into wskbd, the wscons keyboard support module. This is the manual page for all the keyboard magic that happens under the hood β€” and yes, it's giving kernel developer energy but we're gonna make it make sense. πŸŽ€


πŸ‘‘ NAME πŸ‘‘

So the whole squad is here: wskbd, wskbd_input, wskbd_rawinput, wskbd_cnattach, wskbd_cndetach, and wskbddevprint. Together they're literally the wscons keyboard support system. Obsessed. ✨


✨ SYNOPSIS ✨

First things first, you gotta include all the right headers or nothing works. No cap.

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wskbdvar.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>

Then here's the function lineup, all iconic:

void
wskbd_input(struct device *kbddev, u_int type, int value);

void
wskbd_rawinput(struct device *kbddev, u_char *buf, int len);

void
wskbd_cnattach(const struct wskbd_consops *consops, void *conscookie,
    const struct wskbd_mapdata *mapdata);

void
wskbd_cndetach(void);

int
wskbddevprint(void *aux, const char *pnp);

πŸ’– DESCRIPTION πŸ’–

So the wskbd module is a whole component of the wscons(9) framework β€” it's what gives you machine-independent keyboard support. Most of the heavy lifting is done by the wskbd(4) device driver, and that driver has to be a child of the hardware device driver. That's the hierarchy, bestie. Don't mess with it. 🌸


πŸŽ€ DATA TYPES πŸŽ€

Keyboard drivers that support wscons keyboards get to play with these data types. Let's go through them one by one, yeah?

kbd_t

An opaque type that describes keyboard properties. It's giving mysterious. πŸ‘‘

keysym_t

The wscons keyboard-independent symbolic representation of the keypress. So when you press a key, this is the symbolic glow-up version of it.

struct wskbd_accessops

This structure is where you specify the keyboard access functions. Every keyboard must provide this structure and pass it to the wskbd(4) child device. It has these members:

int     (*enable)(void *, int);
void    (*set_leds)(void *, int);
int     (*ioctl)(void *v, u_long cmd, void *data,
                int flag, struct lwp *l);

So here's the tea:

  • The enable member defines the function that gets called to enable keypress passing to wscons.
  • The set_leds member defines the function that gets called to set the LEDs on the keyboard.
  • The ioctl member defines the function that gets called to perform keyboard-specific ioctl calls.

And there's a void * cookie provided by the keyboard driver that's associated with these functions β€” it gets passed to them when they're invoked. Cute. 🫢

struct wskbd_consops

This one specifies the keyboard console operations. All keyboards that can operate as a console must provide this structure and pass it to the wskbd(4) child device. If the keyboard can't be a console, you don't have to specify it. It has these members:

void    (*getc)(void *, u_int *, int *);
void    (*pollc)(void *, int);
void    (*bell)(void *, u_int, u_int, u_int);

Again, there's a void * cookie provided by the keyboard driver that's associated with these functions, and it gets passed to them when they're invoked. πŸ’–

struct wscons_keydesc

This structure describes a keyboard mapping table that converts keyboard-specific keycodes to wscons keysyms. It has these members:

kbd_t   name;           /* name of this map */
kbd_t   base;           /* map this one is based on */
int     map_size;       /* size of map */
const   keysym_t *map;  /* the map itself */

struct wskbd_mapdata

This one describes the keyboard layout and operation to interpret the keyboard layout. It contains these members:

const struct wscons_keydesc *keydesc;
kbd_t layout;

struct wskbddev_attach_args

This structure is used to attach the wskbd(4) child device. It has these members:

int console;
const struct wskbd_mapdata *keymap;
const struct wskbd_accessops *accessops;
void *accesscookie;

πŸ”‘ Keymaps πŸ”‘

Keymaps are a dense stream of keysym_t. A declaration has these fields:

pos [cmd] normal [shift] [altgr] [shift-altgr]

Here's what each field means, bestie:

  • pos β€” Always specified as KC(pos) and starts the description of key pos.
  • cmd β€” If the command modifier (KS_Cmd_XXX) is active, the optional command cmd is invoked.
  • normal β€” The keysym if no modifiers are active.
  • shift β€” The keysym if the shift modifier is active.
  • altgr β€” The keysym if the alt-gr modifier is active.
  • shift-altgr β€” The keysym if the shift-alt-gr modifier is active.

If the keysym after pos is not KS_Cmd_XXX, then cmd is empty. The shift, altgr, and shift-altgr fields are determined from previous fields if they aren't specified. So there are exactly four valid keysym declarations:

pos [cmd] normal

pos [cmd] normal shift

pos [cmd] normal shift altgr

pos [cmd] normal shift altgr shift-altgr

Slay. ✨


πŸ”₯ FUNCTIONS πŸ”₯

Okay now the main characters:

wskbd_input(kbddev, type, value)

Pass the keypress of value and type type to the wscons keyboard driver. Valid values of type are:

  • WSCONS_EVENT_KEY_UP β€” Key released.
  • WSCONS_EVENT_KEY_DOWN β€” Key pressed.

wskbd_rawinput(kbddev, buf, len)

Pass the raw keypress in the buffer buf to the wscons keyboard driver. The buffer is len bytes long. This function should only be called if the kernel option WSDISPLAY_COMPAT_RAWKBD is enabled. Don't forget, okay? 😭

wskbd_cnattach(consops, conscookie, mapdata)

Attach this keyboard as the console input by specifying the console operations consops and the keyboard mapping table information in mapdata. The functions specified in consops will be called with conscookie as the first argument. Iconic behavior. πŸ‘‘

wskbd_cndetach()

Detach this keyboard as the console input. Simple, clean, goodbye. πŸ‘‹

wskbddevprint(aux, pnp)

The default wskbd printing routine used by config_found(). (See autoconf(9).)


🌈 AUTOCONFIGURATION 🌈

Keyboard drivers that want to use the wskbd module must be a parent to the wskbd(4) device and provide an attachment interface. To attach the wskbd(4) device, the keyboard driver must allocate and populate a wskbddev_attach_args structure with the supported operations and callbacks, and then call config_found() to perform the attach (see autoconf(9)).

Here's the breakdown:

  • The keymap member points to the wskbd_mapdata structure, which describes the keycode mapping operations.
  • The accessops member points to the wskbd_accessops structure, which describes the keyboard access operations.
  • The console member is a boolean that tells wscons whether this keyboard will be used for console input.

That's it, that's the whole vibe. πŸ’…


πŸ’… OPERATION πŸ’…

If the keyboard belongs to the system console, it must register the wskbd_consops structure specifying the console operations via wskbd_cnattach() at console attach time. Got it? Good.

When a keypress arrives from the keyboard, the keyboard driver must perform any necessary character decoding to wscons events and pass the events to wscons via wskbd_input(). If the kernel is compiled with the option WSDISPLAY_COMPAT_RAWKBD, then the keyboard driver must also pass the raw keyboard data to wscons via wskbd_rawinput().

The wscons framework calls back into the hardware driver by invoking the functions specified in the accessops structure. The enable() and set_leds() functions are relatively simple and self-explanatory. The ioctl() function is called by the wscons interface to perform keyboard-specific ioctl operations (see ioctl(2)). The argument cmd to the ioctl() function specifies the specific command to perform using the data data. Valid commands are listed in sys/dev/wscons/wsconsio.h. πŸ”₯


🧚 CODE REFERENCES 🧚

The wscons subsystem is implemented within the directory sys/dev/wscons. The wskbd module itself is implemented within the files sys/dev/wscons/wskbd.c and sys/dev/wscons/wskbdutil.c. ioctl(2) operations are listed in sys/dev/wscons/wsconsio.h. So if you're looking for the source, that's where it's at. πŸ“


πŸ“ SEE ALSO πŸ“


And that's the whole manual, bestie! This page is from Debian, dated April 6, 2025, for WSKBD(9). You're officially a kernel keyboard expert now. Periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from