[6081] Add HPET emulation to qemu (Beth Kon)
Revision: 6081
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6081 Author: aliguori Date: 2008-12-17 23:28:44 +0000 (Wed, 17 Dec 2008)
Log Message:
-----------
Add HPET emulation to qemu (Beth Kon)
This patch adds HPET emulation. It can be disabled with -disable-hpet. An hpet provides a more finely granular clocksource than otherwise available on PC. This means that latency-dependent applications (e.g. multimedia) will generally be smoother when using the HPET.
Modified Paths:
--------------
trunk/Makefile.target
trunk/hw/apic.c
trunk/hw/i8254.c
trunk/hw/mc146818rtc.c
trunk/hw/pc.c
trunk/hw/pc.h
trunk/monitor.c
trunk/pc-bios/bios-pq/series
trunk/pc-bios/bios.bin
trunk/vl.cAdded Paths:
-----------
trunk/hw/hpet.c
trunk/hw/hpet_emul.h
trunk/pc-bios/bios-pq/0005_hpet.patchModified: trunk/Makefile.target
===================================================================
Makefile.target +1 -1
@@ -635,7 +635,7 @@ OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o -OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o +OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o # virtio support OBJS+= virtio.o virtio-blk.o virtio-balloon.o virtio-net.o CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
Modified: trunk/hw/apic.c
===================================================================
hw/apic.c +7 -0
@@ -945,6 +945,13 @@ {IOAPICState *s = opaque; +/* ISA IRQs map to GSI 1-1 except for IRQ0 which maps +* to GSI 2. GSI maps to ioapic 1-1. This is not +* the cleanest way of doing it but it should work. */ + +if (vector ==0 ) + vector =2 ; +if (vector >=0 && vector <IOAPIC_NUM_PINS ) {uint32_t mask =1 << vector;uint64_t entry = s->ioredtbl[vector];
Added: trunk/hw/hpet.c
===================================================================
hw/hpet.c +588 -0
588 lines not on this page · raw message
Added: trunk/hw/hpet_emul.h
===================================================================
hw/hpet_emul.h +85 -0
85 lines not on this page · raw message
Modified: trunk/hw/i8254.c
===================================================================
hw/i8254.c +21 -0
@@ -463,6 +463,27 @@ } } +/* When HPET is operating in legacy mode, i8254 timer0 is disabled */ +void hpet_pit_disable (void ) { +PITChannelState *s; + s = &pit_state.channels[0 ]; +qemu_del_timer (s->irq_timer); +} + +/* When HPET is reset or leaving legacy mode, it must reenable i8254 +* timer 0 +*/ + +void hpet_pit_enable (void ) +{ +PITState *pit = &pit_state; +PITChannelState *s; + s = &pit->channels[0 ]; + s->mode =3 ; + s->gate =1 ; +pit_load_count (s,0 ); +} +PITState *pit_init (int base,qemu_irq irq) {PITState *pit = &pit_state;
Modified: trunk/hw/mc146818rtc.c
===================================================================
hw/mc146818rtc.c +24 -5
@@ -26,6 +26,7 @@#include "sysemu.h" #include "pc.h" #include "isa.h" +#include "hpet_emul.h" //#define DEBUG_CMOS
@@ -69,6 +70,18 @@QEMUTimer *second_timer2; }; +static void rtc_irq_raise (qemu_irq irq) { +/* When HPET is operating in legacy mode, RTC interrupts are disabled +* We block qemu_irq_raise, but not qemu_irq_lower, in case legacy +* mode is established while interrupt is raised. We want it to +* be lowered in any case +*/ +#if definedTARGET_I386 || definedTARGET_X86_64 + if (!hpet_in_legacy_mode()) +#endif +qemu_irq_raise (irq); +} +static void rtc_set_time (RTCState *s);static void rtc_copy_date (RTCState *s);
@@ -78,8 +91,14 @@int64_t cur_clock, next_irq_clock; period_code = s->cmos_data[RTC_REG_A ] &0x0f ; -if (period_code !=0 && - (s->cmos_data[RTC_REG_B ] ®_B_PIE )) { +#if definedTARGET_I386 || definedTARGET_X86_64 +/* disable periodic timer if hpet is in legacy mode, since interrupts are +* disabled anyway. +*/ +if (period_code !=0 && (s->cmos_data[RTC_REG_B ] ®_B_PIE ) && !hpet_in_legacy_mode ()) { +#else +if (period_code !=0 && (s->cmos_data[RTC_REG_B ] ®_B_PIE )) { +#endif if (period_code <=2 ) period_code +=7 ;/* period in 32 Khz cycles */
@@ -100,7 +119,7 @@rtc_timer_update (s, s->next_periodic_time); s->cmos_data[RTC_REG_C ] |=0xc0 ; -qemu_irq_raise (s->irq); +rtc_irq_raise (s->irq); }static void cmos_ioport_write (void *opaque,uint32_t addr,uint32_t data)
@@ -319,14 +338,14 @@ s->cmos_data[RTC_HOURS_ALARM] == s->current_tm.tm_hour)) { s->cmos_data[RTC_REG_C ] |=0xa0 ; -qemu_irq_raise (s->irq); +rtc_irq_raise (s->irq); } }/* update ended interrupt */ if (s->cmos_data[RTC_REG_B ] ®_B_UIE ) { s->cmos_data[RTC_REG_C ] |=0x90 ; -qemu_irq_raise (s->irq); +rtc_irq_raise (s->irq); }/* clear update in progress bit */
Modified: trunk/hw/pc.c
===================================================================
hw/pc.c +4 -0
@@ -35,6 +35,7 @@#include "fw_cfg.h" #include "virtio-blk.h" #include "virtio-balloon.h" +#include "hpet_emul.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS
@@ -977,6 +978,9 @@ } pit =pit_init (0x40 , i8259[0 ]);pcspk_init (pit); +if (!no_hpet) { +hpet_init (i8259); + }if (pci_enabled) {pic_set_alt_irq_func (isa_pic, ioapic_set_irq, ioapic); }
Modified: trunk/hw/pc.h
===================================================================
hw/pc.h +3 -0
@@ -97,6 +97,9 @@void piix4_smbus_register_device (SMBusDevice *dev,uint8_t addr);void acpi_bios_init (void ); +/* hpet.c */ +extern int no_hpet; +/* pcspk.c */ void pcspk_init (PITState *);int pcspk_audio_init (AudioState *,qemu_irq *pic);
Modified: trunk/monitor.c
===================================================================
monitor.c +7 -0
@@ -252,6 +252,11 @@term_printf ("%s\n" , qemu_name); } +static void do_info_hpet (void ) +{ +term_printf ("HPET is %s by QEMU\n" , (no_hpet) ?"disabled" :"enabled" ); +} +static void do_info_uuid (void ) { term_printf(UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], qemu_uuid[2],
@@ -1531,6 +1536,8 @@ "", "show virtual to physical memory mappings", }, { "mem", "", mem_info, "", "show the active virtual memory mappings", }, + { "hpet", "", do_info_hpet, + "", "show state of HPET", }, #endif { "jit", "", do_info_jit, "", "show dynamic compiler info", },
Added: trunk/pc-bios/bios-pq/0005_hpet.patch
===================================================================
pc-bios/bios-pq/0005_hpet.patch +190 -0
190 lines not on this page · raw message
Modified: trunk/pc-bios/bios-pq/series
===================================================================
pc-bios/bios-pq/series +1 -0
@@ -2,3 +2,4 @@ 0002_e820-high-mem.patch 0003_smp-startup-poll.patch 0004_no-stack-protector.patch +0005_hpet.patch
Modified: trunk/pc-bios/bios.bin
===================================================================
(Binary files differ)
Modified: trunk/vl.c
===================================================================
vl.c +7 -0
@@ -224,6 +224,7 @@int smp_cpus =1 ;const char *vnc_display;int acpi_enabled =1 ; +int no_hpet =0 ;int fd_bootchk =1 ;int no_reboot =0 ;int no_shutdown =0 ;
@@ -3956,6 +3957,7 @@#endif #ifdef TARGET_I386 "-no-acpi disable ACPI\n" + "-no-hpet disable HPET\n"#endif #ifdef CONFIG_CURSES "-curses use a curses/ncurses interface instead of SDL\n"
@@ -4067,6 +4069,7 @@ QEMU_OPTION_smp, QEMU_OPTION_vnc, QEMU_OPTION_no_acpi, + QEMU_OPTION_no_hpet, QEMU_OPTION_curses, QEMU_OPTION_no_reboot, QEMU_OPTION_no_shutdown,
@@ -4180,6 +4183,7 @@/* temporary options */ { "usb", 0, QEMU_OPTION_usb }, { "no-acpi", 0, QEMU_OPTION_no_acpi }, + { "no-hpet", 0, QEMU_OPTION_no_hpet }, { "no-reboot", 0, QEMU_OPTION_no_reboot }, { "no-shutdown", 0, QEMU_OPTION_no_shutdown }, { "show-cursor", 0, QEMU_OPTION_show_cursor },
@@ -5017,6 +5021,9 @@case QEMU_OPTION_no_acpi: acpi_enabled =0 ;break ; +case QEMU_OPTION_no_hpet: + no_hpet =1 ; +break ;case QEMU_OPTION_no_reboot: no_reboot =1 ;break ;
There was a previous attempt to do an hpet emulation. It was in the patches that were used to make Mac OS X run under Qemu. File attached
Quoted 38 lines · Anthony Liguori
Revision: 6081
http://svn.sv.gnu.org/viewvc/? view=rev&root=qemu&revision=6081 Author: aliguori Date: 2008-12-17 23:28:44 +0000 (Wed, 17 Dec 2008)Log Message:
-----------
Add HPET emulation to qemu (Beth Kon)This patch adds HPET emulation. It can be disabled with -disable-hpet. An hpet provides a more finely granular clocksource than otherwise available on PC. This means that latency-dependent applications (e.g. multimedia) will generally be smoother when using the HPET.
Signed-off-by Beth Kon <[email protected]>Signed-off-by Anthony Liguori <[email protected]>Modified Paths:
--------------
trunk/Makefile.target
trunk/hw/apic.c
trunk/hw/i8254.c
trunk/hw/mc146818rtc.c
trunk/hw/pc.c
trunk/hw/pc.h
trunk/monitor.c
trunk/pc-bios/bios-pq/series
trunk/pc-bios/bios.bin
trunk/vl.cAdded Paths:
-----------
trunk/hw/hpet.c
trunk/hw/hpet_emul.h
trunk/pc-bios/bios-pq/0005_hpet.patch
Quoted 1 line · C.W.Betts
There was a previous attempt to do an hpet emulation. It was in the patches that were used to make Mac OS X run under Qemu. File attached
No need to mention me in the commit message - my name is already in hpet.c. And as long as this is a step towards upstream Mac OS X support, I'm glad about any progress!
Plus, I didn't get to review your patch as much as I'd liked, so it's only fair ;-)
Alex
Sorry for the confusion. I only noticed that the hpet.c file that I had was conflicting with a file that the svn server wanted to put on the file. I didn't notice that your name was included.
The attached file was your hpet attempt from the Mac patches.
Quoted 10 lines · Alexander Graf
Quoted 1 line · C.W.Betts
There was a previous attempt to do an hpet emulation. It was in the patches that were used to make Mac OS X run under Qemu. File attached
No need to mention me in the commit message - my name is already in
hpet.c. And as long as this is a step towards upstream Mac OS X support, I'm glad about any progress!Plus, I didn't get to review your patch as much as I'd liked, so it's only fair ;-)
Alex
Quoted 1 line · C.W. Betts
Sorry for the confusion. I only noticed that the
hpet.cfile that I had was conflicting with a file that the svn server wanted to put on the file. I didn't notice that your name was included.
Yeah, Beth improved my HPET emulation quite well and made it work for Windows and Linux.
Quoted 1 line
The attached file was your hpet attempt from the Mac patches.
Thanks for keeping track! :-)
Quoted 1 line
Quoted 1 line
Plus, I didn't get to review your patch as much as I'd liked, so it's only fair ;-)
s/your/Beth's/
It's way too early not to be confused - phew.
Alex