xref: /titanic_52/usr/src/uts/sun4u/sys/sbbcvar.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SBBCVAR_H
28 #define	_SYS_SBBCVAR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct sbbc_intr_map {
37 	uint32_t sbbc_phys_hi;
38 	uint32_t sbbc_phys_mid;
39 	uint32_t sbbc_phys_low;
40 	uint32_t sbbc_intr;
41 	uint32_t intr_ctlr_nodeid;
42 	uint32_t ino;
43 }sbbc_intr_map_t;
44 
45 struct sbbc_intr_map_mask {
46 	uint32_t sbbc_phys_hi;
47 	uint32_t sbbc_phys_mid;
48 	uint32_t sbbc_phys_low;
49 	uint32_t sbbc_intr;
50 };
51 
52 /* sbbc intrspec for initializing its children. */
53 struct sbbc_intrspec {
54 	struct intrspec intr_spec;
55 	dev_info_t *dip;		/* Interrupt parent dip */
56 	uint32_t intr;			/* for lookup */
57 };
58 
59 /*
60  * definition of sbbc child reg spec entry:
61  */
62 typedef struct {
63 	uint32_t addr_hi;
64 	uint32_t addr_low;
65 	uint32_t size;
66 } sbbc_child_regspec_t;
67 
68 /* SBBC range entry */
69 typedef struct sbbc_pci_rangespec {
70 	uint32_t sbbc_phys_hi;		/* Child hi range address */
71 	uint32_t sbbc_phys_low;		/* Child low range address */
72 	uint32_t pci_phys_hi;		/* Parent hi rng addr */
73 	uint32_t pci_phys_mid;		/* Parent mid rng addr */
74 	uint32_t pci_phys_low;		/* Parent low rng addr */
75 	uint32_t rng_size;		/* Range size */
76 } sbbc_pci_rangespec_t;
77 
78 typedef int procid_t;
79 
80 /* Max. SBBC devices/children */
81 #define	MAX_SBBC_DEVICES	3
82 
83 /* Only used for fixed or legacy interrupts */
84 #define	SBBC_INTR_STATE_DISABLE	0	/* disabled */
85 #define	SBBC_INTR_STATE_ENABLE	1	/* enabled */
86 
87 typedef struct sbbc_child_intr {
88 	char *name;
89 	uint_t inum;
90 	uint_t status;
91 	uint_t (*intr_handler)();
92 	caddr_t arg1;
93 	caddr_t	arg2;
94 } sbbc_child_intr_t;
95 
96 typedef struct sbbcsoft {
97 	int instance;
98 	int oflag;
99 	uint_t myinumber;
100 	dev_info_t *dip;			/* device information */
101 	pci_regspec_t *reg;
102 	int nreg;
103 	sbbc_pci_rangespec_t *rangep;
104 	int range_cnt;
105 	int range_len;
106 	struct pci_sbbc *pci_sbbc_map;		/* sbbc registers and devices */
107 	ddi_acc_handle_t pci_sbbc_map_handle;
108 	ddi_iblock_cookie_t sbbc_iblock_cookie; /* interrupt block cookie */
109 	kmutex_t sbbc_intr_mutex;		/* lock for interrupts */
110 	sbbc_child_intr_t *child_intr[MAX_SBBC_DEVICES]; /* intr per device */
111 	boolean_t suspended;			/* TRUE if driver suspended */
112 	kmutex_t umutex;			/* lock for this structure */
113 } sbbcsoft_t;
114 
115 #define	TRUE		1
116 #define	FALSE		0
117 
118 
119 #if defined(DEBUG)
120 
121 #define	SBBC_DBG_ATTACH		0x1
122 #define	SBBC_DBG_DETACH		0x2
123 #define	SBBC_DBG_CTLOPS		0x4
124 #define	SBBC_DBG_INITCHILD	0x8
125 #define	SBBC_DBG_UNINITCHILD	0x10
126 #define	SBBC_DBG_BUSMAP		0x20
127 #define	SBBC_DBG_INTR		0x40
128 #define	SBBC_DBG_PCICONF	0x80
129 #define	SBBC_DBG_MAPRANGES	0x100
130 #define	SBBC_DBG_PROPERTIES	0x200
131 #define	SBBC_DBG_OPEN		0x400
132 #define	SBBC_DBG_CLOSE		0x800
133 #define	SBBC_DBG_IOCTL		0x1000
134 #define	SBBC_DBG_INTROPS	0x2000
135 
136 
137 #define	SBBC_DBG0(flag, dip, fmt) \
138 	sbbc_dbg(flag, dip, fmt, 0, 0, 0, 0, 0);
139 #define	SBBC_DBG1(flag, dip, fmt, a1) \
140 	sbbc_dbg(flag, dip, fmt, (uintptr_t)(a1), 0, 0, 0, 0);
141 #define	SBBC_DBG2(flag, dip, fmt, a1, a2) \
142 	sbbc_dbg(flag, dip, fmt, (uintptr_t)(a1), (uintptr_t)(a2), 0, 0, 0);
143 #define	SBBC_DBG3(flag, dip, fmt, a1, a2, a3) \
144 	sbbc_dbg(flag, dip, fmt, (uintptr_t)(a1), (uintptr_t)(a2), \
145 		(uintptr_t)(a3), 0, 0);
146 #define	SBBC_DBG4(flag, dip, fmt, a1, a2, a3, a4) \
147 	sbbc_dbg(flag, dip, fmt, (uintptr_t)(a1), (uintptr_t)(a2), \
148 		(uintptr_t)(a3), (uintptr_t)(a4), 0);
149 #define	SBBC_DBG5(flag, dip, fmt, a1, a2, a3, a4, a5) \
150 	sbbc_dbg(flag, dip, fmt, (uintptr_t)(a1), (uintptr_t)(a2), \
151 		(uintptr_t)(a3), (uintptr_t)(a4), (uintptr_t)(a5));
152 
153 #else /* DEBUG */
154 
155 #define	SBBC_DBG0(flag, dip, fmt)
156 #define	SBBC_DBG1(flag, dip, fmt, a1)
157 #define	SBBC_DBG2(flag, dip, fmt, a1, a2)
158 #define	SBBC_DBG3(flag, dip, fmt, a1, a2, a3)
159 #define	SBBC_DBG4(flag, dip, fmt, a1, a2, a3, a4)
160 #define	SBBC_DBG5(flag, dip, fmt, a1, a2, a3, a4, a5)
161 
162 #endif /* DEBUG */
163 
164 /* debugging flags */
165 /*
166  * To enable tracing, uncomment this line:
167  * #define	SBBC_TRACE	1
168  */
169 
170 #if defined(SBBC_TRACE)
171 
172 #ifndef NSBBCTRACE
173 #define	NSBBCTRACE	1024
174 #endif
175 
176 struct sbbctrace {
177 	int count;
178 	int function;		/* address of function */
179 	int trace_action;	/* descriptive 4 characters */
180 	int object;		/* object operated on */
181 };
182 
183 /*
184  * For debugging, allocate space for the trace buffer
185  */
186 
187 extern struct sbbctrace sbbctrace_buffer[];
188 extern struct sbbctrace *sbbctrace_ptr;
189 extern int sbbctrace_count;
190 
191 #define	SBBCTRACEINIT() {				\
192 	if (sbbctrace_ptr == NULL)		\
193 		sbbctrace_ptr = sbbctrace_buffer; \
194 	}
195 
196 #define	LOCK_TRACE()	(uint_t)ddi_enter_critical()
197 #define	UNLOCK_TRACE(x)	ddi_exit_critical((uint_t)x)
198 
199 #define	SBBCTRACE(func, act, obj) {		\
200 	int __s = LOCK_TRACE();			\
201 	int *_p = &sbbctrace_ptr->count;	\
202 	*_p++ = ++sbbctrace_count;		\
203 	*_p++ = (int)(func);			\
204 	*_p++ = (int)(act);			\
205 	*_p++ = (int)(obj);			\
206 	if ((struct sbbctrace *)(void *)_p >= &sbbctrace_buffer[NSBBCTRACE])\
207 		sbbctrace_ptr = sbbctrace_buffer; \
208 	else					\
209 		sbbctrace_ptr = (struct sbbctrace *)(void *)_p; \
210 	UNLOCK_TRACE(__s);			\
211 	}
212 
213 #else	/* !SBBC_TRACE */
214 
215 /* If no tracing, define no-ops */
216 #define	SBBCTRACEINIT()
217 #define	SBBCTRACE(a, b, c)
218 
219 #endif	/* !SBBC_TRACE */
220 
221 #ifdef	__cplusplus
222 }
223 #endif
224 
225 #endif	/* _SYS_SBBCVAR_H */
226