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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #define PSMI_1_5 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/mutex.h> 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/time.h> 340Sstevel@tonic-gate #include <sys/machlock.h> 350Sstevel@tonic-gate #include <sys/smp_impldefs.h> 360Sstevel@tonic-gate #include <sys/uadmin.h> 370Sstevel@tonic-gate #include <sys/promif.h> 380Sstevel@tonic-gate #include <sys/psm.h> 390Sstevel@tonic-gate #include <sys/pit.h> 400Sstevel@tonic-gate #include <sys/psm_common.h> 410Sstevel@tonic-gate #include <sys/atomic.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate #define NSEC_IN_SEC 1000000000 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * External References 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate extern int intr_clear(void); 490Sstevel@tonic-gate extern void intr_restore(uint_t); 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * Local Function Prototypes 530Sstevel@tonic-gate */ 540Sstevel@tonic-gate static void uppc_softinit(void); 550Sstevel@tonic-gate static void uppc_picinit(); 560Sstevel@tonic-gate static int uppc_clkinit(int); 570Sstevel@tonic-gate static int uppc_addspl(int irqno, int ipl, int min_ipl, int max_ipl); 580Sstevel@tonic-gate static int uppc_delspl(int irqno, int ipl, int min_ipl, int max_ipl); 590Sstevel@tonic-gate static processorid_t uppc_get_next_processorid(processorid_t cpu_id); 600Sstevel@tonic-gate static int uppc_get_clockirq(int ipl); 610Sstevel@tonic-gate static int uppc_probe(void); 620Sstevel@tonic-gate static int uppc_translate_irq(dev_info_t *dip, int irqno); 630Sstevel@tonic-gate static void uppc_shutdown(int cmd, int fcn); 640Sstevel@tonic-gate static void uppc_preshutdown(int cmd, int fcn); 650Sstevel@tonic-gate static int uppc_init_acpi(void); 660Sstevel@tonic-gate static void uppc_setspl(int); 670Sstevel@tonic-gate static int uppc_intr_enter(int, int *); 680Sstevel@tonic-gate static void uppc_intr_exit(int, int); 690Sstevel@tonic-gate static hrtime_t uppc_gethrtime(); 700Sstevel@tonic-gate 710Sstevel@tonic-gate static int uppc_acpi_irq_configure(acpi_psm_lnk_t *acpipsmlnkp, dev_info_t *dip, 720Sstevel@tonic-gate int *pci_irqp, iflag_t *intr_flagp); 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * Global Data 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate static struct standard_pic pics0; 780Sstevel@tonic-gate int uppc_use_acpi = 1; /* Use ACPI by default */ 790Sstevel@tonic-gate int uppc_enable_acpi = 0; 800Sstevel@tonic-gate 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * For interrupt link devices, if uppc_unconditional_srs is set, an irq resource 840Sstevel@tonic-gate * will be assigned (via _SRS). If it is not set, use the current 850Sstevel@tonic-gate * irq setting (via _CRS), but only if that irq is in the set of possible 860Sstevel@tonic-gate * irqs (returned by _PRS) for the device. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate int uppc_unconditional_srs = 1; 890Sstevel@tonic-gate 900Sstevel@tonic-gate /* 910Sstevel@tonic-gate * For interrupt link devices, if uppc_prefer_crs is set when we are 920Sstevel@tonic-gate * assigning an IRQ resource to a device, prefer the current IRQ setting 930Sstevel@tonic-gate * over other possible irq settings under same conditions. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate int uppc_prefer_crs = 1; 960Sstevel@tonic-gate 970Sstevel@tonic-gate int uppc_verbose = 0; 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* flag definitions for uppc_verbose */ 1000Sstevel@tonic-gate #define UPPC_VERBOSE_IRQ_FLAG 0x00000001 1010Sstevel@tonic-gate #define UPPC_VERBOSE_POWEROFF_FLAG 0x00000002 1020Sstevel@tonic-gate #define UPPC_VERBOSE_POWEROFF_PAUSE_FLAG 0x00000004 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate #define UPPC_VERBOSE_IRQ(fmt) \ 1060Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG) \ 1070Sstevel@tonic-gate cmn_err fmt; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate #define UPPC_VERBOSE_POWEROFF(fmt) \ 1100Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG) \ 1110Sstevel@tonic-gate prom_printf fmt; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate uchar_t uppc_reserved_irqlist[MAX_ISA_IRQ + 1]; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate static uint16_t uppc_irq_shared_table[MAX_ISA_IRQ + 1]; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * Contains SCI irqno from FADT after initialization 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate static int uppc_sci = -1; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * Local Static Data 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate static lock_t uppc_gethrtime_lock; 1270Sstevel@tonic-gate static hrtime_t uppc_lasthrtime; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #ifdef UPPC_DEBUG 1310Sstevel@tonic-gate #define DENT 0x0001 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate static int uppc_debug = 0; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate #endif 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate static struct psm_ops uppc_ops = { 1400Sstevel@tonic-gate uppc_probe, /* psm_probe */ 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate uppc_softinit, /* psm_init */ 1430Sstevel@tonic-gate uppc_picinit, /* psm_picinit */ 1440Sstevel@tonic-gate uppc_intr_enter, /* psm_intr_enter */ 1450Sstevel@tonic-gate uppc_intr_exit, /* psm_intr_exit */ 1460Sstevel@tonic-gate uppc_setspl, /* psm_setspl */ 1470Sstevel@tonic-gate uppc_addspl, /* psm_addspl */ 1480Sstevel@tonic-gate uppc_delspl, /* psm_delspl */ 1490Sstevel@tonic-gate (int (*)(processorid_t))NULL, /* psm_disable_intr */ 1500Sstevel@tonic-gate (void (*)(processorid_t))NULL, /* psm_enable_intr */ 1510Sstevel@tonic-gate (int (*)(int))NULL, /* psm_softlvl_to_irq */ 1520Sstevel@tonic-gate (void (*)(int))NULL, /* psm_set_softintr */ 1530Sstevel@tonic-gate (void (*)(processorid_t))NULL, /* psm_set_idlecpu */ 1540Sstevel@tonic-gate (void (*)(processorid_t))NULL, /* psm_unset_idlecpu */ 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate uppc_clkinit, /* psm_clkinit */ 1570Sstevel@tonic-gate uppc_get_clockirq, /* psm_get_clockirq */ 1580Sstevel@tonic-gate (void (*)(void))NULL, /* psm_hrtimeinit */ 1590Sstevel@tonic-gate uppc_gethrtime, /* psm_gethrtime */ 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate uppc_get_next_processorid, /* psm_get_next_processorid */ 1620Sstevel@tonic-gate (void (*)(processorid_t, caddr_t))NULL, /* psm_cpu_start */ 1630Sstevel@tonic-gate (int (*)(void))NULL, /* psm_post_cpu_start */ 1640Sstevel@tonic-gate uppc_shutdown, /* psm_shutdown */ 1650Sstevel@tonic-gate (int (*)(int, int))NULL, /* psm_get_ipivect */ 1660Sstevel@tonic-gate (void (*)(processorid_t, int))NULL, /* psm_send_ipi */ 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate uppc_translate_irq, /* psm_translate_irq */ 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate (int (*)(todinfo_t *))NULL, /* psm_tod_get */ 1710Sstevel@tonic-gate (int (*)(todinfo_t *))NULL, /* psm_tod_set */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate (void (*)(int, char *))NULL, /* psm_notify_error */ 1740Sstevel@tonic-gate (void (*)(int msg))NULL, /* psm_notify_func */ 1750Sstevel@tonic-gate (void (*)(hrtime_t time))NULL, /* psm_timer_reprogram */ 1760Sstevel@tonic-gate (void (*)(void))NULL, /* psm_timer_enable */ 1770Sstevel@tonic-gate (void (*)(void))NULL, /* psm_timer_disable */ 1780Sstevel@tonic-gate (void (*)(void *arg))NULL, /* psm_post_cyclic_setup */ 1790Sstevel@tonic-gate uppc_preshutdown, /* psm_preshutdown */ 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate (int (*)(dev_info_t *, ddi_intr_handle_impl_t *, 1820Sstevel@tonic-gate psm_intr_op_t, int *))NULL /* psm_intr_ops */ 1830Sstevel@tonic-gate }; 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate static struct psm_info uppc_info = { 1870Sstevel@tonic-gate PSM_INFO_VER01_5, /* version */ 1880Sstevel@tonic-gate PSM_OWN_SYS_DEFAULT, /* ownership */ 1890Sstevel@tonic-gate (struct psm_ops *)&uppc_ops, /* operation */ 1900Sstevel@tonic-gate "uppc", /* machine name */ 1910Sstevel@tonic-gate "UniProcessor PC", /* machine descriptions */ 1920Sstevel@tonic-gate }; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate * Configuration Data 1960Sstevel@tonic-gate */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* 1990Sstevel@tonic-gate * This is the loadable module wrapper. 2000Sstevel@tonic-gate */ 2010Sstevel@tonic-gate #include <sys/modctl.h> 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate static void *uppc_hdlp; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate int 2060Sstevel@tonic-gate _init(void) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate return (psm_mod_init(&uppc_hdlp, &uppc_info)); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate int 2120Sstevel@tonic-gate _fini(void) 2130Sstevel@tonic-gate { 2140Sstevel@tonic-gate return (psm_mod_fini(&uppc_hdlp, &uppc_info)); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate int 2180Sstevel@tonic-gate _info(struct modinfo *modinfop) 2190Sstevel@tonic-gate { 2200Sstevel@tonic-gate return (psm_mod_info(&uppc_hdlp, &uppc_info, modinfop)); 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate /* 2240Sstevel@tonic-gate * Autoconfiguration Routines 2250Sstevel@tonic-gate */ 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate static int 2280Sstevel@tonic-gate uppc_probe(void) 2290Sstevel@tonic-gate { 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate return (PSM_SUCCESS); 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate static void 2360Sstevel@tonic-gate uppc_softinit(void) 2370Sstevel@tonic-gate { 2380Sstevel@tonic-gate struct standard_pic *pp; 2390Sstevel@tonic-gate int i; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate pp = &pics0; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate if (uppc_use_acpi && uppc_init_acpi()) { 2450Sstevel@tonic-gate build_reserved_irqlist((uchar_t *)uppc_reserved_irqlist); 2460Sstevel@tonic-gate for (i = 0; i <= MAX_ISA_IRQ; i++) 2470Sstevel@tonic-gate uppc_irq_shared_table[i] = 0; 2480Sstevel@tonic-gate uppc_enable_acpi = 1; 2490Sstevel@tonic-gate } 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * initialize the ipl mask 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate for (i = 0; i < (MAXIPL << 1); i += 2) { 2550Sstevel@tonic-gate /* enable slave lines on master */ 2560Sstevel@tonic-gate pp->c_iplmask[i] = 0xff; 2570Sstevel@tonic-gate pp->c_iplmask[i+1] = (0xff & ~(1 << MASTERLINE)); 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /*ARGSUSED*/ 2620Sstevel@tonic-gate static int 2630Sstevel@tonic-gate uppc_clkinit(int hertz) 2640Sstevel@tonic-gate { 2650Sstevel@tonic-gate ulong_t clkticks = PIT_HZ / hz; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate if (hertz == 0) 2680Sstevel@tonic-gate return (0); /* One shot mode not supported */ 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate /* 2710Sstevel@tonic-gate * program timer 0 2720Sstevel@tonic-gate */ 2730Sstevel@tonic-gate outb(PITCTL_PORT, (PIT_C0|PIT_NDIVMODE|PIT_READMODE)); 2740Sstevel@tonic-gate outb(PITCTR0_PORT, (uchar_t)clkticks); 2750Sstevel@tonic-gate outb(PITCTR0_PORT, (uchar_t)(clkticks>>8)); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate return (NSEC_IN_SEC / hertz); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate static void 2810Sstevel@tonic-gate uppc_picinit() 2820Sstevel@tonic-gate { 2830Sstevel@tonic-gate picsetup(); 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /* 2860Sstevel@tonic-gate * If a valid SCI is present, manually addspl() 2870Sstevel@tonic-gate * since we're not set-up early enough in boot 2880Sstevel@tonic-gate * to do it "conventionally" (via add_avintr) 2890Sstevel@tonic-gate */ 2900Sstevel@tonic-gate if (uppc_sci >= 0) 2910Sstevel@tonic-gate (void) uppc_addspl(uppc_sci, SCI_IPL, SCI_IPL, SCI_IPL); 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /*ARGSUSED3*/ 2950Sstevel@tonic-gate static int 2960Sstevel@tonic-gate uppc_addspl(int irqno, int ipl, int min_ipl, int max_ipl) 2970Sstevel@tonic-gate { 2980Sstevel@tonic-gate struct standard_pic *pp; 2990Sstevel@tonic-gate int i; 3000Sstevel@tonic-gate int startidx; 3010Sstevel@tonic-gate uchar_t vectmask; 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate if (ipl != min_ipl) 3040Sstevel@tonic-gate return (0); 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate if (irqno > 7) { 3070Sstevel@tonic-gate vectmask = 1 << (irqno - 8); 3080Sstevel@tonic-gate startidx = (ipl << 1); 3090Sstevel@tonic-gate } else { 3100Sstevel@tonic-gate vectmask = 1 << irqno; 3110Sstevel@tonic-gate startidx = (ipl << 1) + 1; 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate if (irqno <= MAX_ISA_IRQ) 3150Sstevel@tonic-gate atomic_add_16(&uppc_irq_shared_table[irqno], 1); 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate /* 3180Sstevel@tonic-gate * mask intr same or above ipl 3190Sstevel@tonic-gate * level MAXIPL has all intr off as init. default 3200Sstevel@tonic-gate */ 3210Sstevel@tonic-gate pp = &pics0; 3220Sstevel@tonic-gate for (i = startidx; i < (MAXIPL << 1); i += 2) { 3230Sstevel@tonic-gate if (pp->c_iplmask[i] & vectmask) 3240Sstevel@tonic-gate break; 3250Sstevel@tonic-gate pp->c_iplmask[i] |= vectmask; 3260Sstevel@tonic-gate } 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* 3290Sstevel@tonic-gate * unmask intr below ipl 3300Sstevel@tonic-gate */ 3310Sstevel@tonic-gate for (i = startidx-2; i >= 0; i -= 2) { 3320Sstevel@tonic-gate if (!(pp->c_iplmask[i] & vectmask)) 3330Sstevel@tonic-gate break; 3340Sstevel@tonic-gate pp->c_iplmask[i] &= ~vectmask; 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate return (0); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate static int 3400Sstevel@tonic-gate uppc_delspl(int irqno, int ipl, int min_ipl, int max_ipl) 3410Sstevel@tonic-gate { 3420Sstevel@tonic-gate struct standard_pic *pp; 3430Sstevel@tonic-gate int i; 3440Sstevel@tonic-gate uchar_t vectmask; 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * skip if we are not deleting the last handler 3480Sstevel@tonic-gate * and the ipl is higher than minimum 3490Sstevel@tonic-gate */ 3500Sstevel@tonic-gate if ((max_ipl != PSM_INVALID_IPL) && (ipl >= min_ipl)) 3510Sstevel@tonic-gate return (0); 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate if (irqno > 7) { 3540Sstevel@tonic-gate vectmask = 1 << (irqno - 8); 3550Sstevel@tonic-gate i = 0; 3560Sstevel@tonic-gate } else { 3570Sstevel@tonic-gate vectmask = 1 << irqno; 3580Sstevel@tonic-gate i = 1; 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate if (irqno <= MAX_ISA_IRQ) 3620Sstevel@tonic-gate atomic_add_16(&uppc_irq_shared_table[irqno], -1); 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate pp = &pics0; 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate /* 3670Sstevel@tonic-gate * check any handlers left for this irqno 3680Sstevel@tonic-gate */ 3690Sstevel@tonic-gate if (max_ipl != PSM_INVALID_IPL) { 3700Sstevel@tonic-gate /* 3710Sstevel@tonic-gate * unmasks all levels below the lowest priority 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate i += ((min_ipl - 1) << 1); 3740Sstevel@tonic-gate for (; i >= 0; i -= 2) { 3750Sstevel@tonic-gate if (!(pp->c_iplmask[i] & vectmask)) 3760Sstevel@tonic-gate break; 3770Sstevel@tonic-gate pp->c_iplmask[i] &= ~vectmask; 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate } else { 3800Sstevel@tonic-gate /* 3810Sstevel@tonic-gate * set mask to all levels 3820Sstevel@tonic-gate */ 3830Sstevel@tonic-gate for (; i < (MAXIPL << 1); i += 2) { 3840Sstevel@tonic-gate if (pp->c_iplmask[i] & vectmask) 3850Sstevel@tonic-gate break; 3860Sstevel@tonic-gate pp->c_iplmask[i] |= vectmask; 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate } 3890Sstevel@tonic-gate return (0); 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate static processorid_t 3930Sstevel@tonic-gate uppc_get_next_processorid(processorid_t cpu_id) 3940Sstevel@tonic-gate { 3950Sstevel@tonic-gate if (cpu_id == -1) 3960Sstevel@tonic-gate return (0); 3970Sstevel@tonic-gate return (-1); 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate /*ARGSUSED*/ 4010Sstevel@tonic-gate static int 4020Sstevel@tonic-gate uppc_get_clockirq(int ipl) 4030Sstevel@tonic-gate { 4040Sstevel@tonic-gate return (CLOCK_VECTOR); 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate static int 4090Sstevel@tonic-gate uppc_init_acpi(void) 4100Sstevel@tonic-gate { 4110Sstevel@tonic-gate int verboseflags = 0; 4120Sstevel@tonic-gate int sci; 4130Sstevel@tonic-gate iflag_t sci_flags; 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * Process SCI configuration here; this may return 4170Sstevel@tonic-gate * an error if acpi-user-options has specified 4180Sstevel@tonic-gate * legacy mode (use ACPI without ACPI mode or SCI) 4190Sstevel@tonic-gate */ 4200Sstevel@tonic-gate if (acpica_get_sci(&sci, &sci_flags) != AE_OK) 4210Sstevel@tonic-gate sci = -1; 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /* 4240Sstevel@tonic-gate * Initialize sub-system - if error is returns, ACPI is not 4250Sstevel@tonic-gate * used. 4260Sstevel@tonic-gate */ 4270Sstevel@tonic-gate if (acpica_init() != AE_OK) 4280Sstevel@tonic-gate return (0); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * uppc implies system is in PIC mode; set edge/level 4320Sstevel@tonic-gate * via ELCR based on return value from get_sci; this 4330Sstevel@tonic-gate * will default to level/low if no override present, 4340Sstevel@tonic-gate * as recommended by Intel ACPI CA team. 4350Sstevel@tonic-gate */ 4360Sstevel@tonic-gate if (sci >= 0) { 4370Sstevel@tonic-gate ASSERT((sci_flags.intr_el == INTR_EL_LEVEL) || 4380Sstevel@tonic-gate (sci_flags.intr_el == INTR_EL_EDGE)); 4390Sstevel@tonic-gate 440*347Smyers psm_set_elcr(sci, sci_flags.intr_el == INTR_EL_LEVEL); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate /* 4440Sstevel@tonic-gate * Remember SCI for later use 4450Sstevel@tonic-gate */ 4460Sstevel@tonic-gate uppc_sci = sci; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG) 4490Sstevel@tonic-gate verboseflags |= PSM_VERBOSE_IRQ_FLAG; 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG) 4520Sstevel@tonic-gate verboseflags |= PSM_VERBOSE_POWEROFF_FLAG; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_POWEROFF_PAUSE_FLAG) 4550Sstevel@tonic-gate verboseflags |= PSM_VERBOSE_POWEROFF_PAUSE_FLAG; 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate if (acpi_psm_init(uppc_info.p_mach_idstring, verboseflags) == 4580Sstevel@tonic-gate ACPI_PSM_FAILURE) { 4590Sstevel@tonic-gate return (0); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate return (1); 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate static void 4670Sstevel@tonic-gate uppc_preshutdown(int cmd, int fcn) 4680Sstevel@tonic-gate { 4690Sstevel@tonic-gate UPPC_VERBOSE_POWEROFF(("uppc_preshutdown(%d,%d);\n", cmd, fcn)); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate if ((cmd != A_SHUTDOWN) || (fcn != AD_POWEROFF)) { 4720Sstevel@tonic-gate return; 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate if (uppc_enable_acpi) { 4760Sstevel@tonic-gate UPPC_VERBOSE_POWEROFF(("uppc_preshutdown: ACPI enabled\n")); 4770Sstevel@tonic-gate } else { 4780Sstevel@tonic-gate UPPC_VERBOSE_POWEROFF(("uppc_preshutdown: ACPI not enabled\n")); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate static void 4830Sstevel@tonic-gate uppc_shutdown(int cmd, int fcn) 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate UPPC_VERBOSE_POWEROFF(("uppc_shutdown(%d,%d);\n", cmd, fcn)); 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate if ((cmd != A_SHUTDOWN) || (fcn != AD_POWEROFF)) { 4880Sstevel@tonic-gate return; 4890Sstevel@tonic-gate } 4900Sstevel@tonic-gate if (uppc_enable_acpi) 4910Sstevel@tonic-gate (void) acpi_poweroff(); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate static int 4950Sstevel@tonic-gate uppc_acpi_translate_pci_irq(dev_info_t *dip, int busid, int devid, 4960Sstevel@tonic-gate int ipin, int *pci_irqp, iflag_t *intr_flagp) 4970Sstevel@tonic-gate { 4980Sstevel@tonic-gate int status; 4990Sstevel@tonic-gate acpi_psm_lnk_t acpipsmlnk; 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate if ((status = acpi_get_irq_cache_ent(busid, devid, ipin, pci_irqp, 5020Sstevel@tonic-gate intr_flagp)) == ACPI_PSM_SUCCESS) { 5030Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Found irqno %d " 5040Sstevel@tonic-gate "from cache for device %s, instance #%d\n", *pci_irqp, 5050Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip))); 5060Sstevel@tonic-gate return (status); 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate bzero(&acpipsmlnk, sizeof (acpi_psm_lnk_t)); 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate if ((status = acpi_translate_pci_irq(dip, ipin, pci_irqp, 5120Sstevel@tonic-gate intr_flagp, &acpipsmlnk)) == ACPI_PSM_FAILURE) { 5130Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: " 5140Sstevel@tonic-gate " acpi_translate_pci_irq failed for device %s, instance" 5150Sstevel@tonic-gate " #%d\n", ddi_get_name(dip), ddi_get_instance(dip))); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate return (status); 5180Sstevel@tonic-gate } 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate if (status == ACPI_PSM_PARTIAL && acpipsmlnk.lnkobj != NULL) { 5210Sstevel@tonic-gate status = uppc_acpi_irq_configure(&acpipsmlnk, dip, pci_irqp, 5220Sstevel@tonic-gate intr_flagp); 5230Sstevel@tonic-gate if (status != ACPI_PSM_SUCCESS) { 5240Sstevel@tonic-gate status = acpi_get_current_irq_resource(&acpipsmlnk, 5250Sstevel@tonic-gate pci_irqp, intr_flagp); 5260Sstevel@tonic-gate } 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate if (status == ACPI_PSM_SUCCESS) { 5300Sstevel@tonic-gate acpi_new_irq_cache_ent(busid, devid, ipin, *pci_irqp, 5310Sstevel@tonic-gate intr_flagp, &acpipsmlnk); 532*347Smyers psm_set_elcr(*pci_irqp, 1); /* set IRQ to PCI mode */ 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: [ACPI] " 5350Sstevel@tonic-gate "new irq %d for device %s, instance #%d\n", 5360Sstevel@tonic-gate *pci_irqp, ddi_get_name(dip), ddi_get_instance(dip))); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate return (status); 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate /* 5430Sstevel@tonic-gate * Configures the irq for the interrupt link device identified by 5440Sstevel@tonic-gate * acpipsmlnkp. 5450Sstevel@tonic-gate * 5460Sstevel@tonic-gate * Gets the current and the list of possible irq settings for the 5470Sstevel@tonic-gate * device. If uppc_unconditional_srs is not set, and the current 5480Sstevel@tonic-gate * resource setting is in the list of possible irq settings, 5490Sstevel@tonic-gate * current irq resource setting is passed to the caller. 5500Sstevel@tonic-gate * 5510Sstevel@tonic-gate * Otherwise, picks an irq number from the list of possible irq 5520Sstevel@tonic-gate * settings, and sets the irq of the device to this value. 5530Sstevel@tonic-gate * If prefer_crs is set, among a set of irq numbers in the list that have 5540Sstevel@tonic-gate * the least number of devices sharing the interrupt, we pick current irq 5550Sstevel@tonic-gate * resource setting if it is a member of this set. 5560Sstevel@tonic-gate * 5570Sstevel@tonic-gate * Passes the irq number in the value pointed to by pci_irqp, and 5580Sstevel@tonic-gate * polarity and sensitivity in the structure pointed to by dipintrflagp 5590Sstevel@tonic-gate * to the caller. 5600Sstevel@tonic-gate * 5610Sstevel@tonic-gate * Note that if setting the irq resource failed, but successfuly obtained 5620Sstevel@tonic-gate * the current irq resource settings, passes the current irq resources 5630Sstevel@tonic-gate * and considers it a success. 5640Sstevel@tonic-gate * 5650Sstevel@tonic-gate * Returns: 5660Sstevel@tonic-gate * ACPI_PSM_SUCCESS on success. 5670Sstevel@tonic-gate * 5680Sstevel@tonic-gate * ACPI_PSM_FAILURE if an error occured during the configuration or 5690Sstevel@tonic-gate * if a suitable irq was not found for this device, or if setting the 5700Sstevel@tonic-gate * irq resource and obtaining the current resource fails. 5710Sstevel@tonic-gate * 5720Sstevel@tonic-gate */ 5730Sstevel@tonic-gate static int 5740Sstevel@tonic-gate uppc_acpi_irq_configure(acpi_psm_lnk_t *acpipsmlnkp, dev_info_t *dip, 5750Sstevel@tonic-gate int *pci_irqp, iflag_t *dipintr_flagp) 5760Sstevel@tonic-gate { 5770Sstevel@tonic-gate int i, min_share, foundnow, done = 0; 5780Sstevel@tonic-gate int32_t irq; 5790Sstevel@tonic-gate int32_t share_irq = -1; 5800Sstevel@tonic-gate int32_t chosen_irq = -1; 5810Sstevel@tonic-gate int cur_irq = -1; 5820Sstevel@tonic-gate acpi_irqlist_t *irqlistp; 5830Sstevel@tonic-gate acpi_irqlist_t *irqlistent; 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate if ((acpi_get_possible_irq_resources(acpipsmlnkp, &irqlistp)) 5860Sstevel@tonic-gate == ACPI_PSM_FAILURE) { 5870Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: Unable to determine " 5880Sstevel@tonic-gate "or assign IRQ for device %s, instance #%d: The system was " 5890Sstevel@tonic-gate "unable to get the list of potential IRQs from ACPI.", 5900Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip))); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate return (ACPI_PSM_FAILURE); 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate if ((acpi_get_current_irq_resource(acpipsmlnkp, &cur_irq, 5960Sstevel@tonic-gate dipintr_flagp) == ACPI_PSM_SUCCESS) && (!uppc_unconditional_srs) && 5970Sstevel@tonic-gate (cur_irq > 0)) { 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate if (acpi_irqlist_find_irq(irqlistp, cur_irq, NULL) 6000Sstevel@tonic-gate == ACPI_PSM_SUCCESS) { 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate acpi_free_irqlist(irqlistp); 6030Sstevel@tonic-gate ASSERT(pci_irqp != NULL); 6040Sstevel@tonic-gate *pci_irqp = cur_irq; 6050Sstevel@tonic-gate return (ACPI_PSM_SUCCESS); 6060Sstevel@tonic-gate } 6070Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: Could not find the " 6080Sstevel@tonic-gate "current irq %d for device %s, instance #%d in ACPI's " 6090Sstevel@tonic-gate "list of possible irqs for this device. Picking one from " 6100Sstevel@tonic-gate " the latter list.", cur_irq, ddi_get_name(dip), 6110Sstevel@tonic-gate ddi_get_instance(dip))); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate } 6140Sstevel@tonic-gate 6150Sstevel@tonic-gate irqlistent = irqlistp; 6160Sstevel@tonic-gate min_share = 255; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate while (irqlistent != NULL) { 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate for (foundnow = 0, i = 0; i < irqlistent->num_irqs; i++) { 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate irq = irqlistp->irqs[i]; 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate if ((irq > MAX_ISA_IRQ) || 6250Sstevel@tonic-gate (irqlistent->intr_flags.intr_el == INTR_EL_EDGE) || 6260Sstevel@tonic-gate (irq == 0)) 6270Sstevel@tonic-gate continue; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate if (uppc_reserved_irqlist[irq]) 6300Sstevel@tonic-gate continue; 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate if (uppc_irq_shared_table[irq] == 0) { 6330Sstevel@tonic-gate chosen_irq = irq; 6340Sstevel@tonic-gate foundnow = 1; 6350Sstevel@tonic-gate if (!(uppc_prefer_crs) || (irq == cur_irq)) { 6360Sstevel@tonic-gate done = 1; 6370Sstevel@tonic-gate break; 6380Sstevel@tonic-gate } 6390Sstevel@tonic-gate } 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate if ((uppc_irq_shared_table[irq] < min_share) || 6420Sstevel@tonic-gate ((uppc_irq_shared_table[irq] == min_share) && 6430Sstevel@tonic-gate (cur_irq == irq) && (uppc_prefer_crs))) { 6440Sstevel@tonic-gate min_share = uppc_irq_shared_table[irq]; 6450Sstevel@tonic-gate share_irq = irq; 6460Sstevel@tonic-gate foundnow = 1; 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate } 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate /* If we found an IRQ in the inner loop, save the details */ 6510Sstevel@tonic-gate if (foundnow && ((chosen_irq != -1) || (share_irq != -1))) { 6520Sstevel@tonic-gate /* 6530Sstevel@tonic-gate * Copy the acpi_prs_private_t and flags from this 6540Sstevel@tonic-gate * irq list entry, since we found an irq from this 6550Sstevel@tonic-gate * entry. 6560Sstevel@tonic-gate */ 6570Sstevel@tonic-gate acpipsmlnkp->acpi_prs_prv = irqlistent->acpi_prs_prv; 6580Sstevel@tonic-gate *dipintr_flagp = irqlistent->intr_flags; 6590Sstevel@tonic-gate } 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate if (done) 6620Sstevel@tonic-gate break; 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* Load the next entry in the irqlist */ 6650Sstevel@tonic-gate irqlistent = irqlistent->next; 6660Sstevel@tonic-gate } 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate acpi_free_irqlist(irqlistp); 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate if (chosen_irq != -1) 6710Sstevel@tonic-gate irq = chosen_irq; 6720Sstevel@tonic-gate else if (share_irq != -1) 6730Sstevel@tonic-gate irq = share_irq; 6740Sstevel@tonic-gate else { 6750Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Could not find a " 6760Sstevel@tonic-gate "suitable irq from the list of possible irqs for device " 6770Sstevel@tonic-gate "%s, instance #%d in ACPI's list of possible\n", 6780Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip))); 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate return (ACPI_PSM_FAILURE); 6810Sstevel@tonic-gate } 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Setting irq %d for device %s " 6850Sstevel@tonic-gate "instance #%d\n", irq, ddi_get_name(dip), ddi_get_instance(dip))); 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate if ((acpi_set_irq_resource(acpipsmlnkp, irq)) == ACPI_PSM_SUCCESS) { 6880Sstevel@tonic-gate /* 6890Sstevel@tonic-gate * setting irq was successful, check to make sure CRS 6900Sstevel@tonic-gate * reflects that. If CRS does not agree with what we 6910Sstevel@tonic-gate * set, return the irq that was set. 6920Sstevel@tonic-gate */ 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate if (acpi_get_current_irq_resource(acpipsmlnkp, &cur_irq, 6950Sstevel@tonic-gate dipintr_flagp) == ACPI_PSM_SUCCESS) { 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate if (cur_irq != irq) 6980Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: " 6990Sstevel@tonic-gate "IRQ resource set (irqno %d) for device %s " 7000Sstevel@tonic-gate "instance #%d, differs from current " 7010Sstevel@tonic-gate "setting irqno %d", 7020Sstevel@tonic-gate irq, ddi_get_name(dip), 7030Sstevel@tonic-gate ddi_get_instance(dip), cur_irq)); 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate /* 7060Sstevel@tonic-gate * return the irq that was set, and not what CRS reports, 7070Sstevel@tonic-gate * since CRS has been seen to be bogus on some systems 7080Sstevel@tonic-gate */ 7090Sstevel@tonic-gate cur_irq = irq; 7100Sstevel@tonic-gate } else { 7110Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: set resource irq %d " 7120Sstevel@tonic-gate "failed for device %s instance #%d", 7130Sstevel@tonic-gate irq, ddi_get_name(dip), ddi_get_instance(dip))); 7140Sstevel@tonic-gate if (cur_irq == -1) 7150Sstevel@tonic-gate return (ACPI_PSM_FAILURE); 7160Sstevel@tonic-gate } 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate ASSERT(pci_irqp != NULL); 7190Sstevel@tonic-gate *pci_irqp = cur_irq; 7200Sstevel@tonic-gate return (ACPI_PSM_SUCCESS); 7210Sstevel@tonic-gate } 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate /*ARGSUSED*/ 7250Sstevel@tonic-gate static int 7260Sstevel@tonic-gate uppc_translate_irq(dev_info_t *dip, int irqno) 7270Sstevel@tonic-gate { 7280Sstevel@tonic-gate char dev_type[16]; 7290Sstevel@tonic-gate int dev_len, pci_irq, devid, busid; 7300Sstevel@tonic-gate ddi_acc_handle_t cfg_handle; 7310Sstevel@tonic-gate uchar_t ipin; 7320Sstevel@tonic-gate iflag_t intr_flag; 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate if (dip == NULL) { 7350Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: irqno = %d" 7360Sstevel@tonic-gate " dip = NULL\n", irqno)); 7370Sstevel@tonic-gate return (irqno); 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate if (!uppc_enable_acpi) { 7410Sstevel@tonic-gate return (irqno); 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate dev_len = sizeof (dev_type); 7450Sstevel@tonic-gate if (ddi_getlongprop_buf(DDI_DEV_T_NONE, ddi_get_parent(dip), 7460Sstevel@tonic-gate DDI_PROP_DONTPASS, "device_type", (caddr_t)dev_type, 7470Sstevel@tonic-gate &dev_len) != DDI_PROP_SUCCESS) { 7480Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: irqno %d" 7490Sstevel@tonic-gate "device %s instance %d no device_type\n", irqno, 7500Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip))); 7510Sstevel@tonic-gate return (irqno); 7520Sstevel@tonic-gate } 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate if (strcmp(dev_type, "pci") == 0) { 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate /* pci device */ 7570Sstevel@tonic-gate if (acpica_get_bdf(dip, &busid, &devid, NULL) != 0) 7580Sstevel@tonic-gate return (irqno); 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate if (pci_config_setup(dip, &cfg_handle) != DDI_SUCCESS) 7610Sstevel@tonic-gate return (irqno); 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate ipin = pci_config_get8(cfg_handle, PCI_CONF_IPIN) - PCI_INTA; 7640Sstevel@tonic-gate pci_config_teardown(&cfg_handle); 7650Sstevel@tonic-gate if (uppc_acpi_translate_pci_irq(dip, busid, devid, 7660Sstevel@tonic-gate ipin, &pci_irq, &intr_flag) == ACPI_PSM_SUCCESS) { 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: [ACPI] new irq " 7690Sstevel@tonic-gate "%d old irq %d device %s, instance %d\n", pci_irq, 7700Sstevel@tonic-gate irqno, ddi_get_name(dip), ddi_get_instance(dip))); 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate /* 7730Sstevel@tonic-gate * Make sure pci_irq is within range. 7740Sstevel@tonic-gate * Otherwise, fall through and return irqno. 7750Sstevel@tonic-gate */ 7760Sstevel@tonic-gate if (pci_irq <= MAX_ISA_IRQ) 7770Sstevel@tonic-gate return (pci_irq); 7780Sstevel@tonic-gate } 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate /* FALLTHRU to common case - returning irqno */ 7810Sstevel@tonic-gate } else { 782*347Smyers /* non-PCI; assumes ISA-style edge-triggered */ 783*347Smyers psm_set_elcr(irqno, 0); /* set IRQ to ISA mode */ 784*347Smyers 7850Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: non-pci," 7860Sstevel@tonic-gate "irqno %d device %s instance %d\n", irqno, 7870Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip))); 788*347Smyers 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate return (irqno); 7920Sstevel@tonic-gate } 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* 7950Sstevel@tonic-gate * uppc_intr_enter() raises the ipl to the level of the current interrupt, 7960Sstevel@tonic-gate * and sends EOI to the pics. 7970Sstevel@tonic-gate * If interrupt is 7 or 15 and not spurious interrupt, send specific EOI 7980Sstevel@tonic-gate * else send non-specific EOI 7990Sstevel@tonic-gate * uppc_intr_enter() returns the new priority level, 8000Sstevel@tonic-gate * or -1 for spurious interrupt 8010Sstevel@tonic-gate */ 8020Sstevel@tonic-gate static int 8030Sstevel@tonic-gate uppc_intr_enter(int ipl, int *vector) 8040Sstevel@tonic-gate { 8050Sstevel@tonic-gate int newipl; 8060Sstevel@tonic-gate int intno; 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate intno = (*vector); 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate ASSERT(intno < 256); 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate newipl = autovect[intno].avh_hi_pri; 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate /* 8150Sstevel@tonic-gate * During wait_till_seen() periods when interrupt vector is being 8160Sstevel@tonic-gate * removed in remove_av(), the removed hardware interrupt could 8170Sstevel@tonic-gate * trigger and got here with newipl 0. It has to send EOI 8180Sstevel@tonic-gate * as usual but no need to call setspl and returns -1 like spurious. 8190Sstevel@tonic-gate */ 8200Sstevel@tonic-gate if ((intno & 7) != 7) { 8210Sstevel@tonic-gate if (newipl) 8220Sstevel@tonic-gate uppc_setspl(newipl); 8230Sstevel@tonic-gate outb(MCMD_PORT, PIC_NSEOI); 8240Sstevel@tonic-gate if (intno >= 8) { 8250Sstevel@tonic-gate outb(SCMD_PORT, PIC_NSEOI); 8260Sstevel@tonic-gate } 8270Sstevel@tonic-gate } else { /* int was 7 or 15 */ 8280Sstevel@tonic-gate if (newipl && newipl <= ipl) { /* Check for spurious int */ 8290Sstevel@tonic-gate if (intno != 7) 8300Sstevel@tonic-gate outb(MCMD_PORT, PIC_NSEOI); 8310Sstevel@tonic-gate return (-1); /* Spurious int */ 8320Sstevel@tonic-gate } else { 8330Sstevel@tonic-gate if (newipl) 8340Sstevel@tonic-gate uppc_setspl(newipl); 8350Sstevel@tonic-gate if (intno != 7) { 8360Sstevel@tonic-gate outb(MCMD_PORT, PIC_NSEOI); 8370Sstevel@tonic-gate outb(SCMD_PORT, PIC_SEOI_LVL7); 8380Sstevel@tonic-gate } else { 8390Sstevel@tonic-gate outb(MCMD_PORT, PIC_SEOI_LVL7); 8400Sstevel@tonic-gate } 8410Sstevel@tonic-gate } 8420Sstevel@tonic-gate } 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate if (newipl) 8450Sstevel@tonic-gate return (newipl); 8460Sstevel@tonic-gate else 8470Sstevel@tonic-gate return (-1); /* not real spurious int */ 8480Sstevel@tonic-gate } 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate /* 8510Sstevel@tonic-gate * uppc_intr_exit() restores the old interrupt 8520Sstevel@tonic-gate * priority level after processing an interrupt. 8530Sstevel@tonic-gate * It is called with interrupts disabled, and does not enable interrupts. 8540Sstevel@tonic-gate */ 8550Sstevel@tonic-gate /* ARGSUSED */ 8560Sstevel@tonic-gate static void 8570Sstevel@tonic-gate uppc_intr_exit(int ipl, int vector) 8580Sstevel@tonic-gate { 8590Sstevel@tonic-gate uppc_setspl(ipl); 8600Sstevel@tonic-gate } 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * uppc_setspl() loads new interrupt masks into the pics 8640Sstevel@tonic-gate * based on input ipl. 8650Sstevel@tonic-gate */ 8660Sstevel@tonic-gate /* ARGSUSED */ 8670Sstevel@tonic-gate static void 8680Sstevel@tonic-gate uppc_setspl(int ipl) 8690Sstevel@tonic-gate { 8700Sstevel@tonic-gate struct standard_pic *pp; 8710Sstevel@tonic-gate uint8_t smask, mmask; 8720Sstevel@tonic-gate uint8_t cursmask, curmmask; 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate pp = &pics0; 8750Sstevel@tonic-gate smask = pp->c_iplmask[ipl * 2]; 8760Sstevel@tonic-gate mmask = pp->c_iplmask[ipl * 2 + 1]; 8770Sstevel@tonic-gate cursmask = pp->c_curmask[0]; 8780Sstevel@tonic-gate curmmask = pp->c_curmask[1]; 8790Sstevel@tonic-gate if (cursmask == smask && curmmask == mmask) 8800Sstevel@tonic-gate return; 8810Sstevel@tonic-gate pp->c_curmask[0] = smask; 8820Sstevel@tonic-gate pp->c_curmask[1] = mmask; 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate if (cursmask != smask) { 8850Sstevel@tonic-gate /* 8860Sstevel@tonic-gate * program new slave pic mask 8870Sstevel@tonic-gate */ 8880Sstevel@tonic-gate outb(SIMR_PORT, smask); 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate if (curmmask != mmask) { 8910Sstevel@tonic-gate /* 8920Sstevel@tonic-gate * program new master pic mask 8930Sstevel@tonic-gate */ 8940Sstevel@tonic-gate outb(MIMR_PORT, mmask); 8950Sstevel@tonic-gate } 8960Sstevel@tonic-gate /* 8970Sstevel@tonic-gate * read master to allow pics to settle 8980Sstevel@tonic-gate */ 8990Sstevel@tonic-gate (void) inb(MIMR_PORT); 9000Sstevel@tonic-gate } 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate /* 9030Sstevel@tonic-gate * uppc_gethrtime() returns high resolution timer value 9040Sstevel@tonic-gate */ 9050Sstevel@tonic-gate static hrtime_t 9060Sstevel@tonic-gate uppc_gethrtime() 9070Sstevel@tonic-gate { 9080Sstevel@tonic-gate hrtime_t timeval, temp; 9090Sstevel@tonic-gate unsigned int oflags, ctr0; 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate oflags = intr_clear(); /* disable ints */ 9120Sstevel@tonic-gate lock_set(&uppc_gethrtime_lock); 9130Sstevel@tonic-gate retry: 9140Sstevel@tonic-gate temp = hrtime_base; 9150Sstevel@tonic-gate outb(PITCTL_PORT, 0); /* latch counter 0 */ 9160Sstevel@tonic-gate /* 9170Sstevel@tonic-gate * read counter 0 9180Sstevel@tonic-gate */ 9190Sstevel@tonic-gate ctr0 = inb(PITCTR0_PORT); 9200Sstevel@tonic-gate ctr0 |= inb(PITCTR0_PORT) << 8; 9210Sstevel@tonic-gate timeval = (hrtime_t)ctr0 * (NANOSEC / PIT_HZ); 9220Sstevel@tonic-gate if (temp != hrtime_base) 9230Sstevel@tonic-gate goto retry; 9240Sstevel@tonic-gate timeval -= temp; 9250Sstevel@tonic-gate if (timeval < uppc_lasthrtime) 9260Sstevel@tonic-gate timeval = uppc_lasthrtime; 9270Sstevel@tonic-gate uppc_lasthrtime = timeval; 9280Sstevel@tonic-gate lock_clear(&uppc_gethrtime_lock); 9290Sstevel@tonic-gate intr_restore(oflags); 9300Sstevel@tonic-gate return (timeval); 9310Sstevel@tonic-gate } 932