[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] hw/timer/i8254: Factor i8254_pit_create() out and document
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 2/5] hw/timer/i8254: Factor i8254_pit_create() out and document |
Date: |
Wed, 15 Feb 2023 18:43:50 +0100 |
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(-)
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)
--
2.38.1