Switch newsmips to timecounters. From gdamore@ on port-newsmips

with one tweak by me, and regressions passed on NWS-5000.
This commit is contained in:
tsutsui 2006-09-13 14:50:42 +00:00
parent 2dce1200cc
commit 3a57046c1d
3 changed files with 29 additions and 54 deletions

View File

@ -1,9 +1,10 @@
/* $NetBSD: types.h,v 1.8 2006/09/04 20:33:24 tsutsui Exp $ */
/* $NetBSD: types.h,v 1.9 2006/09/13 14:50:42 tsutsui Exp $ */
#include <mips/types.h>
#define __HAVE_GENERIC_SOFT_INTERRUPTS
#define __HAVE_GENERIC_TODR
#define __HAVE_TIMECOUNTER
/* MIPS specific options */
#define __HAVE_BOOTINFO_H

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.83 2006/04/09 01:18:14 tsutsui Exp $ */
/* $NetBSD: machdep.c,v 1.84 2006/09/13 14:50:42 tsutsui Exp $ */
/*
* Copyright (c) 1992, 1993
@ -76,7 +76,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.83 2006/04/09 01:18:14 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.84 2006/09/13 14:50:42 tsutsui Exp $");
/* from: Utah Hdr: machdep.c 1.63 91/04/24 */
@ -159,7 +159,6 @@ phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
int mem_cluster_cnt;
struct idrom idrom;
void (*readmicrotime)(struct timeval *tvp);
void (*hardware_intr)(uint32_t, uint32_t, uint32_t, uint32_t);
void (*enable_intr)(void);
void (*disable_intr)(void);
@ -622,33 +621,6 @@ haltsys:
/*NOTREACHED*/
}
/*
* Return the best possible estimate of the time in the timeval
* to which tvp points. Unfortunately, we can't read the hardware registers.
* We guarantee that the time will be greater than the value obtained by a
* previous call.
*/
void
microtime(struct timeval *tvp)
{
int s = splclock();
static struct timeval lasttime;
if (readmicrotime)
readmicrotime(tvp);
else
*tvp = time;
if (tvp->tv_sec == lasttime.tv_sec &&
tvp->tv_usec <= lasttime.tv_usec &&
(tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
tvp->tv_sec++;
tvp->tv_usec -= 1000000;
}
lasttime = *tvp;
splx(s);
}
void
delay(int n)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: news5000.c,v 1.15 2005/12/11 12:18:25 christos Exp $ */
/* $NetBSD: news5000.c,v 1.16 2006/09/13 14:50:42 tsutsui Exp $ */
/*-
* Copyright (C) 1999 SHIMIZU Ryo. All rights reserved.
@ -27,11 +27,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.15 2005/12/11 12:18:25 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.16 2006/09/13 14:50:42 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/timetc.h>
#include <machine/adrsmap.h>
#include <machine/cpu.h>
@ -40,18 +41,15 @@ __KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.15 2005/12/11 12:18:25 christos Exp $
#include <newsmips/apbus/apbusvar.h>
#include <newsmips/newsmips/machid.h>
extern void (*readmicrotime)(struct timeval *tvp);
static void news5000_level1_intr(void);
static void news5000_level0_intr(void);
static void news5000_enable_intr(void);
static void news5000_disable_intr(void);
static void news5000_enable_timer(void);
static void news5000_readmicrotime(struct timeval *);
static void news5000_readidrom(uint8_t *);
static u_int freerun_off;
static void news5000_tc_init(void);
static uint32_t news5000_getfreerun(struct timecounter *);
/*
* Handle news5000 interrupts.
@ -81,7 +79,6 @@ news5000_intr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
if (int2stat & NEWS5000_INT2_TIMER0) {
*(volatile uint32_t *)NEWS5000_TIMER0 = 1;
freerun_off = *(volatile uint32_t *)NEWS5000_FREERUN;
cf.pc = pc;
cf.sr = status;
@ -222,27 +219,33 @@ static void
news5000_enable_timer(void)
{
news5000_tc_init();
/* enable timer interrpt */
*(volatile uint32_t *)NEWS5000_INTEN2 = NEWS5000_INT2_TIMER0;
}
static void
news5000_readmicrotime(struct timeval *tvp)
static uint32_t
news5000_getfreerun(struct timecounter *tc)
{
uint32_t freerun;
*tvp = time;
freerun = *(volatile uint32_t *)NEWS5000_FREERUN;
freerun -= freerun_off;
if (freerun > 1000000)
freerun = 1000000;
tvp->tv_usec += freerun;
if (tvp->tv_usec >= 1000000) {
tvp->tv_usec -= 1000000;
tvp->tv_sec++;
}
return *(volatile uint32_t *)NEWS5000_FREERUN;
}
static void
news5000_tc_init(void)
{
static struct timecounter tc = {
.tc_get_timecount = news5000_getfreerun,
.tc_frequency = 1000000,
.tc_counter_mask = ~0,
.tc_name = "news5000_freerun",
.tc_quality = 100,
};
tc_init(&tc);
}
static void
news5000_readidrom(uint8_t *rom)
{
@ -264,7 +267,6 @@ news5000_init(void)
enable_timer = news5000_enable_timer;
news5000_readidrom((uint8_t *)&idrom);
readmicrotime = news5000_readmicrotime;
hostid = idrom.id_serial;
/* XXX reset uPD72067 FDC to avoid spurious interrupts */