xref: /original-bsd/sys/vax/uba/kgclock.c (revision a1c2194a)
1 /*-
2  * Copyright (c) 1982, 1986 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)kgclock.c	7.4 (Berkeley) 05/09/91
8  */
9 
10 #include "kg.h"
11 #if NKG > 0
12 /*
13  * KL-11 as profiling clock
14  */
15 #include "../include/pte.h"
16 #include "../include/psl.h"
17 
18 #include "sys/param.h"
19 #include "sys/map.h"
20 #include "sys/buf.h"
21 #include "sys/time.h"
22 #include "sys/kernel.h"
23 
24 #include "ubavar.h"
25 
26 int	kgprobe(), kgattach();
27 struct	uba_device *kginfo[1];
28 u_short	kgstd[] = { 0177560, 0 };
29 struct	uba_driver kgdriver =
30     { kgprobe, 0, kgattach, 0, kgstd, "kg", kginfo };
31 
32 struct klregs {
33 	u_short	fill[2];
34 	u_short	tcsr;
35 	u_short	tbuf;
36 };
37 #define	KLSTRT	0300		/* intr enbl + done */
38 struct	klregs *klbase;
39 
40 int	usekgclock = 1;		/* if zero, kgclock is disabled */
41 
42 kgprobe(reg)
43 	caddr_t reg;
44 {
45 	register int br, cvec;	/* value-result */
46 	register struct klregs *klp = (struct klregs *)reg;
47 
48 	klp->tcsr = KLSTRT;
49 	DELAY(100000);
50 	klp->tcsr = 0;
51 	return (sizeof(struct klregs));
52 }
53 
54 kgattach(ui)
55 	struct uba_device *ui;
56 {
57 
58 	klbase = (struct klregs *)ui->ui_addr;
59 }
60 
61 /*
62  * start the sampling clock
63  */
64 startkgclock()
65 {
66 
67 	if (klbase && usekgclock && phz == 0)
68 		klbase->tcsr = KLSTRT;	/* enable interrupts */
69 }
70 
71 /* ARGSUSED */
72 kgclock(dev, r0, r1, r2, r3, r4 ,r5, pc, ps)
73 	caddr_t pc;
74 	int ps;
75 {
76 	register int k;
77 	static long otime;
78 	static long calibrate;
79 
80 	if (usekgclock == 0) {
81 		phz = 0;
82 		otime = 0;
83 		return;
84 	}
85 	klbase->tbuf = 0377;	/* reprime clock (scope sync too) */
86 	if (phz == 0) {
87 		if (otime == 0) {
88 			otime = time.tv_sec + 1;
89 			calibrate = 0;
90 		}
91 		if (time.tv_sec >= otime)
92 			calibrate++;
93 		if (time.tv_sec >= otime + 4) {
94 			phz = calibrate / 4;
95 			otime = 0;
96 		}
97 		return;
98 	}
99 	gatherstats(pc, ps);	/* this routine lives in kern_clock.c */
100 }
101 #endif
102