diff mbox series

[2/5] hw/timer/i8254: Factor i8254_pit_create() out and document

Message ID 20230215174353.37097-3-philmd@linaro.org (mailing list archive)
State New, archived
Headers show
Series hw/timer/i8254: Un-inline and simplify IRQs | expand

Commit Message

Philippe Mathieu-Daudé Feb. 15, 2023, 5:43 p.m. UTC
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/timer/i8254.c         | 16 ++++++++++++++++
 include/hw/timer/i8254.h | 24 +++++++++++++-----------
 2 files changed, 29 insertions(+), 11 deletions(-)

Comments

Richard Henderson Feb. 15, 2023, 6:56 p.m. UTC | #1
On 2/15/23 07:43, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/timer/i8254.c         | 16 ++++++++++++++++
>   include/hw/timer/i8254.h | 24 +++++++++++++-----------
>   2 files changed, 29 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/hw/timer/i8254.c b/hw/timer/i8254.c
index c8388ea432..9b6932ab08 100644
--- a/hw/timer/i8254.c
+++ b/hw/timer/i8254.c
@@ -26,9 +26,11 @@ 
 #include "hw/irq.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
+#include "hw/qdev-properties.h"
 #include "hw/timer/i8254.h"
 #include "hw/timer/i8254_internal.h"
 #include "qom/object.h"
+#include "qapi/error.h"
 
 //#define DEBUG_PIT
 
@@ -47,6 +49,20 @@  struct PITClass {
     DeviceRealize parent_realize;
 };
 
+ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in)
+{
+    DeviceState *dev;
+    ISADevice *d;
+
+    d = isa_new(TYPE_I8254);
+    dev = DEVICE(d);
+    qdev_prop_set_uint32(dev, "iobase", iobase);
+    isa_realize_and_unref(d, bus, &error_fatal);
+    qdev_connect_gpio_out(dev, 0, irq_in);
+
+    return d;
+}
+
 static void pit_irq_timer_update(PITChannelState *s, int64_t current_time);
 
 static int pit_get_count(PITChannelState *s)
diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h
index 8402caad30..a0843cae07 100644
--- a/include/hw/timer/i8254.h
+++ b/include/hw/timer/i8254.h
@@ -45,21 +45,23 @@  OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON)
 #define TYPE_I8254 "isa-pit"
 #define TYPE_KVM_I8254 "kvm-pit"
 
+/**
+ * Create and realize a I8254 PIT device on the heap.
+ * @bus: the #ISABus to put it on.
+ * @iobase: the base I/O port.
+ * @irq_in: qemu_irq to connect the PIT output IRQ to.
+ *
+ * Create the device state structure, initialize it, put it on the
+ * specified ISA @bus, and drop the reference to it (the device is realized).
+ */
+ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in);
+
 static inline ISADevice *i8254_pit_init(ISABus *bus, int base, int isa_irq,
                                         qemu_irq alt_irq)
 {
-    DeviceState *dev;
-    ISADevice *d;
-
-    d = isa_new(TYPE_I8254);
-    dev = DEVICE(d);
-    qdev_prop_set_uint32(dev, "iobase", base);
-    isa_realize_and_unref(d, bus, &error_fatal);
-    qdev_connect_gpio_out(dev, 0,
-                          isa_irq >= 0 ? isa_bus_get_irq(bus, isa_irq)
+    return i8254_pit_create(bus, base, isa_irq >= 0
+                                       ? isa_bus_get_irq(bus, isa_irq)
                                        : alt_irq);
-
-    return d;
 }
 
 static inline ISADevice *kvm_pit_init(ISABus *bus, int base)