1/* $NetBSD: callout.h,v 1.32 2015/02/07 19:36:42 christos Exp $ */
2
3/*-
4 * Copyright (c) 2000, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef _SYS_CALLOUT_H_
34#define _SYS_CALLOUT_H_
35
36#include <sys/types.h>
37
38/*
39 * The callout implementation is private to kern_timeout.c yet uses
40 * caller-supplied storage, as lightweight callout operations are
41 * critical to system performance.
42 *
43 * The size of callout_t must remain constant in order to ensure ABI
44 * compatibility for kernel modules: it may become smaller, but must
45 * not grow. If more space is required, rearrange the members of
46 * callout_impl_t.
47 */
48typedef struct callout {
49 void *_c_store[10];
50} callout_t;
51
52/* Internal flags. */
53#define CALLOUT_BOUND 0x0001 /* bound to a specific CPU */
54#define CALLOUT_PENDING 0x0002 /* callout is on the queue */
55#define CALLOUT_FIRED 0x0004 /* callout has fired */
56#define CALLOUT_INVOKING 0x0008 /* callout function is being invoked */
57
58/* End-user flags. */
59#define CALLOUT_MPSAFE 0x0100 /* does not need kernel_lock */
60#define CALLOUT_FLAGMASK 0xff00
61
62#define CALLOUT_FMT "\177\020\
63b\00BOUND\0\
64b\01PENDING\0\
65b\02FIRED\0\
66b\03INVOKING\0\
67b\10MPSAFE\0"
68
69#ifdef _CALLOUT_PRIVATE
70
71/* The following funkyness is to appease gcc3's strict aliasing. */
72struct callout_circq {
73 /* next element */
74 union {
75 struct callout_impl *elem;
76 struct callout_circq *list;
77 } cq_next;
78 /* previous element */
79 union {
80 struct callout_impl *elem;
81 struct callout_circq *list;
82 } cq_prev;
83};
84#define cq_next_e cq_next.elem
85#define cq_prev_e cq_prev.elem
86#define cq_next_l cq_next.list
87#define cq_prev_l cq_prev.list
88
89struct callout_cpu;
90
91typedef struct callout_impl {
92 struct callout_circq c_list; /* linkage on queue */
93 void (*c_func)(void *); /* function to call */
94 void *c_arg; /* function argument */
95 struct callout_cpu * volatile c_cpu; /* associated CPU */
96 int c_time; /* when callout fires */
97 u_int c_flags; /* state of this entry */
98 u_int c_magic; /* magic number */
99} callout_impl_t;
100#define CALLOUT_MAGIC 0x11deeba1
101
102#endif /* _CALLOUT_PRIVATE */
103
104#ifdef _KERNEL
105struct cpu_info;
106
107void callout_startup(void);
108void callout_init_cpu(struct cpu_info *);
109void callout_hardclock(void);
110
111void callout_init(callout_t *, u_int);
112void callout_destroy(callout_t *);
113void callout_setfunc(callout_t *, void (*)(void *), void *);
114void callout_reset(callout_t *, int, void (*)(void *), void *);
115void callout_schedule(callout_t *, int);
116bool callout_stop(callout_t *);
117bool callout_halt(callout_t *, void *);
118bool callout_pending(callout_t *);
119bool callout_expired(callout_t *);
120bool callout_active(callout_t *);
121bool callout_invoking(callout_t *);
122void callout_ack(callout_t *);
123void callout_bind(callout_t *, struct cpu_info *);
124#endif /* _KERNEL */
125
126#endif /* !_SYS_CALLOUT_H_ */
127