17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*a54f81fbSanish * Common Development and Distribution License (the "License"). 6*a54f81fbSanish * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*a54f81fbSanish * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/conf.h> 307c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 317c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 327c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 337c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 347c478bd9Sstevel@tonic-gate #include <sys/ddi_implfuncs.h> 357c478bd9Sstevel@tonic-gate #include <sys/obpdefs.h> 367c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 377c478bd9Sstevel@tonic-gate #include <sys/errno.h> 387c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 397c478bd9Sstevel@tonic-gate #include <sys/debug.h> 407c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 417c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 427c478bd9Sstevel@tonic-gate #include <sys/spl.h> 437c478bd9Sstevel@tonic-gate #include <sys/iommu.h> 447c478bd9Sstevel@tonic-gate #include <sys/sysiosbus.h> 457c478bd9Sstevel@tonic-gate #include <sys/sysioerr.h> 467c478bd9Sstevel@tonic-gate #include <sys/iocache.h> 477c478bd9Sstevel@tonic-gate #include <sys/async.h> 487c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 497c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 507c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 517c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 527c478bd9Sstevel@tonic-gate #include <sys/starfire.h> 537c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 547c478bd9Sstevel@tonic-gate #include <sys/sdt.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* Useful debugging Stuff */ 577c478bd9Sstevel@tonic-gate #include <sys/nexusdebug.h> 587c478bd9Sstevel@tonic-gate /* Bitfield debugging definitions for this file */ 597c478bd9Sstevel@tonic-gate #define SBUS_ATTACH_DEBUG 0x1 607c478bd9Sstevel@tonic-gate #define SBUS_SBUSMEM_DEBUG 0x2 617c478bd9Sstevel@tonic-gate #define SBUS_INTERRUPT_DEBUG 0x4 627c478bd9Sstevel@tonic-gate #define SBUS_REGISTERS_DEBUG 0x8 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * Interrupt registers table. 667c478bd9Sstevel@tonic-gate * This table is necessary due to inconsistencies in the sysio register 677c478bd9Sstevel@tonic-gate * layout. If this gets fixed in the chip, we can get rid of this stupid 687c478bd9Sstevel@tonic-gate * table. 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_1 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 717c478bd9Sstevel@tonic-gate SBUS_SLOT0_L1_CLEAR, NULL}; 727c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_2 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 737c478bd9Sstevel@tonic-gate SBUS_SLOT0_L2_CLEAR, NULL}; 747c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_3 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 757c478bd9Sstevel@tonic-gate SBUS_SLOT0_L3_CLEAR, NULL}; 767c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_4 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 777c478bd9Sstevel@tonic-gate SBUS_SLOT0_L4_CLEAR, NULL}; 787c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_5 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 797c478bd9Sstevel@tonic-gate SBUS_SLOT0_L5_CLEAR, NULL}; 807c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_6 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 817c478bd9Sstevel@tonic-gate SBUS_SLOT0_L6_CLEAR, NULL}; 827c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_7 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG, 837c478bd9Sstevel@tonic-gate SBUS_SLOT0_L7_CLEAR, NULL}; 847c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_9 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 857c478bd9Sstevel@tonic-gate SBUS_SLOT1_L1_CLEAR, NULL}; 867c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_10 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 877c478bd9Sstevel@tonic-gate SBUS_SLOT1_L2_CLEAR, NULL}; 887c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_11 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 897c478bd9Sstevel@tonic-gate SBUS_SLOT1_L3_CLEAR, NULL}; 907c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_12 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 917c478bd9Sstevel@tonic-gate SBUS_SLOT1_L4_CLEAR, NULL}; 927c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_13 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 937c478bd9Sstevel@tonic-gate SBUS_SLOT1_L5_CLEAR, NULL}; 947c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_14 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 957c478bd9Sstevel@tonic-gate SBUS_SLOT1_L6_CLEAR, NULL}; 967c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_15 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG, 977c478bd9Sstevel@tonic-gate SBUS_SLOT1_L7_CLEAR, NULL}; 987c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_17 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 997c478bd9Sstevel@tonic-gate SBUS_SLOT2_L1_CLEAR, NULL}; 1007c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_18 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1017c478bd9Sstevel@tonic-gate SBUS_SLOT2_L2_CLEAR, NULL}; 1027c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_19 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1037c478bd9Sstevel@tonic-gate SBUS_SLOT2_L3_CLEAR, NULL}; 1047c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_20 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1057c478bd9Sstevel@tonic-gate SBUS_SLOT2_L4_CLEAR, NULL}; 1067c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_21 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1077c478bd9Sstevel@tonic-gate SBUS_SLOT2_L5_CLEAR, NULL}; 1087c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_22 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1097c478bd9Sstevel@tonic-gate SBUS_SLOT2_L6_CLEAR, NULL}; 1107c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_23 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG, 1117c478bd9Sstevel@tonic-gate SBUS_SLOT2_L7_CLEAR, NULL}; 1127c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_25 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1137c478bd9Sstevel@tonic-gate SBUS_SLOT3_L1_CLEAR, NULL}; 1147c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_26 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1157c478bd9Sstevel@tonic-gate SBUS_SLOT3_L2_CLEAR, NULL}; 1167c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_27 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1177c478bd9Sstevel@tonic-gate SBUS_SLOT3_L3_CLEAR, NULL}; 1187c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_28 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1197c478bd9Sstevel@tonic-gate SBUS_SLOT3_L4_CLEAR, NULL}; 1207c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_29 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1217c478bd9Sstevel@tonic-gate SBUS_SLOT3_L5_CLEAR, NULL}; 1227c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_30 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1237c478bd9Sstevel@tonic-gate SBUS_SLOT3_L6_CLEAR, NULL}; 1247c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_31 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG, 1257c478bd9Sstevel@tonic-gate SBUS_SLOT3_L7_CLEAR, NULL}; 1267c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_32 = {SBUS_SLOT5_CONFIG, ESP_MAPREG, 1277c478bd9Sstevel@tonic-gate ESP_CLEAR, ESP_INTR_STATE_SHIFT}; 1287c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_33 = {SBUS_SLOT5_CONFIG, ETHER_MAPREG, 1297c478bd9Sstevel@tonic-gate ETHER_CLEAR, ETHER_INTR_STATE_SHIFT}; 1307c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_34 = {SBUS_SLOT5_CONFIG, PP_MAPREG, 1317c478bd9Sstevel@tonic-gate PP_CLEAR, PP_INTR_STATE_SHIFT}; 1327c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_36 = {SBUS_SLOT4_CONFIG, AUDIO_MAPREG, 1337c478bd9Sstevel@tonic-gate AUDIO_CLEAR, AUDIO_INTR_STATE_SHIFT}; 1347c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_40 = {SBUS_SLOT6_CONFIG, KBDMOUSE_MAPREG, 1357c478bd9Sstevel@tonic-gate KBDMOUSE_CLEAR, 1367c478bd9Sstevel@tonic-gate KBDMOUSE_INTR_STATE_SHIFT}; 1377c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_41 = {SBUS_SLOT6_CONFIG, FLOPPY_MAPREG, 1387c478bd9Sstevel@tonic-gate FLOPPY_CLEAR, FLOPPY_INTR_STATE_SHIFT}; 1397c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_42 = {SBUS_SLOT6_CONFIG, THERMAL_MAPREG, 1407c478bd9Sstevel@tonic-gate THERMAL_CLEAR, 1417c478bd9Sstevel@tonic-gate THERMAL_INTR_STATE_SHIFT}; 1427c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_48 = {SBUS_SLOT6_CONFIG, TIMER0_MAPREG, 1437c478bd9Sstevel@tonic-gate TIMER0_CLEAR, TIMER0_INTR_STATE_SHIFT}; 1447c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_49 = {SBUS_SLOT6_CONFIG, TIMER1_MAPREG, 1457c478bd9Sstevel@tonic-gate TIMER1_CLEAR, TIMER1_INTR_STATE_SHIFT}; 1467c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_52 = {SBUS_SLOT6_CONFIG, UE_ECC_MAPREG, 1477c478bd9Sstevel@tonic-gate UE_ECC_CLEAR, UE_INTR_STATE_SHIFT}; 1487c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_53 = {SBUS_SLOT6_CONFIG, CE_ECC_MAPREG, 1497c478bd9Sstevel@tonic-gate CE_ECC_CLEAR, CE_INTR_STATE_SHIFT}; 1507c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_54 = {SBUS_SLOT6_CONFIG, SBUS_ERR_MAPREG, 1517c478bd9Sstevel@tonic-gate SBUS_ERR_CLEAR, SERR_INTR_STATE_SHIFT}; 1527c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_55 = {SBUS_SLOT6_CONFIG, PM_WAKEUP_MAPREG, 1537c478bd9Sstevel@tonic-gate PM_WAKEUP_CLEAR, PM_INTR_STATE_SHIFT}; 1547c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_ffb = {NULL, FFB_MAPPING_REG, NULL, NULL}; 1557c478bd9Sstevel@tonic-gate static struct sbus_slot_entry ino_exp = {NULL, EXP_MAPPING_REG, NULL, NULL}; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* Construct the interrupt number array */ 1587c478bd9Sstevel@tonic-gate struct sbus_slot_entry *ino_table[] = { 1597c478bd9Sstevel@tonic-gate NULL, &ino_1, &ino_2, &ino_3, &ino_4, &ino_5, &ino_6, &ino_7, 1607c478bd9Sstevel@tonic-gate NULL, &ino_9, &ino_10, &ino_11, &ino_12, &ino_13, &ino_14, &ino_15, 1617c478bd9Sstevel@tonic-gate NULL, &ino_17, &ino_18, &ino_19, &ino_20, &ino_21, &ino_22, &ino_23, 1627c478bd9Sstevel@tonic-gate NULL, &ino_25, &ino_26, &ino_27, &ino_28, &ino_29, &ino_30, &ino_31, 1637c478bd9Sstevel@tonic-gate &ino_32, &ino_33, &ino_34, NULL, &ino_36, NULL, NULL, NULL, 1647c478bd9Sstevel@tonic-gate &ino_40, &ino_41, &ino_42, NULL, NULL, NULL, NULL, NULL, &ino_48, 1657c478bd9Sstevel@tonic-gate &ino_49, NULL, NULL, &ino_52, &ino_53, &ino_54, &ino_55, &ino_ffb, 1667c478bd9Sstevel@tonic-gate &ino_exp 1677c478bd9Sstevel@tonic-gate }; 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * This table represents the Fusion interrupt priorities. They range 1717c478bd9Sstevel@tonic-gate * from 1 - 15, so we'll pattern the priorities after the 4M. We map Fusion 1727c478bd9Sstevel@tonic-gate * interrupt number to system priority. The mondo number is used as an 1737c478bd9Sstevel@tonic-gate * index into this table. 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate int interrupt_priorities[] = { 1767c478bd9Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 0 sbus level 1 - 7 */ 1777c478bd9Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 1 sbus level 1 - 7 */ 1787c478bd9Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 2 sbus level 1 - 7 */ 1797c478bd9Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 3 sbus level 1 - 7 */ 1807c478bd9Sstevel@tonic-gate 4, /* Onboard SCSI */ 1817c478bd9Sstevel@tonic-gate 6, /* Onboard Ethernet */ 1827c478bd9Sstevel@tonic-gate 3, /* Onboard Parallel port */ 1837c478bd9Sstevel@tonic-gate -1, /* Not in use */ 1847c478bd9Sstevel@tonic-gate 9, /* Onboard Audio */ 1857c478bd9Sstevel@tonic-gate -1, -1, -1, /* Not in use */ 1867c478bd9Sstevel@tonic-gate 12, /* Onboard keyboard/serial ports */ 1877c478bd9Sstevel@tonic-gate 11, /* Onboard Floppy */ 1887c478bd9Sstevel@tonic-gate 9, /* Thermal interrupt */ 1897c478bd9Sstevel@tonic-gate -1, -1, -1, /* Not is use */ 1907c478bd9Sstevel@tonic-gate 10, /* Timer 0 (tick timer) */ 1917c478bd9Sstevel@tonic-gate 14, /* Timer 1 (not used) */ 1927c478bd9Sstevel@tonic-gate 15, /* Sysio UE ECC error */ 1937c478bd9Sstevel@tonic-gate 10, /* Sysio CE ECC error */ 1947c478bd9Sstevel@tonic-gate 10, /* Sysio Sbus error */ 1957c478bd9Sstevel@tonic-gate 10, /* PM Wakeup */ 1967c478bd9Sstevel@tonic-gate }; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* Interrupt counter flag. To enable/disable spurious interrupt counter. */ 1997c478bd9Sstevel@tonic-gate static int intr_cntr_on; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * Function prototypes. 2037c478bd9Sstevel@tonic-gate */ 2047c478bd9Sstevel@tonic-gate static int 2057c478bd9Sstevel@tonic-gate sbus_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate static int 2087c478bd9Sstevel@tonic-gate sbus_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 2097c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate static void 2127c478bd9Sstevel@tonic-gate sbus_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 2137c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate static int 2167c478bd9Sstevel@tonic-gate sbus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 2177c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate static int 220a195726fSgovinda sbus_xlate_intrs(dev_info_t *dip, dev_info_t *rdip, uint32_t *intr, 221a195726fSgovinda uint32_t *pil, int32_t ign); 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate static int 2247c478bd9Sstevel@tonic-gate sbus_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate static int 2277c478bd9Sstevel@tonic-gate sbus_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate static int 2307c478bd9Sstevel@tonic-gate sbus_do_detach(dev_info_t *devi); 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate static void 2337c478bd9Sstevel@tonic-gate sbus_add_picN_kstats(dev_info_t *dip); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate static void 2367c478bd9Sstevel@tonic-gate sbus_add_kstats(struct sbus_soft_state *); 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate static int 2397c478bd9Sstevel@tonic-gate sbus_counters_kstat_update(kstat_t *, int); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate extern int 2427c478bd9Sstevel@tonic-gate sysio_err_uninit(struct sbus_soft_state *softsp); 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate extern int 2457c478bd9Sstevel@tonic-gate iommu_uninit(struct sbus_soft_state *softsp); 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate extern int 2487c478bd9Sstevel@tonic-gate stream_buf_uninit(struct sbus_soft_state *softsp); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate static int 2517c478bd9Sstevel@tonic-gate find_sbus_slot(dev_info_t *dip, dev_info_t *rdip); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate static void make_sbus_ppd(dev_info_t *child); 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate static int 2567c478bd9Sstevel@tonic-gate sbusmem_initchild(dev_info_t *dip, dev_info_t *child); 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate static int 2597c478bd9Sstevel@tonic-gate sbus_initchild(dev_info_t *dip, dev_info_t *child); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate static int 2627c478bd9Sstevel@tonic-gate sbus_uninitchild(dev_info_t *dip); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate static int 2657c478bd9Sstevel@tonic-gate sbus_ctlops_poke(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args); 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate static int 2687c478bd9Sstevel@tonic-gate sbus_ctlops_peek(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args, 2697c478bd9Sstevel@tonic-gate void *result); 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate static int 2727c478bd9Sstevel@tonic-gate sbus_init(struct sbus_soft_state *softsp, caddr_t address); 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate static int 2757c478bd9Sstevel@tonic-gate sbus_resume_init(struct sbus_soft_state *softsp, int resume); 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate static void 2787c478bd9Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(uint64_t *cpr_softsp, volatile uint64_t *baddr, 2797c478bd9Sstevel@tonic-gate int flag); 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate static void sbus_intrdist(void *); 2827c478bd9Sstevel@tonic-gate static uint_t sbus_intr_reset(void *); 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate static int 2857c478bd9Sstevel@tonic-gate sbus_update_intr_state(dev_info_t *dip, dev_info_t *rdip, 2867c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state); 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 2897c478bd9Sstevel@tonic-gate void 2907c478bd9Sstevel@tonic-gate pc_ittrans_init(int, caddr_t *); 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate void 2937c478bd9Sstevel@tonic-gate pc_ittrans_uninit(caddr_t); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate int 2967c478bd9Sstevel@tonic-gate pc_translate_tgtid(caddr_t, int, volatile uint64_t *); 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate void 2997c478bd9Sstevel@tonic-gate pc_ittrans_cleanup(caddr_t, volatile uint64_t *); 3007c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate /* 3037c478bd9Sstevel@tonic-gate * Configuration data structures 3047c478bd9Sstevel@tonic-gate */ 3057c478bd9Sstevel@tonic-gate static struct bus_ops sbus_bus_ops = { 3067c478bd9Sstevel@tonic-gate BUSO_REV, 3077c478bd9Sstevel@tonic-gate i_ddi_bus_map, 3087c478bd9Sstevel@tonic-gate 0, 3097c478bd9Sstevel@tonic-gate 0, 3107c478bd9Sstevel@tonic-gate 0, 3117c478bd9Sstevel@tonic-gate i_ddi_map_fault, 3127c478bd9Sstevel@tonic-gate iommu_dma_map, 3137c478bd9Sstevel@tonic-gate iommu_dma_allochdl, 3147c478bd9Sstevel@tonic-gate iommu_dma_freehdl, 3157c478bd9Sstevel@tonic-gate iommu_dma_bindhdl, 3167c478bd9Sstevel@tonic-gate iommu_dma_unbindhdl, 3177c478bd9Sstevel@tonic-gate iommu_dma_flush, 3187c478bd9Sstevel@tonic-gate iommu_dma_win, 3197c478bd9Sstevel@tonic-gate iommu_dma_mctl, 3207c478bd9Sstevel@tonic-gate sbus_ctlops, 3217c478bd9Sstevel@tonic-gate ddi_bus_prop_op, 3227c478bd9Sstevel@tonic-gate 0, /* (*bus_get_eventcookie)(); */ 3237c478bd9Sstevel@tonic-gate 0, /* (*bus_add_eventcall)(); */ 3247c478bd9Sstevel@tonic-gate 0, /* (*bus_remove_eventcall)(); */ 3257c478bd9Sstevel@tonic-gate 0, /* (*bus_post_event)(); */ 3267c478bd9Sstevel@tonic-gate 0, /* (*bus_intr_control)(); */ 3277c478bd9Sstevel@tonic-gate 0, /* (*bus_config)(); */ 3287c478bd9Sstevel@tonic-gate 0, /* (*bus_unconfig)(); */ 3297c478bd9Sstevel@tonic-gate 0, /* (*bus_fm_init)(); */ 3307c478bd9Sstevel@tonic-gate 0, /* (*bus_fm_fini)(); */ 3317c478bd9Sstevel@tonic-gate 0, /* (*bus_fm_access_enter)(); */ 3327c478bd9Sstevel@tonic-gate 0, /* (*bus_fm_access_exit)(); */ 3337c478bd9Sstevel@tonic-gate 0, /* (*bus_power)(); */ 3347c478bd9Sstevel@tonic-gate sbus_intr_ops /* (*bus_intr_op)(); */ 3357c478bd9Sstevel@tonic-gate }; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate static struct cb_ops sbus_cb_ops = { 3387c478bd9Sstevel@tonic-gate nodev, /* open */ 3397c478bd9Sstevel@tonic-gate nodev, /* close */ 3407c478bd9Sstevel@tonic-gate nodev, /* strategy */ 3417c478bd9Sstevel@tonic-gate nodev, /* print */ 3427c478bd9Sstevel@tonic-gate nodev, /* dump */ 3437c478bd9Sstevel@tonic-gate nodev, /* read */ 3447c478bd9Sstevel@tonic-gate nodev, /* write */ 3457c478bd9Sstevel@tonic-gate nodev, /* ioctl */ 3467c478bd9Sstevel@tonic-gate nodev, /* devmap */ 3477c478bd9Sstevel@tonic-gate nodev, /* mmap */ 3487c478bd9Sstevel@tonic-gate nodev, /* segmap */ 3497c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 3507c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 3517c478bd9Sstevel@tonic-gate NULL, 3527c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, 3537c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 3547c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 3557c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 3567c478bd9Sstevel@tonic-gate }; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate static struct dev_ops sbus_ops = { 3597c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 3607c478bd9Sstevel@tonic-gate 0, /* refcnt */ 3617c478bd9Sstevel@tonic-gate ddi_no_info, /* info */ 3627c478bd9Sstevel@tonic-gate nulldev, /* identify */ 3637c478bd9Sstevel@tonic-gate nulldev, /* probe */ 3647c478bd9Sstevel@tonic-gate sbus_attach, /* attach */ 3657c478bd9Sstevel@tonic-gate sbus_detach, /* detach */ 3667c478bd9Sstevel@tonic-gate nodev, /* reset */ 3677c478bd9Sstevel@tonic-gate &sbus_cb_ops, /* driver operations */ 3687c478bd9Sstevel@tonic-gate &sbus_bus_ops, /* bus operations */ 3697c478bd9Sstevel@tonic-gate nulldev /* power */ 3707c478bd9Sstevel@tonic-gate }; 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate /* global data */ 3737c478bd9Sstevel@tonic-gate void *sbusp; /* sbus soft state hook */ 3747c478bd9Sstevel@tonic-gate void *sbus_cprp; /* subs suspend/resume soft state hook */ 3757c478bd9Sstevel@tonic-gate static kstat_t *sbus_picN_ksp[SBUS_NUM_PICS]; /* performance picN kstats */ 3767c478bd9Sstevel@tonic-gate static int sbus_attachcnt = 0; /* number of instances attached */ 3777c478bd9Sstevel@tonic-gate static kmutex_t sbus_attachcnt_mutex; /* sbus_attachcnt lock - attach/detach */ 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 3807c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 3837c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 3847c478bd9Sstevel@tonic-gate "SBus (sysio) nexus driver %I%", /* Name of module. */ 3857c478bd9Sstevel@tonic-gate &sbus_ops, /* driver ops */ 3867c478bd9Sstevel@tonic-gate }; 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3897c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 3907c478bd9Sstevel@tonic-gate }; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* 3937c478bd9Sstevel@tonic-gate * These are the module initialization routines. 3947c478bd9Sstevel@tonic-gate */ 3957c478bd9Sstevel@tonic-gate int 3967c478bd9Sstevel@tonic-gate _init(void) 3977c478bd9Sstevel@tonic-gate { 3987c478bd9Sstevel@tonic-gate int error; 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbusp, 4017c478bd9Sstevel@tonic-gate sizeof (struct sbus_soft_state), 1)) != 0) 4027c478bd9Sstevel@tonic-gate return (error); 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate /* 4057c478bd9Sstevel@tonic-gate * Initialize cpr soft state structure 4067c478bd9Sstevel@tonic-gate */ 4077c478bd9Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbus_cprp, 4087c478bd9Sstevel@tonic-gate sizeof (uint64_t) * MAX_INO_TABLE_SIZE, 0)) != 0) 4097c478bd9Sstevel@tonic-gate return (error); 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate /* Initialize global mutex */ 4127c478bd9Sstevel@tonic-gate mutex_init(&sbus_attachcnt_mutex, NULL, MUTEX_DRIVER, NULL); 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate int 4187c478bd9Sstevel@tonic-gate _fini(void) 4197c478bd9Sstevel@tonic-gate { 4207c478bd9Sstevel@tonic-gate int error; 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) 4237c478bd9Sstevel@tonic-gate return (error); 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate mutex_destroy(&sbus_attachcnt_mutex); 4267c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&sbusp); 4277c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&sbus_cprp); 4287c478bd9Sstevel@tonic-gate return (0); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate int 4327c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 4337c478bd9Sstevel@tonic-gate { 4347c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4387c478bd9Sstevel@tonic-gate static int 4397c478bd9Sstevel@tonic-gate sbus_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 4407c478bd9Sstevel@tonic-gate { 4417c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp; 4427c478bd9Sstevel@tonic-gate int instance, error; 4437c478bd9Sstevel@tonic-gate uint64_t *cpr_softsp; 4447c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t attr; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate #ifdef DEBUG 4487c478bd9Sstevel@tonic-gate debug_info = 1; 4497c478bd9Sstevel@tonic-gate debug_print_level = 0; 4507c478bd9Sstevel@tonic-gate #endif 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate switch (cmd) { 4557c478bd9Sstevel@tonic-gate case DDI_ATTACH: 4567c478bd9Sstevel@tonic-gate break; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate case DDI_RESUME: 4597c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate if ((error = iommu_resume_init(softsp)) != DDI_SUCCESS) 4627c478bd9Sstevel@tonic-gate return (error); 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate if ((error = sbus_resume_init(softsp, 1)) != DDI_SUCCESS) 4657c478bd9Sstevel@tonic-gate return (error); 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate if ((error = stream_buf_resume_init(softsp)) != DDI_SUCCESS) 4687c478bd9Sstevel@tonic-gate return (error); 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate /* 4717c478bd9Sstevel@tonic-gate * Restore Interrupt Mapping registers 4727c478bd9Sstevel@tonic-gate */ 4737c478bd9Sstevel@tonic-gate cpr_softsp = ddi_get_soft_state(sbus_cprp, instance); 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate if (cpr_softsp != NULL) { 4767c478bd9Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(cpr_softsp, 4777c478bd9Sstevel@tonic-gate softsp->intr_mapping_reg, 0); 4787c478bd9Sstevel@tonic-gate ddi_soft_state_free(sbus_cprp, instance); 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate default: 4847c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbusp, instance) != DDI_SUCCESS) 4887c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate /* Set the dip in the soft state */ 4937c478bd9Sstevel@tonic-gate softsp->dip = devi; 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate if ((softsp->upa_id = (int)ddi_getprop(DDI_DEV_T_ANY, softsp->dip, 4967c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1)) == -1) { 4977c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Unable to retrieve sbus upa-portid" 4987c478bd9Sstevel@tonic-gate "property."); 4997c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 5007c478bd9Sstevel@tonic-gate goto bad; 5017c478bd9Sstevel@tonic-gate } 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate /* 5047c478bd9Sstevel@tonic-gate * The firmware maps in all 3 pages of the sysio chips device 5057c478bd9Sstevel@tonic-gate * device registers and exports the mapping in the int-sized 5067c478bd9Sstevel@tonic-gate * property "address". Read in this address and pass it to 5077c478bd9Sstevel@tonic-gate * the subsidiary *_init functions, so we don't create extra 5087c478bd9Sstevel@tonic-gate * mappings to the same physical pages and we don't have to 5097c478bd9Sstevel@tonic-gate * retrieve the more than once. 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate /* 5127c478bd9Sstevel@tonic-gate * Implement new policy to start ignoring the "address" property 5137c478bd9Sstevel@tonic-gate * due to new requirements from DR. The problem is that the contents 5147c478bd9Sstevel@tonic-gate * of the "address" property contain vm mappings from OBP which needs 5157c478bd9Sstevel@tonic-gate * to be recaptured into kernel vm. Instead of relying on a blanket 5167c478bd9Sstevel@tonic-gate * recapture during boot time, we map psycho registers each time during 5177c478bd9Sstevel@tonic-gate * attach and unmap the during detach. In some future point of time 5187c478bd9Sstevel@tonic-gate * OBP will drop creating "address" property but this driver will 5197c478bd9Sstevel@tonic-gate * will already not rely on this property any more. 5207c478bd9Sstevel@tonic-gate */ 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 5237c478bd9Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 5247c478bd9Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 5257c478bd9Sstevel@tonic-gate if (ddi_regs_map_setup(softsp->dip, 0, &softsp->address, 0, 0, 5267c478bd9Sstevel@tonic-gate &attr, &softsp->ac) != DDI_SUCCESS) { 5277c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unable to map reg set 0\n", 5287c478bd9Sstevel@tonic-gate ddi_get_name(softsp->dip), 5297c478bd9Sstevel@tonic-gate ddi_get_instance(softsp->dip)); 5307c478bd9Sstevel@tonic-gate return (0); 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate if (softsp->address == (caddr_t)-1) { 5337c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus%d: No sysio <address> property\n", 5347c478bd9Sstevel@tonic-gate ddi_get_instance(softsp->dip)); 5357c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 538ffadc26eSmike_s DPRINTF(SBUS_ATTACH_DEBUG, ("sbus: devi=0x%p, softsp=0x%p\n", 5397c478bd9Sstevel@tonic-gate devi, softsp)); 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate #ifdef notdef 5427c478bd9Sstevel@tonic-gate /* 5437c478bd9Sstevel@tonic-gate * This bit of code, plus the firmware, will tell us if 5447c478bd9Sstevel@tonic-gate * the #size-cells infrastructure code works, to some degree. 5457c478bd9Sstevel@tonic-gate * You should be able to use the firmware to determine if 5467c478bd9Sstevel@tonic-gate * the address returned by ddi_map_regs maps the correct phys. pages. 5477c478bd9Sstevel@tonic-gate */ 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate { 5507c478bd9Sstevel@tonic-gate caddr_t addr; 5517c478bd9Sstevel@tonic-gate int rv; 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: address property = 0x%x\n", address); 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate if ((rv = ddi_map_regs(softsp->dip, 0, &addr, 5567c478bd9Sstevel@tonic-gate (off_t)0, (off_t)0)) != DDI_SUCCESS) { 5577c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: ddi_map_regs failed: %d\n", 5587c478bd9Sstevel@tonic-gate rv); 5597c478bd9Sstevel@tonic-gate } else { 5607c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: ddi_map_regs returned " 5617c478bd9Sstevel@tonic-gate " virtual address 0x%x\n", addr); 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate #endif /* notdef */ 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate if ((error = iommu_init(softsp, softsp->address)) != DDI_SUCCESS) 5677c478bd9Sstevel@tonic-gate goto bad; 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate if ((error = sbus_init(softsp, softsp->address)) != DDI_SUCCESS) 5707c478bd9Sstevel@tonic-gate goto bad; 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate if ((error = sysio_err_init(softsp, softsp->address)) != DDI_SUCCESS) 5737c478bd9Sstevel@tonic-gate goto bad; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate if ((error = stream_buf_init(softsp, softsp->address)) != DDI_SUCCESS) 5767c478bd9Sstevel@tonic-gate goto bad; 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate /* Init the pokefault mutex for sbus devices */ 5797c478bd9Sstevel@tonic-gate mutex_init(&softsp->pokefault_mutex, NULL, MUTEX_SPIN, 5807c478bd9Sstevel@tonic-gate (void *)ipltospl(SBUS_ERR_PIL - 1)); 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate sbus_add_kstats(softsp); 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate bus_func_register(BF_TYPE_RESINTR, sbus_intr_reset, devi); 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate intr_dist_add(sbus_intrdist, devi); 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate ddi_report_dev(devi); 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate bad: 5937c478bd9Sstevel@tonic-gate ddi_soft_state_free(sbusp, instance); 5947c478bd9Sstevel@tonic-gate return (error); 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5987c478bd9Sstevel@tonic-gate static int 5997c478bd9Sstevel@tonic-gate sbus_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 6007c478bd9Sstevel@tonic-gate { 6017c478bd9Sstevel@tonic-gate int instance; 6027c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp; 6037c478bd9Sstevel@tonic-gate uint64_t *cpr_softsp; 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate switch (cmd) { 6067c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 6077c478bd9Sstevel@tonic-gate /* 6087c478bd9Sstevel@tonic-gate * Allocate the cpr soft data structure to save the current 6097c478bd9Sstevel@tonic-gate * state of the interrupt mapping registers. 6107c478bd9Sstevel@tonic-gate * This structure will be deallocated after the system 6117c478bd9Sstevel@tonic-gate * is resumed. 6127c478bd9Sstevel@tonic-gate */ 6137c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbus_cprp, instance) 6167c478bd9Sstevel@tonic-gate != DDI_SUCCESS) 6177c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate cpr_softsp = ddi_get_soft_state(sbus_cprp, instance); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(cpr_softsp, 6247c478bd9Sstevel@tonic-gate softsp->intr_mapping_reg, 1); 6257c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate case DDI_DETACH: 6287c478bd9Sstevel@tonic-gate return (sbus_do_detach(devi)); 6297c478bd9Sstevel@tonic-gate default: 6307c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate static int 6357c478bd9Sstevel@tonic-gate sbus_do_detach(dev_info_t *devi) 6367c478bd9Sstevel@tonic-gate { 6377c478bd9Sstevel@tonic-gate int instance, pic; 6387c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp; 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 6417c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance); 6427c478bd9Sstevel@tonic-gate ASSERT(softsp != NULL); 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate bus_func_unregister(BF_TYPE_RESINTR, sbus_intr_reset, devi); 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate intr_dist_rem(sbus_intrdist, devi); 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* disable the streamming cache */ 6497c478bd9Sstevel@tonic-gate if (stream_buf_uninit(softsp) == DDI_FAILURE) { 6507c478bd9Sstevel@tonic-gate goto err; 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate /* remove the interrupt handlers from the system */ 6547c478bd9Sstevel@tonic-gate if (sysio_err_uninit(softsp) == DDI_FAILURE) { 6557c478bd9Sstevel@tonic-gate goto err; 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate /* disable the IOMMU */ 6597c478bd9Sstevel@tonic-gate if (iommu_uninit(softsp)) { 6607c478bd9Sstevel@tonic-gate goto err; 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* unmap register space if we have a handle */ 6647c478bd9Sstevel@tonic-gate if (softsp->ac) { 6657c478bd9Sstevel@tonic-gate ddi_regs_map_free(&softsp->ac); 6667c478bd9Sstevel@tonic-gate softsp->address = NULL; 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate /* 6707c478bd9Sstevel@tonic-gate * remove counter kstats for this device 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate if (softsp->sbus_counters_ksp != (kstat_t *)NULL) 6737c478bd9Sstevel@tonic-gate kstat_delete(softsp->sbus_counters_ksp); 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate /* 6767c478bd9Sstevel@tonic-gate * if we are the last instance to detach we need to 6777c478bd9Sstevel@tonic-gate * remove the picN kstats. We use sbus_attachcnt as a 6787c478bd9Sstevel@tonic-gate * count of how many instances are still attached. This 6797c478bd9Sstevel@tonic-gate * is protected by a mutex. 6807c478bd9Sstevel@tonic-gate */ 6817c478bd9Sstevel@tonic-gate mutex_enter(&sbus_attachcnt_mutex); 6827c478bd9Sstevel@tonic-gate sbus_attachcnt --; 6837c478bd9Sstevel@tonic-gate if (sbus_attachcnt == 0) { 6847c478bd9Sstevel@tonic-gate for (pic = 0; pic < SBUS_NUM_PICS; pic++) { 6857c478bd9Sstevel@tonic-gate if (sbus_picN_ksp[pic] != (kstat_t *)NULL) { 6867c478bd9Sstevel@tonic-gate kstat_delete(sbus_picN_ksp[pic]); 6877c478bd9Sstevel@tonic-gate sbus_picN_ksp[pic] = NULL; 6887c478bd9Sstevel@tonic-gate } 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate } 6917c478bd9Sstevel@tonic-gate mutex_exit(&sbus_attachcnt_mutex); 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 6947c478bd9Sstevel@tonic-gate /* free starfire specific soft intr mapping structure */ 6957c478bd9Sstevel@tonic-gate pc_ittrans_uninit(softsp->ittrans_cookie); 6967c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate /* free the soft state structure */ 6997c478bd9Sstevel@tonic-gate ddi_soft_state_free(sbusp, instance); 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7027c478bd9Sstevel@tonic-gate err: 7037c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate static int 7077c478bd9Sstevel@tonic-gate sbus_init(struct sbus_soft_state *softsp, caddr_t address) 7087c478bd9Sstevel@tonic-gate { 7097c478bd9Sstevel@tonic-gate int i; 7107c478bd9Sstevel@tonic-gate extern void set_intr_mapping_reg(int, uint64_t *, int); 7117c478bd9Sstevel@tonic-gate int numproxy; 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate /* 7147c478bd9Sstevel@tonic-gate * Simply add each registers offset to the base address 7157c478bd9Sstevel@tonic-gate * to calculate the already mapped virtual address of 7167c478bd9Sstevel@tonic-gate * the device register... 7177c478bd9Sstevel@tonic-gate * 7187c478bd9Sstevel@tonic-gate * define a macro for the pointer arithmetic; all registers 7197c478bd9Sstevel@tonic-gate * are 64 bits wide and are defined as uint64_t's. 7207c478bd9Sstevel@tonic-gate */ 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate #define REG_ADDR(b, o) (uint64_t *)((caddr_t)(b) + (o)) 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate softsp->sysio_ctrl_reg = REG_ADDR(address, OFF_SYSIO_CTRL_REG); 7257c478bd9Sstevel@tonic-gate softsp->sbus_ctrl_reg = REG_ADDR(address, OFF_SBUS_CTRL_REG); 7267c478bd9Sstevel@tonic-gate softsp->sbus_slot_config_reg = REG_ADDR(address, OFF_SBUS_SLOT_CONFIG); 7277c478bd9Sstevel@tonic-gate softsp->intr_mapping_reg = REG_ADDR(address, OFF_INTR_MAPPING_REG); 7287c478bd9Sstevel@tonic-gate softsp->clr_intr_reg = REG_ADDR(address, OFF_CLR_INTR_REG); 7297c478bd9Sstevel@tonic-gate softsp->intr_retry_reg = REG_ADDR(address, OFF_INTR_RETRY_REG); 7307c478bd9Sstevel@tonic-gate softsp->sbus_intr_state = REG_ADDR(address, OFF_SBUS_INTR_STATE_REG); 7317c478bd9Sstevel@tonic-gate softsp->sbus_pcr = REG_ADDR(address, OFF_SBUS_PCR); 7327c478bd9Sstevel@tonic-gate softsp->sbus_pic = REG_ADDR(address, OFF_SBUS_PIC); 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate #undef REG_ADDR 7357c478bd9Sstevel@tonic-gate 736ffadc26eSmike_s DPRINTF(SBUS_REGISTERS_DEBUG, ("SYSIO Control reg: 0x%p\n" 737ffadc26eSmike_s "SBUS Control reg: 0x%p", softsp->sysio_ctrl_reg, 7387c478bd9Sstevel@tonic-gate softsp->sbus_ctrl_reg)); 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 7417c478bd9Sstevel@tonic-gate /* Setup interrupt target translation for starfire */ 7427c478bd9Sstevel@tonic-gate pc_ittrans_init(softsp->upa_id, &softsp->ittrans_cookie); 7437c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate softsp->intr_mapping_ign = 7467c478bd9Sstevel@tonic-gate UPAID_TO_IGN(softsp->upa_id) << IMR_IGN_SHIFT; 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate /* Diag reg 2 is the next 64 bit word after diag reg 1 */ 7497c478bd9Sstevel@tonic-gate softsp->obio_intr_state = softsp->sbus_intr_state + 1; 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate (void) sbus_resume_init(softsp, 0); 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate /* 7547c478bd9Sstevel@tonic-gate * Set the initial burstsizes for each slot to all 1's. This will 7557c478bd9Sstevel@tonic-gate * get changed at initchild time. 7567c478bd9Sstevel@tonic-gate */ 7577c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) 7587c478bd9Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] = 0xffffffffu; 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate /* 7617c478bd9Sstevel@tonic-gate * Since SYSIO is used as an interrupt mastering device for slave 7627c478bd9Sstevel@tonic-gate * only UPA devices, we call a dedicated kernel function to register 7637c478bd9Sstevel@tonic-gate * The address of the interrupt mapping register for the slave device. 7647c478bd9Sstevel@tonic-gate * 7657c478bd9Sstevel@tonic-gate * If RISC/sysio is wired to support 2 upa slave interrupt 7667c478bd9Sstevel@tonic-gate * devices then register 2nd mapping register with system. 7677c478bd9Sstevel@tonic-gate * The slave/proxy portid algorithm (decribed in Fusion Desktop Spec) 7687c478bd9Sstevel@tonic-gate * allows for upto 3 slaves per proxy but Psycho/SYSIO only support 2. 7697c478bd9Sstevel@tonic-gate * 7707c478bd9Sstevel@tonic-gate * #upa-interrupt-proxies property defines how many UPA interrupt 7717c478bd9Sstevel@tonic-gate * slaves a bridge is wired to support. Older systems that lack 7727c478bd9Sstevel@tonic-gate * this property will default to 1. 7737c478bd9Sstevel@tonic-gate */ 7747c478bd9Sstevel@tonic-gate numproxy = ddi_prop_get_int(DDI_DEV_T_ANY, softsp->dip, 7757c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "#upa-interrupt-proxies", 1); 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate if (numproxy > 0) 7787c478bd9Sstevel@tonic-gate set_intr_mapping_reg(softsp->upa_id, 7797c478bd9Sstevel@tonic-gate (uint64_t *)(softsp->intr_mapping_reg + 7807c478bd9Sstevel@tonic-gate FFB_MAPPING_REG), 1); 7817c478bd9Sstevel@tonic-gate 7827c478bd9Sstevel@tonic-gate if (numproxy > 1) 7837c478bd9Sstevel@tonic-gate set_intr_mapping_reg(softsp->upa_id, 7847c478bd9Sstevel@tonic-gate (uint64_t *)(softsp->intr_mapping_reg + 7857c478bd9Sstevel@tonic-gate EXP_MAPPING_REG), 2); 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate /* support for a 3 interrupt proxy would go here */ 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate /* Turn on spurious interrupt counter if we're not a DEBUG kernel. */ 7907c478bd9Sstevel@tonic-gate #ifndef DEBUG 7917c478bd9Sstevel@tonic-gate intr_cntr_on = 1; 7927c478bd9Sstevel@tonic-gate #else 7937c478bd9Sstevel@tonic-gate intr_cntr_on = 0; 7947c478bd9Sstevel@tonic-gate #endif 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7987c478bd9Sstevel@tonic-gate } 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate /* 8017c478bd9Sstevel@tonic-gate * This procedure is part of sbus initialization. It is called by 8027c478bd9Sstevel@tonic-gate * sbus_init() and is invoked when the system is being resumed. 8037c478bd9Sstevel@tonic-gate */ 8047c478bd9Sstevel@tonic-gate static int 8057c478bd9Sstevel@tonic-gate sbus_resume_init(struct sbus_soft_state *softsp, int resume) 8067c478bd9Sstevel@tonic-gate { 8077c478bd9Sstevel@tonic-gate int i; 8087c478bd9Sstevel@tonic-gate uint_t sbus_burst_sizes; 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate /* 8117c478bd9Sstevel@tonic-gate * This shouldn't be needed when we have a real OBP PROM. 8127c478bd9Sstevel@tonic-gate * (RAZ) Get rid of this later!!! 8137c478bd9Sstevel@tonic-gate */ 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 8167c478bd9Sstevel@tonic-gate /* 8177c478bd9Sstevel@tonic-gate * For Starfire, we need to program a 8187c478bd9Sstevel@tonic-gate * constant odd value. 8197c478bd9Sstevel@tonic-gate * Zero out the MID field before ORing 8207c478bd9Sstevel@tonic-gate * We leave the LSB of the MID field intact since 8217c478bd9Sstevel@tonic-gate * we cannot have a zero(even) MID value 8227c478bd9Sstevel@tonic-gate */ 8237c478bd9Sstevel@tonic-gate uint64_t tmpconst = 0x1DULL; 8247c478bd9Sstevel@tonic-gate *softsp->sysio_ctrl_reg &= 0xFF0FFFFFFFFFFFFFULL; 8257c478bd9Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= tmpconst << 51; 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate /* 8287c478bd9Sstevel@tonic-gate * Program in the interrupt group number 8297c478bd9Sstevel@tonic-gate * Here we have to convert the starfire 8307c478bd9Sstevel@tonic-gate * 7 bit upaid into a 5bit value. 8317c478bd9Sstevel@tonic-gate */ 8327c478bd9Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= 8337c478bd9Sstevel@tonic-gate (uint64_t)STARFIRE_UPAID2HWIGN(softsp->upa_id) 8347c478bd9Sstevel@tonic-gate << SYSIO_IGN; 8357c478bd9Sstevel@tonic-gate #else 8367c478bd9Sstevel@tonic-gate /* for the rest of sun4u's */ 8377c478bd9Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= 8387c478bd9Sstevel@tonic-gate (uint64_t)softsp->upa_id << 51; 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate /* Program in the interrupt group number */ 8417c478bd9Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= 8427c478bd9Sstevel@tonic-gate (uint64_t)softsp->upa_id << SYSIO_IGN; 8437c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 8447c478bd9Sstevel@tonic-gate 8457c478bd9Sstevel@tonic-gate /* 8467c478bd9Sstevel@tonic-gate * Set appropriate fields of sbus control register. 8477c478bd9Sstevel@tonic-gate * Set DVMA arbitration enable for all devices. 8487c478bd9Sstevel@tonic-gate */ 8497c478bd9Sstevel@tonic-gate *softsp->sbus_ctrl_reg |= SBUS_ARBIT_ALL; 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate /* Calculate our burstsizes now so we don't have to do it later */ 8527c478bd9Sstevel@tonic-gate sbus_burst_sizes = (SYSIO64_BURST_RANGE << SYSIO64_BURST_SHIFT) 8537c478bd9Sstevel@tonic-gate | SYSIO_BURST_RANGE; 8547c478bd9Sstevel@tonic-gate 8557c478bd9Sstevel@tonic-gate sbus_burst_sizes = ddi_getprop(DDI_DEV_T_ANY, softsp->dip, 8567c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "up-burst-sizes", sbus_burst_sizes); 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate softsp->sbus_burst_sizes = sbus_burst_sizes & SYSIO_BURST_MASK; 8597c478bd9Sstevel@tonic-gate softsp->sbus64_burst_sizes = sbus_burst_sizes & SYSIO64_BURST_MASK; 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate if (!resume) { 8627c478bd9Sstevel@tonic-gate /* Set burstsizes to smallest value */ 8637c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) { 8647c478bd9Sstevel@tonic-gate volatile uint64_t *config; 8657c478bd9Sstevel@tonic-gate uint64_t tmpreg; 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate config = softsp->sbus_slot_config_reg + i; 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate /* Write out the burst size */ 8707c478bd9Sstevel@tonic-gate tmpreg = (uint64_t)0; 8717c478bd9Sstevel@tonic-gate *config = tmpreg; 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate /* Flush any write buffers */ 8747c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate DPRINTF(SBUS_REGISTERS_DEBUG, ("Sbus slot 0x%x slot " 877ffadc26eSmike_s "configuration reg: 0x%p", (i > 3) ? i + 9 : i, 8787c478bd9Sstevel@tonic-gate config)); 8797c478bd9Sstevel@tonic-gate } 8807c478bd9Sstevel@tonic-gate } else { 8817c478bd9Sstevel@tonic-gate /* Program the slot configuration registers */ 8827c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) { 8837c478bd9Sstevel@tonic-gate volatile uint64_t *config; 8847c478bd9Sstevel@tonic-gate #ifndef lint 8857c478bd9Sstevel@tonic-gate uint64_t tmpreg; 8867c478bd9Sstevel@tonic-gate #endif /* !lint */ 8877c478bd9Sstevel@tonic-gate uint_t slave_burstsizes; 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate slave_burstsizes = 0; 8907c478bd9Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[i] != 0xffffffffu) { 8917c478bd9Sstevel@tonic-gate config = softsp->sbus_slot_config_reg + i; 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[i] & 8947c478bd9Sstevel@tonic-gate SYSIO64_BURST_MASK) { 8957c478bd9Sstevel@tonic-gate /* get the 64 bit burstsizes */ 8967c478bd9Sstevel@tonic-gate slave_burstsizes = 8977c478bd9Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] >> 8987c478bd9Sstevel@tonic-gate SYSIO64_BURST_SHIFT; 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate /* Turn on 64 bit PIO's on the sbus */ 9017c478bd9Sstevel@tonic-gate *config |= SBUS_ETM; 9027c478bd9Sstevel@tonic-gate } else { 9037c478bd9Sstevel@tonic-gate slave_burstsizes = 9047c478bd9Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] & 9057c478bd9Sstevel@tonic-gate SYSIO_BURST_MASK; 9067c478bd9Sstevel@tonic-gate } 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate /* Get burstsizes into sysio register format */ 9097c478bd9Sstevel@tonic-gate slave_burstsizes >>= SYSIO_SLAVEBURST_REGSHIFT; 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate /* Program the burstsizes */ 9127c478bd9Sstevel@tonic-gate *config |= (uint64_t)slave_burstsizes; 9137c478bd9Sstevel@tonic-gate 9147c478bd9Sstevel@tonic-gate /* Flush any write buffers */ 9157c478bd9Sstevel@tonic-gate #ifndef lint 9167c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 9177c478bd9Sstevel@tonic-gate #endif /* !lint */ 9187c478bd9Sstevel@tonic-gate } 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate } 9217c478bd9Sstevel@tonic-gate 9227c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9237c478bd9Sstevel@tonic-gate } 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate #define get_prop(di, pname, flag, pval, plen) \ 9267c478bd9Sstevel@tonic-gate (ddi_prop_op(DDI_DEV_T_NONE, di, PROP_LEN_AND_VAL_ALLOC, \ 9277c478bd9Sstevel@tonic-gate flag | DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, \ 9287c478bd9Sstevel@tonic-gate pname, (caddr_t)pval, plen)) 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate struct prop_ispec { 9317c478bd9Sstevel@tonic-gate uint_t pri, vec; 9327c478bd9Sstevel@tonic-gate }; 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate /* 9357c478bd9Sstevel@tonic-gate * Create a sysio_parent_private_data structure from the ddi properties of 9367c478bd9Sstevel@tonic-gate * the dev_info node. 9377c478bd9Sstevel@tonic-gate * 9387c478bd9Sstevel@tonic-gate * The "reg" and either an "intr" or "interrupts" properties are required 9397c478bd9Sstevel@tonic-gate * if the driver wishes to create mappings or field interrupts on behalf 9407c478bd9Sstevel@tonic-gate * of the device. 9417c478bd9Sstevel@tonic-gate * 9427c478bd9Sstevel@tonic-gate * The "reg" property is assumed to be a list of at least one triple 9437c478bd9Sstevel@tonic-gate * 9447c478bd9Sstevel@tonic-gate * <bustype, address, size>*1 9457c478bd9Sstevel@tonic-gate * 9467c478bd9Sstevel@tonic-gate * On pre-fusion machines, the "intr" property was the IPL for the system. 9477c478bd9Sstevel@tonic-gate * Most new sbus devices post an "interrupts" property that corresponds to 9487c478bd9Sstevel@tonic-gate * a particular bus level. All devices on fusion using an "intr" property 9497c478bd9Sstevel@tonic-gate * will have it's contents translated into a bus level. Hence, "intr" and 9507c478bd9Sstevel@tonic-gate * "interrupts on the fusion platform can be treated the same. 9517c478bd9Sstevel@tonic-gate * 9527c478bd9Sstevel@tonic-gate * The "interrupts" property is assumed to be a list of at least one 9537c478bd9Sstevel@tonic-gate * n-tuples that describes the interrupt capabilities of the bus the device 9547c478bd9Sstevel@tonic-gate * is connected to. For SBus, this looks like 9557c478bd9Sstevel@tonic-gate * 9567c478bd9Sstevel@tonic-gate * <SBus-level>*1 9577c478bd9Sstevel@tonic-gate * 9587c478bd9Sstevel@tonic-gate * (This property obsoletes the 'intr' property). 9597c478bd9Sstevel@tonic-gate * 9607c478bd9Sstevel@tonic-gate * The OBP_RANGES property is optional. 9617c478bd9Sstevel@tonic-gate */ 9627c478bd9Sstevel@tonic-gate static void 9637c478bd9Sstevel@tonic-gate make_sbus_ppd(dev_info_t *child) 9647c478bd9Sstevel@tonic-gate { 9657c478bd9Sstevel@tonic-gate struct sysio_parent_private_data *pdptr; 9667c478bd9Sstevel@tonic-gate int n; 9677c478bd9Sstevel@tonic-gate int *reg_prop, *rgstr_prop, *rng_prop; 9687c478bd9Sstevel@tonic-gate int reg_len, rgstr_len, rng_len; 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate /* 9717c478bd9Sstevel@tonic-gate * Make the function idempotent, because name_child could 9727c478bd9Sstevel@tonic-gate * be called multiple times on a node. 9737c478bd9Sstevel@tonic-gate */ 9747c478bd9Sstevel@tonic-gate if (ddi_get_parent_data(child) != NULL) 9757c478bd9Sstevel@tonic-gate return; 9767c478bd9Sstevel@tonic-gate 9777c478bd9Sstevel@tonic-gate pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 9787c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate /* 9817c478bd9Sstevel@tonic-gate * Handle the 'reg'/'registers' properties. 9827c478bd9Sstevel@tonic-gate * "registers" overrides "reg", but requires that "reg" be exported, 9837c478bd9Sstevel@tonic-gate * so we can handle wildcard specifiers. "registers" implies an 9847c478bd9Sstevel@tonic-gate * sbus style device. "registers" implies that we insert the 9857c478bd9Sstevel@tonic-gate * correct value in the regspec_bustype field of each spec for a real 9867c478bd9Sstevel@tonic-gate * (non-pseudo) device node. "registers" is a s/w only property, so 9877c478bd9Sstevel@tonic-gate * we inhibit the prom search for this property. 9887c478bd9Sstevel@tonic-gate */ 9897c478bd9Sstevel@tonic-gate if (get_prop(child, OBP_REG, 0, ®_prop, ®_len) != DDI_SUCCESS) 9907c478bd9Sstevel@tonic-gate reg_len = 0; 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate /* 9937c478bd9Sstevel@tonic-gate * Save the underlying slot number and slot offset. 9947c478bd9Sstevel@tonic-gate * Among other things, we use these to name the child node. 9957c478bd9Sstevel@tonic-gate */ 9967c478bd9Sstevel@tonic-gate pdptr->slot = (uint_t)-1; 9977c478bd9Sstevel@tonic-gate if (reg_len != 0) { 9987c478bd9Sstevel@tonic-gate pdptr->slot = ((struct regspec *)reg_prop)->regspec_bustype; 9997c478bd9Sstevel@tonic-gate pdptr->offset = ((struct regspec *)reg_prop)->regspec_addr; 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate rgstr_len = 0; 10037c478bd9Sstevel@tonic-gate (void) get_prop(child, "registers", DDI_PROP_NOTPROM, 10047c478bd9Sstevel@tonic-gate &rgstr_prop, &rgstr_len); 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate if (rgstr_len != 0) { 10077c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) && (reg_len != 0)) { 10087c478bd9Sstevel@tonic-gate /* 10097c478bd9Sstevel@tonic-gate * Convert wildcard "registers" for a real node... 10107c478bd9Sstevel@tonic-gate * (Else, this is the wildcard prototype node) 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate struct regspec *rp = (struct regspec *)reg_prop; 10137c478bd9Sstevel@tonic-gate uint_t slot = rp->regspec_bustype; 10147c478bd9Sstevel@tonic-gate int i; 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate rp = (struct regspec *)rgstr_prop; 10177c478bd9Sstevel@tonic-gate n = rgstr_len / sizeof (struct regspec); 10187c478bd9Sstevel@tonic-gate for (i = 0; i < n; ++i, ++rp) 10197c478bd9Sstevel@tonic-gate rp->regspec_bustype = slot; 10207c478bd9Sstevel@tonic-gate } 10217c478bd9Sstevel@tonic-gate 10227c478bd9Sstevel@tonic-gate if (reg_len != 0) 10237c478bd9Sstevel@tonic-gate kmem_free(reg_prop, reg_len); 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate reg_prop = rgstr_prop; 10267c478bd9Sstevel@tonic-gate reg_len = rgstr_len; 10277c478bd9Sstevel@tonic-gate } 10287c478bd9Sstevel@tonic-gate if (reg_len != 0) { 10297c478bd9Sstevel@tonic-gate pdptr->par_nreg = reg_len / (int)sizeof (struct regspec); 10307c478bd9Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop; 10317c478bd9Sstevel@tonic-gate } 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate /* 10347c478bd9Sstevel@tonic-gate * See if I have ranges. 10357c478bd9Sstevel@tonic-gate */ 10367c478bd9Sstevel@tonic-gate if (get_prop(child, OBP_RANGES, 0, &rng_prop, &rng_len) == 10377c478bd9Sstevel@tonic-gate DDI_SUCCESS) { 10387c478bd9Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 10397c478bd9Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop; 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate /* 10447c478bd9Sstevel@tonic-gate * Special handling for "sbusmem" pseudo device nodes. 10457c478bd9Sstevel@tonic-gate * The special handling automatically creates the "reg" 10467c478bd9Sstevel@tonic-gate * property in the sbusmem nodes, based on the parent's 10477c478bd9Sstevel@tonic-gate * property so that each slot will automtically have a 10487c478bd9Sstevel@tonic-gate * correctly sized "reg" property, once created, 10497c478bd9Sstevel@tonic-gate * sbus_initchild does the rest of the work to init 10507c478bd9Sstevel@tonic-gate * the child node. 10517c478bd9Sstevel@tonic-gate */ 10527c478bd9Sstevel@tonic-gate static int 10537c478bd9Sstevel@tonic-gate sbusmem_initchild(dev_info_t *dip, dev_info_t *child) 10547c478bd9Sstevel@tonic-gate { 10557c478bd9Sstevel@tonic-gate int i, n; 10567c478bd9Sstevel@tonic-gate int slot, size; 10577c478bd9Sstevel@tonic-gate char ident[10]; 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate slot = ddi_getprop(DDI_DEV_T_NONE, child, 10607c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "slot", -1); 10617c478bd9Sstevel@tonic-gate if (slot == -1) { 10627c478bd9Sstevel@tonic-gate DPRINTF(SBUS_SBUSMEM_DEBUG, ("can't get slot property\n")); 10637c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10647c478bd9Sstevel@tonic-gate } 10657c478bd9Sstevel@tonic-gate 10667c478bd9Sstevel@tonic-gate /* 10677c478bd9Sstevel@tonic-gate * Find the parent range corresponding to this "slot", 10687c478bd9Sstevel@tonic-gate * so we can set the size of the child's "reg" property. 10697c478bd9Sstevel@tonic-gate */ 10707c478bd9Sstevel@tonic-gate for (i = 0, n = sparc_pd_getnrng(dip); i < n; i++) { 10717c478bd9Sstevel@tonic-gate struct rangespec *rp = sparc_pd_getrng(dip, i); 10727c478bd9Sstevel@tonic-gate 10737c478bd9Sstevel@tonic-gate if (rp->rng_cbustype == (uint_t)slot) { 10747c478bd9Sstevel@tonic-gate struct regspec r; 10757c478bd9Sstevel@tonic-gate 10767c478bd9Sstevel@tonic-gate /* create reg property */ 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate r.regspec_bustype = (uint_t)slot; 10797c478bd9Sstevel@tonic-gate r.regspec_addr = 0; 10807c478bd9Sstevel@tonic-gate r.regspec_size = rp->rng_size; 10817c478bd9Sstevel@tonic-gate (void) ddi_prop_update_int_array(DDI_DEV_T_NONE, 10827c478bd9Sstevel@tonic-gate child, "reg", (int *)&r, 10837c478bd9Sstevel@tonic-gate sizeof (struct regspec) / sizeof (int)); 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate /* create size property for slot */ 10867c478bd9Sstevel@tonic-gate 10877c478bd9Sstevel@tonic-gate size = rp->rng_size; 10887c478bd9Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE, 10897c478bd9Sstevel@tonic-gate child, "size", size); 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate (void) sprintf(ident, "slot%x", slot); 10927c478bd9Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE, 10937c478bd9Sstevel@tonic-gate child, "ident", ident); 10947c478bd9Sstevel@tonic-gate 10957c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10967c478bd9Sstevel@tonic-gate } 10977c478bd9Sstevel@tonic-gate } 10987c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10997c478bd9Sstevel@tonic-gate } 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate /* 11027c478bd9Sstevel@tonic-gate * Nexus routine to name a child. 11037c478bd9Sstevel@tonic-gate * It takes a dev_info node and a buffer, returns the name 11047c478bd9Sstevel@tonic-gate * in the buffer. 11057c478bd9Sstevel@tonic-gate */ 11067c478bd9Sstevel@tonic-gate static int 11077c478bd9Sstevel@tonic-gate sysio_name_child(dev_info_t *child, char *name, int namelen) 11087c478bd9Sstevel@tonic-gate { 11097c478bd9Sstevel@tonic-gate /* 11107c478bd9Sstevel@tonic-gate * Fill in parent-private data 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate make_sbus_ppd(child); 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate /* 11157c478bd9Sstevel@tonic-gate * Name the device node using the underlying (prom) values 11167c478bd9Sstevel@tonic-gate * of the first entry in the "reg" property. For SBus devices, 11177c478bd9Sstevel@tonic-gate * the textual form of the name is <name>@<slot#>,<offset>. 11187c478bd9Sstevel@tonic-gate * This must match the prom's pathname or mountroot, etc, won't 11197c478bd9Sstevel@tonic-gate */ 11207c478bd9Sstevel@tonic-gate name[0] = '\0'; 11217c478bd9Sstevel@tonic-gate if (sysio_pd_getslot(child) != (uint_t)-1) { 11227c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 11237c478bd9Sstevel@tonic-gate sysio_pd_getslot(child), sysio_pd_getoffset(child)); 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 11267c478bd9Sstevel@tonic-gate } 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate /* 11297c478bd9Sstevel@tonic-gate * Called from the bus_ctl op of sysio sbus nexus driver 11307c478bd9Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names 11317c478bd9Sstevel@tonic-gate * the children of sysio sbusses based on the reg spec. 11327c478bd9Sstevel@tonic-gate * 11337c478bd9Sstevel@tonic-gate * Handles the following properties: 11347c478bd9Sstevel@tonic-gate * 11357c478bd9Sstevel@tonic-gate * Property value 11367c478bd9Sstevel@tonic-gate * Name type 11377c478bd9Sstevel@tonic-gate * 11387c478bd9Sstevel@tonic-gate * reg register spec 11397c478bd9Sstevel@tonic-gate * registers wildcard s/w sbus register spec (.conf file property) 11407c478bd9Sstevel@tonic-gate * intr old-form interrupt spec 11417c478bd9Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec 11427c478bd9Sstevel@tonic-gate * ranges range spec 11437c478bd9Sstevel@tonic-gate */ 11447c478bd9Sstevel@tonic-gate static int 11457c478bd9Sstevel@tonic-gate sbus_initchild(dev_info_t *dip, dev_info_t *child) 11467c478bd9Sstevel@tonic-gate { 11477c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 11487c478bd9Sstevel@tonic-gate ulong_t slave_burstsizes; 11497c478bd9Sstevel@tonic-gate int slot; 11507c478bd9Sstevel@tonic-gate volatile uint64_t *slot_reg; 11517c478bd9Sstevel@tonic-gate #ifndef lint 11527c478bd9Sstevel@tonic-gate uint64_t tmp; 11537c478bd9Sstevel@tonic-gate #endif /* !lint */ 11547c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 11557c478bd9Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 11567c478bd9Sstevel@tonic-gate 11577c478bd9Sstevel@tonic-gate if (strcmp(ddi_get_name(child), "sbusmem") == 0) { 11587c478bd9Sstevel@tonic-gate if (sbusmem_initchild(dip, child) != DDI_SUCCESS) 11597c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 11607c478bd9Sstevel@tonic-gate } 11617c478bd9Sstevel@tonic-gate 11627c478bd9Sstevel@tonic-gate /* 11637c478bd9Sstevel@tonic-gate * If this is a s/w node defined with the "registers" property, 11647c478bd9Sstevel@tonic-gate * this means that this is a wildcard specifier, whose properties 11657c478bd9Sstevel@tonic-gate * get applied to all previously defined h/w nodes with the same 11667c478bd9Sstevel@tonic-gate * name and same parent. 11677c478bd9Sstevel@tonic-gate */ 11687c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 11697c478bd9Sstevel@tonic-gate int len = 0; 11707c478bd9Sstevel@tonic-gate if ((ddi_getproplen(DDI_DEV_T_ANY, child, DDI_PROP_NOTPROM, 11717c478bd9Sstevel@tonic-gate "registers", &len) == DDI_SUCCESS) && (len != 0)) { 11727c478bd9Sstevel@tonic-gate ndi_merge_wildcard_node(child); 11737c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 11747c478bd9Sstevel@tonic-gate } 11757c478bd9Sstevel@tonic-gate } 11767c478bd9Sstevel@tonic-gate 11777c478bd9Sstevel@tonic-gate /* name the child */ 11787c478bd9Sstevel@tonic-gate (void) sysio_name_child(child, name, MAXNAMELEN); 11797c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 11807c478bd9Sstevel@tonic-gate 11817c478bd9Sstevel@tonic-gate /* 11827c478bd9Sstevel@tonic-gate * If a pseudo node, attempt to merge it into a hw node. 11837c478bd9Sstevel@tonic-gate * If merge is successful, we uinitialize the node and 11847c478bd9Sstevel@tonic-gate * return failure, to allow caller to remove the node. 11857c478bd9Sstevel@tonic-gate * The merge fails, this is a real pseudo node. Allow 11867c478bd9Sstevel@tonic-gate * initchild to continue. 11877c478bd9Sstevel@tonic-gate */ 11887c478bd9Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && 11897c478bd9Sstevel@tonic-gate (ndi_merge_node(child, sysio_name_child) == DDI_SUCCESS)) { 11907c478bd9Sstevel@tonic-gate (void) sbus_uninitchild(child); 11917c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate /* Figure out the child devices slot number */ 11957c478bd9Sstevel@tonic-gate slot = sysio_pd_getslot(child); 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate /* If we don't have a reg property, bypass slot specific programming */ 11987c478bd9Sstevel@tonic-gate if (slot < 0 || slot >= MAX_SBUS_SLOT_ADDR) { 11997c478bd9Sstevel@tonic-gate #ifdef DEBUG 12007c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "?Invalid sbus slot address 0x%x for %s " 12017c478bd9Sstevel@tonic-gate "device\n", slot, ddi_get_name(child)); 12027c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 12037c478bd9Sstevel@tonic-gate goto done; 12047c478bd9Sstevel@tonic-gate } 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate /* Modify the onboard slot numbers if applicable. */ 12077c478bd9Sstevel@tonic-gate slot = (slot > 3) ? slot - 9 : slot; 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate /* Get the slot configuration register for the child device. */ 12107c478bd9Sstevel@tonic-gate slot_reg = softsp->sbus_slot_config_reg + slot; 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate /* 12137c478bd9Sstevel@tonic-gate * Program the devices slot configuration register for the 12147c478bd9Sstevel@tonic-gate * appropriate slave burstsizes. 12157c478bd9Sstevel@tonic-gate * The upper 16 bits of the slave-burst-sizes are for 64 bit sbus 12167c478bd9Sstevel@tonic-gate * and the lower 16 bits are the burst sizes for 32 bit sbus. If 12177c478bd9Sstevel@tonic-gate * we see that a device supports both 64 bit and 32 bit slave accesses, 12187c478bd9Sstevel@tonic-gate * we default to 64 bit and turn it on in the slot config reg. 12197c478bd9Sstevel@tonic-gate * 12207c478bd9Sstevel@tonic-gate * For older devices, make sure we check the "burst-sizes" property 12217c478bd9Sstevel@tonic-gate * too. 12227c478bd9Sstevel@tonic-gate */ 12237c478bd9Sstevel@tonic-gate if ((slave_burstsizes = (ulong_t)ddi_getprop(DDI_DEV_T_ANY, child, 12247c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "slave-burst-sizes", 0)) != 0 || 12257c478bd9Sstevel@tonic-gate (slave_burstsizes = (ulong_t)ddi_getprop(DDI_DEV_T_ANY, child, 12267c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "burst-sizes", 0)) != 0) { 12277c478bd9Sstevel@tonic-gate uint_t burstsizes = 0; 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate /* 12307c478bd9Sstevel@tonic-gate * If we only have 32 bit burst sizes from a previous device, 12317c478bd9Sstevel@tonic-gate * mask out any burstsizes for 64 bit mode. 12327c478bd9Sstevel@tonic-gate */ 12337c478bd9Sstevel@tonic-gate if (((softsp->sbus_slave_burstsizes[slot] & 12347c478bd9Sstevel@tonic-gate 0xffff0000u) == 0) && 12357c478bd9Sstevel@tonic-gate ((softsp->sbus_slave_burstsizes[slot] & 0xffff) != 0)) { 12367c478bd9Sstevel@tonic-gate slave_burstsizes &= 0xffff; 12377c478bd9Sstevel@tonic-gate } 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate /* 12407c478bd9Sstevel@tonic-gate * If "slave-burst-sizes was defined but we have 0 at this 12417c478bd9Sstevel@tonic-gate * point, we must have had 64 bit burstsizes, however a prior 12427c478bd9Sstevel@tonic-gate * device can only burst in 32 bit mode. Therefore, we leave 12437c478bd9Sstevel@tonic-gate * the burstsizes in the 32 bit mode and disregard the 64 bit. 12447c478bd9Sstevel@tonic-gate */ 12457c478bd9Sstevel@tonic-gate if (slave_burstsizes == 0) 12467c478bd9Sstevel@tonic-gate goto done; 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate /* 12497c478bd9Sstevel@tonic-gate * We and in the new burst sizes with that of prior devices. 12507c478bd9Sstevel@tonic-gate * This ensures that we always take the least common 12517c478bd9Sstevel@tonic-gate * denominator of the burst sizes. 12527c478bd9Sstevel@tonic-gate */ 12537c478bd9Sstevel@tonic-gate softsp->sbus_slave_burstsizes[slot] &= 12547c478bd9Sstevel@tonic-gate (slave_burstsizes & 12557c478bd9Sstevel@tonic-gate ((SYSIO64_SLAVEBURST_RANGE << 12567c478bd9Sstevel@tonic-gate SYSIO64_BURST_SHIFT) | 12577c478bd9Sstevel@tonic-gate SYSIO_SLAVEBURST_RANGE)); 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate /* Get the 64 bit burstsizes. */ 12607c478bd9Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[slot] & 12617c478bd9Sstevel@tonic-gate SYSIO64_BURST_MASK) { 12627c478bd9Sstevel@tonic-gate /* get the 64 bit burstsizes */ 12637c478bd9Sstevel@tonic-gate burstsizes = softsp->sbus_slave_burstsizes[slot] >> 12647c478bd9Sstevel@tonic-gate SYSIO64_BURST_SHIFT; 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate /* Turn on 64 bit PIO's on the sbus */ 12677c478bd9Sstevel@tonic-gate *slot_reg |= SBUS_ETM; 12687c478bd9Sstevel@tonic-gate } else { 12697c478bd9Sstevel@tonic-gate /* Turn off 64 bit PIO's on the sbus */ 12707c478bd9Sstevel@tonic-gate *slot_reg &= ~SBUS_ETM; 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate /* Get the 32 bit burstsizes if we don't have 64 bit. */ 12737c478bd9Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[slot] & 12747c478bd9Sstevel@tonic-gate SYSIO_BURST_MASK) { 12757c478bd9Sstevel@tonic-gate burstsizes = 12767c478bd9Sstevel@tonic-gate softsp->sbus_slave_burstsizes[slot] & 12777c478bd9Sstevel@tonic-gate SYSIO_BURST_MASK; 12787c478bd9Sstevel@tonic-gate } 12797c478bd9Sstevel@tonic-gate } 12807c478bd9Sstevel@tonic-gate 12817c478bd9Sstevel@tonic-gate /* Get the burstsizes into sysio register format */ 12827c478bd9Sstevel@tonic-gate burstsizes >>= SYSIO_SLAVEBURST_REGSHIFT; 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate /* Reset reg in case we're scaling back */ 12857c478bd9Sstevel@tonic-gate *slot_reg &= (uint64_t)~SYSIO_SLAVEBURST_MASK; 12867c478bd9Sstevel@tonic-gate 12877c478bd9Sstevel@tonic-gate /* Program the burstsizes */ 12887c478bd9Sstevel@tonic-gate *slot_reg |= (uint64_t)burstsizes; 12897c478bd9Sstevel@tonic-gate 12907c478bd9Sstevel@tonic-gate /* Flush system load/store buffers */ 12917c478bd9Sstevel@tonic-gate #ifndef lint 12927c478bd9Sstevel@tonic-gate tmp = *slot_reg; 12937c478bd9Sstevel@tonic-gate #endif /* !lint */ 12947c478bd9Sstevel@tonic-gate } 12957c478bd9Sstevel@tonic-gate 12967c478bd9Sstevel@tonic-gate done: 12977c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate static int 13017c478bd9Sstevel@tonic-gate sbus_uninitchild(dev_info_t *dip) 13027c478bd9Sstevel@tonic-gate { 13037c478bd9Sstevel@tonic-gate struct sysio_parent_private_data *pdptr; 13047c478bd9Sstevel@tonic-gate size_t n; 13057c478bd9Sstevel@tonic-gate 13067c478bd9Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) != NULL) { 13077c478bd9Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nrng) != 0) 13087c478bd9Sstevel@tonic-gate kmem_free(pdptr->par_rng, n * 13097c478bd9Sstevel@tonic-gate sizeof (struct rangespec)); 13107c478bd9Sstevel@tonic-gate 13117c478bd9Sstevel@tonic-gate if ((n = pdptr->par_nreg) != 0) 13127c478bd9Sstevel@tonic-gate kmem_free(pdptr->par_reg, n * sizeof (struct regspec)); 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr)); 13157c478bd9Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 13167c478bd9Sstevel@tonic-gate } 13177c478bd9Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 13187c478bd9Sstevel@tonic-gate /* 13197c478bd9Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 13207c478bd9Sstevel@tonic-gate */ 13217c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 13227c478bd9Sstevel@tonic-gate impl_rem_dev_props(dip); 13237c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 13247c478bd9Sstevel@tonic-gate } 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate #ifdef DEBUG 13277c478bd9Sstevel@tonic-gate int sbus_peekfault_cnt = 0; 13287c478bd9Sstevel@tonic-gate int sbus_pokefault_cnt = 0; 13297c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate static int 13327c478bd9Sstevel@tonic-gate sbus_ctlops_poke(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args) 13337c478bd9Sstevel@tonic-gate { 13347c478bd9Sstevel@tonic-gate int err = DDI_SUCCESS; 13357c478bd9Sstevel@tonic-gate on_trap_data_t otd; 13367c478bd9Sstevel@tonic-gate volatile uint64_t tmpreg; 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate /* Cautious access not supported. */ 13397c478bd9Sstevel@tonic-gate if (in_args->handle != NULL) 13407c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate mutex_enter(&softsp->pokefault_mutex); 13437c478bd9Sstevel@tonic-gate softsp->ontrap_data = &otd; 13447c478bd9Sstevel@tonic-gate 13457c478bd9Sstevel@tonic-gate /* Set up protected environment. */ 13467c478bd9Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 13477c478bd9Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault; 13507c478bd9Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr, 13517c478bd9Sstevel@tonic-gate (void *)in_args->host_addr); 13527c478bd9Sstevel@tonic-gate otd.ot_trampoline = tramp; 13537c478bd9Sstevel@tonic-gate } else 13547c478bd9Sstevel@tonic-gate err = DDI_FAILURE; 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate /* Flush any sbus store buffers. */ 13577c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate /* 13607c478bd9Sstevel@tonic-gate * Read the sbus error reg and see if a fault occured. If 13617c478bd9Sstevel@tonic-gate * one has, give the SYSIO time to packetize the interrupt 13627c478bd9Sstevel@tonic-gate * for the fault and send it out. The sbus error handler will 13637c478bd9Sstevel@tonic-gate * 0 these fields when it's called to service the fault. 13647c478bd9Sstevel@tonic-gate */ 13657c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_err_reg; 13667c478bd9Sstevel@tonic-gate while (tmpreg & SB_AFSR_P_TO || tmpreg & SB_AFSR_P_BERR) 13677c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_err_reg; 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate /* Take down protected environment. */ 13707c478bd9Sstevel@tonic-gate no_trap(); 13717c478bd9Sstevel@tonic-gate 13727c478bd9Sstevel@tonic-gate softsp->ontrap_data = NULL; 13737c478bd9Sstevel@tonic-gate mutex_exit(&softsp->pokefault_mutex); 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate #ifdef DEBUG 13767c478bd9Sstevel@tonic-gate if (err == DDI_FAILURE) 13777c478bd9Sstevel@tonic-gate sbus_pokefault_cnt++; 13787c478bd9Sstevel@tonic-gate #endif 13797c478bd9Sstevel@tonic-gate return (err); 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 13837c478bd9Sstevel@tonic-gate static int 13847c478bd9Sstevel@tonic-gate sbus_ctlops_peek(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args, 13857c478bd9Sstevel@tonic-gate void *result) 13867c478bd9Sstevel@tonic-gate { 13877c478bd9Sstevel@tonic-gate int err = DDI_SUCCESS; 13887c478bd9Sstevel@tonic-gate on_trap_data_t otd; 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate /* No safe access except for peek is supported. */ 13917c478bd9Sstevel@tonic-gate if (in_args->handle != NULL) 13927c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 13957c478bd9Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 13967c478bd9Sstevel@tonic-gate 13977c478bd9Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault; 13987c478bd9Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr, 13997c478bd9Sstevel@tonic-gate (void *)in_args->host_addr); 14007c478bd9Sstevel@tonic-gate otd.ot_trampoline = tramp; 14017c478bd9Sstevel@tonic-gate result = (void *)in_args->host_addr; 14027c478bd9Sstevel@tonic-gate } else 14037c478bd9Sstevel@tonic-gate err = DDI_FAILURE; 14047c478bd9Sstevel@tonic-gate 14057c478bd9Sstevel@tonic-gate #ifdef DEBUG 14067c478bd9Sstevel@tonic-gate if (err == DDI_FAILURE) 14077c478bd9Sstevel@tonic-gate sbus_peekfault_cnt++; 14087c478bd9Sstevel@tonic-gate #endif 14097c478bd9Sstevel@tonic-gate no_trap(); 14107c478bd9Sstevel@tonic-gate return (err); 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate 14137c478bd9Sstevel@tonic-gate static int 14147c478bd9Sstevel@tonic-gate sbus_ctlops(dev_info_t *dip, dev_info_t *rdip, 14157c478bd9Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result) 14167c478bd9Sstevel@tonic-gate { 14177c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 14187c478bd9Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 14197c478bd9Sstevel@tonic-gate 14207c478bd9Sstevel@tonic-gate switch (op) { 14217c478bd9Sstevel@tonic-gate 14227c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 14237c478bd9Sstevel@tonic-gate return (sbus_initchild(dip, (dev_info_t *)arg)); 14247c478bd9Sstevel@tonic-gate 14257c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 14267c478bd9Sstevel@tonic-gate return (sbus_uninitchild(arg)); 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: { 14297c478bd9Sstevel@tonic-gate int val = *((int *)result); 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate /* 14327c478bd9Sstevel@tonic-gate * The 'arg' value of nonzero indicates 'streaming' mode. 14337c478bd9Sstevel@tonic-gate * If in streaming mode, pick the largest of our burstsizes 14347c478bd9Sstevel@tonic-gate * available and say that that is our minimum value (modulo 14357c478bd9Sstevel@tonic-gate * what mincycle is). 14367c478bd9Sstevel@tonic-gate */ 1437ffadc26eSmike_s if ((int)(uintptr_t)arg) 14387c478bd9Sstevel@tonic-gate val = maxbit(val, 14397c478bd9Sstevel@tonic-gate (1 << (ddi_fls(softsp->sbus_burst_sizes) - 1))); 14407c478bd9Sstevel@tonic-gate else 14417c478bd9Sstevel@tonic-gate val = maxbit(val, 14427c478bd9Sstevel@tonic-gate (1 << (ddi_ffs(softsp->sbus_burst_sizes) - 1))); 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate *((int *)result) = val; 14457c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: { 14497c478bd9Sstevel@tonic-gate dev_info_t *pdev; 14507c478bd9Sstevel@tonic-gate int i, n, len, f_len; 14517c478bd9Sstevel@tonic-gate char *msgbuf; 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate /* 14547c478bd9Sstevel@tonic-gate * So we can do one atomic cmn_err call, we allocate a 4k 14557c478bd9Sstevel@tonic-gate * buffer, and format the reportdev message into that buffer, 14567c478bd9Sstevel@tonic-gate * send it to cmn_err, and then free the allocated buffer. 14577c478bd9Sstevel@tonic-gate * If message is longer than 1k, the message is truncated and 14587c478bd9Sstevel@tonic-gate * an error message is emitted (debug kernel only). 14597c478bd9Sstevel@tonic-gate */ 14607c478bd9Sstevel@tonic-gate #define REPORTDEV_BUFSIZE 1024 14617c478bd9Sstevel@tonic-gate 14627c478bd9Sstevel@tonic-gate int sbusid = ddi_get_instance(dip); 14637c478bd9Sstevel@tonic-gate 14647c478bd9Sstevel@tonic-gate if (ddi_get_parent_data(rdip) == NULL) 14657c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 14667c478bd9Sstevel@tonic-gate 14677c478bd9Sstevel@tonic-gate msgbuf = kmem_zalloc(REPORTDEV_BUFSIZE, KM_SLEEP); 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate pdev = ddi_get_parent(rdip); 14707c478bd9Sstevel@tonic-gate f_len = snprintf(msgbuf, REPORTDEV_BUFSIZE, 14717c478bd9Sstevel@tonic-gate "%s%d at %s%d: SBus%d ", 14727c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 14737c478bd9Sstevel@tonic-gate ddi_driver_name(pdev), ddi_get_instance(pdev), sbusid); 14747c478bd9Sstevel@tonic-gate len = strlen(msgbuf); 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate for (i = 0, n = sysio_pd_getnreg(rdip); i < n; i++) { 14777c478bd9Sstevel@tonic-gate struct regspec *rp; 14787c478bd9Sstevel@tonic-gate 14797c478bd9Sstevel@tonic-gate rp = sysio_pd_getreg(rdip, i); 14807c478bd9Sstevel@tonic-gate if (i != 0) { 14817c478bd9Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 14827c478bd9Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, " and "); 14837c478bd9Sstevel@tonic-gate len = strlen(msgbuf); 14847c478bd9Sstevel@tonic-gate } 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate f_len += snprintf(msgbuf + len, REPORTDEV_BUFSIZE - len, 14877c478bd9Sstevel@tonic-gate "slot 0x%x offset 0x%x", 14887c478bd9Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_addr); 14897c478bd9Sstevel@tonic-gate len = strlen(msgbuf); 14907c478bd9Sstevel@tonic-gate } 14917c478bd9Sstevel@tonic-gate 1492*a54f81fbSanish for (i = 0, n = i_ddi_get_intx_nintrs(rdip); i < n; i++) { 1493a195726fSgovinda uint32_t sbuslevel, inum, pri; 14947c478bd9Sstevel@tonic-gate 14957c478bd9Sstevel@tonic-gate if (i != 0) { 14967c478bd9Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 14977c478bd9Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, ","); 14987c478bd9Sstevel@tonic-gate len = strlen(msgbuf); 14997c478bd9Sstevel@tonic-gate } 15007c478bd9Sstevel@tonic-gate 1501a195726fSgovinda sbuslevel = inum = i_ddi_get_inum(rdip, i); 1502a195726fSgovinda pri = i_ddi_get_intr_pri(rdip, i); 15037c478bd9Sstevel@tonic-gate 1504a195726fSgovinda (void) sbus_xlate_intrs(dip, rdip, &inum, 1505a195726fSgovinda &pri, softsp->intr_mapping_ign); 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate if (sbuslevel > MAX_SBUS_LEVEL) 15087c478bd9Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 15097c478bd9Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, 15107c478bd9Sstevel@tonic-gate " Onboard device "); 15117c478bd9Sstevel@tonic-gate else 15127c478bd9Sstevel@tonic-gate f_len += snprintf(msgbuf + len, 15137c478bd9Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, " SBus level %d ", 15147c478bd9Sstevel@tonic-gate sbuslevel); 15157c478bd9Sstevel@tonic-gate len = strlen(msgbuf); 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate f_len += snprintf(msgbuf + len, REPORTDEV_BUFSIZE - len, 15187c478bd9Sstevel@tonic-gate "sparc9 ipl %d", pri); 15197c478bd9Sstevel@tonic-gate len = strlen(msgbuf); 15207c478bd9Sstevel@tonic-gate } 15217c478bd9Sstevel@tonic-gate #ifdef DEBUG 15227c478bd9Sstevel@tonic-gate if (f_len + 1 >= REPORTDEV_BUFSIZE) { 15237c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "next message is truncated: " 15247c478bd9Sstevel@tonic-gate "printed length 1024, real length %d", f_len); 15257c478bd9Sstevel@tonic-gate } 15267c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 15277c478bd9Sstevel@tonic-gate 15287c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?%s\n", msgbuf); 15297c478bd9Sstevel@tonic-gate kmem_free(msgbuf, REPORTDEV_BUFSIZE); 15307c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 15317c478bd9Sstevel@tonic-gate 15327c478bd9Sstevel@tonic-gate #undef REPORTDEV_BUFSIZE 15337c478bd9Sstevel@tonic-gate } 15347c478bd9Sstevel@tonic-gate 15357c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 15367c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 15377c478bd9Sstevel@tonic-gate 15387c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: { 15397c478bd9Sstevel@tonic-gate dev_info_t *dipb = (dev_info_t *)arg; 15407c478bd9Sstevel@tonic-gate int r_slot, b_slot; 15417c478bd9Sstevel@tonic-gate 15427c478bd9Sstevel@tonic-gate if ((b_slot = find_sbus_slot(dip, dipb)) < 0) 15437c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate if ((r_slot = find_sbus_slot(dip, rdip)) < 0) 15467c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate return ((b_slot == r_slot)? DDI_SUCCESS : DDI_FAILURE); 15497c478bd9Sstevel@tonic-gate 15507c478bd9Sstevel@tonic-gate } 15517c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 15527c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?DDI_DMAPMAPC called!!\n"); 15537c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 15547c478bd9Sstevel@tonic-gate 15557c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE: 15567c478bd9Sstevel@tonic-gate return (sbus_ctlops_poke(softsp, (peekpoke_ctlops_t *)arg)); 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 15597c478bd9Sstevel@tonic-gate return (sbus_ctlops_peek(softsp, (peekpoke_ctlops_t *)arg, 15607c478bd9Sstevel@tonic-gate result)); 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE: 15637c478bd9Sstevel@tonic-gate *(ulong_t *)result = IOMMU_PAGESIZE; 15647c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 15657c478bd9Sstevel@tonic-gate 15667c478bd9Sstevel@tonic-gate default: 15677c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 15687c478bd9Sstevel@tonic-gate } 15697c478bd9Sstevel@tonic-gate } 15707c478bd9Sstevel@tonic-gate 15717c478bd9Sstevel@tonic-gate static int 15727c478bd9Sstevel@tonic-gate find_sbus_slot(dev_info_t *dip, dev_info_t *rdip) 15737c478bd9Sstevel@tonic-gate { 15747c478bd9Sstevel@tonic-gate dev_info_t *child; 15757c478bd9Sstevel@tonic-gate int slot = -1; 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate /* 15787c478bd9Sstevel@tonic-gate * look for the node that's a direct child of this Sbus node. 15797c478bd9Sstevel@tonic-gate */ 15807c478bd9Sstevel@tonic-gate while (rdip && (child = ddi_get_parent(rdip)) != dip) { 15817c478bd9Sstevel@tonic-gate rdip = child; 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * If there is one, get the slot number of *my* child 15867c478bd9Sstevel@tonic-gate */ 15877c478bd9Sstevel@tonic-gate if (child == dip) 15887c478bd9Sstevel@tonic-gate slot = sysio_pd_getslot(rdip); 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate return (slot); 15917c478bd9Sstevel@tonic-gate } 15927c478bd9Sstevel@tonic-gate 15937c478bd9Sstevel@tonic-gate /* 15947c478bd9Sstevel@tonic-gate * This is the sbus interrupt routine wrapper function. This function 15957c478bd9Sstevel@tonic-gate * installs itself as a child devices interrupt handler. It's function is 15967c478bd9Sstevel@tonic-gate * to dispatch a child devices interrupt handler, and then 15977c478bd9Sstevel@tonic-gate * reset the interrupt clear register for the child device. 15987c478bd9Sstevel@tonic-gate * 15997c478bd9Sstevel@tonic-gate * Warning: This routine may need to be implemented as an assembly level 16007c478bd9Sstevel@tonic-gate * routine to improve performance. 16017c478bd9Sstevel@tonic-gate */ 16027c478bd9Sstevel@tonic-gate 16037c478bd9Sstevel@tonic-gate #define MAX_INTR_CNT 10 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate static uint_t 16067c478bd9Sstevel@tonic-gate sbus_intr_wrapper(caddr_t arg) 16077c478bd9Sstevel@tonic-gate { 16087c478bd9Sstevel@tonic-gate uint_t intr_return = DDI_INTR_UNCLAIMED; 16097c478bd9Sstevel@tonic-gate volatile uint64_t tmpreg; 16107c478bd9Sstevel@tonic-gate struct sbus_wrapper_arg *intr_info; 16117c478bd9Sstevel@tonic-gate struct sbus_intr_handler *intr_handler; 16127c478bd9Sstevel@tonic-gate uchar_t *spurious_cntr; 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate intr_info = (struct sbus_wrapper_arg *)arg; 16157c478bd9Sstevel@tonic-gate spurious_cntr = &intr_info->softsp->spurious_cntrs[intr_info->pil]; 16167c478bd9Sstevel@tonic-gate intr_handler = intr_info->handler_list; 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate while (intr_handler) { 16197c478bd9Sstevel@tonic-gate caddr_t arg1 = intr_handler->arg1; 16207c478bd9Sstevel@tonic-gate caddr_t arg2 = intr_handler->arg2; 16217c478bd9Sstevel@tonic-gate uint_t (*funcp)() = intr_handler->funcp; 16227c478bd9Sstevel@tonic-gate dev_info_t *dip = intr_handler->dip; 16237c478bd9Sstevel@tonic-gate int r; 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate if (intr_handler->intr_state == SBUS_INTR_STATE_DISABLE) { 16267c478bd9Sstevel@tonic-gate intr_handler = intr_handler->next; 16277c478bd9Sstevel@tonic-gate continue; 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate 16307c478bd9Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 16317c478bd9Sstevel@tonic-gate void *, funcp, caddr_t, arg1, caddr_t, arg2); 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate r = (*funcp)(arg1, arg2); 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 16367c478bd9Sstevel@tonic-gate void *, funcp, caddr_t, arg1, int, r); 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate intr_return |= r; 16397c478bd9Sstevel@tonic-gate intr_handler = intr_handler->next; 16407c478bd9Sstevel@tonic-gate } 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate /* Set the interrupt state machine to idle */ 16437c478bd9Sstevel@tonic-gate tmpreg = *intr_info->softsp->sbus_ctrl_reg; 16447c478bd9Sstevel@tonic-gate tmpreg = SBUS_INTR_IDLE; 16457c478bd9Sstevel@tonic-gate *intr_info->clear_reg = tmpreg; 16467c478bd9Sstevel@tonic-gate tmpreg = *intr_info->softsp->sbus_ctrl_reg; 16477c478bd9Sstevel@tonic-gate 16487c478bd9Sstevel@tonic-gate if (intr_return == DDI_INTR_UNCLAIMED) { 16497c478bd9Sstevel@tonic-gate (*spurious_cntr)++; 16507c478bd9Sstevel@tonic-gate 16517c478bd9Sstevel@tonic-gate if (*spurious_cntr < MAX_INTR_CNT) { 16527c478bd9Sstevel@tonic-gate if (intr_cntr_on) 16537c478bd9Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate #ifdef DEBUG 16567c478bd9Sstevel@tonic-gate else if (intr_info->pil >= LOCK_LEVEL) { 16577c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "%d unclaimed interrupts at " 16587c478bd9Sstevel@tonic-gate "interrupt level %d", MAX_INTR_CNT, 16597c478bd9Sstevel@tonic-gate intr_info->pil); 16607c478bd9Sstevel@tonic-gate } 16617c478bd9Sstevel@tonic-gate #endif 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate /* 16647c478bd9Sstevel@tonic-gate * Reset spurious counter once we acknowledge 16657c478bd9Sstevel@tonic-gate * it to the system level. 16667c478bd9Sstevel@tonic-gate */ 16677c478bd9Sstevel@tonic-gate *spurious_cntr = (uchar_t)0; 16687c478bd9Sstevel@tonic-gate } else { 16697c478bd9Sstevel@tonic-gate *spurious_cntr = (uchar_t)0; 16707c478bd9Sstevel@tonic-gate } 16717c478bd9Sstevel@tonic-gate 16727c478bd9Sstevel@tonic-gate return (intr_return); 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate /* 16767c478bd9Sstevel@tonic-gate * add_intrspec - Add an interrupt specification. 16777c478bd9Sstevel@tonic-gate */ 16787c478bd9Sstevel@tonic-gate static int 16797c478bd9Sstevel@tonic-gate sbus_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 16807c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 16817c478bd9Sstevel@tonic-gate { 16827c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 16837c478bd9Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 16847c478bd9Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 16857c478bd9Sstevel@tonic-gate volatile uint64_t tmp_mondo_vec; 16867c478bd9Sstevel@tonic-gate volatile uint64_t *intr_state_reg; 16877c478bd9Sstevel@tonic-gate volatile uint64_t tmpreg; /* HW flush reg */ 16887c478bd9Sstevel@tonic-gate uint_t start_bit; 16897c478bd9Sstevel@tonic-gate int ino; 16907c478bd9Sstevel@tonic-gate uint_t cpu_id; 16917c478bd9Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg; 16927c478bd9Sstevel@tonic-gate struct sbus_intr_handler *intr_handler; 16937c478bd9Sstevel@tonic-gate uint32_t slot; 16947c478bd9Sstevel@tonic-gate /* Interrupt state machine reset flag */ 16957c478bd9Sstevel@tonic-gate int reset_ism_register = 1; 16967c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate /* Check if we have a valid sbus slot address */ 16997c478bd9Sstevel@tonic-gate if (((slot = (uint_t)find_sbus_slot(dip, rdip)) >= 17007c478bd9Sstevel@tonic-gate MAX_SBUS_SLOT_ADDR) || (slot < (uint_t)0)) { 17017c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Invalid sbus slot 0x%x during add intr\n", 17027c478bd9Sstevel@tonic-gate slot); 17037c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 17047c478bd9Sstevel@tonic-gate } 17057c478bd9Sstevel@tonic-gate 17067c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: sbus interrupt %d " 1707a195726fSgovinda "for device %s%d\n", hdlp->ih_vector, ddi_driver_name(rdip), 17087c478bd9Sstevel@tonic-gate ddi_get_instance(rdip))); 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate /* Xlate the interrupt */ 1711a195726fSgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector, 1712a195726fSgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) { 17137c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Can't xlate SBUS devices %s interrupt.\n", 1714a195726fSgovinda ddi_driver_name(rdip)); 17157c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 17167c478bd9Sstevel@tonic-gate } 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate /* get the ino number */ 1719a195726fSgovinda ino = hdlp->ih_vector & SBUS_MAX_INO; 17207c478bd9Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg + 17217c478bd9Sstevel@tonic-gate ino_table[ino]->mapping_reg); 17227c478bd9Sstevel@tonic-gate 17237c478bd9Sstevel@tonic-gate /* 17247c478bd9Sstevel@tonic-gate * This is an intermediate step in identifying 17257c478bd9Sstevel@tonic-gate * the exact bits which represent the device in the interrupt 17267c478bd9Sstevel@tonic-gate * state diagnostic register. 17277c478bd9Sstevel@tonic-gate */ 17287c478bd9Sstevel@tonic-gate if (ino > MAX_MONDO_EXTERNAL) { 17297c478bd9Sstevel@tonic-gate start_bit = ino_table[ino]->diagreg_shift; 17307c478bd9Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state; 17317c478bd9Sstevel@tonic-gate } else { 17327c478bd9Sstevel@tonic-gate start_bit = 16 * (ino >> 3) + 2 * (ino & 0x7); 17337c478bd9Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state; 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate 17367c478bd9Sstevel@tonic-gate 17377c478bd9Sstevel@tonic-gate /* Allocate a nexus interrupt data structure */ 17387c478bd9Sstevel@tonic-gate intr_handler = kmem_zalloc(sizeof (struct sbus_intr_handler), KM_SLEEP); 17397c478bd9Sstevel@tonic-gate intr_handler->dip = rdip; 17407c478bd9Sstevel@tonic-gate intr_handler->funcp = hdlp->ih_cb_func; 17417c478bd9Sstevel@tonic-gate intr_handler->arg1 = hdlp->ih_cb_arg1; 17427c478bd9Sstevel@tonic-gate intr_handler->arg2 = hdlp->ih_cb_arg2; 17437c478bd9Sstevel@tonic-gate intr_handler->inum = hdlp->ih_inum; 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: xlated interrupt 0x%x " 1746ffadc26eSmike_s "intr_handler 0x%p\n", hdlp->ih_vector, intr_handler)); 17477c478bd9Sstevel@tonic-gate 17487c478bd9Sstevel@tonic-gate /* 17497c478bd9Sstevel@tonic-gate * Grab this lock here. So it will protect the poll list. 17507c478bd9Sstevel@tonic-gate */ 17517c478bd9Sstevel@tonic-gate mutex_enter(&softsp->intr_poll_list_lock); 17527c478bd9Sstevel@tonic-gate 17537c478bd9Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino]; 17547c478bd9Sstevel@tonic-gate /* Check if we have a poll list to deal with */ 17557c478bd9Sstevel@tonic-gate if (sbus_arg) { 17567c478bd9Sstevel@tonic-gate tmp_mondo_vec = *mondo_vec_reg; 17577c478bd9Sstevel@tonic-gate tmp_mondo_vec &= ~INTERRUPT_VALID; 17587c478bd9Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec; 17597c478bd9Sstevel@tonic-gate 17607c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 17617c478bd9Sstevel@tonic-gate #ifdef lint 17627c478bd9Sstevel@tonic-gate tmpreg = tmpreg; 17637c478bd9Sstevel@tonic-gate #endif 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:sbus_arg exists " 1766ffadc26eSmike_s "0x%p\n", sbus_arg)); 17677c478bd9Sstevel@tonic-gate /* 17687c478bd9Sstevel@tonic-gate * Two bits per ino in the diagnostic register 17697c478bd9Sstevel@tonic-gate * indicate the status of its interrupt. 17707c478bd9Sstevel@tonic-gate * 0 - idle, 1 - transmit, 3 - pending. 17717c478bd9Sstevel@tonic-gate */ 17727c478bd9Sstevel@tonic-gate while (((*intr_state_reg >> 17737c478bd9Sstevel@tonic-gate start_bit) & 0x3) == INT_PENDING && !panicstr) 17747c478bd9Sstevel@tonic-gate /* empty */; 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate intr_handler->next = sbus_arg->handler_list; 17777c478bd9Sstevel@tonic-gate sbus_arg->handler_list = intr_handler; 17787c478bd9Sstevel@tonic-gate 17797c478bd9Sstevel@tonic-gate reset_ism_register = 0; 17807c478bd9Sstevel@tonic-gate } else { 17817c478bd9Sstevel@tonic-gate sbus_arg = kmem_zalloc(sizeof (struct sbus_wrapper_arg), 17827c478bd9Sstevel@tonic-gate KM_SLEEP); 17837c478bd9Sstevel@tonic-gate 17847c478bd9Sstevel@tonic-gate softsp->intr_list[ino] = sbus_arg; 17857c478bd9Sstevel@tonic-gate sbus_arg->clear_reg = (softsp->clr_intr_reg + 17867c478bd9Sstevel@tonic-gate ino_table[ino]->clear_reg); 17877c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:Ino 0x%x Interrupt " 1788ffadc26eSmike_s "clear reg: 0x%p\n", ino, sbus_arg->clear_reg)); 17897c478bd9Sstevel@tonic-gate sbus_arg->softsp = softsp; 17907c478bd9Sstevel@tonic-gate sbus_arg->handler_list = intr_handler; 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate /* 17937c478bd9Sstevel@tonic-gate * No handler added yet in the interrupt vector 17947c478bd9Sstevel@tonic-gate * table for this ino. 17957c478bd9Sstevel@tonic-gate * Install the nexus interrupt wrapper in the 17967c478bd9Sstevel@tonic-gate * system. The wrapper will call the device 17977c478bd9Sstevel@tonic-gate * interrupt handler. 17987c478bd9Sstevel@tonic-gate */ 17997c478bd9Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 18007c478bd9Sstevel@tonic-gate (ddi_intr_handler_t *)sbus_intr_wrapper, 18017c478bd9Sstevel@tonic-gate (caddr_t)sbus_arg, NULL); 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate /* 18067c478bd9Sstevel@tonic-gate * Restore original interrupt handler 18077c478bd9Sstevel@tonic-gate * and arguments in interrupt handle. 18087c478bd9Sstevel@tonic-gate */ 18097c478bd9Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, intr_handler->funcp, 18107c478bd9Sstevel@tonic-gate intr_handler->arg1, intr_handler->arg2); 18117c478bd9Sstevel@tonic-gate 18129c75c6bfSgovinda if (ret != DDI_SUCCESS) { 18139c75c6bfSgovinda mutex_exit(&softsp->intr_poll_list_lock); 18149c75c6bfSgovinda goto done; 18159c75c6bfSgovinda } 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate if ((slot >= EXT_SBUS_SLOTS) || 18187c478bd9Sstevel@tonic-gate (softsp->intr_hndlr_cnt[slot] == 0)) { 18197c478bd9Sstevel@tonic-gate 18207c478bd9Sstevel@tonic-gate cpu_id = intr_dist_cpuid(); 18217c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 18227c478bd9Sstevel@tonic-gate tmp_mondo_vec = pc_translate_tgtid( 18237c478bd9Sstevel@tonic-gate softsp->ittrans_cookie, cpu_id, 18247c478bd9Sstevel@tonic-gate mondo_vec_reg) << IMR_TID_SHIFT; 18257c478bd9Sstevel@tonic-gate #else 18267c478bd9Sstevel@tonic-gate tmp_mondo_vec = 18277c478bd9Sstevel@tonic-gate cpu_id << IMR_TID_SHIFT; 18287c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: initial " 1829ffadc26eSmike_s "mapping reg 0x%lx\n", tmp_mondo_vec)); 18307c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 18317c478bd9Sstevel@tonic-gate } else { 18327c478bd9Sstevel@tonic-gate /* 18337c478bd9Sstevel@tonic-gate * There is already a different 18347c478bd9Sstevel@tonic-gate * ino programmed at this IMR. 18357c478bd9Sstevel@tonic-gate * Just read the IMR out to get the 18367c478bd9Sstevel@tonic-gate * correct MID target. 18377c478bd9Sstevel@tonic-gate */ 18387c478bd9Sstevel@tonic-gate tmp_mondo_vec = *mondo_vec_reg; 18397c478bd9Sstevel@tonic-gate tmp_mondo_vec &= ~INTERRUPT_VALID; 18407c478bd9Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec; 18417c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: existing " 1842ffadc26eSmike_s "mapping reg 0x%lx\n", tmp_mondo_vec)); 18437c478bd9Sstevel@tonic-gate } 18447c478bd9Sstevel@tonic-gate 18457c478bd9Sstevel@tonic-gate sbus_arg->pil = hdlp->ih_pri; 18467c478bd9Sstevel@tonic-gate 18477c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:Alloc sbus_arg " 1848ffadc26eSmike_s "0x%p\n", sbus_arg)); 18497c478bd9Sstevel@tonic-gate } 18507c478bd9Sstevel@tonic-gate 18517c478bd9Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]++; 18527c478bd9Sstevel@tonic-gate 18537c478bd9Sstevel@tonic-gate mutex_exit(&softsp->intr_poll_list_lock); 18547c478bd9Sstevel@tonic-gate 18557c478bd9Sstevel@tonic-gate /* 18567c478bd9Sstevel@tonic-gate * Program the ino vector accordingly. This MUST be the 18577c478bd9Sstevel@tonic-gate * last thing we do. Once we program the ino, the device 18587c478bd9Sstevel@tonic-gate * may begin to interrupt. Add this hardware interrupt to 18597c478bd9Sstevel@tonic-gate * the interrupt lists, and get the CPU to target it at. 18607c478bd9Sstevel@tonic-gate */ 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate tmp_mondo_vec |= INTERRUPT_VALID; 18637c478bd9Sstevel@tonic-gate 1864ffadc26eSmike_s DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: Ino 0x%x mapping reg: 0x%p " 18657c478bd9Sstevel@tonic-gate "Intr cntr %d\n", ino, mondo_vec_reg, 18667c478bd9Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot])); 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate /* Force the interrupt state machine to idle. */ 18697c478bd9Sstevel@tonic-gate if (reset_ism_register) { 18707c478bd9Sstevel@tonic-gate tmpreg = SBUS_INTR_IDLE; 18717c478bd9Sstevel@tonic-gate *sbus_arg->clear_reg = tmpreg; 18727c478bd9Sstevel@tonic-gate } 18737c478bd9Sstevel@tonic-gate 18747c478bd9Sstevel@tonic-gate /* Store it in the hardware reg. */ 18757c478bd9Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec; 18767c478bd9Sstevel@tonic-gate 18777c478bd9Sstevel@tonic-gate /* Flush store buffers */ 18787c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 18797c478bd9Sstevel@tonic-gate 18807c478bd9Sstevel@tonic-gate done: 18817c478bd9Sstevel@tonic-gate return (ret); 18827c478bd9Sstevel@tonic-gate } 18837c478bd9Sstevel@tonic-gate 18847c478bd9Sstevel@tonic-gate static void 18857c478bd9Sstevel@tonic-gate sbus_free_handler(dev_info_t *dip, uint32_t inum, 18867c478bd9Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg) 18877c478bd9Sstevel@tonic-gate { 18887c478bd9Sstevel@tonic-gate struct sbus_intr_handler *listp, *prevp; 18897c478bd9Sstevel@tonic-gate 18907c478bd9Sstevel@tonic-gate if (sbus_arg) { 18917c478bd9Sstevel@tonic-gate prevp = NULL; 18927c478bd9Sstevel@tonic-gate listp = sbus_arg->handler_list; 18937c478bd9Sstevel@tonic-gate 18947c478bd9Sstevel@tonic-gate while (listp) { 18957c478bd9Sstevel@tonic-gate if (listp->dip == dip && listp->inum == inum) { 18967c478bd9Sstevel@tonic-gate if (prevp) 18977c478bd9Sstevel@tonic-gate prevp->next = listp->next; 18987c478bd9Sstevel@tonic-gate else { 18997c478bd9Sstevel@tonic-gate prevp = listp->next; 19007c478bd9Sstevel@tonic-gate sbus_arg->handler_list = prevp; 19017c478bd9Sstevel@tonic-gate } 19027c478bd9Sstevel@tonic-gate 19037c478bd9Sstevel@tonic-gate kmem_free(listp, 19047c478bd9Sstevel@tonic-gate sizeof (struct sbus_intr_handler)); 19057c478bd9Sstevel@tonic-gate break; 19067c478bd9Sstevel@tonic-gate } 19077c478bd9Sstevel@tonic-gate prevp = listp; 19087c478bd9Sstevel@tonic-gate listp = listp->next; 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate } 19117c478bd9Sstevel@tonic-gate } 19127c478bd9Sstevel@tonic-gate 19137c478bd9Sstevel@tonic-gate /* 19147c478bd9Sstevel@tonic-gate * remove_intrspec - Remove an interrupt specification. 19157c478bd9Sstevel@tonic-gate */ 19167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 19177c478bd9Sstevel@tonic-gate static void 19187c478bd9Sstevel@tonic-gate sbus_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 19197c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 19207c478bd9Sstevel@tonic-gate { 19217c478bd9Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 19227c478bd9Sstevel@tonic-gate volatile uint64_t *intr_state_reg; 19237c478bd9Sstevel@tonic-gate #ifndef lint 19247c478bd9Sstevel@tonic-gate volatile uint64_t tmpreg; 19257c478bd9Sstevel@tonic-gate #endif /* !lint */ 19267c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 19277c478bd9Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 19287c478bd9Sstevel@tonic-gate int start_bit, ino, slot; 19297c478bd9Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg; 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate /* Grab the mutex protecting the poll list */ 19327c478bd9Sstevel@tonic-gate mutex_enter(&softsp->intr_poll_list_lock); 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate /* Xlate the interrupt */ 1935a195726fSgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector, 1936a195726fSgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) { 19377c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Can't xlate SBUS devices %s interrupt.\n", 1938a195726fSgovinda ddi_driver_name(rdip)); 19397c478bd9Sstevel@tonic-gate goto done; 19407c478bd9Sstevel@tonic-gate } 19417c478bd9Sstevel@tonic-gate 1942a195726fSgovinda ino = ((int32_t)hdlp->ih_vector) & SBUS_MAX_INO; 19437c478bd9Sstevel@tonic-gate 19447c478bd9Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg + 19457c478bd9Sstevel@tonic-gate ino_table[ino]->mapping_reg); 19467c478bd9Sstevel@tonic-gate 19477c478bd9Sstevel@tonic-gate /* Turn off the valid bit in the mapping register. */ 19487c478bd9Sstevel@tonic-gate *mondo_vec_reg &= ~INTERRUPT_VALID; 19497c478bd9Sstevel@tonic-gate #ifndef lint 19507c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 19517c478bd9Sstevel@tonic-gate #endif /* !lint */ 19527c478bd9Sstevel@tonic-gate 19537c478bd9Sstevel@tonic-gate /* Get our bit position for checking intr pending */ 19547c478bd9Sstevel@tonic-gate if (ino > MAX_MONDO_EXTERNAL) { 19557c478bd9Sstevel@tonic-gate start_bit = ino_table[ino]->diagreg_shift; 19567c478bd9Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state; 19577c478bd9Sstevel@tonic-gate } else { 19587c478bd9Sstevel@tonic-gate start_bit = 16 * (ino >> 3) + 2 * (ino & 0x7); 19597c478bd9Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state; 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate 19627c478bd9Sstevel@tonic-gate while (((*intr_state_reg >> start_bit) & 0x3) == INT_PENDING && 19637c478bd9Sstevel@tonic-gate !panicstr) 19647c478bd9Sstevel@tonic-gate /* empty */; 19657c478bd9Sstevel@tonic-gate 19667c478bd9Sstevel@tonic-gate slot = find_sbus_slot(dip, rdip); 19677c478bd9Sstevel@tonic-gate 19687c478bd9Sstevel@tonic-gate /* Return if the slot is invalid */ 19697c478bd9Sstevel@tonic-gate if (slot >= MAX_SBUS_SLOT_ADDR || slot < 0) { 19707c478bd9Sstevel@tonic-gate goto done; 19717c478bd9Sstevel@tonic-gate } 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino]; 19747c478bd9Sstevel@tonic-gate 19757c478bd9Sstevel@tonic-gate /* Decrement the intr handler count on this slot */ 19767c478bd9Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]--; 19777c478bd9Sstevel@tonic-gate 1978ffadc26eSmike_s DPRINTF(SBUS_INTERRUPT_DEBUG, ("Rem intr: Softsp 0x%p, Mondo 0x%x, " 1979ffadc26eSmike_s "ino 0x%x, sbus_arg 0x%p intr cntr %d\n", softsp, 1980a195726fSgovinda hdlp->ih_vector, ino, sbus_arg, softsp->intr_hndlr_cnt[slot])); 19817c478bd9Sstevel@tonic-gate 19827c478bd9Sstevel@tonic-gate ASSERT(sbus_arg != NULL); 19837c478bd9Sstevel@tonic-gate ASSERT(sbus_arg->handler_list != NULL); 19847c478bd9Sstevel@tonic-gate sbus_free_handler(rdip, hdlp->ih_inum, sbus_arg); 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate /* If we still have a list, we're done. */ 1987a195726fSgovinda if (sbus_arg->handler_list == NULL) 19887c478bd9Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 19897c478bd9Sstevel@tonic-gate 19907c478bd9Sstevel@tonic-gate /* 19917c478bd9Sstevel@tonic-gate * If other devices are still installed for this slot, we need to 19927c478bd9Sstevel@tonic-gate * turn the valid bit back on. 19937c478bd9Sstevel@tonic-gate */ 19947c478bd9Sstevel@tonic-gate if (softsp->intr_hndlr_cnt[slot] > 0) { 19957c478bd9Sstevel@tonic-gate *mondo_vec_reg |= INTERRUPT_VALID; 19967c478bd9Sstevel@tonic-gate #ifndef lint 19977c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 19987c478bd9Sstevel@tonic-gate #endif /* !lint */ 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate if ((softsp->intr_hndlr_cnt[slot] == 0) || (slot >= EXT_SBUS_SLOTS)) { 20027c478bd9Sstevel@tonic-gate ASSERT(sbus_arg->handler_list == NULL); 20037c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 20047c478bd9Sstevel@tonic-gate /* Do cleanup for interrupt target translation */ 20057c478bd9Sstevel@tonic-gate pc_ittrans_cleanup(softsp->ittrans_cookie, mondo_vec_reg); 20067c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 20077c478bd9Sstevel@tonic-gate } 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate 20107c478bd9Sstevel@tonic-gate /* Free up the memory used for the sbus interrupt handler */ 20117c478bd9Sstevel@tonic-gate if (sbus_arg->handler_list == NULL) { 20127c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Rem intr: Freeing sbus arg " 2013ffadc26eSmike_s "0x%p\n", sbus_arg)); 20147c478bd9Sstevel@tonic-gate kmem_free(sbus_arg, sizeof (struct sbus_wrapper_arg)); 20157c478bd9Sstevel@tonic-gate softsp->intr_list[ino] = NULL; 20167c478bd9Sstevel@tonic-gate } 20177c478bd9Sstevel@tonic-gate 20187c478bd9Sstevel@tonic-gate done: 20197c478bd9Sstevel@tonic-gate mutex_exit(&softsp->intr_poll_list_lock); 20207c478bd9Sstevel@tonic-gate } 20217c478bd9Sstevel@tonic-gate 20227c478bd9Sstevel@tonic-gate /* 20237c478bd9Sstevel@tonic-gate * We're prepared to claim that the interrupt string is in 20247c478bd9Sstevel@tonic-gate * the form of a list of <SBusintr> specifications, or we're dealing 20257c478bd9Sstevel@tonic-gate * with on-board devices and we have an interrupt_number property which 20267c478bd9Sstevel@tonic-gate * gives us our mondo number. 20277c478bd9Sstevel@tonic-gate * Translate the sbus levels or mondos into sysiointrspecs. 20287c478bd9Sstevel@tonic-gate */ 20297c478bd9Sstevel@tonic-gate static int 2030a195726fSgovinda sbus_xlate_intrs(dev_info_t *dip, dev_info_t *rdip, uint32_t *intr, 2031a195726fSgovinda uint32_t *pil, int32_t ign) 20327c478bd9Sstevel@tonic-gate { 2033a195726fSgovinda uint32_t ino, slot, level = *intr; 20347c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 20357c478bd9Sstevel@tonic-gate 20367c478bd9Sstevel@tonic-gate /* 20377c478bd9Sstevel@tonic-gate * Create the sysio ino number. onboard devices will have 20387c478bd9Sstevel@tonic-gate * an "interrupts" property, that is equal to the ino number. 20397c478bd9Sstevel@tonic-gate * If the devices are from the 20407c478bd9Sstevel@tonic-gate * expansion slots, we construct the ino number by putting 20417c478bd9Sstevel@tonic-gate * the slot number in the upper three bits, and the sbus 20427c478bd9Sstevel@tonic-gate * interrupt level in the lower three bits. 20437c478bd9Sstevel@tonic-gate */ 20447c478bd9Sstevel@tonic-gate if (level > MAX_SBUS_LEVEL) { 20457c478bd9Sstevel@tonic-gate ino = level; 20467c478bd9Sstevel@tonic-gate } else { 20477c478bd9Sstevel@tonic-gate /* Construct ino from slot and interrupts */ 20487c478bd9Sstevel@tonic-gate if ((slot = find_sbus_slot(dip, rdip)) == -1) { 20497c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Can't determine sbus slot " 2050a195726fSgovinda "of %s device\n", ddi_driver_name(rdip)); 20517c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 20527c478bd9Sstevel@tonic-gate goto done; 20537c478bd9Sstevel@tonic-gate } 20547c478bd9Sstevel@tonic-gate 20557c478bd9Sstevel@tonic-gate if (slot >= MAX_SBUS_SLOT_ADDR) { 20567c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Invalid sbus slot 0x%x" 2057a195726fSgovinda "in %s device\n", slot, ddi_driver_name(rdip)); 20587c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 20597c478bd9Sstevel@tonic-gate goto done; 20607c478bd9Sstevel@tonic-gate } 20617c478bd9Sstevel@tonic-gate 20627c478bd9Sstevel@tonic-gate ino = slot << 3; 20637c478bd9Sstevel@tonic-gate ino |= level; 20647c478bd9Sstevel@tonic-gate } 20657c478bd9Sstevel@tonic-gate 20667c478bd9Sstevel@tonic-gate /* Sanity check the inos range */ 20677c478bd9Sstevel@tonic-gate if (ino >= MAX_INO_TABLE_SIZE) { 20687c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Ino vector 0x%x out of range", ino); 20697c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 20707c478bd9Sstevel@tonic-gate goto done; 20717c478bd9Sstevel@tonic-gate } 20727c478bd9Sstevel@tonic-gate /* Sanity check the inos value */ 20737c478bd9Sstevel@tonic-gate if (!ino_table[ino]) { 20747c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Ino vector 0x%x is invalid", ino); 20757c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 20767c478bd9Sstevel@tonic-gate goto done; 20777c478bd9Sstevel@tonic-gate } 20787c478bd9Sstevel@tonic-gate 2079a195726fSgovinda if (*pil == 0) { 20807c478bd9Sstevel@tonic-gate #define SOC_PRIORITY 5 20817c478bd9Sstevel@tonic-gate /* The sunfire i/o board has a soc in the printer slot */ 20827c478bd9Sstevel@tonic-gate if ((ino_table[ino]->clear_reg == PP_CLEAR) && 20837c478bd9Sstevel@tonic-gate ((strcmp(ddi_get_name(rdip), "soc") == 0) || 20847c478bd9Sstevel@tonic-gate (strcmp(ddi_get_name(rdip), "SUNW,soc") == 0))) { 2085a195726fSgovinda *pil = SOC_PRIORITY; 20867c478bd9Sstevel@tonic-gate } else { 20877c478bd9Sstevel@tonic-gate /* Figure out the pil associated with this interrupt */ 2088a195726fSgovinda *pil = interrupt_priorities[ino]; 20897c478bd9Sstevel@tonic-gate } 20907c478bd9Sstevel@tonic-gate } 20917c478bd9Sstevel@tonic-gate 20927c478bd9Sstevel@tonic-gate /* Or in the upa_id into the interrupt group number field */ 2093a195726fSgovinda *intr = (uint32_t)(ino | ign); 20947c478bd9Sstevel@tonic-gate 20957c478bd9Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Xlate intr: Interrupt info for " 20967c478bd9Sstevel@tonic-gate "device %s Mondo: 0x%x, ino: 0x%x, Pil: 0x%x, sbus level: 0x%x\n", 2097a195726fSgovinda ddi_driver_name(rdip), *intr, ino, *pil, level)); 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate done: 21007c478bd9Sstevel@tonic-gate return (ret); 21017c478bd9Sstevel@tonic-gate } 21027c478bd9Sstevel@tonic-gate 21037c478bd9Sstevel@tonic-gate /* new intr_ops structure */ 21047c478bd9Sstevel@tonic-gate int 21057c478bd9Sstevel@tonic-gate sbus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 21067c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 21077c478bd9Sstevel@tonic-gate { 21087c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 21097c478bd9Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 21107c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 21117c478bd9Sstevel@tonic-gate 21127c478bd9Sstevel@tonic-gate 21137c478bd9Sstevel@tonic-gate switch (intr_op) { 21147c478bd9Sstevel@tonic-gate case DDI_INTROP_GETCAP: 2115a195726fSgovinda *(int *)result = DDI_INTR_FLAG_LEVEL; 21167c478bd9Sstevel@tonic-gate break; 21177c478bd9Sstevel@tonic-gate case DDI_INTROP_ALLOC: 21187c478bd9Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 21197c478bd9Sstevel@tonic-gate break; 21207c478bd9Sstevel@tonic-gate case DDI_INTROP_FREE: 21217c478bd9Sstevel@tonic-gate break; 21227c478bd9Sstevel@tonic-gate case DDI_INTROP_GETPRI: 2123a195726fSgovinda if (hdlp->ih_vector == 0) { 21247c478bd9Sstevel@tonic-gate /* Xlate the interrupt */ 21257c478bd9Sstevel@tonic-gate (void) sbus_xlate_intrs(dip, rdip, 2126a195726fSgovinda (uint32_t *)&hdlp->ih_vector, &hdlp->ih_pri, 2127a195726fSgovinda softsp->intr_mapping_ign); 21287c478bd9Sstevel@tonic-gate } 21297c478bd9Sstevel@tonic-gate 2130a195726fSgovinda *(int *)result = hdlp->ih_pri; 21317c478bd9Sstevel@tonic-gate break; 21327c478bd9Sstevel@tonic-gate case DDI_INTROP_SETPRI: 21337c478bd9Sstevel@tonic-gate break; 21347c478bd9Sstevel@tonic-gate case DDI_INTROP_ADDISR: 21357c478bd9Sstevel@tonic-gate ret = sbus_add_intr_impl(dip, rdip, hdlp); 21367c478bd9Sstevel@tonic-gate break; 21377c478bd9Sstevel@tonic-gate case DDI_INTROP_REMISR: 21387c478bd9Sstevel@tonic-gate sbus_remove_intr_impl(dip, rdip, hdlp); 21397c478bd9Sstevel@tonic-gate break; 21407c478bd9Sstevel@tonic-gate case DDI_INTROP_ENABLE: 21417c478bd9Sstevel@tonic-gate ret = sbus_update_intr_state(dip, rdip, hdlp, 21427c478bd9Sstevel@tonic-gate SBUS_INTR_STATE_ENABLE); 21437c478bd9Sstevel@tonic-gate break; 21447c478bd9Sstevel@tonic-gate case DDI_INTROP_DISABLE: 21457c478bd9Sstevel@tonic-gate ret = sbus_update_intr_state(dip, rdip, hdlp, 21467c478bd9Sstevel@tonic-gate SBUS_INTR_STATE_DISABLE); 21477c478bd9Sstevel@tonic-gate break; 21487c478bd9Sstevel@tonic-gate case DDI_INTROP_NINTRS: 21497c478bd9Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 2150*a54f81fbSanish *(int *)result = i_ddi_get_intx_nintrs(rdip); 21517c478bd9Sstevel@tonic-gate break; 21527c478bd9Sstevel@tonic-gate case DDI_INTROP_SETCAP: 21537c478bd9Sstevel@tonic-gate case DDI_INTROP_SETMASK: 21547c478bd9Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 21557c478bd9Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 21567c478bd9Sstevel@tonic-gate ret = DDI_ENOTSUP; 21577c478bd9Sstevel@tonic-gate break; 21587c478bd9Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 21597c478bd9Sstevel@tonic-gate /* Sbus nexus driver supports only fixed interrupts */ 2160*a54f81fbSanish *(int *)result = i_ddi_get_intx_nintrs(rdip) ? 21617c478bd9Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0; 21627c478bd9Sstevel@tonic-gate break; 21637c478bd9Sstevel@tonic-gate default: 21647c478bd9Sstevel@tonic-gate ret = i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result); 21657c478bd9Sstevel@tonic-gate break; 21667c478bd9Sstevel@tonic-gate } 21677c478bd9Sstevel@tonic-gate 21687c478bd9Sstevel@tonic-gate return (ret); 21697c478bd9Sstevel@tonic-gate } 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate 21727c478bd9Sstevel@tonic-gate /* 21737c478bd9Sstevel@tonic-gate * Called by suspend/resume to save/restore the interrupt status (valid bit) 21747c478bd9Sstevel@tonic-gate * of the interrupt mapping registers. 21757c478bd9Sstevel@tonic-gate */ 21767c478bd9Sstevel@tonic-gate static void 21777c478bd9Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(uint64_t *cpr_softsp, volatile uint64_t *baddr, 21787c478bd9Sstevel@tonic-gate int save) 21797c478bd9Sstevel@tonic-gate { 21807c478bd9Sstevel@tonic-gate int i; 21817c478bd9Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 21827c478bd9Sstevel@tonic-gate 21837c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_INO_TABLE_SIZE; i++) { 21847c478bd9Sstevel@tonic-gate if (ino_table[i] != NULL) { 21857c478bd9Sstevel@tonic-gate mondo_vec_reg = baddr + ino_table[i]->mapping_reg; 21867c478bd9Sstevel@tonic-gate if (save) { 21877c478bd9Sstevel@tonic-gate if (*mondo_vec_reg & INTERRUPT_VALID) { 21887c478bd9Sstevel@tonic-gate cpr_softsp[i] = *mondo_vec_reg; 21897c478bd9Sstevel@tonic-gate } 21907c478bd9Sstevel@tonic-gate } else { 21917c478bd9Sstevel@tonic-gate if (cpr_softsp[i]) { 21927c478bd9Sstevel@tonic-gate *mondo_vec_reg = cpr_softsp[i]; 21937c478bd9Sstevel@tonic-gate } 21947c478bd9Sstevel@tonic-gate } 21957c478bd9Sstevel@tonic-gate } 21967c478bd9Sstevel@tonic-gate } 21977c478bd9Sstevel@tonic-gate } 21987c478bd9Sstevel@tonic-gate 21997c478bd9Sstevel@tonic-gate #define SZ_INO_TABLE (sizeof (ino_table) / sizeof (ino_table[0])) 22007c478bd9Sstevel@tonic-gate 22017c478bd9Sstevel@tonic-gate /* 22027c478bd9Sstevel@tonic-gate * sbus_intrdist 22037c478bd9Sstevel@tonic-gate * 22047c478bd9Sstevel@tonic-gate * This function retargets active interrupts by reprogramming the mondo 22057c478bd9Sstevel@tonic-gate * vec register. If the CPU ID of the target has not changed, then 22067c478bd9Sstevel@tonic-gate * the mondo is not reprogrammed. The routine must hold the mondo 22077c478bd9Sstevel@tonic-gate * lock for this instance of the sbus. 22087c478bd9Sstevel@tonic-gate */ 22097c478bd9Sstevel@tonic-gate static void 22107c478bd9Sstevel@tonic-gate sbus_intrdist(void *arg) 22117c478bd9Sstevel@tonic-gate { 22127c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp; 22137c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 22147c478bd9Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg; 22157c478bd9Sstevel@tonic-gate uint64_t *last_mondo_vec_reg; 22167c478bd9Sstevel@tonic-gate uint64_t mondo_vec; 22177c478bd9Sstevel@tonic-gate volatile uint64_t *intr_state_reg; 22187c478bd9Sstevel@tonic-gate uint_t start_bit; 22197c478bd9Sstevel@tonic-gate volatile uint64_t tmpreg; /* HW flush reg */ 22207c478bd9Sstevel@tonic-gate uint_t mondo; 22217c478bd9Sstevel@tonic-gate uint_t cpu_id; 22227c478bd9Sstevel@tonic-gate 22237c478bd9Sstevel@tonic-gate /* extract the soft state pointer */ 22247c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate last_mondo_vec_reg = NULL; 22277c478bd9Sstevel@tonic-gate for (mondo = 0; mondo < SZ_INO_TABLE; mondo++) { 22287c478bd9Sstevel@tonic-gate if (ino_table[mondo] == NULL) 22297c478bd9Sstevel@tonic-gate continue; 22307c478bd9Sstevel@tonic-gate 22317c478bd9Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg + 22327c478bd9Sstevel@tonic-gate ino_table[mondo]->mapping_reg); 22337c478bd9Sstevel@tonic-gate 22347c478bd9Sstevel@tonic-gate /* Don't reprogram the same register twice */ 22357c478bd9Sstevel@tonic-gate if (mondo_vec_reg == last_mondo_vec_reg) 22367c478bd9Sstevel@tonic-gate continue; 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate if ((*mondo_vec_reg & INTERRUPT_VALID) == 0) 22397c478bd9Sstevel@tonic-gate continue; 22407c478bd9Sstevel@tonic-gate 22417c478bd9Sstevel@tonic-gate last_mondo_vec_reg = (uint64_t *)mondo_vec_reg; 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate cpu_id = intr_dist_cpuid(); 22447c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 22457c478bd9Sstevel@tonic-gate /* 22467c478bd9Sstevel@tonic-gate * For Starfire it is a pain to check the current target for 22477c478bd9Sstevel@tonic-gate * the mondo since we have to read the PC asics ITTR slot 22487c478bd9Sstevel@tonic-gate * assigned to this mondo. It will be much easier to assume 22497c478bd9Sstevel@tonic-gate * the current target is always different and do the target 22507c478bd9Sstevel@tonic-gate * reprogram all the time. 22517c478bd9Sstevel@tonic-gate */ 22527c478bd9Sstevel@tonic-gate #else 22537c478bd9Sstevel@tonic-gate if (((*mondo_vec_reg & IMR_TID) >> IMR_TID_SHIFT) == cpu_id) { 22547c478bd9Sstevel@tonic-gate /* It is the same, don't reprogram */ 22557c478bd9Sstevel@tonic-gate return; 22567c478bd9Sstevel@tonic-gate } 22577c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 22587c478bd9Sstevel@tonic-gate 22597c478bd9Sstevel@tonic-gate /* So it's OK to reprogram the CPU target */ 22607c478bd9Sstevel@tonic-gate 22617c478bd9Sstevel@tonic-gate /* turn off valid bit and wait for the state machine to idle */ 22627c478bd9Sstevel@tonic-gate *mondo_vec_reg &= ~INTERRUPT_VALID; 22637c478bd9Sstevel@tonic-gate 22647c478bd9Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg; 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate #ifdef lint 22677c478bd9Sstevel@tonic-gate tmpreg = tmpreg; 22687c478bd9Sstevel@tonic-gate #endif /* lint */ 22697c478bd9Sstevel@tonic-gate 22707c478bd9Sstevel@tonic-gate if (mondo > MAX_MONDO_EXTERNAL) { 22717c478bd9Sstevel@tonic-gate start_bit = ino_table[mondo]->diagreg_shift; 22727c478bd9Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state; 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate /* 22757c478bd9Sstevel@tonic-gate * Loop waiting for state machine to idle. Do not keep 22767c478bd9Sstevel@tonic-gate * looping on a panic so that the system does not hang. 22777c478bd9Sstevel@tonic-gate */ 22787c478bd9Sstevel@tonic-gate while ((((*intr_state_reg >> start_bit) & 0x3) == 22797c478bd9Sstevel@tonic-gate INT_PENDING) && !panicstr) 22807c478bd9Sstevel@tonic-gate /* empty */; 22817c478bd9Sstevel@tonic-gate } else { 22827c478bd9Sstevel@tonic-gate int int_pending = 0; /* interrupts pending */ 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate /* 22857c478bd9Sstevel@tonic-gate * Shift over to first bit for this Sbus slot, 16 22867c478bd9Sstevel@tonic-gate * bits per slot, bits 0-1 of each slot are reserved. 22877c478bd9Sstevel@tonic-gate */ 22887c478bd9Sstevel@tonic-gate start_bit = 16 * (mondo >> 3) + 2; 22897c478bd9Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state; 22907c478bd9Sstevel@tonic-gate 22917c478bd9Sstevel@tonic-gate /* 22927c478bd9Sstevel@tonic-gate * Make sure interrupts for levels 1-7 of this slot 22937c478bd9Sstevel@tonic-gate * are not pending. 22947c478bd9Sstevel@tonic-gate */ 22957c478bd9Sstevel@tonic-gate do { 22967c478bd9Sstevel@tonic-gate int level; /* Sbus interrupt level */ 22977c478bd9Sstevel@tonic-gate int shift; /* # of bits to shift */ 22987c478bd9Sstevel@tonic-gate uint64_t state_reg = *intr_state_reg; 22997c478bd9Sstevel@tonic-gate 23007c478bd9Sstevel@tonic-gate int_pending = 0; 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate for (shift = start_bit, level = 1; level < 8; 23037c478bd9Sstevel@tonic-gate level++, shift += 2) { 23047c478bd9Sstevel@tonic-gate if (((state_reg >> shift) & 23057c478bd9Sstevel@tonic-gate 0x3) == INT_PENDING) { 23067c478bd9Sstevel@tonic-gate int_pending = 1; 23077c478bd9Sstevel@tonic-gate break; 23087c478bd9Sstevel@tonic-gate } 23097c478bd9Sstevel@tonic-gate } 23107c478bd9Sstevel@tonic-gate } while (int_pending && !panicstr); 23117c478bd9Sstevel@tonic-gate } 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate /* re-target the mondo and turn it on */ 23147c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 23157c478bd9Sstevel@tonic-gate mondo_vec = (pc_translate_tgtid(softsp->ittrans_cookie, 23167c478bd9Sstevel@tonic-gate cpu_id, mondo_vec_reg) << 23177c478bd9Sstevel@tonic-gate INTERRUPT_CPU_FIELD) | 23187c478bd9Sstevel@tonic-gate INTERRUPT_VALID; 23197c478bd9Sstevel@tonic-gate #else 23207c478bd9Sstevel@tonic-gate mondo_vec = (cpu_id << INTERRUPT_CPU_FIELD) | INTERRUPT_VALID; 23217c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 23227c478bd9Sstevel@tonic-gate 23237c478bd9Sstevel@tonic-gate /* write it back to the hardware. */ 23247c478bd9Sstevel@tonic-gate *mondo_vec_reg = mondo_vec; 23257c478bd9Sstevel@tonic-gate 23267c478bd9Sstevel@tonic-gate /* flush the hardware buffers. */ 23277c478bd9Sstevel@tonic-gate tmpreg = *mondo_vec_reg; 23287c478bd9Sstevel@tonic-gate 23297c478bd9Sstevel@tonic-gate #ifdef lint 23307c478bd9Sstevel@tonic-gate tmpreg = tmpreg; 23317c478bd9Sstevel@tonic-gate #endif /* lint */ 23327c478bd9Sstevel@tonic-gate } 23337c478bd9Sstevel@tonic-gate } 23347c478bd9Sstevel@tonic-gate 23357c478bd9Sstevel@tonic-gate /* 23367c478bd9Sstevel@tonic-gate * Reset interrupts to IDLE. This function is called during 23377c478bd9Sstevel@tonic-gate * panic handling after redistributing interrupts; it's needed to 23387c478bd9Sstevel@tonic-gate * support dumping to network devices after 'sync' from OBP. 23397c478bd9Sstevel@tonic-gate * 23407c478bd9Sstevel@tonic-gate * N.B. This routine runs in a context where all other threads 23417c478bd9Sstevel@tonic-gate * are permanently suspended. 23427c478bd9Sstevel@tonic-gate */ 23437c478bd9Sstevel@tonic-gate static uint_t 23447c478bd9Sstevel@tonic-gate sbus_intr_reset(void *arg) 23457c478bd9Sstevel@tonic-gate { 23467c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 23477c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp; 23487c478bd9Sstevel@tonic-gate uint_t mondo; 23497c478bd9Sstevel@tonic-gate volatile uint64_t *mondo_clear_reg; 23507c478bd9Sstevel@tonic-gate 23517c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 23527c478bd9Sstevel@tonic-gate 23537c478bd9Sstevel@tonic-gate for (mondo = 0; mondo < SZ_INO_TABLE; mondo++) { 23547c478bd9Sstevel@tonic-gate if (ino_table[mondo] == NULL || 23557c478bd9Sstevel@tonic-gate ino_table[mondo]->clear_reg == NULL) { 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate continue; 23587c478bd9Sstevel@tonic-gate } 23597c478bd9Sstevel@tonic-gate 23607c478bd9Sstevel@tonic-gate mondo_clear_reg = (softsp->clr_intr_reg + 23617c478bd9Sstevel@tonic-gate ino_table[mondo]->clear_reg); 23627c478bd9Sstevel@tonic-gate *mondo_clear_reg = SBUS_INTR_IDLE; 23637c478bd9Sstevel@tonic-gate } 23647c478bd9Sstevel@tonic-gate 23657c478bd9Sstevel@tonic-gate return (BF_NONE); 23667c478bd9Sstevel@tonic-gate } 23677c478bd9Sstevel@tonic-gate 23687c478bd9Sstevel@tonic-gate /* 23697c478bd9Sstevel@tonic-gate * called from sbus_add_kstats() to create a kstat for each %pic 23707c478bd9Sstevel@tonic-gate * that the SBUS supports. These (read-only) kstats export the 23717c478bd9Sstevel@tonic-gate * event names that each %pic supports. 23727c478bd9Sstevel@tonic-gate * 23737c478bd9Sstevel@tonic-gate * if we fail to create any of these kstats we must remove any 23747c478bd9Sstevel@tonic-gate * that we have already created and return; 23757c478bd9Sstevel@tonic-gate * 23767c478bd9Sstevel@tonic-gate * NOTE: because all sbus devices use the same events we only 23777c478bd9Sstevel@tonic-gate * need to create the picN kstats once. All instances can 23787c478bd9Sstevel@tonic-gate * use the same picN kstats. 23797c478bd9Sstevel@tonic-gate * 23807c478bd9Sstevel@tonic-gate * The flexibility exists to allow each device specify it's 23817c478bd9Sstevel@tonic-gate * own events by creating picN kstats with the instance number 23827c478bd9Sstevel@tonic-gate * set to ddi_get_instance(softsp->dip). 23837c478bd9Sstevel@tonic-gate * 23847c478bd9Sstevel@tonic-gate * When searching for a picN kstat for a device you should 23857c478bd9Sstevel@tonic-gate * first search for a picN kstat using the instance number 23867c478bd9Sstevel@tonic-gate * of the device you are interested in. If that fails you 23877c478bd9Sstevel@tonic-gate * should use the first picN kstat found for that device. 23887c478bd9Sstevel@tonic-gate */ 23897c478bd9Sstevel@tonic-gate static void 23907c478bd9Sstevel@tonic-gate sbus_add_picN_kstats(dev_info_t *dip) 23917c478bd9Sstevel@tonic-gate { 23927c478bd9Sstevel@tonic-gate /* 23937c478bd9Sstevel@tonic-gate * SBUS Performance Events. 23947c478bd9Sstevel@tonic-gate * 23957c478bd9Sstevel@tonic-gate * We declare an array of event-names and event-masks. 23967c478bd9Sstevel@tonic-gate * The num of events in this array is AC_NUM_EVENTS. 23977c478bd9Sstevel@tonic-gate */ 23987c478bd9Sstevel@tonic-gate sbus_event_mask_t sbus_events_arr[SBUS_NUM_EVENTS] = { 23997c478bd9Sstevel@tonic-gate {"dvma_stream_rd", 0x0}, {"dvma_stream_wr", 0x1}, 24007c478bd9Sstevel@tonic-gate {"dvma_const_rd", 0x2}, {"dvma_const_wr", 0x3}, 24017c478bd9Sstevel@tonic-gate {"dvma_tlb_misses", 0x4}, {"dvma_stream_buf_mis", 0x5}, 24027c478bd9Sstevel@tonic-gate {"dvma_cycles", 0x6}, {"dvma_bytes_xfr", 0x7}, 24037c478bd9Sstevel@tonic-gate {"interrupts", 0x8}, {"upa_inter_nack", 0x9}, 24047c478bd9Sstevel@tonic-gate {"pio_reads", 0xA}, {"pio_writes", 0xB}, 24057c478bd9Sstevel@tonic-gate {"sbus_reruns", 0xC}, {"pio_cycles", 0xD} 24067c478bd9Sstevel@tonic-gate }; 24077c478bd9Sstevel@tonic-gate 24087c478bd9Sstevel@tonic-gate /* 24097c478bd9Sstevel@tonic-gate * We declare an array of clear masks for each pic. 24107c478bd9Sstevel@tonic-gate * These masks are used to clear the %pcr bits for 24117c478bd9Sstevel@tonic-gate * each pic. 24127c478bd9Sstevel@tonic-gate */ 24137c478bd9Sstevel@tonic-gate sbus_event_mask_t sbus_clear_pic[SBUS_NUM_PICS] = { 24147c478bd9Sstevel@tonic-gate /* pic0 */ 24157c478bd9Sstevel@tonic-gate {"clear_pic", (uint64_t)~(0xf)}, 24167c478bd9Sstevel@tonic-gate /* pic1 */ 24177c478bd9Sstevel@tonic-gate {"clear_pic", (uint64_t)~(0xf << 8)} 24187c478bd9Sstevel@tonic-gate }; 24197c478bd9Sstevel@tonic-gate 24207c478bd9Sstevel@tonic-gate struct kstat_named *sbus_pic_named_data; 24217c478bd9Sstevel@tonic-gate int event, pic; 24227c478bd9Sstevel@tonic-gate char pic_name[30]; 24237c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip); 24247c478bd9Sstevel@tonic-gate int pic_shift = 0; 24257c478bd9Sstevel@tonic-gate 24267c478bd9Sstevel@tonic-gate for (pic = 0; pic < SBUS_NUM_PICS; pic++) { 24277c478bd9Sstevel@tonic-gate /* 24287c478bd9Sstevel@tonic-gate * create the picN kstat. The size of this kstat is 24297c478bd9Sstevel@tonic-gate * SBUS_NUM_EVENTS + 1 for the clear_event_mask 24307c478bd9Sstevel@tonic-gate */ 24317c478bd9Sstevel@tonic-gate (void) sprintf(pic_name, "pic%d", pic); /* pic0, pic1 ... */ 24327c478bd9Sstevel@tonic-gate if ((sbus_picN_ksp[pic] = kstat_create("sbus", 24337c478bd9Sstevel@tonic-gate instance, pic_name, "bus", KSTAT_TYPE_NAMED, 24347c478bd9Sstevel@tonic-gate SBUS_NUM_EVENTS + 1, NULL)) == NULL) { 24357c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "sbus %s: kstat_create failed", 24367c478bd9Sstevel@tonic-gate pic_name); 24377c478bd9Sstevel@tonic-gate 24387c478bd9Sstevel@tonic-gate /* remove pic0 kstat if pic1 create fails */ 24397c478bd9Sstevel@tonic-gate if (pic == 1) { 24407c478bd9Sstevel@tonic-gate kstat_delete(sbus_picN_ksp[0]); 24417c478bd9Sstevel@tonic-gate sbus_picN_ksp[0] = NULL; 24427c478bd9Sstevel@tonic-gate } 24437c478bd9Sstevel@tonic-gate return; 24447c478bd9Sstevel@tonic-gate } 24457c478bd9Sstevel@tonic-gate 24467c478bd9Sstevel@tonic-gate sbus_pic_named_data = 24477c478bd9Sstevel@tonic-gate (struct kstat_named *)(sbus_picN_ksp[pic]->ks_data); 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate /* 24507c478bd9Sstevel@tonic-gate * when we are writing pcr_masks to the kstat we need to 24517c478bd9Sstevel@tonic-gate * shift bits left by 8 for pic1 events. 24527c478bd9Sstevel@tonic-gate */ 24537c478bd9Sstevel@tonic-gate if (pic == 1) 24547c478bd9Sstevel@tonic-gate pic_shift = 8; 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate /* 24577c478bd9Sstevel@tonic-gate * for each picN event we need to write a kstat record 24587c478bd9Sstevel@tonic-gate * (name = EVENT, value.ui64 = PCR_MASK) 24597c478bd9Sstevel@tonic-gate */ 24607c478bd9Sstevel@tonic-gate for (event = 0; event < SBUS_NUM_EVENTS; event ++) { 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate /* pcr_mask */ 24637c478bd9Sstevel@tonic-gate sbus_pic_named_data[event].value.ui64 = 24647c478bd9Sstevel@tonic-gate sbus_events_arr[event].pcr_mask << pic_shift; 24657c478bd9Sstevel@tonic-gate 24667c478bd9Sstevel@tonic-gate /* event-name */ 24677c478bd9Sstevel@tonic-gate kstat_named_init(&sbus_pic_named_data[event], 24687c478bd9Sstevel@tonic-gate sbus_events_arr[event].event_name, 24697c478bd9Sstevel@tonic-gate KSTAT_DATA_UINT64); 24707c478bd9Sstevel@tonic-gate } 24717c478bd9Sstevel@tonic-gate 24727c478bd9Sstevel@tonic-gate /* 24737c478bd9Sstevel@tonic-gate * we add the clear_pic event and mask as the last 24747c478bd9Sstevel@tonic-gate * record in the kstat 24757c478bd9Sstevel@tonic-gate */ 24767c478bd9Sstevel@tonic-gate /* pcr mask */ 24777c478bd9Sstevel@tonic-gate sbus_pic_named_data[SBUS_NUM_EVENTS].value.ui64 = 24787c478bd9Sstevel@tonic-gate sbus_clear_pic[pic].pcr_mask; 24797c478bd9Sstevel@tonic-gate 24807c478bd9Sstevel@tonic-gate /* event-name */ 24817c478bd9Sstevel@tonic-gate kstat_named_init(&sbus_pic_named_data[SBUS_NUM_EVENTS], 24827c478bd9Sstevel@tonic-gate sbus_clear_pic[pic].event_name, 24837c478bd9Sstevel@tonic-gate KSTAT_DATA_UINT64); 24847c478bd9Sstevel@tonic-gate 24857c478bd9Sstevel@tonic-gate kstat_install(sbus_picN_ksp[pic]); 24867c478bd9Sstevel@tonic-gate } 24877c478bd9Sstevel@tonic-gate } 24887c478bd9Sstevel@tonic-gate 24897c478bd9Sstevel@tonic-gate static void 24907c478bd9Sstevel@tonic-gate sbus_add_kstats(struct sbus_soft_state *softsp) 24917c478bd9Sstevel@tonic-gate { 24927c478bd9Sstevel@tonic-gate struct kstat *sbus_counters_ksp; 24937c478bd9Sstevel@tonic-gate struct kstat_named *sbus_counters_named_data; 24947c478bd9Sstevel@tonic-gate 24957c478bd9Sstevel@tonic-gate /* 24967c478bd9Sstevel@tonic-gate * Create the picN kstats if we are the first instance 24977c478bd9Sstevel@tonic-gate * to attach. We use sbus_attachcnt as a count of how 24987c478bd9Sstevel@tonic-gate * many instances have attached. This is protected by 24997c478bd9Sstevel@tonic-gate * a mutex. 25007c478bd9Sstevel@tonic-gate */ 25017c478bd9Sstevel@tonic-gate mutex_enter(&sbus_attachcnt_mutex); 25027c478bd9Sstevel@tonic-gate if (sbus_attachcnt == 0) 25037c478bd9Sstevel@tonic-gate sbus_add_picN_kstats(softsp->dip); 25047c478bd9Sstevel@tonic-gate 25057c478bd9Sstevel@tonic-gate sbus_attachcnt ++; 25067c478bd9Sstevel@tonic-gate mutex_exit(&sbus_attachcnt_mutex); 25077c478bd9Sstevel@tonic-gate 25087c478bd9Sstevel@tonic-gate /* 25097c478bd9Sstevel@tonic-gate * A "counter" kstat is created for each sbus 25107c478bd9Sstevel@tonic-gate * instance that provides access to the %pcr and %pic 25117c478bd9Sstevel@tonic-gate * registers for that instance. 25127c478bd9Sstevel@tonic-gate * 25137c478bd9Sstevel@tonic-gate * The size of this kstat is SBUS_NUM_PICS + 1 for %pcr 25147c478bd9Sstevel@tonic-gate */ 25157c478bd9Sstevel@tonic-gate if ((sbus_counters_ksp = kstat_create("sbus", 25167c478bd9Sstevel@tonic-gate ddi_get_instance(softsp->dip), "counters", 25177c478bd9Sstevel@tonic-gate "bus", KSTAT_TYPE_NAMED, SBUS_NUM_PICS + 1, 25187c478bd9Sstevel@tonic-gate KSTAT_FLAG_WRITABLE)) == NULL) { 25197c478bd9Sstevel@tonic-gate 25207c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "sbus%d counters: kstat_create" 25217c478bd9Sstevel@tonic-gate " failed", ddi_get_instance(softsp->dip)); 25227c478bd9Sstevel@tonic-gate return; 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate 25257c478bd9Sstevel@tonic-gate sbus_counters_named_data = 25267c478bd9Sstevel@tonic-gate (struct kstat_named *)(sbus_counters_ksp->ks_data); 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate /* initialize the named kstats */ 25297c478bd9Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[0], 25307c478bd9Sstevel@tonic-gate "pcr", KSTAT_DATA_UINT64); 25317c478bd9Sstevel@tonic-gate 25327c478bd9Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[1], 25337c478bd9Sstevel@tonic-gate "pic0", KSTAT_DATA_UINT64); 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[2], 25367c478bd9Sstevel@tonic-gate "pic1", KSTAT_DATA_UINT64); 25377c478bd9Sstevel@tonic-gate 25387c478bd9Sstevel@tonic-gate sbus_counters_ksp->ks_update = sbus_counters_kstat_update; 25397c478bd9Sstevel@tonic-gate sbus_counters_ksp->ks_private = (void *)softsp; 25407c478bd9Sstevel@tonic-gate 25417c478bd9Sstevel@tonic-gate kstat_install(sbus_counters_ksp); 25427c478bd9Sstevel@tonic-gate 25437c478bd9Sstevel@tonic-gate /* update the sofstate */ 25447c478bd9Sstevel@tonic-gate softsp->sbus_counters_ksp = sbus_counters_ksp; 25457c478bd9Sstevel@tonic-gate } 25467c478bd9Sstevel@tonic-gate 25477c478bd9Sstevel@tonic-gate static int 25487c478bd9Sstevel@tonic-gate sbus_counters_kstat_update(kstat_t *ksp, int rw) 25497c478bd9Sstevel@tonic-gate { 25507c478bd9Sstevel@tonic-gate struct kstat_named *sbus_counters_data; 25517c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp; 25527c478bd9Sstevel@tonic-gate uint64_t pic_register; 25537c478bd9Sstevel@tonic-gate 25547c478bd9Sstevel@tonic-gate sbus_counters_data = (struct kstat_named *)ksp->ks_data; 25557c478bd9Sstevel@tonic-gate softsp = (struct sbus_soft_state *)ksp->ks_private; 25567c478bd9Sstevel@tonic-gate 25577c478bd9Sstevel@tonic-gate if (rw == KSTAT_WRITE) { 25587c478bd9Sstevel@tonic-gate 25597c478bd9Sstevel@tonic-gate /* 25607c478bd9Sstevel@tonic-gate * Write the pcr value to the softsp->sbus_pcr. 25617c478bd9Sstevel@tonic-gate * The pic register is read-only so we don't 25627c478bd9Sstevel@tonic-gate * attempt to write to it. 25637c478bd9Sstevel@tonic-gate */ 25647c478bd9Sstevel@tonic-gate 25657c478bd9Sstevel@tonic-gate *softsp->sbus_pcr = 25667c478bd9Sstevel@tonic-gate (uint32_t)sbus_counters_data[0].value.ui64; 25677c478bd9Sstevel@tonic-gate 25687c478bd9Sstevel@tonic-gate } else { 25697c478bd9Sstevel@tonic-gate /* 25707c478bd9Sstevel@tonic-gate * Read %pcr and %pic register values and write them 25717c478bd9Sstevel@tonic-gate * into counters kstat. 25727c478bd9Sstevel@tonic-gate * 25737c478bd9Sstevel@tonic-gate * Due to a hardware bug we need to right shift the %pcr 25747c478bd9Sstevel@tonic-gate * by 4 bits. This is only done when reading the %pcr. 25757c478bd9Sstevel@tonic-gate * 25767c478bd9Sstevel@tonic-gate */ 25777c478bd9Sstevel@tonic-gate /* pcr */ 25787c478bd9Sstevel@tonic-gate sbus_counters_data[0].value.ui64 = *softsp->sbus_pcr >> 4; 25797c478bd9Sstevel@tonic-gate 25807c478bd9Sstevel@tonic-gate pic_register = *softsp->sbus_pic; 25817c478bd9Sstevel@tonic-gate /* 25827c478bd9Sstevel@tonic-gate * sbus pic register: 25837c478bd9Sstevel@tonic-gate * (63:32) = pic0 25847c478bd9Sstevel@tonic-gate * (31:00) = pic1 25857c478bd9Sstevel@tonic-gate */ 25867c478bd9Sstevel@tonic-gate 25877c478bd9Sstevel@tonic-gate /* pic0 */ 25887c478bd9Sstevel@tonic-gate sbus_counters_data[1].value.ui64 = pic_register >> 32; 25897c478bd9Sstevel@tonic-gate /* pic1 */ 25907c478bd9Sstevel@tonic-gate sbus_counters_data[2].value.ui64 = 25917c478bd9Sstevel@tonic-gate pic_register & SBUS_PIC0_MASK; 25927c478bd9Sstevel@tonic-gate 25937c478bd9Sstevel@tonic-gate } 25947c478bd9Sstevel@tonic-gate return (0); 25957c478bd9Sstevel@tonic-gate } 25967c478bd9Sstevel@tonic-gate 25977c478bd9Sstevel@tonic-gate static int 25987c478bd9Sstevel@tonic-gate sbus_update_intr_state(dev_info_t *dip, dev_info_t *rdip, 25997c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state) 26007c478bd9Sstevel@tonic-gate { 26017c478bd9Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *) 26027c478bd9Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip)); 26037c478bd9Sstevel@tonic-gate int ino; 26047c478bd9Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg; 26057c478bd9Sstevel@tonic-gate struct sbus_intr_handler *intr_handler; 26067c478bd9Sstevel@tonic-gate 26077c478bd9Sstevel@tonic-gate /* Xlate the interrupt */ 2608a195726fSgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector, 2609a195726fSgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) { 26107c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "sbus_update_intr_state() can't xlate SBUS " 2611a195726fSgovinda "devices %s interrupt.", ddi_driver_name(rdip)); 26127c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 26137c478bd9Sstevel@tonic-gate } 26147c478bd9Sstevel@tonic-gate 2615a195726fSgovinda ino = ((int32_t)hdlp->ih_vector) & SBUS_MAX_INO; 26167c478bd9Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino]; 26177c478bd9Sstevel@tonic-gate 26187c478bd9Sstevel@tonic-gate ASSERT(sbus_arg != NULL); 26197c478bd9Sstevel@tonic-gate ASSERT(sbus_arg->handler_list != NULL); 26207c478bd9Sstevel@tonic-gate intr_handler = sbus_arg->handler_list; 26217c478bd9Sstevel@tonic-gate 26227c478bd9Sstevel@tonic-gate while (intr_handler) { 26237c478bd9Sstevel@tonic-gate if ((intr_handler->inum == hdlp->ih_inum) && 26247c478bd9Sstevel@tonic-gate (intr_handler->dip == rdip)) { 26257c478bd9Sstevel@tonic-gate intr_handler->intr_state = new_intr_state; 26267c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 26277c478bd9Sstevel@tonic-gate } 26287c478bd9Sstevel@tonic-gate 26297c478bd9Sstevel@tonic-gate intr_handler = intr_handler->next; 26307c478bd9Sstevel@tonic-gate } 26317c478bd9Sstevel@tonic-gate 26327c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 26337c478bd9Sstevel@tonic-gate } 2634