1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright (c) 1995-1999 by Sun Microsystems, Inc.
  24  * All rights reserved.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/systm.h>
  29 #include <sys/user.h>
  30 #include <sys/buf.h>
  31 #include <sys/file.h>
  32 #include <sys/uio.h>
  33 #include <sys/conf.h>
  34 #include <sys/stat.h>
  35 #include <sys/autoconf.h>
  36 #include <sys/vtoc.h>
  37 #include <sys/dkio.h>
  38 #include <sys/ddi.h>
  39 #include <sys/sunddi.h>
  40 #include <sys/ddi_impldefs.h>
  41 #include <sys/kstat.h>
  42 #include <sys/kmem.h>
  43 #include <sys/modctl.h>
  44 #include <sys/kobj.h>
  45 
  46 #include <sys/pctypes.h>
  47 #include <pcmcia/sys/cs_types.h>
  48 #include <pcmcia/sys/cis.h>
  49 #include <pcmcia/sys/cis_handlers.h>
  50 
  51 /*
  52  *
  53  * The following speed tables are used by cistpl_devspeed() to generate
  54  *      device speeds from tuple data.
  55  *
  56  * Define the device speed table.  For a description of this table's contents,
  57  *      see PCMCIA Release 2.01 Card Metaformat pg. 5-14 table 5-12.
  58  *
  59  * All times in this table are in nS.
  60  */
  61 uint32_t cistpl_devspeed_table[CISTPL_DEVSPEED_MAX_TBL] = {
  62     0,          /* 0x00 - DSPEED_NULL */
  63     250,        /* 0x01 - DSPEED_250NS */
  64     200,        /* 0x02 - DSPEED_200NS */
  65     150,        /* 0x03 - DSPEED_150NS */
  66     100,        /* 0x04 - DSPEED_100NS */
  67     0,          /* 0x05 - reserved */
  68     0,          /* 0x06 - reserved */
  69     0           /* 0x07 - use extended speed byte */
  70 };
  71 
  72 /*
  73  * Define the power-of-10 table.
  74  */
  75 uint32_t cistpl_exspeed_tenfac[] = {
  76     1,          /* 10^0 */
  77     10,         /* 10^1 */
  78     100,        /* 10^2 */
  79     1000,       /* 10^3 */
  80     10000,      /* 10^4 */
  81     100000,     /* 10^5 */
  82     1000000,    /* 10^6 */
  83     10000000    /* 10^7  */
  84 };
  85 
  86 /*
  87  * The extended device speed code mantissa table.
  88  *
  89  * This table is described in PCMCIA Release 2.01 Card Metaformat
  90  *      pg. 5-15 table 5-13.
  91  *
  92  * The description of this table uses non-integer values.  We multiply
  93  *      everything by 10 before it goes into the table, and the code
  94  *      will divide by 10 after it calculates the device speed.
  95  */
  96 uint32_t cistpl_devspeed_man[CISTPL_DEVSPEED_MAX_MAN] = {
  97     0,          /* no units */
  98     10,         /* no units */
  99     12,         /* no units */
 100     13,         /* no units */
 101     15,         /* no units */
 102     20,         /* no units */
 103     25,         /* no units */
 104     30,         /* no units */
 105     35,         /* no units */
 106     40,         /* no units */
 107     45,         /* no units */
 108     50,         /* no units */
 109     55,         /* no units */
 110     60,         /* no units */
 111     70,         /* no units */
 112     80,         /* no units */
 113 };
 114 
 115 /*
 116  * The extended device speed code exponent table.
 117  *
 118  * This table is described in PCMCIA Release 2.01 Card Metaformat
 119  *      pg. 5-15 table 5-13.
 120  *
 121  * The description of this table uses various timing units.  This
 122  *      table contains all times in nS.
 123  */
 124 uint32_t cistpl_devspeed_exp[CISTPL_DEVSPEED_MAX_EXP] = {
 125     1,          /* 1 nS */
 126     10,         /* 10 nS */
 127     100,        /* 100 nS */
 128     1000,       /* 1000 nS */
 129     10000,      /* 10000 nS */
 130     100000,     /* 100000 nS */
 131     1000000,    /* 1000000 nS */
 132     10000000    /* 10000000 nS */
 133 };
 134 
 135 /*
 136  * The power description mantissa table.
 137  *
 138  * This table is described in PCMCIA Release 2.01 Card Metaformat
 139  *      pg. 5-28 table 5-32.
 140  *
 141  * The description of this table uses non-integer values.  We multiply
 142  *      everything by 10 before it goes into the table, and the code
 143  *      will divide by 10 after it calculates the device power.
 144  */
 145 uint32_t cistpl_pd_man[] = {
 146     10,         /* no units */
 147     12,         /* no units */
 148     13,         /* no units */
 149     15,         /* no units */
 150     20,         /* no units */
 151     25,         /* no units */
 152     30,         /* no units */
 153     35,         /* no units */
 154     40,         /* no units */
 155     45,         /* no units */
 156     50,         /* no units */
 157     55,         /* no units */
 158     60,         /* no units */
 159     70,         /* no units */
 160     80,         /* no units */
 161     90,         /* no units */
 162 };
 163 
 164 /*
 165  * The power description exponent table.
 166  *
 167  * This table is described in PCMCIA Release 2.01 Card Metaformat
 168  *      pg. 5-28 table 5-32.
 169  *
 170  * The description of this table uses various voltage and current units.
 171  *      This table contains all currents in nanoAMPS and all voltages
 172  *      in microVOLTS.
 173  *
 174  * Note if you're doing a current table lookup, you need to multiply
 175  *      the lookup value by ten.
 176  */
 177 uint32_t cistpl_pd_exp[] = {
 178     10,         /* 10 microVOLTS, 100 nanoAMPS */
 179     100,        /* 100 microVOLTS, 1000 nanoAMPS */
 180     1000,       /* 1000 microVOLTS, 10000 nanoAMPS */
 181     10000,      /* 10000 microVOLTS, 100000 nanoAMPS */
 182     100000,     /* 100000 microVOLTS, 1000000 nanoAMPS */
 183     1000000,    /* 1000000 microVOLTS, 10000000 nanoAMPS */
 184     10000000,   /* 10000000 microVOLTS, 100000000 nanoAMPS */
 185     100000000   /* 100000000 microVOLTS, 1000000000 nanoAMPS */
 186 };
 187 
 188 /*
 189  * Fill out the structure pointers.
 190  */
 191 cistpl_devspeed_struct_t cistpl_devspeed_struct = {
 192         cistpl_devspeed_table,
 193         cistpl_exspeed_tenfac,
 194         cistpl_devspeed_man,
 195         cistpl_devspeed_exp,
 196 };
 197 
 198 cistpl_pd_struct_t cistpl_pd_struct = {
 199         cistpl_pd_man,
 200         cistpl_pd_exp,
 201 };
 202 
 203 /*
 204  * Some handy lookup tables that should probably eventually be
 205  *      done away with.
 206  *
 207  * These are used mostly by the CISTPL_CFTABLE_ENTRY tuple handler.
 208  */
 209 uint32_t cistpl_cftable_io_size_table[] = {
 210         0,
 211         1,
 212         2,
 213         4,
 214 };
 215 
 216 uint32_t cistpl_cftable_shift_table[] = {
 217         0,
 218         8,
 219         16,
 220         24,
 221 };
 222 
 223 /*
 224  * List of tuples in the global CIS to ignore if they show
 225  *      up in both the global and function-specific CIS lists.
 226  * This list MUST end with CISTPL_NULL.
 227  */
 228 cistpl_ignore_list_t cistpl_ignore_list[] = {
 229         { CISTPL_FUNCID },
 230         { CISTPL_FUNCE },
 231         { CISTPL_CONFIG },
 232         { CISTPL_CFTABLE_ENTRY },
 233         { CISTPL_NULL } /* list must end with CISTPL_NULL */
 234 };