root/dev/sdmmc/sdmmcvar.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


    1 /*      $OpenBSD: sdmmcvar.h,v 1.9 2007/05/31 10:09:01 uwe Exp $        */
    2 
    3 /*
    4  * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
    5  *
    6  * Permission to use, copy, modify, and distribute this software for any
    7  * purpose with or without fee is hereby granted, provided that the above
    8  * copyright notice and this permission notice appear in all copies.
    9  *
   10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   17  */
   18 
   19 #ifndef _SDMMCVAR_H_
   20 #define _SDMMCVAR_H_
   21 
   22 #include <sys/queue.h>
   23 
   24 #include <scsi/scsi_all.h>
   25 #include <scsi/scsiconf.h>
   26 
   27 #include <dev/sdmmc/sdmmcchip.h>
   28 #include <dev/sdmmc/sdmmcreg.h>
   29 
   30 struct sdmmc_csd {
   31         int     csdver;         /* CSD structure format */
   32         int     mmcver;         /* MMC version (for CID format) */
   33         int     capacity;       /* total number of sectors */
   34         int     sector_size;    /* sector size in bytes */
   35         int     read_bl_len;    /* block length for reads */
   36         /* ... */
   37 };
   38 
   39 struct sdmmc_cid {
   40         int     mid;            /* manufacturer identification number */
   41         int     oid;            /* OEM/product identification number */
   42         char    pnm[8];         /* product name (MMC v1 has the longest) */
   43         int     rev;            /* product revision */
   44         int     psn;            /* product serial number */
   45         int     mdt;            /* manufacturing date */
   46 };
   47 
   48 typedef u_int32_t sdmmc_response[4];
   49 
   50 struct sdmmc_softc;
   51 
   52 struct sdmmc_task {
   53         void (*func)(void *arg);
   54         void *arg;
   55         int onqueue;
   56         struct sdmmc_softc *sc;
   57         TAILQ_ENTRY(sdmmc_task) next;
   58 };
   59 
   60 #define sdmmc_init_task(xtask, xfunc, xarg) do {                        \
   61         (xtask)->func = (xfunc);                                        \
   62         (xtask)->arg = (xarg);                                          \
   63         (xtask)->onqueue = 0;                                           \
   64         (xtask)->sc = NULL;                                             \
   65 } while (0)
   66 
   67 #define sdmmc_task_pending(xtask) ((xtask)->onqueue)
   68 
   69 struct sdmmc_command {
   70         struct sdmmc_task c_task;       /* task queue entry */
   71         u_int16_t        c_opcode;      /* SD or MMC command index */
   72         u_int32_t        c_arg;         /* SD/MMC command argument */
   73         sdmmc_response   c_resp;        /* response buffer */
   74         void            *c_data;        /* buffer to send or read into */
   75         int              c_datalen;     /* length of data buffer */
   76         int              c_blklen;      /* block length */
   77         int              c_flags;       /* see below */
   78 #define SCF_ITSDONE      0x0001         /* command is complete */
   79 #define SCF_CMD(flags)   ((flags) & 0x00f0)
   80 #define SCF_CMD_AC       0x0000
   81 #define SCF_CMD_ADTC     0x0010
   82 #define SCF_CMD_BC       0x0020
   83 #define SCF_CMD_BCR      0x0030
   84 #define SCF_CMD_READ     0x0040         /* read command (data expected) */
   85 #define SCF_RSP_BSY      0x0100
   86 #define SCF_RSP_136      0x0200
   87 #define SCF_RSP_CRC      0x0400
   88 #define SCF_RSP_IDX      0x0800
   89 #define SCF_RSP_PRESENT  0x1000
   90 /* response types */
   91 #define SCF_RSP_R0       0 /* none */
   92 #define SCF_RSP_R1       (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
   93 #define SCF_RSP_R1B      (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX|SCF_RSP_BSY)
   94 #define SCF_RSP_R2       (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_136)
   95 #define SCF_RSP_R3       (SCF_RSP_PRESENT)
   96 #define SCF_RSP_R4       (SCF_RSP_PRESENT)
   97 #define SCF_RSP_R5       (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
   98 #define SCF_RSP_R5B      (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX|SCF_RSP_BSY)
   99 #define SCF_RSP_R6       (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
  100         int              c_error;       /* errno value on completion */
  101 
  102         /* Host controller owned fields for data xfer in progress */
  103         int c_resid;                    /* remaining I/O */
  104         u_char *c_buf;                  /* remaining data */
  105 };
  106 
  107 /*
  108  * Decoded PC Card 16 based Card Information Structure (CIS),
  109  * per card (function 0) and per function (1 and greater).
  110  */
  111 struct sdmmc_cis {
  112         u_int16_t        manufacturer;
  113 #define SDMMC_VENDOR_INVALID    0xffff
  114         u_int16_t        product;
  115 #define SDMMC_PRODUCT_INVALID   0xffff
  116         u_int8_t         function;
  117 #define SDMMC_FUNCTION_INVALID  0xff
  118         u_char           cis1_major;
  119         u_char           cis1_minor;
  120         char             cis1_info_buf[256];
  121         char            *cis1_info[4];
  122 };
  123 
  124 /*
  125  * Structure describing either an SD card I/O function or a SD/MMC
  126  * memory card from a "stack of cards" that responded to CMD2.  For a
  127  * combo card with one I/O function and one memory card, there will be
  128  * two of these structures allocated.  Each card slot has such a list
  129  * of sdmmc_function structures.
  130  */
  131 struct sdmmc_function {
  132         /* common members */
  133         struct sdmmc_softc *sc;         /* card slot softc */
  134         u_int16_t rca;                  /* relative card address */
  135         int flags;
  136 #define SFF_ERROR               0x0001  /* function is poo; ignore it */
  137         SIMPLEQ_ENTRY(sdmmc_function) sf_list;
  138         /* SD card I/O function members */
  139         int number;                     /* I/O function number or -1 */
  140         struct device *child;           /* function driver */
  141         struct sdmmc_cis cis;           /* decoded CIS */
  142         /* SD/MMC memory card members */
  143         struct sdmmc_csd csd;           /* decoded CSD value */
  144         struct sdmmc_cid cid;           /* decoded CID value */
  145         sdmmc_response raw_cid;         /* temp. storage for decoding */
  146 };
  147 
  148 /*
  149  * Structure describing a single SD/MMC/SDIO card slot.
  150  */
  151 struct sdmmc_softc {
  152         struct device sc_dev;           /* base device */
  153 #define SDMMCDEVNAME(sc)        ((sc)->sc_dev.dv_xname)
  154         sdmmc_chipset_tag_t sct;        /* host controller chipset tag */
  155         sdmmc_chipset_handle_t sch;     /* host controller chipset handle */
  156         int sc_flags;
  157 #define SMF_SD_MODE             0x0001  /* host in SD mode (MMC otherwise) */
  158 #define SMF_IO_MODE             0x0002  /* host in I/O mode (SD mode only) */
  159 #define SMF_MEM_MODE            0x0004  /* host in memory mode (SD or MMC) */
  160 #define SMF_CARD_PRESENT        0x0010  /* card presence noticed */
  161 #define SMF_CARD_ATTACHED       0x0020  /* card driver(s) attached */
  162         int sc_function_count;          /* number of I/O functions (SDIO) */
  163         struct sdmmc_function *sc_card; /* selected card */
  164         struct sdmmc_function *sc_fn0;  /* function 0, the card itself */
  165         SIMPLEQ_HEAD(, sdmmc_function) sf_head; /* list of card functions */
  166         int sc_dying;                   /* bus driver is shutting down */
  167         struct proc *sc_task_thread;    /* asynchronous tasks */
  168         TAILQ_HEAD(, sdmmc_task) sc_tskq;   /* task thread work queue */
  169         struct sdmmc_task sc_discover_task; /* card attach/detach task */
  170         struct sdmmc_task sc_intr_task; /* card interrupt task */
  171         struct lock sc_lock;            /* lock around host controller */
  172         void *sc_scsibus;               /* SCSI bus emulation softc */
  173         TAILQ_HEAD(, sdmmc_intr_handler) sc_intrq; /* interrupt handlers */
  174 };
  175 
  176 /*
  177  * Attach devices at the sdmmc bus.
  178  */
  179 struct sdmmc_attach_args {
  180         struct scsi_link scsi_link;     /* XXX */
  181         struct sdmmc_function *sf;
  182 };
  183 
  184 #define IPL_SDMMC       IPL_BIO
  185 #define splsdmmc()      splbio()
  186 
  187 #define SDMMC_LOCK(sc)   lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL)
  188 #define SDMMC_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL)
  189 
  190 void    sdmmc_add_task(struct sdmmc_softc *, struct sdmmc_task *);
  191 void    sdmmc_del_task(struct sdmmc_task *);
  192 
  193 struct  sdmmc_function *sdmmc_function_alloc(struct sdmmc_softc *);
  194 void    sdmmc_function_free(struct sdmmc_function *);
  195 int     sdmmc_set_bus_power(struct sdmmc_softc *, u_int32_t, u_int32_t);
  196 int     sdmmc_mmc_command(struct sdmmc_softc *, struct sdmmc_command *);
  197 int     sdmmc_app_command(struct sdmmc_softc *, struct sdmmc_command *);
  198 void    sdmmc_go_idle_state(struct sdmmc_softc *);
  199 int     sdmmc_select_card(struct sdmmc_softc *, struct sdmmc_function *);
  200 int     sdmmc_set_relative_addr(struct sdmmc_softc *,
  201             struct sdmmc_function *);
  202 
  203 void    sdmmc_intr_enable(struct sdmmc_function *);
  204 void    sdmmc_intr_disable(struct sdmmc_function *);
  205 void    *sdmmc_intr_establish(struct device *, int (*)(void *),
  206             void *, const char *);
  207 void    sdmmc_intr_disestablish(void *);
  208 void    sdmmc_intr_task(void *);
  209 
  210 int     sdmmc_io_enable(struct sdmmc_softc *);
  211 void    sdmmc_io_scan(struct sdmmc_softc *);
  212 int     sdmmc_io_init(struct sdmmc_softc *, struct sdmmc_function *);
  213 void    sdmmc_io_attach(struct sdmmc_softc *);
  214 void    sdmmc_io_detach(struct sdmmc_softc *);
  215 u_int8_t sdmmc_io_read_1(struct sdmmc_function *, int);
  216 u_int16_t sdmmc_io_read_2(struct sdmmc_function *, int);
  217 u_int32_t sdmmc_io_read_4(struct sdmmc_function *, int);
  218 int     sdmmc_io_read_multi_1(struct sdmmc_function *, int, u_char *, int);
  219 void    sdmmc_io_write_1(struct sdmmc_function *, int, u_int8_t);
  220 void    sdmmc_io_write_2(struct sdmmc_function *, int, u_int16_t);
  221 void    sdmmc_io_write_4(struct sdmmc_function *, int, u_int32_t);
  222 int     sdmmc_io_write_multi_1(struct sdmmc_function *, int, u_char *, int);
  223 int     sdmmc_io_function_ready(struct sdmmc_function *);
  224 int     sdmmc_io_function_enable(struct sdmmc_function *);
  225 void    sdmmc_io_function_disable(struct sdmmc_function *);
  226 
  227 int     sdmmc_read_cis(struct sdmmc_function *, struct sdmmc_cis *);
  228 void    sdmmc_print_cis(struct sdmmc_function *);
  229 void    sdmmc_check_cis_quirks(struct sdmmc_function *);
  230 
  231 int     sdmmc_mem_enable(struct sdmmc_softc *);
  232 void    sdmmc_mem_scan(struct sdmmc_softc *);
  233 int     sdmmc_mem_init(struct sdmmc_softc *, struct sdmmc_function *);
  234 int     sdmmc_mem_read_block(struct sdmmc_function *, int, u_char *, size_t);
  235 int     sdmmc_mem_write_block(struct sdmmc_function *, int, u_char *, size_t);
  236 
  237 /* ioctls */
  238 
  239 #include <sys/ioccom.h>
  240 
  241 struct bio_sdmmc_command {
  242         void *cookie;
  243         struct sdmmc_command cmd;
  244 };
  245 
  246 struct bio_sdmmc_debug {
  247         void *cookie;
  248         int debug;
  249 };
  250 
  251 #define SDIOCEXECMMC    _IOWR('S',0, struct bio_sdmmc_command)
  252 #define SDIOCEXECAPP    _IOWR('S',1, struct bio_sdmmc_command)
  253 #define SDIOCSETDEBUG   _IOWR('S',2, struct bio_sdmmc_debug)
  254 
  255 #endif

/* [<][>][^][v][top][bottom][index][help] */