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