17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54303384aSanish * Common Development and Distribution License (the "License").
64303384aSanish * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
220f1b305eSSeth Goldberg * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
26a3114836SGerry Liu #define PSMI_1_7
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/time.h>
317c478bd9Sstevel@tonic-gate #include <sys/machlock.h>
327c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h>
337c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
347c478bd9Sstevel@tonic-gate #include <sys/promif.h>
357c478bd9Sstevel@tonic-gate #include <sys/psm.h>
367c478bd9Sstevel@tonic-gate #include <sys/pit.h>
370f1b305eSSeth Goldberg #include <sys/apic.h>
387c478bd9Sstevel@tonic-gate #include <sys/psm_common.h>
397c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
40ae115bc7Smrj #include <sys/archsystm.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #define NSEC_IN_SEC 1000000000
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate * Local Function Prototypes
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate static void uppc_softinit(void);
487c478bd9Sstevel@tonic-gate static void uppc_picinit();
490f1b305eSSeth Goldberg static int uppc_post_cpu_start(void);
507c478bd9Sstevel@tonic-gate static int uppc_clkinit(int);
517c478bd9Sstevel@tonic-gate static int uppc_addspl(int irqno, int ipl, int min_ipl, int max_ipl);
527c478bd9Sstevel@tonic-gate static int uppc_delspl(int irqno, int ipl, int min_ipl, int max_ipl);
537c478bd9Sstevel@tonic-gate static processorid_t uppc_get_next_processorid(processorid_t cpu_id);
547c478bd9Sstevel@tonic-gate static int uppc_get_clockirq(int ipl);
557c478bd9Sstevel@tonic-gate static int uppc_probe(void);
567c478bd9Sstevel@tonic-gate static int uppc_translate_irq(dev_info_t *dip, int irqno);
577c478bd9Sstevel@tonic-gate static void uppc_shutdown(int cmd, int fcn);
587c478bd9Sstevel@tonic-gate static void uppc_preshutdown(int cmd, int fcn);
590f1b305eSSeth Goldberg static int uppc_state(psm_state_request_t *request);
607c478bd9Sstevel@tonic-gate static int uppc_init_acpi(void);
617c478bd9Sstevel@tonic-gate static void uppc_setspl(int);
627c478bd9Sstevel@tonic-gate static int uppc_intr_enter(int, int *);
637c478bd9Sstevel@tonic-gate static void uppc_intr_exit(int, int);
647c478bd9Sstevel@tonic-gate static hrtime_t uppc_gethrtime();
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate static int uppc_acpi_irq_configure(acpi_psm_lnk_t *acpipsmlnkp, dev_info_t *dip,
677c478bd9Sstevel@tonic-gate int *pci_irqp, iflag_t *intr_flagp);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate * Global Data
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate static struct standard_pic pics0;
737c478bd9Sstevel@tonic-gate int uppc_use_acpi = 1; /* Use ACPI by default */
747c478bd9Sstevel@tonic-gate int uppc_enable_acpi = 0;
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * For interrupt link devices, if uppc_unconditional_srs is set, an irq resource
797c478bd9Sstevel@tonic-gate * will be assigned (via _SRS). If it is not set, use the current
807c478bd9Sstevel@tonic-gate * irq setting (via _CRS), but only if that irq is in the set of possible
817c478bd9Sstevel@tonic-gate * irqs (returned by _PRS) for the device.
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate int uppc_unconditional_srs = 1;
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate * For interrupt link devices, if uppc_prefer_crs is set when we are
877c478bd9Sstevel@tonic-gate * assigning an IRQ resource to a device, prefer the current IRQ setting
887c478bd9Sstevel@tonic-gate * over other possible irq settings under same conditions.
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate int uppc_prefer_crs = 1;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate int uppc_verbose = 0;
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate /* flag definitions for uppc_verbose */
957c478bd9Sstevel@tonic-gate #define UPPC_VERBOSE_IRQ_FLAG 0x00000001
967c478bd9Sstevel@tonic-gate #define UPPC_VERBOSE_POWEROFF_FLAG 0x00000002
977c478bd9Sstevel@tonic-gate #define UPPC_VERBOSE_POWEROFF_PAUSE_FLAG 0x00000004
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate #define UPPC_VERBOSE_IRQ(fmt) \
1017c478bd9Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG) \
1027c478bd9Sstevel@tonic-gate cmn_err fmt;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate #define UPPC_VERBOSE_POWEROFF(fmt) \
1057c478bd9Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG) \
1067c478bd9Sstevel@tonic-gate prom_printf fmt;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate uchar_t uppc_reserved_irqlist[MAX_ISA_IRQ + 1];
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate static uint16_t uppc_irq_shared_table[MAX_ISA_IRQ + 1];
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate * Contains SCI irqno from FADT after initialization
1147c478bd9Sstevel@tonic-gate */
1157c478bd9Sstevel@tonic-gate static int uppc_sci = -1;
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * Local Static Data
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate static lock_t uppc_gethrtime_lock;
1227c478bd9Sstevel@tonic-gate static hrtime_t uppc_lasthrtime;
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate #ifdef UPPC_DEBUG
1267c478bd9Sstevel@tonic-gate #define DENT 0x0001
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate static int uppc_debug = 0;
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate static struct psm_ops uppc_ops = {
1357c478bd9Sstevel@tonic-gate uppc_probe, /* psm_probe */
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate uppc_softinit, /* psm_init */
1387c478bd9Sstevel@tonic-gate uppc_picinit, /* psm_picinit */
1397c478bd9Sstevel@tonic-gate uppc_intr_enter, /* psm_intr_enter */
1407c478bd9Sstevel@tonic-gate uppc_intr_exit, /* psm_intr_exit */
1417c478bd9Sstevel@tonic-gate uppc_setspl, /* psm_setspl */
1427c478bd9Sstevel@tonic-gate uppc_addspl, /* psm_addspl */
1437c478bd9Sstevel@tonic-gate uppc_delspl, /* psm_delspl */
1447c478bd9Sstevel@tonic-gate (int (*)(processorid_t))NULL, /* psm_disable_intr */
1457c478bd9Sstevel@tonic-gate (void (*)(processorid_t))NULL, /* psm_enable_intr */
1467c478bd9Sstevel@tonic-gate (int (*)(int))NULL, /* psm_softlvl_to_irq */
1477c478bd9Sstevel@tonic-gate (void (*)(int))NULL, /* psm_set_softintr */
1487c478bd9Sstevel@tonic-gate (void (*)(processorid_t))NULL, /* psm_set_idlecpu */
1497c478bd9Sstevel@tonic-gate (void (*)(processorid_t))NULL, /* psm_unset_idlecpu */
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate uppc_clkinit, /* psm_clkinit */
1527c478bd9Sstevel@tonic-gate uppc_get_clockirq, /* psm_get_clockirq */
1537c478bd9Sstevel@tonic-gate (void (*)(void))NULL, /* psm_hrtimeinit */
1547c478bd9Sstevel@tonic-gate uppc_gethrtime, /* psm_gethrtime */
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate uppc_get_next_processorid, /* psm_get_next_processorid */
157ae115bc7Smrj (int (*)(processorid_t, caddr_t))NULL, /* psm_cpu_start */
1580f1b305eSSeth Goldberg uppc_post_cpu_start, /* psm_post_cpu_start */
1597c478bd9Sstevel@tonic-gate uppc_shutdown, /* psm_shutdown */
1607c478bd9Sstevel@tonic-gate (int (*)(int, int))NULL, /* psm_get_ipivect */
1617c478bd9Sstevel@tonic-gate (void (*)(processorid_t, int))NULL, /* psm_send_ipi */
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate uppc_translate_irq, /* psm_translate_irq */
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate (void (*)(int, char *))NULL, /* psm_notify_error */
1667c478bd9Sstevel@tonic-gate (void (*)(int msg))NULL, /* psm_notify_func */
1677c478bd9Sstevel@tonic-gate (void (*)(hrtime_t time))NULL, /* psm_timer_reprogram */
1687c478bd9Sstevel@tonic-gate (void (*)(void))NULL, /* psm_timer_enable */
1697c478bd9Sstevel@tonic-gate (void (*)(void))NULL, /* psm_timer_disable */
1707c478bd9Sstevel@tonic-gate (void (*)(void *arg))NULL, /* psm_post_cyclic_setup */
1717c478bd9Sstevel@tonic-gate uppc_preshutdown, /* psm_preshutdown */
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate (int (*)(dev_info_t *, ddi_intr_handle_impl_t *,
1740f1b305eSSeth Goldberg psm_intr_op_t, int *))NULL, /* psm_intr_ops */
1750f1b305eSSeth Goldberg
176a3114836SGerry Liu uppc_state, /* psm_state */
177a3114836SGerry Liu (int (*)(psm_cpu_request_t *))NULL /* psm_cpu_ops */
1787c478bd9Sstevel@tonic-gate };
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate static struct psm_info uppc_info = {
182a3114836SGerry Liu PSM_INFO_VER01_7, /* version */
1837c478bd9Sstevel@tonic-gate PSM_OWN_SYS_DEFAULT, /* ownership */
1847c478bd9Sstevel@tonic-gate (struct psm_ops *)&uppc_ops, /* operation */
1857c478bd9Sstevel@tonic-gate "uppc", /* machine name */
1867c478bd9Sstevel@tonic-gate "UniProcessor PC", /* machine descriptions */
1877c478bd9Sstevel@tonic-gate };
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate * Configuration Data
1917c478bd9Sstevel@tonic-gate */
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate * This is the loadable module wrapper.
1957c478bd9Sstevel@tonic-gate */
1967c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate static void *uppc_hdlp;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate int
_init(void)2017c478bd9Sstevel@tonic-gate _init(void)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate return (psm_mod_init(&uppc_hdlp, &uppc_info));
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate int
_fini(void)2077c478bd9Sstevel@tonic-gate _fini(void)
2087c478bd9Sstevel@tonic-gate {
2097c478bd9Sstevel@tonic-gate return (psm_mod_fini(&uppc_hdlp, &uppc_info));
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2137c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2147c478bd9Sstevel@tonic-gate {
2157c478bd9Sstevel@tonic-gate return (psm_mod_info(&uppc_hdlp, &uppc_info, modinfop));
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate * Autoconfiguration Routines
2207c478bd9Sstevel@tonic-gate */
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate static int
uppc_probe(void)2237c478bd9Sstevel@tonic-gate uppc_probe(void)
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate return (PSM_SUCCESS);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate static void
uppc_softinit(void)2317c478bd9Sstevel@tonic-gate uppc_softinit(void)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate struct standard_pic *pp;
2347c478bd9Sstevel@tonic-gate int i;
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate pp = &pics0;
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate if (uppc_use_acpi && uppc_init_acpi()) {
2407c478bd9Sstevel@tonic-gate build_reserved_irqlist((uchar_t *)uppc_reserved_irqlist);
2417c478bd9Sstevel@tonic-gate for (i = 0; i <= MAX_ISA_IRQ; i++)
2427c478bd9Sstevel@tonic-gate uppc_irq_shared_table[i] = 0;
2437c478bd9Sstevel@tonic-gate uppc_enable_acpi = 1;
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate * initialize the ipl mask
2487c478bd9Sstevel@tonic-gate */
2497c478bd9Sstevel@tonic-gate for (i = 0; i < (MAXIPL << 1); i += 2) {
2507c478bd9Sstevel@tonic-gate /* enable slave lines on master */
2517c478bd9Sstevel@tonic-gate pp->c_iplmask[i] = 0xff;
2527c478bd9Sstevel@tonic-gate pp->c_iplmask[i+1] = (0xff & ~(1 << MASTERLINE));
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2577c478bd9Sstevel@tonic-gate static int
uppc_clkinit(int hertz)2587c478bd9Sstevel@tonic-gate uppc_clkinit(int hertz)
2597c478bd9Sstevel@tonic-gate {
2607c478bd9Sstevel@tonic-gate ulong_t clkticks = PIT_HZ / hz;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate if (hertz == 0)
2637c478bd9Sstevel@tonic-gate return (0); /* One shot mode not supported */
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate * program timer 0
2677c478bd9Sstevel@tonic-gate */
2687c478bd9Sstevel@tonic-gate outb(PITCTL_PORT, (PIT_C0|PIT_NDIVMODE|PIT_READMODE));
2697c478bd9Sstevel@tonic-gate outb(PITCTR0_PORT, (uchar_t)clkticks);
2707c478bd9Sstevel@tonic-gate outb(PITCTR0_PORT, (uchar_t)(clkticks>>8));
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate return (NSEC_IN_SEC / hertz);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate static void
uppc_picinit()2767c478bd9Sstevel@tonic-gate uppc_picinit()
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate picsetup();
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate * If a valid SCI is present, manually addspl()
2827c478bd9Sstevel@tonic-gate * since we're not set-up early enough in boot
2837c478bd9Sstevel@tonic-gate * to do it "conventionally" (via add_avintr)
2847c478bd9Sstevel@tonic-gate */
2857c478bd9Sstevel@tonic-gate if (uppc_sci >= 0)
2867c478bd9Sstevel@tonic-gate (void) uppc_addspl(uppc_sci, SCI_IPL, SCI_IPL, SCI_IPL);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2890f1b305eSSeth Goldberg static int
uppc_post_cpu_start(void)2900f1b305eSSeth Goldberg uppc_post_cpu_start(void)
2910f1b305eSSeth Goldberg {
2920f1b305eSSeth Goldberg /*
2930f1b305eSSeth Goldberg * On uppc machines psm_post_cpu_start is called during S3 resume
2940f1b305eSSeth Goldberg * on the boot cpu from assembly, using the ap_mlsetup vector.
2950f1b305eSSeth Goldberg */
2960f1b305eSSeth Goldberg
2970f1b305eSSeth Goldberg /*
2980f1b305eSSeth Goldberg * Init master and slave pic
2990f1b305eSSeth Goldberg */
3000f1b305eSSeth Goldberg picsetup();
3010f1b305eSSeth Goldberg
3020f1b305eSSeth Goldberg /*
3030f1b305eSSeth Goldberg * program timer 0
3040f1b305eSSeth Goldberg */
3050f1b305eSSeth Goldberg (void) uppc_clkinit(hz);
3060f1b305eSSeth Goldberg
3070f1b305eSSeth Goldberg return (PSM_SUCCESS);
3080f1b305eSSeth Goldberg }
3090f1b305eSSeth Goldberg
3107c478bd9Sstevel@tonic-gate /*ARGSUSED3*/
3117c478bd9Sstevel@tonic-gate static int
uppc_addspl(int irqno,int ipl,int min_ipl,int max_ipl)3127c478bd9Sstevel@tonic-gate uppc_addspl(int irqno, int ipl, int min_ipl, int max_ipl)
3137c478bd9Sstevel@tonic-gate {
3147c478bd9Sstevel@tonic-gate struct standard_pic *pp;
3157c478bd9Sstevel@tonic-gate int i;
3167c478bd9Sstevel@tonic-gate int startidx;
3177c478bd9Sstevel@tonic-gate uchar_t vectmask;
3187c478bd9Sstevel@tonic-gate
3194303384aSanish if (irqno <= MAX_ISA_IRQ)
320*1a5e258fSJosef 'Jeff' Sipek atomic_inc_16(&uppc_irq_shared_table[irqno]);
3214303384aSanish
3227c478bd9Sstevel@tonic-gate if (ipl != min_ipl)
3237c478bd9Sstevel@tonic-gate return (0);
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate if (irqno > 7) {
3267c478bd9Sstevel@tonic-gate vectmask = 1 << (irqno - 8);
3277c478bd9Sstevel@tonic-gate startidx = (ipl << 1);
3287c478bd9Sstevel@tonic-gate } else {
3297c478bd9Sstevel@tonic-gate vectmask = 1 << irqno;
3307c478bd9Sstevel@tonic-gate startidx = (ipl << 1) + 1;
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate * mask intr same or above ipl
3357c478bd9Sstevel@tonic-gate * level MAXIPL has all intr off as init. default
3367c478bd9Sstevel@tonic-gate */
3377c478bd9Sstevel@tonic-gate pp = &pics0;
3387c478bd9Sstevel@tonic-gate for (i = startidx; i < (MAXIPL << 1); i += 2) {
3397c478bd9Sstevel@tonic-gate if (pp->c_iplmask[i] & vectmask)
3407c478bd9Sstevel@tonic-gate break;
3417c478bd9Sstevel@tonic-gate pp->c_iplmask[i] |= vectmask;
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate * unmask intr below ipl
3467c478bd9Sstevel@tonic-gate */
3477c478bd9Sstevel@tonic-gate for (i = startidx-2; i >= 0; i -= 2) {
3487c478bd9Sstevel@tonic-gate if (!(pp->c_iplmask[i] & vectmask))
3497c478bd9Sstevel@tonic-gate break;
3507c478bd9Sstevel@tonic-gate pp->c_iplmask[i] &= ~vectmask;
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate return (0);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate static int
uppc_delspl(int irqno,int ipl,int min_ipl,int max_ipl)3567c478bd9Sstevel@tonic-gate uppc_delspl(int irqno, int ipl, int min_ipl, int max_ipl)
3577c478bd9Sstevel@tonic-gate {
3587c478bd9Sstevel@tonic-gate struct standard_pic *pp;
3597c478bd9Sstevel@tonic-gate int i;
3607c478bd9Sstevel@tonic-gate uchar_t vectmask;
3617c478bd9Sstevel@tonic-gate
3624303384aSanish if (irqno <= MAX_ISA_IRQ)
363*1a5e258fSJosef 'Jeff' Sipek atomic_dec_16(&uppc_irq_shared_table[irqno]);
3644303384aSanish
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * skip if we are not deleting the last handler
3677c478bd9Sstevel@tonic-gate * and the ipl is higher than minimum
3687c478bd9Sstevel@tonic-gate */
3697c478bd9Sstevel@tonic-gate if ((max_ipl != PSM_INVALID_IPL) && (ipl >= min_ipl))
3707c478bd9Sstevel@tonic-gate return (0);
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate if (irqno > 7) {
3737c478bd9Sstevel@tonic-gate vectmask = 1 << (irqno - 8);
3747c478bd9Sstevel@tonic-gate i = 0;
3757c478bd9Sstevel@tonic-gate } else {
3767c478bd9Sstevel@tonic-gate vectmask = 1 << irqno;
3777c478bd9Sstevel@tonic-gate i = 1;
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate pp = &pics0;
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate /*
3837c478bd9Sstevel@tonic-gate * check any handlers left for this irqno
3847c478bd9Sstevel@tonic-gate */
3857c478bd9Sstevel@tonic-gate if (max_ipl != PSM_INVALID_IPL) {
3867c478bd9Sstevel@tonic-gate /*
3877c478bd9Sstevel@tonic-gate * unmasks all levels below the lowest priority
3887c478bd9Sstevel@tonic-gate */
3897c478bd9Sstevel@tonic-gate i += ((min_ipl - 1) << 1);
3907c478bd9Sstevel@tonic-gate for (; i >= 0; i -= 2) {
3917c478bd9Sstevel@tonic-gate if (!(pp->c_iplmask[i] & vectmask))
3927c478bd9Sstevel@tonic-gate break;
3937c478bd9Sstevel@tonic-gate pp->c_iplmask[i] &= ~vectmask;
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate } else {
3967c478bd9Sstevel@tonic-gate /*
3977c478bd9Sstevel@tonic-gate * set mask to all levels
3987c478bd9Sstevel@tonic-gate */
3997c478bd9Sstevel@tonic-gate for (; i < (MAXIPL << 1); i += 2) {
4007c478bd9Sstevel@tonic-gate if (pp->c_iplmask[i] & vectmask)
4017c478bd9Sstevel@tonic-gate break;
4027c478bd9Sstevel@tonic-gate pp->c_iplmask[i] |= vectmask;
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate return (0);
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate static processorid_t
uppc_get_next_processorid(processorid_t cpu_id)4097c478bd9Sstevel@tonic-gate uppc_get_next_processorid(processorid_t cpu_id)
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate if (cpu_id == -1)
4127c478bd9Sstevel@tonic-gate return (0);
4137c478bd9Sstevel@tonic-gate return (-1);
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4177c478bd9Sstevel@tonic-gate static int
uppc_get_clockirq(int ipl)4187c478bd9Sstevel@tonic-gate uppc_get_clockirq(int ipl)
4197c478bd9Sstevel@tonic-gate {
4207c478bd9Sstevel@tonic-gate return (CLOCK_VECTOR);
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate static int
uppc_init_acpi(void)4257c478bd9Sstevel@tonic-gate uppc_init_acpi(void)
4267c478bd9Sstevel@tonic-gate {
4277c478bd9Sstevel@tonic-gate int verboseflags = 0;
4287c478bd9Sstevel@tonic-gate int sci;
4297c478bd9Sstevel@tonic-gate iflag_t sci_flags;
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate /*
4327c478bd9Sstevel@tonic-gate * Process SCI configuration here; this may return
4337c478bd9Sstevel@tonic-gate * an error if acpi-user-options has specified
4347c478bd9Sstevel@tonic-gate * legacy mode (use ACPI without ACPI mode or SCI)
4357c478bd9Sstevel@tonic-gate */
4367c478bd9Sstevel@tonic-gate if (acpica_get_sci(&sci, &sci_flags) != AE_OK)
4377c478bd9Sstevel@tonic-gate sci = -1;
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate /*
4407c478bd9Sstevel@tonic-gate * Initialize sub-system - if error is returns, ACPI is not
4417c478bd9Sstevel@tonic-gate * used.
4427c478bd9Sstevel@tonic-gate */
4437c478bd9Sstevel@tonic-gate if (acpica_init() != AE_OK)
4447c478bd9Sstevel@tonic-gate return (0);
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate /*
4477c478bd9Sstevel@tonic-gate * uppc implies system is in PIC mode; set edge/level
4487c478bd9Sstevel@tonic-gate * via ELCR based on return value from get_sci; this
4497c478bd9Sstevel@tonic-gate * will default to level/low if no override present,
4507c478bd9Sstevel@tonic-gate * as recommended by Intel ACPI CA team.
4517c478bd9Sstevel@tonic-gate */
4527c478bd9Sstevel@tonic-gate if (sci >= 0) {
4537c478bd9Sstevel@tonic-gate ASSERT((sci_flags.intr_el == INTR_EL_LEVEL) ||
4547c478bd9Sstevel@tonic-gate (sci_flags.intr_el == INTR_EL_EDGE));
4557c478bd9Sstevel@tonic-gate
456450d6964Smyers psm_set_elcr(sci, sci_flags.intr_el == INTR_EL_LEVEL);
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate /*
4607c478bd9Sstevel@tonic-gate * Remember SCI for later use
4617c478bd9Sstevel@tonic-gate */
4627c478bd9Sstevel@tonic-gate uppc_sci = sci;
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG)
4657c478bd9Sstevel@tonic-gate verboseflags |= PSM_VERBOSE_IRQ_FLAG;
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG)
4687c478bd9Sstevel@tonic-gate verboseflags |= PSM_VERBOSE_POWEROFF_FLAG;
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gate if (uppc_verbose & UPPC_VERBOSE_POWEROFF_PAUSE_FLAG)
4717c478bd9Sstevel@tonic-gate verboseflags |= PSM_VERBOSE_POWEROFF_PAUSE_FLAG;
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate if (acpi_psm_init(uppc_info.p_mach_idstring, verboseflags) ==
4747c478bd9Sstevel@tonic-gate ACPI_PSM_FAILURE) {
4757c478bd9Sstevel@tonic-gate return (0);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate return (1);
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate static void
uppc_preshutdown(int cmd,int fcn)4837c478bd9Sstevel@tonic-gate uppc_preshutdown(int cmd, int fcn)
4847c478bd9Sstevel@tonic-gate {
4857c478bd9Sstevel@tonic-gate UPPC_VERBOSE_POWEROFF(("uppc_preshutdown(%d,%d);\n", cmd, fcn));
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate static void
uppc_shutdown(int cmd,int fcn)4907c478bd9Sstevel@tonic-gate uppc_shutdown(int cmd, int fcn)
4917c478bd9Sstevel@tonic-gate {
4927c478bd9Sstevel@tonic-gate UPPC_VERBOSE_POWEROFF(("uppc_shutdown(%d,%d);\n", cmd, fcn));
4937c478bd9Sstevel@tonic-gate
4940f2cfdbbSmyers /*
4950f2cfdbbSmyers * Return if passed a command other than A_SHUTDOWN or
4960f2cfdbbSmyers * if we're not using ACPI.
4970f2cfdbbSmyers */
4980f2cfdbbSmyers if ((cmd != A_SHUTDOWN) || (!uppc_enable_acpi))
4997c478bd9Sstevel@tonic-gate return;
5000f2cfdbbSmyers
50127004895Smyers /*
50227004895Smyers * Switch system back into Legacy-Mode if using ACPI and
50327004895Smyers * not powering-off. Some BIOSes need to remain in ACPI-mode
50427004895Smyers * for power-off to succeed (Dell Dimension 4600)
50527004895Smyers */
50627004895Smyers if (fcn != AD_POWEROFF) {
5070f2cfdbbSmyers (void) AcpiDisable();
5080f2cfdbbSmyers return;
50927004895Smyers }
5100f2cfdbbSmyers
5117c478bd9Sstevel@tonic-gate (void) acpi_poweroff();
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate
5140f1b305eSSeth Goldberg
5150f1b305eSSeth Goldberg static int
uppc_acpi_enter_picmode(void)5160f1b305eSSeth Goldberg uppc_acpi_enter_picmode(void)
5170f1b305eSSeth Goldberg {
5180f1b305eSSeth Goldberg ACPI_OBJECT_LIST arglist;
5190f1b305eSSeth Goldberg ACPI_OBJECT arg;
5200f1b305eSSeth Goldberg ACPI_STATUS status;
5210f1b305eSSeth Goldberg
5220f1b305eSSeth Goldberg /* Setup parameter object */
5230f1b305eSSeth Goldberg arglist.Count = 1;
5240f1b305eSSeth Goldberg arglist.Pointer = &arg;
5250f1b305eSSeth Goldberg arg.Type = ACPI_TYPE_INTEGER;
5260f1b305eSSeth Goldberg arg.Integer.Value = ACPI_PIC_MODE;
5270f1b305eSSeth Goldberg
5280f1b305eSSeth Goldberg status = AcpiEvaluateObject(NULL, "\\_PIC", &arglist, NULL);
5290f1b305eSSeth Goldberg if (ACPI_FAILURE(status))
5300f1b305eSSeth Goldberg return (PSM_FAILURE);
5310f1b305eSSeth Goldberg else
5320f1b305eSSeth Goldberg return (PSM_SUCCESS);
5330f1b305eSSeth Goldberg }
5340f1b305eSSeth Goldberg
5350f1b305eSSeth Goldberg
5360f1b305eSSeth Goldberg struct pic_state {
5370f1b305eSSeth Goldberg int8_t mmask;
5380f1b305eSSeth Goldberg int8_t smask;
5390f1b305eSSeth Goldberg uint16_t elcr;
5400f1b305eSSeth Goldberg };
5410f1b305eSSeth Goldberg
5420f1b305eSSeth Goldberg
5430f1b305eSSeth Goldberg static void
pic_save_state(struct pic_state * sp)5440f1b305eSSeth Goldberg pic_save_state(struct pic_state *sp)
5450f1b305eSSeth Goldberg {
5460f1b305eSSeth Goldberg struct standard_pic *pp;
5470f1b305eSSeth Goldberg int vecno;
5480f1b305eSSeth Goldberg
5490f1b305eSSeth Goldberg /*
5500f1b305eSSeth Goldberg * Only the PIC masks and the ELCR can be saved;
5510f1b305eSSeth Goldberg * other 8259 state is write-only
5520f1b305eSSeth Goldberg */
5530f1b305eSSeth Goldberg
5540f1b305eSSeth Goldberg /*
5550f1b305eSSeth Goldberg * save current master and slave interrupt mask
5560f1b305eSSeth Goldberg */
5570f1b305eSSeth Goldberg pp = &pics0;
5580f1b305eSSeth Goldberg sp->smask = pp->c_curmask[0];
5590f1b305eSSeth Goldberg sp->mmask = pp->c_curmask[1];
5600f1b305eSSeth Goldberg
5610f1b305eSSeth Goldberg /*
5620f1b305eSSeth Goldberg * save edge/level configuration for isa interrupts
5630f1b305eSSeth Goldberg */
5640f1b305eSSeth Goldberg sp->elcr = 0;
5650f1b305eSSeth Goldberg for (vecno = 0; vecno <= MAX_ISA_IRQ; vecno++)
5660f1b305eSSeth Goldberg sp->elcr |= psm_get_elcr(vecno) << vecno;
5670f1b305eSSeth Goldberg }
5680f1b305eSSeth Goldberg
5690f1b305eSSeth Goldberg static void
pic_restore_state(struct pic_state * sp)5700f1b305eSSeth Goldberg pic_restore_state(struct pic_state *sp)
5710f1b305eSSeth Goldberg {
5720f1b305eSSeth Goldberg int vecno;
5730f1b305eSSeth Goldberg
5740f1b305eSSeth Goldberg /* Restore master and slave interrupt masks */
5750f1b305eSSeth Goldberg outb(SIMR_PORT, sp->smask);
5760f1b305eSSeth Goldberg outb(MIMR_PORT, sp->mmask);
5770f1b305eSSeth Goldberg
5780f1b305eSSeth Goldberg /* Read master to allow pics to settle */
5790f1b305eSSeth Goldberg (void) inb(MIMR_PORT);
5800f1b305eSSeth Goldberg
5810f1b305eSSeth Goldberg /* Restore edge/level configuration for isa interupts */
5820f1b305eSSeth Goldberg for (vecno = 0; vecno <= MAX_ISA_IRQ; vecno++)
5830f1b305eSSeth Goldberg psm_set_elcr(vecno, sp->elcr & (1 << vecno));
5840f1b305eSSeth Goldberg
5850f1b305eSSeth Goldberg /* Reenter PIC mode before restoring LNK devices */
5860f1b305eSSeth Goldberg (void) uppc_acpi_enter_picmode();
5870f1b305eSSeth Goldberg
5880f1b305eSSeth Goldberg /* Restore ACPI link device mappings */
5890f1b305eSSeth Goldberg acpi_restore_link_devices();
5900f1b305eSSeth Goldberg }
5910f1b305eSSeth Goldberg
5920f1b305eSSeth Goldberg static int
uppc_state(psm_state_request_t * rp)5930f1b305eSSeth Goldberg uppc_state(psm_state_request_t *rp)
5940f1b305eSSeth Goldberg {
5950f1b305eSSeth Goldberg switch (rp->psr_cmd) {
5960f1b305eSSeth Goldberg case PSM_STATE_ALLOC:
5970f1b305eSSeth Goldberg rp->req.psm_state_req.psr_state =
5980f1b305eSSeth Goldberg kmem_zalloc(sizeof (struct pic_state), KM_NOSLEEP);
5990f1b305eSSeth Goldberg if (rp->req.psm_state_req.psr_state == NULL)
6000f1b305eSSeth Goldberg return (ENOMEM);
6010f1b305eSSeth Goldberg rp->req.psm_state_req.psr_state_size =
6020f1b305eSSeth Goldberg sizeof (struct pic_state);
6030f1b305eSSeth Goldberg return (0);
6040f1b305eSSeth Goldberg case PSM_STATE_FREE:
6050f1b305eSSeth Goldberg kmem_free(rp->req.psm_state_req.psr_state,
6060f1b305eSSeth Goldberg rp->req.psm_state_req.psr_state_size);
6070f1b305eSSeth Goldberg return (0);
6080f1b305eSSeth Goldberg case PSM_STATE_SAVE:
6090f1b305eSSeth Goldberg pic_save_state(rp->req.psm_state_req.psr_state);
6100f1b305eSSeth Goldberg return (0);
6110f1b305eSSeth Goldberg case PSM_STATE_RESTORE:
6120f1b305eSSeth Goldberg pic_restore_state(rp->req.psm_state_req.psr_state);
6130f1b305eSSeth Goldberg return (0);
6140f1b305eSSeth Goldberg default:
6150f1b305eSSeth Goldberg return (EINVAL);
6160f1b305eSSeth Goldberg }
6170f1b305eSSeth Goldberg }
6180f1b305eSSeth Goldberg
6190f1b305eSSeth Goldberg
6207c478bd9Sstevel@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)6217c478bd9Sstevel@tonic-gate uppc_acpi_translate_pci_irq(dev_info_t *dip, int busid, int devid,
6227c478bd9Sstevel@tonic-gate int ipin, int *pci_irqp, iflag_t *intr_flagp)
6237c478bd9Sstevel@tonic-gate {
6247c478bd9Sstevel@tonic-gate int status;
6257c478bd9Sstevel@tonic-gate acpi_psm_lnk_t acpipsmlnk;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate if ((status = acpi_get_irq_cache_ent(busid, devid, ipin, pci_irqp,
6287c478bd9Sstevel@tonic-gate intr_flagp)) == ACPI_PSM_SUCCESS) {
6297c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Found irqno %d "
6307c478bd9Sstevel@tonic-gate "from cache for device %s, instance #%d\n", *pci_irqp,
6317c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip)));
6327c478bd9Sstevel@tonic-gate return (status);
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate
6357c478bd9Sstevel@tonic-gate bzero(&acpipsmlnk, sizeof (acpi_psm_lnk_t));
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate if ((status = acpi_translate_pci_irq(dip, ipin, pci_irqp,
6387c478bd9Sstevel@tonic-gate intr_flagp, &acpipsmlnk)) == ACPI_PSM_FAILURE) {
6397c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: "
6407c478bd9Sstevel@tonic-gate " acpi_translate_pci_irq failed for device %s, instance"
6417c478bd9Sstevel@tonic-gate " #%d\n", ddi_get_name(dip), ddi_get_instance(dip)));
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate return (status);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate if (status == ACPI_PSM_PARTIAL && acpipsmlnk.lnkobj != NULL) {
6477c478bd9Sstevel@tonic-gate status = uppc_acpi_irq_configure(&acpipsmlnk, dip, pci_irqp,
6487c478bd9Sstevel@tonic-gate intr_flagp);
6497c478bd9Sstevel@tonic-gate if (status != ACPI_PSM_SUCCESS) {
6507c478bd9Sstevel@tonic-gate status = acpi_get_current_irq_resource(&acpipsmlnk,
6517c478bd9Sstevel@tonic-gate pci_irqp, intr_flagp);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate if (status == ACPI_PSM_SUCCESS) {
6567c478bd9Sstevel@tonic-gate acpi_new_irq_cache_ent(busid, devid, ipin, *pci_irqp,
6577c478bd9Sstevel@tonic-gate intr_flagp, &acpipsmlnk);
658450d6964Smyers psm_set_elcr(*pci_irqp, 1); /* set IRQ to PCI mode */
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: [ACPI] "
6617c478bd9Sstevel@tonic-gate "new irq %d for device %s, instance #%d\n",
6627c478bd9Sstevel@tonic-gate *pci_irqp, ddi_get_name(dip), ddi_get_instance(dip)));
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate return (status);
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate /*
6697c478bd9Sstevel@tonic-gate * Configures the irq for the interrupt link device identified by
6707c478bd9Sstevel@tonic-gate * acpipsmlnkp.
6717c478bd9Sstevel@tonic-gate *
6727c478bd9Sstevel@tonic-gate * Gets the current and the list of possible irq settings for the
6737c478bd9Sstevel@tonic-gate * device. If uppc_unconditional_srs is not set, and the current
6747c478bd9Sstevel@tonic-gate * resource setting is in the list of possible irq settings,
6757c478bd9Sstevel@tonic-gate * current irq resource setting is passed to the caller.
6767c478bd9Sstevel@tonic-gate *
6777c478bd9Sstevel@tonic-gate * Otherwise, picks an irq number from the list of possible irq
6787c478bd9Sstevel@tonic-gate * settings, and sets the irq of the device to this value.
6797c478bd9Sstevel@tonic-gate * If prefer_crs is set, among a set of irq numbers in the list that have
6807c478bd9Sstevel@tonic-gate * the least number of devices sharing the interrupt, we pick current irq
6817c478bd9Sstevel@tonic-gate * resource setting if it is a member of this set.
6827c478bd9Sstevel@tonic-gate *
6837c478bd9Sstevel@tonic-gate * Passes the irq number in the value pointed to by pci_irqp, and
6847c478bd9Sstevel@tonic-gate * polarity and sensitivity in the structure pointed to by dipintrflagp
6857c478bd9Sstevel@tonic-gate * to the caller.
6867c478bd9Sstevel@tonic-gate *
6877c478bd9Sstevel@tonic-gate * Note that if setting the irq resource failed, but successfuly obtained
6887c478bd9Sstevel@tonic-gate * the current irq resource settings, passes the current irq resources
6897c478bd9Sstevel@tonic-gate * and considers it a success.
6907c478bd9Sstevel@tonic-gate *
6917c478bd9Sstevel@tonic-gate * Returns:
6927c478bd9Sstevel@tonic-gate * ACPI_PSM_SUCCESS on success.
6937c478bd9Sstevel@tonic-gate *
6947c478bd9Sstevel@tonic-gate * ACPI_PSM_FAILURE if an error occured during the configuration or
6957c478bd9Sstevel@tonic-gate * if a suitable irq was not found for this device, or if setting the
6967c478bd9Sstevel@tonic-gate * irq resource and obtaining the current resource fails.
6977c478bd9Sstevel@tonic-gate *
6987c478bd9Sstevel@tonic-gate */
6997c478bd9Sstevel@tonic-gate static int
uppc_acpi_irq_configure(acpi_psm_lnk_t * acpipsmlnkp,dev_info_t * dip,int * pci_irqp,iflag_t * dipintr_flagp)7007c478bd9Sstevel@tonic-gate uppc_acpi_irq_configure(acpi_psm_lnk_t *acpipsmlnkp, dev_info_t *dip,
7017c478bd9Sstevel@tonic-gate int *pci_irqp, iflag_t *dipintr_flagp)
7027c478bd9Sstevel@tonic-gate {
7037c478bd9Sstevel@tonic-gate int i, min_share, foundnow, done = 0;
7047c478bd9Sstevel@tonic-gate int32_t irq;
7057c478bd9Sstevel@tonic-gate int32_t share_irq = -1;
7067c478bd9Sstevel@tonic-gate int32_t chosen_irq = -1;
7077c478bd9Sstevel@tonic-gate int cur_irq = -1;
7087c478bd9Sstevel@tonic-gate acpi_irqlist_t *irqlistp;
7097c478bd9Sstevel@tonic-gate acpi_irqlist_t *irqlistent;
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate if ((acpi_get_possible_irq_resources(acpipsmlnkp, &irqlistp))
7127c478bd9Sstevel@tonic-gate == ACPI_PSM_FAILURE) {
7137c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: Unable to determine "
7147c478bd9Sstevel@tonic-gate "or assign IRQ for device %s, instance #%d: The system was "
7157c478bd9Sstevel@tonic-gate "unable to get the list of potential IRQs from ACPI.",
7167c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip)));
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate return (ACPI_PSM_FAILURE);
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate if ((acpi_get_current_irq_resource(acpipsmlnkp, &cur_irq,
7227c478bd9Sstevel@tonic-gate dipintr_flagp) == ACPI_PSM_SUCCESS) && (!uppc_unconditional_srs) &&
7237c478bd9Sstevel@tonic-gate (cur_irq > 0)) {
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate if (acpi_irqlist_find_irq(irqlistp, cur_irq, NULL)
7267c478bd9Sstevel@tonic-gate == ACPI_PSM_SUCCESS) {
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate acpi_free_irqlist(irqlistp);
7297c478bd9Sstevel@tonic-gate ASSERT(pci_irqp != NULL);
7307c478bd9Sstevel@tonic-gate *pci_irqp = cur_irq;
7317c478bd9Sstevel@tonic-gate return (ACPI_PSM_SUCCESS);
7327c478bd9Sstevel@tonic-gate }
7337c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: Could not find the "
7347c478bd9Sstevel@tonic-gate "current irq %d for device %s, instance #%d in ACPI's "
7357c478bd9Sstevel@tonic-gate "list of possible irqs for this device. Picking one from "
7367c478bd9Sstevel@tonic-gate " the latter list.", cur_irq, ddi_get_name(dip),
7377c478bd9Sstevel@tonic-gate ddi_get_instance(dip)));
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate irqlistent = irqlistp;
7427c478bd9Sstevel@tonic-gate min_share = 255;
7437c478bd9Sstevel@tonic-gate
7447c478bd9Sstevel@tonic-gate while (irqlistent != NULL) {
7457c478bd9Sstevel@tonic-gate
7467c478bd9Sstevel@tonic-gate for (foundnow = 0, i = 0; i < irqlistent->num_irqs; i++) {
7477c478bd9Sstevel@tonic-gate
7487c478bd9Sstevel@tonic-gate irq = irqlistp->irqs[i];
7497c478bd9Sstevel@tonic-gate
7507c478bd9Sstevel@tonic-gate if ((irq > MAX_ISA_IRQ) ||
7517c478bd9Sstevel@tonic-gate (irqlistent->intr_flags.intr_el == INTR_EL_EDGE) ||
7527c478bd9Sstevel@tonic-gate (irq == 0))
7537c478bd9Sstevel@tonic-gate continue;
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate if (uppc_reserved_irqlist[irq])
7567c478bd9Sstevel@tonic-gate continue;
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate if (uppc_irq_shared_table[irq] == 0) {
7597c478bd9Sstevel@tonic-gate chosen_irq = irq;
7607c478bd9Sstevel@tonic-gate foundnow = 1;
7617c478bd9Sstevel@tonic-gate if (!(uppc_prefer_crs) || (irq == cur_irq)) {
7627c478bd9Sstevel@tonic-gate done = 1;
7637c478bd9Sstevel@tonic-gate break;
7647c478bd9Sstevel@tonic-gate }
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate if ((uppc_irq_shared_table[irq] < min_share) ||
7687c478bd9Sstevel@tonic-gate ((uppc_irq_shared_table[irq] == min_share) &&
7697c478bd9Sstevel@tonic-gate (cur_irq == irq) && (uppc_prefer_crs))) {
7707c478bd9Sstevel@tonic-gate min_share = uppc_irq_shared_table[irq];
7717c478bd9Sstevel@tonic-gate share_irq = irq;
7727c478bd9Sstevel@tonic-gate foundnow = 1;
7737c478bd9Sstevel@tonic-gate }
7747c478bd9Sstevel@tonic-gate }
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate /* If we found an IRQ in the inner loop, save the details */
7777c478bd9Sstevel@tonic-gate if (foundnow && ((chosen_irq != -1) || (share_irq != -1))) {
7787c478bd9Sstevel@tonic-gate /*
7797c478bd9Sstevel@tonic-gate * Copy the acpi_prs_private_t and flags from this
7807c478bd9Sstevel@tonic-gate * irq list entry, since we found an irq from this
7817c478bd9Sstevel@tonic-gate * entry.
7827c478bd9Sstevel@tonic-gate */
7837c478bd9Sstevel@tonic-gate acpipsmlnkp->acpi_prs_prv = irqlistent->acpi_prs_prv;
7847c478bd9Sstevel@tonic-gate *dipintr_flagp = irqlistent->intr_flags;
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate if (done)
7887c478bd9Sstevel@tonic-gate break;
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate /* Load the next entry in the irqlist */
7917c478bd9Sstevel@tonic-gate irqlistent = irqlistent->next;
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate acpi_free_irqlist(irqlistp);
7957c478bd9Sstevel@tonic-gate
7967c478bd9Sstevel@tonic-gate if (chosen_irq != -1)
7977c478bd9Sstevel@tonic-gate irq = chosen_irq;
7987c478bd9Sstevel@tonic-gate else if (share_irq != -1)
7997c478bd9Sstevel@tonic-gate irq = share_irq;
8007c478bd9Sstevel@tonic-gate else {
8017c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Could not find a "
8027c478bd9Sstevel@tonic-gate "suitable irq from the list of possible irqs for device "
8037c478bd9Sstevel@tonic-gate "%s, instance #%d in ACPI's list of possible\n",
8047c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip)));
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate return (ACPI_PSM_FAILURE);
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate
8107c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: Setting irq %d for device %s "
8117c478bd9Sstevel@tonic-gate "instance #%d\n", irq, ddi_get_name(dip), ddi_get_instance(dip)));
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate if ((acpi_set_irq_resource(acpipsmlnkp, irq)) == ACPI_PSM_SUCCESS) {
8147c478bd9Sstevel@tonic-gate /*
8157c478bd9Sstevel@tonic-gate * setting irq was successful, check to make sure CRS
8167c478bd9Sstevel@tonic-gate * reflects that. If CRS does not agree with what we
8177c478bd9Sstevel@tonic-gate * set, return the irq that was set.
8187c478bd9Sstevel@tonic-gate */
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate if (acpi_get_current_irq_resource(acpipsmlnkp, &cur_irq,
8217c478bd9Sstevel@tonic-gate dipintr_flagp) == ACPI_PSM_SUCCESS) {
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate if (cur_irq != irq)
8247c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: "
8257c478bd9Sstevel@tonic-gate "IRQ resource set (irqno %d) for device %s "
8267c478bd9Sstevel@tonic-gate "instance #%d, differs from current "
8277c478bd9Sstevel@tonic-gate "setting irqno %d",
8287c478bd9Sstevel@tonic-gate irq, ddi_get_name(dip),
8297c478bd9Sstevel@tonic-gate ddi_get_instance(dip), cur_irq));
8307c478bd9Sstevel@tonic-gate }
8317c478bd9Sstevel@tonic-gate /*
8327c478bd9Sstevel@tonic-gate * return the irq that was set, and not what CRS reports,
8337c478bd9Sstevel@tonic-gate * since CRS has been seen to be bogus on some systems
8347c478bd9Sstevel@tonic-gate */
8357c478bd9Sstevel@tonic-gate cur_irq = irq;
8367c478bd9Sstevel@tonic-gate } else {
8377c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_WARN, "!uppc: set resource irq %d "
8387c478bd9Sstevel@tonic-gate "failed for device %s instance #%d",
8397c478bd9Sstevel@tonic-gate irq, ddi_get_name(dip), ddi_get_instance(dip)));
8407c478bd9Sstevel@tonic-gate if (cur_irq == -1)
8417c478bd9Sstevel@tonic-gate return (ACPI_PSM_FAILURE);
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate ASSERT(pci_irqp != NULL);
8457c478bd9Sstevel@tonic-gate *pci_irqp = cur_irq;
8467c478bd9Sstevel@tonic-gate return (ACPI_PSM_SUCCESS);
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8517c478bd9Sstevel@tonic-gate static int
uppc_translate_irq(dev_info_t * dip,int irqno)8527c478bd9Sstevel@tonic-gate uppc_translate_irq(dev_info_t *dip, int irqno)
8537c478bd9Sstevel@tonic-gate {
8547c478bd9Sstevel@tonic-gate char dev_type[16];
8557c478bd9Sstevel@tonic-gate int dev_len, pci_irq, devid, busid;
8567c478bd9Sstevel@tonic-gate ddi_acc_handle_t cfg_handle;
857f6db9695Smyers uchar_t ipin, iline;
8587c478bd9Sstevel@tonic-gate iflag_t intr_flag;
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate if (dip == NULL) {
8617c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: irqno = %d"
8627c478bd9Sstevel@tonic-gate " dip = NULL\n", irqno));
8637c478bd9Sstevel@tonic-gate return (irqno);
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate if (!uppc_enable_acpi) {
8677c478bd9Sstevel@tonic-gate return (irqno);
8687c478bd9Sstevel@tonic-gate }
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate dev_len = sizeof (dev_type);
871a3282898Scth if (ddi_getlongprop_buf(DDI_DEV_T_ANY, ddi_get_parent(dip),
8727c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "device_type", (caddr_t)dev_type,
8737c478bd9Sstevel@tonic-gate &dev_len) != DDI_PROP_SUCCESS) {
8747c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: irqno %d"
8757c478bd9Sstevel@tonic-gate "device %s instance %d no device_type\n", irqno,
8767c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip)));
8777c478bd9Sstevel@tonic-gate return (irqno);
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate
88070025d76Sjohnny if ((strcmp(dev_type, "pci") == 0) ||
88170025d76Sjohnny (strcmp(dev_type, "pciex") == 0)) {
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate /* pci device */
8847c478bd9Sstevel@tonic-gate if (acpica_get_bdf(dip, &busid, &devid, NULL) != 0)
8857c478bd9Sstevel@tonic-gate return (irqno);
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate if (pci_config_setup(dip, &cfg_handle) != DDI_SUCCESS)
8887c478bd9Sstevel@tonic-gate return (irqno);
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate ipin = pci_config_get8(cfg_handle, PCI_CONF_IPIN) - PCI_INTA;
891f6db9695Smyers iline = pci_config_get8(cfg_handle, PCI_CONF_ILINE);
8927c478bd9Sstevel@tonic-gate if (uppc_acpi_translate_pci_irq(dip, busid, devid,
8937c478bd9Sstevel@tonic-gate ipin, &pci_irq, &intr_flag) == ACPI_PSM_SUCCESS) {
8947c478bd9Sstevel@tonic-gate
8957c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: [ACPI] new irq "
8967c478bd9Sstevel@tonic-gate "%d old irq %d device %s, instance %d\n", pci_irq,
8977c478bd9Sstevel@tonic-gate irqno, ddi_get_name(dip), ddi_get_instance(dip)));
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate /*
9007c478bd9Sstevel@tonic-gate * Make sure pci_irq is within range.
9017c478bd9Sstevel@tonic-gate * Otherwise, fall through and return irqno.
9027c478bd9Sstevel@tonic-gate */
903f6db9695Smyers if (pci_irq <= MAX_ISA_IRQ) {
904f6db9695Smyers if (iline != pci_irq) {
905f6db9695Smyers /*
906f6db9695Smyers * Update the device's ILINE byte,
907f6db9695Smyers * in case uppc_acpi_translate_pci_irq
908f6db9695Smyers * has choosen a different pci_irq
909f6db9695Smyers * than the BIOS has configured.
910f6db9695Smyers * Some chipsets use the value in
911f6db9695Smyers * ILINE to control interrupt routing,
912f6db9695Smyers * in conflict with the PCI spec.
913f6db9695Smyers */
914f6db9695Smyers pci_config_put8(cfg_handle,
915f6db9695Smyers PCI_CONF_ILINE, pci_irq);
916f6db9695Smyers }
917f6db9695Smyers pci_config_teardown(&cfg_handle);
9187c478bd9Sstevel@tonic-gate return (pci_irq);
9197c478bd9Sstevel@tonic-gate }
920f6db9695Smyers }
921f6db9695Smyers pci_config_teardown(&cfg_handle);
9227c478bd9Sstevel@tonic-gate
9237c478bd9Sstevel@tonic-gate /* FALLTHRU to common case - returning irqno */
9247c478bd9Sstevel@tonic-gate } else {
925450d6964Smyers /* non-PCI; assumes ISA-style edge-triggered */
926450d6964Smyers psm_set_elcr(irqno, 0); /* set IRQ to ISA mode */
927450d6964Smyers
9287c478bd9Sstevel@tonic-gate UPPC_VERBOSE_IRQ((CE_CONT, "!uppc: non-pci,"
9297c478bd9Sstevel@tonic-gate "irqno %d device %s instance %d\n", irqno,
9307c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip)));
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate return (irqno);
9347c478bd9Sstevel@tonic-gate }
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gate /*
9377c478bd9Sstevel@tonic-gate * uppc_intr_enter() raises the ipl to the level of the current interrupt,
9387c478bd9Sstevel@tonic-gate * and sends EOI to the pics.
9397c478bd9Sstevel@tonic-gate * If interrupt is 7 or 15 and not spurious interrupt, send specific EOI
9407c478bd9Sstevel@tonic-gate * else send non-specific EOI
9417c478bd9Sstevel@tonic-gate * uppc_intr_enter() returns the new priority level,
9427c478bd9Sstevel@tonic-gate * or -1 for spurious interrupt
9437c478bd9Sstevel@tonic-gate */
9447c478bd9Sstevel@tonic-gate static int
uppc_intr_enter(int ipl,int * vector)9457c478bd9Sstevel@tonic-gate uppc_intr_enter(int ipl, int *vector)
9467c478bd9Sstevel@tonic-gate {
9477c478bd9Sstevel@tonic-gate int newipl;
9487c478bd9Sstevel@tonic-gate int intno;
9497c478bd9Sstevel@tonic-gate
9507c478bd9Sstevel@tonic-gate intno = (*vector);
9517c478bd9Sstevel@tonic-gate
9527c478bd9Sstevel@tonic-gate ASSERT(intno < 256);
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate newipl = autovect[intno].avh_hi_pri;
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate /*
9577c478bd9Sstevel@tonic-gate * During wait_till_seen() periods when interrupt vector is being
9587c478bd9Sstevel@tonic-gate * removed in remove_av(), the removed hardware interrupt could
9597c478bd9Sstevel@tonic-gate * trigger and got here with newipl 0. It has to send EOI
9607c478bd9Sstevel@tonic-gate * as usual but no need to call setspl and returns -1 like spurious.
9617c478bd9Sstevel@tonic-gate */
9627c478bd9Sstevel@tonic-gate if ((intno & 7) != 7) {
9637c478bd9Sstevel@tonic-gate if (newipl)
9647c478bd9Sstevel@tonic-gate uppc_setspl(newipl);
9657c478bd9Sstevel@tonic-gate outb(MCMD_PORT, PIC_NSEOI);
9667c478bd9Sstevel@tonic-gate if (intno >= 8) {
9677c478bd9Sstevel@tonic-gate outb(SCMD_PORT, PIC_NSEOI);
9687c478bd9Sstevel@tonic-gate }
9697c478bd9Sstevel@tonic-gate } else { /* int was 7 or 15 */
9707c478bd9Sstevel@tonic-gate if (newipl && newipl <= ipl) { /* Check for spurious int */
9717c478bd9Sstevel@tonic-gate if (intno != 7)
9727c478bd9Sstevel@tonic-gate outb(MCMD_PORT, PIC_NSEOI);
9737c478bd9Sstevel@tonic-gate return (-1); /* Spurious int */
9747c478bd9Sstevel@tonic-gate } else {
9757c478bd9Sstevel@tonic-gate if (newipl)
9767c478bd9Sstevel@tonic-gate uppc_setspl(newipl);
9777c478bd9Sstevel@tonic-gate if (intno != 7) {
9787c478bd9Sstevel@tonic-gate outb(MCMD_PORT, PIC_NSEOI);
9797c478bd9Sstevel@tonic-gate outb(SCMD_PORT, PIC_SEOI_LVL7);
9807c478bd9Sstevel@tonic-gate } else {
9817c478bd9Sstevel@tonic-gate outb(MCMD_PORT, PIC_SEOI_LVL7);
9827c478bd9Sstevel@tonic-gate }
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate }
9857c478bd9Sstevel@tonic-gate
9867c478bd9Sstevel@tonic-gate if (newipl)
9877c478bd9Sstevel@tonic-gate return (newipl);
9887c478bd9Sstevel@tonic-gate else
9897c478bd9Sstevel@tonic-gate return (-1); /* not real spurious int */
9907c478bd9Sstevel@tonic-gate }
9917c478bd9Sstevel@tonic-gate
9927c478bd9Sstevel@tonic-gate /*
9937c478bd9Sstevel@tonic-gate * uppc_intr_exit() restores the old interrupt
9947c478bd9Sstevel@tonic-gate * priority level after processing an interrupt.
9957c478bd9Sstevel@tonic-gate * It is called with interrupts disabled, and does not enable interrupts.
9967c478bd9Sstevel@tonic-gate */
9977c478bd9Sstevel@tonic-gate /* ARGSUSED */
9987c478bd9Sstevel@tonic-gate static void
uppc_intr_exit(int ipl,int vector)9997c478bd9Sstevel@tonic-gate uppc_intr_exit(int ipl, int vector)
10007c478bd9Sstevel@tonic-gate {
10017c478bd9Sstevel@tonic-gate uppc_setspl(ipl);
10027c478bd9Sstevel@tonic-gate }
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate /*
10057c478bd9Sstevel@tonic-gate * uppc_setspl() loads new interrupt masks into the pics
10067c478bd9Sstevel@tonic-gate * based on input ipl.
10077c478bd9Sstevel@tonic-gate */
10087c478bd9Sstevel@tonic-gate /* ARGSUSED */
10097c478bd9Sstevel@tonic-gate static void
uppc_setspl(int ipl)10107c478bd9Sstevel@tonic-gate uppc_setspl(int ipl)
10117c478bd9Sstevel@tonic-gate {
10127c478bd9Sstevel@tonic-gate struct standard_pic *pp;
10137c478bd9Sstevel@tonic-gate uint8_t smask, mmask;
10147c478bd9Sstevel@tonic-gate uint8_t cursmask, curmmask;
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate pp = &pics0;
10177c478bd9Sstevel@tonic-gate smask = pp->c_iplmask[ipl * 2];
10187c478bd9Sstevel@tonic-gate mmask = pp->c_iplmask[ipl * 2 + 1];
10197c478bd9Sstevel@tonic-gate cursmask = pp->c_curmask[0];
10207c478bd9Sstevel@tonic-gate curmmask = pp->c_curmask[1];
10217c478bd9Sstevel@tonic-gate if (cursmask == smask && curmmask == mmask)
10227c478bd9Sstevel@tonic-gate return;
10237c478bd9Sstevel@tonic-gate pp->c_curmask[0] = smask;
10247c478bd9Sstevel@tonic-gate pp->c_curmask[1] = mmask;
10257c478bd9Sstevel@tonic-gate
10267c478bd9Sstevel@tonic-gate if (cursmask != smask) {
10277c478bd9Sstevel@tonic-gate /*
10287c478bd9Sstevel@tonic-gate * program new slave pic mask
10297c478bd9Sstevel@tonic-gate */
10307c478bd9Sstevel@tonic-gate outb(SIMR_PORT, smask);
10317c478bd9Sstevel@tonic-gate }
10327c478bd9Sstevel@tonic-gate if (curmmask != mmask) {
10337c478bd9Sstevel@tonic-gate /*
10347c478bd9Sstevel@tonic-gate * program new master pic mask
10357c478bd9Sstevel@tonic-gate */
10367c478bd9Sstevel@tonic-gate outb(MIMR_PORT, mmask);
10377c478bd9Sstevel@tonic-gate }
10387c478bd9Sstevel@tonic-gate /*
10397c478bd9Sstevel@tonic-gate * read master to allow pics to settle
10407c478bd9Sstevel@tonic-gate */
10417c478bd9Sstevel@tonic-gate (void) inb(MIMR_PORT);
10427c478bd9Sstevel@tonic-gate }
10437c478bd9Sstevel@tonic-gate
10447c478bd9Sstevel@tonic-gate /*
10457c478bd9Sstevel@tonic-gate * uppc_gethrtime() returns high resolution timer value
10467c478bd9Sstevel@tonic-gate */
10477c478bd9Sstevel@tonic-gate static hrtime_t
uppc_gethrtime()10487c478bd9Sstevel@tonic-gate uppc_gethrtime()
10497c478bd9Sstevel@tonic-gate {
10507c478bd9Sstevel@tonic-gate hrtime_t timeval, temp;
1051ae115bc7Smrj unsigned int ctr0;
1052ae115bc7Smrj ulong_t oflags;
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate oflags = intr_clear(); /* disable ints */
10557c478bd9Sstevel@tonic-gate lock_set(&uppc_gethrtime_lock);
10567c478bd9Sstevel@tonic-gate retry:
10577c478bd9Sstevel@tonic-gate temp = hrtime_base;
10587c478bd9Sstevel@tonic-gate outb(PITCTL_PORT, 0); /* latch counter 0 */
10597c478bd9Sstevel@tonic-gate /*
10607c478bd9Sstevel@tonic-gate * read counter 0
10617c478bd9Sstevel@tonic-gate */
10627c478bd9Sstevel@tonic-gate ctr0 = inb(PITCTR0_PORT);
10637c478bd9Sstevel@tonic-gate ctr0 |= inb(PITCTR0_PORT) << 8;
10647c478bd9Sstevel@tonic-gate timeval = (hrtime_t)ctr0 * (NANOSEC / PIT_HZ);
10657c478bd9Sstevel@tonic-gate if (temp != hrtime_base)
10667c478bd9Sstevel@tonic-gate goto retry;
10677c478bd9Sstevel@tonic-gate timeval -= temp;
10687c478bd9Sstevel@tonic-gate if (timeval < uppc_lasthrtime)
10697c478bd9Sstevel@tonic-gate timeval = uppc_lasthrtime;
10707c478bd9Sstevel@tonic-gate uppc_lasthrtime = timeval;
10717c478bd9Sstevel@tonic-gate lock_clear(&uppc_gethrtime_lock);
10727c478bd9Sstevel@tonic-gate intr_restore(oflags);
10737c478bd9Sstevel@tonic-gate return (timeval);
10747c478bd9Sstevel@tonic-gate }
1075