kernel - Fix sysclock_t comparison in usched code
[dragonfly.git] / sys / sys / systimer.h
CommitLineData
88c4d2f6
MD
1/*
2 * SYS/SYSTIMER.H
8c10bfcf
MD
3 *
4 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
5 *
6 * This code is derived from software contributed to The DragonFly Project
7 * by Matthew Dillon <dillon@backplane.com>
8 *
88c4d2f6
MD
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
8c10bfcf 12 *
88c4d2f6
MD
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
8c10bfcf
MD
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * 3. Neither the name of The DragonFly Project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific, prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88c4d2f6 34 * SUCH DAMAGE.
8c10bfcf 35 *
4b52d1af 36 * $DragonFly: src/sys/sys/systimer.h,v 1.13 2007/04/30 06:57:36 dillon Exp $
88c4d2f6
MD
37 */
38
39#ifndef _SYS_SYSTIMER_H_
40#define _SYS_SYSTIMER_H_
41
59ef3aa7
SZ
42#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
43
1bd40720
MD
44#ifndef _SYS_TYPES_H_
45#include <sys/types.h>
46#endif
47#ifndef _SYS_QUEUE_H_
48#include <sys/queue.h>
49#endif
50
59ef3aa7
SZ
51/* XXX fix sys/kinfo.h */
52#ifndef __BOOLEAN_T_DEFINED__
53#define __BOOLEAN_T_DEFINED__
54typedef __boolean_t boolean_t;
55#endif
56
88c4d2f6
MD
57struct intrframe;
58
59typedef __uint32_t sysclock_t;
68a23bee 60typedef int32_t ssysclock_t;
88c4d2f6 61typedef TAILQ_HEAD(systimerq, systimer) *systimerq_t;
96d52ac8 62typedef void (*systimer_func_t)(struct systimer *, int, struct intrframe *);
88c4d2f6
MD
63
64typedef struct systimer {
65 TAILQ_ENTRY(systimer) node;
66 systimerq_t queue;
67 sysclock_t time; /* absolute time next intr */
68 sysclock_t periodic; /* if non-zero */
96d52ac8 69 systimer_func_t func;
88c4d2f6
MD
70 void *data;
71 int flags;
4b52d1af
MD
72 int freq; /* frequency if periodic */
73 struct cputimer *which; /* which timer was used? */
88c4d2f6
MD
74 struct globaldata *gd; /* cpu owning structure */
75} *systimer_t;
76
77#define SYSTF_ONQUEUE 0x0001
78#define SYSTF_IPIRUNNING 0x0002
0d1dffdf 79#define SYSTF_NONQUEUED 0x0004
88c4d2f6 80
43adde98 81void systimer_intr_enable(void);
b8a98473 82void systimer_intr(sysclock_t *, int, struct intrframe *);
0ded555b
MD
83void systimer_add(systimer_t);
84void systimer_del(systimer_t);
96d52ac8
SZ
85void systimer_init_periodic(systimer_t, systimer_func_t, void *, int);
86void systimer_init_periodic_nq(systimer_t, systimer_func_t, void *, int);
4b52d1af 87void systimer_adjust_periodic(systimer_t, int);
96d52ac8 88void systimer_init_oneshot(systimer_t, systimer_func_t, void *, int);
88c4d2f6 89
88c4d2f6 90/*
044ee7c4
MD
91 * cputimer interface. This provides a free-running (non-interrupt)
92 * timebase for the system. The cputimer
93 *
88c4d2f6 94 * These variables hold the fixed cputimer frequency, determining the
624051cd
SZ
95 * granularity of cputimer_count().
96 *
97 * Note that cputimer_count() always returns a full-width wrapping counter.
88c4d2f6
MD
98 *
99 * The 64 bit versions are used for converting count values into uS or nS
100 * as follows:
101 *
102 * usec = (cputimer_freq64_usec * count) >> 32
103 */
044ee7c4
MD
104
105struct cputimer {
d8fdd978 106 SLIST_ENTRY(cputimer) next;
044ee7c4
MD
107 const char *name;
108 int pri;
109 int type;
110 sysclock_t (*count)(void);
111 sysclock_t (*fromhz)(int freq);
112 sysclock_t (*fromus)(int us);
624051cd
SZ
113 void (*construct)(struct cputimer *, sysclock_t);
114 void (*destruct)(struct cputimer *);
044ee7c4
MD
115 sysclock_t freq; /* in Hz */
116 int64_t freq64_usec; /* in (1e6 << 32) / timer_freq */
117 int64_t freq64_nsec; /* in (1e9 << 32) / timer_freq */
118 sysclock_t base; /* (implementation dependant) */
119};
120
121extern struct cputimer *sys_cputimer;
122
123#define CPUTIMER_DUMMY 0
124#define CPUTIMER_8254_SEL1 1
125#define CPUTIMER_8254_SEL2 2
126#define CPUTIMER_ACPI 3
60297eb4 127#define CPUTIMER_VKERNEL 4
bea6e278 128#define CPUTIMER_HPET 5
a75ee873 129#define CPUTIMER_GEODE 6
96d52ac8 130#define CPUTIMER_CS5536 7
044ee7c4
MD
131
132#define CPUTIMER_PRI_DUMMY -10
133#define CPUTIMER_PRI_8254 0
134#define CPUTIMER_PRI_ACPI 10
bea6e278 135#define CPUTIMER_PRI_HPET 15
a75ee873
AH
136#define CPUTIMER_PRI_CS5536 17
137#define CPUTIMER_PRI_GEODE 18
60297eb4 138#define CPUTIMER_PRI_VKERNEL 20
044ee7c4 139
0ded555b
MD
140void cputimer_select(struct cputimer *, int);
141void cputimer_register(struct cputimer *);
142void cputimer_deregister(struct cputimer *);
143void cputimer_set_frequency(struct cputimer *, int);
144sysclock_t cputimer_default_fromhz(int);
145sysclock_t cputimer_default_fromus(int);
146void cputimer_default_construct(struct cputimer *, sysclock_t);
147void cputimer_default_destruct(struct cputimer *);
044ee7c4 148
ef612539
SZ
149/*
150 * Interrupt cputimer interface.
151 *
152 * Interrupt cputimers are normally one shot timers which will
153 * generate interrupt upon expiration.
154 *
155 * initclock -- Called at SI_BOOT2_CLOCKREG, SI_ORDER_SECOND. The
156 * interrupt timer could deregister itself here, if it
157 * is not the selected system interrupt cputimer. Before
158 * this function is called, 'enable' and 'reload' will
159 * not be called.
160 * enable -- Enable interrupt. It is called by each CPU. It is
161 * only called once during boot. Before this function
162 * is called, 'reload' will not be called.
163 * reload -- Called by each CPU when it wants to to reprogram the
164 * one shot timer expiration time. The reload value is
165 * measured in sys_cputimer->freq.
166 * config -- Setup the interrupt cputimer according to the passed
167 * in non-interrupt cputimer. It will be called when
168 * sys_cputimer's frequency is changed or when sys_cputimer
169 * itself is changed. It is also called when this interrupt
170 * cputimer gets registered.
171 * restart -- Start the possibly stalled interrupt cputimer immediately.
172 * Do fixup if necessary.
173 * pmfixup -- Called after ACPI power management is enabled.
174 */
175struct cputimer_intr {
176 sysclock_t freq;
177 void (*reload)
178 (struct cputimer_intr *, sysclock_t);
179 void (*enable)
180 (struct cputimer_intr *);
181 void (*config)
182 (struct cputimer_intr *, const struct cputimer *);
183 void (*restart)
184 (struct cputimer_intr *);
185 void (*pmfixup)
186 (struct cputimer_intr *);
187 void (*initclock)
188 (struct cputimer_intr *, boolean_t);
189 SLIST_ENTRY(cputimer_intr) next;
190 const char *name;
191 int type; /* CPUTIMER_INTR_ */
192 int prio; /* CPUTIMER_INTR_PRIO_ */
193 uint32_t caps; /* CPUTIMER_INTR_CAP_ */
194};
195
196#define CPUTIMER_INTR_8254 0
197#define CPUTIMER_INTR_LAPIC 1
198#define CPUTIMER_INTR_VKERNEL 2
199
200/* NOTE: Keep the new values less than CPUTIMER_INTR_PRIO_MAX */
201#define CPUTIMER_INTR_PRIO_8254 0
202#define CPUTIMER_INTR_PRIO_LAPIC 10
203#define CPUTIMER_INTR_PRIO_VKERNEL 20
204#define CPUTIMER_INTR_PRIO_MAX 1000
205
206#define CPUTIMER_INTR_CAP_NONE 0
207#define CPUTIMER_INTR_CAP_PS 0x1 /* works during powersaving */
208
209/*
210 * Interrupt cputimer implementation interfaces
211 *
212 * NOTE:
213 * cputimer_intr_deregister() is _not_ allowed to be called
214 * with the currently selected interrupt cputimer.
215 */
216void cputimer_intr_register(struct cputimer_intr *);
217void cputimer_intr_deregister(struct cputimer_intr *);
218int cputimer_intr_select(struct cputimer_intr *, int);
219
220/*
221 * Interrupt cputimer implementation helper functions
222 *
223 * default_enable -- NOP
224 * default_restart -- reload(0)
225 * default_config -- NOP
226 * default_pmfixup -- NOP
227 * default_initclock -- NOP
228 */
229void cputimer_intr_default_enable(struct cputimer_intr *);
230void cputimer_intr_default_restart(struct cputimer_intr *);
231void cputimer_intr_default_config(struct cputimer_intr *,
232 const struct cputimer *);
233void cputimer_intr_default_pmfixup(struct cputimer_intr *);
234void cputimer_intr_default_initclock(struct cputimer_intr *, boolean_t);
235
236/*
237 * Interrupt cputimer external interfaces
238 */
43adde98 239void cputimer_intr_enable(void);
ef612539
SZ
240void cputimer_intr_pmfixup(void);
241void cputimer_intr_config(const struct cputimer *);
242void cputimer_intr_reload(sysclock_t);
243void cputimer_intr_restart(void);
244int cputimer_intr_select_caps(uint32_t);
88c4d2f6 245
59ef3aa7
SZ
246#endif /* _KERNEL || _KERNEL_STRUCTURES */
247
624051cd 248#endif /* !_SYS_SYSTIMER_H_ */