- 论坛徽章:
- 17
|
本帖最后由 asuka2001 于 2013-06-05 20:32 编辑
以MTD设备为例吧:
driver/mtdchar.c向用户空间注册设备节点,如/dev/mtd0,提供 struct file_operations mtd_fops。它是cdev,它提供的功能必须依赖于实际的物理设备 device,即 struct mtd_info (mtd_info有成员 struct device dev)。
从/dev/mtd0到struct mtd_info的映射是由设备节点号来完成,内核在mtdchar_open()中调用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);
.....................
}
来实际操作物理设备,假设是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);
.........................
}
来最终将来自用户空间的需求转换为实际的设备操作。
而这些/dev/mtd0 --> mtd_info --> nand_chip映射,是通过注册设备时设定好的。
|
|