xref: /illumos-gate/usr/src/uts/i86pc/io/cbe.c (revision 027bcc9f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21ae115bc7Smrj 
227c478bd9Sstevel@tonic-gate /*
23454ab202SMadhavan Venkataraman  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26ae115bc7Smrj 
277c478bd9Sstevel@tonic-gate #include <sys/systm.h>
287c478bd9Sstevel@tonic-gate #include <sys/cyclic.h>
297c478bd9Sstevel@tonic-gate #include <sys/cyclic_impl.h>
307c478bd9Sstevel@tonic-gate #include <sys/spl.h>
317c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
327c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
337c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
347c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h>
357c478bd9Sstevel@tonic-gate #include <sys/psm_types.h>
36ae115bc7Smrj #include <sys/psm.h>
377c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
387c478bd9Sstevel@tonic-gate #include <sys/clock.h>
392df1fe9cSrandyf #include <sys/x86_archext.h>
407c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
417c478bd9Sstevel@tonic-gate #include <sys/ddi_intr.h>
42e23a7e34Slq #include <sys/avintr.h>
43a3114836SGerry Liu #include <sys/note.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate static int cbe_vector;
467c478bd9Sstevel@tonic-gate static int cbe_ticks = 0;
477c478bd9Sstevel@tonic-gate 
4887a18d3fSMadhavan Venkataraman /*
4987a18d3fSMadhavan Venkataraman  * cbe_xcall_lock is used to protect the xcall globals since the cyclic
5087a18d3fSMadhavan Venkataraman  * reprogramming API does not use cpu_lock.
5187a18d3fSMadhavan Venkataraman  */
5287a18d3fSMadhavan Venkataraman static kmutex_t cbe_xcall_lock;
537c478bd9Sstevel@tonic-gate static cyc_func_t volatile cbe_xcall_func;
547c478bd9Sstevel@tonic-gate static cpu_t *volatile cbe_xcall_cpu;
557c478bd9Sstevel@tonic-gate static void *cbe_xcall_farg;
567c478bd9Sstevel@tonic-gate static cpuset_t cbe_enabled;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static ddi_softint_hdl_impl_t cbe_low_hdl =
594da99751SToomas Soome 	{0, 0, NULL, NULL, 0, NULL, NULL, NULL};
607c478bd9Sstevel@tonic-gate static ddi_softint_hdl_impl_t cbe_clock_hdl =
614da99751SToomas Soome 	{0, 0, NULL, NULL, 0, NULL, NULL, NULL};
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate cyclic_id_t cbe_hres_cyclic;
647c478bd9Sstevel@tonic-gate int cbe_psm_timer_mode = TIMER_ONESHOT;
65b9499e44Smrj static hrtime_t cbe_timer_resolution;
667c478bd9Sstevel@tonic-gate 
672df1fe9cSrandyf extern int tsc_gethrtime_enable;
682df1fe9cSrandyf 
697c478bd9Sstevel@tonic-gate void cbe_hres_tick(void);
707c478bd9Sstevel@tonic-gate 
71*027bcc9fSToomas Soome uint_t
cbe_softclock(caddr_t arg1 __unused,caddr_t arg2 __unused)72*027bcc9fSToomas Soome cbe_softclock(caddr_t arg1 __unused, caddr_t arg2 __unused)
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	cyclic_softint(CPU, CY_LOCK_LEVEL);
757c478bd9Sstevel@tonic-gate 	return (1);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate 
78*027bcc9fSToomas Soome uint_t
cbe_low_level(caddr_t arg1 __unused,caddr_t arg2 __unused)79*027bcc9fSToomas Soome cbe_low_level(caddr_t arg1 __unused, caddr_t arg2 __unused)
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate 	cpu_t *cpu = CPU;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	cyclic_softint(cpu, CY_LOW_LEVEL);
847c478bd9Sstevel@tonic-gate 	return (1);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * We can be in cbe_fire() either due to a cyclic-induced cross call, or due
897c478bd9Sstevel@tonic-gate  * to the timer firing at level-14.  Because cyclic_fire() can tolerate
907c478bd9Sstevel@tonic-gate  * spurious calls, it would not matter if we called cyclic_fire() in both
917c478bd9Sstevel@tonic-gate  * cases.
927c478bd9Sstevel@tonic-gate  */
93*027bcc9fSToomas Soome uint_t
cbe_fire(caddr_t arg1 __unused,caddr_t arg2 __unused)94*027bcc9fSToomas Soome cbe_fire(caddr_t arg1 __unused, caddr_t arg2 __unused)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 	cpu_t *cpu = CPU;
977c478bd9Sstevel@tonic-gate 	processorid_t me = cpu->cpu_id, i;
987c478bd9Sstevel@tonic-gate 	int cross_call = (cbe_xcall_func != NULL && cbe_xcall_cpu == cpu);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	cyclic_fire(cpu);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if (cbe_psm_timer_mode != TIMER_ONESHOT && me == 0 && !cross_call) {
1037c478bd9Sstevel@tonic-gate 		for (i = 1; i < NCPU; i++) {
104ae115bc7Smrj 			if (CPU_IN_SET(cbe_enabled, i)) {
1057c478bd9Sstevel@tonic-gate 				send_dirint(i, CBE_HIGH_PIL);
106ae115bc7Smrj 			}
1077c478bd9Sstevel@tonic-gate 		}
1087c478bd9Sstevel@tonic-gate 	}
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if (cross_call) {
1117c478bd9Sstevel@tonic-gate 		ASSERT(cbe_xcall_func != NULL && cbe_xcall_cpu == cpu);
1127c478bd9Sstevel@tonic-gate 		(*cbe_xcall_func)(cbe_xcall_farg);
1137c478bd9Sstevel@tonic-gate 		cbe_xcall_func = NULL;
1147c478bd9Sstevel@tonic-gate 		cbe_xcall_cpu = NULL;
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	return (1);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1217c478bd9Sstevel@tonic-gate void
cbe_softint(void * arg,cyc_level_t level)1227c478bd9Sstevel@tonic-gate cbe_softint(void *arg, cyc_level_t level)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	switch (level) {
1257c478bd9Sstevel@tonic-gate 	case CY_LOW_LEVEL:
126e23a7e34Slq 		(*setsoftint)(CBE_LOW_PIL, cbe_low_hdl.ih_pending);
1277c478bd9Sstevel@tonic-gate 		break;
1287c478bd9Sstevel@tonic-gate 	case CY_LOCK_LEVEL:
129e23a7e34Slq 		(*setsoftint)(CBE_LOCK_PIL, cbe_clock_hdl.ih_pending);
1307c478bd9Sstevel@tonic-gate 		break;
1317c478bd9Sstevel@tonic-gate 	default:
1327c478bd9Sstevel@tonic-gate 		panic("cbe_softint: unexpected soft level %d", level);
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1377c478bd9Sstevel@tonic-gate void
cbe_reprogram(void * arg,hrtime_t time)1387c478bd9Sstevel@tonic-gate cbe_reprogram(void *arg, hrtime_t time)
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate 	if (cbe_psm_timer_mode == TIMER_ONESHOT)
1417c478bd9Sstevel@tonic-gate 		(*psm_timer_reprogram)(time);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1457c478bd9Sstevel@tonic-gate cyc_cookie_t
cbe_set_level(void * arg,cyc_level_t level)1467c478bd9Sstevel@tonic-gate cbe_set_level(void *arg, cyc_level_t level)
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate 	int ipl;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	switch (level) {
1517c478bd9Sstevel@tonic-gate 	case CY_LOW_LEVEL:
1527c478bd9Sstevel@tonic-gate 		ipl = CBE_LOW_PIL;
1537c478bd9Sstevel@tonic-gate 		break;
1547c478bd9Sstevel@tonic-gate 	case CY_LOCK_LEVEL:
1557c478bd9Sstevel@tonic-gate 		ipl = CBE_LOCK_PIL;
1567c478bd9Sstevel@tonic-gate 		break;
1577c478bd9Sstevel@tonic-gate 	case CY_HIGH_LEVEL:
1587c478bd9Sstevel@tonic-gate 		ipl = CBE_HIGH_PIL;
1597c478bd9Sstevel@tonic-gate 		break;
1607c478bd9Sstevel@tonic-gate 	default:
1617c478bd9Sstevel@tonic-gate 		panic("cbe_set_level: unexpected level %d", level);
1627c478bd9Sstevel@tonic-gate 	}
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	return (splr(ipltospl(ipl)));
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1687c478bd9Sstevel@tonic-gate void
cbe_restore_level(void * arg,cyc_cookie_t cookie)1697c478bd9Sstevel@tonic-gate cbe_restore_level(void *arg, cyc_cookie_t cookie)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate 	splx(cookie);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1757c478bd9Sstevel@tonic-gate void
cbe_xcall(void * arg,cpu_t * dest,cyc_func_t func,void * farg)1767c478bd9Sstevel@tonic-gate cbe_xcall(void *arg, cpu_t *dest, cyc_func_t func, void *farg)
1777c478bd9Sstevel@tonic-gate {
1787c478bd9Sstevel@tonic-gate 	kpreempt_disable();
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	if (dest == CPU) {
1817c478bd9Sstevel@tonic-gate 		(*func)(farg);
1827c478bd9Sstevel@tonic-gate 		kpreempt_enable();
1837c478bd9Sstevel@tonic-gate 		return;
1847c478bd9Sstevel@tonic-gate 	}
1857c478bd9Sstevel@tonic-gate 
18687a18d3fSMadhavan Venkataraman 	mutex_enter(&cbe_xcall_lock);
18787a18d3fSMadhavan Venkataraman 
1887c478bd9Sstevel@tonic-gate 	ASSERT(cbe_xcall_func == NULL);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	cbe_xcall_farg = farg;
1917c478bd9Sstevel@tonic-gate 	membar_producer();
1927c478bd9Sstevel@tonic-gate 	cbe_xcall_cpu = dest;
1937c478bd9Sstevel@tonic-gate 	cbe_xcall_func = func;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	send_dirint(dest->cpu_id, CBE_HIGH_PIL);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	while (cbe_xcall_func != NULL || cbe_xcall_cpu != NULL)
1987c478bd9Sstevel@tonic-gate 		continue;
1997c478bd9Sstevel@tonic-gate 
20087a18d3fSMadhavan Venkataraman 	mutex_exit(&cbe_xcall_lock);
20187a18d3fSMadhavan Venkataraman 
2027c478bd9Sstevel@tonic-gate 	kpreempt_enable();
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate void *
cbe_configure(cpu_t * cpu)2067c478bd9Sstevel@tonic-gate cbe_configure(cpu_t *cpu)
2077c478bd9Sstevel@tonic-gate {
2087c478bd9Sstevel@tonic-gate 	return (cpu);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate 
211a3114836SGerry Liu void
cbe_unconfigure(void * arg)212a3114836SGerry Liu cbe_unconfigure(void *arg)
213a3114836SGerry Liu {
214a3114836SGerry Liu 	_NOTE(ARGUNUSED(arg));
215a3114836SGerry Liu 	ASSERT(!CPU_IN_SET(cbe_enabled, ((cpu_t *)arg)->cpu_id));
216a3114836SGerry Liu }
217a3114836SGerry Liu 
2182df1fe9cSrandyf #ifndef __xpv
2192df1fe9cSrandyf /*
2202df1fe9cSrandyf  * declarations needed for time adjustment
2212df1fe9cSrandyf  */
2222df1fe9cSrandyf extern void	tsc_suspend(void);
2232df1fe9cSrandyf extern void	tsc_resume(void);
2242df1fe9cSrandyf /*
2252df1fe9cSrandyf  * Call the resume function in the cyclic, instead of inline in the
2262df1fe9cSrandyf  * resume path.
2272df1fe9cSrandyf  */
2282df1fe9cSrandyf extern int	tsc_resume_in_cyclic;
2292df1fe9cSrandyf #endif
2302df1fe9cSrandyf 
2312df1fe9cSrandyf /*ARGSUSED*/
2322df1fe9cSrandyf static void
cbe_suspend(cyb_arg_t arg)2332df1fe9cSrandyf cbe_suspend(cyb_arg_t arg)
2342df1fe9cSrandyf {
2352df1fe9cSrandyf #ifndef __xpv
2362df1fe9cSrandyf 	/*
2372df1fe9cSrandyf 	 * This is an x86 backend, so let the tsc_suspend
2382df1fe9cSrandyf 	 * that is specific to x86 platforms do the work.
2392df1fe9cSrandyf 	 */
2402df1fe9cSrandyf 	tsc_suspend();
2412df1fe9cSrandyf #endif
2422df1fe9cSrandyf }
2432df1fe9cSrandyf 
2442df1fe9cSrandyf /*ARGSUSED*/
2452df1fe9cSrandyf static void
cbe_resume(cyb_arg_t arg)2462df1fe9cSrandyf cbe_resume(cyb_arg_t arg)
2472df1fe9cSrandyf {
2482df1fe9cSrandyf #ifndef __xpv
2492df1fe9cSrandyf 	if (tsc_resume_in_cyclic) {
2502df1fe9cSrandyf 		tsc_resume();
2512df1fe9cSrandyf 	}
2522df1fe9cSrandyf #endif
2532df1fe9cSrandyf }
2542df1fe9cSrandyf 
2557c478bd9Sstevel@tonic-gate void
cbe_enable(void * arg)2567c478bd9Sstevel@tonic-gate cbe_enable(void *arg)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate 	processorid_t me = ((cpu_t *)arg)->cpu_id;
2597c478bd9Sstevel@tonic-gate 
260d90554ebSdmick 	/* neither enable nor disable cpu0 if TIMER_PERIODIC is set */
2617c478bd9Sstevel@tonic-gate 	if ((cbe_psm_timer_mode != TIMER_ONESHOT) && (me == 0))
2627c478bd9Sstevel@tonic-gate 		return;
2637c478bd9Sstevel@tonic-gate 
2642df1fe9cSrandyf 	/*
2652df1fe9cSrandyf 	 * Added (me == 0) to the ASSERT because the timer isn't
2662df1fe9cSrandyf 	 * disabled on CPU 0, and cbe_enable is called when we resume.
2672df1fe9cSrandyf 	 */
2682df1fe9cSrandyf 	ASSERT((me == 0) || !CPU_IN_SET(cbe_enabled, me));
2697c478bd9Sstevel@tonic-gate 	CPUSET_ADD(cbe_enabled, me);
2707c478bd9Sstevel@tonic-gate 	if (cbe_psm_timer_mode == TIMER_ONESHOT)
2717c478bd9Sstevel@tonic-gate 		(*psm_timer_enable)();
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate void
cbe_disable(void * arg)2757c478bd9Sstevel@tonic-gate cbe_disable(void *arg)
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate 	processorid_t me = ((cpu_t *)arg)->cpu_id;
2787c478bd9Sstevel@tonic-gate 
279d90554ebSdmick 	/* neither enable nor disable cpu0 if TIMER_PERIODIC is set */
280d90554ebSdmick 	if ((cbe_psm_timer_mode != TIMER_ONESHOT) && (me == 0))
2817c478bd9Sstevel@tonic-gate 		return;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	ASSERT(CPU_IN_SET(cbe_enabled, me));
2847c478bd9Sstevel@tonic-gate 	CPUSET_DEL(cbe_enabled, me);
2857c478bd9Sstevel@tonic-gate 	if (cbe_psm_timer_mode == TIMER_ONESHOT)
2867c478bd9Sstevel@tonic-gate 		(*psm_timer_disable)();
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate /*
290d90554ebSdmick  * Unbound cyclic, called once per tick (every nsec_per_tick ns).
2917c478bd9Sstevel@tonic-gate  */
2927c478bd9Sstevel@tonic-gate void
cbe_hres_tick(void)2937c478bd9Sstevel@tonic-gate cbe_hres_tick(void)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate 	int s;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	dtrace_hres_tick();
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	/*
3007c478bd9Sstevel@tonic-gate 	 * Because hres_tick effectively locks hres_lock, we must be at the
3017c478bd9Sstevel@tonic-gate 	 * same PIL as that used for CLOCK_LOCK.
3027c478bd9Sstevel@tonic-gate 	 */
3037c478bd9Sstevel@tonic-gate 	s = splr(ipltospl(XC_HI_PIL));
3047c478bd9Sstevel@tonic-gate 	hres_tick();
3057c478bd9Sstevel@tonic-gate 	splx(s);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	if ((cbe_ticks % hz) == 0)
3087c478bd9Sstevel@tonic-gate 		(*hrtime_tick)();
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	cbe_ticks++;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate 
314b9499e44Smrj void
cbe_init_pre(void)315b9499e44Smrj cbe_init_pre(void)
316b9499e44Smrj {
317b9499e44Smrj 	cbe_vector = (*psm_get_clockirq)(CBE_HIGH_PIL);
318b9499e44Smrj 
319b9499e44Smrj 	CPUSET_ZERO(cbe_enabled);
320b9499e44Smrj 
321b9499e44Smrj 	cbe_timer_resolution = (*clkinitf)(TIMER_ONESHOT, &cbe_psm_timer_mode);
322b9499e44Smrj }
323b9499e44Smrj 
3247c478bd9Sstevel@tonic-gate void
cbe_init(void)3257c478bd9Sstevel@tonic-gate cbe_init(void)
3267c478bd9Sstevel@tonic-gate {
3277c478bd9Sstevel@tonic-gate 	cyc_backend_t cbe = {
3287c478bd9Sstevel@tonic-gate 		cbe_configure,		/* cyb_configure */
329a3114836SGerry Liu 		cbe_unconfigure,	/* cyb_unconfigure */
3307c478bd9Sstevel@tonic-gate 		cbe_enable,		/* cyb_enable */
3317c478bd9Sstevel@tonic-gate 		cbe_disable,		/* cyb_disable */
3327c478bd9Sstevel@tonic-gate 		cbe_reprogram,		/* cyb_reprogram */
3337c478bd9Sstevel@tonic-gate 		cbe_softint,		/* cyb_softint */
3347c478bd9Sstevel@tonic-gate 		cbe_set_level,		/* cyb_set_level */
3357c478bd9Sstevel@tonic-gate 		cbe_restore_level,	/* cyb_restore_level */
3367c478bd9Sstevel@tonic-gate 		cbe_xcall,		/* cyb_xcall */
3372df1fe9cSrandyf 		cbe_suspend,		/* cyb_suspend */
3382df1fe9cSrandyf 		cbe_resume		/* cyb_resume */
3397c478bd9Sstevel@tonic-gate 	};
3407c478bd9Sstevel@tonic-gate 	cyc_handler_t hdlr;
3417c478bd9Sstevel@tonic-gate 	cyc_time_t when;
3427c478bd9Sstevel@tonic-gate 
34387a18d3fSMadhavan Venkataraman 	mutex_init(&cbe_xcall_lock, NULL, MUTEX_DEFAULT, NULL);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
346b9499e44Smrj 	cyclic_init(&cbe, cbe_timer_resolution);
3477c478bd9Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
3487c478bd9Sstevel@tonic-gate 
349*027bcc9fSToomas Soome 	(void) add_avintr(NULL, CBE_HIGH_PIL, cbe_fire,
3507a364d25Sschwartz 	    "cbe_fire_master", cbe_vector, 0, NULL, NULL, NULL);
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	if (psm_get_ipivect != NULL) {
353*027bcc9fSToomas Soome 		(void) add_avintr(NULL, CBE_HIGH_PIL, cbe_fire,
3547c478bd9Sstevel@tonic-gate 		    "cbe_fire_slave",
3557c478bd9Sstevel@tonic-gate 		    (*psm_get_ipivect)(CBE_HIGH_PIL, PSM_INTR_IPI_HI),
3567a364d25Sschwartz 		    0, NULL, NULL, NULL);
3577c478bd9Sstevel@tonic-gate 	}
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	(void) add_avsoftintr((void *)&cbe_clock_hdl, CBE_LOCK_PIL,
360*027bcc9fSToomas Soome 	    cbe_softclock, "softclock", NULL, NULL);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	(void) add_avsoftintr((void *)&cbe_low_hdl, CBE_LOW_PIL,
363*027bcc9fSToomas Soome 	    cbe_low_level, "low level", NULL, NULL);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	hdlr.cyh_level = CY_HIGH_LEVEL;
3687c478bd9Sstevel@tonic-gate 	hdlr.cyh_func = (cyc_func_t)cbe_hres_tick;
3697c478bd9Sstevel@tonic-gate 	hdlr.cyh_arg = NULL;
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	when.cyt_when = 0;
3727c478bd9Sstevel@tonic-gate 	when.cyt_interval = nsec_per_tick;
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	cbe_hres_cyclic = cyclic_add(&hdlr, &when);
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	if (psm_post_cyclic_setup != NULL)
3777c478bd9Sstevel@tonic-gate 		(*psm_post_cyclic_setup)(NULL);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
3807c478bd9Sstevel@tonic-gate }
381