hw/timer/i8254: Un-inline and simplify IRQs
cover hw/timer/i8254: Un-inline and simplify IRQs
i8254_pit_init() uses a odd pattern of "use this IRQ output line if non-NULL, otherwise use the ISA IRQ #number as output".
Rework as simply "Use this IRQ output".
Un-inline/rename/document functions.
Based-on: <[email protected]>
"hw/ide: Untangle ISA/PCI abuses of ide_init_ioport" v2
https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (5):
hw/timer/hpet: Include missing 'hw/qdev-properties.h' header hw/timer/i8254: Factor i8254_pit_create() out and document hw/i386/pc: Un-inline i8254_pit_init() hw/timer/i8254: Really inline i8254_pit_init() hw/i386/kvm: Factor i8254_pit_create_try_kvm() out
hw/i386/kvm/i8254.c | 18 ++++++++++++++ hw/i386/microvm.c | 6 +---- hw/i386/pc.c | 15 +++++------- hw/isa/i82378.c | 2 +- hw/isa/piix4.c | 4 ++-- hw/isa/vt82c686.c | 2 +- hw/mips/jazz.c | 2 +- hw/timer/hpet.c | 1 + hw/timer/i8254.c | 16 +++++++++++++ include/hw/timer/i8254.h | 48 +++++++++++++------------------------- target/i386/kvm/kvm-stub.c | 6 +++++ 11 files changed, 69 insertions(+), 51 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/5 hw/timer/hpet: Include missing 'hw/qdev-properties.h' header
Avoid when refactoring unrelated headers:
hw/timer/hpet.c:776:39: error: array has incomplete element type 'Property' (aka 'struct Property')
static Property hpet_device_properties[] = {
^ hw/timer/hpet.c:777:5: error: implicit declaration of function 'DEFINE_PROP_UINT8' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
DEFINE_PROP_UINT8("timers", HPETState, num_timers, HPET_MIN_TIMERS),
^
--- hw/timer/hpet.c | 1 + 1 file changed, 1 insertion(+)
hw/timer/hpet.c +1 -0
@@ -30,6 +30,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "hw/qdev-properties.h" #include "hw/timer/hpet.h" #include "hw/sysbus.h" #include "hw/rtc/mc146818rtc.h"
Signature · 1 line
2.38.1
Re: [PATCH 1/5] hw/timer/hpet: Include missing 'hw/qdev-properties.h' header
Quoted 19 lines · Philippe Mathieu-Daudé
Avoid when refactoring unrelated headers:
hw/timer/hpet.c:776:39: error: array has incomplete element type 'Property' (aka 'struct Property')static Property hpet_device_properties[] = { ^
hw/timer/hpet.c:777:5: error: implicit declaration of function 'DEFINE_PROP_UINT8' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
DEFINE_PROP_UINT8("timers", HPETState, num_timers, HPET_MIN_TIMERS),
^Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/timer/hpet.c | 1 + 1 file changed, 1 insertion(+)hw/timer/hpet.c +0
-0
hw/timer/hpet.c line 36
Quoted 7 lines
hw/timer/hpet.c +1
-0@@ -30,6 +30,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "hw/qdev-properties.h" #include "hw/timer/hpet.h" #include "hw/sysbus.h" #include "hw/rtc/mc146818rtc.h"
r~
PATCH 2/5 hw/timer/i8254: Factor i8254_pit_create() out and document
In reply to Philippe Mathieu-Daudé--- hw/timer/i8254.c | 16 ++++++++++++++++ include/hw/timer/i8254.h | 24 +++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-)
hw/timer/i8254.c +16 -0
@@ -26,9 +26,11 @@#include "hw/irq.h" #include "qemu/module.h" #include "qemu/timer.h" +#include "hw/qdev-properties.h" #include "hw/timer/i8254.h" #include "hw/timer/i8254_internal.h" #include "qom/object.h" +#include "qapi/error.h" //#define DEBUG_PIT
@@ -47,6 +49,20 @@ struct PITClass {DeviceRealize parent_realize; }; +ISADevice *i8254_pit_create (ISABus *bus,int iobase,qemu_irq irq_in) +{ +DeviceState *dev; +ISADevice *d; + + d =isa_new (TYPE_I8254 ); + dev =DEVICE (d); +qdev_prop_set_uint32 (dev,"iobase" , iobase); +isa_realize_and_unref (d, bus, &error_fatal); +qdev_connect_gpio_out (dev,0 , irq_in); + +return d; +} +static void pit_irq_timer_update (PITChannelState *s,int64_t current_time);static int pit_get_count (PITChannelState *s)
include/hw/timer/i8254.h +13 -11
@@ -45,21 +45,23 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON)#define TYPE_I8254 "isa-pit"#define TYPE_KVM_I8254 "kvm-pit" +/** +* Create and realize a I8254 PIT device on the heap. +* @bus: the #ISABus to put it on. +* @iobase: the base I/O port. +* @irq_in: qemu_irq to connect the PIT output IRQ to. +* +* Create the device state structure, initialize it, put it on the +* specified ISA @bus, and drop the reference to it (the device is realized). +*/ +ISADevice *i8254_pit_create (ISABus *bus,int iobase,qemu_irq irq_in); +static inline ISADevice *i8254_pit_init (ISABus *bus,int base,int isa_irq,qemu_irq alt_irq) { -DeviceState *dev; -ISADevice *d; - - d =isa_new (TYPE_I8254 ); - dev =DEVICE (d); -qdev_prop_set_uint32 (dev,"iobase" , base); -isa_realize_and_unref (d, bus, &error_fatal); -qdev_connect_gpio_out (dev,0 , - isa_irq >=0 ?isa_bus_get_irq (bus, isa_irq) +return i8254_pit_create (bus, base, isa_irq >=0 + ?isa_bus_get_irq (bus, isa_irq) : alt_irq); - -return d; }static inline ISADevice *kvm_pit_init (ISABus *bus,int base)
Signature · 1 line
2.38.1
Re: [PATCH 2/5] hw/timer/i8254: Factor i8254_pit_create() out and document
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/timer/i8254.c | 16 ++++++++++++++++ include/hw/timer/i8254.h | 24 +++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-)
r~
PATCH 3/5 hw/i386/pc: Un-inline i8254_pit_init()
In reply to Philippe Mathieu-Daudépc_basic_device_init() is the single caller of i8254_pit_init() with a non-NULL 'alt_irq' argument. Open-code i8254_pit_init() by direclty calling i8254_pit_create().
To confirm all other callers pass a NULL 'alt_irq', add an assertion in i8254_pit_init().
--- hw/i386/pc.c | 10 +++++----- include/hw/timer/i8254.h | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-)
hw/i386/pc.c +5 -5
@@ -1258,8 +1258,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, {int i;DeviceState *hpet =NULL ; -int pit_isa_irq =0 ; -qemu_irq pit_alt_irq =NULL ; +qemu_irq pit_irq;qemu_irq rtc_irq =NULL ;ISADevice *pit =NULL ;MemoryRegion *ioport80_io =g_new (MemoryRegion,1 );
@@ -1301,9 +1300,10 @@ void pc_basic_device_init(struct PCMachineState *pcms,for (i =0 ; i <GSI_NUM_PINS ; i++) {sysbus_connect_irq (SYS_BUS_DEVICE (hpet), i, gsi[i]); } - pit_isa_irq =-1 ; - pit_alt_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_PIT_INT ); + pit_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_PIT_INT ); rtc_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_RTC_INT ); + }else { + pit_irq =isa_bus_get_irq (isa_bus,0 ); } *rtc_state =mc146818_rtc_init (isa_bus,2000 , rtc_irq);
@@ -1314,7 +1314,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,if (kvm_pit_in_kernel ()) { pit =kvm_pit_init (isa_bus,0x40 ); }else { - pit =i8254_pit_init (isa_bus,0x40 , pit_isa_irq, pit_alt_irq); + pit =i8254_pit_create (isa_bus,0x40 , pit_irq); }if (hpet) {/* connect PIT to output control line of the HPET */
include/hw/timer/i8254.h +2 -3
@@ -59,9 +59,8 @@ ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in);static inline ISADevice *i8254_pit_init (ISABus *bus,int base,int isa_irq,qemu_irq alt_irq) { -return i8254_pit_create (bus, base, isa_irq >=0 - ?isa_bus_get_irq (bus, isa_irq) - : alt_irq); +assert (isa_irq ==0 && alt_irq ==NULL ); +return i8254_pit_create (bus, base,isa_bus_get_irq (bus,0 )); }static inline ISADevice *kvm_pit_init (ISABus *bus,int base)
Signature · 1 line
2.38.1
Re: [PATCH 3/5] hw/i386/pc: Un-inline i8254_pit_init()
Quoted 4 lines · Philippe Mathieu-Daudé
pc_basic_device_init()is the single caller ofi8254_pit_init()with a non-NULL 'alt_irq' argument. Open-codei8254_pit_init()by direclty callingi8254_pit_create().
Quoted 8 lines
To confirm all other callers pass a NULL '
alt_irq', add an assertion ini8254_pit_init().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/i386/pc.c | 10 +++++----- include/hw/timer/i8254.h | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-)
r~
PATCH 4/5 hw/timer/i8254: Really inline i8254_pit_init()
In reply to Philippe Mathieu-DaudéIn-line the one-line i8254_pit_create() call.
--- hw/i386/microvm.c | 2 +- hw/isa/i82378.c | 2 +- hw/isa/piix4.c | 4 ++-- hw/isa/vt82c686.c | 2 +- hw/mips/jazz.c | 2 +- include/hw/timer/i8254.h | 7 ------- 6 files changed, 6 insertions(+), 13 deletions(-)
hw/i386/microvm.c +1 -1
@@ -261,7 +261,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)if (kvm_pit_in_kernel ()) {kvm_pit_init (isa_bus,0x40 ); }else { -i8254_pit_init (isa_bus,0x40 ,0 ,NULL ); +i8254_pit_create (isa_bus,0x40 ,isa_bus_get_irq (isa_bus,0 )); } }
hw/isa/i82378.c +1 -1
@@ -99,7 +99,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)isa_bus_irqs (isabus, s->i8259);/* 1 82C54 (pit) */ - pit =i8254_pit_init (isabus,0x40 ,0 ,NULL ); + pit =i8254_pit_create (isabus,0x40 ,isa_bus_get_irq (isabus,0 ));/* speaker */ pcspk_init (isa_new (TYPE_PC_SPEAKER ), isabus, pit);
hw/isa/piix4.c +2 -2
@@ -214,8 +214,8 @@ static void piix4_realize(PCIDevice *dev, Error **errp)/* initialize ISA irqs */ isa_bus_irqs (isa_bus, s->isa); -/* initialize pit */ -i8254_pit_init (isa_bus,0x40 ,0 ,NULL ); +/* PIT */ +i8254_pit_create (isa_bus,0x40 ,isa_bus_get_irq (isa_bus,0 ));/* DMA */ i8257_dma_init (isa_bus,0 );
hw/isa/vt82c686.c +1 -1
@@ -624,7 +624,7 @@ static void via_isa_realize(PCIDevice *d, Error **errp) s->isa_irqs =i8259_init (isa_bus, *isa_irq);isa_bus_irqs (isa_bus, s->isa_irqs); -i8254_pit_init (isa_bus,0x40 ,0 ,NULL ); +i8254_pit_create (isa_bus,0x40 ,isa_bus_get_irq (isa_bus,0 ));i8257_dma_init (isa_bus,0 );/* RTC */
hw/mips/jazz.c +1 -1
@@ -251,7 +251,7 @@ static void mips_jazz_init(MachineState *machine, i8259 =i8259_init (isa_bus, env->irq[4 ]);isa_bus_irqs (isa_bus, i8259);i8257_dma_init (isa_bus,0 ); - pit =i8254_pit_init (isa_bus,0x40 ,0 ,NULL ); + pit =i8254_pit_create (isa_bus,0x40 ,isa_bus_get_irq (isa_bus,0 ));pcspk_init (isa_new (TYPE_PC_SPEAKER ), isa_bus, pit);/* Video card */
include/hw/timer/i8254.h +0 -7
@@ -56,13 +56,6 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON)*/ ISADevice *i8254_pit_create (ISABus *bus,int iobase,qemu_irq irq_in); -static inline ISADevice *i8254_pit_init (ISABus *bus,int base,int isa_irq, -qemu_irq alt_irq) -{ -assert (isa_irq ==0 && alt_irq ==NULL ); -return i8254_pit_create (bus, base,isa_bus_get_irq (bus,0 )); -} -static inline ISADevice *kvm_pit_init (ISABus *bus,int base) {DeviceState *dev;
Signature · 1 line
2.38.1
Re: [PATCH 4/5] hw/timer/i8254: Really inline i8254_pit_init()
Quoted 11 lines · Philippe Mathieu-Daudé
In-line the one-line
i8254_pit_create()call.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/i386/microvm.c | 2 +- hw/isa/i82378.c | 2 +- hw/isa/piix4.c | 4 ++-- hw/isa/vt82c686.c | 2 +- hw/mips/jazz.c | 2 +- include/hw/timer/i8254.h | 7 ------- 6 files changed, 6 i
r~
PATCH 5/5 hw/i386/kvm: Factor i8254_pit_create_try_kvm() out
In reply to Philippe Mathieu-DaudéFactor a new i8254_pit_create_try_kvm() helper out of the following patter:
if (kvm_pit_in_kernel()) {
kvm_pit_init(...);
} else }
i8254_pit_create(...);
}(adding a stub for non-KVM builds).
Since kvm_pit_init() is only used once, un-inline it and remove the now unused headers from "hw/timer/i8254.h".
--- hw/i386/kvm/i8254.c | 18 ++++++++++++++++++ hw/i386/microvm.c | 6 +----- hw/i386/pc.c | 7 ++----- include/hw/timer/i8254.h | 22 ++++++---------------- target/i386/kvm/kvm-stub.c | 6 ++++++ 5 files changed, 33 insertions(+), 26 deletions(-)
hw/i386/kvm/i8254.c +18 -0
@@ -35,6 +35,7 @@#include "hw/qdev-properties-system.h" #include "sysemu/kvm.h" #include "qom/object.h" +#include "kvm/kvm_i386.h" #define KVM_PIT_REINJECT_BIT 0
@@ -59,6 +60,23 @@ struct KVMPITClass {DeviceRealize parent_realize; }; +ISADevice *i8254_pit_create_try_kvm (ISABus *bus,int iobase,qemu_irq irq_in) +{ +DeviceState *dev; +ISADevice *d; + +if (!kvm_pit_in_kernel ()) { +return i8254_pit_create (bus, iobase, irq_in); + } + + d =isa_new (TYPE_KVM_I8254 ); + dev =DEVICE (d); +qdev_prop_set_uint32 (dev,"iobase" , iobase); +isa_realize_and_unref (d, bus, &error_fatal); + +return d; +} +static void kvm_pit_update_clock_offset (KVMPITState *s) {int64_t offset, clock_offset;
hw/i386/microvm.c +1 -5
@@ -258,11 +258,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) }if (x86ms->pit ==ON_OFF_AUTO_ON || x86ms->pit ==ON_OFF_AUTO_AUTO ) { -if (kvm_pit_in_kernel ()) { -kvm_pit_init (isa_bus,0x40 ); - }else { -i8254_pit_create (isa_bus,0x40 ,isa_bus_get_irq (isa_bus,0 )); - } +i8254_pit_create_try_kvm (isa_bus,0x40 ,isa_bus_get_irq (isa_bus,0 )); } if (mms->rtc == ON_OFF_AUTO_ON ||
hw/i386/pc.c +2 -5
@@ -1311,11 +1311,8 @@ void pc_basic_device_init(struct PCMachineState *pcms,if (!xen_enabled () && (x86ms->pit ==ON_OFF_AUTO_AUTO || x86ms->pit ==ON_OFF_AUTO_ON )) { -if (kvm_pit_in_kernel ()) { - pit =kvm_pit_init (isa_bus,0x40 ); - }else { - pit =i8254_pit_create (isa_bus,0x40 , pit_irq); - } + pit =i8254_pit_create_try_kvm (isa_bus,0x40 , pit_irq); +if (hpet) {/* connect PIT to output control line of the HPET */ qdev_connect_gpio_out (hpet,0 ,qdev_get_gpio_in (DEVICE (pit),0 ));
include/hw/timer/i8254.h +6 -16
@@ -25,9 +25,6 @@#ifndef HW_I8254_H #define HW_I8254_H -#include "hw/qdev-properties.h" -#include "hw/isa/isa.h" -#include "qapi/error.h" #include "qom/object.h" #define PIT_FREQ 1193182
@@ -55,19 +52,12 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON)* specified ISA @bus, and drop the reference to it (the device is realized). */ ISADevice *i8254_pit_create (ISABus *bus,int iobase,qemu_irq irq_in); - -static inline ISADevice *kvm_pit_init (ISABus *bus,int base) -{ -DeviceState *dev; -ISADevice *d; - - d =isa_new (TYPE_KVM_I8254 ); - dev =DEVICE (d); -qdev_prop_set_uint32 (dev,"iobase" , base); -isa_realize_and_unref (d, bus, &error_fatal); - -return d; -} +/** +* Try to create and realize a in-kernel I8254 PIT device on the heap. +* If KVM is not available or doesn't have in-kernel PIT support, a +* emulated PIT is used. See i8254_pit_create. +*/ +ISADevice *i8254_pit_create_try_kvm (ISABus *bus,int iobase,qemu_irq irq_in);void pit_set_gate (ISADevice *dev,int channel,int val);void pit_get_channel_info (ISADevice *dev,int channel,PITChannelInfo *info);
target/i386/kvm/kvm-stub.c +6 -0
@@ -10,6 +10,7 @@* */ #include "qemu/osdep.h" +#include "hw/timer/i8254.h" #include "cpu.h" #include "kvm_i386.h"
@@ -49,3 +50,8 @@ void kvm_set_max_apic_id(uint32_t max_apic_id) {return ; } + +ISADevice *i8254_pit_create_try_kvm (ISABus *bus,int iobase,qemu_irq irq_in) +{ +return i8254_pit_create (bus, iobase, irq_in); +}
Signature · 1 line
2.38.1
Re: [PATCH 5/5] hw/i386/kvm: Factor i8254_pit_create_try_kvm() out
Quoted 2 lines · Philippe Mathieu-Daudé
Factor a new
i8254_pit_create_try_kvm()helper out of the following patter:
pattern
Quoted 12 lines
if (kvm_pit_in_kernel()) { kvm_pit_init(...); } else } i8254_pit_create(...); }(adding a stub for non-KVM builds).
Since
kvm_pit_init()is only used once, un-inline it and remove the now unused headers from "hw/timer/i8254.h".
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/i386/kvm/i8254.c | 18 ++++++++++++++++++ hw/i386/microvm.c | 6 +----- hw/i386/pc.c | 7 ++----- include/hw/timer/i8254.h | 22 ++++++---------------- target/i386/kvm/kvm-stub.c | 6 ++++++ 5 files changed, 33 insertions(+), 26 deletions(-)
r~
Quoted 4 lines · Philippe Mathieu-Daudé
i8254_pit_init()uses a odd pattern of "use this IRQ output line if non-NULL, otherwise use the ISA IRQ #number as output".Rework as simply "Use this IRQ output".
Given it also affects KVM I will let Paolo merge this.
Quoted 28 lines
Un-inline/rename/document functions.
Based-on: <[email protected]>
"hw/ide: Untangle ISA/PCI abuses ofide_init_ioport" v2
https://lore.kernel.org/qemu-devel/[email protected]/Philippe Mathieu-Daudé (5):
hw/timer/hpet: Include missing 'hw/qdev-properties.h' header hw/timer/i8254: Factori8254_pit_create()out and document hw/i386/pc: Un-inlinei8254_pit_init()hw/timer/i8254: Really inlinei8254_pit_init()hw/i386/kvm: Factori8254_pit_create_try_kvm()outhw/i386/kvm/i8254.c | 18 ++++++++++++++ hw/i386/microvm.c | 6 +---- hw/i386/pc.c | 15 +++++------- hw/isa/i82378.c | 2 +- hw/isa/piix4.c | 4 ++-- hw/isa/vt82c686.c | 2 +- hw/mips/jazz.c | 2 +- hw/timer/hpet.c | 1 + hw/timer/i8254.c | 16 +++++++++++++ include/hw/timer/i8254.h | 48 +++++++++++++------------------------- target/i386/kvm/kvm-stub.c | 6 +++++ 11 files changed, 69 insertions(+), 51 deletions(-)Signature · 1 line
2.38.1