From 1211bd9ac2d4fe67294a2526bfbd0a7bf5d8d97a Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Mon, 31 Mar 2008 14:33:12 -0500 Subject: [PATCH] Move in-kernel PIT device to separate file This patch is mostly code motion to move the newly refactored in-kernel PIT device to a separate file. Signed-off-by: Anthony Liguori Signed-off-by: Avi Kivity --- Makefile.target | 3 ++ configure | 20 ++++++++++ hw/i8254-kvm.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i8254.c | 121 ++------------------------------------------------------ hw/i8254.h | 66 +++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 117 deletions(-) create mode 100644 hw/i8254-kvm.c create mode 100644 hw/i8254.h diff --git a/Makefile.target b/Makefile.target index f282fa3b7b..2fc2988e72 100644 --- a/Makefile.target +++ b/Makefile.target @@ -592,6 +592,9 @@ 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 extboot.o +ifeq ($(USE_KVM_PIT), 1) +OBJS+= i8254-kvm.o +endif CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE endif ifeq ($(TARGET_BASE_ARCH), ia64) diff --git a/configure b/configure index a13a11b14e..ca9bce20f4 100755 --- a/configure +++ b/configure @@ -100,6 +100,7 @@ bsd="no" linux="no" kqemu="no" kvm="no" +kvm_cap_pit="no" profiler="no" kernel_path="" cocoa="no" @@ -616,6 +617,22 @@ int main(void) { EOF ########################################## +# KVM probe + +if test "$kvm" = "yes" ; then +cat > $TMPC < +#ifndef KVM_CAP_PIT +#error "kvm no pit capability" +#endif +int main(void) { return 0; } +EOF + if $cc $ARCH_CFLAGS $CFLAGS -I"$kernel_path"/include -o $TMPE ${OS_CFLAGS} $TMPC 2> /dev/null ; then + kvm_cap_pit="yes" + fi +fi + +########################################## # SDL probe sdl_too_old=no @@ -1168,6 +1185,9 @@ configure_kvm() { echo "#define USE_KVM 1" >> $config_h echo "USE_KVM=1" >> $config_mak echo "CONFIG_KVM_KERNEL_INC=$kernel_path/include" >> $config_mak + if test $kvm_cap_pit = "yes" ; then + echo "USE_KVM_PIT=1" >> $config_mak + fi disable_cpu_emulation fi } diff --git a/hw/i8254-kvm.c b/hw/i8254-kvm.c new file mode 100644 index 0000000000..127b347361 --- /dev/null +++ b/hw/i8254-kvm.c @@ -0,0 +1,108 @@ +/* + * QEMU 8253/8254 interval timer emulation + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "hw.h" +#include "pc.h" +#include "isa.h" +#include "qemu-timer.h" +#include "i8254.h" +#include "qemu-kvm.h" + +static PITState pit_state; + +static void kvm_pit_save(QEMUFile *f, void *opaque) +{ + PITState *s = opaque; + struct kvm_pit_state pit; + struct kvm_pit_channel_state *c; + struct PITChannelState *sc; + int i; + + kvm_get_pit(kvm_context, &pit); + + for (i = 0; i < 3; i++) { + c = &pit.channels[i]; + sc = &s->channels[i]; + sc->count = c->count; + sc->latched_count = c->latched_count; + sc->count_latched = c->count_latched; + sc->status_latched = c->status_latched; + sc->status = c->status; + sc->read_state = c->read_state; + sc->write_state = c->write_state; + sc->write_latch = c->write_latch; + sc->rw_mode = c->rw_mode; + sc->mode = c->mode; + sc->bcd = c->bcd; + sc->gate = c->gate; + sc->count_load_time = c->count_load_time; + } + + pit_save(f, s); +} + +static int kvm_pit_load(QEMUFile *f, void *opaque, int version_id) +{ + PITState *s = opaque; + struct kvm_pit_state pit; + struct kvm_pit_channel_state *c; + struct PITChannelState *sc; + int i; + + pit_load(f, s, version_id); + + for (i = 0; i < 3; i++) { + c = &pit.channels[i]; + sc = &s->channels[i]; + c->count = sc->count; + c->latched_count = sc->latched_count; + c->count_latched = sc->count_latched; + c->status_latched = sc->status_latched; + c->status = sc->status; + c->read_state = sc->read_state; + c->write_state = sc->write_state; + c->write_latch = sc->write_latch; + c->rw_mode = sc->rw_mode; + c->mode = sc->mode; + c->bcd = sc->bcd; + c->gate = sc->gate; + c->count_load_time = sc->count_load_time; + } + + kvm_set_pit(kvm_context, &pit); + + return 0; +} + +PITState *kvm_pit_init(int base, qemu_irq irq) +{ + PITState *pit = &pit_state; + + register_savevm(PIT_SAVEVM_NAME, base, PIT_SAVEVM_VERSION, + kvm_pit_save, kvm_pit_load, pit); + + qemu_register_reset(pit_reset, pit); + pit_reset(pit); + + return pit; +} diff --git a/hw/i8254.c b/hw/i8254.c index bcd9dba842..69eb889c1e 100644 --- a/hw/i8254.c +++ b/hw/i8254.c @@ -25,43 +25,10 @@ #include "pc.h" #include "isa.h" #include "qemu-timer.h" - -#include "qemu-kvm.h" +#include "i8254.h" //#define DEBUG_PIT -#define PIT_SAVEVM_NAME "i8254" -#define PIT_SAVEVM_VERSION 1 - -#define RW_STATE_LSB 1 -#define RW_STATE_MSB 2 -#define RW_STATE_WORD0 3 -#define RW_STATE_WORD1 4 - -typedef struct PITChannelState { - int count; /* can be 65536 */ - uint16_t latched_count; - uint8_t count_latched; - uint8_t status_latched; - uint8_t status; - uint8_t read_state; - uint8_t write_state; - uint8_t write_latch; - uint8_t rw_mode; - uint8_t mode; - uint8_t bcd; /* not supported */ - uint8_t gate; /* timer start */ - int64_t count_load_time; - /* irq handling */ - int64_t next_transition_time; - QEMUTimer *irq_timer; - qemu_irq irq; -} PITChannelState; - -struct PITState { - PITChannelState channels[3]; -}; - static PITState pit_state; static void pit_irq_timer_update(PITChannelState *s, int64_t current_time); @@ -417,7 +384,7 @@ static void pit_irq_timer(void *opaque) pit_irq_timer_update(s, s->next_transition_time); } -static void pit_save(QEMUFile *f, void *opaque) +void pit_save(QEMUFile *f, void *opaque) { PITState *pit = opaque; PITChannelState *s; @@ -445,7 +412,7 @@ static void pit_save(QEMUFile *f, void *opaque) } } -static int pit_load(QEMUFile *f, void *opaque, int version_id) +int pit_load(QEMUFile *f, void *opaque, int version_id) { PITState *pit = opaque; PITChannelState *s; @@ -478,7 +445,7 @@ static int pit_load(QEMUFile *f, void *opaque, int version_id) return 0; } -static void pit_reset(void *opaque) +void pit_reset(void *opaque) { PITState *pit = opaque; PITChannelState *s; @@ -513,83 +480,3 @@ PITState *pit_init(int base, qemu_irq irq) return pit; } - -#ifdef KVM_CAP_PIT - -static void kvm_pit_save(QEMUFile *f, void *opaque) -{ - PITState *s = opaque; - struct kvm_pit_state pit; - struct kvm_pit_channel_state *c; - struct PITChannelState *sc; - int i; - - kvm_get_pit(kvm_context, &pit); - - for (i = 0; i < 3; i++) { - c = &pit.channels[i]; - sc = &s->channels[i]; - sc->count = c->count; - sc->latched_count = c->latched_count; - sc->count_latched = c->count_latched; - sc->status_latched = c->status_latched; - sc->status = c->status; - sc->read_state = c->read_state; - sc->write_state = c->write_state; - sc->write_latch = c->write_latch; - sc->rw_mode = c->rw_mode; - sc->mode = c->mode; - sc->bcd = c->bcd; - sc->gate = c->gate; - sc->count_load_time = c->count_load_time; - } - - pit_save(f, s); -} - -static int kvm_pit_load(QEMUFile *f, void *opaque, int version_id) -{ - PITState *s = opaque; - struct kvm_pit_state pit; - struct kvm_pit_channel_state *c; - struct PITChannelState *sc; - int i; - - pit_load(f, s, version_id); - - for (i = 0; i < 3; i++) { - c = &pit.channels[i]; - sc = &s->channels[i]; - c->count = sc->count; - c->latched_count = sc->latched_count; - c->count_latched = sc->count_latched; - c->status_latched = sc->status_latched; - c->status = sc->status; - c->read_state = sc->read_state; - c->write_state = sc->write_state; - c->write_latch = sc->write_latch; - c->rw_mode = sc->rw_mode; - c->mode = sc->mode; - c->bcd = sc->bcd; - c->gate = sc->gate; - c->count_load_time = sc->count_load_time; - } - - kvm_set_pit(kvm_context, &pit); - - return 0; -} - -PITState *kvm_pit_init(int base, qemu_irq irq) -{ - PITState *pit = &pit_state; - - register_savevm(PIT_SAVEVM_NAME, base, PIT_SAVEVM_VERSION, - kvm_pit_save, kvm_pit_load, pit); - - qemu_register_reset(pit_reset, pit); - pit_reset(pit); - - return pit; -} -#endif diff --git a/hw/i8254.h b/hw/i8254.h new file mode 100644 index 0000000000..ee68ab55b9 --- /dev/null +++ b/hw/i8254.h @@ -0,0 +1,66 @@ +/* + * QEMU 8253/8254 interval timer emulation + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_I8254_H +#define QEMU_I8254_H + +#define PIT_SAVEVM_NAME "i8254" +#define PIT_SAVEVM_VERSION 1 + +#define RW_STATE_LSB 1 +#define RW_STATE_MSB 2 +#define RW_STATE_WORD0 3 +#define RW_STATE_WORD1 4 + +typedef struct PITChannelState { + int count; /* can be 65536 */ + uint16_t latched_count; + uint8_t count_latched; + uint8_t status_latched; + uint8_t status; + uint8_t read_state; + uint8_t write_state; + uint8_t write_latch; + uint8_t rw_mode; + uint8_t mode; + uint8_t bcd; /* not supported */ + uint8_t gate; /* timer start */ + int64_t count_load_time; + /* irq handling */ + int64_t next_transition_time; + QEMUTimer *irq_timer; + qemu_irq irq; +} PITChannelState; + +struct PITState { + PITChannelState channels[3]; +}; + +void pit_save(QEMUFile *f, void *opaque); + +int pit_load(QEMUFile *f, void *opaque, int version_id); + +void pit_reset(void *opaque); + +#endif -- 2.11.4.GIT