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
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate/*
237c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
307c478bd9Sstevel@tonic-gate#include <sys/machparam.h>	/* To get SYSBASE and PAGESIZE */
317c478bd9Sstevel@tonic-gate#include <sys/privregs.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate#if !defined(lint)
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate	.seg	".text"
367c478bd9Sstevel@tonic-gate	.align	4
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate#define	PSR_PIL_BIT	0x8
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate/*
417c478bd9Sstevel@tonic-gate * Macro to raise processor priority level.
427c478bd9Sstevel@tonic-gate * Avoid dropping processor priority if already at high level.
437c478bd9Sstevel@tonic-gate * Also avoid going below CPU->cpu_base_spl, which could've just been set by
447c478bd9Sstevel@tonic-gate * a higher-level interrupt thread that just blocked.
457c478bd9Sstevel@tonic-gate * XXX4U: bring splr inline
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate#define	RAISE(level) \
487c478bd9Sstevel@tonic-gate	b	splr; \
497c478bd9Sstevel@tonic-gate	mov	((level) << PSR_PIL_BIT), %o0
507c478bd9Sstevel@tonic-gate/*
517c478bd9Sstevel@tonic-gate * Macro to set the priority to a specified level.
527c478bd9Sstevel@tonic-gate * Avoid dropping the priority below CPU->cpu_base_spl.
537c478bd9Sstevel@tonic-gate * XXX4U: bring splx inline
547c478bd9Sstevel@tonic-gate */
557c478bd9Sstevel@tonic-gate#define SETPRI(level) \
567c478bd9Sstevel@tonic-gate	b	splx; \
577c478bd9Sstevel@tonic-gate	mov	((level) << PSR_PIL_BIT), %o0
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate#endif	/* lint */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate	/*
627c478bd9Sstevel@tonic-gate	 * Berkley 4.3 introduced symbolically named interrupt levels
637c478bd9Sstevel@tonic-gate	 * as a way deal with priority in a machine independent fashion.
647c478bd9Sstevel@tonic-gate	 * Numbered priorities are machine specific, and should be
657c478bd9Sstevel@tonic-gate	 * discouraged where possible.
667c478bd9Sstevel@tonic-gate	 *
677c478bd9Sstevel@tonic-gate	 * Note, for the machine specific priorities there are
687c478bd9Sstevel@tonic-gate	 * examples listed for devices that use a particular priority.
697c478bd9Sstevel@tonic-gate	 * It should not be construed that all devices of that
707c478bd9Sstevel@tonic-gate	 * type should be at that priority.  It is currently were
717c478bd9Sstevel@tonic-gate	 * the current devices fit into the priority scheme based
727c478bd9Sstevel@tonic-gate	 * upon time criticalness.
737c478bd9Sstevel@tonic-gate	 *
747c478bd9Sstevel@tonic-gate	 * The underlying assumption of these assignments is that
757c478bd9Sstevel@tonic-gate	 * SPARC9 IPL 10 is the highest level from which a device
767c478bd9Sstevel@tonic-gate	 * routine can call wakeup.  Devices that interrupt from higher
777c478bd9Sstevel@tonic-gate	 * levels are restricted in what they can do.  If they need
787c478bd9Sstevel@tonic-gate	 * kernels services they should schedule a routine at a lower
797c478bd9Sstevel@tonic-gate	 * level (via software interrupt) to do the required
807c478bd9Sstevel@tonic-gate	 * processing.
817c478bd9Sstevel@tonic-gate	 *
827c478bd9Sstevel@tonic-gate	 * Examples of this higher usage:
837c478bd9Sstevel@tonic-gate	 *	Level	Usage
847c478bd9Sstevel@tonic-gate	 *	15	Asynchronous memory exceptions
857c478bd9Sstevel@tonic-gate	 *	14	Profiling clock (and PROM uart polling clock)
867c478bd9Sstevel@tonic-gate	 *	13	Audio device
877c478bd9Sstevel@tonic-gate	 *	12	Serial ports
887c478bd9Sstevel@tonic-gate	 *	11	Floppy controller
897c478bd9Sstevel@tonic-gate	 *
907c478bd9Sstevel@tonic-gate	 * The serial ports request lower level processing on level 6.
917c478bd9Sstevel@tonic-gate	 * Audio and floppy request lower level processing on level 4.
927c478bd9Sstevel@tonic-gate	 *
937c478bd9Sstevel@tonic-gate	 * Also, almost all splN routines (where N is a number or a
947c478bd9Sstevel@tonic-gate	 * mnemonic) will do a RAISE(), on the assumption that they are
957c478bd9Sstevel@tonic-gate	 * never used to lower our priority.
967c478bd9Sstevel@tonic-gate	 * The exceptions are:
977c478bd9Sstevel@tonic-gate	 *	spl8()		Because you can't be above 15 to begin with!
987c478bd9Sstevel@tonic-gate	 *	splzs()		Because this is used at boot time to lower our
997c478bd9Sstevel@tonic-gate	 *			priority, to allow the PROM to poll the uart.
1007c478bd9Sstevel@tonic-gate	 *	spl0()		Used to lower priority to 0.
1017c478bd9Sstevel@tonic-gate	 *	splsoftclock()	Used by hardclock to lower priority.
1027c478bd9Sstevel@tonic-gate	 */
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate#if defined(lint)
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gateint splimp(void)	{ return (0); }
1077c478bd9Sstevel@tonic-gateint splnet(void)	{ return (0); }
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate#ifdef	notdef
1107c478bd9Sstevel@tonic-gateint spl6(void)		{ return (0); }
1117c478bd9Sstevel@tonic-gateint spl5(void)		{ return (0); }
1127c478bd9Sstevel@tonic-gate#endif	notdef
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate#else	/* lint */
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate	/* locks out all interrupts, including memory errors */
1177c478bd9Sstevel@tonic-gate	ENTRY(spl8)
1187c478bd9Sstevel@tonic-gate	SETPRI(15)
1197c478bd9Sstevel@tonic-gate	SET_SIZE(spl8)
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate	/* just below the level that profiling runs */
1227c478bd9Sstevel@tonic-gate	ALTENTRY(splaudio)
1237c478bd9Sstevel@tonic-gate	ENTRY(spl7)
1247c478bd9Sstevel@tonic-gate	RAISE(13)
1257c478bd9Sstevel@tonic-gate	SET_SIZE(spl7)
1267c478bd9Sstevel@tonic-gate	SET_SIZE(splaudio)
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate	/* sun specific - highest priority onboard serial i/o zs ports */
1297c478bd9Sstevel@tonic-gate	ALTENTRY(splzs)
1307c478bd9Sstevel@tonic-gate	SETPRI(12)	/* Can't be a RAISE, as it's used to lower us */
1317c478bd9Sstevel@tonic-gate	SET_SIZE(splzs)
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate	/*
1347c478bd9Sstevel@tonic-gate	 * should lock out clocks and all interrupts,
1357c478bd9Sstevel@tonic-gate	 * as you can see, there are exceptions
1367c478bd9Sstevel@tonic-gate	 */
1377c478bd9Sstevel@tonic-gate	ALTENTRY(splhigh)
1387c478bd9Sstevel@tonic-gate	ALTENTRY(splhi)
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate	/* the standard clock interrupt priority */
1417c478bd9Sstevel@tonic-gate	ALTENTRY(splclock)
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate	/* highest priority for any tty handling */
1447c478bd9Sstevel@tonic-gate	ALTENTRY(spltty)
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate	/* highest priority required for protection of buffered io system */
1477c478bd9Sstevel@tonic-gate	ALTENTRY(splbio)
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate	/* machine specific */
1507c478bd9Sstevel@tonic-gate	ENTRY2(spl6,spl5)
1517c478bd9Sstevel@tonic-gate	RAISE(10)
1527c478bd9Sstevel@tonic-gate	SET_SIZE(splhigh)
1537c478bd9Sstevel@tonic-gate	SET_SIZE(splhi)
1547c478bd9Sstevel@tonic-gate	SET_SIZE(splclock)
1557c478bd9Sstevel@tonic-gate	SET_SIZE(spltty)
1567c478bd9Sstevel@tonic-gate	SET_SIZE(splbio)
1577c478bd9Sstevel@tonic-gate	SET_SIZE(spl5)
1587c478bd9Sstevel@tonic-gate	SET_SIZE(spl6)
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate	/*
1617c478bd9Sstevel@tonic-gate	 * machine specific
1627c478bd9Sstevel@tonic-gate	 * for sun, some frame buffers must be at this priority
1637c478bd9Sstevel@tonic-gate	 */
1647c478bd9Sstevel@tonic-gate	ENTRY(spl4)
1657c478bd9Sstevel@tonic-gate	RAISE(8)
1667c478bd9Sstevel@tonic-gate	SET_SIZE(spl4)
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate	/* highest level that any network device will use */
1697c478bd9Sstevel@tonic-gate	ALTENTRY(splimp)
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate	/*
1727c478bd9Sstevel@tonic-gate	 * machine specific
1737c478bd9Sstevel@tonic-gate	 * for sun, devices with limited buffering: tapes, ethernet
1747c478bd9Sstevel@tonic-gate	 */
1757c478bd9Sstevel@tonic-gate	ENTRY(spl3)
1767c478bd9Sstevel@tonic-gate	RAISE(6)
1777c478bd9Sstevel@tonic-gate	SET_SIZE(splimp)
1787c478bd9Sstevel@tonic-gate	SET_SIZE(spl3)
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate	/*
1817c478bd9Sstevel@tonic-gate	 * machine specific - not as time critical as above
1827c478bd9Sstevel@tonic-gate	 * for sun, disks
1837c478bd9Sstevel@tonic-gate	 */
1847c478bd9Sstevel@tonic-gate	ENTRY(spl2)
1857c478bd9Sstevel@tonic-gate	RAISE(4)
1867c478bd9Sstevel@tonic-gate	SET_SIZE(spl2)
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate	ENTRY(spl1)
1897c478bd9Sstevel@tonic-gate	RAISE(2)
1907c478bd9Sstevel@tonic-gate	SET_SIZE(spl1)
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate	/* highest level that any protocol handler will run */
1937c478bd9Sstevel@tonic-gate	ENTRY(splnet)
1947c478bd9Sstevel@tonic-gate	RAISE(1)
1957c478bd9Sstevel@tonic-gate	SET_SIZE(splnet)
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate	/* softcall priority */
1987c478bd9Sstevel@tonic-gate	/* used by hardclock to LOWER priority */
1997c478bd9Sstevel@tonic-gate	ENTRY(splsoftclock)
2007c478bd9Sstevel@tonic-gate	SETPRI(1)
2017c478bd9Sstevel@tonic-gate	SET_SIZE(splsoftclock)
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate	/* allow all interrupts */
2047c478bd9Sstevel@tonic-gate	ENTRY(spl0)
2057c478bd9Sstevel@tonic-gate	SETPRI(0)
2067c478bd9Sstevel@tonic-gate	SET_SIZE(spl0)
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate#endif	/* lint */
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate/*
2117c478bd9Sstevel@tonic-gate * splx - set PIL back to that indicated by the old %PSR passed as an argument,
2127c478bd9Sstevel@tonic-gate * or to the CPU's base priority, whichever is higher.
2137c478bd9Sstevel@tonic-gate * sys_rtt (in locore.s) relies on this not to use %g1 or %g2.
2147c478bd9Sstevel@tonic-gate */
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate#if defined(lint)
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate/* ARGSUSED */
2197c478bd9Sstevel@tonic-gatevoid
2207c478bd9Sstevel@tonic-gatesplx(int level)
2217c478bd9Sstevel@tonic-gate{
2227c478bd9Sstevel@tonic-gate}
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate#else	/* lint */
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate	ENTRY(splx)
2277c478bd9Sstevel@tonic-gate	rdpr	%pil, %o1	! get current pil
2287c478bd9Sstevel@tonic-gate	wrpr	%o0, %pil
2297c478bd9Sstevel@tonic-gate	retl
2307c478bd9Sstevel@tonic-gate	mov	%o1, %o0
2317c478bd9Sstevel@tonic-gate	SET_SIZE(splx)
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate#endif	/* level */
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate/*
2367c478bd9Sstevel@tonic-gate * splr()
2377c478bd9Sstevel@tonic-gate *
2387c478bd9Sstevel@tonic-gate * splr is like splx but will only raise the priority and never drop it
2397c478bd9Sstevel@tonic-gate * Be careful not to set priority lower than CPU->cpu_base_pri,
2407c478bd9Sstevel@tonic-gate * even though it seems we're raising the priority, it could be set higher
2417c478bd9Sstevel@tonic-gate * at any time by an interrupt routine, so we must block interrupts and
2427c478bd9Sstevel@tonic-gate * look at CPU->cpu_base_pri.
2437c478bd9Sstevel@tonic-gate *
2447c478bd9Sstevel@tonic-gate */
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate#if defined(lint)
2477c478bd9Sstevel@tonic-gate#ifdef	notdef
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate/* ARGSUSED */
2507c478bd9Sstevel@tonic-gateint
2517c478bd9Sstevel@tonic-gatesplr(int level)
2527c478bd9Sstevel@tonic-gate{ return (0); }
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate#endif	notdef
2557c478bd9Sstevel@tonic-gate#else	/* lint */
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate/*
2587c478bd9Sstevel@tonic-gate * splr(psr_pri_field)
2597c478bd9Sstevel@tonic-gate * splr is like splx but will only raise the priority and never drop it
2607c478bd9Sstevel@tonic-gate */
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate	ENTRY(splr)
2637c478bd9Sstevel@tonic-gate	rdpr	%pil, %o1	! get current pil
2647c478bd9Sstevel@tonic-gate	cmp	%o0, %o1
2657c478bd9Sstevel@tonic-gate	ble	1f
2667c478bd9Sstevel@tonic-gate	nop
2677c478bd9Sstevel@tonic-gate	wrpr	%o0, %pil
2687c478bd9Sstevel@tonic-gate1:	retl
2697c478bd9Sstevel@tonic-gate	mov	%o1, %o0	! return the old pil
2707c478bd9Sstevel@tonic-gate	SET_SIZE(splr)
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate#endif	/* lint */
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate/*
2757c478bd9Sstevel@tonic-gate * get_ticks()
2767c478bd9Sstevel@tonic-gate */
2777c478bd9Sstevel@tonic-gate#if defined(lint)
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate/* ARGSUSED */
2807c478bd9Sstevel@tonic-gateuint64_t
2817c478bd9Sstevel@tonic-gateget_ticks(void)
2827c478bd9Sstevel@tonic-gate{ return (0); }
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate#else	/* lint */
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate	ENTRY(get_ticks)
2877c478bd9Sstevel@tonic-gate	rdpr	%tick, %o0
2887c478bd9Sstevel@tonic-gate	sllx	%o0, 1, %o0
2897c478bd9Sstevel@tonic-gate	retl
2907c478bd9Sstevel@tonic-gate	srlx	%o0, 1, %o0		! shake off npt bit
2917c478bd9Sstevel@tonic-gate	SET_SIZE(get_ticks)
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate#endif	/* lint */
294