xref: /illumos-gate/usr/src/uts/common/pcmcia/sys/cis.h (revision 63f91fbc3c024870d86dc3332a4a0080fb29bc40)
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 _CIS_H
27 #define	_CIS_H
28 
29 /*
30  * This is the Card Services Card Information Structure (CIS) interpreter
31  *	header file.  CIS information in this file is based on the
32  *	Release 2.01 PCMCIA standard.
33  */
34 
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 
41 #if defined(DEBUG)
42 #define	CIS_DEBUG
43 #endif
44 
45 
46 /*
47  * The CIS interpreter has a single entry point with a bunch of function
48  *	id numbers.
49  */
50 #define	CISP_CIS_SETUP		0x01	/* setup CS address in CIS */
51 #define	CISP_CIS_LIST_CREATE	0x02	/* create the CIS linked list */
52 #define	CISP_CIS_LIST_DESTROY	0x03	/* destroy the CIS linked list */
53 #define	CISP_CIS_GET_LTUPLE	0x04	/* get a tuple */
54 #define	CISP_CIS_PARSE_TUPLE	0x05	/* parse a tuple */
55 #define	CISP_CIS_CONV_DEVSPEED	0x06	/* convert devspeed to nS and back */
56 #define	CISP_CIS_CONV_DEVSIZE	0x07	/* convert device size */
57 
58 /*
59  * Make the  calls to CardServices look like function calls.
60  */
61 #define	CIS_CARD_SERVICES	(*cis_card_services)
62 
63 /*
64  * define the tuples that we recognize
65  *
66  * Layer 1 - Basic Compatability TUples
67  */
68 #define	CISTPL_NULL		0x000	/* null tuple - ignore */
69 #define	CISTPL_DEVICE		0x001	/* device information */
70 #define	CISTPL_LONGLINK_CB	0x002	/* longlink to next tuple chain */
71 #define	CISTPL_CONFIG_CB	0x004	/* configuration tuple */
72 #define	CISTPL_CFTABLE_ENTRY_CB	0x005	/* configuration table entry */
73 #define	CISTPL_LONGLINK_MFC	0x006	/* multi-function tuple */
74 #define	CISTPL_BAR		0x007	/* Base Address Register definition */
75 #define	CISTPL_CHECKSUM		0x010	/* checksum control */
76 #define	CISTPL_LONGLINK_A	0x011	/* long-link to AM */
77 #define	CISTPL_LONGLINK_C	0x012	/* long-link to CM */
78 #define	CISTPL_LINKTARGET	0x013	/* link-target control */
79 #define	CISTPL_NO_LINK		0x014	/* no-link control */
80 #define	CISTPL_VERS_1		0x015	/* level 1 version information */
81 #define	CISTPL_ALTSTR		0x016	/* alternate language string */
82 #define	CISTPL_DEVICE_A		0x017	/* AM device information */
83 #define	CISTPL_JEDEC_C		0x018	/* JEDEC programming info for CM */
84 #define	CISTPL_JEDEC_A		0x019	/* JEDEC programming info for AM */
85 #define	CISTPL_CONFIG		0x01a	/* configuration */
86 #define	CISTPL_CFTABLE_ENTRY	0x01b	/* configuration-table-entry */
87 #define	CISTPL_DEVICE_OC	0x01c	/* other op conditions CM device info */
88 #define	CISTPL_DEVICE_OA	0x01d	/* other op conditions AM device info */
89 #define	CISTPL_DEVICEGEO	0x01e	/* Common Memory device geometry */
90 #define	CISTPL_DEVICEGEO_A	0x01f	/* Attribute Memory device geometry */
91 #define	CISTPL_MANFID		0x020	/* manufacturer identification */
92 #define	CISTPL_FUNCID		0x021	/* function identification */
93 #define	CISTPL_FUNCE		0x022	/* function extension */
94 
95 /*
96  * Layer 2 - Data Recording Format Tuples
97  */
98 #define	CISTPL_SWIL		0x023	/* software interleave */
99 #define	CISTPL_VERS_2		0x040	/* level 2 version information */
100 #define	CISTPL_FORMAT		0x041	/* Common Memory recording format */
101 #define	CISTPL_GEOMETRY		0x042	/* geometry */
102 #define	CISTPL_BYTEORDER	0x043	/* byte order */
103 #define	CISTPL_DATE		0x044	/* card initialization date */
104 #define	CISTPL_BATTERY		0x045	/* battery replacement date */
105 #define	CISTPL_FORMAT_A		0x047	/* Attribute Memory recording format */
106 
107 /*
108  * Layer 3 - Data Organization Tuples
109  */
110 #define	CISTPL_ORG		0x046	/* organization */
111 
112 /*
113  * Layer 4 - System Specific Standard Tuples
114  */
115 #define	CISTPL_VEND_SPEC_80	0x080	/* vendor-specific 0x80 */
116 #define	CISTPL_VEND_SPEC_81	0x081	/* vendor-specific 0x81 */
117 #define	CISTPL_VEND_SPEC_82	0x082	/* vendor-specific 0x82 */
118 #define	CISTPL_VEND_SPEC_83	0x083	/* vendor-specific 0x83 */
119 #define	CISTPL_VEND_SPEC_84	0x084	/* vendor-specific 0x84 */
120 #define	CISTPL_VEND_SPEC_85	0x085	/* vendor-specific 0x85 */
121 #define	CISTPL_VEND_SPEC_86	0x086	/* vendor-specific 0x86 */
122 #define	CISTPL_VEND_SPEC_87	0x087	/* vendor-specific 0x87 */
123 #define	CISTPL_VEND_SPEC_88	0x088	/* vendor-specific 0x88 */
124 #define	CISTPL_VEND_SPEC_89	0x089	/* vendor-specific 0x89 */
125 #define	CISTPL_VEND_SPEC_8a	0x08a	/* vendor-specific 0x8a */
126 #define	CISTPL_VEND_SPEC_8b	0x08b	/* vendor-specific 0x8b */
127 #define	CISTPL_VEND_SPEC_8c	0x08c	/* vendor-specific 0x8c */
128 #define	CISTPL_VEND_SPEC_8d	0x08d	/* vendor-specific 0x8d */
129 #define	CISTPL_VEND_SPEC_8e	0x08e	/* vendor-specific 0x8e */
130 #define	CISTPL_VEND_SPEC_8f	0x08f	/* vendor-specific 0x8f */
131 #define	CISTPL_SPCL		0x090	/* special-purpose tuple */
132 #define	CISTPL_END		0x0ff	/* end-of-list tuple */
133 
134 /*
135  * Macro to check if tuple is a vendor-specific tuple.
136  */
137 #define	CISTPL_VENDSPEC_START	CISTPL_VEND_SPEC_80
138 #define	CISTPL_VENDSPEC_END	CISTPL_VEND_SPEC_8f
139 #define	CISTPL_IS_VENDOR_SPECIFIC(td)	(((td) >= CISTPL_VENDSPEC_START) &&   \
140 						((td) <= CISTPL_VENDSPEC_END))
141 
142 /*
143  * The GetFirstTuple and GetNextTuple Card Services function calls use
144  *	the DesiredTuple member of the tuple_t structure to determine
145  *	while tuple type to return; since the CIS parser doesn't ever
146  *	return CISTPL_END tuples, we can never ask for those tuples,
147  *	so we overload this tuple code to mean that we want the
148  *	first (or next) tuple in the chain.
149  * XXX - If we ever do return CISTPL_END tuples, we'll have to
150  *	re-think this.
151  */
152 #define	RETURN_FIRST_TUPLE	0x0ff	/* return first/next tuple */
153 #define	RETURN_NEXT_TUPLE	0x0ff	/* return first/next tuple */
154 
155 /*
156  * types for data in CIS and pointers into PC card's CIS space
157  *
158  * The "size" member is used by the NEXT_CIS_ADDR macro so that
159  *	we don't run past the end of the mapped CIS address space.
160  */
161 typedef uchar_t cisdata_t;
162 
163 typedef struct cisptr_t {
164     acc_handle_t	handle;	/* access handle of CIS space */
165     uint32_t		size;	/* size of mapped area */
166     uint32_t		offset;	/* byte offset into CIS space */
167 	/* see flag definitions for cistpl_t structure */
168     uint32_t		flags;
169 } cisptr_t;
170 
171 /*
172  * This is the maximum length that the data portion of a tuple can be.
173  *	We have to use this since the brain-damaged 2.01 PCMCIA spec
174  *	specifies that you can end a CIS chain by putting a CISTPL_END
175  *	in the link field of the last VALID tuple.
176  */
177 #define	CIS_MAX_TUPLE_DATA_LEN	254
178 
179 /*
180  * This is the maximum size of the string used to describe the name
181  *	of the tuple.
182  */
183 #define	CIS_MAX_TUPLE_NAME_LEN	40
184 
185 /*
186  * CIS_MAX_FUNCTIONS defines the maximum number of functions that can
187  *	exist on a card.
188  */
189 #define	CIS_MAX_FUNCTIONS	8	/* max number of functions per card */
190 
191 /*
192  * Macros to manipulate addresses and data in various CIS spaces
193  *
194  * NEXT_CIS_ADDR(cisptr_t *) increments the offset to point to the
195  *	next data element in the CIS, based on what space the CIS
196  *	we are reading resides in.  If the resulting address would
197  *	be past the end of the mapped-in area, we return NULL,
198  *	otherwise the adjusted offset value is returned. Note that
199  *	this only works if the "size" member specifies the maximum
200  *	mapped in window size and an "offset" member value of zero
201  *	refers to the first byte of the window.
202  *
203  * GET_CIS_DATA(ptr) returns the data byte at the current CIS location.
204  *
205  * GET_CIS_ADDR(tp,ptr) returns the virtual address that was saved by a
206  *	call to STORE_CIS_ADDR.
207  *
208  * BAD_CIS_ADDR is a flag that should be returned by callers of NEXT_CIS_ADDR
209  *	if that macro returns NULL.  Note that this flag shares the same bit
210  *	field definitions as the tuple handler flags defined in cis_handlers.h
211  *	so check that file if you make any changes to these flags.
212  * XXX - not the best distribution of flags, I'm afraid
213  */
214 #define	NEXT_CIS_ADDR(ptr)	\
215 			(((ptr->flags&CISTPLF_AM_SPACE)?(ptr->offset += 2): \
216 				(ptr->offset++)),	\
217 				((ptr->offset > ptr->size)?(0):ptr->offset))
218 #define	GET_CIS_DATA(ptr)	csx_Get8(ptr->handle, ptr->offset)
219 #define	GET_CIS_ADDR(tp)	((cisdata_t *)(uintptr_t)(tp)->offset)
220 #define	BAD_CIS_ADDR	0x080000000 /* read past end of mapped CIS error */
221 
222 /*
223  * CIS_MEM_ALLOC(len) is used to allocate memory for our local linked
224  *	CIS list; we use a macro so that the same code can be used in
225  *	the kernel as well as in user space
226  *
227  * CIS_MEM_FREE(ptr) - same comment as CIS_MEM_ALLOC
228  */
229 #if !defined(_KERNEL)
230 #ifdef	CISMALLOC_DEBUG
231 #define	CIS_MEM_ALLOC(len)		cis_malloc((uint32_t)len)
232 #define	CIS_MEM_FREE(ptr)		cis_free(ptr)
233 #else
234 #define	CIS_MEM_ALLOC(len)		malloc((uint32_t)len)
235 #define	CIS_MEM_FREE(ptr)		free(ptr)
236 #endif	/* CISMALLOC_DEBUG */
237 #else
238 #define	CIS_MEM_ALLOC(len)		cis_malloc((uint32_t)len)
239 #define	CIS_MEM_FREE(ptr)		cis_free(ptr)
240 #endif
241 
242 typedef struct cis_u_malloc_tag_t {
243 	caddr_t		addr;
244 	uint32_t	len;
245 } cis_u_malloc_tag_t;
246 
247 /*
248  * We keep the tuples in a locally-maintained linked list.  This allows
249  *	us to return the tuple information at any time to a client for
250  *	those cards that make their CIS inaccessible once the card is
251  *	configured.
252  */
253 typedef struct cistpl_t {
254 	cisdata_t	type;	/* type of tuple */
255 	cisdata_t	len;	/* length of tuple data */
256 	cisdata_t	*data;	/* data in tuple */
257 	union {
258 		cisdata_t	*byte;	/* read pointer for GET_BYTE macros */
259 		uint16_t	*sword;
260 	}		read;
261 	uint32_t	flags;	/* misc flags */
262 	uint32_t	offset;	/* CIS address offset of start of tuple */
263 	struct cistpl_t	*prev;	/* back pointer */
264 	struct cistpl_t	*next;	/* forward pointer */
265 } cistpl_t;
266 
267 /*
268  * Flags that are used in the cistpl_t and cisptr_t linked lists
269  */
270 #define	CISTPLF_NOERROR		0x000000000 /* no error return from handler */
271 #define	CISTPLF_UNKNOWN		0x000000001 /* unknown tuple */
272 #define	CISTPLF_REGS		0x000000002 /* tuple contains registers */
273 #define	CISTPLF_COPYOK		0x000000004 /* OK to copy tuple data */
274 #define	CISTPLF_VALID		0x000000008 /* tuple is valid */
275 #define	CISTPLF_GLOBAL_CIS	0x000000010 /* tuple from global CIS */
276 #define	CISTPLF_MF_CIS		0x000000020 /* tuple from MF CIS chain */
277 #define	CISTPLF_FROM_AM		0x000000040 /* tuple read from AM space */
278 #define	CISTPLF_FROM_CM		0x000000080 /* tuple read from CM space */
279 #define	CISTPLF_IGNORE_TUPLE	0x000000100 /* ignore this tuple */
280 #define	CISTPLF_VENDOR_SPECIFIC	0x000000200 /* vnedor-specific tuple */
281 #define	CISTPLF_LINK_INVALID	0x001000000 /* tuple link is invalid */
282 #define	CISTPLF_PARAMS_INVALID	0x002000000 /* tuple body is invalid */
283 #define	CISTPLF_AM_SPACE	0x010000000 /* this tuple is in AM space */
284 #define	CISTPLF_CM_SPACE	0x020000000 /* this tuple is in CM space */
285 #define	CISTPLF_LM_SPACE	0x040000000 /* this tuple is in local memory */
286 #define	CISTPLF_MEM_ERR		0x080000000 /* GET_BYTE macros memory error */
287 
288 /*
289  * Some convienience macros
290  */
291 #define	CISTPLF_SPACE_MASK	(CISTPLF_AM_SPACE | CISTPLF_CM_SPACE |	\
292 							CISTPLF_LM_SPACE)
293 #define	CISTPLF_FROM_MASK	(CISTPLF_FROM_AM | CISTPLF_FROM_CM)
294 
295 /*
296  * Values used internally on calls to cis_get_ltuple.
297  *
298  * The GET_XXX_LTUPLEF and FIND_XXX_XXX values are mutually exclusive,
299  *	i.e. cis_get_ltuple can only do one of these operations per call.
300  *
301  * The other flags are bit flags and they share the flags parameter.
302  *
303  *    CIS_GET_LTUPLE_IGNORE - return tuples with CISTPLF_IGNORE_TUPLE
304  *				set in cistpl_t->flags
305  */
306 #define	GET_FIRST_LTUPLEF	0x000000001 /* return first tuple in list */
307 #define	GET_LAST_LTUPLEF	0x000000002 /* return last tuple in list */
308 #define	FIND_LTUPLE_FWDF	0x000000003 /* find tuple, fwd search from tp */
309 #define	FIND_LTUPLE_BACKF	0x000000004 /* find tuple, backward from tp */
310 #define	FIND_NEXT_LTUPLEF	0x000000005 /* find tuple, fwd from tp+1 */
311 #define	FIND_PREV_LTUPLEF	0x000000006 /* find tuple, backward from tp-1 */
312 #define	GET_NEXT_LTUPLEF	0x000000007 /* return next tuple in list */
313 #define	GET_PREV_LTUPLEF	0x000000008 /* return prev tuple in list */
314 #define	CIS_GET_LTUPLE_OPMASK	0x00000ffff /* mask for operation values */
315 #define	CIS_GET_LTUPLE_IGNORE	0x000010000 /* return ignored tuples */
316 
317 /*
318  * macros for getting various data types out of a tuple
319  * Note that due to the modem tuple using a few big-endian values,
320  * we have to support both big and little endian macros
321  *
322  * Common Memory Specific macros - these will also work for tuples in
323  *	local memory
324  */
325 #define	GET_CM_BYTE(tp)	(((size_t)(tp)->len >= \
326 				((uintptr_t)(tp)->read.byte - \
327 					(uintptr_t)(tp)->data)) ? \
328 			 *(tp)->read.byte++ : ((tp)->flags |= CISTPLF_MEM_ERR))
329 #define	GET_CM_LEN(tp)	((size_t)(tp)->len - \
330 				((uintptr_t)(tp)->read.byte - \
331 				(uintptr_t)(tp)->data))
332 
333 /* Attribute Memory Specific macros */
334 #define	GET_AM_BYTE(tp)	(((size_t)(tp)->len >= \
335 				(((uintptr_t)(tp)->read.byte - \
336 					(uintptr_t)(tp)->data))>>1) ? \
337 			 *(cisdata_t *)(tp)->read.sword++ : \
338 				((tp)->flags |= CISTPLF_MEM_ERR))
339 #define	GET_AM_LEN(tp)	((size_t)(tp)->len - (((uintptr_t)(tp)->read.byte - \
340 				(uintptr_t)(tp)->data) >> 1))
341 
342 /* generic macros */
343 #define	RESET_TP(tp)	(tp)->read.byte = (tp)->data
344 #define	LOOK_BYTE(tp)	*(tp)->read.byte
345 #define	GET_BYTE_ADDR(tp) (tp)->read.byte
346 
347 #define	GET_BYTE(tp)	(((tp)->flags & CISTPLF_AM_SPACE) ? \
348 				GET_AM_BYTE(tp) : GET_CM_BYTE(tp))
349 #define	GET_SHORT(tp)		cis_get_short(tp)
350 #define	GET_BE_SHORT(tp)	cis_get_be_short(tp)
351 #define	GET_INT24(tp)		cis_get_int24(tp)
352 #define	GET_LONG(tp)		cis_get_long(tp)
353 #define	GET_LEN(tp)	(((tp)->flags & CISTPLF_AM_SPACE) ? \
354 				GET_AM_LEN(tp) : GET_CM_LEN(tp))
355 
356 /*
357  * cistpl_ignore_list_t - this structure describes tuples in the global
358  *				CIS list that we want to ignore if they
359  *				also show up in a function-specific CIS.
360  */
361 typedef struct cistpl_ignore_list_t {
362 	cisdata_t	type;
363 } cistpl_ignore_list_t;
364 
365 #ifdef	__cplusplus
366 }
367 #endif
368 
369 #endif	/* _CIS_H */
370