ps2kbd.c (154972aff898a787b38af3bab5b8d754b5a42447) ps2kbd.c (b0de25cb23668fa4535078d18a0618eee442c000)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
5 * Copyright (c) 2015 Nahanni Systems Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 164 unchanged lines hidden (view full) ---

173 0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
174 0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x36, 0x4e,
175 0x0e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
176 0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
177 0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
178 0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
179};
180
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
5 * Copyright (c) 2015 Nahanni Systems Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 164 unchanged lines hidden (view full) ---

173 0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
174 0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x36, 0x4e,
175 0x0e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
176 0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
177 0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
178 0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
179};
180
181/* ScanCode set1 to set2 lookup table */
182const uint8_t keyset1to2_translations[128] = {
183 0, 0x76, 0x16, 0x1E, 0x26, 0x25, 0x2e, 0x36,
184 0x3d, 0x3e, 0x46, 0x45, 0x4e, 0x55, 0x66, 0x0d,
185 0x15, 0x1d, 0x24, 0x2d, 0x2c, 0x35, 0x3c, 0x43,
186 0x44, 0x4d, 0x54, 0x5b, 0x5a, 0x14, 0x1c, 0x1b,
187 0x23, 0x2b, 0x34, 0x33, 0x3b, 0x42, 0x4b, 0x4c,
188 0x52, 0x0e, 0x12, 0x5d, 0x1a, 0x22, 0x21, 0x2a,
189 0x32, 0x31, 0x3a, 0x41, 0x49, 0x4a, 0x59, 0x7c,
190 0x11, 0x29, 0x58, 0x05, 0x06, 0x04, 0x0c, 0x03,
191 0x0b, 0x83, 0x0a, 0x01, 0x09, 0x77, 0x7e, 0x6c,
192 0x75, 0x7d, 0x7b, 0x6b, 0x73, 0x74, 0x79, 0x69,
193 0x72, 0x7a, 0x70, 0x71, 0x84, 0x60, 0x61, 0x78,
194 0x07, 0x0f, 0x17, 0x1f, 0x27, 0x2f, 0x37, 0x3f,
195 0x47, 0x4f, 0x56, 0x5e, 0x08, 0x10, 0x18, 0x20,
196 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x57, 0x6f,
197 0x13, 0x19, 0x39, 0x51, 0x53, 0x5c, 0x5f, 0x62,
198 0x63, 0x64, 0x65, 0x67, 0x68, 0x6a, 0x6d, 0x6e,
199};
200
181static void
182fifo_init(struct ps2kbd_softc *sc)
183{
184 struct fifo *fifo;
185
186 fifo = &sc->fifo;
187 fifo->size = sizeof(((struct fifo *)0)->buf);
188}

--- 118 unchanged lines hidden (view full) ---

307 pthread_mutex_unlock(&sc->mtx);
308}
309
310/*
311 * Translate keysym to type 2 scancode and insert into keyboard buffer.
312 */
313static void
314ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
201static void
202fifo_init(struct ps2kbd_softc *sc)
203{
204 struct fifo *fifo;
205
206 fifo = &sc->fifo;
207 fifo->size = sizeof(((struct fifo *)0)->buf);
208}

--- 118 unchanged lines hidden (view full) ---

327 pthread_mutex_unlock(&sc->mtx);
328}
329
330/*
331 * Translate keysym to type 2 scancode and insert into keyboard buffer.
332 */
333static void
334ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
315 int down, uint32_t keysym)
335 int down, uint32_t keysym, uint32_t keycode)
316{
317 assert(pthread_mutex_isowned_np(&sc->mtx));
318 int e0_prefix, found;
319 uint8_t code;
320 const struct extended_translation *trans;
321
336{
337 assert(pthread_mutex_isowned_np(&sc->mtx));
338 int e0_prefix, found;
339 uint8_t code;
340 const struct extended_translation *trans;
341
322 found = 0;
323 if (keysym < 0x80) {
324 code = ascii_translations[keysym];
325 e0_prefix = 0;
342 if (keycode) {
343 code = keyset1to2_translations[(uint8_t)(keycode & 0x7f)];
344 e0_prefix = ((keycode & 0x80) ? SCANCODE_E0_PREFIX : 0);
326 found = 1;
327 } else {
345 found = 1;
346 } else {
328 for (trans = &(extended_translations[0]); trans->keysym != 0;
329 trans++) {
330 if (keysym == trans->keysym) {
331 code = trans->scancode;
332 e0_prefix = trans->flags & SCANCODE_E0_PREFIX;
333 found = 1;
334 break;
347 found = 0;
348 if (keysym < 0x80) {
349 code = ascii_translations[keysym];
350 e0_prefix = 0;
351 found = 1;
352 } else {
353 for (trans = &(extended_translations[0]); trans->keysym != 0;
354 trans++) {
355 if (keysym == trans->keysym) {
356 code = trans->scancode;
357 e0_prefix = trans->flags & SCANCODE_E0_PREFIX;
358 found = 1;
359 break;
360 }
335 }
336 }
337 }
338
339 if (!found) {
340 EPRINTLN("Unhandled ps2 keyboard keysym 0x%x", keysym);
341 return;
342 }
343
344 if (e0_prefix)
345 fifo_put(sc, 0xe0);
346 if (!down)
347 fifo_put(sc, 0xf0);
348 fifo_put(sc, code);
349}
350
351static void
361 }
362 }
363 }
364
365 if (!found) {
366 EPRINTLN("Unhandled ps2 keyboard keysym 0x%x", keysym);
367 return;
368 }
369
370 if (e0_prefix)
371 fifo_put(sc, 0xe0);
372 if (!down)
373 fifo_put(sc, 0xf0);
374 fifo_put(sc, code);
375}
376
377static void
352ps2kbd_event(int down, uint32_t keysym, void *arg)
378ps2kbd_event(int down, uint32_t keysym, uint32_t keycode, void *arg)
353{
354 struct ps2kbd_softc *sc = arg;
355 int fifo_full;
356
357 pthread_mutex_lock(&sc->mtx);
358 if (!sc->enabled) {
359 pthread_mutex_unlock(&sc->mtx);
360 return;
361 }
362 fifo_full = sc->fifo.num == PS2KBD_FIFOSZ;
379{
380 struct ps2kbd_softc *sc = arg;
381 int fifo_full;
382
383 pthread_mutex_lock(&sc->mtx);
384 if (!sc->enabled) {
385 pthread_mutex_unlock(&sc->mtx);
386 return;
387 }
388 fifo_full = sc->fifo.num == PS2KBD_FIFOSZ;
363 ps2kbd_keysym_queue(sc, down, keysym);
389 ps2kbd_keysym_queue(sc, down, keysym, keycode);
364 pthread_mutex_unlock(&sc->mtx);
365
366 if (!fifo_full)
367 atkbdc_event(sc->atkbdc_sc, 1);
368}
369
370struct ps2kbd_softc *
371ps2kbd_init(struct atkbdc_softc *atkbdc_sc)

--- 13 unchanged lines hidden ---
390 pthread_mutex_unlock(&sc->mtx);
391
392 if (!fifo_full)
393 atkbdc_event(sc->atkbdc_sc, 1);
394}
395
396struct ps2kbd_softc *
397ps2kbd_init(struct atkbdc_softc *atkbdc_sc)

--- 13 unchanged lines hidden ---