1*49567Sbostic /*-
2*49567Sbostic * Copyright (c) 1982, 1986 The Regents of the University of California.
3*49567Sbostic * All rights reserved.
423330Smckusick *
5*49567Sbostic * %sccs.include.redist.c%
6*49567Sbostic *
7*49567Sbostic * @(#)kgclock.c 7.4 (Berkeley) 05/09/91
823330Smckusick */
911357Smckusick
1012825Ssam #include "kg.h"
1112825Ssam #if NKG > 0
1212825Ssam /*
1312825Ssam * KL-11 as profiling clock
1412825Ssam */
1545804Sbostic #include "../include/pte.h"
1645804Sbostic #include "../include/psl.h"
1711357Smckusick
1845804Sbostic #include "sys/param.h"
1945804Sbostic #include "sys/map.h"
2045804Sbostic #include "sys/buf.h"
2145804Sbostic #include "sys/time.h"
2245804Sbostic #include "sys/kernel.h"
2312825Ssam
2417074Sbloom #include "ubavar.h"
2511357Smckusick
2611357Smckusick int kgprobe(), kgattach();
2711357Smckusick struct uba_device *kginfo[1];
2811357Smckusick u_short kgstd[] = { 0177560, 0 };
2911357Smckusick struct uba_driver kgdriver =
3011357Smckusick { kgprobe, 0, kgattach, 0, kgstd, "kg", kginfo };
3111357Smckusick
3211357Smckusick struct klregs {
3311357Smckusick u_short fill[2];
3411357Smckusick u_short tcsr;
3511357Smckusick u_short tbuf;
3611357Smckusick };
3711357Smckusick #define KLSTRT 0300 /* intr enbl + done */
3811357Smckusick struct klregs *klbase;
3911357Smckusick
4016972Skarels int usekgclock = 1; /* if zero, kgclock is disabled */
4116972Skarels
kgprobe(reg)4211357Smckusick kgprobe(reg)
4312825Ssam caddr_t reg;
4411357Smckusick {
4511357Smckusick register int br, cvec; /* value-result */
4611357Smckusick register struct klregs *klp = (struct klregs *)reg;
4711357Smckusick
4811357Smckusick klp->tcsr = KLSTRT;
4911357Smckusick DELAY(100000);
5011357Smckusick klp->tcsr = 0;
5124960Skarels return (sizeof(struct klregs));
5211357Smckusick }
5311357Smckusick
5411357Smckusick kgattach(ui)
5511393Ssam struct uba_device *ui;
5611357Smckusick {
5711393Ssam
5811357Smckusick klbase = (struct klregs *)ui->ui_addr;
5911357Smckusick }
6011357Smckusick
6111357Smckusick /*
6211357Smckusick * start the sampling clock
6311357Smckusick */
startkgclock()6411357Smckusick startkgclock()
6511357Smckusick {
6611393Ssam
6716972Skarels if (klbase && usekgclock && phz == 0)
6811357Smckusick klbase->tcsr = KLSTRT; /* enable interrupts */
6911357Smckusick }
7011357Smckusick
7111357Smckusick /* ARGSUSED */
kgclock(dev,r0,r1,r2,r3,r4,r5,pc,ps)7211357Smckusick kgclock(dev, r0, r1, r2, r3, r4 ,r5, pc, ps)
7311393Ssam caddr_t pc;
7411393Ssam int ps;
7511357Smckusick {
7611357Smckusick register int k;
7712825Ssam static long otime;
7812825Ssam static long calibrate;
7911357Smckusick
8016972Skarels if (usekgclock == 0) {
8116972Skarels phz = 0;
8216972Skarels otime = 0;
8316972Skarels return;
8416972Skarels }
8511357Smckusick klbase->tbuf = 0377; /* reprime clock (scope sync too) */
8611358Smckusick if (phz == 0) {
8711358Smckusick if (otime == 0) {
8812825Ssam otime = time.tv_sec + 1;
8911358Smckusick calibrate = 0;
9011358Smckusick }
9112825Ssam if (time.tv_sec >= otime)
9211358Smckusick calibrate++;
9312825Ssam if (time.tv_sec >= otime + 4) {
9411358Smckusick phz = calibrate / 4;
9511358Smckusick otime = 0;
9611358Smckusick }
9711358Smckusick return;
9811358Smckusick }
9911393Ssam gatherstats(pc, ps); /* this routine lives in kern_clock.c */
10011357Smckusick }
10112825Ssam #endif
102