device_driver include/linux/device.h struct device_driver {
const char???????????? * name; /* 驅動名稱 */
struct bus_type??????? * bus;? /* 總線類型 */
struct completion????? unloaded;? /* 卸載事件通知機制 */ struct kobject????????????????????? kobj; /* sys 中的對象 */
struct klist?????????? klist_devices; /* 設備列表 */ struct klist_node?????????????????????? knode_bus; /* 總線結點列表 */
struct module????????? * owner;/* 所有者 */
/* 設備驅動通用方法 */
int???? (*probe)?? ?(struct device * dev); /* 探測設備 */ int??? (*remove)? ?(struct device * dev); /* 移除設備 */ void??? (*shutdown)???? (struct device * dev); /* 關閉設備 */
/* 掛起設備?????? ?*/
int??? (*suspend)???? (struct device * dev, pm_message_t state, u32 level); int?????? (*resume)????? (struct device * dev, u32 level); /* 恢復 */
};
platform_device include/linux/device.h struct platform_device {
const char???? * name;? /* 名稱 */
u32??????????? id;????? /* 設備編號, -1 表示不支持同類多個設備 */ struct device dev;?????????????? /* 設備 */
u32??????????? num_resources; /* 資源數 */ struct resource * resource; /* 資源列表 */
};
3. resource struct resource {
const char name;????????? /*
資源名稱 */
unsigned
long start, end; /* 開始位置和結束位置 */ unsigned long flags;???????????????????????? /* 資源類型 */
/* 資源在資源樹中的父親,兄弟和孩子
*/ struct resource *parent, *sibling, *child;
};
4. device include/linux/device.h
struct device {
struct klist?????????? klist_children;
/* 在設備列表中的孩子列表 */ struct klist_node?????????????????????? knode_parent;?? /* 兄弟結點 */
struct
klist_node? knode_driver;?? /* 驅動結點 */ struct klist_node?? knode_bus;??? /* 總線結點 */ struct device?? parent; /* 父親?? ?*/
struct kobject kobj;?????????????????? /* sys結點 */ char
bus_id[BUS_ID_SIZE];
struct semaphore
sem;??? /* 同步驅動的信號量 */
struct bus_type * bus;??????? /* 總線類型??????? ?*/
struct device_driver *driver;?? /* 設備驅動????? */ void? *driver_data;
/* 驅動的私有數據? ?*/
void?????????? *platform_data; /* 平臺指定的數據,為 device
核心驅動保留 */ void?????????????? *firmware_data; /* 固件指定的數據,為 device
核心驅動保留 */ struct dev_pm_info
power;???? /* 設備電源管理信息 ?*/
u64??????????? *dma_mask;????? /* DMA掩碼???????? ?*/
u64??????????? coherent_dma_mask;
struct
list_head dma_pools;???? /* DMA緩沖池????? ?*/
struct dma_coherent_mem *dma_mem; /* 連續 DMA 內存的起始位置
*/
void??? (*release)(struct device * dev);? /*
釋放設置方法 */
};
nand_hw_control
include/linux/mtd/nand.h struct nand_hw_control {
spinlock_t?? lock;? ?/* 自旋鎖,用于硬件控制 */ struct nand_chip *active; /* 正在處理 MTD 設備
*/ wait_queue_head_t wq;???? ?/* 等待隊列??? */
};
nand_chip
include/linux/mtd/nand.h struct nand_chip {
void??? iomem?? *IO_ADDR_R; /* 讀地址 */ void??? iomem?????????????? *IO_ADDR_W; /* 寫地址 */
/* 字節操作?? */
u_char???????? (*read_byte)(struct mtd_info *mtd);? /*
讀一個字節 */
void?????????? (*write_byte)(struct mtd_info *mtd, u_char byte); /* 寫一個字節 */
/*
雙字節操作 */
u16??????????? (*read_word)(struct mtd_info mtd); /* 讀一個字 */
void?????????? (*write_word)(struct mtd_info *mtd, u16 word); /* 寫一個字 */
/*
buffer 操作 */
void?????????? (*write_buf)(struct mtd_info *mtd, const u_char *buf, int len); void?????????????? (*read_buf)(struct mtd_info
*mtd, u_char *buf, int len);
int??????????? (*verify_buf)(struct
mtd_info *mtd, const u_char
*buf, int len);
/*
選擇一個操作芯片 */
void?????????? (*select_chip)(struct
mtd_info *mtd, int chip);
/*
壞塊檢查操作 */
int??????????? (*block_bad)(struct
mtd_info *mtd, loff_t ofs, int getchip);
/*
壞塊標記操作 */
int??????????? (*block_markbad)(struct
mtd_info *mtd, loff_t ofs);
/*
硬件控制操作 */
void?????????? (*hwcontrol)(struct
mtd_info *mtd, int cmd);
/*
設備準備操作 */
int??????????? (*dev_ready)(struct
mtd_info *mtd);
/*
命令發送操作 */
void?????????? (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, int
page_addr);
/*
等待命令完成 */
int??????????? (*waitfunc)(struct mtd_info
*mtd, struct nand_chip
*this, int state);
/*
計算 ECC 碼操作 */
int??????????? (*calculate_ecc)(struct
mtd_info *mtd, const u_char *dat,
u_char
*ecc_code);
/*
數據糾錯操作 */
int??????????? (*correct_data)(struct mtd_info *mtd, u_char *dat, u_char *read_ecc,
u_char *calc_ecc);
/*
開啟硬件 ECC */
void?????????? (*enable_hwecc)(struct
mtd_info *mtd, int mode);
/* 擦除操作???? */
void?????????? (*erase_cmd)(struct
mtd_info *mtd, int page);
/* 檢查壞塊表?? */
int??????????? (*scan_bbt)(struct
mtd_info *mtd);
int??????????? eccmode;?? /* ECC 模式????? */
int??????????? eccsize;?? /* ECC 計算時使用的字節數 */
int??????????? eccbytes;? /*
ECC 碼的字節數 */
int??????????? eccsteps;? /*
ECC 碼計算的步驟數 */
int??????????? chip_delay;
/* 芯片的延遲時間 */ spinlock_t?????????????? chip_lock;? /*
芯片訪問的自旋鎖 */ wait_queue_head_t wq;??????????? /* 芯片訪問的等待隊列 */ nand_state_t? state;? /*
Nand Flash 狀態 */
int??????????? page_shift; /* 頁右移的位數,即 column
地址位數 */
int??????????? phys_erase_shift; /* 塊右移的位數, 即 column 和頁一共的地址位數 */ int?????????????? bbt_erase_shift; /* 壞塊頁表的位數 */
int??????????? chip_shift; /* 該芯片總共的地址位數 */
u_char???????? *data_buf;? /*
數據緩沖區 */
u_char???????? *oob_buf;? /*
oob 緩沖區 */
int??????????? oobdirty;? /*
oob 緩沖區是否需要重新初始化 */
u_char???????? *data_poi;? /* 數據緩沖區指針 */ unsigned int?????????????? options;?? /*
芯片專有選項 */
int??????????? badblockpos;/* 壞塊標示字節在 OOB 中的位置 */
int??????????? numchips;? /* 芯片的個數?? */
unsigned
long
chipsize;
/*
在多個芯片組中, 一個芯片的大小 */
int
pagemask;
/* 每個芯片頁數的屏蔽字, 通過它取出每個芯片包含多少個頁 */
int
pagebuf;
/*
在頁緩沖區中的頁號 */
struct nand_oobinfo??? *autooob; /* oob 信息 */ uint8_t? *bbt;????????????????????? /* 壞塊頁表 */
struct nand_bbt_descr?????????????? *bbt_td;
/* 壞塊表描述 */
struct nand_bbt_descr? *bbt_md; /*
壞塊表鏡像描述 */
struct nand_bbt_descr? *badblock_pattern; /* 壞塊檢測模板 */
struct nand_hw_control *controller; /* 硬件控制 */
void?????????? *priv;
/* 私有數據結構 */
/*
進行附加錯誤檢查 */
int??????????? (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);
};
mtd_info include/linux/mtd/mtd.h struct mtd_info {
u_char type;?? /* 設備類型?? */ u_int32_t flags; /* 設備標志位組 */ u_int32_t
size; /* 總共設備的大小 */ u_int32_t
erasesize;? /* 擦除塊的大小 */
u_int32_t
oobblock; /* OOB 塊的大小,如:512 個字節有一個 OOB */ u_int32_t oobsize; /* OOB數據的大小,如:一個 OOB 塊有 16 個字節
*/ u_int32_t ecctype; /* ECC 校驗的類型 */
u_int32_t eccsize;? /* ECC 碼的大小? */
char
*name;??????? /* 設備名稱?????? */
int
index;???????? /* 設備編號?????? */
/* oobinfo
信息,它可以通過 MEMSETOOBINFO ioctl 命令來設置 */ struct nand_oobinfo oobinfo;
u_int32_t
oobavail;? /* OOB區的有效字節數,為文件系統提供 */
/* 數據擦除邊界信息???????? */
int numeraseregions;
struct mtd_erase_region_info *eraseregions;
u_int32_t
bank_size; /* 保留 */
/*
擦除操作 */
int (*erase) (struct mtd_info *mtd,
struct erase_info *instr);
/* 指向某個執行代碼位置 */
int (*point) (struct mtd_info *mtd,
loff_t from,
size_t len, size_t *retlen, u_char **mtdbuf);
/*
取消指向 */
void (*unpoint)
(struct mtd_info *mtd, u_char *
addr, loff_t from, size_t len);
/*
讀/寫操作 */
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);
/* 帶 ECC 碼的讀/寫操作 */
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);
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);
/* 帶 OOB 碼的讀/寫操作 */
int
(*read_oob) (struct mtd_info
*mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf);
int
(*write_oob) (struct mtd_info
*mtd, loff_t to, size_t
len, size_t *retlen, const u_char *buf);
/* 提供訪問保護寄存器區的方法 */
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);
/* 提供 readv
和 writev 方法???????? */
int
(*readv) (struct mtd_info
*mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
int
(*readv_ecc) (struct mtd_info
*mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen, u_char *eccbuf,
struct nand_oobinfo *oobsel);
int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
int (*writev_ecc) (struct mtd_info
*mtd, const struct kvec *vecs,
unsigned long count, loff_t to, size_t *retlen, u_char *eccbuf, struct
nand_oobinfo *oobsel);
/*
同步操作 */
void (*sync) (struct mtd_info *mtd);
/* 芯片級支持的加/解鎖操作 */
int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_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);
/* 重啟前的通知事件??????? */
struct
notifier_block reboot_notifier; void *priv; /* 私有數據結構 */
struct module
*owner; /* 模塊所有者 */ int usecount; /* 使用次數 */
};