xref: /illumos-gate/usr/src/uts/sun4u/sys/pci/pci_ib.h (revision 2a1fd0ff)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b0fc0e77Sgovinda  * Common Development and Distribution License (the "License").
6b0fc0e77Sgovinda  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2209b1eac2SEvan Yan  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25*2a1fd0ffSPeter Tribble /*
26*2a1fd0ffSPeter Tribble  * Copyright 2019 Peter Tribble.
27*2a1fd0ffSPeter Tribble  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_PCI_IB_H
307c478bd9Sstevel@tonic-gate #define	_SYS_PCI_IB_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
377851eb82Sschwartz #include <sys/pci_tools.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate typedef uint8_t ib_ino_t;
407c478bd9Sstevel@tonic-gate typedef uint16_t ib_mondo_t;
417c478bd9Sstevel@tonic-gate typedef struct ib_ino_info ib_ino_info_t;
42b0fc0e77Sgovinda typedef struct ib_ino_pil ib_ino_pil_t;
437c478bd9Sstevel@tonic-gate typedef uint8_t device_num_t;
447c478bd9Sstevel@tonic-gate typedef uint8_t interrupt_t;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * interrupt block soft state structure:
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  * Each pci node may share an interrupt block structure with its peer
507c478bd9Sstevel@tonic-gate  * node or have its own private interrupt block structure.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate typedef struct ib ib_t;
537c478bd9Sstevel@tonic-gate struct ib {
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	pci_t *ib_pci_p;	/* link back to pci soft state */
567c478bd9Sstevel@tonic-gate 	pci_ign_t ib_ign;	/* interrupt group # */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	/*
597c478bd9Sstevel@tonic-gate 	 * PCI slot and onboard I/O interrupt mapping register blocks addresses:
607c478bd9Sstevel@tonic-gate 	 */
617c478bd9Sstevel@tonic-gate 	uintptr_t ib_slot_intr_map_regs;
627c478bd9Sstevel@tonic-gate #define	ib_intr_map_regs	ib_slot_intr_map_regs
637c478bd9Sstevel@tonic-gate 	uintptr_t ib_obio_intr_map_regs;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	/*
667c478bd9Sstevel@tonic-gate 	 * PCI slot and onboard I/O clear interrupt register block addresses:
677c478bd9Sstevel@tonic-gate 	 */
687c478bd9Sstevel@tonic-gate 	uintptr_t ib_slot_clear_intr_regs;
697c478bd9Sstevel@tonic-gate 	uintptr_t ib_obio_clear_intr_regs;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	/*
727c478bd9Sstevel@tonic-gate 	 * UPA expansion slot interrupt mapping register addresses:
737c478bd9Sstevel@tonic-gate 	 */
747c478bd9Sstevel@tonic-gate 	volatile uint64_t *ib_upa_imr[2];
757c478bd9Sstevel@tonic-gate 	uint64_t ib_upa_imr_state[2];
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	/*
787c478bd9Sstevel@tonic-gate 	 * Interrupt retry register address:
797c478bd9Sstevel@tonic-gate 	 */
807c478bd9Sstevel@tonic-gate 	volatile uint64_t *ib_intr_retry_timer_reg;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	/*
837c478bd9Sstevel@tonic-gate 	 * PCI slot and onboard I/O interrupt state diag register addresses:
847c478bd9Sstevel@tonic-gate 	 */
857c478bd9Sstevel@tonic-gate 	volatile uint64_t *ib_slot_intr_state_diag_reg;
867c478bd9Sstevel@tonic-gate 	volatile uint64_t *ib_obio_intr_state_diag_reg;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	uint_t ib_max_ino;			/* largest supported INO */
897c478bd9Sstevel@tonic-gate 	ib_ino_info_t *ib_ino_lst;		/* ino link list */
907c478bd9Sstevel@tonic-gate 	kmutex_t ib_ino_lst_mutex;		/* mutex for ino link list */
917c478bd9Sstevel@tonic-gate 	kmutex_t ib_intr_lock;			/* lock for internal intr  */
927c478bd9Sstevel@tonic-gate 	uint16_t ib_map_reg_counters[8];	/* counters for shared map */
937c478bd9Sstevel@tonic-gate 						/* registers */
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #define	PCI_PULSE_INO	0x80000000
977c478bd9Sstevel@tonic-gate #define	PSYCHO_MAX_INO	0x3f
987c478bd9Sstevel@tonic-gate #define	SCHIZO_MAX_INO	0x37
997c478bd9Sstevel@tonic-gate #define	PCI_INO_BITS	6			/* INO#s are 6 bits long */
1007c478bd9Sstevel@tonic-gate #define	PCI_IGN_BITS	5			/* IGN#s are 5 bits long */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
103b0fc0e77Sgovinda  * ih structure: one per every consumer of each ino and pil pair with interrupt
104b0fc0e77Sgovinda  * registered.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate typedef struct ih {
1077c478bd9Sstevel@tonic-gate 	dev_info_t *ih_dip;		/* devinfo structure */
1087c478bd9Sstevel@tonic-gate 	uint32_t ih_inum;		/* interrupt number for this device */
1097c478bd9Sstevel@tonic-gate 	uint_t	ih_intr_state;		/* Only used for fixed interrupts */
1107c478bd9Sstevel@tonic-gate 	uint_t (*ih_handler)();		/* interrupt handler */
1117c478bd9Sstevel@tonic-gate 	caddr_t ih_handler_arg1;	/* interrupt handler argument #1 */
1127c478bd9Sstevel@tonic-gate 	caddr_t ih_handler_arg2;	/* interrupt handler argument #2 */
1137c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t ih_config_handle; /* config space reg map handle */
1147c478bd9Sstevel@tonic-gate 	struct ih *ih_next;		/* next entry in list */
1157c478bd9Sstevel@tonic-gate 	uint64_t ih_ticks;		/* ticks spent in this handler */
1167c478bd9Sstevel@tonic-gate 	uint64_t ih_nsec;		/* nsec spent in this handler */
117b0fc0e77Sgovinda 	kstat_t *ih_ksp;		/* pointer to kstat information */
118b0fc0e77Sgovinda 	ib_ino_pil_t *ih_ipil_p;	/* only for use by kstat */
1197c478bd9Sstevel@tonic-gate } ih_t;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /* Only used for fixed or legacy interrupts */
1227c478bd9Sstevel@tonic-gate #define	PCI_INTR_STATE_DISABLE	0	/* disabled */
1237c478bd9Sstevel@tonic-gate #define	PCI_INTR_STATE_ENABLE	1	/* enabled */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
126b0fc0e77Sgovinda  * ino_pil structure: one per each ino and pil pair with interrupt registered
127b0fc0e77Sgovinda  */
128b0fc0e77Sgovinda struct ib_ino_pil {
129b0fc0e77Sgovinda 	ushort_t ipil_pil;		/* PIL for this ino */
130b0fc0e77Sgovinda 	ushort_t ipil_ih_size;		/* size of ih_t list */
131b0fc0e77Sgovinda 	ih_t *ipil_ih_head;		/* ih_t list head */
132b0fc0e77Sgovinda 	ih_t *ipil_ih_tail;		/* ih_t list tail */
133b0fc0e77Sgovinda 	ih_t *ipil_ih_start;		/* starting point in ih_t list  */
134b0fc0e77Sgovinda 	ib_ino_info_t *ipil_ino_p;	/* pointer to ib_ino_info_t */
135b0fc0e77Sgovinda 	ib_ino_pil_t *ipil_next_p;	/* pointer to next ib_ino_pil_t */
136b0fc0e77Sgovinda };
137b0fc0e77Sgovinda 
138b0fc0e77Sgovinda /*
139b0fc0e77Sgovinda  * ino structure: one per each ino with interrupt registered
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate struct ib_ino_info {
1427c478bd9Sstevel@tonic-gate 	ib_ino_t ino_ino;		/* INO number - 8 bit */
143b0fc0e77Sgovinda 	uint64_t ino_mondo;		/* store mondo number */
1447c478bd9Sstevel@tonic-gate 	uint8_t ino_slot_no;		/* PCI slot number 0-8 */
1457c478bd9Sstevel@tonic-gate 	ib_t *ino_ib_p;			/* link back to interrupt block state */
1467c478bd9Sstevel@tonic-gate 	volatile uint64_t *ino_clr_reg;	/* ino interrupt clear register */
1477c478bd9Sstevel@tonic-gate 	volatile uint64_t *ino_map_reg;	/* ino interrupt mapping register */
1487c478bd9Sstevel@tonic-gate 	uint64_t ino_map_reg_save;	/* = *ino_map_reg if saved */
149b0fc0e77Sgovinda 	volatile uint_t ino_unclaimed_intrs; /* number of unclaimed intrs */
1507c478bd9Sstevel@tonic-gate 	clock_t ino_spurintr_begin;	/* begin time of spurious intr series */
1517c478bd9Sstevel@tonic-gate 	int ino_established;		/* ino has been associated with a cpu */
1527c478bd9Sstevel@tonic-gate 	uint32_t ino_cpuid;		/* cpu that ino is targeting */
1537c478bd9Sstevel@tonic-gate 	int32_t ino_intr_weight;	/* intr weight of devices sharing ino */
154b0fc0e77Sgovinda 	ushort_t ino_ipil_size;		/* number of ib_ino_pil_t sharing ino */
155b0fc0e77Sgovinda 	ushort_t ino_lopil;		/* lowest PIL sharing ino */
156b0fc0e77Sgovinda 	ushort_t ino_claimed;		/* pil bit masks, who claimed intr */
157b0fc0e77Sgovinda 	ib_ino_pil_t *ino_ipil_p;	/* pointer to first ib_ino_pil_t */
158b0fc0e77Sgovinda 	ib_ino_info_t *ino_next_p;	/* pointer to next ib_ino_info_t */
1597c478bd9Sstevel@tonic-gate };
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #define	IB_INTR_WAIT	1		/* wait for interrupt completion */
1627c478bd9Sstevel@tonic-gate #define	IB_INTR_NOWAIT	0		/* already handling intr, no wait */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #define	IB2CB(ib_p)	((ib_p)->ib_pci_p->pci_cb_p)
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #define	IB_MONDO_TO_INO(mondo)		((ib_ino_t)((mondo) & 0x3f))
1677c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_ON(reg_p)		*(reg_p) |= COMMON_INTR_MAP_REG_VALID
1687c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_OFF(reg_p)		*(reg_p) &= ~COMMON_INTR_MAP_REG_VALID
1697c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_RESET(reg_p)	*(reg_p) = 0ull
1707c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_STATE_REG(ib_p, ino) ((ino) & 0x20 ? \
1717c478bd9Sstevel@tonic-gate 	ib_p->ib_obio_intr_state_diag_reg : ib_p->ib_slot_intr_state_diag_reg)
1727c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_PENDING(reg_p, ino) \
1737c478bd9Sstevel@tonic-gate 	(((*(reg_p) >> (((ino) & 0x1f) << 1)) & COMMON_CLEAR_INTR_REG_MASK) == \
1747c478bd9Sstevel@tonic-gate 	COMMON_CLEAR_INTR_REG_PENDING)
1757c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_CLEAR(reg_p)	*(reg_p) = COMMON_CLEAR_INTR_REG_IDLE
1767c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_TRIG(reg_p)	*(reg_p) = COMMON_CLEAR_INTR_REG_RECEIVED
1777c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_PEND(reg_p)		*(reg_p) = COMMON_CLEAR_INTR_REG_PENDING
1787c478bd9Sstevel@tonic-gate #define	IB_INO_INTR_ISON(imr)		((imr) >> 31)
1797c478bd9Sstevel@tonic-gate #define	IB_IMR2MONDO(imr) \
1807c478bd9Sstevel@tonic-gate 	((imr) & (COMMON_INTR_MAP_REG_IGN | COMMON_INTR_MAP_REG_INO))
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #define	IB_IS_OBIO_INO(ino) (ino & 0x20)
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	IB_IGN_TO_MONDO(ign, ino)	(((ign) << PCI_INO_BITS) | (ino))
1857c478bd9Sstevel@tonic-gate #define	IB_INO_TO_MONDO(ib_p, ino)	IB_IGN_TO_MONDO((ib_p)->ib_ign, ino)
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate extern void ib_create(pci_t *pci_p);
1887c478bd9Sstevel@tonic-gate extern void ib_destroy(pci_t *pci_p);
1897c478bd9Sstevel@tonic-gate extern void ib_configure(ib_t *ib_p);
1907c478bd9Sstevel@tonic-gate extern uint64_t ib_get_map_reg(ib_mondo_t mondo, uint32_t cpu_id);
1917c478bd9Sstevel@tonic-gate extern void ib_intr_enable(pci_t *pci_p, ib_ino_t ino);
1927c478bd9Sstevel@tonic-gate extern void ib_intr_disable(ib_t *ib_p, ib_ino_t ino, int wait);
1937c478bd9Sstevel@tonic-gate extern void ib_nintr_clear(ib_t *ib_p, ib_ino_t ino);
1947c478bd9Sstevel@tonic-gate extern void ib_suspend(ib_t *ib_p);
1957c478bd9Sstevel@tonic-gate extern void ib_resume(ib_t *ib_p);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate extern ib_ino_info_t *ib_locate_ino(ib_t *ib_p, ib_ino_t ino_num);
198b0fc0e77Sgovinda extern ib_ino_pil_t *ib_new_ino_pil(ib_t *ib_p, ib_ino_t ino_num, uint_t pil,
199b0fc0e77Sgovinda     ih_t *ih_p);
200b0fc0e77Sgovinda extern void ib_delete_ino_pil(ib_t *ib_p, ib_ino_pil_t *ipil_p);
2017c478bd9Sstevel@tonic-gate extern void ib_free_ino_all(ib_t *ib_p);
202b0fc0e77Sgovinda extern ib_ino_pil_t *ib_ino_locate_ipil(ib_ino_info_t *ino_p, uint_t pil);
203b0fc0e77Sgovinda extern void ib_ino_add_intr(pci_t *pci_p, ib_ino_pil_t *ipil_p, ih_t *ih_p);
204b0fc0e77Sgovinda extern void ib_ino_rem_intr(pci_t *pci_p, ib_ino_pil_t *ipil_p, ih_t *ih_p);
205b0fc0e77Sgovinda extern ih_t *ib_intr_locate_ih(ib_ino_pil_t *ipil_p, dev_info_t *dip,
2067c478bd9Sstevel@tonic-gate     uint32_t inum);
2077c478bd9Sstevel@tonic-gate extern ih_t *ib_alloc_ih(dev_info_t *dip, uint32_t inum,
2087c478bd9Sstevel@tonic-gate     uint_t (*int_handler)(caddr_t int_handler_arg1, caddr_t int_handler_arg2),
2097c478bd9Sstevel@tonic-gate     caddr_t int_handler_arg1, caddr_t int_handler_arg2);
2107c478bd9Sstevel@tonic-gate extern void ib_free_ih(ih_t *ih_p);
2117c478bd9Sstevel@tonic-gate extern void ib_ino_map_reg_share(ib_t *ib_p, ib_ino_t ino,
212b0fc0e77Sgovinda     ib_ino_info_t *ino_p);
2137c478bd9Sstevel@tonic-gate extern int ib_ino_map_reg_unshare(ib_t *ib_p, ib_ino_t ino,
214b0fc0e77Sgovinda     ib_ino_info_t *ino_p);
2157c478bd9Sstevel@tonic-gate extern uint32_t ib_register_intr(ib_t *ib_p, ib_mondo_t mondo, uint_t pil,
216b0fc0e77Sgovinda     uint_t (*handler)(caddr_t arg), caddr_t arg);
2177c478bd9Sstevel@tonic-gate extern void ib_unregister_intr(ib_mondo_t mondo);
2187c478bd9Sstevel@tonic-gate extern void ib_intr_dist_nintr(ib_t *ib_p, ib_ino_t ino,
219b0fc0e77Sgovinda     volatile uint64_t *imr_p);
2207c478bd9Sstevel@tonic-gate extern void ib_intr_dist_all(void *arg, int32_t max_weight, int32_t weight);
2217851eb82Sschwartz extern void ib_cpu_ticks_to_ih_nsec(ib_t *ib_p, ih_t *ih_p, uint32_t cpu_id);
22209b1eac2SEvan Yan extern int ib_update_intr_state(pci_t *pci_p, dev_info_t *rdip,
22309b1eac2SEvan Yan     ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state);
22409b1eac2SEvan Yan extern int ib_get_intr_target(pci_t *pci_p, ib_ino_t ino, int *cpu_id_p);
22509b1eac2SEvan Yan extern int ib_set_intr_target(pci_t *pci_p, ib_ino_t ino, int cpu_id);
2267851eb82Sschwartz extern uint8_t ib_get_ino_devs(ib_t *ib_p, uint32_t ino, uint8_t *devs_ret,
227b0fc0e77Sgovinda     pcitool_intr_dev_t *devs);
2287851eb82Sschwartz extern void ib_log_new_cpu(ib_t *ib_p, uint32_t old_cpu_id, uint32_t new_cpu_id,
229b0fc0e77Sgovinda     uint32_t ino);
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate extern int pci_pil[];
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #endif	/* _SYS_PCI_IB_H */
238