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