[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/50] ps2: implement ps2_reset() for the PS2_DEVICE QOM type bas
From: |
Mark Cave-Ayland |
Subject: |
[PATCH 08/50] ps2: implement ps2_reset() for the PS2_DEVICE QOM type based upon ps2_common_reset() |
Date: |
Sun, 22 May 2022 19:17:54 +0100 |
The functionality of ps2_common_reset() can be moved into a new ps2_reset()
function
for the PS2_DEVICE QOM type. Update PS2DeviceClass to hold a reference to the
parent
reset function and update the PS2_KBD_DEVICE and PS2_MOUSE_DEVICE types to use
device_class_set_parent_reset() accordingly.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hw/input/ps2.c | 48 ++++++++++++++++++++++++++++++------------
include/hw/input/ps2.h | 2 ++
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 3a770f3b78..5990eb6f79 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -995,8 +995,10 @@ void ps2_write_mouse(PS2MouseState *s, int val)
}
}
-static void ps2_common_reset(PS2State *s)
+static void ps2_reset(DeviceState *dev)
{
+ PS2State *s = PS2_DEVICE(dev);
+
s->write_cmd = -1;
ps2_reset_queue(s);
s->update_irq(s->update_arg, 0);
@@ -1028,26 +1030,28 @@ static void ps2_common_post_load(PS2State *s)
q->cwptr = ccount ? (q->rptr + ccount) & (PS2_BUFFER_SIZE - 1) : -1;
}
-static void ps2_kbd_reset(void *opaque)
+static void ps2_kbd_reset(DeviceState *dev)
{
- PS2KbdState *s = (PS2KbdState *) opaque;
- PS2State *ps2 = PS2_DEVICE(s);
+ PS2DeviceClass *ps2dc = PS2_DEVICE_GET_CLASS(dev);
+ PS2KbdState *s = PS2_KBD_DEVICE(dev);
+
+ trace_ps2_kbd_reset(s);
+ ps2dc->parent_reset(dev);
- trace_ps2_kbd_reset(opaque);
- ps2_common_reset(ps2);
s->scan_enabled = 1;
s->translate = 0;
s->scancode_set = 2;
s->modifiers = 0;
}
-static void ps2_mouse_reset(void *opaque)
+static void ps2_mouse_reset(DeviceState *dev)
{
- PS2MouseState *s = (PS2MouseState *) opaque;
- PS2State *ps2 = PS2_DEVICE(s);
+ PS2DeviceClass *ps2dc = PS2_DEVICE_GET_CLASS(dev);
+ PS2MouseState *s = PS2_MOUSE_DEVICE(dev);
+
+ trace_ps2_mouse_reset(s);
+ ps2dc->parent_reset(dev);
- trace_ps2_mouse_reset(opaque);
- ps2_common_reset(ps2);
s->mouse_status = 0;
s->mouse_resolution = 0;
s->mouse_sample_rate = 0;
@@ -1227,7 +1231,6 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void
*update_arg)
vmstate_register(NULL, 0, &vmstate_ps2_keyboard, s);
qemu_input_handler_register((DeviceState *)s,
&ps2_keyboard_handler);
- qemu_register_reset(ps2_kbd_reset, s);
return s;
}
@@ -1255,26 +1258,45 @@ void *ps2_mouse_init(void (*update_irq)(void *, int),
void *update_arg)
vmstate_register(NULL, 0, &vmstate_ps2_mouse, s);
qemu_input_handler_register((DeviceState *)s,
&ps2_mouse_handler);
- qemu_register_reset(ps2_mouse_reset, s);
return s;
}
+static void ps2_kbd_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass);
+
+ device_class_set_parent_reset(dc, ps2_kbd_reset, &ps2dc->parent_reset);
+}
+
static const TypeInfo ps2_kbd_info = {
.name = TYPE_PS2_KBD_DEVICE,
.parent = TYPE_PS2_DEVICE,
.instance_size = sizeof(PS2KbdState),
+ .class_init = ps2_kbd_class_init
};
+static void ps2_mouse_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass);
+
+ device_class_set_parent_reset(dc, ps2_mouse_reset,
+ &ps2dc->parent_reset);
+}
+
static const TypeInfo ps2_mouse_info = {
.name = TYPE_PS2_MOUSE_DEVICE,
.parent = TYPE_PS2_DEVICE,
.instance_size = sizeof(PS2MouseState),
+ .class_init = ps2_mouse_class_init
};
static void ps2_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ dc->reset = ps2_reset;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
}
diff --git a/include/hw/input/ps2.h b/include/hw/input/ps2.h
index 0493b78812..4e8de912c6 100644
--- a/include/hw/input/ps2.h
+++ b/include/hw/input/ps2.h
@@ -35,6 +35,8 @@
struct PS2DeviceClass {
DeviceClass parent_class;
+
+ DeviceReset parent_reset;
};
/*
--
2.20.1
- [PATCH 00/50] PS2 device QOMification - part 1, Mark Cave-Ayland, 2022/05/22
- [PATCH 02/50] ps2: QOMify PS2State, Mark Cave-Ayland, 2022/05/22
- [PATCH 03/50] ps2: QOMify PS2KbdState, Mark Cave-Ayland, 2022/05/22
- [PATCH 01/50] ps2: checkpatch fixes, Mark Cave-Ayland, 2022/05/22
- [PATCH 04/50] ps2: QOMify PS2MouseState, Mark Cave-Ayland, 2022/05/22
- [PATCH 06/50] ps2: improve function prototypes in ps2.c and ps2.h, Mark Cave-Ayland, 2022/05/22
- [PATCH 05/50] ps2: move QOM type definitions from ps2.c to ps2.h, Mark Cave-Ayland, 2022/05/22
- [PATCH 08/50] ps2: implement ps2_reset() for the PS2_DEVICE QOM type based upon ps2_common_reset(),
Mark Cave-Ayland <=
- [PATCH 07/50] ps2: introduce PS2DeviceClass, Mark Cave-Ayland, 2022/05/22
- [PATCH 12/50] ps2: don't use vmstate_register() in ps2_kbd_init(), Mark Cave-Ayland, 2022/05/22
- [PATCH 10/50] ps2: implement ps2_kbd_realize() and use it to register ps2_keyboard_handler, Mark Cave-Ayland, 2022/05/22
- [PATCH 09/50] ps2: remove duplicate setting of scancode_set in ps2_kbd_init(), Mark Cave-Ayland, 2022/05/22
- [PATCH 11/50] ps2: implement ps2_mouse_realize() and use it to register ps2_mouse_handler, Mark Cave-Ayland, 2022/05/22
- [PATCH 14/50] pl050: checkpatch fixes, Mark Cave-Ayland, 2022/05/22
- [PATCH 13/50] ps2: don't use vmstate_register() in ps2_mouse_init(), Mark Cave-Ayland, 2022/05/22
- [PATCH 15/50] pl050: split pl050_update_irq() into separate pl050_set_irq() and pl050_update_irq() functions, Mark Cave-Ayland, 2022/05/22