1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate #ifndef _CS_PRIV_H
28*7c478bd9Sstevel@tonic-gate #define	_CS_PRIV_H
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * PCMCIA Card Services private header file
38*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * typedef for function pointers to quiet lint and cc -v
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate typedef	int32_t (f_t)(int32_t, ...);	/* for lint - cc -v quieting */
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * Magic number we use when talking with Socket Services
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate #define	CS_MAGIC	PCCS_MAGIC
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  * Make the calls to SocketServices and the CIS Parser look like
52*7c478bd9Sstevel@tonic-gate  *	function calls.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate #define	SocketServices	(*cs_socket_services)
55*7c478bd9Sstevel@tonic-gate #define	CIS_PARSER	(*cis_parser)
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * CIS_DEFAULT_SPEED is the default speed to use to read the CIS
59*7c478bd9Sstevel@tonic-gate  *	in AM space.  It is expressed in nS.
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate #define	CIS_DEFAULT_SPEED	250
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate  * This is the IO window speed.
65*7c478bd9Sstevel@tonic-gate  */
66*7c478bd9Sstevel@tonic-gate #define	IO_WIN_SPEED		250
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate  * Flags to support various internal first/next functions. All of
70*7c478bd9Sstevel@tonic-gate  *	these must be within CIS_GET_LTUPLE_OPMASK which is defined
71*7c478bd9Sstevel@tonic-gate  *	in the cis.h file. Values outside this mask range are used
72*7c478bd9Sstevel@tonic-gate  *	internally by the CIS parser.
73*7c478bd9Sstevel@tonic-gate  */
74*7c478bd9Sstevel@tonic-gate #define	CS_GET_FIRST_FLAG	0x0001
75*7c478bd9Sstevel@tonic-gate #define	CS_GET_NEXT_FLAG	0x0002
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * Macros to manipulate bits - only does up to uint32_t size
79*7c478bd9Sstevel@tonic-gate  */
80*7c478bd9Sstevel@tonic-gate #define	CS_BIT_WORDSIZE		(sizeof (uint32_t))
82*7c478bd9Sstevel@tonic-gate #define	CS_BIT_GET(val, bit)	\
83*7c478bd9Sstevel@tonic-gate 			((uint32_t)(val) & (uint32_t)(1<<(uint32_t)(bit)))
85*7c478bd9Sstevel@tonic-gate #define	CS_BIT_CLEAR(val, bit)	((val) &= (uint32_t)~(1<<(uint32_t)(bit)))
87*7c478bd9Sstevel@tonic-gate #define	CS_BIT_SET(val, bit)	\
88*7c478bd9Sstevel@tonic-gate 			((uint32_t)(val) |= (uint32_t)(1<<(uint32_t)(bit)))
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate  * Minimum time to wait after socket reset before we are allowed to
92*7c478bd9Sstevel@tonic-gate  *	access the card.  The PCMCIA specification says at least 20mS
93*7c478bd9Sstevel@tonic-gate  *	must elapse from the time that the card is reset until the
94*7c478bd9Sstevel@tonic-gate  *	first access of any kind can be made to the card. This time
95*7c478bd9Sstevel@tonic-gate  *	value is expressed in mS.
96*7c478bd9Sstevel@tonic-gate  */
97*7c478bd9Sstevel@tonic-gate #define	RESET_TIMEOUT_TIME	180
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate  * Maximum time to wait for card ready after resetting the socket.
101*7c478bd9Sstevel@tonic-gate  *	We wait for card ready a maximum of 20 seconds after card
102*7c478bd9Sstevel@tonic-gate  *	reset before considering that we have an error condition.
103*7c478bd9Sstevel@tonic-gate  * XXX - what does PCMCIA specify as the max time here??
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate #define	READY_TIMEOUT_TIME	(drv_usectohz(20000000))
107*7c478bd9Sstevel@tonic-gate /*
108*7c478bd9Sstevel@tonic-gate  * Time between periodically kicking the soft interrupt handler.
109*7c478bd9Sstevel@tonic-gate  */
110*7c478bd9Sstevel@tonic-gate #define	SOFTINT_TIMEOUT_TIME	(drv_usectohz(2000000))
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate  * Various delays are necessary when switching the card and socket
114*7c478bd9Sstevel@tonic-gate  *	between IO and memory modes. All delays are in mS.
115*7c478bd9Sstevel@tonic-gate  *
116*7c478bd9Sstevel@tonic-gate  *  cs_request_configuration parameters:
117*7c478bd9Sstevel@tonic-gate  *    CS_RC1_DELAY - delay between writing COR and switching socket
118*7c478bd9Sstevel@tonic-gate  *			to IO mode
119*7c478bd9Sstevel@tonic-gate  *    CS_RC2_DELAY - delay after switching socket to IO mode
120*7c478bd9Sstevel@tonic-gate  *
121*7c478bd9Sstevel@tonic-gate  *  cs_release_configuration parameters:
122*7c478bd9Sstevel@tonic-gate  *	CS_RQ_DELAY - amount of time that the RESET bit in the COR is
123*7c478bd9Sstevel@tonic-gate  *			held asserted
124*7c478bd9Sstevel@tonic-gate  */
125*7c478bd9Sstevel@tonic-gate #define	CS_RC1_DELAY		20	/* COR->IO delay in mS */
126*7c478bd9Sstevel@tonic-gate #define	CS_RC2_DELAY		300	/* post-COR delay in mS */
127*7c478bd9Sstevel@tonic-gate #define	CS_RQ_DELAY		100	/* COR(RESET) delay in mS */
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate  * Handy macro to do untimeout.
131*7c478bd9Sstevel@tonic-gate  */
132*7c478bd9Sstevel@tonic-gate #define	UNTIMEOUT(id)		\
133*7c478bd9Sstevel@tonic-gate 	if ((id)) {		\
134*7c478bd9Sstevel@tonic-gate 	    (void) untimeout((id));	\
135*7c478bd9Sstevel@tonic-gate 	    (id) = 0;		\
136*7c478bd9Sstevel@tonic-gate 	}
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * Macros to enter/exit event thread mutex
140*7c478bd9Sstevel@tonic-gate  */
141*7c478bd9Sstevel@tonic-gate #define	EVENT_THREAD_MUTEX_ENTER(acq, sp)		\
142*7c478bd9Sstevel@tonic-gate 	acq = !MUTEX_HELD(&sp->client_lock);		\
143*7c478bd9Sstevel@tonic-gate 	if (acq)					\
144*7c478bd9Sstevel@tonic-gate 	    mutex_enter(&sp->client_lock);
145*7c478bd9Sstevel@tonic-gate #define	EVENT_THREAD_MUTEX_EXIT(acq, sp)		\
146*7c478bd9Sstevel@tonic-gate 	if (acq)					\
147*7c478bd9Sstevel@tonic-gate 	    mutex_exit(&sp->client_lock);
149*7c478bd9Sstevel@tonic-gate /*
150*7c478bd9Sstevel@tonic-gate  * cisregister_t structure is used to support the CISRegister
151*7c478bd9Sstevel@tonic-gate  *	and the CISUnregister function calls
152*7c478bd9Sstevel@tonic-gate  */
153*7c478bd9Sstevel@tonic-gate typedef struct cisregister_t {
154*7c478bd9Sstevel@tonic-gate 	uint32_t		cis_magic;
155*7c478bd9Sstevel@tonic-gate 	uint32_t		cis_version;
156*7c478bd9Sstevel@tonic-gate 	void *			(*cis_parser)(int32_t function, ...);
157*7c478bd9Sstevel@tonic-gate 	cistpl_callout_t	*cistpl_std_callout; /* standard callout list */
158*7c478bd9Sstevel@tonic-gate } cisregister_t;
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * These two defines are to support CISRegister and CISUnregister
162*7c478bd9Sstevel@tonic-gate  */
163*7c478bd9Sstevel@tonic-gate #define	CIS_MAGIC	0x20434953
164*7c478bd9Sstevel@tonic-gate #define	CIS_VERSION	_VERSION(0, 1)
166*7c478bd9Sstevel@tonic-gate /*
167*7c478bd9Sstevel@tonic-gate  * CS_MAX_CIS defines the number of CIS chains that we hang off the per-socket
168*7c478bd9Sstevel@tonic-gate  *	structure.
169*7c478bd9Sstevel@tonic-gate  *
170*7c478bd9Sstevel@tonic-gate  * CS_GLOBAL_CIS defines the index where the CIS parser puts the first CIS list
171*7c478bd9Sstevel@tonic-gate  *	for a single-function card or the global CIS list for a multi-function
172*7c478bd9Sstevel@tonic-gate  *	card.
173*7c478bd9Sstevel@tonic-gate  *
174*7c478bd9Sstevel@tonic-gate  * CS_MAX_CIS is one greater than CIS_MAX_FUNCTIONS since the CIS parser
175*7c478bd9Sstevel@tonic-gate  *	puts the global CIS chain on the CS_GLOBAL_CIS function index as
176*7c478bd9Sstevel@tonic-gate  * 	follows:
177*7c478bd9Sstevel@tonic-gate  *
178*7c478bd9Sstevel@tonic-gate  *	For single-function cards:
179*7c478bd9Sstevel@tonic-gate  *	    sp->cis[0] - CIS chain
180*7c478bd9Sstevel@tonic-gate  *	    sp->cis[1..(CIS_MAX_FUNCTIONS - 1)] - not used
181*7c478bd9Sstevel@tonic-gate  *	    sp->cis[CS_GLOBAL_CIS] - not used
182*7c478bd9Sstevel@tonic-gate  *
183*7c478bd9Sstevel@tonic-gate  *	For multi-function cards:
184*7c478bd9Sstevel@tonic-gate  *	    sp->cis[0..(CIS_MAX_FUNCTIONS - 1)] - global CIS chain followed
185*7c478bd9Sstevel@tonic-gate  *					by per-function CIS chain
186*7c478bd9Sstevel@tonic-gate  *	    sp->cis[CS_GLOBAL_CIS] - global CIS chain
187*7c478bd9Sstevel@tonic-gate  */
188*7c478bd9Sstevel@tonic-gate #define	CS_MAX_CIS	(CIS_MAX_FUNCTIONS + 1)
189*7c478bd9Sstevel@tonic-gate #define	CS_GLOBAL_CIS	CIS_MAX_FUNCTIONS
191*7c478bd9Sstevel@tonic-gate /*
192*7c478bd9Sstevel@tonic-gate  * CS_SS_CLIENT_HANDLE is a special client handle that Socket Services gets
193*7c478bd9Sstevel@tonic-gate  *	when it registers with RegisterClient.
194*7c478bd9Sstevel@tonic-gate  */
195*7c478bd9Sstevel@tonic-gate #define	CS_SS_CLIENT_HANDLE	0x00000000
197*7c478bd9Sstevel@tonic-gate /*
198*7c478bd9Sstevel@tonic-gate  * Client handle, socket number, function number and socket pointer
199*7c478bd9Sstevel@tonic-gate  *	macros. The client handle encoding is private to Card Services,
200*7c478bd9Sstevel@tonic-gate  *	and external modules should not use these macros to manipulate
201*7c478bd9Sstevel@tonic-gate  *	client handles.
202*7c478bd9Sstevel@tonic-gate  *
203*7c478bd9Sstevel@tonic-gate  *	The encoding of the client handle is:
204*7c478bd9Sstevel@tonic-gate  *
205*7c478bd9Sstevel@tonic-gate  *		xxxxxfff | xsssssss | cccccccc | cccccccc
206*7c478bd9Sstevel@tonic-gate  *
207*7c478bd9Sstevel@tonic-gate  *	f - function number bit
208*7c478bd9Sstevel@tonic-gate  *	s - socket number bit
209*7c478bd9Sstevel@tonic-gate  *	c - client number bit
210*7c478bd9Sstevel@tonic-gate  *	x - don't care bits
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate #define	CLIENT_HANDLE_IS_SS(ch)		(!GET_CLIENT_MINOR((ch)))
213*7c478bd9Sstevel@tonic-gate #define	CS_MAX_SOCKETS_MASK		(PCMCIA_MAX_SOCKETS - 1)
214*7c478bd9Sstevel@tonic-gate #define	CS_MAX_FUNCTIONS_MASK		(CIS_MAX_FUNCTIONS - 1)
215*7c478bd9Sstevel@tonic-gate #define	CS_MAX_CLIENTS_MASK		0x0ffff
216*7c478bd9Sstevel@tonic-gate #define	CS_MAX_CLIENTS			(CS_MAX_CLIENTS_MASK - 2)
217*7c478bd9Sstevel@tonic-gate #define	MAKE_CLIENT_HANDLE(s, f, c)	((((f)&CS_MAX_FUNCTIONS_MASK)<<24) | \
218*7c478bd9Sstevel@tonic-gate 					    (((s)&CS_MAX_SOCKETS_MASK)<<16) | \
219*7c478bd9Sstevel@tonic-gate 					    ((c)&CS_MAX_CLIENTS_MASK))
220*7c478bd9Sstevel@tonic-gate #define	GET_CLIENT_SOCKET(ch)		(((ch)>>16)&CS_MAX_SOCKETS_MASK)
221*7c478bd9Sstevel@tonic-gate #define	GET_CLIENT_FUNCTION(ch)		(((ch)>>24)&CS_MAX_FUNCTIONS_MASK)
222*7c478bd9Sstevel@tonic-gate #define	GET_CLIENT_MINOR(ch)		((ch)&CS_MAX_CLIENTS_MASK)
224*7c478bd9Sstevel@tonic-gate /*
225*7c478bd9Sstevel@tonic-gate  * Socket number macros. These are used by Socket Services, CSI
226*7c478bd9Sstevel@tonic-gate  *	drivers and the "super-client" driver to specify which
227*7c478bd9Sstevel@tonic-gate  *	socket and function number on that socket they wish to
228*7c478bd9Sstevel@tonic-gate  *	manipulate. This socket number encoding is typically passed
229*7c478bd9Sstevel@tonic-gate  *	to various Card Services functions by these drivers.
230*7c478bd9Sstevel@tonic-gate  *
231*7c478bd9Sstevel@tonic-gate  *	The encoding of the socket number is:
232*7c478bd9Sstevel@tonic-gate  *
233*7c478bd9Sstevel@tonic-gate  *		xxxxxxxx | xxxxgfff | xxxxxxxx | xsssssss
234*7c478bd9Sstevel@tonic-gate  *
235*7c478bd9Sstevel@tonic-gate  *	g - global CIS bit
236*7c478bd9Sstevel@tonic-gate  *	f - function number bit
237*7c478bd9Sstevel@tonic-gate  *	s - socket number bit
238*7c478bd9Sstevel@tonic-gate  *	x - don't care bits
239*7c478bd9Sstevel@tonic-gate  */
240*7c478bd9Sstevel@tonic-gate #define	CS_GET_SOCKET_NUMBER(s)		((s)&CS_MAX_SOCKETS_MASK)
241*7c478bd9Sstevel@tonic-gate #define	CS_GET_FUNCTION_NUMBER(s)	(((s)>>16)&(CS_MAX_FUNCTIONS_MASK | \
242*7c478bd9Sstevel@tonic-gate 							CIS_MAX_FUNCTIONS))
243*7c478bd9Sstevel@tonic-gate #define	CS_SET_SOCKET_NUMBER(s)		((s)&CS_MAX_SOCKETS_MASK)
244*7c478bd9Sstevel@tonic-gate #define	CS_SET_FUNCTION_NUMBER(f)	(((f)&(CS_MAX_FUNCTIONS_MASK | \
245*7c478bd9Sstevel@tonic-gate 						CIS_MAX_FUNCTIONS))<<16)
246*7c478bd9Sstevel@tonic-gate #define	CS_MAKE_SOCKET_NUMBER(s, f)	(CS_SET_SOCKET_NUMBER(s) | \
247*7c478bd9Sstevel@tonic-gate 						CS_SET_FUNCTION_NUMBER(f))
249*7c478bd9Sstevel@tonic-gate /*
250*7c478bd9Sstevel@tonic-gate  * DIP2SOCKET_NUM(dip) - this macro gets the PCM_DEV_SOCKET property from
251*7c478bd9Sstevel@tonic-gate  *	the passed dip.  If the property can't be found, then the default
252*7c478bd9Sstevel@tonic-gate  *	value of cs_globals.max_socket_num is returned.
253*7c478bd9Sstevel@tonic-gate  */
254*7c478bd9Sstevel@tonic-gate #define	DIP2SOCKET_NUM(dip)		ddi_getprop(DDI_DEV_T_NONE, dip,\
255*7c478bd9Sstevel@tonic-gate 						(DDI_PROP_CANSLEEP |	\
256*7c478bd9Sstevel@tonic-gate 							DDI_PROP_NOTPROM), \
257*7c478bd9Sstevel@tonic-gate 						PCM_DEV_SOCKET,		\
258*7c478bd9Sstevel@tonic-gate 						cs_globals.max_socket_num)
260*7c478bd9Sstevel@tonic-gate /*
261*7c478bd9Sstevel@tonic-gate  * Range checking macros
262*7c478bd9Sstevel@tonic-gate  *
263*7c478bd9Sstevel@tonic-gate  * CHECK_SOCKET_NUM(socket_number, max_sockets) returns 1 if
264*7c478bd9Sstevel@tonic-gate  *	socket_number is in range
265*7c478bd9Sstevel@tonic-gate  */
266*7c478bd9Sstevel@tonic-gate #define	CHECK_SOCKET_NUM(sn, ms)	(((sn) >= (ms))?0:1)
268*7c478bd9Sstevel@tonic-gate /*
269*7c478bd9Sstevel@tonic-gate  * window macros
270*7c478bd9Sstevel@tonic-gate  *
271*7c478bd9Sstevel@tonic-gate  * These all expect that the window has been validated as a valid
272*7c478bd9Sstevel@tonic-gate  *	window (i.e. CW_WINDOW_VALID is set in window state)
273*7c478bd9Sstevel@tonic-gate  *
274*7c478bd9Sstevel@tonic-gate  * Note that WINDOW_FOR_SOCKET expects a socket mask for the wsm
275*7c478bd9Sstevel@tonic-gate  *	parameter (this is a socket_enum_t type, and NOT just a
276*7c478bd9Sstevel@tonic-gate  *	plain old uint32_t)
277*7c478bd9Sstevel@tonic-gate  */
278*7c478bd9Sstevel@tonic-gate #define	WINDOW_FOR_SOCKET(wsm, sn)	((wsm)[sn/PR_WORDSIZE] & \
279*7c478bd9Sstevel@tonic-gate 						(1 << ((sn) & PR_MASK)))
280*7c478bd9Sstevel@tonic-gate #define	WINDOW_AVAILABLE_FOR_MEM(cwp)	(!(cwp->state & CW_WIN_IN_USE))
281*7c478bd9Sstevel@tonic-gate #define	WINDOW_AVAILABLE_FOR_IO(cwp)	\
282*7c478bd9Sstevel@tonic-gate 		(!(cwp->state & (CW_CIS | CW_MEM | CW_ALLOCATED)))
284*7c478bd9Sstevel@tonic-gate /*
285*7c478bd9Sstevel@tonic-gate  * IO Base and NumPorts address frobnitz macros
286*7c478bd9Sstevel@tonic-gate  */
287*7c478bd9Sstevel@tonic-gate #define	IOADDR_FROBNITZ(Base, IOAddrLines)	(Base&((1<<IOAddrLines)-1))
288*7c478bd9Sstevel@tonic-gate #define	IONUMPORTS_FROBNITZ(np)			(((np)&1)?((np)+1):(np))
290*7c478bd9Sstevel@tonic-gate /*
291*7c478bd9Sstevel@tonic-gate  * Structure that contains offsets to the card's configuration registers
292*7c478bd9Sstevel@tonic-gate  *	as well as copies of the data written to them in RequestConfiguration.
293*7c478bd9Sstevel@tonic-gate  *	We use an offset per register approach since not all cards have
294*7c478bd9Sstevel@tonic-gate  *	all registers implemented, and by specifying a NULL register offset,
295*7c478bd9Sstevel@tonic-gate  *	we know not to try to access that register.
296*7c478bd9Sstevel@tonic-gate  */
297*7c478bd9Sstevel@tonic-gate typedef struct config_regs_t {
298*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	cor;		/* Configuration Option Register */
299*7c478bd9Sstevel@tonic-gate 	uint32_t	cor_p;
300*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	ccsr;		/* Configuration and Status Register */
301*7c478bd9Sstevel@tonic-gate 	uint32_t	ccsr_p;
302*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	prr;		/* Pin Replacement Register */
303*7c478bd9Sstevel@tonic-gate 	uint32_t	prr_p;
304*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	scr;		/* Socket and Copy Register */
305*7c478bd9Sstevel@tonic-gate 	uint32_t	scr_p;
306*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	exstat;		/* Extended Status Register */
307*7c478bd9Sstevel@tonic-gate 	uint32_t	exstat_p;
308*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase0;	/* IO Base 0 Register */
309*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase0_p;
310*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase1;	/* IO Base 1 Register */
311*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase1_p;
312*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase2;	/* IO Base 2 Register */
313*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase2_p;
314*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase3;	/* IO Base 3 Register */
315*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase3_p;
316*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iolimit;	/* IO Limit Register */
317*7c478bd9Sstevel@tonic-gate 	uint32_t	iolimit_p;
318*7c478bd9Sstevel@tonic-gate } config_regs_t;
320*7c478bd9Sstevel@tonic-gate /*
321*7c478bd9Sstevel@tonic-gate  * Macro to make calling the client's event handler look like a function.
322*7c478bd9Sstevel@tonic-gate  */
323*7c478bd9Sstevel@tonic-gate #define	CLIENT_EVENT_CALLBACK(cp, event, pri)		\
324*7c478bd9Sstevel@tonic-gate 	    (cp)->event_callback_handler(event, pri,	\
325*7c478bd9Sstevel@tonic-gate 			&(cp)->event_callback_args)
327*7c478bd9Sstevel@tonic-gate /*
328*7c478bd9Sstevel@tonic-gate  * Macro to return event in PRR - this also clears the changed bit if
329*7c478bd9Sstevel@tonic-gate  *	the event occured.
330*7c478bd9Sstevel@tonic-gate  */
331*7c478bd9Sstevel@tonic-gate #define	PRR_EVENT(prrx, pe, ps, ce, re)	\
332*7c478bd9Sstevel@tonic-gate 	if (prrx & pe) {		\
333*7c478bd9Sstevel@tonic-gate 	    if (prrx & ps)		\
334*7c478bd9Sstevel@tonic-gate 		(re) |= ce;		\
335*7c478bd9Sstevel@tonic-gate 	    prrx &= ~pe;		\
336*7c478bd9Sstevel@tonic-gate 	    prrx |= ps;			\
337*7c478bd9Sstevel@tonic-gate 	}
339*7c478bd9Sstevel@tonic-gate /*
340*7c478bd9Sstevel@tonic-gate  * io_alloc_t struct used to keep track of a client's IO window allocation
341*7c478bd9Sstevel@tonic-gate  */
342*7c478bd9Sstevel@tonic-gate typedef struct io_alloc_t {
343*7c478bd9Sstevel@tonic-gate 	uint32_t	Window1;	/* allocated IO window no. for set #1 */
344*7c478bd9Sstevel@tonic-gate 	baseaddru_t	BasePort1;	/* 1st IO range base address or port */
345*7c478bd9Sstevel@tonic-gate 	uint32_t	NumPorts1;	/* 1st IO range no. contiguous ports */
346*7c478bd9Sstevel@tonic-gate 	uint32_t	Attributes1;	/* 1st IO range attributes */
347*7c478bd9Sstevel@tonic-gate 	uint32_t	Window2;	/* allocated IO window no. for set #2 */
348*7c478bd9Sstevel@tonic-gate 	baseaddru_t	BasePort2;	/* s2nd IO range base address or port */
349*7c478bd9Sstevel@tonic-gate 	uint32_t	NumPorts2;	/* 2nd IO range no. contiguous ports */
350*7c478bd9Sstevel@tonic-gate 	uint32_t	Attributes2;	/* second IO range attributes */
351*7c478bd9Sstevel@tonic-gate 	uint32_t	IOAddrLines;	/* number of IO address lines decoded */
352*7c478bd9Sstevel@tonic-gate } io_alloc_t;
354*7c478bd9Sstevel@tonic-gate /*
355*7c478bd9Sstevel@tonic-gate  * irq_alloc_t structure used to keep track of a client's IRQ allocation
356*7c478bd9Sstevel@tonic-gate  */
357*7c478bd9Sstevel@tonic-gate typedef struct irq_alloc_t {
358*7c478bd9Sstevel@tonic-gate 	uint32_t	Attributes;	/* IRQ attribute flags */
359*7c478bd9Sstevel@tonic-gate 	uint32_t	irq;		/* assigned IRQ number */
360*7c478bd9Sstevel@tonic-gate 	uint32_t	handler_id;	/* IRQ handler ID for this IRQ */
361*7c478bd9Sstevel@tonic-gate 	f_t		*irq_handler;
362*7c478bd9Sstevel@tonic-gate 	void		*irq_handler_arg1;
363*7c478bd9Sstevel@tonic-gate 	void		*irq_handler_arg2;
364*7c478bd9Sstevel@tonic-gate } irq_alloc_t;
366*7c478bd9Sstevel@tonic-gate /*
367*7c478bd9Sstevel@tonic-gate  * The client data structure
368*7c478bd9Sstevel@tonic-gate  */
369*7c478bd9Sstevel@tonic-gate typedef struct client_t {
370*7c478bd9Sstevel@tonic-gate 	client_handle_t	client_handle;	/* this client's client handle */
371*7c478bd9Sstevel@tonic-gate 	unsigned	flags;		/* client flags */
372*7c478bd9Sstevel@tonic-gate 	/* resource control */
373*7c478bd9Sstevel@tonic-gate 	uint32_t	memwin_count;	/* number of mem windows allocated */
374*7c478bd9Sstevel@tonic-gate 	io_alloc_t	io_alloc;	/* IO resource allocations */
375*7c478bd9Sstevel@tonic-gate 	irq_alloc_t	irq_alloc;	/* IRQ resource allocations */
376*7c478bd9Sstevel@tonic-gate 	/* event support */
377*7c478bd9Sstevel@tonic-gate 	uint32_t	event_mask;	/* client event mask */
378*7c478bd9Sstevel@tonic-gate 	uint32_t	global_mask;	/* client global event mask */
379*7c478bd9Sstevel@tonic-gate 	uint32_t	events;		/* current events pending */
380*7c478bd9Sstevel@tonic-gate 	uint32_t	pending_events;	/* events pending in RegisterClient */
381*7c478bd9Sstevel@tonic-gate 	csfunction_t	*event_callback_handler;
382*7c478bd9Sstevel@tonic-gate 	event_callback_args_t	event_callback_args;
383*7c478bd9Sstevel@tonic-gate 	/* config registers support */
384*7c478bd9Sstevel@tonic-gate 	config_regs_t	config_regs;	/* pointers to config registers */
385*7c478bd9Sstevel@tonic-gate 	uint32_t	config_regs_offset; /* offset from start of AM */
386*7c478bd9Sstevel@tonic-gate 	unsigned	pin;		/* valid bits in PRR */
387*7c478bd9Sstevel@tonic-gate 	uint32_t	present;	/* which config registers present */
388*7c478bd9Sstevel@tonic-gate 	/* DDI support */
389*7c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;		/* this client's dip */
390*7c478bd9Sstevel@tonic-gate 	char		*driver_name;	/* client's driver name */
391*7c478bd9Sstevel@tonic-gate 	int32_t		instance;	/* client's driver instance */
392*7c478bd9Sstevel@tonic-gate 	/* list control */
393*7c478bd9Sstevel@tonic-gate 	struct client_t	*next;		/* next client pointer */
394*7c478bd9Sstevel@tonic-gate 	struct client_t	*prev;		/* previous client pointer */
395*7c478bd9Sstevel@tonic-gate } client_t;
397*7c478bd9Sstevel@tonic-gate /*
398*7c478bd9Sstevel@tonic-gate  * Flags for client structure - note that we share the client_t->flags
399*7c478bd9Sstevel@tonic-gate  *	member with the definitions in cs.h that are used by the
400*7c478bd9Sstevel@tonic-gate  *	RegisterClient function.
401*7c478bd9Sstevel@tonic-gate  *
402*7c478bd9Sstevel@tonic-gate  * We can start our flags from 0x00001000 and on up.
403*7c478bd9Sstevel@tonic-gate  */
404*7c478bd9Sstevel@tonic-gate #define	REQ_CONFIGURATION_DONE	0x00001000	/* RequestConfiguration done */
405*7c478bd9Sstevel@tonic-gate #define	REQ_SOCKET_MASK_DONE	0x00002000	/* RequestSocketMask done */
406*7c478bd9Sstevel@tonic-gate #define	REQ_IO_DONE		0x00004000	/* RequestIO done */
407*7c478bd9Sstevel@tonic-gate #define	REQ_IRQ_DONE		0x00008000	/* RequestIRQ done */
408*7c478bd9Sstevel@tonic-gate #define	CLIENT_SUPER_CLIENT	0x00010000	/* "super-client" client */
409*7c478bd9Sstevel@tonic-gate #define	CLIENT_CSI_CLIENT	0x00020000	/* CSI client */
410*7c478bd9Sstevel@tonic-gate #define	CLIENT_CARD_INSERTED	0x00100000	/* current card for client */
411*7c478bd9Sstevel@tonic-gate #define	CLIENT_SENT_INSERTION	0x00200000	/* send CARD_INSERTION */
412*7c478bd9Sstevel@tonic-gate #define	CLIENT_MTD_IN_PROGRESS	0x01000000	/* MTD op in progress */
413*7c478bd9Sstevel@tonic-gate #define	CLIENT_IO_ALLOCATED	0x02000000	/* IO resources allocated */
414*7c478bd9Sstevel@tonic-gate #define	CLIENT_IRQ_ALLOCATED	0x04000000	/* IRQ resources allocated */
415*7c478bd9Sstevel@tonic-gate #define	CLIENT_WIN_ALLOCATED	0x08000000	/* window resources allocated */
417*7c478bd9Sstevel@tonic-gate #ifdef	USE_IOMMAP_WINDOW
418*7c478bd9Sstevel@tonic-gate /*
419*7c478bd9Sstevel@tonic-gate  * io_mmap_window_t structure that describes the memory-mapped IO
420*7c478bd9Sstevel@tonic-gate  *	window on this socket
421*7c478bd9Sstevel@tonic-gate  */
422*7c478bd9Sstevel@tonic-gate typedef struct io_mmap_window_t {
423*7c478bd9Sstevel@tonic-gate 	uint32_t		flags;	/* window flags */
424*7c478bd9Sstevel@tonic-gate 	uint32_t		number;	/* IO window number */
425*7c478bd9Sstevel@tonic-gate 	uint32_t		size;	/* size of mapped IO window */
426*7c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	handle;	/* window mapped base address */
427*7c478bd9Sstevel@tonic-gate 	uint32_t		count;	/* referance count */
428*7c478bd9Sstevel@tonic-gate } io_mmap_window_t;
429*7c478bd9Sstevel@tonic-gate #endif	/* USE_IOMMAP_WINDOW */
431*7c478bd9Sstevel@tonic-gate /*
432*7c478bd9Sstevel@tonic-gate  * cis_info_t structure used to hold per-socket CIS information
433*7c478bd9Sstevel@tonic-gate  */
434*7c478bd9Sstevel@tonic-gate typedef struct cis_info_t {
435*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* CIS-specific flags */
436*7c478bd9Sstevel@tonic-gate 	cistpl_t	*cis;		/* CIS linked lists */
437*7c478bd9Sstevel@tonic-gate 	uint32_t	nchains;	/* number of tuple chains in CIS */
438*7c478bd9Sstevel@tonic-gate 	uint32_t	ntuples;	/* number of tuples in CIS */
439*7c478bd9Sstevel@tonic-gate } cis_info_t;
441*7c478bd9Sstevel@tonic-gate /*
442*7c478bd9Sstevel@tonic-gate  * cs_adapter_t structure used to hold per-socket
443*7c478bd9Sstevel@tonic-gate  *	adapter-specific info
444*7c478bd9Sstevel@tonic-gate  */
445*7c478bd9Sstevel@tonic-gate typedef struct cs_adapter_t {
446*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* adapter flags */
447*7c478bd9Sstevel@tonic-gate 	char		name[MODMAXNAMELEN]; /* adapter module name */
448*7c478bd9Sstevel@tonic-gate 	uint32_t	major;		/* adapter major number */
449*7c478bd9Sstevel@tonic-gate 	uint32_t	minor;		/* adapter minor number */
450*7c478bd9Sstevel@tonic-gate 	uint32_t	instance;	/* instance number of this adapter */
451*7c478bd9Sstevel@tonic-gate 	uint32_t	number;		/* canonical adapter number */
452*7c478bd9Sstevel@tonic-gate 	uint32_t	num_sockets;	/* # sockets on this adapter */
453*7c478bd9Sstevel@tonic-gate 	uint32_t	first_socket;	/* first socket # on this adapter */
454*7c478bd9Sstevel@tonic-gate } cs_adapter_t;
456*7c478bd9Sstevel@tonic-gate /*
457*7c478bd9Sstevel@tonic-gate  * The per-socket structure.
458*7c478bd9Sstevel@tonic-gate  */
459*7c478bd9Sstevel@tonic-gate typedef struct cs_socket_t {
460*7c478bd9Sstevel@tonic-gate 	unsigned	socket_num;	/* socket number */
461*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* socket flags */
462*7c478bd9Sstevel@tonic-gate 	uint32_t	init_state;	/* cs_init state */
463*7c478bd9Sstevel@tonic-gate 	cs_adapter_t	adapter;	/* adapter info */
464*7c478bd9Sstevel@tonic-gate 	/* socket thread control and status */
465*7c478bd9Sstevel@tonic-gate 	kthread_t	*event_thread;	/* per-socket work thread */
466*7c478bd9Sstevel@tonic-gate 	uint32_t	thread_state;	/* socket thread state flags */
467*7c478bd9Sstevel@tonic-gate 	kmutex_t	lock;		/* protects events and clients */
468*7c478bd9Sstevel@tonic-gate 	kcondvar_t	thread_cv;	/* event handling synchronization */
469*7c478bd9Sstevel@tonic-gate 	kcondvar_t	caller_cv;	/* event handling synchronization */
470*7c478bd9Sstevel@tonic-gate 	kcondvar_t	reset_cv;	/* for use after card RESET */
471*7c478bd9Sstevel@tonic-gate 	uint32_t	events;		/* socket events */
472*7c478bd9Sstevel@tonic-gate 	uint32_t	event_mask;	/* socket event mask */
473*7c478bd9Sstevel@tonic-gate 	ddi_softintr_t	softint_id;	/* soft interrupt handler ID */
474*7c478bd9Sstevel@tonic-gate 	timeout_id_t	rdybsy_tmo_id;	/* timer ID for READY/BUSY timer */
475*7c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t	*iblk;	/* event iblk cookie */
476*7c478bd9Sstevel@tonic-gate 	ddi_idevice_cookie_t	*idev;	/* event idev cookie */
477*7c478bd9Sstevel@tonic-gate 	callb_cpr_t	cprinfo_cs;	/* CPR cookie for cs_event_thread */
478*7c478bd9Sstevel@tonic-gate 	callb_cpr_t	cprinfo_ss;	/* CPR cookie for cs_ss_thread */
479*7c478bd9Sstevel@tonic-gate 	/* client management */
480*7c478bd9Sstevel@tonic-gate 	client_t	*client_list;	/* clients on this socket */
481*7c478bd9Sstevel@tonic-gate 	unsigned	next_cl_minor;	/* next available client minor num */
482*7c478bd9Sstevel@tonic-gate 	kmutex_t	client_lock;	/* protects client list */
483*7c478bd9Sstevel@tonic-gate 	uint32_t	num_clients;	/* number of clients on this socket */
484*7c478bd9Sstevel@tonic-gate 	/* CIS support */
485*7c478bd9Sstevel@tonic-gate 	uint32_t	cis_win_num;	/* CIS window number */
486*7c478bd9Sstevel@tonic-gate 	unsigned	cis_win_size;	/* CIS window size */
487*7c478bd9Sstevel@tonic-gate 	uint32_t	cis_flags;
488*7c478bd9Sstevel@tonic-gate 	uint32_t	nfuncs;		/* number of functions */
489*7c478bd9Sstevel@tonic-gate 	cis_info_t	cis[CS_MAX_CIS]; /* CIS information */
490*7c478bd9Sstevel@tonic-gate 	kmutex_t	cis_lock;	/* protects CIS */
491*7c478bd9Sstevel@tonic-gate #ifdef	USE_IOMMAP_WINDOW
492*7c478bd9Sstevel@tonic-gate 	/* memory mapped IO window support */
493*7c478bd9Sstevel@tonic-gate 	io_mmap_window_t *io_mmap_window;
494*7c478bd9Sstevel@tonic-gate #endif	/* USE_IOMMAP_WINDOW */
495*7c478bd9Sstevel@tonic-gate 	/* Socket Services work thread control and status */
496*7c478bd9Sstevel@tonic-gate 	kthread_t	*ss_thread;	/* SS work thread */
497*7c478bd9Sstevel@tonic-gate 	uint32_t	ss_thread_state; /* SS work thread state */
498*7c478bd9Sstevel@tonic-gate 	kcondvar_t	ss_thread_cv;	/* SS work thread synchronization */
499*7c478bd9Sstevel@tonic-gate 	kcondvar_t	ss_caller_cv;	/* SS work thread synchronization */
500*7c478bd9Sstevel@tonic-gate 	kmutex_t	ss_thread_lock;	/* protects SS work thread state */
501*7c478bd9Sstevel@tonic-gate 	struct cs_socket_t	*next;	/* next socket in list */
502*7c478bd9Sstevel@tonic-gate } cs_socket_t;
504*7c478bd9Sstevel@tonic-gate /*
505*7c478bd9Sstevel@tonic-gate  * cs_socket_t->flags flags
506*7c478bd9Sstevel@tonic-gate  */
507*7c478bd9Sstevel@tonic-gate #define	SOCKET_CARD_INSERTED		0x00000001	/* card is inserted */
508*7c478bd9Sstevel@tonic-gate #define	SOCKET_IS_IO			0x00000002	/* socket in IO mode */
509*7c478bd9Sstevel@tonic-gate #define	SOCKET_UNLOAD_MODULE		0x00000004	/* want to unload CS */
510*7c478bd9Sstevel@tonic-gate #define	SOCKET_NEEDS_THREAD		0x00000008	/* wake event thread */
511*7c478bd9Sstevel@tonic-gate #define	SOCKET_IS_VALID			0x00000020	/* socket OK to use */
513*7c478bd9Sstevel@tonic-gate /*
514*7c478bd9Sstevel@tonic-gate  * cs_socket_t->thread_state and cs_socket_t->ss_thread_state flags
515*7c478bd9Sstevel@tonic-gate  */
517*7c478bd9Sstevel@tonic-gate /* generic for all threads */
518*7c478bd9Sstevel@tonic-gate #define	SOCKET_THREAD_EXIT		0x00000001	/* exit event thread */
520*7c478bd9Sstevel@tonic-gate /* only used for per-socket event thread */
521*7c478bd9Sstevel@tonic-gate #define	SOCKET_WAIT_FOR_READY		0x00001000	/* waiting for READY */
522*7c478bd9Sstevel@tonic-gate #define	SOCKET_RESET_TIMER		0x00002000	/* RESET timer */
523*7c478bd9Sstevel@tonic-gate #define	SOCKET_WAIT_SYNC		0x00004000	/* SYNC */
525*7c478bd9Sstevel@tonic-gate /* only used for Socket Services work thread */
526*7c478bd9Sstevel@tonic-gate #define	SOCKET_THREAD_CSCISInit		0x00100000	/* call CSCISInit */
528*7c478bd9Sstevel@tonic-gate /*
529*7c478bd9Sstevel@tonic-gate  * cs_socket_t->cis_flags and cs_socket_t->cis_info_t->flags flags
530*7c478bd9Sstevel@tonic-gate  */
531*7c478bd9Sstevel@tonic-gate #define	CW_VALID_CIS			0x00000001	/* valid CIS */
532*7c478bd9Sstevel@tonic-gate #define	CW_MULTI_FUNCTION_CIS		0x00000002	/* multifunction card */
533*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_A_FOUND		0x00000004	/* CISTPL_LONGLINK_A */
534*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_C_FOUND		0x00000008	/* CISTP_LONGLINK_C */
535*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_MFC_FOUND		0x00000010	/* LONGLINK_MFC */
536*7c478bd9Sstevel@tonic-gate #define	CW_CHECK_LINKTARGET		0x00000020	/* check linktarget */
537*7c478bd9Sstevel@tonic-gate #define	CW_RET_ON_LINKTARGET_ERROR	0x00000040	/* linktarget invalid */
538*7c478bd9Sstevel@tonic-gate #define	CW_CHECK_PRIMARY_CHAIN		0x00000080	/* check for primary */
539*7c478bd9Sstevel@tonic-gate 							/* chain tuples */
541*7c478bd9Sstevel@tonic-gate /*
542*7c478bd9Sstevel@tonic-gate  * CW_LONGLINK_FOUND - a combination of the various CW_LONGLINK_XXX_FOUND
543*7c478bd9Sstevel@tonic-gate  *			flags used to make the code less dense.
544*7c478bd9Sstevel@tonic-gate  */
545*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_FOUND		(CW_LONGLINK_A_FOUND |	\
546*7c478bd9Sstevel@tonic-gate 					CW_LONGLINK_C_FOUND |	\
547*7c478bd9Sstevel@tonic-gate 					CW_LONGLINK_MFC_FOUND)
549*7c478bd9Sstevel@tonic-gate /*
550*7c478bd9Sstevel@tonic-gate  * macro to test for a valid CIS window on a socket
551*7c478bd9Sstevel@tonic-gate  */
552*7c478bd9Sstevel@tonic-gate #define	SOCKET_HAS_CIS_WINDOW(sp)	(sp->cis_win_num != PCMCIA_MAX_WINDOWS)
554*7c478bd9Sstevel@tonic-gate /*
555*7c478bd9Sstevel@tonic-gate  * cs_socket_t->init_state flags - these flags are used to keep track of what
556*7c478bd9Sstevel@tonic-gate  *	was allocated in cs_init so that things can be deallocated properly
557*7c478bd9Sstevel@tonic-gate  *	in cs_deinit.
558*7c478bd9Sstevel@tonic-gate  */
559*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_MUTEX		0x00000001	/* mutexii are OK */
560*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_CV		0x00000002	/* cvii are OK */
561*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_THREAD	0x00000004	/* thread OK */
562*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_READY		0x00000008	/* socket OK */
563*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_SS_THREAD	0x00000010	/* SS thread OK */
564*7c478bd9Sstevel@tonic-gate /*
565*7c478bd9Sstevel@tonic-gate  * While this next flag doesn't really describe a per-socket resource,
566*7c478bd9Sstevel@tonic-gate  *	we still set it for each socket.  When the soft interrupt handler
567*7c478bd9Sstevel@tonic-gate  *	finally gets removed in cs_deinit, this flag will get cleared.
568*7c478bd9Sstevel@tonic-gate  *	The value of this flag should follow the previous SOCKET_INIT
569*7c478bd9Sstevel@tonic-gate  *	flag values.
570*7c478bd9Sstevel@tonic-gate  */
571*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_SOFTINTR	0x00000020	/* softintr handler */
573*7c478bd9Sstevel@tonic-gate /*
574*7c478bd9Sstevel@tonic-gate  * Macro to create a socket event thread.
575*7c478bd9Sstevel@tonic-gate  */
576*7c478bd9Sstevel@tonic-gate #define	CS_THREAD_PRIORITY		(v.v_maxsyspri - 4)
577*7c478bd9Sstevel@tonic-gate #define	CREATE_SOCKET_EVENT_THREAD(eh, csp)			\
578*7c478bd9Sstevel@tonic-gate 	thread_create(NULL, 0, eh, (void *)csp,			\
579*7c478bd9Sstevel@tonic-gate 	0, &p0, TS_RUN, CS_THREAD_PRIORITY)
581*7c478bd9Sstevel@tonic-gate /*
582*7c478bd9Sstevel@tonic-gate  * The per-window structure.
583*7c478bd9Sstevel@tonic-gate  */
584*7c478bd9Sstevel@tonic-gate typedef struct cs_window_t {
585*7c478bd9Sstevel@tonic-gate 	uint32_t	window_num;	/* window number */
586*7c478bd9Sstevel@tonic-gate 	window_handle_t	window_handle;	/* unique window handle */
587*7c478bd9Sstevel@tonic-gate 	client_handle_t	client_handle;	/* owner of this window */
588*7c478bd9Sstevel@tonic-gate 	unsigned	socket_num;	/* socket number */
589*7c478bd9Sstevel@tonic-gate 	unsigned	state;		/* window state flags */
590*7c478bd9Sstevel@tonic-gate 	struct cs_window_t	*next;	/* next window in list */
591*7c478bd9Sstevel@tonic-gate } cs_window_t;
593*7c478bd9Sstevel@tonic-gate /*
594*7c478bd9Sstevel@tonic-gate  * Window structure state flags - if none of the bits in the
595*7c478bd9Sstevel@tonic-gate  *	CW_WIN_IN_USE mask are set AND if CW_WINDOW_VALID is set,
596*7c478bd9Sstevel@tonic-gate  *	it means that this window is available and not being used
597*7c478bd9Sstevel@tonic-gate  *	by anyone.
598*7c478bd9Sstevel@tonic-gate  * Setting the CW_ALLOCATED will prevent the window from being found
599*7c478bd9Sstevel@tonic-gate  *	as an available window for memory or IO; since memory windows
600*7c478bd9Sstevel@tonic-gate  *	are not shared between clients, RequestWindow will always set
601*7c478bd9Sstevel@tonic-gate  *	the CW_ALLOCATED flag when it has assigned a memory window to
602*7c478bd9Sstevel@tonic-gate  *	a client.  Since we can sometimes share IO windows, RequestIO
603*7c478bd9Sstevel@tonic-gate  *	will only set the CW_ALLOCATED flag if it doesn't want the IO
604*7c478bd9Sstevel@tonic-gate  *	window to be used by other calls to RequestIO.
605*7c478bd9Sstevel@tonic-gate  * When CW_WINDOW_VALID is set, it means that this is a valid window
606*7c478bd9Sstevel@tonic-gate  *	that has been added by the framework and can be used. If this
607*7c478bd9Sstevel@tonic-gate  *	bit is not set, this window can not be used at all.
608*7c478bd9Sstevel@tonic-gate  */
609*7c478bd9Sstevel@tonic-gate #define	CW_ALLOCATED	0x00000001	/* window is allocated  */
610*7c478bd9Sstevel@tonic-gate #define	CW_CIS		0x00000002	/* window being used as CIS window */
611*7c478bd9Sstevel@tonic-gate #define	CW_MEM		0x00000004	/* window being used as mem window */
612*7c478bd9Sstevel@tonic-gate #define	CW_IO		0x00000008	/* window being used as IO window */
613*7c478bd9Sstevel@tonic-gate #define	CW_WIN_IN_USE	0x0000ffff	/* window in use mask */
614*7c478bd9Sstevel@tonic-gate #define	CW_WINDOW_VALID	0x00010000	/* window is valid */
616*7c478bd9Sstevel@tonic-gate /*
617*7c478bd9Sstevel@tonic-gate  * window handle defines - the WINDOW_HANDLE_MASK implies the maximum number
618*7c478bd9Sstevel@tonic-gate  *	of windows allowed
619*7c478bd9Sstevel@tonic-gate  */
620*7c478bd9Sstevel@tonic-gate #define	WINDOW_HANDLE_MAGIC	0x574d0000
621*7c478bd9Sstevel@tonic-gate #define	WINDOW_HANDLE_MASK	0x0000ffff
622*7c478bd9Sstevel@tonic-gate #define	GET_WINDOW_NUMBER(wh)	((wh) & WINDOW_HANDLE_MASK)
623*7c478bd9Sstevel@tonic-gate #define	GET_WINDOW_MAGIC(wh)	((wh) & ~WINDOW_HANDLE_MASK)
625*7c478bd9Sstevel@tonic-gate /*
626*7c478bd9Sstevel@tonic-gate  * The client type structures, used to sequence events to clients on a
627*7c478bd9Sstevel@tonic-gate  *	socket. The "type" flags are the same as are used for the
628*7c478bd9Sstevel@tonic-gate  *	RegisterClient function.
629*7c478bd9Sstevel@tonic-gate  */
630*7c478bd9Sstevel@tonic-gate typedef struct client_types_t {
631*7c478bd9Sstevel@tonic-gate 	uint32_t		type;
632*7c478bd9Sstevel@tonic-gate 	uint32_t		order;
633*7c478bd9Sstevel@tonic-gate 	struct client_types_t	*next;
634*7c478bd9Sstevel@tonic-gate } client_types_t;
636*7c478bd9Sstevel@tonic-gate /*
637*7c478bd9Sstevel@tonic-gate  * Flags that specify the order of client event notifications for the
638*7c478bd9Sstevel@tonic-gate  *	client_types_t structure.
639*7c478bd9Sstevel@tonic-gate  */
640*7c478bd9Sstevel@tonic-gate #define	CLIENT_EVENTS_LIFO	0x00000001
641*7c478bd9Sstevel@tonic-gate #define	CLIENT_EVENTS_FIFO	0x00000002
643*7c478bd9Sstevel@tonic-gate /*
644*7c478bd9Sstevel@tonic-gate  * This is a structure that CS uses to keep track of items that are global
645*7c478bd9Sstevel@tonic-gate  *	to all functions in the module.
646*7c478bd9Sstevel@tonic-gate  */
647*7c478bd9Sstevel@tonic-gate typedef struct cs_globals_t {
648*7c478bd9Sstevel@tonic-gate 	cs_socket_t	*sp;		/* head of socket list */
649*7c478bd9Sstevel@tonic-gate 	cs_window_t	*cw;		/* head of window list */
650*7c478bd9Sstevel@tonic-gate 	kmutex_t	global_lock;	/* protects this struct */
651*7c478bd9Sstevel@tonic-gate 	kmutex_t	window_lock;	/* protects cs_windows */
652*7c478bd9Sstevel@tonic-gate 	ddi_softintr_t	softint_id;	/* soft interrupt handler id */
653*7c478bd9Sstevel@tonic-gate 	timeout_id_t	sotfint_tmo;	/* soft interrupt handler timeout id */
654*7c478bd9Sstevel@tonic-gate 	uint32_t	init_state;	/* flags set in cs_init */
655*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* general global flags */
656*7c478bd9Sstevel@tonic-gate 	uint32_t	max_socket_num;	/* highest socket number plus one */
657*7c478bd9Sstevel@tonic-gate 	uint32_t	num_sockets;	/* total number of sockets */
658*7c478bd9Sstevel@tonic-gate 	uint32_t	num_windows;	/* total number of windows */
659*7c478bd9Sstevel@tonic-gate 	struct sclient_list_t	*sclient_list;
660*7c478bd9Sstevel@tonic-gate } cs_globals_t;
662*7c478bd9Sstevel@tonic-gate /*
663*7c478bd9Sstevel@tonic-gate  * Flags for cs_globals_t->init_state
664*7c478bd9Sstevel@tonic-gate  */
665*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_SOFTINTR	0x00010000	/* softintr handler */
666*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_MUTEX		0x00020000	/* global mutex init */
667*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_NO_CLIENTS	0x00040000	/* no new clients */
668*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_UNLOADING	0x00080000	/* cs_deinit running */
669*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_SS_READY	0x00100000	/* SS ready for */
670*7c478bd9Sstevel@tonic-gate 							/* callbacks */
671*7c478bd9Sstevel@tonic-gate /*
672*7c478bd9Sstevel@tonic-gate  * Flags for cs_globals_t->flags
673*7c478bd9Sstevel@tonic-gate  */
674*7c478bd9Sstevel@tonic-gate #define	GLOBAL_SUPER_CLIENT_REGISTERED	0x00000001	/* "super-client" reg */
675*7c478bd9Sstevel@tonic-gate #define	GLOBAL_IN_SOFTINTR		0x00000002	/* in soft int code */
677*7c478bd9Sstevel@tonic-gate /*
678*7c478bd9Sstevel@tonic-gate  * sclient_reg_t struct for RegisterClient when a "super-client" is
679*7c478bd9Sstevel@tonic-gate  *	registering.
680*7c478bd9Sstevel@tonic-gate  * This structure is actually hung off of the client_reg_t.private
681*7c478bd9Sstevel@tonic-gate  *	structure member.  Since we don't make public how to write
682*7c478bd9Sstevel@tonic-gate  *	a "super-client", the actual structure that the client uses
683*7c478bd9Sstevel@tonic-gate  *	is defined in this private header file.
684*7c478bd9Sstevel@tonic-gate  */
685*7c478bd9Sstevel@tonic-gate typedef struct sclient_reg_t {
686*7c478bd9Sstevel@tonic-gate 	uint32_t		max_socket_num;
687*7c478bd9Sstevel@tonic-gate 	uint32_t		num_sockets;
688*7c478bd9Sstevel@tonic-gate 	uint32_t		num_windows;
689*7c478bd9Sstevel@tonic-gate 	uint32_t		num_clients;
690*7c478bd9Sstevel@tonic-gate 	struct sclient_list_t {
691*7c478bd9Sstevel@tonic-gate 		client_handle_t	client_handle;
692*7c478bd9Sstevel@tonic-gate 		uint32_t	error;
693*7c478bd9Sstevel@tonic-gate 	} **sclient_list;
694*7c478bd9Sstevel@tonic-gate } sclient_reg_t;
696*7c478bd9Sstevel@tonic-gate /*
697*7c478bd9Sstevel@tonic-gate  * structure for event text used for cs_ss_event_text
698*7c478bd9Sstevel@tonic-gate  */
699*7c478bd9Sstevel@tonic-gate typedef struct cs_ss_event_text_t {
700*7c478bd9Sstevel@tonic-gate 	event_t		ss_event;	/* SS event code */
701*7c478bd9Sstevel@tonic-gate 	event_t		cs_event;	/* CS event code */
702*7c478bd9Sstevel@tonic-gate 	char		*text;
703*7c478bd9Sstevel@tonic-gate } cs_ss_event_text_t;
705*7c478bd9Sstevel@tonic-gate /*
706*7c478bd9Sstevel@tonic-gate  * Flags for cs_read_event_status
707*7c478bd9Sstevel@tonic-gate  */
708*7c478bd9Sstevel@tonic-gate #define	CS_RES_IGNORE_NO_CARD		0x0001	/* don't check for card */
710*7c478bd9Sstevel@tonic-gate /*
711*7c478bd9Sstevel@tonic-gate  * cs_csfunc2text_strings_t structure used internally in Error2Text
712*7c478bd9Sstevel@tonic-gate  */
713*7c478bd9Sstevel@tonic-gate typedef struct cs_csfunc2text_strings_t {
714*7c478bd9Sstevel@tonic-gate 	uint32_t	item;
715*7c478bd9Sstevel@tonic-gate 	char		*text;
716*7c478bd9Sstevel@tonic-gate } cs_csfunc2text_strings_t;
718*7c478bd9Sstevel@tonic-gate /*
719*7c478bd9Sstevel@tonic-gate  * Flags for Error2Text - not used by clients; the struct is defined
720*7c478bd9Sstevel@tonic-gate  *	in the cs.h header file.
721*7c478bd9Sstevel@tonic-gate  */
722*7c478bd9Sstevel@tonic-gate #define	CSFUN2TEXT_FUNCTION	0x0001	/* return text of CS function code */
723*7c478bd9Sstevel@tonic-gate #define	CSFUN2TEXT_RETURN	0x0002	/* return text of CS return code */
725*7c478bd9Sstevel@tonic-gate /*
726*7c478bd9Sstevel@tonic-gate  * Macros to walk the local linked CIS list.
727*7c478bd9Sstevel@tonic-gate  *
728*7c478bd9Sstevel@tonic-gate  * These macros can take any valid local list tuple pointer.  They return
729*7c478bd9Sstevel@tonic-gate  *	another tuple pointer or NULL if they fail.
730*7c478bd9Sstevel@tonic-gate  */
731*7c478bd9Sstevel@tonic-gate #define	GET_NEXT_TUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,  \
732*7c478bd9Sstevel@tonic-gate 						NULL, GET_NEXT_LTUPLEF |     \
733*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
734*7c478bd9Sstevel@tonic-gate #define	GET_PREV_TUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,  \
735*7c478bd9Sstevel@tonic-gate 						NULL, GET_PREV_LTUPLEF |     \
736*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
737*7c478bd9Sstevel@tonic-gate #define	GET_FIRST_LTUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
738*7c478bd9Sstevel@tonic-gate 						NULL, GET_FIRST_LTUPLEF |     \
739*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
740*7c478bd9Sstevel@tonic-gate #define	GET_LAST_LTUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
741*7c478bd9Sstevel@tonic-gate 						NULL, GET_LAST_LTUPLEF |      \
742*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
743*7c478bd9Sstevel@tonic-gate #define	FIND_LTUPLE_FWD(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
744*7c478bd9Sstevel@tonic-gate 						tu, FIND_LTUPLE_FWDF |        \
745*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
746*7c478bd9Sstevel@tonic-gate #define	FIND_LTUPLE_BACK(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
747*7c478bd9Sstevel@tonic-gate 						tu, FIND_LTUPLE_BACKF |       \
748*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
749*7c478bd9Sstevel@tonic-gate #define	FIND_NEXT_LTUPLE(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
750*7c478bd9Sstevel@tonic-gate 						tu, FIND_NEXT_LTUPLEF |       \
751*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
752*7c478bd9Sstevel@tonic-gate #define	FIND_PREV_LTUPLE(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
753*7c478bd9Sstevel@tonic-gate 						tu, FIND_PREV_LTUPLEF |       \
754*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
755*7c478bd9Sstevel@tonic-gate #define	FIND_FIRST_LTUPLE(tp, tu, f)	FIND_LTUPLE_FWD(GET_FIRST_LTUPLE(tp,  \
756*7c478bd9Sstevel@tonic-gate 								f), tu, f)
759*7c478bd9Sstevel@tonic-gate /*
760*7c478bd9Sstevel@tonic-gate  * Card Services hooks and general nexus prototypes
761*7c478bd9Sstevel@tonic-gate  */
762*7c478bd9Sstevel@tonic-gate int	 cs_init(void);
763*7c478bd9Sstevel@tonic-gate uint32_t cs_event(event_t, uint32_t, uint32_t);
764*7c478bd9Sstevel@tonic-gate int	 pcmcia_set_em_handler(int (*handler)(), caddr_t events,
765*7c478bd9Sstevel@tonic-gate 	    int elen, uint32_t id, void **cs, void **ss);
767*7c478bd9Sstevel@tonic-gate extern csfunction_t	*cs_socket_services;
770*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
771*7c478bd9Sstevel@tonic-gate }
772*7c478bd9Sstevel@tonic-gate #endif
774*7c478bd9Sstevel@tonic-gate #endif	/* _CS_PRIV_H */