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