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