xref: /onnv-gate/usr/src/uts/sun4u/sys/pci/pci_ib.h (revision 946:5fb89afc576e)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_PCI_IB_H
280Sstevel@tonic-gate #define	_SYS_PCI_IB_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
37117Sschwartz #include <sys/pci_tools.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate typedef uint8_t ib_ino_t;
400Sstevel@tonic-gate typedef uint16_t ib_mondo_t;
410Sstevel@tonic-gate typedef struct ib_ino_info ib_ino_info_t;
420Sstevel@tonic-gate typedef uint8_t device_num_t;
430Sstevel@tonic-gate typedef uint8_t interrupt_t;
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * interrupt block soft state structure:
470Sstevel@tonic-gate  *
480Sstevel@tonic-gate  * Each pci node may share an interrupt block structure with its peer
490Sstevel@tonic-gate  * node or have its own private interrupt block structure.
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate typedef struct ib ib_t;
520Sstevel@tonic-gate struct ib {
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	pci_t *ib_pci_p;	/* link back to pci soft state */
550Sstevel@tonic-gate 	pci_ign_t ib_ign;	/* interrupt group # */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	/*
580Sstevel@tonic-gate 	 * PCI slot and onboard I/O interrupt mapping register blocks addresses:
590Sstevel@tonic-gate 	 */
600Sstevel@tonic-gate 	uintptr_t ib_slot_intr_map_regs;
610Sstevel@tonic-gate #define	ib_intr_map_regs	ib_slot_intr_map_regs
620Sstevel@tonic-gate 	uintptr_t ib_obio_intr_map_regs;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	/*
650Sstevel@tonic-gate 	 * PCI slot and onboard I/O clear interrupt register block addresses:
660Sstevel@tonic-gate 	 */
670Sstevel@tonic-gate 	uintptr_t ib_slot_clear_intr_regs;
680Sstevel@tonic-gate 	uintptr_t ib_obio_clear_intr_regs;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/*
710Sstevel@tonic-gate 	 * UPA expansion slot interrupt mapping register addresses:
720Sstevel@tonic-gate 	 */
730Sstevel@tonic-gate 	volatile uint64_t *ib_upa_imr[2];
740Sstevel@tonic-gate 	uint64_t ib_upa_imr_state[2];
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	/*
770Sstevel@tonic-gate 	 * Interrupt retry register address:
780Sstevel@tonic-gate 	 */
790Sstevel@tonic-gate 	volatile uint64_t *ib_intr_retry_timer_reg;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	/*
820Sstevel@tonic-gate 	 * PCI slot and onboard I/O interrupt state diag register addresses:
830Sstevel@tonic-gate 	 */
840Sstevel@tonic-gate 	volatile uint64_t *ib_slot_intr_state_diag_reg;
850Sstevel@tonic-gate 	volatile uint64_t *ib_obio_intr_state_diag_reg;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	uint_t ib_max_ino;			/* largest supported INO */
880Sstevel@tonic-gate 	ib_ino_info_t *ib_ino_lst;		/* ino link list */
890Sstevel@tonic-gate 	kmutex_t ib_ino_lst_mutex;		/* mutex for ino link list */
900Sstevel@tonic-gate 	kmutex_t ib_intr_lock;			/* lock for internal intr  */
910Sstevel@tonic-gate 	uint16_t ib_map_reg_counters[8];	/* counters for shared map */
920Sstevel@tonic-gate 						/* registers */
930Sstevel@tonic-gate };
940Sstevel@tonic-gate 
950Sstevel@tonic-gate #define	PCI_PULSE_INO	0x80000000
960Sstevel@tonic-gate #define	PSYCHO_MAX_INO	0x3f
970Sstevel@tonic-gate #define	SCHIZO_MAX_INO	0x37
980Sstevel@tonic-gate #define	PCI_INO_BITS	6			/* INO#s are 6 bits long */
990Sstevel@tonic-gate #define	PCI_IGN_BITS	5			/* IGN#s are 5 bits long */
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * The following structure represents an interrupt entry for an INO.
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate typedef struct ih {
1050Sstevel@tonic-gate 	dev_info_t *ih_dip;		/* devinfo structure */
1060Sstevel@tonic-gate 	uint32_t ih_inum;		/* interrupt number for this device */
1070Sstevel@tonic-gate 	uint_t	ih_intr_state;		/* Only used for fixed interrupts */
1080Sstevel@tonic-gate 	uint_t (*ih_handler)();		/* interrupt handler */
1090Sstevel@tonic-gate 	caddr_t ih_handler_arg1;	/* interrupt handler argument #1 */
1100Sstevel@tonic-gate 	caddr_t ih_handler_arg2;	/* interrupt handler argument #2 */
1110Sstevel@tonic-gate 	ddi_acc_handle_t ih_config_handle; /* config space reg map handle */
1120Sstevel@tonic-gate 	struct ih *ih_next;		/* next entry in list */
1130Sstevel@tonic-gate 	uint64_t ih_ticks;		/* ticks spent in this handler */
1140Sstevel@tonic-gate 	uint64_t ih_nsec;		/* nsec spent in this handler */
1150Sstevel@tonic-gate 	kstat_t *ih_ksp;
1160Sstevel@tonic-gate 	struct ib_ino_info *ih_ino_p;	/* only for use by kstat */
1170Sstevel@tonic-gate } ih_t;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /* Only used for fixed or legacy interrupts */
1200Sstevel@tonic-gate #define	PCI_INTR_STATE_DISABLE	0	/* disabled */
1210Sstevel@tonic-gate #define	PCI_INTR_STATE_ENABLE	1	/* enabled */
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * ino structure : one per each psycho slot ino with interrupt registered
1250Sstevel@tonic-gate  */
1260Sstevel@tonic-gate struct ib_ino_info {
1270Sstevel@tonic-gate 	ib_ino_t ino_ino;		/* INO number - 8 bit */
1280Sstevel@tonic-gate 	uint8_t ino_slot_no;		/* PCI slot number 0-8 */
1290Sstevel@tonic-gate 	uint16_t ino_ih_size;		/* size of the pci intrspec list */
1300Sstevel@tonic-gate 	struct ib_ino_info *ino_next;
1310Sstevel@tonic-gate 	ih_t *ino_ih_head;		/* intr spec (part of ppd) list head */
1320Sstevel@tonic-gate 	ih_t *ino_ih_tail;		/* intr spec (part of ppd) list tail */
1330Sstevel@tonic-gate 	ih_t *ino_ih_start;		/* starting point in intr spec list  */
1340Sstevel@tonic-gate 	ib_t *ino_ib_p;			/* link back to interrupt block state */
1350Sstevel@tonic-gate 	volatile uint64_t *ino_clr_reg;	/* ino interrupt clear register */
1360Sstevel@tonic-gate 	volatile uint64_t *ino_map_reg;	/* ino interrupt mapping register */
1370Sstevel@tonic-gate 	uint64_t ino_map_reg_save;	/* = *ino_map_reg if saved */
1380Sstevel@tonic-gate 	uint32_t ino_pil;		/* PIL for this ino */
1390Sstevel@tonic-gate 	volatile uint_t ino_unclaimed;	/* number of unclaimed interrupts */
1400Sstevel@tonic-gate 	clock_t ino_spurintr_begin;	/* begin time of spurious intr series */
1410Sstevel@tonic-gate 	int ino_established;		/* ino has been associated with a cpu */
1420Sstevel@tonic-gate 	uint32_t ino_cpuid;		/* cpu that ino is targeting */
1430Sstevel@tonic-gate 	int32_t ino_intr_weight;	/* intr weight of devices sharing ino */
144909Segillett 	uint64_t ino_mondo;		/* store mondo number */
1450Sstevel@tonic-gate };
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #define	IB_INTR_WAIT	1		/* wait for interrupt completion */
1480Sstevel@tonic-gate #define	IB_INTR_NOWAIT	0		/* already handling intr, no wait */
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate #define	IB2CB(ib_p)	((ib_p)->ib_pci_p->pci_cb_p)
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	IB_MONDO_TO_INO(mondo)		((ib_ino_t)((mondo) & 0x3f))
1530Sstevel@tonic-gate #define	IB_INO_INTR_ON(reg_p)		*(reg_p) |= COMMON_INTR_MAP_REG_VALID
1540Sstevel@tonic-gate #define	IB_INO_INTR_OFF(reg_p)		*(reg_p) &= ~COMMON_INTR_MAP_REG_VALID
1550Sstevel@tonic-gate #define	IB_INO_INTR_RESET(reg_p)	*(reg_p) = 0ull
1560Sstevel@tonic-gate #define	IB_INO_INTR_STATE_REG(ib_p, ino) ((ino) & 0x20 ? \
1570Sstevel@tonic-gate 	ib_p->ib_obio_intr_state_diag_reg : ib_p->ib_slot_intr_state_diag_reg)
1580Sstevel@tonic-gate #define	IB_INO_INTR_PENDING(reg_p, ino) \
1590Sstevel@tonic-gate 	(((*(reg_p) >> (((ino) & 0x1f) << 1)) & COMMON_CLEAR_INTR_REG_MASK) == \
1600Sstevel@tonic-gate 	COMMON_CLEAR_INTR_REG_PENDING)
1610Sstevel@tonic-gate #define	IB_INO_INTR_CLEAR(reg_p)	*(reg_p) = COMMON_CLEAR_INTR_REG_IDLE
1620Sstevel@tonic-gate #define	IB_INO_INTR_TRIG(reg_p)	*(reg_p) = COMMON_CLEAR_INTR_REG_RECEIVED
1630Sstevel@tonic-gate #define	IB_INO_INTR_PEND(reg_p)		*(reg_p) = COMMON_CLEAR_INTR_REG_PENDING
1640Sstevel@tonic-gate #define	IB_INO_INTR_ISON(imr)		((imr) >> 31)
1650Sstevel@tonic-gate #define	IB_IMR2MONDO(imr) \
1660Sstevel@tonic-gate 	((imr) & (COMMON_INTR_MAP_REG_IGN | COMMON_INTR_MAP_REG_INO))
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	IB_IS_OBIO_INO(ino) (ino & 0x20)
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate #ifdef _STARFIRE
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * returns a uniq ino per interrupt mapping register
1730Sstevel@tonic-gate  * For on board devices, inos are not shared. But for plugin devices,
1740Sstevel@tonic-gate  * return the 1st ino of the 4 that are sharing the same mapping register.
1750Sstevel@tonic-gate  */
1760Sstevel@tonic-gate #define	IB_GET_MAPREG_INO(ino)	\
177*946Smathue 	((volatile uint64_t *)(uintptr_t)((ino & 0x20) ? \
178*946Smathue 	    ino : ((ino >> 2) << 2)))
1790Sstevel@tonic-gate #endif /* _STARFIRE */
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #define	IB_IGN_TO_MONDO(ign, ino)	(((ign) << PCI_INO_BITS) | (ino))
1820Sstevel@tonic-gate #define	IB_INO_TO_MONDO(ib_p, ino)	IB_IGN_TO_MONDO((ib_p)->ib_ign, ino)
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate extern void ib_create(pci_t *pci_p);
1850Sstevel@tonic-gate extern void ib_destroy(pci_t *pci_p);
1860Sstevel@tonic-gate extern void ib_configure(ib_t *ib_p);
1870Sstevel@tonic-gate extern uint64_t ib_get_map_reg(ib_mondo_t mondo, uint32_t cpu_id);
1880Sstevel@tonic-gate extern void ib_intr_enable(pci_t *pci_p, ib_ino_t ino);
1890Sstevel@tonic-gate extern void ib_intr_disable(ib_t *ib_p, ib_ino_t ino, int wait);
1900Sstevel@tonic-gate extern void ib_nintr_clear(ib_t *ib_p, ib_ino_t ino);
1910Sstevel@tonic-gate extern void ib_suspend(ib_t *ib_p);
1920Sstevel@tonic-gate extern void ib_resume(ib_t *ib_p);
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate extern ib_ino_info_t *ib_locate_ino(ib_t *ib_p, ib_ino_t ino_num);
1950Sstevel@tonic-gate extern ib_ino_info_t *ib_new_ino(ib_t *ib_p, ib_ino_t ino_num, ih_t *ih_p);
1960Sstevel@tonic-gate extern void ib_delete_ino(ib_t *ib_p, ib_ino_info_t *ino_p);
1970Sstevel@tonic-gate extern void ib_free_ino_all(ib_t *ib_p);
1980Sstevel@tonic-gate extern int ib_update_intr_state(pci_t *pci_p, dev_info_t *rdip,
1990Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state);
2000Sstevel@tonic-gate extern void ib_ino_add_intr(pci_t *pci_p, ib_ino_info_t *ino_p, ih_t *ih_p);
2010Sstevel@tonic-gate extern void ib_ino_rem_intr(pci_t *pci_p, ib_ino_info_t *ino_p, ih_t *ih_p);
2020Sstevel@tonic-gate extern ih_t *ib_ino_locate_intr(ib_ino_info_t *ino_p, dev_info_t *dip,
2030Sstevel@tonic-gate     uint32_t inum);
2040Sstevel@tonic-gate extern ih_t *ib_alloc_ih(dev_info_t *dip, uint32_t inum,
2050Sstevel@tonic-gate     uint_t (*int_handler)(caddr_t int_handler_arg1, caddr_t int_handler_arg2),
2060Sstevel@tonic-gate     caddr_t int_handler_arg1, caddr_t int_handler_arg2);
2070Sstevel@tonic-gate extern void ib_free_ih(ih_t *ih_p);
2080Sstevel@tonic-gate extern void ib_ino_map_reg_share(ib_t *ib_p, ib_ino_t ino,
2090Sstevel@tonic-gate 	ib_ino_info_t *ino_p);
2100Sstevel@tonic-gate extern int ib_ino_map_reg_unshare(ib_t *ib_p, ib_ino_t ino,
2110Sstevel@tonic-gate 	ib_ino_info_t *ino_p);
2120Sstevel@tonic-gate extern uint32_t ib_register_intr(ib_t *ib_p, ib_mondo_t mondo, uint_t pil,
2130Sstevel@tonic-gate 	uint_t (*handler)(caddr_t arg), caddr_t arg);
2140Sstevel@tonic-gate extern void ib_unregister_intr(ib_mondo_t mondo);
2150Sstevel@tonic-gate extern void ib_intr_dist_nintr(ib_t *ib_p, ib_ino_t ino,
2160Sstevel@tonic-gate 	volatile uint64_t *imr_p);
2170Sstevel@tonic-gate extern void ib_intr_dist_all(void *arg, int32_t max_weight, int32_t weight);
218117Sschwartz extern void ib_cpu_ticks_to_ih_nsec(ib_t *ib_p, ih_t *ih_p, uint32_t cpu_id);
219117Sschwartz extern uint8_t ib_get_ino_devs(ib_t *ib_p, uint32_t ino, uint8_t *devs_ret,
220117Sschwartz 	pcitool_intr_dev_t *devs);
221117Sschwartz extern void ib_log_new_cpu(ib_t *ib_p, uint32_t old_cpu_id, uint32_t new_cpu_id,
222117Sschwartz 	uint32_t ino);
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate extern int pci_pil[];
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate #ifdef	__cplusplus
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate #endif
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate #endif	/* _SYS_PCI_IB_H */
231