tools/build-R2_19_3/fsboot/cbl/nand/mtd.h

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

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