17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
55f9e250hx * Common Development and Distribution License (the "License").
65f9e250hx * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
225f9e250hx * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate#ifndef _CIS_H
277c478bdstevel@tonic-gate#define	_CIS_H
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate/*
307c478bdstevel@tonic-gate * This is the Card Services Card Information Structure (CIS) interpreter
317c478bdstevel@tonic-gate *	header file.  CIS information in this file is based on the
327c478bdstevel@tonic-gate *	Release 2.01 PCMCIA standard.
337c478bdstevel@tonic-gate */
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#ifdef	__cplusplus
377c478bdstevel@tonic-gateextern "C" {
387c478bdstevel@tonic-gate#endif
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate#if defined(DEBUG)
427c478bdstevel@tonic-gate#define	CIS_DEBUG
437c478bdstevel@tonic-gate#endif
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate/*
477c478bdstevel@tonic-gate * The CIS interpreter has a single entry point with a bunch of function
487c478bdstevel@tonic-gate *	id numbers.
497c478bdstevel@tonic-gate */
507c478bdstevel@tonic-gate#define	CISP_CIS_SETUP		0x01	/* setup CS address in CIS */
517c478bdstevel@tonic-gate#define	CISP_CIS_LIST_CREATE	0x02	/* create the CIS linked list */
527c478bdstevel@tonic-gate#define	CISP_CIS_LIST_DESTROY	0x03	/* destroy the CIS linked list */
537c478bdstevel@tonic-gate#define	CISP_CIS_GET_LTUPLE	0x04	/* get a tuple */
547c478bdstevel@tonic-gate#define	CISP_CIS_PARSE_TUPLE	0x05	/* parse a tuple */
557c478bdstevel@tonic-gate#define	CISP_CIS_CONV_DEVSPEED	0x06	/* convert devspeed to nS and back */
567c478bdstevel@tonic-gate#define	CISP_CIS_CONV_DEVSIZE	0x07	/* convert device size */
577c478bdstevel@tonic-gate
587c478bdstevel@tonic-gate/*
597c478bdstevel@tonic-gate * Make the  calls to CardServices look like function calls.
607c478bdstevel@tonic-gate */
617c478bdstevel@tonic-gate#define	CIS_CARD_SERVICES	(*cis_card_services)
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gate/*
647c478bdstevel@tonic-gate * define the tuples that we recognize
657c478bdstevel@tonic-gate *
667c478bdstevel@tonic-gate * Layer 1 - Basic Compatability TUples
677c478bdstevel@tonic-gate */
687c478bdstevel@tonic-gate#define	CISTPL_NULL		0x000	/* null tuple - ignore */
697c478bdstevel@tonic-gate#define	CISTPL_DEVICE		0x001	/* device information */
707c478bdstevel@tonic-gate#define	CISTPL_LONGLINK_CB	0x002	/* longlink to next tuple chain */
717c478bdstevel@tonic-gate#define	CISTPL_CONFIG_CB	0x004	/* configuration tuple */
727c478bdstevel@tonic-gate#define	CISTPL_CFTABLE_ENTRY_CB	0x005	/* configuration table entry */
737c478bdstevel@tonic-gate#define	CISTPL_LONGLINK_MFC	0x006	/* multi-function tuple */
747c478bdstevel@tonic-gate#define	CISTPL_BAR		0x007	/* Base Address Register definition */
757c478bdstevel@tonic-gate#define	CISTPL_CHECKSUM		0x010	/* checksum control */
767c478bdstevel@tonic-gate#define	CISTPL_LONGLINK_A	0x011	/* long-link to AM */
777c478bdstevel@tonic-gate#define	CISTPL_LONGLINK_C	0x012	/* long-link to CM */
787c478bdstevel@tonic-gate#define	CISTPL_LINKTARGET	0x013	/* link-target control */
797c478bdstevel@tonic-gate#define	CISTPL_NO_LINK		0x014	/* no-link control */
807c478bdstevel@tonic-gate#define	CISTPL_VERS_1		0x015	/* level 1 version information */
817c478bdstevel@tonic-gate#define	CISTPL_ALTSTR		0x016	/* alternate language string */
827c478bdstevel@tonic-gate#define	CISTPL_DEVICE_A		0x017	/* AM device information */
837c478bdstevel@tonic-gate#define	CISTPL_JEDEC_C		0x018	/* JEDEC programming info for CM */
847c478bdstevel@tonic-gate#define	CISTPL_JEDEC_A		0x019	/* JEDEC programming info for AM */
857c478bdstevel@tonic-gate#define	CISTPL_CONFIG		0x01a	/* configuration */
867c478bdstevel@tonic-gate#define	CISTPL_CFTABLE_ENTRY	0x01b	/* configuration-table-entry */
877c478bdstevel@tonic-gate#define	CISTPL_DEVICE_OC	0x01c	/* other op conditions CM device info */
887c478bdstevel@tonic-gate#define	CISTPL_DEVICE_OA	0x01d	/* other op conditions AM device info */
897c478bdstevel@tonic-gate#define	CISTPL_DEVICEGEO	0x01e	/* Common Memory device geometry */
907c478bdstevel@tonic-gate#define	CISTPL_DEVICEGEO_A	0x01f	/* Attribute Memory device geometry */
91c48c304Toomas Soome#define	CISTPL_MANFID		0x020	/* manufacturer identification */
927c478bdstevel@tonic-gate#define	CISTPL_FUNCID		0x021	/* function identification */
937c478bdstevel@tonic-gate#define	CISTPL_FUNCE		0x022	/* function extension */
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gate/*
967c478bdstevel@tonic-gate * Layer 2 - Data Recording Format Tuples
977c478bdstevel@tonic-gate */
987c478bdstevel@tonic-gate#define	CISTPL_SWIL		0x023	/* software interleave */
997c478bdstevel@tonic-gate#define	CISTPL_VERS_2		0x040	/* level 2 version information */
1007c478bdstevel@tonic-gate#define	CISTPL_FORMAT		0x041	/* Common Memory recording format */
1017c478bdstevel@tonic-gate#define	CISTPL_GEOMETRY		0x042	/* geometry */
1027c478bdstevel@tonic-gate#define	CISTPL_BYTEORDER	0x043	/* byte order */
1037c478bdstevel@tonic-gate#define	CISTPL_DATE		0x044	/* card initialization date */
1047c478bdstevel@tonic-gate#define	CISTPL_BATTERY		0x045	/* battery replacement date */
1057c478bdstevel@tonic-gate#define	CISTPL_FORMAT_A		0x047	/* Attribute Memory recording format */
1067c478bdstevel@tonic-gate
1077c478bdstevel@tonic-gate/*
1087c478bdstevel@tonic-gate * Layer 3 - Data Organization Tuples
1097c478bdstevel@tonic-gate */
1107c478bdstevel@tonic-gate#define	CISTPL_ORG		0x046	/* organization */
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gate/*
1137c478bdstevel@tonic-gate * Layer 4 - System Specific Standard Tuples
1147c478bdstevel@tonic-gate */
1157c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_80	0x080	/* vendor-specific 0x80 */
1167c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_81	0x081	/* vendor-specific 0x81 */
1177c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_82	0x082	/* vendor-specific 0x82 */
1187c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_83	0x083	/* vendor-specific 0x83 */
1197c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_84	0x084	/* vendor-specific 0x84 */
1207c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_85	0x085	/* vendor-specific 0x85 */
1217c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_86	0x086	/* vendor-specific 0x86 */
1227c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_87	0x087	/* vendor-specific 0x87 */
1237c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_88	0x088	/* vendor-specific 0x88 */
1247c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_89	0x089	/* vendor-specific 0x89 */
1257c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_8a	0x08a	/* vendor-specific 0x8a */
1267c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_8b	0x08b	/* vendor-specific 0x8b */
1277c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_8c	0x08c	/* vendor-specific 0x8c */
1287c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_8d	0x08d	/* vendor-specific 0x8d */
1297c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_8e	0x08e	/* vendor-specific 0x8e */
1307c478bdstevel@tonic-gate#define	CISTPL_VEND_SPEC_8f	0x08f	/* vendor-specific 0x8f */
1317c478bdstevel@tonic-gate#define	CISTPL_SPCL		0x090	/* special-purpose tuple */
1327c478bdstevel@tonic-gate#define	CISTPL_END		0x0ff	/* end-of-list tuple */
1337c478bdstevel@tonic-gate
1347c478bdstevel@tonic-gate/*
1357c478bdstevel@tonic-gate * Macro to check if tuple is a vendor-specific tuple.
1367c478bdstevel@tonic-gate */
1377c478bdstevel@tonic-gate#define	CISTPL_VENDSPEC_START	CISTPL_VEND_SPEC_80
1387c478bdstevel@tonic-gate#define	CISTPL_VENDSPEC_END	CISTPL_VEND_SPEC_8f
1397c478bdstevel@tonic-gate#define	CISTPL_IS_VENDOR_SPECIFIC(td)	(((td) >= CISTPL_VENDSPEC_START) &&   \
1407c478bdstevel@tonic-gate						((td) <= CISTPL_VENDSPEC_END))
1417c478bdstevel@tonic-gate
1427c478bdstevel@tonic-gate/*
1437c478bdstevel@tonic-gate * The GetFirstTuple and GetNextTuple Card Services function calls use
1447c478bdstevel@tonic-gate *	the DesiredTuple member of the tuple_t structure to determine
1457c478bdstevel@tonic-gate *	while tuple type to return; since the CIS parser doesn't ever
1467c478bdstevel@tonic-gate *	return CISTPL_END tuples, we can never ask for those tuples,
1477c478bdstevel@tonic-gate *	so we overload this tuple code to mean that we want the
1487c478bdstevel@tonic-gate *	first (or next) tuple in the chain.
1497c478bdstevel@tonic-gate * XXX - If we ever do return CISTPL_END tuples, we'll have to
1507c478bdstevel@tonic-gate *	re-think this.
1517c478bdstevel@tonic-gate */
1527c478bdstevel@tonic-gate#define	RETURN_FIRST_TUPLE	0x0ff	/* return first/next tuple */
1537c478bdstevel@tonic-gate#define	RETURN_NEXT_TUPLE	0x0ff	/* return first/next tuple */
1547c478bdstevel@tonic-gate
1557c478bdstevel@tonic-gate/*
1567c478bdstevel@tonic-gate * types for data in CIS and pointers into PC card's CIS space
1577c478bdstevel@tonic-gate *
1587c478bdstevel@tonic-gate * The "size" member is used by the NEXT_CIS_ADDR macro so that
1597c478bdstevel@tonic-gate *	we don't run past the end of the mapped CIS address space.
1607c478bdstevel@tonic-gate */
1617c478bdstevel@tonic-gatetypedef uchar_t cisdata_t;
1627c478bdstevel@tonic-gate
1637c478bdstevel@tonic-gatetypedef struct cisptr_t {
1647c478bdstevel@tonic-gate    acc_handle_t	handle;	/* access handle of CIS space */
1657c478bdstevel@tonic-gate    uint32_t		size;	/* size of mapped area */
1667c478bdstevel@tonic-gate    uint32_t		offset;	/* byte offset into CIS space */
1677c478bdstevel@tonic-gate	/* see flag definitions for cistpl_t structure */
1687c478bdstevel@tonic-gate    uint32_t		flags;
1697c478bdstevel@tonic-gate} cisptr_t;
1707c478bdstevel@tonic-gate
1717c478bdstevel@tonic-gate/*
1727c478bdstevel@tonic-gate * This is the maximum length that the data portion of a tuple can be.
1737c478bdstevel@tonic-gate *	We have to use this since the brain-damaged 2.01 PCMCIA spec
1747c478bdstevel@tonic-gate *	specifies that you can end a CIS chain by putting a CISTPL_END
1757c478bdstevel@tonic-gate *	in the link field of the last VALID tuple.
1767c478bdstevel@tonic-gate */
1777c478bdstevel@tonic-gate#define	CIS_MAX_TUPLE_DATA_LEN	254
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gate/*
1807c478bdstevel@tonic-gate * This is the maximum size of the string used to describe the name
1817c478bdstevel@tonic-gate *	of the tuple.
1827c478bdstevel@tonic-gate */
1837c478bdstevel@tonic-gate#define	CIS_MAX_TUPLE_NAME_LEN	40
1847c478bdstevel@tonic-gate
1857c478bdstevel@tonic-gate/*
1867c478bdstevel@tonic-gate * CIS_MAX_FUNCTIONS defines the maximum number of functions that can
1877c478bdstevel@tonic-gate *	exist on a card.
1887c478bdstevel@tonic-gate */
1897c478bdstevel@tonic-gate#define	CIS_MAX_FUNCTIONS	8	/* max number of functions per card */
1907c478bdstevel@tonic-gate
1917c478bdstevel@tonic-gate/*
1927c478bdstevel@tonic-gate * Macros to manipulate addresses and data in various CIS spaces
1937c478bdstevel@tonic-gate *
1947c478bdstevel@tonic-gate * NEXT_CIS_ADDR(cisptr_t *) increments the offset to point to the
1957c478bdstevel@tonic-gate *	next data element in the CIS, based on what space the CIS
1967c478bdstevel@tonic-gate *	we are reading resides in.  If the resulting address would
1977c478bdstevel@tonic-gate *	be past the end of the mapped-in area, we return NULL,
1987c478bdstevel@tonic-gate *	otherwise the adjusted offset value is returned. Note that
1997c478bdstevel@tonic-gate *	this only works if the "size" member specifies the maximum
2007c478bdstevel@tonic-gate *	mapped in window size and an "offset" member value of zero
2017c478bdstevel@tonic-gate *	refers to the first byte of the window.
2027c478bdstevel@tonic-gate *
2037c478bdstevel@tonic-gate * GET_CIS_DATA(ptr) returns the data byte at the current CIS location.
2047c478bdstevel@tonic-gate *
2057c478bdstevel@tonic-gate * GET_CIS_ADDR(tp,ptr) returns the virtual address that was saved by a
2067c478bdstevel@tonic-gate *	call to STORE_CIS_ADDR.
2077c478bdstevel@tonic-gate *
2087c478bdstevel@tonic-gate * BAD_CIS_ADDR is a flag that should be returned by callers of NEXT_CIS_ADDR
2097c478bdstevel@tonic-gate *	if that macro returns NULL.  Note that this flag shares the same bit
2107c478bdstevel@tonic-gate *	field definitions as the tuple handler flags defined in cis_handlers.h
2117c478bdstevel@tonic-gate *	so check that file if you make any changes to these flags.
2127c478bdstevel@tonic-gate * XXX - not the best distribution of flags, I'm afraid
2137c478bdstevel@tonic-gate */
2147c478bdstevel@tonic-gate#define	NEXT_CIS_ADDR(ptr)	\
2157c478bdstevel@tonic-gate			(((ptr->flags&CISTPLF_AM_SPACE)?(ptr->offset += 2): \
2167c478bdstevel@tonic-gate				(ptr->offset++)),	\
217c48c304Toomas Soome				((ptr->offset > ptr->size)?(0):ptr->offset))
2187c478bdstevel@tonic-gate#define	GET_CIS_DATA(ptr)	csx_Get8(ptr->handle, ptr->offset)
2197c478bdstevel@tonic-gate#define	GET_CIS_ADDR(tp)	((cisdata_t *)(uintptr_t)(tp)->offset)
2207c478bdstevel@tonic-gate#define	BAD_CIS_ADDR	0x080000000 /* read past end of mapped CIS error */
2217c478bdstevel@tonic-gate
2227c478bdstevel@tonic-gate/*
2237c478bdstevel@tonic-gate * CIS_MEM_ALLOC(len) is used to allocate memory for our local linked
2247c478bdstevel@tonic-gate *	CIS list; we use a macro so that the same code can be used in
2257c478bdstevel@tonic-gate *	the kernel as well as in user space
2267c478bdstevel@tonic-gate *
2277c478bdstevel@tonic-gate * CIS_MEM_FREE(ptr) - same comment as CIS_MEM_ALLOC
2287c478bdstevel@tonic-gate */
2297c478bdstevel@tonic-gate#if !defined(_KERNEL)
2307c478bdstevel@tonic-gate#ifdef	CISMALLOC_DEBUG
2317c478bdstevel@tonic-gate#define	CIS_MEM_ALLOC(len)		cis_malloc((uint32_t)len)
2327c478bdstevel@tonic-gate#define	CIS_MEM_FREE(ptr)		cis_free(ptr)
2337c478bdstevel@tonic-gate#else
2347c478bdstevel@tonic-gate#define	CIS_MEM_ALLOC(len)		malloc((uint32_t)len)
2357c478bdstevel@tonic-gate#define	CIS_MEM_FREE(ptr)		free(ptr)
2367c478bdstevel@tonic-gate#endif	/* CISMALLOC_DEBUG */
2377c478bdstevel@tonic-gate#else
2387c478bdstevel@tonic-gate#define	CIS_MEM_ALLOC(len)		cis_malloc((uint32_t)len)
2397c478bdstevel@tonic-gate#define	CIS_MEM_FREE(ptr)		cis_free(ptr)
2407c478bdstevel@tonic-gate#endif
2417c478bdstevel@tonic-gate
2427c478bdstevel@tonic-gatetypedef struct cis_u_malloc_tag_t {
2437c478bdstevel@tonic-gate	caddr_t		addr;
2447c478bdstevel@tonic-gate	uint32_t	len;
2457c478bdstevel@tonic-gate} cis_u_malloc_tag_t;
2467c478bdstevel@tonic-gate
2477c478bdstevel@tonic-gate/*
2487c478bdstevel@tonic-gate * We keep the tuples in a locally-maintained linked list.  This allows
2497c478bdstevel@tonic-gate *	us to return the tuple information at any time to a client for
2507c478bdstevel@tonic-gate *	those cards that make their CIS inaccessible once the card is
2517c478bdstevel@tonic-gate *	configured.
2527c478bdstevel@tonic-gate */
2537c478bdstevel@tonic-gatetypedef struct cistpl_t {
2547c478bdstevel@tonic-gate	cisdata_t	type;	/* type of tuple */
2557c478bdstevel@tonic-gate	cisdata_t	len;	/* length of tuple data */
2567c478bdstevel@tonic-gate	cisdata_t	*data;	/* data in tuple */
2577c478bdstevel@tonic-gate	union {
2587c478bdstevel@tonic-gate		cisdata_t	*byte;	/* read pointer for GET_BYTE macros */
2597c478bdstevel@tonic-gate		uint16_t	*sword;
2607c478bdstevel@tonic-gate	}		read;
2617c478bdstevel@tonic-gate	uint32_t	flags;	/* misc flags */
2627c478bdstevel@tonic-gate	uint32_t	offset;	/* CIS address offset of start of tuple */
2637c478bdstevel@tonic-gate	struct cistpl_t	*prev;	/* back pointer */
2647c478bdstevel@tonic-gate	struct cistpl_t	*next;	/* forward pointer */
2657c478bdstevel@tonic-gate} cistpl_t;
2667c478bdstevel@tonic-gate
2677c478bdstevel@tonic-gate/*
2687c478bdstevel@tonic-gate * Flags that are used in the cistpl_t and cisptr_t linked lists
2697c478bdstevel@tonic-gate */
2707c478bdstevel@tonic-gate#define	CISTPLF_NOERROR		0x000000000 /* no error return from handler */
2717c478bdstevel@tonic-gate#define	CISTPLF_UNKNOWN		0x000000001 /* unknown tuple */
2727c478bdstevel@tonic-gate#define	CISTPLF_REGS		0x000000002 /* tuple contains registers */
2737c478bdstevel@tonic-gate#define	CISTPLF_COPYOK		0x000000004 /* OK to copy tuple data */
2747c478bdstevel@tonic-gate#define	CISTPLF_VALID		0x000000008 /* tuple is valid */
2757c478bdstevel@tonic-gate#define	CISTPLF_GLOBAL_CIS	0x000000010 /* tuple from global CIS */
2767c478bdstevel@tonic-gate#define	CISTPLF_MF_CIS		0x000000020 /* tuple from MF CIS chain */
2777c478bdstevel@tonic-gate#define	CISTPLF_FROM_AM		0x000000040 /* tuple read from AM space */
2787c478bdstevel@tonic-gate#define	CISTPLF_FROM_CM		0x000000080 /* tuple read from CM space */
2797c478bdstevel@tonic-gate#define	CISTPLF_IGNORE_TUPLE	0x000000100 /* ignore this tuple */
2807c478bdstevel@tonic-gate#define	CISTPLF_VENDOR_SPECIFIC	0x000000200 /* vnedor-specific tuple */
2817c478bdstevel@tonic-gate#define	CISTPLF_LINK_INVALID	0x001000000 /* tuple link is invalid */
2827c478bdstevel@tonic-gate#define	CISTPLF_PARAMS_INVALID	0x002000000 /* tuple body is invalid */
2837c478bdstevel@tonic-gate#define	CISTPLF_AM_SPACE	0x010000000 /* this tuple is in AM space */
2847c478bdstevel@tonic-gate#define	CISTPLF_CM_SPACE	0x020000000 /* this tuple is in CM space */
2857c478bdstevel@tonic-gate#define	CISTPLF_LM_SPACE	0x040000000 /* this tuple is in local memory */
2867c478bdstevel@tonic-gate#define	CISTPLF_MEM_ERR		0x080000000 /* GET_BYTE macros memory error */
2877c478bdstevel@tonic-gate
2887c478bdstevel@tonic-gate/*
2897c478bdstevel@tonic-gate * Some convienience macros
2907c478bdstevel@tonic-gate */
2917c478bdstevel@tonic-gate#define	CISTPLF_SPACE_MASK	(CISTPLF_AM_SPACE | CISTPLF_CM_SPACE |	\
2927c478bdstevel@tonic-gate							CISTPLF_LM_SPACE)
2937c478bdstevel@tonic-gate#define	CISTPLF_FROM_MASK	(CISTPLF_FROM_AM | CISTPLF_FROM_CM)
2947c478bdstevel@tonic-gate
2957c478bdstevel@tonic-gate/*
2967c478bdstevel@tonic-gate * Values used internally on calls to cis_get_ltuple.
2977c478bdstevel@tonic-gate *
2987c478bdstevel@tonic-gate * The GET_XXX_LTUPLEF and FIND_XXX_XXX values are mutually exclusive,
2997c478bdstevel@tonic-gate *	i.e. cis_get_ltuple can only do one of these operations per call.
3007c478bdstevel@tonic-gate *
3017c478bdstevel@tonic-gate * The other flags are bit flags and they share the flags parameter.
3027c478bdstevel@tonic-gate *
3037c478bdstevel@tonic-gate *    CIS_GET_LTUPLE_IGNORE - return tuples with CISTPLF_IGNORE_TUPLE
3047c478bdstevel@tonic-gate *				set in cistpl_t->flags
3057c478bdstevel@tonic-gate */
3067c478bdstevel@tonic-gate#define	GET_FIRST_LTUPLEF	0x000000001 /* return first tuple in list */
3077c478bdstevel@tonic-gate#define	GET_LAST_LTUPLEF	0x000000002 /* return last tuple in list */
3087c478bdstevel@tonic-gate#define	FIND_LTUPLE_FWDF	0x000000003 /* find tuple, fwd search from tp */
3097c478bdstevel@tonic-gate#define	FIND_LTUPLE_BACKF	0x000000004 /* find tuple, backward from tp */
3107c478bdstevel@tonic-gate#define	FIND_NEXT_LTUPLEF	0x000000005 /* find tuple, fwd from tp+1 */
3117c478bdstevel@tonic-gate#define	FIND_PREV_LTUPLEF	0x000000006 /* find tuple, backward from tp-1 */
3127c478bdstevel@tonic-gate#define	GET_NEXT_LTUPLEF	0x000000007 /* return next tuple in list */
3137c478bdstevel@tonic-gate#define	GET_PREV_LTUPLEF	0x000000008 /* return prev tuple in list */
3147c478bdstevel@tonic-gate#define	CIS_GET_LTUPLE_OPMASK	0x00000ffff /* mask for operation values */
3157c478bdstevel@tonic-gate#define	CIS_GET_LTUPLE_IGNORE	0x000010000 /* return ignored tuples */
3167c478bdstevel@tonic-gate
3177c478bdstevel@tonic-gate/*
3187c478bdstevel@tonic-gate * macros for getting various data types out of a tuple
3197c478bdstevel@tonic-gate * Note that due to the modem tuple using a few big-endian values,
3207c478bdstevel@tonic-gate * we have to support both big and little endian macros
3217c478bdstevel@tonic-gate *
3227c478bdstevel@tonic-gate * Common Memory Specific macros - these will also work for tuples in
3237c478bdstevel@tonic-gate *	local memory
3247c478bdstevel@tonic-gate */
3257c478bdstevel@tonic-gate#define	GET_CM_BYTE(tp)	(((size_t)(tp)->len >= \
3267c478bdstevel@tonic-gate				((uintptr_t)(tp)->read.byte - \
3277c478bdstevel@tonic-gate					(uintptr_t)(tp)->data)) ? \
3287c478bdstevel@tonic-gate			 *(tp)->read.byte++ : ((tp)->flags |= CISTPLF_MEM_ERR))
3297c478bdstevel@tonic-gate#define	GET_CM_LEN(tp)	((size_t)(tp)->len - \
3307c478bdstevel@tonic-gate				((uintptr_t)(tp)->read.byte - \
3317c478bdstevel@tonic-gate				(uintptr_t)(tp)->data))
3327c478bdstevel@tonic-gate
3337c478bdstevel@tonic-gate/* Attribute Memory Specific macros */
3347c478bdstevel@tonic-gate#define	GET_AM_BYTE(tp)	(((size_t)(tp)->len >= \
3357c478bdstevel@tonic-gate				(((uintptr_t)(tp)->read.byte - \
3367c478bdstevel@tonic-gate					(uintptr_t)(tp)->data))>>1) ? \
3377c478bdstevel@tonic-gate			 *(cisdata_t *)(tp)->read.sword++ : \
3387c478bdstevel@tonic-gate				((tp)->flags |= CISTPLF_MEM_ERR))
3397c478bdstevel@tonic-gate#define	GET_AM_LEN(tp)	((size_t)(tp)->len - (((uintptr_t)(tp)->read.byte - \
3407c478bdstevel@tonic-gate				(uintptr_t)(tp)->data) >> 1))
3417c478bdstevel@tonic-gate
3427c478bdstevel@tonic-gate/* generic macros */
3437c478bdstevel@tonic-gate#define	RESET_TP(tp)	(tp)->read.byte = (tp)->data
3447c478bdstevel@tonic-gate#define	LOOK_BYTE(tp)	*(tp)->read.byte
3457c478bdstevel@tonic-gate#define	GET_BYTE_ADDR(tp) (tp)->read.byte
3467c478bdstevel@tonic-gate
3477c478bdstevel@tonic-gate#define	GET_BYTE(tp)	(((tp)->flags & CISTPLF_AM_SPACE) ? \
3487c478bdstevel@tonic-gate				GET_AM_BYTE(tp) : GET_CM_BYTE(tp))
3495f9e250hx#define	GET_SHORT(tp)		cis_get_short(tp)
3505f9e250hx#define	GET_BE_SHORT(tp)	cis_get_be_short(tp)
3515f9e250hx#define	GET_INT24(tp)		cis_get_int24(tp)
3525f9e250hx#define	GET_LONG(tp)		cis_get_long(tp)
3537c478bdstevel@tonic-gate#define	GET_LEN(tp)	(((tp)->flags & CISTPLF_AM_SPACE) ? \
3547c478bdstevel@tonic-gate				GET_AM_LEN(tp) : GET_CM_LEN(tp))
3557c478bdstevel@tonic-gate
3567c478bdstevel@tonic-gate/*
3577c478bdstevel@tonic-gate * cistpl_ignore_list_t - this structure describes tuples in the global
3587c478bdstevel@tonic-gate *				CIS list that we want to ignore if they
3597c478bdstevel@tonic-gate *				also show up in a function-specific CIS.
3607c478bdstevel@tonic-gate */
3617c478bdstevel@tonic-gatetypedef struct cistpl_ignore_list_t {
3627c478bdstevel@tonic-gate	cisdata_t	type;
3637c478bdstevel@tonic-gate} cistpl_ignore_list_t;
3647c478bdstevel@tonic-gate
3657c478bdstevel@tonic-gate#ifdef	__cplusplus
3667c478bdstevel@tonic-gate}
3677c478bdstevel@tonic-gate#endif
3687c478bdstevel@tonic-gate
3697c478bdstevel@tonic-gate#endif	/* _CIS_H */
370