[BACK]Return to flashvar.h CVS log [TXT][DIR] Up to [local] / sys / dev

Annotation of sys/dev/flashvar.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: flashvar.h,v 1.2 2007/06/20 18:15:46 deraadt Exp $    */
                      2:
                      3: /*
                      4:  * Copyright (c) 2005 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 _FLASHVAR_H_
                     20: #define _FLASHVAR_H_
                     21:
                     22: #ifdef _KERNEL
                     23:
                     24: /* Flash controller descriptor structure */
                     25: struct flash_ctl_tag {
                     26:        u_int8_t (*reg8_read)(void *, int);
                     27:        int      (*regx_read_page)(void *, caddr_t, caddr_t);
                     28:        void     (*reg8_write)(void *, int, u_int8_t);
                     29:        int      (*regx_write_page)(void *, caddr_t, caddr_t);
                     30:        void     (*default_disklabel)(void *, dev_t, struct disklabel *);
                     31:        int      (*safe_strategy)(void *, struct buf *);
                     32: };
                     33:
                     34: /*
                     35:  * Pseudo-registers for a fictitious flash controller
                     36:  *
                     37:  * Note that logical levels are assumed for CE and WP bits.
                     38:  * Signals corresponding to these bits are usually negated.
                     39:  */
                     40: #define FLASH_REG_DATA         0x00
                     41: #define FLASH_REG_COL          0x01
                     42: #define FLASH_REG_ROW          0x02
                     43: #define FLASH_REG_CMD          0x03
                     44: #define FLASH_REG_ALE          0x04
                     45: #define FLASH_REG_CLE          0x05
                     46: #define FLASH_REG_CE           0x06
                     47: #define FLASH_REG_WP           0x07
                     48: #define FLASH_REG_READY                0x0f
                     49:
                     50: /* Flash device descriptor structure */
                     51: struct flashdev {
                     52:        u_int16_t        id;
                     53:        const char      *longname;
                     54:        u_long           pagesize;      /* bytes per page */
                     55:        u_long           oobsize;       /* OOB bytes per page */
                     56:        u_long           blkpages;      /* pages per erasable block */
                     57:        u_long           capacity;      /* pages per device */
                     58: };
                     59:
                     60: #define FLASH_DEVICE(v,d)              ((FLASH_VENDOR_##v << 8) | (d))
                     61:
                     62: /* Flash device vendors */
                     63: #define FLASH_VENDOR_SAMSUNG           0xec
                     64:
                     65: /* Flash devices */
                     66: #define FLASH_DEVICE_SAMSUNG_K9F2808U0C FLASH_DEVICE(SAMSUNG, 0x73)
                     67: #define FLASH_DEVICE_SAMSUNG_K9F1G08U0A FLASH_DEVICE(SAMSUNG, 0xf1)
                     68:
                     69: /* Maximum sizes for all devices */
                     70: #define FLASH_MAXPAGESIZE      2048
                     71: #define FLASH_MAXOOBSIZE       64
                     72:
                     73: /*
                     74:  * Should-be private softc structure for the generic flash driver.
                     75:  */
                     76: struct flash_softc {
                     77:        struct device            sc_dev;
                     78:        /* Disk device information */
                     79:        struct disk              sc_dk;
                     80:        struct buf               sc_q;
                     81:        struct buf              *sc_bp;
                     82:        int                      sc_flags;
                     83:        /* Flash controller tag */
                     84:        struct flash_ctl_tag    *sc_tag;
                     85:        void                    *sc_cookie;
                     86:        /* Flash device characteristics */
                     87:        const struct flashdev   *sc_flashdev;
                     88:        int                      sc_maxwaitready;
                     89:        int                      sc_maxwaitcomplete;
                     90: };
                     91:
                     92: /* Values for sc_flags */
                     93: #define FDK_LOADED              0x00000001
                     94: #define FDK_SAFE                0x00000002
                     95:
                     96: /*
                     97:  * Similar to vnd(4) devices there are two kinds of flash devices.
                     98:  * Both device kinds share the same disklabel.
                     99:  *
                    100:  * ``Safe'' devices have bit 11 set in the minor number and use the
                    101:  * out-of-band page data to implement wear-leveling and transparent
                    102:  * management of bad block information. Block erasing and rewriting
                    103:  * is also handled transparently; arbitrary pages can be modified.
                    104:  *
                    105:  * ``Unsafe'' devices provide raw access to the flash pages. Access
                    106:  * to OOB page data is possible via ioctl()s only with these devices.
                    107:  * Erasing the containing flash block may be necessary before a page
                    108:  * can be writting successfully, but the block erase command is only
                    109:  * provided as an ioctl().
                    110:  */
                    111: #define flashsafe(x)   (minor(x) & 0x800)
                    112: #define flashunit(x)   DISKUNIT(makedev(major(x), minor(x) & 0x7ff))
                    113: #define flashpart(x)   DISKPART(makedev(major(x), minor(x) & 0x7ff))
                    114: #define flashlabeldev(x) (MAKEDISKDEV(major(x), flashunit(x), RAW_PART)\
                    115:                         |flashsafe(x))
                    116:
                    117: void    flashattach(struct flash_softc *, struct flash_ctl_tag *, void *);
                    118: int     flashdetach(struct device *, int);
                    119: int     flashactivate(struct device *, enum devact);
                    120:
                    121: u_int8_t flash_reg8_read(struct flash_softc *, int);
                    122: void    flash_reg8_read_page(struct flash_softc *, caddr_t, caddr_t);
                    123: void    flash_reg8_write(struct flash_softc *, int, u_int8_t);
                    124: void    flash_reg8_write_page(struct flash_softc *, caddr_t, caddr_t);
                    125: void    flash_chip_enable(struct flash_softc *);
                    126: void    flash_chip_disable(struct flash_softc *);
                    127: int     flash_chip_reset(struct flash_softc *);
                    128: int     flash_chip_identify(struct flash_softc *, u_int8_t *, u_int8_t *);
                    129: int     flash_chip_erase_block(struct flash_softc *, long);
                    130: int     flash_chip_read_block(struct flash_softc *, long, caddr_t);
                    131: int     flash_chip_read_page(struct flash_softc *, long, caddr_t, caddr_t);
                    132: int     flash_chip_read_oob(struct flash_softc *, long, caddr_t);
                    133: int     flash_chip_write_block(struct flash_softc *, long, caddr_t, caddr_t);
                    134: int     flash_chip_write_page(struct flash_softc *, long, caddr_t, caddr_t);
                    135: int     flash_chip_verify_block(struct flash_softc *, long, caddr_t, caddr_t);
                    136: int     flash_chip_verify_page(struct flash_softc *, long, caddr_t, caddr_t);
                    137:
                    138: #endif /* _KERNEL */
                    139:
                    140: /* XXX: define ioctl commands for OOB page data access and block erase. */
                    141:
                    142: #endif /* _FLASHVAR_H_ */

CVSweb