Merge from vendor branch OPENSSL:
[dragonfly.git] / sys / sys / systimer.h
1 /*
2  * SYS/SYSTIMER.H
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  * 
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 
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
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
34  * SUCH DAMAGE.
35  * 
36  * $DragonFly: src/sys/sys/systimer.h,v 1.2 2004/07/16 05:51:57 dillon Exp $
37  */
38
39 #ifndef _SYS_SYSTIMER_H_
40 #define _SYS_SYSTIMER_H_
41
42 struct intrframe;
43
44 typedef __uint32_t      sysclock_t;
45 typedef TAILQ_HEAD(systimerq, systimer) *systimerq_t;
46 typedef void (*systimer_func_t)(struct systimer *info);
47 typedef void (*systimer_func2_t)(struct systimer *info, struct intrframe *frame);
48
49 typedef struct systimer {
50     TAILQ_ENTRY(systimer)       node;
51     systimerq_t                 queue;
52     sysclock_t                  time;           /* absolute time next intr */
53     sysclock_t                  periodic;       /* if non-zero */
54     systimer_func2_t            func;
55     void                        *data;
56     int                         flags;
57     struct globaldata           *gd;            /* cpu owning structure */
58 } *systimer_t;
59
60 #define SYSTF_ONQUEUE           0x0001
61 #define SYSTF_IPIRUNNING        0x0002
62
63 void systimer_intr(sysclock_t *time, struct intrframe *frame);
64 void systimer_add(systimer_t info);
65 void systimer_del(systimer_t info);
66 void systimer_init_periodic(systimer_t info, void *func, void *data, int hz);
67 void systimer_init_oneshot(systimer_t info, void *func, void *data, int us);
68
69
70 /*
71  * note that cputimer_count() always returns a full-width wrapping counter.
72  */
73 sysclock_t cputimer_count(void);
74 sysclock_t cputimer_fromhz(int freq);
75 sysclock_t cputimer_fromus(int us);
76 void cputimer_intr_reload(sysclock_t clock);
77
78 /*
79  * These variables hold the fixed cputimer frequency, determining the
80  * granularity of cputimer_count().  
81  *
82  * The 64 bit versions are used for converting count values into uS or nS
83  * as follows:
84  *
85  *      usec = (cputimer_freq64_usec * count) >> 32
86  */
87 extern sysclock_t cputimer_freq;        /* in Hz */
88 extern int64_t cputimer_freq64_usec;    /* in (1e6 << 32) / timer_freq */
89 extern int64_t cputimer_freq64_nsec;    /* in (1e9 << 32) / timer_freq */
90
91 #endif
92