From owner-freebsd-current@FreeBSD.ORG Mon Jul 12 13:34:33 2010 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6953C1065670; Mon, 12 Jul 2010 13:34:33 +0000 (UTC) (envelope-from nyan@FreeBSD.org) Received: from sakura.ccs.furiru.org (sakura.ccs.furiru.org [IPv6:2001:2f0:104:8060::1]) by mx1.freebsd.org (Postfix) with ESMTP id 25F528FC08; Mon, 12 Jul 2010 13:34:32 +0000 (UTC) Received: from localhost (authenticated bits=0) by sakura.ccs.furiru.org (unknown) with ESMTP id o6CDYR4P014192; Mon, 12 Jul 2010 22:34:29 +0900 (JST) (envelope-from nyan@FreeBSD.org) Date: Mon, 12 Jul 2010 22:33:11 +0900 (JST) Message-Id: <20100712.223311.27842410.nyan@FreeBSD.org> To: mav@FreeBSD.org From: TAKAHASHI Yoshihiro In-Reply-To: <4C3AD4A8.602@FreeBSD.org> References: <4C3AD4A8.602@FreeBSD.org> X-Mailer: Mew version 6.3 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_Jul_12_22_33_11_2010_131)--" Content-Transfer-Encoding: 7bit Cc: freebsd-current@FreeBSD.org Subject: Re: [patch] Clocks on PC98 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2010 13:34:33 -0000 ----Next_Part(Mon_Jul_12_22_33_11_2010_131)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit In article <4C3AD4A8.602@FreeBSD.org> Alexander Motin writes: > I've made a patch to unify PC98 event timer code with the rest of x86. > Could somebody test it on that hardware, as all I can say now is that it > builds. > > I have no idea about ISA PNP on PC98, so if it doesn't report timer > presence, it may be needed to add to device.hints lines like: > hint.attimer.0.at="isa" > hint.attimer.0.port="0x71" > hint.attimer.0.irq="0" This patch has two problems. The one is a missing change in timer_spkr_setfreq() and the other is wrong allocation for I/O ports. I attach new patch that works fine for pc98. Please feel it free. Thanks for your work. --- TAKAHASHI Yoshihiro ----Next_Part(Mon_Jul_12_22_33_11_2010_131)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="clock.diff" Index: conf/files.pc98 =================================================================== RCS file: /home/ncvs/src/sys/conf/files.pc98,v retrieving revision 1.386 diff -u -r1.386 files.pc98 --- conf/files.pc98 8 Jun 2010 18:36:03 -0000 1.386 +++ conf/files.pc98 12 Jul 2010 11:10:16 -0000 @@ -227,7 +227,6 @@ libkern/umoddi3.c standard pc98/apm/apm_bioscall.S optional apm pc98/cbus/cbus_dma.c optional isa -pc98/cbus/clock.c standard pc98/cbus/fdc.c optional fdc pc98/cbus/fdc_cbus.c optional fdc isa pc98/cbus/gdc.c optional gdc @@ -253,8 +252,10 @@ # x86 shared code between IA32, AMD64 and PC98 architectures # x86/isa/atpic.c optional atpic +x86/isa/clock.c standard x86/isa/isa.c optional isa x86/x86/io_apic.c optional apic x86/x86/local_apic.c optional apic x86/x86/mca.c standard x86/x86/msi.c optional apic pci +x86/x86/timeevents.c standard Index: pc98/conf/GENERIC.hints =================================================================== RCS file: /home/ncvs/src/sys/pc98/conf/GENERIC.hints,v retrieving revision 1.28 diff -u -r1.28 GENERIC.hints --- pc98/conf/GENERIC.hints 25 Aug 2008 14:52:50 -0000 1.28 +++ pc98/conf/GENERIC.hints 12 Jul 2010 12:52:00 -0000 @@ -42,6 +42,10 @@ #hint.ct.0.at="isa" #hint.ct.0.flags="0x50000" +hint.attimer.0.at="isa" +hint.attimer.0.port="0x71" +hint.attimer.0.irq="0" + hint.pcrtc.0.at="isa" hint.pckbd.0.at="isa" Index: x86/isa/clock.c =================================================================== RCS file: /home/ncvs/src/sys/x86/isa/clock.c,v retrieving revision 1.11 diff -u -r1.11 clock.c --- x86/isa/clock.c 12 Jul 2010 06:46:17 -0000 1.11 +++ x86/isa/clock.c 12 Jul 2010 12:56:47 -0000 @@ -66,9 +66,17 @@ #include #include +#ifdef PC98 +#include +#else #include +#endif #ifdef DEV_ISA +#ifdef PC98 +#include +#else #include +#endif #include #endif @@ -78,8 +86,12 @@ int clkintr_pending; #ifndef TIMER_FREQ +#ifdef PC98 +#define TIMER_FREQ 2457600 +#else #define TIMER_FREQ 1193182 #endif +#endif u_int i8254_freq = TIMER_FREQ; TUNABLE_INT("hw.i8254.freq", &i8254_freq); int i8254_max_count; @@ -97,6 +109,10 @@ int port_rid, intr_rid; struct resource *port_res; struct resource *intr_res; +#ifdef PC98 + int port_rid2; + struct resource *port_res2; +#endif void *intr_handler; struct timecounter tc; struct eventtimer et; @@ -150,7 +166,11 @@ { int mode; +#ifdef PC98 + mode = TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT; +#else mode = TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT; +#endif if (timer2_state != RELEASED) return (-1); @@ -163,7 +183,11 @@ * and this is probably good enough for timer2, so we aren't as * careful with it as with timer0. */ +#ifdef PC98 + outb(TIMER_MODE, TIMER_SEL1 | (mode & 0x3f)); +#else outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f)); +#endif ppi_spkr_on(); /* enable counter2 output to speaker */ return (0); } @@ -175,7 +199,11 @@ if (timer2_state != ACQUIRED) return (-1); timer2_state = RELEASED; +#ifdef PC98 + outb(TIMER_MODE, TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT); +#else outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT); +#endif ppi_spkr_off(); /* disable counter2 output to speaker */ return (0); } @@ -186,8 +214,13 @@ freq = i8254_freq / freq; mtx_lock_spin(&clock_lock); +#ifdef PC98 + outb(TIMER_CNTR1, freq & 0xff); + outb(TIMER_CNTR1, freq >> 8); +#else outb(TIMER_CNTR2, freq & 0xff); outb(TIMER_CNTR2, freq >> 8); +#endif mtx_unlock_spin(&clock_lock); } @@ -293,7 +326,11 @@ while (ticks_left > 0) { #ifdef KDB if (kdb_active) { +#ifdef PC98 + outb(0x5f, 0); +#else inb(0x84); +#endif tick = prev_tick - 1; if (tick <= 0) tick = i8254_max_count; @@ -377,7 +414,9 @@ { i8254_restore(); /* restore i8254_freq and hz */ +#ifndef PC98 atrtc_restore(); /* reenable RTC interrupts */ +#endif } #endif @@ -387,6 +426,10 @@ { mtx_init(&clock_lock, "clk", NULL, MTX_SPIN | MTX_NOPROFILE); +#ifdef PC98 + if (pc98_machine_type & M_8M) + i8254_freq = 1996800L; /* 1.9968 MHz */ +#endif set_i8254_freq(i8254_freq, 0); } @@ -506,6 +549,51 @@ { 0 } }; +#ifdef PC98 +static void +pc98_alloc_resource(device_t dev) +{ + static bus_addr_t iat1[] = {0, 2, 4, 6}; + static bus_addr_t iat2[] = {0, 4}; + struct attimer_softc *sc; + + sc = device_get_softc(dev); + + sc->port_rid = 0; + bus_set_resource(dev, SYS_RES_IOPORT, sc->port_rid, IO_TIMER1, 1); + sc->port_res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, + &sc->port_rid, iat1, 4, RF_ACTIVE); + if (sc->port_res == NULL) + device_printf(dev, "Warning: Couldn't map I/O.\n"); + else + isa_load_resourcev(sc->port_res, iat1, 4); + + sc->port_rid2 = 4; + bus_set_resource(dev, SYS_RES_IOPORT, sc->port_rid2, TIMER_CNTR1, 1); + sc->port_res2 = isa_alloc_resourcev(dev, SYS_RES_IOPORT, + &sc->port_rid2, iat2, 2, RF_ACTIVE); + if (sc->port_res2 == NULL) + device_printf(dev, "Warning: Couldn't map I/O.\n"); + else + isa_load_resourcev(sc->port_res2, iat2, 2); +} + +static void +pc98_release_resource(device_t dev) +{ + struct attimer_softc *sc; + + sc = device_get_softc(dev); + + if (sc->port_res) + bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid, + sc->port_res); + if (sc->port_res2) + bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid2, + sc->port_res2); +} +#endif + static int attimer_probe(device_t dev) { @@ -515,6 +603,11 @@ /* ENOENT means no PnP-ID, device is hinted. */ if (result == ENOENT) { device_set_desc(dev, "AT timer"); +#ifdef PC98 + /* To print resources correctly. */ + pc98_alloc_resource(dev); + pc98_release_resource(dev); +#endif return (BUS_PROBE_LOW_PRIORITY); } return (result); @@ -529,9 +622,13 @@ attimer_sc = sc = device_get_softc(dev); bzero(sc, sizeof(struct attimer_softc)); +#ifdef PC98 + pc98_alloc_resource(dev); +#else if (!(sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, IO_TIMER1, IO_TIMER1 + 3, 4, RF_ACTIVE))) device_printf(dev,"Warning: Couldn't map I/O.\n"); +#endif i8254_intsrc = intr_lookup_source(0); if (i8254_intsrc != NULL) i8254_pending = i8254_intsrc->is_pic->pic_source_pending; ----Next_Part(Mon_Jul_12_22_33_11_2010_131)----