pc: Implement -no-hpet as sugar for -machine hpet=on
PATCH v3 1/1 pc: Implement -no-hpet as sugar for -machine hpet=on
Get rid of yet another global variable.
The default will be hpet=on only if CONFIG_HPET=y.
---
Changes v2 -> v3:
* Revert v2 changes (use "hpet" property), plus:
* Default to hpet=off if CONFIG_HPET=n
* Error out if creation of HPET device fails and hpet=on
Changes v1 -> v2:
* Rename property to "allow-hpet" to make its semantic clearer, as it won't make sure HPET is created if CONFIG_HPET=n
* Use qdev_new(TYPE_HPET) at pc_basic_device_init()
--- include/hw/i386/pc.h | 1 + include/hw/i386/x86.h | 3 --- hw/i386/pc.c | 61 +++++++++++++++++++++++++++++-------------- hw/i386/pc_piix.c | 2 +- softmmu/vl.c | 4 +-- 5 files changed, 46 insertions(+), 25 deletions(-)
include/hw/i386/pc.h +1 -0
@@ -43,6 +43,7 @@ typedef struct PCMachineState {bool smbus_enabled;bool sata_enabled;bool pit_enabled; +bool hpet_enabled;/* NUMA information: */ uint64_t numa_nodes;
include/hw/i386/x86.h +0 -3
@@ -124,7 +124,4 @@ qemu_irq x86_allocate_cpu_irq(void);void gsi_handler (void *opaque,int n,int level);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name); -/* hpet.c */ -extern int no_hpet; -#endif
hw/i386/pc.c +42 -19
88 lines not on this page · raw message
hw/i386/pc_piix.c +1 -1
@@ -216,7 +216,7 @@ static void pc_init1(MachineState *machine, i440fx_state =NULL ; isa_bus =isa_bus_new (NULL ,get_system_memory (), system_io, &error_abort); - no_hpet =1 ; + pcms->hpet_enabled = false; }isa_bus_irqs (isa_bus, x86ms->gsi);
softmmu/vl.c +2 -2
@@ -146,7 +146,6 @@ static Chardev **serial_hds;Chardev *parallel_hds[MAX_PARALLEL_PORTS ];int win2k_install_hack =0 ;int singlestep =0 ; -int no_hpet =0 ;int fd_bootchk =1 ;static int no_reboot;int no_shutdown =0 ;
@@ -3562,7 +3561,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opts_parse_noisily (olist,"acpi=off" , false);break ;case QEMU_OPTION_no_hpet: - no_hpet =1 ; + olist =qemu_find_opts ("machine" ); +qemu_opts_parse_noisily (olist,"hpet=off" , false);break ;case QEMU_OPTION_no_reboot: no_reboot =1 ;
Signature · 1 line
2.28.0
Quoted 170 lines · Eduardo Habkost
Get rid of yet another global variable.
The default will be hpet=on only if
CONFIG_HPET=y.Signed-off-by Eduardo Habkost <[email protected]>---
Changes v2 -> v3:
* Revert v2 changes (use "hpet" property), plus:
* Default to hpet=off ifCONFIG_HPET=n
* Error out if creation of HPET device fails and hpet=onChanges v1 -> v2:
* Rename property to "allow-hpet" to make its semantic clearer, as it won't make sure HPET is created ifCONFIG_HPET=n
* Useqdev_new(TYPE_HPET)atpc_basic_device_init()--- include/hw/i386/pc.h | 1 + include/hw/i386/x86.h | 3 --- hw/i386/pc.c | 61 +++++++++++++++++++++++++++++-------------- hw/i386/pc_piix.c | 2 +- softmmu/vl.c | 4 +-- 5 files changed, 46 insertions(+), 25 deletions(-)include/hw/i386/pc.h +1
-0@@ -43,6 +43,7 @@ typedef struct PCMachineState {bool smbus_enabled;bool sata_enabled;bool pit_enabled; +bool hpet_enabled;/* NUMA information: */ uint64_t numa_nodes;include/hw/i386/x86.h +0
-3@@ -124,7 +124,4 @@ qemu_irq x86_allocate_cpu_irq(void);void gsi_handler (void *opaque,int n,int level);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name); -/* hpet.c */ -extern int no_hpet; -#endif hw/i386/pc.c +42
-19@@ -1142,28 +1142,31 @@ void pc_basic_device_init(struct PCMachineState *pcms,* Without KVM_CAP_PIT_STATE2, we cannot switch off the in-kernel PIT * when the HPET wants to take over. Thus we have to disable the latter. */ -if (!no_hpet && (!kvm_irqchip_in_kernel () ||kvm_has_pit_state2 ())) { +if (pcms->hpet_enabled && (!kvm_irqchip_in_kernel () || +kvm_has_pit_state2 ())) { hpet =qdev_try_new (TYPE_HPET ); -if (hpet) { -/* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 -* and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, -* IRQ8 and IRQ2. -*/ -uint8_t compat =object_property_get_uint (OBJECT (hpet), -HPET_INTCAP ,NULL ); -if (!compat) { -qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); - } -sysbus_realize_and_unref (SYS_BUS_DEVICE (hpet), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (hpet),0 ,HPET_BASE ); +if (!hpet) { +error_report ("couldn't create HPET device" ); +exit (1 ); + } +/* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 +* and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, +* IRQ8 and IRQ2. +*/ +uint8_t compat =object_property_get_uint (OBJECT (hpet), +HPET_INTCAP ,NULL ); +if (!compat) { +qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); + } +sysbus_realize_and_unref (SYS_BUS_DEVICE (hpet), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (hpet),0 ,HPET_BASE ); -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 ); - rtc_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_RTC_INT ); +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 ); + rtc_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_RTC_INT ); } *rtc_state =mc146818_rtc_init (isa_bus,2000 , rtc_irq);@@ -1535,6 +1538,20 @@ static void pc_machine_set_pit(Object *obj, bool value, Error **errp) pcms->pit_enabled = value; } +static bool pc_machine_get_hpet (Object *obj,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); + +return pcms->hpet_enabled; +} + +static void pc_machine_set_hpet (Object *obj,bool value,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); + + pcms->hpet_enabled = value; +} +static void pc_machine_get_max_ram_below_4g (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)@@ -1585,6 +1602,9 @@ static void pc_machine_initfn(Object *obj) pcms->smbus_enabled = true; pcms->sata_enabled = true; pcms->pit_enabled = true; +#ifdef CONFIG_HPET + pcms->hpet_enabled = true; +#endif pc_system_flash_create (pcms); pcms->pcspk =isa_new (TYPE_PC_SPEAKER );@@ -1705,6 +1725,9 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)object_class_property_add_bool (oc,PC_MACHINE_PIT , pc_machine_get_pit, pc_machine_set_pit); + +object_class_property_add_bool (oc,"hpet" , + pc_machine_get_hpet, pc_machine_set_hpet); }static const TypeInfo pc_machine_info = {hw/i386/pc_piix.c +1
-1@@ -216,7 +216,7 @@ static void pc_init1(MachineState *machine, i440fx_state =NULL ; isa_bus =isa_bus_new (NULL ,get_system_memory (), system_io, &error_abort); - no_hpet =1 ; + pcms->hpet_enabled = false; }isa_bus_irqs (isa_bus, x86ms->gsi);softmmu/vl.c +0
-1@@ -146,7 +146,6 @@ static Chardev **serial_hds;Chardev *parallel_hds[MAX_PARALLEL_PORTS ];int win2k_install_hack =0 ;int singlestep =0 ; -int no_hpet =0 ;int fd_bootchk =1 ;static int no_reboot;int no_shutdown =0 ;
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3568
Quoted 9 lines
softmmu/vl.c +2
-1@@ -3562,7 +3561,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opts_parse_noisily (olist,"acpi=off" , false);break ;case QEMU_OPTION_no_hpet: - no_hpet =1 ; + olist =qemu_find_opts ("machine" ); +qemu_opts_parse_noisily (olist,"hpet=off" , false);break ;case QEMU_OPTION_no_reboot: no_reboot =1 ;
Thanks!
Paolo
Michael S. Tsirkin
Reviewed-byQuoted 183 lines · Paolo Bonzini
Quoted 170 lines · Eduardo Habkost
Get rid of yet another global variable.
The default will be hpet=on only if
CONFIG_HPET=y.Signed-off-by Eduardo Habkost <[email protected]>---
Changes v2 -> v3:
* Revert v2 changes (use "hpet" property), plus:
* Default to hpet=off ifCONFIG_HPET=n
* Error out if creation of HPET device fails and hpet=onChanges v1 -> v2:
* Rename property to "allow-hpet" to make its semantic clearer, as it won't make sure HPET is created ifCONFIG_HPET=n
* Useqdev_new(TYPE_HPET)atpc_basic_device_init()--- include/hw/i386/pc.h | 1 + include/hw/i386/x86.h | 3 --- hw/i386/pc.c | 61 +++++++++++++++++++++++++++++-------------- hw/i386/pc_piix.c | 2 +- softmmu/vl.c | 4 +-- 5 files changed, 46 insertions(+), 25 deletions(-)include/hw/i386/pc.h +1
-0@@ -43,6 +43,7 @@ typedef struct PCMachineState {bool smbus_enabled;bool sata_enabled;bool pit_enabled; +bool hpet_enabled;/* NUMA information: */ uint64_t numa_nodes;include/hw/i386/x86.h +0
-3@@ -124,7 +124,4 @@ qemu_irq x86_allocate_cpu_irq(void);void gsi_handler (void *opaque,int n,int level);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name); -/* hpet.c */ -extern int no_hpet; -#endif hw/i386/pc.c +42
-19@@ -1142,28 +1142,31 @@ void pc_basic_device_init(struct PCMachineState *pcms,* Without KVM_CAP_PIT_STATE2, we cannot switch off the in-kernel PIT * when the HPET wants to take over. Thus we have to disable the latter. */ -if (!no_hpet && (!kvm_irqchip_in_kernel () ||kvm_has_pit_state2 ())) { +if (pcms->hpet_enabled && (!kvm_irqchip_in_kernel () || +kvm_has_pit_state2 ())) { hpet =qdev_try_new (TYPE_HPET ); -if (hpet) { -/* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 -* and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, -* IRQ8 and IRQ2. -*/ -uint8_t compat =object_property_get_uint (OBJECT (hpet), -HPET_INTCAP ,NULL ); -if (!compat) { -qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); - } -sysbus_realize_and_unref (SYS_BUS_DEVICE (hpet), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (hpet),0 ,HPET_BASE ); +if (!hpet) { +error_report ("couldn't create HPET device" ); +exit (1 ); + } +/* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 +* and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, +* IRQ8 and IRQ2. +*/ +uint8_t compat =object_property_get_uint (OBJECT (hpet), +HPET_INTCAP ,NULL ); +if (!compat) { +qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); + } +sysbus_realize_and_unref (SYS_BUS_DEVICE (hpet), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (hpet),0 ,HPET_BASE ); -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 ); - rtc_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_RTC_INT ); +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 ); + rtc_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_RTC_INT ); } *rtc_state =mc146818_rtc_init (isa_bus,2000 , rtc_irq);@@ -1535,6 +1538,20 @@ static void pc_machine_set_pit(Object *obj, bool value, Error **errp) pcms->pit_enabled = value; } +static bool pc_machine_get_hpet (Object *obj,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); + +return pcms->hpet_enabled; +} + +static void pc_machine_set_hpet (Object *obj,bool value,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); + + pcms->hpet_enabled = value; +} +static void pc_machine_get_max_ram_below_4g (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)@@ -1585,6 +1602,9 @@ static void pc_machine_initfn(Object *obj) pcms->smbus_enabled = true; pcms->sata_enabled = true; pcms->pit_enabled = true; +#ifdef CONFIG_HPET + pcms->hpet_enabled = true; +#endif pc_system_flash_create (pcms); pcms->pcspk =isa_new (TYPE_PC_SPEAKER );@@ -1705,6 +1725,9 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)object_class_property_add_bool (oc,PC_MACHINE_PIT , pc_machine_get_pit, pc_machine_set_pit); + +object_class_property_add_bool (oc,"hpet" , + pc_machine_get_hpet, pc_machine_set_hpet); }static const TypeInfo pc_machine_info = {hw/i386/pc_piix.c +1
-1@@ -216,7 +216,7 @@ static void pc_init1(MachineState *machine, i440fx_state =NULL ; isa_bus =isa_bus_new (NULL ,get_system_memory (), system_io, &error_abort); - no_hpet =1 ; + pcms->hpet_enabled = false; }isa_bus_irqs (isa_bus, x86ms->gsi);softmmu/vl.c +0
-1@@ -146,7 +146,6 @@ static Chardev **serial_hds;Chardev *parallel_hds[MAX_PARALLEL_PORTS ];int win2k_install_hack =0 ;int singlestep =0 ; -int no_hpet =0 ;int fd_bootchk =1 ;static int no_reboot;int no_shutdown =0 ;softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3568
Quoted 9 lines
softmmu/vl.c +2
-1@@ -3562,7 +3561,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opts_parse_noisily (olist,"acpi=off" , false);break ;case QEMU_OPTION_no_hpet: - no_hpet =1 ; + olist =qemu_find_opts ("machine" ); +qemu_opts_parse_noisily (olist,"hpet=off" , false);break ;case QEMU_OPTION_no_reboot: no_reboot =1 ;Acked-by Paolo Bonzini <[email protected]>
Quoted 3 lines
Thanks!
Paolo
I will queue this, thanks!