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;
1166