struct mtd_info { //硬件设备的类型,如:MTD_RAM,MTD_ROM,MTD_NORFlash,MTD_NANDFlash,MTD_PEROM等 u_char type; //设备支持的选项,如:MTD_ERASEABLE(可擦除),MTD_WRITEB_WRITEALBE(可编程), //MTD_XIP(可片内执行),MTD_OOB(NAND额外数据),MTD_ECC(支持自动ECC)等 uint32_t flags; uint64_t size;//MTD设备的大小 uint32_t erasesize;//主要的擦除块大小(注意:同一个MTD设备可能有几种不同的erasesize) uint32_t writesize;//编程块大小 uint32_t oobsize;//OOB数据大小 uint32_t oobavail;
unsigned int erasesize_shift; unsigned int writesize_shift; unsigned int erasesize_mask; unsigned int writesize_mask;
const char *name; int index;
struct nand_ecclayout *ecclayout;//ECC布局结构
int numeraseregions;//擦除区域的个数,通常为1 struct mtd_erase_region_info *eraseregions;//擦除区域的指针
//此方法将一个erase_info结构放入擦除队列中 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
//point和unpoint方法分别用于允许和禁止芯片内执行(eXecute-In-Place,简称XIP),如果unpoint为NULL,则表示禁止XIP int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, void **virt, resource_size_t *phys); void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
//如果不为NULL,则表示允许无MMU单元的虚拟地址映射 unsigned long (*get_unmapped_area) (struct mtd_info *mtd,unsigned long len,unsigned long offset,unsigned long flags); struct backing_dev_info *backing_dev_info;
//read和write分别用于MTD设备的读和写 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
//read_oob和write_oob分别用于读写MTD设备的OOB数据 int (*read_oob) (struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops); int (*write_oob) (struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
//一下几个方法是用于实现访问一些受保护的寄存器(一般这只是出现在某些特定的Flash设备上) int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
//基于kvec的形式写 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
//实现MTD设备的同步操作 void (*sync) (struct mtd_info *mtd);
//实现特定芯片的加锁和解锁 int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
//实现支持电源管理 int (*suspend) (struct mtd_info *mtd); void (*resume) (struct mtd_info *mtd);
//坏块管理功能 int (*block_isbad) (struct mtd_info *mtd, loff_t ofs); int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
//默认重启的MTD设备工作模式 struct notifier_block reboot_notifier;
//用于记录ECC状态的信息 struct mtd_ecc_stats ecc_stats; /* Subpage shift (NAND) */ int subpage_sft;
//私有数据,注意是void类型的指针 void *priv;
struct module *owner; struct device dev; int usecount;//记录用户的个数
//这两个方法用于设备驱动的回调,可以根据具体需要来决定是否实现他们 int (*get_device) (struct mtd_info *mtd); void (*put_device) (struct mtd_info *mtd); }; |