]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/cddl/dev/cyclic/i386/cyclic_machdep.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / cddl / dev / cyclic / i386 / cyclic_machdep.c
1 /*-
2  * Copyright 2006-2008 John Birrell <jb@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 
13  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  *
27  */
28
29 static void enable(cyb_arg_t);
30 static void disable(cyb_arg_t);
31 static void reprogram(cyb_arg_t, hrtime_t);
32 static void xcall(cyb_arg_t, cpu_t *, cyc_func_t, void *);
33
34 static cyc_backend_t    be      = {
35         NULL,           /* cyb_configure */
36         NULL,           /* cyb_unconfigure */
37         enable,
38         disable,
39         reprogram,
40         xcall,
41         NULL            /* cyb_arg_t cyb_arg */
42 };
43
44 static void
45 cyclic_ap_start(void *dummy)
46 {
47         /* Initialise the rest of the CPUs. */
48         cyclic_mp_init();
49 }
50
51 SYSINIT(cyclic_ap_start, SI_SUB_SMP, SI_ORDER_ANY, cyclic_ap_start, NULL);
52
53 /*
54  *  Machine dependent cyclic subsystem initialisation.
55  */
56 static void
57 cyclic_machdep_init(void)
58 {
59         /* Register the cyclic backend. */
60         cyclic_init(&be);
61 }
62
63 static void
64 cyclic_machdep_uninit(void)
65 {
66         int i;
67
68         for (i = 0; i <= mp_maxid; i++)
69                 /* Reset the cyclic clock callback hook. */
70                 lapic_cyclic_clock_func[i] = NULL;
71
72         /* De-register the cyclic backend. */
73         cyclic_uninit();
74 }
75
76 static hrtime_t exp_due[MAXCPU];
77
78 /*
79  * This function is the one registered by the machine dependent
80  * initialiser as the callback for high speed timer events.
81  */
82 static void
83 cyclic_clock(struct trapframe *frame)
84 {
85         cpu_t *c = &solaris_cpu[curcpu];
86
87         if (c->cpu_cyclic != NULL && gethrtime() >= exp_due[curcpu]) {
88                 if (TRAPF_USERMODE(frame)) {
89                         c->cpu_profile_pc = 0;
90                         c->cpu_profile_upc = TRAPF_PC(frame);
91                 } else {
92                         c->cpu_profile_pc = TRAPF_PC(frame);
93                         c->cpu_profile_upc = 0;
94                 }
95
96                 c->cpu_intr_actv = 1;
97
98                 /* Fire any timers that are due. */
99                 cyclic_fire(c);
100
101                 c->cpu_intr_actv = 0;
102         }
103 }
104
105 static void enable(cyb_arg_t arg)
106 {
107         /* Register the cyclic clock callback function. */
108         lapic_cyclic_clock_func[curcpu] = cyclic_clock;
109 }
110
111 static void disable(cyb_arg_t arg)
112 {
113         /* Reset the cyclic clock callback function. */
114         lapic_cyclic_clock_func[curcpu] = NULL;
115 }
116
117 static void reprogram(cyb_arg_t arg, hrtime_t exp)
118 {
119         exp_due[curcpu] = exp;
120 }
121
122 static void xcall(cyb_arg_t arg, cpu_t *c, cyc_func_t func, void *param)
123 {
124         /*
125          * If the target CPU is the current one, just call the
126          * function. This covers the non-SMP case.
127          */
128         if (c == &solaris_cpu[curcpu])
129                 (*func)(param);
130         else
131                 smp_rendezvous_cpus((cpumask_t) (1 << c->cpuid), NULL,
132                     func, smp_no_rendevous_barrier, param);
133 }