xref: /onnv-gate/usr/src/uts/i86pc/os/mp_machdep.c (revision 2006:11a559c797d5)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2006Sandrei  * Common Development and Distribution License (the "License").
6*2006Sandrei  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
221228Sandrei  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #define	PSMI_1_5
290Sstevel@tonic-gate #include <sys/smp_impldefs.h>
300Sstevel@tonic-gate #include <sys/psm.h>
310Sstevel@tonic-gate #include <sys/psm_modctl.h>
320Sstevel@tonic-gate #include <sys/pit.h>
330Sstevel@tonic-gate #include <sys/cmn_err.h>
340Sstevel@tonic-gate #include <sys/strlog.h>
350Sstevel@tonic-gate #include <sys/clock.h>
360Sstevel@tonic-gate #include <sys/debug.h>
370Sstevel@tonic-gate #include <sys/rtc.h>
380Sstevel@tonic-gate #include <sys/x86_archext.h>
390Sstevel@tonic-gate #include <sys/cpupart.h>
400Sstevel@tonic-gate #include <sys/cpuvar.h>
410Sstevel@tonic-gate #include <sys/chip.h>
420Sstevel@tonic-gate #include <sys/disp.h>
430Sstevel@tonic-gate #include <sys/cpu.h>
440Sstevel@tonic-gate #include <sys/archsystm.h>
45916Sschwartz #include <sys/mach_intr.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	OFFSETOF(s, m)		(size_t)(&(((s *)0)->m))
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  *	Local function prototypes
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate static int mp_disable_intr(processorid_t cpun);
530Sstevel@tonic-gate static void mp_enable_intr(processorid_t cpun);
540Sstevel@tonic-gate static void mach_init();
550Sstevel@tonic-gate static void mach_picinit();
560Sstevel@tonic-gate static uint64_t mach_calchz(uint32_t pit_counter, uint64_t *processor_clks);
570Sstevel@tonic-gate static int machhztomhz(uint64_t cpu_freq_hz);
580Sstevel@tonic-gate static uint64_t mach_getcpufreq(void);
590Sstevel@tonic-gate static void mach_fixcpufreq(void);
600Sstevel@tonic-gate static int mach_clkinit(int, int *);
610Sstevel@tonic-gate static void mach_smpinit(void);
62999Slq150181 static void mach_set_softintr(int ipl, struct av_softinfo *);
630Sstevel@tonic-gate static void mach_cpu_start(int cpun);
640Sstevel@tonic-gate static int mach_softlvl_to_vect(int ipl);
650Sstevel@tonic-gate static void mach_get_platform(int owner);
660Sstevel@tonic-gate static void mach_construct_info();
670Sstevel@tonic-gate static int mach_translate_irq(dev_info_t *dip, int irqno);
680Sstevel@tonic-gate static int mach_intr_ops(dev_info_t *, ddi_intr_handle_impl_t *,
690Sstevel@tonic-gate     psm_intr_op_t, int *);
700Sstevel@tonic-gate static timestruc_t mach_tod_get(void);
710Sstevel@tonic-gate static void mach_tod_set(timestruc_t ts);
720Sstevel@tonic-gate static void mach_notify_error(int level, char *errmsg);
730Sstevel@tonic-gate static hrtime_t dummy_hrtime(void);
740Sstevel@tonic-gate static void dummy_scalehrtime(hrtime_t *);
750Sstevel@tonic-gate static void cpu_halt(void);
760Sstevel@tonic-gate static void cpu_wakeup(cpu_t *, int);
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  *	External reference functions
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate extern void return_instr();
810Sstevel@tonic-gate extern timestruc_t (*todgetf)(void);
820Sstevel@tonic-gate extern void (*todsetf)(timestruc_t);
830Sstevel@tonic-gate extern long gmt_lag;
840Sstevel@tonic-gate extern uint64_t freq_tsc(uint32_t *);
850Sstevel@tonic-gate #if defined(__i386)
860Sstevel@tonic-gate extern uint64_t freq_notsc(uint32_t *);
870Sstevel@tonic-gate #endif
880Sstevel@tonic-gate extern void pc_gethrestime(timestruc_t *);
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  *	PSM functions initialization
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate void (*psm_shutdownf)(int, int)	= return_instr;
940Sstevel@tonic-gate void (*psm_preshutdownf)(int, int) = return_instr;
950Sstevel@tonic-gate void (*psm_notifyf)(int)	= return_instr;
960Sstevel@tonic-gate void (*psm_set_idle_cpuf)(int)	= return_instr;
970Sstevel@tonic-gate void (*psm_unset_idle_cpuf)(int) = return_instr;
980Sstevel@tonic-gate void (*psminitf)()		= mach_init;
990Sstevel@tonic-gate void (*picinitf)() 		= return_instr;
1000Sstevel@tonic-gate int (*clkinitf)(int, int *) 	= (int (*)(int, int *))return_instr;
1010Sstevel@tonic-gate void (*cpu_startf)() 		= return_instr;
1020Sstevel@tonic-gate int (*ap_mlsetup)() 		= (int (*)(void))return_instr;
1030Sstevel@tonic-gate void (*send_dirintf)() 		= return_instr;
1040Sstevel@tonic-gate void (*setspl)(int)		= return_instr;
1050Sstevel@tonic-gate int (*addspl)(int, int, int, int) = (int (*)(int, int, int, int))return_instr;
1060Sstevel@tonic-gate int (*delspl)(int, int, int, int) = (int (*)(int, int, int, int))return_instr;
107999Slq150181 void (*setsoftint)(int, struct av_softinfo *)=
108999Slq150181 	(void (*)(int, struct av_softinfo *))return_instr;
1090Sstevel@tonic-gate int (*slvltovect)(int)		= (int (*)(int))return_instr;
1100Sstevel@tonic-gate int (*setlvl)(int, int *)	= (int (*)(int, int *))return_instr;
1110Sstevel@tonic-gate void (*setlvlx)(int, int)	= (void (*)(int, int))return_instr;
1120Sstevel@tonic-gate int (*psm_disable_intr)(int)	= mp_disable_intr;
1130Sstevel@tonic-gate void (*psm_enable_intr)(int)	= mp_enable_intr;
1140Sstevel@tonic-gate hrtime_t (*gethrtimef)(void)	= dummy_hrtime;
1150Sstevel@tonic-gate hrtime_t (*gethrtimeunscaledf)(void)	= dummy_hrtime;
1160Sstevel@tonic-gate void (*scalehrtimef)(hrtime_t *)	= dummy_scalehrtime;
1170Sstevel@tonic-gate int (*psm_translate_irq)(dev_info_t *, int) = mach_translate_irq;
1180Sstevel@tonic-gate void (*gethrestimef)(timestruc_t *) = pc_gethrestime;
1190Sstevel@tonic-gate int (*psm_todgetf)(todinfo_t *) = (int (*)(todinfo_t *))return_instr;
1200Sstevel@tonic-gate int (*psm_todsetf)(todinfo_t *) = (int (*)(todinfo_t *))return_instr;
1210Sstevel@tonic-gate void (*psm_notify_error)(int, char *) = (void (*)(int, char *))NULL;
1220Sstevel@tonic-gate int (*psm_get_clockirq)(int) = NULL;
1230Sstevel@tonic-gate int (*psm_get_ipivect)(int, int) = NULL;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate int (*psm_clkinit)(int) = NULL;
1260Sstevel@tonic-gate void (*psm_timer_reprogram)(hrtime_t) = NULL;
1270Sstevel@tonic-gate void (*psm_timer_enable)(void) = NULL;
1280Sstevel@tonic-gate void (*psm_timer_disable)(void) = NULL;
1290Sstevel@tonic-gate void (*psm_post_cyclic_setup)(void *arg) = NULL;
1300Sstevel@tonic-gate int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *, psm_intr_op_t,
1310Sstevel@tonic-gate     int *) = mach_intr_ops;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate void (*notify_error)(int, char *) = (void (*)(int, char *))return_instr;
1340Sstevel@tonic-gate void (*hrtime_tick)(void)	= return_instr;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate int tsc_gethrtime_enable = 1;
1370Sstevel@tonic-gate int tsc_gethrtime_initted = 0;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Local Static Data
1410Sstevel@tonic-gate  */
1420Sstevel@tonic-gate static struct psm_ops mach_ops;
1430Sstevel@tonic-gate static struct psm_ops *mach_set[4] = {&mach_ops, NULL, NULL, NULL};
1440Sstevel@tonic-gate static ushort_t mach_ver[4] = {0, 0, 0, 0};
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * If non-zero, idle cpus will "halted" when there's
1480Sstevel@tonic-gate  * no work to do.
1490Sstevel@tonic-gate  */
1500Sstevel@tonic-gate int	halt_idle_cpus = 1;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #if defined(__amd64)
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * If non-zero, will use cr8 for interrupt priority masking
1550Sstevel@tonic-gate  * We declare this here since install_spl is called from here
1560Sstevel@tonic-gate  * (where this is checked).
1570Sstevel@tonic-gate  */
1580Sstevel@tonic-gate int	intpri_use_cr8 = 0;
1590Sstevel@tonic-gate #endif	/* __amd64 */
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate #ifdef	_SIMULATOR_SUPPORT
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate int simulator_run = 0;	/* patch to non-zero if running under simics */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #endif	/* _SIMULATOR_SUPPORT */
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate /* ARGSUSED */
1680Sstevel@tonic-gate void
1690Sstevel@tonic-gate chip_plat_define_chip(cpu_t *cp, chip_def_t *cd)
1700Sstevel@tonic-gate {
1711228Sandrei 	if ((x86_feature & (X86_HTT|X86_CMP)) == X86_HTT) {
1720Sstevel@tonic-gate 		/*
1731228Sandrei 		 * Single-core Pentiums with Hyper-Threading enabled.
1740Sstevel@tonic-gate 		 */
1750Sstevel@tonic-gate 		cd->chipd_type = CHIP_SMT;
1761228Sandrei 	} else if ((x86_feature & (X86_HTT|X86_CMP)) == X86_CMP) {
1771228Sandrei 		/*
1781228Sandrei 		 * Multi-core Opterons or Multi-core Pentiums with
1791228Sandrei 		 * Hyper-Threading disabled.
1801228Sandrei 		 */
1811228Sandrei 		cd->chipd_type = CHIP_CMP_SPLIT_CACHE;
1821228Sandrei 	} else if ((x86_feature & (X86_HTT|X86_CMP)) == (X86_HTT|X86_CMP)) {
1831228Sandrei 		/*
1841228Sandrei 		 * Multi-core Pentiums with Hyper-Threading enabled.
1851228Sandrei 		 */
1861228Sandrei 		cd->chipd_type = CHIP_CMT;
1871228Sandrei 	} else {
1881228Sandrei 		/*
1891228Sandrei 		 * Single-core/single-threaded chips.
1901228Sandrei 		 */
1910Sstevel@tonic-gate 		cd->chipd_type = CHIP_DEFAULT;
1921228Sandrei 	}
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	cd->chipd_rechoose_adj = 0;
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate  * Routine to ensure initial callers to hrtime gets 0 as return
1990Sstevel@tonic-gate  */
2000Sstevel@tonic-gate static hrtime_t
2010Sstevel@tonic-gate dummy_hrtime(void)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate 	return (0);
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate /* ARGSUSED */
2070Sstevel@tonic-gate static void
2080Sstevel@tonic-gate dummy_scalehrtime(hrtime_t *ticks)
2090Sstevel@tonic-gate {}
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate /*
2120Sstevel@tonic-gate  * Halt the present CPU until awoken via an interrupt
2130Sstevel@tonic-gate  */
2140Sstevel@tonic-gate static void
2150Sstevel@tonic-gate cpu_halt(void)
2160Sstevel@tonic-gate {
2170Sstevel@tonic-gate 	cpu_t		*cpup = CPU;
2180Sstevel@tonic-gate 	processorid_t	cpun = cpup->cpu_id;
219711Sesaxe 	cpupart_t	*cp = cpup->cpu_part;
2200Sstevel@tonic-gate 	int		hset_update = 1;
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	/*
2230Sstevel@tonic-gate 	 * If this CPU is online, and there's multiple CPUs
2240Sstevel@tonic-gate 	 * in the system, then we should notate our halting
2250Sstevel@tonic-gate 	 * by adding ourselves to the partition's halted CPU
2260Sstevel@tonic-gate 	 * bitmap. This allows other CPUs to find/awaken us when
2270Sstevel@tonic-gate 	 * work becomes available.
2280Sstevel@tonic-gate 	 */
2290Sstevel@tonic-gate 	if (cpup->cpu_flags & CPU_OFFLINE || ncpus == 1)
2300Sstevel@tonic-gate 		hset_update = 0;
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 	/*
2330Sstevel@tonic-gate 	 * Add ourselves to the partition's halted CPUs bitmask
2340Sstevel@tonic-gate 	 * and set our HALTED flag, if necessary.
2350Sstevel@tonic-gate 	 *
236711Sesaxe 	 * When a thread becomes runnable, it is placed on the queue
237711Sesaxe 	 * and then the halted cpuset is checked to determine who
238711Sesaxe 	 * (if anyone) should be awoken. We therefore need to first
239711Sesaxe 	 * add ourselves to the halted cpuset, and and then check if there
240711Sesaxe 	 * is any work available.
241711Sesaxe 	 *
2420Sstevel@tonic-gate 	 * Note that memory barriers after updating the HALTED flag
2430Sstevel@tonic-gate 	 * are not necessary since an atomic operation (updating the bitmap)
2440Sstevel@tonic-gate 	 * immediately follows. On x86 the atomic operation acts as a
2450Sstevel@tonic-gate 	 * memory barrier for the update of cpu_disp_flags.
2460Sstevel@tonic-gate 	 */
2470Sstevel@tonic-gate 	if (hset_update) {
2480Sstevel@tonic-gate 		cpup->cpu_disp_flags |= CPU_DISP_HALTED;
2490Sstevel@tonic-gate 		CPUSET_ATOMIC_ADD(cp->cp_haltset, cpun);
2500Sstevel@tonic-gate 	}
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 	/*
2530Sstevel@tonic-gate 	 * Check to make sure there's really nothing to do.
254711Sesaxe 	 * Work destined for this CPU may become available after
255711Sesaxe 	 * this check. We'll be notified through the clearing of our
256711Sesaxe 	 * bit in the halted CPU bitmask, and a poke.
2570Sstevel@tonic-gate 	 */
2580Sstevel@tonic-gate 	if (disp_anywork()) {
2590Sstevel@tonic-gate 		if (hset_update) {
2600Sstevel@tonic-gate 			cpup->cpu_disp_flags &= ~CPU_DISP_HALTED;
2610Sstevel@tonic-gate 			CPUSET_ATOMIC_DEL(cp->cp_haltset, cpun);
2620Sstevel@tonic-gate 		}
263711Sesaxe 		return;
264711Sesaxe 	}
265711Sesaxe 
266711Sesaxe 	/*
267711Sesaxe 	 * We're on our way to being halted.
268711Sesaxe 	 *
269711Sesaxe 	 * Disable interrupts now, so that we'll awaken immediately
270711Sesaxe 	 * after halting if someone tries to poke us between now and
271711Sesaxe 	 * the time we actually halt.
272711Sesaxe 	 *
273711Sesaxe 	 * We check for the presence of our bit after disabling interrupts.
274711Sesaxe 	 * If it's cleared, we'll return. If the bit is cleared after
275711Sesaxe 	 * we check then the poke will pop us out of the halted state.
276711Sesaxe 	 *
277711Sesaxe 	 * This means that the ordering of the poke and the clearing
278711Sesaxe 	 * of the bit by cpu_wakeup is important.
279711Sesaxe 	 * cpu_wakeup() must clear, then poke.
280711Sesaxe 	 * cpu_halt() must disable interrupts, then check for the bit.
281711Sesaxe 	 */
282711Sesaxe 	cli();
283711Sesaxe 
284711Sesaxe 	if (hset_update && !CPU_IN_SET(cp->cp_haltset, cpun)) {
285711Sesaxe 		cpup->cpu_disp_flags &= ~CPU_DISP_HALTED;
286711Sesaxe 		sti();
287711Sesaxe 		return;
288711Sesaxe 	}
289711Sesaxe 
290711Sesaxe 	/*
291711Sesaxe 	 * The check for anything locally runnable is here for performance
292711Sesaxe 	 * and isn't needed for correctness. disp_nrunnable ought to be
293711Sesaxe 	 * in our cache still, so it's inexpensive to check, and if there
294711Sesaxe 	 * is anything runnable we won't have to wait for the poke.
295711Sesaxe 	 */
296711Sesaxe 	if (cpup->cpu_disp->disp_nrunnable != 0) {
297711Sesaxe 		if (hset_update) {
298711Sesaxe 			cpup->cpu_disp_flags &= ~CPU_DISP_HALTED;
299711Sesaxe 			CPUSET_ATOMIC_DEL(cp->cp_haltset, cpun);
300711Sesaxe 		}
3010Sstevel@tonic-gate 		sti();
3020Sstevel@tonic-gate 		return;
3030Sstevel@tonic-gate 	}
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	/*
3060Sstevel@tonic-gate 	 * Call the halt sequence:
3070Sstevel@tonic-gate 	 * sti
3080Sstevel@tonic-gate 	 * hlt
3090Sstevel@tonic-gate 	 */
3100Sstevel@tonic-gate 	i86_halt();
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	/*
3130Sstevel@tonic-gate 	 * We're no longer halted
3140Sstevel@tonic-gate 	 */
3150Sstevel@tonic-gate 	if (hset_update) {
3160Sstevel@tonic-gate 		cpup->cpu_disp_flags &= ~CPU_DISP_HALTED;
3170Sstevel@tonic-gate 		CPUSET_ATOMIC_DEL(cp->cp_haltset, cpun);
3180Sstevel@tonic-gate 	}
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate /*
3230Sstevel@tonic-gate  * If "cpu" is halted, then wake it up clearing its halted bit in advance.
3240Sstevel@tonic-gate  * Otherwise, see if other CPUs in the cpu partition are halted and need to
3250Sstevel@tonic-gate  * be woken up so that they can steal the thread we placed on this CPU.
3260Sstevel@tonic-gate  * This function is only used on MP systems.
3270Sstevel@tonic-gate  */
3280Sstevel@tonic-gate static void
3290Sstevel@tonic-gate cpu_wakeup(cpu_t *cpu, int bound)
3300Sstevel@tonic-gate {
3310Sstevel@tonic-gate 	uint_t		cpu_found;
3320Sstevel@tonic-gate 	int		result;
3330Sstevel@tonic-gate 	cpupart_t	*cp;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	cp = cpu->cpu_part;
3360Sstevel@tonic-gate 	if (CPU_IN_SET(cp->cp_haltset, cpu->cpu_id)) {
3370Sstevel@tonic-gate 		/*
3380Sstevel@tonic-gate 		 * Clear the halted bit for that CPU since it will be
3390Sstevel@tonic-gate 		 * poked in a moment.
3400Sstevel@tonic-gate 		 */
3410Sstevel@tonic-gate 		CPUSET_ATOMIC_DEL(cp->cp_haltset, cpu->cpu_id);
3420Sstevel@tonic-gate 		/*
3430Sstevel@tonic-gate 		 * We may find the current CPU present in the halted cpuset
3440Sstevel@tonic-gate 		 * if we're in the context of an interrupt that occurred
3450Sstevel@tonic-gate 		 * before we had a chance to clear our bit in cpu_halt().
3460Sstevel@tonic-gate 		 * Poking ourself is obviously unnecessary, since if
3470Sstevel@tonic-gate 		 * we're here, we're not halted.
3480Sstevel@tonic-gate 		 */
3490Sstevel@tonic-gate 		if (cpu != CPU)
3500Sstevel@tonic-gate 			poke_cpu(cpu->cpu_id);
3510Sstevel@tonic-gate 		return;
3520Sstevel@tonic-gate 	} else {
3530Sstevel@tonic-gate 		/*
3540Sstevel@tonic-gate 		 * This cpu isn't halted, but it's idle or undergoing a
3550Sstevel@tonic-gate 		 * context switch. No need to awaken anyone else.
3560Sstevel@tonic-gate 		 */
3570Sstevel@tonic-gate 		if (cpu->cpu_thread == cpu->cpu_idle_thread ||
3580Sstevel@tonic-gate 		    cpu->cpu_disp_flags & CPU_DISP_DONTSTEAL)
3590Sstevel@tonic-gate 			return;
3600Sstevel@tonic-gate 	}
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate 	/*
3630Sstevel@tonic-gate 	 * No need to wake up other CPUs if the thread we just enqueued
3640Sstevel@tonic-gate 	 * is bound.
3650Sstevel@tonic-gate 	 */
3660Sstevel@tonic-gate 	if (bound)
3670Sstevel@tonic-gate 		return;
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	/*
3710Sstevel@tonic-gate 	 * See if there's any other halted CPUs. If there are, then
3720Sstevel@tonic-gate 	 * select one, and awaken it.
3730Sstevel@tonic-gate 	 * It's possible that after we find a CPU, somebody else
3740Sstevel@tonic-gate 	 * will awaken it before we get the chance.
3750Sstevel@tonic-gate 	 * In that case, look again.
3760Sstevel@tonic-gate 	 */
3770Sstevel@tonic-gate 	do {
3780Sstevel@tonic-gate 		CPUSET_FIND(cp->cp_haltset, cpu_found);
3790Sstevel@tonic-gate 		if (cpu_found == CPUSET_NOTINSET)
3800Sstevel@tonic-gate 			return;
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 		ASSERT(cpu_found >= 0 && cpu_found < NCPU);
3830Sstevel@tonic-gate 		CPUSET_ATOMIC_XDEL(cp->cp_haltset, cpu_found, result);
3840Sstevel@tonic-gate 	} while (result < 0);
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	if (cpu_found != CPU->cpu_id)
3870Sstevel@tonic-gate 		poke_cpu(cpu_found);
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate static int
3910Sstevel@tonic-gate mp_disable_intr(int cpun)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate 	/*
3940Sstevel@tonic-gate 	 * switch to the offline cpu
3950Sstevel@tonic-gate 	 */
3960Sstevel@tonic-gate 	affinity_set(cpun);
3970Sstevel@tonic-gate 	/*
3980Sstevel@tonic-gate 	 * raise ipl to just below cross call
3990Sstevel@tonic-gate 	 */
4000Sstevel@tonic-gate 	splx(XC_MED_PIL-1);
4010Sstevel@tonic-gate 	/*
4020Sstevel@tonic-gate 	 *	set base spl to prevent the next swtch to idle from
4030Sstevel@tonic-gate 	 *	lowering back to ipl 0
4040Sstevel@tonic-gate 	 */
4050Sstevel@tonic-gate 	CPU->cpu_intr_actv |= (1 << (XC_MED_PIL-1));
4060Sstevel@tonic-gate 	set_base_spl();
4070Sstevel@tonic-gate 	affinity_clear();
4080Sstevel@tonic-gate 	return (DDI_SUCCESS);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate static void
4120Sstevel@tonic-gate mp_enable_intr(int cpun)
4130Sstevel@tonic-gate {
4140Sstevel@tonic-gate 	/*
4150Sstevel@tonic-gate 	 * switch to the online cpu
4160Sstevel@tonic-gate 	 */
4170Sstevel@tonic-gate 	affinity_set(cpun);
4180Sstevel@tonic-gate 	/*
4190Sstevel@tonic-gate 	 * clear the interrupt active mask
4200Sstevel@tonic-gate 	 */
4210Sstevel@tonic-gate 	CPU->cpu_intr_actv &= ~(1 << (XC_MED_PIL-1));
4220Sstevel@tonic-gate 	set_base_spl();
4230Sstevel@tonic-gate 	(void) spl0();
4240Sstevel@tonic-gate 	affinity_clear();
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate static void
4280Sstevel@tonic-gate mach_get_platform(int owner)
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate 	void		**srv_opsp;
4310Sstevel@tonic-gate 	void		**clt_opsp;
4320Sstevel@tonic-gate 	int		i;
4330Sstevel@tonic-gate 	int		total_ops;
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate 	/* fix up psm ops */
4360Sstevel@tonic-gate 	srv_opsp = (void **)mach_set[0];
4370Sstevel@tonic-gate 	clt_opsp = (void **)mach_set[owner];
4380Sstevel@tonic-gate 	if (mach_ver[owner] == (ushort_t)PSM_INFO_VER01)
4390Sstevel@tonic-gate 		total_ops = sizeof (struct psm_ops_ver01) /
4400Sstevel@tonic-gate 				sizeof (void (*)(void));
4410Sstevel@tonic-gate 	else if (mach_ver[owner] == (ushort_t)PSM_INFO_VER01_1)
4420Sstevel@tonic-gate 		/* no psm_notify_func */
4430Sstevel@tonic-gate 		total_ops = OFFSETOF(struct psm_ops, psm_notify_func) /
4440Sstevel@tonic-gate 		    sizeof (void (*)(void));
4450Sstevel@tonic-gate 	else if (mach_ver[owner] == (ushort_t)PSM_INFO_VER01_2)
4460Sstevel@tonic-gate 		/* no psm_timer funcs */
4470Sstevel@tonic-gate 		total_ops = OFFSETOF(struct psm_ops, psm_timer_reprogram) /
4480Sstevel@tonic-gate 		    sizeof (void (*)(void));
4490Sstevel@tonic-gate 	else if (mach_ver[owner] == (ushort_t)PSM_INFO_VER01_3)
4500Sstevel@tonic-gate 		/* no psm_preshutdown function */
4510Sstevel@tonic-gate 		total_ops = OFFSETOF(struct psm_ops, psm_preshutdown) /
4520Sstevel@tonic-gate 		    sizeof (void (*)(void));
4530Sstevel@tonic-gate 	else if (mach_ver[owner] == (ushort_t)PSM_INFO_VER01_4)
4540Sstevel@tonic-gate 		/* no psm_preshutdown function */
4550Sstevel@tonic-gate 		total_ops = OFFSETOF(struct psm_ops, psm_intr_ops) /
4560Sstevel@tonic-gate 		    sizeof (void (*)(void));
4570Sstevel@tonic-gate 	else
4580Sstevel@tonic-gate 		total_ops = sizeof (struct psm_ops) / sizeof (void (*)(void));
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 	/*
4610Sstevel@tonic-gate 	 * Save the version of the PSM module, in case we need to
4620Sstevel@tonic-gate 	 * bahave differently based on version.
4630Sstevel@tonic-gate 	 */
4640Sstevel@tonic-gate 	mach_ver[0] = mach_ver[owner];
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	for (i = 0; i < total_ops; i++)
4670Sstevel@tonic-gate 		if (clt_opsp[i] != NULL)
4680Sstevel@tonic-gate 			srv_opsp[i] = clt_opsp[i];
4690Sstevel@tonic-gate }
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate static void
4720Sstevel@tonic-gate mach_construct_info()
4730Sstevel@tonic-gate {
4740Sstevel@tonic-gate 	register struct psm_sw *swp;
4750Sstevel@tonic-gate 	int	mach_cnt[PSM_OWN_OVERRIDE+1] = {0};
4760Sstevel@tonic-gate 	int	conflict_owner = 0;
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	if (psmsw->psw_forw == psmsw)
4790Sstevel@tonic-gate 		panic("No valid PSM modules found");
4800Sstevel@tonic-gate 	mutex_enter(&psmsw_lock);
4810Sstevel@tonic-gate 	for (swp = psmsw->psw_forw; swp != psmsw; swp = swp->psw_forw) {
4820Sstevel@tonic-gate 		if (!(swp->psw_flag & PSM_MOD_IDENTIFY))
4830Sstevel@tonic-gate 			continue;
4840Sstevel@tonic-gate 		mach_set[swp->psw_infop->p_owner] = swp->psw_infop->p_ops;
4850Sstevel@tonic-gate 		mach_ver[swp->psw_infop->p_owner] = swp->psw_infop->p_version;
4860Sstevel@tonic-gate 		mach_cnt[swp->psw_infop->p_owner]++;
4870Sstevel@tonic-gate 	}
4880Sstevel@tonic-gate 	mutex_exit(&psmsw_lock);
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 	mach_get_platform(PSM_OWN_SYS_DEFAULT);
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	/* check to see are there any conflicts */
4930Sstevel@tonic-gate 	if (mach_cnt[PSM_OWN_EXCLUSIVE] > 1)
4940Sstevel@tonic-gate 		conflict_owner = PSM_OWN_EXCLUSIVE;
4950Sstevel@tonic-gate 	if (mach_cnt[PSM_OWN_OVERRIDE] > 1)
4960Sstevel@tonic-gate 		conflict_owner = PSM_OWN_OVERRIDE;
4970Sstevel@tonic-gate 	if (conflict_owner) {
4980Sstevel@tonic-gate 		/* remove all psm modules except uppc */
4990Sstevel@tonic-gate 		cmn_err(CE_WARN,
5000Sstevel@tonic-gate 			"Conflicts detected on the following PSM modules:");
5010Sstevel@tonic-gate 		mutex_enter(&psmsw_lock);
5020Sstevel@tonic-gate 		for (swp = psmsw->psw_forw; swp != psmsw; swp = swp->psw_forw) {
5030Sstevel@tonic-gate 			if (swp->psw_infop->p_owner == conflict_owner)
5040Sstevel@tonic-gate 				cmn_err(CE_WARN, "%s ",
5050Sstevel@tonic-gate 					swp->psw_infop->p_mach_idstring);
5060Sstevel@tonic-gate 		}
5070Sstevel@tonic-gate 		mutex_exit(&psmsw_lock);
5080Sstevel@tonic-gate 		cmn_err(CE_WARN,
5090Sstevel@tonic-gate 			"Setting the system back to SINGLE processor mode!");
5100Sstevel@tonic-gate 		cmn_err(CE_WARN,
5110Sstevel@tonic-gate 		    "Please edit /etc/mach to remove the invalid PSM module.");
5120Sstevel@tonic-gate 		return;
5130Sstevel@tonic-gate 	}
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate 	if (mach_set[PSM_OWN_EXCLUSIVE])
5160Sstevel@tonic-gate 		mach_get_platform(PSM_OWN_EXCLUSIVE);
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 	if (mach_set[PSM_OWN_OVERRIDE])
5190Sstevel@tonic-gate 		mach_get_platform(PSM_OWN_OVERRIDE);
5200Sstevel@tonic-gate }
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate static void
5230Sstevel@tonic-gate mach_init()
5240Sstevel@tonic-gate {
5250Sstevel@tonic-gate 	register struct psm_ops  *pops;
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 	mach_construct_info();
5280Sstevel@tonic-gate 
5290Sstevel@tonic-gate 	pops = mach_set[0];
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate 	/* register the interrupt and clock initialization rotuines */
5320Sstevel@tonic-gate 	picinitf = mach_picinit;
5330Sstevel@tonic-gate 	clkinitf = mach_clkinit;
5340Sstevel@tonic-gate 	psm_get_clockirq = pops->psm_get_clockirq;
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 	/* register the interrupt setup code */
5370Sstevel@tonic-gate 	slvltovect = mach_softlvl_to_vect;
5380Sstevel@tonic-gate 	addspl	= pops->psm_addspl;
5390Sstevel@tonic-gate 	delspl	= pops->psm_delspl;
5400Sstevel@tonic-gate 
5410Sstevel@tonic-gate 	if (pops->psm_translate_irq)
5420Sstevel@tonic-gate 		psm_translate_irq = pops->psm_translate_irq;
5430Sstevel@tonic-gate 	if (pops->psm_intr_ops)
5440Sstevel@tonic-gate 		psm_intr_ops = pops->psm_intr_ops;
5450Sstevel@tonic-gate 	if (pops->psm_tod_get) {
5460Sstevel@tonic-gate 		todgetf = mach_tod_get;
5470Sstevel@tonic-gate 		psm_todgetf = pops->psm_tod_get;
5480Sstevel@tonic-gate 	}
5490Sstevel@tonic-gate 	if (pops->psm_tod_set) {
5500Sstevel@tonic-gate 		todsetf = mach_tod_set;
5510Sstevel@tonic-gate 		psm_todsetf = pops->psm_tod_set;
5520Sstevel@tonic-gate 	}
5530Sstevel@tonic-gate 	if (pops->psm_notify_error) {
5540Sstevel@tonic-gate 		psm_notify_error = mach_notify_error;
5550Sstevel@tonic-gate 		notify_error = pops->psm_notify_error;
5560Sstevel@tonic-gate 	}
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate 	(*pops->psm_softinit)();
5590Sstevel@tonic-gate 
5600Sstevel@tonic-gate 	/*
5610Sstevel@tonic-gate 	 * Initialize the dispatcher's function hooks
5620Sstevel@tonic-gate 	 * to enable CPU halting when idle
5630Sstevel@tonic-gate 	 */
5640Sstevel@tonic-gate #if defined(_SIMULATOR_SUPPORT)
5650Sstevel@tonic-gate 	if (halt_idle_cpus && !simulator_run)
5660Sstevel@tonic-gate 		idle_cpu = cpu_halt;
5670Sstevel@tonic-gate #else
5680Sstevel@tonic-gate 	if (halt_idle_cpus)
5690Sstevel@tonic-gate 		idle_cpu = cpu_halt;
5700Sstevel@tonic-gate #endif	/* _SIMULATOR_SUPPORT */
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate 	mach_smpinit();
5730Sstevel@tonic-gate }
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate static void
5760Sstevel@tonic-gate mach_smpinit(void)
5770Sstevel@tonic-gate {
578*2006Sandrei 	struct psm_ops  *pops;
579*2006Sandrei 	processorid_t cpu_id;
580*2006Sandrei 	int cnt;
581*2006Sandrei 	cpuset_t cpumask;
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 	pops = mach_set[0];
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate 	cpu_id = -1;
5860Sstevel@tonic-gate 	cpu_id = (*pops->psm_get_next_processorid)(cpu_id);
587*2006Sandrei 	for (cnt = 0, CPUSET_ZERO(cpumask); cpu_id != -1; cnt++) {
588*2006Sandrei 		CPUSET_ADD(cpumask, cpu_id);
5890Sstevel@tonic-gate 		cpu_id = (*pops->psm_get_next_processorid)(cpu_id);
5900Sstevel@tonic-gate 	}
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate 	mp_cpus = cpumask;
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate 	/* MP related routines */
5950Sstevel@tonic-gate 	cpu_startf = mach_cpu_start;
5960Sstevel@tonic-gate 	ap_mlsetup = pops->psm_post_cpu_start;
5970Sstevel@tonic-gate 	send_dirintf = pops->psm_send_ipi;
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate 	/* optional MP related routines */
6000Sstevel@tonic-gate 	if (pops->psm_shutdown)
6010Sstevel@tonic-gate 		psm_shutdownf = pops->psm_shutdown;
6020Sstevel@tonic-gate 	if (pops->psm_preshutdown)
6030Sstevel@tonic-gate 		psm_preshutdownf = pops->psm_preshutdown;
6040Sstevel@tonic-gate 	if (pops->psm_notify_func)
6050Sstevel@tonic-gate 		psm_notifyf = pops->psm_notify_func;
6060Sstevel@tonic-gate 	if (pops->psm_set_idlecpu)
6070Sstevel@tonic-gate 		psm_set_idle_cpuf = pops->psm_set_idlecpu;
6080Sstevel@tonic-gate 	if (pops->psm_unset_idlecpu)
6090Sstevel@tonic-gate 		psm_unset_idle_cpuf = pops->psm_unset_idlecpu;
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate 	psm_clkinit = pops->psm_clkinit;
6120Sstevel@tonic-gate 
6130Sstevel@tonic-gate 	if (pops->psm_timer_reprogram)
6140Sstevel@tonic-gate 		psm_timer_reprogram = pops->psm_timer_reprogram;
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate 	if (pops->psm_timer_enable)
6170Sstevel@tonic-gate 		psm_timer_enable = pops->psm_timer_enable;
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate 	if (pops->psm_timer_disable)
6200Sstevel@tonic-gate 		psm_timer_disable = pops->psm_timer_disable;
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate 	if (pops->psm_post_cyclic_setup)
6230Sstevel@tonic-gate 		psm_post_cyclic_setup = pops->psm_post_cyclic_setup;
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate 	/* check for multiple cpu's */
6260Sstevel@tonic-gate 	if (cnt < 2)
6270Sstevel@tonic-gate 		return;
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 	/* check for MP platforms */
6300Sstevel@tonic-gate 	if (pops->psm_cpu_start == NULL)
6310Sstevel@tonic-gate 		return;
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate 	/*
6340Sstevel@tonic-gate 	 * Set the dispatcher hook to enable cpu "wake up"
6350Sstevel@tonic-gate 	 * when a thread becomes runnable.
6360Sstevel@tonic-gate 	 */
6370Sstevel@tonic-gate #if defined(_SIMULATOR_SUPPORT)
6380Sstevel@tonic-gate 	if (halt_idle_cpus && !simulator_run) {
6390Sstevel@tonic-gate 		disp_enq_thread = cpu_wakeup;
6400Sstevel@tonic-gate 	}
6410Sstevel@tonic-gate #else
6420Sstevel@tonic-gate 	if (halt_idle_cpus) {
6430Sstevel@tonic-gate 		disp_enq_thread = cpu_wakeup;
6440Sstevel@tonic-gate 	}
6450Sstevel@tonic-gate #endif	/* _SIMULATOR_SUPPORT */
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate 	if (pops->psm_disable_intr)
6480Sstevel@tonic-gate 		psm_disable_intr = pops->psm_disable_intr;
6490Sstevel@tonic-gate 	if (pops->psm_enable_intr)
6500Sstevel@tonic-gate 		psm_enable_intr  = pops->psm_enable_intr;
6510Sstevel@tonic-gate 
6520Sstevel@tonic-gate 	psm_get_ipivect = pops->psm_get_ipivect;
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate 	(void) add_avintr((void *)NULL, XC_HI_PIL, xc_serv, "xc_hi_intr",
6550Sstevel@tonic-gate 		(*pops->psm_get_ipivect)(XC_HI_PIL, PSM_INTR_IPI_HI),
656916Sschwartz 		(caddr_t)X_CALL_HIPRI, NULL, NULL, NULL);
6570Sstevel@tonic-gate 	(void) add_avintr((void *)NULL, XC_MED_PIL, xc_serv, "xc_med_intr",
6580Sstevel@tonic-gate 		(*pops->psm_get_ipivect)(XC_MED_PIL, PSM_INTR_IPI_LO),
659916Sschwartz 		(caddr_t)X_CALL_MEDPRI, NULL, NULL, NULL);
6600Sstevel@tonic-gate 
6610Sstevel@tonic-gate 	(void) (*pops->psm_get_ipivect)(XC_CPUPOKE_PIL, PSM_INTR_POKE);
6620Sstevel@tonic-gate }
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate static void
6650Sstevel@tonic-gate mach_picinit()
6660Sstevel@tonic-gate {
667*2006Sandrei 	struct psm_ops  *pops;
6680Sstevel@tonic-gate 	extern void install_spl(void);	/* XXX: belongs in a header file */
6690Sstevel@tonic-gate #if defined(__amd64) && defined(DEBUG)
6700Sstevel@tonic-gate 	extern void *spl_patch, *slow_spl, *setsplhi_patch, *slow_setsplhi;
6710Sstevel@tonic-gate #endif
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 	pops = mach_set[0];
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate 	/* register the interrupt handlers */
6760Sstevel@tonic-gate 	setlvl = pops->psm_intr_enter;
6770Sstevel@tonic-gate 	setlvlx = pops->psm_intr_exit;
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 	/* initialize the interrupt hardware */
6800Sstevel@tonic-gate 	(*pops->psm_picinit)();
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate 	/* set interrupt mask for current ipl */
6830Sstevel@tonic-gate 	setspl = pops->psm_setspl;
6840Sstevel@tonic-gate 	setspl(CPU->cpu_pri);
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate 	/* Install proper spl routine now that we can Program the PIC   */
6870Sstevel@tonic-gate #if defined(__amd64)
6880Sstevel@tonic-gate 	/*
6890Sstevel@tonic-gate 	 * It would be better if we could check this at compile time
6900Sstevel@tonic-gate 	 */
6910Sstevel@tonic-gate 	ASSERT(((uintptr_t)&slow_setsplhi - (uintptr_t)&setsplhi_patch < 128) &&
6920Sstevel@tonic-gate 		((uintptr_t)&slow_spl - (uintptr_t)&spl_patch < 128));
6930Sstevel@tonic-gate #endif
6940Sstevel@tonic-gate 	install_spl();
6950Sstevel@tonic-gate }
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate uint_t	cpu_freq;	/* MHz */
6980Sstevel@tonic-gate uint64_t cpu_freq_hz;	/* measured (in hertz) */
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate #define	MEGA_HZ		1000000
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate static uint64_t
7030Sstevel@tonic-gate mach_calchz(uint32_t pit_counter, uint64_t *processor_clks)
7040Sstevel@tonic-gate {
7050Sstevel@tonic-gate 	uint64_t cpu_hz;
7060Sstevel@tonic-gate 
7070Sstevel@tonic-gate 	if ((pit_counter == 0) || (*processor_clks == 0) ||
7080Sstevel@tonic-gate 	    (*processor_clks > (((uint64_t)-1) / PIT_HZ)))
7090Sstevel@tonic-gate 		return (0);
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 	cpu_hz = ((uint64_t)PIT_HZ * *processor_clks) / pit_counter;
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate 	return (cpu_hz);
7140Sstevel@tonic-gate }
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate static uint64_t
7170Sstevel@tonic-gate mach_getcpufreq(void)
7180Sstevel@tonic-gate {
7190Sstevel@tonic-gate 	uint32_t pit_counter;
7200Sstevel@tonic-gate 	uint64_t processor_clks;
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate 	if (x86_feature & X86_TSC) {
7230Sstevel@tonic-gate 		/*
7240Sstevel@tonic-gate 		 * We have a TSC. freq_tsc() knows how to measure the number
7250Sstevel@tonic-gate 		 * of clock cycles sampled against the PIT.
7260Sstevel@tonic-gate 		 */
7270Sstevel@tonic-gate 		processor_clks = freq_tsc(&pit_counter);
7280Sstevel@tonic-gate 		return (mach_calchz(pit_counter, &processor_clks));
7290Sstevel@tonic-gate 	} else if (x86_vendor == X86_VENDOR_Cyrix || x86_type == X86_TYPE_P5) {
7300Sstevel@tonic-gate #if defined(__amd64)
7310Sstevel@tonic-gate 		panic("mach_getcpufreq: no TSC!");
7320Sstevel@tonic-gate #elif defined(__i386)
7330Sstevel@tonic-gate 		/*
7340Sstevel@tonic-gate 		 * We are a Cyrix based on a 6x86 core or an Intel Pentium
7350Sstevel@tonic-gate 		 * for which freq_notsc() knows how to measure the number of
7360Sstevel@tonic-gate 		 * elapsed clock cycles sampled against the PIT
7370Sstevel@tonic-gate 		 */
7380Sstevel@tonic-gate 		processor_clks = freq_notsc(&pit_counter);
7390Sstevel@tonic-gate 		return (mach_calchz(pit_counter, &processor_clks));
7400Sstevel@tonic-gate #endif	/* __i386 */
7410Sstevel@tonic-gate 	}
7420Sstevel@tonic-gate 
7430Sstevel@tonic-gate 	/* We do not know how to calculate cpu frequency for this cpu. */
7440Sstevel@tonic-gate 	return (0);
7450Sstevel@tonic-gate }
7460Sstevel@tonic-gate 
7470Sstevel@tonic-gate /*
7480Sstevel@tonic-gate  * If the clock speed of a cpu is found to be reported incorrectly, do not add
7490Sstevel@tonic-gate  * to this array, instead improve the accuracy of the algorithm that determines
7500Sstevel@tonic-gate  * the clock speed of the processor or extend the implementation to support the
7510Sstevel@tonic-gate  * vendor as appropriate. This is here only to support adjusting the speed on
7520Sstevel@tonic-gate  * older slower processors that mach_fixcpufreq() would not be able to account
7530Sstevel@tonic-gate  * for otherwise.
7540Sstevel@tonic-gate  */
7550Sstevel@tonic-gate static int x86_cpu_freq[] = { 60, 75, 80, 90, 120, 160, 166, 175, 180, 233 };
7560Sstevel@tonic-gate 
7570Sstevel@tonic-gate /*
7580Sstevel@tonic-gate  * On fast processors the clock frequency that is measured may be off by
7590Sstevel@tonic-gate  * a few MHz from the value printed on the part. This is a combination of
7600Sstevel@tonic-gate  * the factors that for such fast parts being off by this much is within
7610Sstevel@tonic-gate  * the tolerances for manufacture and because of the difficulties in the
7620Sstevel@tonic-gate  * measurement that can lead to small error. This function uses some
7630Sstevel@tonic-gate  * heuristics in order to tweak the value that was measured to match what
7640Sstevel@tonic-gate  * is most likely printed on the part.
7650Sstevel@tonic-gate  *
7660Sstevel@tonic-gate  * Some examples:
7670Sstevel@tonic-gate  * 	AMD Athlon 1000 mhz measured as 998 mhz
7680Sstevel@tonic-gate  * 	Intel Pentium III Xeon 733 mhz measured as 731 mhz
7690Sstevel@tonic-gate  * 	Intel Pentium IV 1500 mhz measured as 1495mhz
7700Sstevel@tonic-gate  *
7710Sstevel@tonic-gate  * If in the future this function is no longer sufficient to correct
7720Sstevel@tonic-gate  * for the error in the measurement, then the algorithm used to perform
7730Sstevel@tonic-gate  * the measurement will have to be improved in order to increase accuracy
7740Sstevel@tonic-gate  * rather than adding horrible and questionable kludges here.
7750Sstevel@tonic-gate  *
7760Sstevel@tonic-gate  * This is called after the cyclics subsystem because of the potential
7770Sstevel@tonic-gate  * that the heuristics within may give a worse estimate of the clock
7780Sstevel@tonic-gate  * frequency than the value that was measured.
7790Sstevel@tonic-gate  */
7800Sstevel@tonic-gate static void
7810Sstevel@tonic-gate mach_fixcpufreq(void)
7820Sstevel@tonic-gate {
7830Sstevel@tonic-gate 	uint32_t freq, mul, near66, delta66, near50, delta50, fixed, delta, i;
7840Sstevel@tonic-gate 
7850Sstevel@tonic-gate 	freq = (uint32_t)cpu_freq;
7860Sstevel@tonic-gate 
7870Sstevel@tonic-gate 	/*
7880Sstevel@tonic-gate 	 * Find the nearest integer multiple of 200/3 (about 66) MHz to the
7890Sstevel@tonic-gate 	 * measured speed taking into account that the 667 MHz parts were
7900Sstevel@tonic-gate 	 * the first to round-up.
7910Sstevel@tonic-gate 	 */
7920Sstevel@tonic-gate 	mul = (uint32_t)((3 * (uint64_t)freq + 100) / 200);
7930Sstevel@tonic-gate 	near66 = (uint32_t)((200 * (uint64_t)mul + ((mul >= 10) ? 1 : 0)) / 3);
7940Sstevel@tonic-gate 	delta66 = (near66 > freq) ? (near66 - freq) : (freq - near66);
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 	/* Find the nearest integer multiple of 50 MHz to the measured speed */
7970Sstevel@tonic-gate 	mul = (freq + 25) / 50;
7980Sstevel@tonic-gate 	near50 = mul * 50;
7990Sstevel@tonic-gate 	delta50 = (near50 > freq) ? (near50 - freq) : (freq - near50);
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate 	/* Find the closer of the two */
8020Sstevel@tonic-gate 	if (delta66 < delta50) {
8030Sstevel@tonic-gate 		fixed = near66;
8040Sstevel@tonic-gate 		delta = delta66;
8050Sstevel@tonic-gate 	} else {
8060Sstevel@tonic-gate 		fixed = near50;
8070Sstevel@tonic-gate 		delta = delta50;
8080Sstevel@tonic-gate 	}
8090Sstevel@tonic-gate 
8100Sstevel@tonic-gate 	if (fixed > INT_MAX)
8110Sstevel@tonic-gate 		return;
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 	/*
8140Sstevel@tonic-gate 	 * Some older parts have a core clock frequency that is not an
8150Sstevel@tonic-gate 	 * integral multiple of 50 or 66 MHz. Check if one of the old
8160Sstevel@tonic-gate 	 * clock frequencies is closer to the measured value than any
8170Sstevel@tonic-gate 	 * of the integral multiples of 50 an 66, and if so set fixed
8180Sstevel@tonic-gate 	 * and delta appropriately to represent the closest value.
8190Sstevel@tonic-gate 	 */
8200Sstevel@tonic-gate 	i = sizeof (x86_cpu_freq) / sizeof (int);
8210Sstevel@tonic-gate 	while (i > 0) {
8220Sstevel@tonic-gate 		i--;
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate 		if (x86_cpu_freq[i] <= freq) {
8250Sstevel@tonic-gate 			mul = freq - x86_cpu_freq[i];
8260Sstevel@tonic-gate 
8270Sstevel@tonic-gate 			if (mul < delta) {
8280Sstevel@tonic-gate 				fixed = x86_cpu_freq[i];
8290Sstevel@tonic-gate 				delta = mul;
8300Sstevel@tonic-gate 			}
8310Sstevel@tonic-gate 
8320Sstevel@tonic-gate 			break;
8330Sstevel@tonic-gate 		}
8340Sstevel@tonic-gate 
8350Sstevel@tonic-gate 		mul = x86_cpu_freq[i] - freq;
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate 		if (mul < delta) {
8380Sstevel@tonic-gate 			fixed = x86_cpu_freq[i];
8390Sstevel@tonic-gate 			delta = mul;
8400Sstevel@tonic-gate 		}
8410Sstevel@tonic-gate 	}
8420Sstevel@tonic-gate 
8430Sstevel@tonic-gate 	/*
8440Sstevel@tonic-gate 	 * Set a reasonable maximum for how much to correct the measured
8450Sstevel@tonic-gate 	 * result by. This check is here to prevent the adjustment made
8460Sstevel@tonic-gate 	 * by this function from being more harm than good. It is entirely
8470Sstevel@tonic-gate 	 * possible that in the future parts will be made that are not
8480Sstevel@tonic-gate 	 * integral multiples of 66 or 50 in clock frequency or that
8490Sstevel@tonic-gate 	 * someone may overclock a part to some odd frequency. If the
8500Sstevel@tonic-gate 	 * measured value is farther from the corrected value than
8510Sstevel@tonic-gate 	 * allowed, then assume the corrected value is in error and use
8520Sstevel@tonic-gate 	 * the measured value.
8530Sstevel@tonic-gate 	 */
8540Sstevel@tonic-gate 	if (6 < delta)
8550Sstevel@tonic-gate 		return;
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate 	cpu_freq = (int)fixed;
8580Sstevel@tonic-gate }
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 
8610Sstevel@tonic-gate static int
8620Sstevel@tonic-gate machhztomhz(uint64_t cpu_freq_hz)
8630Sstevel@tonic-gate {
8640Sstevel@tonic-gate 	uint64_t cpu_mhz;
8650Sstevel@tonic-gate 
8660Sstevel@tonic-gate 	/* Round to nearest MHZ */
8670Sstevel@tonic-gate 	cpu_mhz = (cpu_freq_hz + (MEGA_HZ / 2)) / MEGA_HZ;
8680Sstevel@tonic-gate 
8690Sstevel@tonic-gate 	if (cpu_mhz > INT_MAX)
8700Sstevel@tonic-gate 		return (0);
8710Sstevel@tonic-gate 
8720Sstevel@tonic-gate 	return ((int)cpu_mhz);
8730Sstevel@tonic-gate 
8740Sstevel@tonic-gate }
8750Sstevel@tonic-gate 
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate static int
8780Sstevel@tonic-gate mach_clkinit(int preferred_mode, int *set_mode)
8790Sstevel@tonic-gate {
8800Sstevel@tonic-gate 	register struct psm_ops  *pops;
8810Sstevel@tonic-gate 	int resolution;
8820Sstevel@tonic-gate 
8830Sstevel@tonic-gate 	pops = mach_set[0];
8840Sstevel@tonic-gate 
8850Sstevel@tonic-gate #ifdef	_SIMULATOR_SUPPORT
8860Sstevel@tonic-gate 	if (!simulator_run)
8870Sstevel@tonic-gate 		cpu_freq_hz = mach_getcpufreq();
8880Sstevel@tonic-gate 	else
8890Sstevel@tonic-gate 		cpu_freq_hz = 40000000; /* use 40 Mhz (hack for simulator) */
8900Sstevel@tonic-gate #else
8910Sstevel@tonic-gate 	cpu_freq_hz = mach_getcpufreq();
8920Sstevel@tonic-gate #endif	/* _SIMULATOR_SUPPORT */
8930Sstevel@tonic-gate 
8940Sstevel@tonic-gate 	cpu_freq = machhztomhz(cpu_freq_hz);
8950Sstevel@tonic-gate 
8960Sstevel@tonic-gate 	if (!(x86_feature & X86_TSC) || (cpu_freq == 0))
8970Sstevel@tonic-gate 		tsc_gethrtime_enable = 0;
8980Sstevel@tonic-gate 
8990Sstevel@tonic-gate 	if (tsc_gethrtime_enable) {
9000Sstevel@tonic-gate 		tsc_hrtimeinit(cpu_freq_hz);
9010Sstevel@tonic-gate 		gethrtimef = tsc_gethrtime;
9020Sstevel@tonic-gate 		gethrtimeunscaledf = tsc_gethrtimeunscaled;
9030Sstevel@tonic-gate 		scalehrtimef = tsc_scalehrtime;
9040Sstevel@tonic-gate 		hrtime_tick = tsc_tick;
9050Sstevel@tonic-gate 		tsc_gethrtime_initted = 1;
9060Sstevel@tonic-gate 	} else {
9070Sstevel@tonic-gate 		if (pops->psm_hrtimeinit)
9080Sstevel@tonic-gate 			(*pops->psm_hrtimeinit)();
9090Sstevel@tonic-gate 		gethrtimef = pops->psm_gethrtime;
9100Sstevel@tonic-gate 		gethrtimeunscaledf = gethrtimef;
9110Sstevel@tonic-gate 		/* scalehrtimef will remain dummy */
9120Sstevel@tonic-gate 	}
9130Sstevel@tonic-gate 
9140Sstevel@tonic-gate 	mach_fixcpufreq();
9150Sstevel@tonic-gate 
9160Sstevel@tonic-gate 	if (mach_ver[0] >= PSM_INFO_VER01_3) {
9170Sstevel@tonic-gate 		if ((preferred_mode == TIMER_ONESHOT) &&
9180Sstevel@tonic-gate 		    (tsc_gethrtime_enable)) {
9190Sstevel@tonic-gate 
9200Sstevel@tonic-gate 			resolution = (*pops->psm_clkinit)(0);
9210Sstevel@tonic-gate 			if (resolution != 0)  {
9220Sstevel@tonic-gate 				*set_mode = TIMER_ONESHOT;
9230Sstevel@tonic-gate 				return (resolution);
9240Sstevel@tonic-gate 			}
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate 		}
9270Sstevel@tonic-gate 
9280Sstevel@tonic-gate 		/*
9290Sstevel@tonic-gate 		 * either periodic mode was requested or could not set to
9300Sstevel@tonic-gate 		 * one-shot mode
9310Sstevel@tonic-gate 		 */
9320Sstevel@tonic-gate 		resolution = (*pops->psm_clkinit)(hz);
9330Sstevel@tonic-gate 		/*
9340Sstevel@tonic-gate 		 * psm should be able to do periodic, so we do not check
9350Sstevel@tonic-gate 		 * for return value of psm_clkinit here.
9360Sstevel@tonic-gate 		 */
9370Sstevel@tonic-gate 		*set_mode = TIMER_PERIODIC;
9380Sstevel@tonic-gate 		return (resolution);
9390Sstevel@tonic-gate 	} else {
9400Sstevel@tonic-gate 		/*
9410Sstevel@tonic-gate 		 * PSMI interface prior to PSMI_3 does not define a return
9420Sstevel@tonic-gate 		 * value for psm_clkinit, so the return value is ignored.
9430Sstevel@tonic-gate 		 */
9440Sstevel@tonic-gate 		(void) (*pops->psm_clkinit)(hz);
9450Sstevel@tonic-gate 		*set_mode = TIMER_PERIODIC;
9460Sstevel@tonic-gate 		return (nsec_per_tick);
9470Sstevel@tonic-gate 	}
9480Sstevel@tonic-gate }
9490Sstevel@tonic-gate 
950999Slq150181 /*ARGSUSED*/
951999Slq150181 static void
952999Slq150181 mach_psm_set_softintr(int ipl, struct av_softinfo *pending)
953999Slq150181 {
954999Slq150181 	register struct psm_ops  *pops;
955999Slq150181 
956999Slq150181 	/* invoke hardware interrupt					*/
957999Slq150181 	pops = mach_set[0];
958999Slq150181 	(*pops->psm_set_softintr)(ipl);
959999Slq150181 }
960999Slq150181 
9610Sstevel@tonic-gate static int
9620Sstevel@tonic-gate mach_softlvl_to_vect(register int ipl)
9630Sstevel@tonic-gate {
9640Sstevel@tonic-gate 	register int softvect;
9650Sstevel@tonic-gate 	register struct psm_ops  *pops;
9660Sstevel@tonic-gate 
9670Sstevel@tonic-gate 	pops = mach_set[0];
9680Sstevel@tonic-gate 
9690Sstevel@tonic-gate 	/* check for null handler for set soft interrupt call		*/
9700Sstevel@tonic-gate 	if (pops->psm_set_softintr == NULL) {
971999Slq150181 		setsoftint = av_set_softint_pending;
9720Sstevel@tonic-gate 		return (PSM_SV_SOFTWARE);
9730Sstevel@tonic-gate 	}
9740Sstevel@tonic-gate 
9750Sstevel@tonic-gate 	softvect = (*pops->psm_softlvl_to_irq)(ipl);
9760Sstevel@tonic-gate 	/* check for hardware scheme					*/
9770Sstevel@tonic-gate 	if (softvect > PSM_SV_SOFTWARE) {
978999Slq150181 		setsoftint = mach_psm_set_softintr;
9790Sstevel@tonic-gate 		return (softvect);
9800Sstevel@tonic-gate 	}
9810Sstevel@tonic-gate 
9820Sstevel@tonic-gate 	if (softvect == PSM_SV_SOFTWARE)
983999Slq150181 		setsoftint = av_set_softint_pending;
9840Sstevel@tonic-gate 	else	/* hardware and software mixed scheme			*/
9850Sstevel@tonic-gate 		setsoftint = mach_set_softintr;
9860Sstevel@tonic-gate 
9870Sstevel@tonic-gate 	return (PSM_SV_SOFTWARE);
9880Sstevel@tonic-gate }
9890Sstevel@tonic-gate 
9900Sstevel@tonic-gate static void
991999Slq150181 mach_set_softintr(register int ipl, struct av_softinfo *pending)
9920Sstevel@tonic-gate {
9930Sstevel@tonic-gate 	register struct psm_ops  *pops;
9940Sstevel@tonic-gate 
9950Sstevel@tonic-gate 	/* set software pending bits					*/
996999Slq150181 	av_set_softint_pending(ipl, pending);
9970Sstevel@tonic-gate 
9980Sstevel@tonic-gate 	/*	check if dosoftint will be called at the end of intr	*/
9990Sstevel@tonic-gate 	if (CPU_ON_INTR(CPU) || (curthread->t_intr))
10000Sstevel@tonic-gate 		return;
10010Sstevel@tonic-gate 
10020Sstevel@tonic-gate 	/* invoke hardware interrupt					*/
10030Sstevel@tonic-gate 	pops = mach_set[0];
10040Sstevel@tonic-gate 	(*pops->psm_set_softintr)(ipl);
10050Sstevel@tonic-gate }
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate static void
10080Sstevel@tonic-gate mach_cpu_start(register int cpun)
10090Sstevel@tonic-gate {
10100Sstevel@tonic-gate 	register struct psm_ops  *pops;
10110Sstevel@tonic-gate 	int	i;
10120Sstevel@tonic-gate 
10130Sstevel@tonic-gate 	pops = mach_set[0];
10140Sstevel@tonic-gate 
10150Sstevel@tonic-gate 	(*pops->psm_cpu_start)(cpun, rm_platter_va);
10160Sstevel@tonic-gate 
10170Sstevel@tonic-gate 	/* wait for the auxillary cpu to be ready			*/
10180Sstevel@tonic-gate 	for (i = 20000; i; i--) {
10190Sstevel@tonic-gate 		if (cpu[cpun]->cpu_flags & CPU_READY)
10200Sstevel@tonic-gate 			return;
10210Sstevel@tonic-gate 		drv_usecwait(100);
10220Sstevel@tonic-gate 	}
10230Sstevel@tonic-gate }
10240Sstevel@tonic-gate 
10250Sstevel@tonic-gate /*ARGSUSED*/
10260Sstevel@tonic-gate static int
10270Sstevel@tonic-gate mach_translate_irq(dev_info_t *dip, int irqno)
10280Sstevel@tonic-gate {
10290Sstevel@tonic-gate 	return (irqno);	/* default to NO translation */
10300Sstevel@tonic-gate }
10310Sstevel@tonic-gate 
10320Sstevel@tonic-gate static timestruc_t
10330Sstevel@tonic-gate mach_tod_get(void)
10340Sstevel@tonic-gate {
10350Sstevel@tonic-gate 	timestruc_t ts;
10360Sstevel@tonic-gate 	todinfo_t tod;
10370Sstevel@tonic-gate 	static int mach_range_warn = 1;	/* warn only once */
10380Sstevel@tonic-gate 
10390Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
10400Sstevel@tonic-gate 
10410Sstevel@tonic-gate 	/* The year returned from is the last 2 digit only */
10420Sstevel@tonic-gate 	if ((*psm_todgetf)(&tod)) {
10430Sstevel@tonic-gate 		ts.tv_sec = 0;
10440Sstevel@tonic-gate 		ts.tv_nsec = 0;
10450Sstevel@tonic-gate 		tod_fault_reset();
10460Sstevel@tonic-gate 		return (ts);
10470Sstevel@tonic-gate 	}
10480Sstevel@tonic-gate 
10490Sstevel@tonic-gate 	/* assume that we wrap the rtc year back to zero at 2000 */
10500Sstevel@tonic-gate 	if (tod.tod_year < 69) {
10510Sstevel@tonic-gate 		if (mach_range_warn && tod.tod_year > 38) {
10520Sstevel@tonic-gate 			cmn_err(CE_WARN, "hardware real-time clock is out "
10530Sstevel@tonic-gate 				"of range -- time needs to be reset");
10540Sstevel@tonic-gate 			mach_range_warn = 0;
10550Sstevel@tonic-gate 		}
10560Sstevel@tonic-gate 		tod.tod_year += 100;
10570Sstevel@tonic-gate 	}
10580Sstevel@tonic-gate 
10590Sstevel@tonic-gate 	/* tod_to_utc uses 1900 as base for the year */
10600Sstevel@tonic-gate 	ts.tv_sec = tod_to_utc(tod) + gmt_lag;
10610Sstevel@tonic-gate 	ts.tv_nsec = 0;
10620Sstevel@tonic-gate 
10630Sstevel@tonic-gate 	return (ts);
10640Sstevel@tonic-gate }
10650Sstevel@tonic-gate 
10660Sstevel@tonic-gate static void
10670Sstevel@tonic-gate mach_tod_set(timestruc_t ts)
10680Sstevel@tonic-gate {
10690Sstevel@tonic-gate 	todinfo_t tod = utc_to_tod(ts.tv_sec - gmt_lag);
10700Sstevel@tonic-gate 
10710Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate 	if (tod.tod_year >= 100)
10740Sstevel@tonic-gate 		tod.tod_year -= 100;
10750Sstevel@tonic-gate 
10760Sstevel@tonic-gate 	(*psm_todsetf)(&tod);
10770Sstevel@tonic-gate }
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate static void
10800Sstevel@tonic-gate mach_notify_error(int level, char *errmsg)
10810Sstevel@tonic-gate {
10820Sstevel@tonic-gate 	/*
10830Sstevel@tonic-gate 	 * SL_FATAL is pass in once panicstr is set, deliver it
10840Sstevel@tonic-gate 	 * as CE_PANIC.  Also, translate SL_ codes back to CE_
10850Sstevel@tonic-gate 	 * codes for the psmi handler
10860Sstevel@tonic-gate 	 */
10870Sstevel@tonic-gate 	if (level & SL_FATAL)
10880Sstevel@tonic-gate 		(*notify_error)(CE_PANIC, errmsg);
10890Sstevel@tonic-gate 	else if (level & SL_WARN)
10900Sstevel@tonic-gate 		(*notify_error)(CE_WARN, errmsg);
10910Sstevel@tonic-gate 	else if (level & SL_NOTE)
10920Sstevel@tonic-gate 		(*notify_error)(CE_NOTE, errmsg);
10930Sstevel@tonic-gate 	else if (level & SL_CONSOLE)
10940Sstevel@tonic-gate 		(*notify_error)(CE_CONT, errmsg);
10950Sstevel@tonic-gate }
10960Sstevel@tonic-gate 
10970Sstevel@tonic-gate /*
10980Sstevel@tonic-gate  * It provides the default basic intr_ops interface for the new DDI
10990Sstevel@tonic-gate  * interrupt framework if the PSM doesn't have one.
11000Sstevel@tonic-gate  *
11010Sstevel@tonic-gate  * Input:
11020Sstevel@tonic-gate  * dip     - pointer to the dev_info structure of the requested device
11030Sstevel@tonic-gate  * hdlp    - pointer to the internal interrupt handle structure for the
11040Sstevel@tonic-gate  *	     requested interrupt
11050Sstevel@tonic-gate  * intr_op - opcode for this call
11060Sstevel@tonic-gate  * result  - pointer to the integer that will hold the result to be
11070Sstevel@tonic-gate  *	     passed back if return value is PSM_SUCCESS
11080Sstevel@tonic-gate  *
11090Sstevel@tonic-gate  * Output:
11100Sstevel@tonic-gate  * return value is either PSM_SUCCESS or PSM_FAILURE
11110Sstevel@tonic-gate  */
11120Sstevel@tonic-gate static int
11130Sstevel@tonic-gate mach_intr_ops(dev_info_t *dip, ddi_intr_handle_impl_t *hdlp,
11140Sstevel@tonic-gate     psm_intr_op_t intr_op, int *result)
11150Sstevel@tonic-gate {
11160Sstevel@tonic-gate 	struct intrspec *ispec;
11170Sstevel@tonic-gate 
11180Sstevel@tonic-gate 	switch (intr_op) {
11190Sstevel@tonic-gate 	case PSM_INTR_OP_CHECK_MSI:
11200Sstevel@tonic-gate 		*result = hdlp->ih_type & ~(DDI_INTR_TYPE_MSI |
11210Sstevel@tonic-gate 			    DDI_INTR_TYPE_MSIX);
11220Sstevel@tonic-gate 		break;
11230Sstevel@tonic-gate 	case PSM_INTR_OP_ALLOC_VECTORS:
11240Sstevel@tonic-gate 		if (hdlp->ih_type == DDI_INTR_TYPE_FIXED)
11250Sstevel@tonic-gate 			*result = 1;
11260Sstevel@tonic-gate 		else
11270Sstevel@tonic-gate 			*result = 0;
11280Sstevel@tonic-gate 		break;
11290Sstevel@tonic-gate 	case PSM_INTR_OP_FREE_VECTORS:
11300Sstevel@tonic-gate 		break;
11310Sstevel@tonic-gate 	case PSM_INTR_OP_NAVAIL_VECTORS:
11320Sstevel@tonic-gate 		if (hdlp->ih_type == DDI_INTR_TYPE_FIXED)
11330Sstevel@tonic-gate 			*result = 1;
11340Sstevel@tonic-gate 		else
11350Sstevel@tonic-gate 			*result = 0;
11360Sstevel@tonic-gate 		break;
11370Sstevel@tonic-gate 	case PSM_INTR_OP_XLATE_VECTOR:
1138916Sschwartz 		ispec = ((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp;
11390Sstevel@tonic-gate 		*result = psm_translate_irq(dip, ispec->intrspec_vec);
11400Sstevel@tonic-gate 		break;
11410Sstevel@tonic-gate 	case PSM_INTR_OP_GET_CAP:
11420Sstevel@tonic-gate 		*result = 0;
11430Sstevel@tonic-gate 		break;
11440Sstevel@tonic-gate 	case PSM_INTR_OP_GET_PENDING:
11450Sstevel@tonic-gate 	case PSM_INTR_OP_CLEAR_MASK:
11460Sstevel@tonic-gate 	case PSM_INTR_OP_SET_MASK:
11470Sstevel@tonic-gate 	case PSM_INTR_OP_GET_SHARED:
11480Sstevel@tonic-gate 	case PSM_INTR_OP_SET_PRI:
11490Sstevel@tonic-gate 	case PSM_INTR_OP_SET_CAP:
1150916Sschwartz 	case PSM_INTR_OP_SET_CPU:
1151916Sschwartz 	case PSM_INTR_OP_GET_INTR:
11520Sstevel@tonic-gate 	default:
11530Sstevel@tonic-gate 		return (PSM_FAILURE);
11540Sstevel@tonic-gate 	}
11550Sstevel@tonic-gate 	return (PSM_SUCCESS);
11560Sstevel@tonic-gate }
1157