1*25cf1a30Sjl /*
2*25cf1a30Sjl  * CDDL HEADER START
3*25cf1a30Sjl  *
4*25cf1a30Sjl  * The contents of this file are subject to the terms of the
5*25cf1a30Sjl  * Common Development and Distribution License (the "License").
6*25cf1a30Sjl  * You may not use this file except in compliance with the License.
7*25cf1a30Sjl  *
8*25cf1a30Sjl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25cf1a30Sjl  * or http://www.opensolaris.org/os/licensing.
10*25cf1a30Sjl  * See the License for the specific language governing permissions
11*25cf1a30Sjl  * and limitations under the License.
12*25cf1a30Sjl  *
13*25cf1a30Sjl  * When distributing Covered Code, include this CDDL HEADER in each
14*25cf1a30Sjl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25cf1a30Sjl  * If applicable, add the following below this CDDL HEADER, with the
16*25cf1a30Sjl  * fields enclosed by brackets "[]" replaced with your own identifying
17*25cf1a30Sjl  * information: Portions Copyright [yyyy] [name of copyright owner]
18*25cf1a30Sjl  *
19*25cf1a30Sjl  * CDDL HEADER END
20*25cf1a30Sjl  */
21*25cf1a30Sjl /*
22*25cf1a30Sjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*25cf1a30Sjl  * Use is subject to license terms.
24*25cf1a30Sjl  */
25*25cf1a30Sjl 
26*25cf1a30Sjl #ifndef	_SYS_PCMU_IB_H
27*25cf1a30Sjl #define	_SYS_PCMU_IB_H
28*25cf1a30Sjl 
29*25cf1a30Sjl #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*25cf1a30Sjl 
31*25cf1a30Sjl #ifdef	__cplusplus
32*25cf1a30Sjl extern "C" {
33*25cf1a30Sjl #endif
34*25cf1a30Sjl 
35*25cf1a30Sjl #include <sys/ddi_subrdefs.h>
36*25cf1a30Sjl 
37*25cf1a30Sjl typedef uint8_t pcmu_ib_ino_t;
38*25cf1a30Sjl typedef uint16_t pcmu_ib_mondo_t;
39*25cf1a30Sjl 
40*25cf1a30Sjl /*
41*25cf1a30Sjl  * The following structure represents an interrupt entry for an INO.
42*25cf1a30Sjl  */
43*25cf1a30Sjl typedef struct ih {
44*25cf1a30Sjl 	dev_info_t *ih_dip;		/* devinfo structure */
45*25cf1a30Sjl 	uint32_t ih_inum;		/* interrupt number for this device */
46*25cf1a30Sjl 	uint_t	ih_intr_state;		/* Only used for fixed interrupts */
47*25cf1a30Sjl 	uint_t (*ih_handler)();		/* interrupt handler */
48*25cf1a30Sjl 	caddr_t ih_handler_arg1;	/* interrupt handler argument #1 */
49*25cf1a30Sjl 	caddr_t ih_handler_arg2;	/* interrupt handler argument #2 */
50*25cf1a30Sjl 	ddi_acc_handle_t ih_config_handle; /* config space reg map handle */
51*25cf1a30Sjl 	struct ih *ih_next;		/* next entry in list */
52*25cf1a30Sjl } ih_t;
53*25cf1a30Sjl 
54*25cf1a30Sjl /*
55*25cf1a30Sjl  * ino structure : one per CMU-CH ino with interrupt registered
56*25cf1a30Sjl  */
57*25cf1a30Sjl typedef struct pcmu_ib_ino_info {
58*25cf1a30Sjl 	struct pcmu_ib_ino_info *pino_next;
59*25cf1a30Sjl 	pcmu_ib_ino_t pino_ino;		/* INO number - 8 bit */
60*25cf1a30Sjl 	uint8_t pino_slot_no;		/* PCI slot number 0-8 */
61*25cf1a30Sjl 	uint16_t pino_ih_size;		/* size of the pci intrspec list */
62*25cf1a30Sjl 	ih_t *pino_ih_head;		/* intr spec (part of ppd) list head */
63*25cf1a30Sjl 	ih_t *pino_ih_tail;		/* intr spec (part of ppd) list tail */
64*25cf1a30Sjl 	ih_t *pino_ih_start;		/* starting point in intr spec list  */
65*25cf1a30Sjl 	pcmu_ib_t *pino_ib_p;		/* link back to interrupt block state */
66*25cf1a30Sjl 	volatile uint64_t *pino_clr_reg; /* ino interrupt clear register */
67*25cf1a30Sjl 	volatile uint64_t *pino_map_reg; /* ino interrupt mapping register */
68*25cf1a30Sjl 	uint64_t pino_map_reg_save;	/* = *pino_map_reg if saved */
69*25cf1a30Sjl 	uint32_t pino_pil;		/* PIL for this ino */
70*25cf1a30Sjl 	volatile uint_t pino_unclaimed;	/* number of unclaimed interrupts */
71*25cf1a30Sjl 	clock_t pino_spurintr_begin;	/* begin time of spurious intr series */
72*25cf1a30Sjl 	int pino_established;		/* ino has been associated with a cpu */
73*25cf1a30Sjl 	uint32_t pino_cpuid;		/* cpu that ino is targeting */
74*25cf1a30Sjl 	int32_t pino_intr_weight;	/* intr weight of devices sharing ino */
75*25cf1a30Sjl } pcmu_ib_ino_info_t;
76*25cf1a30Sjl 
77*25cf1a30Sjl /*
78*25cf1a30Sjl  * interrupt block soft state structure:
79*25cf1a30Sjl  */
80*25cf1a30Sjl struct pcmu_ib {
81*25cf1a30Sjl 	pcmu_t *pib_pcmu_p;	/* link back to pci soft state */
82*25cf1a30Sjl 	pcmu_ign_t pib_ign;	/* interrupt group # */
83*25cf1a30Sjl 	uintptr_t pib_obio_intr_map_regs;	/* onboard intr map register */
84*25cf1a30Sjl 	uintptr_t pib_obio_clear_intr_regs;	/* onboard intr clear reg */
85*25cf1a30Sjl 	volatile uint64_t *pib_upa_imr[2]; /* UPA expansion intr map register */
86*25cf1a30Sjl 	uint64_t pib_upa_imr_state[2];	   /* UPA intr map state */ /* RAGS */
87*25cf1a30Sjl 	volatile uint64_t *pib_intr_retry_timer_reg; /* intr retry register */
88*25cf1a30Sjl 	volatile uint64_t *pib_obio_intr_state_diag_reg; /* onboard intr st. */
89*25cf1a30Sjl 	uint_t pib_max_ino;			/* largest supported INO */
90*25cf1a30Sjl 	pcmu_ib_ino_info_t *pib_ino_lst;	/* ino link list */
91*25cf1a30Sjl 	kmutex_t pib_ino_lst_mutex;		/* mutex for ino link list */
92*25cf1a30Sjl 	kmutex_t pib_intr_lock;			/* lock for internal intr  */
93*25cf1a30Sjl };
94*25cf1a30Sjl 
95*25cf1a30Sjl #define	PCMU_MAX_INO		0x3f
96*25cf1a30Sjl #define	PCMU_INO_BITS		6		/* INO#s are 6 bits long */
97*25cf1a30Sjl 
98*25cf1a30Sjl /*
99*25cf1a30Sjl  * Only used for fixed or legacy interrupts
100*25cf1a30Sjl  */
101*25cf1a30Sjl #define	PCMU_INTR_STATE_DISABLE	0		/* disabled */
102*25cf1a30Sjl #define	PCMU_INTR_STATE_ENABLE	1		/* enabled */
103*25cf1a30Sjl 
104*25cf1a30Sjl #define	PCMU_IB_INTR_WAIT	1		/* wait for inter completion */
105*25cf1a30Sjl #define	PCMU_IB_INTR_NOWAIT	0		/* handling intr, no wait */
106*25cf1a30Sjl 
107*25cf1a30Sjl #define	PCMU_IB2CB(pib_p)	((pib_p)->pib_pcmu_p->pcmu_cb_p)
108*25cf1a30Sjl 
109*25cf1a30Sjl #define	PCMU_IB_MONDO_TO_INO(mondo)	((pcmu_ib_ino_t)((mondo) & 0x3f))
110*25cf1a30Sjl #define	PCMU_IB_INO_INTR_ON(reg_p)	*(reg_p) |= PCMU_INTR_MAP_REG_VALID
111*25cf1a30Sjl #define	PCMU_IB_INO_INTR_OFF(reg_p)	*(reg_p) &= ~PCMU_INTR_MAP_REG_VALID
112*25cf1a30Sjl #define	PCMU_IB_INO_INTR_STATE_REG(pib_p, ino)		\
113*25cf1a30Sjl 	    (pib_p->pib_obio_intr_state_diag_reg)
114*25cf1a30Sjl 
115*25cf1a30Sjl #define	PCMU_IB_INO_INTR_PENDING(reg_p, ino)		\
116*25cf1a30Sjl 	    (((*(reg_p) >> (((ino) & 0x1f) << 1)) &	\
117*25cf1a30Sjl 	    PCMU_CLEAR_INTR_REG_MASK) == PCMU_CLEAR_INTR_REG_PENDING)
118*25cf1a30Sjl 
119*25cf1a30Sjl #define	PCMU_IB_INO_INTR_CLEAR(reg_p)	*(reg_p) = PCMU_CLEAR_INTR_REG_IDLE
120*25cf1a30Sjl #define	PCMU_IB_INO_INTR_PEND(reg_p)	*(reg_p) = PCMU_CLEAR_INTR_REG_PENDING
121*25cf1a30Sjl #define	PCMU_IB_INO_INTR_ISON(imr)	((imr) >> 31)
122*25cf1a30Sjl 
123*25cf1a30Sjl #define	PCMU_IB_IMR2MONDO(imr)	((imr) &		\
124*25cf1a30Sjl 	    (PCMU_INTR_MAP_REG_IGN | PCMU_INTR_MAP_REG_INO))
125*25cf1a30Sjl 
126*25cf1a30Sjl #define	PCMU_IB_IS_OBIO_INO(ino) (ino & 0x20)
127*25cf1a30Sjl 
128*25cf1a30Sjl #define	PCMU_IB_IGN_TO_MONDO(ign, ino)	(((ign) << PCMU_INO_BITS) | (ino))
129*25cf1a30Sjl #define	PCMU_IB_INO_TO_MONDO(pib_p, ino)	\
130*25cf1a30Sjl     PCMU_IB_IGN_TO_MONDO((pib_p)->pib_ign, ino)
131*25cf1a30Sjl 
132*25cf1a30Sjl 
133*25cf1a30Sjl extern int pcmu_pil[];
134*25cf1a30Sjl 
135*25cf1a30Sjl /*
136*25cf1a30Sjl  * Prototypes
137*25cf1a30Sjl  */
138*25cf1a30Sjl extern void pcmu_ib_create(pcmu_t *pcmu_p);
139*25cf1a30Sjl extern void pcmu_ib_destroy(pcmu_t *pcmu_p);
140*25cf1a30Sjl extern void pcmu_ib_configure(pcmu_ib_t *pib_p);
141*25cf1a30Sjl extern uint64_t ib_get_map_reg(pcmu_ib_mondo_t mondo, uint32_t cpu_id);
142*25cf1a30Sjl extern void pcmu_ib_intr_enable(pcmu_t *pcmu_p, pcmu_ib_ino_t ino);
143*25cf1a30Sjl extern void pcmu_ib_intr_disable(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino, int wait);
144*25cf1a30Sjl extern void pcmu_ib_nintr_clear(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino);
145*25cf1a30Sjl extern void pcmu_ib_suspend(pcmu_ib_t *pib_p);
146*25cf1a30Sjl extern void pcmu_ib_resume(pcmu_ib_t *pib_p);
147*25cf1a30Sjl extern pcmu_ib_ino_info_t *pcmu_ib_locate_ino(pcmu_ib_t *pib_p,
148*25cf1a30Sjl     pcmu_ib_ino_t ino_num);
149*25cf1a30Sjl extern pcmu_ib_ino_info_t *pcmu_ib_new_ino(pcmu_ib_t *pib_p,
150*25cf1a30Sjl     pcmu_ib_ino_t ino_num, ih_t *ih_p);
151*25cf1a30Sjl extern void pcmu_ib_delete_ino(pcmu_ib_t *pib_p, pcmu_ib_ino_info_t *ino_p);
152*25cf1a30Sjl extern void pcmu_ib_free_ino_all(pcmu_ib_t *pib_p);
153*25cf1a30Sjl extern int pcmu_ib_update_intr_state(pcmu_t *pcmu_p, dev_info_t *rdip,
154*25cf1a30Sjl     ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state);
155*25cf1a30Sjl extern void pcmu_ib_ino_add_intr(pcmu_t *pcmu_p,
156*25cf1a30Sjl     pcmu_ib_ino_info_t *ino_p, ih_t *ih_p);
157*25cf1a30Sjl extern void pcmu_ib_ino_rem_intr(pcmu_t *pcmu_p,
158*25cf1a30Sjl     pcmu_ib_ino_info_t *ino_p, ih_t *ih_p);
159*25cf1a30Sjl extern ih_t *pcmu_ib_ino_locate_intr(pcmu_ib_ino_info_t *ino_p,
160*25cf1a30Sjl     dev_info_t *dip, uint32_t inum);
161*25cf1a30Sjl extern ih_t *pcmu_ib_alloc_ih(dev_info_t *dip, uint32_t inum,
162*25cf1a30Sjl     uint_t (*int_handler)(caddr_t int_handler_arg1, caddr_t int_handler_arg2),
163*25cf1a30Sjl     caddr_t int_handler_arg1, caddr_t int_handler_arg2);
164*25cf1a30Sjl extern void pcmu_ib_intr_dist_nintr(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino,
165*25cf1a30Sjl     volatile uint64_t *imr_p);
166*25cf1a30Sjl extern void pcmu_ib_intr_dist_all(void *arg,
167*25cf1a30Sjl     int32_t max_weight, int32_t weight);
168*25cf1a30Sjl 
169*25cf1a30Sjl #ifdef	__cplusplus
170*25cf1a30Sjl }
171*25cf1a30Sjl #endif
172*25cf1a30Sjl 
173*25cf1a30Sjl #endif	/* _SYS_PCMU_IB_H */
174