10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
52580Sanish * Common Development and Distribution License (the "License").
62580Sanish * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
227240Srh87107 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/conf.h>
290Sstevel@tonic-gate #include <sys/ddi.h>
300Sstevel@tonic-gate #include <sys/sunddi.h>
310Sstevel@tonic-gate #include <sys/sunndi.h>
320Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
330Sstevel@tonic-gate #include <sys/ddi_implfuncs.h>
340Sstevel@tonic-gate #include <sys/obpdefs.h>
350Sstevel@tonic-gate #include <sys/cmn_err.h>
360Sstevel@tonic-gate #include <sys/errno.h>
370Sstevel@tonic-gate #include <sys/kmem.h>
380Sstevel@tonic-gate #include <sys/debug.h>
390Sstevel@tonic-gate #include <sys/sysmacros.h>
400Sstevel@tonic-gate #include <sys/autoconf.h>
410Sstevel@tonic-gate #include <sys/spl.h>
420Sstevel@tonic-gate #include <sys/iommu.h>
430Sstevel@tonic-gate #include <sys/sysiosbus.h>
440Sstevel@tonic-gate #include <sys/sysioerr.h>
450Sstevel@tonic-gate #include <sys/iocache.h>
460Sstevel@tonic-gate #include <sys/async.h>
470Sstevel@tonic-gate #include <sys/machsystm.h>
480Sstevel@tonic-gate #include <sys/intreg.h>
490Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
500Sstevel@tonic-gate #ifdef _STARFIRE
510Sstevel@tonic-gate #include <sys/starfire.h>
520Sstevel@tonic-gate #endif /* _STARFIRE */
530Sstevel@tonic-gate #include <sys/sdt.h>
540Sstevel@tonic-gate
550Sstevel@tonic-gate /* Useful debugging Stuff */
560Sstevel@tonic-gate #include <sys/nexusdebug.h>
570Sstevel@tonic-gate /* Bitfield debugging definitions for this file */
580Sstevel@tonic-gate #define SBUS_ATTACH_DEBUG 0x1
590Sstevel@tonic-gate #define SBUS_SBUSMEM_DEBUG 0x2
600Sstevel@tonic-gate #define SBUS_INTERRUPT_DEBUG 0x4
610Sstevel@tonic-gate #define SBUS_REGISTERS_DEBUG 0x8
620Sstevel@tonic-gate
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate * Interrupt registers table.
650Sstevel@tonic-gate * This table is necessary due to inconsistencies in the sysio register
660Sstevel@tonic-gate * layout. If this gets fixed in the chip, we can get rid of this stupid
670Sstevel@tonic-gate * table.
680Sstevel@tonic-gate */
690Sstevel@tonic-gate static struct sbus_slot_entry ino_1 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
700Sstevel@tonic-gate SBUS_SLOT0_L1_CLEAR, NULL};
710Sstevel@tonic-gate static struct sbus_slot_entry ino_2 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
720Sstevel@tonic-gate SBUS_SLOT0_L2_CLEAR, NULL};
730Sstevel@tonic-gate static struct sbus_slot_entry ino_3 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
740Sstevel@tonic-gate SBUS_SLOT0_L3_CLEAR, NULL};
750Sstevel@tonic-gate static struct sbus_slot_entry ino_4 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
760Sstevel@tonic-gate SBUS_SLOT0_L4_CLEAR, NULL};
770Sstevel@tonic-gate static struct sbus_slot_entry ino_5 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
780Sstevel@tonic-gate SBUS_SLOT0_L5_CLEAR, NULL};
790Sstevel@tonic-gate static struct sbus_slot_entry ino_6 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
800Sstevel@tonic-gate SBUS_SLOT0_L6_CLEAR, NULL};
810Sstevel@tonic-gate static struct sbus_slot_entry ino_7 = {SBUS_SLOT0_CONFIG, SBUS_SLOT0_MAPREG,
820Sstevel@tonic-gate SBUS_SLOT0_L7_CLEAR, NULL};
830Sstevel@tonic-gate static struct sbus_slot_entry ino_9 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
840Sstevel@tonic-gate SBUS_SLOT1_L1_CLEAR, NULL};
850Sstevel@tonic-gate static struct sbus_slot_entry ino_10 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
860Sstevel@tonic-gate SBUS_SLOT1_L2_CLEAR, NULL};
870Sstevel@tonic-gate static struct sbus_slot_entry ino_11 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
880Sstevel@tonic-gate SBUS_SLOT1_L3_CLEAR, NULL};
890Sstevel@tonic-gate static struct sbus_slot_entry ino_12 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
900Sstevel@tonic-gate SBUS_SLOT1_L4_CLEAR, NULL};
910Sstevel@tonic-gate static struct sbus_slot_entry ino_13 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
920Sstevel@tonic-gate SBUS_SLOT1_L5_CLEAR, NULL};
930Sstevel@tonic-gate static struct sbus_slot_entry ino_14 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
940Sstevel@tonic-gate SBUS_SLOT1_L6_CLEAR, NULL};
950Sstevel@tonic-gate static struct sbus_slot_entry ino_15 = {SBUS_SLOT1_CONFIG, SBUS_SLOT1_MAPREG,
960Sstevel@tonic-gate SBUS_SLOT1_L7_CLEAR, NULL};
970Sstevel@tonic-gate static struct sbus_slot_entry ino_17 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
980Sstevel@tonic-gate SBUS_SLOT2_L1_CLEAR, NULL};
990Sstevel@tonic-gate static struct sbus_slot_entry ino_18 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
1000Sstevel@tonic-gate SBUS_SLOT2_L2_CLEAR, NULL};
1010Sstevel@tonic-gate static struct sbus_slot_entry ino_19 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
1020Sstevel@tonic-gate SBUS_SLOT2_L3_CLEAR, NULL};
1030Sstevel@tonic-gate static struct sbus_slot_entry ino_20 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
1040Sstevel@tonic-gate SBUS_SLOT2_L4_CLEAR, NULL};
1050Sstevel@tonic-gate static struct sbus_slot_entry ino_21 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
1060Sstevel@tonic-gate SBUS_SLOT2_L5_CLEAR, NULL};
1070Sstevel@tonic-gate static struct sbus_slot_entry ino_22 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
1080Sstevel@tonic-gate SBUS_SLOT2_L6_CLEAR, NULL};
1090Sstevel@tonic-gate static struct sbus_slot_entry ino_23 = {SBUS_SLOT2_CONFIG, SBUS_SLOT2_MAPREG,
1100Sstevel@tonic-gate SBUS_SLOT2_L7_CLEAR, NULL};
1110Sstevel@tonic-gate static struct sbus_slot_entry ino_25 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1120Sstevel@tonic-gate SBUS_SLOT3_L1_CLEAR, NULL};
1130Sstevel@tonic-gate static struct sbus_slot_entry ino_26 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1140Sstevel@tonic-gate SBUS_SLOT3_L2_CLEAR, NULL};
1150Sstevel@tonic-gate static struct sbus_slot_entry ino_27 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1160Sstevel@tonic-gate SBUS_SLOT3_L3_CLEAR, NULL};
1170Sstevel@tonic-gate static struct sbus_slot_entry ino_28 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1180Sstevel@tonic-gate SBUS_SLOT3_L4_CLEAR, NULL};
1190Sstevel@tonic-gate static struct sbus_slot_entry ino_29 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1200Sstevel@tonic-gate SBUS_SLOT3_L5_CLEAR, NULL};
1210Sstevel@tonic-gate static struct sbus_slot_entry ino_30 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1220Sstevel@tonic-gate SBUS_SLOT3_L6_CLEAR, NULL};
1230Sstevel@tonic-gate static struct sbus_slot_entry ino_31 = {SBUS_SLOT3_CONFIG, SBUS_SLOT3_MAPREG,
1240Sstevel@tonic-gate SBUS_SLOT3_L7_CLEAR, NULL};
1250Sstevel@tonic-gate static struct sbus_slot_entry ino_32 = {SBUS_SLOT5_CONFIG, ESP_MAPREG,
1260Sstevel@tonic-gate ESP_CLEAR, ESP_INTR_STATE_SHIFT};
1270Sstevel@tonic-gate static struct sbus_slot_entry ino_33 = {SBUS_SLOT5_CONFIG, ETHER_MAPREG,
1280Sstevel@tonic-gate ETHER_CLEAR, ETHER_INTR_STATE_SHIFT};
1290Sstevel@tonic-gate static struct sbus_slot_entry ino_34 = {SBUS_SLOT5_CONFIG, PP_MAPREG,
1300Sstevel@tonic-gate PP_CLEAR, PP_INTR_STATE_SHIFT};
1310Sstevel@tonic-gate static struct sbus_slot_entry ino_36 = {SBUS_SLOT4_CONFIG, AUDIO_MAPREG,
1320Sstevel@tonic-gate AUDIO_CLEAR, AUDIO_INTR_STATE_SHIFT};
1330Sstevel@tonic-gate static struct sbus_slot_entry ino_40 = {SBUS_SLOT6_CONFIG, KBDMOUSE_MAPREG,
1340Sstevel@tonic-gate KBDMOUSE_CLEAR,
1350Sstevel@tonic-gate KBDMOUSE_INTR_STATE_SHIFT};
1360Sstevel@tonic-gate static struct sbus_slot_entry ino_41 = {SBUS_SLOT6_CONFIG, FLOPPY_MAPREG,
1370Sstevel@tonic-gate FLOPPY_CLEAR, FLOPPY_INTR_STATE_SHIFT};
1380Sstevel@tonic-gate static struct sbus_slot_entry ino_42 = {SBUS_SLOT6_CONFIG, THERMAL_MAPREG,
1390Sstevel@tonic-gate THERMAL_CLEAR,
1400Sstevel@tonic-gate THERMAL_INTR_STATE_SHIFT};
1410Sstevel@tonic-gate static struct sbus_slot_entry ino_48 = {SBUS_SLOT6_CONFIG, TIMER0_MAPREG,
1420Sstevel@tonic-gate TIMER0_CLEAR, TIMER0_INTR_STATE_SHIFT};
1430Sstevel@tonic-gate static struct sbus_slot_entry ino_49 = {SBUS_SLOT6_CONFIG, TIMER1_MAPREG,
1440Sstevel@tonic-gate TIMER1_CLEAR, TIMER1_INTR_STATE_SHIFT};
1450Sstevel@tonic-gate static struct sbus_slot_entry ino_52 = {SBUS_SLOT6_CONFIG, UE_ECC_MAPREG,
1460Sstevel@tonic-gate UE_ECC_CLEAR, UE_INTR_STATE_SHIFT};
1470Sstevel@tonic-gate static struct sbus_slot_entry ino_53 = {SBUS_SLOT6_CONFIG, CE_ECC_MAPREG,
1480Sstevel@tonic-gate CE_ECC_CLEAR, CE_INTR_STATE_SHIFT};
1490Sstevel@tonic-gate static struct sbus_slot_entry ino_54 = {SBUS_SLOT6_CONFIG, SBUS_ERR_MAPREG,
1500Sstevel@tonic-gate SBUS_ERR_CLEAR, SERR_INTR_STATE_SHIFT};
1510Sstevel@tonic-gate static struct sbus_slot_entry ino_55 = {SBUS_SLOT6_CONFIG, PM_WAKEUP_MAPREG,
1520Sstevel@tonic-gate PM_WAKEUP_CLEAR, PM_INTR_STATE_SHIFT};
1530Sstevel@tonic-gate static struct sbus_slot_entry ino_ffb = {NULL, FFB_MAPPING_REG, NULL, NULL};
1540Sstevel@tonic-gate static struct sbus_slot_entry ino_exp = {NULL, EXP_MAPPING_REG, NULL, NULL};
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate /* Construct the interrupt number array */
1570Sstevel@tonic-gate struct sbus_slot_entry *ino_table[] = {
1580Sstevel@tonic-gate NULL, &ino_1, &ino_2, &ino_3, &ino_4, &ino_5, &ino_6, &ino_7,
1590Sstevel@tonic-gate NULL, &ino_9, &ino_10, &ino_11, &ino_12, &ino_13, &ino_14, &ino_15,
1600Sstevel@tonic-gate NULL, &ino_17, &ino_18, &ino_19, &ino_20, &ino_21, &ino_22, &ino_23,
1610Sstevel@tonic-gate NULL, &ino_25, &ino_26, &ino_27, &ino_28, &ino_29, &ino_30, &ino_31,
1620Sstevel@tonic-gate &ino_32, &ino_33, &ino_34, NULL, &ino_36, NULL, NULL, NULL,
1630Sstevel@tonic-gate &ino_40, &ino_41, &ino_42, NULL, NULL, NULL, NULL, NULL, &ino_48,
1640Sstevel@tonic-gate &ino_49, NULL, NULL, &ino_52, &ino_53, &ino_54, &ino_55, &ino_ffb,
1650Sstevel@tonic-gate &ino_exp
1660Sstevel@tonic-gate };
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate /*
1690Sstevel@tonic-gate * This table represents the Fusion interrupt priorities. They range
1700Sstevel@tonic-gate * from 1 - 15, so we'll pattern the priorities after the 4M. We map Fusion
1710Sstevel@tonic-gate * interrupt number to system priority. The mondo number is used as an
1720Sstevel@tonic-gate * index into this table.
1730Sstevel@tonic-gate */
1740Sstevel@tonic-gate int interrupt_priorities[] = {
1750Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 0 sbus level 1 - 7 */
1760Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 1 sbus level 1 - 7 */
1770Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 2 sbus level 1 - 7 */
1780Sstevel@tonic-gate -1, 2, 3, 5, 7, 9, 11, 13, /* Slot 3 sbus level 1 - 7 */
1790Sstevel@tonic-gate 4, /* Onboard SCSI */
1800Sstevel@tonic-gate 6, /* Onboard Ethernet */
1810Sstevel@tonic-gate 3, /* Onboard Parallel port */
1820Sstevel@tonic-gate -1, /* Not in use */
1830Sstevel@tonic-gate 9, /* Onboard Audio */
1840Sstevel@tonic-gate -1, -1, -1, /* Not in use */
1850Sstevel@tonic-gate 12, /* Onboard keyboard/serial ports */
1860Sstevel@tonic-gate 11, /* Onboard Floppy */
1870Sstevel@tonic-gate 9, /* Thermal interrupt */
1880Sstevel@tonic-gate -1, -1, -1, /* Not is use */
1890Sstevel@tonic-gate 10, /* Timer 0 (tick timer) */
1900Sstevel@tonic-gate 14, /* Timer 1 (not used) */
1910Sstevel@tonic-gate 15, /* Sysio UE ECC error */
1920Sstevel@tonic-gate 10, /* Sysio CE ECC error */
1930Sstevel@tonic-gate 10, /* Sysio Sbus error */
1940Sstevel@tonic-gate 10, /* PM Wakeup */
1950Sstevel@tonic-gate };
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate /* Interrupt counter flag. To enable/disable spurious interrupt counter. */
1980Sstevel@tonic-gate static int intr_cntr_on;
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate * Function prototypes.
2020Sstevel@tonic-gate */
2030Sstevel@tonic-gate static int
2040Sstevel@tonic-gate sbus_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *);
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate static int
2070Sstevel@tonic-gate sbus_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
2080Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp);
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate static void
2110Sstevel@tonic-gate sbus_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
2120Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp);
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate static int
2150Sstevel@tonic-gate sbus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
2160Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result);
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate static int
219693Sgovinda sbus_xlate_intrs(dev_info_t *dip, dev_info_t *rdip, uint32_t *intr,
220693Sgovinda uint32_t *pil, int32_t ign);
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate static int
2230Sstevel@tonic-gate sbus_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate static int
2260Sstevel@tonic-gate sbus_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate static int
2290Sstevel@tonic-gate sbus_do_detach(dev_info_t *devi);
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate static void
2320Sstevel@tonic-gate sbus_add_picN_kstats(dev_info_t *dip);
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate static void
2350Sstevel@tonic-gate sbus_add_kstats(struct sbus_soft_state *);
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate static int
2380Sstevel@tonic-gate sbus_counters_kstat_update(kstat_t *, int);
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate extern int
2410Sstevel@tonic-gate sysio_err_uninit(struct sbus_soft_state *softsp);
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate extern int
2440Sstevel@tonic-gate iommu_uninit(struct sbus_soft_state *softsp);
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate extern int
2470Sstevel@tonic-gate stream_buf_uninit(struct sbus_soft_state *softsp);
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate static int
2500Sstevel@tonic-gate find_sbus_slot(dev_info_t *dip, dev_info_t *rdip);
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate static void make_sbus_ppd(dev_info_t *child);
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate static int
2550Sstevel@tonic-gate sbusmem_initchild(dev_info_t *dip, dev_info_t *child);
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate static int
2580Sstevel@tonic-gate sbus_initchild(dev_info_t *dip, dev_info_t *child);
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate static int
2610Sstevel@tonic-gate sbus_uninitchild(dev_info_t *dip);
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate static int
2640Sstevel@tonic-gate sbus_ctlops_poke(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args);
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate static int
2670Sstevel@tonic-gate sbus_ctlops_peek(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args,
2680Sstevel@tonic-gate void *result);
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate static int
2710Sstevel@tonic-gate sbus_init(struct sbus_soft_state *softsp, caddr_t address);
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate static int
2740Sstevel@tonic-gate sbus_resume_init(struct sbus_soft_state *softsp, int resume);
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate static void
2770Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(uint64_t *cpr_softsp, volatile uint64_t *baddr,
2780Sstevel@tonic-gate int flag);
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate static void sbus_intrdist(void *);
2810Sstevel@tonic-gate static uint_t sbus_intr_reset(void *);
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate static int
2840Sstevel@tonic-gate sbus_update_intr_state(dev_info_t *dip, dev_info_t *rdip,
2850Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state);
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate #ifdef _STARFIRE
2880Sstevel@tonic-gate void
2890Sstevel@tonic-gate pc_ittrans_init(int, caddr_t *);
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate void
2920Sstevel@tonic-gate pc_ittrans_uninit(caddr_t);
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate int
2950Sstevel@tonic-gate pc_translate_tgtid(caddr_t, int, volatile uint64_t *);
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate void
2980Sstevel@tonic-gate pc_ittrans_cleanup(caddr_t, volatile uint64_t *);
2990Sstevel@tonic-gate #endif /* _STARFIRE */
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate /*
3020Sstevel@tonic-gate * Configuration data structures
3030Sstevel@tonic-gate */
3040Sstevel@tonic-gate static struct bus_ops sbus_bus_ops = {
3050Sstevel@tonic-gate BUSO_REV,
3060Sstevel@tonic-gate i_ddi_bus_map,
3070Sstevel@tonic-gate 0,
3080Sstevel@tonic-gate 0,
3090Sstevel@tonic-gate 0,
3100Sstevel@tonic-gate i_ddi_map_fault,
3110Sstevel@tonic-gate iommu_dma_map,
3120Sstevel@tonic-gate iommu_dma_allochdl,
3130Sstevel@tonic-gate iommu_dma_freehdl,
3140Sstevel@tonic-gate iommu_dma_bindhdl,
3150Sstevel@tonic-gate iommu_dma_unbindhdl,
3160Sstevel@tonic-gate iommu_dma_flush,
3170Sstevel@tonic-gate iommu_dma_win,
3180Sstevel@tonic-gate iommu_dma_mctl,
3190Sstevel@tonic-gate sbus_ctlops,
3200Sstevel@tonic-gate ddi_bus_prop_op,
3210Sstevel@tonic-gate 0, /* (*bus_get_eventcookie)(); */
3220Sstevel@tonic-gate 0, /* (*bus_add_eventcall)(); */
3230Sstevel@tonic-gate 0, /* (*bus_remove_eventcall)(); */
3240Sstevel@tonic-gate 0, /* (*bus_post_event)(); */
3250Sstevel@tonic-gate 0, /* (*bus_intr_control)(); */
3260Sstevel@tonic-gate 0, /* (*bus_config)(); */
3270Sstevel@tonic-gate 0, /* (*bus_unconfig)(); */
3280Sstevel@tonic-gate 0, /* (*bus_fm_init)(); */
3290Sstevel@tonic-gate 0, /* (*bus_fm_fini)(); */
3300Sstevel@tonic-gate 0, /* (*bus_fm_access_enter)(); */
3310Sstevel@tonic-gate 0, /* (*bus_fm_access_exit)(); */
3320Sstevel@tonic-gate 0, /* (*bus_power)(); */
3330Sstevel@tonic-gate sbus_intr_ops /* (*bus_intr_op)(); */
3340Sstevel@tonic-gate };
3350Sstevel@tonic-gate
3360Sstevel@tonic-gate static struct cb_ops sbus_cb_ops = {
3370Sstevel@tonic-gate nodev, /* open */
3380Sstevel@tonic-gate nodev, /* close */
3390Sstevel@tonic-gate nodev, /* strategy */
3400Sstevel@tonic-gate nodev, /* print */
3410Sstevel@tonic-gate nodev, /* dump */
3420Sstevel@tonic-gate nodev, /* read */
3430Sstevel@tonic-gate nodev, /* write */
3440Sstevel@tonic-gate nodev, /* ioctl */
3450Sstevel@tonic-gate nodev, /* devmap */
3460Sstevel@tonic-gate nodev, /* mmap */
3470Sstevel@tonic-gate nodev, /* segmap */
3480Sstevel@tonic-gate nochpoll, /* poll */
3490Sstevel@tonic-gate ddi_prop_op, /* prop_op */
3500Sstevel@tonic-gate NULL,
3510Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG,
3520Sstevel@tonic-gate CB_REV, /* rev */
3530Sstevel@tonic-gate nodev, /* int (*cb_aread)() */
3540Sstevel@tonic-gate nodev /* int (*cb_awrite)() */
3550Sstevel@tonic-gate };
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate static struct dev_ops sbus_ops = {
3580Sstevel@tonic-gate DEVO_REV, /* devo_rev, */
3590Sstevel@tonic-gate 0, /* refcnt */
3600Sstevel@tonic-gate ddi_no_info, /* info */
3610Sstevel@tonic-gate nulldev, /* identify */
3620Sstevel@tonic-gate nulldev, /* probe */
3630Sstevel@tonic-gate sbus_attach, /* attach */
3640Sstevel@tonic-gate sbus_detach, /* detach */
3650Sstevel@tonic-gate nodev, /* reset */
3660Sstevel@tonic-gate &sbus_cb_ops, /* driver operations */
3670Sstevel@tonic-gate &sbus_bus_ops, /* bus operations */
368*7656SSherry.Moore@Sun.COM nulldev, /* power */
369*7656SSherry.Moore@Sun.COM ddi_quiesce_not_supported, /* devo_quiesce */
3700Sstevel@tonic-gate };
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate /* global data */
3730Sstevel@tonic-gate void *sbusp; /* sbus soft state hook */
3740Sstevel@tonic-gate void *sbus_cprp; /* subs suspend/resume soft state hook */
3750Sstevel@tonic-gate static kstat_t *sbus_picN_ksp[SBUS_NUM_PICS]; /* performance picN kstats */
3760Sstevel@tonic-gate static int sbus_attachcnt = 0; /* number of instances attached */
3770Sstevel@tonic-gate static kmutex_t sbus_attachcnt_mutex; /* sbus_attachcnt lock - attach/detach */
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate #include <sys/modctl.h>
3800Sstevel@tonic-gate extern struct mod_ops mod_driverops;
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate static struct modldrv modldrv = {
3830Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */
3847240Srh87107 "SBus (sysio) nexus driver", /* Name of module. */
3850Sstevel@tonic-gate &sbus_ops, /* driver ops */
3860Sstevel@tonic-gate };
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate static struct modlinkage modlinkage = {
3890Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL
3900Sstevel@tonic-gate };
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate /*
3930Sstevel@tonic-gate * These are the module initialization routines.
3940Sstevel@tonic-gate */
3950Sstevel@tonic-gate int
_init(void)3960Sstevel@tonic-gate _init(void)
3970Sstevel@tonic-gate {
3980Sstevel@tonic-gate int error;
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbusp,
4010Sstevel@tonic-gate sizeof (struct sbus_soft_state), 1)) != 0)
4020Sstevel@tonic-gate return (error);
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate /*
4050Sstevel@tonic-gate * Initialize cpr soft state structure
4060Sstevel@tonic-gate */
4070Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbus_cprp,
4080Sstevel@tonic-gate sizeof (uint64_t) * MAX_INO_TABLE_SIZE, 0)) != 0)
4090Sstevel@tonic-gate return (error);
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate /* Initialize global mutex */
4120Sstevel@tonic-gate mutex_init(&sbus_attachcnt_mutex, NULL, MUTEX_DRIVER, NULL);
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate return (mod_install(&modlinkage));
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate int
_fini(void)4180Sstevel@tonic-gate _fini(void)
4190Sstevel@tonic-gate {
4200Sstevel@tonic-gate int error;
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0)
4230Sstevel@tonic-gate return (error);
4240Sstevel@tonic-gate
4250Sstevel@tonic-gate mutex_destroy(&sbus_attachcnt_mutex);
4260Sstevel@tonic-gate ddi_soft_state_fini(&sbusp);
4270Sstevel@tonic-gate ddi_soft_state_fini(&sbus_cprp);
4280Sstevel@tonic-gate return (0);
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate int
_info(struct modinfo * modinfop)4320Sstevel@tonic-gate _info(struct modinfo *modinfop)
4330Sstevel@tonic-gate {
4340Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
4350Sstevel@tonic-gate }
4360Sstevel@tonic-gate
4370Sstevel@tonic-gate /*ARGSUSED*/
4380Sstevel@tonic-gate static int
sbus_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)4390Sstevel@tonic-gate sbus_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
4400Sstevel@tonic-gate {
4410Sstevel@tonic-gate struct sbus_soft_state *softsp;
4420Sstevel@tonic-gate int instance, error;
4430Sstevel@tonic-gate uint64_t *cpr_softsp;
4440Sstevel@tonic-gate ddi_device_acc_attr_t attr;
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate
4470Sstevel@tonic-gate #ifdef DEBUG
4480Sstevel@tonic-gate debug_info = 1;
4490Sstevel@tonic-gate debug_print_level = 0;
4500Sstevel@tonic-gate #endif
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate instance = ddi_get_instance(devi);
4530Sstevel@tonic-gate
4540Sstevel@tonic-gate switch (cmd) {
4550Sstevel@tonic-gate case DDI_ATTACH:
4560Sstevel@tonic-gate break;
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate case DDI_RESUME:
4590Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance);
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate if ((error = iommu_resume_init(softsp)) != DDI_SUCCESS)
4620Sstevel@tonic-gate return (error);
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate if ((error = sbus_resume_init(softsp, 1)) != DDI_SUCCESS)
4650Sstevel@tonic-gate return (error);
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate if ((error = stream_buf_resume_init(softsp)) != DDI_SUCCESS)
4680Sstevel@tonic-gate return (error);
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate /*
4710Sstevel@tonic-gate * Restore Interrupt Mapping registers
4720Sstevel@tonic-gate */
4730Sstevel@tonic-gate cpr_softsp = ddi_get_soft_state(sbus_cprp, instance);
4740Sstevel@tonic-gate
4750Sstevel@tonic-gate if (cpr_softsp != NULL) {
4760Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(cpr_softsp,
4770Sstevel@tonic-gate softsp->intr_mapping_reg, 0);
4780Sstevel@tonic-gate ddi_soft_state_free(sbus_cprp, instance);
4790Sstevel@tonic-gate }
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate return (DDI_SUCCESS);
4820Sstevel@tonic-gate
4830Sstevel@tonic-gate default:
4840Sstevel@tonic-gate return (DDI_FAILURE);
4850Sstevel@tonic-gate }
4860Sstevel@tonic-gate
4870Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbusp, instance) != DDI_SUCCESS)
4880Sstevel@tonic-gate return (DDI_FAILURE);
4890Sstevel@tonic-gate
4900Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance);
4910Sstevel@tonic-gate
4920Sstevel@tonic-gate /* Set the dip in the soft state */
4930Sstevel@tonic-gate softsp->dip = devi;
4940Sstevel@tonic-gate
4950Sstevel@tonic-gate if ((softsp->upa_id = (int)ddi_getprop(DDI_DEV_T_ANY, softsp->dip,
4960Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1)) == -1) {
4970Sstevel@tonic-gate cmn_err(CE_WARN, "Unable to retrieve sbus upa-portid"
4980Sstevel@tonic-gate "property.");
4990Sstevel@tonic-gate error = DDI_FAILURE;
5000Sstevel@tonic-gate goto bad;
5010Sstevel@tonic-gate }
5020Sstevel@tonic-gate
5030Sstevel@tonic-gate /*
5040Sstevel@tonic-gate * The firmware maps in all 3 pages of the sysio chips device
5050Sstevel@tonic-gate * device registers and exports the mapping in the int-sized
5060Sstevel@tonic-gate * property "address". Read in this address and pass it to
5070Sstevel@tonic-gate * the subsidiary *_init functions, so we don't create extra
5080Sstevel@tonic-gate * mappings to the same physical pages and we don't have to
5090Sstevel@tonic-gate * retrieve the more than once.
5100Sstevel@tonic-gate */
5110Sstevel@tonic-gate /*
5120Sstevel@tonic-gate * Implement new policy to start ignoring the "address" property
5130Sstevel@tonic-gate * due to new requirements from DR. The problem is that the contents
5140Sstevel@tonic-gate * of the "address" property contain vm mappings from OBP which needs
5150Sstevel@tonic-gate * to be recaptured into kernel vm. Instead of relying on a blanket
5160Sstevel@tonic-gate * recapture during boot time, we map psycho registers each time during
5170Sstevel@tonic-gate * attach and unmap the during detach. In some future point of time
5180Sstevel@tonic-gate * OBP will drop creating "address" property but this driver will
5190Sstevel@tonic-gate * will already not rely on this property any more.
5200Sstevel@tonic-gate */
5210Sstevel@tonic-gate
5220Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
5230Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
5240Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
5250Sstevel@tonic-gate if (ddi_regs_map_setup(softsp->dip, 0, &softsp->address, 0, 0,
526*7656SSherry.Moore@Sun.COM &attr, &softsp->ac) != DDI_SUCCESS) {
5270Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unable to map reg set 0\n",
528*7656SSherry.Moore@Sun.COM ddi_get_name(softsp->dip),
529*7656SSherry.Moore@Sun.COM ddi_get_instance(softsp->dip));
5300Sstevel@tonic-gate return (0);
5310Sstevel@tonic-gate }
5320Sstevel@tonic-gate if (softsp->address == (caddr_t)-1) {
5330Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus%d: No sysio <address> property\n",
5340Sstevel@tonic-gate ddi_get_instance(softsp->dip));
5350Sstevel@tonic-gate return (DDI_FAILURE);
5360Sstevel@tonic-gate }
5370Sstevel@tonic-gate
5381035Smike_s DPRINTF(SBUS_ATTACH_DEBUG, ("sbus: devi=0x%p, softsp=0x%p\n",
5397240Srh87107 (void *)devi, (void *)softsp));
5400Sstevel@tonic-gate
5410Sstevel@tonic-gate #ifdef notdef
5420Sstevel@tonic-gate /*
5430Sstevel@tonic-gate * This bit of code, plus the firmware, will tell us if
5440Sstevel@tonic-gate * the #size-cells infrastructure code works, to some degree.
5450Sstevel@tonic-gate * You should be able to use the firmware to determine if
5460Sstevel@tonic-gate * the address returned by ddi_map_regs maps the correct phys. pages.
5470Sstevel@tonic-gate */
5480Sstevel@tonic-gate
5490Sstevel@tonic-gate {
5500Sstevel@tonic-gate caddr_t addr;
5510Sstevel@tonic-gate int rv;
5520Sstevel@tonic-gate
5530Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: address property = 0x%x\n", address);
5540Sstevel@tonic-gate
5550Sstevel@tonic-gate if ((rv = ddi_map_regs(softsp->dip, 0, &addr,
5560Sstevel@tonic-gate (off_t)0, (off_t)0)) != DDI_SUCCESS) {
5570Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: ddi_map_regs failed: %d\n",
5580Sstevel@tonic-gate rv);
5590Sstevel@tonic-gate } else {
5600Sstevel@tonic-gate cmn_err(CE_CONT, "?sbus: ddi_map_regs returned "
5610Sstevel@tonic-gate " virtual address 0x%x\n", addr);
5620Sstevel@tonic-gate }
5630Sstevel@tonic-gate }
5640Sstevel@tonic-gate #endif /* notdef */
5650Sstevel@tonic-gate
5660Sstevel@tonic-gate if ((error = iommu_init(softsp, softsp->address)) != DDI_SUCCESS)
5670Sstevel@tonic-gate goto bad;
5680Sstevel@tonic-gate
5690Sstevel@tonic-gate if ((error = sbus_init(softsp, softsp->address)) != DDI_SUCCESS)
5700Sstevel@tonic-gate goto bad;
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate if ((error = sysio_err_init(softsp, softsp->address)) != DDI_SUCCESS)
5730Sstevel@tonic-gate goto bad;
5740Sstevel@tonic-gate
5750Sstevel@tonic-gate if ((error = stream_buf_init(softsp, softsp->address)) != DDI_SUCCESS)
5760Sstevel@tonic-gate goto bad;
5770Sstevel@tonic-gate
5780Sstevel@tonic-gate /* Init the pokefault mutex for sbus devices */
5790Sstevel@tonic-gate mutex_init(&softsp->pokefault_mutex, NULL, MUTEX_SPIN,
5800Sstevel@tonic-gate (void *)ipltospl(SBUS_ERR_PIL - 1));
5810Sstevel@tonic-gate
5820Sstevel@tonic-gate sbus_add_kstats(softsp);
5830Sstevel@tonic-gate
5840Sstevel@tonic-gate bus_func_register(BF_TYPE_RESINTR, sbus_intr_reset, devi);
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate intr_dist_add(sbus_intrdist, devi);
5870Sstevel@tonic-gate
5880Sstevel@tonic-gate ddi_report_dev(devi);
5890Sstevel@tonic-gate
5900Sstevel@tonic-gate return (DDI_SUCCESS);
5910Sstevel@tonic-gate
5920Sstevel@tonic-gate bad:
5930Sstevel@tonic-gate ddi_soft_state_free(sbusp, instance);
5940Sstevel@tonic-gate return (error);
5950Sstevel@tonic-gate }
5960Sstevel@tonic-gate
5970Sstevel@tonic-gate /* ARGSUSED */
5980Sstevel@tonic-gate static int
sbus_detach(dev_info_t * devi,ddi_detach_cmd_t cmd)5990Sstevel@tonic-gate sbus_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
6000Sstevel@tonic-gate {
6010Sstevel@tonic-gate int instance;
6020Sstevel@tonic-gate struct sbus_soft_state *softsp;
6030Sstevel@tonic-gate uint64_t *cpr_softsp;
6040Sstevel@tonic-gate
6050Sstevel@tonic-gate switch (cmd) {
6060Sstevel@tonic-gate case DDI_SUSPEND:
6070Sstevel@tonic-gate /*
6080Sstevel@tonic-gate * Allocate the cpr soft data structure to save the current
6090Sstevel@tonic-gate * state of the interrupt mapping registers.
6100Sstevel@tonic-gate * This structure will be deallocated after the system
6110Sstevel@tonic-gate * is resumed.
6120Sstevel@tonic-gate */
6130Sstevel@tonic-gate instance = ddi_get_instance(devi);
6140Sstevel@tonic-gate
6150Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbus_cprp, instance)
616*7656SSherry.Moore@Sun.COM != DDI_SUCCESS)
6170Sstevel@tonic-gate return (DDI_FAILURE);
6180Sstevel@tonic-gate
6190Sstevel@tonic-gate cpr_softsp = ddi_get_soft_state(sbus_cprp, instance);
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance);
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(cpr_softsp,
6240Sstevel@tonic-gate softsp->intr_mapping_reg, 1);
6250Sstevel@tonic-gate return (DDI_SUCCESS);
6260Sstevel@tonic-gate
6270Sstevel@tonic-gate case DDI_DETACH:
6280Sstevel@tonic-gate return (sbus_do_detach(devi));
6290Sstevel@tonic-gate default:
6300Sstevel@tonic-gate return (DDI_FAILURE);
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate }
6330Sstevel@tonic-gate
6340Sstevel@tonic-gate static int
sbus_do_detach(dev_info_t * devi)6350Sstevel@tonic-gate sbus_do_detach(dev_info_t *devi)
6360Sstevel@tonic-gate {
6370Sstevel@tonic-gate int instance, pic;
6380Sstevel@tonic-gate struct sbus_soft_state *softsp;
6390Sstevel@tonic-gate
6400Sstevel@tonic-gate instance = ddi_get_instance(devi);
6410Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, instance);
6420Sstevel@tonic-gate ASSERT(softsp != NULL);
6430Sstevel@tonic-gate
6440Sstevel@tonic-gate bus_func_unregister(BF_TYPE_RESINTR, sbus_intr_reset, devi);
6450Sstevel@tonic-gate
6460Sstevel@tonic-gate intr_dist_rem(sbus_intrdist, devi);
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate /* disable the streamming cache */
6490Sstevel@tonic-gate if (stream_buf_uninit(softsp) == DDI_FAILURE) {
6500Sstevel@tonic-gate goto err;
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate /* remove the interrupt handlers from the system */
6540Sstevel@tonic-gate if (sysio_err_uninit(softsp) == DDI_FAILURE) {
6550Sstevel@tonic-gate goto err;
6560Sstevel@tonic-gate }
6570Sstevel@tonic-gate
6580Sstevel@tonic-gate /* disable the IOMMU */
6590Sstevel@tonic-gate if (iommu_uninit(softsp)) {
6600Sstevel@tonic-gate goto err;
6610Sstevel@tonic-gate }
6620Sstevel@tonic-gate
6630Sstevel@tonic-gate /* unmap register space if we have a handle */
6640Sstevel@tonic-gate if (softsp->ac) {
6650Sstevel@tonic-gate ddi_regs_map_free(&softsp->ac);
6660Sstevel@tonic-gate softsp->address = NULL;
6670Sstevel@tonic-gate }
6680Sstevel@tonic-gate
6690Sstevel@tonic-gate /*
6700Sstevel@tonic-gate * remove counter kstats for this device
6710Sstevel@tonic-gate */
6720Sstevel@tonic-gate if (softsp->sbus_counters_ksp != (kstat_t *)NULL)
6730Sstevel@tonic-gate kstat_delete(softsp->sbus_counters_ksp);
6740Sstevel@tonic-gate
6750Sstevel@tonic-gate /*
6760Sstevel@tonic-gate * if we are the last instance to detach we need to
6770Sstevel@tonic-gate * remove the picN kstats. We use sbus_attachcnt as a
6780Sstevel@tonic-gate * count of how many instances are still attached. This
6790Sstevel@tonic-gate * is protected by a mutex.
6800Sstevel@tonic-gate */
6810Sstevel@tonic-gate mutex_enter(&sbus_attachcnt_mutex);
6820Sstevel@tonic-gate sbus_attachcnt --;
6830Sstevel@tonic-gate if (sbus_attachcnt == 0) {
6840Sstevel@tonic-gate for (pic = 0; pic < SBUS_NUM_PICS; pic++) {
6850Sstevel@tonic-gate if (sbus_picN_ksp[pic] != (kstat_t *)NULL) {
6860Sstevel@tonic-gate kstat_delete(sbus_picN_ksp[pic]);
6870Sstevel@tonic-gate sbus_picN_ksp[pic] = NULL;
6880Sstevel@tonic-gate }
6890Sstevel@tonic-gate }
6900Sstevel@tonic-gate }
6910Sstevel@tonic-gate mutex_exit(&sbus_attachcnt_mutex);
6920Sstevel@tonic-gate
6930Sstevel@tonic-gate #ifdef _STARFIRE
6940Sstevel@tonic-gate /* free starfire specific soft intr mapping structure */
6950Sstevel@tonic-gate pc_ittrans_uninit(softsp->ittrans_cookie);
6960Sstevel@tonic-gate #endif /* _STARFIRE */
6970Sstevel@tonic-gate
6980Sstevel@tonic-gate /* free the soft state structure */
6990Sstevel@tonic-gate ddi_soft_state_free(sbusp, instance);
7000Sstevel@tonic-gate
7010Sstevel@tonic-gate return (DDI_SUCCESS);
7020Sstevel@tonic-gate err:
7030Sstevel@tonic-gate return (DDI_FAILURE);
7040Sstevel@tonic-gate }
7050Sstevel@tonic-gate
7060Sstevel@tonic-gate static int
sbus_init(struct sbus_soft_state * softsp,caddr_t address)7070Sstevel@tonic-gate sbus_init(struct sbus_soft_state *softsp, caddr_t address)
7080Sstevel@tonic-gate {
7090Sstevel@tonic-gate int i;
7100Sstevel@tonic-gate extern void set_intr_mapping_reg(int, uint64_t *, int);
7110Sstevel@tonic-gate int numproxy;
7120Sstevel@tonic-gate
7130Sstevel@tonic-gate /*
7140Sstevel@tonic-gate * Simply add each registers offset to the base address
7150Sstevel@tonic-gate * to calculate the already mapped virtual address of
7160Sstevel@tonic-gate * the device register...
7170Sstevel@tonic-gate *
7180Sstevel@tonic-gate * define a macro for the pointer arithmetic; all registers
7190Sstevel@tonic-gate * are 64 bits wide and are defined as uint64_t's.
7200Sstevel@tonic-gate */
7210Sstevel@tonic-gate
7220Sstevel@tonic-gate #define REG_ADDR(b, o) (uint64_t *)((caddr_t)(b) + (o))
7230Sstevel@tonic-gate
7240Sstevel@tonic-gate softsp->sysio_ctrl_reg = REG_ADDR(address, OFF_SYSIO_CTRL_REG);
7250Sstevel@tonic-gate softsp->sbus_ctrl_reg = REG_ADDR(address, OFF_SBUS_CTRL_REG);
7260Sstevel@tonic-gate softsp->sbus_slot_config_reg = REG_ADDR(address, OFF_SBUS_SLOT_CONFIG);
7270Sstevel@tonic-gate softsp->intr_mapping_reg = REG_ADDR(address, OFF_INTR_MAPPING_REG);
7280Sstevel@tonic-gate softsp->clr_intr_reg = REG_ADDR(address, OFF_CLR_INTR_REG);
7290Sstevel@tonic-gate softsp->intr_retry_reg = REG_ADDR(address, OFF_INTR_RETRY_REG);
7300Sstevel@tonic-gate softsp->sbus_intr_state = REG_ADDR(address, OFF_SBUS_INTR_STATE_REG);
7310Sstevel@tonic-gate softsp->sbus_pcr = REG_ADDR(address, OFF_SBUS_PCR);
7320Sstevel@tonic-gate softsp->sbus_pic = REG_ADDR(address, OFF_SBUS_PIC);
7330Sstevel@tonic-gate
7340Sstevel@tonic-gate #undef REG_ADDR
7350Sstevel@tonic-gate
7361035Smike_s DPRINTF(SBUS_REGISTERS_DEBUG, ("SYSIO Control reg: 0x%p\n"
7377240Srh87107 "SBUS Control reg: 0x%p", (void *)softsp->sysio_ctrl_reg,
7387240Srh87107 (void *)softsp->sbus_ctrl_reg));
7390Sstevel@tonic-gate
7400Sstevel@tonic-gate #ifdef _STARFIRE
7410Sstevel@tonic-gate /* Setup interrupt target translation for starfire */
7420Sstevel@tonic-gate pc_ittrans_init(softsp->upa_id, &softsp->ittrans_cookie);
7430Sstevel@tonic-gate #endif /* _STARFIRE */
7440Sstevel@tonic-gate
7450Sstevel@tonic-gate softsp->intr_mapping_ign =
7460Sstevel@tonic-gate UPAID_TO_IGN(softsp->upa_id) << IMR_IGN_SHIFT;
7470Sstevel@tonic-gate
7480Sstevel@tonic-gate /* Diag reg 2 is the next 64 bit word after diag reg 1 */
7490Sstevel@tonic-gate softsp->obio_intr_state = softsp->sbus_intr_state + 1;
7500Sstevel@tonic-gate
7510Sstevel@tonic-gate (void) sbus_resume_init(softsp, 0);
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate /*
7540Sstevel@tonic-gate * Set the initial burstsizes for each slot to all 1's. This will
7550Sstevel@tonic-gate * get changed at initchild time.
7560Sstevel@tonic-gate */
7570Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++)
7580Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] = 0xffffffffu;
7590Sstevel@tonic-gate
7600Sstevel@tonic-gate /*
7610Sstevel@tonic-gate * Since SYSIO is used as an interrupt mastering device for slave
7620Sstevel@tonic-gate * only UPA devices, we call a dedicated kernel function to register
7630Sstevel@tonic-gate * The address of the interrupt mapping register for the slave device.
7640Sstevel@tonic-gate *
7650Sstevel@tonic-gate * If RISC/sysio is wired to support 2 upa slave interrupt
7660Sstevel@tonic-gate * devices then register 2nd mapping register with system.
7670Sstevel@tonic-gate * The slave/proxy portid algorithm (decribed in Fusion Desktop Spec)
7680Sstevel@tonic-gate * allows for upto 3 slaves per proxy but Psycho/SYSIO only support 2.
7690Sstevel@tonic-gate *
7700Sstevel@tonic-gate * #upa-interrupt-proxies property defines how many UPA interrupt
7710Sstevel@tonic-gate * slaves a bridge is wired to support. Older systems that lack
7720Sstevel@tonic-gate * this property will default to 1.
7730Sstevel@tonic-gate */
7740Sstevel@tonic-gate numproxy = ddi_prop_get_int(DDI_DEV_T_ANY, softsp->dip,
7750Sstevel@tonic-gate DDI_PROP_DONTPASS, "#upa-interrupt-proxies", 1);
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate if (numproxy > 0)
7780Sstevel@tonic-gate set_intr_mapping_reg(softsp->upa_id,
7790Sstevel@tonic-gate (uint64_t *)(softsp->intr_mapping_reg +
7800Sstevel@tonic-gate FFB_MAPPING_REG), 1);
7810Sstevel@tonic-gate
7820Sstevel@tonic-gate if (numproxy > 1)
7830Sstevel@tonic-gate set_intr_mapping_reg(softsp->upa_id,
7840Sstevel@tonic-gate (uint64_t *)(softsp->intr_mapping_reg +
7850Sstevel@tonic-gate EXP_MAPPING_REG), 2);
7860Sstevel@tonic-gate
7870Sstevel@tonic-gate /* support for a 3 interrupt proxy would go here */
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate /* Turn on spurious interrupt counter if we're not a DEBUG kernel. */
7900Sstevel@tonic-gate #ifndef DEBUG
7910Sstevel@tonic-gate intr_cntr_on = 1;
7920Sstevel@tonic-gate #else
7930Sstevel@tonic-gate intr_cntr_on = 0;
7940Sstevel@tonic-gate #endif
7950Sstevel@tonic-gate
7960Sstevel@tonic-gate
7970Sstevel@tonic-gate return (DDI_SUCCESS);
7980Sstevel@tonic-gate }
7990Sstevel@tonic-gate
8000Sstevel@tonic-gate /*
8010Sstevel@tonic-gate * This procedure is part of sbus initialization. It is called by
8020Sstevel@tonic-gate * sbus_init() and is invoked when the system is being resumed.
8030Sstevel@tonic-gate */
8040Sstevel@tonic-gate static int
sbus_resume_init(struct sbus_soft_state * softsp,int resume)8050Sstevel@tonic-gate sbus_resume_init(struct sbus_soft_state *softsp, int resume)
8060Sstevel@tonic-gate {
8070Sstevel@tonic-gate int i;
8080Sstevel@tonic-gate uint_t sbus_burst_sizes;
8090Sstevel@tonic-gate
8100Sstevel@tonic-gate /*
8110Sstevel@tonic-gate * This shouldn't be needed when we have a real OBP PROM.
8120Sstevel@tonic-gate * (RAZ) Get rid of this later!!!
8130Sstevel@tonic-gate */
8140Sstevel@tonic-gate
8150Sstevel@tonic-gate #ifdef _STARFIRE
8160Sstevel@tonic-gate /*
8170Sstevel@tonic-gate * For Starfire, we need to program a
8180Sstevel@tonic-gate * constant odd value.
8190Sstevel@tonic-gate * Zero out the MID field before ORing
8200Sstevel@tonic-gate * We leave the LSB of the MID field intact since
8210Sstevel@tonic-gate * we cannot have a zero(even) MID value
8220Sstevel@tonic-gate */
8230Sstevel@tonic-gate uint64_t tmpconst = 0x1DULL;
8240Sstevel@tonic-gate *softsp->sysio_ctrl_reg &= 0xFF0FFFFFFFFFFFFFULL;
8250Sstevel@tonic-gate *softsp->sysio_ctrl_reg |= tmpconst << 51;
8260Sstevel@tonic-gate
8270Sstevel@tonic-gate /*
8280Sstevel@tonic-gate * Program in the interrupt group number
8290Sstevel@tonic-gate * Here we have to convert the starfire
8300Sstevel@tonic-gate * 7 bit upaid into a 5bit value.
8310Sstevel@tonic-gate */
8320Sstevel@tonic-gate *softsp->sysio_ctrl_reg |=
833*7656SSherry.Moore@Sun.COM (uint64_t)STARFIRE_UPAID2HWIGN(softsp->upa_id)
834*7656SSherry.Moore@Sun.COM << SYSIO_IGN;
8350Sstevel@tonic-gate #else
8360Sstevel@tonic-gate /* for the rest of sun4u's */
8370Sstevel@tonic-gate *softsp->sysio_ctrl_reg |=
838*7656SSherry.Moore@Sun.COM (uint64_t)softsp->upa_id << 51;
8390Sstevel@tonic-gate
8400Sstevel@tonic-gate /* Program in the interrupt group number */
8410Sstevel@tonic-gate *softsp->sysio_ctrl_reg |=
842*7656SSherry.Moore@Sun.COM (uint64_t)softsp->upa_id << SYSIO_IGN;
8430Sstevel@tonic-gate #endif /* _STARFIRE */
8440Sstevel@tonic-gate
8450Sstevel@tonic-gate /*
8460Sstevel@tonic-gate * Set appropriate fields of sbus control register.
8470Sstevel@tonic-gate * Set DVMA arbitration enable for all devices.
8480Sstevel@tonic-gate */
8490Sstevel@tonic-gate *softsp->sbus_ctrl_reg |= SBUS_ARBIT_ALL;
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate /* Calculate our burstsizes now so we don't have to do it later */
8520Sstevel@tonic-gate sbus_burst_sizes = (SYSIO64_BURST_RANGE << SYSIO64_BURST_SHIFT)
853*7656SSherry.Moore@Sun.COM | SYSIO_BURST_RANGE;
8540Sstevel@tonic-gate
8550Sstevel@tonic-gate sbus_burst_sizes = ddi_getprop(DDI_DEV_T_ANY, softsp->dip,
856*7656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS, "up-burst-sizes", sbus_burst_sizes);
8570Sstevel@tonic-gate
8580Sstevel@tonic-gate softsp->sbus_burst_sizes = sbus_burst_sizes & SYSIO_BURST_MASK;
8590Sstevel@tonic-gate softsp->sbus64_burst_sizes = sbus_burst_sizes & SYSIO64_BURST_MASK;
8600Sstevel@tonic-gate
8610Sstevel@tonic-gate if (!resume) {
8620Sstevel@tonic-gate /* Set burstsizes to smallest value */
8630Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) {
8640Sstevel@tonic-gate volatile uint64_t *config;
8650Sstevel@tonic-gate uint64_t tmpreg;
8660Sstevel@tonic-gate
8670Sstevel@tonic-gate config = softsp->sbus_slot_config_reg + i;
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate /* Write out the burst size */
8700Sstevel@tonic-gate tmpreg = (uint64_t)0;
8710Sstevel@tonic-gate *config = tmpreg;
8720Sstevel@tonic-gate
8730Sstevel@tonic-gate /* Flush any write buffers */
8740Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
8750Sstevel@tonic-gate
8760Sstevel@tonic-gate DPRINTF(SBUS_REGISTERS_DEBUG, ("Sbus slot 0x%x slot "
8771035Smike_s "configuration reg: 0x%p", (i > 3) ? i + 9 : i,
8787240Srh87107 (void *)config));
8790Sstevel@tonic-gate }
8800Sstevel@tonic-gate } else {
8810Sstevel@tonic-gate /* Program the slot configuration registers */
8820Sstevel@tonic-gate for (i = 0; i < MAX_SBUS_SLOTS; i++) {
8830Sstevel@tonic-gate volatile uint64_t *config;
8840Sstevel@tonic-gate #ifndef lint
8850Sstevel@tonic-gate uint64_t tmpreg;
8860Sstevel@tonic-gate #endif /* !lint */
8870Sstevel@tonic-gate uint_t slave_burstsizes;
8880Sstevel@tonic-gate
8890Sstevel@tonic-gate slave_burstsizes = 0;
8900Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[i] != 0xffffffffu) {
8910Sstevel@tonic-gate config = softsp->sbus_slot_config_reg + i;
8920Sstevel@tonic-gate
8930Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[i] &
8940Sstevel@tonic-gate SYSIO64_BURST_MASK) {
8950Sstevel@tonic-gate /* get the 64 bit burstsizes */
8960Sstevel@tonic-gate slave_burstsizes =
8970Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] >>
8980Sstevel@tonic-gate SYSIO64_BURST_SHIFT;
8990Sstevel@tonic-gate
9000Sstevel@tonic-gate /* Turn on 64 bit PIO's on the sbus */
9010Sstevel@tonic-gate *config |= SBUS_ETM;
9020Sstevel@tonic-gate } else {
9030Sstevel@tonic-gate slave_burstsizes =
9040Sstevel@tonic-gate softsp->sbus_slave_burstsizes[i] &
9050Sstevel@tonic-gate SYSIO_BURST_MASK;
9060Sstevel@tonic-gate }
9070Sstevel@tonic-gate
9080Sstevel@tonic-gate /* Get burstsizes into sysio register format */
9090Sstevel@tonic-gate slave_burstsizes >>= SYSIO_SLAVEBURST_REGSHIFT;
9100Sstevel@tonic-gate
9110Sstevel@tonic-gate /* Program the burstsizes */
9120Sstevel@tonic-gate *config |= (uint64_t)slave_burstsizes;
9130Sstevel@tonic-gate
9140Sstevel@tonic-gate /* Flush any write buffers */
9150Sstevel@tonic-gate #ifndef lint
9160Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
9170Sstevel@tonic-gate #endif /* !lint */
9180Sstevel@tonic-gate }
9190Sstevel@tonic-gate }
9200Sstevel@tonic-gate }
9210Sstevel@tonic-gate
9220Sstevel@tonic-gate return (DDI_SUCCESS);
9230Sstevel@tonic-gate }
9240Sstevel@tonic-gate
9250Sstevel@tonic-gate #define get_prop(di, pname, flag, pval, plen) \
9260Sstevel@tonic-gate (ddi_prop_op(DDI_DEV_T_NONE, di, PROP_LEN_AND_VAL_ALLOC, \
9270Sstevel@tonic-gate flag | DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, \
9280Sstevel@tonic-gate pname, (caddr_t)pval, plen))
9290Sstevel@tonic-gate
9300Sstevel@tonic-gate struct prop_ispec {
9310Sstevel@tonic-gate uint_t pri, vec;
9320Sstevel@tonic-gate };
9330Sstevel@tonic-gate
9340Sstevel@tonic-gate /*
9350Sstevel@tonic-gate * Create a sysio_parent_private_data structure from the ddi properties of
9360Sstevel@tonic-gate * the dev_info node.
9370Sstevel@tonic-gate *
9380Sstevel@tonic-gate * The "reg" and either an "intr" or "interrupts" properties are required
9390Sstevel@tonic-gate * if the driver wishes to create mappings or field interrupts on behalf
9400Sstevel@tonic-gate * of the device.
9410Sstevel@tonic-gate *
9420Sstevel@tonic-gate * The "reg" property is assumed to be a list of at least one triple
9430Sstevel@tonic-gate *
9440Sstevel@tonic-gate * <bustype, address, size>*1
9450Sstevel@tonic-gate *
9460Sstevel@tonic-gate * On pre-fusion machines, the "intr" property was the IPL for the system.
9470Sstevel@tonic-gate * Most new sbus devices post an "interrupts" property that corresponds to
9480Sstevel@tonic-gate * a particular bus level. All devices on fusion using an "intr" property
9490Sstevel@tonic-gate * will have it's contents translated into a bus level. Hence, "intr" and
9500Sstevel@tonic-gate * "interrupts on the fusion platform can be treated the same.
9510Sstevel@tonic-gate *
9520Sstevel@tonic-gate * The "interrupts" property is assumed to be a list of at least one
9530Sstevel@tonic-gate * n-tuples that describes the interrupt capabilities of the bus the device
9540Sstevel@tonic-gate * is connected to. For SBus, this looks like
9550Sstevel@tonic-gate *
9560Sstevel@tonic-gate * <SBus-level>*1
9570Sstevel@tonic-gate *
9580Sstevel@tonic-gate * (This property obsoletes the 'intr' property).
9590Sstevel@tonic-gate *
9600Sstevel@tonic-gate * The OBP_RANGES property is optional.
9610Sstevel@tonic-gate */
9620Sstevel@tonic-gate static void
make_sbus_ppd(dev_info_t * child)9630Sstevel@tonic-gate make_sbus_ppd(dev_info_t *child)
9640Sstevel@tonic-gate {
9650Sstevel@tonic-gate struct sysio_parent_private_data *pdptr;
9660Sstevel@tonic-gate int n;
9670Sstevel@tonic-gate int *reg_prop, *rgstr_prop, *rng_prop;
9680Sstevel@tonic-gate int reg_len, rgstr_len, rng_len;
9690Sstevel@tonic-gate
9700Sstevel@tonic-gate /*
9710Sstevel@tonic-gate * Make the function idempotent, because name_child could
9720Sstevel@tonic-gate * be called multiple times on a node.
9730Sstevel@tonic-gate */
9740Sstevel@tonic-gate if (ddi_get_parent_data(child) != NULL)
9750Sstevel@tonic-gate return;
9760Sstevel@tonic-gate
9770Sstevel@tonic-gate pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP);
9780Sstevel@tonic-gate ddi_set_parent_data(child, pdptr);
9790Sstevel@tonic-gate
9800Sstevel@tonic-gate /*
9810Sstevel@tonic-gate * Handle the 'reg'/'registers' properties.
9820Sstevel@tonic-gate * "registers" overrides "reg", but requires that "reg" be exported,
9830Sstevel@tonic-gate * so we can handle wildcard specifiers. "registers" implies an
9840Sstevel@tonic-gate * sbus style device. "registers" implies that we insert the
9850Sstevel@tonic-gate * correct value in the regspec_bustype field of each spec for a real
9860Sstevel@tonic-gate * (non-pseudo) device node. "registers" is a s/w only property, so
9870Sstevel@tonic-gate * we inhibit the prom search for this property.
9880Sstevel@tonic-gate */
9890Sstevel@tonic-gate if (get_prop(child, OBP_REG, 0, ®_prop, ®_len) != DDI_SUCCESS)
9900Sstevel@tonic-gate reg_len = 0;
9910Sstevel@tonic-gate
9920Sstevel@tonic-gate /*
9930Sstevel@tonic-gate * Save the underlying slot number and slot offset.
9940Sstevel@tonic-gate * Among other things, we use these to name the child node.
9950Sstevel@tonic-gate */
9960Sstevel@tonic-gate pdptr->slot = (uint_t)-1;
9970Sstevel@tonic-gate if (reg_len != 0) {
9980Sstevel@tonic-gate pdptr->slot = ((struct regspec *)reg_prop)->regspec_bustype;
9990Sstevel@tonic-gate pdptr->offset = ((struct regspec *)reg_prop)->regspec_addr;
10000Sstevel@tonic-gate }
10010Sstevel@tonic-gate
10020Sstevel@tonic-gate rgstr_len = 0;
10030Sstevel@tonic-gate (void) get_prop(child, "registers", DDI_PROP_NOTPROM,
10040Sstevel@tonic-gate &rgstr_prop, &rgstr_len);
10050Sstevel@tonic-gate
10060Sstevel@tonic-gate if (rgstr_len != 0) {
10070Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) && (reg_len != 0)) {
10080Sstevel@tonic-gate /*
10090Sstevel@tonic-gate * Convert wildcard "registers" for a real node...
10100Sstevel@tonic-gate * (Else, this is the wildcard prototype node)
10110Sstevel@tonic-gate */
10120Sstevel@tonic-gate struct regspec *rp = (struct regspec *)reg_prop;
10130Sstevel@tonic-gate uint_t slot = rp->regspec_bustype;
10140Sstevel@tonic-gate int i;
10150Sstevel@tonic-gate
10160Sstevel@tonic-gate rp = (struct regspec *)rgstr_prop;
10170Sstevel@tonic-gate n = rgstr_len / sizeof (struct regspec);
10180Sstevel@tonic-gate for (i = 0; i < n; ++i, ++rp)
10190Sstevel@tonic-gate rp->regspec_bustype = slot;
10200Sstevel@tonic-gate }
10210Sstevel@tonic-gate
10220Sstevel@tonic-gate if (reg_len != 0)
10230Sstevel@tonic-gate kmem_free(reg_prop, reg_len);
10240Sstevel@tonic-gate
10250Sstevel@tonic-gate reg_prop = rgstr_prop;
10260Sstevel@tonic-gate reg_len = rgstr_len;
10270Sstevel@tonic-gate }
10280Sstevel@tonic-gate if (reg_len != 0) {
10290Sstevel@tonic-gate pdptr->par_nreg = reg_len / (int)sizeof (struct regspec);
10300Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop;
10310Sstevel@tonic-gate }
10320Sstevel@tonic-gate
10330Sstevel@tonic-gate /*
10340Sstevel@tonic-gate * See if I have ranges.
10350Sstevel@tonic-gate */
10360Sstevel@tonic-gate if (get_prop(child, OBP_RANGES, 0, &rng_prop, &rng_len) ==
10370Sstevel@tonic-gate DDI_SUCCESS) {
10380Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec));
10390Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop;
10400Sstevel@tonic-gate }
10410Sstevel@tonic-gate }
10420Sstevel@tonic-gate
10430Sstevel@tonic-gate /*
10440Sstevel@tonic-gate * Special handling for "sbusmem" pseudo device nodes.
10450Sstevel@tonic-gate * The special handling automatically creates the "reg"
10460Sstevel@tonic-gate * property in the sbusmem nodes, based on the parent's
10470Sstevel@tonic-gate * property so that each slot will automtically have a
10480Sstevel@tonic-gate * correctly sized "reg" property, once created,
10490Sstevel@tonic-gate * sbus_initchild does the rest of the work to init
10500Sstevel@tonic-gate * the child node.
10510Sstevel@tonic-gate */
10520Sstevel@tonic-gate static int
sbusmem_initchild(dev_info_t * dip,dev_info_t * child)10530Sstevel@tonic-gate sbusmem_initchild(dev_info_t *dip, dev_info_t *child)
10540Sstevel@tonic-gate {
10550Sstevel@tonic-gate int i, n;
10560Sstevel@tonic-gate int slot, size;
10570Sstevel@tonic-gate char ident[10];
10580Sstevel@tonic-gate
10590Sstevel@tonic-gate slot = ddi_getprop(DDI_DEV_T_NONE, child,
10600Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "slot", -1);
10610Sstevel@tonic-gate if (slot == -1) {
10620Sstevel@tonic-gate DPRINTF(SBUS_SBUSMEM_DEBUG, ("can't get slot property\n"));
10630Sstevel@tonic-gate return (DDI_FAILURE);
10640Sstevel@tonic-gate }
10650Sstevel@tonic-gate
10660Sstevel@tonic-gate /*
10670Sstevel@tonic-gate * Find the parent range corresponding to this "slot",
10680Sstevel@tonic-gate * so we can set the size of the child's "reg" property.
10690Sstevel@tonic-gate */
10700Sstevel@tonic-gate for (i = 0, n = sparc_pd_getnrng(dip); i < n; i++) {
10710Sstevel@tonic-gate struct rangespec *rp = sparc_pd_getrng(dip, i);
10720Sstevel@tonic-gate
10730Sstevel@tonic-gate if (rp->rng_cbustype == (uint_t)slot) {
10740Sstevel@tonic-gate struct regspec r;
10750Sstevel@tonic-gate
10760Sstevel@tonic-gate /* create reg property */
10770Sstevel@tonic-gate
10780Sstevel@tonic-gate r.regspec_bustype = (uint_t)slot;
10790Sstevel@tonic-gate r.regspec_addr = 0;
10800Sstevel@tonic-gate r.regspec_size = rp->rng_size;
10810Sstevel@tonic-gate (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
10820Sstevel@tonic-gate child, "reg", (int *)&r,
10830Sstevel@tonic-gate sizeof (struct regspec) / sizeof (int));
10840Sstevel@tonic-gate
10850Sstevel@tonic-gate /* create size property for slot */
10860Sstevel@tonic-gate
10870Sstevel@tonic-gate size = rp->rng_size;
10880Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE,
10890Sstevel@tonic-gate child, "size", size);
10900Sstevel@tonic-gate
10910Sstevel@tonic-gate (void) sprintf(ident, "slot%x", slot);
10920Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE,
10930Sstevel@tonic-gate child, "ident", ident);
10940Sstevel@tonic-gate
10950Sstevel@tonic-gate return (DDI_SUCCESS);
10960Sstevel@tonic-gate }
10970Sstevel@tonic-gate }
10980Sstevel@tonic-gate return (DDI_FAILURE);
10990Sstevel@tonic-gate }
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate /*
11020Sstevel@tonic-gate * Nexus routine to name a child.
11030Sstevel@tonic-gate * It takes a dev_info node and a buffer, returns the name
11040Sstevel@tonic-gate * in the buffer.
11050Sstevel@tonic-gate */
11060Sstevel@tonic-gate static int
sysio_name_child(dev_info_t * child,char * name,int namelen)11070Sstevel@tonic-gate sysio_name_child(dev_info_t *child, char *name, int namelen)
11080Sstevel@tonic-gate {
11090Sstevel@tonic-gate /*
11100Sstevel@tonic-gate * Fill in parent-private data
11110Sstevel@tonic-gate */
11120Sstevel@tonic-gate make_sbus_ppd(child);
11130Sstevel@tonic-gate
11140Sstevel@tonic-gate /*
11150Sstevel@tonic-gate * Name the device node using the underlying (prom) values
11160Sstevel@tonic-gate * of the first entry in the "reg" property. For SBus devices,
11170Sstevel@tonic-gate * the textual form of the name is <name>@<slot#>,<offset>.
11180Sstevel@tonic-gate * This must match the prom's pathname or mountroot, etc, won't
11190Sstevel@tonic-gate */
11200Sstevel@tonic-gate name[0] = '\0';
11210Sstevel@tonic-gate if (sysio_pd_getslot(child) != (uint_t)-1) {
11220Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x",
11230Sstevel@tonic-gate sysio_pd_getslot(child), sysio_pd_getoffset(child));
11240Sstevel@tonic-gate }
11250Sstevel@tonic-gate return (DDI_SUCCESS);
11260Sstevel@tonic-gate }
11270Sstevel@tonic-gate
11280Sstevel@tonic-gate /*
11290Sstevel@tonic-gate * Called from the bus_ctl op of sysio sbus nexus driver
11300Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names
11310Sstevel@tonic-gate * the children of sysio sbusses based on the reg spec.
11320Sstevel@tonic-gate *
11330Sstevel@tonic-gate * Handles the following properties:
11340Sstevel@tonic-gate *
11350Sstevel@tonic-gate * Property value
11360Sstevel@tonic-gate * Name type
11370Sstevel@tonic-gate *
11380Sstevel@tonic-gate * reg register spec
11390Sstevel@tonic-gate * registers wildcard s/w sbus register spec (.conf file property)
11400Sstevel@tonic-gate * intr old-form interrupt spec
11410Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec
11420Sstevel@tonic-gate * ranges range spec
11430Sstevel@tonic-gate */
11440Sstevel@tonic-gate static int
sbus_initchild(dev_info_t * dip,dev_info_t * child)11450Sstevel@tonic-gate sbus_initchild(dev_info_t *dip, dev_info_t *child)
11460Sstevel@tonic-gate {
11470Sstevel@tonic-gate char name[MAXNAMELEN];
11480Sstevel@tonic-gate ulong_t slave_burstsizes;
11490Sstevel@tonic-gate int slot;
11500Sstevel@tonic-gate volatile uint64_t *slot_reg;
11510Sstevel@tonic-gate #ifndef lint
11520Sstevel@tonic-gate uint64_t tmp;
11530Sstevel@tonic-gate #endif /* !lint */
11540Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *)
11550Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip));
11560Sstevel@tonic-gate
11570Sstevel@tonic-gate if (strcmp(ddi_get_name(child), "sbusmem") == 0) {
11580Sstevel@tonic-gate if (sbusmem_initchild(dip, child) != DDI_SUCCESS)
11590Sstevel@tonic-gate return (DDI_FAILURE);
11600Sstevel@tonic-gate }
11610Sstevel@tonic-gate
11620Sstevel@tonic-gate /*
11630Sstevel@tonic-gate * If this is a s/w node defined with the "registers" property,
11640Sstevel@tonic-gate * this means that this is a wildcard specifier, whose properties
11650Sstevel@tonic-gate * get applied to all previously defined h/w nodes with the same
11660Sstevel@tonic-gate * name and same parent.
11670Sstevel@tonic-gate */
11680Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) {
11690Sstevel@tonic-gate int len = 0;
11700Sstevel@tonic-gate if ((ddi_getproplen(DDI_DEV_T_ANY, child, DDI_PROP_NOTPROM,
11710Sstevel@tonic-gate "registers", &len) == DDI_SUCCESS) && (len != 0)) {
11720Sstevel@tonic-gate ndi_merge_wildcard_node(child);
11730Sstevel@tonic-gate return (DDI_FAILURE);
11740Sstevel@tonic-gate }
11750Sstevel@tonic-gate }
11760Sstevel@tonic-gate
11770Sstevel@tonic-gate /* name the child */
11780Sstevel@tonic-gate (void) sysio_name_child(child, name, MAXNAMELEN);
11790Sstevel@tonic-gate ddi_set_name_addr(child, name);
11800Sstevel@tonic-gate
11810Sstevel@tonic-gate /*
11820Sstevel@tonic-gate * If a pseudo node, attempt to merge it into a hw node.
11830Sstevel@tonic-gate * If merge is successful, we uinitialize the node and
11840Sstevel@tonic-gate * return failure, to allow caller to remove the node.
11850Sstevel@tonic-gate * The merge fails, this is a real pseudo node. Allow
11860Sstevel@tonic-gate * initchild to continue.
11870Sstevel@tonic-gate */
11880Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) &&
11890Sstevel@tonic-gate (ndi_merge_node(child, sysio_name_child) == DDI_SUCCESS)) {
11900Sstevel@tonic-gate (void) sbus_uninitchild(child);
11910Sstevel@tonic-gate return (DDI_FAILURE);
11920Sstevel@tonic-gate }
11930Sstevel@tonic-gate
11940Sstevel@tonic-gate /* Figure out the child devices slot number */
11950Sstevel@tonic-gate slot = sysio_pd_getslot(child);
11960Sstevel@tonic-gate
11970Sstevel@tonic-gate /* If we don't have a reg property, bypass slot specific programming */
11980Sstevel@tonic-gate if (slot < 0 || slot >= MAX_SBUS_SLOT_ADDR) {
11990Sstevel@tonic-gate #ifdef DEBUG
12000Sstevel@tonic-gate cmn_err(CE_WARN, "?Invalid sbus slot address 0x%x for %s "
12010Sstevel@tonic-gate "device\n", slot, ddi_get_name(child));
12020Sstevel@tonic-gate #endif /* DEBUG */
12030Sstevel@tonic-gate goto done;
12040Sstevel@tonic-gate }
12050Sstevel@tonic-gate
12060Sstevel@tonic-gate /* Modify the onboard slot numbers if applicable. */
12070Sstevel@tonic-gate slot = (slot > 3) ? slot - 9 : slot;
12080Sstevel@tonic-gate
12090Sstevel@tonic-gate /* Get the slot configuration register for the child device. */
12100Sstevel@tonic-gate slot_reg = softsp->sbus_slot_config_reg + slot;
12110Sstevel@tonic-gate
12120Sstevel@tonic-gate /*
12130Sstevel@tonic-gate * Program the devices slot configuration register for the
12140Sstevel@tonic-gate * appropriate slave burstsizes.
12150Sstevel@tonic-gate * The upper 16 bits of the slave-burst-sizes are for 64 bit sbus
12160Sstevel@tonic-gate * and the lower 16 bits are the burst sizes for 32 bit sbus. If
12170Sstevel@tonic-gate * we see that a device supports both 64 bit and 32 bit slave accesses,
12180Sstevel@tonic-gate * we default to 64 bit and turn it on in the slot config reg.
12190Sstevel@tonic-gate *
12200Sstevel@tonic-gate * For older devices, make sure we check the "burst-sizes" property
12210Sstevel@tonic-gate * too.
12220Sstevel@tonic-gate */
12230Sstevel@tonic-gate if ((slave_burstsizes = (ulong_t)ddi_getprop(DDI_DEV_T_ANY, child,
12240Sstevel@tonic-gate DDI_PROP_DONTPASS, "slave-burst-sizes", 0)) != 0 ||
12250Sstevel@tonic-gate (slave_burstsizes = (ulong_t)ddi_getprop(DDI_DEV_T_ANY, child,
12260Sstevel@tonic-gate DDI_PROP_DONTPASS, "burst-sizes", 0)) != 0) {
12270Sstevel@tonic-gate uint_t burstsizes = 0;
12280Sstevel@tonic-gate
12290Sstevel@tonic-gate /*
12300Sstevel@tonic-gate * If we only have 32 bit burst sizes from a previous device,
12310Sstevel@tonic-gate * mask out any burstsizes for 64 bit mode.
12320Sstevel@tonic-gate */
12330Sstevel@tonic-gate if (((softsp->sbus_slave_burstsizes[slot] &
12340Sstevel@tonic-gate 0xffff0000u) == 0) &&
12350Sstevel@tonic-gate ((softsp->sbus_slave_burstsizes[slot] & 0xffff) != 0)) {
12360Sstevel@tonic-gate slave_burstsizes &= 0xffff;
12370Sstevel@tonic-gate }
12380Sstevel@tonic-gate
12390Sstevel@tonic-gate /*
12400Sstevel@tonic-gate * If "slave-burst-sizes was defined but we have 0 at this
12410Sstevel@tonic-gate * point, we must have had 64 bit burstsizes, however a prior
12420Sstevel@tonic-gate * device can only burst in 32 bit mode. Therefore, we leave
12430Sstevel@tonic-gate * the burstsizes in the 32 bit mode and disregard the 64 bit.
12440Sstevel@tonic-gate */
12450Sstevel@tonic-gate if (slave_burstsizes == 0)
12460Sstevel@tonic-gate goto done;
12470Sstevel@tonic-gate
12480Sstevel@tonic-gate /*
12490Sstevel@tonic-gate * We and in the new burst sizes with that of prior devices.
12500Sstevel@tonic-gate * This ensures that we always take the least common
12510Sstevel@tonic-gate * denominator of the burst sizes.
12520Sstevel@tonic-gate */
12530Sstevel@tonic-gate softsp->sbus_slave_burstsizes[slot] &=
12540Sstevel@tonic-gate (slave_burstsizes &
12550Sstevel@tonic-gate ((SYSIO64_SLAVEBURST_RANGE <<
12560Sstevel@tonic-gate SYSIO64_BURST_SHIFT) |
12570Sstevel@tonic-gate SYSIO_SLAVEBURST_RANGE));
12580Sstevel@tonic-gate
12590Sstevel@tonic-gate /* Get the 64 bit burstsizes. */
12600Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[slot] &
12610Sstevel@tonic-gate SYSIO64_BURST_MASK) {
12620Sstevel@tonic-gate /* get the 64 bit burstsizes */
12630Sstevel@tonic-gate burstsizes = softsp->sbus_slave_burstsizes[slot] >>
12640Sstevel@tonic-gate SYSIO64_BURST_SHIFT;
12650Sstevel@tonic-gate
12660Sstevel@tonic-gate /* Turn on 64 bit PIO's on the sbus */
12670Sstevel@tonic-gate *slot_reg |= SBUS_ETM;
12680Sstevel@tonic-gate } else {
12690Sstevel@tonic-gate /* Turn off 64 bit PIO's on the sbus */
12700Sstevel@tonic-gate *slot_reg &= ~SBUS_ETM;
12710Sstevel@tonic-gate
12720Sstevel@tonic-gate /* Get the 32 bit burstsizes if we don't have 64 bit. */
12730Sstevel@tonic-gate if (softsp->sbus_slave_burstsizes[slot] &
12740Sstevel@tonic-gate SYSIO_BURST_MASK) {
12750Sstevel@tonic-gate burstsizes =
12760Sstevel@tonic-gate softsp->sbus_slave_burstsizes[slot] &
12770Sstevel@tonic-gate SYSIO_BURST_MASK;
12780Sstevel@tonic-gate }
12790Sstevel@tonic-gate }
12800Sstevel@tonic-gate
12810Sstevel@tonic-gate /* Get the burstsizes into sysio register format */
12820Sstevel@tonic-gate burstsizes >>= SYSIO_SLAVEBURST_REGSHIFT;
12830Sstevel@tonic-gate
12840Sstevel@tonic-gate /* Reset reg in case we're scaling back */
12850Sstevel@tonic-gate *slot_reg &= (uint64_t)~SYSIO_SLAVEBURST_MASK;
12860Sstevel@tonic-gate
12870Sstevel@tonic-gate /* Program the burstsizes */
12880Sstevel@tonic-gate *slot_reg |= (uint64_t)burstsizes;
12890Sstevel@tonic-gate
12900Sstevel@tonic-gate /* Flush system load/store buffers */
12910Sstevel@tonic-gate #ifndef lint
12920Sstevel@tonic-gate tmp = *slot_reg;
12930Sstevel@tonic-gate #endif /* !lint */
12940Sstevel@tonic-gate }
12950Sstevel@tonic-gate
12960Sstevel@tonic-gate done:
12970Sstevel@tonic-gate return (DDI_SUCCESS);
12980Sstevel@tonic-gate }
12990Sstevel@tonic-gate
13000Sstevel@tonic-gate static int
sbus_uninitchild(dev_info_t * dip)13010Sstevel@tonic-gate sbus_uninitchild(dev_info_t *dip)
13020Sstevel@tonic-gate {
13030Sstevel@tonic-gate struct sysio_parent_private_data *pdptr;
13040Sstevel@tonic-gate size_t n;
13050Sstevel@tonic-gate
13060Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) != NULL) {
13070Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nrng) != 0)
13080Sstevel@tonic-gate kmem_free(pdptr->par_rng, n *
13090Sstevel@tonic-gate sizeof (struct rangespec));
13100Sstevel@tonic-gate
13110Sstevel@tonic-gate if ((n = pdptr->par_nreg) != 0)
13120Sstevel@tonic-gate kmem_free(pdptr->par_reg, n * sizeof (struct regspec));
13130Sstevel@tonic-gate
13140Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr));
13150Sstevel@tonic-gate ddi_set_parent_data(dip, NULL);
13160Sstevel@tonic-gate }
13170Sstevel@tonic-gate ddi_set_name_addr(dip, NULL);
13180Sstevel@tonic-gate /*
13190Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form
13200Sstevel@tonic-gate */
13210Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
13220Sstevel@tonic-gate impl_rem_dev_props(dip);
13230Sstevel@tonic-gate return (DDI_SUCCESS);
13240Sstevel@tonic-gate }
13250Sstevel@tonic-gate
13260Sstevel@tonic-gate #ifdef DEBUG
13270Sstevel@tonic-gate int sbus_peekfault_cnt = 0;
13280Sstevel@tonic-gate int sbus_pokefault_cnt = 0;
13290Sstevel@tonic-gate #endif /* DEBUG */
13300Sstevel@tonic-gate
13310Sstevel@tonic-gate static int
sbus_ctlops_poke(struct sbus_soft_state * softsp,peekpoke_ctlops_t * in_args)13320Sstevel@tonic-gate sbus_ctlops_poke(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args)
13330Sstevel@tonic-gate {
13340Sstevel@tonic-gate int err = DDI_SUCCESS;
13350Sstevel@tonic-gate on_trap_data_t otd;
13360Sstevel@tonic-gate volatile uint64_t tmpreg;
13370Sstevel@tonic-gate
13380Sstevel@tonic-gate /* Cautious access not supported. */
13390Sstevel@tonic-gate if (in_args->handle != NULL)
13400Sstevel@tonic-gate return (DDI_FAILURE);
13410Sstevel@tonic-gate
13420Sstevel@tonic-gate mutex_enter(&softsp->pokefault_mutex);
13430Sstevel@tonic-gate softsp->ontrap_data = &otd;
13440Sstevel@tonic-gate
13450Sstevel@tonic-gate /* Set up protected environment. */
13460Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) {
13470Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline;
13480Sstevel@tonic-gate
13490Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault;
13500Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr,
13510Sstevel@tonic-gate (void *)in_args->host_addr);
13520Sstevel@tonic-gate otd.ot_trampoline = tramp;
13530Sstevel@tonic-gate } else
13540Sstevel@tonic-gate err = DDI_FAILURE;
13550Sstevel@tonic-gate
13560Sstevel@tonic-gate /* Flush any sbus store buffers. */
13570Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
13580Sstevel@tonic-gate
13590Sstevel@tonic-gate /*
13600Sstevel@tonic-gate * Read the sbus error reg and see if a fault occured. If
13610Sstevel@tonic-gate * one has, give the SYSIO time to packetize the interrupt
13620Sstevel@tonic-gate * for the fault and send it out. The sbus error handler will
13630Sstevel@tonic-gate * 0 these fields when it's called to service the fault.
13640Sstevel@tonic-gate */
13650Sstevel@tonic-gate tmpreg = *softsp->sbus_err_reg;
13660Sstevel@tonic-gate while (tmpreg & SB_AFSR_P_TO || tmpreg & SB_AFSR_P_BERR)
13670Sstevel@tonic-gate tmpreg = *softsp->sbus_err_reg;
13680Sstevel@tonic-gate
13690Sstevel@tonic-gate /* Take down protected environment. */
13700Sstevel@tonic-gate no_trap();
13710Sstevel@tonic-gate
13720Sstevel@tonic-gate softsp->ontrap_data = NULL;
13730Sstevel@tonic-gate mutex_exit(&softsp->pokefault_mutex);
13740Sstevel@tonic-gate
13750Sstevel@tonic-gate #ifdef DEBUG
13760Sstevel@tonic-gate if (err == DDI_FAILURE)
13770Sstevel@tonic-gate sbus_pokefault_cnt++;
13780Sstevel@tonic-gate #endif
13790Sstevel@tonic-gate return (err);
13800Sstevel@tonic-gate }
13810Sstevel@tonic-gate
13820Sstevel@tonic-gate /*ARGSUSED*/
13830Sstevel@tonic-gate static int
sbus_ctlops_peek(struct sbus_soft_state * softsp,peekpoke_ctlops_t * in_args,void * result)13840Sstevel@tonic-gate sbus_ctlops_peek(struct sbus_soft_state *softsp, peekpoke_ctlops_t *in_args,
13850Sstevel@tonic-gate void *result)
13860Sstevel@tonic-gate {
13870Sstevel@tonic-gate int err = DDI_SUCCESS;
13880Sstevel@tonic-gate on_trap_data_t otd;
13890Sstevel@tonic-gate
13900Sstevel@tonic-gate /* No safe access except for peek is supported. */
13910Sstevel@tonic-gate if (in_args->handle != NULL)
13920Sstevel@tonic-gate return (DDI_FAILURE);
13930Sstevel@tonic-gate
13940Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) {
13950Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline;
13960Sstevel@tonic-gate
13970Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault;
13980Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr,
13990Sstevel@tonic-gate (void *)in_args->host_addr);
14000Sstevel@tonic-gate otd.ot_trampoline = tramp;
14010Sstevel@tonic-gate result = (void *)in_args->host_addr;
14020Sstevel@tonic-gate } else
14030Sstevel@tonic-gate err = DDI_FAILURE;
14040Sstevel@tonic-gate
14050Sstevel@tonic-gate #ifdef DEBUG
14060Sstevel@tonic-gate if (err == DDI_FAILURE)
14070Sstevel@tonic-gate sbus_peekfault_cnt++;
14080Sstevel@tonic-gate #endif
14090Sstevel@tonic-gate no_trap();
14100Sstevel@tonic-gate return (err);
14110Sstevel@tonic-gate }
14120Sstevel@tonic-gate
14130Sstevel@tonic-gate static int
sbus_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t op,void * arg,void * result)14140Sstevel@tonic-gate sbus_ctlops(dev_info_t *dip, dev_info_t *rdip,
14150Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result)
14160Sstevel@tonic-gate {
14170Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *)
1418*7656SSherry.Moore@Sun.COM ddi_get_soft_state(sbusp, ddi_get_instance(dip));
14190Sstevel@tonic-gate
14200Sstevel@tonic-gate switch (op) {
14210Sstevel@tonic-gate
14220Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD:
14230Sstevel@tonic-gate return (sbus_initchild(dip, (dev_info_t *)arg));
14240Sstevel@tonic-gate
14250Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD:
14260Sstevel@tonic-gate return (sbus_uninitchild(arg));
14270Sstevel@tonic-gate
14280Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: {
14290Sstevel@tonic-gate int val = *((int *)result);
14300Sstevel@tonic-gate
14310Sstevel@tonic-gate /*
14320Sstevel@tonic-gate * The 'arg' value of nonzero indicates 'streaming' mode.
14330Sstevel@tonic-gate * If in streaming mode, pick the largest of our burstsizes
14340Sstevel@tonic-gate * available and say that that is our minimum value (modulo
14350Sstevel@tonic-gate * what mincycle is).
14360Sstevel@tonic-gate */
14371035Smike_s if ((int)(uintptr_t)arg)
14380Sstevel@tonic-gate val = maxbit(val,
14390Sstevel@tonic-gate (1 << (ddi_fls(softsp->sbus_burst_sizes) - 1)));
14400Sstevel@tonic-gate else
14410Sstevel@tonic-gate val = maxbit(val,
14420Sstevel@tonic-gate (1 << (ddi_ffs(softsp->sbus_burst_sizes) - 1)));
14430Sstevel@tonic-gate
14440Sstevel@tonic-gate *((int *)result) = val;
14450Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result));
14460Sstevel@tonic-gate }
14470Sstevel@tonic-gate
14480Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: {
14490Sstevel@tonic-gate dev_info_t *pdev;
14500Sstevel@tonic-gate int i, n, len, f_len;
14510Sstevel@tonic-gate char *msgbuf;
14520Sstevel@tonic-gate
14530Sstevel@tonic-gate /*
14540Sstevel@tonic-gate * So we can do one atomic cmn_err call, we allocate a 4k
14550Sstevel@tonic-gate * buffer, and format the reportdev message into that buffer,
14560Sstevel@tonic-gate * send it to cmn_err, and then free the allocated buffer.
14570Sstevel@tonic-gate * If message is longer than 1k, the message is truncated and
14580Sstevel@tonic-gate * an error message is emitted (debug kernel only).
14590Sstevel@tonic-gate */
14600Sstevel@tonic-gate #define REPORTDEV_BUFSIZE 1024
14610Sstevel@tonic-gate
14620Sstevel@tonic-gate int sbusid = ddi_get_instance(dip);
14630Sstevel@tonic-gate
14640Sstevel@tonic-gate if (ddi_get_parent_data(rdip) == NULL)
14650Sstevel@tonic-gate return (DDI_FAILURE);
14660Sstevel@tonic-gate
14670Sstevel@tonic-gate msgbuf = kmem_zalloc(REPORTDEV_BUFSIZE, KM_SLEEP);
14680Sstevel@tonic-gate
14690Sstevel@tonic-gate pdev = ddi_get_parent(rdip);
14700Sstevel@tonic-gate f_len = snprintf(msgbuf, REPORTDEV_BUFSIZE,
14710Sstevel@tonic-gate "%s%d at %s%d: SBus%d ",
14720Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip),
14730Sstevel@tonic-gate ddi_driver_name(pdev), ddi_get_instance(pdev), sbusid);
14740Sstevel@tonic-gate len = strlen(msgbuf);
14750Sstevel@tonic-gate
14760Sstevel@tonic-gate for (i = 0, n = sysio_pd_getnreg(rdip); i < n; i++) {
14770Sstevel@tonic-gate struct regspec *rp;
14780Sstevel@tonic-gate
14790Sstevel@tonic-gate rp = sysio_pd_getreg(rdip, i);
14800Sstevel@tonic-gate if (i != 0) {
14810Sstevel@tonic-gate f_len += snprintf(msgbuf + len,
14820Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, " and ");
14830Sstevel@tonic-gate len = strlen(msgbuf);
14840Sstevel@tonic-gate }
14850Sstevel@tonic-gate
14860Sstevel@tonic-gate f_len += snprintf(msgbuf + len, REPORTDEV_BUFSIZE - len,
14870Sstevel@tonic-gate "slot 0x%x offset 0x%x",
14880Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_addr);
14890Sstevel@tonic-gate len = strlen(msgbuf);
14900Sstevel@tonic-gate }
14910Sstevel@tonic-gate
14922580Sanish for (i = 0, n = i_ddi_get_intx_nintrs(rdip); i < n; i++) {
1493693Sgovinda uint32_t sbuslevel, inum, pri;
14940Sstevel@tonic-gate
14950Sstevel@tonic-gate if (i != 0) {
14960Sstevel@tonic-gate f_len += snprintf(msgbuf + len,
14970Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, ",");
14980Sstevel@tonic-gate len = strlen(msgbuf);
14990Sstevel@tonic-gate }
15000Sstevel@tonic-gate
1501693Sgovinda sbuslevel = inum = i_ddi_get_inum(rdip, i);
1502693Sgovinda pri = i_ddi_get_intr_pri(rdip, i);
1503693Sgovinda
1504693Sgovinda (void) sbus_xlate_intrs(dip, rdip, &inum,
1505693Sgovinda &pri, softsp->intr_mapping_ign);
15060Sstevel@tonic-gate
15070Sstevel@tonic-gate if (sbuslevel > MAX_SBUS_LEVEL)
15080Sstevel@tonic-gate f_len += snprintf(msgbuf + len,
15090Sstevel@tonic-gate REPORTDEV_BUFSIZE - len,
15100Sstevel@tonic-gate " Onboard device ");
15110Sstevel@tonic-gate else
15120Sstevel@tonic-gate f_len += snprintf(msgbuf + len,
15130Sstevel@tonic-gate REPORTDEV_BUFSIZE - len, " SBus level %d ",
15140Sstevel@tonic-gate sbuslevel);
15150Sstevel@tonic-gate len = strlen(msgbuf);
15160Sstevel@tonic-gate
15170Sstevel@tonic-gate f_len += snprintf(msgbuf + len, REPORTDEV_BUFSIZE - len,
15180Sstevel@tonic-gate "sparc9 ipl %d", pri);
15190Sstevel@tonic-gate len = strlen(msgbuf);
15200Sstevel@tonic-gate }
15210Sstevel@tonic-gate #ifdef DEBUG
15220Sstevel@tonic-gate if (f_len + 1 >= REPORTDEV_BUFSIZE) {
15230Sstevel@tonic-gate cmn_err(CE_NOTE, "next message is truncated: "
15240Sstevel@tonic-gate "printed length 1024, real length %d", f_len);
15250Sstevel@tonic-gate }
15260Sstevel@tonic-gate #endif /* DEBUG */
15270Sstevel@tonic-gate
15280Sstevel@tonic-gate cmn_err(CE_CONT, "?%s\n", msgbuf);
15290Sstevel@tonic-gate kmem_free(msgbuf, REPORTDEV_BUFSIZE);
15300Sstevel@tonic-gate return (DDI_SUCCESS);
15310Sstevel@tonic-gate
15320Sstevel@tonic-gate #undef REPORTDEV_BUFSIZE
15330Sstevel@tonic-gate }
15340Sstevel@tonic-gate
15350Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY:
15360Sstevel@tonic-gate return (DDI_FAILURE);
15370Sstevel@tonic-gate
15380Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: {
15390Sstevel@tonic-gate dev_info_t *dipb = (dev_info_t *)arg;
15400Sstevel@tonic-gate int r_slot, b_slot;
15410Sstevel@tonic-gate
15420Sstevel@tonic-gate if ((b_slot = find_sbus_slot(dip, dipb)) < 0)
15430Sstevel@tonic-gate return (DDI_FAILURE);
15440Sstevel@tonic-gate
15450Sstevel@tonic-gate if ((r_slot = find_sbus_slot(dip, rdip)) < 0)
15460Sstevel@tonic-gate return (DDI_FAILURE);
15470Sstevel@tonic-gate
15480Sstevel@tonic-gate return ((b_slot == r_slot)? DDI_SUCCESS : DDI_FAILURE);
15490Sstevel@tonic-gate
15500Sstevel@tonic-gate }
15510Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC:
15520Sstevel@tonic-gate cmn_err(CE_CONT, "?DDI_DMAPMAPC called!!\n");
15530Sstevel@tonic-gate return (DDI_FAILURE);
15540Sstevel@tonic-gate
15550Sstevel@tonic-gate case DDI_CTLOPS_POKE:
15560Sstevel@tonic-gate return (sbus_ctlops_poke(softsp, (peekpoke_ctlops_t *)arg));
15570Sstevel@tonic-gate
15580Sstevel@tonic-gate case DDI_CTLOPS_PEEK:
15590Sstevel@tonic-gate return (sbus_ctlops_peek(softsp, (peekpoke_ctlops_t *)arg,
15600Sstevel@tonic-gate result));
15610Sstevel@tonic-gate
15620Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE:
15630Sstevel@tonic-gate *(ulong_t *)result = IOMMU_PAGESIZE;
15640Sstevel@tonic-gate return (DDI_SUCCESS);
15650Sstevel@tonic-gate
15660Sstevel@tonic-gate default:
15670Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result));
15680Sstevel@tonic-gate }
15690Sstevel@tonic-gate }
15700Sstevel@tonic-gate
15710Sstevel@tonic-gate static int
find_sbus_slot(dev_info_t * dip,dev_info_t * rdip)15720Sstevel@tonic-gate find_sbus_slot(dev_info_t *dip, dev_info_t *rdip)
15730Sstevel@tonic-gate {
15740Sstevel@tonic-gate dev_info_t *child;
15750Sstevel@tonic-gate int slot = -1;
15760Sstevel@tonic-gate
15770Sstevel@tonic-gate /*
15780Sstevel@tonic-gate * look for the node that's a direct child of this Sbus node.
15790Sstevel@tonic-gate */
15800Sstevel@tonic-gate while (rdip && (child = ddi_get_parent(rdip)) != dip) {
15810Sstevel@tonic-gate rdip = child;
15820Sstevel@tonic-gate }
15830Sstevel@tonic-gate
15840Sstevel@tonic-gate /*
15850Sstevel@tonic-gate * If there is one, get the slot number of *my* child
15860Sstevel@tonic-gate */
15870Sstevel@tonic-gate if (child == dip)
15880Sstevel@tonic-gate slot = sysio_pd_getslot(rdip);
15890Sstevel@tonic-gate
15900Sstevel@tonic-gate return (slot);
15910Sstevel@tonic-gate }
15920Sstevel@tonic-gate
15930Sstevel@tonic-gate /*
15940Sstevel@tonic-gate * This is the sbus interrupt routine wrapper function. This function
15950Sstevel@tonic-gate * installs itself as a child devices interrupt handler. It's function is
15960Sstevel@tonic-gate * to dispatch a child devices interrupt handler, and then
15970Sstevel@tonic-gate * reset the interrupt clear register for the child device.
15980Sstevel@tonic-gate *
15990Sstevel@tonic-gate * Warning: This routine may need to be implemented as an assembly level
16000Sstevel@tonic-gate * routine to improve performance.
16010Sstevel@tonic-gate */
16020Sstevel@tonic-gate
16030Sstevel@tonic-gate #define MAX_INTR_CNT 10
16040Sstevel@tonic-gate
16050Sstevel@tonic-gate static uint_t
sbus_intr_wrapper(caddr_t arg)16060Sstevel@tonic-gate sbus_intr_wrapper(caddr_t arg)
16070Sstevel@tonic-gate {
16080Sstevel@tonic-gate uint_t intr_return = DDI_INTR_UNCLAIMED;
16090Sstevel@tonic-gate volatile uint64_t tmpreg;
16100Sstevel@tonic-gate struct sbus_wrapper_arg *intr_info;
16110Sstevel@tonic-gate struct sbus_intr_handler *intr_handler;
16120Sstevel@tonic-gate uchar_t *spurious_cntr;
16130Sstevel@tonic-gate
16140Sstevel@tonic-gate intr_info = (struct sbus_wrapper_arg *)arg;
16150Sstevel@tonic-gate spurious_cntr = &intr_info->softsp->spurious_cntrs[intr_info->pil];
16160Sstevel@tonic-gate intr_handler = intr_info->handler_list;
16170Sstevel@tonic-gate
16180Sstevel@tonic-gate while (intr_handler) {
16190Sstevel@tonic-gate caddr_t arg1 = intr_handler->arg1;
16200Sstevel@tonic-gate caddr_t arg2 = intr_handler->arg2;
16210Sstevel@tonic-gate uint_t (*funcp)() = intr_handler->funcp;
16220Sstevel@tonic-gate dev_info_t *dip = intr_handler->dip;
16230Sstevel@tonic-gate int r;
16240Sstevel@tonic-gate
16250Sstevel@tonic-gate if (intr_handler->intr_state == SBUS_INTR_STATE_DISABLE) {
16260Sstevel@tonic-gate intr_handler = intr_handler->next;
16270Sstevel@tonic-gate continue;
16280Sstevel@tonic-gate }
16290Sstevel@tonic-gate
16300Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip,
16310Sstevel@tonic-gate void *, funcp, caddr_t, arg1, caddr_t, arg2);
16320Sstevel@tonic-gate
16330Sstevel@tonic-gate r = (*funcp)(arg1, arg2);
16340Sstevel@tonic-gate
16350Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip,
16360Sstevel@tonic-gate void *, funcp, caddr_t, arg1, int, r);
16370Sstevel@tonic-gate
16380Sstevel@tonic-gate intr_return |= r;
16390Sstevel@tonic-gate intr_handler = intr_handler->next;
16400Sstevel@tonic-gate }
16410Sstevel@tonic-gate
16420Sstevel@tonic-gate /* Set the interrupt state machine to idle */
16430Sstevel@tonic-gate tmpreg = *intr_info->softsp->sbus_ctrl_reg;
16440Sstevel@tonic-gate tmpreg = SBUS_INTR_IDLE;
16450Sstevel@tonic-gate *intr_info->clear_reg = tmpreg;
16460Sstevel@tonic-gate tmpreg = *intr_info->softsp->sbus_ctrl_reg;
16470Sstevel@tonic-gate
16480Sstevel@tonic-gate if (intr_return == DDI_INTR_UNCLAIMED) {
16490Sstevel@tonic-gate (*spurious_cntr)++;
16500Sstevel@tonic-gate
16510Sstevel@tonic-gate if (*spurious_cntr < MAX_INTR_CNT) {
16520Sstevel@tonic-gate if (intr_cntr_on)
16530Sstevel@tonic-gate return (DDI_INTR_CLAIMED);
16540Sstevel@tonic-gate }
16550Sstevel@tonic-gate #ifdef DEBUG
16560Sstevel@tonic-gate else if (intr_info->pil >= LOCK_LEVEL) {
16570Sstevel@tonic-gate cmn_err(CE_PANIC, "%d unclaimed interrupts at "
16580Sstevel@tonic-gate "interrupt level %d", MAX_INTR_CNT,
16590Sstevel@tonic-gate intr_info->pil);
16600Sstevel@tonic-gate }
16610Sstevel@tonic-gate #endif
16620Sstevel@tonic-gate
16630Sstevel@tonic-gate /*
16640Sstevel@tonic-gate * Reset spurious counter once we acknowledge
16650Sstevel@tonic-gate * it to the system level.
16660Sstevel@tonic-gate */
16670Sstevel@tonic-gate *spurious_cntr = (uchar_t)0;
16680Sstevel@tonic-gate } else {
16690Sstevel@tonic-gate *spurious_cntr = (uchar_t)0;
16700Sstevel@tonic-gate }
16710Sstevel@tonic-gate
16720Sstevel@tonic-gate return (intr_return);
16730Sstevel@tonic-gate }
16740Sstevel@tonic-gate
16750Sstevel@tonic-gate /*
16760Sstevel@tonic-gate * add_intrspec - Add an interrupt specification.
16770Sstevel@tonic-gate */
16780Sstevel@tonic-gate static int
sbus_add_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)16790Sstevel@tonic-gate sbus_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
16800Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp)
16810Sstevel@tonic-gate {
16820Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *)
16830Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip));
16840Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg;
16850Sstevel@tonic-gate volatile uint64_t tmp_mondo_vec;
16860Sstevel@tonic-gate volatile uint64_t *intr_state_reg;
16870Sstevel@tonic-gate volatile uint64_t tmpreg; /* HW flush reg */
16880Sstevel@tonic-gate uint_t start_bit;
16890Sstevel@tonic-gate int ino;
16900Sstevel@tonic-gate uint_t cpu_id;
16910Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg;
16920Sstevel@tonic-gate struct sbus_intr_handler *intr_handler;
16930Sstevel@tonic-gate uint32_t slot;
16940Sstevel@tonic-gate /* Interrupt state machine reset flag */
16950Sstevel@tonic-gate int reset_ism_register = 1;
16960Sstevel@tonic-gate int ret = DDI_SUCCESS;
16970Sstevel@tonic-gate
16980Sstevel@tonic-gate /* Check if we have a valid sbus slot address */
16990Sstevel@tonic-gate if (((slot = (uint_t)find_sbus_slot(dip, rdip)) >=
17000Sstevel@tonic-gate MAX_SBUS_SLOT_ADDR) || (slot < (uint_t)0)) {
17010Sstevel@tonic-gate cmn_err(CE_WARN, "Invalid sbus slot 0x%x during add intr\n",
17020Sstevel@tonic-gate slot);
17030Sstevel@tonic-gate return (DDI_FAILURE);
17040Sstevel@tonic-gate }
17050Sstevel@tonic-gate
17060Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: sbus interrupt %d "
1707693Sgovinda "for device %s%d\n", hdlp->ih_vector, ddi_driver_name(rdip),
17080Sstevel@tonic-gate ddi_get_instance(rdip)));
17090Sstevel@tonic-gate
17100Sstevel@tonic-gate /* Xlate the interrupt */
1711693Sgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector,
1712693Sgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) {
17130Sstevel@tonic-gate cmn_err(CE_WARN, "Can't xlate SBUS devices %s interrupt.\n",
1714693Sgovinda ddi_driver_name(rdip));
17150Sstevel@tonic-gate return (DDI_FAILURE);
17160Sstevel@tonic-gate }
17170Sstevel@tonic-gate
17180Sstevel@tonic-gate /* get the ino number */
1719693Sgovinda ino = hdlp->ih_vector & SBUS_MAX_INO;
17200Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg +
17210Sstevel@tonic-gate ino_table[ino]->mapping_reg);
17220Sstevel@tonic-gate
17230Sstevel@tonic-gate /*
17240Sstevel@tonic-gate * This is an intermediate step in identifying
17250Sstevel@tonic-gate * the exact bits which represent the device in the interrupt
17260Sstevel@tonic-gate * state diagnostic register.
17270Sstevel@tonic-gate */
17280Sstevel@tonic-gate if (ino > MAX_MONDO_EXTERNAL) {
17290Sstevel@tonic-gate start_bit = ino_table[ino]->diagreg_shift;
17300Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state;
17310Sstevel@tonic-gate } else {
17320Sstevel@tonic-gate start_bit = 16 * (ino >> 3) + 2 * (ino & 0x7);
17330Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state;
17340Sstevel@tonic-gate }
17350Sstevel@tonic-gate
17360Sstevel@tonic-gate
17370Sstevel@tonic-gate /* Allocate a nexus interrupt data structure */
17380Sstevel@tonic-gate intr_handler = kmem_zalloc(sizeof (struct sbus_intr_handler), KM_SLEEP);
17390Sstevel@tonic-gate intr_handler->dip = rdip;
17400Sstevel@tonic-gate intr_handler->funcp = hdlp->ih_cb_func;
17410Sstevel@tonic-gate intr_handler->arg1 = hdlp->ih_cb_arg1;
17420Sstevel@tonic-gate intr_handler->arg2 = hdlp->ih_cb_arg2;
17430Sstevel@tonic-gate intr_handler->inum = hdlp->ih_inum;
17440Sstevel@tonic-gate
17450Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: xlated interrupt 0x%x "
17467240Srh87107 "intr_handler 0x%p\n", hdlp->ih_vector, (void *)intr_handler));
17470Sstevel@tonic-gate
17480Sstevel@tonic-gate /*
17490Sstevel@tonic-gate * Grab this lock here. So it will protect the poll list.
17500Sstevel@tonic-gate */
17510Sstevel@tonic-gate mutex_enter(&softsp->intr_poll_list_lock);
17520Sstevel@tonic-gate
17530Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino];
17540Sstevel@tonic-gate /* Check if we have a poll list to deal with */
17550Sstevel@tonic-gate if (sbus_arg) {
17560Sstevel@tonic-gate tmp_mondo_vec = *mondo_vec_reg;
17570Sstevel@tonic-gate tmp_mondo_vec &= ~INTERRUPT_VALID;
17580Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec;
17590Sstevel@tonic-gate
17600Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
17610Sstevel@tonic-gate #ifdef lint
17620Sstevel@tonic-gate tmpreg = tmpreg;
17630Sstevel@tonic-gate #endif
17640Sstevel@tonic-gate
17650Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:sbus_arg exists "
17667240Srh87107 "0x%p\n", (void *)sbus_arg));
17670Sstevel@tonic-gate /*
17680Sstevel@tonic-gate * Two bits per ino in the diagnostic register
17690Sstevel@tonic-gate * indicate the status of its interrupt.
17700Sstevel@tonic-gate * 0 - idle, 1 - transmit, 3 - pending.
17710Sstevel@tonic-gate */
17720Sstevel@tonic-gate while (((*intr_state_reg >>
17730Sstevel@tonic-gate start_bit) & 0x3) == INT_PENDING && !panicstr)
17740Sstevel@tonic-gate /* empty */;
17750Sstevel@tonic-gate
17760Sstevel@tonic-gate intr_handler->next = sbus_arg->handler_list;
17770Sstevel@tonic-gate sbus_arg->handler_list = intr_handler;
17780Sstevel@tonic-gate
17790Sstevel@tonic-gate reset_ism_register = 0;
17800Sstevel@tonic-gate } else {
17810Sstevel@tonic-gate sbus_arg = kmem_zalloc(sizeof (struct sbus_wrapper_arg),
17820Sstevel@tonic-gate KM_SLEEP);
17830Sstevel@tonic-gate
17840Sstevel@tonic-gate softsp->intr_list[ino] = sbus_arg;
17850Sstevel@tonic-gate sbus_arg->clear_reg = (softsp->clr_intr_reg +
17860Sstevel@tonic-gate ino_table[ino]->clear_reg);
17870Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:Ino 0x%x Interrupt "
17887240Srh87107 "clear reg: 0x%p\n", ino, (void *)sbus_arg->clear_reg));
17890Sstevel@tonic-gate sbus_arg->softsp = softsp;
17900Sstevel@tonic-gate sbus_arg->handler_list = intr_handler;
17910Sstevel@tonic-gate
17920Sstevel@tonic-gate /*
17930Sstevel@tonic-gate * No handler added yet in the interrupt vector
17940Sstevel@tonic-gate * table for this ino.
17950Sstevel@tonic-gate * Install the nexus interrupt wrapper in the
17960Sstevel@tonic-gate * system. The wrapper will call the device
17970Sstevel@tonic-gate * interrupt handler.
17980Sstevel@tonic-gate */
17990Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp,
18000Sstevel@tonic-gate (ddi_intr_handler_t *)sbus_intr_wrapper,
18010Sstevel@tonic-gate (caddr_t)sbus_arg, NULL);
18020Sstevel@tonic-gate
18030Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp);
18040Sstevel@tonic-gate
18050Sstevel@tonic-gate /*
18060Sstevel@tonic-gate * Restore original interrupt handler
18070Sstevel@tonic-gate * and arguments in interrupt handle.
18080Sstevel@tonic-gate */
18090Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, intr_handler->funcp,
18100Sstevel@tonic-gate intr_handler->arg1, intr_handler->arg2);
18110Sstevel@tonic-gate
1812965Sgovinda if (ret != DDI_SUCCESS) {
1813965Sgovinda mutex_exit(&softsp->intr_poll_list_lock);
1814965Sgovinda goto done;
1815965Sgovinda }
18160Sstevel@tonic-gate
18170Sstevel@tonic-gate if ((slot >= EXT_SBUS_SLOTS) ||
18180Sstevel@tonic-gate (softsp->intr_hndlr_cnt[slot] == 0)) {
18190Sstevel@tonic-gate
18200Sstevel@tonic-gate cpu_id = intr_dist_cpuid();
18210Sstevel@tonic-gate #ifdef _STARFIRE
18220Sstevel@tonic-gate tmp_mondo_vec = pc_translate_tgtid(
18230Sstevel@tonic-gate softsp->ittrans_cookie, cpu_id,
1824*7656SSherry.Moore@Sun.COM mondo_vec_reg) << IMR_TID_SHIFT;
18250Sstevel@tonic-gate #else
18260Sstevel@tonic-gate tmp_mondo_vec =
18270Sstevel@tonic-gate cpu_id << IMR_TID_SHIFT;
18280Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: initial "
18291035Smike_s "mapping reg 0x%lx\n", tmp_mondo_vec));
18300Sstevel@tonic-gate #endif /* _STARFIRE */
18310Sstevel@tonic-gate } else {
18320Sstevel@tonic-gate /*
18330Sstevel@tonic-gate * There is already a different
18340Sstevel@tonic-gate * ino programmed at this IMR.
18350Sstevel@tonic-gate * Just read the IMR out to get the
18360Sstevel@tonic-gate * correct MID target.
18370Sstevel@tonic-gate */
18380Sstevel@tonic-gate tmp_mondo_vec = *mondo_vec_reg;
18390Sstevel@tonic-gate tmp_mondo_vec &= ~INTERRUPT_VALID;
18400Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec;
18410Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: existing "
18421035Smike_s "mapping reg 0x%lx\n", tmp_mondo_vec));
18430Sstevel@tonic-gate }
18440Sstevel@tonic-gate
18450Sstevel@tonic-gate sbus_arg->pil = hdlp->ih_pri;
18460Sstevel@tonic-gate
18470Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr:Alloc sbus_arg "
18487240Srh87107 "0x%p\n", (void *)sbus_arg));
18490Sstevel@tonic-gate }
18500Sstevel@tonic-gate
18510Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]++;
18520Sstevel@tonic-gate
18530Sstevel@tonic-gate mutex_exit(&softsp->intr_poll_list_lock);
18540Sstevel@tonic-gate
18550Sstevel@tonic-gate /*
18560Sstevel@tonic-gate * Program the ino vector accordingly. This MUST be the
18570Sstevel@tonic-gate * last thing we do. Once we program the ino, the device
18580Sstevel@tonic-gate * may begin to interrupt. Add this hardware interrupt to
18590Sstevel@tonic-gate * the interrupt lists, and get the CPU to target it at.
18600Sstevel@tonic-gate */
18610Sstevel@tonic-gate
18620Sstevel@tonic-gate tmp_mondo_vec |= INTERRUPT_VALID;
18630Sstevel@tonic-gate
18641035Smike_s DPRINTF(SBUS_INTERRUPT_DEBUG, ("Add intr: Ino 0x%x mapping reg: 0x%p "
18657240Srh87107 "Intr cntr %d\n", ino, (void *)mondo_vec_reg,
18660Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]));
18670Sstevel@tonic-gate
18680Sstevel@tonic-gate /* Force the interrupt state machine to idle. */
18690Sstevel@tonic-gate if (reset_ism_register) {
18700Sstevel@tonic-gate tmpreg = SBUS_INTR_IDLE;
18710Sstevel@tonic-gate *sbus_arg->clear_reg = tmpreg;
18720Sstevel@tonic-gate }
18730Sstevel@tonic-gate
18740Sstevel@tonic-gate /* Store it in the hardware reg. */
18750Sstevel@tonic-gate *mondo_vec_reg = tmp_mondo_vec;
18760Sstevel@tonic-gate
18770Sstevel@tonic-gate /* Flush store buffers */
18780Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
18790Sstevel@tonic-gate
18800Sstevel@tonic-gate done:
18810Sstevel@tonic-gate return (ret);
18820Sstevel@tonic-gate }
18830Sstevel@tonic-gate
18840Sstevel@tonic-gate static void
sbus_free_handler(dev_info_t * dip,uint32_t inum,struct sbus_wrapper_arg * sbus_arg)18850Sstevel@tonic-gate sbus_free_handler(dev_info_t *dip, uint32_t inum,
18860Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg)
18870Sstevel@tonic-gate {
18880Sstevel@tonic-gate struct sbus_intr_handler *listp, *prevp;
18890Sstevel@tonic-gate
18900Sstevel@tonic-gate if (sbus_arg) {
18910Sstevel@tonic-gate prevp = NULL;
18920Sstevel@tonic-gate listp = sbus_arg->handler_list;
18930Sstevel@tonic-gate
18940Sstevel@tonic-gate while (listp) {
18950Sstevel@tonic-gate if (listp->dip == dip && listp->inum == inum) {
18960Sstevel@tonic-gate if (prevp)
18970Sstevel@tonic-gate prevp->next = listp->next;
18980Sstevel@tonic-gate else {
18990Sstevel@tonic-gate prevp = listp->next;
19000Sstevel@tonic-gate sbus_arg->handler_list = prevp;
19010Sstevel@tonic-gate }
19020Sstevel@tonic-gate
19030Sstevel@tonic-gate kmem_free(listp,
19040Sstevel@tonic-gate sizeof (struct sbus_intr_handler));
19050Sstevel@tonic-gate break;
19060Sstevel@tonic-gate }
19070Sstevel@tonic-gate prevp = listp;
19080Sstevel@tonic-gate listp = listp->next;
19090Sstevel@tonic-gate }
19100Sstevel@tonic-gate }
19110Sstevel@tonic-gate }
19120Sstevel@tonic-gate
19130Sstevel@tonic-gate /*
19140Sstevel@tonic-gate * remove_intrspec - Remove an interrupt specification.
19150Sstevel@tonic-gate */
19160Sstevel@tonic-gate /*ARGSUSED*/
19170Sstevel@tonic-gate static void
sbus_remove_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)19180Sstevel@tonic-gate sbus_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
19190Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp)
19200Sstevel@tonic-gate {
19210Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg;
19220Sstevel@tonic-gate volatile uint64_t *intr_state_reg;
19230Sstevel@tonic-gate #ifndef lint
19240Sstevel@tonic-gate volatile uint64_t tmpreg;
19250Sstevel@tonic-gate #endif /* !lint */
19260Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *)
19270Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip));
19280Sstevel@tonic-gate int start_bit, ino, slot;
19290Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg;
19300Sstevel@tonic-gate
19310Sstevel@tonic-gate /* Grab the mutex protecting the poll list */
19320Sstevel@tonic-gate mutex_enter(&softsp->intr_poll_list_lock);
19330Sstevel@tonic-gate
19340Sstevel@tonic-gate /* Xlate the interrupt */
1935693Sgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector,
1936693Sgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) {
19370Sstevel@tonic-gate cmn_err(CE_WARN, "Can't xlate SBUS devices %s interrupt.\n",
1938693Sgovinda ddi_driver_name(rdip));
19390Sstevel@tonic-gate goto done;
19400Sstevel@tonic-gate }
19410Sstevel@tonic-gate
1942693Sgovinda ino = ((int32_t)hdlp->ih_vector) & SBUS_MAX_INO;
19430Sstevel@tonic-gate
19440Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg +
19450Sstevel@tonic-gate ino_table[ino]->mapping_reg);
19460Sstevel@tonic-gate
19470Sstevel@tonic-gate /* Turn off the valid bit in the mapping register. */
19480Sstevel@tonic-gate *mondo_vec_reg &= ~INTERRUPT_VALID;
19490Sstevel@tonic-gate #ifndef lint
19500Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
19510Sstevel@tonic-gate #endif /* !lint */
19520Sstevel@tonic-gate
19530Sstevel@tonic-gate /* Get our bit position for checking intr pending */
19540Sstevel@tonic-gate if (ino > MAX_MONDO_EXTERNAL) {
19550Sstevel@tonic-gate start_bit = ino_table[ino]->diagreg_shift;
19560Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state;
19570Sstevel@tonic-gate } else {
19580Sstevel@tonic-gate start_bit = 16 * (ino >> 3) + 2 * (ino & 0x7);
19590Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state;
19600Sstevel@tonic-gate }
19610Sstevel@tonic-gate
19620Sstevel@tonic-gate while (((*intr_state_reg >> start_bit) & 0x3) == INT_PENDING &&
19630Sstevel@tonic-gate !panicstr)
19640Sstevel@tonic-gate /* empty */;
19650Sstevel@tonic-gate
19660Sstevel@tonic-gate slot = find_sbus_slot(dip, rdip);
19670Sstevel@tonic-gate
19680Sstevel@tonic-gate /* Return if the slot is invalid */
19690Sstevel@tonic-gate if (slot >= MAX_SBUS_SLOT_ADDR || slot < 0) {
19700Sstevel@tonic-gate goto done;
19710Sstevel@tonic-gate }
19720Sstevel@tonic-gate
19730Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino];
19740Sstevel@tonic-gate
19750Sstevel@tonic-gate /* Decrement the intr handler count on this slot */
19760Sstevel@tonic-gate softsp->intr_hndlr_cnt[slot]--;
19770Sstevel@tonic-gate
19781035Smike_s DPRINTF(SBUS_INTERRUPT_DEBUG, ("Rem intr: Softsp 0x%p, Mondo 0x%x, "
19797240Srh87107 "ino 0x%x, sbus_arg 0x%p intr cntr %d\n", (void *)softsp,
19807240Srh87107 hdlp->ih_vector, ino, (void *)sbus_arg,
19817240Srh87107 softsp->intr_hndlr_cnt[slot]));
19820Sstevel@tonic-gate
19830Sstevel@tonic-gate ASSERT(sbus_arg != NULL);
19840Sstevel@tonic-gate ASSERT(sbus_arg->handler_list != NULL);
19850Sstevel@tonic-gate sbus_free_handler(rdip, hdlp->ih_inum, sbus_arg);
19860Sstevel@tonic-gate
19870Sstevel@tonic-gate /* If we still have a list, we're done. */
1988693Sgovinda if (sbus_arg->handler_list == NULL)
19890Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp);
19900Sstevel@tonic-gate
19910Sstevel@tonic-gate /*
19920Sstevel@tonic-gate * If other devices are still installed for this slot, we need to
19930Sstevel@tonic-gate * turn the valid bit back on.
19940Sstevel@tonic-gate */
19950Sstevel@tonic-gate if (softsp->intr_hndlr_cnt[slot] > 0) {
19960Sstevel@tonic-gate *mondo_vec_reg |= INTERRUPT_VALID;
19970Sstevel@tonic-gate #ifndef lint
19980Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
19990Sstevel@tonic-gate #endif /* !lint */
20000Sstevel@tonic-gate }
20010Sstevel@tonic-gate
20020Sstevel@tonic-gate if ((softsp->intr_hndlr_cnt[slot] == 0) || (slot >= EXT_SBUS_SLOTS)) {
20030Sstevel@tonic-gate ASSERT(sbus_arg->handler_list == NULL);
20040Sstevel@tonic-gate #ifdef _STARFIRE
20050Sstevel@tonic-gate /* Do cleanup for interrupt target translation */
20060Sstevel@tonic-gate pc_ittrans_cleanup(softsp->ittrans_cookie, mondo_vec_reg);
20070Sstevel@tonic-gate #endif /* _STARFIRE */
20080Sstevel@tonic-gate }
20090Sstevel@tonic-gate
20100Sstevel@tonic-gate
20110Sstevel@tonic-gate /* Free up the memory used for the sbus interrupt handler */
20120Sstevel@tonic-gate if (sbus_arg->handler_list == NULL) {
20130Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Rem intr: Freeing sbus arg "
20147240Srh87107 "0x%p\n", (void *)sbus_arg));
20150Sstevel@tonic-gate kmem_free(sbus_arg, sizeof (struct sbus_wrapper_arg));
20160Sstevel@tonic-gate softsp->intr_list[ino] = NULL;
20170Sstevel@tonic-gate }
20180Sstevel@tonic-gate
20190Sstevel@tonic-gate done:
20200Sstevel@tonic-gate mutex_exit(&softsp->intr_poll_list_lock);
20210Sstevel@tonic-gate }
20220Sstevel@tonic-gate
20230Sstevel@tonic-gate /*
20240Sstevel@tonic-gate * We're prepared to claim that the interrupt string is in
20250Sstevel@tonic-gate * the form of a list of <SBusintr> specifications, or we're dealing
20260Sstevel@tonic-gate * with on-board devices and we have an interrupt_number property which
20270Sstevel@tonic-gate * gives us our mondo number.
20280Sstevel@tonic-gate * Translate the sbus levels or mondos into sysiointrspecs.
20290Sstevel@tonic-gate */
20300Sstevel@tonic-gate static int
sbus_xlate_intrs(dev_info_t * dip,dev_info_t * rdip,uint32_t * intr,uint32_t * pil,int32_t ign)2031693Sgovinda sbus_xlate_intrs(dev_info_t *dip, dev_info_t *rdip, uint32_t *intr,
2032693Sgovinda uint32_t *pil, int32_t ign)
20330Sstevel@tonic-gate {
2034693Sgovinda uint32_t ino, slot, level = *intr;
20350Sstevel@tonic-gate int ret = DDI_SUCCESS;
20360Sstevel@tonic-gate
20370Sstevel@tonic-gate /*
20380Sstevel@tonic-gate * Create the sysio ino number. onboard devices will have
20390Sstevel@tonic-gate * an "interrupts" property, that is equal to the ino number.
20400Sstevel@tonic-gate * If the devices are from the
20410Sstevel@tonic-gate * expansion slots, we construct the ino number by putting
20420Sstevel@tonic-gate * the slot number in the upper three bits, and the sbus
20430Sstevel@tonic-gate * interrupt level in the lower three bits.
20440Sstevel@tonic-gate */
20450Sstevel@tonic-gate if (level > MAX_SBUS_LEVEL) {
20460Sstevel@tonic-gate ino = level;
20470Sstevel@tonic-gate } else {
20480Sstevel@tonic-gate /* Construct ino from slot and interrupts */
20490Sstevel@tonic-gate if ((slot = find_sbus_slot(dip, rdip)) == -1) {
20500Sstevel@tonic-gate cmn_err(CE_WARN, "Can't determine sbus slot "
2051693Sgovinda "of %s device\n", ddi_driver_name(rdip));
20520Sstevel@tonic-gate ret = DDI_FAILURE;
20530Sstevel@tonic-gate goto done;
20540Sstevel@tonic-gate }
20550Sstevel@tonic-gate
20560Sstevel@tonic-gate if (slot >= MAX_SBUS_SLOT_ADDR) {
20570Sstevel@tonic-gate cmn_err(CE_WARN, "Invalid sbus slot 0x%x"
2058693Sgovinda "in %s device\n", slot, ddi_driver_name(rdip));
20590Sstevel@tonic-gate ret = DDI_FAILURE;
20600Sstevel@tonic-gate goto done;
20610Sstevel@tonic-gate }
20620Sstevel@tonic-gate
20630Sstevel@tonic-gate ino = slot << 3;
20640Sstevel@tonic-gate ino |= level;
20650Sstevel@tonic-gate }
20660Sstevel@tonic-gate
20670Sstevel@tonic-gate /* Sanity check the inos range */
20680Sstevel@tonic-gate if (ino >= MAX_INO_TABLE_SIZE) {
20690Sstevel@tonic-gate cmn_err(CE_WARN, "Ino vector 0x%x out of range", ino);
20700Sstevel@tonic-gate ret = DDI_FAILURE;
20710Sstevel@tonic-gate goto done;
20720Sstevel@tonic-gate }
20730Sstevel@tonic-gate /* Sanity check the inos value */
20740Sstevel@tonic-gate if (!ino_table[ino]) {
20750Sstevel@tonic-gate cmn_err(CE_WARN, "Ino vector 0x%x is invalid", ino);
20760Sstevel@tonic-gate ret = DDI_FAILURE;
20770Sstevel@tonic-gate goto done;
20780Sstevel@tonic-gate }
20790Sstevel@tonic-gate
2080693Sgovinda if (*pil == 0) {
20810Sstevel@tonic-gate #define SOC_PRIORITY 5
20820Sstevel@tonic-gate /* The sunfire i/o board has a soc in the printer slot */
20830Sstevel@tonic-gate if ((ino_table[ino]->clear_reg == PP_CLEAR) &&
20840Sstevel@tonic-gate ((strcmp(ddi_get_name(rdip), "soc") == 0) ||
2085*7656SSherry.Moore@Sun.COM (strcmp(ddi_get_name(rdip), "SUNW,soc") == 0))) {
2086693Sgovinda *pil = SOC_PRIORITY;
20870Sstevel@tonic-gate } else {
20880Sstevel@tonic-gate /* Figure out the pil associated with this interrupt */
2089693Sgovinda *pil = interrupt_priorities[ino];
20900Sstevel@tonic-gate }
20910Sstevel@tonic-gate }
20920Sstevel@tonic-gate
20930Sstevel@tonic-gate /* Or in the upa_id into the interrupt group number field */
2094693Sgovinda *intr = (uint32_t)(ino | ign);
20950Sstevel@tonic-gate
20960Sstevel@tonic-gate DPRINTF(SBUS_INTERRUPT_DEBUG, ("Xlate intr: Interrupt info for "
20970Sstevel@tonic-gate "device %s Mondo: 0x%x, ino: 0x%x, Pil: 0x%x, sbus level: 0x%x\n",
2098693Sgovinda ddi_driver_name(rdip), *intr, ino, *pil, level));
20990Sstevel@tonic-gate
21000Sstevel@tonic-gate done:
21010Sstevel@tonic-gate return (ret);
21020Sstevel@tonic-gate }
21030Sstevel@tonic-gate
21040Sstevel@tonic-gate /* new intr_ops structure */
21050Sstevel@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)21060Sstevel@tonic-gate sbus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
21070Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result)
21080Sstevel@tonic-gate {
21090Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *)
21100Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip));
21110Sstevel@tonic-gate int ret = DDI_SUCCESS;
21120Sstevel@tonic-gate
21130Sstevel@tonic-gate
21140Sstevel@tonic-gate switch (intr_op) {
21150Sstevel@tonic-gate case DDI_INTROP_GETCAP:
2116693Sgovinda *(int *)result = DDI_INTR_FLAG_LEVEL;
21170Sstevel@tonic-gate break;
21180Sstevel@tonic-gate case DDI_INTROP_ALLOC:
21190Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1;
21200Sstevel@tonic-gate break;
21210Sstevel@tonic-gate case DDI_INTROP_FREE:
21220Sstevel@tonic-gate break;
21230Sstevel@tonic-gate case DDI_INTROP_GETPRI:
21243744Sgovinda if (hdlp->ih_pri == 0) {
21250Sstevel@tonic-gate /* Xlate the interrupt */
21260Sstevel@tonic-gate (void) sbus_xlate_intrs(dip, rdip,
2127693Sgovinda (uint32_t *)&hdlp->ih_vector, &hdlp->ih_pri,
2128693Sgovinda softsp->intr_mapping_ign);
21290Sstevel@tonic-gate }
21300Sstevel@tonic-gate
2131693Sgovinda *(int *)result = hdlp->ih_pri;
21320Sstevel@tonic-gate break;
21330Sstevel@tonic-gate case DDI_INTROP_SETPRI:
21340Sstevel@tonic-gate break;
21350Sstevel@tonic-gate case DDI_INTROP_ADDISR:
21360Sstevel@tonic-gate ret = sbus_add_intr_impl(dip, rdip, hdlp);
21370Sstevel@tonic-gate break;
21380Sstevel@tonic-gate case DDI_INTROP_REMISR:
21390Sstevel@tonic-gate sbus_remove_intr_impl(dip, rdip, hdlp);
21400Sstevel@tonic-gate break;
21410Sstevel@tonic-gate case DDI_INTROP_ENABLE:
21420Sstevel@tonic-gate ret = sbus_update_intr_state(dip, rdip, hdlp,
21430Sstevel@tonic-gate SBUS_INTR_STATE_ENABLE);
21440Sstevel@tonic-gate break;
21450Sstevel@tonic-gate case DDI_INTROP_DISABLE:
21460Sstevel@tonic-gate ret = sbus_update_intr_state(dip, rdip, hdlp,
21470Sstevel@tonic-gate SBUS_INTR_STATE_DISABLE);
21480Sstevel@tonic-gate break;
21490Sstevel@tonic-gate case DDI_INTROP_NINTRS:
21500Sstevel@tonic-gate case DDI_INTROP_NAVAIL:
21512580Sanish *(int *)result = i_ddi_get_intx_nintrs(rdip);
21520Sstevel@tonic-gate break;
21530Sstevel@tonic-gate case DDI_INTROP_SETCAP:
21540Sstevel@tonic-gate case DDI_INTROP_SETMASK:
21550Sstevel@tonic-gate case DDI_INTROP_CLRMASK:
21560Sstevel@tonic-gate case DDI_INTROP_GETPENDING:
21570Sstevel@tonic-gate ret = DDI_ENOTSUP;
21580Sstevel@tonic-gate break;
21590Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES:
21600Sstevel@tonic-gate /* Sbus nexus driver supports only fixed interrupts */
21612580Sanish *(int *)result = i_ddi_get_intx_nintrs(rdip) ?
21620Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0;
21630Sstevel@tonic-gate break;
21640Sstevel@tonic-gate default:
21650Sstevel@tonic-gate ret = i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result);
21660Sstevel@tonic-gate break;
21670Sstevel@tonic-gate }
21680Sstevel@tonic-gate
21690Sstevel@tonic-gate return (ret);
21700Sstevel@tonic-gate }
21710Sstevel@tonic-gate
21720Sstevel@tonic-gate
21730Sstevel@tonic-gate /*
21740Sstevel@tonic-gate * Called by suspend/resume to save/restore the interrupt status (valid bit)
21750Sstevel@tonic-gate * of the interrupt mapping registers.
21760Sstevel@tonic-gate */
21770Sstevel@tonic-gate static void
sbus_cpr_handle_intr_map_reg(uint64_t * cpr_softsp,volatile uint64_t * baddr,int save)21780Sstevel@tonic-gate sbus_cpr_handle_intr_map_reg(uint64_t *cpr_softsp, volatile uint64_t *baddr,
21790Sstevel@tonic-gate int save)
21800Sstevel@tonic-gate {
21810Sstevel@tonic-gate int i;
21820Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg;
21830Sstevel@tonic-gate
21840Sstevel@tonic-gate for (i = 0; i < MAX_INO_TABLE_SIZE; i++) {
21850Sstevel@tonic-gate if (ino_table[i] != NULL) {
21860Sstevel@tonic-gate mondo_vec_reg = baddr + ino_table[i]->mapping_reg;
21870Sstevel@tonic-gate if (save) {
21880Sstevel@tonic-gate if (*mondo_vec_reg & INTERRUPT_VALID) {
21890Sstevel@tonic-gate cpr_softsp[i] = *mondo_vec_reg;
21900Sstevel@tonic-gate }
21910Sstevel@tonic-gate } else {
21920Sstevel@tonic-gate if (cpr_softsp[i]) {
21930Sstevel@tonic-gate *mondo_vec_reg = cpr_softsp[i];
21940Sstevel@tonic-gate }
21950Sstevel@tonic-gate }
21960Sstevel@tonic-gate }
21970Sstevel@tonic-gate }
21980Sstevel@tonic-gate }
21990Sstevel@tonic-gate
22000Sstevel@tonic-gate #define SZ_INO_TABLE (sizeof (ino_table) / sizeof (ino_table[0]))
22010Sstevel@tonic-gate
22020Sstevel@tonic-gate /*
22030Sstevel@tonic-gate * sbus_intrdist
22040Sstevel@tonic-gate *
22050Sstevel@tonic-gate * This function retargets active interrupts by reprogramming the mondo
22060Sstevel@tonic-gate * vec register. If the CPU ID of the target has not changed, then
22070Sstevel@tonic-gate * the mondo is not reprogrammed. The routine must hold the mondo
22080Sstevel@tonic-gate * lock for this instance of the sbus.
22090Sstevel@tonic-gate */
22100Sstevel@tonic-gate static void
sbus_intrdist(void * arg)22110Sstevel@tonic-gate sbus_intrdist(void *arg)
22120Sstevel@tonic-gate {
22130Sstevel@tonic-gate struct sbus_soft_state *softsp;
22140Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg;
22150Sstevel@tonic-gate volatile uint64_t *mondo_vec_reg;
22160Sstevel@tonic-gate uint64_t *last_mondo_vec_reg;
22170Sstevel@tonic-gate uint64_t mondo_vec;
22180Sstevel@tonic-gate volatile uint64_t *intr_state_reg;
22190Sstevel@tonic-gate uint_t start_bit;
22200Sstevel@tonic-gate volatile uint64_t tmpreg; /* HW flush reg */
22210Sstevel@tonic-gate uint_t mondo;
22220Sstevel@tonic-gate uint_t cpu_id;
22230Sstevel@tonic-gate
22240Sstevel@tonic-gate /* extract the soft state pointer */
22250Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, ddi_get_instance(dip));
22260Sstevel@tonic-gate
22270Sstevel@tonic-gate last_mondo_vec_reg = NULL;
22280Sstevel@tonic-gate for (mondo = 0; mondo < SZ_INO_TABLE; mondo++) {
22290Sstevel@tonic-gate if (ino_table[mondo] == NULL)
22300Sstevel@tonic-gate continue;
22310Sstevel@tonic-gate
22320Sstevel@tonic-gate mondo_vec_reg = (softsp->intr_mapping_reg +
2233*7656SSherry.Moore@Sun.COM ino_table[mondo]->mapping_reg);
22340Sstevel@tonic-gate
22350Sstevel@tonic-gate /* Don't reprogram the same register twice */
22360Sstevel@tonic-gate if (mondo_vec_reg == last_mondo_vec_reg)
22370Sstevel@tonic-gate continue;
22380Sstevel@tonic-gate
22390Sstevel@tonic-gate if ((*mondo_vec_reg & INTERRUPT_VALID) == 0)
22400Sstevel@tonic-gate continue;
22410Sstevel@tonic-gate
22420Sstevel@tonic-gate last_mondo_vec_reg = (uint64_t *)mondo_vec_reg;
22430Sstevel@tonic-gate
22440Sstevel@tonic-gate cpu_id = intr_dist_cpuid();
22450Sstevel@tonic-gate #ifdef _STARFIRE
22460Sstevel@tonic-gate /*
22470Sstevel@tonic-gate * For Starfire it is a pain to check the current target for
22480Sstevel@tonic-gate * the mondo since we have to read the PC asics ITTR slot
22490Sstevel@tonic-gate * assigned to this mondo. It will be much easier to assume
22500Sstevel@tonic-gate * the current target is always different and do the target
22510Sstevel@tonic-gate * reprogram all the time.
22520Sstevel@tonic-gate */
22530Sstevel@tonic-gate #else
22540Sstevel@tonic-gate if (((*mondo_vec_reg & IMR_TID) >> IMR_TID_SHIFT) == cpu_id) {
22550Sstevel@tonic-gate /* It is the same, don't reprogram */
22560Sstevel@tonic-gate return;
22570Sstevel@tonic-gate }
22580Sstevel@tonic-gate #endif /* _STARFIRE */
22590Sstevel@tonic-gate
22600Sstevel@tonic-gate /* So it's OK to reprogram the CPU target */
22610Sstevel@tonic-gate
22620Sstevel@tonic-gate /* turn off valid bit and wait for the state machine to idle */
22630Sstevel@tonic-gate *mondo_vec_reg &= ~INTERRUPT_VALID;
22640Sstevel@tonic-gate
22650Sstevel@tonic-gate tmpreg = *softsp->sbus_ctrl_reg;
22660Sstevel@tonic-gate
22670Sstevel@tonic-gate #ifdef lint
22680Sstevel@tonic-gate tmpreg = tmpreg;
22690Sstevel@tonic-gate #endif /* lint */
22700Sstevel@tonic-gate
22710Sstevel@tonic-gate if (mondo > MAX_MONDO_EXTERNAL) {
22720Sstevel@tonic-gate start_bit = ino_table[mondo]->diagreg_shift;
22730Sstevel@tonic-gate intr_state_reg = softsp->obio_intr_state;
22740Sstevel@tonic-gate
22750Sstevel@tonic-gate /*
22760Sstevel@tonic-gate * Loop waiting for state machine to idle. Do not keep
22770Sstevel@tonic-gate * looping on a panic so that the system does not hang.
22780Sstevel@tonic-gate */
22790Sstevel@tonic-gate while ((((*intr_state_reg >> start_bit) & 0x3) ==
22800Sstevel@tonic-gate INT_PENDING) && !panicstr)
22810Sstevel@tonic-gate /* empty */;
22820Sstevel@tonic-gate } else {
22830Sstevel@tonic-gate int int_pending = 0; /* interrupts pending */
22840Sstevel@tonic-gate
22850Sstevel@tonic-gate /*
22860Sstevel@tonic-gate * Shift over to first bit for this Sbus slot, 16
22870Sstevel@tonic-gate * bits per slot, bits 0-1 of each slot are reserved.
22880Sstevel@tonic-gate */
22890Sstevel@tonic-gate start_bit = 16 * (mondo >> 3) + 2;
22900Sstevel@tonic-gate intr_state_reg = softsp->sbus_intr_state;
22910Sstevel@tonic-gate
22920Sstevel@tonic-gate /*
22930Sstevel@tonic-gate * Make sure interrupts for levels 1-7 of this slot
22940Sstevel@tonic-gate * are not pending.
22950Sstevel@tonic-gate */
22960Sstevel@tonic-gate do {
22970Sstevel@tonic-gate int level; /* Sbus interrupt level */
22980Sstevel@tonic-gate int shift; /* # of bits to shift */
22990Sstevel@tonic-gate uint64_t state_reg = *intr_state_reg;
23000Sstevel@tonic-gate
23010Sstevel@tonic-gate int_pending = 0;
23020Sstevel@tonic-gate
23030Sstevel@tonic-gate for (shift = start_bit, level = 1; level < 8;
23040Sstevel@tonic-gate level++, shift += 2) {
23050Sstevel@tonic-gate if (((state_reg >> shift) &
23060Sstevel@tonic-gate 0x3) == INT_PENDING) {
23070Sstevel@tonic-gate int_pending = 1;
23080Sstevel@tonic-gate break;
23090Sstevel@tonic-gate }
23100Sstevel@tonic-gate }
23110Sstevel@tonic-gate } while (int_pending && !panicstr);
23120Sstevel@tonic-gate }
23130Sstevel@tonic-gate
23140Sstevel@tonic-gate /* re-target the mondo and turn it on */
23150Sstevel@tonic-gate #ifdef _STARFIRE
23160Sstevel@tonic-gate mondo_vec = (pc_translate_tgtid(softsp->ittrans_cookie,
23170Sstevel@tonic-gate cpu_id, mondo_vec_reg) <<
23180Sstevel@tonic-gate INTERRUPT_CPU_FIELD) |
23190Sstevel@tonic-gate INTERRUPT_VALID;
23200Sstevel@tonic-gate #else
23210Sstevel@tonic-gate mondo_vec = (cpu_id << INTERRUPT_CPU_FIELD) | INTERRUPT_VALID;
23220Sstevel@tonic-gate #endif /* _STARFIRE */
23230Sstevel@tonic-gate
23240Sstevel@tonic-gate /* write it back to the hardware. */
23250Sstevel@tonic-gate *mondo_vec_reg = mondo_vec;
23260Sstevel@tonic-gate
23270Sstevel@tonic-gate /* flush the hardware buffers. */
23280Sstevel@tonic-gate tmpreg = *mondo_vec_reg;
23290Sstevel@tonic-gate
23300Sstevel@tonic-gate #ifdef lint
23310Sstevel@tonic-gate tmpreg = tmpreg;
23320Sstevel@tonic-gate #endif /* lint */
23330Sstevel@tonic-gate }
23340Sstevel@tonic-gate }
23350Sstevel@tonic-gate
23360Sstevel@tonic-gate /*
23370Sstevel@tonic-gate * Reset interrupts to IDLE. This function is called during
23380Sstevel@tonic-gate * panic handling after redistributing interrupts; it's needed to
23390Sstevel@tonic-gate * support dumping to network devices after 'sync' from OBP.
23400Sstevel@tonic-gate *
23410Sstevel@tonic-gate * N.B. This routine runs in a context where all other threads
23420Sstevel@tonic-gate * are permanently suspended.
23430Sstevel@tonic-gate */
23440Sstevel@tonic-gate static uint_t
sbus_intr_reset(void * arg)23450Sstevel@tonic-gate sbus_intr_reset(void *arg)
23460Sstevel@tonic-gate {
23470Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg;
23480Sstevel@tonic-gate struct sbus_soft_state *softsp;
23490Sstevel@tonic-gate uint_t mondo;
23500Sstevel@tonic-gate volatile uint64_t *mondo_clear_reg;
23510Sstevel@tonic-gate
23520Sstevel@tonic-gate softsp = ddi_get_soft_state(sbusp, ddi_get_instance(dip));
23530Sstevel@tonic-gate
23540Sstevel@tonic-gate for (mondo = 0; mondo < SZ_INO_TABLE; mondo++) {
23550Sstevel@tonic-gate if (ino_table[mondo] == NULL ||
2356*7656SSherry.Moore@Sun.COM ino_table[mondo]->clear_reg == NULL) {
23570Sstevel@tonic-gate
23580Sstevel@tonic-gate continue;
23590Sstevel@tonic-gate }
23600Sstevel@tonic-gate
23610Sstevel@tonic-gate mondo_clear_reg = (softsp->clr_intr_reg +
23620Sstevel@tonic-gate ino_table[mondo]->clear_reg);
23630Sstevel@tonic-gate *mondo_clear_reg = SBUS_INTR_IDLE;
23640Sstevel@tonic-gate }
23650Sstevel@tonic-gate
23660Sstevel@tonic-gate return (BF_NONE);
23670Sstevel@tonic-gate }
23680Sstevel@tonic-gate
23690Sstevel@tonic-gate /*
23700Sstevel@tonic-gate * called from sbus_add_kstats() to create a kstat for each %pic
23710Sstevel@tonic-gate * that the SBUS supports. These (read-only) kstats export the
23720Sstevel@tonic-gate * event names that each %pic supports.
23730Sstevel@tonic-gate *
23740Sstevel@tonic-gate * if we fail to create any of these kstats we must remove any
23750Sstevel@tonic-gate * that we have already created and return;
23760Sstevel@tonic-gate *
23770Sstevel@tonic-gate * NOTE: because all sbus devices use the same events we only
23780Sstevel@tonic-gate * need to create the picN kstats once. All instances can
23790Sstevel@tonic-gate * use the same picN kstats.
23800Sstevel@tonic-gate *
23810Sstevel@tonic-gate * The flexibility exists to allow each device specify it's
23820Sstevel@tonic-gate * own events by creating picN kstats with the instance number
23830Sstevel@tonic-gate * set to ddi_get_instance(softsp->dip).
23840Sstevel@tonic-gate *
23850Sstevel@tonic-gate * When searching for a picN kstat for a device you should
23860Sstevel@tonic-gate * first search for a picN kstat using the instance number
23870Sstevel@tonic-gate * of the device you are interested in. If that fails you
23880Sstevel@tonic-gate * should use the first picN kstat found for that device.
23890Sstevel@tonic-gate */
23900Sstevel@tonic-gate static void
sbus_add_picN_kstats(dev_info_t * dip)23910Sstevel@tonic-gate sbus_add_picN_kstats(dev_info_t *dip)
23920Sstevel@tonic-gate {
23930Sstevel@tonic-gate /*
23940Sstevel@tonic-gate * SBUS Performance Events.
23950Sstevel@tonic-gate *
23960Sstevel@tonic-gate * We declare an array of event-names and event-masks.
23970Sstevel@tonic-gate * The num of events in this array is AC_NUM_EVENTS.
23980Sstevel@tonic-gate */
23990Sstevel@tonic-gate sbus_event_mask_t sbus_events_arr[SBUS_NUM_EVENTS] = {
24000Sstevel@tonic-gate {"dvma_stream_rd", 0x0}, {"dvma_stream_wr", 0x1},
24010Sstevel@tonic-gate {"dvma_const_rd", 0x2}, {"dvma_const_wr", 0x3},
24020Sstevel@tonic-gate {"dvma_tlb_misses", 0x4}, {"dvma_stream_buf_mis", 0x5},
24030Sstevel@tonic-gate {"dvma_cycles", 0x6}, {"dvma_bytes_xfr", 0x7},
24040Sstevel@tonic-gate {"interrupts", 0x8}, {"upa_inter_nack", 0x9},
24050Sstevel@tonic-gate {"pio_reads", 0xA}, {"pio_writes", 0xB},
24060Sstevel@tonic-gate {"sbus_reruns", 0xC}, {"pio_cycles", 0xD}
24070Sstevel@tonic-gate };
24080Sstevel@tonic-gate
24090Sstevel@tonic-gate /*
24100Sstevel@tonic-gate * We declare an array of clear masks for each pic.
24110Sstevel@tonic-gate * These masks are used to clear the %pcr bits for
24120Sstevel@tonic-gate * each pic.
24130Sstevel@tonic-gate */
24140Sstevel@tonic-gate sbus_event_mask_t sbus_clear_pic[SBUS_NUM_PICS] = {
24150Sstevel@tonic-gate /* pic0 */
24160Sstevel@tonic-gate {"clear_pic", (uint64_t)~(0xf)},
24170Sstevel@tonic-gate /* pic1 */
24180Sstevel@tonic-gate {"clear_pic", (uint64_t)~(0xf << 8)}
24190Sstevel@tonic-gate };
24200Sstevel@tonic-gate
24210Sstevel@tonic-gate struct kstat_named *sbus_pic_named_data;
24220Sstevel@tonic-gate int event, pic;
24230Sstevel@tonic-gate char pic_name[30];
24240Sstevel@tonic-gate int instance = ddi_get_instance(dip);
24250Sstevel@tonic-gate int pic_shift = 0;
24260Sstevel@tonic-gate
24270Sstevel@tonic-gate for (pic = 0; pic < SBUS_NUM_PICS; pic++) {
24280Sstevel@tonic-gate /*
24290Sstevel@tonic-gate * create the picN kstat. The size of this kstat is
24300Sstevel@tonic-gate * SBUS_NUM_EVENTS + 1 for the clear_event_mask
24310Sstevel@tonic-gate */
24320Sstevel@tonic-gate (void) sprintf(pic_name, "pic%d", pic); /* pic0, pic1 ... */
24330Sstevel@tonic-gate if ((sbus_picN_ksp[pic] = kstat_create("sbus",
2434*7656SSherry.Moore@Sun.COM instance, pic_name, "bus", KSTAT_TYPE_NAMED,
2435*7656SSherry.Moore@Sun.COM SBUS_NUM_EVENTS + 1, NULL)) == NULL) {
24360Sstevel@tonic-gate cmn_err(CE_WARN, "sbus %s: kstat_create failed",
2437*7656SSherry.Moore@Sun.COM pic_name);
24380Sstevel@tonic-gate
24390Sstevel@tonic-gate /* remove pic0 kstat if pic1 create fails */
24400Sstevel@tonic-gate if (pic == 1) {
24410Sstevel@tonic-gate kstat_delete(sbus_picN_ksp[0]);
24420Sstevel@tonic-gate sbus_picN_ksp[0] = NULL;
24430Sstevel@tonic-gate }
24440Sstevel@tonic-gate return;
24450Sstevel@tonic-gate }
24460Sstevel@tonic-gate
24470Sstevel@tonic-gate sbus_pic_named_data =
2448*7656SSherry.Moore@Sun.COM (struct kstat_named *)(sbus_picN_ksp[pic]->ks_data);
24490Sstevel@tonic-gate
24500Sstevel@tonic-gate /*
24510Sstevel@tonic-gate * when we are writing pcr_masks to the kstat we need to
24520Sstevel@tonic-gate * shift bits left by 8 for pic1 events.
24530Sstevel@tonic-gate */
24540Sstevel@tonic-gate if (pic == 1)
24550Sstevel@tonic-gate pic_shift = 8;
24560Sstevel@tonic-gate
24570Sstevel@tonic-gate /*
24580Sstevel@tonic-gate * for each picN event we need to write a kstat record
24590Sstevel@tonic-gate * (name = EVENT, value.ui64 = PCR_MASK)
24600Sstevel@tonic-gate */
24610Sstevel@tonic-gate for (event = 0; event < SBUS_NUM_EVENTS; event ++) {
24620Sstevel@tonic-gate
24630Sstevel@tonic-gate /* pcr_mask */
24640Sstevel@tonic-gate sbus_pic_named_data[event].value.ui64 =
2465*7656SSherry.Moore@Sun.COM sbus_events_arr[event].pcr_mask << pic_shift;
24660Sstevel@tonic-gate
24670Sstevel@tonic-gate /* event-name */
24680Sstevel@tonic-gate kstat_named_init(&sbus_pic_named_data[event],
2469*7656SSherry.Moore@Sun.COM sbus_events_arr[event].event_name,
2470*7656SSherry.Moore@Sun.COM KSTAT_DATA_UINT64);
24710Sstevel@tonic-gate }
24720Sstevel@tonic-gate
24730Sstevel@tonic-gate /*
24740Sstevel@tonic-gate * we add the clear_pic event and mask as the last
24750Sstevel@tonic-gate * record in the kstat
24760Sstevel@tonic-gate */
24770Sstevel@tonic-gate /* pcr mask */
24780Sstevel@tonic-gate sbus_pic_named_data[SBUS_NUM_EVENTS].value.ui64 =
2479*7656SSherry.Moore@Sun.COM sbus_clear_pic[pic].pcr_mask;
24800Sstevel@tonic-gate
24810Sstevel@tonic-gate /* event-name */
24820Sstevel@tonic-gate kstat_named_init(&sbus_pic_named_data[SBUS_NUM_EVENTS],
2483*7656SSherry.Moore@Sun.COM sbus_clear_pic[pic].event_name,
2484*7656SSherry.Moore@Sun.COM KSTAT_DATA_UINT64);
24850Sstevel@tonic-gate
24860Sstevel@tonic-gate kstat_install(sbus_picN_ksp[pic]);
24870Sstevel@tonic-gate }
24880Sstevel@tonic-gate }
24890Sstevel@tonic-gate
24900Sstevel@tonic-gate static void
sbus_add_kstats(struct sbus_soft_state * softsp)24910Sstevel@tonic-gate sbus_add_kstats(struct sbus_soft_state *softsp)
24920Sstevel@tonic-gate {
24930Sstevel@tonic-gate struct kstat *sbus_counters_ksp;
24940Sstevel@tonic-gate struct kstat_named *sbus_counters_named_data;
24950Sstevel@tonic-gate
24960Sstevel@tonic-gate /*
24970Sstevel@tonic-gate * Create the picN kstats if we are the first instance
24980Sstevel@tonic-gate * to attach. We use sbus_attachcnt as a count of how
24990Sstevel@tonic-gate * many instances have attached. This is protected by
25000Sstevel@tonic-gate * a mutex.
25010Sstevel@tonic-gate */
25020Sstevel@tonic-gate mutex_enter(&sbus_attachcnt_mutex);
25030Sstevel@tonic-gate if (sbus_attachcnt == 0)
25040Sstevel@tonic-gate sbus_add_picN_kstats(softsp->dip);
25050Sstevel@tonic-gate
25060Sstevel@tonic-gate sbus_attachcnt ++;
25070Sstevel@tonic-gate mutex_exit(&sbus_attachcnt_mutex);
25080Sstevel@tonic-gate
25090Sstevel@tonic-gate /*
25100Sstevel@tonic-gate * A "counter" kstat is created for each sbus
25110Sstevel@tonic-gate * instance that provides access to the %pcr and %pic
25120Sstevel@tonic-gate * registers for that instance.
25130Sstevel@tonic-gate *
25140Sstevel@tonic-gate * The size of this kstat is SBUS_NUM_PICS + 1 for %pcr
25150Sstevel@tonic-gate */
25160Sstevel@tonic-gate if ((sbus_counters_ksp = kstat_create("sbus",
2517*7656SSherry.Moore@Sun.COM ddi_get_instance(softsp->dip), "counters",
2518*7656SSherry.Moore@Sun.COM "bus", KSTAT_TYPE_NAMED, SBUS_NUM_PICS + 1,
2519*7656SSherry.Moore@Sun.COM KSTAT_FLAG_WRITABLE)) == NULL) {
25200Sstevel@tonic-gate
25210Sstevel@tonic-gate cmn_err(CE_WARN, "sbus%d counters: kstat_create"
2522*7656SSherry.Moore@Sun.COM " failed", ddi_get_instance(softsp->dip));
25230Sstevel@tonic-gate return;
25240Sstevel@tonic-gate }
25250Sstevel@tonic-gate
25260Sstevel@tonic-gate sbus_counters_named_data =
2527*7656SSherry.Moore@Sun.COM (struct kstat_named *)(sbus_counters_ksp->ks_data);
25280Sstevel@tonic-gate
25290Sstevel@tonic-gate /* initialize the named kstats */
25300Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[0],
2531*7656SSherry.Moore@Sun.COM "pcr", KSTAT_DATA_UINT64);
25320Sstevel@tonic-gate
25330Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[1],
2534*7656SSherry.Moore@Sun.COM "pic0", KSTAT_DATA_UINT64);
25350Sstevel@tonic-gate
25360Sstevel@tonic-gate kstat_named_init(&sbus_counters_named_data[2],
2537*7656SSherry.Moore@Sun.COM "pic1", KSTAT_DATA_UINT64);
25380Sstevel@tonic-gate
25390Sstevel@tonic-gate sbus_counters_ksp->ks_update = sbus_counters_kstat_update;
25400Sstevel@tonic-gate sbus_counters_ksp->ks_private = (void *)softsp;
25410Sstevel@tonic-gate
25420Sstevel@tonic-gate kstat_install(sbus_counters_ksp);
25430Sstevel@tonic-gate
25440Sstevel@tonic-gate /* update the sofstate */
25450Sstevel@tonic-gate softsp->sbus_counters_ksp = sbus_counters_ksp;
25460Sstevel@tonic-gate }
25470Sstevel@tonic-gate
25480Sstevel@tonic-gate static int
sbus_counters_kstat_update(kstat_t * ksp,int rw)25490Sstevel@tonic-gate sbus_counters_kstat_update(kstat_t *ksp, int rw)
25500Sstevel@tonic-gate {
25510Sstevel@tonic-gate struct kstat_named *sbus_counters_data;
25520Sstevel@tonic-gate struct sbus_soft_state *softsp;
25530Sstevel@tonic-gate uint64_t pic_register;
25540Sstevel@tonic-gate
25550Sstevel@tonic-gate sbus_counters_data = (struct kstat_named *)ksp->ks_data;
25560Sstevel@tonic-gate softsp = (struct sbus_soft_state *)ksp->ks_private;
25570Sstevel@tonic-gate
25580Sstevel@tonic-gate if (rw == KSTAT_WRITE) {
25590Sstevel@tonic-gate
25600Sstevel@tonic-gate /*
25610Sstevel@tonic-gate * Write the pcr value to the softsp->sbus_pcr.
25620Sstevel@tonic-gate * The pic register is read-only so we don't
25630Sstevel@tonic-gate * attempt to write to it.
25640Sstevel@tonic-gate */
25650Sstevel@tonic-gate
25660Sstevel@tonic-gate *softsp->sbus_pcr =
2567*7656SSherry.Moore@Sun.COM (uint32_t)sbus_counters_data[0].value.ui64;
25680Sstevel@tonic-gate
25690Sstevel@tonic-gate } else {
25700Sstevel@tonic-gate /*
25710Sstevel@tonic-gate * Read %pcr and %pic register values and write them
25720Sstevel@tonic-gate * into counters kstat.
25730Sstevel@tonic-gate *
25740Sstevel@tonic-gate * Due to a hardware bug we need to right shift the %pcr
25750Sstevel@tonic-gate * by 4 bits. This is only done when reading the %pcr.
25760Sstevel@tonic-gate *
25770Sstevel@tonic-gate */
25780Sstevel@tonic-gate /* pcr */
25790Sstevel@tonic-gate sbus_counters_data[0].value.ui64 = *softsp->sbus_pcr >> 4;
25800Sstevel@tonic-gate
25810Sstevel@tonic-gate pic_register = *softsp->sbus_pic;
25820Sstevel@tonic-gate /*
25830Sstevel@tonic-gate * sbus pic register:
25840Sstevel@tonic-gate * (63:32) = pic0
25850Sstevel@tonic-gate * (31:00) = pic1
25860Sstevel@tonic-gate */
25870Sstevel@tonic-gate
25880Sstevel@tonic-gate /* pic0 */
25890Sstevel@tonic-gate sbus_counters_data[1].value.ui64 = pic_register >> 32;
25900Sstevel@tonic-gate /* pic1 */
25910Sstevel@tonic-gate sbus_counters_data[2].value.ui64 =
2592*7656SSherry.Moore@Sun.COM pic_register & SBUS_PIC0_MASK;
25930Sstevel@tonic-gate
25940Sstevel@tonic-gate }
25950Sstevel@tonic-gate return (0);
25960Sstevel@tonic-gate }
25970Sstevel@tonic-gate
25980Sstevel@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)25990Sstevel@tonic-gate sbus_update_intr_state(dev_info_t *dip, dev_info_t *rdip,
26000Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state)
26010Sstevel@tonic-gate {
26020Sstevel@tonic-gate struct sbus_soft_state *softsp = (struct sbus_soft_state *)
26030Sstevel@tonic-gate ddi_get_soft_state(sbusp, ddi_get_instance(dip));
26040Sstevel@tonic-gate int ino;
26050Sstevel@tonic-gate struct sbus_wrapper_arg *sbus_arg;
26060Sstevel@tonic-gate struct sbus_intr_handler *intr_handler;
26070Sstevel@tonic-gate
26080Sstevel@tonic-gate /* Xlate the interrupt */
2609693Sgovinda if (sbus_xlate_intrs(dip, rdip, (uint32_t *)&hdlp->ih_vector,
2610693Sgovinda &hdlp->ih_pri, softsp->intr_mapping_ign) == DDI_FAILURE) {
26110Sstevel@tonic-gate cmn_err(CE_WARN, "sbus_update_intr_state() can't xlate SBUS "
2612693Sgovinda "devices %s interrupt.", ddi_driver_name(rdip));
26130Sstevel@tonic-gate return (DDI_FAILURE);
26140Sstevel@tonic-gate }
26150Sstevel@tonic-gate
2616693Sgovinda ino = ((int32_t)hdlp->ih_vector) & SBUS_MAX_INO;
26170Sstevel@tonic-gate sbus_arg = softsp->intr_list[ino];
26180Sstevel@tonic-gate
26190Sstevel@tonic-gate ASSERT(sbus_arg != NULL);
26200Sstevel@tonic-gate ASSERT(sbus_arg->handler_list != NULL);
26210Sstevel@tonic-gate intr_handler = sbus_arg->handler_list;
26220Sstevel@tonic-gate
26230Sstevel@tonic-gate while (intr_handler) {
26240Sstevel@tonic-gate if ((intr_handler->inum == hdlp->ih_inum) &&
26250Sstevel@tonic-gate (intr_handler->dip == rdip)) {
26260Sstevel@tonic-gate intr_handler->intr_state = new_intr_state;
26270Sstevel@tonic-gate return (DDI_SUCCESS);
26280Sstevel@tonic-gate }
26290Sstevel@tonic-gate
26300Sstevel@tonic-gate intr_handler = intr_handler->next;
26310Sstevel@tonic-gate }
26320Sstevel@tonic-gate
26330Sstevel@tonic-gate return (DDI_FAILURE);
26340Sstevel@tonic-gate }
2635