Skip to contentSkip to conversation

i8259: improve qdev PIC modelling (and misc fixes)

PATCH Superseded Mark Cave-Ayland 1 participant 3 messages Oct 19

lore
Share & tools
lore
#0 lore raw

v3 cover i8259: improve qdev PIC modelling (and misc fixes)

This series attempts to improve the modelling of legacy x86 PICs within QEMU. The initial aim was to have a qdev device with one output gpio, and 16 input gpios representing the legacy IRQ lines, however as I went about trying to model this, I found a number of other inconsistencies/bugs: in particular there seemed to be some fuzziness around the functionality that belongs to an individual i8259 chip, and a cascaded i8259 configuration.

For the purposes of this patch an i8259 device is considered to be a single i8259 chip whilst a PIC device is considered to be either a cascaded i8259 configuration (emulated/KVM) or standalone device (Xen) representing the set of 16 legacy IRQs and a single output IRQ.

Due to the updated device names, there is currently one visible change in the HMP monitor output for "info irq" where the isa-i8259 device now appears as isa-i8259-pic and the kvm-i8259 device appears as kvm-i8259-pic (see patch 25).

[Patches still requiring review: 18-21, 23]

v3:
- Rebase onto master

- Add R-B tags from Peter

- Introduce isa_realize() function in patch 18 and use it in patches 19 and 21 to fix refcounting for ISA devices within the PIC container device

- Don't pass input IRQ 2 from the primary PIC when implementing the cascaded PIC configuration in patch 20

v2:
- Rebase onto master

- Add R-B tags from Peter

- Remove FIXME from commit message and rename trace event in patch 13

- Introduce a separate I8259State for TYPE_I8259 and KVMI8259State for TYPE_KVM_I8259 as suggested by Peter

- Keep but rename the associated classes for TYPE_I8259 and TYPE_KVM_I8259 and move the DeviceRealize function into each one, instead of keeping it in the parent class

- Add patches to make variable names consistent when accessing I8259CommonState from child objects

- Update the comment on patch 19 to reflect that implementing the cascaded secondary is actually a bugfix

Mark Cave-Ayland (28):
i8259_internal.h: rename PIC_COMMON to I8259_COMMON i8259_internal.h: rename TYPE_I8259_COMMON to i8259-common i8259_internal.h: rename PICCommonState to I8259CommonState i8259_internal.h: rename PICCommonClass to I8259CommonClass i8259.c: rename PICClass to I8259Class
i8259.c: introduce TYPE_I8259 device
i8259.c: always use cs for I8259CommonState variables kvm/i8259.c: rename KVMPICClass to KVMI8259Class kvm/i8259.c: introduce TYPE_KVM_I8259 device
kvm/i8259.c: always use cs for I8259CommonState variables i8259_common.c: always use cs for I8259CommonState variables i8259_common.c: use i8259/i8259_common prefix for functions i8259.c: use i8259 prefix for functions
kvm/i8259.c: use kvm_i8259 prefix for functions i8259_common.c: convert to use DEFINE_TYPES() macro i8259.c: convert to use DEFINE_TYPES() macro
kvm/i8259.c: convert to use DEFINE_TYPES() macro isa-bus.c: introduce isa_realize() function
i8259.c: introduce TYPE_I8259_PIC device
i8259.c: properly cascade secondary i8259 from primary i8259 kvm/i8259.c: introduce TYPE_KVM_I8259_PIC device xen-hvm.c: rename xen_interrupt_controller_init() to xen_i8259_init() xen/xen-hvm.c: introduce TYPE_XEN_I8259_PIC device i8259_common.c: remove unused i8259_init_chip() function
i8259: move InterruptStatsProviderClass get_statistics() from i8259 to
PIC
i8259.c: switch isa_pic from I8259State to I8259PICState i8259_common.c: remove static irq_count and irq_level variables i8259_common.c: add missing 0x prefixes to "info pic" output

 include/hw/intc/i8259.h         |  11 +-
 include/hw/isa/i8259_internal.h |  19 +-
 include/hw/isa/isa.h            |   1 +
 include/hw/xen/xen.h            |   2 +-
 hw/i386/kvm/i8259.c             | 250 ++++++++++++-----
 hw/i386/pc.c                    |   2 +-
 hw/i386/xen/xen-hvm.c           |  40 ++-
 hw/intc/i8259.c                 | 470 ++++++++++++++++++++------------
 hw/intc/i8259_common.c          | 225 +++++++--------
 hw/isa/isa-bus.c                |   5 +
 stubs/xen-hw-stub.c             |   2 +-
 hw/intc/trace-events            |   8 +-
 12 files changed, 648 insertions(+), 387 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/28 i8259_internal.h: rename PIC_COMMON to I8259_COMMON

This is to emphasise that child types of PIC_COMMON are all instances of an an 8259 PIC.

---
 include/hw/isa/i8259_internal.h |  4 ++--
 hw/i386/kvm/i8259.c             |  8 ++++----
 hw/intc/i8259.c                 | 10 +++++-----
 hw/intc/i8259_common.c          | 14 +++++++-------
 4 files changed, 18 insertions(+), 18 deletions(-)
include/hw/isa/i8259_internal.h +2 -2
index f9dcc4163e..54dc9036cf 100644
@@ -31,8 +31,8 @@
 #include "qom/object.h"
 
 
-#define TYPE_PIC_COMMON "pic-common"
-OBJECT_DECLARE_TYPE(PICCommonState, PICCommonClass, PIC_COMMON)
+#define TYPE_I8259_COMMON "pic-common"
+OBJECT_DECLARE_TYPE(PICCommonState, PICCommonClass, I8259_COMMON)
 
 struct PICCommonClass {
     DeviceClass parent_class;
hw/i386/kvm/i8259.c +4 -4
index 66f37e1303..14029783e5 100644
@@ -103,7 +103,7 @@ static void kvm_pic_put(PICCommonState *s)
 
 static void kvm_pic_reset(DeviceState *dev)
 {
-    PICCommonState *s = PIC_COMMON(dev);
+    PICCommonState *s = I8259_COMMON(dev);
 
     s->elcr = 0;
     pic_reset_common(s);
@@ -122,7 +122,7 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)
 
 static void kvm_pic_realize(DeviceState *dev, Error **errp)
 {
-    PICCommonState *s = PIC_COMMON(dev);
+    PICCommonState *s = I8259_COMMON(dev);
     KVMPICClass *kpc = KVM_PIC_GET_CLASS(dev);
 
     memory_region_init_io(&s->base_io, OBJECT(dev), NULL, NULL, "kvm-pic", 2);
@@ -142,7 +142,7 @@ qemu_irq *kvm_i8259_init(ISABus *bus)
 static void kvm_i8259_class_init(ObjectClass *klass, const void *data)
 {
     KVMPICClass *kpc = KVM_PIC_CLASS(klass);
-    PICCommonClass *k = PIC_COMMON_CLASS(klass);
+    PICCommonClass *k = I8259_COMMON_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     device_class_set_legacy_reset(dc, kvm_pic_reset);
@@ -153,7 +153,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, const void *data)
 
 static const TypeInfo kvm_i8259_info = {
     .name = TYPE_KVM_I8259,
-    .parent = TYPE_PIC_COMMON,
+    .parent = TYPE_I8259_COMMON,
     .instance_size = sizeof(PICCommonState),
     .class_init = kvm_i8259_class_init,
     .class_size = sizeof(KVMPICClass),
hw/intc/i8259.c +5 -5
index 8f2aa1f0fb..52e24d333e 100644
@@ -218,7 +218,7 @@ static void pic_init_reset(PICCommonState *s)
 
 static void pic_reset(DeviceState *dev)
 {
-    PICCommonState *s = PIC_COMMON(dev);
+    PICCommonState *s = I8259_COMMON(dev);
 
     s->elcr = 0;
     s->ltim = 0;
@@ -387,7 +387,7 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
 
 static void pic_realize(DeviceState *dev, Error **errp)
 {
-    PICCommonState *s = PIC_COMMON(dev);
+    PICCommonState *s = I8259_COMMON(dev);
     PICClass *pc = PIC_GET_CLASS(dev);
 
     memory_region_init_io(&s->base_io, OBJECT(s), &pic_base_ioport_ops, s,
@@ -418,7 +418,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in)
         irq_set[i] = qdev_get_gpio_in(dev, i);
     }
 
-    isa_pic = PIC_COMMON(dev);
+    isa_pic = I8259_COMMON(dev);
 
     isadev = i8259_init_chip(TYPE_I8259, bus, false);
     dev = DEVICE(isadev);
@@ -428,7 +428,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in)
         irq_set[i + 8] = qdev_get_gpio_in(dev, i);
     }
 
-    slave_pic = PIC_COMMON(dev);
+    slave_pic = I8259_COMMON(dev);
 
     return irq_set;
 }
@@ -445,7 +445,7 @@ static void i8259_class_init(ObjectClass *klass, const void *data)
 static const TypeInfo i8259_info = {
     .name       = TYPE_I8259,
     .instance_size = sizeof(PICCommonState),
-    .parent     = TYPE_PIC_COMMON,
+    .parent     = TYPE_I8259_COMMON,
     .class_init = i8259_class_init,
     .class_size = sizeof(PICClass),
 };
hw/intc/i8259_common.c +7 -7
index 8ceb5841b9..e2f997e161 100644
@@ -56,7 +56,7 @@ void pic_reset_common(PICCommonState *s)
 static int pic_dispatch_pre_save(void *opaque)
 {
     PICCommonState *s = opaque;
-    PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
+    PICCommonClass *info = I8259_COMMON_GET_CLASS(s);
 
     if (info->pre_save) {
         info->pre_save(s);
@@ -68,7 +68,7 @@ static int pic_dispatch_pre_save(void *opaque)
 static int pic_dispatch_post_load(void *opaque, int version_id)
 {
     PICCommonState *s = opaque;
-    PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
+    PICCommonClass *info = I8259_COMMON_GET_CLASS(s);
 
     if (info->post_load) {
         info->post_load(s);
@@ -78,7 +78,7 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
 
 static void pic_common_realize(DeviceState *dev, Error **errp)
 {
-    PICCommonState *s = PIC_COMMON(dev);
+    PICCommonState *s = I8259_COMMON(dev);
     ISADevice *isa = ISA_DEVICE(dev);
 
     isa_register_ioport(isa, &s->base_io, s->iobase);
@@ -118,7 +118,7 @@ void pic_stat_update_irq(int irq, int level)
 static bool pic_get_statistics(InterruptStatsProvider *obj,
                                uint64_t **irq_counts, unsigned int *nb_irqs)
 {
-    PICCommonState *s = PIC_COMMON(obj);
+    PICCommonState *s = I8259_COMMON(obj);
 
     if (s->master) {
         *irq_counts = irq_count;
@@ -133,7 +133,7 @@ static bool pic_get_statistics(InterruptStatsProvider *obj,
 
 static void pic_print_info(InterruptStatsProvider *obj, GString *buf)
 {
-    PICCommonState *s = PIC_COMMON(obj);
+    PICCommonState *s = I8259_COMMON(obj);
 
     pic_dispatch_pre_save(s);
     g_string_append_printf(buf, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
@@ -146,7 +146,7 @@ static void pic_print_info(InterruptStatsProvider *obj, GString *buf)
 
 static bool ltim_state_needed(void *opaque)
 {
-    PICCommonState *s = PIC_COMMON(opaque);
+    PICCommonState *s = I8259_COMMON(opaque);
 
     return !!s->ltim;
 }
@@ -220,7 +220,7 @@ static void pic_common_class_init(ObjectClass *klass, const void *data)
 }
 
 static const TypeInfo pic_common_type = {
-    .name = TYPE_PIC_COMMON,
+    .name = TYPE_I8259_COMMON,
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(PICCommonState),
     .class_size = sizeof(PICCommonClass),
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/28 i8259_internal.h: rename TYPE_I8259_COMMON to i8259-common

In reply to Mark Cave-Ayland

This is to emphasise that child types of PIC_COMMON are all instances of an an 8259 PIC.

---
 include/hw/isa/i8259_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/isa/i8259_internal.h +1 -1
index 54dc9036cf..289d08b7d7 100644
@@ -31,7 +31,7 @@
 #include "qom/object.h"
 
 
-#define TYPE_I8259_COMMON "pic-common"
+#define TYPE_I8259_COMMON "i8259-common"
 OBJECT_DECLARE_TYPE(PICCommonState, PICCommonClass, I8259_COMMON)
 
 struct PICCommonClass {
Signature · 1 line
2.43.0