- 論壇徽章:
- 17
|
本帖最后由 asuka2001 于 2013-06-05 20:32 編輯
以MTD設(shè)備為例吧:
driver/mtdchar.c向用戶空間注冊設(shè)備節(jié)點,如/dev/mtd0,提供 struct file_operations mtd_fops。它是cdev,它提供的功能必須依賴于實際的物理設(shè)備 device,即 struct mtd_info (mtd_info有成員 struct device dev)。
從/dev/mtd0到struct mtd_info的映射是由設(shè)備節(jié)點號來完成,內(nèi)核在mtdchar_open()中調(diào)用mtd = get_mtd_device(NULL, devnum);來完成此映射。
mtd_info通過自身的接口,如
struct mtd_info {
....................
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);
.....................
}
來實際操作物理設(shè)備,假設(shè)是nand flash。mtd_info后面又要通過成員變量 priv映射到 struct nand_chip,通過它的成員方法
struct nand_chip {
.........................
void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
void (*erase_cmd)(struct mtd_info *mtd, int page);
int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
const uint8_t *buf, int oob_required, int page,
int cached, int raw);
.........................
}
來最終將來自用戶空間的需求轉(zhuǎn)換為實際的設(shè)備操作。
而這些/dev/mtd0 --> mtd_info --> nand_chip映射,是通過注冊設(shè)備時設(shè)定好的。
|
|