Date: Mon, 12 Jul 2010 22:33:11 +0900 (JST) From: TAKAHASHI Yoshihiro <nyan@FreeBSD.org> To: mav@FreeBSD.org Cc: freebsd-current@FreeBSD.org Subject: Re: [patch] Clocks on PC98 Message-ID: <20100712.223311.27842410.nyan@FreeBSD.org> In-Reply-To: <4C3AD4A8.602@FreeBSD.org> References: <4C3AD4A8.602@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
----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 <mav@FreeBSD.org> 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 <nyan@FreeBSD.org>
----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 <machine/ppireg.h>
#include <machine/timerreg.h>
+#ifdef PC98
+#include <pc98/pc98/pc98_machdep.h>
+#else
#include <isa/rtc.h>
+#endif
#ifdef DEV_ISA
+#ifdef PC98
+#include <pc98/cbus/cbus.h>
+#else
#include <isa/isareg.h>
+#endif
#include <isa/isavar.h>
#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)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100712.223311.27842410.nyan>
