xref: /plan9-contrib/sys/src/9k/k10/hpet.c (revision 9ef1f84b659abcb917c5c090acbce0772e494f21)
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 
7 typedef struct Hpet Hpet;
8 typedef struct Tn Tn;
9 
10 struct Hpet {					/* Event Timer Block */
11 	u32int	cap;				/* General Capabilities */
12 	u32int	period;				/* Main Counter Tick Period */
13 	u32int	_8_[2];
14 	u32int	cnf;				/* General Configuration */
15 	u32int	_20_[3];
16 	u32int	sts;				/* General Interrupt Status */
17 	u32int	_36_[51];
18 	union {					/* Main Counter Value */
19 		u32int	u32[2];
20 		u64int	u64;
21 	} counter;
22 	u32int	_248[2];
23 	Tn	tn[];				/* Timers */
24 };
25 
26 struct Tn {					/* Timer */
27 	u32int	cnf;				/* Configuration */
28 	u32int	cap;				/* Capabilities */
29 	union {					/* Comparator */
30 		u32int	u32[2];
31 		u64int	u64;
32 	} comparator;
33 	u32int	val;				/* FSB Interrupt Value */
34 	u32int	addr;				/* FSB Interrupt Address */
35 	u32int	_24_[2];
36 };
37 
38 static Hpet* etb[8];				/* Event Timer Blocks */
39 
40 void
hpetinit(int seqno,uintptr pa,int minticks)41 hpetinit(int seqno, uintptr pa, int minticks)
42 {
43 	Tn *tn;
44 	int i, n;
45 	Hpet *hpet;
46 	u64int val;
47 
48 	DBG("hpet: seqno %d pa %#p minticks %d\n", seqno, pa, minticks);
49 	if(seqno < 0 || seqno > nelem(etb) || (hpet = vmap(pa, 1024)) == nil)
50 		return;
51 	etb[seqno] = hpet;
52 
53 	DBG("HPET: cap %#8.8ux period %#8.8ux\n", hpet->cap, hpet->period);
54 	DBG("HPET: cnf %#8.8ux sts %#8.8ux\n",hpet->cnf, hpet->sts);
55 	DBG("HPET: counter %#16.16llux\n",
56 		(((u64int)hpet->counter.u32[1])<<32)|hpet->counter.u32[0]);
57 
58 	n = ((hpet->cap>>8) & 0x0F) + 1;
59 	for(i = 0; i < n; i++){
60 		tn = &hpet->tn[i];
61 		DBG("Tn%d: cnf %#8.8ux cap %#8.8ux\n", i, tn->cnf, tn->cap);
62 		DBG("Tn%d: comparator %#16.16llux\n", i,
63 			(((u64int)tn->comparator.u32[1])<<32)|tn->comparator.u32[0]);
64 		DBG("Tn%d: val %#8.8ux addr %#8.8ux\n", i, tn->val, tn->addr);
65 	}
66 
67 	/*
68 	 * hpet->period is the number of femtoseconds per counter tick.
69 	 */
70 }
71