i8259: improve qdev PIC modelling (and misc fixes)
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 19).
Mark Cave-Ayland (22):
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: move parent_realize from PICClass to I8259CommonClass kvm/i8259.c: move parent_realize from KVMPICClass to I8259CommonClass 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
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 I8259CommonState 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 | 12 +- include/hw/isa/i8259_internal.h | 21 ++- include/hw/xen/xen.h | 2 +- hw/i386/kvm/i8259.c | 167 +++++++++++++---- hw/i386/pc.c | 2 +- hw/i386/xen/xen-hvm.c | 40 +++- hw/intc/i8259.c | 322 +++++++++++++++++++++----------- hw/intc/i8259_common.c | 171 ++++++++--------- stubs/xen-hw-stub.c | 2 +- 9 files changed, 477 insertions(+), 262 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/22 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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH 01/22] i8259_internal.h: rename PIC_COMMON to I8259_COMMON
Quoted 5 lines · Mark Cave-Ayland
This is to emphasise that child types of
PIC_COMMONare all instances of an an 8259 PIC.Signed-off-by Mark Cave-Ayland <[email protected]>
thanks
-- PMM
PATCH 2/22 i8259_internal.h: rename TYPE_I8259_COMMON to i8259-common
In reply to Mark Cave-AylandThis 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
@@ -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
Re: [PATCH 02/22] i8259_internal.h: rename TYPE_I8259_COMMON to i8259-common
Quoted 8 lines · Mark Cave-Ayland
This is to emphasise that child types of
PIC_COMMONare all instances of an an 8259 PIC.Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/isa/i8259_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
(I checked that we don't use the typename in a vmstate struct name, so renaming won't accidentally break migration compat)
thanks
-- PMM
PATCH 3/22 i8259_internal.h: rename PICCommonState to I8259CommonState
In reply to Mark Cave-Ayland--- include/hw/intc/i8259.h | 8 ++--- include/hw/isa/i8259_internal.h | 10 +++--- hw/i386/kvm/i8259.c | 10 +++--- hw/intc/i8259.c | 34 +++++++++---------- hw/intc/i8259_common.c | 58 ++++++++++++++++----------------- 5 files changed, 60 insertions(+), 60 deletions(-)
include/hw/intc/i8259.h +4 -4
@@ -3,9 +3,9 @@/* i8259.c */ -typedef struct PICCommonState PICCommonState ; +typedef struct I8259CommonState I8259CommonState ; -extern PICCommonState *isa_pic; +extern I8259CommonState *isa_pic;/* * i8259_init()
@@ -16,7 +16,7 @@ extern PICCommonState *isa_pic;*/ qemu_irq *i8259_init (ISABus *bus,qemu_irq parent_irq_in);qemu_irq *kvm_i8259_init (ISABus *bus); -int pic_get_output (PICCommonState *s); -int pic_read_irq (PICCommonState *s); +int pic_get_output (I8259CommonState *s); +int pic_read_irq (I8259CommonState *s);#endif
include/hw/isa/i8259_internal.h +5 -5
@@ -32,16 +32,16 @@#define TYPE_I8259_COMMON "i8259-common" -OBJECT_DECLARE_TYPE(PICCommonState, PICCommonClass, I8259_COMMON) +OBJECT_DECLARE_TYPE(I8259CommonState, PICCommonClass, I8259_COMMON)struct PICCommonClass {DeviceClass parent_class; -void (*pre_save)(PICCommonState *s); -void (*post_load)(PICCommonState *s); +void (*pre_save)(I8259CommonState *s); +void (*post_load)(I8259CommonState *s); }; -struct PICCommonState { +struct I8259CommonState {ISADevice parent_obj;uint8_t last_irr;/* edge detection */
@@ -70,7 +70,7 @@ struct PICCommonState {MemoryRegion elcr_io; }; -void pic_reset_common (PICCommonState *s); +void pic_reset_common (I8259CommonState *s);ISADevice *i8259_init_chip (const char *name,ISABus *bus,bool master);void pic_stat_update_irq (int irq,int level);
hw/i386/kvm/i8259.c +5 -5
@@ -34,7 +34,7 @@ struct KVMPICClass {DeviceRealize parent_realize; }; -static void kvm_pic_get (PICCommonState *s) +static void kvm_pic_get (I8259CommonState *s) {struct kvm_irqchip chip;struct kvm_pic_state *kpic;
@@ -67,7 +67,7 @@ static void kvm_pic_get(PICCommonState *s) s->elcr_mask = kpic->elcr_mask; } -static void kvm_pic_put (PICCommonState *s) +static void kvm_pic_put (I8259CommonState *s) {struct kvm_irqchip chip;struct kvm_pic_state *kpic;
@@ -103,7 +103,7 @@ static void kvm_pic_put(PICCommonState *s)static void kvm_pic_reset (DeviceState *dev) { -PICCommonState *s =I8259_COMMON (dev); +I8259CommonState *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 =I8259_COMMON (dev); +I8259CommonState *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 );
@@ -154,7 +154,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, const void *data)static const TypeInfo kvm_i8259_info = { .name =TYPE_KVM_I8259 , .parent =TYPE_I8259_COMMON , - .instance_size =sizeof (PICCommonState), + .instance_size =sizeof (I8259CommonState), .class_init = kvm_i8259_class_init, .class_size =sizeof (KVMPICClass), };
hw/intc/i8259.c +17 -17
@@ -52,12 +52,12 @@ struct PICClass {#ifdef DEBUG_IRQ_LATENCY static int64_t irq_time[16 ];#endif -PICCommonState *isa_pic; -static PICCommonState *slave_pic; +I8259CommonState *isa_pic; +static I8259CommonState *slave_pic;/* return the highest priority found in mask (highest = smallest number). Return 8 if no irq */ -static int get_priority (PICCommonState *s,int mask) +static int get_priority (I8259CommonState *s,int mask) {int priority;
@@ -72,7 +72,7 @@ static int get_priority(PICCommonState *s, int mask) }/* return the pic wanted interrupt. return -1 if none */ -static int pic_get_irq (PICCommonState *s) +static int pic_get_irq (I8259CommonState *s) {int mask, cur_priority, priority;
@@ -101,7 +101,7 @@ static int pic_get_irq(PICCommonState *s) }/* Update INT output. Must be called every time the output may have changed. */ -static void pic_update_irq (PICCommonState *s) +static void pic_update_irq (I8259CommonState *s) {int irq;
@@ -117,7 +117,7 @@ static void pic_update_irq(PICCommonState *s)/* set irq level. If an edge is detected, then the IRR is set to 1 */ static void pic_set_irq (void *opaque,int irq,int level) { -PICCommonState *s = opaque; +I8259CommonState *s = opaque;int mask =1 << irq;int irq_index = s->master ? irq : irq +8 ;
@@ -154,7 +154,7 @@ static void pic_set_irq(void *opaque, int irq, int level) }/* acknowledge interrupt 'irq' */ -static void pic_intack (PICCommonState *s,int irq) +static void pic_intack (I8259CommonState *s,int irq) {if (s->auto_eoi) {if (s->rotate_on_auto_eoi) {
@@ -170,7 +170,7 @@ static void pic_intack(PICCommonState *s, int irq)pic_update_irq (s); } -int pic_read_irq (PICCommonState *s) +int pic_read_irq (I8259CommonState *s) {int irq, intno;
@@ -210,7 +210,7 @@ int pic_read_irq(PICCommonState *s)return intno; } -static void pic_init_reset (PICCommonState *s) +static void pic_init_reset (I8259CommonState *s) {pic_reset_common (s);pic_update_irq (s);
@@ -218,7 +218,7 @@ static void pic_init_reset(PICCommonState *s)static void pic_reset (DeviceState *dev) { -PICCommonState *s =I8259_COMMON (dev); +I8259CommonState *s =I8259_COMMON (dev); s->elcr =0 ; s->ltim =0 ;
@@ -228,7 +228,7 @@ static void pic_reset(DeviceState *dev)static void pic_ioport_write (void *opaque,hwaddr addr64,uint64_t val64,unsigned size) { -PICCommonState *s = opaque; +I8259CommonState *s = opaque;uint32_t addr = addr64;uint32_t val = val64;int priority, cmd, irq;
@@ -321,7 +321,7 @@ static void pic_ioport_write(void *opaque, hwaddr addr64,static uint64_t pic_ioport_read (void *opaque,hwaddr addr,unsigned size) { -PICCommonState *s = opaque; +I8259CommonState *s = opaque;int ret;if (s->poll) {
@@ -348,7 +348,7 @@ static uint64_t pic_ioport_read(void *opaque, hwaddr addr,return ret; } -int pic_get_output (PICCommonState *s) +int pic_get_output (I8259CommonState *s) {return (pic_get_irq (s) >=0 ); }
@@ -356,14 +356,14 @@ int pic_get_output(PICCommonState *s)static void elcr_ioport_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) { -PICCommonState *s = opaque; +I8259CommonState *s = opaque; s->elcr = val & s->elcr_mask; }static uint64_t elcr_ioport_read (void *opaque,hwaddr addr,unsigned size) { -PICCommonState *s = opaque; +I8259CommonState *s = opaque;return s->elcr; }
@@ -387,7 +387,7 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {static void pic_realize (DeviceState *dev,Error **errp) { -PICCommonState *s =I8259_COMMON (dev); +I8259CommonState *s =I8259_COMMON (dev);PICClass *pc =PIC_GET_CLASS (dev); memory_region_init_io(&s->base_io, OBJECT(s), &pic_base_ioport_ops, s,
@@ -444,7 +444,7 @@ static void i8259_class_init(ObjectClass *klass, const void *data)static const TypeInfo i8259_info = { .name =TYPE_I8259 , - .instance_size =sizeof (PICCommonState), + .instance_size =sizeof (I8259CommonState), .parent =TYPE_I8259_COMMON , .class_init = i8259_class_init, .class_size =sizeof (PICClass),
hw/intc/i8259_common.c +29 -29
124 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 03/22] i8259_internal.h: rename PICCommonState to I8259CommonState
Quoted 10 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/intc/i8259.h | 8 ++--- include/hw/isa/i8259_internal.h | 10 +++--- hw/i386/kvm/i8259.c | 10 +++--- hw/intc/i8259.c | 34 +++++++++---------- hw/intc/i8259_common.c | 58 ++++++++++++++++----------------- 5 files changed, 60 insertions(+), 60 deletions(-)
thanks
-- PMM
PATCH 4/22 i8259_internal.h: rename PICCommonClass to I8259CommonClass
In reply to Mark Cave-Ayland--- include/hw/isa/i8259_internal.h | 4 ++-- hw/i386/kvm/i8259.c | 4 ++-- hw/intc/i8259.c | 2 +- hw/intc/i8259_common.c | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-)
include/hw/isa/i8259_internal.h +2 -2
@@ -32,9 +32,9 @@#define TYPE_I8259_COMMON "i8259-common" -OBJECT_DECLARE_TYPE(I8259CommonState, PICCommonClass, I8259_COMMON) +OBJECT_DECLARE_TYPE(I8259CommonState, I8259CommonClass, I8259_COMMON) -struct PICCommonClass { +struct I8259CommonClass {DeviceClass parent_class;void (*pre_save)(I8259CommonState *s);
hw/i386/kvm/i8259.c +2 -2
@@ -29,7 +29,7 @@ DECLARE_CLASS_CHECKERS(KVMPICClass, KVM_PIC,* @parent_realize: The parent's realizefn. */ struct KVMPICClass { -PICCommonClass parent_class; +I8259CommonClass parent_class;DeviceRealize parent_realize; };
@@ -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 =I8259_COMMON_CLASS (klass); +I8259CommonClass *k =I8259_COMMON_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass);device_class_set_legacy_reset (dc, kvm_pic_reset);
hw/intc/i8259.c +1 -1
@@ -44,7 +44,7 @@ DECLARE_CLASS_CHECKERS(PICClass, PIC,* @parent_realize: The parent's realizefn. */ struct PICClass { -PICCommonClass parent_class; +I8259CommonClass parent_class;DeviceRealize parent_realize; };
hw/intc/i8259_common.c +3 -3
@@ -56,7 +56,7 @@ void pic_reset_common(I8259CommonState *s)static int pic_dispatch_pre_save (void *opaque) {I8259CommonState *s = opaque; -PICCommonClass *info =I8259_COMMON_GET_CLASS (s); +I8259CommonClass *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) {I8259CommonState *s = opaque; -PICCommonClass *info =I8259_COMMON_GET_CLASS (s); +I8259CommonClass *info =I8259_COMMON_GET_CLASS (s);if (info->post_load) { info->post_load (s);
@@ -223,7 +223,7 @@ static const TypeInfo pic_common_type = { .name = TYPE_I8259_COMMON, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(I8259CommonState), - .class_size = sizeof(PICCommonClass), + .class_size = sizeof(I8259CommonClass), .class_init = pic_common_class_init, .abstract = true, .interfaces = (const InterfaceInfo []) {
Signature · 1 line
2.43.0
Re: [PATCH 04/22] i8259_internal.h: rename PICCommonClass to I8259CommonClass
Quoted 8 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/isa/i8259_internal.h | 4 ++-- hw/i386/kvm/i8259.c | 4 ++-- hw/intc/i8259.c | 2 +- hw/intc/i8259_common.c | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-)
thanks
-- PMM
PATCH 5/22 i8259.c: move parent_realize from PICClass to I8259CommonClass
In reply to Mark Cave-AylandBoth the emulated and KVM i8259 implementations store a reference to the parent_realize function in their respective classes. Start by moving parent_realize from PICClass to I8259CommonClass and removing PICClass since it is no longer required.
--- include/hw/isa/i8259_internal.h | 2 ++ hw/intc/i8259.c | 21 +++------------------ 2 files changed, 5 insertions(+), 18 deletions(-)
include/hw/isa/i8259_internal.h +2 -0
@@ -37,6 +37,8 @@ OBJECT_DECLARE_TYPE(I8259CommonState, I8259CommonClass, I8259_COMMON)struct I8259CommonClass {DeviceClass parent_class; +DeviceRealize parent_realize; +void (*pre_save)(I8259CommonState *s);void (*post_load)(I8259CommonState *s); };
hw/intc/i8259.c +3 -18
@@ -35,19 +35,6 @@/*#define DEBUG_IRQ_LATENCY*/ #define TYPE_I8259 "isa-i8259" -typedef struct PICClass PICClass ; -DECLARE_CLASS_CHECKERS (PICClass,PIC , -TYPE_I8259 ) - -/** -* PICClass: -* @parent_realize: The parent's realizefn. - */ -struct PICClass { -I8259CommonClass parent_class; - -DeviceRealize parent_realize; -};#ifdef DEBUG_IRQ_LATENCY static int64_t irq_time[16 ];
@@ -388,7 +375,7 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {static void pic_realize (DeviceState *dev,Error **errp) {I8259CommonState *s =I8259_COMMON (dev); -PICClass *pc =PIC_GET_CLASS (dev); +I8259CommonClass *k =I8259_COMMON_GET_CLASS (dev);memory_region_init_io (&s->base_io,OBJECT (s), &pic_base_ioport_ops, s,"pic" ,2 );
@@ -398,7 +385,7 @@ static void pic_realize(DeviceState *dev, Error **errp)qdev_init_gpio_out (dev, s->int_out,ARRAY_SIZE (s->int_out));qdev_init_gpio_in (dev, pic_set_irq,8 ); - pc->parent_realize (dev, errp); + k->parent_realize (dev, errp); }qemu_irq *i8259_init (ISABus *bus,qemu_irq parent_irq_in)
@@ -435,7 +422,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in)static void i8259_class_init (ObjectClass *klass,const void *data) { -PICClass *k =PIC_CLASS (klass); +I8259CommonClass *k =I8259_COMMON_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass);device_class_set_parent_realize (dc, pic_realize, &k->parent_realize);
@@ -444,10 +431,8 @@ static void i8259_class_init(ObjectClass *klass, const void *data)static const TypeInfo i8259_info = { .name =TYPE_I8259 , - .instance_size =sizeof (I8259CommonState), .parent =TYPE_I8259_COMMON , .class_init = i8259_class_init, - .class_size =sizeof (PICClass), };static void pic_register_types (void )
Signature · 1 line
2.43.0
Re: [PATCH 05/22] i8259.c: move parent_realize from PICClass to I8259CommonClass
Quoted 7 lines · Mark Cave-Ayland
Both the emulated and KVM i8259 implementations store a reference to the
parent_realizefunction in their respective classes. Start by movingparent_realizefrom PICClass to I8259CommonClass and removing PICClass since it is no longer required.Signed-off-by Mark Cave-Ayland <[email protected]>
This is one of those things where I think we're not 100% consistent about whether we think the parent_realize field should go in the child class struct or the parent class struct. The name "parent_realize" implies it ought to be in the child struct, though, and I think we do that more often than we put it in the parent class. This also makes some kind of separation-of-concerns sense too: it's the child that knows (a) that it exists at all and that (b) it wants to have a realize method that will mean it needs to chain back to the parent.
The docs for device_class_set_parent_realize() claim the parent realize ptr is stored "usually in the instance structure" which I think is just completely wrong.
I could be persuaded otherwise. As usual with QOM/qdev, I'm mostly interested in (a) consistency and (b) documenting what the "right thing" is. Realize, reset and unrealize are the three methods where QOM's lack of convenient support for "child implementation of method will need to chain to parent impl" is most awkward.
thanks
-- PMM
Re: [PATCH 05/22] i8259.c: move parent_realize from PICClass to I8259CommonClass
Quoted 23 lines · Peter Maydell
Quoted 7 lines · Mark Cave-Ayland
Both the emulated and KVM i8259 implementations store a reference to the
parent_realizefunction in their respective classes. Start by movingparent_realizefrom PICClass to I8259CommonClass and removing PICClass since it is no longer required.Signed-off-by Mark Cave-Ayland <[email protected]>This is one of those things where I think we're not 100% consistent about whether we think the
parent_realizefield should go in the child class struct or the parent class struct. The name "parent_realize" implies it ought to be in the child struct, though, and I think we do that more often than we put it in the parent class. This also makes some kind of separation-of-concerns sense too: it's the child that knows (a) that it exists at all and that (b) it wants to have a realize method that will mean it needs to chain back to the parent.The docs for
device_class_set_parent_realize()claim the parent realize ptr is stored "usually in the instance structure" which I think is just completely wrong.
Quoted 6 lines
I could be persuaded otherwise. As usual with QOM/qdev, I'm mostly interested in (a) consistency and (b) documenting what the "right thing" is. Realize, reset and unrealize are the three methods where QOM's lack of convenient support for "child implementation of method will need to chain to parent impl" is most awkward.
Yeah it's a tricky one. This patch was really just refactoring what was already there, but I'm open to moving it into the instance if you think that is better. I agree with your point about the child instance being the one that knows it needs to chain back to the parent.
I'll have an experiment and if it looks good, I'll move it to the instance in v2.
ATB,
Mark.
Re: [PATCH 05/22] i8259.c: move parent_realize from PICClass to I8259CommonClass
Quoted 31 lines · Mark Cave-Ayland
Quoted 23 lines · Peter Maydell
Quoted 7 lines · Mark Cave-Ayland
Both the emulated and KVM i8259 implementations store a reference to the
parent_realizefunction in their respective classes. Start by movingparent_realizefrom PICClass to I8259CommonClass and removing PICClass since it is no longer required.Signed-off-by Mark Cave-Ayland <[email protected]>This is one of those things where I think we're not 100% consistent about whether we think the
parent_realizefield should go in the child class struct or the parent class struct. The name "parent_realize" implies it ought to be in the child struct, though, and I think we do that more often than we put it in the parent class. This also makes some kind of separation-of-concerns sense too: it's the child that knows (a) that it exists at all and that (b) it wants to have a realize method that will mean it needs to chain back to the parent.The docs for
device_class_set_parent_realize()claim the parent realize ptr is stored "usually in the instance structure" which I think is just completely wrong.Quoted 6 lines
I could be persuaded otherwise. As usual with QOM/qdev, I'm mostly interested in (a) consistency and (b) documenting what the "right thing" is. Realize, reset and unrealize are the three methods where QOM's lack of convenient support for "child implementation of method will need to chain to parent impl" is most awkward.
Quoted 3 lines
Yeah it's a tricky one. This patch was really just refactoring what was already there, but I'm open to moving it into the instance if you think that is better. I agree with your point about the child instance being the one that knows it needs to chain back to the parent.
I'll have an experiment and if it looks good, I'll move it to the instance in v2.
I did a search over the codebase and checked all references to DeviceRealize, and they are all stored in QOM classes and make use of device_class_set_parent_realize(). So for now I think we can say it is the documentation for device_class_set_parent_realize() that is wrong, and I will leave it this way in v2 of the series.
ATB,
Mark.
Re: [PATCH 05/22] i8259.c: move parent_realize from PICClass to I8259CommonClass
Quoted 40 lines · Mark Cave-Ayland
Quoted 37 lines · Mark Cave-Ayland
Quoted 24 lines · Peter Maydell
Quoted 8 lines · Mark Cave-Ayland
Both the emulated and KVM i8259 implementations store a reference to the
parent_realizefunction in their respective classes. Start by movingparent_realizefrom PICClass to I8259CommonClass and removing PICClass since
it is no longer required.Signed-off-by Mark Cave-Ayland <[email protected]>This is one of those things where I think we're not 100% consistent about whether we think the
parent_realizefield should go in the child class struct or the parent class struct. The name "parent_realize" implies it ought to be in the child struct, though, and I think we do that more often than we put it in the parent class. This also makes some kind of separation-of-concerns sense too: it's the child that knows (a) that it exists at all and that (b) it wants to have a realize method that will mean it needs to chain back to the parent.The docs for
device_class_set_parent_realize()claim the parent realize ptr is stored "usually in the instance structure" which I think is just completely wrong.Quoted 6 lines
I could be persuaded otherwise. As usual with QOM/qdev, I'm mostly interested in (a) consistency and (b) documenting what the "right thing" is. Realize, reset and unrealize are the three methods where QOM's lack of convenient support for "child implementation of method will need to chain to parent impl" is most awkward.
Yeah it's a tricky one. This patch was really just refactoring what was already there, but I'm open to moving it into the instance if you think that is better. I agree with your point about the child instance being the one that knows it needs to chain back to the parent.
Quoted 7 lines
Quoted 2 lines
I'll have an experiment and if it looks good, I'll move it to the instance in v2.
I did a search over the codebase and checked all references to DeviceRealize, and they are all stored in QOM classes and make use of
device_class_set_parent_realize(). So for now I think we can say it is the documentation fordevice_class_set_parent_realize()that is wrong, and I will leave it this way in v2 of the series.
Yes, the *instance* part is definitely wrong. But there's still "parent class struct" vs "child class struct". This patch puts it in the parent class struct, and as I say above I kind of prefer child class struct and think we do that the most often.
-- PMM
Re: [PATCH 05/22] i8259.c: move parent_realize from PICClass to I8259CommonClass
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
Quoted 6 lines · Mark Cave-Ayland
Both the emulated and KVM i8259 implementations store a reference to the
parent_realizefunction in their respective classes. Start by movingparent_realizefrom PICClass to I8259CommonClass and removing PICClass since it is no longer required.
Quoted 7 lines
Quoted 1 line
Signed-off-by Mark Cave-Ayland <[email protected]>This is one of those things where I think we're not 100% consistent about whether we think the
parent_realizefield should go in the child class struct or the parent class struct. The name "parent_realize" implies it ought to be in the child struct, though, and I think we do that more often than we put it in the parent class.
We do, although it's a bit closer than I thought: about 50 callsites put the parent_realize pointer in the child class struct; about 25 put it in the parent class struct. So I think for new code we should prefer to follow the child-class-struct version.
in child's class:
hw/arm/smmu-common.c: device_class_set_parent_realize(dc, smmu_base_realize, hw/arm/smmuv3.c: device_class_set_parent_realize(dc, smmu_realize, hw/display/macfb.c: device_class_set_parent_realize(dc, macfb_nubus_realize, hw/i386/kvm/i8254.c: device_class_set_parent_realize(dc, kvm_pit_realizefn, hw/i386/kvm/i8259.c: device_class_set_parent_realize(dc, kvm_pic_realize, &kpc->parent_realize); hw/input/adb-kbd.c: device_class_set_parent_realize(dc, adb_kbd_realizefn, hw/input/adb-mouse.c: device_class_set_parent_realize(dc,
adb_mouse_realizefn,hw/intc/arm_gic.c: device_class_set_parent_realize(dc,arm_gic_realize, &agc->parent_realize);hw/intc/arm_gic_kvm.c: device_class_set_parent_realize(dc,kvm_arm_gic_realize,hw/intc/arm_gicv3.c: device_class_set_parent_realize(dc,arm_gic_realize, &agc->parent_realize);hw/intc/arm_gicv3_hvf.c: device_class_set_parent_realize(dc,hvf_gicv3_realize,hw/intc/arm_gicv3_kvm.c: device_class_set_parent_realize(dc,kvm_arm_gicv3_realize,hw/intc/arm_gicv3_whpx.c: device_class_set_parent_realize(dc,whpx_gicv3_realize,hw/intc/arm_gicv5.c: device_class_set_parent_realize(dc,gicv5_realize, &gc->parent_realize);hw/intc/i8259.c: device_class_set_parent_realize(dc, pic_realize,&k->parent_realize);hw/intc/loongarch_dintc.c: device_class_set_parent_realize(dc,loongarch_dintc_realize,hw/intc/loongarch_extioi.c: device_class_set_parent_realize(dc,loongarch_extioi_realize, hw/intc/loongarch_extioi_common.c:
device_class_set_parent_realize(dc, loongarch_extioi_common_realize,hw/intc/loongarch_ipi.c: device_class_set_parent_realize(dc,loongarch_ipi_realize,hw/intc/loongarch_pch_pic.c: device_class_set_parent_realize(dc,loongarch_pic_realize,hw/intc/loongarch_pic_common.c: device_class_set_parent_realize(dc,loongarch_pic_common_realize,hw/intc/loongson_ipi.c: device_class_set_parent_realize(dc,loongson_ipi_realize,hw/intc/loongson_ipi_common.c: device_class_set_parent_realize(dc,loongson_ipi_common_realize,hw/intc/pnv_xive.c: device_class_set_parent_realize(dc,pnv_xive_realize, &pxc->parent_realize);
hw/intc/pnv_xive2.c: device_class_set_parent_realize(dc, pnv_xive2_realize, hw/intc/spapr_xive.c: device_class_set_parent_realize(dc, spapr_xive_realize, hw/intc/xics_pnv.c: device_class_set_parent_realize(dc, pnv_icp_realize, hw/intc/s390_flic_kvm.c: device_class_set_parent_realize(dc,
kvm_s390_flic_realize,hw/nubus/nubus-virtio-mmio.c: device_class_set_parent_realize(dc,nubus_virtio_mmio_realize,hw/timer/i8254.c: device_class_set_parent_realize(dc,pit_realizefn, &pc->parent_realize);hw/virtio/virtio-pci.c: device_class_set_parent_realize(dc,virtio_pci_dc_realize,
target/alpha/cpu.c: device_class_set_parent_realize(dc, alpha_cpu_realizefn, target/arm/cpu.c: device_class_set_parent_realize(dc, arm_cpu_realizefn, target/avr/cpu.c: device_class_set_parent_realize(dc, avr_cpu_realizefn, &mcc->parent_realize); target/hexagon/cpu.c: device_class_set_parent_realize(dc, hexagon_cpu_realize, target/hppa/cpu.c: device_class_set_parent_realize(dc, hppa_cpu_realizefn, target/i386/cpu.c: device_class_set_parent_realize(dc, x86_cpu_realizefn, target/loongarch/cpu.c: device_class_set_parent_realize(dc, loongarch_cpu_realizefn, target/m68k/cpu.c: device_class_set_parent_realize(dc, m68k_cpu_realizefn, target/microblaze/cpu.c: device_class_set_parent_realize(dc, mb_cpu_realizefn, target/mips/cpu.c: device_class_set_parent_realize(dc, mips_cpu_realizefn, target/or1k/cpu.c: device_class_set_parent_realize(dc, openrisc_cpu_realizefn, target/ppc/cpu_init.c: device_class_set_parent_realize(dc, ppc_cpu_realize, target/riscv/cpu.c: device_class_set_parent_realize(dc, riscv_cpu_realize, target/rx/cpu.c: device_class_set_parent_realize(dc, rx_cpu_realize, target/s390x/cpu.c: device_class_set_parent_realize(dc, s390_cpu_realizefn, target/sh4/cpu.c: device_class_set_parent_realize(dc, superh_cpu_realizefn, target/sparc/cpu.c: device_class_set_parent_realize(dc, sparc_cpu_realizefn, target/tricore/cpu.c: device_class_set_parent_realize(dc,
tricore_cpu_realizefn,target/xtensa/cpu.c: device_class_set_parent_realize(dc,xtensa_cpu_realizefn,
in parent's class:
hw/input/lasips2.c: device_class_set_parent_realize(dc,lasips2_kbd_port_realize,hw/input/lasips2.c: device_class_set_parent_realize(dc,lasips2_mouse_port_realize,
hw/input/pl050.c: device_class_set_parent_realize(dc, pl050_kbd_realize, hw/input/pl050.c: device_class_set_parent_realize(dc, pl050_mouse_realize, hw/intc/xics_spapr.c: device_class_set_parent_realize(dc, ics_spapr_realize, hw/isa/pc87312.c: device_class_set_parent_realize(dc, pc87312_realize, hw/isa/vt82c686.c: device_class_set_parent_realize(dc, via_superio_realize, hw/pci-bridge/cxl_root_port.c: device_class_set_parent_realize(dc,
cxl_rp_realize, &rpc->parent_realize); hw/pci-bridge/gen_pcie_root_port.c:device_class_set_parent_realize(dc, gen_rp_realize, &rpc->parent_realize);hw/pci-host/pnv_phb.c: device_class_set_parent_realize(dc,pnv_phb_root_port_realize,hw/pci-host/pnv_phb3_msi.c: device_class_set_parent_realize(dc,phb3_msi_realize,
hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power8_realize, hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power9_realize, hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power10_realize, hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power11_realize, hw/ppc/pnv_lpc.c: device_class_set_parent_realize(dc, pnv_lpc_power8_realize, hw/ppc/pnv_lpc.c: device_class_set_parent_realize(dc, pnv_lpc_power9_realize,
hw/s390x/tod-kvm.c:
device_class_set_parent_realize(DEVICE_CLASS(oc),kvm_s390_tod_realize,hw/virtio/vhost-user-gpio.c: device_class_set_parent_realize(dc,vgpio_realize,
hw/virtio/vhost-user-i2c.c: device_class_set_parent_realize(dc, vi2c_realize, hw/virtio/vhost-user-input.c: device_class_set_parent_realize(dc,
vinput_realize,hw/virtio/vhost-user-rng.c: device_class_set_parent_realize(dc,vu_rng_base_realize,hw/virtio/vhost-user-rtc.c: device_class_set_parent_realize(dc,vu_rtc_base_realize,hw/virtio/vhost-user-snd.c: device_class_set_parent_realize(dc,vu_snd_base_realize,hw/virtio/vhost-user-spi.c: device_class_set_parent_realize(dc, vspi_realize,
thanks
-- PMM
Re: [PATCH 05/22] i8259.c: move parent_realize from PICClass to I8259CommonClass
Quoted 139 lines · Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Mark Cave-Ayland
Both the emulated and KVM i8259 implementations store a reference to the
parent_realizefunction in their respective classes. Start by movingparent_realizefrom PICClass to I8259CommonClass and removing PICClass since it is no longer required.Quoted 7 lines
Quoted 1 line
Signed-off-by Mark Cave-Ayland <[email protected]>This is one of those things where I think we're not 100% consistent about whether we think the
parent_realizefield should go in the child class struct or the parent class struct. The name "parent_realize" implies it ought to be in the child struct, though, and I think we do that more often than we put it in the parent class.We do, although it's a bit closer than I thought: about 50 callsites put the
parent_realizepointer in the child class struct; about 25 put it in the parent class struct. So I think for new code we should prefer to follow the child-class-struct version.in child's class:
hw/arm/smmu-common.c: device_class_set_parent_realize(dc, smmu_base_realize, hw/arm/smmuv3.c: device_class_set_parent_realize(dc, smmu_realize, hw/display/macfb.c: device_class_set_parent_realize(dc, macfb_nubus_realize, hw/i386/kvm/i8254.c: device_class_set_parent_realize(dc, kvm_pit_realizefn, hw/i386/kvm/i8259.c: device_class_set_parent_realize(dc, kvm_pic_realize, &kpc->parent_realize); hw/input/adb-kbd.c: device_class_set_parent_realize(dc, adb_kbd_realizefn, hw/input/adb-mouse.c: device_class_set_parent_realize(dc,
adb_mouse_realizefn,hw/intc/arm_gic.c: device_class_set_parent_realize(dc,arm_gic_realize,&agc->parent_realize);hw/intc/arm_gic_kvm.c: device_class_set_parent_realize(dc,kvm_arm_gic_realize,hw/intc/arm_gicv3.c: device_class_set_parent_realize(dc,arm_gic_realize,&agc->parent_realize);hw/intc/arm_gicv3_hvf.c: device_class_set_parent_realize(dc,hvf_gicv3_realize,hw/intc/arm_gicv3_kvm.c: device_class_set_parent_realize(dc,kvm_arm_gicv3_realize,hw/intc/arm_gicv3_whpx.c: device_class_set_parent_realize(dc,whpx_gicv3_realize,hw/intc/arm_gicv5.c: device_class_set_parent_realize(dc,gicv5_realize,&gc->parent_realize);hw/intc/i8259.c: device_class_set_parent_realize(dc,pic_realize,&k->parent_realize);hw/intc/loongarch_dintc.c: device_class_set_parent_realize(dc,loongarch_dintc_realize,hw/intc/loongarch_extioi.c: device_class_set_parent_realize(dc,loongarch_extioi_realize,hw/intc/loongarch_extioi_common.c:
device_class_set_parent_realize(dc,loongarch_extioi_common_realize,hw/intc/loongarch_ipi.c: device_class_set_parent_realize(dc,loongarch_ipi_realize,hw/intc/loongarch_pch_pic.c: device_class_set_parent_realize(dc,loongarch_pic_realize,hw/intc/loongarch_pic_common.c: device_class_set_parent_realize(dc,loongarch_pic_common_realize,hw/intc/loongson_ipi.c: device_class_set_parent_realize(dc,loongson_ipi_realize,hw/intc/loongson_ipi_common.c: device_class_set_parent_realize(dc,loongson_ipi_common_realize,hw/intc/pnv_xive.c: device_class_set_parent_realize(dc,pnv_xive_realize,&pxc->parent_realize);hw/intc/pnv_xive2.c: device_class_set_parent_realize(dc, pnv_xive2_realize, hw/intc/spapr_xive.c: device_class_set_parent_realize(dc, spapr_xive_realize, hw/intc/xics_pnv.c: device_class_set_parent_realize(dc, pnv_icp_realize, hw/intc/s390_flic_kvm.c: device_class_set_parent_realize(dc,
kvm_s390_flic_realize,hw/nubus/nubus-virtio-mmio.c: device_class_set_parent_realize(dc,nubus_virtio_mmio_realize,hw/timer/i8254.c: device_class_set_parent_realize(dc,pit_realizefn,&pc->parent_realize);hw/virtio/virtio-pci.c: device_class_set_parent_realize(dc,virtio_pci_dc_realize,target/alpha/cpu.c: device_class_set_parent_realize(dc, alpha_cpu_realizefn, target/arm/cpu.c: device_class_set_parent_realize(dc, arm_cpu_realizefn, target/avr/cpu.c: device_class_set_parent_realize(dc, avr_cpu_realizefn, &mcc->parent_realize); target/hexagon/cpu.c: device_class_set_parent_realize(dc, hexagon_cpu_realize, target/hppa/cpu.c: device_class_set_parent_realize(dc, hppa_cpu_realizefn, target/i386/cpu.c: device_class_set_parent_realize(dc, x86_cpu_realizefn, target/loongarch/cpu.c: device_class_set_parent_realize(dc, loongarch_cpu_realizefn, target/m68k/cpu.c: device_class_set_parent_realize(dc, m68k_cpu_realizefn, target/microblaze/cpu.c: device_class_set_parent_realize(dc, mb_cpu_realizefn, target/mips/cpu.c: device_class_set_parent_realize(dc, mips_cpu_realizefn, target/or1k/cpu.c: device_class_set_parent_realize(dc, openrisc_cpu_realizefn, target/ppc/cpu_init.c: device_class_set_parent_realize(dc, ppc_cpu_realize, target/riscv/cpu.c: device_class_set_parent_realize(dc, riscv_cpu_realize, target/rx/cpu.c: device_class_set_parent_realize(dc, rx_cpu_realize, target/s390x/cpu.c: device_class_set_parent_realize(dc, s390_cpu_realizefn, target/sh4/cpu.c: device_class_set_parent_realize(dc, superh_cpu_realizefn, target/sparc/cpu.c: device_class_set_parent_realize(dc, sparc_cpu_realizefn, target/tricore/cpu.c: device_class_set_parent_realize(dc,
tricore_cpu_realizefn,target/xtensa/cpu.c: device_class_set_parent_realize(dc,xtensa_cpu_realizefn,in parent's class:
hw/input/lasips2.c: device_class_set_parent_realize(dc,lasips2_kbd_port_realize,hw/input/lasips2.c: device_class_set_parent_realize(dc,lasips2_mouse_port_realize,hw/input/pl050.c: device_class_set_parent_realize(dc, pl050_kbd_realize, hw/input/pl050.c: device_class_set_parent_realize(dc, pl050_mouse_realize, hw/intc/xics_spapr.c: device_class_set_parent_realize(dc, ics_spapr_realize, hw/isa/pc87312.c: device_class_set_parent_realize(dc, pc87312_realize, hw/isa/vt82c686.c: device_class_set_parent_realize(dc, via_superio_realize, hw/pci-bridge/cxl_root_port.c: device_class_set_parent_realize(dc,
cxl_rp_realize,&rpc->parent_realize);hw/pci-bridge/gen_pcie_root_port.c:device_class_set_parent_realize(dc, gen_rp_realize, &rpc->parent_realize);hw/pci-host/pnv_phb.c: device_class_set_parent_realize(dc,pnv_phb_root_port_realize,hw/pci-host/pnv_phb3_msi.c: device_class_set_parent_realize(dc,phb3_msi_realize,hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power8_realize, hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power9_realize, hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power10_realize, hw/ppc/pnv.c: device_class_set_parent_realize(dc, pnv_chip_power11_realize, hw/ppc/pnv_lpc.c: device_class_set_parent_realize(dc, pnv_lpc_power8_realize, hw/ppc/pnv_lpc.c: device_class_set_parent_realize(dc, pnv_lpc_power9_realize,
hw/s390x/tod-kvm.c:
device_class_set_parent_realize(DEVICE_CLASS(oc),kvm_s390_tod_realize,hw/virtio/vhost-user-gpio.c: device_class_set_parent_realize(dc,vgpio_realize,hw/virtio/vhost-user-i2c.c: device_class_set_parent_realize(dc, vi2c_realize, hw/virtio/vhost-user-input.c: device_class_set_parent_realize(dc,
Quoted 8 lines
vinput_realize,hw/virtio/vhost-user-rng.c: device_class_set_parent_realize(dc,vu_rng_base_realize,hw/virtio/vhost-user-rtc.c: device_class_set_parent_realize(dc,vu_rtc_base_realize,hw/virtio/vhost-user-snd.c: device_class_set_parent_realize(dc,vu_snd_base_realize,hw/virtio/vhost-user-spi.c: device_class_set_parent_realize(dc,vspi_realize,
Thanks for the analysis. I agree that it makes sense to put parent_realize in the child class as opposed to the parent class, and I'll make that change to my current series.
I also realise from this and your previous response that I misunderstood exactly what you mean by storing it in the instance...
ATB,
Mark.
PATCH 6/22 kvm/i8259.c: move parent_realize from KVMPICClass to I8259CommonClass
In reply to Mark Cave-AylandMove parent_realize from KVMPICClass to I8259CommonClass and remove KVMPICClass since it is no longer required.
--- hw/i386/kvm/i8259.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
hw/i386/kvm/i8259.c +3 -19
@@ -20,19 +20,6 @@#include "qom/object.h" #define TYPE_KVM_I8259 "kvm-i8259" -typedef struct KVMPICClass KVMPICClass ; -DECLARE_CLASS_CHECKERS (KVMPICClass,KVM_PIC , -TYPE_KVM_I8259 ) - -/** -* KVMPICClass: -* @parent_realize: The parent's realizefn. - */ -struct KVMPICClass { -I8259CommonClass parent_class; - -DeviceRealize parent_realize; -};static void kvm_pic_get (I8259CommonState *s) {
@@ -123,12 +110,12 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)static void kvm_pic_realize (DeviceState *dev,Error **errp) {I8259CommonState *s =I8259_COMMON (dev); -KVMPICClass *kpc =KVM_PIC_GET_CLASS (dev); +I8259CommonClass *k =I8259_COMMON_GET_CLASS (dev);memory_region_init_io (&s->base_io,OBJECT (dev),NULL ,NULL ,"kvm-pic" ,2 );memory_region_init_io (&s->elcr_io,OBJECT (dev),NULL ,NULL ,"kvm-elcr" ,1 ); - kpc->parent_realize (dev, errp); + k->parent_realize (dev, errp); }qemu_irq *kvm_i8259_init (ISABus *bus)
@@ -141,12 +128,11 @@ qemu_irq *kvm_i8259_init(ISABus *bus)static void kvm_i8259_class_init (ObjectClass *klass,const void *data) { -KVMPICClass *kpc =KVM_PIC_CLASS (klass);I8259CommonClass *k =I8259_COMMON_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass);device_class_set_legacy_reset (dc, kvm_pic_reset); -device_class_set_parent_realize (dc, kvm_pic_realize, &kpc->parent_realize); +device_class_set_parent_realize (dc, kvm_pic_realize, &k->parent_realize); k->pre_save = kvm_pic_get; k->post_load = kvm_pic_put; }
@@ -154,9 +140,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, const void *data)static const TypeInfo kvm_i8259_info = { .name =TYPE_KVM_I8259 , .parent =TYPE_I8259_COMMON , - .instance_size =sizeof (I8259CommonState), .class_init = kvm_i8259_class_init, - .class_size =sizeof (KVMPICClass), };static void kvm_pic_register_types (void )
Signature · 1 line
2.43.0
PATCH 7/22 i8259_common.c: use i8259/i8259_common prefix for functions
In reply to Mark Cave-AylandThis ensures consistency with our normal QOM-based naming convention.
--- include/hw/isa/i8259_internal.h | 4 +-- hw/i386/kvm/i8259.c | 4 +-- hw/intc/i8259.c | 4 +-- hw/intc/i8259_common.c | 49 +++++++++++++++++---------------- 4 files changed, 31 insertions(+), 30 deletions(-)
include/hw/isa/i8259_internal.h +2 -2
@@ -72,8 +72,8 @@ struct I8259CommonState { MemoryRegion elcr_io; }; -void pic_reset_common (I8259CommonState *s); +void i8259_common_reset (I8259CommonState *s);ISADevice *i8259_init_chip (const char *name,ISABus *bus,bool master); -void pic_stat_update_irq (int irq,int level); +void i8259_stat_update_irq (int irq,int level);#endif /* QEMU_I8259_INTERNAL_H */
hw/i386/kvm/i8259.c +2 -2
@@ -93,7 +93,7 @@ static void kvm_pic_reset(DeviceState *dev)I8259CommonState *s =I8259_COMMON (dev); s->elcr =0 ; -pic_reset_common (s); +i8259_common_reset (s);kvm_pic_put (s); }
@@ -102,7 +102,7 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level) {int delivered; -pic_stat_update_irq (irq, level); +i8259_stat_update_irq (irq, level); delivered =kvm_set_irq (kvm_state, irq, level);kvm_report_irq_delivered (delivered); }
hw/intc/i8259.c +2 -2
@@ -109,7 +109,7 @@ static void pic_set_irq(void *opaque, int irq, int level)int irq_index = s->master ? irq : irq +8 ;trace_pic_set_irq (s->master, irq, level); -pic_stat_update_irq (irq_index, level); +i8259_stat_update_irq (irq_index, level);#ifdef DEBUG_IRQ_LATENCY if (level) {
@@ -199,7 +199,7 @@ int pic_read_irq(I8259CommonState *s)static void pic_init_reset (I8259CommonState *s) { -pic_reset_common (s); +i8259_common_reset (s);pic_update_irq (s); }
hw/intc/i8259_common.c +25 -24
137 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 07/22] i8259_common.c: use i8259/i8259_common prefix for functions
Quoted 10 lines · Mark Cave-Ayland
This ensures consistency with our normal QOM-based naming convention.
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/isa/i8259_internal.h | 4 +-- hw/i386/kvm/i8259.c | 4 +-- hw/intc/i8259.c | 4 +-- hw/intc/i8259_common.c | 49 +++++++++++++++++---------------- 4 files changed, 31 insertions(+), 30 deletions(-)
thanks
-- PMM
PATCH 8/22 i8259.c: use i8259 prefix for functions
In reply to Mark Cave-AylandThis ensures consistency with our normal QOM-based naming convention.
FIXME: rename trace events?
--- hw/intc/i8259.c | 96 ++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 48 deletions(-)
hw/intc/i8259.c +48 -48
@@ -58,8 +58,8 @@ static int get_priority(I8259CommonState *s, int mask)return priority; } -/* return the pic wanted interrupt. return -1 if none */ -static int pic_get_irq (I8259CommonState *s) +/* return the i8259 wanted interrupt. return -1 if none */ +static int i8259_get_irq (I8259CommonState *s) {int mask, cur_priority, priority;
@@ -88,11 +88,11 @@ static int pic_get_irq(I8259CommonState *s) }/* Update INT output. Must be called every time the output may have changed. */ -static void pic_update_irq (I8259CommonState *s) +static void i8259_update_irq (I8259CommonState *s) {int irq; - irq =pic_get_irq (s); + irq =i8259_get_irq (s);if (irq >=0 ) {trace_pic_update_irq (s->master, s->imr, s->irr, s->priority_add);qemu_irq_raise (s->int_out[0 ]);
@@ -102,7 +102,7 @@ static void pic_update_irq(I8259CommonState *s) }/* set irq level. If an edge is detected, then the IRR is set to 1 */ -static void pic_set_irq (void *opaque,int irq,int level) +static void i8259_set_irq (void *opaque,int irq,int level) {I8259CommonState *s = opaque;int mask =1 << irq;
@@ -137,11 +137,11 @@ static void pic_set_irq(void *opaque, int irq, int level) s->last_irr &= ~mask; } } -pic_update_irq (s); +i8259_update_irq (s); }/* acknowledge interrupt 'irq' */ -static void pic_intack (I8259CommonState *s,int irq) +static void i8259_intack (I8259CommonState *s,int irq) {if (s->auto_eoi) {if (s->rotate_on_auto_eoi) {
@@ -154,31 +154,31 @@ static void pic_intack(I8259CommonState *s, int irq)if (!s->ltim && !(s->elcr & (1 << irq))) { s->irr &= ~(1 << irq); } -pic_update_irq (s); +i8259_update_irq (s); }int pic_read_irq (I8259CommonState *s) {int irq, intno; - irq =pic_get_irq (s); + irq =i8259_get_irq (s);if (irq >=0 ) {int irq2;if (irq ==2 ) { - irq2 =pic_get_irq (slave_pic); + irq2 =i8259_get_irq (slave_pic);if (irq2 >=0 ) { -pic_intack (slave_pic, irq2); +i8259_intack (slave_pic, irq2); }else {/* spurious IRQ on slave controller */ irq2 =7 ; } intno = slave_pic->irq_base + irq2; -pic_intack (s, irq); +i8259_intack (s, irq); irq = irq2 +8 ; }else { intno = s->irq_base + irq; -pic_intack (s, irq); +i8259_intack (s, irq); } }else {/* spurious IRQ on host controller */
@@ -197,23 +197,23 @@ int pic_read_irq(I8259CommonState *s)return intno; } -static void pic_init_reset (I8259CommonState *s) +static void i8259_init_reset (I8259CommonState *s) {i8259_common_reset (s); -pic_update_irq (s); +i8259_update_irq (s); } -static void pic_reset (DeviceState *dev) +static void i8259_reset (DeviceState *dev) {I8259CommonState *s =I8259_COMMON (dev); s->elcr =0 ; s->ltim =0 ; -pic_init_reset (s); +i8259_init_reset (s); } -static void pic_ioport_write (void *opaque,hwaddr addr64, -uint64_t val64,unsigned size) +static void i8259_base_ioport_write (void *opaque,hwaddr addr64, +uint64_t val64,unsigned size) {I8259CommonState *s = opaque;uint32_t addr = addr64;
@@ -224,7 +224,7 @@ static void pic_ioport_write(void *opaque, hwaddr addr64,if (addr ==0 ) {if (val &0x10 ) { -pic_init_reset (s); +i8259_init_reset (s); s->init_state =1 ; s->init4 = val &1 ; s->single_mode = val &2 ;
@@ -255,23 +255,23 @@ static void pic_ioport_write(void *opaque, hwaddr addr64,if (cmd ==5 ) { s->priority_add = (irq +1 ) &7 ; } -pic_update_irq (s); +i8259_update_irq (s); }break ;case 3 : irq = val &7 ; s->isr &= ~(1 << irq); -pic_update_irq (s); +i8259_update_irq (s);break ;case 6 : s->priority_add = (val +1 ) &7 ; -pic_update_irq (s); +i8259_update_irq (s);break ;case 7 : irq = val &7 ; s->isr &= ~(1 << irq); s->priority_add = (irq +1 ) &7 ; -pic_update_irq (s); +i8259_update_irq (s);break ;default :/* no operation */
@@ -283,7 +283,7 @@ static void pic_ioport_write(void *opaque, hwaddr addr64,case 0 :/* normal mode */ s->imr = val; -pic_update_irq (s); +i8259_update_irq (s);break ;case 1 : s->irq_base = val &0xf8 ;
@@ -305,16 +305,16 @@ static void pic_ioport_write(void *opaque, hwaddr addr64, } } -static uint64_t pic_ioport_read (void *opaque,hwaddr addr, -unsigned size) +static uint64_t i8259_base_ioport_read (void *opaque,hwaddr addr, +unsigned size) {I8259CommonState *s = opaque;int ret;if (s->poll) { - ret =pic_get_irq (s); + ret =i8259_get_irq (s);if (ret >=0 ) { -pic_intack (s, ret); +i8259_intack (s, ret); ret |=0x80 ; }else { ret =0 ;
@@ -337,53 +337,53 @@ static uint64_t pic_ioport_read(void *opaque, hwaddr addr,int pic_get_output (I8259CommonState *s) { -return (pic_get_irq (s) >=0 ); +return (i8259_get_irq (s) >=0 ); } -static void elcr_ioport_write (void *opaque,hwaddr addr, -uint64_t val,unsigned size) +static void i8259_elcr_ioport_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) {I8259CommonState *s = opaque; s->elcr = val & s->elcr_mask; } -static uint64_t elcr_ioport_read (void *opaque,hwaddr addr, -unsigned size) +static uint64_t i8259_elcr_ioport_read (void *opaque,hwaddr addr, +unsigned size) {I8259CommonState *s = opaque;return s->elcr; } -static const MemoryRegionOps pic_base_ioport_ops = { - .read = pic_ioport_read, - .write = pic_ioport_write, +static const MemoryRegionOps i8259_base_ioport_ops = { + .read = i8259_base_ioport_read, + .write = i8259_base_ioport_write, .impl = { .min_access_size =1 , .max_access_size =1 , }, }; -static const MemoryRegionOps pic_elcr_ioport_ops = { - .read = elcr_ioport_read, - .write = elcr_ioport_write, +static const MemoryRegionOps i8259_elcr_ioport_ops = { + .read = i8259_elcr_ioport_read, + .write = i8259_elcr_ioport_write, .impl = { .min_access_size =1 , .max_access_size =1 , }, }; -static void pic_realize (DeviceState *dev,Error **errp) +static void i8259_realize (DeviceState *dev,Error **errp) {I8259CommonState *s =I8259_COMMON (dev);I8259CommonClass *k =I8259_COMMON_GET_CLASS (dev); -memory_region_init_io (&s->base_io,OBJECT (s), &pic_base_ioport_ops, s, +memory_region_init_io (&s->base_io,OBJECT (s), &i8259_base_ioport_ops, s,"pic" ,2 ); -memory_region_init_io (&s->elcr_io,OBJECT (s), &pic_elcr_ioport_ops, s, +memory_region_init_io (&s->elcr_io,OBJECT (s), &i8259_elcr_ioport_ops, s,"elcr" ,1 );qdev_init_gpio_out (dev, s->int_out,ARRAY_SIZE (s->int_out)); -qdev_init_gpio_in (dev, pic_set_irq,8 ); +qdev_init_gpio_in (dev, i8259_set_irq,8 ); k->parent_realize (dev, errp); }
@@ -425,8 +425,8 @@ static void i8259_class_init(ObjectClass *klass, const void *data)I8259CommonClass *k =I8259_COMMON_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); -device_class_set_parent_realize (dc, pic_realize, &k->parent_realize); -device_class_set_legacy_reset (dc, pic_reset); +device_class_set_parent_realize (dc, i8259_realize, &k->parent_realize); +device_class_set_legacy_reset (dc, i8259_reset); }static const TypeInfo i8259_info = {
@@ -435,9 +435,9 @@ static const TypeInfo i8259_info = { .class_init = i8259_class_init, }; -static void pic_register_types (void ) +static void i8259_register_types (void ) {type_register_static (&i8259_info); } -type_init (pic_register_types) +type_init (i8259_register_types)
Signature · 1 line
2.43.0
Re: [PATCH 08/22] i8259.c: use i8259 prefix for functions
Quoted 5 lines · Mark Cave-Ayland
This ensures consistency with our normal QOM-based naming convention.
Signed-off-by Mark Cave-Ayland <[email protected]>FIXME: rename trace events?
I recommend removing FIXME comments before posting patches, it avoids the possibility of reviewers suggesting you do the extra work :-)
I don't believe we make any claims about stability of trace event names, so we could rename them. Should be a separate patch if we do, though.
For this patch and with the FIXME line removed,
thanks
-- PMM
Re: [PATCH 08/22] i8259.c: use i8259 prefix for functions
Quoted 10 lines · Peter Maydell
Quoted 5 lines · Mark Cave-Ayland
This ensures consistency with our normal QOM-based naming convention.
Signed-off-by Mark Cave-Ayland <[email protected]>FIXME: rename trace events?
I recommend removing FIXME comments before posting patches, it avoids the possibility of reviewers suggesting you do the extra work :-)
Ooops, sorry about that :)
Quoted 3 lines
I don't believe we make any claims about stability of trace event names, so we could rename them. Should be a separate patch if we do, though.
Okay I'll rename the trace event to match in v2.
Quoted 2 lines
For this patch and with the FIXME line removed,
Reviewed-by Peter Maydell <[email protected]>
ATB,
Mark.
PATCH 9/22 kvm/i8259.c: use kvm_i8259 prefix for functions
In reply to Mark Cave-AylandThis ensures consistency with our normal QOM-based naming convention.
--- hw/i386/kvm/i8259.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
hw/i386/kvm/i8259.c +11 -11
@@ -21,7 +21,7 @@#define TYPE_KVM_I8259 "kvm-i8259" -static void kvm_pic_get (I8259CommonState *s) +static void kvm_i8259_get (I8259CommonState *s) {struct kvm_irqchip chip;struct kvm_pic_state *kpic;
@@ -54,7 +54,7 @@ static void kvm_pic_get(I8259CommonState *s) s->elcr_mask = kpic->elcr_mask; } -static void kvm_pic_put (I8259CommonState *s) +static void kvm_i8259_put (I8259CommonState *s) {struct kvm_irqchip chip;struct kvm_pic_state *kpic;
@@ -88,14 +88,14 @@ static void kvm_pic_put(I8259CommonState *s) } } -static void kvm_pic_reset (DeviceState *dev) +static void kvm_i8259_reset (DeviceState *dev) {I8259CommonState *s =I8259_COMMON (dev); s->elcr =0 ;i8259_common_reset (s); -kvm_pic_put (s); +kvm_i8259_put (s); }static void kvm_pic_set_irq (void *opaque,int irq,int level)
@@ -107,7 +107,7 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)kvm_report_irq_delivered (delivered); } -static void kvm_pic_realize (DeviceState *dev,Error **errp) +static void kvm_i8259_realize (DeviceState *dev,Error **errp) {I8259CommonState *s =I8259_COMMON (dev);I8259CommonClass *k =I8259_COMMON_GET_CLASS (dev);
@@ -131,10 +131,10 @@ static void kvm_i8259_class_init(ObjectClass *klass, const void *data)I8259CommonClass *k =I8259_COMMON_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); -device_class_set_legacy_reset (dc, kvm_pic_reset); -device_class_set_parent_realize (dc, kvm_pic_realize, &k->parent_realize); - k->pre_save = kvm_pic_get; - k->post_load = kvm_pic_put; +device_class_set_legacy_reset (dc, kvm_i8259_reset); +device_class_set_parent_realize (dc, kvm_i8259_realize, &k->parent_realize); + k->pre_save = kvm_i8259_get; + k->post_load = kvm_i8259_put; }static const TypeInfo kvm_i8259_info = {
@@ -143,9 +143,9 @@ static const TypeInfo kvm_i8259_info = { .class_init = kvm_i8259_class_init, }; -static void kvm_pic_register_types (void ) +static void kvm_i8259_register_types (void ) {type_register_static (&kvm_i8259_info); } -type_init (kvm_pic_register_types) +type_init (kvm_i8259_register_types)
Signature · 1 line
2.43.0
Re: [PATCH 09/22] kvm/i8259.c: use kvm_i8259 prefix for functions
Quoted 7 lines · Mark Cave-Ayland
This ensures consistency with our normal QOM-based naming convention.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/kvm/i8259.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
thanks
-- PMM
PATCH 10/22 i8259_common.c: convert to use DEFINE_TYPES() macro
In reply to Mark Cave-Ayland--- hw/intc/i8259_common.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
hw/intc/i8259_common.c +13 -16
@@ -220,22 +220,19 @@ static void i8259_common_class_init(ObjectClass *klass, const void *data) ic->print_info = i8259_common_print_info; } -static const TypeInfo i8259_common_type = { - .name =TYPE_I8259_COMMON , - .parent =TYPE_ISA_DEVICE , - .instance_size =sizeof (I8259CommonState), - .class_size =sizeof (I8259CommonClass), - .class_init = i8259_common_class_init, - .abstract = true, - .interfaces = (const InterfaceInfo []) { - {TYPE_INTERRUPT_STATS_PROVIDER }, - { } +static const TypeInfo i8259_common_type_infos[] = { + { + .name =TYPE_I8259_COMMON , + .parent =TYPE_ISA_DEVICE , + .instance_size =sizeof (I8259CommonState), + .class_size =sizeof (I8259CommonClass), + .class_init = i8259_common_class_init, + .abstract = true, + .interfaces = (const InterfaceInfo []) { + {TYPE_INTERRUPT_STATS_PROVIDER }, + { } + }, }, }; -static void i8259_common_register_types (void ) -{ -type_register_static (&i8259_common_type); -} - -type_init (i8259_common_register_types) +DEFINE_TYPES (i8259_common_type_infos)
Signature · 1 line
2.43.0
Re: [PATCH 10/22] i8259_common.c: convert to use DEFINE_TYPES() macro
Quoted 5 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259_common.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
thanks
-- PMM
PATCH 11/22 i8259.c: convert to use DEFINE_TYPES() macro
In reply to Mark Cave-Ayland--- hw/intc/i8259.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
hw/intc/i8259.c +7 -10
@@ -429,15 +429,12 @@ static void i8259_class_init(ObjectClass *klass, const void *data)device_class_set_legacy_reset (dc, i8259_reset); } -static const TypeInfo i8259_info = { - .name =TYPE_I8259 , - .parent =TYPE_I8259_COMMON , - .class_init = i8259_class_init, +static const TypeInfo i8259_type_infos[] = { + { + .name =TYPE_I8259 , + .parent =TYPE_I8259_COMMON , + .class_init = i8259_class_init, + }, }; -static void i8259_register_types (void ) -{ -type_register_static (&i8259_info); -} - -type_init (i8259_register_types) +DEFINE_TYPES (i8259_type_infos)
Signature · 1 line
2.43.0
Re: [PATCH 11/22] i8259.c: convert to use DEFINE_TYPES() macro
Quoted 5 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
thanks
-- PMM
PATCH 12/22 kvm/i8259.c: convert to use DEFINE_TYPES() macro
In reply to Mark Cave-Ayland--- hw/i386/kvm/i8259.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
hw/i386/kvm/i8259.c +7 -10
@@ -137,15 +137,12 @@ static void kvm_i8259_class_init(ObjectClass *klass, const void *data) k->post_load = kvm_i8259_put; } -static const TypeInfo kvm_i8259_info = { - .name =TYPE_KVM_I8259 , - .parent =TYPE_I8259_COMMON , - .class_init = kvm_i8259_class_init, +static const TypeInfo kvm_i8259_type_infos[] = { + { + .name =TYPE_KVM_I8259 , + .parent =TYPE_I8259_COMMON , + .class_init = kvm_i8259_class_init, + }, }; -static void kvm_i8259_register_types (void ) -{ -type_register_static (&kvm_i8259_info); -} - -type_init (kvm_i8259_register_types) +DEFINE_TYPES (kvm_i8259_type_infos)
Signature · 1 line
2.43.0
Re: [PATCH 12/22] kvm/i8259.c: convert to use DEFINE_TYPES() macro
Quoted 6 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/kvm/i8259.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
thanks
-- PMM
PATCH 13/22 i8259.c: introduce TYPE_I8259_PIC device
In reply to Mark Cave-AylandThis device represents a PIC for an x86 machine consisting of 2 cascaded i8259 devices wired accordingly.
--- hw/intc/i8259.c | 133 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 118 insertions(+), 15 deletions(-)
hw/intc/i8259.c +118 -15
@@ -25,7 +25,9 @@#include "qemu/osdep.h" #include "hw/intc/i8259.h" #include "hw/core/irq.h" +#include "hw/core/qdev-properties.h" #include "hw/isa/isa.h" +#include "qapi/error.h" #include "qemu/timer.h" #include "qemu/log.h" #include "hw/isa/i8259_internal.h"
@@ -36,6 +38,22 @@#define TYPE_I8259 "isa-i8259" +#define TYPE_I8259_PIC "isa-i8259-pic" + +struct I8259PICState { +DeviceState parent_obj; + +qemu_irq pic_out_irq; +qemu_irq pass_irqs[ISA_NUM_IRQS ]; + +ISABus *isabus; +IRQState i8259_primary_out_irq; +I8259CommonState i8259[2 ]; +}; + +OBJECT_DECLARE_SIMPLE_TYPE(I8259PICState, I8259_PIC) + +#ifdef DEBUG_IRQ_LATENCY static int64_t irq_time[16 ];#endif
@@ -392,30 +410,24 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in) {qemu_irq *irq_set;DeviceState *dev; -ISADevice *isadev; +Object *pic_obj;int i; irq_set =g_new0 (qemu_irq,ISA_NUM_IRQS ); - isadev =i8259_init_chip (TYPE_I8259 , bus, true); - dev =DEVICE (isadev); + dev =qdev_new (TYPE_I8259_PIC ); +object_property_set_link (OBJECT (dev),"bus" ,OBJECT (bus), &error_fatal); +qdev_realize_and_unref (dev,NULL , &error_fatal);qdev_connect_gpio_out (dev,0 , parent_irq_in); -for (i =0 ; i <8 ; i++) { +for (i =0 ; i <ISA_NUM_IRQS ; i++) { irq_set[i] =qdev_get_gpio_in (dev, i); } - isa_pic =I8259_COMMON (dev); - - isadev =i8259_init_chip (TYPE_I8259 , bus, false); - dev =DEVICE (isadev); - -qdev_connect_gpio_out (dev,0 , irq_set[2 ]); -for (i =0 ; i <8 ; i++) { - irq_set[i +8 ] =qdev_get_gpio_in (dev, i); - } - - slave_pic =I8259_COMMON (dev); + pic_obj =object_resolve_path_component (OBJECT (dev),"primary" ); + isa_pic =I8259_COMMON (pic_obj); + pic_obj =object_resolve_path_component (OBJECT (dev),"secondary" ); + slave_pic =I8259_COMMON (pic_obj);return irq_set; }
@@ -429,12 +441,103 @@ static void i8259_class_init(ObjectClass *klass, const void *data)device_class_set_legacy_reset (dc, i8259_reset); } + +static void i8259_pic_set_irq (void *opaque,int n,int level) +{ +I8259PICState *s = opaque; + +qemu_set_irq (s->pass_irqs[n], level); +} + +static void i8259_primary_out_irq (void *opaque,int n,int level) +{ +I8259PICState *s = opaque; + +qemu_set_irq (s->pic_out_irq, level); +} + +static void i8259_pic_init (Object *obj) +{ +I8259PICState *s =I8259_PIC (obj); + +object_initialize_child (obj,"primary" , &s->i8259[0 ],TYPE_I8259 ); +object_initialize_child (obj,"secondary" , &s->i8259[1 ],TYPE_I8259 ); + +qemu_init_irq (&s->i8259_primary_out_irq, i8259_primary_out_irq, s,1 ); + +qdev_init_gpio_in (DEVICE (obj), i8259_pic_set_irq,ISA_NUM_IRQS ); +qdev_init_gpio_out (DEVICE (obj), &s->pic_out_irq,1 ); +} + +static void i8259_pic_realize (DeviceState *dev,Error **errp) +{ +I8259PICState *s =I8259_PIC (dev); +DeviceState *pri_dev, *sec_dev; +int i; + +/* Primary */ + pri_dev =DEVICE (&s->i8259[0 ]); +qdev_prop_set_uint32 (pri_dev,"iobase" ,0x20 ); +qdev_prop_set_uint32 (pri_dev,"elcr_addr" ,0x4d0 ); +qdev_prop_set_uint8 (pri_dev,"elcr_mask" ,0xf8 ); +qdev_prop_set_bit (pri_dev,"master" ,1 ); +if (!isa_realize_and_unref (ISA_DEVICE (pri_dev), s->isabus, errp)) { +return ; + } + +for (i =0 ; i <8 ; i++) { + s->pass_irqs[i] =qdev_get_gpio_in (pri_dev, i); + } + +qdev_connect_gpio_out (pri_dev,0 , &s->i8259_primary_out_irq); + +/* Secondary */ + sec_dev =DEVICE (&s->i8259[1 ]); +qdev_prop_set_uint32 (sec_dev,"iobase" ,0xa0 ); +qdev_prop_set_uint32 (sec_dev,"elcr_addr" ,0x4d1 ); +qdev_prop_set_uint8 (sec_dev,"elcr_mask" ,0xde ); +if (!isa_realize_and_unref (ISA_DEVICE (sec_dev), s->isabus, errp)) { +return ; + } + +/* Wire up secondary cascade */ +qdev_connect_gpio_out (sec_dev,0 , s->pass_irqs[2 ]); + +for (i =8 ; i <ISA_NUM_IRQS ; i++) { + s->pass_irqs[i] =qdev_get_gpio_in (sec_dev, i -8 ); + } +} + +static const Property i8259_pic_properties[] = { +DEFINE_PROP_LINK ("bus" , I8259PICState, isabus,TYPE_ISA_BUS , + ISABus *), +}; + +static void i8259_pic_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = i8259_pic_realize; +device_class_set_props (dc, i8259_pic_properties); +/* +* Reason: must be wired to the ISA bus via the "bus" property +*/ + dc->user_creatable = false; +} +static const TypeInfo i8259_type_infos[] = { { .name =TYPE_I8259 , .parent =TYPE_I8259_COMMON , .class_init = i8259_class_init, }, + { + .name =TYPE_I8259_PIC , + .parent =TYPE_DEVICE , + .class_init = i8259_pic_class_init, + .instance_init = i8259_pic_init, + .instance_size =sizeof (I8259PICState), + }, };DEFINE_TYPES (i8259_type_infos)
Signature · 1 line
2.43.0
Re: [PATCH 13/22] i8259.c: introduce TYPE_I8259_PIC device
Quoted 28 lines · Mark Cave-Ayland
This device represents a PIC for an x86 machine consisting of 2 cascaded i8259 devices wired accordingly.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259.c | 133 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 118 insertions(+), 15 deletions(-)hw/intc/i8259.c +3
-0@@ -25,7 +25,9 @@#include "qemu/osdep.h" #include "hw/intc/i8259.h" #include "hw/core/irq.h" +#include "hw/core/qdev-properties.h" #include "hw/isa/isa.h" +#include "qapi/error.h" #include "qemu/timer.h" #include "qemu/log.h" #include "hw/isa/i8259_internal.h" @@ -36,6 +38,22 @@#define TYPE_I8259 "isa-i8259" +#define TYPE_I8259_PIC "isa-i8259-pic"
hw/intc/i8259.c line 51
Quoted 10 lines
hw/intc/i8259.c +10
-0+ +struct I8259PICState { +DeviceState parent_obj; + +qemu_irq pic_out_irq; +qemu_irq pass_irqs[ISA_NUM_IRQS ]; + +ISABus *isabus; +IRQState i8259_primary_out_irq; +I8259CommonState i8259[2 ];
This allocates only enough space for the common base class's instance struct, but later we do an object_initialize_child() of the child class. If the child class's state struct is ever bigger than the common class, this will break.
hw/intc/i8259.c static void i8259_class_init(ObjectClass *klass, const void *data) · line 536
Quoted 9 lines
hw/intc/i8259.c +3
-0static const TypeInfo i8259_type_infos[] = { { .name =TYPE_I8259 , .parent =TYPE_I8259_COMMON , .class_init = i8259_class_init, }, + { + .name =TYPE_I8259_PIC , + .parent =TYPE_DEVICE ,
Devices that directly inherit from TYPE_DEVICE are awkward, because they never get reset. Conviently this device doesn't currently need a reset method, but still, is this a good idea?
hw/intc/i8259.c static void i8259_class_init(ObjectClass *klass, const void *data) · line 543
Quoted 7 lines
hw/intc/i8259.c +4
-0+ .class_init = i8259_pic_class_init, + .instance_init = i8259_pic_init, + .instance_size = sizeof(I8259PICState), + }, };DEFINE_TYPES (i8259_type_infos)
-- PMM
Re: [PATCH 13/22] i8259.c: introduce TYPE_I8259_PIC device
Quoted 29 lines · Peter Maydell
Quoted 27 lines · Mark Cave-Ayland
This device represents a PIC for an x86 machine consisting of 2 cascaded i8259 devices wired accordingly.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259.c | 133 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 118 insertions(+), 15 deletions(-)hw/intc/i8259.c +2
-0@@ -25,7 +25,9 @@#include "qemu/osdep.h" #include "hw/intc/i8259.h" #include "hw/core/irq.h" +#include "hw/core/qdev-properties.h" #include "hw/isa/isa.h" +#include "qapi/error.h" #include "qemu/timer.h" #include "qemu/log.h" #include "hw/isa/i8259_internal.h" @@ -36,6 +38,22 @@#define TYPE_I8259 "isa-i8259"
Quoted 16 lines
hw/intc/i8259.c line 51
Quoted 11 lines
hw/intc/i8259.c +11
-0+#define TYPE_I8259_PIC "isa-i8259-pic" + +struct I8259PICState { +DeviceState parent_obj; + +qemu_irq pic_out_irq; +qemu_irq pass_irqs[ISA_NUM_IRQS ]; + +ISABus *isabus; +IRQState i8259_primary_out_irq; +I8259CommonState i8259[2 ];This allocates only enough space for the common base class's instance struct, but later we do an
object_initialize_child()of the child class. If the child class's state struct is ever bigger than the common class, this will break.
That's true. In theory this should be something like I8259State, however I didn't think it was worth adding a specific OBJECT_DECLARE_SIMPLE_TYPE() if there were no extra fields. I did quickly check that if this happens, then the assert() in object_initialize() fires so if this did happen then we'd find out really quickly.
Quoted 10 lines
hw/intc/i8259.c static void i8259_class_init(ObjectClass *klass, const void *data) · line 536
Quoted 9 lines
hw/intc/i8259.c +3
-0static const TypeInfo i8259_type_infos[] = { { .name =TYPE_I8259 , .parent =TYPE_I8259_COMMON , .class_init = i8259_class_init, }, + { + .name =TYPE_I8259_PIC , + .parent =TYPE_DEVICE ,
Quoted 3 lines
Devices that directly inherit from
TYPE_DEVICEare awkward, because they never get reset. Conviently this device doesn't currently need a reset method, but still, is this a good idea?
In this case I think it's correct, because the PIC device in this case is a container for 2 cascaded i8259s which are connected separately to the ISA bus. Therefore each i8259 will have its reset triggered via a reset of the ISA bus.
The container itself can't exist on the ISA bus because it would then appear as a separate device which doesn't make sense in this case.
Quoted 9 lines
hw/intc/i8259.c static void i8259_class_init(ObjectClass *klass, const void *data) · line 543
Quoted 7 lines
hw/intc/i8259.c +4
-0+ .class_init = i8259_pic_class_init, + .instance_init = i8259_pic_init, + .instance_size = sizeof(I8259PICState), + }, };DEFINE_TYPES (i8259_type_infos)-- PMM
ATB,
Mark.
Re: [PATCH 13/22] i8259.c: introduce TYPE_I8259_PIC device
Quoted 20 lines · Mark Cave-Ayland
Quoted 16 lines · Peter Maydell
hw/intc/i8259.c line 51
Quoted 9 lines · Mark Cave-Ayland
hw/intc/i8259.c +9
-0+struct I8259PICState { +DeviceState parent_obj; + +qemu_irq pic_out_irq; +qemu_irq pass_irqs[ISA_NUM_IRQS ]; + +ISABus *isabus; +IRQState i8259_primary_out_irq; +I8259CommonState i8259[2 ];This allocates only enough space for the common base class's instance struct, but later we do an
object_initialize_child()of the child class. If the child class's state struct is ever bigger than the common class, this will break.
Quoted 6 lines
That's true. In theory this should be something like I8259State, however I didn't think it was worth adding a specific
OBJECT_DECLARE_SIMPLE_TYPE()if there were no extra fields. I did quickly check that if this happens, then theassert()inobject_initialize()fires so if this did happen then we'd find out really quickly.
I think that every QOM class ought to define its own instance struct, even if it doesn't contain anything beyond the base class. This means that when we do need to add a field in future we don't have to go around and find the places which currently use the parent-class struct but really want the leaf-class struct. (There are places where we don't catch mistakes like this -- for instance I think if you don't update the .instance_size in a type then that doesn't get noticed:
we've had a bug or too like that).
We don't write that down in https://wiki.qemu.org/Documentation/QOMConventions
but we do have some similar rules about class structs that
boil down to "either you're a leaf class and provide none
of these things, or else you should provide them all; don't
have a halfway-house 'we happen to only need X and Y but
not Z right now' setup".
Quoted 14 lines
Quoted 10 lines
hw/intc/i8259.c static void i8259_class_init(ObjectClass *klass, const void *data) · line 536
Quoted 9 lines
static const TypeInfo i8259_type_infos[] = { { .name = TYPE_I8259, .parent = TYPE_I8259_COMMON, .class_init = i8259_class_init, },hw/intc/i8259.c +3
-0+ { + .name = TYPE_I8259_PIC, + .parent = TYPE_DEVICE,Quoted 3 lines
Devices that directly inherit from
TYPE_DEVICEare awkward, because they never get reset. Conviently this device doesn't currently need a reset method, but still, is this a good idea?
Quoted 7 lines
In this case I think it's correct, because the PIC device in this case is a container for 2 cascaded i8259s which are connected separately to the ISA bus. Therefore each i8259 will have its reset triggered via a reset of the ISA bus.
The container itself can't exist on the ISA bus because it would then appear as a separate device which doesn't make sense in this case.
OK.
-- PMM
Re: [PATCH 13/22] i8259.c: introduce TYPE_I8259_PIC device
Quoted 39 lines · Peter Maydell
Quoted 20 lines · Mark Cave-Ayland
Quoted 16 lines · Peter Maydell
hw/intc/i8259.c line 51
Quoted 9 lines · Mark Cave-Ayland
hw/intc/i8259.c +9
-0+struct I8259PICState { +DeviceState parent_obj; + +qemu_irq pic_out_irq; +qemu_irq pass_irqs[ISA_NUM_IRQS ]; + +ISABus *isabus; +IRQState i8259_primary_out_irq; +I8259CommonState i8259[2 ];This allocates only enough space for the common base class's instance struct, but later we do an
object_initialize_child()of the child class. If the child class's state struct is ever bigger than the common class, this will break.Quoted 6 lines
That's true. In theory this should be something like I8259State, however I didn't think it was worth adding a specific
OBJECT_DECLARE_SIMPLE_TYPE()if there were no extra fields. I did quickly check that if this happens, then theassert()inobject_initialize()fires so if this did happen then we'd find out really quickly.I think that every QOM class ought to define its own instance struct, even if it doesn't contain anything beyond the base class. This means that when we do need to add a field in future we don't have to go around and find the places which currently use the parent-class struct but really want the leaf-class struct. (There are places where we don't catch mistakes like this -- for instance I think if you don't update the .instance_size in a type then that doesn't get noticed:
we've had a bug or too like that).
Quoted 6 lines
We don't write that down in https://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.qemu.org_Documentation_QOMConventions&d=DwIBaQ&c=s883GpUCOChKOHiocYtGcg&r=c23RpsaH4D2MKyD3EPJTDa0BAxz6tV8aUJqVSoytEiY&m=_sMHrUpIgbF65xjh0xd4r-zuudhThxapWCIXp0orT8OH8CbTHKgmaw4SuUcNTpeW&s=9mPS_zIx9x3FD_6cxEpVK-5JyOlynQ3bsBTf44iWLPk&e=
but we do have some similar rules about class structs that
boil down to "either you're a leaf class and provide none
of these things, or else you should provide them all; don't
have a halfway-house 'we happen to only need X and Y but
not Z right now' setup".
Yes, that's fine with me. I have done it that way previously, however there are some people on-list still advocating for the approach in this series.
If we decide that this is our preferred style then I think it's worth documenting in somewhere in https://qemu.readthedocs.io/en/master/devel/style.html#qemu-object-model-declarations so that we can point people (and LLMs) towards it.
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
hw/intc/i8259.c static void i8259_class_init(ObjectClass *klass, const void *data) · line 536
Quoted 9 lines
static const TypeInfo i8259_type_infos[] = { { .name = TYPE_I8259, .parent = TYPE_I8259_COMMON, .class_init = i8259_class_init, },hw/intc/i8259.c +3
-0+ { + .name = TYPE_I8259_PIC, + .parent = TYPE_DEVICE,Quoted 3 lines
Devices that directly inherit from
TYPE_DEVICEare awkward, because they never get reset. Conviently this device doesn't currently need a reset method, but still, is this a good idea?In this case I think it's correct, because the PIC device in this case is a container for 2 cascaded i8259s which are connected separately to the ISA bus. Therefore each i8259 will have its reset triggered via a reset of the ISA bus.
Quoted 4 lines
Quoted 2 lines
The container itself can't exist on the ISA bus because it would then appear as a separate device which doesn't make sense in this case.
OK.
ATB,
Mark.
PATCH 14/22 i8259.c: properly cascade secondary i8259 from primary i8259
In reply to Mark Cave-AylandCurrently the cascaded output from the secondary i8259 is returned directly in the pass_irqs[] array, instead of being connected to the relevant input of the primary i8259.
--- hw/intc/i8259.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/intc/i8259.c +2 -1
@@ -501,7 +501,8 @@ static void i8259_pic_realize(DeviceState *dev, Error **errp) }/* Wire up secondary cascade */ -qdev_connect_gpio_out (sec_dev,0 , s->pass_irqs[2 ]); +qdev_connect_gpio_out (sec_dev,0 , +qdev_get_gpio_in (pri_dev,2 ));for (i =8 ; i <ISA_NUM_IRQS ; i++) { s->pass_irqs[i] =qdev_get_gpio_in (sec_dev, i -8 );
Signature · 1 line
2.43.0
Re: [PATCH 14/22] i8259.c: properly cascade secondary i8259 from primary i8259
Quoted 15 lines · Mark Cave-Ayland
Currently the cascaded output from the secondary i8259 is returned directly in the pass_irqs[] array, instead of being connected to the relevant input of the primary i8259.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/intc/i8259.c +0
-0
hw/intc/i8259.c static void i8259_pic_realize(DeviceState *dev, Error **errp) · line 505
Quoted 6 lines
hw/intc/i8259.c +2
-1@@ -501,7 +501,8 @@ static void i8259_pic_realize(DeviceState *dev, Error **errp) }/* Wire up secondary cascade */ -qdev_connect_gpio_out (sec_dev,0 , s->pass_irqs[2 ]); +qdev_connect_gpio_out (sec_dev,0 , +qdev_get_gpio_in (pri_dev,2 ));
We just added this line in the previous patch, so we might as well squash this change into the previous one I think.
-- PMM
Re: [PATCH 14/22] i8259.c: properly cascade secondary i8259 from primary i8259
Quoted 19 lines · Peter Maydell
Quoted 17 lines · Mark Cave-Ayland
Currently the cascaded output from the secondary i8259 is returned directly in the pass_irqs[] array, instead of being connected to the relevant input of the primary i8259.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/intc/i8259.c +0
-0@@ -501,7 +501,8 @@ static void i8259_pic_realize(DeviceState *dev, Error **errp) }
Quoted 7 lines
hw/intc/i8259.c static void i8259_pic_realize(DeviceState *dev, Error **errp) · line 505
Quoted 4 lines
hw/intc/i8259.c +2
-1/* Wire up secondary cascade */ -qdev_connect_gpio_out (sec_dev,0 , s->pass_irqs[2 ]); +qdev_connect_gpio_out (sec_dev,0 , +qdev_get_gpio_in (pri_dev,2 ));We just added this line in the previous patch, so we might as well squash this change into the previous one I think.
The reason for having this in a separate commit is because it is technically a behaviour change. Before this commit, an interrupt from the secondary PIC would *always* raise the passed interrupt, whereas on real hardware it is possible to disable interrupts from the secondary PIC by masking the relevant input on the primary PIC [1].
Since real hardware works this way then I would argue that this is fixing an existing bug, but I thought it was worth having as a separate commit just to be sure.
ATB,
Mark.
Re: [PATCH 14/22] i8259.c: properly cascade secondary i8259 from primary i8259
Quoted 29 lines · Mark Cave-Ayland
Quoted 19 lines · Peter Maydell
Quoted 17 lines · Mark Cave-Ayland
Currently the cascaded output from the secondary i8259 is returned directly in the pass_irqs[] array, instead of being connected to the relevant input of the primary i8259.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/intc/i8259.c +0
-0@@ -501,7 +501,8 @@ static void i8259_pic_realize(DeviceState *dev, Error **errp) }Quoted 7 lines
hw/intc/i8259.c static void i8259_pic_realize(DeviceState *dev, Error **errp) · line 505
Quoted 4 lines
hw/intc/i8259.c +2
-1/* Wire up secondary cascade */ -qdev_connect_gpio_out (sec_dev,0 , s->pass_irqs[2 ]); +qdev_connect_gpio_out (sec_dev,0 , +qdev_get_gpio_in (pri_dev,2 ));We just added this line in the previous patch, so we might as well squash this change into the previous one I think.
Quoted 5 lines
The reason for having this in a separate commit is because it is technically a behaviour change. Before this commit, an interrupt from the secondary PIC would *always* raise the passed interrupt, whereas on real hardware it is possible to disable interrupts from the secondary PIC by masking the relevant input on the primary PIC [1].
OK, if it's a behaviour change that's fine. The commit message is written as if it's just a refactoring, though -- it would be helpful to spell out what the behaviour change there and that it's fixing a corner case bug.
-- PMM
PATCH 15/22 kvm/i8259.c: introduce TYPE_KVM_I8259_PIC device
In reply to Mark Cave-AylandThis device represents the KVM in-kernel PIC for an x86 machine.
--- hw/i386/kvm/i8259.c | 91 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-)
hw/i386/kvm/i8259.c +88 -3
@@ -16,11 +16,25 @@#include "qemu/module.h" #include "hw/intc/kvm_irqcount.h" #include "hw/core/irq.h" +#include "hw/core/qdev-properties.h" #include "system/kvm.h" +#include "qapi/error.h" #include "qom/object.h" #define TYPE_KVM_I8259 "kvm-i8259" +#define TYPE_KVM_I8259_PIC "kvm-i8259-pic" + +struct KVMI8259PICState { +DeviceState parent_obj; + +ISABus *isabus; +I8259CommonState i8259[2 ]; +}; + +OBJECT_DECLARE_SIMPLE_TYPE(KVMI8259PICState, KVM_I8259_PIC) + +static void kvm_i8259_get (I8259CommonState *s) {struct kvm_irqchip chip;
@@ -120,10 +134,21 @@ static void kvm_i8259_realize(DeviceState *dev, Error **errp)qemu_irq *kvm_i8259_init (ISABus *bus) { -i8259_init_chip (TYPE_KVM_I8259 , bus, true); -i8259_init_chip (TYPE_KVM_I8259 , bus, false); +qemu_irq *irq_set; +DeviceState *dev; +int i; + + irq_set =g_new0 (qemu_irq,ISA_NUM_IRQS ); + + dev =qdev_new (TYPE_KVM_I8259_PIC ); +object_property_set_link (OBJECT (dev),"bus" ,OBJECT (bus), &error_fatal); +qdev_realize_and_unref (dev,NULL , &error_fatal); -return qemu_allocate_irqs (kvm_pic_set_irq,NULL ,ISA_NUM_IRQS ); +for (i =0 ; i <ISA_NUM_IRQS ; i++) { + irq_set[i] =qdev_get_gpio_in (dev, i); + } + +return irq_set; }static void kvm_i8259_class_init (ObjectClass *klass,const void *data)
@@ -137,12 +162,72 @@ static void kvm_i8259_class_init(ObjectClass *klass, const void *data) k->post_load = kvm_i8259_put; } + +static void kvm_i8259_pic_init (Object *obj) +{ +KVMI8259PICState *s =KVM_I8259_PIC (obj); + +object_initialize_child (obj,"primary" , &s->i8259[0 ],TYPE_KVM_I8259 ); +object_initialize_child (obj,"secondary" , &s->i8259[1 ],TYPE_KVM_I8259 ); + +qdev_init_gpio_in (DEVICE (obj), kvm_pic_set_irq,ISA_NUM_IRQS ); +} + +static void kvm_i8259_pic_realize (DeviceState *dev,Error **errp) +{ +KVMI8259PICState *s =KVM_I8259_PIC (dev); +DeviceState *pri_dev, *sec_dev; + +/* Primary */ + pri_dev =DEVICE (&s->i8259[0 ]); +qdev_prop_set_uint32 (pri_dev,"iobase" ,0x20 ); +qdev_prop_set_uint32 (pri_dev,"elcr_addr" ,0x4d0 ); +qdev_prop_set_uint8 (pri_dev,"elcr_mask" ,0xf8 ); +qdev_prop_set_bit (pri_dev,"master" ,1 ); +if (!isa_realize_and_unref (ISA_DEVICE (pri_dev), s->isabus, errp)) { +return ; + } + +/* Secondary */ + sec_dev =DEVICE (&s->i8259[1 ]); +qdev_prop_set_uint32 (sec_dev,"iobase" ,0xa0 ); +qdev_prop_set_uint32 (sec_dev,"elcr_addr" ,0x4d1 ); +qdev_prop_set_uint8 (sec_dev,"elcr_mask" ,0xde ); +if (!isa_realize_and_unref (ISA_DEVICE (sec_dev), s->isabus, errp)) { +return ; + } +} + +static const Property kvm_i8259_pic_properties[] = { +DEFINE_PROP_LINK ("bus" , KVMI8259PICState, isabus,TYPE_ISA_BUS , + ISABus *), +}; + +static void kvm_i8259_pic_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = kvm_i8259_pic_realize; +device_class_set_props (dc, kvm_i8259_pic_properties); +/* +* Reason: must be wired to the ISA bus via the "bus" property +*/ + dc->user_creatable = false; +} +static const TypeInfo kvm_i8259_type_infos[] = { { .name =TYPE_KVM_I8259 , .parent =TYPE_I8259_COMMON , .class_init = kvm_i8259_class_init, }, + { + .name =TYPE_KVM_I8259_PIC , + .parent =TYPE_DEVICE , + .class_init = kvm_i8259_pic_class_init, + .instance_init = kvm_i8259_pic_init, + .instance_size =sizeof (KVMI8259PICState), + }, };DEFINE_TYPES (kvm_i8259_type_infos)
Signature · 1 line
2.43.0
PATCH 16/22 xen-hvm.c: rename xen_interrupt_controller_init() to xen_i8259_init()
In reply to Mark Cave-AylandThis clarifies that the interrupt controller being modelled is an emulated i8259 implementation, and brings the naming convention in line with the in-built i8259 and KVM i8259 implementations.
--- include/hw/xen/xen.h | 2 +- hw/i386/pc.c | 2 +- hw/i386/xen/xen-hvm.c | 2 +- stubs/xen-hw-stub.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
include/hw/xen/xen.h +1 -1
@@ -42,7 +42,7 @@ void xen_intx_set_irq(void *opaque, int irq_num, int level);void xen_hvm_inject_msi (uint64_t addr,uint32_t data);int xen_is_pirq_msi (uint32_t msi_data); -qemu_irq *xen_interrupt_controller_init (void ); +qemu_irq *xen_i8259_init (void );void xen_register_framebuffer (struct MemoryRegion *mr);
hw/i386/pc.c +1 -1
@@ -1169,7 +1169,7 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs)if (kvm_pic_in_kernel ()) { i8259 =kvm_i8259_init (isa_bus); }else if (xen_enabled ()) { - i8259 =xen_interrupt_controller_init (); + i8259 =xen_i8259_init (); }else { i8259 =i8259_init (isa_bus,x86_allocate_cpu_irq ()); }
hw/i386/xen/xen-hvm.c +1 -1
@@ -112,7 +112,7 @@ static void xen_set_irq(void *opaque, int irq, int level)xen_set_isa_irq_level (xen_domid, irq, level); } -qemu_irq *xen_interrupt_controller_init (void ) +qemu_irq *xen_i8259_init (void ) {return qemu_allocate_irqs (xen_set_irq,NULL ,16 ); }
stubs/xen-hw-stub.c +1 -1
@@ -29,7 +29,7 @@ int xen_is_pirq_msi(uint32_t msi_data)return 0 ; } -qemu_irq *xen_interrupt_controller_init (void ) +qemu_irq *xen_i8259_init (void ) {return NULL ; }
Signature · 1 line
2.43.0
Re: [PATCH 16/22] xen-hvm.c: rename xen_interrupt_controller_init() to xen_i8259_init()
Quoted 5 lines · Mark Cave-Ayland
This clarifies that the interrupt controller being modelled is an emulated i8259 implementation, and brings the naming convention in line with the in-built i8259 and KVM i8259 implementations.
Quoted 7 lines
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/xen/xen.h | 2 +- hw/i386/pc.c | 2 +- hw/i386/xen/xen-hvm.c | 2 +- stubs/xen-hw-stub.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
thanks
-- PMM
PATCH 17/22 xen/xen-hvm.c: introduce TYPE_XEN_I8259_PIC device
In reply to Mark Cave-AylandThis device represents the Xen PIC for an x86 machine.
--- hw/i386/xen/xen-hvm.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
hw/i386/xen/xen-hvm.c +37 -1
@@ -13,6 +13,7 @@#include "qemu/error-report.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" +#include "qom/object.h" #include "trace.h" #include "hw/core/hw-error.h"
@@ -69,6 +70,12 @@ static unsigned long *dirty_bitmap;static Notifier suspend;static Notifier wakeup; +#define TYPE_XEN_I8259_PIC "xen-i8259-pic" + +DECLARE_OBJ_CHECKERS (DeviceState, DeviceClass,XEN_I8259_PIC , +TYPE_XEN_I8259_PIC ) + + /* Xen specific function for piix pci */int xen_pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num)
@@ -114,9 +121,28 @@ static void xen_set_irq(void *opaque, int irq, int level)qemu_irq *xen_i8259_init (void ) { -return qemu_allocate_irqs (xen_set_irq,NULL ,16 ); +qemu_irq *irq_set; +DeviceState *dev; +int i; + + irq_set =g_new0 (qemu_irq,16 ); + + dev =qdev_new (TYPE_XEN_I8259_PIC ); +qdev_realize_and_unref (dev,NULL , &error_fatal); + +for (i =0 ; i <16 ; i++) { + irq_set[i] =qdev_get_gpio_in (dev, i); + } + +return irq_set; } +static void xen_i8259_pic_init (Object *obj) +{ +qdev_init_gpio_in (DEVICE (obj), xen_set_irq,16 ); +} + +/* Memory Ops */ static void xen_ram_init(PCMachineState *pcms,
@@ -760,3 +786,13 @@ void arch_handle_ioreq(XenIOState *state, ioreq_t *req)hw_error ("Invalid ioreq type 0x%x\n" , req->type); } } + +static const TypeInfo xen_i8259_type_infos[] = { + { + .name =TYPE_XEN_I8259_PIC , + .parent =TYPE_DEVICE , + .instance_init = xen_i8259_pic_init, + }, +}; + +DEFINE_TYPES (xen_i8259_type_infos)
Signature · 1 line
2.43.0
PATCH 18/22 i8259_common.c: remove unused i8259_init_chip() function
In reply to Mark Cave-AylandThis function is now unused and can be removed.
--- include/hw/isa/i8259_internal.h | 1 - hw/intc/i8259_common.c | 16 ---------------- 2 files changed, 17 deletions(-)
include/hw/isa/i8259_internal.h +0 -1
@@ -73,7 +73,6 @@ struct I8259CommonState { };void i8259_common_reset (I8259CommonState *s); -ISADevice *i8259_init_chip (const char *name,ISABus *bus,bool master);void i8259_stat_update_irq (int irq,int level);#endif /* QEMU_I8259_INTERNAL_H */
hw/intc/i8259_common.c +0 -16
@@ -89,22 +89,6 @@ static void i8259_common_realize(DeviceState *dev, Error **errp)qdev_set_legacy_instance_id (dev, s->iobase,1 ); } -ISADevice *i8259_init_chip (const char *name,ISABus *bus,bool master) -{ -DeviceState *dev; -ISADevice *isadev; - - isadev =isa_new (name); - dev =DEVICE (isadev); -qdev_prop_set_uint32 (dev,"iobase" , master ?0x20 :0xa0 ); -qdev_prop_set_uint32 (dev,"elcr_addr" , master ?0x4d0 :0x4d1 ); -qdev_prop_set_uint8 (dev,"elcr_mask" , master ?0xf8 :0xde ); -qdev_prop_set_bit (dev,"master" , master); -isa_realize_and_unref (isadev, bus, &error_fatal); - -return isadev; -} -void i8259_stat_update_irq (int irq,int level) {if (level != irq_level[irq]) {
Signature · 1 line
2.43.0
Re: [PATCH 18/22] i8259_common.c: remove unused i8259_init_chip() function
Quoted 8 lines · Mark Cave-Ayland
This function is now unused and can be removed.
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/isa/i8259_internal.h | 1 - hw/intc/i8259_common.c | 16 ---------------- 2 files changed, 17 deletions(-)
thanks
-- PMM
PATCH 19/22 i8259: move InterruptStatsProviderClass get_statistics() from i8259 to PIC
In reply to Mark Cave-AylandThe internal i8259 implementation has workaround logic for storing interrupt statistics since these are currently recorded at the PIC level (i.e. for all 16 interrupt lines) whilst being stored in the master i8259 device which only has 8 physical interrupt lines.
Move the get_statistics() implementation from the individual i8259 device to the containing PIC device in preparation for removing this hack. Note that this has a visible change to the "info pic" HMP monitor output since the named device displayed by "info irq" is now the PIC and not the individual i8259:
Before (TCG):
(qemu) info irq
IRQ statistics for ioapic:
0: 68
4: 1
IRQ statistics for isa-i8259:
0: 68
4: 1
After (TCG):
(qemu) info irq
IRQ statistics for ioapic:
0: 47
4: 1
IRQ statistics for isa-i8259-pic:
0: 47
4: 1
Before (KVM):
(qemu) info irq
IRQ statistics for kvm-ioapic:
4: 1
IRQ statistics for kvm-i8259:
4: 1
After (KVM):
(qemu) info irq
IRQ statistics for kvm-ioapic:
1: 3
4: 1
IRQ statistics for kvm-i8259-pic:
1: 3
4: 1
--- include/hw/intc/i8259.h | 6 ++++++ include/hw/isa/i8259_internal.h | 1 - hw/i386/kvm/i8259.c | 7 +++++++ hw/intc/i8259.c | 7 +++++++ hw/intc/i8259_common.c | 27 ++++++++++++++++++--------- 5 files changed, 38 insertions(+), 10 deletions(-)
include/hw/intc/i8259.h +6 -0
@@ -1,6 +1,8 @@#ifndef HW_I8259_H #define HW_I8259_H +#include "hw/intc/intc.h" +/* i8259.c */ typedef struct I8259CommonState I8259CommonState ;
@@ -18,5 +20,9 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in);qemu_irq *kvm_i8259_init (ISABus *bus);int pic_get_output (I8259CommonState *s);int pic_read_irq (I8259CommonState *s); +bool i8259_pic_get_statistics (InterruptStatsProvider *obj, +uint64_t **irq_counts, +unsigned int *nb_irqs); +void i8259_pic_print_info (InterruptStatsProvider *obj,GString *buf);#endif
include/hw/isa/i8259_internal.h +0 -1
@@ -26,7 +26,6 @@#define QEMU_I8259_INTERNAL_H #include "hw/isa/isa.h" -#include "hw/intc/intc.h" #include "hw/intc/i8259.h" #include "qom/object.h"
hw/i386/kvm/i8259.c +7 -0
@@ -206,9 +206,12 @@ static const Property kvm_i8259_pic_properties[] = {static void kvm_i8259_pic_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +InterruptStatsProviderClass *ic =INTERRUPT_STATS_PROVIDER_CLASS (klass); dc->realize = kvm_i8259_pic_realize;device_class_set_props (dc, kvm_i8259_pic_properties); + ic->get_statistics = i8259_pic_get_statistics; + ic->print_info = i8259_pic_print_info;/* * Reason: must be wired to the ISA bus via the "bus" property */
@@ -227,6 +230,10 @@ static const TypeInfo kvm_i8259_type_infos[] = { .class_init = kvm_i8259_pic_class_init, .instance_init = kvm_i8259_pic_init, .instance_size = sizeof(KVMI8259PICState), + .interfaces = (const InterfaceInfo []) { + {TYPE_INTERRUPT_STATS_PROVIDER }, + { } + }, }, };
hw/intc/i8259.c +7 -0
@@ -517,9 +517,12 @@ static const Property i8259_pic_properties[] = {static void i8259_pic_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +InterruptStatsProviderClass *ic =INTERRUPT_STATS_PROVIDER_CLASS (klass); dc->realize = i8259_pic_realize;device_class_set_props (dc, i8259_pic_properties); + ic->get_statistics = i8259_pic_get_statistics; + ic->print_info = i8259_pic_print_info;/* * Reason: must be wired to the ISA bus via the "bus" property */
@@ -538,6 +541,10 @@ static const TypeInfo i8259_type_infos[] = { .class_init = i8259_pic_class_init, .instance_init = i8259_pic_init, .instance_size = sizeof(I8259PICState), + .interfaces = (const InterfaceInfo []) { + {TYPE_INTERRUPT_STATS_PROVIDER }, + { } + }, }, };
hw/intc/i8259_common.c +18 -9
@@ -99,19 +99,28 @@ void i8259_stat_update_irq(int irq, int level) } } +bool i8259_pic_get_statistics (InterruptStatsProvider *obj, +uint64_t **irq_counts, +unsigned int *nb_irqs) +{ + *irq_counts = irq_count; + *nb_irqs =ARRAY_SIZE (irq_count); + +return true; +} + +void i8259_pic_print_info (InterruptStatsProvider *obj,GString *buf) +{ +/* No information for i8259-based PICs */ +return ; +} +static bool i8259_common_get_statistics (InterruptStatsProvider *obj,uint64_t **irq_counts,unsigned int *nb_irqs) { -I8259CommonState *s =I8259_COMMON (obj); - -if (s->master) { - *irq_counts = irq_count; - *nb_irqs =ARRAY_SIZE (irq_count); - }else { - *irq_counts =NULL ; - *nb_irqs =0 ; - } +/* No statistics for individual i8259s */ + *nb_irqs =0 ;return true; }
Signature · 1 line
2.43.0
Re: [PATCH 19/22] i8259: move InterruptStatsProviderClass get_statistics() from i8259 to PIC
Quoted 11 lines · Mark Cave-Ayland
The internal i8259 implementation has workaround logic for storing interrupt statistics since these are currently recorded at the PIC level (i.e. for all 16 interrupt lines) whilst being stored in the master i8259 device which only has 8 physical interrupt lines.
Move the
get_statistics()implementation from the individual i8259 device to the containing PIC device in preparation for removing this hack. Note that this has a visible change to the "info pic" HMP monitor output since the named device displayed by "info irq" is now the PIC and not the individual i8259:
thanks
-- PMM
PATCH 20/22 i8259.c: switch isa_pic from I8259CommonState to I8259PICState
In reply to Mark Cave-AylandThe isa_pic variable exists to allow the output to be fetched or read (fetched and acknowledged) from the x86 PIC. Since this can also contain a cascaded interrupt from a slave i8259, switch isa_pic from I8259CommonState to I8259PICState and update both pic_get_output() and pic_read_irq() accordingly.
This has the advantage that a i8259-based PIC device contains its own internal reference to both the primary and secondary i8259s, and therefore it becomes possible to completely remove the slave_pic variable.
--- include/hw/intc/i8259.h | 7 ++++--- hw/intc/i8259.c | 33 +++++++++++++++------------------ 2 files changed, 19 insertions(+), 21 deletions(-)
include/hw/intc/i8259.h +4 -3
@@ -6,8 +6,9 @@/* i8259.c */ typedef struct I8259CommonState I8259CommonState ; +typedef struct I8259PICState I8259PICState ; -extern I8259CommonState *isa_pic; +extern I8259PICState *isa_pic;/* * i8259_init()
@@ -18,8 +19,8 @@ extern I8259CommonState *isa_pic;*/ qemu_irq *i8259_init (ISABus *bus,qemu_irq parent_irq_in);qemu_irq *kvm_i8259_init (ISABus *bus); -int pic_get_output (I8259CommonState *s); -int pic_read_irq (I8259CommonState *s); +int pic_get_output (I8259PICState *s); +int pic_read_irq (I8259PICState *s);bool i8259_pic_get_statistics (InterruptStatsProvider *obj,uint64_t **irq_counts,unsigned int *nb_irqs);
hw/intc/i8259.c +15 -18
@@ -57,8 +57,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(I8259PICState, I8259_PIC)#ifdef DEBUG_IRQ_LATENCY static int64_t irq_time[16 ];#endif -I8259CommonState *isa_pic; -static I8259CommonState *slave_pic; +I8259PICState *isa_pic;/* return the highest priority found in mask (highest = smallest number). Return 8 if no irq */
@@ -175,33 +174,35 @@ static void i8259_intack(I8259CommonState *s, int irq)i8259_update_irq (s); } -int pic_read_irq (I8259CommonState *s) +int pic_read_irq (I8259PICState *s) { +I8259CommonState *pri = &s->i8259[0 ]; +I8259CommonState *sec = &s->i8259[1 ];int irq, intno; - irq =i8259_get_irq (s); + irq =i8259_get_irq (pri);if (irq >=0 ) {int irq2;if (irq ==2 ) { - irq2 =i8259_get_irq (slave_pic); + irq2 =i8259_get_irq (sec);if (irq2 >=0 ) { -i8259_intack (slave_pic, irq2); +i8259_intack (sec, irq2); }else {/* spurious IRQ on slave controller */ irq2 =7 ; } - intno = slave_pic->irq_base + irq2; -i8259_intack (s, irq); + intno = sec->irq_base + irq2; +i8259_intack (pri, irq); irq = irq2 +8 ; }else { - intno = s->irq_base + irq; -i8259_intack (s, irq); + intno = pri->irq_base + irq; +i8259_intack (pri, irq); } }else {/* spurious IRQ on host controller */ irq =7 ; - intno = s->irq_base + irq; + intno = pri->irq_base + irq; }#ifdef DEBUG_IRQ_LATENCY
@@ -353,9 +354,9 @@ static uint64_t i8259_base_ioport_read(void *opaque, hwaddr addr,return ret; } -int pic_get_output (I8259CommonState *s) +int pic_get_output (I8259PICState *s) { -return (i8259_get_irq (s) >=0 ); +return (i8259_get_irq (&s->i8259[0 ]) >=0 ); } static void i8259_elcr_ioport_write(void *opaque, hwaddr addr,
@@ -410,7 +411,6 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in) {qemu_irq *irq_set;DeviceState *dev; -Object *pic_obj;int i; irq_set =g_new0 (qemu_irq,ISA_NUM_IRQS );
@@ -424,10 +424,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in) irq_set[i] =qdev_get_gpio_in (dev, i); } - pic_obj =object_resolve_path_component (OBJECT (dev),"primary" ); - isa_pic =I8259_COMMON (pic_obj); - pic_obj =object_resolve_path_component (OBJECT (dev),"secondary" ); - slave_pic =I8259_COMMON (pic_obj); + isa_pic =I8259_PIC (dev);return irq_set; }
Signature · 1 line
2.43.0
Re: [PATCH 20/22] i8259.c: switch isa_pic from I8259CommonState to I8259PICState
Quoted 6 lines · Mark Cave-Ayland
The
isa_picvariable exists to allow the output to be fetched or read (fetched and acknowledged) from the x86 PIC. Since this can also contain a cascaded interrupt from a slave i8259, switchisa_picfrom I8259CommonState to I8259PICState and update bothpic_get_output()andpic_read_irq()accordingly.
Quoted 6 lines
This has the advantage that a i8259-based PIC device contains its own internal reference to both the primary and secondary i8259s, and therefore it becomes possible to completely remove the
slave_picvariable.Signed-off-by Mark Cave-Ayland <[email protected]>---
(That isa_pic global is kind of ugly; in an ideal world the callers would have a pointer to the PIC they cared about rather than relying on there being exactly one in the system...)
thanks
-- PMM
Re: [PATCH 20/22] i8259.c: switch isa_pic from I8259CommonState to I8259PICState
Quoted 12 lines · Peter Maydell
Quoted 10 lines · Mark Cave-Ayland
The
isa_picvariable exists to allow the output to be fetched or read (fetched and acknowledged) from the x86 PIC. Since this can also contain a cascaded interrupt from a slave i8259, switchisa_picfrom I8259CommonState to I8259PICState and update bothpic_get_output()andpic_read_irq()accordingly.This has the advantage that a i8259-based PIC device contains its own internal reference to both the primary and secondary i8259s, and therefore it becomes possible to completely remove the
slave_picvariable.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Mark Cave-Ayland <[email protected]>---
Reviewed-by Peter Maydell <[email protected]>(That
isa_picglobal is kind of ugly; in an ideal world the callers would have a pointer to the PIC they cared about rather than relying on there being exactly one in the system...)
That was actually one of the ultimate aims of this series, however I submitted the 8259 changes separately to avoid sending a much larger series :)
ATB,
Mark.
PATCH 21/22 i8259_common.c: remove static irq_count and irq_level variables
In reply to Mark Cave-AylandAdjust the parameters to i8259_stat_update_irq() to allow passing in pointers to the irq_count and irq_level arrays, and then move the arrays into the corresponding i8259 PIC and KVM PIC devices.
Doing this allows the statistics capture logic in i8259_set_irq() that handles incoming cascading interrupts to be removed.
--- include/hw/intc/i8259.h | 3 --- include/hw/isa/i8259_internal.h | 3 ++- hw/i386/kvm/i8259.c | 20 +++++++++++++++-- hw/intc/i8259.c | 40 ++++++++++++++++++++++----------- hw/intc/i8259_common.c | 21 +++++------------ 5 files changed, 52 insertions(+), 35 deletions(-)
include/hw/intc/i8259.h +0 -3
@@ -21,9 +21,6 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq_in);qemu_irq *kvm_i8259_init (ISABus *bus);int pic_get_output (I8259PICState *s);int pic_read_irq (I8259PICState *s); -bool i8259_pic_get_statistics (InterruptStatsProvider *obj, -uint64_t **irq_counts, -unsigned int *nb_irqs);void i8259_pic_print_info (InterruptStatsProvider *obj,GString *buf);#endif
include/hw/isa/i8259_internal.h +2 -1
@@ -72,6 +72,7 @@ struct I8259CommonState { };void i8259_common_reset (I8259CommonState *s); -void i8259_stat_update_irq (int irq,int level); +void i8259_stat_update_irq (uint64_t *irq_levels,int *irq_counts, +int irq,int level);#endif /* QEMU_I8259_INTERNAL_H */
hw/i386/kvm/i8259.c +18 -2
@@ -30,6 +30,9 @@ struct KVMI8259PICState {ISABus *isabus;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; };OBJECT_DECLARE_SIMPLE_TYPE (KVMI8259PICState,KVM_I8259_PIC )
@@ -102,6 +105,18 @@ static void kvm_i8259_put(I8259CommonState *s) } } +static bool kvm_i8259_pic_get_statistics (InterruptStatsProvider *obj, +uint64_t **irq_counts, +unsigned int *nb_irqs) +{ +KVMI8259PICState *s =KVM_I8259_PIC (obj); + + *irq_counts = s->irq_count; + *nb_irqs =ARRAY_SIZE (s->irq_count); + +return true; +} +static void kvm_i8259_reset (DeviceState *dev) {I8259CommonState *s =I8259_COMMON (dev);
@@ -114,9 +129,10 @@ static void kvm_i8259_reset(DeviceState *dev)static void kvm_pic_set_irq (void *opaque,int irq,int level) { +KVMI8259PICState *s = opaque;int delivered; -i8259_stat_update_irq (irq, level); +i8259_stat_update_irq (s->irq_count, s->irq_level, irq, level); delivered =kvm_set_irq (kvm_state, irq, level);kvm_report_irq_delivered (delivered); }
@@ -210,7 +226,7 @@ static void kvm_i8259_pic_class_init(ObjectClass *klass, const void *data) dc->realize = kvm_i8259_pic_realize;device_class_set_props (dc, kvm_i8259_pic_properties); - ic->get_statistics = i8259_pic_get_statistics; + ic->get_statistics = kvm_i8259_pic_get_statistics; ic->print_info = i8259_pic_print_info;/* * Reason: must be wired to the ISA bus via the "bus" property
hw/intc/i8259.c +27 -13
@@ -49,14 +49,16 @@ struct I8259PICState {ISABus *isabus;IRQState i8259_primary_out_irq;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; +#ifdef DEBUG_IRQ_LATENCY +int64_t irq_time[ISA_NUM_IRQS ]; +#endif }; OBJECT_DECLARE_SIMPLE_TYPE(I8259PICState, I8259_PIC) - -#ifdef DEBUG_IRQ_LATENCY -static int64_t irq_time[16 ]; -#endif I8259PICState *isa_pic;/* return the highest priority found in mask (highest = smallest
@@ -123,16 +125,8 @@ static void i8259_set_irq(void *opaque, int irq, int level) {I8259CommonState *s = opaque;int mask =1 << irq; -int irq_index = s->master ? irq : irq +8 ;trace_pic_set_irq (s->master, irq, level); -i8259_stat_update_irq (irq_index, level); - -#ifdef DEBUG_IRQ_LATENCY -if (level) { - irq_time[irq_index] =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); - } -#endif if (s->ltim || (s->elcr & mask)) {/* level triggered */
@@ -209,7 +203,7 @@ int pic_read_irq(I8259PICState *s)printf ("IRQ%d latency=%0.3fus\n" , irq, (double )(qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - - irq_time[irq]) *1000000.0 /NANOSECONDS_PER_SECOND ); + s->irq_time[irq]) *1000000.0 /NANOSECONDS_PER_SECOND );#endif trace_pic_interrupt (irq, intno);
@@ -439,10 +433,30 @@ static void i8259_class_init(ObjectClass *klass, const void *data) } +static bool i8259_pic_get_statistics (InterruptStatsProvider *obj, +uint64_t **irq_counts, +unsigned int *nb_irqs) +{ +I8259PICState *s =I8259_PIC (obj); + + *irq_counts = s->irq_count; + *nb_irqs =ARRAY_SIZE (s->irq_count); + +return true; +} +static void i8259_pic_set_irq (void *opaque,int n,int level) {I8259PICState *s = opaque; +i8259_stat_update_irq (s->irq_count, s->irq_level, n, level); + +#ifdef DEBUG_IRQ_LATENCY +if (level) { + s->irq_time[n] =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + } +#endif +qemu_set_irq (s->pass_irqs[n], level); }
hw/intc/i8259_common.c +5 -16
@@ -30,8 +30,6 @@#include "migration/vmstate.h" #include "qapi/error.h" -static int irq_level[16 ]; -static uint64_t irq_count[16 ];void i8259_common_reset (I8259CommonState *s) {
@@ -89,26 +87,17 @@ static void i8259_common_realize(DeviceState *dev, Error **errp)qdev_set_legacy_instance_id (dev, s->iobase,1 ); } -void i8259_stat_update_irq (int irq,int level) +void i8259_stat_update_irq (uint64_t *irq_counts,int *irq_levels, +int irq,int level) { -if (level != irq_level[irq]) { - irq_level[irq] = level; +if (level != irq_levels[irq]) { + irq_levels[irq] = level;if (level ==1 ) { - irq_count[irq]++; + irq_counts[irq]++; } } } -bool i8259_pic_get_statistics (InterruptStatsProvider *obj, -uint64_t **irq_counts, -unsigned int *nb_irqs) -{ - *irq_counts = irq_count; - *nb_irqs =ARRAY_SIZE (irq_count); - -return true; -} -void i8259_pic_print_info (InterruptStatsProvider *obj,GString *buf) {/* No information for i8259-based PICs */
Signature · 1 line
2.43.0
Re: [PATCH 21/22] i8259_common.c: remove static irq_count and irq_level variables
Quoted 29 lines · Mark Cave-Ayland
Adjust the parameters to
i8259_stat_update_irq()to allow passing in pointers to theirq_countandirq_levelarrays, and then move the arrays into the corresponding i8259 PIC and KVM PIC devices.Doing this allows the statistics capture logic in
i8259_set_irq()that handles incoming cascading interrupts to be removed.Signed-off-by Mark Cave-Ayland <[email protected]>hw/i386/kvm/i8259.c +3
-0@@ -30,6 +30,9 @@ struct KVMI8259PICState {ISABus *isabus;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; };hw/intc/i8259.c +0
-0
hw/intc/i8259.c struct I8259PICState { · line 58
Quoted 10 lines
hw/intc/i8259.c +6
-0@@ -49,14 +49,16 @@ struct I8259PICState {ISABus *isabus;IRQState i8259_primary_out_irq;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; +#ifdef DEBUG_IRQ_LATENCY +int64_t irq_time[ISA_NUM_IRQS ]; +#endif };
Would it make sense for these two types to have a common base class (where the stats stuff could then live)? AIUI they're both intending to provide the same interface ("pair of i8259 devices cascaded together in the way that x86 does it").
-- PMM
Re: [PATCH 21/22] i8259_common.c: remove static irq_count and irq_level variables
Quoted 38 lines · Peter Maydell
Quoted 36 lines · Mark Cave-Ayland
Adjust the parameters to
i8259_stat_update_irq()to allow passing in pointers to theirq_countandirq_levelarrays, and then move the arrays into the corresponding i8259 PIC and KVM PIC devices.Doing this allows the statistics capture logic in
i8259_set_irq()that handles incoming cascading interrupts to be removed.Signed-off-by Mark Cave-Ayland <[email protected]>hw/i386/kvm/i8259.c +3
-0@@ -30,6 +30,9 @@ struct KVMI8259PICState {ISABus *isabus;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; };hw/intc/i8259.c +4
-0@@ -49,14 +49,16 @@ struct I8259PICState {ISABus *isabus;IRQState i8259_primary_out_irq;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; +#ifdef DEBUG_IRQ_LATENCY
Quoted 8 lines
hw/intc/i8259.c struct I8259PICState { · line 58
Quoted 3 lines
hw/intc/i8259.c +2
-0+int64_t irq_time[ISA_NUM_IRQS ]; +#endif };Would it make sense for these two types to have a common base class (where the stats stuff could then live)? AIUI they're both intending to provide the same interface ("pair of i8259 devices cascaded together in the way that x86 does it").
I did consider this in development since it would avoid the duplication here (and potentially in both realize() methods), but wasn't sure the extra complexity of the object hierarchy was worth it.
However since you've also raised the idea, I'll have a look at this and add it to v2 if it looks good.
ATB,
Mark.
Re: [PATCH 21/22] i8259_common.c: remove static irq_count and irq_level variables
In reply to Peter MaydellQuoted 38 lines · Peter Maydell
Quoted 36 lines · Mark Cave-Ayland
Adjust the parameters to
i8259_stat_update_irq()to allow passing in pointers to theirq_countandirq_levelarrays, and then move the arrays into the corresponding i8259 PIC and KVM PIC devices.Doing this allows the statistics capture logic in
i8259_set_irq()that handles incoming cascading interrupts to be removed.Signed-off-by Mark Cave-Ayland <[email protected]>hw/i386/kvm/i8259.c +3
-0@@ -30,6 +30,9 @@ struct KVMI8259PICState {ISABus *isabus;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; };hw/intc/i8259.c +4
-0@@ -49,14 +49,16 @@ struct I8259PICState {ISABus *isabus;IRQState i8259_primary_out_irq;I8259CommonState i8259[2 ]; + +int irq_level[ISA_NUM_IRQS ]; +uint64_t irq_count[ISA_NUM_IRQS ]; +#ifdef DEBUG_IRQ_LATENCY
Quoted 8 lines
hw/intc/i8259.c struct I8259PICState { · line 58
Quoted 3 lines
hw/intc/i8259.c +2
-0+int64_t irq_time[ISA_NUM_IRQS ]; +#endif };Would it make sense for these two types to have a common base class (where the stats stuff could then live)? AIUI they're both intending to provide the same interface ("pair of i8259 devices cascaded together in the way that x86 does it").
I had a go at this, however it didn't really make sense since the fields shared were minimal and the complexity of introducing another class into the hierarchy didn't seem like a win in this case.
ATB,
Mark.
PATCH 22/22 i8259_common.c: add missing 0x prefixes to "info pic" output
In reply to Mark Cave-AylandThis indicates that the specified register values are being output in hex.
--- hw/intc/i8259_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/intc/i8259_common.c +3 -2
@@ -119,8 +119,9 @@ static void i8259_common_print_info(InterruptStatsProvider *obj, GString *buf)I8259CommonState *s =I8259_COMMON (obj);i8259_common_dispatch_pre_save (s); - g_string_append_printf(buf, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d " - "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n", + g_string_append_printf(buf, + "pic%d: irr=0x%02x imr=0x%02x isr=0x%02x hprio=%d " + "irq_base=0x%02x rr_sel=%d elcr=0x%02x fnm=%d\n", s->master ? 0 : 1, s->irr, s->imr, s->isr, s->priority_add, s->irq_base, s->read_reg_select, s->elcr,
Signature · 1 line
2.43.0
Re: [PATCH 22/22] i8259_common.c: add missing 0x prefixes to "info pic" output
Quoted 8 lines · Mark Cave-Ayland
This indicates that the specified register values are being output in hex.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/intc/i8259_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
thanks
-- PMM
Quoted 45 lines · Mark Cave-Ayland
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 19).
Signed-off-by Mark Cave-Ayland <[email protected]>Mark Cave-Ayland (22):
i8259_internal.h: renamePIC_COMMONtoI8259_COMMONi8259_internal.h: renameTYPE_I8259_COMMONto i8259-commoni8259_internal.h: rename PICCommonState to I8259CommonStatei8259_internal.h: rename PICCommonClass to I8259CommonClassi8259.c: moveparent_realizefrom PICClass to I8259CommonClasskvm/i8259.c: moveparent_realizefrom KVMPICClass to I8259CommonClassi8259_common.c: use i8259/i8259_common prefix for functionsi8259.c: use i8259 prefix for functions
kvm/i8259.c: usekvm_i8259prefix for functionsi8259_common.c: convert to useDEFINE_TYPES()macroi8259.c: convert to useDEFINE_TYPES()macro
kvm/i8259.c: convert to useDEFINE_TYPES()macro
i8259.c: introduceTYPE_I8259_PICdevice
i8259.c: properly cascade secondary i8259 from primary i8259kvm/i8259.c: introduceTYPE_KVM_I8259_PICdevicexen-hvm.c: renamexen_interrupt_controller_init()toxen_i8259_init()xen/xen-hvm.c: introduceTYPE_XEN_I8259_PICdevicei8259_common.c: remove unusedi8259_init_chip()function
i8259: move InterruptStatsProviderClassget_statistics()from i8259 to
PIC
i8259.c: switchisa_picfrom I8259CommonState to I8259PICStatei8259_common.c: remove staticirq_countandirq_levelvariablesi8259_common.c: add missing 0x prefixes to "info pic" output
Quoted 10 lines
include/hw/intc/i8259.h | 12 +- include/hw/isa/i8259_internal.h | 21 ++- include/hw/xen/xen.h | 2 +- hw/i386/kvm/i8259.c | 167 +++++++++++++---- hw/i386/pc.c | 2 +- hw/i386/xen/xen-hvm.c | 40 +++- hw/intc/i8259.c | 322 +++++++++++++++++++++----------- hw/intc/i8259_common.c | 171 ++++++++--------- stubs/xen-hw-stub.c | 2 +- 9 files changed, 477 insertions(+), 262 deletions(-)
Ping?
ATB,
Mark.