xref: /onnv-gate/usr/src/uts/i86pc/io/psm/uppc.c (revision 12004:93f274d4a367)
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
51742Sanish  * Common Development and Distribution License (the "License").
61742Sanish  * 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 /*
228550SSeth.Goldberg@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
26*12004Sjiang.liu@intel.com #define	PSMI_1_7
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/mutex.h>
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/time.h>
310Sstevel@tonic-gate #include <sys/machlock.h>
320Sstevel@tonic-gate #include <sys/smp_impldefs.h>
330Sstevel@tonic-gate #include <sys/uadmin.h>
340Sstevel@tonic-gate #include <sys/promif.h>
350Sstevel@tonic-gate #include <sys/psm.h>
360Sstevel@tonic-gate #include <sys/pit.h>
378550SSeth.Goldberg@Sun.COM #include <sys/apic.h>
380Sstevel@tonic-gate #include <sys/psm_common.h>
390Sstevel@tonic-gate #include <sys/atomic.h>
403446Smrj #include <sys/archsystm.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #define	NSEC_IN_SEC		1000000000
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * Local Function Prototypes
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate static void uppc_softinit(void);
480Sstevel@tonic-gate static void uppc_picinit();
498550SSeth.Goldberg@Sun.COM static int uppc_post_cpu_start(void);
500Sstevel@tonic-gate static int uppc_clkinit(int);
510Sstevel@tonic-gate static int uppc_addspl(int irqno, int ipl, int min_ipl, int max_ipl);
520Sstevel@tonic-gate static int uppc_delspl(int irqno, int ipl, int min_ipl, int max_ipl);
530Sstevel@tonic-gate static processorid_t uppc_get_next_processorid(processorid_t cpu_id);
540Sstevel@tonic-gate static int uppc_get_clockirq(int ipl);
550Sstevel@tonic-gate static int uppc_probe(void);
560Sstevel@tonic-gate static int uppc_translate_irq(dev_info_t *dip, int irqno);
570Sstevel@tonic-gate static void uppc_shutdown(int cmd, int fcn);
580Sstevel@tonic-gate static void uppc_preshutdown(int cmd, int fcn);
598550SSeth.Goldberg@Sun.COM static int uppc_state(psm_state_request_t *request);
600Sstevel@tonic-gate static int uppc_init_acpi(void);
610Sstevel@tonic-gate static void uppc_setspl(int);
620Sstevel@tonic-gate static int uppc_intr_enter(int, int *);
630Sstevel@tonic-gate static void uppc_intr_exit(int, int);
640Sstevel@tonic-gate static hrtime_t uppc_gethrtime();
650Sstevel@tonic-gate 
660Sstevel@tonic-gate static int uppc_acpi_irq_configure(acpi_psm_lnk_t *acpipsmlnkp, dev_info_t *dip,
670Sstevel@tonic-gate     int *pci_irqp, iflag_t *intr_flagp);
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * Global Data
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate static struct standard_pic pics0;
730Sstevel@tonic-gate int uppc_use_acpi = 1;	/* Use ACPI by default */
740Sstevel@tonic-gate int uppc_enable_acpi = 0;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * For interrupt link devices, if uppc_unconditional_srs is set, an irq resource
790Sstevel@tonic-gate  * will be assigned (via _SRS). If it is not set, use the current
800Sstevel@tonic-gate  * irq setting (via _CRS), but only if that irq is in the set of possible
810Sstevel@tonic-gate  * irqs (returned by _PRS) for the device.
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate int uppc_unconditional_srs = 1;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * For interrupt link devices, if uppc_prefer_crs is set when we are
870Sstevel@tonic-gate  * assigning an IRQ resource to a device, prefer the current IRQ setting
880Sstevel@tonic-gate  * over other possible irq settings under same conditions.
890Sstevel@tonic-gate  */
900Sstevel@tonic-gate int uppc_prefer_crs = 1;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate int uppc_verbose = 0;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /* flag definitions for uppc_verbose */
950Sstevel@tonic-gate #define	UPPC_VERBOSE_IRQ_FLAG			0x00000001
960Sstevel@tonic-gate #define	UPPC_VERBOSE_POWEROFF_FLAG		0x00000002
970Sstevel@tonic-gate #define	UPPC_VERBOSE_POWEROFF_PAUSE_FLAG	0x00000004
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate #define	UPPC_VERBOSE_IRQ(fmt) \
1010Sstevel@tonic-gate 	if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG) \
1020Sstevel@tonic-gate 		cmn_err fmt;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate #define	UPPC_VERBOSE_POWEROFF(fmt) \
1050Sstevel@tonic-gate 	if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG) \
1060Sstevel@tonic-gate 		prom_printf fmt;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate uchar_t uppc_reserved_irqlist[MAX_ISA_IRQ + 1];
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate static uint16_t uppc_irq_shared_table[MAX_ISA_IRQ + 1];
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /*
1130Sstevel@tonic-gate  * Contains SCI irqno from FADT after initialization
1140Sstevel@tonic-gate  */
1150Sstevel@tonic-gate static int uppc_sci = -1;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate  * Local Static Data
1190Sstevel@tonic-gate  */
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate static lock_t uppc_gethrtime_lock;
1220Sstevel@tonic-gate static hrtime_t uppc_lasthrtime;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #ifdef UPPC_DEBUG
1260Sstevel@tonic-gate #define	DENT	0x0001
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate static int	uppc_debug = 0;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #endif
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate static struct	psm_ops uppc_ops = {
1350Sstevel@tonic-gate 	uppc_probe,				/* psm_probe		*/
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	uppc_softinit,				/* psm_init		*/
1380Sstevel@tonic-gate 	uppc_picinit,				/* psm_picinit		*/
1390Sstevel@tonic-gate 	uppc_intr_enter,			/* psm_intr_enter	*/
1400Sstevel@tonic-gate 	uppc_intr_exit,				/* psm_intr_exit	*/
1410Sstevel@tonic-gate 	uppc_setspl,				/* psm_setspl		*/
1420Sstevel@tonic-gate 	uppc_addspl,				/* psm_addspl		*/
1430Sstevel@tonic-gate 	uppc_delspl,				/* psm_delspl		*/
1440Sstevel@tonic-gate 	(int (*)(processorid_t))NULL,		/* psm_disable_intr	*/
1450Sstevel@tonic-gate 	(void (*)(processorid_t))NULL,		/* psm_enable_intr	*/
1460Sstevel@tonic-gate 	(int (*)(int))NULL,			/* psm_softlvl_to_irq	*/
1470Sstevel@tonic-gate 	(void (*)(int))NULL,			/* psm_set_softintr	*/
1480Sstevel@tonic-gate 	(void (*)(processorid_t))NULL,		/* psm_set_idlecpu	*/
1490Sstevel@tonic-gate 	(void (*)(processorid_t))NULL,		/* psm_unset_idlecpu	*/
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	uppc_clkinit,				/* psm_clkinit		*/
1520Sstevel@tonic-gate 	uppc_get_clockirq,			/* psm_get_clockirq	*/
1530Sstevel@tonic-gate 	(void (*)(void))NULL,			/* psm_hrtimeinit	*/
1540Sstevel@tonic-gate 	uppc_gethrtime,				/* psm_gethrtime	*/
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	uppc_get_next_processorid,		/* psm_get_next_processorid */
1573446Smrj 	(int (*)(processorid_t, caddr_t))NULL,	/* psm_cpu_start	*/
1588550SSeth.Goldberg@Sun.COM 	uppc_post_cpu_start,			/* psm_post_cpu_start	*/
1590Sstevel@tonic-gate 	uppc_shutdown,				/* psm_shutdown		*/
1600Sstevel@tonic-gate 	(int (*)(int, int))NULL,		/* psm_get_ipivect	*/
1610Sstevel@tonic-gate 	(void (*)(processorid_t, int))NULL,	/* psm_send_ipi		*/
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	uppc_translate_irq,			/* psm_translate_irq	*/
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	(void (*)(int, char *))NULL,		/* psm_notify_error	*/
1660Sstevel@tonic-gate 	(void (*)(int msg))NULL,		/* psm_notify_func	*/
1670Sstevel@tonic-gate 	(void (*)(hrtime_t time))NULL,		/* psm_timer_reprogram	*/
1680Sstevel@tonic-gate 	(void (*)(void))NULL,			/* psm_timer_enable	*/
1690Sstevel@tonic-gate 	(void (*)(void))NULL,			/* psm_timer_disable	*/
1700Sstevel@tonic-gate 	(void (*)(void *arg))NULL,		/* psm_post_cyclic_setup */
1710Sstevel@tonic-gate 	uppc_preshutdown,			/* psm_preshutdown	*/
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 	(int (*)(dev_info_t *, ddi_intr_handle_impl_t *,
1748550SSeth.Goldberg@Sun.COM 	    psm_intr_op_t, int *))NULL,		/* psm_intr_ops		*/
1758550SSeth.Goldberg@Sun.COM 
176*12004Sjiang.liu@intel.com 	uppc_state,				/* psm_state		*/
177*12004Sjiang.liu@intel.com 	(int (*)(psm_cpu_request_t *))NULL	/* psm_cpu_ops		*/
1780Sstevel@tonic-gate };
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate static struct	psm_info uppc_info = {
182*12004Sjiang.liu@intel.com 	PSM_INFO_VER01_7,	/* version				*/
1830Sstevel@tonic-gate 	PSM_OWN_SYS_DEFAULT,	/* ownership				*/
1840Sstevel@tonic-gate 	(struct psm_ops *)&uppc_ops, /* operation			*/
1850Sstevel@tonic-gate 	"uppc",			/* machine name				*/
1860Sstevel@tonic-gate 	"UniProcessor PC",	/* machine descriptions			*/
1870Sstevel@tonic-gate };
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate /*
1900Sstevel@tonic-gate  * Configuration Data
1910Sstevel@tonic-gate  */
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate /*
1940Sstevel@tonic-gate  * This is the loadable module wrapper.
1950Sstevel@tonic-gate  */
1960Sstevel@tonic-gate #include <sys/modctl.h>
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate static void *uppc_hdlp;
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate int
_init(void)2010Sstevel@tonic-gate _init(void)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate 	return (psm_mod_init(&uppc_hdlp, &uppc_info));
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate int
_fini(void)2070Sstevel@tonic-gate _fini(void)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate 	return (psm_mod_fini(&uppc_hdlp, &uppc_info));
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2130Sstevel@tonic-gate _info(struct modinfo *modinfop)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate 	return (psm_mod_info(&uppc_hdlp, &uppc_info, modinfop));
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /*
2190Sstevel@tonic-gate  * Autoconfiguration Routines
2200Sstevel@tonic-gate  */
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate static int
uppc_probe(void)2230Sstevel@tonic-gate uppc_probe(void)
2240Sstevel@tonic-gate {
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 	return (PSM_SUCCESS);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate static void
uppc_softinit(void)2310Sstevel@tonic-gate uppc_softinit(void)
2320Sstevel@tonic-gate {
2330Sstevel@tonic-gate 	struct standard_pic *pp;
2340Sstevel@tonic-gate 	int i;
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 	pp = &pics0;
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	if (uppc_use_acpi && uppc_init_acpi()) {
2400Sstevel@tonic-gate 		build_reserved_irqlist((uchar_t *)uppc_reserved_irqlist);
2410Sstevel@tonic-gate 		for (i = 0; i <= MAX_ISA_IRQ; i++)
2420Sstevel@tonic-gate 			uppc_irq_shared_table[i] = 0;
2430Sstevel@tonic-gate 		uppc_enable_acpi = 1;
2440Sstevel@tonic-gate 	}
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	/*
2470Sstevel@tonic-gate 	 * initialize the ipl mask
2480Sstevel@tonic-gate 	 */
2490Sstevel@tonic-gate 	for (i = 0; i < (MAXIPL << 1); i += 2) {
2500Sstevel@tonic-gate 		/* enable slave lines on master */
2510Sstevel@tonic-gate 		pp->c_iplmask[i] = 0xff;
2520Sstevel@tonic-gate 		pp->c_iplmask[i+1] = (0xff & ~(1 << MASTERLINE));
2530Sstevel@tonic-gate 	}
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate /*ARGSUSED*/
2570Sstevel@tonic-gate static int
uppc_clkinit(int hertz)2580Sstevel@tonic-gate uppc_clkinit(int hertz)
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate 	ulong_t clkticks = PIT_HZ / hz;
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate 	if (hertz == 0)
2630Sstevel@tonic-gate 		return (0);	/* One shot mode not supported */
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	/*
2660Sstevel@tonic-gate 	 * program timer 0
2670Sstevel@tonic-gate 	 */
2680Sstevel@tonic-gate 	outb(PITCTL_PORT, (PIT_C0|PIT_NDIVMODE|PIT_READMODE));
2690Sstevel@tonic-gate 	outb(PITCTR0_PORT, (uchar_t)clkticks);
2700Sstevel@tonic-gate 	outb(PITCTR0_PORT, (uchar_t)(clkticks>>8));
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	return (NSEC_IN_SEC / hertz);
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate static void
uppc_picinit()2760Sstevel@tonic-gate uppc_picinit()
2770Sstevel@tonic-gate {
2780Sstevel@tonic-gate 	picsetup();
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 	/*
2810Sstevel@tonic-gate 	 * If a valid SCI is present, manually addspl()
2820Sstevel@tonic-gate 	 * since we're not set-up early enough in boot
2830Sstevel@tonic-gate 	 * to do it "conventionally" (via add_avintr)
2840Sstevel@tonic-gate 	 */
2850Sstevel@tonic-gate 	if (uppc_sci >= 0)
2860Sstevel@tonic-gate 		(void) uppc_addspl(uppc_sci, SCI_IPL, SCI_IPL, SCI_IPL);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate 
2898550SSeth.Goldberg@Sun.COM static int
uppc_post_cpu_start(void)2908550SSeth.Goldberg@Sun.COM uppc_post_cpu_start(void)
2918550SSeth.Goldberg@Sun.COM {
2928550SSeth.Goldberg@Sun.COM 	/*
2938550SSeth.Goldberg@Sun.COM 	 * On uppc machines psm_post_cpu_start is called during S3 resume
2948550SSeth.Goldberg@Sun.COM 	 * on the boot cpu from assembly, using the ap_mlsetup vector.
2958550SSeth.Goldberg@Sun.COM 	 */
2968550SSeth.Goldberg@Sun.COM 
2978550SSeth.Goldberg@Sun.COM 	/*
2988550SSeth.Goldberg@Sun.COM 	 * Init master and slave pic
2998550SSeth.Goldberg@Sun.COM 	 */
3008550SSeth.Goldberg@Sun.COM 	picsetup();
3018550SSeth.Goldberg@Sun.COM 
3028550SSeth.Goldberg@Sun.COM 	/*
3038550SSeth.Goldberg@Sun.COM 	 * program timer 0
3048550SSeth.Goldberg@Sun.COM 	 */
3058550SSeth.Goldberg@Sun.COM 	(void) uppc_clkinit(hz);
3068550SSeth.Goldberg@Sun.COM 
3078550SSeth.Goldberg@Sun.COM 	return (PSM_SUCCESS);
3088550SSeth.Goldberg@Sun.COM }
3098550SSeth.Goldberg@Sun.COM 
3100Sstevel@tonic-gate /*ARGSUSED3*/
3110Sstevel@tonic-gate static int
uppc_addspl(int irqno,int ipl,int min_ipl,int max_ipl)3120Sstevel@tonic-gate uppc_addspl(int irqno, int ipl, int min_ipl, int max_ipl)
3130Sstevel@tonic-gate {
3140Sstevel@tonic-gate 	struct standard_pic *pp;
3150Sstevel@tonic-gate 	int i;
3160Sstevel@tonic-gate 	int startidx;
3170Sstevel@tonic-gate 	uchar_t	vectmask;
3180Sstevel@tonic-gate 
3191742Sanish 	if (irqno <= MAX_ISA_IRQ)
3201742Sanish 		atomic_add_16(&uppc_irq_shared_table[irqno], 1);
3211742Sanish 
3220Sstevel@tonic-gate 	if (ipl != min_ipl)
3230Sstevel@tonic-gate 		return (0);
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	if (irqno > 7) {
3260Sstevel@tonic-gate 		vectmask = 1 << (irqno - 8);
3270Sstevel@tonic-gate 		startidx = (ipl << 1);
3280Sstevel@tonic-gate 	} else {
3290Sstevel@tonic-gate 		vectmask = 1 << irqno;
3300Sstevel@tonic-gate 		startidx = (ipl << 1) + 1;
3310Sstevel@tonic-gate 	}
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	/*
3340Sstevel@tonic-gate 	 * mask intr same or above ipl
3350Sstevel@tonic-gate 	 * level MAXIPL has all intr off as init. default
3360Sstevel@tonic-gate 	 */
3370Sstevel@tonic-gate 	pp = &pics0;
3380Sstevel@tonic-gate 	for (i = startidx; i < (MAXIPL << 1); i += 2) {
3390Sstevel@tonic-gate 		if (pp->c_iplmask[i] & vectmask)
3400Sstevel@tonic-gate 			break;
3410Sstevel@tonic-gate 		pp->c_iplmask[i] |= vectmask;
3420Sstevel@tonic-gate 	}
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	/*
3450Sstevel@tonic-gate 	 * unmask intr below ipl
3460Sstevel@tonic-gate 	 */
3470Sstevel@tonic-gate 	for (i = startidx-2; i >= 0; i -= 2) {
3480Sstevel@tonic-gate 		if (!(pp->c_iplmask[i] & vectmask))
3490Sstevel@tonic-gate 			break;
3500Sstevel@tonic-gate 		pp->c_iplmask[i] &= ~vectmask;
3510Sstevel@tonic-gate 	}
3520Sstevel@tonic-gate 	return (0);
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate static int
uppc_delspl(int irqno,int ipl,int min_ipl,int max_ipl)3560Sstevel@tonic-gate uppc_delspl(int irqno, int ipl, int min_ipl, int max_ipl)
3570Sstevel@tonic-gate {
3580Sstevel@tonic-gate 	struct standard_pic *pp;
3590Sstevel@tonic-gate 	int i;
3600Sstevel@tonic-gate 	uchar_t	vectmask;
3610Sstevel@tonic-gate 
3621742Sanish 	if (irqno <= MAX_ISA_IRQ)
3631742Sanish 		atomic_add_16(&uppc_irq_shared_table[irqno], -1);
3641742Sanish 
3650Sstevel@tonic-gate 	/*
3660Sstevel@tonic-gate 	 * skip if we are not deleting the last handler
3670Sstevel@tonic-gate 	 * and the ipl is higher than minimum
3680Sstevel@tonic-gate 	 */
3690Sstevel@tonic-gate 	if ((max_ipl != PSM_INVALID_IPL) && (ipl >= min_ipl))
3700Sstevel@tonic-gate 		return (0);
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	if (irqno > 7) {
3730Sstevel@tonic-gate 		vectmask = 1 << (irqno - 8);
3740Sstevel@tonic-gate 		i = 0;
3750Sstevel@tonic-gate 	} else {
3760Sstevel@tonic-gate 		vectmask = 1 << irqno;
3770Sstevel@tonic-gate 		i = 1;
3780Sstevel@tonic-gate 	}
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	pp = &pics0;
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	/*
3830Sstevel@tonic-gate 	 * check any handlers left for this irqno
3840Sstevel@tonic-gate 	 */
3850Sstevel@tonic-gate 	if (max_ipl != PSM_INVALID_IPL) {
3860Sstevel@tonic-gate 		/*
3870Sstevel@tonic-gate 		 * unmasks all levels below the lowest priority
3880Sstevel@tonic-gate 		 */
3890Sstevel@tonic-gate 		i += ((min_ipl - 1) << 1);
3900Sstevel@tonic-gate 		for (; i >= 0; i -= 2) {
3910Sstevel@tonic-gate 			if (!(pp->c_iplmask[i] & vectmask))
3920Sstevel@tonic-gate 				break;
3930Sstevel@tonic-gate 			pp->c_iplmask[i] &= ~vectmask;
3940Sstevel@tonic-gate 		}
3950Sstevel@tonic-gate 	} else {
3960Sstevel@tonic-gate 		/*
3970Sstevel@tonic-gate 		 * set mask to all levels
3980Sstevel@tonic-gate 		 */
3990Sstevel@tonic-gate 		for (; i < (MAXIPL << 1); i += 2) {
4000Sstevel@tonic-gate 			if (pp->c_iplmask[i] & vectmask)
4010Sstevel@tonic-gate 				break;
4020Sstevel@tonic-gate 			pp->c_iplmask[i] |= vectmask;
4030Sstevel@tonic-gate 		}
4040Sstevel@tonic-gate 	}
4050Sstevel@tonic-gate 	return (0);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate static processorid_t
uppc_get_next_processorid(processorid_t cpu_id)4090Sstevel@tonic-gate uppc_get_next_processorid(processorid_t cpu_id)
4100Sstevel@tonic-gate {
4110Sstevel@tonic-gate 	if (cpu_id == -1)
4120Sstevel@tonic-gate 		return (0);
4130Sstevel@tonic-gate 	return (-1);
4140Sstevel@tonic-gate }
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate /*ARGSUSED*/
4170Sstevel@tonic-gate static int
uppc_get_clockirq(int ipl)4180Sstevel@tonic-gate uppc_get_clockirq(int ipl)
4190Sstevel@tonic-gate {
4200Sstevel@tonic-gate 	return (CLOCK_VECTOR);
4210Sstevel@tonic-gate }
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate static int
uppc_init_acpi(void)4250Sstevel@tonic-gate uppc_init_acpi(void)
4260Sstevel@tonic-gate {
4270Sstevel@tonic-gate 	int verboseflags = 0;
4280Sstevel@tonic-gate 	int	sci;
4290Sstevel@tonic-gate 	iflag_t sci_flags;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	/*
4320Sstevel@tonic-gate 	 * Process SCI configuration here; this may return
4330Sstevel@tonic-gate 	 * an error if acpi-user-options has specified
4340Sstevel@tonic-gate 	 * legacy mode (use ACPI without ACPI mode or SCI)
4350Sstevel@tonic-gate 	 */
4360Sstevel@tonic-gate 	if (acpica_get_sci(&sci, &sci_flags) != AE_OK)
4370Sstevel@tonic-gate 		sci = -1;
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	/*
4400Sstevel@tonic-gate 	 * Initialize sub-system - if error is returns, ACPI is not
4410Sstevel@tonic-gate 	 * used.
4420Sstevel@tonic-gate 	 */
4430Sstevel@tonic-gate 	if (acpica_init() != AE_OK)
4440Sstevel@tonic-gate 		return (0);
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate 	/*
4470Sstevel@tonic-gate 	 * uppc implies system is in PIC mode; set edge/level
4480Sstevel@tonic-gate 	 * via ELCR based on return value from get_sci; this
4490Sstevel@tonic-gate 	 * will default to level/low if no override present,
4500Sstevel@tonic-gate 	 * as recommended by Intel ACPI CA team.
4510Sstevel@tonic-gate 	 */
4520Sstevel@tonic-gate 	if (sci >= 0) {
4530Sstevel@tonic-gate 		ASSERT((sci_flags.intr_el == INTR_EL_LEVEL) ||
4540Sstevel@tonic-gate 		    (sci_flags.intr_el == INTR_EL_EDGE));
4550Sstevel@tonic-gate 
456347Smyers 		psm_set_elcr(sci, sci_flags.intr_el == INTR_EL_LEVEL);
4570Sstevel@tonic-gate 	}
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 	/*
4600Sstevel@tonic-gate 	 * Remember SCI for later use
4610Sstevel@tonic-gate 	 */
4620Sstevel@tonic-gate 	uppc_sci = sci;
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG)
4650Sstevel@tonic-gate 		verboseflags |= PSM_VERBOSE_IRQ_FLAG;
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG)
4680Sstevel@tonic-gate 		verboseflags |= PSM_VERBOSE_POWEROFF_FLAG;
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate 	if (uppc_verbose & UPPC_VERBOSE_POWEROFF_PAUSE_FLAG)
4710Sstevel@tonic-gate 		verboseflags |= PSM_VERBOSE_POWEROFF_PAUSE_FLAG;
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate 	if (acpi_psm_init(uppc_info.p_mach_idstring, verboseflags) ==
4740Sstevel@tonic-gate 	    ACPI_PSM_FAILURE) {
4750Sstevel@tonic-gate 		return (0);
4760Sstevel@tonic-gate 	}
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	return (1);
4790Sstevel@tonic-gate }
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate static void
uppc_preshutdown(int cmd,int fcn)4830Sstevel@tonic-gate uppc_preshutdown(int cmd, int fcn)
4840Sstevel@tonic-gate {
4850Sstevel@tonic-gate 	UPPC_VERBOSE_POWEROFF(("uppc_preshutdown(%d,%d);\n", cmd, fcn));
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate }
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate static void
uppc_shutdown(int cmd,int fcn)4900Sstevel@tonic-gate uppc_shutdown(int cmd, int fcn)
4910Sstevel@tonic-gate {
4920Sstevel@tonic-gate 	UPPC_VERBOSE_POWEROFF(("uppc_shutdown(%d,%d);\n", cmd, fcn));
4930Sstevel@tonic-gate 
4943472Smyers 	/*
4953472Smyers 	 * Return if passed a command other than A_SHUTDOWN or
4963472Smyers 	 * if we're not using ACPI.
4973472Smyers 	 */
4983472Smyers 	if ((cmd != A_SHUTDOWN) || (!uppc_enable_acpi))
4990Sstevel@tonic-gate 		return;
5003472Smyers 
5014189Smyers 	/*
5024189Smyers 	 * Switch system back into Legacy-Mode if using ACPI and
5034189Smyers 	 * not powering-off.  Some BIOSes need to remain in ACPI-mode
5044189Smyers 	 * for power-off to succeed (Dell Dimension 4600)
5054189Smyers 	 */
5064189Smyers 	if (fcn != AD_POWEROFF) {
5074189Smyers 		(void) AcpiDisable();
5083472Smyers 		return;
5094189Smyers 	}
5103472Smyers 
5113472Smyers 	(void) acpi_poweroff();
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate 
5148550SSeth.Goldberg@Sun.COM 
5158550SSeth.Goldberg@Sun.COM static int
uppc_acpi_enter_picmode(void)5168550SSeth.Goldberg@Sun.COM uppc_acpi_enter_picmode(void)
5178550SSeth.Goldberg@Sun.COM {
5188550SSeth.Goldberg@Sun.COM 	ACPI_OBJECT_LIST	arglist;
5198550SSeth.Goldberg@Sun.COM 	ACPI_OBJECT		arg;
5208550SSeth.Goldberg@Sun.COM 	ACPI_STATUS		status;
5218550SSeth.Goldberg@Sun.COM 
5228550SSeth.Goldberg@Sun.COM 	/* Setup parameter object */
5238550SSeth.Goldberg@Sun.COM 	arglist.Count = 1;
5248550SSeth.Goldberg@Sun.COM 	arglist.Pointer = &arg;
5258550SSeth.Goldberg@Sun.COM 	arg.Type = ACPI_TYPE_INTEGER;
5268550SSeth.Goldberg@Sun.COM 	arg.Integer.Value = ACPI_PIC_MODE;
5278550SSeth.Goldberg@Sun.COM 
5288550SSeth.Goldberg@Sun.COM 	status = AcpiEvaluateObject(NULL, "\\_PIC", &arglist, NULL);
5298550SSeth.Goldberg@Sun.COM 	if (ACPI_FAILURE(status))
5308550SSeth.Goldberg@Sun.COM 		return (PSM_FAILURE);
5318550SSeth.Goldberg@Sun.COM 	else
5328550SSeth.Goldberg@Sun.COM 		return (PSM_SUCCESS);
5338550SSeth.Goldberg@Sun.COM }
5348550SSeth.Goldberg@Sun.COM 
5358550SSeth.Goldberg@Sun.COM 
5368550SSeth.Goldberg@Sun.COM struct pic_state {
5378550SSeth.Goldberg@Sun.COM 	int8_t		mmask;
5388550SSeth.Goldberg@Sun.COM 	int8_t		smask;
5398550SSeth.Goldberg@Sun.COM 	uint16_t	elcr;
5408550SSeth.Goldberg@Sun.COM };
5418550SSeth.Goldberg@Sun.COM 
5428550SSeth.Goldberg@Sun.COM 
5438550SSeth.Goldberg@Sun.COM static void
pic_save_state(struct pic_state * sp)5448550SSeth.Goldberg@Sun.COM pic_save_state(struct pic_state *sp)
5458550SSeth.Goldberg@Sun.COM {
5468550SSeth.Goldberg@Sun.COM 	struct standard_pic *pp;
5478550SSeth.Goldberg@Sun.COM 	int	vecno;
5488550SSeth.Goldberg@Sun.COM 
5498550SSeth.Goldberg@Sun.COM 	/*
5508550SSeth.Goldberg@Sun.COM 	 * Only the PIC masks and the ELCR can be saved;
5518550SSeth.Goldberg@Sun.COM 	 * other 8259 state is write-only
5528550SSeth.Goldberg@Sun.COM 	 */
5538550SSeth.Goldberg@Sun.COM 
5548550SSeth.Goldberg@Sun.COM 	/*
5558550SSeth.Goldberg@Sun.COM 	 * save current master and slave interrupt mask
5568550SSeth.Goldberg@Sun.COM 	 */
5578550SSeth.Goldberg@Sun.COM 	pp = &pics0;
5588550SSeth.Goldberg@Sun.COM 	sp->smask = pp->c_curmask[0];
5598550SSeth.Goldberg@Sun.COM 	sp->mmask = pp->c_curmask[1];
5608550SSeth.Goldberg@Sun.COM 
5618550SSeth.Goldberg@Sun.COM 	/*
5628550SSeth.Goldberg@Sun.COM 	 * save edge/level configuration for isa interrupts
5638550SSeth.Goldberg@Sun.COM 	 */
5648550SSeth.Goldberg@Sun.COM 	sp->elcr = 0;
5658550SSeth.Goldberg@Sun.COM 	for (vecno = 0; vecno <= MAX_ISA_IRQ; vecno++)
5668550SSeth.Goldberg@Sun.COM 		sp->elcr |= psm_get_elcr(vecno) << vecno;
5678550SSeth.Goldberg@Sun.COM }
5688550SSeth.Goldberg@Sun.COM 
5698550SSeth.Goldberg@Sun.COM static void
pic_restore_state(struct pic_state * sp)5708550SSeth.Goldberg@Sun.COM pic_restore_state(struct pic_state *sp)
5718550SSeth.Goldberg@Sun.COM {
5728550SSeth.Goldberg@Sun.COM 	int	vecno;
5738550SSeth.Goldberg@Sun.COM 
5748550SSeth.Goldberg@Sun.COM 	/* Restore master and slave interrupt masks */
5758550SSeth.Goldberg@Sun.COM 	outb(SIMR_PORT, sp->smask);
5768550SSeth.Goldberg@Sun.COM 	outb(MIMR_PORT, sp->mmask);
5778550SSeth.Goldberg@Sun.COM 
5788550SSeth.Goldberg@Sun.COM 	/* Read master to allow pics to settle */
5798550SSeth.Goldberg@Sun.COM 	(void) inb(MIMR_PORT);
5808550SSeth.Goldberg@Sun.COM 
5818550SSeth.Goldberg@Sun.COM 	/* Restore edge/level configuration for isa interupts */
5828550SSeth.Goldberg@Sun.COM 	for (vecno = 0; vecno <= MAX_ISA_IRQ; vecno++)
5838550SSeth.Goldberg@Sun.COM 		psm_set_elcr(vecno, sp->elcr & (1 << vecno));
5848550SSeth.Goldberg@Sun.COM 
5858550SSeth.Goldberg@Sun.COM 	/* Reenter PIC mode before restoring LNK devices */
5868550SSeth.Goldberg@Sun.COM 	(void) uppc_acpi_enter_picmode();
5878550SSeth.Goldberg@Sun.COM 
5888550SSeth.Goldberg@Sun.COM 	/* Restore ACPI link device mappings */
5898550SSeth.Goldberg@Sun.COM 	acpi_restore_link_devices();
5908550SSeth.Goldberg@Sun.COM }
5918550SSeth.Goldberg@Sun.COM 
5928550SSeth.Goldberg@Sun.COM static int
uppc_state(psm_state_request_t * rp)5938550SSeth.Goldberg@Sun.COM uppc_state(psm_state_request_t *rp)
5948550SSeth.Goldberg@Sun.COM {
5958550SSeth.Goldberg@Sun.COM 	switch (rp->psr_cmd) {
5968550SSeth.Goldberg@Sun.COM 	case PSM_STATE_ALLOC:
5978550SSeth.Goldberg@Sun.COM 		rp->req.psm_state_req.psr_state =
5988550SSeth.Goldberg@Sun.COM 		    kmem_zalloc(sizeof (struct pic_state), KM_NOSLEEP);
5998550SSeth.Goldberg@Sun.COM 		if (rp->req.psm_state_req.psr_state == NULL)
6008550SSeth.Goldberg@Sun.COM 			return (ENOMEM);
6018550SSeth.Goldberg@Sun.COM 		rp->req.psm_state_req.psr_state_size =
6028550SSeth.Goldberg@Sun.COM 		    sizeof (struct pic_state);
6038550SSeth.Goldberg@Sun.COM 		return (0);
6048550SSeth.Goldberg@Sun.COM 	case PSM_STATE_FREE:
6058550SSeth.Goldberg@Sun.COM 		kmem_free(rp->req.psm_state_req.psr_state,
6068550SSeth.Goldberg@Sun.COM 		    rp->req.psm_state_req.psr_state_size);
6078550SSeth.Goldberg@Sun.COM 		return (0);
6088550SSeth.Goldberg@Sun.COM 	case PSM_STATE_SAVE:
6098550SSeth.Goldberg@Sun.COM 		pic_save_state(rp->req.psm_state_req.psr_state);
6108550SSeth.Goldberg@Sun.COM 		return (0);
6118550SSeth.Goldberg@Sun.COM 	case PSM_STATE_RESTORE:
6128550SSeth.Goldberg@Sun.COM 		pic_restore_state(rp->req.psm_state_req.psr_state);
6138550SSeth.Goldberg@Sun.COM 		return (0);
6148550SSeth.Goldberg@Sun.COM 	default:
6158550SSeth.Goldberg@Sun.COM 		return (EINVAL);
6168550SSeth.Goldberg@Sun.COM 	}
6178550SSeth.Goldberg@Sun.COM }
6188550SSeth.Goldberg@Sun.COM 
6198550SSeth.Goldberg@Sun.COM 
6200Sstevel@tonic-gate static int
uppc_acpi_translate_pci_irq(dev_info_t * dip,int busid,int devid,int ipin,int * pci_irqp,iflag_t * intr_flagp)6210Sstevel@tonic-gate uppc_acpi_translate_pci_irq(dev_info_t *dip, int busid, int devid,
6220Sstevel@tonic-gate     int ipin, int *pci_irqp, iflag_t *intr_flagp)
6230Sstevel@tonic-gate {
6240Sstevel@tonic-gate 	int status;
6250Sstevel@tonic-gate 	acpi_psm_lnk_t acpipsmlnk;
6260Sstevel@tonic-gate 
6270Sstevel@tonic-gate 	if ((status = acpi_get_irq_cache_ent(busid, devid, ipin, pci_irqp,
6280Sstevel@tonic-gate 	    intr_flagp)) == ACPI_PSM_SUCCESS) {
6290Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Found irqno %d "
6300Sstevel@tonic-gate 		    "from cache for device %s, instance #%d\n", *pci_irqp,
6310Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip)));
6320Sstevel@tonic-gate 		return (status);
6330Sstevel@tonic-gate 	}
6340Sstevel@tonic-gate 
6350Sstevel@tonic-gate 	bzero(&acpipsmlnk, sizeof (acpi_psm_lnk_t));
6360Sstevel@tonic-gate 
6370Sstevel@tonic-gate 	if ((status = acpi_translate_pci_irq(dip, ipin, pci_irqp,
6380Sstevel@tonic-gate 	    intr_flagp, &acpipsmlnk)) == ACPI_PSM_FAILURE) {
6390Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: "
6400Sstevel@tonic-gate 		    " acpi_translate_pci_irq failed for device %s, instance"
6410Sstevel@tonic-gate 		    " #%d\n", ddi_get_name(dip), ddi_get_instance(dip)));
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 		return (status);
6440Sstevel@tonic-gate 	}
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate 	if (status == ACPI_PSM_PARTIAL && acpipsmlnk.lnkobj != NULL) {
6470Sstevel@tonic-gate 		status = uppc_acpi_irq_configure(&acpipsmlnk, dip, pci_irqp,
6480Sstevel@tonic-gate 		    intr_flagp);
6490Sstevel@tonic-gate 		if (status != ACPI_PSM_SUCCESS) {
6500Sstevel@tonic-gate 			status = acpi_get_current_irq_resource(&acpipsmlnk,
6510Sstevel@tonic-gate 			    pci_irqp, intr_flagp);
6520Sstevel@tonic-gate 		}
6530Sstevel@tonic-gate 	}
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 	if (status == ACPI_PSM_SUCCESS) {
6560Sstevel@tonic-gate 		acpi_new_irq_cache_ent(busid, devid, ipin, *pci_irqp,
6570Sstevel@tonic-gate 		    intr_flagp, &acpipsmlnk);
658347Smyers 		psm_set_elcr(*pci_irqp, 1); 	/* set IRQ to PCI mode */
6590Sstevel@tonic-gate 
6600Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: [ACPI] "
6610Sstevel@tonic-gate 		    "new irq %d for device %s, instance #%d\n",
6620Sstevel@tonic-gate 		    *pci_irqp, ddi_get_name(dip), ddi_get_instance(dip)));
6630Sstevel@tonic-gate 	}
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate 	return (status);
6660Sstevel@tonic-gate }
6670Sstevel@tonic-gate 
6680Sstevel@tonic-gate /*
6690Sstevel@tonic-gate  * Configures the irq for the interrupt link device identified by
6700Sstevel@tonic-gate  * acpipsmlnkp.
6710Sstevel@tonic-gate  *
6720Sstevel@tonic-gate  * Gets the current and the list of possible irq settings for the
6730Sstevel@tonic-gate  * device. If uppc_unconditional_srs is not set, and the current
6740Sstevel@tonic-gate  * resource setting is in the list of possible irq settings,
6750Sstevel@tonic-gate  * current irq resource setting is passed to the caller.
6760Sstevel@tonic-gate  *
6770Sstevel@tonic-gate  * Otherwise, picks an irq number from the list of possible irq
6780Sstevel@tonic-gate  * settings, and sets the irq of the device to this value.
6790Sstevel@tonic-gate  * If prefer_crs is set, among a set of irq numbers in the list that have
6800Sstevel@tonic-gate  * the least number of devices sharing the interrupt, we pick current irq
6810Sstevel@tonic-gate  * resource setting if it is a member of this set.
6820Sstevel@tonic-gate  *
6830Sstevel@tonic-gate  * Passes the irq number in the value pointed to by pci_irqp, and
6840Sstevel@tonic-gate  * polarity and sensitivity in the structure pointed to by dipintrflagp
6850Sstevel@tonic-gate  * to the caller.
6860Sstevel@tonic-gate  *
6870Sstevel@tonic-gate  * Note that if setting the irq resource failed, but successfuly obtained
6880Sstevel@tonic-gate  * the current irq resource settings, passes the current irq resources
6890Sstevel@tonic-gate  * and considers it a success.
6900Sstevel@tonic-gate  *
6910Sstevel@tonic-gate  * Returns:
6920Sstevel@tonic-gate  * ACPI_PSM_SUCCESS on success.
6930Sstevel@tonic-gate  *
6940Sstevel@tonic-gate  * ACPI_PSM_FAILURE if an error occured during the configuration or
6950Sstevel@tonic-gate  * if a suitable irq was not found for this device, or if setting the
6960Sstevel@tonic-gate  * irq resource and obtaining the current resource fails.
6970Sstevel@tonic-gate  *
6980Sstevel@tonic-gate  */
6990Sstevel@tonic-gate static int
uppc_acpi_irq_configure(acpi_psm_lnk_t * acpipsmlnkp,dev_info_t * dip,int * pci_irqp,iflag_t * dipintr_flagp)7000Sstevel@tonic-gate uppc_acpi_irq_configure(acpi_psm_lnk_t *acpipsmlnkp, dev_info_t *dip,
7010Sstevel@tonic-gate     int *pci_irqp, iflag_t *dipintr_flagp)
7020Sstevel@tonic-gate {
7030Sstevel@tonic-gate 	int i, min_share, foundnow, done = 0;
7040Sstevel@tonic-gate 	int32_t irq;
7050Sstevel@tonic-gate 	int32_t share_irq = -1;
7060Sstevel@tonic-gate 	int32_t chosen_irq = -1;
7070Sstevel@tonic-gate 	int cur_irq = -1;
7080Sstevel@tonic-gate 	acpi_irqlist_t *irqlistp;
7090Sstevel@tonic-gate 	acpi_irqlist_t *irqlistent;
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 	if ((acpi_get_possible_irq_resources(acpipsmlnkp, &irqlistp))
7120Sstevel@tonic-gate 	    == ACPI_PSM_FAILURE) {
7130Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: Unable to determine "
7140Sstevel@tonic-gate 		    "or assign IRQ for device %s, instance #%d: The system was "
7150Sstevel@tonic-gate 		    "unable to get the list of potential IRQs from ACPI.",
7160Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip)));
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate 		return (ACPI_PSM_FAILURE);
7190Sstevel@tonic-gate 	}
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate 	if ((acpi_get_current_irq_resource(acpipsmlnkp, &cur_irq,
7220Sstevel@tonic-gate 	    dipintr_flagp) == ACPI_PSM_SUCCESS) && (!uppc_unconditional_srs) &&
7230Sstevel@tonic-gate 	    (cur_irq > 0)) {
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate 		if (acpi_irqlist_find_irq(irqlistp, cur_irq, NULL)
7260Sstevel@tonic-gate 		    == ACPI_PSM_SUCCESS) {
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate 			acpi_free_irqlist(irqlistp);
7290Sstevel@tonic-gate 			ASSERT(pci_irqp != NULL);
7300Sstevel@tonic-gate 			*pci_irqp = cur_irq;
7310Sstevel@tonic-gate 			return (ACPI_PSM_SUCCESS);
7320Sstevel@tonic-gate 		}
7330Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: Could not find the "
7340Sstevel@tonic-gate 		    "current irq %d for device %s, instance #%d in ACPI's "
7350Sstevel@tonic-gate 		    "list of possible irqs for this device. Picking one from "
7360Sstevel@tonic-gate 		    " the latter list.", cur_irq, ddi_get_name(dip),
7370Sstevel@tonic-gate 		    ddi_get_instance(dip)));
7380Sstevel@tonic-gate 
7390Sstevel@tonic-gate 	}
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate 	irqlistent = irqlistp;
7420Sstevel@tonic-gate 	min_share = 255;
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate 	while (irqlistent != NULL) {
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 		for (foundnow = 0, i = 0; i < irqlistent->num_irqs; i++) {
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate 			irq = irqlistp->irqs[i];
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate 			if ((irq > MAX_ISA_IRQ) ||
7510Sstevel@tonic-gate 			    (irqlistent->intr_flags.intr_el == INTR_EL_EDGE) ||
7520Sstevel@tonic-gate 			    (irq == 0))
7530Sstevel@tonic-gate 				continue;
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate 			if (uppc_reserved_irqlist[irq])
7560Sstevel@tonic-gate 				continue;
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate 			if (uppc_irq_shared_table[irq] == 0) {
7590Sstevel@tonic-gate 				chosen_irq = irq;
7600Sstevel@tonic-gate 				foundnow = 1;
7610Sstevel@tonic-gate 				if (!(uppc_prefer_crs) || (irq == cur_irq)) {
7620Sstevel@tonic-gate 					done = 1;
7630Sstevel@tonic-gate 					break;
7640Sstevel@tonic-gate 				}
7650Sstevel@tonic-gate 			}
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 			if ((uppc_irq_shared_table[irq] < min_share) ||
7680Sstevel@tonic-gate 			    ((uppc_irq_shared_table[irq] == min_share) &&
7690Sstevel@tonic-gate 			    (cur_irq == irq) && (uppc_prefer_crs))) {
7700Sstevel@tonic-gate 				min_share = uppc_irq_shared_table[irq];
7710Sstevel@tonic-gate 				share_irq = irq;
7720Sstevel@tonic-gate 				foundnow = 1;
7730Sstevel@tonic-gate 			}
7740Sstevel@tonic-gate 		}
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 		/* If we found an IRQ in the inner loop, save the details */
7770Sstevel@tonic-gate 		if (foundnow && ((chosen_irq != -1) || (share_irq != -1))) {
7780Sstevel@tonic-gate 			/*
7790Sstevel@tonic-gate 			 * Copy the acpi_prs_private_t and flags from this
7800Sstevel@tonic-gate 			 * irq list entry, since we found an irq from this
7810Sstevel@tonic-gate 			 * entry.
7820Sstevel@tonic-gate 			 */
7830Sstevel@tonic-gate 			acpipsmlnkp->acpi_prs_prv = irqlistent->acpi_prs_prv;
7840Sstevel@tonic-gate 			*dipintr_flagp = irqlistent->intr_flags;
7850Sstevel@tonic-gate 		}
7860Sstevel@tonic-gate 
7870Sstevel@tonic-gate 		if (done)
7880Sstevel@tonic-gate 			break;
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate 		/* Load the next entry in the irqlist */
7910Sstevel@tonic-gate 		irqlistent = irqlistent->next;
7920Sstevel@tonic-gate 	}
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate 	acpi_free_irqlist(irqlistp);
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 	if (chosen_irq != -1)
7970Sstevel@tonic-gate 		irq = chosen_irq;
7980Sstevel@tonic-gate 	else if (share_irq != -1)
7990Sstevel@tonic-gate 		irq = share_irq;
8000Sstevel@tonic-gate 	else {
8010Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Could not find a "
8020Sstevel@tonic-gate 		    "suitable irq from the list of possible irqs for device "
8030Sstevel@tonic-gate 		    "%s, instance #%d in ACPI's list of possible\n",
8040Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip)));
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate 		return (ACPI_PSM_FAILURE);
8070Sstevel@tonic-gate 	}
8080Sstevel@tonic-gate 
8090Sstevel@tonic-gate 
8100Sstevel@tonic-gate 	UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Setting irq %d for device %s "
8110Sstevel@tonic-gate 	    "instance #%d\n", irq, ddi_get_name(dip), ddi_get_instance(dip)));
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 	if ((acpi_set_irq_resource(acpipsmlnkp, irq)) == ACPI_PSM_SUCCESS) {
8140Sstevel@tonic-gate 		/*
8150Sstevel@tonic-gate 		 * setting irq was successful, check to make sure CRS
8160Sstevel@tonic-gate 		 * reflects that. If CRS does not agree with what we
8170Sstevel@tonic-gate 		 * set, return the irq that was set.
8180Sstevel@tonic-gate 		 */
8190Sstevel@tonic-gate 
8200Sstevel@tonic-gate 		if (acpi_get_current_irq_resource(acpipsmlnkp, &cur_irq,
8210Sstevel@tonic-gate 		    dipintr_flagp) == ACPI_PSM_SUCCESS) {
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 			if (cur_irq != irq)
8240Sstevel@tonic-gate 				UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: "
8250Sstevel@tonic-gate 				    "IRQ resource set (irqno %d) for device %s "
8260Sstevel@tonic-gate 				    "instance #%d, differs from current "
8270Sstevel@tonic-gate 				    "setting irqno %d",
8280Sstevel@tonic-gate 				    irq, ddi_get_name(dip),
8290Sstevel@tonic-gate 				    ddi_get_instance(dip), cur_irq));
8300Sstevel@tonic-gate 		}
8310Sstevel@tonic-gate 		/*
8320Sstevel@tonic-gate 		 * return the irq that was set, and not what CRS reports,
8330Sstevel@tonic-gate 		 * since CRS has been seen to be bogus on some systems
8340Sstevel@tonic-gate 		 */
8350Sstevel@tonic-gate 		cur_irq = irq;
8360Sstevel@tonic-gate 	} else {
8370Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: set resource irq %d "
8380Sstevel@tonic-gate 		    "failed for device %s instance #%d",
8390Sstevel@tonic-gate 		    irq, ddi_get_name(dip), ddi_get_instance(dip)));
8400Sstevel@tonic-gate 		if (cur_irq == -1)
8410Sstevel@tonic-gate 			return (ACPI_PSM_FAILURE);
8420Sstevel@tonic-gate 	}
8430Sstevel@tonic-gate 
8440Sstevel@tonic-gate 	ASSERT(pci_irqp != NULL);
8450Sstevel@tonic-gate 	*pci_irqp = cur_irq;
8460Sstevel@tonic-gate 	return (ACPI_PSM_SUCCESS);
8470Sstevel@tonic-gate }
8480Sstevel@tonic-gate 
8490Sstevel@tonic-gate 
8500Sstevel@tonic-gate /*ARGSUSED*/
8510Sstevel@tonic-gate static int
uppc_translate_irq(dev_info_t * dip,int irqno)8520Sstevel@tonic-gate uppc_translate_irq(dev_info_t *dip, int irqno)
8530Sstevel@tonic-gate {
8540Sstevel@tonic-gate 	char dev_type[16];
8550Sstevel@tonic-gate 	int dev_len, pci_irq, devid, busid;
8560Sstevel@tonic-gate 	ddi_acc_handle_t cfg_handle;
857926Smyers 	uchar_t ipin, iline;
8580Sstevel@tonic-gate 	iflag_t intr_flag;
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 	if (dip == NULL) {
8610Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: irqno = %d"
8620Sstevel@tonic-gate 		    " dip = NULL\n", irqno));
8630Sstevel@tonic-gate 		return (irqno);
8640Sstevel@tonic-gate 	}
8650Sstevel@tonic-gate 
8660Sstevel@tonic-gate 	if (!uppc_enable_acpi) {
8670Sstevel@tonic-gate 		return (irqno);
8680Sstevel@tonic-gate 	}
8690Sstevel@tonic-gate 
8700Sstevel@tonic-gate 	dev_len = sizeof (dev_type);
871506Scth 	if (ddi_getlongprop_buf(DDI_DEV_T_ANY, ddi_get_parent(dip),
8720Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "device_type", (caddr_t)dev_type,
8730Sstevel@tonic-gate 	    &dev_len) != DDI_PROP_SUCCESS) {
8740Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: irqno %d"
8750Sstevel@tonic-gate 		    "device %s instance %d no device_type\n", irqno,
8760Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip)));
8770Sstevel@tonic-gate 		return (irqno);
8780Sstevel@tonic-gate 	}
8790Sstevel@tonic-gate 
880881Sjohnny 	if ((strcmp(dev_type, "pci") == 0) ||
881881Sjohnny 	    (strcmp(dev_type, "pciex") == 0)) {
8820Sstevel@tonic-gate 
8830Sstevel@tonic-gate 		/* pci device */
8840Sstevel@tonic-gate 		if (acpica_get_bdf(dip, &busid, &devid, NULL) != 0)
8850Sstevel@tonic-gate 			return (irqno);
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 		if (pci_config_setup(dip, &cfg_handle) != DDI_SUCCESS)
8880Sstevel@tonic-gate 			return (irqno);
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate 		ipin = pci_config_get8(cfg_handle, PCI_CONF_IPIN) - PCI_INTA;
891926Smyers 		iline = pci_config_get8(cfg_handle, PCI_CONF_ILINE);
8920Sstevel@tonic-gate 		if (uppc_acpi_translate_pci_irq(dip, busid, devid,
8930Sstevel@tonic-gate 		    ipin, &pci_irq, &intr_flag) == ACPI_PSM_SUCCESS) {
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate 			UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: [ACPI] new irq "
8960Sstevel@tonic-gate 			    "%d old irq %d device %s, instance %d\n", pci_irq,
8970Sstevel@tonic-gate 			    irqno, ddi_get_name(dip), ddi_get_instance(dip)));
8980Sstevel@tonic-gate 
8990Sstevel@tonic-gate 			/*
9000Sstevel@tonic-gate 			 * Make sure pci_irq is within range.
9010Sstevel@tonic-gate 			 * Otherwise, fall through and return irqno.
9020Sstevel@tonic-gate 			 */
903926Smyers 			if (pci_irq <= MAX_ISA_IRQ) {
904926Smyers 				if (iline != pci_irq) {
905926Smyers 					/*
906926Smyers 					 * Update the device's ILINE byte,
907926Smyers 					 * in case uppc_acpi_translate_pci_irq
908926Smyers 					 * has choosen a different pci_irq
909926Smyers 					 * than the BIOS has configured.
910926Smyers 					 * Some chipsets use the value in
911926Smyers 					 * ILINE to control interrupt routing,
912926Smyers 					 * in conflict with the PCI spec.
913926Smyers 					 */
914926Smyers 					pci_config_put8(cfg_handle,
915926Smyers 					    PCI_CONF_ILINE, pci_irq);
916926Smyers 				}
917926Smyers 				pci_config_teardown(&cfg_handle);
9180Sstevel@tonic-gate 				return (pci_irq);
919926Smyers 			}
9200Sstevel@tonic-gate 		}
921926Smyers 		pci_config_teardown(&cfg_handle);
9220Sstevel@tonic-gate 
9230Sstevel@tonic-gate 		/* FALLTHRU to common case - returning irqno */
9240Sstevel@tonic-gate 	} else {
925347Smyers 		/* non-PCI; assumes ISA-style edge-triggered */
926347Smyers 		psm_set_elcr(irqno, 0); 	/* set IRQ to ISA mode */
927347Smyers 
9280Sstevel@tonic-gate 		UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: non-pci,"
9290Sstevel@tonic-gate 		    "irqno %d device %s instance %d\n", irqno,
9300Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip)));
9310Sstevel@tonic-gate 	}
9320Sstevel@tonic-gate 
9330Sstevel@tonic-gate 	return (irqno);
9340Sstevel@tonic-gate }
9350Sstevel@tonic-gate 
9360Sstevel@tonic-gate /*
9370Sstevel@tonic-gate  * uppc_intr_enter() raises the ipl to the level of the current interrupt,
9380Sstevel@tonic-gate  * and sends EOI to the pics.
9390Sstevel@tonic-gate  * If interrupt is 7 or 15 and not spurious interrupt, send specific EOI
9400Sstevel@tonic-gate  * else send non-specific EOI
9410Sstevel@tonic-gate  * uppc_intr_enter() returns the new priority level,
9420Sstevel@tonic-gate  * or -1 for spurious interrupt
9430Sstevel@tonic-gate  */
9440Sstevel@tonic-gate static int
uppc_intr_enter(int ipl,int * vector)9450Sstevel@tonic-gate uppc_intr_enter(int ipl, int *vector)
9460Sstevel@tonic-gate {
9470Sstevel@tonic-gate 	int newipl;
9480Sstevel@tonic-gate 	int intno;
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate 	intno = (*vector);
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate 	ASSERT(intno < 256);
9530Sstevel@tonic-gate 
9540Sstevel@tonic-gate 	newipl = autovect[intno].avh_hi_pri;
9550Sstevel@tonic-gate 
9560Sstevel@tonic-gate 	/*
9570Sstevel@tonic-gate 	 * During wait_till_seen() periods when interrupt vector is being
9580Sstevel@tonic-gate 	 * removed in remove_av(), the removed hardware interrupt could
9590Sstevel@tonic-gate 	 * trigger and got here with newipl 0.  It has to send EOI
9600Sstevel@tonic-gate 	 * as usual but no need to call setspl and returns -1 like spurious.
9610Sstevel@tonic-gate 	 */
9620Sstevel@tonic-gate 	if ((intno & 7) != 7) {
9630Sstevel@tonic-gate 		if (newipl)
9640Sstevel@tonic-gate 			uppc_setspl(newipl);
9650Sstevel@tonic-gate 		outb(MCMD_PORT, PIC_NSEOI);
9660Sstevel@tonic-gate 		if (intno >= 8) {
9670Sstevel@tonic-gate 			outb(SCMD_PORT, PIC_NSEOI);
9680Sstevel@tonic-gate 		}
9690Sstevel@tonic-gate 	} else { /* int was 7 or 15 */
9700Sstevel@tonic-gate 		if (newipl && newipl <= ipl) { /* Check for spurious int */
9710Sstevel@tonic-gate 			if (intno != 7)
9720Sstevel@tonic-gate 				outb(MCMD_PORT, PIC_NSEOI);
9730Sstevel@tonic-gate 			return (-1); /* Spurious int */
9740Sstevel@tonic-gate 		} else {
9750Sstevel@tonic-gate 			if (newipl)
9760Sstevel@tonic-gate 				uppc_setspl(newipl);
9770Sstevel@tonic-gate 			if (intno != 7) {
9780Sstevel@tonic-gate 				outb(MCMD_PORT, PIC_NSEOI);
9790Sstevel@tonic-gate 				outb(SCMD_PORT, PIC_SEOI_LVL7);
9800Sstevel@tonic-gate 			} else  {
9810Sstevel@tonic-gate 				outb(MCMD_PORT, PIC_SEOI_LVL7);
9820Sstevel@tonic-gate 			}
9830Sstevel@tonic-gate 		}
9840Sstevel@tonic-gate 	}
9850Sstevel@tonic-gate 
9860Sstevel@tonic-gate 	if (newipl)
9870Sstevel@tonic-gate 		return (newipl);
9880Sstevel@tonic-gate 	else
9890Sstevel@tonic-gate 		return (-1); /* not real spurious int */
9900Sstevel@tonic-gate }
9910Sstevel@tonic-gate 
9920Sstevel@tonic-gate /*
9930Sstevel@tonic-gate  * uppc_intr_exit() restores the old interrupt
9940Sstevel@tonic-gate  * priority level after processing an interrupt.
9950Sstevel@tonic-gate  * It is called with interrupts disabled, and does not enable interrupts.
9960Sstevel@tonic-gate  */
9970Sstevel@tonic-gate /* ARGSUSED */
9980Sstevel@tonic-gate static void
uppc_intr_exit(int ipl,int vector)9990Sstevel@tonic-gate uppc_intr_exit(int ipl, int vector)
10000Sstevel@tonic-gate {
10010Sstevel@tonic-gate 	uppc_setspl(ipl);
10020Sstevel@tonic-gate }
10030Sstevel@tonic-gate 
10040Sstevel@tonic-gate /*
10050Sstevel@tonic-gate  * uppc_setspl() loads new interrupt masks into the pics
10060Sstevel@tonic-gate  * based on input ipl.
10070Sstevel@tonic-gate  */
10080Sstevel@tonic-gate /* ARGSUSED */
10090Sstevel@tonic-gate static void
uppc_setspl(int ipl)10100Sstevel@tonic-gate uppc_setspl(int ipl)
10110Sstevel@tonic-gate {
10120Sstevel@tonic-gate 	struct standard_pic *pp;
10130Sstevel@tonic-gate 	uint8_t smask, mmask;
10140Sstevel@tonic-gate 	uint8_t cursmask, curmmask;
10150Sstevel@tonic-gate 
10160Sstevel@tonic-gate 	pp = &pics0;
10170Sstevel@tonic-gate 	smask = pp->c_iplmask[ipl * 2];
10180Sstevel@tonic-gate 	mmask = pp->c_iplmask[ipl * 2 + 1];
10190Sstevel@tonic-gate 	cursmask = pp->c_curmask[0];
10200Sstevel@tonic-gate 	curmmask = pp->c_curmask[1];
10210Sstevel@tonic-gate 	if (cursmask == smask && curmmask == mmask)
10220Sstevel@tonic-gate 		return;
10230Sstevel@tonic-gate 	pp->c_curmask[0] = smask;
10240Sstevel@tonic-gate 	pp->c_curmask[1] = mmask;
10250Sstevel@tonic-gate 
10260Sstevel@tonic-gate 	if (cursmask != smask) {
10270Sstevel@tonic-gate 		/*
10280Sstevel@tonic-gate 		 * program new slave pic mask
10290Sstevel@tonic-gate 		 */
10300Sstevel@tonic-gate 		outb(SIMR_PORT, smask);
10310Sstevel@tonic-gate 	}
10320Sstevel@tonic-gate 	if (curmmask != mmask) {
10330Sstevel@tonic-gate 		/*
10340Sstevel@tonic-gate 		 * program new master pic mask
10350Sstevel@tonic-gate 		 */
10360Sstevel@tonic-gate 		outb(MIMR_PORT, mmask);
10370Sstevel@tonic-gate 	}
10380Sstevel@tonic-gate 	/*
10390Sstevel@tonic-gate 	 * read master to allow pics to settle
10400Sstevel@tonic-gate 	 */
10410Sstevel@tonic-gate 	(void) inb(MIMR_PORT);
10420Sstevel@tonic-gate }
10430Sstevel@tonic-gate 
10440Sstevel@tonic-gate /*
10450Sstevel@tonic-gate  * uppc_gethrtime() returns high resolution timer value
10460Sstevel@tonic-gate  */
10470Sstevel@tonic-gate static hrtime_t
uppc_gethrtime()10480Sstevel@tonic-gate uppc_gethrtime()
10490Sstevel@tonic-gate {
10500Sstevel@tonic-gate 	hrtime_t timeval, temp;
10513446Smrj 	unsigned int ctr0;
10523446Smrj 	ulong_t oflags;
10530Sstevel@tonic-gate 
10540Sstevel@tonic-gate 	oflags = intr_clear(); /* disable ints */
10550Sstevel@tonic-gate 	lock_set(&uppc_gethrtime_lock);
10560Sstevel@tonic-gate retry:
10570Sstevel@tonic-gate 	temp = hrtime_base;
10580Sstevel@tonic-gate 	outb(PITCTL_PORT, 0);	/* latch counter 0 */
10590Sstevel@tonic-gate 	/*
10600Sstevel@tonic-gate 	 * read counter 0
10610Sstevel@tonic-gate 	 */
10620Sstevel@tonic-gate 	ctr0 = inb(PITCTR0_PORT);
10630Sstevel@tonic-gate 	ctr0 |= inb(PITCTR0_PORT) << 8;
10640Sstevel@tonic-gate 	timeval = (hrtime_t)ctr0 * (NANOSEC / PIT_HZ);
10650Sstevel@tonic-gate 	if (temp != hrtime_base)
10660Sstevel@tonic-gate 		goto retry;
10670Sstevel@tonic-gate 	timeval -= temp;
10680Sstevel@tonic-gate 	if (timeval < uppc_lasthrtime)
10690Sstevel@tonic-gate 		timeval = uppc_lasthrtime;
10700Sstevel@tonic-gate 	uppc_lasthrtime = timeval;
10710Sstevel@tonic-gate 	lock_clear(&uppc_gethrtime_lock);
10720Sstevel@tonic-gate 	intr_restore(oflags);
10730Sstevel@tonic-gate 	return (timeval);
10740Sstevel@tonic-gate }
1075