17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
235f9e250aShx  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * This file contains the tuple handlers that are called by the CIS
297c478bd9Sstevel@tonic-gate  *	parser.
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  * XXX - how about a better explaination??
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/systm.h>
367c478bd9Sstevel@tonic-gate #include <sys/user.h>
377c478bd9Sstevel@tonic-gate #include <sys/buf.h>
387c478bd9Sstevel@tonic-gate #include <sys/file.h>
397c478bd9Sstevel@tonic-gate #include <sys/uio.h>
407c478bd9Sstevel@tonic-gate #include <sys/conf.h>
417c478bd9Sstevel@tonic-gate #include <sys/stat.h>
427c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
437c478bd9Sstevel@tonic-gate #include <sys/vtoc.h>
447c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
457c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
467c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
477c478bd9Sstevel@tonic-gate #include <sys/debug.h>
487c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
497c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
507c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
517c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
527c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
537c478bd9Sstevel@tonic-gate #include <sys/callb.h>
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #include <sys/pctypes.h>
567c478bd9Sstevel@tonic-gate #include <pcmcia/sys/cs_types.h>
577c478bd9Sstevel@tonic-gate #include <pcmcia/sys/cis.h>
587c478bd9Sstevel@tonic-gate #include <pcmcia/sys/cis_handlers.h>
597c478bd9Sstevel@tonic-gate #include <pcmcia/sys/cs.h>
607c478bd9Sstevel@tonic-gate #include <pcmcia/sys/cs_priv.h>
617c478bd9Sstevel@tonic-gate #include <pcmcia/sys/cis_protos.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * Function prototypes
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate static void cistpl_pd_parse(cistpl_t *, cistpl_cftable_entry_pwr_t *);
677c478bd9Sstevel@tonic-gate static void cis_return_name(cistpl_callout_t *, cistpl_get_tuple_name_t *);
687c478bd9Sstevel@tonic-gate 
695f9e250aShx /*
705f9e250aShx  * Fetch data functions.
715f9e250aShx  */
725f9e250aShx uint16_t
cis_get_short(cistpl_t * tp)735f9e250aShx cis_get_short(cistpl_t *tp)
745f9e250aShx {
755f9e250aShx 	uint16_t result;
765f9e250aShx 
775f9e250aShx 	if (tp->flags & CISTPLF_AM_SPACE) {
785f9e250aShx 		result = GET_AM_BYTE(tp);
795f9e250aShx 		result |= GET_AM_BYTE(tp) << 8;
805f9e250aShx 	} else {
815f9e250aShx 		result = GET_CM_BYTE(tp);
825f9e250aShx 		result |= GET_CM_BYTE(tp) << 8;
835f9e250aShx 	}
845f9e250aShx 	return (result);
855f9e250aShx }
865f9e250aShx 
875f9e250aShx uint16_t
cis_get_be_short(cistpl_t * tp)885f9e250aShx cis_get_be_short(cistpl_t *tp)
895f9e250aShx {
905f9e250aShx 	uint16_t result;
915f9e250aShx 
925f9e250aShx 	if (tp->flags & CISTPLF_AM_SPACE) {
935f9e250aShx 		result = GET_AM_BYTE(tp) << 8;
945f9e250aShx 		result |= GET_AM_BYTE(tp);
955f9e250aShx 	} else {
965f9e250aShx 		result = GET_CM_BYTE(tp) << 8;
975f9e250aShx 		result |= GET_CM_BYTE(tp);
985f9e250aShx 	}
995f9e250aShx 	return (result);
1005f9e250aShx }
1015f9e250aShx 
1025f9e250aShx uint32_t
cis_get_int24(cistpl_t * tp)1035f9e250aShx cis_get_int24(cistpl_t *tp)
1045f9e250aShx {
1055f9e250aShx 	uint32_t result = cis_get_short(tp);
1065f9e250aShx 
1075f9e250aShx 	result |= GET_BYTE(tp) << 16;
1085f9e250aShx 	return (result);
1095f9e250aShx }
1105f9e250aShx 
1115f9e250aShx uint32_t
cis_get_long(cistpl_t * tp)1125f9e250aShx cis_get_long(cistpl_t *tp)
1135f9e250aShx {
1145f9e250aShx 	uint32_t result = cis_get_short(tp);
1155f9e250aShx 
1165f9e250aShx 	result |= cis_get_short(tp) << 16;
1175f9e250aShx 	return (result);
1185f9e250aShx }
1195f9e250aShx 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * cis_tuple_handler - call the handler for the tuple described by the
1227c478bd9Sstevel@tonic-gate  *				tuple pointer
1237c478bd9Sstevel@tonic-gate  *
1247c478bd9Sstevel@tonic-gate  *	cistpl_callout_t *co - pointer to callout structure
1257c478bd9Sstevel@tonic-gate  *				array to use to find this tuple
1267c478bd9Sstevel@tonic-gate  *	cistpl_t *tp - pointer to a tuple structure
1277c478bd9Sstevel@tonic-gate  *	int flags - action for the handler to perform
1287c478bd9Sstevel@tonic-gate  * XXX - we need a description of the flags passed to the tuple handler
1297c478bd9Sstevel@tonic-gate  *	void *arg - argument to pass on to tuple handler
1307c478bd9Sstevel@tonic-gate  *
1317c478bd9Sstevel@tonic-gate  * If the tuple is not recognized but is is a vendor-specific tuple, we
1327c478bd9Sstevel@tonic-gate  *	set the CISTPLF_VENDOR_SPECIFIC flag in the tuple.
1337c478bd9Sstevel@tonic-gate  *
1347c478bd9Sstevel@tonic-gate  * We return CISTPLF_UNKNOWN if this is an unrecognized	tuple as well as
1357c478bd9Sstevel@tonic-gate  *	set the CISTPLF_UNKNOWN flag in the tuple list structure.  Note
1367c478bd9Sstevel@tonic-gate  *	that encountering an unknown tuple is not necessarily an error,
1377c478bd9Sstevel@tonic-gate  *	so we don't set the HANDTPL_ERROR flag on the return code.  It
1387c478bd9Sstevel@tonic-gate  *	is up to the caller to determine what an unrecognized tuple means.
1397c478bd9Sstevel@tonic-gate  *
1407c478bd9Sstevel@tonic-gate  * If this is a recognized tuple, the apropriate tuple handler is called and
1417c478bd9Sstevel@tonic-gate  *	the return value from the handler is returned directly to the caller.
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * The void *arg is optional, and it's meaning is dependent on the
1447c478bd9Sstevel@tonic-gate  *	particular tuple handler called and the flags parameter.
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  * For the special case of HANDTPL_RETURN_NAME, we don't bother calling the
1477c478bd9Sstevel@tonic-gate  *	tuple handler and just return the tuple name to the caller.
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate uint32_t
cis_tuple_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg,cisdata_t subtype)1507c478bd9Sstevel@tonic-gate cis_tuple_handler(cistpl_callout_t *co, cistpl_t *tp, uint32_t flags,
1517c478bd9Sstevel@tonic-gate 					void *arg, cisdata_t subtype)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	/*
1547c478bd9Sstevel@tonic-gate 	 * Check to see if this is a vendor-specific tuple.
1557c478bd9Sstevel@tonic-gate 	 */
1567c478bd9Sstevel@tonic-gate 	if (CISTPL_IS_VENDOR_SPECIFIC(tp->type))
1577c478bd9Sstevel@tonic-gate 	    tp->flags |= CISTPLF_VENDOR_SPECIFIC;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * Scan the callout list until we find the tuple passed to us, or we
1617c478bd9Sstevel@tonic-gate 	 *	encounter a CISTPL_END in the callout list, which signals that
1627c478bd9Sstevel@tonic-gate 	 *	there are no more tuples in the callout list.
1637c478bd9Sstevel@tonic-gate 	 */
1647c478bd9Sstevel@tonic-gate 	while (co->type != (cisdata_t)CISTPL_END) {
1657c478bd9Sstevel@tonic-gate 	    if (co->type == tp->type &&
1667c478bd9Sstevel@tonic-gate 		((tp->type != CISTPL_FUNCE) ||
1677c478bd9Sstevel@tonic-gate 		    (tp->type == CISTPL_FUNCE && co->subtype == subtype))) {
1687c478bd9Sstevel@tonic-gate 			tp->flags &= ~CISTPLF_UNKNOWN;
1697c478bd9Sstevel@tonic-gate 			if (flags & HANDTPL_RETURN_NAME) {
1707c478bd9Sstevel@tonic-gate 			    cis_return_name(co, (cistpl_get_tuple_name_t *)arg);
1717c478bd9Sstevel@tonic-gate 			    return (CISTPLF_NOERROR);
1727c478bd9Sstevel@tonic-gate 			} else {
1737c478bd9Sstevel@tonic-gate 			    return ((*co->handler) (co, tp, flags, arg));
1747c478bd9Sstevel@tonic-gate 			} /* HANDTPL_RETURN_NAME */
1757c478bd9Sstevel@tonic-gate 	    } /* if */
1767c478bd9Sstevel@tonic-gate 	    co++;
1777c478bd9Sstevel@tonic-gate 	} /* while */
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	/*
1807c478bd9Sstevel@tonic-gate 	 * If we didn't recognize the tuple and the caller wants the tuple
1817c478bd9Sstevel@tonic-gate 	 *	name back, then return the "unknown tuple" string. At this
1827c478bd9Sstevel@tonic-gate 	 *	point, "co" will be pointing to the last entry in the
1837c478bd9Sstevel@tonic-gate 	 *	callout list. It's not an error to not recognize the tuple
1847c478bd9Sstevel@tonic-gate 	 *	when the operation is HANDTPL_RETURN_NAME.
1857c478bd9Sstevel@tonic-gate 	 */
1867c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_RETURN_NAME) {
1877c478bd9Sstevel@tonic-gate 	    cis_return_name(co, (cistpl_get_tuple_name_t *)arg);
1887c478bd9Sstevel@tonic-gate 	    return (CISTPLF_NOERROR);
1897c478bd9Sstevel@tonic-gate 	}
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	tp->flags |= CISTPLF_UNKNOWN;
1927c478bd9Sstevel@tonic-gate 	return (CISTPLF_UNKNOWN);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * cis_no_tuple_handler - this generic tuple handler is used if no special
1977c478bd9Sstevel@tonic-gate  *				tuple processing is required for the passed
1987c478bd9Sstevel@tonic-gate  *				tuple
1997c478bd9Sstevel@tonic-gate  *
2007c478bd9Sstevel@tonic-gate  *	cistpl_callout_t *co - pointer to this tuple's entry in the
2017c478bd9Sstevel@tonic-gate  *				tuple callout structure
2027c478bd9Sstevel@tonic-gate  *	cistpl_t *tp - pointer to this tuple's entry in the local linked list
2037c478bd9Sstevel@tonic-gate  *	int flags - action to perform
2047c478bd9Sstevel@tonic-gate  *
2057c478bd9Sstevel@tonic-gate  * This handler will set the CISTPLF_COPYOK flag if the tuple link is greater
2067c478bd9Sstevel@tonic-gate  *	than zero, indicating that it's OK to copy the tuple data body. It
2077c478bd9Sstevel@tonic-gate  *	will also set whatever flags are specified in the callout structure.
2087c478bd9Sstevel@tonic-gate  *
2097c478bd9Sstevel@tonic-gate  * We always set the CISTPLF_VALID when we're called with HANDTPL_COPY_DONE.
2107c478bd9Sstevel@tonic-gate  *
2117c478bd9Sstevel@tonic-gate  * We return CISTPLF_UNKNOWN if we're being called to parse the tuple.
2127c478bd9Sstevel@tonic-gate  *
2137c478bd9Sstevel@tonic-gate  * We return CISTPLF_NOERROR in every other case to indicate that this is a
2147c478bd9Sstevel@tonic-gate  *	recognized tuple.
2157c478bd9Sstevel@tonic-gate  */
2167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2177c478bd9Sstevel@tonic-gate uint32_t
cis_no_tuple_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg)2187c478bd9Sstevel@tonic-gate cis_no_tuple_handler(cistpl_callout_t *co, cistpl_t *tp,
2197c478bd9Sstevel@tonic-gate 					uint32_t flags, void *arg)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_SET_FLAGS) {
2227c478bd9Sstevel@tonic-gate 		tp->flags |= co->flags;	/* XXX - is = the right thing here? */
2237c478bd9Sstevel@tonic-gate 		if (tp->len > 0)
2247c478bd9Sstevel@tonic-gate 			tp->flags |= CISTPLF_COPYOK;
2257c478bd9Sstevel@tonic-gate 	}
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_COPY_DONE)
2287c478bd9Sstevel@tonic-gate 		tp->flags |= CISTPLF_VALID;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_PARSE_LTUPLE)
2317c478bd9Sstevel@tonic-gate 	    return (CISTPLF_UNKNOWN);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	return (CISTPLF_NOERROR);
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * cis_unknown_tuple_handler - this generic tuple handler is used if we don't
2387c478bd9Sstevel@tonic-gate  *				understand this tuple
2397c478bd9Sstevel@tonic-gate  *
2407c478bd9Sstevel@tonic-gate  *	cistpl_callout_t *co - pointer to this tuple's entry in the
2417c478bd9Sstevel@tonic-gate  *				tuple callout structure
2427c478bd9Sstevel@tonic-gate  *	cistpl_t *tp - pointer to this tuple's entry in the local linked list
2437c478bd9Sstevel@tonic-gate  *	int flags - action to perform
2447c478bd9Sstevel@tonic-gate  *
2457c478bd9Sstevel@tonic-gate  * This handler will not set the CISTPLF_COPYOK flag since we don't know the
2467c478bd9Sstevel@tonic-gate  *	contents of a vendor-specific tuple.
2477c478bd9Sstevel@tonic-gate  *
2487c478bd9Sstevel@tonic-gate  * We always set the CISTPLF_VALID when we're called with HANDTPL_COPY_DONE
2497c478bd9Sstevel@tonic-gate  *	to specify that we understand this tuple's code, but not it's data
2507c478bd9Sstevel@tonic-gate  *	body.
2517c478bd9Sstevel@tonic-gate  *
2527c478bd9Sstevel@tonic-gate  * We return CISTPLF_UNKNOWN if we're being called to parse the tuple or to
2537c478bd9Sstevel@tonic-gate  *	perform any other operation.
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2567c478bd9Sstevel@tonic-gate uint32_t
cis_unknown_tuple_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg)2577c478bd9Sstevel@tonic-gate cis_unknown_tuple_handler(cistpl_callout_t *co, cistpl_t *tp,
2587c478bd9Sstevel@tonic-gate 					uint32_t flags, void *arg)
2597c478bd9Sstevel@tonic-gate {
2607c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_SET_FLAGS) {
2617c478bd9Sstevel@tonic-gate 		tp->flags |= co->flags;	/* XXX - is = the right thing here? */
2627c478bd9Sstevel@tonic-gate 		return (CISTPLF_NOERROR);
2637c478bd9Sstevel@tonic-gate 	}
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_COPY_DONE) {
2667c478bd9Sstevel@tonic-gate 		tp->flags |= CISTPLF_VALID;
2677c478bd9Sstevel@tonic-gate 		return (CISTPLF_NOERROR);
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	return (CISTPLF_UNKNOWN);
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * cistpl_vers_1_handler - handler for the CISTPL_VERS_1 tuple
2757c478bd9Sstevel@tonic-gate  *
2767c478bd9Sstevel@tonic-gate  *	void *arg - points to a cistpl_vers_1_t * where the
2777c478bd9Sstevel@tonic-gate  *			information is stuffed into
2787c478bd9Sstevel@tonic-gate  */
2797c478bd9Sstevel@tonic-gate uint32_t
cistpl_vers_1_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg)2807c478bd9Sstevel@tonic-gate cistpl_vers_1_handler(cistpl_callout_t *co, cistpl_t *tp,
2817c478bd9Sstevel@tonic-gate 					uint32_t flags, void *arg)
2827c478bd9Sstevel@tonic-gate {
2837c478bd9Sstevel@tonic-gate 	/*
2847c478bd9Sstevel@tonic-gate 	 * nothing special about our flags, so just call the
2857c478bd9Sstevel@tonic-gate 	 *	generic handler for this
2867c478bd9Sstevel@tonic-gate 	 */
2877c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_SET_FLAGS)
2887c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	/*
2917c478bd9Sstevel@tonic-gate 	 * We don't currently validate this tuple. This call will
2927c478bd9Sstevel@tonic-gate 	 *	always set tp->flags |= CISTPLF_VALID.
2937c478bd9Sstevel@tonic-gate 	 */
2947c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_COPY_DONE)
2957c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_PARSE_LTUPLE) {
2987c478bd9Sstevel@tonic-gate 		cistpl_vers_1_t *cs = (cistpl_vers_1_t *)arg;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 		RESET_TP(tp);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 		cs->major = GET_BYTE(tp);
3047c478bd9Sstevel@tonic-gate 		cs->minor = GET_BYTE(tp);
3057c478bd9Sstevel@tonic-gate 		for (cs->ns = 0; GET_LEN(tp) > 0 &&
3067c478bd9Sstevel@tonic-gate 				/* CSTYLED */
3077c478bd9Sstevel@tonic-gate 				cs->ns < CISTPL_VERS_1_MAX_PROD_STRINGS; ) {
3087c478bd9Sstevel@tonic-gate 			(void) strcpy(cs->pi[cs->ns++], cis_getstr(tp));
3097c478bd9Sstevel@tonic-gate 		} /* for */
3107c478bd9Sstevel@tonic-gate 	} /* HANDTPL_PARSE_LTUPLE */
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	return (CISTPLF_NOERROR);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate  * cistpl_config_handler - handler for the CISTPL_CONFIG tuple
3177c478bd9Sstevel@tonic-gate  *
3187c478bd9Sstevel@tonic-gate  *	void *arg - points to a XXX where the information is stuffed into
3197c478bd9Sstevel@tonic-gate  *
3207c478bd9Sstevel@tonic-gate  * For the first ten config registers we set the present flags in the
3217c478bd9Sstevel@tonic-gate  *	cistpl_config_t if the register exists.  The flags that we use
3227c478bd9Sstevel@tonic-gate  *	for this are the same as the flags reguired for the Card Services
3237c478bd9Sstevel@tonic-gate  *	RequestConfiguration function and they can be used by clients
3247c478bd9Sstevel@tonic-gate  *	directly without requiring any remapping of values.
3257c478bd9Sstevel@tonic-gate  *
3267c478bd9Sstevel@tonic-gate  * XXX we don't handle TPCC_SBTPL subtuples yet
3277c478bd9Sstevel@tonic-gate  */
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate uint32_t	config_regs_present_map[] = {
3307c478bd9Sstevel@tonic-gate 	CONFIG_OPTION_REG_PRESENT,	/* COR present */
3317c478bd9Sstevel@tonic-gate 	CONFIG_STATUS_REG_PRESENT,	/* STAT reg present */
3327c478bd9Sstevel@tonic-gate 	CONFIG_PINREPL_REG_PRESENT,	/* PRR present */
3337c478bd9Sstevel@tonic-gate 	CONFIG_COPY_REG_PRESENT,	/* COPY reg present */
3347c478bd9Sstevel@tonic-gate 	CONFIG_EXSTAT_REG_PRESENT,	/* EXSTAT reg present */
3357c478bd9Sstevel@tonic-gate 	CONFIG_IOBASE0_REG_PRESENT,	/* IOBASE0 reg present */
3367c478bd9Sstevel@tonic-gate 	CONFIG_IOBASE1_REG_PRESENT,	/* IOBASE1 reg present */
3377c478bd9Sstevel@tonic-gate 	CONFIG_IOBASE2_REG_PRESENT,	/* IOBASE2 reg present */
3387c478bd9Sstevel@tonic-gate 	CONFIG_IOBASE3_REG_PRESENT,	/* IOBASE3 reg present */
3397c478bd9Sstevel@tonic-gate 	CONFIG_IOLIMIT_REG_PRESENT,	/* IOLIMIT reg present */
3407c478bd9Sstevel@tonic-gate };
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate uint32_t
cistpl_config_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg)3437c478bd9Sstevel@tonic-gate cistpl_config_handler(cistpl_callout_t *co, cistpl_t *tp,
3447c478bd9Sstevel@tonic-gate 					uint32_t flags, void *arg)
3457c478bd9Sstevel@tonic-gate {
3467c478bd9Sstevel@tonic-gate 	cisdata_t tpcc_sz;
3477c478bd9Sstevel@tonic-gate 	int i, n, nrb, na, hr = 0;
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	/*
3507c478bd9Sstevel@tonic-gate 	 * nothing special about our flags, so just call the
3517c478bd9Sstevel@tonic-gate 	 *	generic handler for this
3527c478bd9Sstevel@tonic-gate 	 */
3537c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_SET_FLAGS)
3547c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	/*
3577c478bd9Sstevel@tonic-gate 	 * We don't currently validate this tuple. This call will
3587c478bd9Sstevel@tonic-gate 	 *	always set tp->flags |= CISTPLF_VALID.
3597c478bd9Sstevel@tonic-gate 	 */
3607c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_COPY_DONE)
3617c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_PARSE_LTUPLE) {
3647c478bd9Sstevel@tonic-gate 		cistpl_config_t *cr = (cistpl_config_t *)arg;
3657c478bd9Sstevel@tonic-gate 		int crn = 0;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 		RESET_TP(tp);
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		tpcc_sz = GET_BYTE(tp);		/* config regs size fields */
3707c478bd9Sstevel@tonic-gate 		cr->last = GET_BYTE(tp);	/* last config index */
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 		na = (tpcc_sz&3)+1;		/* config regs address bytes */
3737c478bd9Sstevel@tonic-gate 		nrb = ((tpcc_sz>>2)&0x0f)+1;	/* number of bytes in config */
3747c478bd9Sstevel@tonic-gate 						/*	regs presence mask */
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 		/*
3777c478bd9Sstevel@tonic-gate 		 * Construct the base offset address for the config registers.
3787c478bd9Sstevel@tonic-gate 		 *	We jump through these hoops because the base address
3797c478bd9Sstevel@tonic-gate 		 *	can be between one and four bytes in length.
3807c478bd9Sstevel@tonic-gate 		 */
3817c478bd9Sstevel@tonic-gate 		cr->base = 0;
3827c478bd9Sstevel@tonic-gate 		n = na;
3837c478bd9Sstevel@tonic-gate 		while (n--)
3847c478bd9Sstevel@tonic-gate 			cr->base |= ((GET_BYTE(tp) & 0x0ff) <<
3857c478bd9Sstevel@tonic-gate 							(8 * (na - (n+1))));
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 		/*
3887c478bd9Sstevel@tonic-gate 		 * Go through the config register presense mask bit by bit and
3897c478bd9Sstevel@tonic-gate 		 *	figure out which config registers are present and which
3907c478bd9Sstevel@tonic-gate 		 *	aren't.
3917c478bd9Sstevel@tonic-gate 		 * For the first ten config registers, set the appropriate
3927c478bd9Sstevel@tonic-gate 		 *	bits in the cr->present member so that the caller
3937c478bd9Sstevel@tonic-gate 		 *	doesn't have to do this.
3947c478bd9Sstevel@tonic-gate 		 */
3957c478bd9Sstevel@tonic-gate 		cr->nr = 0;
3967c478bd9Sstevel@tonic-gate 		cr->present = 0;
3977c478bd9Sstevel@tonic-gate 		n = nrb;
3987c478bd9Sstevel@tonic-gate 		while (n--) {
3997c478bd9Sstevel@tonic-gate 			for (i = 0; i < 8; i++, crn++) {
4007c478bd9Sstevel@tonic-gate 				if (LOOK_BYTE(tp) & (1<<i)) {
4017c478bd9Sstevel@tonic-gate 				    if (crn < (sizeof (config_regs_present_map)/
4027c478bd9Sstevel@tonic-gate 							sizeof (uint32_t)))
4037c478bd9Sstevel@tonic-gate 					cr->present |=
4047c478bd9Sstevel@tonic-gate 						config_regs_present_map[crn];
4057c478bd9Sstevel@tonic-gate 				    cr->nr++;
4067c478bd9Sstevel@tonic-gate 				    cr->hr = hr;
4077c478bd9Sstevel@tonic-gate 				    cr->regs[hr] = MAKE_CONFIG_REG_ADDR(
4087c478bd9Sstevel@tonic-gate 								cr->base, hr);
4097c478bd9Sstevel@tonic-gate 				} /* LOOK_BYTE */
4107c478bd9Sstevel@tonic-gate 				hr++;
4117c478bd9Sstevel@tonic-gate 			} /* for */
4127c478bd9Sstevel@tonic-gate 			(void) GET_BYTE(tp);
4137c478bd9Sstevel@tonic-gate 		} /* while */
4147c478bd9Sstevel@tonic-gate 	}
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	return (CISTPLF_NOERROR);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate /*
4207c478bd9Sstevel@tonic-gate  * cistpl_device_handler - handler for the CISTPL_DEVICE, CISTPL_DEVICE_A,
4217c478bd9Sstevel@tonic-gate  *				CISTPL_DEVICE_OC and CISTPL_DEVICE_OA tuples
4227c478bd9Sstevel@tonic-gate  *
4237c478bd9Sstevel@tonic-gate  *	void *arg - points to a cistpl_device_t * where the
4247c478bd9Sstevel@tonic-gate  *			information is stuffed into
4257c478bd9Sstevel@tonic-gate  *
4267c478bd9Sstevel@tonic-gate  * XXX - we only handle CISTPL_DEVICE_MAX_DEVICES device descriptions
4277c478bd9Sstevel@tonic-gate  *		described in the tuple
4287c478bd9Sstevel@tonic-gate  */
4297c478bd9Sstevel@tonic-gate uint32_t
cistpl_device_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg)4307c478bd9Sstevel@tonic-gate cistpl_device_handler(cistpl_callout_t *co, cistpl_t *tp,
4317c478bd9Sstevel@tonic-gate 					uint32_t flags, void *arg)
4327c478bd9Sstevel@tonic-gate {
4337c478bd9Sstevel@tonic-gate 	cisdata_t dev_id;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	/*
4367c478bd9Sstevel@tonic-gate 	 * nothing special about our flags, so just call the
4377c478bd9Sstevel@tonic-gate 	 *	generic handler for this
4387c478bd9Sstevel@tonic-gate 	 */
4397c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_SET_FLAGS)
4407c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 	/*
4437c478bd9Sstevel@tonic-gate 	 * We don't currently validate this tuple. This call will
4447c478bd9Sstevel@tonic-gate 	 *	always set tp->flags |= CISTPLF_VALID.
4457c478bd9Sstevel@tonic-gate 	 */
4467c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_COPY_DONE)
4477c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_PARSE_LTUPLE) {
4507c478bd9Sstevel@tonic-gate 		convert_speed_t convert_speed;
4517c478bd9Sstevel@tonic-gate 		cistpl_device_t *dt = (cistpl_device_t *)arg;
4527c478bd9Sstevel@tonic-gate 		cistpl_device_node_t *cdn;
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 		/*
4557c478bd9Sstevel@tonic-gate 		 * XXX - fix this to look for more than one device definition
4567c478bd9Sstevel@tonic-gate 		 * XXX - fix this to handle the OC fields for
4577c478bd9Sstevel@tonic-gate 		 *	CISTPL_DEVICE_OC and CISTPL_DEVICE_OA
4587c478bd9Sstevel@tonic-gate 		 */
4597c478bd9Sstevel@tonic-gate 		dt->num_devices = 1;
4607c478bd9Sstevel@tonic-gate 		cdn = &dt->devnode[0];
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 		cdn->flags = 0;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 		RESET_TP(tp);
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 		dev_id = GET_BYTE(tp);
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 		/*
4697c478bd9Sstevel@tonic-gate 		 * Get the device speed code.  If it's 7, then there is an
4707c478bd9Sstevel@tonic-gate 		 *	extended speed code table in use, so parse that.
4717c478bd9Sstevel@tonic-gate 		 *	If it's anything else, get the speed information
4727c478bd9Sstevel@tonic-gate 		 *	directly from the device speed code.
4737c478bd9Sstevel@tonic-gate 		 */
4747c478bd9Sstevel@tonic-gate 		if ((dev_id & 7) == 7) {
4757c478bd9Sstevel@tonic-gate 		    cdn->nS_speed = cistpl_devspeed(tp, 0, CISTPL_DEVSPEED_EXT);
4767c478bd9Sstevel@tonic-gate 		} else {
4777c478bd9Sstevel@tonic-gate 		    cdn->nS_speed = cistpl_devspeed(NULL, dev_id,
4787c478bd9Sstevel@tonic-gate 							CISTPL_DEVSPEED_TABLE);
4797c478bd9Sstevel@tonic-gate 		}
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 		/*
4827c478bd9Sstevel@tonic-gate 		 * Convert the speed in nS to a device speed code.
4837c478bd9Sstevel@tonic-gate 		 * XXX -  should check return code from cis_convert_devspeed()
4847c478bd9Sstevel@tonic-gate 		 */
4857c478bd9Sstevel@tonic-gate 		convert_speed.Attributes = CONVERT_NS_TO_DEVSPEED;
4867c478bd9Sstevel@tonic-gate 		convert_speed.nS = cdn->nS_speed;
4877c478bd9Sstevel@tonic-gate 		(void) cis_convert_devspeed(&convert_speed);
4887c478bd9Sstevel@tonic-gate 		cdn->speed = convert_speed.devspeed;
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 		if (dev_id & 8)
4917c478bd9Sstevel@tonic-gate 			cdn->flags |= CISTPL_DEVICE_WPS;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 		/*
4947c478bd9Sstevel@tonic-gate 		 * Set the device type.  Note that we take the raw value
4957c478bd9Sstevel@tonic-gate 		 *	from the tuple and pass it back to the caller.
4967c478bd9Sstevel@tonic-gate 		 *	If the device type codes in the standard change,
4977c478bd9Sstevel@tonic-gate 		 *	we will have to change our flags as well.
4987c478bd9Sstevel@tonic-gate 		 */
4997c478bd9Sstevel@tonic-gate 		cdn->type = (dev_id>>4) & 0x0f;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 		/*
5027c478bd9Sstevel@tonic-gate 		 * XXX - what about the device_size byte?  Is the spec wrong?
5037c478bd9Sstevel@tonic-gate 		 */
5047c478bd9Sstevel@tonic-gate 		cdn->size = GET_BYTE(tp);
5057c478bd9Sstevel@tonic-gate 		/* check for end of list */
5067c478bd9Sstevel@tonic-gate 		if (cdn->size != 0x0ff) {
5077c478bd9Sstevel@tonic-gate 		    convert_size_t convert_size;
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 		    convert_size.devsize = cdn->size;
5107c478bd9Sstevel@tonic-gate 		    convert_size.Attributes = CONVERT_DEVSIZE_TO_BYTES;
5117c478bd9Sstevel@tonic-gate 		    (void) cis_convert_devsize(&convert_size);
5127c478bd9Sstevel@tonic-gate 		    cdn->size_in_bytes = convert_size.bytes;
5137c478bd9Sstevel@tonic-gate 		}
5147c478bd9Sstevel@tonic-gate 	}
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	return (CISTPLF_NOERROR);
5177c478bd9Sstevel@tonic-gate }
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate /*
5207c478bd9Sstevel@tonic-gate  * cistpl_cftable_handler - handler for the CISTPL_CFTABLE_ENTRY tuple
5217c478bd9Sstevel@tonic-gate  *
5227c478bd9Sstevel@tonic-gate  *	void *arg - points to a XXX where the information is stuffed into
5237c478bd9Sstevel@tonic-gate  *
5247c478bd9Sstevel@tonic-gate  *    Return:	CISTPLF_NOERROR - if no error parsing tuple
5257c478bd9Sstevel@tonic-gate  *		HANDTPL_ERROR - if error parsing tuple
5267c478bd9Sstevel@tonic-gate  */
5277c478bd9Sstevel@tonic-gate extern uint32_t cistpl_cftable_io_size_table[];
5287c478bd9Sstevel@tonic-gate extern uint32_t cistpl_cftable_shift_table[];
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate uint32_t
cistpl_cftable_handler(cistpl_callout_t * co,cistpl_t * tp,uint32_t flags,void * arg)5317c478bd9Sstevel@tonic-gate cistpl_cftable_handler(cistpl_callout_t *co, cistpl_t *tp,
5327c478bd9Sstevel@tonic-gate 					uint32_t flags, void *arg)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	cisdata_t tpce_indx, tpce_fs, tpce_td, sf, tpce_io, nr;
5357c478bd9Sstevel@tonic-gate 	cisdata_t ior_desc, tpce_ir, tpce_msd;
5367c478bd9Sstevel@tonic-gate 	int i, j;
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 	/*
5397c478bd9Sstevel@tonic-gate 	 * nothing special about our flags, so just call the
5407c478bd9Sstevel@tonic-gate 	 *	generic handler for this
5417c478bd9Sstevel@tonic-gate 	 */
5427c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_SET_FLAGS)
5437c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	/*
5467c478bd9Sstevel@tonic-gate 	 * We don't currently validate this tuple. This call will
5477c478bd9Sstevel@tonic-gate 	 *	always set tp->flags |= CISTPLF_VALID.
5487c478bd9Sstevel@tonic-gate 	 */
5497c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_COPY_DONE)
5507c478bd9Sstevel@tonic-gate 		return (cis_no_tuple_handler(co, tp, flags, arg));
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	if (flags & HANDTPL_PARSE_LTUPLE) {
5537c478bd9Sstevel@tonic-gate 		cistpl_cftable_entry_t *ce = (cistpl_cftable_entry_t *)arg;
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 		RESET_TP(tp);
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 		/*
5587c478bd9Sstevel@tonic-gate 		 * Check to see if we have an interface description byte.  If
5597c478bd9Sstevel@tonic-gate 		 *	we do, grab it and give it directly to the caller, and
5607c478bd9Sstevel@tonic-gate 		 *	set a flag so the caller knows that it's there.
5617c478bd9Sstevel@tonic-gate 		 * We also setup the appropriate values in the ce->pin member
5627c478bd9Sstevel@tonic-gate 		 *	so that clients can feed this value directly to the
5637c478bd9Sstevel@tonic-gate 		 *	Card Services RequestConfiguration call.
5647c478bd9Sstevel@tonic-gate 		 */
5657c478bd9Sstevel@tonic-gate 		if ((tpce_indx = GET_BYTE(tp)) & CISTPL_CFTABLE_TPCE_IFM) {
5667c478bd9Sstevel@tonic-gate 			ce->ifc = GET_BYTE(tp);
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 			ce->pin = 0;
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 			if (ce->ifc & CISTPL_CFTABLE_TPCE_IF_BVD)
5717c478bd9Sstevel@tonic-gate 			    ce->pin |= (PRR_BVD1_STATUS | PRR_BVD2_STATUS |
5727c478bd9Sstevel@tonic-gate 					PRR_BVD1_EVENT | PRR_BVD2_EVENT);
5737c478bd9Sstevel@tonic-gate 			if (ce->ifc & CISTPL_CFTABLE_TPCE_IF_WP)
5747c478bd9Sstevel@tonic-gate 			    ce->pin |= (PRR_WP_STATUS | PRR_WP_EVENT);
5757c478bd9Sstevel@tonic-gate 			if (ce->ifc & CISTPL_CFTABLE_TPCE_IF_RDY)
5767c478bd9Sstevel@tonic-gate 			    ce->pin |= (PRR_READY_STATUS | PRR_READY_EVENT);
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 			ce->flags |= CISTPL_CFTABLE_TPCE_IF;
5797c478bd9Sstevel@tonic-gate 		}
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 		/*
5827c478bd9Sstevel@tonic-gate 		 * Return the configuration index to the caller, and set the
5837c478bd9Sstevel@tonic-gate 		 *	default configuration flag if this is a default
5847c478bd9Sstevel@tonic-gate 		 *	configuration.
5857c478bd9Sstevel@tonic-gate 		 */
5867c478bd9Sstevel@tonic-gate 		ce->index = tpce_indx & CISTPL_CFTABLE_TPCE_CFGENTRYM;
5877c478bd9Sstevel@tonic-gate 		if (tpce_indx & CISTPL_CFTABLE_TPCE_DEFAULTM)
5887c478bd9Sstevel@tonic-gate 			ce->flags |= CISTPL_CFTABLE_TPCE_DEFAULT;
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 		/*
5917c478bd9Sstevel@tonic-gate 		 * Feature selection flags.
5927c478bd9Sstevel@tonic-gate 		 */
5937c478bd9Sstevel@tonic-gate 		tpce_fs = GET_BYTE(tp);
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 		/*
5967c478bd9Sstevel@tonic-gate 		 * See what types of power information are available,
5977c478bd9Sstevel@tonic-gate 		 *	and if there is any, set the global power
5987c478bd9Sstevel@tonic-gate 		 *	information flag as well as a flag for each
5997c478bd9Sstevel@tonic-gate 		 *	power description available.
6007c478bd9Sstevel@tonic-gate 		 */
6017c478bd9Sstevel@tonic-gate 		if (tpce_fs & CISTPL_CFTABLE_TPCE_FS_PWRM) {
6027c478bd9Sstevel@tonic-gate 		    cistpl_cftable_entry_pd_t *pd = &ce->pd;
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 		    ce->flags |= CISTPL_CFTABLE_TPCE_FS_PWR;
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 		    switch (tpce_fs & CISTPL_CFTABLE_TPCE_FS_PWRM) {
6077c478bd9Sstevel@tonic-gate 			case CISTPL_CFTABLE_TPCE_FS_PWR_VPP2M:
6087c478bd9Sstevel@tonic-gate 				pd->flags |= CISTPL_CFTABLE_TPCE_FS_PWR_VPP2;
6097c478bd9Sstevel@tonic-gate 				/* FALLTHROUGH */
6107c478bd9Sstevel@tonic-gate 			case CISTPL_CFTABLE_TPCE_FS_PWR_VPP1M:
6117c478bd9Sstevel@tonic-gate 				pd->flags |= CISTPL_CFTABLE_TPCE_FS_PWR_VPP1;
6127c478bd9Sstevel@tonic-gate 				/* FALLTHROUGH */
6137c478bd9Sstevel@tonic-gate 			case CISTPL_CFTABLE_TPCE_FS_PWR_VCCM:
6147c478bd9Sstevel@tonic-gate 				pd->flags |= CISTPL_CFTABLE_TPCE_FS_PWR_VCC;
6157c478bd9Sstevel@tonic-gate 		    } /* switch */
6167c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_PWRM) */
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 		/*
6197c478bd9Sstevel@tonic-gate 		 * Set up the global memory information flag.
6207c478bd9Sstevel@tonic-gate 		 */
6217c478bd9Sstevel@tonic-gate 		if (tpce_fs & CISTPL_CFTABLE_TPCE_FS_MEMM)
6227c478bd9Sstevel@tonic-gate 			ce->flags |= CISTPL_CFTABLE_TPCE_FS_MEM;
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 		/*
6257c478bd9Sstevel@tonic-gate 		 * Parse the various power description structures.
6267c478bd9Sstevel@tonic-gate 		 */
6277c478bd9Sstevel@tonic-gate 		if (ce->flags & CISTPL_CFTABLE_TPCE_FS_PWR) {
6287c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_pd_t *pd = &ce->pd;
6297c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_pwr_t *pwr;
6307c478bd9Sstevel@tonic-gate 			/*
6317c478bd9Sstevel@tonic-gate 			 * Collect any Vcc information.
6327c478bd9Sstevel@tonic-gate 			 */
6337c478bd9Sstevel@tonic-gate 			if (pd->flags & CISTPL_CFTABLE_TPCE_FS_PWR_VCC) {
6347c478bd9Sstevel@tonic-gate 				pwr = &pd->pd_vcc;
6357c478bd9Sstevel@tonic-gate 				cistpl_pd_parse(tp, pwr);
6367c478bd9Sstevel@tonic-gate 			}
6377c478bd9Sstevel@tonic-gate 			/*
6387c478bd9Sstevel@tonic-gate 			 * Collect any Vpp1 information.
6397c478bd9Sstevel@tonic-gate 			 */
6407c478bd9Sstevel@tonic-gate 			if (pd->flags & CISTPL_CFTABLE_TPCE_FS_PWR_VPP1) {
6417c478bd9Sstevel@tonic-gate 				pwr = &pd->pd_vpp1;
6427c478bd9Sstevel@tonic-gate 				cistpl_pd_parse(tp, pwr);
6437c478bd9Sstevel@tonic-gate 			}
6447c478bd9Sstevel@tonic-gate 			/*
6457c478bd9Sstevel@tonic-gate 			 * Collect any Vpp2 information.
6467c478bd9Sstevel@tonic-gate 			 */
6477c478bd9Sstevel@tonic-gate 			if (pd->flags & CISTPL_CFTABLE_TPCE_FS_PWR_VPP2) {
6487c478bd9Sstevel@tonic-gate 				pwr = &pd->pd_vpp2;
6497c478bd9Sstevel@tonic-gate 				cistpl_pd_parse(tp, pwr);
6507c478bd9Sstevel@tonic-gate 			}
6517c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_PWR) */
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 		/*
6547c478bd9Sstevel@tonic-gate 		 * Check to see if there's any timing information, and if
6557c478bd9Sstevel@tonic-gate 		 *	so, parse the tuple data and store it in the
6567c478bd9Sstevel@tonic-gate 		 *	caller's structure.  Set a flag in the global
6577c478bd9Sstevel@tonic-gate 		 *	flag field indicating that there is timing information.
6587c478bd9Sstevel@tonic-gate 		 */
6597c478bd9Sstevel@tonic-gate 		if (tpce_fs & CISTPL_CFTABLE_TPCE_FS_TDM) {
6607c478bd9Sstevel@tonic-gate 			convert_speed_t convert_speed;
6617c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_speed_t *sp = &ce->speed;
6627c478bd9Sstevel@tonic-gate 			ce->flags |= CISTPL_CFTABLE_TPCE_FS_TD;
6637c478bd9Sstevel@tonic-gate 			tpce_td = GET_BYTE(tp);
6647c478bd9Sstevel@tonic-gate 			/*
6657c478bd9Sstevel@tonic-gate 			 * Parse TPCE_TD to get the various timing
6667c478bd9Sstevel@tonic-gate 			 *	scale factors. Each scale factor has
6677c478bd9Sstevel@tonic-gate 			 *	a value that indicates that the particular
6687c478bd9Sstevel@tonic-gate 			 *	timing parameter doesn't exist.
6697c478bd9Sstevel@tonic-gate 			 */
6707c478bd9Sstevel@tonic-gate 			if ((sf = (tpce_td &
6717c478bd9Sstevel@tonic-gate 					CISTPL_CFTABLE_TPCE_FS_TD_WAITM)) !=
6727c478bd9Sstevel@tonic-gate 			    CISTPL_CFTABLE_TPCE_FS_TD_WAITM) {
6737c478bd9Sstevel@tonic-gate 				sp->nS_wait = cistpl_devspeed(tp,
6747c478bd9Sstevel@tonic-gate 						GET_TPCE_FS_TD_WAITS(sf),
6757c478bd9Sstevel@tonic-gate 						CISTPL_DEVSPEED_EXT);
6767c478bd9Sstevel@tonic-gate 				convert_speed.Attributes =
6777c478bd9Sstevel@tonic-gate 							CONVERT_NS_TO_DEVSPEED;
6787c478bd9Sstevel@tonic-gate 				convert_speed.nS = sp->nS_wait;
6797c478bd9Sstevel@tonic-gate 				(void) cis_convert_devspeed(&convert_speed);
6807c478bd9Sstevel@tonic-gate 				sp->wait = convert_speed.devspeed;
6817c478bd9Sstevel@tonic-gate 				sp->flags |= CISTPL_CFTABLE_TPCE_FS_TD_WAIT;
6827c478bd9Sstevel@tonic-gate 			}
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 			if ((sf = (tpce_td & CISTPL_CFTABLE_TPCE_FS_TD_RDYM)) !=
6857c478bd9Sstevel@tonic-gate 			    CISTPL_CFTABLE_TPCE_FS_TD_RDYM) {
6867c478bd9Sstevel@tonic-gate 				sp->nS_rdybsy = cistpl_devspeed(tp,
6877c478bd9Sstevel@tonic-gate 						GET_TPCE_FS_TD_RDYS(sf),
6887c478bd9Sstevel@tonic-gate 						CISTPL_DEVSPEED_EXT);
6897c478bd9Sstevel@tonic-gate 				convert_speed.Attributes =
6907c478bd9Sstevel@tonic-gate 							CONVERT_NS_TO_DEVSPEED;
6917c478bd9Sstevel@tonic-gate 				convert_speed.nS = sp->nS_rdybsy;
6927c478bd9Sstevel@tonic-gate 				(void) cis_convert_devspeed(&convert_speed);
6937c478bd9Sstevel@tonic-gate 				sp->rdybsy = convert_speed.devspeed;
6947c478bd9Sstevel@tonic-gate 				sp->flags |= CISTPL_CFTABLE_TPCE_FS_TD_RDY;
6957c478bd9Sstevel@tonic-gate 			}
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate 			if ((sf = (tpce_td &
6987c478bd9Sstevel@tonic-gate 					CISTPL_CFTABLE_TPCE_FS_TD_RSVDM)) !=
6997c478bd9Sstevel@tonic-gate 			    CISTPL_CFTABLE_TPCE_FS_TD_RSVDM) {
7007c478bd9Sstevel@tonic-gate 				sp->nS_rsvd = cistpl_devspeed(tp,
7017c478bd9Sstevel@tonic-gate 						GET_TPCE_FS_TD_RSVDS(sf),
7027c478bd9Sstevel@tonic-gate 						CISTPL_DEVSPEED_EXT);
7037c478bd9Sstevel@tonic-gate 				convert_speed.Attributes =
7047c478bd9Sstevel@tonic-gate 							CONVERT_NS_TO_DEVSPEED;
7057c478bd9Sstevel@tonic-gate 				convert_speed.nS = sp->nS_rsvd;
7067c478bd9Sstevel@tonic-gate 				(void) cis_convert_devspeed(&convert_speed);
7077c478bd9Sstevel@tonic-gate 				sp->rsvd = convert_speed.devspeed;
7087c478bd9Sstevel@tonic-gate 				sp->flags |= CISTPL_CFTABLE_TPCE_FS_TD_RSVD;
7097c478bd9Sstevel@tonic-gate 			}
7107c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_TDM) */
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 		/*
7147c478bd9Sstevel@tonic-gate 		 * Parse any I/O address information.  If there is I/O
7157c478bd9Sstevel@tonic-gate 		 *	inforamtion, set a flag in the global flag field
7167c478bd9Sstevel@tonic-gate 		 *	to let the caller know.
7177c478bd9Sstevel@tonic-gate 		 */
7187c478bd9Sstevel@tonic-gate 		if (tpce_fs & CISTPL_CFTABLE_TPCE_FS_IOM) {
7197c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_io_t *io = &ce->io;
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 			ce->flags |= CISTPL_CFTABLE_TPCE_FS_IO;
7227c478bd9Sstevel@tonic-gate 			tpce_io = GET_BYTE(tp);
7237c478bd9Sstevel@tonic-gate 			/*
7247c478bd9Sstevel@tonic-gate 			 * Pass any I/O flags that are in the tuple directly
7257c478bd9Sstevel@tonic-gate 			 *	to the caller.
7267c478bd9Sstevel@tonic-gate 			 */
7277c478bd9Sstevel@tonic-gate 			io->flags = tpce_io;
7287c478bd9Sstevel@tonic-gate 			io->addr_lines = tpce_io &
7297c478bd9Sstevel@tonic-gate 						CISTPL_CFTABLE_TPCE_FS_IO_ALM;
7307c478bd9Sstevel@tonic-gate 			/*
7317c478bd9Sstevel@tonic-gate 			 * If there are any ranges, extract the number of
7327c478bd9Sstevel@tonic-gate 			 *	ranges and the range descriptions.
7337c478bd9Sstevel@tonic-gate 			 */
7347c478bd9Sstevel@tonic-gate 			if (tpce_io & CISTPL_CFTABLE_TPCE_FS_IO_RANGEM) {
7357c478bd9Sstevel@tonic-gate 				cistpl_cftable_entry_io_range_t *ior;
7367c478bd9Sstevel@tonic-gate 				ior_desc = GET_BYTE(tp);
7377c478bd9Sstevel@tonic-gate 				/*
7387c478bd9Sstevel@tonic-gate 				 * Number of I/O ranges is the value specified
7397c478bd9Sstevel@tonic-gate 				 *	in the tuple plus one, so there's
7407c478bd9Sstevel@tonic-gate 				 *	always at least one I/O range if the
7417c478bd9Sstevel@tonic-gate 				 *	CISTPL_CFTABLE_TPCE_FS_IO_RANGEM bit
7427c478bd9Sstevel@tonic-gate 				 *	in the I/O flags register is set.
7437c478bd9Sstevel@tonic-gate 				 */
7447c478bd9Sstevel@tonic-gate 				nr = (ior_desc & 0x0f) + 1;
7457c478bd9Sstevel@tonic-gate 				io->ranges = nr;
7467c478bd9Sstevel@tonic-gate 				/*
7477c478bd9Sstevel@tonic-gate 				 * Cycle through each I/O range.
7487c478bd9Sstevel@tonic-gate 				 */
7497c478bd9Sstevel@tonic-gate 				for (i = 0; i < (int)nr; i++) {
7507c478bd9Sstevel@tonic-gate 					ior = &io->range[i];
7517c478bd9Sstevel@tonic-gate 					ior->addr = 0;
7527c478bd9Sstevel@tonic-gate 					ior->length = 0;
7537c478bd9Sstevel@tonic-gate 					/*
7547c478bd9Sstevel@tonic-gate 					 * Gather the address information.
7557c478bd9Sstevel@tonic-gate 					 *	It's OK if there's no address
7567c478bd9Sstevel@tonic-gate 					 *	information in which case this
7577c478bd9Sstevel@tonic-gate 					 *	loop will never execute.
7587c478bd9Sstevel@tonic-gate 					 */
7597c478bd9Sstevel@tonic-gate 					for (j = 0; j <
7607c478bd9Sstevel@tonic-gate 						cistpl_cftable_io_size_table[
7617c478bd9Sstevel@tonic-gate 							(ior_desc>>4)&3];
7627c478bd9Sstevel@tonic-gate 									j++)
7637c478bd9Sstevel@tonic-gate 						ior->addr |= (GET_BYTE(tp) <<
7647c478bd9Sstevel@tonic-gate 						cistpl_cftable_shift_table[j]);
7657c478bd9Sstevel@tonic-gate 					/*
7667c478bd9Sstevel@tonic-gate 					 * Gather the length information.
7677c478bd9Sstevel@tonic-gate 					 *	It's OK if there's no length
7687c478bd9Sstevel@tonic-gate 					 *	information in which case this
7697c478bd9Sstevel@tonic-gate 					 *	loop will never execute.
7707c478bd9Sstevel@tonic-gate 					 */
7717c478bd9Sstevel@tonic-gate 					for (j = 0; j <
7727c478bd9Sstevel@tonic-gate 						cistpl_cftable_io_size_table[
7737c478bd9Sstevel@tonic-gate 							(ior_desc>>6)&3];
7747c478bd9Sstevel@tonic-gate 									j++)
7757c478bd9Sstevel@tonic-gate 						ior->length |= (GET_BYTE(tp) <<
7767c478bd9Sstevel@tonic-gate 						cistpl_cftable_shift_table[j]);
7777c478bd9Sstevel@tonic-gate 				} /* for (nr) */
7787c478bd9Sstevel@tonic-gate 			} /* if (CISTPL_CFTABLE_TPCE_FS_IO_RANGEM) */
7797c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_IOM) */
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 		/*
7827c478bd9Sstevel@tonic-gate 		 * Parse any IRQ information.  If there is IRQ inforamtion,
7837c478bd9Sstevel@tonic-gate 		 *	set a flag in the global flag field to let the
7847c478bd9Sstevel@tonic-gate 		 *	caller know.
7857c478bd9Sstevel@tonic-gate 		 */
7867c478bd9Sstevel@tonic-gate 		if (tpce_fs & CISTPL_CFTABLE_TPCE_FS_IRQM) {
7877c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_irq_t *irq = &ce->irq;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 			ce->flags |= CISTPL_CFTABLE_TPCE_FS_IRQ;
7907c478bd9Sstevel@tonic-gate 			tpce_ir = GET_BYTE(tp);
7917c478bd9Sstevel@tonic-gate 			/*
7927c478bd9Sstevel@tonic-gate 			 * Pass any IRQ flags that are in the tuple directly
7937c478bd9Sstevel@tonic-gate 			 *	to the caller.
7947c478bd9Sstevel@tonic-gate 			 */
7957c478bd9Sstevel@tonic-gate 			irq->flags = tpce_ir;
7967c478bd9Sstevel@tonic-gate 			/*
7977c478bd9Sstevel@tonic-gate 			 * Check for and parse the extended IRQ bitmask
7987c478bd9Sstevel@tonic-gate 			 *	if it exists.
7997c478bd9Sstevel@tonic-gate 			 */
8007c478bd9Sstevel@tonic-gate 			if (tpce_ir & CISTPL_CFTABLE_TPCE_FS_IRQ_MASKM) {
8017c478bd9Sstevel@tonic-gate 				irq->irqs = GET_BYTE(tp) & 0x0ff;
8027c478bd9Sstevel@tonic-gate 				irq->irqs |= (GET_BYTE(tp) << 8)&0x0ff00;
8037c478bd9Sstevel@tonic-gate 			} else {
8047c478bd9Sstevel@tonic-gate 				irq->irqs = (1<< (tpce_ir&0x0f));
8057c478bd9Sstevel@tonic-gate 			}
8067c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_IRQM) */
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 		/*
8097c478bd9Sstevel@tonic-gate 		 * Parse any memory information.
8107c478bd9Sstevel@tonic-gate 		 *
8117c478bd9Sstevel@tonic-gate 		 * XXX - should be a cleaner way to parse this information.
8127c478bd9Sstevel@tonic-gate 		 */
8137c478bd9Sstevel@tonic-gate 		if (ce->flags & CISTPL_CFTABLE_TPCE_FS_MEM) {
8147c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_mem_t *mem = &ce->mem;
8157c478bd9Sstevel@tonic-gate 			cistpl_cftable_entry_mem_window_t *win;
8167c478bd9Sstevel@tonic-gate 			/*
8177c478bd9Sstevel@tonic-gate 			 * Switch on the type of memory description
8187c478bd9Sstevel@tonic-gate 			 *	information that is available.
8197c478bd9Sstevel@tonic-gate 			 */
8207c478bd9Sstevel@tonic-gate 			switch (tpce_fs & CISTPL_CFTABLE_TPCE_FS_MEMM) {
8217c478bd9Sstevel@tonic-gate 				/*
8227c478bd9Sstevel@tonic-gate 				 * variable length memory space description
8237c478bd9Sstevel@tonic-gate 				 */
8247c478bd9Sstevel@tonic-gate 			case CISTPL_CFTABLE_TPCE_FS_MEM3M:
8257c478bd9Sstevel@tonic-gate 				mem->flags |= CISTPL_CFTABLE_TPCE_FS_MEM3;
8267c478bd9Sstevel@tonic-gate 				/* memory space descriptor */
8277c478bd9Sstevel@tonic-gate 				tpce_msd = GET_BYTE(tp);
8287c478bd9Sstevel@tonic-gate 				mem->windows = ((tpce_msd &
8297c478bd9Sstevel@tonic-gate 					(CISTPL_CFTABLE_ENTRY_MAX_MEM_WINDOWS -
8307c478bd9Sstevel@tonic-gate 								1)) + 1);
8317c478bd9Sstevel@tonic-gate 				/*
8327c478bd9Sstevel@tonic-gate 				 * If there's host address information, let
8337c478bd9Sstevel@tonic-gate 				 *	the caller know.
8347c478bd9Sstevel@tonic-gate 				 */
8357c478bd9Sstevel@tonic-gate 				if (tpce_msd & CISTPL_CFTABLE_TPCE_FS_MEM_HOSTM)
8367c478bd9Sstevel@tonic-gate 					mem->flags |=
8377c478bd9Sstevel@tonic-gate 						CISTPL_CFTABLE_TPCE_FS_MEM_HOST;
8387c478bd9Sstevel@tonic-gate 				/*
8397c478bd9Sstevel@tonic-gate 				 * Cycle through each window space description
8407c478bd9Sstevel@tonic-gate 				 *	and collect all the interesting bits.
8417c478bd9Sstevel@tonic-gate 				 */
8427c478bd9Sstevel@tonic-gate 				for (i = 0; i < mem->windows; i++) {
8437c478bd9Sstevel@tonic-gate 					win = &mem->window[i];
8447c478bd9Sstevel@tonic-gate 					win->length = 0;
8457c478bd9Sstevel@tonic-gate 					win->card_addr = 0;
8467c478bd9Sstevel@tonic-gate 					win->host_addr = 0;
8477c478bd9Sstevel@tonic-gate 					/*
8487c478bd9Sstevel@tonic-gate 					 * Gather the length information.
8497c478bd9Sstevel@tonic-gate 					 *	It's OK if there's no length
8507c478bd9Sstevel@tonic-gate 					 *	information in which case this
8517c478bd9Sstevel@tonic-gate 					 *	loop will never execute.
8527c478bd9Sstevel@tonic-gate 					 */
8537c478bd9Sstevel@tonic-gate 					for (j = 0; j <
8547c478bd9Sstevel@tonic-gate 						(int)((tpce_msd>>3)&3); j++)
8557c478bd9Sstevel@tonic-gate 						win->length |= (GET_BYTE(tp) <<
8567c478bd9Sstevel@tonic-gate 						cistpl_cftable_shift_table[j]);
8577c478bd9Sstevel@tonic-gate 					/*
8587c478bd9Sstevel@tonic-gate 					 * Gather the card address information.
8597c478bd9Sstevel@tonic-gate 					 *	It's OK if there's no card
8607c478bd9Sstevel@tonic-gate 					 *	address information in which
8617c478bd9Sstevel@tonic-gate 					 *	case this loop will never
8627c478bd9Sstevel@tonic-gate 					 *	execute.
8637c478bd9Sstevel@tonic-gate 					 */
8647c478bd9Sstevel@tonic-gate 					for (j = 0; j <
8657c478bd9Sstevel@tonic-gate 						(int)((tpce_msd>>5)&3); j++)
8667c478bd9Sstevel@tonic-gate 						win->card_addr |=
8677c478bd9Sstevel@tonic-gate 							(GET_BYTE(tp) <<
8687c478bd9Sstevel@tonic-gate 						cistpl_cftable_shift_table[j]);
8697c478bd9Sstevel@tonic-gate 					/*
8707c478bd9Sstevel@tonic-gate 					 * If there's a host address
8717c478bd9Sstevel@tonic-gate 					 *	description, grab that
8727c478bd9Sstevel@tonic-gate 					 *	as well.
8737c478bd9Sstevel@tonic-gate 					 */
8747c478bd9Sstevel@tonic-gate 					if (mem->flags &
8757c478bd9Sstevel@tonic-gate 					    CISTPL_CFTABLE_TPCE_FS_MEM_HOST) {
8767c478bd9Sstevel@tonic-gate 						/*
8777c478bd9Sstevel@tonic-gate 						 * Gather the host address
8787c478bd9Sstevel@tonic-gate 						 *	information.  It's OK
8797c478bd9Sstevel@tonic-gate 						 *	if there's no host
8807c478bd9Sstevel@tonic-gate 						 *	address information in
8817c478bd9Sstevel@tonic-gate 						 *	which case this loop
8827c478bd9Sstevel@tonic-gate 						 *	will never execute.
8837c478bd9Sstevel@tonic-gate 						 * Note that we use the card
8847c478bd9Sstevel@tonic-gate 						 *	address size to
8857c478bd9Sstevel@tonic-gate 						 *	determine how many
8867c478bd9Sstevel@tonic-gate 						 *	bytes of host address
8877c478bd9Sstevel@tonic-gate 						 *	are present.
8887c478bd9Sstevel@tonic-gate 						 */
8897c478bd9Sstevel@tonic-gate 						for (j = 0; j <
8907c478bd9Sstevel@tonic-gate 							(int)((tpce_msd>>5)&3);
8917c478bd9Sstevel@tonic-gate 									j++)
8927c478bd9Sstevel@tonic-gate 							win->host_addr |=
8937c478bd9Sstevel@tonic-gate 							(GET_BYTE(tp) <<
8947c478bd9Sstevel@tonic-gate 						cistpl_cftable_shift_table[j]);
8957c478bd9Sstevel@tonic-gate 					} else {
8967c478bd9Sstevel@tonic-gate 						/*
8977c478bd9Sstevel@tonic-gate 						 * No host address information,
8987c478bd9Sstevel@tonic-gate 						 *	so the host address is
8997c478bd9Sstevel@tonic-gate 						 *	equal to the card
9007c478bd9Sstevel@tonic-gate 						 *	address.
9017c478bd9Sstevel@tonic-gate 						 */
9027c478bd9Sstevel@tonic-gate 						win->host_addr = win->card_addr;
9037c478bd9Sstevel@tonic-gate 					}
9047c478bd9Sstevel@tonic-gate 				} /* for (i<mem->windows) */
9057c478bd9Sstevel@tonic-gate 				break;
9067c478bd9Sstevel@tonic-gate 				/*
9077c478bd9Sstevel@tonic-gate 				 * single length and card base address specified
9087c478bd9Sstevel@tonic-gate 				 */
9097c478bd9Sstevel@tonic-gate 			case CISTPL_CFTABLE_TPCE_FS_MEM2M:
9107c478bd9Sstevel@tonic-gate 				mem->flags |= CISTPL_CFTABLE_TPCE_FS_MEM2;
9117c478bd9Sstevel@tonic-gate 				win = &mem->window[0];
9127c478bd9Sstevel@tonic-gate 				mem->windows = 1;
9137c478bd9Sstevel@tonic-gate 				/*
9147c478bd9Sstevel@tonic-gate 				 * Construct the size of the window.
9157c478bd9Sstevel@tonic-gate 				 */
9167c478bd9Sstevel@tonic-gate 				win->length = GET_BYTE(tp);
9177c478bd9Sstevel@tonic-gate 				win->length |= (GET_BYTE(tp)<<8);
9187c478bd9Sstevel@tonic-gate 				win->length *=
9197c478bd9Sstevel@tonic-gate 					CISTPL_CFTABLE_TPCE_FS_MEM_PGSIZE;
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 				/*
9227c478bd9Sstevel@tonic-gate 				 * Construct the card base address.
9237c478bd9Sstevel@tonic-gate 				 */
9247c478bd9Sstevel@tonic-gate 				win->card_addr = GET_BYTE(tp);
9257c478bd9Sstevel@tonic-gate 				win->card_addr |= (GET_BYTE(tp)<<8);
9267c478bd9Sstevel@tonic-gate 				win->card_addr *=
9277c478bd9Sstevel@tonic-gate 					CISTPL_CFTABLE_TPCE_FS_MEM_PGSIZE;
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate 				/*
9307c478bd9Sstevel@tonic-gate 				 * In this mode, both the host base address
9317c478bd9Sstevel@tonic-gate 				 *	and the card base address are equal.
9327c478bd9Sstevel@tonic-gate 				 */
9337c478bd9Sstevel@tonic-gate 				win->host_addr = win->card_addr;
9347c478bd9Sstevel@tonic-gate 				break;
9357c478bd9Sstevel@tonic-gate 				/*
9367c478bd9Sstevel@tonic-gate 				 * single length specified
9377c478bd9Sstevel@tonic-gate 				 */
9387c478bd9Sstevel@tonic-gate 			case CISTPL_CFTABLE_TPCE_FS_MEM1M:
9397c478bd9Sstevel@tonic-gate 				mem->flags |= CISTPL_CFTABLE_TPCE_FS_MEM1;
9407c478bd9Sstevel@tonic-gate 				win = &mem->window[0];
9417c478bd9Sstevel@tonic-gate 				mem->windows = 1;
9427c478bd9Sstevel@tonic-gate 				win->card_addr = 0;
9437c478bd9Sstevel@tonic-gate 				win->host_addr = 0;
9447c478bd9Sstevel@tonic-gate 				/*
9457c478bd9Sstevel@tonic-gate 				 * Construct the size of the window.
9467c478bd9Sstevel@tonic-gate 				 */
9477c478bd9Sstevel@tonic-gate 				win->length = GET_BYTE(tp);
9487c478bd9Sstevel@tonic-gate 				win->length |= (GET_BYTE(tp)<<8);
9497c478bd9Sstevel@tonic-gate 				win->length *=
9507c478bd9Sstevel@tonic-gate 					CISTPL_CFTABLE_TPCE_FS_MEM_PGSIZE;
9517c478bd9Sstevel@tonic-gate 				break;
9527c478bd9Sstevel@tonic-gate 			} /* switch (CISTPL_CFTABLE_TPCE_FS_MEMM) */
9537c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_MEM) */
9547c478bd9Sstevel@tonic-gate 
9557c478bd9Sstevel@tonic-gate 		/*
9567c478bd9Sstevel@tonic-gate 		 * Check for and parse any miscellaneous information.
9577c478bd9Sstevel@tonic-gate 		 *
9587c478bd9Sstevel@tonic-gate 		 * We only understand how to parse the first
9597c478bd9Sstevel@tonic-gate 		 *	CISTPL_CFTABLE_TPCE_FS_MISC_MAX extension
9607c478bd9Sstevel@tonic-gate 		 *	bytes specified in the PC Card 95 standard;
9617c478bd9Sstevel@tonic-gate 		 *	we throw away any other extension bytes that
9627c478bd9Sstevel@tonic-gate 		 *	are past these bytes.
9637c478bd9Sstevel@tonic-gate 		 * XXX Note that the assumption here is that the
9647c478bd9Sstevel@tonic-gate 		 *	size of cistpl_cftable_entry_misc_t->flags
9657c478bd9Sstevel@tonic-gate 		 *	is at least CISTPL_CFTABLE_TPCE_FS_MISC_MAX
9667c478bd9Sstevel@tonic-gate 		 *	bytes in length.
9677c478bd9Sstevel@tonic-gate 		 */
9687c478bd9Sstevel@tonic-gate 		if (tpce_fs & CISTPL_CFTABLE_TPCE_FS_MISCM) {
9697c478bd9Sstevel@tonic-gate 		    cistpl_cftable_entry_misc_t *misc = &ce->misc;
9707c478bd9Sstevel@tonic-gate 		    int mb = CISTPL_CFTABLE_TPCE_FS_MISC_MAX;
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 		    ce->flags |= CISTPL_CFTABLE_TPCE_FS_MISC;
9737c478bd9Sstevel@tonic-gate 		    misc->flags = 0;
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 		    do {
9767c478bd9Sstevel@tonic-gate 			if (mb) {
9777c478bd9Sstevel@tonic-gate 			    misc->flags = (misc->flags << 8) | LOOK_BYTE(tp);
9787c478bd9Sstevel@tonic-gate 			    mb--;
9797c478bd9Sstevel@tonic-gate 			}
9807c478bd9Sstevel@tonic-gate 		    } while ((GET_BYTE(tp) & CISTPL_EXT_BIT) &&
9817c478bd9Sstevel@tonic-gate 				(!(tp->flags & CISTPLF_MEM_ERR)));
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 			/*
9847c478bd9Sstevel@tonic-gate 			 * Check to see if we tried to read past the
9857c478bd9Sstevel@tonic-gate 			 *	end of the tuple data; if we have,
9867c478bd9Sstevel@tonic-gate 			 *	there's no point in trying to parse
9877c478bd9Sstevel@tonic-gate 			 *	any more of the tuple.
9887c478bd9Sstevel@tonic-gate 			 */
9897c478bd9Sstevel@tonic-gate 		    if (tp->flags & CISTPLF_MEM_ERR)
9907c478bd9Sstevel@tonic-gate 			return (HANDTPL_ERROR);
9917c478bd9Sstevel@tonic-gate 		} /* if (CISTPL_CFTABLE_TPCE_FS_MISCM) */
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate 		/*
9947c478bd9Sstevel@tonic-gate 		 * Check for and parse any additional subtuple
9957c478bd9Sstevel@tonic-gate 		 *	information. We know that there is
9967c478bd9Sstevel@tonic-gate 		 *	additional information if we haven't
9977c478bd9Sstevel@tonic-gate 		 *	reached the end of the tuple data area
9987c478bd9Sstevel@tonic-gate 		 *	and if the additional information is
9997c478bd9Sstevel@tonic-gate 		 *	in standard tuple format.
10007c478bd9Sstevel@tonic-gate 		 * If we don't recognize the additional info,
10017c478bd9Sstevel@tonic-gate 		 *	then just silently ignore it, don't
10027c478bd9Sstevel@tonic-gate 		 *	flag it as an error.
10037c478bd9Sstevel@tonic-gate 		 */
10047c478bd9Sstevel@tonic-gate #ifdef	PARSE_STCE_TUPLES
10057c478bd9Sstevel@tonic-gate 		if (GET_LEN(tp) > 0) {
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate 		ce->flags |= CISTPL_CFTABLE_TPCE_FS_STCE_EV
10087c478bd9Sstevel@tonic-gate 		ce->flags |= CISTPL_CFTABLE_TPCE_FS_STCE_PD
10097c478bd9Sstevel@tonic-gate #endif
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 	} /* if (HANDTPL_PARSE_LTUPLE) */
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate 	return (CISTPLF_NOERROR);
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate /*
10177c478bd9Sstevel@tonic-gate  * cistpl_pd_parse - read and parse a power description structure
10187c478bd9Sstevel@tonic-gate  *
10197c478bd9Sstevel@tonic-gate  *	cisdata_t **ddp - pointer to pointer tuple data area
10207c478bd9Sstevel@tonic-gate  *	cistpl_cftable_entry_pwr_t *pd - pointer to local power description
10217c478bd9Sstevel@tonic-gate  *					structure
10227c478bd9Sstevel@tonic-gate  */
10237c478bd9Sstevel@tonic-gate static void
10247c478bd9Sstevel@tonic-gate cistpl_pd_parse(cistpl_t *tp, cistpl_cftable_entry_pwr_t *pd)
10257c478bd9Sstevel@tonic-gate {
10267c478bd9Sstevel@tonic-gate 	cisdata_t pdesc;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	pdesc = GET_BYTE(tp);	/* power description selector */
10297c478bd9Sstevel@tonic-gate 
10307c478bd9Sstevel@tonic-gate 	/* nominal supply voltage */
10317c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_NOMV) {
10327c478bd9Sstevel@tonic-gate 		pd->nomV = cistpl_expd_parse(tp, &pd->nomV_flags) / 100;
10337c478bd9Sstevel@tonic-gate 		pd->nomV_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10347c478bd9Sstevel@tonic-gate 	}
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 	/* minimum supply voltage */
10377c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_MINV) {
10387c478bd9Sstevel@tonic-gate 		pd->minV = cistpl_expd_parse(tp, &pd->minV_flags) / 100;
10397c478bd9Sstevel@tonic-gate 		pd->minV_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10407c478bd9Sstevel@tonic-gate 	}
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 	/* maximum supply voltage */
10437c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_MAXV) {
10447c478bd9Sstevel@tonic-gate 		pd->maxV = cistpl_expd_parse(tp, &pd->maxV_flags) / 100;
10457c478bd9Sstevel@tonic-gate 		pd->maxV_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10467c478bd9Sstevel@tonic-gate 	}
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	/* continuous supply current */
10497c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_STATICI) {
10507c478bd9Sstevel@tonic-gate 		pd->staticI_flags |= CISTPL_CFTABLE_PD_MUL10;
10517c478bd9Sstevel@tonic-gate 		pd->staticI = cistpl_expd_parse(tp, &pd->staticI_flags);
10527c478bd9Sstevel@tonic-gate 		pd->staticI_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10537c478bd9Sstevel@tonic-gate 	}
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	/* maximum current required averaged over 1 second */
10567c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_AVGI) {
10577c478bd9Sstevel@tonic-gate 		pd->avgI_flags |= CISTPL_CFTABLE_PD_MUL10;
10587c478bd9Sstevel@tonic-gate 		pd->avgI = cistpl_expd_parse(tp, &pd->avgI_flags);
10597c478bd9Sstevel@tonic-gate 		pd->avgI_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10607c478bd9Sstevel@tonic-gate 	}
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate 	/* maximum current required averaged over 10mS */
10637c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_PEAKI) {
10647c478bd9Sstevel@tonic-gate 		pd->peakI_flags |= CISTPL_CFTABLE_PD_MUL10;
10657c478bd9Sstevel@tonic-gate 		pd->peakI = cistpl_expd_parse(tp, &pd->peakI_flags);
10667c478bd9Sstevel@tonic-gate 		pd->peakI_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10677c478bd9Sstevel@tonic-gate 	}
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate 	/* power down supply curent required */
10707c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_CFTABLE_PD_PDOWNI) {
10717c478bd9Sstevel@tonic-gate 		pd->pdownI_flags |= CISTPL_CFTABLE_PD_MUL10;
10727c478bd9Sstevel@tonic-gate 		pd->pdownI = cistpl_expd_parse(tp, &pd->pdownI_flags);
10737c478bd9Sstevel@tonic-gate 		pd->pdownI_flags |= (pdesc | CISTPL_CFTABLE_PD_EXISTS);
10747c478bd9Sstevel@tonic-gate 	}
10757c478bd9Sstevel@tonic-gate }
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate /*
10787c478bd9Sstevel@tonic-gate  * cistpl_expd_parse - read and parse an extended power description structure
10797c478bd9Sstevel@tonic-gate  *
10807c478bd9Sstevel@tonic-gate  *	cistpl_t *tp - pointer to pointer tuple data area
10817c478bd9Sstevel@tonic-gate  *	int *flags - flags that get for this parameter:
10827c478bd9Sstevel@tonic-gate  *			CISTPL_CFTABLE_PD_NC_SLEEP - no connection on
10837c478bd9Sstevel@tonic-gate  *							sleep/power down
10847c478bd9Sstevel@tonic-gate  *			CISTPL_CFTABLE_PD_ZERO - zero value required
10857c478bd9Sstevel@tonic-gate  *			CISTPL_CFTABLE_PD_NC - no connection ever
10867c478bd9Sstevel@tonic-gate  *
10877c478bd9Sstevel@tonic-gate  * The power consumption is returned in the following units:
10887c478bd9Sstevel@tonic-gate  *
10897c478bd9Sstevel@tonic-gate  *				voltage - milliVOLTS
10907c478bd9Sstevel@tonic-gate  *				current - microAMPS
10917c478bd9Sstevel@tonic-gate  */
10927c478bd9Sstevel@tonic-gate extern cistpl_pd_struct_t cistpl_pd_struct;
10937c478bd9Sstevel@tonic-gate 
10947c478bd9Sstevel@tonic-gate uint32_t
10957c478bd9Sstevel@tonic-gate cistpl_expd_parse(cistpl_t *tp, uint32_t *flags)
10967c478bd9Sstevel@tonic-gate {
10977c478bd9Sstevel@tonic-gate 	cisdata_t pdesc;
10987c478bd9Sstevel@tonic-gate 	uint32_t exponent, mantisa, val, digits = 0;
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate 	/*
11017c478bd9Sstevel@tonic-gate 	 * Get the power description parameter byte and break it up
11027c478bd9Sstevel@tonic-gate 	 *	into mantissa and exponent.
11037c478bd9Sstevel@tonic-gate 	 */
11047c478bd9Sstevel@tonic-gate 	pdesc = GET_BYTE(tp);
11057c478bd9Sstevel@tonic-gate 	exponent = pdesc&7;
11067c478bd9Sstevel@tonic-gate 	mantisa = (pdesc>>3)&0x0f;
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate 	if (pdesc & CISTPL_EXT_BIT) {
11097c478bd9Sstevel@tonic-gate 		do {
11107c478bd9Sstevel@tonic-gate 			if (LOOK_BYTE(tp) <= 0x63)
11117c478bd9Sstevel@tonic-gate 				digits = LOOK_BYTE(tp);
11127c478bd9Sstevel@tonic-gate 			if (LOOK_BYTE(tp) == CISTPL_CFTABLE_PD_NC_SLEEPM)
11137c478bd9Sstevel@tonic-gate 				*flags |= CISTPL_CFTABLE_PD_NC_SLEEP;
11147c478bd9Sstevel@tonic-gate 			if (LOOK_BYTE(tp) == CISTPL_CFTABLE_PD_ZEROM)
11157c478bd9Sstevel@tonic-gate 				*flags |= CISTPL_CFTABLE_PD_ZERO;
11167c478bd9Sstevel@tonic-gate 			if (LOOK_BYTE(tp) == CISTPL_CFTABLE_PD_NCM)
11177c478bd9Sstevel@tonic-gate 				*flags |= CISTPL_CFTABLE_PD_NC;
11187c478bd9Sstevel@tonic-gate 		} while (GET_BYTE(tp) & CISTPL_EXT_BIT);
11197c478bd9Sstevel@tonic-gate 	}
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 	val = CISTPL_PD_MAN(mantisa) * CISTPL_PD_EXP(exponent);
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 	/*
11247c478bd9Sstevel@tonic-gate 	 * If we have to multiply the power value by ten, then just
11257c478bd9Sstevel@tonic-gate 	 *	don't bother dividing.
11267c478bd9Sstevel@tonic-gate 	 */
11277c478bd9Sstevel@tonic-gate 	if (! (*flags & CISTPL_CFTABLE_PD_MUL10))
11287c478bd9Sstevel@tonic-gate 		val = val/10;	/* do this since our mantissa table is X 10 */
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 	/*
11317c478bd9Sstevel@tonic-gate 	 * If we need to add some digits to the right of the decimal, do
11327c478bd9Sstevel@tonic-gate 	 *	that here.
11337c478bd9Sstevel@tonic-gate 	 */
11347c478bd9Sstevel@tonic-gate 	if (exponent)
11357c478bd9Sstevel@tonic-gate 		val = val + (digits * CISTPL_PD_EXP(exponent-1));
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate 	val /= 1000;
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 	return (val);
11407c478bd9Sstevel@tonic-gate }
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate /*
11437c478bd9Sstevel@tonic-gate  * cistpl_devspeed - returns device speed in nS
11447c478bd9Sstevel@tonic-gate  *
11457c478bd9Sstevel@tonic-gate  *	cistpl_t *tp - tuple pointer.
11467c478bd9Sstevel@tonic-gate  *	cisdata_t spindex - device speed table index
11477c478bd9Sstevel@tonic-gate  *	int flags - operation flags
11487c478bd9Sstevel@tonic-gate  *		CISTPL_DEVSPEED_TABLE:
11497c478bd9Sstevel@tonic-gate  *		    Use the spindex argument as an index into a simple
11507c478bd9Sstevel@tonic-gate  *			device speed table. ref: PCMCIA Release 2.01
11517c478bd9Sstevel@tonic-gate  *			Card Metaformat pg. 5-14 table 5-12.
11527c478bd9Sstevel@tonic-gate  *		    When this flag is set, the spindex argument is ignored.
11537c478bd9Sstevel@tonic-gate  *		CISTPL_DEVSPEED_EXT:
11547c478bd9Sstevel@tonic-gate  *		    Use the tp argument to access the
11557c478bd9Sstevel@tonic-gate  *			tuple data area containing an extended speed
11567c478bd9Sstevel@tonic-gate  *			code table.  ref: PCMCIA Release 2.01 Card
11577c478bd9Sstevel@tonic-gate  *			Metaformat pg. 5-15 table 5-13.
11587c478bd9Sstevel@tonic-gate  *		    The tp->read argument must point to the first byte of
11597c478bd9Sstevel@tonic-gate  *			an extended speed code table.
11607c478bd9Sstevel@tonic-gate  *		    When this flag is set, the spindex argument is
11617c478bd9Sstevel@tonic-gate  *			used as a power-of-10 scale factor.  We only allow
11627c478bd9Sstevel@tonic-gate  *			a maximum scale factor of 10^16.
11637c478bd9Sstevel@tonic-gate  *
11647c478bd9Sstevel@tonic-gate  * The device speed is returned in nS for all combinations of flags and
11657c478bd9Sstevel@tonic-gate  *	speed table entries.
11667c478bd9Sstevel@tonic-gate  *
11677c478bd9Sstevel@tonic-gate  * Note if you pass the CISTPL_DEVSPEED_TABLE with a spindex index that
11687c478bd9Sstevel@tonic-gate  *	refers to an extended speed table, you will get back an undefined
11697c478bd9Sstevel@tonic-gate  *	speed value.
11707c478bd9Sstevel@tonic-gate  */
11717c478bd9Sstevel@tonic-gate extern cistpl_devspeed_struct_t cistpl_devspeed_struct;
11727c478bd9Sstevel@tonic-gate 
11737c478bd9Sstevel@tonic-gate uint32_t
11747c478bd9Sstevel@tonic-gate cistpl_devspeed(cistpl_t *tp, cisdata_t spindex, uint32_t flags)
11757c478bd9Sstevel@tonic-gate {
11767c478bd9Sstevel@tonic-gate 	int scale = 1, first;
11777c478bd9Sstevel@tonic-gate 	cisdata_t exspeed;
11787c478bd9Sstevel@tonic-gate 	int exponent, mantisa;
11797c478bd9Sstevel@tonic-gate 	uint32_t speed;
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	switch (flags) {
11827c478bd9Sstevel@tonic-gate 	case CISTPL_DEVSPEED_TABLE:
11837c478bd9Sstevel@tonic-gate 		speed = CISTPL_DEVSPEED_TBL(spindex);
11847c478bd9Sstevel@tonic-gate 		break;
11857c478bd9Sstevel@tonic-gate 	case CISTPL_DEVSPEED_EXT:
11867c478bd9Sstevel@tonic-gate 		do {
11877c478bd9Sstevel@tonic-gate 			exspeed = GET_BYTE(tp);
11887c478bd9Sstevel@tonic-gate 			first = 1;
11897c478bd9Sstevel@tonic-gate 			if (first) {
11907c478bd9Sstevel@tonic-gate 				/*
11917c478bd9Sstevel@tonic-gate 				 * XXX - ugh! we don't understand additional
11927c478bd9Sstevel@tonic-gate 				 *	exspeed bytes
11937c478bd9Sstevel@tonic-gate 				 */
11947c478bd9Sstevel@tonic-gate 				first = 0;
11957c478bd9Sstevel@tonic-gate 				exponent = (exspeed & 0x07);
11967c478bd9Sstevel@tonic-gate 				mantisa = (exspeed >> 3) & 0x0f;
11977c478bd9Sstevel@tonic-gate 				spindex &= 0x0f;	/* only allow 10^16 */
11987c478bd9Sstevel@tonic-gate 				while (spindex--)
11997c478bd9Sstevel@tonic-gate 					scale *= 10;
12007c478bd9Sstevel@tonic-gate 			} /* if (first) */
12017c478bd9Sstevel@tonic-gate 		} while (exspeed & CISTPL_EXT_BIT);
12027c478bd9Sstevel@tonic-gate 		speed = scale * CISTPL_DEVSPEED_MAN(mantisa) *
12037c478bd9Sstevel@tonic-gate 						CISTPL_DEVSPEED_EXP(exponent);
12047c478bd9Sstevel@tonic-gate 		speed = speed/10;	/* XXX - mantissa table is all X 10 */
12057c478bd9Sstevel@tonic-gate 		break;
12067c478bd9Sstevel@tonic-gate 	default:
12077c478bd9Sstevel@tonic-gate 		break;
12087c478bd9Sstevel@tonic-gate 	}
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 	return (speed);
12117c478bd9Sstevel@tonic-gate }
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate /*
1214