双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

关于设备驱动模型的一个问题,谢谢

charles8513 charles8513 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我们知道cdev表示的是字符设备,而block_device表示的是块设备,但似乎都没看见他们内嵌device结构,2.6里面不是利用device结构来使得这些设备被包含在各种各样的subsystem里面的吗?似乎gendisk 结构里面还有一个device的指针,但是为什么不内嵌在里面,而使用指针呢?在cdev里面就找不到device的影子了:

struct block_device {
dev_t bd_dev; /* not a kdev_t - it's a search key */
struct inode * bd_inode; /* will die */
int bd_openers;
struct semaphore bd_sem; /* open/close mutex */
struct semaphore bd_mount_sem; /* mount mutex */
struct list_head bd_inodes;
void * bd_holder;
int bd_holders;
struct block_device * bd_contains;
unsigned bd_block_size;
struct hd_struct * bd_part;
unsigned bd_part_count;
int bd_invalidated;
struct gendisk * bd_disk;
struct list_head bd_list;
/*
* Private data. You must have bd_claim'ed the block_device
* to use this. NOTE: bd_claim allows an owner to claim
* the same device multiple times, the owner must take special
* care to not mess up bd_private for that case.
*/
unsigned long bd_private;
};

struct cdev {
struct kobject kobj;
struct module *owner;
struct file_operations *ops;
struct list_head list;
dev_t dev;
unsigned int count;
};


struct device {
int dev_type; // PCICA, PCICC, or PCIXCC
enum devstat dev_stat; // current device status
int dev_self_x; // Index in array
int disabled; // Set when device is in error
int user_disabled; // Set when device is disabled by user
int dev_q_depth; // q depth
unsigned char * dev_resp_p; // Response buffer address
int dev_resp_l; // Response Buffer length
int dev_caller_count; // Number of callers
int dev_total_req_cnt; // # requests for device since load
struct list_head dev_caller_list; // List of callers
};

那么像device这样的通用设备结构和具体的设备结构到底是个什么关系呢?谢谢。
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
charles8513
Linux_Kernel 4,469 成员 17,458 内容