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