【ACCESS精品源码栏目提醒】:网学会员为需要ACCESS精品源码的朋友们搜集整理了linux驱动程序设计介绍 - 计算机教材相关资料,希望对各位网友有所帮助!
linux驱动程序设计介绍 对linux的devfs类型的驱动程序的编写可以从以下几大内容理解和入手: 通过分析驱动程序源代码可以发现驱动程序一般可分三部分: 核心数据结构核心数据和资源的初始化注册以及注消释放底层设备操作函数 A. 核心数据结构 struct file_operations fops 设备驱动程序接口 struct file_operations struct module owner loff_t llseek struct file loff_t int ssize_t read struct file char size_t loff_t ssize_t write struct file const char size_t loff_t int readdir struct file void filldir_t unsigned int poll struct file struct poll_table_struct int ioctl struct inode struct file unsigned int unsigned long int mmap struct file struct vm_area_struct int open struct inode struct file int flush struct file int release struct inode struct file int fsync struct file struct dentry int datasync int fasync int struct file int int lock struct file int struct file_lock ssize_t readv struct file const struct iovec unsigned long loff_t ssize_t writev struct file const struct iovec unsigned long loff_t ssize_t sendpage struct file struct page int size_t loff_t int unsigned long get_unmapped_areastruct file unsigned long unsigned long unsigned long unsigned long block_device_operations 块设备驱动程序接口 int open struct inode struct file int release struct inode struct file int ioctl struct inode struct file unsigned unsigned long int check_media_change kdev_t int revalidate kdev_t struct module owner 块设备的READ.WRITE不在这里注册而是在设备的读写请求队列里注册内核在这里将调用通用的blk_readblk_write.向读写队列发出读写请求. Linux 利用这些数据结构向内核注册 open release ioctl check_media_change rvalidate 等函数的入口句柄. 我们将要编写的openreleaseioctlcheck_media_changerevalidate等函数将在驱动初始化的时候通过一个此结构类型的变量向内核提供函数的 入口. struct request_queue_t 设备请求队列的数据结构 struct request_list unsigned int count unsigned int pending2 struct list_head free struct request struct list_head queue int elevator_sequence kdev_t rq_dev int cmd / READ or WRITE / int errors unsigned long start_time unsigned long sector unsigned long nr_sectors unsigned long hard_sector hard_nr_sectors unsigned int nr_segments unsigned int nr_hw_segments unsigned long current_nr_sectors hard_cur_sectors void special char buffer struct completion waiting struct buffer_head bh struct buffer_head bhtail request_queue_t q struct request_queue / the queue request freelist one for reads and one for writes / struct request_list rq / The total number of requests on each queue / int nr_requests / Batching threshold for sleep/wakeup decisions / int batch_requests / The total number of 512byte blocks on each queue / atomic_t nr_sectors / Batching threshold for sleep/wakeup decisions / int batch_sectors / The max number of 512byte blocks on each queue / int max_queue_sectors / Together with queue_head for cacheline sharing / struct list_head queue_head elevator_t elevator request_fn_proc request_fn merge_request_fn back_merge_fn merge_request_fn front_merge_fn merge_requests_fn merge_requests_fn make_request_fn make_request_fn plug_device_fn plug_device_fn / The