- vdpa-dev: Fix initialisation order to restore VDUSE compatibility - tcg: Allow top bit of SIMD_DATA_BITS to be set in simd_desc() - migration: fix-possible-int-overflow - target/m68k: Map FPU exceptions to FPSR register - qemu-options: Fix CXL Fixed Memory Window interleave-granularity typo - hvf: arm: Fix encodings for ID_AA64PFR1_EL1 and debug System registers - hw/intc/arm_gic: Fix handling of NS view of GICC_APR<n> - qio: Inherit follow_coroutine_ctx across TLS - target/riscv: Fix the element agnostic function problem - accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded - tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers - migration: Fix file migration with fdset - ui/vnc: don't return an empty SASL mechlist to the client - target/arm: Fix FJCVTZS vs flush-to-zero - hw/ppc/e500: Prefer QOM cast - sphinx/qapidoc: Fix to generate doc for explicit, unboxed arguments - hw/ppc/e500: Remove unused "irqs" parameter - hw/ppc/e500: Add missing device tree properties to i2c controller node - hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb() - hw/arm/mps2-tz.c: fix RX/TX interrupts order - target/i386: csv: Add support to migrate the incoming context for CSV3 guest - target/i386: csv: Add support to migrate the outgoing context for CSV3 guest - target/i386: csv: Add support to migrate the incoming page for CSV3 guest - target/i386: csv: Add support to migrate the outgoing page for CSV3 guest - linux-headers: update kernel headers to include CSV3 migration cmds - vfio: Only map shared region for CSV3 virtual machine - vga: Force full update for CSV3 guest - target/i386: csv: Load initial image to private memory for CSV3 guest - target/i386: csv: Do not register/unregister guest secure memory for CSV3 guest - target/i386: cpu: Populate CPUID 0x8000_001F when CSV3 is active - target/i386: csv: Add command to load vmcb to CSV3 guest memory - target/i386: csv: Add command to load data to CSV3 guest memory - target/i386: csv: Add command to initialize CSV3 context - target/i386: csv: Add CSV3 context - next-kbd: convert to use qemu_input_handler_register() - qemu/bswap: Undefine CPU_CONVERT() once done - exec/memop: Remove unused memop_big_endian() helper - hw/nvme: fix handling of over-committed queues - 9pfs: fix crash on 'Treaddir' request - hw/misc/psp: Pin the hugepage memory specified by mem2 during use for psp - hw/misc: support tkm use mem2 memory - hw/i386: add mem2 option for qemu - kvm: add support for guest physical bits - target/i386: add guest-phys-bits cpu property Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com> (cherry picked from commit f45f35e88509a4ffa9f62332ee9601e9fe1f8d09)
225 lines
7.1 KiB
Diff
225 lines
7.1 KiB
Diff
From 91e07a78026caafa181134beeb8c5b79157718ad Mon Sep 17 00:00:00 2001
|
|
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
|
|
Date: Wed, 6 Nov 2024 12:09:27 +0000
|
|
Subject: [PATCH] next-kbd: convert to use qemu_input_handler_register()
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Convert the next-kbd device from the legacy UI qemu_add_kbd_event_handler()
|
|
function to use qemu_input_handler_register().
|
|
|
|
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
|
|
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
|
|
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
Message-ID: <20241106120928.242443-2-mark.cave-ayland@ilande.co.uk>
|
|
[thuth: Removed the NEXTKBD_NO_KEY definition - replaced by 0 now]
|
|
Signed-off-by: Thomas Huth <thuth@redhat.com>
|
|
Signed-off-by: Zhongrui Tang <tangzhongrui_yewu@cmss.chinamobile.com>
|
|
---
|
|
hw/m68k/next-kbd.c | 158 +++++++++++++++++++++++++++++----------------
|
|
1 file changed, 103 insertions(+), 55 deletions(-)
|
|
|
|
diff --git a/hw/m68k/next-kbd.c b/hw/m68k/next-kbd.c
|
|
index 0c348c18cf..880ebe3602 100644
|
|
--- a/hw/m68k/next-kbd.c
|
|
+++ b/hw/m68k/next-kbd.c
|
|
@@ -68,7 +68,6 @@ struct NextKBDState {
|
|
uint16_t shift;
|
|
};
|
|
|
|
-static void queue_code(void *opaque, int code);
|
|
|
|
/* lots of magic numbers here */
|
|
static uint32_t kbd_read_byte(void *opaque, hwaddr addr)
|
|
@@ -166,68 +165,70 @@ static const MemoryRegionOps kbd_ops = {
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
};
|
|
|
|
-static void nextkbd_event(void *opaque, int ch)
|
|
-{
|
|
- /*
|
|
- * Will want to set vars for caps/num lock
|
|
- * if (ch & 0x80) -> key release
|
|
- * there's also e0 escaped scancodes that might need to be handled
|
|
- */
|
|
- queue_code(opaque, ch);
|
|
-}
|
|
-
|
|
-static const unsigned char next_keycodes[128] = {
|
|
- 0x00, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x50, 0x4F,
|
|
- 0x4E, 0x1E, 0x1F, 0x20, 0x1D, 0x1C, 0x1B, 0x00,
|
|
- 0x42, 0x43, 0x44, 0x45, 0x48, 0x47, 0x46, 0x06,
|
|
- 0x07, 0x08, 0x00, 0x00, 0x2A, 0x00, 0x39, 0x3A,
|
|
- 0x3B, 0x3C, 0x3D, 0x40, 0x3F, 0x3E, 0x2D, 0x2C,
|
|
- 0x2B, 0x26, 0x00, 0x00, 0x31, 0x32, 0x33, 0x34,
|
|
- 0x35, 0x37, 0x36, 0x2e, 0x2f, 0x30, 0x00, 0x00,
|
|
- 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
+static const int qcode_to_nextkbd_keycode[] = {
|
|
+ [Q_KEY_CODE_ESC] = 0x49,
|
|
+ [Q_KEY_CODE_1] = 0x4a,
|
|
+ [Q_KEY_CODE_2] = 0x4b,
|
|
+ [Q_KEY_CODE_3] = 0x4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[Q_KEY_CODE_C] = 0x33,
|
|
+ [Q_KEY_CODE_V] = 0x34,
|
|
+
|
|
+ [Q_KEY_CODE_B] = 0x35,
|
|
+ [Q_KEY_CODE_N] = 0x37,
|
|
+ [Q_KEY_CODE_M] = 0x36,
|
|
+ [Q_KEY_CODE_COMMA] = 0x2e,
|
|
+ [Q_KEY_CODE_DOT] = 0x2f,
|
|
+ [Q_KEY_CODE_SLASH] = 0x30,
|
|
+
|
|
+ [Q_KEY_CODE_SPC] = 0x38,
|
|
};
|
|
|
|
-static void queue_code(void *opaque, int code)
|
|
+static void nextkbd_put_keycode(NextKBDState *s, int keycode)
|
|
{
|
|
- NextKBDState *s = NEXTKBD(opaque);
|
|
KBDQueue *q = &s->queue;
|
|
- int key = code & KD_KEYMASK;
|
|
- int release = code & 0x80;
|
|
- static int ext;
|
|
-
|
|
- if (code == 0xE0) {
|
|
- ext = 1;
|
|
- }
|
|
-
|
|
- if (code == 0x2A || code == 0x1D || code == 0x36) {
|
|
- if (code == 0x2A) {
|
|
- s->shift = KD_LSHIFT;
|
|
- } else if (code == 0x36) {
|
|
- s->shift = KD_RSHIFT;
|
|
- ext = 0;
|
|
- } else if (code == 0x1D && !ext) {
|
|
- s->shift = KD_LCOMM;
|
|
- } else if (code == 0x1D && ext) {
|
|
- ext = 0;
|
|
- s->shift = KD_RCOMM;
|
|
- }
|
|
- return;
|
|
- } else if (code == (0x2A | 0x80) || code == (0x1D | 0x80) ||
|
|
- code == (0x36 | 0x80)) {
|
|
- s->shift = 0;
|
|
- return;
|
|
- }
|
|
|
|
if (q->count >= KBD_QUEUE_SIZE) {
|
|
return;
|
|
}
|
|
|
|
- q->data[q->wptr] = next_keycodes[key] | release;
|
|
-
|
|
+ q->data[q->wptr] = keycode;
|
|
if (++q->wptr == KBD_QUEUE_SIZE) {
|
|
q->wptr = 0;
|
|
}
|
|
@@ -241,6 +242,53 @@ static void queue_code(void *opaque, int code)
|
|
/* s->update_irq(s->update_arg, 1); */
|
|
}
|
|
|
|
+static void nextkbd_event(DeviceState *dev, QemuConsole *src, InputEvent *evt)
|
|
+{
|
|
+ NextKBDState *s = NEXTKBD(dev);
|
|
+ int qcode, keycode;
|
|
+ bool key_down = evt->u.key.data->down;
|
|
+
|
|
+ qcode = qemu_input_key_value_to_qcode(evt->u.key.data->key);
|
|
+ if (qcode >= ARRAY_SIZE(qcode_to_nextkbd_keycode)) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ /* Shift key currently has no keycode, so handle separately */
|
|
+ if (qcode == Q_KEY_CODE_SHIFT) {
|
|
+ if (key_down) {
|
|
+ s->shift |= KD_LSHIFT;
|
|
+ } else {
|
|
+ s->shift &= ~KD_LSHIFT;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (qcode == Q_KEY_CODE_SHIFT_R) {
|
|
+ if (key_down) {
|
|
+ s->shift |= KD_RSHIFT;
|
|
+ } else {
|
|
+ s->shift &= ~KD_RSHIFT;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ keycode = qcode_to_nextkbd_keycode[qcode];
|
|
+ if (!keycode) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ /* If key release event, create keyboard break code */
|
|
+ if (!key_down) {
|
|
+ keycode |= 0x80;
|
|
+ }
|
|
+
|
|
+ nextkbd_put_keycode(s, keycode);
|
|
+}
|
|
+
|
|
+static const QemuInputHandler nextkbd_handler = {
|
|
+ .name = "QEMU NeXT Keyboard",
|
|
+ .mask = INPUT_EVENT_MASK_KEY,
|
|
+ .event = nextkbd_event,
|
|
+};
|
|
+
|
|
static void nextkbd_reset(DeviceState *dev)
|
|
{
|
|
NextKBDState *nks = NEXTKBD(dev);
|
|
@@ -256,7 +304,7 @@ static void nextkbd_realize(DeviceState *dev, Error **errp)
|
|
memory_region_init_io(&s->mr, OBJECT(dev), &kbd_ops, s, "next.kbd", 0x1000);
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
|
|
|
|
- qemu_add_kbd_event_handler(nextkbd_event, s);
|
|
+ qemu_input_handler_register(dev, &nextkbd_handler);
|
|
}
|
|
|
|
static const VMStateDescription nextkbd_vmstate = {
|
|
--
|
|
2.41.0.windows.1
|
|
|