设为首页 加入收藏

TOP

Linux驱动开发之块设备初入门(二)
2016-12-12 08:15:24 】 浏览:631
Tags:Linux 驱动 开发 设备 入门
(struct inode *, struct file *, unsigned, unsigned long);

long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
long (*compat_ioctl) (struct file *, unsigned, unsigned long);
int (*direct_access) (struct block_device *, sector_t, unsigned long *);

/*内核周期调用检查驱动器介质有没有发生改变,改变返回非0,没有改变返回0。用于支持可移动设备,非可以移动设备不用实现*/
int (*media_changed) (struct gendisk *);

/*被调用响应介质被改变,驱动进行必要的工作*/
int (*reva lidate_disk) (struct gendisk *);

/*根据驱动器的几何信息填充hd_geometry,包含磁头,柱面,扇区等信息.*/
int (*getgeo)(struct block_device *, struct hd_geometry *);

/*模块拥有者,一般初始化为THIS_MODULE*/
struct module *owner;
};
block_device_operations 结构中没有实际读或写数据的函数,在块 I/O 子系统中,这些操作由请求函数处理。


6、request 和 bio 结构体


struct request {
struct list_head queuelist;/*请求链表*/
struct list_head donelist;
request_queue_t *q; /*请求所属队列*/
unsigned int cmd_flags;
enum rq_cmd_type_bits cmd_type;
sector_t sector; /* 当前扇区 */
sector_t hard_sector; /*要传输的下一个扇区*/
unsigned long nr_sectors;/* 要传输的扇区数目*/
unsigned long hard_nr_sectors; /*要被完成扇区的数目 */
unsigned int current_nr_sectors;/*当前传送的扇区*/
unsigned int hard_cur_sectors; /*当前要被完成的扇区数目*/
struct bio *bio; /*请求的block i/o(bio)结构体链表首 request请求 第一个bio*/
struct bio *biotail;/*请求的bio结构体链表尾 request请求 最后个bio*/
char *buffer; /*request请求中断 第一个bio*/
int ref_count;/*引用计数*/
.....................
};


struct request_queue
{
..........................
/*自旋锁 保护队列结构*/
spinlock_t __queue_lock;
spinlock_t *queue_lock;


/*kobject队列 */
struct kobject kobj;


/* queue settings */
unsigned long nr_requests; /*最大的请求数量*/
unsigned int nr_congestion_on;
unsigned int nr_congestion_off;
unsigned int nr_batching;
unsigned short max_sectors; /*最大扇区数*/
unsigned short max_hw_sectors;
unsigned short max_phys_sectors;/*最大的段数*/
unsigned short max_hw_segments;
unsigned short hardsect_size; /*硬件扇区尺寸*/
unsigned int max_segment_size; /*最大的段尺寸*/
unsigned long seg_boundary_mask;/*段边界掩码*/
unsigned int dma_alignment; /*DMA传送内存对齐限制*/
struct blk_queue_tag* queue_tags;
atomic_t refcnt; /*引用计数*/
unsigned int in_flight;
unsigned int sg_timeout;
unsigned int sg_reserved_size;
int node;
struct list_head drain_list;
struct request* flush_rq;
unsigned char ordered;
};

关于request_queue的操作:
/*初始化请求队列*/

kernel elevator = deadline;/*给kernel添加启动参数*/

request_queue_t *blk_init_queue(request_fn_proc *rfn, spinlock_t *lock)
/*
*两个参数分别是请求处理函数指针 控制队列访问权限的自旋锁
*此函数会分配内存,需要判断返回值,在加载函数中调用
*/



/*清除请求队列*/
void blk_cleanup_queue(request_queue_t * q)
/*
* 此函数完成将请求队列返回给系统的任务,一般在卸载函数中调用.
* 此函数即bld_put_queue()的宏定义#define blk_put_queue(q) blk_cleanup_queue((q))
*/



/*分配请求队列*/
request_queue_t *blk_alloc_queue(gfp_t gfp_mask)

void blk_queue_make_request(request_queue_t * q, make_request_fn * mfn)
/*
* 前一个函数用于分配一个请求队列,后一个函数是将请求队列和"制造函数"进行绑定
* 但函数blk_alloc_queue实际上并不包含任何请求.
*/

/*去除请求*/
void blkdev_dequeue_request(struct request* req);
void elv_requeue_request(request_queue_t* queue, struct request* req);

/*启停请求*/
void blk_stop_queue(request_queue_t* queue);

首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Nand Flash驱动程序编写 下一篇在Linux下的中断方式读取按键驱动..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目