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 #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/conf.h> 310Sstevel@tonic-gate #include <sys/ddi.h> 320Sstevel@tonic-gate #include <sys/sunddi.h> 330Sstevel@tonic-gate #include <sys/sunndi.h> 340Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 350Sstevel@tonic-gate #include <sys/ddi_implfuncs.h> 360Sstevel@tonic-gate #include <sys/obpdefs.h> 370Sstevel@tonic-gate #include <sys/cmn_err.h> 380Sstevel@tonic-gate #include <sys/errno.h> 390Sstevel@tonic-gate #include <sys/kmem.h> 400Sstevel@tonic-gate #include <sys/debug.h> 410Sstevel@tonic-gate #include <sys/sysmacros.h> 420Sstevel@tonic-gate #include <sys/autoconf.h> 430Sstevel@tonic-gate #include <sys/spl.h> 440Sstevel@tonic-gate #include <sys/iommu.h> 450Sstevel@tonic-gate #include <sys/sysiosbus.h> 460Sstevel@tonic-gate #include <sys/sysioerr.h> 470Sstevel@tonic-gate #include <sys/iocache.h> 480Sstevel@tonic-gate #include <sys/async.h> 490Sstevel@tonic-gate #include <sys/machsystm.h> 500Sstevel@tonic-gate #include <sys/intreg.h> 510Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 520Sstevel@tonic-gate #ifdef _STARFIRE 530Sstevel@tonic-gate #include <sys/starfire.h> 540Sstevel@tonic-gate #endif /* _STARFIRE */ 550Sstevel@tonic-gate #include <sys/sdt.h> 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* Useful debugging Stuff */ 580Sstevel@tonic-gate #include <sys/nexusdebug.h> 590Sstevel@tonic-gate /* Bitfield debugging definitions for this file */ 600Sstevel@tonic-gate #define SBUS_ATTACH_DEBUG 0x1 610Sstevel@tonic-gate #define SBUS_SBUSMEM_DEBUG 0x2 620Sstevel@tonic-gate #define SBUS_INTERRUPT_DEBUG 0x4 630Sstevel@tonic-gate #define SBUS_REGISTERS_DEBUG 0x8 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Interrupt registers table. 670Sstevel@tonic-gate * This table is necessary due to inconsistencies in the sysio register 680Sstevel@tonic-gate * layout. If this gets fixed in the chip, we can get rid of this stupid 690Sstevel@tonic-gate * table. 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate static struct sbus_slot_entry ino_1 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 720Sstevel@tonic-gate SBUS_SLOT0_L1_CLEAR, NULL}; 730Sstevel@tonic-gate static struct sbus_slot_entry ino_2 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 740Sstevel@tonic-gate SBUS_SLOT0_L2_CLEAR, NULL}; 750Sstevel@tonic-gate static struct sbus_slot_entry ino_3 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 760Sstevel@tonic-gate SBUS_SLOT0_L3_CLEAR, NULL}; 770Sstevel@tonic-gate static struct sbus_slot_entry ino_4 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 780Sstevel@tonic-gate SBUS_SLOT0_L4_CLEAR, NULL}; 790Sstevel@tonic-gate static struct sbus_slot_entry ino_5 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 800Sstevel@tonic-gate SBUS_SLOT0_L5_CLEAR, NULL}; 810Sstevel@tonic-gate static struct sbus_slot_entry ino_6 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 820Sstevel@tonic-gate SBUS_SLOT0_L6_CLEAR, NULL}; 830Sstevel@tonic-gate static struct sbus_slot_entry ino_7 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 840Sstevel@tonic-gate SBUS_SLOT0_L7_CLEAR, NULL}; 850Sstevel@tonic-gate static struct sbus_slot_entry ino_9 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 860Sstevel@tonic-gate SBUS_SLOT1_L1_CLEAR, NULL}; 870Sstevel@tonic-gate static struct sbus_slot_entry ino_10 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 880Sstevel@tonic-gate SBUS_SLOT1_L2_CLEAR, NULL}; 890Sstevel@tonic-gate static struct sbus_slot_entry ino_11 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 900Sstevel@tonic-gate SBUS_SLOT1_L3_CLEAR, NULL}; 910Sstevel@tonic-gate static struct sbus_slot_entry ino_12 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 920Sstevel@tonic-gate SBUS_SLOT1_L4_CLEAR, NULL}; 930Sstevel@tonic-gate static struct sbus_slot_entry ino_13 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 940Sstevel@tonic-gate SBUS_SLOT1_L5_CLEAR, NULL}; 950Sstevel@tonic-gate static struct sbus_slot_entry ino_14 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 960Sstevel@tonic-gate SBUS_SLOT1_L6_CLEAR, NULL}; 970Sstevel@tonic-gate static struct sbus_slot_entry ino_15 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 980Sstevel@tonic-gate SBUS_SLOT1_L7_CLEAR, NULL}; 990Sstevel@tonic-gate static struct sbus_slot_entry ino_17 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1000Sstevel@tonic-gate SBUS_SLOT2_L1_CLEAR, NULL}; 1010Sstevel@tonic-gate static struct sbus_slot_entry ino_18 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1020Sstevel@tonic-gate SBUS_SLOT2_L2_CLEAR, NULL}; 1030Sstevel@tonic-gate static struct sbus_slot_entry ino_19 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1040Sstevel@tonic-gate SBUS_SLOT2_L3_CLEAR, NULL}; 1050Sstevel@tonic-gate static struct sbus_slot_entry ino_20 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1060Sstevel@tonic-gate SBUS_SLOT2_L4_CLEAR, NULL}; 1070Sstevel@tonic-gate static struct sbus_slot_entry ino_21 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1080Sstevel@tonic-gate SBUS_SLOT2_L5_CLEAR, NULL}; 1090Sstevel@tonic-gate static struct sbus_slot_entry ino_22 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1100Sstevel@tonic-gate SBUS_SLOT2_L6_CLEAR, NULL}; 1110Sstevel@tonic-gate static struct sbus_slot_entry ino_23 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1120Sstevel@tonic-gate SBUS_SLOT2_L7_CLEAR, NULL}; 1130Sstevel@tonic-gate static struct sbus_slot_entry ino_25 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1140Sstevel@tonic-gate SBUS_SLOT3_L1_CLEAR, NULL}; 1150Sstevel@tonic-gate static struct sbus_slot_entry ino_26 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1160Sstevel@tonic-gate SBUS_SLOT3_L2_CLEAR, NULL}; 1170Sstevel@tonic-gate static struct sbus_slot_entry ino_27 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1180Sstevel@tonic-gate SBUS_SLOT3_L3_CLEAR, NULL}; 1190Sstevel@tonic-gate static struct sbus_slot_entry ino_28 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1200Sstevel@tonic-gate SBUS_SLOT3_L4_CLEAR, NULL}; 1210Sstevel@tonic-gate static struct sbus_slot_entry ino_29 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1220Sstevel@tonic-gate SBUS_SLOT3_L5_CLEAR, NULL}; 1230Sstevel@tonic-gate static struct sbus_slot_entry ino_30 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1240Sstevel@tonic-gate SBUS_SLOT3_L6_CLEAR, NULL}; 1250Sstevel@tonic-gate static struct sbus_slot_entry ino_31 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1260Sstevel@tonic-gate SBUS_SLOT3_L7_CLEAR, NULL}; 1270Sstevel@tonic-gate static struct sbus_slot_entry ino_32 = {SBUS_SLOT5_CONFIG, ESP_MAPREG, 1280Sstevel@tonic-gate ESP_CLEAR, ESP_INTR_STATE_SHIFT}; 1290Sstevel@tonic-gate static struct sbus_slot_entry ino_33 = {SBUS_SLOT5_CONFIG, ETHER_MAPREG, 1300Sstevel@tonic-gate ETHER_CLEAR, ETHER_INTR_STATE_SHIFT}; 1310Sstevel@tonic-gate static struct sbus_slot_entry ino_34 = {SBUS_SLOT5_CONFIG, PP_MAPREG, 1320Sstevel@tonic-gate PP_CLEAR, PP_INTR_STATE_SHIFT}; 1330Sstevel@tonic-gate static struct sbus_slot_entry ino_36 = {SBUS_SLOT4_CONFIG, AUDIO_MAPREG, 1340Sstevel@tonic-gate AUDIO_CLEAR, AUDIO_INTR_STATE_SHIFT}; 1350Sstevel@tonic-gate static struct sbus_slot_entry ino_40 = {SBUS_SLOT6_CONFIG, KBDMOUSE_MAPREG, 1360Sstevel@tonic-gate KBDMOUSE_CLEAR, 1370Sstevel@tonic-gate KBDMOUSE_INTR_STATE_SHIFT}; 1380Sstevel@tonic-gate static struct sbus_slot_entry ino_41 = {SBUS_SLOT6_CONFIG, FLOPPY_MAPREG, 1390Sstevel@tonic-gate FLOPPY_CLEAR, FLOPPY_INTR_STATE_SHIFT}; 1400Sstevel@tonic-gate static struct sbus_slot_entry ino_42 = {SBUS_SLOT6_CONFIG, THERMAL_MAPREG, 1410Sstevel@tonic-gate THERMAL_CLEAR, 1420Sstevel@tonic-gate THERMAL_INTR_STATE_SHIFT}; 1430Sstevel@tonic-gate static struct sbus_slot_entry ino_48 = {SBUS_SLOT6_CONFIG, TIMER0_MAPREG, 1440Sstevel@tonic-gate TIMER0_CLEAR, TIMER0_INTR_STATE_SHIFT}; 1450Sstevel@tonic-gate static struct sbus_slot_entry ino_49 = {SBUS_SLOT6_CONFIG, TIMER1_MAPREG, 1460Sstevel@tonic-gate TIMER1_CLEAR, TIMER1_INTR_STATE_SHIFT}; 1470Sstevel@tonic-gate static struct sbus_slot_entry ino_52 = {SBUS_SLOT6_CONFIG, UE_ECC_MAPREG, 1480Sstevel@tonic-gate UE_ECC_CLEAR, UE_INTR_STATE_SHIFT}; 1490Sstevel@tonic-gate static struct sbus_slot_entry ino_53 = {SBUS_SLOT6_CONFIG, CE_ECC_MAPREG, 1500Sstevel@tonic-gate CE_ECC_CLEAR, CE_INTR_STATE_SHIFT}; 1510Sstevel@tonic-gate static struct sbus_slot_entry ino_54 = {SBUS_SLOT6_CONFIG, SBUS_ERR_MAPREG, 1520Sstevel@tonic-gate SBUS_ERR_CLEAR, SERR_INTR_STATE_SHIFT}; 1530Sstevel@tonic-gate static struct sbus_slot_entry ino_55 = {SBUS_SLOT6_CONFIG, PM_WAKEUP_MAPREG, 1540Sstevel@tonic-gate PM_WAKEUP_CLEAR, PM_INTR_STATE_SHIFT}; 1550Sstevel@tonic-gate static struct sbus_slot_entry ino_ffb = {NULL, FFB_MAPPING_REG, NULL, NULL}; 1560Sstevel@tonic-gate static struct sbus_slot_entry ino_exp = {NULL, EXP_MAPPING_REG, NULL, NULL}; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* Construct the interrupt number array */ 1590Sstevel@tonic-gate struct sbus_slot_entry *ino_table[] = { 1600Sstevel@tonic-gate NULL, &ino_1, &ino_2, &ino_3, &ino_4, &ino_5, &ino_6, &ino_7, 1610Sstevel@tonic-gate NULL, &ino_9, &ino_10, &ino_11, &ino_12, &ino_13, &ino_14, &ino_15, 1620Sstevel@tonic-gate NULL, &ino_17, &ino_18, &ino_19, &ino_20, &ino_21, &ino_22, &ino_23, 1630Sstevel@tonic-gate NULL, &ino_25, &ino_26, &ino_27, &ino_28, &ino_29, &ino_30, &ino_31, 1640Sstevel@tonic-gate &ino_32, &ino_33, &ino_34, NULL, &ino_36, NULL, NULL, NULL, 1650Sstevel@tonic-gate &ino_40, &ino_41, &ino_42, NULL, NULL, NULL, NULL, NULL, &ino_48, 1660Sstevel@tonic-gate &ino_49, NULL, NULL, &ino_52, &ino_53, &ino_54, &ino_55, &ino_ffb, 1670Sstevel@tonic-gate &ino_exp 1680Sstevel@tonic-gate }; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * This table represents the Fusion interrupt priorities. They range 1720Sstevel@tonic-gate * from 1 - 15, so we'll pattern the priorities after the 4M. We map Fusion 1730Sstevel@tonic-gate * interrupt number to system priority. The mondo number is used as an 1740Sstevel@tonic-gate * index into this table. 1750Sstevel@tonic-gate */ 1760Sstevel@tonic-gate int interrupt_priorities[] = { 1770Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 0 sbus level 1 - 7 */ 1780Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 1 sbus level 1 - 7 */ 1790Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 2 sbus level 1 - 7 */ 1800Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 3 sbus level 1 - 7 */ 1810Sstevel@tonic-gate 4, /* Onboard SCSI */ 1820Sstevel@tonic-gate 6, /* Onboard Ethernet */ 1830Sstevel@tonic-gate 3, /* Onboard Parallel port */ 1840Sstevel@tonic-gate -1, /* Not in use */ 1850Sstevel@tonic-gate 9, /* Onboard Audio */ 1860Sstevel@tonic-gate -1, -1, -1, /* Not in use */ 1870Sstevel@tonic-gate 12, /* Onboard keyboard/serial ports */ 1880Sstevel@tonic-gate 11, /* Onboard Floppy */ 1890Sstevel@tonic-gate 9, /* Thermal interrupt */ 1900Sstevel@tonic-gate -1, -1, -1, /* Not is use */ 1910Sstevel@tonic-gate 10, /* Timer 0 (tick timer) */ 1920Sstevel@tonic-gate 14, /* Timer 1 (not used) */ 1930Sstevel@tonic-gate 15, /* Sysio UE ECC error */ 1940Sstevel@tonic-gate 10, /* Sysio CE ECC error */ 1950Sstevel@tonic-gate 10, /* Sysio Sbus error */ 1960Sstevel@tonic-gate 10, /* PM Wakeup */ 1970Sstevel@tonic-gate }; 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate /* Interrupt counter flag. To enable/disable spurious interrupt counter. */ 2000Sstevel@tonic-gate static int intr_cntr_on; 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * Function prototypes. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate static int 2060Sstevel@tonic-gate sbus_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate static int 2090Sstevel@tonic-gate sbus_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 2100Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate static void 2130Sstevel@tonic-gate sbus_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 2140Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate static int 2170Sstevel@tonic-gate sbus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 2180Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result); 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate static int 221693Sgovinda sbus_xlate_intrs(dev_info_t *dip, dev_info_t *rdip, uint32_t *intr, 222693Sgovinda uint32_t *pil, int32_t ign); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate static int 2250Sstevel@tonic-gate sbus_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate static int 2280Sstevel@tonic-gate sbus_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate static int 2310Sstevel@tonic-gate sbus_do_detach(dev_info_t *devi); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate static void 2340Sstevel@tonic-gate sbus_add_picN_kstats(dev_info_t *dip); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate static void 2370Sstevel@tonic-gate sbus_add_kstats(struct sbus_soft_state *); 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate static int 2400Sstevel@tonic-gate sbus_counters_kstat_update(kstat_t *, int); 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate extern int 2430Sstevel@tonic-gate sysio_err_uninit(struct sbus_soft_state *softsp); 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate extern int 2460Sstevel@tonic-gate iommu_uninit(struct sbus_soft_state *softsp); 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate extern int 2490Sstevel@tonic-gate stream_buf_uninit(struct sbus_soft_state *softsp); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate static int 2520Sstevel@tonic-gate find_sbus_slot(dev_info_t *dip, dev_info_t *rdip); 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate static void make_sbus_ppd(dev_info_t *child); 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate static int 2570Sstevel@tonic-gate sbusmem_initchild(dev_info_t *dip, dev_info_t *child); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate static int 2600Sstevel@tonic-gate sbus_initchild(dev_info_t *dip, dev_info_t *child); 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate static int 2630Sstevel@tonic-gate sbus_uninitchild(dev_info_t *dip); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate static int 2660Sstevel@tonic-gate sbus_ctlops_poke(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args); 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate static int 2690Sstevel@tonic-gate sbus_ctlops_peek(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args, 2700Sstevel@tonic-gate void *result); 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate static int 2730Sstevel@tonic-gate sbus_init(struct sbus_soft_state *softsp, caddr_t address); 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate static int 2760Sstevel@tonic-gate sbus_resume_init(struct sbus_soft_state *softsp, int resume); 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate static void 2790Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(uint64_t *cpr_softsp, volatile uint64_t *baddr, 2800Sstevel@tonic-gate int flag); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate static void sbus_intrdist(void *); 2830Sstevel@tonic-gate static uint_t sbus_intr_reset(void *); 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate static int 2860Sstevel@tonic-gate sbus_update_intr_state(dev_info_t *dip, dev_info_t *rdip, 2870Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate #ifdef _STARFIRE 2900Sstevel@tonic-gate void 2910Sstevel@tonic-gate pc_ittrans_init(int, caddr_t *); 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate void 2940Sstevel@tonic-gate pc_ittrans_uninit(caddr_t); 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate int 2970Sstevel@tonic-gate pc_translate_tgtid(caddr_t, int, volatile uint64_t *); 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate void 3000Sstevel@tonic-gate pc_ittrans_cleanup(caddr_t, volatile uint64_t *); 3010Sstevel@tonic-gate #endif /* _STARFIRE */ 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* 3040Sstevel@tonic-gate * Configuration data structures 3050Sstevel@tonic-gate */ 3060Sstevel@tonic-gate static struct bus_ops sbus_bus_ops = { 3070Sstevel@tonic-gate BUSO_REV, 3080Sstevel@tonic-gate i_ddi_bus_map, 3090Sstevel@tonic-gate 0, 3100Sstevel@tonic-gate 0, 3110Sstevel@tonic-gate 0, 3120Sstevel@tonic-gate i_ddi_map_fault, 3130Sstevel@tonic-gate iommu_dma_map, 3140Sstevel@tonic-gate iommu_dma_allochdl, 3150Sstevel@tonic-gate iommu_dma_freehdl, 3160Sstevel@tonic-gate iommu_dma_bindhdl, 3170Sstevel@tonic-gate iommu_dma_unbindhdl, 3180Sstevel@tonic-gate iommu_dma_flush, 3190Sstevel@tonic-gate iommu_dma_win, 3200Sstevel@tonic-gate iommu_dma_mctl, 3210Sstevel@tonic-gate sbus_ctlops, 3220Sstevel@tonic-gate ddi_bus_prop_op, 3230Sstevel@tonic-gate 0, /* (*bus_get_eventcookie)(); */ 3240Sstevel@tonic-gate 0, /* (*bus_add_eventcall)(); */ 3250Sstevel@tonic-gate 0, /* (*bus_remove_eventcall)(); */ 3260Sstevel@tonic-gate 0, /* (*bus_post_event)(); */ 3270Sstevel@tonic-gate 0, /* (*bus_intr_control)(); */ 3280Sstevel@tonic-gate 0, /* (*bus_config)(); */ 3290Sstevel@tonic-gate 0, /* (*bus_unconfig)(); */ 3300Sstevel@tonic-gate 0, /* (*bus_fm_init)(); */ 3310Sstevel@tonic-gate 0, /* (*bus_fm_fini)(); */ 3320Sstevel@tonic-gate 0, /* (*bus_fm_access_enter)(); */ 3330Sstevel@tonic-gate 0, /* (*bus_fm_access_exit)(); */ 3340Sstevel@tonic-gate 0, /* (*bus_power)(); */ 3350Sstevel@tonic-gate sbus_intr_ops /* (*bus_intr_op)(); */ 3360Sstevel@tonic-gate }; 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate static struct cb_ops sbus_cb_ops = { 3390Sstevel@tonic-gate nodev, /* open */ 3400Sstevel@tonic-gate nodev, /* close */ 3410Sstevel@tonic-gate nodev, /* strategy */ 3420Sstevel@tonic-gate nodev, /* print */ 3430Sstevel@tonic-gate nodev, /* dump */ 3440Sstevel@tonic-gate nodev, /* read */ 3450Sstevel@tonic-gate nodev, /* write */ 3460Sstevel@tonic-gate nodev, /* ioctl */ 3470Sstevel@tonic-gate nodev, /* devmap */ 3480Sstevel@tonic-gate nodev, /* mmap */ 3490Sstevel@tonic-gate nodev, /* segmap */ 3500Sstevel@tonic-gate nochpoll, /* poll */ 3510Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 3520Sstevel@tonic-gate NULL, 3530Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, 3540Sstevel@tonic-gate CB_REV, /* rev */ 3550Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 3560Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 3570Sstevel@tonic-gate }; 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate static struct dev_ops sbus_ops = { 3600Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 3610Sstevel@tonic-gate 0, /* refcnt */ 3620Sstevel@tonic-gate ddi_no_info, /* info */ 3630Sstevel@tonic-gate nulldev, /* identify */ 3640Sstevel@tonic-gate nulldev, /* probe */ 3650Sstevel@tonic-gate sbus_attach, /* attach */ 3660Sstevel@tonic-gate sbus_detach, /* detach */ 3670Sstevel@tonic-gate nodev, /* reset */ 3680Sstevel@tonic-gate &sbus_cb_ops, /* driver operations */ 3690Sstevel@tonic-gate &sbus_bus_ops, /* bus operations */ 3700Sstevel@tonic-gate nulldev /* power */ 3710Sstevel@tonic-gate }; 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate /* global data */ 3740Sstevel@tonic-gate void *sbusp; /* sbus soft state hook */ 3750Sstevel@tonic-gate void *sbus_cprp; /* subs suspend/resume soft state hook */ 3760Sstevel@tonic-gate static kstat_t *sbus_picN_ksp[SBUS_NUM_PICS]; /* performance picN kstats */ 3770Sstevel@tonic-gate static int sbus_attachcnt = 0; /* number of instances attached */ 3780Sstevel@tonic-gate static kmutex_t sbus_attachcnt_mutex; /* sbus_attachcnt lock - attach/detach */ 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate #include <sys/modctl.h> 3810Sstevel@tonic-gate extern struct mod_ops mod_driverops; 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate static struct modldrv modldrv = { 3840Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 3850Sstevel@tonic-gate "SBus (sysio) nexus driver %I%", /* Name of module. */ 3860Sstevel@tonic-gate &sbus_ops, /* driver ops */ 3870Sstevel@tonic-gate }; 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate static struct modlinkage modlinkage = { 3900Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 3910Sstevel@tonic-gate }; 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate /* 3940Sstevel@tonic-gate * These are the module initialization routines. 3950Sstevel@tonic-gate */ 3960Sstevel@tonic-gate int 3970Sstevel@tonic-gate _init(void) 3980Sstevel@tonic-gate { 3990Sstevel@tonic-gate int error; 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbusp, 4020Sstevel@tonic-gate sizeof (struct sbus_soft_state), 1)) != 0) 4030Sstevel@tonic-gate return (error); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate /* 4060Sstevel@tonic-gate * Initialize cpr soft state structure 4070Sstevel@tonic-gate */ 4080Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbus_cprp, 4090Sstevel@tonic-gate sizeof (uint64_t) * MAX_INO_TABLE_SIZE, 0)) != 0) 4100Sstevel@tonic-gate return (error); 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate /* Initialize global mutex */ 4130Sstevel@tonic-gate mutex_init(&sbus_attachcnt_mutex, NULL, MUTEX_DRIVER, NULL); 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate return (mod_install(&modlinkage)); 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate int 4190Sstevel@tonic-gate _fini(void) 4200Sstevel@tonic-gate { 4210Sstevel@tonic-gate int error; 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) 4240Sstevel@tonic-gate return (error); 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate mutex_destroy(&sbus_attachcnt_mutex); 4270Sstevel@tonic-gate ddi_soft_state_fini(&sbusp); 4280Sstevel@tonic-gate ddi_soft_state_fini(&sbus_cprp); 4290Sstevel@tonic-gate return (0); 4300Sstevel@tonic-gate } 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate int 4330Sstevel@tonic-gate _info(struct modinfo *modinfop) 4340Sstevel@tonic-gate { 4350Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4360Sstevel@tonic-gate } 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /*ARGSUSED*/ 4390Sstevel@tonic-gate static int 4400Sstevel@tonic-gate sbus_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 4410Sstevel@tonic-gate { 4420Sstevel@tonic-gate struct sbus_soft_state *softsp; 4430Sstevel@tonic-gate int instance, error; 4440Sstevel@tonic-gate uint64_t *cpr_softsp; 4450Sstevel@tonic-gate ddi_device_acc_attr_t attr; 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate #ifdef DEBUG 4490Sstevel@tonic-gate debug_info = 1; 4500Sstevel@tonic-gate debug_print_level = 0; 4510Sstevel@tonic-gate #endif 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate instance = ddi_get_instance(devi); 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate switch (cmd) { 4560Sstevel@tonic-gate case DDI_ATTACH: 4570Sstevel@tonic-gate break; 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate case DDI_RESUME: 4600Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate if ((error = iommu_resume_init(softsp)) != DDI_SUCCESS) 4630Sstevel@tonic-gate return (error); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if ((error = sbus_resume_init(softsp, 1)) != DDI_SUCCESS) 4660Sstevel@tonic-gate return (error); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate if ((error = stream_buf_resume_init(softsp)) != DDI_SUCCESS) 4690Sstevel@tonic-gate return (error); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * Restore Interrupt Mapping registers 4730Sstevel@tonic-gate */ 4740Sstevel@tonic-gate cpr_softsp = ddi_get_soft_state(sbus_cprp, instance); 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate if (cpr_softsp != NULL) { 4770Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(cpr_softsp, 4780Sstevel@tonic-gate softsp->intr_mapping_reg, 0); 4790Sstevel@tonic-gate ddi_soft_state_free(sbus_cprp, instance); 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate return (DDI_SUCCESS); 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate default: 4850Sstevel@tonic-gate return (DDI_FAILURE); 4860Sstevel@tonic-gate } 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbusp, instance) != DDI_SUCCESS) 4890Sstevel@tonic-gate return (DDI_FAILURE); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate /* Set the dip in the soft state */ 4940Sstevel@tonic-gate softsp->dip = devi; 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate if ((softsp->upa_id = (int)ddi_getprop(DDI_DEV_T_ANY, softsp->dip, 4970Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1)) == -1) { 4980Sstevel@tonic-gate cmn_err(CE_WARN, "Unable to retrieve sbus upa-portid" 4990Sstevel@tonic-gate "property."); 5000Sstevel@tonic-gate error = DDI_FAILURE; 5010Sstevel@tonic-gate goto bad; 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate /* 5050Sstevel@tonic-gate * The firmware maps in all 3 pages of the sysio chips device 5060Sstevel@tonic-gate * device registers and exports the mapping in the int-sized 5070Sstevel@tonic-gate * property "address". Read in this address and pass it to 5080Sstevel@tonic-gate * the subsidiary *_init functions, so we don't create extra 5090Sstevel@tonic-gate * mappings to the same physical pages and we don't have to 5100Sstevel@tonic-gate * retrieve the more than once. 5110Sstevel@tonic-gate */ 5120Sstevel@tonic-gate /* 5130Sstevel@tonic-gate * Implement new policy to start ignoring the "address" property 5140Sstevel@tonic-gate * due to new requirements from DR. The problem is that the contents 5150Sstevel@tonic-gate * of the "address" property contain vm mappings from OBP which needs 5160Sstevel@tonic-gate * to be recaptured into kernel vm. Instead of relying on a blanket 5170Sstevel@tonic-gate * recapture during boot time, we map psycho registers each time during 5180Sstevel@tonic-gate * attach and unmap the during detach. In some future point of time 5190Sstevel@tonic-gate * OBP will drop creating "address" property but this driver will 5200Sstevel@tonic-gate * will already not rely on this property any more. 5210Sstevel@tonic-gate */ 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 5240Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 5250Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 5260Sstevel@tonic-gate if (ddi_regs_map_setup(softsp->dip, 0, &softsp->address, 0, 0, 5270Sstevel@tonic-gate &attr, &softsp->ac) != DDI_SUCCESS) { 5280Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unable to map reg set 0\n", 5290Sstevel@tonic-gate ddi_get_name(softsp->dip), 5300Sstevel@tonic-gate ddi_get_instance(softsp->dip)); 5310Sstevel@tonic-gate return (0); 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate if (softsp->address == (caddr_t)-1) { 5340Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus%d: No sysio <address> property\n", 5350Sstevel@tonic-gate ddi_get_instance(softsp->dip)); 5360Sstevel@tonic-gate return (DDI_FAILURE); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 539*1035Smike_s DPRINTF(SBUS_ATTACH_DEBUG, ("sbus: devi=0x%p, softsp=0x%p\n", 5400Sstevel@tonic-gate devi, softsp)); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate #ifdef notdef 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * This bit of code, plus the firmware, will tell us if 5450Sstevel@tonic-gate * the #size-cells infrastructure code works, to some degree. 5460Sstevel@tonic-gate * You should be able to use the firmware to determine if 5470Sstevel@tonic-gate * the address returned by ddi_map_regs maps the correct phys. pages. 5480Sstevel@tonic-gate */ 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate { 5510Sstevel@tonic-gate caddr_t addr; 5520Sstevel@tonic-gate int rv; 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: address property = 0x%x\n", address); 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate if ((rv = ddi_map_regs(softsp->dip, 0, &addr, 5570Sstevel@tonic-gate (off_t)0, (off_t)0)) != DDI_SUCCESS) { 5580Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: ddi_map_regs failed: %d\n", 5590Sstevel@tonic-gate rv); 5600Sstevel@tonic-gate } else { 5610Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: ddi_map_regs returned " 5620Sstevel@tonic-gate " virtual address 0x%x\n", addr); 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate #endif /* notdef */ 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate if ((error = iommu_init(softsp, softsp->address)) != DDI_SUCCESS) 5680Sstevel@tonic-gate goto bad; 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate if ((error = sbus_init(softsp, softsp->address)) != DDI_SUCCESS) 5710Sstevel@tonic-gate goto bad; 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate if ((error = sysio_err_init(softsp, softsp->address)) != DDI_SUCCESS) 5740Sstevel@tonic-gate goto bad; 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate if ((error = stream_buf_init(softsp, softsp->address)) != DDI_SUCCESS) 5770Sstevel@tonic-gate goto bad; 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /* Init the pokefault mutex for sbus devices */ 5800Sstevel@tonic-gate mutex_init(&softsp->pokefault_mutex, NULL, MUTEX_SPIN, 5810Sstevel@tonic-gate (void *)ipltospl(SBUS_ERR_PIL - 1)); 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate sbus_add_kstats(softsp); 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate bus_func_register(BF_TYPE_RESINTR, sbus_intr_reset, devi); 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate intr_dist_add(sbus_intrdist, devi); 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate ddi_report_dev(devi); 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate return (DDI_SUCCESS); 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate bad: 5940Sstevel@tonic-gate ddi_soft_state_free(sbusp, instance); 5950Sstevel@tonic-gate return (error); 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate /* ARGSUSED */ 5990Sstevel@tonic-gate static int 6000Sstevel@tonic-gate sbus_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 6010Sstevel@tonic-gate { 6020Sstevel@tonic-gate int instance; 6030Sstevel@tonic-gate struct sbus_soft_state *softsp; 6040Sstevel@tonic-gate uint64_t *cpr_softsp; 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate switch (cmd) { 6070Sstevel@tonic-gate case DDI_SUSPEND: 6080Sstevel@tonic-gate /* 6090Sstevel@tonic-gate * Allocate the cpr soft data structure to save the current 6100Sstevel@tonic-gate * state of the interrupt mapping registers. 6110Sstevel@tonic-gate * This structure will be deallocated after the system 6120Sstevel@tonic-gate * is resumed. 6130Sstevel@tonic-gate */ 6140Sstevel@tonic-gate instance = ddi_get_instance(devi); 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbus_cprp, instance) 6170Sstevel@tonic-gate != DDI_SUCCESS) 6180Sstevel@tonic-gate return (DDI_FAILURE); 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate cpr_softsp = ddi_get_soft_state(sbus_cprp, instance); 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(cpr_softsp, 6250Sstevel@tonic-gate softsp->intr_mapping_reg, 1); 6260Sstevel@tonic-gate return (DDI_SUCCESS); 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate case DDI_DETACH: 6290Sstevel@tonic-gate return (sbus_do_detach(devi)); 6300Sstevel@tonic-gate default: 6310Sstevel@tonic-gate return (DDI_FAILURE); 6320Sstevel@tonic-gate } 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate static int 6360Sstevel@tonic-gate sbus_do_detach(dev_info_t *devi) 6370Sstevel@tonic-gate { 6380Sstevel@tonic-gate int instance, pic; 6390Sstevel@tonic-gate struct sbus_soft_state *softsp; 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate instance = ddi_get_instance(devi); 6420Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 6430Sstevel@tonic-gate ASSERT(softsp != NULL); 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate bus_func_unregister(BF_TYPE_RESINTR, sbus_intr_reset, devi); 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate intr_dist_rem(sbus_intrdist, devi); 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* disable the streamming cache */ 6500Sstevel@tonic-gate if (stream_buf_uninit(softsp) == DDI_FAILURE) { 6510Sstevel@tonic-gate goto err; 6520Sstevel@tonic-gate } 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate /* remove the interrupt handlers from the system */ 6550Sstevel@tonic-gate if (sysio_err_uninit(softsp) == DDI_FAILURE) { 6560Sstevel@tonic-gate goto err; 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate /* disable the IOMMU */ 6600Sstevel@tonic-gate if (iommu_uninit(softsp)) { 6610Sstevel@tonic-gate goto err; 6620Sstevel@tonic-gate } 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* unmap register space if we have a handle */ 6650Sstevel@tonic-gate if (softsp->ac) { 6660Sstevel@tonic-gate ddi_regs_map_free(&softsp->ac); 6670Sstevel@tonic-gate softsp->address = NULL; 6680Sstevel@tonic-gate } 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate /* 6710Sstevel@tonic-gate * remove counter kstats for this device 6720Sstevel@tonic-gate */ 6730Sstevel@tonic-gate if (softsp->sbus_counters_ksp != (kstat_t *)NULL) 6740Sstevel@tonic-gate kstat_delete(softsp->sbus_counters_ksp); 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate /* 6770Sstevel@tonic-gate * if we are the last instance to detach we need to 6780Sstevel@tonic-gate * remove the picN kstats. We use sbus_attachcnt as a 6790Sstevel@tonic-gate * count of how many instances are still attached. This 6800Sstevel@tonic-gate * is protected by a mutex. 6810Sstevel@tonic-gate */ 6820Sstevel@tonic-gate mutex_enter(&sbus_attachcnt_mutex); 6830Sstevel@tonic-gate sbus_attachcnt --; 6840Sstevel@tonic-gate if (sbus_attachcnt == 0) { 6850Sstevel@tonic-gate for (pic = 0; pic < SBUS_NUM_PICS; pic++) { 6860Sstevel@tonic-gate if (sbus_picN_ksp[pic] != (kstat_t *)NULL) { 6870Sstevel@tonic-gate kstat_delete(sbus_picN_ksp[pic]); 6880Sstevel@tonic-gate sbus_picN_ksp[pic] = NULL; 6890Sstevel@tonic-gate } 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate } 6920Sstevel@tonic-gate mutex_exit(&sbus_attachcnt_mutex); 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate #ifdef _STARFIRE 6950Sstevel@tonic-gate /* free starfire specific soft intr mapping structure */ 6960Sstevel@tonic-gate pc_ittrans_uninit(softsp->ittrans_cookie); 6970Sstevel@tonic-gate #endif /* _STARFIRE */ 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate /* free the soft state structure */ 7000Sstevel@tonic-gate ddi_soft_state_free(sbusp, instance); 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate return (DDI_SUCCESS); 7030Sstevel@tonic-gate err: 7040Sstevel@tonic-gate return (DDI_FAILURE); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate static int 7080Sstevel@tonic-gate sbus_init(struct sbus_soft_state *softsp, caddr_t address) 7090Sstevel@tonic-gate { 7100Sstevel@tonic-gate int i; 7110Sstevel@tonic-gate extern void set_intr_mapping_reg(int, uint64_t *, int); 7120Sstevel@tonic-gate int numproxy; 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate /* 7150Sstevel@tonic-gate * Simply add each registers offset to the base address 7160Sstevel@tonic-gate * to calculate the already mapped virtual address of 7170Sstevel@tonic-gate * the device register... 7180Sstevel@tonic-gate * 7190Sstevel@tonic-gate * define a macro for the pointer arithmetic; all registers 7200Sstevel@tonic-gate * are 64 bits wide and are defined as uint64_t's. 7210Sstevel@tonic-gate */ 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate #define REG_ADDR(b, o) (uint64_t *)((caddr_t)(b) + (o)) 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate softsp->sysio_ctrl_reg = REG_ADDR(address, OFF_SYSIO_CTRL_REG); 7260Sstevel@tonic-gate softsp->sbus_ctrl_reg = REG_ADDR(address, OFF_SBUS_CTRL_REG); 7270Sstevel@tonic-gate softsp->sbus_slot_config_reg = REG_ADDR(address, OFF_SBUS_SLOT_CONFIG); 7280Sstevel@tonic-gate softsp->intr_mapping_reg = REG_ADDR(address, OFF_INTR_MAPPING_REG); 7290Sstevel@tonic-gate softsp->clr_intr_reg = REG_ADDR(address, OFF_CLR_INTR_REG); 7300Sstevel@tonic-gate softsp->intr_retry_reg = REG_ADDR(address, OFF_INTR_RETRY_REG); 7310Sstevel@tonic-gate softsp->sbus_intr_state = REG_ADDR(address, OFF_SBUS_INTR_STATE_REG); 7320Sstevel@tonic-gate softsp->sbus_pcr = REG_ADDR(address, OFF_SBUS_PCR); 7330Sstevel@tonic-gate softsp->sbus_pic = REG_ADDR(address, OFF_SBUS_PIC); 7340Sstevel@tonic-gate 7350Sstevel@tonic-gate #undef REG_ADDR 7360Sstevel@tonic-gate 737*1035Smike_s DPRINTF(SBUS_REGISTERS_DEBUG, ("SYSIO Control reg: 0x%p\n" 738*1035Smike_s "SBUS Control reg: 0x%p", softsp->sysio_ctrl_reg, 7390Sstevel@tonic-gate softsp->sbus_ctrl_reg)); 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate #ifdef _STARFIRE 7420Sstevel@tonic-gate /* Setup interrupt target translation for starfire */ 7430Sstevel@tonic-gate pc_ittrans_init(softsp->upa_id, &softsp->ittrans_cookie); 7440Sstevel@tonic-gate #endif /* _STARFIRE */ 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate softsp->intr_mapping_ign = 7470Sstevel@tonic-gate UPAID_TO_IGN(softsp->upa_id) << IMR_IGN_SHIFT; 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate /* Diag reg 2 is the next 64 bit word after diag reg 1 */ 7500Sstevel@tonic-gate softsp->obio_intr_state = softsp->sbus_intr_state + 1; 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate (void) sbus_resume_init(softsp, 0); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate /* 7550Sstevel@tonic-gate * Set the initial burstsizes for each slot to all 1's. This will 7560Sstevel@tonic-gate * get changed at initchild time. 7570Sstevel@tonic-gate */ 7580Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) 7590Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] = 0xffffffffu; 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate /* 7620Sstevel@tonic-gate * Since SYSIO is used as an interrupt mastering device for slave 7630Sstevel@tonic-gate * only UPA devices, we call a dedicated kernel function to register 7640Sstevel@tonic-gate * The address of the interrupt mapping register for the slave device. 7650Sstevel@tonic-gate * 7660Sstevel@tonic-gate * If RISC/sysio is wired to support 2 upa slave interrupt 7670Sstevel@tonic-gate * devices then register 2nd mapping register with system. 7680Sstevel@tonic-gate * The slave/proxy portid algorithm (decribed in Fusion Desktop Spec) 7690Sstevel@tonic-gate * allows for upto 3 slaves per proxy but Psycho/SYSIO only support 2. 7700Sstevel@tonic-gate * 7710Sstevel@tonic-gate * #upa-interrupt-proxies property defines how many UPA interrupt 7720Sstevel@tonic-gate * slaves a bridge is wired to support. Older systems that lack 7730Sstevel@tonic-gate * this property will default to 1. 7740Sstevel@tonic-gate */ 7750Sstevel@tonic-gate numproxy = ddi_prop_get_int(DDI_DEV_T_ANY, softsp->dip, 7760Sstevel@tonic-gate DDI_PROP_DONTPASS, "#upa-interrupt-proxies", 1); 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate if (numproxy > 0) 7790Sstevel@tonic-gate set_intr_mapping_reg(softsp->upa_id, 7800Sstevel@tonic-gate (uint64_t *)(softsp->intr_mapping_reg + 7810Sstevel@tonic-gate FFB_MAPPING_REG), 1); 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate if (numproxy > 1) 7840Sstevel@tonic-gate set_intr_mapping_reg(softsp->upa_id, 7850Sstevel@tonic-gate (uint64_t *)(softsp->intr_mapping_reg + 7860Sstevel@tonic-gate EXP_MAPPING_REG), 2); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate /* support for a 3 interrupt proxy would go here */ 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* Turn on spurious interrupt counter if we're not a DEBUG kernel. */ 7910Sstevel@tonic-gate #ifndef DEBUG 7920Sstevel@tonic-gate intr_cntr_on = 1; 7930Sstevel@tonic-gate #else 7940Sstevel@tonic-gate intr_cntr_on = 0; 7950Sstevel@tonic-gate #endif 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate return (DDI_SUCCESS); 7990Sstevel@tonic-gate } 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate /* 8020Sstevel@tonic-gate * This procedure is part of sbus initialization. It is called by 8030Sstevel@tonic-gate * sbus_init() and is invoked when the system is being resumed. 8040Sstevel@tonic-gate */ 8050Sstevel@tonic-gate static int 8060Sstevel@tonic-gate sbus_resume_init(struct sbus_soft_state *softsp, int resume) 8070Sstevel@tonic-gate { 8080Sstevel@tonic-gate int i; 8090Sstevel@tonic-gate uint_t sbus_burst_sizes; 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate /* 8120Sstevel@tonic-gate * This shouldn't be needed when we have a real OBP PROM. 8130Sstevel@tonic-gate * (RAZ) Get rid of this later!!! 8140Sstevel@tonic-gate */ 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate #ifdef _STARFIRE 8170Sstevel@tonic-gate /* 8180Sstevel@tonic-gate * For Starfire, we need to program a 8190Sstevel@tonic-gate * constant odd value. 8200Sstevel@tonic-gate * Zero out the MID field before ORing 8210Sstevel@tonic-gate * We leave the LSB of the MID field intact since 8220Sstevel@tonic-gate * we cannot have a zero(even) MID value 8230Sstevel@tonic-gate */ 8240Sstevel@tonic-gate uint64_t tmpconst = 0x1DULL; 8250Sstevel@tonic-gate *softsp->sysio_ctrl_reg &= 0xFF0FFFFFFFFFFFFFULL; 8260Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= tmpconst << 51; 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate /* 8290Sstevel@tonic-gate * Program in the interrupt group number 8300Sstevel@tonic-gate * Here we have to convert the starfire 8310Sstevel@tonic-gate * 7 bit upaid into a 5bit value. 8320Sstevel@tonic-gate */ 8330Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= 8340Sstevel@tonic-gate (uint64_t)STARFIRE_UPAID2HWIGN(softsp->upa_id) 8350Sstevel@tonic-gate << SYSIO_IGN; 8360Sstevel@tonic-gate #else 8370Sstevel@tonic-gate /* for the rest of sun4u's */ 8380Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= 8390Sstevel@tonic-gate (uint64_t)softsp->upa_id << 51; 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate /* Program in the interrupt group number */ 8420Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= 8430Sstevel@tonic-gate (uint64_t)softsp->upa_id << SYSIO_IGN; 8440Sstevel@tonic-gate #endif /* _STARFIRE */ 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate /* 8470Sstevel@tonic-gate * Set appropriate fields of sbus control register. 8480Sstevel@tonic-gate * Set DVMA arbitration enable for all devices. 8490Sstevel@tonic-gate */ 8500Sstevel@tonic-gate *softsp->sbus_ctrl_reg |= SBUS_ARBIT_ALL; 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate /* Calculate our burstsizes now so we don't have to do it later */ 8530Sstevel@tonic-gate sbus_burst_sizes = (SYSIO64_BURST_RANGE << SYSIO64_BURST_SHIFT) 8540Sstevel@tonic-gate | SYSIO_BURST_RANGE; 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate sbus_burst_sizes = ddi_getprop(DDI_DEV_T_ANY, softsp->dip, 8570Sstevel@tonic-gate DDI_PROP_DONTPASS, "up-burst-sizes", sbus_burst_sizes); 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate softsp->sbus_burst_sizes = sbus_burst_sizes & SYSIO_BURST_MASK; 8600Sstevel@tonic-gate softsp->sbus64_burst_sizes = sbus_burst_sizes & SYSIO64_BURST_MASK; 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate if (!resume) { 8630Sstevel@tonic-gate /* Set burstsizes to smallest value */ 8640Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) { 8650Sstevel@tonic-gate volatile uint64_t *config; 8660Sstevel@tonic-gate uint64_t tmpreg; 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate config = softsp->sbus_slot_config_reg + i; 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate /* Write out the burst size */ 8710Sstevel@tonic-gate tmpreg = (uint64_t)0; 8720Sstevel@tonic-gate *config = tmpreg; 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate /* Flush any write buffers */ 8750Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate DPRINTF(SBUS_REGISTERS_DEBUG, ("Sbus slot 0x%x slot " 878*1035Smike_s "configuration reg: 0x%p", (i > 3) ? i + 9 : i, 8790Sstevel@tonic-gate config)); 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate } else { 8820Sstevel@tonic-gate /* Program the slot configuration registers */ 8830Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) { 8840Sstevel@tonic-gate volatile uint64_t *config; 8850Sstevel@tonic-gate #ifndef lint 8860Sstevel@tonic-gate uint64_t tmpreg; 8870Sstevel@tonic-gate #endif /* !lint */ 8880Sstevel@tonic-gate uint_t slave_burstsizes; 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate slave_burstsizes = 0; 8910Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[i] != 0xffffffffu) { 8920Sstevel@tonic-gate config = softsp->sbus_slot_config_reg + i; 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[i] & 8950Sstevel@tonic-gate SYSIO64_BURST_MASK) { 8960Sstevel@tonic-gate /* get the 64 bit burstsizes */ 8970Sstevel@tonic-gate slave_burstsizes = 8980Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] >> 8990Sstevel@tonic-gate SYSIO64_BURST_SHIFT; 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate /* Turn on 64 bit PIO's on the sbus */ 9020Sstevel@tonic-gate *config |= SBUS_ETM; 9030Sstevel@tonic-gate } else { 9040Sstevel@tonic-gate slave_burstsizes = 9050Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] & 9060Sstevel@tonic-gate SYSIO_BURST_MASK; 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate /* Get burstsizes into sysio register format */ 9100Sstevel@tonic-gate slave_burstsizes >>= SYSIO_SLAVEBURST_REGSHIFT; 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate /* Program the burstsizes */ 9130Sstevel@tonic-gate *config |= (uint64_t)slave_burstsizes; 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate /* Flush any write buffers */ 9160Sstevel@tonic-gate #ifndef lint 9170Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 9180Sstevel@tonic-gate #endif /* !lint */ 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate } 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate return (DDI_SUCCESS); 9240Sstevel@tonic-gate } 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate #define get_prop(di, pname, flag, pval, plen) \ 9270Sstevel@tonic-gate (ddi_prop_op(DDI_DEV_T_NONE, di, PROP_LEN_AND_VAL_ALLOC, \ 9280Sstevel@tonic-gate flag | DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, \ 9290Sstevel@tonic-gate pname, (caddr_t)pval, plen)) 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate struct prop_ispec { 9320Sstevel@tonic-gate uint_t pri, vec; 9330Sstevel@tonic-gate }; 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate /* 9360Sstevel@tonic-gate * Create a sysio_parent_private_data structure from the ddi properties of 9370Sstevel@tonic-gate * the dev_info node. 9380Sstevel@tonic-gate * 9390Sstevel@tonic-gate * The "reg" and either an "intr" or "interrupts" properties are required 9400Sstevel@tonic-gate * if the driver wishes to create mappings or field interrupts on behalf 9410Sstevel@tonic-gate * of the device. 9420Sstevel@tonic-gate * 9430Sstevel@tonic-gate * The "reg" property is assumed to be a list of at least one triple 9440Sstevel@tonic-gate * 9450Sstevel@tonic-gate * <bustype, address, size>*1 9460Sstevel@tonic-gate * 9470Sstevel@tonic-gate * On pre-fusion machines, the "intr" property was the IPL for the system. 9480Sstevel@tonic-gate * Most new sbus devices post an "interrupts" property that corresponds to 9490Sstevel@tonic-gate * a particular bus level. All devices on fusion using an "intr" property 9500Sstevel@tonic-gate * will have it's contents translated into a bus level. Hence, "intr" and 9510Sstevel@tonic-gate * "interrupts on the fusion platform can be treated the same. 9520Sstevel@tonic-gate * 9530Sstevel@tonic-gate * The "interrupts" property is assumed to be a list of at least one 9540Sstevel@tonic-gate * n-tuples that describes the interrupt capabilities of the bus the device 9550Sstevel@tonic-gate * is connected to. For SBus, this looks like 9560Sstevel@tonic-gate * 9570Sstevel@tonic-gate * <SBus-level>*1 9580Sstevel@tonic-gate * 9590Sstevel@tonic-gate * (This property obsoletes the 'intr' property). 9600Sstevel@tonic-gate * 9610Sstevel@tonic-gate * The OBP_RANGES property is optional. 9620Sstevel@tonic-gate */ 9630Sstevel@tonic-gate static void 9640Sstevel@tonic-gate make_sbus_ppd(dev_info_t *child) 9650Sstevel@tonic-gate { 9660Sstevel@tonic-gate struct sysio_parent_private_data *pdptr; 9670Sstevel@tonic-gate int n; 9680Sstevel@tonic-gate int *reg_prop, *rgstr_prop, *rng_prop; 9690Sstevel@tonic-gate int reg_len, rgstr_len, rng_len; 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate /* 9720Sstevel@tonic-gate * Make the function idempotent, because name_child could 9730Sstevel@tonic-gate * be called multiple times on a node. 9740Sstevel@tonic-gate */ 9750Sstevel@tonic-gate if (ddi_get_parent_data(child) != NULL) 9760Sstevel@tonic-gate return; 9770Sstevel@tonic-gate 9780Sstevel@tonic-gate pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 9790Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate /* 9820Sstevel@tonic-gate * Handle the 'reg'/'registers' properties. 9830Sstevel@tonic-gate * "registers" overrides "reg", but requires that "reg" be exported, 9840Sstevel@tonic-gate * so we can handle wildcard specifiers. "registers" implies an 9850Sstevel@tonic-gate * sbus style device. "registers" implies that we insert the 9860Sstevel@tonic-gate * correct value in the regspec_bustype field of each spec for a real 9870Sstevel@tonic-gate * (non-pseudo) device node. "registers" is a s/w only property, so 9880Sstevel@tonic-gate * we inhibit the prom search for this property. 9890Sstevel@tonic-gate */ 9900Sstevel@tonic-gate if (get_prop(child, OBP_REG, 0, ®_prop, ®_len) != DDI_SUCCESS) 9910Sstevel@tonic-gate reg_len = 0; 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate /* 9940Sstevel@tonic-gate * Save the underlying slot number and slot offset. 9950Sstevel@tonic-gate * Among other things, we use these to name the child node. 9960Sstevel@tonic-gate */ 9970Sstevel@tonic-gate pdptr->slot = (uint_t)-1; 9980Sstevel@tonic-gate if (reg_len != 0) { 9990Sstevel@tonic-gate pdptr->slot = ((struct regspec *)reg_prop)->regspec_bustype; 10000Sstevel@tonic-gate pdptr->offset = ((struct regspec *)reg_prop)->regspec_addr; 10010Sstevel@tonic-gate } 10020Sstevel@tonic-gate 10030Sstevel@tonic-gate rgstr_len = 0; 10040Sstevel@tonic-gate (void) get_prop(child, "registers", DDI_PROP_NOTPROM, 10050Sstevel@tonic-gate &rgstr_prop, &rgstr_len); 10060Sstevel@tonic-gate 10070Sstevel@tonic-gate if (rgstr_len != 0) { 10080Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) && (reg_len != 0)) { 10090Sstevel@tonic-gate /* 10100Sstevel@tonic-gate * Convert wildcard "registers" for a real node... 10110Sstevel@tonic-gate * (Else, this is the wildcard prototype node) 10120Sstevel@tonic-gate */ 10130Sstevel@tonic-gate struct regspec *rp = (struct regspec *)reg_prop; 10140Sstevel@tonic-gate uint_t slot = rp->regspec_bustype; 10150Sstevel@tonic-gate int i; 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate rp = (struct regspec *)rgstr_prop; 10180Sstevel@tonic-gate n = rgstr_len / sizeof (struct regspec); 10190Sstevel@tonic-gate for (i = 0; i < n; ++i, ++rp) 10200Sstevel@tonic-gate rp->regspec_bustype = slot; 10210Sstevel@tonic-gate } 10220Sstevel@tonic-gate 10230Sstevel@tonic-gate if (reg_len != 0) 10240Sstevel@tonic-gate kmem_free(reg_prop, reg_len); 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate reg_prop = rgstr_prop; 10270Sstevel@tonic-gate reg_len = rgstr_len; 10280Sstevel@tonic-gate } 10290Sstevel@tonic-gate if (reg_len != 0) { 10300Sstevel@tonic-gate pdptr->par_nreg = reg_len / (int)sizeof (struct regspec); 10310Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop; 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate /* 10350Sstevel@tonic-gate * See if I have ranges. 10360Sstevel@tonic-gate */ 10370Sstevel@tonic-gate if (get_prop(child, OBP_RANGES, 0, &rng_prop, &rng_len) == 10380Sstevel@tonic-gate DDI_SUCCESS) { 10390Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 10400Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop; 10410Sstevel@tonic-gate } 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate 10440Sstevel@tonic-gate /* 10450Sstevel@tonic-gate * Special handling for "sbusmem" pseudo device nodes. 10460Sstevel@tonic-gate * The special handling automatically creates the "reg" 10470Sstevel@tonic-gate * property in the sbusmem nodes, based on the parent's 10480Sstevel@tonic-gate * property so that each slot will automtically have a 10490Sstevel@tonic-gate * correctly sized "reg" property, once created, 10500Sstevel@tonic-gate * sbus_initchild does the rest of the work to init 10510Sstevel@tonic-gate * the child node. 10520Sstevel@tonic-gate */ 10530Sstevel@tonic-gate static int 10540Sstevel@tonic-gate sbusmem_initchild(dev_info_t *dip, dev_info_t *child) 10550Sstevel@tonic-gate { 10560Sstevel@tonic-gate int i, n; 10570Sstevel@tonic-gate int slot, size; 10580Sstevel@tonic-gate char ident[10]; 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate slot = ddi_getprop(DDI_DEV_T_NONE, child, 10610Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "slot", -1); 10620Sstevel@tonic-gate if (slot == -1) { 10630Sstevel@tonic-gate DPRINTF(SBUS_SBUSMEM_DEBUG, ("can't get slot property\n")); 10640Sstevel@tonic-gate return (DDI_FAILURE); 10650Sstevel@tonic-gate } 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate /* 10680Sstevel@tonic-gate * Find the parent range corresponding to this "slot", 10690Sstevel@tonic-gate * so we can set the size of the child's "reg" property. 10700Sstevel@tonic-gate */ 10710Sstevel@tonic-gate for (i = 0, n = sparc_pd_getnrng(dip); i < n; i++) { 10720Sstevel@tonic-gate struct rangespec *rp = sparc_pd_getrng(dip, i); 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate if (rp->rng_cbustype == (uint_t)slot) { 10750Sstevel@tonic-gate struct regspec r; 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate /* create reg property */ 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate r.regspec_bustype = (uint_t)slot; 10800Sstevel@tonic-gate r.regspec_addr = 0; 10810Sstevel@tonic-gate r.regspec_size = rp->rng_size; 10820Sstevel@tonic-gate (void) ddi_prop_update_int_array(DDI_DEV_T_NONE, 10830Sstevel@tonic-gate child, "reg", (int *)&r, 10840Sstevel@tonic-gate sizeof (struct regspec) / sizeof (int)); 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate /* create size property for slot */ 10870Sstevel@tonic-gate 10880Sstevel@tonic-gate size = rp->rng_size; 10890Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE, 10900Sstevel@tonic-gate child, "size", size); 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate (void) sprintf(ident, "slot%x", slot); 10930Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE, 10940Sstevel@tonic-gate child, "ident", ident); 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate return (DDI_SUCCESS); 10970Sstevel@tonic-gate } 10980Sstevel@tonic-gate } 10990Sstevel@tonic-gate return (DDI_FAILURE); 11000Sstevel@tonic-gate } 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate /* 11030Sstevel@tonic-gate * Nexus routine to name a child. 11040Sstevel@tonic-gate * It takes a dev_info node and a buffer, returns the name 11050Sstevel@tonic-gate * in the buffer. 11060Sstevel@tonic-gate */ 11070Sstevel@tonic-gate static int 11080Sstevel@tonic-gate sysio_name_child(dev_info_t *child, char *name, int namelen) 11090Sstevel@tonic-gate { 11100Sstevel@tonic-gate /* 11110Sstevel@tonic-gate * Fill in parent-private data 11120Sstevel@tonic-gate */ 11130Sstevel@tonic-gate make_sbus_ppd(child); 11140Sstevel@tonic-gate 11150Sstevel@tonic-gate /* 11160Sstevel@tonic-gate * Name the device node using the underlying (prom) values 11170Sstevel@tonic-gate * of the first entry in the "reg" property. For SBus devices, 11180Sstevel@tonic-gate * the textual form of the name is <name>@<slot#>,<offset>. 11190Sstevel@tonic-gate * This must match the prom's pathname or mountroot, etc, won't 11200Sstevel@tonic-gate */ 11210Sstevel@tonic-gate name[0] = '\0'; 11220Sstevel@tonic-gate if (sysio_pd_getslot(child) != (uint_t)-1) { 11230Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 11240Sstevel@tonic-gate sysio_pd_getslot(child), sysio_pd_getoffset(child)); 11250Sstevel@tonic-gate } 11260Sstevel@tonic-gate return (DDI_SUCCESS); 11270Sstevel@tonic-gate } 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate /* 11300Sstevel@tonic-gate * Called from the bus_ctl op of sysio sbus nexus driver 11310Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names 11320Sstevel@tonic-gate * the children of sysio sbusses based on the reg spec. 11330Sstevel@tonic-gate * 11340Sstevel@tonic-gate * Handles the following properties: 11350Sstevel@tonic-gate * 11360Sstevel@tonic-gate * Property value 11370Sstevel@tonic-gate * Name type 11380Sstevel@tonic-gate * 11390Sstevel@tonic-gate * reg register spec 11400Sstevel@tonic-gate * registers wildcard s/w sbus register spec (.conf file property) 11410Sstevel@tonic-gate * intr old-form interrupt spec 11420Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec 11430Sstevel@tonic-gate * ranges range spec 11440Sstevel@tonic-gate */ 11450Sstevel@tonic-gate static int 11460Sstevel@tonic-gate sbus_initchild(dev_info_t *dip, dev_info_t *child) 11470Sstevel@tonic-gate { 11480Sstevel@tonic-gate char name[MAXNAMELEN]; 11490Sstevel@tonic-gate ulong_t slave_burstsizes; 11500Sstevel@tonic-gate int slot; 11510Sstevel@tonic-gate volatile uint64_t *slot_reg; 11520Sstevel@tonic-gate #ifndef lint 11530Sstevel@tonic-gate uint64_t tmp; 11540Sstevel@tonic-gate #endif /* !lint */ 11550Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 11560Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate if (strcmp(ddi_get_name(child), "sbusmem") == 0) { 11590Sstevel@tonic-gate if (sbusmem_initchild(dip, child) != DDI_SUCCESS) 11600Sstevel@tonic-gate return (DDI_FAILURE); 11610Sstevel@tonic-gate } 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate /* 11640Sstevel@tonic-gate * If this is a s/w node defined with the "registers" property, 11650Sstevel@tonic-gate * this means that this is a wildcard specifier, whose properties 11660Sstevel@tonic-gate * get applied to all previously defined h/w nodes with the same 11670Sstevel@tonic-gate * name and same parent. 11680Sstevel@tonic-gate */ 11690Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 11700Sstevel@tonic-gate int len = 0; 11710Sstevel@tonic-gate if ((ddi_getproplen(DDI_DEV_T_ANY, child, DDI_PROP_NOTPROM, 11720Sstevel@tonic-gate "registers", &len) == DDI_SUCCESS) && (len != 0)) { 11730Sstevel@tonic-gate ndi_merge_wildcard_node(child); 11740Sstevel@tonic-gate return (DDI_FAILURE); 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate /* name the child */ 11790Sstevel@tonic-gate (void) sysio_name_child(child, name, MAXNAMELEN); 11800Sstevel@tonic-gate ddi_set_name_addr(child, name); 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate /* 11830Sstevel@tonic-gate * If a pseudo node, attempt to merge it into a hw node. 11840Sstevel@tonic-gate * If merge is successful, we uinitialize the node and 11850Sstevel@tonic-gate * return failure, to allow caller to remove the node. 11860Sstevel@tonic-gate * The merge fails, this is a real pseudo node. Allow 11870Sstevel@tonic-gate * initchild to continue. 11880Sstevel@tonic-gate */ 11890Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && 11900Sstevel@tonic-gate (ndi_merge_node(child, sysio_name_child) == DDI_SUCCESS)) { 11910Sstevel@tonic-gate (void) sbus_uninitchild(child); 11920Sstevel@tonic-gate return (DDI_FAILURE); 11930Sstevel@tonic-gate } 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate /* Figure out the child devices slot number */ 11960Sstevel@tonic-gate slot = sysio_pd_getslot(child); 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate /* If we don't have a reg property, bypass slot specific programming */ 11990Sstevel@tonic-gate if (slot < 0 || slot >= MAX_SBUS_SLOT_ADDR) { 12000Sstevel@tonic-gate #ifdef DEBUG 12010Sstevel@tonic-gate cmn_err(CE_WARN, "?Invalid sbus slot address 0x%x for %s " 12020Sstevel@tonic-gate "device\n", slot, ddi_get_name(child)); 12030Sstevel@tonic-gate #endif /* DEBUG */ 12040Sstevel@tonic-gate goto done; 12050Sstevel@tonic-gate } 12060Sstevel@tonic-gate 12070Sstevel@tonic-gate /* Modify the onboard slot numbers if applicable. */ 12080Sstevel@tonic-gate slot = (slot > 3) ? slot - 9 : slot; 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate /* Get the slot configuration register for the child device. */ 12110Sstevel@tonic-gate slot_reg = softsp->sbus_slot_config_reg + slot; 12120Sstevel@tonic-gate 12130Sstevel@tonic-gate /* 12140Sstevel@tonic-gate * Program the devices slot configuration register for the 12150Sstevel@tonic-gate * appropriate slave burstsizes. 12160Sstevel@tonic-gate * The upper 16 bits of the slave-burst-sizes are for 64 bit sbus 12170Sstevel@tonic-gate * and the lower 16 bits are the burst sizes for 32 bit sbus. If 12180Sstevel@tonic-gate * we see that a device supports both 64 bit and 32 bit slave accesses, 12190Sstevel@tonic-gate * we default to 64 bit and turn it on in the slot config reg. 12200Sstevel@tonic-gate * 12210Sstevel@tonic-gate * For older devices, make sure we check the "burst-sizes" property 12220Sstevel@tonic-gate * too. 12230Sstevel@tonic-gate */ 12240Sstevel@tonic-gate if ((slave_burstsizes = (ulong_t)ddi_getprop(DDI_DEV_T_ANY, child, 12250Sstevel@tonic-gate DDI_PROP_DONTPASS, "slave-burst-sizes", 0)) != 0 || 12260Sstevel@tonic-gate (slave_burstsizes = (ulong_t)ddi_getprop(DDI_DEV_T_ANY, child, 12270Sstevel@tonic-gate DDI_PROP_DONTPASS, "burst-sizes", 0)) != 0) { 12280Sstevel@tonic-gate uint_t burstsizes = 0; 12290Sstevel@tonic-gate 12300Sstevel@tonic-gate /* 12310Sstevel@tonic-gate * If we only have 32 bit burst sizes from a previous device, 12320Sstevel@tonic-gate * mask out any burstsizes for 64 bit mode. 12330Sstevel@tonic-gate */ 12340Sstevel@tonic-gate if (((softsp->sbus_slave_burstsizes[slot] & 12350Sstevel@tonic-gate 0xffff0000u) == 0) && 12360Sstevel@tonic-gate ((softsp->sbus_slave_burstsizes[slot] & 0xffff) != 0)) { 12370Sstevel@tonic-gate slave_burstsizes &= 0xffff; 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate 12400Sstevel@tonic-gate /* 12410Sstevel@tonic-gate * If "slave-burst-sizes was defined but we have 0 at this 12420Sstevel@tonic-gate * point, we must have had 64 bit burstsizes, however a prior 12430Sstevel@tonic-gate * device can only burst in 32 bit mode. Therefore, we leave 12440Sstevel@tonic-gate * the burstsizes in the 32 bit mode and disregard the 64 bit. 12450Sstevel@tonic-gate */ 12460Sstevel@tonic-gate if (slave_burstsizes == 0) 12470Sstevel@tonic-gate goto done; 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate /* 12500Sstevel@tonic-gate * We and in the new burst sizes with that of prior devices. 12510Sstevel@tonic-gate * This ensures that we always take the least common 12520Sstevel@tonic-gate * denominator of the burst sizes. 12530Sstevel@tonic-gate */ 12540Sstevel@tonic-gate softsp->sbus_slave_burstsizes[slot] &= 12550Sstevel@tonic-gate (slave_burstsizes & 12560Sstevel@tonic-gate ((SYSIO64_SLAVEBURST_RANGE << 12570Sstevel@tonic-gate SYSIO64_BURST_SHIFT) | 12580Sstevel@tonic-gate SYSIO_SLAVEBURST_RANGE)); 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate /* Get the 64 bit burstsizes. */ 12610Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[slot] & 12620Sstevel@tonic-gate SYSIO64_BURST_MASK) { 12630Sstevel@tonic-gate /* get the 64 bit burstsizes */ 12640Sstevel@tonic-gate burstsizes = softsp->sbus_slave_burstsizes[slot] >> 12650Sstevel@tonic-gate SYSIO64_BURST_SHIFT; 12660Sstevel@tonic-gate 12670Sstevel@tonic-gate /* Turn on 64 bit PIO's on the sbus */ 12680Sstevel@tonic-gate *slot_reg |= SBUS_ETM; 12690Sstevel@tonic-gate } else { 12700Sstevel@tonic-gate /* Turn off 64 bit PIO's on the sbus */ 12710Sstevel@tonic-gate *slot_reg &= ~SBUS_ETM; 12720Sstevel@tonic-gate 12730Sstevel@tonic-gate /* Get the 32 bit burstsizes if we don't have 64 bit. */ 12740Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[slot] & 12750Sstevel@tonic-gate SYSIO_BURST_MASK) { 12760Sstevel@tonic-gate burstsizes = 12770Sstevel@tonic-gate softsp->sbus_slave_burstsizes[slot] & 12780Sstevel@tonic-gate SYSIO_BURST_MASK; 12790Sstevel@tonic-gate } 12800Sstevel@tonic-gate } 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate /* Get the burstsizes into sysio register format */ 12830Sstevel@tonic-gate burstsizes >>= SYSIO_SLAVEBURST_REGSHIFT; 12840Sstevel@tonic-gate 12850Sstevel@tonic-gate /* Reset reg in case we're scaling back */ 12860Sstevel@tonic-gate *slot_reg &= (uint64_t)~SYSIO_SLAVEBURST_MASK; 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate /* Program the burstsizes */ 12890Sstevel@tonic-gate *slot_reg |= (uint64_t)burstsizes; 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate /* Flush system load/store buffers */ 12920Sstevel@tonic-gate #ifndef lint 12930Sstevel@tonic-gate tmp = *slot_reg; 12940Sstevel@tonic-gate #endif /* !lint */ 12950Sstevel@tonic-gate } 12960Sstevel@tonic-gate 12970Sstevel@tonic-gate done: 12980Sstevel@tonic-gate return (DDI_SUCCESS); 12990Sstevel@tonic-gate } 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate static int 13020Sstevel@tonic-gate sbus_uninitchild(dev_info_t *dip) 13030Sstevel@tonic-gate { 13040Sstevel@tonic-gate struct sysio_parent_private_data *pdptr; 13050Sstevel@tonic-gate size_t n; 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) != NULL) { 13080Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nrng) != 0) 13090Sstevel@tonic-gate kmem_free(pdptr->par_rng, n * 13100Sstevel@tonic-gate sizeof (struct rangespec)); 13110Sstevel@tonic-gate 13120Sstevel@tonic-gate if ((n = pdptr->par_nreg) != 0) 13130Sstevel@tonic-gate kmem_free(pdptr->par_reg, n * sizeof (struct regspec)); 13140Sstevel@tonic-gate 13150Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr)); 13160Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 13190Sstevel@tonic-gate /* 13200Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 13210Sstevel@tonic-gate */ 13220Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 13230Sstevel@tonic-gate impl_rem_dev_props(dip); 13240Sstevel@tonic-gate return (DDI_SUCCESS); 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate #ifdef DEBUG 13280Sstevel@tonic-gate int sbus_peekfault_cnt = 0; 13290Sstevel@tonic-gate int sbus_pokefault_cnt = 0; 13300Sstevel@tonic-gate #endif /* DEBUG */ 13310Sstevel@tonic-gate 13320Sstevel@tonic-gate static int 13330Sstevel@tonic-gate sbus_ctlops_poke(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args) 13340Sstevel@tonic-gate { 13350Sstevel@tonic-gate int err = DDI_SUCCESS; 13360Sstevel@tonic-gate on_trap_data_t otd; 13370Sstevel@tonic-gate volatile uint64_t tmpreg; 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate /* Cautious access not supported. */ 13400Sstevel@tonic-gate if (in_args->handle != NULL) 13410Sstevel@tonic-gate return (DDI_FAILURE); 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate mutex_enter(&softsp->pokefault_mutex); 13440Sstevel@tonic-gate softsp->ontrap_data = &otd; 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate /* Set up protected environment. */ 13470Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 13480Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 13490Sstevel@tonic-gate 13500Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault; 13510Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr, 13520Sstevel@tonic-gate (void *)in_args->host_addr); 13530Sstevel@tonic-gate otd.ot_trampoline = tramp; 13540Sstevel@tonic-gate } else 13550Sstevel@tonic-gate err = DDI_FAILURE; 13560Sstevel@tonic-gate 13570Sstevel@tonic-gate /* Flush any sbus store buffers. */ 13580Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 13590Sstevel@tonic-gate 13600Sstevel@tonic-gate /* 13610Sstevel@tonic-gate * Read the sbus error reg and see if a fault occured. If 13620Sstevel@tonic-gate * one has, give the SYSIO time to packetize the interrupt 13630Sstevel@tonic-gate * for the fault and send it out. The sbus error handler will 13640Sstevel@tonic-gate * 0 these fields when it's called to service the fault. 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate tmpreg = *softsp->sbus_err_reg; 13670Sstevel@tonic-gate while (tmpreg & SB_AFSR_P_TO || tmpreg & SB_AFSR_P_BERR) 13680Sstevel@tonic-gate tmpreg = *softsp->sbus_err_reg; 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate /* Take down protected environment. */ 13710Sstevel@tonic-gate no_trap(); 13720Sstevel@tonic-gate 13730Sstevel@tonic-gate softsp->ontrap_data = NULL; 13740Sstevel@tonic-gate mutex_exit(&softsp->pokefault_mutex); 13750Sstevel@tonic-gate 13760Sstevel@tonic-gate #ifdef DEBUG 13770Sstevel@tonic-gate if (err == DDI_FAILURE) 13780Sstevel@tonic-gate sbus_pokefault_cnt++; 13790Sstevel@tonic-gate #endif 13800Sstevel@tonic-gate return (err); 13810Sstevel@tonic-gate } 13820Sstevel@tonic-gate 13830Sstevel@tonic-gate /*ARGSUSED*/ 13840Sstevel@tonic-gate static int 13850Sstevel@tonic-gate sbus_ctlops_peek(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args, 13860Sstevel@tonic-gate void *result) 13870Sstevel@tonic-gate { 13880Sstevel@tonic-gate int err = DDI_SUCCESS; 13890Sstevel@tonic-gate on_trap_data_t otd; 13900Sstevel@tonic-gate 13910Sstevel@tonic-gate /* No safe access except for peek is supported. */ 13920Sstevel@tonic-gate if (in_args->handle != NULL) 13930Sstevel@tonic-gate return (DDI_FAILURE); 13940Sstevel@tonic-gate 13950Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 13960Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault; 13990Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr, 14000Sstevel@tonic-gate (void *)in_args->host_addr); 14010Sstevel@tonic-gate otd.ot_trampoline = tramp; 14020Sstevel@tonic-gate result = (void *)in_args->host_addr; 14030Sstevel@tonic-gate } else 14040Sstevel@tonic-gate err = DDI_FAILURE; 14050Sstevel@tonic-gate 14060Sstevel@tonic-gate #ifdef DEBUG 14070Sstevel@tonic-gate if (err == DDI_FAILURE) 14080Sstevel@tonic-gate sbus_peekfault_cnt++; 14090Sstevel@tonic-gate #endif 14100Sstevel@tonic-gate no_trap(); 14110Sstevel@tonic-gate return (err); 14120Sstevel@tonic-gate } 14130Sstevel@tonic-gate 14140Sstevel@tonic-gate static int 14150Sstevel@tonic-gate sbus_ctlops(dev_info_t *dip, dev_info_t *rdip, 14160Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result) 14170Sstevel@tonic-gate { 14180Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 14190Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 14200Sstevel@tonic-gate 14210Sstevel@tonic-gate switch (op) { 14220Sstevel@tonic-gate 14230Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 14240Sstevel@tonic-gate return (sbus_initchild(dip, (dev_info_t *)arg)); 14250Sstevel@tonic-gate 14260Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 14270Sstevel@tonic-gate return (sbus_uninitchild(arg)); 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: { 14300Sstevel@tonic-gate int val = *((int *)result); 14310Sstevel@tonic-gate 14320Sstevel@tonic-gate /* 14330Sstevel@tonic-gate * The 'arg' value of nonzero indicates 'streaming' mode. 14340Sstevel@tonic-gate * If in streaming mode, pick the largest of our burstsizes 14350Sstevel@tonic-gate * available and say that that is our minimum value (modulo 14360Sstevel@tonic-gate * what mincycle is). 14370Sstevel@tonic-gate */ 1438*1035Smike_s if ((int)(uintptr_t)arg) 14390Sstevel@tonic-gate val = maxbit(val, 14400Sstevel@tonic-gate (1 << (ddi_fls(softsp->sbus_burst_sizes) - 1))); 14410Sstevel@tonic-gate else 14420Sstevel@tonic-gate val = maxbit(val, 14430Sstevel@tonic-gate (1 << (ddi_ffs(softsp->sbus_burst_sizes) - 1))); 14440Sstevel@tonic-gate 14450Sstevel@tonic-gate *((int *)result) = val; 14460Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: { 14500Sstevel@tonic-gate dev_info_t *pdev; 14510Sstevel@tonic-gate int i, n, len, f_len; 14520Sstevel@tonic-gate char *msgbuf; 14530Sstevel@tonic-gate 14540Sstevel@tonic-gate /* 14550Sstevel@tonic-gate * So we can do one atomic cmn_err call, we allocate a 4k 14560Sstevel@tonic-gate * buffer, and format the reportdev message into that buffer, 14570Sstevel@tonic-gate * send it to cmn_err, and then free the allocated buffer. 14580Sstevel@tonic-gate * If message is longer than 1k, the message is truncated and 14590Sstevel@tonic-gate * an error message is emitted (debug kernel only). 14600Sstevel@tonic-gate */ 14610Sstevel@tonic-gate #define REPORTDEV_BUFSIZE 1024 14620Sstevel@tonic-gate 14630Sstevel@tonic-gate int sbusid = ddi_get_instance(dip); 14640Sstevel@tonic-gate 14650Sstevel@tonic-gate if (ddi_get_parent_data(rdip) == NULL) 14660Sstevel@tonic-gate return (DDI_FAILURE); 14670Sstevel@tonic-gate 14680Sstevel@tonic-gate msgbuf = kmem_zalloc(REPORTDEV_BUFSIZE, KM_SLEEP); 14690Sstevel@tonic-gate 14700Sstevel@tonic-gate pdev = ddi_get_parent(rdip); 14710Sstevel@tonic-gate f_len = snprintf(msgbuf, REPORTDEV_BUFSIZE, 14720Sstevel@tonic-gate "%s%d at %s%d: SBus%d ", 14730Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 14740Sstevel@tonic-gate ddi_driver_name(pdev), ddi_get_instance(pdev), sbusid); 14750Sstevel@tonic-gate len = strlen(msgbuf); 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate for (i = 0, n = sysio_pd_getnreg(rdip); i < n; i++) { 14780Sstevel@tonic-gate struct regspec *rp; 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate rp = sysio_pd_getreg(rdip, i); 14810Sstevel@tonic-gate if (i != 0) { 14820Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 14830Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, " and "); 14840Sstevel@tonic-gate len = strlen(msgbuf); 14850Sstevel@tonic-gate } 14860Sstevel@tonic-gate 14870Sstevel@tonic-gate f_len += snprintf(msgbuf + len, REPORTDEV_BUFSIZE - len, 14880Sstevel@tonic-gate "slot 0x%x offset 0x%x", 14890Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_addr); 14900Sstevel@tonic-gate len = strlen(msgbuf); 14910Sstevel@tonic-gate } 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate for (i = 0, n = i_ddi_get_nintrs(rdip); i < n; i++) { 1494693Sgovinda uint32_t sbuslevel, inum, pri; 14950Sstevel@tonic-gate 14960Sstevel@tonic-gate if (i != 0) { 14970Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 14980Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, ","); 14990Sstevel@tonic-gate len = strlen(msgbuf); 15000Sstevel@tonic-gate } 15010Sstevel@tonic-gate 1502693Sgovinda sbuslevel = inum = i_ddi_get_inum(rdip, i); 1503693Sgovinda pri = i_ddi_get_intr_pri(rdip, i); 1504693Sgovinda 1505693Sgovinda (void) sbus_xlate_intrs(dip, rdip, &inum, 1506693Sgovinda &pri, softsp->intr_mapping_ign); 15070Sstevel@tonic-gate 15080Sstevel@tonic-gate if (sbuslevel > MAX_SBUS_LEVEL) 15090Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 15100Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, 15110Sstevel@tonic-gate " Onboard device "); 15120Sstevel@tonic-gate else 15130Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 15140Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, " SBus level %d ", 15150Sstevel@tonic-gate sbuslevel); 15160Sstevel@tonic-gate len = strlen(msgbuf); 15170Sstevel@tonic-gate 15180Sstevel@tonic-gate f_len += snprintf(msgbuf + len, REPORTDEV_BUFSIZE - len, 15190Sstevel@tonic-gate "sparc9 ipl %d", pri); 15200Sstevel@tonic-gate len = strlen(msgbuf); 15210Sstevel@tonic-gate } 15220Sstevel@tonic-gate #ifdef DEBUG 15230Sstevel@tonic-gate if (f_len + 1 >= REPORTDEV_BUFSIZE) { 15240Sstevel@tonic-gate cmn_err(CE_NOTE, "next message is truncated: " 15250Sstevel@tonic-gate "printed length 1024, real length %d", f_len); 15260Sstevel@tonic-gate } 15270Sstevel@tonic-gate #endif /* DEBUG */ 15280Sstevel@tonic-gate 15290Sstevel@tonic-gate cmn_err(CE_CONT, "?%s\n", msgbuf); 15300Sstevel@tonic-gate kmem_free(msgbuf, REPORTDEV_BUFSIZE); 15310Sstevel@tonic-gate return (DDI_SUCCESS); 15320Sstevel@tonic-gate 15330Sstevel@tonic-gate #undef REPORTDEV_BUFSIZE 15340Sstevel@tonic-gate } 15350Sstevel@tonic-gate 15360Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 15370Sstevel@tonic-gate return (DDI_FAILURE); 15380Sstevel@tonic-gate 15390Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: { 15400Sstevel@tonic-gate dev_info_t *dipb = (dev_info_t *)arg; 15410Sstevel@tonic-gate int r_slot, b_slot; 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate if ((b_slot = find_sbus_slot(dip, dipb)) < 0) 15440Sstevel@tonic-gate return (DDI_FAILURE); 15450Sstevel@tonic-gate 15460Sstevel@tonic-gate if ((r_slot = find_sbus_slot(dip, rdip)) < 0) 15470Sstevel@tonic-gate return (DDI_FAILURE); 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate return ((b_slot == r_slot)? DDI_SUCCESS : DDI_FAILURE); 15500Sstevel@tonic-gate 15510Sstevel@tonic-gate } 15520Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 15530Sstevel@tonic-gate cmn_err(CE_CONT, "?DDI_DMAPMAPC called!!\n"); 15540Sstevel@tonic-gate return (DDI_FAILURE); 15550Sstevel@tonic-gate 15560Sstevel@tonic-gate case DDI_CTLOPS_POKE: 15570Sstevel@tonic-gate return (sbus_ctlops_poke(softsp, (peekpoke_ctlops_t *)arg)); 15580Sstevel@tonic-gate 15590Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 15600Sstevel@tonic-gate return (sbus_ctlops_peek(softsp, (peekpoke_ctlops_t *)arg, 15610Sstevel@tonic-gate result)); 15620Sstevel@tonic-gate 15630Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE: 15640Sstevel@tonic-gate *(ulong_t *)result = IOMMU_PAGESIZE; 15650Sstevel@tonic-gate return (DDI_SUCCESS); 15660Sstevel@tonic-gate 15670Sstevel@tonic-gate default: 15680Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 15690Sstevel@tonic-gate } 15700Sstevel@tonic-gate } 15710Sstevel@tonic-gate 15720Sstevel@tonic-gate static int 15730Sstevel@tonic-gate find_sbus_slot(dev_info_t *dip, dev_info_t *rdip) 15740Sstevel@tonic-gate { 15750Sstevel@tonic-gate dev_info_t *child; 15760Sstevel@tonic-gate int slot = -1; 15770Sstevel@tonic-gate 15780Sstevel@tonic-gate /* 15790Sstevel@tonic-gate * look for the node that's a direct child of this Sbus node. 15800Sstevel@tonic-gate */ 15810Sstevel@tonic-gate while (rdip && (child = ddi_get_parent(rdip)) != dip) { 15820Sstevel@tonic-gate rdip = child; 15830Sstevel@tonic-gate } 15840Sstevel@tonic-gate 15850Sstevel@tonic-gate /* 15860Sstevel@tonic-gate * If there is one, get the slot number of *my* child 15870Sstevel@tonic-gate */ 15880Sstevel@tonic-gate if (child == dip) 15890Sstevel@tonic-gate slot = sysio_pd_getslot(rdip); 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate return (slot); 15920Sstevel@tonic-gate } 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate /* 15950Sstevel@tonic-gate * This is the sbus interrupt routine wrapper function. This function 15960Sstevel@tonic-gate * installs itself as a child devices interrupt handler. It's function is 15970Sstevel@tonic-gate * to dispatch a child devices interrupt handler, and then 15980Sstevel@tonic-gate * reset the interrupt clear register for the child device. 15990Sstevel@tonic-gate * 16000Sstevel@tonic-gate * Warning: This routine may need to be implemented as an assembly level 16010Sstevel@tonic-gate * routine to improve performance. 16020Sstevel@tonic-gate */ 16030Sstevel@tonic-gate 16040Sstevel@tonic-gate #define MAX_INTR_CNT 10 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate static uint_t 16070Sstevel@tonic-gate sbus_intr_wrapper(caddr_t arg) 16080Sstevel@tonic-gate { 16090Sstevel@tonic-gate uint_t intr_return = DDI_INTR_UNCLAIMED; 16100Sstevel@tonic-gate volatile uint64_t tmpreg; 16110Sstevel@tonic-gate struct sbus_wrapper_arg *intr_info; 16120Sstevel@tonic-gate struct sbus_intr_handler *intr_handler; 16130Sstevel@tonic-gate uchar_t *spurious_cntr; 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate intr_info = (struct sbus_wrapper_arg *)arg; 16160Sstevel@tonic-gate spurious_cntr = &intr_info->softsp->spurious_cntrs[intr_info->pil]; 16170Sstevel@tonic-gate intr_handler = intr_info->handler_list; 16180Sstevel@tonic-gate 16190Sstevel@tonic-gate while (intr_handler) { 16200Sstevel@tonic-gate caddr_t arg1 = intr_handler->arg1; 16210Sstevel@tonic-gate caddr_t arg2 = intr_handler->arg2; 16220Sstevel@tonic-gate uint_t (*funcp)() = intr_handler->funcp; 16230Sstevel@tonic-gate dev_info_t *dip = intr_handler->dip; 16240Sstevel@tonic-gate int r; 16250Sstevel@tonic-gate 16260Sstevel@tonic-gate if (intr_handler->intr_state == SBUS_INTR_STATE_DISABLE) { 16270Sstevel@tonic-gate intr_handler = intr_handler->next; 16280Sstevel@tonic-gate continue; 16290Sstevel@tonic-gate } 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 16320Sstevel@tonic-gate void *, funcp, caddr_t, arg1, caddr_t, arg2); 16330Sstevel@tonic-gate 16340Sstevel@tonic-gate r = (*funcp)(arg1, arg2); 16350Sstevel@tonic-gate 16360Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 16370Sstevel@tonic-gate void *, funcp, caddr_t, arg1, int, r); 16380Sstevel@tonic-gate 16390Sstevel@tonic-gate intr_return |= r; 16400Sstevel@tonic-gate intr_handler = intr_handler->next; 16410Sstevel@tonic-gate } 16420Sstevel@tonic-gate 16430Sstevel@tonic-gate /* Set the interrupt state machine to idle */ 16440Sstevel@tonic-gate tmpreg = *intr_info->softsp->sbus_ctrl_reg; 16450Sstevel@tonic-gate tmpreg = SBUS_INTR_IDLE; 16460Sstevel@tonic-gate *intr_info->clear_reg = tmpreg; 16470Sstevel@tonic-gate tmpreg = *intr_info->softsp->sbus_ctrl_reg; 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate if (intr_return == DDI_INTR_UNCLAIMED) { 16500Sstevel@tonic-gate (*spurious_cntr)++; 16510Sstevel@tonic-gate 16520Sstevel@tonic-gate if (*spurious_cntr < MAX_INTR_CNT) { 16530Sstevel@tonic-gate if (intr_cntr_on) 16540Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 16550Sstevel@tonic-gate } 16560Sstevel@tonic-gate #ifdef DEBUG 16570Sstevel@tonic-gate else if (intr_info->pil >= LOCK_LEVEL) { 16580Sstevel@tonic-gate cmn_err(CE_PANIC, "%d unclaimed interrupts at " 16590Sstevel@tonic-gate "interrupt level %d", MAX_INTR_CNT, 16600Sstevel@tonic-gate intr_info->pil); 16610Sstevel@tonic-gate } 16620Sstevel@tonic-gate #endif 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate /* 16650Sstevel@tonic-gate * Reset spurious counter once we acknowledge 16660Sstevel@tonic-gate * it to the system level. 16670Sstevel@tonic-gate */ 16680Sstevel@tonic-gate *spurious_cntr = (uchar_t)0; 16690Sstevel@tonic-gate } else { 16700Sstevel@tonic-gate *spurious_cntr = (uchar_t)0; 16710Sstevel@tonic-gate } 16720Sstevel@tonic-gate 16730Sstevel@tonic-gate return (intr_return); 16740Sstevel@tonic-gate } 16750Sstevel@tonic-gate 16760Sstevel@tonic-gate /* 16770Sstevel@tonic-gate * add_intrspec - Add an interrupt specification. 16780Sstevel@tonic-gate */ 16790Sstevel@tonic-gate static int 16800Sstevel@tonic-gate sbus_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 16810Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 16820Sstevel@tonic-gate { 16830Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 16840Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 16850Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 16860Sstevel@tonic-gate volatile uint64_t tmp_mondo_vec; 16870Sstevel@tonic-gate volatile uint64_t *intr_state_reg; 16880Sstevel@tonic-gate volatile uint64_t tmpreg; /* HW flush reg */ 16890Sstevel@tonic-gate uint_t start_bit; 16900Sstevel@tonic-gate int ino; 16910Sstevel@tonic-gate uint_t cpu_id; 16920Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg; 16930Sstevel@tonic-gate struct sbus_intr_handler *intr_handler; 16940Sstevel@tonic-gate uint32_t slot; 16950Sstevel@tonic-gate /* Interrupt state machine reset flag */ 16960Sstevel@tonic-gate int reset_ism_register = 1; 16970Sstevel@tonic-gate int ret = DDI_SUCCESS; 16980Sstevel@tonic-gate 16990Sstevel@tonic-gate /* Check if we have a valid sbus slot address */ 17000Sstevel@tonic-gate if (((slot = (uint_t)find_sbus_slot(dip, rdip)) >= 17010Sstevel@tonic-gate MAX_SBUS_SLOT_ADDR) || (slot < (uint_t)0)) { 17020Sstevel@tonic-gate cmn_err(CE_WARN, "Invalid sbus slot 0x%x during add intr\n", 17030Sstevel@tonic-gate slot); 17040Sstevel@tonic-gate return (DDI_FAILURE); 17050Sstevel@tonic-gate } 17060Sstevel@tonic-gate 17070Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: sbus interrupt %d " 1708693Sgovinda "for device %s%d\n", hdlp->ih_vector, ddi_driver_name(rdip), 17090Sstevel@tonic-gate ddi_get_instance(rdip))); 17100Sstevel@tonic-gate 17110Sstevel@tonic-gate /* Xlate the interrupt */ 1712693Sgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector, 1713693Sgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) { 17140Sstevel@tonic-gate cmn_err(CE_WARN, "Can't xlate SBUS devices %s interrupt.\n", 1715693Sgovinda ddi_driver_name(rdip)); 17160Sstevel@tonic-gate return (DDI_FAILURE); 17170Sstevel@tonic-gate } 17180Sstevel@tonic-gate 17190Sstevel@tonic-gate /* get the ino number */ 1720693Sgovinda ino = hdlp->ih_vector & SBUS_MAX_INO; 17210Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg + 17220Sstevel@tonic-gate ino_table[ino]->mapping_reg); 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate /* 17250Sstevel@tonic-gate * This is an intermediate step in identifying 17260Sstevel@tonic-gate * the exact bits which represent the device in the interrupt 17270Sstevel@tonic-gate * state diagnostic register. 17280Sstevel@tonic-gate */ 17290Sstevel@tonic-gate if (ino > MAX_MONDO_EXTERNAL) { 17300Sstevel@tonic-gate start_bit = ino_table[ino]->diagreg_shift; 17310Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state; 17320Sstevel@tonic-gate } else { 17330Sstevel@tonic-gate start_bit = 16 * (ino >> 3) + 2 * (ino & 0x7); 17340Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state; 17350Sstevel@tonic-gate } 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate 17380Sstevel@tonic-gate /* Allocate a nexus interrupt data structure */ 17390Sstevel@tonic-gate intr_handler = kmem_zalloc(sizeof (struct sbus_intr_handler), KM_SLEEP); 17400Sstevel@tonic-gate intr_handler->dip = rdip; 17410Sstevel@tonic-gate intr_handler->funcp = hdlp->ih_cb_func; 17420Sstevel@tonic-gate intr_handler->arg1 = hdlp->ih_cb_arg1; 17430Sstevel@tonic-gate intr_handler->arg2 = hdlp->ih_cb_arg2; 17440Sstevel@tonic-gate intr_handler->inum = hdlp->ih_inum; 17450Sstevel@tonic-gate 17460Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: xlated interrupt 0x%x " 1747*1035Smike_s "intr_handler 0x%p\n", hdlp->ih_vector, intr_handler)); 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate /* 17500Sstevel@tonic-gate * Grab this lock here. So it will protect the poll list. 17510Sstevel@tonic-gate */ 17520Sstevel@tonic-gate mutex_enter(&softsp->intr_poll_list_lock); 17530Sstevel@tonic-gate 17540Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino]; 17550Sstevel@tonic-gate /* Check if we have a poll list to deal with */ 17560Sstevel@tonic-gate if (sbus_arg) { 17570Sstevel@tonic-gate tmp_mondo_vec = *mondo_vec_reg; 17580Sstevel@tonic-gate tmp_mondo_vec &= ~INTERRUPT_VALID; 17590Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec; 17600Sstevel@tonic-gate 17610Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 17620Sstevel@tonic-gate #ifdef lint 17630Sstevel@tonic-gate tmpreg = tmpreg; 17640Sstevel@tonic-gate #endif 17650Sstevel@tonic-gate 17660Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:sbus_arg exists " 1767*1035Smike_s "0x%p\n", sbus_arg)); 17680Sstevel@tonic-gate /* 17690Sstevel@tonic-gate * Two bits per ino in the diagnostic register 17700Sstevel@tonic-gate * indicate the status of its interrupt. 17710Sstevel@tonic-gate * 0 - idle, 1 - transmit, 3 - pending. 17720Sstevel@tonic-gate */ 17730Sstevel@tonic-gate while (((*intr_state_reg >> 17740Sstevel@tonic-gate start_bit) & 0x3) == INT_PENDING && !panicstr) 17750Sstevel@tonic-gate /* empty */; 17760Sstevel@tonic-gate 17770Sstevel@tonic-gate intr_handler->next = sbus_arg->handler_list; 17780Sstevel@tonic-gate sbus_arg->handler_list = intr_handler; 17790Sstevel@tonic-gate 17800Sstevel@tonic-gate reset_ism_register = 0; 17810Sstevel@tonic-gate } else { 17820Sstevel@tonic-gate sbus_arg = kmem_zalloc(sizeof (struct sbus_wrapper_arg), 17830Sstevel@tonic-gate KM_SLEEP); 17840Sstevel@tonic-gate 17850Sstevel@tonic-gate softsp->intr_list[ino] = sbus_arg; 17860Sstevel@tonic-gate sbus_arg->clear_reg = (softsp->clr_intr_reg + 17870Sstevel@tonic-gate ino_table[ino]->clear_reg); 17880Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:Ino 0x%x Interrupt " 1789*1035Smike_s "clear reg: 0x%p\n", ino, sbus_arg->clear_reg)); 17900Sstevel@tonic-gate sbus_arg->softsp = softsp; 17910Sstevel@tonic-gate sbus_arg->handler_list = intr_handler; 17920Sstevel@tonic-gate 17930Sstevel@tonic-gate /* 17940Sstevel@tonic-gate * No handler added yet in the interrupt vector 17950Sstevel@tonic-gate * table for this ino. 17960Sstevel@tonic-gate * Install the nexus interrupt wrapper in the 17970Sstevel@tonic-gate * system. The wrapper will call the device 17980Sstevel@tonic-gate * interrupt handler. 17990Sstevel@tonic-gate */ 18000Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 18010Sstevel@tonic-gate (ddi_intr_handler_t *)sbus_intr_wrapper, 18020Sstevel@tonic-gate (caddr_t)sbus_arg, NULL); 18030Sstevel@tonic-gate 18040Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 18050Sstevel@tonic-gate 18060Sstevel@tonic-gate /* 18070Sstevel@tonic-gate * Restore original interrupt handler 18080Sstevel@tonic-gate * and arguments in interrupt handle. 18090Sstevel@tonic-gate */ 18100Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, intr_handler->funcp, 18110Sstevel@tonic-gate intr_handler->arg1, intr_handler->arg2); 18120Sstevel@tonic-gate 1813965Sgovinda if (ret != DDI_SUCCESS) { 1814965Sgovinda mutex_exit(&softsp->intr_poll_list_lock); 1815965Sgovinda goto done; 1816965Sgovinda } 18170Sstevel@tonic-gate 18180Sstevel@tonic-gate if ((slot >= EXT_SBUS_SLOTS) || 18190Sstevel@tonic-gate (softsp->intr_hndlr_cnt[slot] == 0)) { 18200Sstevel@tonic-gate 18210Sstevel@tonic-gate cpu_id = intr_dist_cpuid(); 18220Sstevel@tonic-gate #ifdef _STARFIRE 18230Sstevel@tonic-gate tmp_mondo_vec = pc_translate_tgtid( 18240Sstevel@tonic-gate softsp->ittrans_cookie, cpu_id, 18250Sstevel@tonic-gate mondo_vec_reg) << IMR_TID_SHIFT; 18260Sstevel@tonic-gate #else 18270Sstevel@tonic-gate tmp_mondo_vec = 18280Sstevel@tonic-gate cpu_id << IMR_TID_SHIFT; 18290Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: initial " 1830*1035Smike_s "mapping reg 0x%lx\n", tmp_mondo_vec)); 18310Sstevel@tonic-gate #endif /* _STARFIRE */ 18320Sstevel@tonic-gate } else { 18330Sstevel@tonic-gate /* 18340Sstevel@tonic-gate * There is already a different 18350Sstevel@tonic-gate * ino programmed at this IMR. 18360Sstevel@tonic-gate * Just read the IMR out to get the 18370Sstevel@tonic-gate * correct MID target. 18380Sstevel@tonic-gate */ 18390Sstevel@tonic-gate tmp_mondo_vec = *mondo_vec_reg; 18400Sstevel@tonic-gate tmp_mondo_vec &= ~INTERRUPT_VALID; 18410Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec; 18420Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: existing " 1843*1035Smike_s "mapping reg 0x%lx\n", tmp_mondo_vec)); 18440Sstevel@tonic-gate } 18450Sstevel@tonic-gate 18460Sstevel@tonic-gate sbus_arg->pil = hdlp->ih_pri; 18470Sstevel@tonic-gate 18480Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:Alloc sbus_arg " 1849*1035Smike_s "0x%p\n", sbus_arg)); 18500Sstevel@tonic-gate } 18510Sstevel@tonic-gate 18520Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]++; 18530Sstevel@tonic-gate 18540Sstevel@tonic-gate mutex_exit(&softsp->intr_poll_list_lock); 18550Sstevel@tonic-gate 18560Sstevel@tonic-gate /* 18570Sstevel@tonic-gate * Program the ino vector accordingly. This MUST be the 18580Sstevel@tonic-gate * last thing we do. Once we program the ino, the device 18590Sstevel@tonic-gate * may begin to interrupt. Add this hardware interrupt to 18600Sstevel@tonic-gate * the interrupt lists, and get the CPU to target it at. 18610Sstevel@tonic-gate */ 18620Sstevel@tonic-gate 18630Sstevel@tonic-gate tmp_mondo_vec |= INTERRUPT_VALID; 18640Sstevel@tonic-gate 1865*1035Smike_s DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: Ino 0x%x mapping reg: 0x%p " 18660Sstevel@tonic-gate "Intr cntr %d\n", ino, mondo_vec_reg, 18670Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot])); 18680Sstevel@tonic-gate 18690Sstevel@tonic-gate /* Force the interrupt state machine to idle. */ 18700Sstevel@tonic-gate if (reset_ism_register) { 18710Sstevel@tonic-gate tmpreg = SBUS_INTR_IDLE; 18720Sstevel@tonic-gate *sbus_arg->clear_reg = tmpreg; 18730Sstevel@tonic-gate } 18740Sstevel@tonic-gate 18750Sstevel@tonic-gate /* Store it in the hardware reg. */ 18760Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec; 18770Sstevel@tonic-gate 18780Sstevel@tonic-gate /* Flush store buffers */ 18790Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 18800Sstevel@tonic-gate 18810Sstevel@tonic-gate done: 18820Sstevel@tonic-gate return (ret); 18830Sstevel@tonic-gate } 18840Sstevel@tonic-gate 18850Sstevel@tonic-gate static void 18860Sstevel@tonic-gate sbus_free_handler(dev_info_t *dip, uint32_t inum, 18870Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg) 18880Sstevel@tonic-gate { 18890Sstevel@tonic-gate struct sbus_intr_handler *listp, *prevp; 18900Sstevel@tonic-gate 18910Sstevel@tonic-gate if (sbus_arg) { 18920Sstevel@tonic-gate prevp = NULL; 18930Sstevel@tonic-gate listp = sbus_arg->handler_list; 18940Sstevel@tonic-gate 18950Sstevel@tonic-gate while (listp) { 18960Sstevel@tonic-gate if (listp->dip == dip && listp->inum == inum) { 18970Sstevel@tonic-gate if (prevp) 18980Sstevel@tonic-gate prevp->next = listp->next; 18990Sstevel@tonic-gate else { 19000Sstevel@tonic-gate prevp = listp->next; 19010Sstevel@tonic-gate sbus_arg->handler_list = prevp; 19020Sstevel@tonic-gate } 19030Sstevel@tonic-gate 19040Sstevel@tonic-gate kmem_free(listp, 19050Sstevel@tonic-gate sizeof (struct sbus_intr_handler)); 19060Sstevel@tonic-gate break; 19070Sstevel@tonic-gate } 19080Sstevel@tonic-gate prevp = listp; 19090Sstevel@tonic-gate listp = listp->next; 19100Sstevel@tonic-gate } 19110Sstevel@tonic-gate } 19120Sstevel@tonic-gate } 19130Sstevel@tonic-gate 19140Sstevel@tonic-gate /* 19150Sstevel@tonic-gate * remove_intrspec - Remove an interrupt specification. 19160Sstevel@tonic-gate */ 19170Sstevel@tonic-gate /*ARGSUSED*/ 19180Sstevel@tonic-gate static void 19190Sstevel@tonic-gate sbus_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 19200Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 19210Sstevel@tonic-gate { 19220Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 19230Sstevel@tonic-gate volatile uint64_t *intr_state_reg; 19240Sstevel@tonic-gate #ifndef lint 19250Sstevel@tonic-gate volatile uint64_t tmpreg; 19260Sstevel@tonic-gate #endif /* !lint */ 19270Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 19280Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 19290Sstevel@tonic-gate int start_bit, ino, slot; 19300Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg; 19310Sstevel@tonic-gate 19320Sstevel@tonic-gate /* Grab the mutex protecting the poll list */ 19330Sstevel@tonic-gate mutex_enter(&softsp->intr_poll_list_lock); 19340Sstevel@tonic-gate 19350Sstevel@tonic-gate /* Xlate the interrupt */ 1936693Sgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector, 1937693Sgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) { 19380Sstevel@tonic-gate cmn_err(CE_WARN, "Can't xlate SBUS devices %s interrupt.\n", 1939693Sgovinda ddi_driver_name(rdip)); 19400Sstevel@tonic-gate goto done; 19410Sstevel@tonic-gate } 19420Sstevel@tonic-gate 1943693Sgovinda ino = ((int32_t)hdlp->ih_vector) & SBUS_MAX_INO; 19440Sstevel@tonic-gate 19450Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg + 19460Sstevel@tonic-gate ino_table[ino]->mapping_reg); 19470Sstevel@tonic-gate 19480Sstevel@tonic-gate /* Turn off the valid bit in the mapping register. */ 19490Sstevel@tonic-gate *mondo_vec_reg &= ~INTERRUPT_VALID; 19500Sstevel@tonic-gate #ifndef lint 19510Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 19520Sstevel@tonic-gate #endif /* !lint */ 19530Sstevel@tonic-gate 19540Sstevel@tonic-gate /* Get our bit position for checking intr pending */ 19550Sstevel@tonic-gate if (ino > MAX_MONDO_EXTERNAL) { 19560Sstevel@tonic-gate start_bit = ino_table[ino]->diagreg_shift; 19570Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state; 19580Sstevel@tonic-gate } else { 19590Sstevel@tonic-gate start_bit = 16 * (ino >> 3) + 2 * (ino & 0x7); 19600Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state; 19610Sstevel@tonic-gate } 19620Sstevel@tonic-gate 19630Sstevel@tonic-gate while (((*intr_state_reg >> start_bit) & 0x3) == INT_PENDING && 19640Sstevel@tonic-gate !panicstr) 19650Sstevel@tonic-gate /* empty */; 19660Sstevel@tonic-gate 19670Sstevel@tonic-gate slot = find_sbus_slot(dip, rdip); 19680Sstevel@tonic-gate 19690Sstevel@tonic-gate /* Return if the slot is invalid */ 19700Sstevel@tonic-gate if (slot >= MAX_SBUS_SLOT_ADDR || slot < 0) { 19710Sstevel@tonic-gate goto done; 19720Sstevel@tonic-gate } 19730Sstevel@tonic-gate 19740Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino]; 19750Sstevel@tonic-gate 19760Sstevel@tonic-gate /* Decrement the intr handler count on this slot */ 19770Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]--; 19780Sstevel@tonic-gate 1979*1035Smike_s DPRINTF(SBUS_INTERRUPT_DEBUG, ("Rem intr: Softsp 0x%p, Mondo 0x%x, " 1980*1035Smike_s "ino 0x%x, sbus_arg 0x%p intr cntr %d\n", softsp, 1981693Sgovinda hdlp->ih_vector, ino, sbus_arg, softsp->intr_hndlr_cnt[slot])); 19820Sstevel@tonic-gate 19830Sstevel@tonic-gate ASSERT(sbus_arg != NULL); 19840Sstevel@tonic-gate ASSERT(sbus_arg->handler_list != NULL); 19850Sstevel@tonic-gate sbus_free_handler(rdip, hdlp->ih_inum, sbus_arg); 19860Sstevel@tonic-gate 19870Sstevel@tonic-gate /* If we still have a list, we're done. */ 1988693Sgovinda if (sbus_arg->handler_list == NULL) 19890Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 19900Sstevel@tonic-gate 19910Sstevel@tonic-gate /* 19920Sstevel@tonic-gate * If other devices are still installed for this slot, we need to 19930Sstevel@tonic-gate * turn the valid bit back on. 19940Sstevel@tonic-gate */ 19950Sstevel@tonic-gate if (softsp->intr_hndlr_cnt[slot] > 0) { 19960Sstevel@tonic-gate *mondo_vec_reg |= INTERRUPT_VALID; 19970Sstevel@tonic-gate #ifndef lint 19980Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 19990Sstevel@tonic-gate #endif /* !lint */ 20000Sstevel@tonic-gate } 20010Sstevel@tonic-gate 20020Sstevel@tonic-gate if ((softsp->intr_hndlr_cnt[slot] == 0) || (slot >= EXT_SBUS_SLOTS)) { 20030Sstevel@tonic-gate ASSERT(sbus_arg->handler_list == NULL); 20040Sstevel@tonic-gate #ifdef _STARFIRE 20050Sstevel@tonic-gate /* Do cleanup for interrupt target translation */ 20060Sstevel@tonic-gate pc_ittrans_cleanup(softsp->ittrans_cookie, mondo_vec_reg); 20070Sstevel@tonic-gate #endif /* _STARFIRE */ 20080Sstevel@tonic-gate } 20090Sstevel@tonic-gate 20100Sstevel@tonic-gate 20110Sstevel@tonic-gate /* Free up the memory used for the sbus interrupt handler */ 20120Sstevel@tonic-gate if (sbus_arg->handler_list == NULL) { 20130Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Rem intr: Freeing sbus arg " 2014*1035Smike_s "0x%p\n", sbus_arg)); 20150Sstevel@tonic-gate kmem_free(sbus_arg, sizeof (struct sbus_wrapper_arg)); 20160Sstevel@tonic-gate softsp->intr_list[ino] = NULL; 20170Sstevel@tonic-gate } 20180Sstevel@tonic-gate 20190Sstevel@tonic-gate done: 20200Sstevel@tonic-gate mutex_exit(&softsp->intr_poll_list_lock); 20210Sstevel@tonic-gate } 20220Sstevel@tonic-gate 20230Sstevel@tonic-gate /* 20240Sstevel@tonic-gate * We're prepared to claim that the interrupt string is in 20250Sstevel@tonic-gate * the form of a list of <SBusintr> specifications, or we're dealing 20260Sstevel@tonic-gate * with on-board devices and we have an interrupt_number property which 20270Sstevel@tonic-gate * gives us our mondo number. 20280Sstevel@tonic-gate * Translate the sbus levels or mondos into sysiointrspecs. 20290Sstevel@tonic-gate */ 20300Sstevel@tonic-gate static int 2031693Sgovinda sbus_xlate_intrs(dev_info_t *dip, dev_info_t *rdip, uint32_t *intr, 2032693Sgovinda uint32_t *pil, int32_t ign) 20330Sstevel@tonic-gate { 2034693Sgovinda uint32_t ino, slot, level = *intr; 20350Sstevel@tonic-gate int ret = DDI_SUCCESS; 20360Sstevel@tonic-gate 20370Sstevel@tonic-gate /* 20380Sstevel@tonic-gate * Create the sysio ino number. onboard devices will have 20390Sstevel@tonic-gate * an "interrupts" property, that is equal to the ino number. 20400Sstevel@tonic-gate * If the devices are from the 20410Sstevel@tonic-gate * expansion slots, we construct the ino number by putting 20420Sstevel@tonic-gate * the slot number in the upper three bits, and the sbus 20430Sstevel@tonic-gate * interrupt level in the lower three bits. 20440Sstevel@tonic-gate */ 20450Sstevel@tonic-gate if (level > MAX_SBUS_LEVEL) { 20460Sstevel@tonic-gate ino = level; 20470Sstevel@tonic-gate } else { 20480Sstevel@tonic-gate /* Construct ino from slot and interrupts */ 20490Sstevel@tonic-gate if ((slot = find_sbus_slot(dip, rdip)) == -1) { 20500Sstevel@tonic-gate cmn_err(CE_WARN, "Can't determine sbus slot " 2051693Sgovinda "of %s device\n", ddi_driver_name(rdip)); 20520Sstevel@tonic-gate ret = DDI_FAILURE; 20530Sstevel@tonic-gate goto done; 20540Sstevel@tonic-gate } 20550Sstevel@tonic-gate 20560Sstevel@tonic-gate if (slot >= MAX_SBUS_SLOT_ADDR) { 20570Sstevel@tonic-gate cmn_err(CE_WARN, "Invalid sbus slot 0x%x" 2058693Sgovinda "in %s device\n", slot, ddi_driver_name(rdip)); 20590Sstevel@tonic-gate ret = DDI_FAILURE; 20600Sstevel@tonic-gate goto done; 20610Sstevel@tonic-gate } 20620Sstevel@tonic-gate 20630Sstevel@tonic-gate ino = slot << 3; 20640Sstevel@tonic-gate ino |= level; 20650Sstevel@tonic-gate } 20660Sstevel@tonic-gate 20670Sstevel@tonic-gate /* Sanity check the inos range */ 20680Sstevel@tonic-gate if (ino >= MAX_INO_TABLE_SIZE) { 20690Sstevel@tonic-gate cmn_err(CE_WARN, "Ino vector 0x%x out of range", ino); 20700Sstevel@tonic-gate ret = DDI_FAILURE; 20710Sstevel@tonic-gate goto done; 20720Sstevel@tonic-gate } 20730Sstevel@tonic-gate /* Sanity check the inos value */ 20740Sstevel@tonic-gate if (!ino_table[ino]) { 20750Sstevel@tonic-gate cmn_err(CE_WARN, "Ino vector 0x%x is invalid", ino); 20760Sstevel@tonic-gate ret = DDI_FAILURE; 20770Sstevel@tonic-gate goto done; 20780Sstevel@tonic-gate } 20790Sstevel@tonic-gate 2080693Sgovinda if (*pil == 0) { 20810Sstevel@tonic-gate #define SOC_PRIORITY 5 20820Sstevel@tonic-gate /* The sunfire i/o board has a soc in the printer slot */ 20830Sstevel@tonic-gate if ((ino_table[ino]->clear_reg == PP_CLEAR) && 20840Sstevel@tonic-gate ((strcmp(ddi_get_name(rdip), "soc") == 0) || 20850Sstevel@tonic-gate (strcmp(ddi_get_name(rdip), "SUNW,soc") == 0))) { 2086693Sgovinda *pil = SOC_PRIORITY; 20870Sstevel@tonic-gate } else { 20880Sstevel@tonic-gate /* Figure out the pil associated with this interrupt */ 2089693Sgovinda *pil = interrupt_priorities[ino]; 20900Sstevel@tonic-gate } 20910Sstevel@tonic-gate } 20920Sstevel@tonic-gate 20930Sstevel@tonic-gate /* Or in the upa_id into the interrupt group number field */ 2094693Sgovinda *intr = (uint32_t)(ino | ign); 20950Sstevel@tonic-gate 20960Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Xlate intr: Interrupt info for " 20970Sstevel@tonic-gate "device %s Mondo: 0x%x, ino: 0x%x, Pil: 0x%x, sbus level: 0x%x\n", 2098693Sgovinda ddi_driver_name(rdip), *intr, ino, *pil, level)); 20990Sstevel@tonic-gate 21000Sstevel@tonic-gate done: 21010Sstevel@tonic-gate return (ret); 21020Sstevel@tonic-gate } 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate /* new intr_ops structure */ 21050Sstevel@tonic-gate int 21060Sstevel@tonic-gate sbus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 21070Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 21080Sstevel@tonic-gate { 21090Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 21100Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 21110Sstevel@tonic-gate int ret = DDI_SUCCESS; 21120Sstevel@tonic-gate 21130Sstevel@tonic-gate 21140Sstevel@tonic-gate switch (intr_op) { 21150Sstevel@tonic-gate case DDI_INTROP_GETCAP: 2116693Sgovinda *(int *)result = DDI_INTR_FLAG_LEVEL; 21170Sstevel@tonic-gate break; 21180Sstevel@tonic-gate case DDI_INTROP_ALLOC: 21190Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 21200Sstevel@tonic-gate break; 21210Sstevel@tonic-gate case DDI_INTROP_FREE: 21220Sstevel@tonic-gate break; 21230Sstevel@tonic-gate case DDI_INTROP_GETPRI: 2124693Sgovinda if (hdlp->ih_vector == 0) { 21250Sstevel@tonic-gate /* Xlate the interrupt */ 21260Sstevel@tonic-gate (void) sbus_xlate_intrs(dip, rdip, 2127693Sgovinda (uint32_t *)&hdlp->ih_vector, &hdlp->ih_pri, 2128693Sgovinda softsp->intr_mapping_ign); 21290Sstevel@tonic-gate } 21300Sstevel@tonic-gate 2131693Sgovinda *(int *)result = hdlp->ih_pri; 21320Sstevel@tonic-gate break; 21330Sstevel@tonic-gate case DDI_INTROP_SETPRI: 21340Sstevel@tonic-gate break; 21350Sstevel@tonic-gate case DDI_INTROP_ADDISR: 21360Sstevel@tonic-gate ret = sbus_add_intr_impl(dip, rdip, hdlp); 21370Sstevel@tonic-gate break; 21380Sstevel@tonic-gate case DDI_INTROP_REMISR: 21390Sstevel@tonic-gate sbus_remove_intr_impl(dip, rdip, hdlp); 21400Sstevel@tonic-gate break; 21410Sstevel@tonic-gate case DDI_INTROP_ENABLE: 21420Sstevel@tonic-gate ret = sbus_update_intr_state(dip, rdip, hdlp, 21430Sstevel@tonic-gate SBUS_INTR_STATE_ENABLE); 21440Sstevel@tonic-gate break; 21450Sstevel@tonic-gate case DDI_INTROP_DISABLE: 21460Sstevel@tonic-gate ret = sbus_update_intr_state(dip, rdip, hdlp, 21470Sstevel@tonic-gate SBUS_INTR_STATE_DISABLE); 21480Sstevel@tonic-gate break; 21490Sstevel@tonic-gate case DDI_INTROP_NINTRS: 21500Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 21510Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip); 21520Sstevel@tonic-gate break; 21530Sstevel@tonic-gate case DDI_INTROP_SETCAP: 21540Sstevel@tonic-gate case DDI_INTROP_SETMASK: 21550Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 21560Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 21570Sstevel@tonic-gate ret = DDI_ENOTSUP; 21580Sstevel@tonic-gate break; 21590Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 21600Sstevel@tonic-gate /* Sbus nexus driver supports only fixed interrupts */ 21610Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip) ? 21620Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0; 21630Sstevel@tonic-gate break; 21640Sstevel@tonic-gate default: 21650Sstevel@tonic-gate ret = i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result); 21660Sstevel@tonic-gate break; 21670Sstevel@tonic-gate } 21680Sstevel@tonic-gate 21690Sstevel@tonic-gate return (ret); 21700Sstevel@tonic-gate } 21710Sstevel@tonic-gate 21720Sstevel@tonic-gate 21730Sstevel@tonic-gate /* 21740Sstevel@tonic-gate * Called by suspend/resume to save/restore the interrupt status (valid bit) 21750Sstevel@tonic-gate * of the interrupt mapping registers. 21760Sstevel@tonic-gate */ 21770Sstevel@tonic-gate static void 21780Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(uint64_t *cpr_softsp, volatile uint64_t *baddr, 21790Sstevel@tonic-gate int save) 21800Sstevel@tonic-gate { 21810Sstevel@tonic-gate int i; 21820Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 21830Sstevel@tonic-gate 21840Sstevel@tonic-gate for (i = 0; i < MAX_INO_TABLE_SIZE; i++) { 21850Sstevel@tonic-gate if (ino_table[i] != NULL) { 21860Sstevel@tonic-gate mondo_vec_reg = baddr + ino_table[i]->mapping_reg; 21870Sstevel@tonic-gate if (save) { 21880Sstevel@tonic-gate if (*mondo_vec_reg & INTERRUPT_VALID) { 21890Sstevel@tonic-gate cpr_softsp[i] = *mondo_vec_reg; 21900Sstevel@tonic-gate } 21910Sstevel@tonic-gate } else { 21920Sstevel@tonic-gate if (cpr_softsp[i]) { 21930Sstevel@tonic-gate *mondo_vec_reg = cpr_softsp[i]; 21940Sstevel@tonic-gate } 21950Sstevel@tonic-gate } 21960Sstevel@tonic-gate } 21970Sstevel@tonic-gate } 21980Sstevel@tonic-gate } 21990Sstevel@tonic-gate 22000Sstevel@tonic-gate #define SZ_INO_TABLE (sizeof (ino_table) / sizeof (ino_table[0])) 22010Sstevel@tonic-gate 22020Sstevel@tonic-gate /* 22030Sstevel@tonic-gate * sbus_intrdist 22040Sstevel@tonic-gate * 22050Sstevel@tonic-gate * This function retargets active interrupts by reprogramming the mondo 22060Sstevel@tonic-gate * vec register. If the CPU ID of the target has not changed, then 22070Sstevel@tonic-gate * the mondo is not reprogrammed. The routine must hold the mondo 22080Sstevel@tonic-gate * lock for this instance of the sbus. 22090Sstevel@tonic-gate */ 22100Sstevel@tonic-gate static void 22110Sstevel@tonic-gate sbus_intrdist(void *arg) 22120Sstevel@tonic-gate { 22130Sstevel@tonic-gate struct sbus_soft_state *softsp; 22140Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 22150Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 22160Sstevel@tonic-gate uint64_t *last_mondo_vec_reg; 22170Sstevel@tonic-gate uint64_t mondo_vec; 22180Sstevel@tonic-gate volatile uint64_t *intr_state_reg; 22190Sstevel@tonic-gate uint_t start_bit; 22200Sstevel@tonic-gate volatile uint64_t tmpreg; /* HW flush reg */ 22210Sstevel@tonic-gate uint_t mondo; 22220Sstevel@tonic-gate uint_t cpu_id; 22230Sstevel@tonic-gate 22240Sstevel@tonic-gate /* extract the soft state pointer */ 22250Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 22260Sstevel@tonic-gate 22270Sstevel@tonic-gate last_mondo_vec_reg = NULL; 22280Sstevel@tonic-gate for (mondo = 0; mondo < SZ_INO_TABLE; mondo++) { 22290Sstevel@tonic-gate if (ino_table[mondo] == NULL) 22300Sstevel@tonic-gate continue; 22310Sstevel@tonic-gate 22320Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg + 22330Sstevel@tonic-gate ino_table[mondo]->mapping_reg); 22340Sstevel@tonic-gate 22350Sstevel@tonic-gate /* Don't reprogram the same register twice */ 22360Sstevel@tonic-gate if (mondo_vec_reg == last_mondo_vec_reg) 22370Sstevel@tonic-gate continue; 22380Sstevel@tonic-gate 22390Sstevel@tonic-gate if ((*mondo_vec_reg & INTERRUPT_VALID) == 0) 22400Sstevel@tonic-gate continue; 22410Sstevel@tonic-gate 22420Sstevel@tonic-gate last_mondo_vec_reg = (uint64_t *)mondo_vec_reg; 22430Sstevel@tonic-gate 22440Sstevel@tonic-gate cpu_id = intr_dist_cpuid(); 22450Sstevel@tonic-gate #ifdef _STARFIRE 22460Sstevel@tonic-gate /* 22470Sstevel@tonic-gate * For Starfire it is a pain to check the current target for 22480Sstevel@tonic-gate * the mondo since we have to read the PC asics ITTR slot 22490Sstevel@tonic-gate * assigned to this mondo. It will be much easier to assume 22500Sstevel@tonic-gate * the current target is always different and do the target 22510Sstevel@tonic-gate * reprogram all the time. 22520Sstevel@tonic-gate */ 22530Sstevel@tonic-gate #else 22540Sstevel@tonic-gate if (((*mondo_vec_reg & IMR_TID) >> IMR_TID_SHIFT) == cpu_id) { 22550Sstevel@tonic-gate /* It is the same, don't reprogram */ 22560Sstevel@tonic-gate return; 22570Sstevel@tonic-gate } 22580Sstevel@tonic-gate #endif /* _STARFIRE */ 22590Sstevel@tonic-gate 22600Sstevel@tonic-gate /* So it's OK to reprogram the CPU target */ 22610Sstevel@tonic-gate 22620Sstevel@tonic-gate /* turn off valid bit and wait for the state machine to idle */ 22630Sstevel@tonic-gate *mondo_vec_reg &= ~INTERRUPT_VALID; 22640Sstevel@tonic-gate 22650Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 22660Sstevel@tonic-gate 22670Sstevel@tonic-gate #ifdef lint 22680Sstevel@tonic-gate tmpreg = tmpreg; 22690Sstevel@tonic-gate #endif /* lint */ 22700Sstevel@tonic-gate 22710Sstevel@tonic-gate if (mondo > MAX_MONDO_EXTERNAL) { 22720Sstevel@tonic-gate start_bit = ino_table[mondo]->diagreg_shift; 22730Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state; 22740Sstevel@tonic-gate 22750Sstevel@tonic-gate /* 22760Sstevel@tonic-gate * Loop waiting for state machine to idle. Do not keep 22770Sstevel@tonic-gate * looping on a panic so that the system does not hang. 22780Sstevel@tonic-gate */ 22790Sstevel@tonic-gate while ((((*intr_state_reg >> start_bit) & 0x3) == 22800Sstevel@tonic-gate INT_PENDING) && !panicstr) 22810Sstevel@tonic-gate /* empty */; 22820Sstevel@tonic-gate } else { 22830Sstevel@tonic-gate int int_pending = 0; /* interrupts pending */ 22840Sstevel@tonic-gate 22850Sstevel@tonic-gate /* 22860Sstevel@tonic-gate * Shift over to first bit for this Sbus slot, 16 22870Sstevel@tonic-gate * bits per slot, bits 0-1 of each slot are reserved. 22880Sstevel@tonic-gate */ 22890Sstevel@tonic-gate start_bit = 16 * (mondo >> 3) + 2; 22900Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state; 22910Sstevel@tonic-gate 22920Sstevel@tonic-gate /* 22930Sstevel@tonic-gate * Make sure interrupts for levels 1-7 of this slot 22940Sstevel@tonic-gate * are not pending. 22950Sstevel@tonic-gate */ 22960Sstevel@tonic-gate do { 22970Sstevel@tonic-gate int level; /* Sbus interrupt level */ 22980Sstevel@tonic-gate int shift; /* # of bits to shift */ 22990Sstevel@tonic-gate uint64_t state_reg = *intr_state_reg; 23000Sstevel@tonic-gate 23010Sstevel@tonic-gate int_pending = 0; 23020Sstevel@tonic-gate 23030Sstevel@tonic-gate for (shift = start_bit, level = 1; level < 8; 23040Sstevel@tonic-gate level++, shift += 2) { 23050Sstevel@tonic-gate if (((state_reg >> shift) & 23060Sstevel@tonic-gate 0x3) == INT_PENDING) { 23070Sstevel@tonic-gate int_pending = 1; 23080Sstevel@tonic-gate break; 23090Sstevel@tonic-gate } 23100Sstevel@tonic-gate } 23110Sstevel@tonic-gate } while (int_pending && !panicstr); 23120Sstevel@tonic-gate } 23130Sstevel@tonic-gate 23140Sstevel@tonic-gate /* re-target the mondo and turn it on */ 23150Sstevel@tonic-gate #ifdef _STARFIRE 23160Sstevel@tonic-gate mondo_vec = (pc_translate_tgtid(softsp->ittrans_cookie, 23170Sstevel@tonic-gate cpu_id, mondo_vec_reg) << 23180Sstevel@tonic-gate INTERRUPT_CPU_FIELD) | 23190Sstevel@tonic-gate INTERRUPT_VALID; 23200Sstevel@tonic-gate #else 23210Sstevel@tonic-gate mondo_vec = (cpu_id << INTERRUPT_CPU_FIELD) | INTERRUPT_VALID; 23220Sstevel@tonic-gate #endif /* _STARFIRE */ 23230Sstevel@tonic-gate 23240Sstevel@tonic-gate /* write it back to the hardware. */ 23250Sstevel@tonic-gate *mondo_vec_reg = mondo_vec; 23260Sstevel@tonic-gate 23270Sstevel@tonic-gate /* flush the hardware buffers. */ 23280Sstevel@tonic-gate tmpreg = *mondo_vec_reg; 23290Sstevel@tonic-gate 23300Sstevel@tonic-gate #ifdef lint 23310Sstevel@tonic-gate tmpreg = tmpreg; 23320Sstevel@tonic-gate #endif /* lint */ 23330Sstevel@tonic-gate } 23340Sstevel@tonic-gate } 23350Sstevel@tonic-gate 23360Sstevel@tonic-gate /* 23370Sstevel@tonic-gate * Reset interrupts to IDLE. This function is called during 23380Sstevel@tonic-gate * panic handling after redistributing interrupts; it's needed to 23390Sstevel@tonic-gate * support dumping to network devices after 'sync' from OBP. 23400Sstevel@tonic-gate * 23410Sstevel@tonic-gate * N.B. This routine runs in a context where all other threads 23420Sstevel@tonic-gate * are permanently suspended. 23430Sstevel@tonic-gate */ 23440Sstevel@tonic-gate static uint_t 23450Sstevel@tonic-gate sbus_intr_reset(void *arg) 23460Sstevel@tonic-gate { 23470Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 23480Sstevel@tonic-gate struct sbus_soft_state *softsp; 23490Sstevel@tonic-gate uint_t mondo; 23500Sstevel@tonic-gate volatile uint64_t *mondo_clear_reg; 23510Sstevel@tonic-gate 23520Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 23530Sstevel@tonic-gate 23540Sstevel@tonic-gate for (mondo = 0; mondo < SZ_INO_TABLE; mondo++) { 23550Sstevel@tonic-gate if (ino_table[mondo] == NULL || 23560Sstevel@tonic-gate ino_table[mondo]->clear_reg == NULL) { 23570Sstevel@tonic-gate 23580Sstevel@tonic-gate continue; 23590Sstevel@tonic-gate } 23600Sstevel@tonic-gate 23610Sstevel@tonic-gate mondo_clear_reg = (softsp->clr_intr_reg + 23620Sstevel@tonic-gate ino_table[mondo]->clear_reg); 23630Sstevel@tonic-gate *mondo_clear_reg = SBUS_INTR_IDLE; 23640Sstevel@tonic-gate } 23650Sstevel@tonic-gate 23660Sstevel@tonic-gate return (BF_NONE); 23670Sstevel@tonic-gate } 23680Sstevel@tonic-gate 23690Sstevel@tonic-gate /* 23700Sstevel@tonic-gate * called from sbus_add_kstats() to create a kstat for each %pic 23710Sstevel@tonic-gate * that the SBUS supports. These (read-only) kstats export the 23720Sstevel@tonic-gate * event names that each %pic supports. 23730Sstevel@tonic-gate * 23740Sstevel@tonic-gate * if we fail to create any of these kstats we must remove any 23750Sstevel@tonic-gate * that we have already created and return; 23760Sstevel@tonic-gate * 23770Sstevel@tonic-gate * NOTE: because all sbus devices use the same events we only 23780Sstevel@tonic-gate * need to create the picN kstats once. All instances can 23790Sstevel@tonic-gate * use the same picN kstats. 23800Sstevel@tonic-gate * 23810Sstevel@tonic-gate * The flexibility exists to allow each device specify it's 23820Sstevel@tonic-gate * own events by creating picN kstats with the instance number 23830Sstevel@tonic-gate * set to ddi_get_instance(softsp->dip). 23840Sstevel@tonic-gate * 23850Sstevel@tonic-gate * When searching for a picN kstat for a device you should 23860Sstevel@tonic-gate * first search for a picN kstat using the instance number 23870Sstevel@tonic-gate * of the device you are interested in. If that fails you 23880Sstevel@tonic-gate * should use the first picN kstat found for that device. 23890Sstevel@tonic-gate */ 23900Sstevel@tonic-gate static void 23910Sstevel@tonic-gate sbus_add_picN_kstats(dev_info_t *dip) 23920Sstevel@tonic-gate { 23930Sstevel@tonic-gate /* 23940Sstevel@tonic-gate * SBUS Performance Events. 23950Sstevel@tonic-gate * 23960Sstevel@tonic-gate * We declare an array of event-names and event-masks. 23970Sstevel@tonic-gate * The num of events in this array is AC_NUM_EVENTS. 23980Sstevel@tonic-gate */ 23990Sstevel@tonic-gate sbus_event_mask_t sbus_events_arr[SBUS_NUM_EVENTS] = { 24000Sstevel@tonic-gate {"dvma_stream_rd", 0x0}, {"dvma_stream_wr", 0x1}, 24010Sstevel@tonic-gate {"dvma_const_rd", 0x2}, {"dvma_const_wr", 0x3}, 24020Sstevel@tonic-gate {"dvma_tlb_misses", 0x4}, {"dvma_stream_buf_mis", 0x5}, 24030Sstevel@tonic-gate {"dvma_cycles", 0x6}, {"dvma_bytes_xfr", 0x7}, 24040Sstevel@tonic-gate {"interrupts", 0x8}, {"upa_inter_nack", 0x9}, 24050Sstevel@tonic-gate {"pio_reads", 0xA}, {"pio_writes", 0xB}, 24060Sstevel@tonic-gate {"sbus_reruns", 0xC}, {"pio_cycles", 0xD} 24070Sstevel@tonic-gate }; 24080Sstevel@tonic-gate 24090Sstevel@tonic-gate /* 24100Sstevel@tonic-gate * We declare an array of clear masks for each pic. 24110Sstevel@tonic-gate * These masks are used to clear the %pcr bits for 24120Sstevel@tonic-gate * each pic. 24130Sstevel@tonic-gate */ 24140Sstevel@tonic-gate sbus_event_mask_t sbus_clear_pic[SBUS_NUM_PICS] = { 24150Sstevel@tonic-gate /* pic0 */ 24160Sstevel@tonic-gate {"clear_pic", (uint64_t)~(0xf)}, 24170Sstevel@tonic-gate /* pic1 */ 24180Sstevel@tonic-gate {"clear_pic", (uint64_t)~(0xf << 8)} 24190Sstevel@tonic-gate }; 24200Sstevel@tonic-gate 24210Sstevel@tonic-gate struct kstat_named *sbus_pic_named_data; 24220Sstevel@tonic-gate int event, pic; 24230Sstevel@tonic-gate char pic_name[30]; 24240Sstevel@tonic-gate int instance = ddi_get_instance(dip); 24250Sstevel@tonic-gate int pic_shift = 0; 24260Sstevel@tonic-gate 24270Sstevel@tonic-gate for (pic = 0; pic < SBUS_NUM_PICS; pic++) { 24280Sstevel@tonic-gate /* 24290Sstevel@tonic-gate * create the picN kstat. The size of this kstat is 24300Sstevel@tonic-gate * SBUS_NUM_EVENTS + 1 for the clear_event_mask 24310Sstevel@tonic-gate */ 24320Sstevel@tonic-gate (void) sprintf(pic_name, "pic%d", pic); /* pic0, pic1 ... */ 24330Sstevel@tonic-gate if ((sbus_picN_ksp[pic] = kstat_create("sbus", 24340Sstevel@tonic-gate instance, pic_name, "bus", KSTAT_TYPE_NAMED, 24350Sstevel@tonic-gate SBUS_NUM_EVENTS + 1, NULL)) == NULL) { 24360Sstevel@tonic-gate cmn_err(CE_WARN, "sbus %s: kstat_create failed", 24370Sstevel@tonic-gate pic_name); 24380Sstevel@tonic-gate 24390Sstevel@tonic-gate /* remove pic0 kstat if pic1 create fails */ 24400Sstevel@tonic-gate if (pic == 1) { 24410Sstevel@tonic-gate kstat_delete(sbus_picN_ksp[0]); 24420Sstevel@tonic-gate sbus_picN_ksp[0] = NULL; 24430Sstevel@tonic-gate } 24440Sstevel@tonic-gate return; 24450Sstevel@tonic-gate } 24460Sstevel@tonic-gate 24470Sstevel@tonic-gate sbus_pic_named_data = 24480Sstevel@tonic-gate (struct kstat_named *)(sbus_picN_ksp[pic]->ks_data); 24490Sstevel@tonic-gate 24500Sstevel@tonic-gate /* 24510Sstevel@tonic-gate * when we are writing pcr_masks to the kstat we need to 24520Sstevel@tonic-gate * shift bits left by 8 for pic1 events. 24530Sstevel@tonic-gate */ 24540Sstevel@tonic-gate if (pic == 1) 24550Sstevel@tonic-gate pic_shift = 8; 24560Sstevel@tonic-gate 24570Sstevel@tonic-gate /* 24580Sstevel@tonic-gate * for each picN event we need to write a kstat record 24590Sstevel@tonic-gate * (name = EVENT, value.ui64 = PCR_MASK) 24600Sstevel@tonic-gate */ 24610Sstevel@tonic-gate for (event = 0; event < SBUS_NUM_EVENTS; event ++) { 24620Sstevel@tonic-gate 24630Sstevel@tonic-gate /* pcr_mask */ 24640Sstevel@tonic-gate sbus_pic_named_data[event].value.ui64 = 24650Sstevel@tonic-gate sbus_events_arr[event].pcr_mask << pic_shift; 24660Sstevel@tonic-gate 24670Sstevel@tonic-gate /* event-name */ 24680Sstevel@tonic-gate kstat_named_init(&sbus_pic_named_data[event], 24690Sstevel@tonic-gate sbus_events_arr[event].event_name, 24700Sstevel@tonic-gate KSTAT_DATA_UINT64); 24710Sstevel@tonic-gate } 24720Sstevel@tonic-gate 24730Sstevel@tonic-gate /* 24740Sstevel@tonic-gate * we add the clear_pic event and mask as the last 24750Sstevel@tonic-gate * record in the kstat 24760Sstevel@tonic-gate */ 24770Sstevel@tonic-gate /* pcr mask */ 24780Sstevel@tonic-gate sbus_pic_named_data[SBUS_NUM_EVENTS].value.ui64 = 24790Sstevel@tonic-gate sbus_clear_pic[pic].pcr_mask; 24800Sstevel@tonic-gate 24810Sstevel@tonic-gate /* event-name */ 24820Sstevel@tonic-gate kstat_named_init(&sbus_pic_named_data[SBUS_NUM_EVENTS], 24830Sstevel@tonic-gate sbus_clear_pic[pic].event_name, 24840Sstevel@tonic-gate KSTAT_DATA_UINT64); 24850Sstevel@tonic-gate 24860Sstevel@tonic-gate kstat_install(sbus_picN_ksp[pic]); 24870Sstevel@tonic-gate } 24880Sstevel@tonic-gate } 24890Sstevel@tonic-gate 24900Sstevel@tonic-gate static void 24910Sstevel@tonic-gate sbus_add_kstats(struct sbus_soft_state *softsp) 24920Sstevel@tonic-gate { 24930Sstevel@tonic-gate struct kstat *sbus_counters_ksp; 24940Sstevel@tonic-gate struct kstat_named *sbus_counters_named_data; 24950Sstevel@tonic-gate 24960Sstevel@tonic-gate /* 24970Sstevel@tonic-gate * Create the picN kstats if we are the first instance 24980Sstevel@tonic-gate * to attach. We use sbus_attachcnt as a count of how 24990Sstevel@tonic-gate * many instances have attached. This is protected by 25000Sstevel@tonic-gate * a mutex. 25010Sstevel@tonic-gate */ 25020Sstevel@tonic-gate mutex_enter(&sbus_attachcnt_mutex); 25030Sstevel@tonic-gate if (sbus_attachcnt == 0) 25040Sstevel@tonic-gate sbus_add_picN_kstats(softsp->dip); 25050Sstevel@tonic-gate 25060Sstevel@tonic-gate sbus_attachcnt ++; 25070Sstevel@tonic-gate mutex_exit(&sbus_attachcnt_mutex); 25080Sstevel@tonic-gate 25090Sstevel@tonic-gate /* 25100Sstevel@tonic-gate * A "counter" kstat is created for each sbus 25110Sstevel@tonic-gate * instance that provides access to the %pcr and %pic 25120Sstevel@tonic-gate * registers for that instance. 25130Sstevel@tonic-gate * 25140Sstevel@tonic-gate * The size of this kstat is SBUS_NUM_PICS + 1 for %pcr 25150Sstevel@tonic-gate */ 25160Sstevel@tonic-gate if ((sbus_counters_ksp = kstat_create("sbus", 25170Sstevel@tonic-gate ddi_get_instance(softsp->dip), "counters", 25180Sstevel@tonic-gate "bus", KSTAT_TYPE_NAMED, SBUS_NUM_PICS + 1, 25190Sstevel@tonic-gate KSTAT_FLAG_WRITABLE)) == NULL) { 25200Sstevel@tonic-gate 25210Sstevel@tonic-gate cmn_err(CE_WARN, "sbus%d counters: kstat_create" 25220Sstevel@tonic-gate " failed", ddi_get_instance(softsp->dip)); 25230Sstevel@tonic-gate return; 25240Sstevel@tonic-gate } 25250Sstevel@tonic-gate 25260Sstevel@tonic-gate sbus_counters_named_data = 25270Sstevel@tonic-gate (struct kstat_named *)(sbus_counters_ksp->ks_data); 25280Sstevel@tonic-gate 25290Sstevel@tonic-gate /* initialize the named kstats */ 25300Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[0], 25310Sstevel@tonic-gate "pcr", KSTAT_DATA_UINT64); 25320Sstevel@tonic-gate 25330Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[1], 25340Sstevel@tonic-gate "pic0", KSTAT_DATA_UINT64); 25350Sstevel@tonic-gate 25360Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[2], 25370Sstevel@tonic-gate "pic1", KSTAT_DATA_UINT64); 25380Sstevel@tonic-gate 25390Sstevel@tonic-gate sbus_counters_ksp->ks_update = sbus_counters_kstat_update; 25400Sstevel@tonic-gate sbus_counters_ksp->ks_private = (void *)softsp; 25410Sstevel@tonic-gate 25420Sstevel@tonic-gate kstat_install(sbus_counters_ksp); 25430Sstevel@tonic-gate 25440Sstevel@tonic-gate /* update the sofstate */ 25450Sstevel@tonic-gate softsp->sbus_counters_ksp = sbus_counters_ksp; 25460Sstevel@tonic-gate } 25470Sstevel@tonic-gate 25480Sstevel@tonic-gate static int 25490Sstevel@tonic-gate sbus_counters_kstat_update(kstat_t *ksp, int rw) 25500Sstevel@tonic-gate { 25510Sstevel@tonic-gate struct kstat_named *sbus_counters_data; 25520Sstevel@tonic-gate struct sbus_soft_state *softsp; 25530Sstevel@tonic-gate uint64_t pic_register; 25540Sstevel@tonic-gate 25550Sstevel@tonic-gate sbus_counters_data = (struct kstat_named *)ksp->ks_data; 25560Sstevel@tonic-gate softsp = (struct sbus_soft_state *)ksp->ks_private; 25570Sstevel@tonic-gate 25580Sstevel@tonic-gate if (rw == KSTAT_WRITE) { 25590Sstevel@tonic-gate 25600Sstevel@tonic-gate /* 25610Sstevel@tonic-gate * Write the pcr value to the softsp->sbus_pcr. 25620Sstevel@tonic-gate * The pic register is read-only so we don't 25630Sstevel@tonic-gate * attempt to write to it. 25640Sstevel@tonic-gate */ 25650Sstevel@tonic-gate 25660Sstevel@tonic-gate *softsp->sbus_pcr = 25670Sstevel@tonic-gate (uint32_t)sbus_counters_data[0].value.ui64; 25680Sstevel@tonic-gate 25690Sstevel@tonic-gate } else { 25700Sstevel@tonic-gate /* 25710Sstevel@tonic-gate * Read %pcr and %pic register values and write them 25720Sstevel@tonic-gate * into counters kstat. 25730Sstevel@tonic-gate * 25740Sstevel@tonic-gate * Due to a hardware bug we need to right shift the %pcr 25750Sstevel@tonic-gate * by 4 bits. This is only done when reading the %pcr. 25760Sstevel@tonic-gate * 25770Sstevel@tonic-gate */ 25780Sstevel@tonic-gate /* pcr */ 25790Sstevel@tonic-gate sbus_counters_data[0].value.ui64 = *softsp->sbus_pcr >> 4; 25800Sstevel@tonic-gate 25810Sstevel@tonic-gate pic_register = *softsp->sbus_pic; 25820Sstevel@tonic-gate /* 25830Sstevel@tonic-gate * sbus pic register: 25840Sstevel@tonic-gate * (63:32) = pic0 25850Sstevel@tonic-gate * (31:00) = pic1 25860Sstevel@tonic-gate */ 25870Sstevel@tonic-gate 25880Sstevel@tonic-gate /* pic0 */ 25890Sstevel@tonic-gate sbus_counters_data[1].value.ui64 = pic_register >> 32; 25900Sstevel@tonic-gate /* pic1 */ 25910Sstevel@tonic-gate sbus_counters_data[2].value.ui64 = 25920Sstevel@tonic-gate pic_register & SBUS_PIC0_MASK; 25930Sstevel@tonic-gate 25940Sstevel@tonic-gate } 25950Sstevel@tonic-gate return (0); 25960Sstevel@tonic-gate } 25970Sstevel@tonic-gate 25980Sstevel@tonic-gate static int 25990Sstevel@tonic-gate sbus_update_intr_state(dev_info_t *dip, dev_info_t *rdip, 26000Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state) 26010Sstevel@tonic-gate { 26020Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 26030Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 26040Sstevel@tonic-gate int ino; 26050Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg; 26060Sstevel@tonic-gate struct sbus_intr_handler *intr_handler; 26070Sstevel@tonic-gate 26080Sstevel@tonic-gate /* Xlate the interrupt */ 2609693Sgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector, 2610693Sgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) { 26110Sstevel@tonic-gate cmn_err(CE_WARN, "sbus_update_intr_state() can't xlate SBUS " 2612693Sgovinda "devices %s interrupt.", ddi_driver_name(rdip)); 26130Sstevel@tonic-gate return (DDI_FAILURE); 26140Sstevel@tonic-gate } 26150Sstevel@tonic-gate 2616693Sgovinda ino = ((int32_t)hdlp->ih_vector) & SBUS_MAX_INO; 26170Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino]; 26180Sstevel@tonic-gate 26190Sstevel@tonic-gate ASSERT(sbus_arg != NULL); 26200Sstevel@tonic-gate ASSERT(sbus_arg->handler_list != NULL); 26210Sstevel@tonic-gate intr_handler = sbus_arg->handler_list; 26220Sstevel@tonic-gate 26230Sstevel@tonic-gate while (intr_handler) { 26240Sstevel@tonic-gate if ((intr_handler->inum == hdlp->ih_inum) && 26250Sstevel@tonic-gate (intr_handler->dip == rdip)) { 26260Sstevel@tonic-gate intr_handler->intr_state = new_intr_state; 26270Sstevel@tonic-gate return (DDI_SUCCESS); 26280Sstevel@tonic-gate } 26290Sstevel@tonic-gate 26300Sstevel@tonic-gate intr_handler = intr_handler->next; 26310Sstevel@tonic-gate } 26320Sstevel@tonic-gate 26330Sstevel@tonic-gate return (DDI_FAILURE); 26340Sstevel@tonic-gate } 2635