From patchwork Tue Dec 22 17:41:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5q2m55SwID0/SVNPLTIwMjItSlA/Qj9JQnNrUWoxVFRHa2JLRUk9Pz0=?= X-Patchwork-Id: 41631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9FCF8B7BBF for ; Wed, 23 Dec 2009 05:14:37 +1100 (EST) Received: from localhost ([127.0.0.1]:54115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN9Dw-0001HP-O9 for incoming@patchwork.ozlabs.org; Tue, 22 Dec 2009 13:12:44 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NN8nQ-0000Go-8E for qemu-devel@nongnu.org; Tue, 22 Dec 2009 12:45:20 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NN8nK-0000Ep-Fx for qemu-devel@nongnu.org; Tue, 22 Dec 2009 12:45:18 -0500 Received: from [199.232.76.173] (port=55241 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN8nJ-0000Ee-Ny for qemu-devel@nongnu.org; Tue, 22 Dec 2009 12:45:14 -0500 Received: from smtp-vip.mem.interq.net ([210.157.1.50]:22974 helo=smtp01.mem.internal-gmo) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NN8nD-0002Ft-Is for qemu-devel@nongnu.org; Tue, 22 Dec 2009 12:45:13 -0500 Received: (from root@localhost) by smtp01.mem.internal-gmo (8.13.8/8.12.6) id nBMHj0JU021954 for qemu-devel@nongnu.org; Wed, 23 Dec 2009 02:45:00 +0900 (JST) Received: (from root@localhost) by smtp01.mem.internal-gmo (8.13.8/8.12.6) id nBMHgJxu021818 for qemu-devel@nongnu.org; Wed, 23 Dec 2009 02:42:19 +0900 (JST) Received: from YOUR-BD18D6DD63.m1.interq.or.jp (ntymns039132.ymns.nt.ftth.ppp.infoweb.ne.jp [121.92.167.132]) by smtp01.mem.internal-gmo with ESMTP id nBMHgGgM021741 for ; (me101664 for with PLAIN) Wed, 23 Dec 2009 02:42:18 +0900 (JST) Message-Id: <200912221741.AA00215@YOUR-BD18D6DD63.m1.interq.or.jp> From: "TAKEDA, toshiya" Date: Wed, 23 Dec 2009 02:41:07 +0900 To: qemu-devel MIME-Version: 1.0 X-Mailer: AL-Mail32 Version 1.13 X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) Subject: [Qemu-devel] [PATCH V4 12/18] i8254: support NEC PC-9821 interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: TAKEDA, toshiya --- hw/i8254.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 51 insertions(+), 6 deletions(-) diff --git a/hw/i8254.c b/hw/i8254.c index faaa884..155f879 100644 --- a/hw/i8254.c +++ b/hw/i8254.c @@ -47,6 +47,7 @@ typedef struct PITChannelState { uint8_t bcd; /* not supported */ uint8_t gate; /* timer start */ int64_t count_load_time; + uint64_t frequency; /* irq handling */ int64_t next_transition_time; QEMUTimer *irq_timer; @@ -66,7 +67,7 @@ static int pit_get_count(PITChannelState *s) uint64_t d; int counter; - d = muldiv64(qemu_get_clock(vm_clock) - s->count_load_time, PIT_FREQ, + d = muldiv64(qemu_get_clock(vm_clock) - s->count_load_time, s->frequency, get_ticks_per_sec()); switch(s->mode) { case 0: @@ -92,7 +93,7 @@ static int pit_get_out1(PITChannelState *s, int64_t current_time) uint64_t d; int out; - d = muldiv64(current_time - s->count_load_time, PIT_FREQ, + d = muldiv64(current_time - s->count_load_time, s->frequency, get_ticks_per_sec()); switch(s->mode) { default: @@ -132,7 +133,7 @@ static int64_t pit_get_next_transition_time(PITChannelState *s, uint64_t d, next_time, base; int period2; - d = muldiv64(current_time - s->count_load_time, PIT_FREQ, + d = muldiv64(current_time - s->count_load_time, s->frequency, get_ticks_per_sec()); switch(s->mode) { default: @@ -170,7 +171,7 @@ static int64_t pit_get_next_transition_time(PITChannelState *s, } /* convert to timer units */ next_time = s->count_load_time + muldiv64(next_time, get_ticks_per_sec(), - PIT_FREQ); + s->frequency); /* fix potential rounding problems */ /* XXX: better solution: use a clock at PIT_FREQ Hz */ if (next_time <= current_time) @@ -498,20 +499,64 @@ void hpet_pit_enable(void) pit_load_count(s, 0); } -PITState *pit_init(int base, qemu_irq irq) +static void pit_init_common(PITState *pit, int base, qemu_irq irq, + uint64_t frequency) { - PITState *pit = &pit_state; PITChannelState *s; + int i; s = &pit->channels[0]; /* the timer 0 is connected to an IRQ */ s->irq_timer = qemu_new_timer(vm_clock, pit_irq_timer, s); s->irq = irq; + for (i = 0; i < 3; i++) { + pit->channels[i].frequency = frequency; + } + vmstate_register(base, &vmstate_pit, pit); qemu_register_reset(pit_reset, pit); +} + +PITState *pit_init(int base, qemu_irq irq) +{ + PITState *pit = &pit_state; + + pit_init_common(pit, base, irq, PIT_FREQ); + register_ioport_write(base, 4, 1, pit_ioport_write, pit); register_ioport_read(base, 3, 1, pit_ioport_read, pit); return pit; } + +/* NEC PC-9821 */ + +static void pc98_pit_ioport_write(void *opaque, uint32_t addr, uint32_t val) +{ + pit_ioport_write(opaque, addr >> 1, val); +} + +static uint32_t pc98_pit_ioport_read(void *opaque, uint32_t addr) +{ + return pit_ioport_read(opaque, addr >> 1); +} + +PITState *pc98_pit_init(qemu_irq irq) +{ + PITState *pit = &pit_state; + int i; + + pit_init_common(pit, 0, irq, PC98_PIT_FREQ); + + for (i = 0; i < 4; i++) { + register_ioport_write(0x71 + (i << 1), 1, 1, pc98_pit_ioport_write, pit); + register_ioport_write(0x3fd9 + (i << 1), 1, 1, pc98_pit_ioport_write, pit); + } + for (i = 0; i < 3; i++) { + register_ioport_read(0x71 + (i << 1), 1, 1, pc98_pit_ioport_read, pit); + register_ioport_read(0x3fd9 + (i << 1), 1, 1, pc98_pit_ioport_read, pit); + } + + return pit; +}