os/nandboot-R2_0_4/mtd/mtd.h

Go to the documentation of this file.
00001 /*
00002  * Taken from  include/linux/mtd/mtd.h, from Linux 2.6.16 (IR2_6_16-9)
00003  * Modified to run outside Linux.
00004  * #if 0'd to remove non-essential functionality
00005  *
00006  * $Id: mtd.h,v 1.1.1.1 2008/11/27 20:04:00 elphel Exp $
00007  *
00008  * Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al.
00009  *
00010  * Released under GPL
00011  */
00012 
00013 #ifndef __MTD_MTD_H__
00014 #define __MTD_MTD_H__
00015 
00016 #ifndef __KERNEL__
00017 #error This is a kernel header. Perhaps include mtd-user.h instead?
00018 #endif
00019 
00020 /* only include absolutely necessary linux headers which will not change
00021  * significantly
00022  */
00023 #if 0
00024 #include <linux/config.h>
00025 #endif
00026 #include <linux/types.h>
00027 #if 0
00028 #include <linux/module.h>
00029 #include <linux/uio.h>
00030 #include <linux/notifier.h>
00031 
00032 #include <linux/mtd/compatmac.h>
00033 #include <mtd/mtd-abi.h>
00034 #endif
00035 
00036 #include "mtd-abi.h"
00037 
00038 #define MTD_CHAR_MAJOR 90
00039 #define MTD_BLOCK_MAJOR 31
00040 #define MAX_MTD_DEVICES 16
00041 
00042 #define MTD_ERASE_PENDING       0x01
00043 #define MTD_ERASING             0x02
00044 #define MTD_ERASE_SUSPEND       0x04
00045 #define MTD_ERASE_DONE          0x08
00046 #define MTD_ERASE_FAILED        0x10
00047 
00048 /* If the erase fails, fail_addr might indicate exactly which block failed.  If
00049    fail_addr = 0xffffffff, the failure was not at the device level or was not
00050    specific to any particular block. */
00051 struct erase_info {
00052         struct mtd_info *mtd;
00053         u_int32_t addr;
00054         u_int32_t len;
00055         u_int32_t fail_addr;
00056         u_long time;
00057         u_long retries;
00058         u_int dev;
00059         u_int cell;
00060         void (*callback) (struct erase_info *self);
00061         u_long priv;
00062         u_char state;
00063         struct erase_info *next;
00064 };
00065 
00066 struct mtd_erase_region_info {
00067         u_int32_t offset;                       /* At which this region starts, from the beginning of the MTD */
00068         u_int32_t erasesize;            /* For this region */
00069         u_int32_t numblocks;            /* Number of blocks of erasesize in this region */
00070 };
00071 
00072 struct mtd_info {
00073         u_char type;
00074         u_int32_t flags;
00075         u_int32_t size;  // Total size of the MTD
00076 
00077         /* "Major" erase size for the device. Naïve users may take this
00078          * to be the only erase size available, or may use the more detailed
00079          * information below if they desire
00080          */
00081         u_int32_t erasesize;
00082 
00083         u_int32_t oobblock;  // Size of OOB blocks (e.g. 512)
00084         u_int32_t oobsize;   // Amount of OOB data per block (e.g. 16)
00085         u_int32_t ecctype;
00086         u_int32_t eccsize;
00087 
00088         /*
00089          * Reuse some of the above unused fields in the case of NOR flash
00090          * with configurable programming regions to avoid modifying the
00091          * user visible structure layout/size.  Only valid when the
00092          * MTD_PROGRAM_REGIONS flag is set.
00093          * (Maybe we should have an union for those?)
00094          */
00095 #define MTD_PROGREGION_SIZE(mtd)  (mtd)->oobblock
00096 #define MTD_PROGREGION_CTRLMODE_VALID(mtd)  (mtd)->oobsize
00097 #define MTD_PROGREGION_CTRLMODE_INVALID(mtd)  (mtd)->ecctype
00098 
00099         // Kernel-only stuff starts here.
00100         char *name;
00101         int index;
00102 
00103         // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO)
00104         struct nand_oobinfo oobinfo;
00105         u_int32_t oobavail;  // Number of bytes in OOB area available for fs
00106 
00107         /* Data for variable erase regions. If numeraseregions is zero,
00108          * it means that the whole device has erasesize as given above.
00109          */
00110         int numeraseregions;
00111         struct mtd_erase_region_info *eraseregions;
00112 
00113         /* This really shouldn't be here. It can go away in 2.5 */
00114         u_int32_t bank_size;
00115 
00116         int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
00117 
00118         /* This stuff for eXecute-In-Place */
00119         int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
00120 
00121         /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
00122         void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);
00123 
00124 
00125         int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00126         int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
00127 
00128         int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
00129         int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
00130 
00131         int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00132         int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
00133 
00134         /*
00135          * Methods to access the protection register area, present in some
00136          * flash devices. The user data is one time programmable but the
00137          * factory data is read only.
00138          */
00139         int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
00140         int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00141         int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
00142         int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00143         int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00144         int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
00145 
00146         /* kvec-based read/write methods. We need these especially for NAND flash,
00147            with its limited number of write cycles per erase.
00148            NB: The 'count' parameter is the number of _vectors_, each of
00149            which contains an (ofs, len) tuple.
00150         */
00151         int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
00152         int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from,
00153                 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
00154         int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
00155         int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to,
00156                 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
00157 
00158         /* Sync */
00159         void (*sync) (struct mtd_info *mtd);
00160 
00161         /* Chip-supported device locking */
00162         int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
00163         int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
00164 
00165         /* Power Management functions */
00166         int (*suspend) (struct mtd_info *mtd);
00167         void (*resume) (struct mtd_info *mtd);
00168 
00169         /* Bad block management functions */
00170         int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
00171         int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
00172 
00173         struct notifier_block reboot_notifier;  /* default mode before reboot */
00174 
00175         void *priv;
00176 
00177         struct module *owner;
00178         int usecount;
00179 };
00180 
00181 
00182         /* Kernel-side ioctl definitions */
00183 
00184 extern int add_mtd_device(struct mtd_info *mtd);
00185 extern int del_mtd_device (struct mtd_info *mtd);
00186 
00187 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
00188 
00189 extern void put_mtd_device(struct mtd_info *mtd);
00190 
00191 
00192 struct mtd_notifier {
00193         void (*add)(struct mtd_info *mtd);
00194         void (*remove)(struct mtd_info *mtd);
00195         struct list_head list;
00196 };
00197 
00198 
00199 extern void register_mtd_user (struct mtd_notifier *new);
00200 extern int unregister_mtd_user (struct mtd_notifier *old);
00201 
00202 int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
00203                        unsigned long count, loff_t to, size_t *retlen);
00204 
00205 int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
00206                       unsigned long count, loff_t from, size_t *retlen);
00207 
00208 #define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
00209 #define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
00210 #define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
00211 #define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
00212 #define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
00213 #define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
00214 #define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
00215 #define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
00216 #define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
00217 #define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
00218 #define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
00219 #define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd);  } while (0)
00220 
00221 
00222 #ifdef CONFIG_MTD_PARTITIONS
00223 void mtd_erase_callback(struct erase_info *instr);
00224 #else
00225 static inline void mtd_erase_callback(struct erase_info *instr)
00226 {
00227         if (instr->callback)
00228                 instr->callback(instr);
00229 }
00230 #endif
00231 
00232 /*
00233  * Debugging macro and defines
00234  */
00235 #define MTD_DEBUG_LEVEL0        (0)     /* Quiet   */
00236 #define MTD_DEBUG_LEVEL1        (1)     /* Audible */
00237 #define MTD_DEBUG_LEVEL2        (2)     /* Loud    */
00238 #define MTD_DEBUG_LEVEL3        (3)     /* Noisy   */
00239 
00240 #ifdef CONFIG_MTD_DEBUG
00241 #define DEBUG(n, args...)                               \
00242         do {                                            \
00243                 if (n <= CONFIG_MTD_DEBUG_VERBOSE)      \
00244                         printk(KERN_INFO args);         \
00245         } while(0)
00246 #else /* CONFIG_MTD_DEBUG */
00247 #define DEBUG(n, args...) do { } while(0)
00248 
00249 #endif /* CONFIG_MTD_DEBUG */
00250 
00251 #endif /* __MTD_MTD_H__ */

Generated on Fri Nov 28 00:06:24 2008 for elphel by  doxygen 1.5.1