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: stable/9/sys/cddl/dev/cyclic/i386/cyclic_machdep.c 222813 2011-06-07 08:46:13Z attilio $
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 static void cyclic_clock(struct trapframe *frame);
34
35 static cyc_backend_t be = {
36 NULL, /* cyb_configure */
37 NULL, /* cyb_unconfigure */
38 enable,
39 disable,
40 reprogram,
41 xcall,
42 NULL /* cyb_arg_t cyb_arg */
43 };
44
45 static void
cyclic_ap_start(void * dummy)46 cyclic_ap_start(void *dummy)
47 {
48 /* Initialise the rest of the CPUs. */
49 cyclic_clock_func = cyclic_clock;
50 cyclic_mp_init();
51 }
52
53 SYSINIT(cyclic_ap_start, SI_SUB_SMP, SI_ORDER_ANY, cyclic_ap_start, NULL);
54
55 /*
56 * Machine dependent cyclic subsystem initialisation.
57 */
58 static void
cyclic_machdep_init(void)59 cyclic_machdep_init(void)
60 {
61 /* Register the cyclic backend. */
62 cyclic_init(&be);
63 }
64
65 static void
cyclic_machdep_uninit(void)66 cyclic_machdep_uninit(void)
67 {
68 /* De-register the cyclic backend. */
69 cyclic_uninit();
70 }
71
72 /*
73 * This function is the one registered by the machine dependent
74 * initialiser as the callback for high speed timer events.
75 */
76 static void
cyclic_clock(struct trapframe * frame)77 cyclic_clock(struct trapframe *frame)
78 {
79 cpu_t *c = &solaris_cpu[curcpu];
80
81 if (c->cpu_cyclic != NULL) {
82 if (TRAPF_USERMODE(frame)) {
83 c->cpu_profile_pc = 0;
84 c->cpu_profile_upc = TRAPF_PC(frame);
85 } else {
86 c->cpu_profile_pc = TRAPF_PC(frame);
87 c->cpu_profile_upc = 0;
88 }
89
90 c->cpu_intr_actv = 1;
91
92 /* Fire any timers that are due. */
93 cyclic_fire(c);
94
95 c->cpu_intr_actv = 0;
96 }
97 }
98
99 static void
enable(cyb_arg_t arg __unused)100 enable(cyb_arg_t arg __unused)
101 {
102
103 }
104
105 static void
disable(cyb_arg_t arg __unused)106 disable(cyb_arg_t arg __unused)
107 {
108
109 }
110
111 static void
reprogram(cyb_arg_t arg __unused,hrtime_t exp)112 reprogram(cyb_arg_t arg __unused, hrtime_t exp)
113 {
114 struct bintime bt;
115 struct timespec ts;
116
117 ts.tv_sec = exp / 1000000000;
118 ts.tv_nsec = exp % 1000000000;
119 timespec2bintime(&ts, &bt);
120 clocksource_cyc_set(&bt);
121 }
122
xcall(cyb_arg_t arg __unused,cpu_t * c,cyc_func_t func,void * param)123 static void xcall(cyb_arg_t arg __unused, cpu_t *c, cyc_func_t func,
124 void *param)
125 {
126 cpuset_t cpus;
127
128 CPU_SETOF(c->cpuid, &cpus);
129 smp_rendezvous_cpus(cpus,
130 smp_no_rendevous_barrier, func, smp_no_rendevous_barrier, param);
131 }
132