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